GIRAFFE Pipeline Reference Manual

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

This file is part of the GIRAFFE Pipeline Reference Manual 2.12.
Documentation copyright © 2002-2006 European Southern Observatory.
Generated on Mon Mar 24 2014 11:43:53 by doxygen 1.8.2 written by Dimitri van Heesch, © 1997-2004