GIRAFFE Pipeline Reference Manual

giwavecalib_types.c
1/*
2 * This file is part of the GIRAFFE Pipeline
3 * Copyright (C) 2002-2019 European Southern Observatory
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#ifdef HAVE_CONFIG_H
21# include <config.h>
22#endif
23
24#include "gialias.h"
25#include "gimatrix.h"
26
27#include "giwavecalib_types.h"
28
48GiWcalSolution*
50{
51
52 GiWcalSolution* tmp = NULL;
53
54 tmp = (GiWcalSolution*) cx_calloc(1, sizeof(GiWcalSolution));
55
56 tmp->subslitfit = FALSE;
57 tmp->opt_mod = LMRQ_UNDEFINED;
58 tmp->opt_mod_params = NULL;
59 tmp->wav_coeffs = NULL;
60
61 return tmp;
62}
63
75void
76giraffe_wcalsolution_delete(GiWcalSolution *ws)
77{
78
79 if (ws==NULL) { return; }
80
81 if (ws->opt_mod_params!=NULL)
82 cpl_matrix_delete(ws->opt_mod_params);
83 if (ws->wav_coeffs!=NULL)
84 giraffe_slitgeometry_delete(ws->wav_coeffs);
85
86}
87
100void
101giraffe_wcalsolution_dump(GiWcalSolution *ws)
102{
103
104 const cxchar *fctid = "giraffe_wcalsolution_dump";
105
106 cpl_msg_debug(fctid,"---- GiWcalSolution --------------------");
107
108
109 if (ws==NULL) {
110 cpl_msg_debug(fctid, "Empty GiWcalSolution!");
111 } else {
112 cpl_msg_debug(fctid, "Subslit fitted : %s",
113 ws->subslitfit ? "YES" : "NO" );
114
115 if (ws->opt_mod==LMRQ_XOPTMOD) {
116 cpl_msg_debug(fctid, "Opt Model : xoptmod");
117 } else if (ws->opt_mod==LMRQ_XOPTMOD2) {
118 cpl_msg_debug(fctid, "Opt Model : xoptmod2");
119 } else {
120 cpl_msg_debug(fctid, "Opt Model : undefined");
121 }
122
123 cpl_msg_debug(fctid, "Optical Model Parameters :");
124 if (ws->opt_mod_params!=NULL) {
125 giraffe_matrix_dump(ws->opt_mod_params, 15);
126 } else {
127 cpl_msg_debug(fctid, "NONE!");
128 }
129
130
131 cpl_msg_debug(fctid, "Slit Geometry :");
132 if (ws->wav_coeffs!=NULL) {
133 cxint i;
134 for (i=0; i<giraffe_slitgeometry_size(ws->wav_coeffs); i++) {
135 cpl_msg_debug(fctid, "Subslit [%d] : ", i);
136
138 100);
139 }
140 }
141 else {
142 cpl_msg_debug(fctid, "NONE!!");
143 }
144 }
145}
146
163GiWcalSolution*
164giraffe_wcalsolution_create(GiTable *wavesolution)
165{
166
167 GiWcalSolution *wavcoeff = NULL;
168
169 cpl_plist *_properties = NULL;
170 cpl_table *_table = NULL;
171
172 cxint poly_x_deg = 0,
173 poly_y_deg = 0,
174 ncoefficients = 0,
175 subslitfit = 0,
176 i;
177
178 cpl_matrix *coefficients = NULL;
179 cxdouble *pd_coefficients = NULL;
180
181 cxchar buffer[68];
182
183 if (wavesolution==NULL) { return NULL; }
184
185 wavcoeff = (GiWcalSolution*) cx_calloc(1, sizeof(GiWcalSolution));
186
187 _properties = giraffe_table_get_properties(wavesolution);
188 _table = giraffe_table_get(wavesolution);
189
190 /*
191 * Retrieve values from FITS keywords
192 */
193
194 /* subslit fit */
195
196 if (cpl_plist_contains(_properties, GIALIAS_WSOL_SUBSLITS)) {
197 if (cpl_plist_get_bool(_properties, GIALIAS_WSOL_SUBSLITS) == FALSE)
198 wavcoeff->subslitfit = FALSE;
199 else
200 wavcoeff->subslitfit = TRUE;
201 } else {
202 cx_free(wavcoeff);
203 return NULL;
204 }
205
206 /* optical model */
207
208 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMNAME)) {
209 const cxchar *optmod;
210 optmod = cpl_plist_get_string(_properties, GIALIAS_WSOL_OMNAME);
211
212 if (strcmp(optmod, "xoptmod2")==0)
213 wavcoeff->opt_mod = LMRQ_XOPTMOD2;
214 else if (strcmp(optmod, "xoptmod")==0)
215 wavcoeff->opt_mod = LMRQ_XOPTMOD;
216 else
217 wavcoeff->opt_mod = LMRQ_UNDEFINED;
218 }
219
220 if (wavcoeff->opt_mod==LMRQ_XOPTMOD2) {
221
222 wavcoeff->opt_mod_params = cpl_matrix_new(7,1);
223
224 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMDIR)) {
225 cpl_matrix_set(
226 wavcoeff->opt_mod_params,
227 0,
228 0,
229 cpl_plist_get_int(_properties, GIALIAS_WSOL_OMDIR)
230 );
231 } else {
232 cx_free(wavcoeff);
233 return NULL;
234 }
235
236 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMFCOLL)) {
237 cpl_matrix_set(
238 wavcoeff->opt_mod_params,
239 1,
240 0,
241 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMFCOLL)
242 );
243 } else {
244 cx_free(wavcoeff);
245 return NULL;
246 }
247
248 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMGCAM)) {
249 cpl_matrix_set(
250 wavcoeff->opt_mod_params,
251 2,
252 0,
253 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMGCAM)
254 );
255 } else {
256 cx_free(wavcoeff);
257 return NULL;
258 }
259
260 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMGTHETA)) {
261 cpl_matrix_set(
262 wavcoeff->opt_mod_params,
263 3,
264 0,
265 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMGTHETA)
266 );
267 } else {
268 cx_free(wavcoeff);
269 return NULL;
270 }
271
272 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMSDX)) {
273 cpl_matrix_set(
274 wavcoeff->opt_mod_params,
275 4,
276 0,
277 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMSDX)
278 );
279 } else {
280 cx_free(wavcoeff);
281 return NULL;
282 }
283
284 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMSDY)) {
285
286
287
288 cpl_matrix_set(
289 wavcoeff->opt_mod_params,
290 5,
291 0,
292 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMSDY)
293 );
294
295 } else {
296 cx_free(wavcoeff);
297 return NULL;
298 }
299
300 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMSPHI)) {
301 cpl_matrix_set(
302 wavcoeff->opt_mod_params,
303 6,
304 0,
305 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMSPHI)
306 );
307
308 } else {
309 cx_free(wavcoeff);
310 return NULL;
311 }
312
313 } else if (wavcoeff->opt_mod==LMRQ_XOPTMOD) {
314
315 wavcoeff->opt_mod_params = cpl_matrix_new(4,1);
316
317 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMDIR)) {
318 cpl_matrix_set(
319 wavcoeff->opt_mod_params,
320 0,
321 0,
322 cpl_plist_get_int(_properties, GIALIAS_WSOL_OMDIR)
323 );
324 } else {
325 cx_free(wavcoeff);
326 return NULL;
327 }
328
329 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMFCOLL)) {
330 cpl_matrix_set(
331 wavcoeff->opt_mod_params,
332 1,
333 0,
334 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMFCOLL)
335 );
336 } else {
337 cx_free(wavcoeff);
338 return NULL;
339 }
340
341 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMGCAM)) {
342 cpl_matrix_set(
343 wavcoeff->opt_mod_params,
344 2,
345 0,
346 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMGCAM)
347 );
348 } else {
349 cx_free(wavcoeff);
350 return NULL;
351 }
352
353 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMGTHETA)) {
354 cpl_matrix_set(
355 wavcoeff->opt_mod_params,
356 3,
357 0,
358 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMGTHETA)
359 );
360 } else {
361 cx_free(wavcoeff);
362 return NULL;
363 }
364
365
366 } else {
367
368 cx_free(wavcoeff);
369 return NULL;
370
371 }
372
373 wavcoeff->wav_coeffs = giraffe_slitgeometry_new();
374 giraffe_slitgeometry_resize(wavcoeff->wav_coeffs, 1);
375
376 if (cpl_plist_contains(_properties, GIALIAS_XRES_PDEG)) {
377
378 cxchar *l, *r, *tmpstr;
379
380 tmpstr = (cxchar*) cpl_plist_get_string(_properties, GIALIAS_XRES_PDEG);
381
382 l = &(tmpstr[0]);
383 r = &(tmpstr[2]);
384
385 poly_x_deg = atoi(l) + 1;
386 poly_y_deg = atoi(r) + 1;
387
388 } else {
389 giraffe_slitgeometry_delete(wavcoeff->wav_coeffs);
390 cx_free(wavcoeff);
391 return NULL;
392 }
393
394 ncoefficients = poly_x_deg * poly_y_deg;
395
396 coefficients = cpl_matrix_new(poly_x_deg,poly_y_deg);
397 pd_coefficients = cpl_matrix_get_data(coefficients);
398
399 subslitfit = cpl_table_get_int(_table, "SSN", 0, NULL);
400
401 for (i=0; i<ncoefficients; i++) {
402
403 snprintf(buffer, sizeof(buffer), "XC%-d", i);
404
405 pd_coefficients[i] =
406 cpl_table_get_double(_table, buffer, 0, NULL);
407
408 }
409
410 giraffe_slitgeometry_set(wavcoeff->wav_coeffs, 0, coefficients);
411
412 return wavcoeff;
413
414}
void giraffe_matrix_dump(const cpl_matrix *matrix, cxint max_rows)
Output a maximum number of rows of the input matrix.
Definition: gimatrix.c:836
GiSlitGeometry * giraffe_slitgeometry_new(void)
Create a new GiSlitGeometry.
void giraffe_slitgeometry_resize(GiSlitGeometry *self, cxint size)
Destructive resize of a GiSlitGeometry.
cxint giraffe_slitgeometry_size(GiSlitGeometry *self)
Returns current size of a GiSlitGeometry.
cpl_matrix * giraffe_slitgeometry_get(GiSlitGeometry *self, cxint pos)
Gets a reference to the matrix at a specified position.
void giraffe_slitgeometry_set(GiSlitGeometry *self, cxint pos, cpl_matrix *nm)
Sets (copies) a cpl_matrix to a specified position of the GiSlitGeometry.
void giraffe_slitgeometry_delete(GiSlitGeometry *self)
Destroy an GiSlitGeometry.
cpl_table * giraffe_table_get(const GiTable *self)
Get the table data from a Giraffe table.
Definition: gitable.c:433
cpl_propertylist * giraffe_table_get_properties(const GiTable *self)
Gets the table properties.
Definition: gitable.c:489
GiWcalSolution * giraffe_wcalsolution_new(void)
Create a new GiWcalSolution.
void giraffe_wcalsolution_delete(GiWcalSolution *ws)
Destroy an GiWcalSolution.
void giraffe_wcalsolution_dump(GiWcalSolution *ws)
Dump the the information contained in a GiWcalSolution to output.
GiWcalSolution * giraffe_wcalsolution_create(GiTable *wavesolution)
Create a wavecalibration results structure based on a GiTable read from disk.

This file is part of the GIRAFFE Pipeline Reference Manual 2.16.12.
Documentation copyright © 2002-2006 European Southern Observatory.
Generated on Mon Dec 2 2024 11:59:44 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2004