sinfo_flat_ini_by_cpl.c

00001 /*
00002  * This file is part of the ESO SINFONI Pipeline
00003  * Copyright (C) 2004,2005 European Southern Observatory
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
00018  */
00019 /*----------------------------------------------------------------------------
00020    
00021    File name    :   sinfo_flat_ini_by_cpl.c
00022    Author       :   Andrea Modigliani
00023    Created on   :   May 19, 2004
00024    Description  :   read cpl input for SPIFFI
00025  ---------------------------------------------------------------------------*/
00026 #ifdef HAVE_CONFIG_H
00027 #  include <config.h>
00028 #endif
00029 /*---------------------------------------------------------------------------
00030                                 Includes
00031  ---------------------------------------------------------------------------*/
00032 #include <string.h>
00033 #include "sinfo_flat_ini_by_cpl.h"
00034 #include "sinfo_error.h"
00035 #include "sinfo_hidden.h"
00036 #include "sinfo_pro_types.h"
00037 #include "sinfo_raw_types.h"
00038 #include "sinfo_functions.h"
00039 #include "sinfo_file_handling.h"
00040 /*---------------------------------------------------------------------------
00041                     Functions private to this module
00042  ---------------------------------------------------------------------------*/
00043 void sinfo_flat_free_alloc(flat_config * cfg);
00044 static void 
00045 parse_section_frames(flat_config *, cpl_frameset* sof, 
00046                      cpl_frameset** raw, int* status);
00047 static void parse_section_cleanmean(flat_config *, cpl_parameterlist* cpl_cfg);
00048 static void parse_section_badpixel(flat_config *, cpl_parameterlist* cpl_cfg);
00049 static void parse_section_badpix(flat_config *, cpl_parameterlist* cpl_cfg);
00050 static void parse_section_thresh(flat_config *, cpl_parameterlist* cpl_cfg);
00051 static void     
00052 parse_section_qclog(flat_config * cfg, cpl_parameterlist *   cpl_cfg);
00074 flat_config * 
00075 sinfo_parse_cpl_input_flat(cpl_parameterlist* cpl_cfg, 
00076                                    cpl_frameset* sof, 
00077                                    cpl_frameset** raw)
00078 {
00079         flat_config   *       cfg = sinfo_flat_cfg_create();
00080         int status=0;
00081         /*
00082          * Perform sanity checks, fill up the structure with what was
00083          * found in the ini file
00084          */
00085         parse_section_badpixel  (cfg, cpl_cfg);
00086         parse_section_cleanmean (cfg, cpl_cfg);
00087         parse_section_badpix    (cfg, cpl_cfg);
00088         parse_section_thresh    (cfg, cpl_cfg); 
00089         parse_section_qclog     (cfg,cpl_cfg);
00090       
00091         parse_section_frames    (cfg, sof, raw,  &status);
00092         if (status > 0) {
00093                 sinfo_msg_error("parsing cpl input");
00094                 sinfo_flat_cfg_destroy(cfg);
00095                 cfg = NULL ;
00096                 return NULL ;
00097         }
00098         return cfg ;
00099 }
00100 
00110 static void     
00111 parse_section_frames(flat_config * cfg,
00112              cpl_frameset * sof,
00113              cpl_frameset ** raw,
00114                      int* status)
00115 {
00116    int                     i;
00117 
00118    char           *       name ;
00119 
00120    int                     nobj, noff ;
00121    int                     nditherobj, nditheroff ;
00122    int                     found_sky ;
00123    int                     found_dither ;
00124    int nframes=0;
00125    int nraw=0;
00126    char* tag;
00127    char spat_res[FILE_NAME_SZ];
00128    char lamp_status[FILE_NAME_SZ];
00129    char band[FILE_NAME_SZ];
00130    int ins_set=0;
00131 
00132    cpl_frame* frame   = NULL;
00133 
00134 
00135    nframes = cpl_frameset_get_size(sof);
00136 
00137    sinfo_extract_raw_frames_type(sof,raw,RAW_FLAT_LAMP);
00138    nraw=cpl_frameset_get_size(*raw);
00139 
00140    if (nraw==0) {
00141       sinfo_extract_raw_frames_type(sof,raw,RAW_FLAT_NS);
00142    }   
00143 
00144 
00145    nraw=cpl_frameset_get_size(*raw);
00146    if (nraw==0) {
00147        sinfo_msg("Frame %s or %s not found!", RAW_FLAT_LAMP,RAW_FLAT_NS);
00148        (*status)++;
00149        return   ;
00150    }
00151 
00152    nraw  = cpl_frameset_get_size(*raw);
00153 
00154    sinfo_msg("nraw=%d",nraw);
00155    if(nraw<1) {
00156      sinfo_msg_error("no good raw frame in input, something wrong!");
00157      (*status)++;
00158      return;
00159    }
00160 
00161    cknull_nomsg(frame = cpl_frameset_get_frame(*raw,0));
00162 
00163    ck0_nomsg(sinfo_get_spatial_res(frame,spat_res));
00164    switch(sinfo_frame_is_on(frame))
00165      {
00166 
00167     case 0: 
00168       strcpy(lamp_status,"on");
00169       break;
00170     case 1: 
00171       strcpy(lamp_status,"off");
00172       break;
00173     case -1:
00174       strcpy(lamp_status,"undefined");
00175       break;
00176     default: 
00177       strcpy(lamp_status,"undefined");
00178       break;
00179 
00180      }
00181 
00182    sinfo_get_band(frame,band);
00183    sinfo_msg("Spatial resolution: %s lamp status: %s band: %s \n",
00184                      spat_res,              lamp_status,    band);
00185 
00186    
00187    sinfo_get_ins_set(band,&ins_set);
00188 
00189 
00190    /* Allocate structures to go into the blackboard */
00191    cfg->framelist     = cpl_malloc(nraw * sizeof(char*));
00192    cfg->frametype     = cpl_malloc(nraw * sizeof(int));
00193    cfg->frameposition = cpl_malloc(nraw * sizeof(int));
00194 
00195    found_sky     = 0 ;
00196    found_dither  = 0 ;
00197    nobj          = 0 ;
00198    noff          = 0 ;
00199    nditheroff    = 0 ;
00200    nditherobj    = 0 ;
00201    for (i=0;i<nraw;i++) {
00202      cfg->framelist[i]=NULL;
00203      cfg->frametype[i]=-1;
00204      cfg->frameposition[i]=-1;
00205    }
00206 
00207 
00208    cfg->nframes         = nraw ;
00209     /* Browse through the charmatrix to get names and file types */
00210    for (i=0 ; i<nraw ; i++) {
00211       frame = cpl_frameset_get_frame(*raw,i);
00212       name= (char*) cpl_frame_get_filename(frame);
00213       if(sinfo_file_exists(name)==1) {
00214     /* to go on the file must exist */
00215     if(cpl_frame_get_tag(frame) != NULL) {
00216       /* If the frame has a tag we process it. Else it is an object */ 
00217       tag= (char*) cpl_frame_get_tag(frame);
00218           /* sinfo_msg("frame %s tag =%s \n",name,tag); */
00219           if((sinfo_frame_is_on(frame)  == 0) ||
00220              (sinfo_frame_is_sky(frame)  == 1) ) 
00221         {
00222 
00223              cfg->framelist[i]=(char*) cpl_frame_get_filename(frame);
00224              cfg->frametype[i] = FRAME_OFF ;
00225              found_sky = 1;
00226              if (sinfo_frame_is_dither(frame)) 
00227            {
00228                 cfg->frameposition[i] = FRAME_POS2 ;
00229                 found_dither = 1 ;
00230                 nditheroff++ ;
00231            }
00232              else 
00233            {
00234                  cfg->frameposition[i] = FRAME_POS1 ;
00235                  noff++ ;
00236            }
00237         }
00238           else if(sinfo_frame_is_on(frame)  == 1) 
00239         {
00240            cfg->framelist[i]=(char*) cpl_frame_get_filename(frame);
00241            cfg->frametype[i] = FRAME_ON ;
00242           if (sinfo_frame_is_dither(frame))
00243         {
00244           cfg->frameposition[i] = FRAME_POS2 ;
00245           found_dither = 1 ;
00246           nditherobj++ ;
00247         }
00248               else 
00249         {
00250           cfg->frameposition[i] = FRAME_POS1 ;
00251           nobj++ ;
00252         }
00253         }
00254  
00255     }
00256        
00257         else 
00258       {
00259             /* No type means an object */
00260             /* No type means position 1 */
00261     /*
00262         cfg->frametype[i] = FRAME_ON ;
00263         cfg->frameposition[i] = FRAME_POS1 ;
00264         nobj ++ ;
00265     */
00266       }
00267       }
00268       /* Store file name into framelist */
00269       /* sinfo_msg("frame=%s\n",cfg->framelist[i]); */
00270     }
00271    
00272    /*
00273    sinfo_msg("Noff= %d Nobj= %d Nditheroff= %d Nditherobj= %d",
00274                      noff,nobj,nditheroff,nditherobj);
00275    */
00276 
00277 
00278    if((nobj<1) && (nditherobj< 1)) {
00279      sinfo_msg_error("no ON raw frame in input, something wrong!");
00280      sinfo_flat_free_alloc(cfg);
00281      (*status)++;
00282      return;
00283    }
00284  
00285    /* Copy relevant information into the blackboard */
00286    cfg->nobj            = nobj ;
00287    cfg->noff            = noff ;
00288    cfg->nditherobj      = nditherobj ;
00289    cfg->nditheroff      = nditheroff ;
00290    cfg->contains_sky    = found_sky ;
00291    cfg->contains_dither = found_dither ;
00292 
00293    strcpy(cfg -> outName, LAMP_FLATS_OUT_FILENAME);
00294 
00295    if(cfg->interpolInd != 0) {
00296 
00297       if(NULL != cpl_frameset_find(sof,PRO_BP_MAP)) {
00298          frame = cpl_frameset_find(sof,PRO_BP_MAP);
00299          strcpy(cfg -> mask,cpl_frame_get_filename(frame));
00300          if(sinfo_file_exists(cfg->mask)==1) {
00301          } else {
00302             sinfo_msg_error("Filename %s for Frame %s not found!", 
00303                        cfg->mask, PRO_BP_MAP);
00304             sinfo_flat_free_alloc(cfg);
00305             (*status)++;
00306            return;
00307  
00308          }
00309 
00310       } else {
00311         sinfo_msg_error("Frame %s not found!", PRO_BP_MAP);
00312         sinfo_flat_free_alloc(cfg);
00313         (*status)++;
00314        return;
00315       } 
00316       if(NULL != cpl_frameset_find(sof,PRO_SLIT_POS)) {
00317          frame = cpl_frameset_find(sof,PRO_SLIT_POS);
00318          strcpy(cfg -> slitposList,cpl_frame_get_filename(frame));
00319          if(sinfo_file_exists(cfg->mask) == 1) {
00320          } else {
00321             sinfo_msg_error("Filename %s for Frame %s not found!", 
00322                        cfg->slitposList, PRO_SLIT_POS);
00323             sinfo_flat_free_alloc(cfg);
00324             (*status)++;
00325             return;
00326      }
00327       } else {
00328         sinfo_msg_error("Frame %s not found!", PRO_SLIT_POS);
00329         sinfo_flat_free_alloc(cfg);
00330         (*status)++;
00331         return;
00332       }
00333 
00334    }
00335 
00336   cleanup:
00337 
00338    return;
00339 }
00340 
00348 static void     
00349 parse_section_cleanmean(flat_config * cfg, cpl_parameterlist * cpl_cfg)
00350 {
00351    cpl_parameter *p; 
00352   
00353    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.low_rejection");
00354    cfg -> loReject = cpl_parameter_get_double(p);
00355 
00356    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.high_rejection");
00357    cfg -> hiReject = cpl_parameter_get_double(p);
00358 
00359 }
00360 
00368 static void     
00369 parse_section_badpixel(flat_config * cfg, cpl_parameterlist * cpl_cfg)
00370 {
00371    cpl_parameter *p; 
00372 
00373    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.interpol_index");
00374    cfg -> interpolInd = cpl_parameter_get_bool(p);
00375 
00376    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.max_rad");
00377    cfg -> maxRad =  cpl_parameter_get_int(p);
00378 
00379 }
00380 
00388 static void     
00389 parse_section_badpix(flat_config * cfg, cpl_parameterlist * cpl_cfg)
00390 {
00391 
00392    cpl_parameter* p;
00393 
00394    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.bad_ind");
00395    cfg ->  badInd = cpl_parameter_get_bool(p);
00396 
00397    strcpy(cfg -> maskname, LAMP_FLATS_OUT_BPMAP);
00398 
00399    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.sigma_factor");
00400    cfg -> sigmaFactor = cpl_parameter_get_double(p);
00401 
00402    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.factor");
00403    cfg -> factor = cpl_parameter_get_double(p);
00404 
00405    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.iterations");
00406    cfg -> iterations = cpl_parameter_get_int(p);
00407 
00408    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.bad_low_rejection");
00409    cfg -> badLoReject = cpl_parameter_get_double(p);
00410 
00411    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.bad_high_rejection");
00412    cfg -> badHiReject = cpl_parameter_get_double(p);
00413 
00414    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.llx");
00415    cfg -> llx = cpl_parameter_get_int(p);
00416 
00417    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.lly");
00418    cfg -> lly = cpl_parameter_get_int(p);
00419  
00420    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.urx");
00421    cfg -> urx = cpl_parameter_get_int(p);
00422 
00423    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.ury");
00424    cfg -> ury = cpl_parameter_get_int(p);
00425 
00426 }
00427 
00435 static void     
00436 parse_section_thresh(flat_config * cfg,cpl_parameterlist* cpl_cfg)
00437 {
00438 
00439    cpl_parameter* p;
00440    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.thresh_ind");
00441    cfg -> threshInd =cpl_parameter_get_bool(p);
00442 
00443    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.mean_factor");
00444    cfg -> meanfactor = cpl_parameter_get_double(p);
00445 
00446 
00447 }
00448 
00449 
00457 static void     
00458 parse_section_qclog(flat_config * cfg, cpl_parameterlist *   cpl_cfg)
00459 {
00460    cpl_parameter *p;  
00461 
00462    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.qc_fpn_xmin1");
00463    cfg -> qc_fpn_xmin1 = cpl_parameter_get_int(p);
00464 
00465    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.qc_fpn_xmax1");
00466    cfg -> qc_fpn_xmax1 = cpl_parameter_get_int(p);
00467 
00468    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.qc_fpn_ymin1");
00469    cfg -> qc_fpn_ymin1 = cpl_parameter_get_int(p);
00470 
00471    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.qc_fpn_ymax1");
00472    cfg -> qc_fpn_ymax1 = cpl_parameter_get_int(p);
00473 
00474    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.qc_fpn_xmin2");
00475    cfg -> qc_fpn_xmin2 = cpl_parameter_get_int(p);
00476    
00477    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.qc_fpn_xmax2");
00478    cfg -> qc_fpn_xmax2 = cpl_parameter_get_int(p);
00479 
00480    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.qc_fpn_ymin2");
00481    cfg -> qc_fpn_ymin2 = cpl_parameter_get_int(p);
00482 
00483    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.qc_fpn_ymax2");
00484    cfg -> qc_fpn_ymax2 = cpl_parameter_get_int(p);
00485 
00486    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.qc_thresh_min");
00487    cfg -> qc_thresh_min = cpl_parameter_get_int(p);
00488 
00489    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.lamp_flats.qc_thresh_max");
00490    cfg -> qc_thresh_max = cpl_parameter_get_int(p);
00491 
00492 }
00500 void
00501 sinfo_flat_free(flat_config ** cfg)
00502 {  
00503   if ((*cfg) != NULL) {
00504     sinfo_flat_free_alloc(*cfg);
00505     sinfo_flat_cfg_destroy(*cfg);
00506     *cfg=NULL;
00507   }
00508   return;
00509 
00510 }
00518 void 
00519 sinfo_flat_free_alloc(flat_config * cfg)
00520 {
00521   if(cfg->frametype != NULL){
00522        cpl_free(cfg->frametype); 
00523   }
00524   if(cfg->framelist != NULL) {
00525      cpl_free(cfg->framelist);
00526   }
00527   if(cfg->frameposition != NULL) {
00528      cpl_free(cfg->frameposition);
00529   }
00530 return ;
00531 }

Generated on 3 Mar 2013 for SINFONI Pipeline Reference Manual by  doxygen 1.6.1