aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2017-12-05 12:16:20 +0100
committerThomas White <taw@physics.org>2018-02-27 17:12:42 +0100
commitde9fbc4335a5d2e3896381403f4b1b5b19dcf444 (patch)
treeb483f58c9489e894b67ae9a507e5a69a650bbea6
parentb7fd93ba785778107214c2f137aaa128084be46b (diff)
const-cleanliness (and a bit of error checking)
-rw-r--r--src/scaling.c28
-rw-r--r--src/scaling.h2
2 files changed, 20 insertions, 10 deletions
diff --git a/src/scaling.c b/src/scaling.c
index ea2a47bd..97503b89 100644
--- a/src/scaling.c
+++ b/src/scaling.c
@@ -459,10 +459,11 @@ void scale_all(Crystal **crystals, int n_crystals, int nthreads,
}
-int linear_scale(RefList *list1, const RefList *list2, double *G)
+/* Calculates G, by which list2 should be multiplied to fit list1 */
+int linear_scale(const RefList *list1, const RefList *list2, double *G)
{
- Reflection *refl1;
- Reflection *refl2;
+ const Reflection *refl1;
+ const Reflection *refl2;
RefListIterator *iter;
int max_n = 256;
int n = 0;
@@ -482,9 +483,9 @@ int linear_scale(RefList *list1, const RefList *list2, double *G)
}
int nb = 0;
- for ( refl1 = first_refl(list1, &iter);
+ for ( refl1 = first_refl_const(list1, &iter);
refl1 != NULL;
- refl1 = next_refl(refl1, iter) )
+ refl1 = next_refl_const(refl1, iter) )
{
signed int h, k, l;
double Ih1, Ih2;
@@ -542,15 +543,24 @@ int linear_scale(RefList *list1, const RefList *list2, double *G)
void scale_all_to_reference(Crystal **crystals, int n_crystals,
- RefList *reference)
+ const RefList *reference)
{
int i;
for ( i=0; i<n_crystals; i++ ) {
double G;
- linear_scale(crystal_get_reflections(crystals[i]), reference, &G);
- crystal_set_osf(crystals[i], G);
- crystal_set_Bfac(crystals[i], 0.0);
+ if ( linear_scale(reference,
+ crystal_get_reflections(crystals[i]),
+ &G) == 0 )
+ {
+ if ( isnan(G) ) {
+ ERROR("NaN scaling factor for crystal %i\n", i);
+ }
+ crystal_set_osf(crystals[i], G);
+ crystal_set_Bfac(crystals[i], 0.0);
+ } else {
+ ERROR("Scaling failed for crystal %i\n", i);
+ }
progress_bar(i, n_crystals, "Scaling to reference");
}
progress_bar(n_crystals, n_crystals, "Scaling to reference");
diff --git a/src/scaling.h b/src/scaling.h
index 85e8c8ab..4d075a3b 100644
--- a/src/scaling.h
+++ b/src/scaling.h
@@ -41,7 +41,7 @@
extern double log_residual(Crystal *cr, const RefList *full, int free,
int *pn_used, const char *filename);
-extern int linear_scale(RefList *list1, const RefList *list2, double *G);
+extern int linear_scale(const RefList *list1, const RefList *list2, double *G);
extern void scale_all(Crystal **crystals, int n_crystals, int nthreads,
PartialityModel pmodel);