aboutsummaryrefslogtreecommitdiff
path: root/src/indexamajig.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/indexamajig.c')
-rw-r--r--src/indexamajig.c63
1 files changed, 1 insertions, 62 deletions
diff --git a/src/indexamajig.c b/src/indexamajig.c
index 681d5d31..e4568966 100644
--- a/src/indexamajig.c
+++ b/src/indexamajig.c
@@ -250,66 +250,6 @@ 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;
- }
-
- s = malloc(sizeof(struct spectrum));
- if ( s == NULL ) return NULL;
-
- if ( fscanf(f, "%d", &s->n) == EOF ) {
- return NULL;
- }
-
- if ( s->n <= 0 ) {
- return NULL;
- }
-
- s->ks = malloc(s->n * sizeof(double));
- if ( s->ks == NULL ) {
- ERROR("Failed to allocate spectrum!\n");
- return NULL;
- }
-
- s->weights = malloc(s->n * sizeof(double));
- if ( s->weights == NULL ) {
- ERROR("Failed to allocate spectrum!\n");
- return NULL;
- }
-
- 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;
- }
- }
-
- if ( i < s->n - 1 ) {
- ERROR("Failed to read %d lines from %s\n", s->n, fn);
- return NULL;
- }
-
- for ( i=0; i<s->n; i++ ) {
- s->weights[i] /= w_sum;
- }
-
- return s;
-}
-
-
int main(int argc, char *argv[])
{
int c;
@@ -1164,13 +1104,12 @@ int main(int argc, char *argv[])
/* Load spectrum from file if given */
if ( spectrum_fn != NULL ) {
- iargs.spectrum = read_spectrum_fromfile(spectrum_fn);
+ iargs.spectrum = spectrum_load(spectrum_fn);
if ( iargs.spectrum == NULL ) {
ERROR("Couldn't read spectrum (from %s)\n", spectrum_fn);
return 1;
}
free(spectrum_fn);
- STATUS("Read %d lines from %s\n", iargs.spectrum->n, spectrum_fn);
} else {
iargs.spectrum = NULL;
}