GIRAFFE Pipeline Reference Manual

giwavecalib_types.c

00001 /* $Id: giwavecalib_types.c,v 1.10 2006/03/10 15:56:10 rpalsa Exp $
00002  *
00003  * This file is part of the GIRAFFE Pipeline
00004  * Copyright (C) 2002-2006 European Southern Observatory
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019  */
00020 
00021 /*
00022  * $Author: rpalsa $
00023  * $Date: 2006/03/10 15:56:10 $
00024  * $Revision: 1.10 $
00025  * $Name: giraffe-2_5_3 $
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 
00049 
00062 GiWcalSolution*
00063 giraffe_wcalsolution_new(void)
00064 {
00065 
00066     GiWcalSolution* tmp = NULL;
00067 
00068     tmp = (GiWcalSolution*) cx_calloc(1, sizeof(GiWcalSolution));
00069 
00070     tmp->subslitfit     = FALSE;
00071     tmp->opt_mod        = LMRQ_UNDEFINED;
00072     tmp->opt_mod_params = NULL;
00073     tmp->wav_coeffs     = NULL;
00074 
00075     return tmp;
00076 }
00077 
00089 void
00090 giraffe_wcalsolution_delete(GiWcalSolution *ws)
00091 {
00092 
00093     if (ws==NULL) { return; }
00094 
00095     if (ws->opt_mod_params!=NULL)
00096         cpl_matrix_delete(ws->opt_mod_params);
00097     if (ws->wav_coeffs!=NULL)
00098         giraffe_slitgeometry_delete(ws->wav_coeffs);
00099 
00100 }
00101 
00114 void
00115 giraffe_wcalsolution_dump(GiWcalSolution *ws)
00116 {
00117 
00118     const cxchar *fctid = "giraffe_wcalsolution_dump";
00119 
00120     cpl_msg_debug(fctid,"---- GiWcalSolution --------------------");
00121 
00122 
00123     if (ws==NULL) {
00124         cpl_msg_debug(fctid, "Empty GiWcalSolution!");
00125     } else {
00126         cpl_msg_debug(fctid, "Subslit fitted       : %s",
00127                       ws->subslitfit ? "YES" : "NO" );
00128 
00129         if (ws->opt_mod==LMRQ_XOPTMOD) {
00130             cpl_msg_debug(fctid, "Opt Model            : xoptmod");
00131         } else if (ws->opt_mod==LMRQ_XOPTMOD2) {
00132             cpl_msg_debug(fctid, "Opt Model            : xoptmod2");
00133         } else {
00134             cpl_msg_debug(fctid, "Opt Model            : undefined");
00135         }
00136 
00137         cpl_msg_debug(fctid, "Optical Model Parameters :");
00138         if (ws->opt_mod_params!=NULL) {
00139             giraffe_matrix_dump(ws->opt_mod_params, 15);
00140         } else {
00141             cpl_msg_debug(fctid, "NONE!");
00142         }
00143 
00144 
00145         cpl_msg_debug(fctid, "Slit Geometry            :");
00146         if (ws->wav_coeffs!=NULL) {
00147             cxint i;
00148             for (i=0; i<giraffe_slitgeometry_size(ws->wav_coeffs); i++) {
00149                 cpl_msg_debug(fctid, "Subslit [%d] : ", i);
00150 
00151                 giraffe_matrix_dump(giraffe_slitgeometry_get(ws->wav_coeffs, i),
00152                                     100);
00153             }
00154         }
00155         else {
00156             cpl_msg_debug(fctid, "NONE!!");
00157         }
00158     }
00159 }
00160 
00177 GiWcalSolution*
00178 giraffe_wcalsolution_create(GiTable *wavesolution)
00179 {
00180 
00181     GiWcalSolution *wavcoeff        = NULL;
00182 
00183     cpl_plist      *_properties     = NULL;
00184     cpl_table      *_table          = NULL;
00185 
00186     cxint           poly_x_deg      = 0,
00187                     poly_y_deg      = 0,
00188                     ncoefficients   = 0,
00189                     subslitfit      = 0,
00190                     i;
00191 
00192     cpl_matrix     *coefficients    = NULL;
00193     cxdouble       *pd_coefficients = NULL;
00194 
00195     cxchar          buffer[68];
00196 
00197     if (wavesolution==NULL) { return NULL; }
00198 
00199     wavcoeff = (GiWcalSolution*) cx_calloc(1, sizeof(GiWcalSolution));
00200 
00201     _properties = giraffe_table_get_properties(wavesolution);
00202     _table      = giraffe_table_get(wavesolution);
00203 
00204     /*
00205      *  Retrieve values from FITS keywords
00206      */
00207 
00208     /* subslit fit */
00209 
00210     if (cpl_plist_contains(_properties, GIALIAS_WSOL_SUBSLITS)) {
00211         if (cpl_plist_get_bool(_properties, GIALIAS_WSOL_SUBSLITS) == FALSE)
00212             wavcoeff->subslitfit = FALSE;
00213         else
00214             wavcoeff->subslitfit = TRUE;
00215     } else {
00216         cx_free(wavcoeff);
00217         return NULL;
00218     }
00219 
00220     /* optical model */
00221 
00222     if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMNAME)) {
00223         const cxchar *optmod;
00224         optmod = cpl_plist_get_string(_properties, GIALIAS_WSOL_OMNAME);
00225 
00226         if (strcmp(optmod, "xoptmod2")==0)
00227             wavcoeff->opt_mod = LMRQ_XOPTMOD2;
00228         else if (strcmp(optmod, "xoptmod")==0)
00229             wavcoeff->opt_mod = LMRQ_XOPTMOD;
00230         else
00231             wavcoeff->opt_mod = LMRQ_UNDEFINED;
00232     }
00233 
00234     if (wavcoeff->opt_mod==LMRQ_XOPTMOD2) {
00235 
00236         wavcoeff->opt_mod_params = cpl_matrix_new(7,1);
00237 
00238         if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMDIR)) {
00239             cpl_matrix_set(
00240                 wavcoeff->opt_mod_params,
00241                 0,
00242                 0,
00243                 cpl_plist_get_int(_properties, GIALIAS_WSOL_OMDIR)
00244             );
00245         } else {
00246             cx_free(wavcoeff);
00247             return NULL;
00248         }
00249 
00250         if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMFCOLL)) {
00251             cpl_matrix_set(
00252                 wavcoeff->opt_mod_params,
00253                 1,
00254                 0,
00255                 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMFCOLL)
00256             );
00257         } else {
00258             cx_free(wavcoeff);
00259             return NULL;
00260         }
00261 
00262         if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMGCAM)) {
00263             cpl_matrix_set(
00264                 wavcoeff->opt_mod_params,
00265                 2,
00266                 0,
00267                 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMGCAM)
00268             );
00269         } else {
00270             cx_free(wavcoeff);
00271             return NULL;
00272         }
00273 
00274         if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMGTHETA)) {
00275             cpl_matrix_set(
00276                 wavcoeff->opt_mod_params,
00277                 3,
00278                 0,
00279                 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMGTHETA)
00280             );
00281         } else {
00282             cx_free(wavcoeff);
00283             return NULL;
00284         }
00285 
00286         if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMSDX)) {
00287             cpl_matrix_set(
00288                 wavcoeff->opt_mod_params,
00289                 4,
00290                 0,
00291                 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMSDX)
00292             );
00293         } else {
00294             cx_free(wavcoeff);
00295             return NULL;
00296         }
00297 
00298         if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMSDY)) {
00299 
00300 
00301 
00302             cpl_matrix_set(
00303                 wavcoeff->opt_mod_params,
00304                 5,
00305                 0,
00306                 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMSDY)
00307             );
00308 
00309         } else {
00310             cx_free(wavcoeff);
00311             return NULL;
00312         }
00313 
00314         if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMSPHI)) {
00315             cpl_matrix_set(
00316                 wavcoeff->opt_mod_params,
00317                 6,
00318                 0,
00319                 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMSPHI)
00320             );
00321 
00322         } else {
00323             cx_free(wavcoeff);
00324             return NULL;
00325         }
00326 
00327     } else if (wavcoeff->opt_mod==LMRQ_XOPTMOD) {
00328 
00329         wavcoeff->opt_mod_params = cpl_matrix_new(4,1);
00330 
00331         if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMDIR)) {
00332             cpl_matrix_set(
00333                 wavcoeff->opt_mod_params,
00334                 0,
00335                 0,
00336                 cpl_plist_get_int(_properties, GIALIAS_WSOL_OMDIR)
00337             );
00338         } else {
00339             cx_free(wavcoeff);
00340             return NULL;
00341         }
00342 
00343         if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMFCOLL)) {
00344             cpl_matrix_set(
00345                 wavcoeff->opt_mod_params,
00346                 1,
00347                 0,
00348                 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMFCOLL)
00349             );
00350         } else {
00351             cx_free(wavcoeff);
00352             return NULL;
00353         }
00354 
00355         if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMGCAM)) {
00356             cpl_matrix_set(
00357                 wavcoeff->opt_mod_params,
00358                 2,
00359                 0,
00360                 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMGCAM)
00361             );
00362         } else {
00363             cx_free(wavcoeff);
00364             return NULL;
00365         }
00366 
00367         if (cpl_plist_contains(_properties, GIALIAS_WSOL_OMGTHETA)) {
00368             cpl_matrix_set(
00369                 wavcoeff->opt_mod_params,
00370                 3,
00371                 0,
00372                 cpl_plist_get_double(_properties, GIALIAS_WSOL_OMGTHETA)
00373             );
00374         } else {
00375             cx_free(wavcoeff);
00376             return NULL;
00377         }
00378 
00379 
00380     } else {
00381 
00382         cx_free(wavcoeff);
00383         return NULL;
00384 
00385     }
00386 
00387     wavcoeff->wav_coeffs = giraffe_slitgeometry_new();
00388     giraffe_slitgeometry_resize(wavcoeff->wav_coeffs, 1);
00389 
00390     if (cpl_plist_contains(_properties, GIALIAS_XRES_PDEG)) {
00391 
00392         cxchar *l, *r, *tmpstr;
00393 
00394         tmpstr = (cxchar*) cpl_plist_get_string(_properties, GIALIAS_XRES_PDEG);
00395 
00396         l = &(tmpstr[0]);
00397         r = &(tmpstr[2]);
00398 
00399         poly_x_deg = atoi(l) + 1;
00400         poly_y_deg = atoi(r) + 1;
00401 
00402     } else {
00403         giraffe_slitgeometry_delete(wavcoeff->wav_coeffs);
00404         cx_free(wavcoeff);
00405         return NULL;
00406     }
00407 
00408     ncoefficients = poly_x_deg * poly_y_deg;
00409 
00410     coefficients = cpl_matrix_new(poly_x_deg,poly_y_deg);
00411     pd_coefficients = cpl_matrix_get_data(coefficients);
00412 
00413     subslitfit = cpl_table_get_int(_table, "SSN", 0, NULL);
00414 
00415     for (i=0; i<ncoefficients; i++) {
00416 
00417         snprintf(buffer, sizeof(cxchar)*80, "XC%-d", i);
00418 
00419         pd_coefficients[i] =
00420             cpl_table_get_double(_table, buffer, 0, NULL);
00421 
00422     }
00423 
00424     giraffe_slitgeometry_set(wavcoeff->wav_coeffs, 0, coefficients);
00425 
00426     return wavcoeff;
00427 
00428 }

This file is part of the GIRAFFE Pipeline Reference Manual 2.5.3.
Documentation copyright © 2002-2006 European Southern Observatory.
Generated on Fri Jul 18 09:49:48 2008 by doxygen 1.4.6 written by Dimitri van Heesch, © 1997-2004