1 /*
2   calculations.c
3   sky_model
5   Created by Jayant Murthy on 07/10/12.
6   Copyright (c) 2012 Jayant Murthy. All rights reserved.
7 */
8 #include "sky_model.h"
10 float CALC_SCALE_FACTOR(struct SPECTRA x, struct SPECTRA y)
11 {
12     float scale_factor, int_lambda;
13     float new_spec;
14     int ix, iy;
15     
16     iy = 0;
17     scale_factor = 0;
18     int_lambda   = 0;
19     
20     /*Scale to the filter; Assume that they are all monotonic increasing.
21       Counts = int(flux*effarea)/(int(effarea)*/
22     for (ix = 0; ix < x.nelements; ++ix) {
23         while (y.wavelength[iy] < x.wavelength[ix])
24             ++iy;
25         if (iy == 0)
26             new_spec = 0;
27         else
28             new_spec = y.spectrum[iy - 1] + (y.spectrum[iy] - y.spectrum[iy - 1])/
29             (y.wavelength[iy] - y.wavelength[iy - 1])*
30             (x.wavelength[ix] - y.wavelength[iy - 1]);
31         if (ix > 0)
32             scale_factor += new_spec*x.spectrum[ix]*(x.wavelength[ix] -
33                                                      x.wavelength[ix - 1]);
34     }
35     return (scale_factor);
36 }