3
Pascal Ballester (ESO/Garching)
17
/* general Midas includes */
19
#include <midas_def.h>
21
/* FEROS specific includes */
28
int verif, double linid[], double linwav[], double liny[], double lindif[],
29
int nbrow, double lcat[], int nbrowcat, double alpha, double *stdres,
30
double dnull, int reject[]
34
verif, linid, linwav, liny, lindif, nbrow,
35
lcat, nbrowcat, alpha, stdres, dnull, reject
38
double lcat[], linid[], linwav[], liny[], lindif[], alpha;
39
double dnull, *stdres;
40
int reject[], verif, nbrow, nbrowcat;
46
int rowlow, rowupp, rowref, index;
47
int nmatch=0, ldir, ldir_ref;
48
int not_bottom, not_top, debug=0, nbump=0;
49
double resref, reslow, resupp, residual;
50
double resref_abs, reslow_abs, resupp_abs, res_abs;
51
double lambda_ref, lambda_low, lambda_upp, lambda_next;
52
double minlin, mincat;
53
double lambda_lin, lambda_cat;
56
/* Verification loop */
57
/* If the verification parameter verif<0, the line catalog is explored to
58
make sure that wavelengths are sorted by increasing value and no
59
wavelength is duplicated. The value returned is >0 if no violation
62
mincat = minlin = lambda_lin = lambda_low = 0.0;
63
resupp_abs = reslow_abs = reslow = 0.0;
69
lambda_next = lcat[2];
71
ldir_ref = (lambda_next > lambda_low) ? 1 : -1;
73
for (row=2; row<=nbrowcat; row++)
75
lambda_upp = lcat[row];
76
ldir = (lambda_upp > lambda_low) ? 1 : -1;
77
if (ldir != ldir_ref) {
78
sprintf(text,"Warning: Column :WAVE of the line catalog is not sorted by increasing wavelength");
82
if (lambda_low == lambda_upp) {
83
sprintf(text,"Error: Column :WAVE of the line catalog contains duplicate wavelength : %f",lambda_low);
87
lambda_low = lambda_upp;
97
/* Some assumptions are made concerning the input data :
98
- Index of arrays are in the range 1 to N
99
- All N values in the input arrays are valid
100
- Line catalog is sorted by increasing wavelength and contain no duplicated lines
103
for (row = 1; row <= nbrow; row++)
106
reject[row] = NOT_PROCESSED;
110
/* Reads current wavelength to be identified and relative order number */
111
lambda_lin = linwav[row];
114
sprintf(text,"Reading line.tbl row = %d line = %f\n",row,lambda_lin);
118
if ((not_bottom = (row > 1 && liny[row-1] == ordref))) {
120
lambda_low = linwav[rowlow];
121
reslow = lambda_lin - lambda_low;
122
reslow_abs = (reslow < 0) ? -reslow : reslow; /* abs. value */
125
if ((not_top = (row < nbrow && liny[row+1] == ordref))) {
127
lambda_upp = linwav[rowupp];
128
resupp = lambda_lin - lambda_upp;
129
resupp_abs = (resupp < 0) ? -resupp : resupp; /* abs. value */
132
if (not_bottom && not_top)
133
minlin = (reslow_abs<resupp_abs) ? reslow_abs : resupp_abs;
134
if (! not_bottom) minlin = resupp_abs;
135
if (! not_top) minlin = reslow_abs;
137
/* Reads the line catalog at the first entry point and initializes
140
sprintf(text,"Reading catalog thar.tbl rowcat = %d\n",rowcat);
145
lambda_upp = lcat[rowupp];
146
resupp = lambda_lin - lambda_upp;
147
resupp_abs = (resupp < 0) ? -resupp : resupp; /* abs. value */
151
lambda_low = lcat[rowlow];
152
reslow = lambda_lin - lambda_low;
153
reslow_abs = (reslow < 0) ? -reslow : reslow; /* abs. value */
155
else reslow_abs = resupp_abs + 1.;
158
/* The line catalog is assumed to be sorted by increasing wavelength.
159
Depending on which direction is found the minimum residual, the
160
catalog will be searched further in this direction */
162
if (reslow_abs < resupp_abs) {
165
resref_abs = reslow_abs;
166
lambda_ref = lambda_low;
172
resref_abs = resupp_abs;
173
lambda_ref = lambda_upp;
177
res_abs = resref_abs;
179
lambda_cat = lambda_ref;
181
/* Explores the catalog in the direction indicated by index and finds the
182
position of the minimum residual */
183
while (res_abs <= resref_abs) {
185
resref_abs = res_abs;
186
lambda_ref = lambda_cat;
188
if (rowcat < 1 || rowcat > nbrowcat) {
191
/* reject[row] = REACHED_LIMIT; */
195
lambda_cat = lcat[rowcat];
197
sprintf(text,"Matching loop at rowcat = %d lambda_cat = %f, lambda_lin = %f\n", rowcat,lambda_cat,lambda_lin);
200
residual = lambda_lin - lambda_cat;
201
res_abs = (residual < 0) ? -residual : residual; /* abs. value */
205
rowref = rowcat - index;
207
sprintf(text,"Minimum found at %d, lambda_cat = %7.1f, lambda_lin = %7.1f, Residual = %4.1f\n",rowref, lambda_ref, lambda_lin, resref_abs);
211
if ((not_bottom = (rowref > 1))) {
213
lambda_low = lcat[rowlow];
214
reslow = lambda_ref - lambda_low;
215
reslow_abs = (reslow < 0) ? -reslow : reslow; /* abs. value */
218
if ((not_top = (rowref < nbrowcat))) {
220
lambda_upp = lcat[rowupp];
221
resupp = lambda_ref - lambda_upp;
222
resupp_abs = (resupp < 0) ? -resupp : resupp; /* abs. value */
225
if (not_bottom && not_top)
226
mincat = (reslow_abs<resupp_abs) ? reslow_abs : resupp_abs;
227
if (! not_bottom) mincat = resupp_abs;
228
if (! not_top) mincat = reslow_abs;
230
/* Find minimum of all minima */
232
reslow = (minlin < mincat) ? minlin : mincat;
236
sprintf(text,"Comparing line %f with catalog %f.\nResidual is %f and maximum residual is %f\n",lambda_ref,lambda_lin,resref_abs,reslow);
240
if (reject[row] == NOT_PROCESSED) {
242
if (resref_abs < reslow ) {
243
linid[row] = lambda_ref, lindif[row] = resref;
244
reject[row] = SUCCESSFULL_MATCH, *stdres += resref_abs, nmatch++;
246
sprintf(text,"**** Identified line: cat = %f line = %f Residual = %f\n",lambda_ref,lambda_lin,resref);
250
else reject[row] = MATCH_FAILED;
252
} /* End of if (reject[row] == NOT_PROCESSED) */
255
sprintf(text,"Row %d Order %d - %f %f %f %f %f\n",row,ordref,minlin,resref_abs, lambda_ref, lambda_lin,mincat);
262
if (nmatch > 0) *stdres /= (double) nmatch;