diff options
author | Thomas White <taw@physics.org> | 2018-09-10 15:29:18 +0200 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2018-09-10 15:29:18 +0200 |
commit | b89a8bb0780a623b85a82d356d2e82b09942b8a5 (patch) | |
tree | eb081f53ff920be6df7be49c97d0dc9da64fcdb8 /src/indexamajig.c | |
parent | 925610d93bbbdf590a58c5bb9fdae2af5a8fd30f (diff) |
Fussiness / formatting
Diffstat (limited to 'src/indexamajig.c')
-rw-r--r-- | src/indexamajig.c | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/src/indexamajig.c b/src/indexamajig.c index d6ebe3ea..4a80e762 100644 --- a/src/indexamajig.c +++ b/src/indexamajig.c @@ -244,9 +244,19 @@ static void add_geom_beam_stuff_to_field_list(struct imagefile_field_list *copym static struct spectrum *read_spectrum_fromfile(char *fn) { FILE *f; + struct spectrum *s; + int i; + double k, w; + double w_sum = 0; + f = fopen(fn, "r"); + if ( f == NULL ) { + ERROR("Couldn't open '%s'\n", fn); + return NULL; + } - struct spectrum *s = malloc(sizeof(struct spectrum)); + s = malloc(sizeof(struct spectrum)); + if ( s == NULL ) return NULL; if ( fscanf(f, "%d", &s->n) == EOF ) { return NULL; @@ -268,15 +278,14 @@ static struct spectrum *read_spectrum_fromfile(char *fn) return NULL; } - int i; - double k, w; - double w_sum = 0; - for ( i = 0; i < s->n; i++ ) { - if (fscanf(f, "%lf %lf", &k, &w) != EOF) { + for ( i=0; i<s->n; i++ ) { + if ( fscanf(f, "%lf %lf", &k, &w) != EOF ) { s->ks[i] = ph_eV_to_k(k); s->weights[i] = w; w_sum += w; - } else break; + } else { + break; + } } if ( i < s->n - 1 ) { @@ -284,7 +293,7 @@ static struct spectrum *read_spectrum_fromfile(char *fn) return NULL; } - for ( i = 0; i < s->n; i++ ) { + for ( i=0; i<s->n; i++ ) { s->weights[i] /= w_sum; } |