1
/*===========================================================================
2
Copyright (C) 1995-2009 European Southern Observatory (ESO)
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License as
6
published by the Free Software Foundation; either version 2 of
7
the License, or (at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public
15
License along with this program; if not, write to the Free
16
Software Foundation, Inc., 675 Massachusetts Ave, Cambridge,
19
Correspondence concerning ESO-MIDAS should be addressed as follows:
20
Internet e-mail: midas@eso.org
21
Postal address: European Southern Observatory
22
Data Management Division
23
Karl-Schwarzschild-Strasse 2
24
D 85748 Garching bei Muenchen
26
===========================================================================*/
28
/* +++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
29
/* .IDENT mosdisp.c */
30
/* .AUTHORS Pascal Ballester (ESO/Garching) */
31
/* Cristian Levin (ESO/La Silla) */
32
/* .KEYWORDS Spectroscopy, Long-Slit, MOS */
34
/* .VERSION 1.0 Package Modification 21-SEP-1993 */
36
/* 090507 last modif */
37
/* ------------------------------------------------------- */
40
This module is related to the dispersion relation and its representation.
41
The upper modules (lncalib.c, lnrebin.c) do not know which representation is
42
used (Chebyshev polynomials, or any other), nor how it is stored (which
43
descriptor, meaning of coefficients). This design enables to replace
44
this module lndisp.c by any other based on a different representation.
49
Because the module is based on Numerical Recipes routines, which arrays
50
start at index 1, the general rule is that arrays start at index 1. However
51
the module can accomodate any starting index, which is specified at
52
initialisation time (function initdisp).
57
The module provides ten top-level routines related to the evaluation of the
58
dispersion relation. Only those six routines can be used in applications
59
related to the dispersion relation (wavelength calibration, rebinning, ...).
60
The lower level routines must be considered as private.
62
--- void mos_savedisp (save) ---
64
Stores dispersion coefficients in array <save>.
67
--- double mos_fit_disp (ndata, degree, x, l, chi) ---
69
This routine evaluates the dispersion relation on the basis of ndata
70
couples of d values (x,l). Array indexes start at 0. The degree is
71
indicative. If ndata is too small, a smaller degree will be fitted
72
to the couples. Minimum value for ndata is 2. The procedure returns
73
a rough estimate of the average pixel size and the error of the
76
--- void mos_eval_disp (x, l, ndata) ---
78
Applies the last previously estimated (or loaded) dispersion relation
79
to ndata values of x and estimates the corresponding wavelength l.
80
Arrays start at index 0.
82
--- void mos_initdisp (name, mode, start) ---
84
Open (mode = OLD) or Create (mode = NEW) a storage table (named <name>).
85
In addition to initdisp also the column :SLIT is created.
88
--- void mos_writedisp(line, slit, pix_y, world_y, nyrow) ---
90
Store in the storage table the dispersion relation corresponding to the
91
slitlet <slit>, row number <line>, and world coordinate <y>.
93
--- double mos_readdisp(line) ---
95
Retrieves from the storage table the dispersion relation corresponding
96
to the row number <line>. The procedure returns a rough estimate of
97
the average pixel size.
106
#include <dispersion.h>
110
/* -------------------------------------------------------------------------- */
114
mos_savedisp (double save[])
125
/* printf("Dispersion Relation. Degree: %d. Refdeg: %d. MaxCoef:%d\n",
126
fdeg,refdeg,maxcoef);
127
printf("Coefficients: "); */
129
for (i = 0; i <= ncoef-1; i++)
132
/* printf("save[%d] = %f ",i, save[i]); */
137
/* -------------------------------------------------------------------------- */
141
mos_fit_disp (int *ndata, int *deg, double x[],
142
double l[], double *chi)
145
mos_fit_disp (ndata, deg, x, l, chi)
147
double x[], l[], *chi;
152
double *sig, *chisq, **covar;
154
int actvals, maxdeg, i;
157
/* printf("NData : %d --- Deg value : %d\n",*ndata,*deg); */
166
maxcoef = refdeg + 1;
170
printf ("Not enough lines (minimum is 2). \nNo dispersion relation computed\n");
176
printf ("Degree : %d. No dispersion relation fitted\n", *deg);
182
covar = (double **) dmatrix (1, *ndata, 1, *ndata);
183
chisq = (double *) dvector (0, *ndata);
184
sig = (double *) dvector (1, *ndata);
186
lista = (int *) ivector (1, ncoef);
187
for (i = 1; i <= ncoef; i++)
189
for (i = 1; i <= *ndata; i++)
192
SCKGETC("POLTYP", 1, 8, &actvals, poltyp);
193
if (toupper(poltyp[0]) == 'L')
194
lfit2(x,l,sig,*ndata,coef,ncoef,lista,ncoef,covar,chisq,fleg);
196
lfit2(x,l,sig,*ndata,coef,ncoef,lista,ncoef,covar,chisq,fcheb);
200
free_dmatrix (covar, 1, *ndata, 1, *ndata);
201
free_dvector (chisq, 0, *ndata);
202
free_dvector (sig, 1, *ndata);
203
free_ivector (lista, 1, ncoef);
209
/* -------------------------------------------------------------------------- */
211
void mos_eval_disp (double x[], double l[], int n)
213
void mos_eval_disp (x, l, n)
220
int actvals, i, icoef;
224
SCKGETC("POLTYP", 1, 8, &actvals, poltyp);
225
for (i = start_index; i < (n + start_index); i++)
228
if (toupper(poltyp[0]) == 'L')
229
fleg (x[i], xp, ncoef);
231
fcheb (x[i], xp, ncoef);
232
for (icoef = 1; icoef <= ncoef; icoef++)
233
l[i] += coef[icoef] * xp[icoef];
237
/* -------------------------------------------------------------------------- */
240
void mos_initdisp (char name[], char mode[], int start)
242
void mos_initdisp (name, mode, start)
250
char colnam[30], numb[10];
253
int ncol, nrow, nsort, allcol, allrow;
258
if (toupper (mode[0]) == 'N')
260
if (TCTINI (name, F_TRANS, F_IO_MODE, 5, 10, &tide))
261
SCTPUT ("**** Error while creating output table");
266
if (TCTOPN (name, F_IO_MODE, &tide))
267
SCTPUT ("**** Error while opening output table");
268
SCDRDD (tide, "LNPIX", 1, 1, &actvals, &pixbin, &kunit, &null);
269
SCDRDI (tide, "LNDEG", 1, 1, &actvals, &refdeg, &kunit, &null);
270
SCDRDI (tide, "LNCOE", 1, 1, &actvals, &maxcoef, &kunit, &null);
271
/* fdeg=refdeg, ncoef=maxcoef; */
272
TCIGET (tide, &ncol, &nrow, &nsort, &allcol, &allrow);
276
TCCSER (tide, ":SLIT", &colslit);
278
TCCINI (tide, D_I4_FORMAT, 1, "I6", "Slit Number",
281
TCCSER (tide, ":ROW", &colline);
283
TCCINI (tide, D_I4_FORMAT, 1, "I6", "Row Number",
286
TCCSER (tide, ":Y", &coly);
288
TCCINI (tide, D_R8_FORMAT, 1, "F8.2", "Y Value",
291
TCCSER (tide, ":RMS", &colrms);
293
TCCINI (tide, D_R8_FORMAT, 1, "F8.4", "Angstrom",
296
for (icoef = 1; icoef <= maxcoef; icoef++)
298
strcpy (colnam, ":COEF_");
299
sprintf (numb, "%d", icoef);
300
strcat (colnam, numb);
301
TCCSER (tide, colnam, &colcoef[icoef]);
302
if (colcoef[icoef] == (-1))
303
TCCINI (tide, D_R8_FORMAT, 1, "F16.10", "Coefficients",
304
colnam, &colcoef[icoef]);
308
/*----------------------------------------------------------------------------*/
310
int mos_readdisp (int y, int slit)
312
int mos_readdisp (y, slit)
316
/* long int y; Pixel number of the row */
319
int line, yval, linext, ydif, null, icoef;
324
for (line = 1; line <= nbline; line++)
326
TCERDI (tide, line, colline, &yval, &null);
327
TCERDI (tide, line, colslit, &actslit, &null);
328
if (!null && actslit == slit)
336
mindif = ydif, linext = line;
343
fdeg = refdeg, ncoef = maxcoef;
345
for (icoef = 1; icoef <= ncoef; icoef++)
346
TCERDD (tide, linext, colcoef[icoef], &coef[icoef], &null);
352
/* -------------------------------------------------------------------------- */
355
void mos_writedisp (int line, int slit, int ypix,
356
double y, int numrow, double rms)
358
void mos_writedisp (line, slit, ypix, y, numrow, rms)
359
int line, slit, ypix, numrow;
367
TCEWRI (tide, line, colslit, &slit);
368
TCEWRI (tide, line, colline, &ypix);
369
TCEWRD (tide, line, coly, &y);
370
TCEWRD (tide, line, colrms, &rms);
372
/* if (nbline<line) nbline=line; */
376
for (icoef = 1; icoef <= maxcoef; icoef++)
377
TCEWRD (tide, line, colcoef[icoef], &coef[icoef]);