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 WAVECALIB_TYPES /* This file is unused, the ifdef is used to prevent
21 the file from being parsed by linters and other tools. */
22
23#ifdef HAVE_CONFIG_H
24# include <config.h>
25#endif
26
27#include "gialias.h"
28#include "gimatrix.h"
29
30#include "giwavecalib_types.h"
31
51GiWcalSolution*
52giraffe_wcalsolution_new(void)
53{
54
55 GiWcalSolution* tmp = NULL;
56
57 tmp = (GiWcalSolution*) cx_calloc(1, sizeof(GiWcalSolution));
58
59 tmp->subslitfit = FALSE;
60 tmp->opt_mod = LMRQ_UNDEFINED;
61 tmp->opt_mod_params = NULL;
62 tmp->wav_coeffs = NULL;
63
64 return tmp;
65}
66
78void
79giraffe_wcalsolution_delete(GiWcalSolution *ws)
80{
81
82 if (ws==NULL) { return; }
83
84 if (ws->opt_mod_params!=NULL)
85 cpl_matrix_delete(ws->opt_mod_params);
86 if (ws->wav_coeffs!=NULL)
87 giraffe_slitgeometry_delete(ws->wav_coeffs);
88
89}
90
103void
104giraffe_wcalsolution_dump(GiWcalSolution *ws)
105{
106
107 const cxchar *fctid = "giraffe_wcalsolution_dump";
108
109 cpl_msg_debug(fctid,"---- GiWcalSolution --------------------");
110
111
112 if (ws==NULL) {
113 cpl_msg_debug(fctid, "Empty GiWcalSolution!");
114 } else {
115 cpl_msg_debug(fctid, "Subslit fitted : %s",
116 ws->subslitfit ? "YES" : "NO" );
117
118 if (ws->opt_mod==LMRQ_XOPTMOD) {
119 cpl_msg_debug(fctid, "Opt Model : xoptmod");
120 } else if (ws->opt_mod==LMRQ_XOPTMOD2) {
121 cpl_msg_debug(fctid, "Opt Model : xoptmod2");
122 } else {
123 cpl_msg_debug(fctid, "Opt Model : undefined");
124 }
125
126 cpl_msg_debug(fctid, "Optical Model Parameters :");
127 if (ws->opt_mod_params!=NULL) {
128 giraffe_matrix_dump(ws->opt_mod_params, 15);
129 } else {
130 cpl_msg_debug(fctid, "NONE!");
131 }
132
133
134 cpl_msg_debug(fctid, "Slit Geometry :");
135 if (ws->wav_coeffs!=NULL) {
136 cxint i;
137 for (i=0; i<giraffe_slitgeometry_size(ws->wav_coeffs); i++) {
138 cpl_msg_debug(fctid, "Subslit [%d] : ", i);
139
141 100);
142 }
143 }
144 else {
145 cpl_msg_debug(fctid, "NONE!!");
146 }
147 }
148}
149
166GiWcalSolution*
167giraffe_wcalsolution_create(GiTable *wavesolution)
168{
169
170 GiWcalSolution *wavcoeff = NULL;
171
172 cpl_plist *_properties = NULL;
173 cpl_table *_table = NULL;
174
175 cxint poly_x_deg = 0,
176 poly_y_deg = 0,
177 ncoefficients = 0,
178 subslitfit = 0,
179 i;
180
181 cpl_matrix *coefficients = NULL;
182 cxdouble *pd_coefficients = NULL;
183
184 cxchar buffer[68];
185
186 if (wavesolution==NULL) { return NULL; }
187
188 wavcoeff = (GiWcalSolution*) cx_calloc(1, sizeof(GiWcalSolution));
189
190 _properties = giraffe_table_get_properties(wavesolution);
191 _table = giraffe_table_get(wavesolution);
192
193 /*
194 * Retrieve values from FITS keywords
195 */
196
197 /* subslit fit */
198
199 if (cpl_plist_contains(_properties, GIALIAS_WSOL_SUBSLITS)) {
200 if (cpl_plist_get_bool(_properties, GIALIAS_WSOL_SUBSLITS) == FALSE)
201 wavcoeff->subslitfit = FALSE;
202 else
203 wavcoeff->subslitfit = TRUE;
204 } else {
205 cx_free(wavcoeff);
206 return NULL;
207 }
208
209 /* optical model */
210
211 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMNAME)) {
212 const cxchar *optmod;
213 optmod = cpl_plist_get_string(_properties, GIALIAS_WSOL_OMNAME);
214
215 if (strcmp(optmod, "xoptmod2")==0)
216 wavcoeff->opt_mod = LMRQ_XOPTMOD2;
217 else if (strcmp(optmod, "xoptmod")==0)
218 wavcoeff->opt_mod = LMRQ_XOPTMOD;
219 else
220 wavcoeff->opt_mod = LMRQ_UNDEFINED;
221 }
222
223 if (wavcoeff->opt_mod==LMRQ_XOPTMOD2) {
224
225 wavcoeff->opt_mod_params = cpl_matrix_new(7,1);
226
227 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMDIR)) {
228 cpl_matrix_set(
229 wavcoeff->opt_mod_params,
230 0,
231 0,
232 cpl_plist_get_int(_properties, GIALIAS_WSOL_OMDIR)
233 );
234 } else {
235 cx_free(wavcoeff);
236 return NULL;
237 }
238
239 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMFCOLL)) {
240 cpl_matrix_set(
241 wavcoeff->opt_mod_params,
242 1,
243 0,
244 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMFCOLL)
245 );
246 } else {
247 cx_free(wavcoeff);
248 return NULL;
249 }
250
251 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMGCAM)) {
252 cpl_matrix_set(
253 wavcoeff->opt_mod_params,
254 2,
255 0,
256 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMGCAM)
257 );
258 } else {
259 cx_free(wavcoeff);
260 return NULL;
261 }
262
263 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMGTHETA)) {
264 cpl_matrix_set(
265 wavcoeff->opt_mod_params,
266 3,
267 0,
268 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMGTHETA)
269 );
270 } else {
271 cx_free(wavcoeff);
272 return NULL;
273 }
274
275 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMSDX)) {
276 cpl_matrix_set(
277 wavcoeff->opt_mod_params,
278 4,
279 0,
280 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMSDX)
281 );
282 } else {
283 cx_free(wavcoeff);
284 return NULL;
285 }
286
287 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMSDY)) {
288
289
290
291 cpl_matrix_set(
292 wavcoeff->opt_mod_params,
293 5,
294 0,
295 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMSDY)
296 );
297
298 } else {
299 cx_free(wavcoeff);
300 return NULL;
301 }
302
303 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMSPHI)) {
304 cpl_matrix_set(
305 wavcoeff->opt_mod_params,
306 6,
307 0,
308 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMSPHI)
309 );
310
311 } else {
312 cx_free(wavcoeff);
313 return NULL;
314 }
315
316 } else if (wavcoeff->opt_mod==LMRQ_XOPTMOD) {
317
318 wavcoeff->opt_mod_params = cpl_matrix_new(4,1);
319
320 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMDIR)) {
321 cpl_matrix_set(
322 wavcoeff->opt_mod_params,
323 0,
324 0,
325 cpl_plist_get_int(_properties, GIALIAS_WSOL_OMDIR)
326 );
327 } else {
328 cx_free(wavcoeff);
329 return NULL;
330 }
331
332 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMFCOLL)) {
333 cpl_matrix_set(
334 wavcoeff->opt_mod_params,
335 1,
336 0,
337 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMFCOLL)
338 );
339 } else {
340 cx_free(wavcoeff);
341 return NULL;
342 }
343
344 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMGCAM)) {
345 cpl_matrix_set(
346 wavcoeff->opt_mod_params,
347 2,
348 0,
349 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMGCAM)
350 );
351 } else {
352 cx_free(wavcoeff);
353 return NULL;
354 }
355
356 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMGTHETA)) {
357 cpl_matrix_set(
358 wavcoeff->opt_mod_params,
359 3,
360 0,
361 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMGTHETA)
362 );
363 } else {
364 cx_free(wavcoeff);
365 return NULL;
366 }
367
368
369 } else {
370
371 cx_free(wavcoeff);
372 return NULL;
373
374 }
375
376 wavcoeff->wav_coeffs = giraffe_slitgeometry_new();
377 giraffe_slitgeometry_resize(wavcoeff->wav_coeffs, 1);
378
379 if (cpl_plist_contains(_properties, GIALIAS_XRES_PDEG)) {
380
381 cxchar *l, *r, *tmpstr;
382
383 tmpstr = (cxchar*) cpl_plist_get_string(_properties, GIALIAS_XRES_PDEG);
384
385 l = &(tmpstr[0]);
386 r = &(tmpstr[2]);
387
388 poly_x_deg = atoi(l) + 1;
389 poly_y_deg = atoi(r) + 1;
390
391 } else {
392 giraffe_slitgeometry_delete(wavcoeff->wav_coeffs);
393 cx_free(wavcoeff);
394 return NULL;
395 }
396
397 ncoefficients = poly_x_deg * poly_y_deg;
398
399 coefficients = cpl_matrix_new(poly_x_deg,poly_y_deg);
400 pd_coefficients = cpl_matrix_get_data(coefficients);
401
402 subslitfit = cpl_table_get_int(_table, "SSN", 0, NULL);
403
404 for (i=0; i<ncoefficients; i++) {
405
406 snprintf(buffer, sizeof(buffer), "XC%-d", i);
407
408 pd_coefficients[i] =
409 cpl_table_get_double(_table, buffer, 0, NULL);
410
411 }
412
413 giraffe_slitgeometry_set(wavcoeff->wav_coeffs, 0, coefficients);
414
415 return wavcoeff;
416
417}
418
419#endif
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

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