35 #include "giwavecalib_types.h"
60 GiWcalSolution* tmp = NULL;
62 tmp = (GiWcalSolution*) cx_calloc(1,
sizeof(GiWcalSolution));
64 tmp->subslitfit = FALSE;
65 tmp->opt_mod = LMRQ_UNDEFINED;
66 tmp->opt_mod_params = NULL;
67 tmp->wav_coeffs = NULL;
87 if (ws==NULL) {
return; }
89 if (ws->opt_mod_params!=NULL)
90 cpl_matrix_delete(ws->opt_mod_params);
91 if (ws->wav_coeffs!=NULL)
112 const cxchar *fctid =
"giraffe_wcalsolution_dump";
114 cpl_msg_debug(fctid,
"---- GiWcalSolution --------------------");
118 cpl_msg_debug(fctid,
"Empty GiWcalSolution!");
120 cpl_msg_debug(fctid,
"Subslit fitted : %s",
121 ws->subslitfit ?
"YES" :
"NO" );
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");
128 cpl_msg_debug(fctid,
"Opt Model : undefined");
131 cpl_msg_debug(fctid,
"Optical Model Parameters :");
132 if (ws->opt_mod_params!=NULL) {
135 cpl_msg_debug(fctid,
"NONE!");
139 cpl_msg_debug(fctid,
"Slit Geometry :");
140 if (ws->wav_coeffs!=NULL) {
143 cpl_msg_debug(fctid,
"Subslit [%d] : ", i);
150 cpl_msg_debug(fctid,
"NONE!!");
175 GiWcalSolution *wavcoeff = NULL;
177 cpl_plist *_properties = NULL;
178 cpl_table *_table = NULL;
180 cxint poly_x_deg = 0,
186 cpl_matrix *coefficients = NULL;
187 cxdouble *pd_coefficients = NULL;
191 if (wavesolution==NULL) {
return NULL; }
193 wavcoeff = (GiWcalSolution*) cx_calloc(1,
sizeof(GiWcalSolution));
204 if (cpl_plist_contains(_properties, GIALIAS_WSOL_SUBSLITS)) {
205 if (cpl_plist_get_bool(_properties, GIALIAS_WSOL_SUBSLITS) == FALSE)
206 wavcoeff->subslitfit = FALSE;
208 wavcoeff->subslitfit = TRUE;
216 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMNAME)) {
217 const cxchar *optmod;
218 optmod = cpl_plist_get_string(_properties, GIALIAS_WSOL_OMNAME);
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;
225 wavcoeff->opt_mod = LMRQ_UNDEFINED;
228 if (wavcoeff->opt_mod==LMRQ_XOPTMOD2) {
230 wavcoeff->opt_mod_params = cpl_matrix_new(7,1);
232 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMDIR)) {
234 wavcoeff->opt_mod_params,
237 cpl_plist_get_int(_properties, GIALIAS_WSOL_OMDIR)
244 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMFCOLL)) {
246 wavcoeff->opt_mod_params,
249 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMFCOLL)
256 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMGCAM)) {
258 wavcoeff->opt_mod_params,
261 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMGCAM)
268 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMGTHETA)) {
270 wavcoeff->opt_mod_params,
273 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMGTHETA)
280 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMSDX)) {
282 wavcoeff->opt_mod_params,
285 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMSDX)
292 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMSDY)) {
297 wavcoeff->opt_mod_params,
300 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMSDY)
308 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMSPHI)) {
310 wavcoeff->opt_mod_params,
313 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMSPHI)
321 }
else if (wavcoeff->opt_mod==LMRQ_XOPTMOD) {
323 wavcoeff->opt_mod_params = cpl_matrix_new(4,1);
325 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMDIR)) {
327 wavcoeff->opt_mod_params,
330 cpl_plist_get_int(_properties, GIALIAS_WSOL_OMDIR)
337 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMFCOLL)) {
339 wavcoeff->opt_mod_params,
342 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMFCOLL)
349 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMGCAM)) {
351 wavcoeff->opt_mod_params,
354 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMGCAM)
361 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMGTHETA)) {
363 wavcoeff->opt_mod_params,
366 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMGTHETA)
384 if (cpl_plist_contains(_properties, GIALIAS_XRES_PDEG)) {
386 cxchar *l, *r, *tmpstr;
388 tmpstr = (cxchar*) cpl_plist_get_string(_properties, GIALIAS_XRES_PDEG);
393 poly_x_deg = atoi(l) + 1;
394 poly_y_deg = atoi(r) + 1;
402 ncoefficients = poly_x_deg * poly_y_deg;
404 coefficients = cpl_matrix_new(poly_x_deg,poly_y_deg);
405 pd_coefficients = cpl_matrix_get_data(coefficients);
407 subslitfit = cpl_table_get_int(_table,
"SSN", 0, NULL);
409 for (i=0; i<ncoefficients; i++) {
411 snprintf(buffer,
sizeof(buffer),
"XC%-d", i);
414 cpl_table_get_double(_table, buffer, 0, NULL);
GiSlitGeometry * giraffe_slitgeometry_new(void)
Create a new GiSlitGeometry.
cxint giraffe_slitgeometry_size(GiSlitGeometry *self)
Returns current size of a GiSlitGeometry.
void giraffe_slitgeometry_resize(GiSlitGeometry *self, cxint size)
Destructive resize of a GiSlitGeometry.
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.
cpl_table * giraffe_table_get(const GiTable *self)
Get the table data from a Giraffe table.
GiWcalSolution * giraffe_wcalsolution_new(void)
Create a new GiWcalSolution.
void giraffe_slitgeometry_delete(GiSlitGeometry *self)
Destroy an GiSlitGeometry.
cpl_matrix * giraffe_slitgeometry_get(GiSlitGeometry *self, cxint pos)
Gets a reference to the matrix at a specified position.
void giraffe_matrix_dump(const cpl_matrix *matrix, cxint max_rows)
Output a maximum number of rows of the input matrix.
void giraffe_wcalsolution_delete(GiWcalSolution *ws)
Destroy an GiWcalSolution.
cpl_propertylist * giraffe_table_get_properties(const GiTable *self)
Gets the table properties.
void giraffe_slitgeometry_set(GiSlitGeometry *self, cxint pos, cpl_matrix *nm)
Sets (copies) a cpl_matrix to a specified position of the GiSlitGeometry.