30#include "giwavecalib_types.h"
52giraffe_wcalsolution_new(
void)
55 GiWcalSolution* tmp = NULL;
57 tmp = (GiWcalSolution*) cx_calloc(1,
sizeof(GiWcalSolution));
59 tmp->subslitfit = FALSE;
60 tmp->opt_mod = LMRQ_UNDEFINED;
61 tmp->opt_mod_params = NULL;
62 tmp->wav_coeffs = NULL;
79giraffe_wcalsolution_delete(GiWcalSolution *ws)
82 if (ws==NULL) {
return; }
84 if (ws->opt_mod_params!=NULL)
85 cpl_matrix_delete(ws->opt_mod_params);
86 if (ws->wav_coeffs!=NULL)
104giraffe_wcalsolution_dump(GiWcalSolution *ws)
107 const cxchar *fctid =
"giraffe_wcalsolution_dump";
109 cpl_msg_debug(fctid,
"---- GiWcalSolution --------------------");
113 cpl_msg_debug(fctid,
"Empty GiWcalSolution!");
115 cpl_msg_debug(fctid,
"Subslit fitted : %s",
116 ws->subslitfit ?
"YES" :
"NO" );
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");
123 cpl_msg_debug(fctid,
"Opt Model : undefined");
126 cpl_msg_debug(fctid,
"Optical Model Parameters :");
127 if (ws->opt_mod_params!=NULL) {
130 cpl_msg_debug(fctid,
"NONE!");
134 cpl_msg_debug(fctid,
"Slit Geometry :");
135 if (ws->wav_coeffs!=NULL) {
138 cpl_msg_debug(fctid,
"Subslit [%d] : ", i);
145 cpl_msg_debug(fctid,
"NONE!!");
167giraffe_wcalsolution_create(GiTable *wavesolution)
170 GiWcalSolution *wavcoeff = NULL;
172 cpl_plist *_properties = NULL;
173 cpl_table *_table = NULL;
175 cxint poly_x_deg = 0,
181 cpl_matrix *coefficients = NULL;
182 cxdouble *pd_coefficients = NULL;
186 if (wavesolution==NULL) {
return NULL; }
188 wavcoeff = (GiWcalSolution*) cx_calloc(1,
sizeof(GiWcalSolution));
199 if (cpl_plist_contains(_properties, GIALIAS_WSOL_SUBSLITS)) {
200 if (cpl_plist_get_bool(_properties, GIALIAS_WSOL_SUBSLITS) == FALSE)
201 wavcoeff->subslitfit = FALSE;
203 wavcoeff->subslitfit = TRUE;
211 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMNAME)) {
212 const cxchar *optmod;
213 optmod = cpl_plist_get_string(_properties, GIALIAS_WSOL_OMNAME);
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;
220 wavcoeff->opt_mod = LMRQ_UNDEFINED;
223 if (wavcoeff->opt_mod==LMRQ_XOPTMOD2) {
225 wavcoeff->opt_mod_params = cpl_matrix_new(7,1);
227 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMDIR)) {
229 wavcoeff->opt_mod_params,
232 cpl_plist_get_int(_properties, GIALIAS_WSOL_OMDIR)
239 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMFCOLL)) {
241 wavcoeff->opt_mod_params,
244 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMFCOLL)
251 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMGCAM)) {
253 wavcoeff->opt_mod_params,
256 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMGCAM)
263 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMGTHETA)) {
265 wavcoeff->opt_mod_params,
268 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMGTHETA)
275 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMSDX)) {
277 wavcoeff->opt_mod_params,
280 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMSDX)
287 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMSDY)) {
292 wavcoeff->opt_mod_params,
295 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMSDY)
303 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMSPHI)) {
305 wavcoeff->opt_mod_params,
308 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMSPHI)
316 }
else if (wavcoeff->opt_mod==LMRQ_XOPTMOD) {
318 wavcoeff->opt_mod_params = cpl_matrix_new(4,1);
320 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMDIR)) {
322 wavcoeff->opt_mod_params,
325 cpl_plist_get_int(_properties, GIALIAS_WSOL_OMDIR)
332 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMFCOLL)) {
334 wavcoeff->opt_mod_params,
337 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMFCOLL)
344 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMGCAM)) {
346 wavcoeff->opt_mod_params,
349 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMGCAM)
356 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMGTHETA)) {
358 wavcoeff->opt_mod_params,
361 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMGTHETA)
379 if (cpl_plist_contains(_properties, GIALIAS_XRES_PDEG)) {
381 cxchar *l, *r, *tmpstr;
383 tmpstr = (cxchar*) cpl_plist_get_string(_properties, GIALIAS_XRES_PDEG);
388 poly_x_deg = atoi(l) + 1;
389 poly_y_deg = atoi(r) + 1;
397 ncoefficients = poly_x_deg * poly_y_deg;
399 coefficients = cpl_matrix_new(poly_x_deg,poly_y_deg);
400 pd_coefficients = cpl_matrix_get_data(coefficients);
402 subslitfit = cpl_table_get_int(_table,
"SSN", 0, NULL);
404 for (i=0; i<ncoefficients; i++) {
406 snprintf(buffer,
sizeof(buffer),
"XC%-d", i);
409 cpl_table_get_double(_table, buffer, 0, NULL);
void giraffe_matrix_dump(const cpl_matrix *matrix, cxint max_rows)
Output a maximum number of rows of the input matrix.
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.
cpl_propertylist * giraffe_table_get_properties(const GiTable *self)
Gets the table properties.