forked from MTMurphy77/UVES_popler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUVES_synthThAr.c
59 lines (53 loc) · 2.12 KB
/
UVES_synthThAr.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/****************************************************************************
* Generate a synthetic emission line (or ThAr) calibration spectrum as
* a series of equal height, equal width (in velocity space)
* Gaussians. The existing ThAr spectra are overwritten in this
* process. No noise is put on the new spectra but the error array is
* reset to a small value.
****************************************************************************/
#include <math.h>
#include "UVES_popler.h"
#include "gamm.h"
#include "const.h"
#include "error.h"
int UVES_synthThAr(spectrum *spec, params *par) {
double wlg=0.0,pref=0.0,sigl=0.0,sigr=0.0;
/* double wlg2=0.0,pref2=0.0,sigl2=0.0,sigr2=0.0; */
int fval=0,lval=0; /* First and last valid pixels in raw order */
int i=0,l=0;
/* Loop over all orders */
for (l=0; l<spec->nor; l++) {
/* Check first to see if order is useful */
if (spec->or[l].nuse>=MINUSE) {
/* Find first valid pixel in raw array */
i=0; while (spec->or[l].st[i]<1) i++; fval=i;
/* Find last valid pixel in raw array */
i=spec->or[l].np-1; while (spec->or[l].st[i]<1) i--; lval=i;
/* Loop over valid pixels */
for (i=fval; i<=lval; i++) {
/* Is this pixel near enough to a Gaussian for us to calculate the flux? */
wlg=2.0*(double)((int)(spec->or[l].vhwl[i]/2.0));
wlg=(spec->or[l].vhwl[i]-wlg>1.0) ? wlg+2.0 : wlg;
/* Initialise flux and error */
spec->or[l].fl[i]=100.0; spec->or[l].er[i]=0.1;
if (C_C_K*fabs(spec->or[l].vhwl[i]-wlg)/wlg<20.0) {
pref=70000.0*C_FWHMSIG/spec->or[l].vhwl[i]/C_SQRT2;
sigl=(i) ? pref*(spec->or[l].vhrwl[i-1]-wlg) :
pref*(spec->or[l].fvhlwl-wlg);
sigr=pref*(spec->or[l].vhrwl[i]-wlg);
spec->or[l].fl[i]+=10000.0*(erffn(sigr)-erffn(sigl));
spec->or[l].er[i]+=1.e-2*sqrt(spec->or[l].fl[i]-100.0);
/*
wlg2=wlg*(1.0-0.4/C_C_K);
pref2=110000.0*C_FWHMSIG/spec->or[l].vhwl[i]/C_SQRT2;
sigl2=(i) ? pref2*(spec->or[l].vhrwl[i-1]-wlg2) :
pref2*(spec->or[l].fvhlwl-wlg2);
sigr2=pref2*(spec->or[l].vhrwl[i]-wlg2);
spec->or[l].fl[i]+=10000.0*(erffn(sigr2)-erffn(sigl2));
*/
}
}
}
}
return 1;
}