00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifdef HAVE_CONFIG_H
00029 # include <config.h>
00030 #endif
00031
00032 #include "gialias.h"
00033 #include "gimatrix.h"
00034
00035 #include "giwavecalib_types.h"
00036
00056 GiWcalSolution*
00057 giraffe_wcalsolution_new(void)
00058 {
00059
00060 GiWcalSolution* tmp = NULL;
00061
00062 tmp = (GiWcalSolution*) cx_calloc(1, sizeof(GiWcalSolution));
00063
00064 tmp->subslitfit = FALSE;
00065 tmp->opt_mod = LMRQ_UNDEFINED;
00066 tmp->opt_mod_params = NULL;
00067 tmp->wav_coeffs = NULL;
00068
00069 return tmp;
00070 }
00071
00083 void
00084 giraffe_wcalsolution_delete(GiWcalSolution *ws)
00085 {
00086
00087 if (ws==NULL) { return; }
00088
00089 if (ws->opt_mod_params!=NULL)
00090 cpl_matrix_delete(ws->opt_mod_params);
00091 if (ws->wav_coeffs!=NULL)
00092 giraffe_slitgeometry_delete(ws->wav_coeffs);
00093
00094 }
00095
00108 void
00109 giraffe_wcalsolution_dump(GiWcalSolution *ws)
00110 {
00111
00112 const cxchar *fctid = "giraffe_wcalsolution_dump";
00113
00114 cpl_msg_debug(fctid,"---- GiWcalSolution --------------------");
00115
00116
00117 if (ws==NULL) {
00118 cpl_msg_debug(fctid, "Empty GiWcalSolution!");
00119 } else {
00120 cpl_msg_debug(fctid, "Subslit fitted : %s",
00121 ws->subslitfit ? "YES" : "NO" );
00122
00123 if (ws->opt_mod==LMRQ_XOPTMOD) {
00124 cpl_msg_debug(fctid, "Opt Model : xoptmod");
00125 } else if (ws->opt_mod==LMRQ_XOPTMOD2) {
00126 cpl_msg_debug(fctid, "Opt Model : xoptmod2");
00127 } else {
00128 cpl_msg_debug(fctid, "Opt Model : undefined");
00129 }
00130
00131 cpl_msg_debug(fctid, "Optical Model Parameters :");
00132 if (ws->opt_mod_params!=NULL) {
00133 giraffe_matrix_dump(ws->opt_mod_params, 15);
00134 } else {
00135 cpl_msg_debug(fctid, "NONE!");
00136 }
00137
00138
00139 cpl_msg_debug(fctid, "Slit Geometry :");
00140 if (ws->wav_coeffs!=NULL) {
00141 cxint i;
00142 for (i=0; i<giraffe_slitgeometry_size(ws->wav_coeffs); i++) {
00143 cpl_msg_debug(fctid, "Subslit [%d] : ", i);
00144
00145 giraffe_matrix_dump(giraffe_slitgeometry_get(ws->wav_coeffs, i),
00146 100);
00147 }
00148 }
00149 else {
00150 cpl_msg_debug(fctid, "NONE!!");
00151 }
00152 }
00153 }
00154
00171 GiWcalSolution*
00172 giraffe_wcalsolution_create(GiTable *wavesolution)
00173 {
00174
00175 GiWcalSolution *wavcoeff = NULL;
00176
00177 cpl_plist *_properties = NULL;
00178 cpl_table *_table = NULL;
00179
00180 cxint poly_x_deg = 0,
00181 poly_y_deg = 0,
00182 ncoefficients = 0,
00183 subslitfit = 0,
00184 i;
00185
00186 cpl_matrix *coefficients = NULL;
00187 cxdouble *pd_coefficients = NULL;
00188
00189 cxchar buffer[68];
00190
00191 if (wavesolution==NULL) { return NULL; }
00192
00193 wavcoeff = (GiWcalSolution*) cx_calloc(1, sizeof(GiWcalSolution));
00194
00195 _properties = giraffe_table_get_properties(wavesolution);
00196 _table = giraffe_table_get(wavesolution);
00197
00198
00199
00200
00201
00202
00203
00204 if (cpl_plist_contains(_properties, GIALIAS_WSOL_SUBSLITS)) {
00205 if (cpl_plist_get_bool(_properties, GIALIAS_WSOL_SUBSLITS) == FALSE)
00206 wavcoeff->subslitfit = FALSE;
00207 else
00208 wavcoeff->subslitfit = TRUE;
00209 } else {
00210 cx_free(wavcoeff);
00211 return NULL;
00212 }
00213
00214
00215
00216 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMNAME)) {
00217 const cxchar *optmod;
00218 optmod = cpl_plist_get_string(_properties, GIALIAS_WSOL_OMNAME);
00219
00220 if (strcmp(optmod, "xoptmod2")==0)
00221 wavcoeff->opt_mod = LMRQ_XOPTMOD2;
00222 else if (strcmp(optmod, "xoptmod")==0)
00223 wavcoeff->opt_mod = LMRQ_XOPTMOD;
00224 else
00225 wavcoeff->opt_mod = LMRQ_UNDEFINED;
00226 }
00227
00228 if (wavcoeff->opt_mod==LMRQ_XOPTMOD2) {
00229
00230 wavcoeff->opt_mod_params = cpl_matrix_new(7,1);
00231
00232 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMDIR)) {
00233 cpl_matrix_set(
00234 wavcoeff->opt_mod_params,
00235 0,
00236 0,
00237 cpl_plist_get_int(_properties, GIALIAS_WSOL_OMDIR)
00238 );
00239 } else {
00240 cx_free(wavcoeff);
00241 return NULL;
00242 }
00243
00244 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMFCOLL)) {
00245 cpl_matrix_set(
00246 wavcoeff->opt_mod_params,
00247 1,
00248 0,
00249 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMFCOLL)
00250 );
00251 } else {
00252 cx_free(wavcoeff);
00253 return NULL;
00254 }
00255
00256 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMGCAM)) {
00257 cpl_matrix_set(
00258 wavcoeff->opt_mod_params,
00259 2,
00260 0,
00261 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMGCAM)
00262 );
00263 } else {
00264 cx_free(wavcoeff);
00265 return NULL;
00266 }
00267
00268 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMGTHETA)) {
00269 cpl_matrix_set(
00270 wavcoeff->opt_mod_params,
00271 3,
00272 0,
00273 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMGTHETA)
00274 );
00275 } else {
00276 cx_free(wavcoeff);
00277 return NULL;
00278 }
00279
00280 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMSDX)) {
00281 cpl_matrix_set(
00282 wavcoeff->opt_mod_params,
00283 4,
00284 0,
00285 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMSDX)
00286 );
00287 } else {
00288 cx_free(wavcoeff);
00289 return NULL;
00290 }
00291
00292 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMSDY)) {
00293
00294
00295
00296 cpl_matrix_set(
00297 wavcoeff->opt_mod_params,
00298 5,
00299 0,
00300 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMSDY)
00301 );
00302
00303 } else {
00304 cx_free(wavcoeff);
00305 return NULL;
00306 }
00307
00308 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMSPHI)) {
00309 cpl_matrix_set(
00310 wavcoeff->opt_mod_params,
00311 6,
00312 0,
00313 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMSPHI)
00314 );
00315
00316 } else {
00317 cx_free(wavcoeff);
00318 return NULL;
00319 }
00320
00321 } else if (wavcoeff->opt_mod==LMRQ_XOPTMOD) {
00322
00323 wavcoeff->opt_mod_params = cpl_matrix_new(4,1);
00324
00325 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMDIR)) {
00326 cpl_matrix_set(
00327 wavcoeff->opt_mod_params,
00328 0,
00329 0,
00330 cpl_plist_get_int(_properties, GIALIAS_WSOL_OMDIR)
00331 );
00332 } else {
00333 cx_free(wavcoeff);
00334 return NULL;
00335 }
00336
00337 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMFCOLL)) {
00338 cpl_matrix_set(
00339 wavcoeff->opt_mod_params,
00340 1,
00341 0,
00342 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMFCOLL)
00343 );
00344 } else {
00345 cx_free(wavcoeff);
00346 return NULL;
00347 }
00348
00349 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMGCAM)) {
00350 cpl_matrix_set(
00351 wavcoeff->opt_mod_params,
00352 2,
00353 0,
00354 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMGCAM)
00355 );
00356 } else {
00357 cx_free(wavcoeff);
00358 return NULL;
00359 }
00360
00361 if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMGTHETA)) {
00362 cpl_matrix_set(
00363 wavcoeff->opt_mod_params,
00364 3,
00365 0,
00366 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMGTHETA)
00367 );
00368 } else {
00369 cx_free(wavcoeff);
00370 return NULL;
00371 }
00372
00373
00374 } else {
00375
00376 cx_free(wavcoeff);
00377 return NULL;
00378
00379 }
00380
00381 wavcoeff->wav_coeffs = giraffe_slitgeometry_new();
00382 giraffe_slitgeometry_resize(wavcoeff->wav_coeffs, 1);
00383
00384 if (cpl_plist_contains(_properties, GIALIAS_XRES_PDEG)) {
00385
00386 cxchar *l, *r, *tmpstr;
00387
00388 tmpstr = (cxchar*) cpl_plist_get_string(_properties, GIALIAS_XRES_PDEG);
00389
00390 l = &(tmpstr[0]);
00391 r = &(tmpstr[2]);
00392
00393 poly_x_deg = atoi(l) + 1;
00394 poly_y_deg = atoi(r) + 1;
00395
00396 } else {
00397 giraffe_slitgeometry_delete(wavcoeff->wav_coeffs);
00398 cx_free(wavcoeff);
00399 return NULL;
00400 }
00401
00402 ncoefficients = poly_x_deg * poly_y_deg;
00403
00404 coefficients = cpl_matrix_new(poly_x_deg,poly_y_deg);
00405 pd_coefficients = cpl_matrix_get_data(coefficients);
00406
00407 subslitfit = cpl_table_get_int(_table, "SSN", 0, NULL);
00408
00409 for (i=0; i<ncoefficients; i++) {
00410
00411 snprintf(buffer, sizeof(cxchar)*80, "XC%-d", i);
00412
00413 pd_coefficients[i] =
00414 cpl_table_get_double(_table, buffer, 0, NULL);
00415
00416 }
00417
00418 giraffe_slitgeometry_set(wavcoeff->wav_coeffs, 0, coefficients);
00419
00420 return wavcoeff;
00421
00422 }