twiflat_ini_by_cpl.c

00001 
00002 /*----------------------------------------------------------------------------
00003    
00004    File name    :   twiflat_ini_by_cpl.c
00005    Author       :   Andrea Modigliani
00006    Created on   :   May 20, 2004
00007    Description  :   parse cpl input for the generation of twilight flats 
00008 
00009  ---------------------------------------------------------------------------*/
00010 
00011 /*---------------------------------------------------------------------------
00012                                 Includes
00013  ---------------------------------------------------------------------------*/
00014 
00015 #include "twiflat_ini_by_cpl.h"
00016 
00017 /*---------------------------------------------------------------------------
00018                     Functions private to this module
00019  ---------------------------------------------------------------------------*/
00020 
00021 static void     parse_section_frames(twiflat_config *,  cpl_parameterlist* cpl_cfg, cpl_frameset* sof, cpl_frameset** raw, int* status);
00022 static void     parse_section_cleanmean(twiflat_config *,  cpl_parameterlist* cpl_cfg);
00023 static void     parse_section_warpfix(twiflat_config *,  cpl_parameterlist* cpl_cfg);
00024 
00025 /* removed generateTwiflat_ini_file */
00026 
00027 /*-------------------------------------------------------------------------*/
00038 /*--------------------------------------------------------------------------*/
00039 
00040 twiflat_config * 
00041 parse_cpl_input_twiflat(cpl_parameterlist * cpl_cfg, cpl_frameset* sof, 
00042             cpl_frameset** raw) 
00043 {
00044 
00045  const cxchar * _id = "parse_cpl_input_twiflat";
00046   twiflat_config   *  cfg = twiflat_cfg_create();
00047   int status=0;
00048   /*
00049    * Perform sanity checks, fill up the structure with what was
00050    * found in the ini file
00051    */
00052   /* Here we need to set (see bad_ini.c)
00053            "eclipse:versionnumber"
00054            "general:maximummemory"->"max_ram"
00055            "general:maximumswap"->"max_swap"
00056            "general:verbose"
00057            "general:debug"
00058            "general:tmpdirname"
00059            "general:logfile"
00060     */
00061     parse_section_cleanmean (cfg, cpl_cfg);
00062     parse_section_warpfix   (cfg, cpl_cfg);
00063     parse_section_frames    (cfg, cpl_cfg, sof, raw, &status);
00064         if (status > 0) {
00065                 cpl_msg_error(_id,"parsing cpl input");
00066                 twiflat_cfg_destroy(cfg);
00067                 cfg = NULL ;
00068                 return NULL ;
00069         }
00070     return cfg ;
00071 }
00072 
00073 
00074 static void     
00075 parse_section_frames(twiflat_config * cfg, 
00076              cpl_parameterlist * cpl_cfg,
00077              cpl_frameset * sof,
00078              cpl_frameset ** raw,
00079                      int* status)
00080 {
00081 
00082  const cxchar * _id = "parse_section_frames";
00083         int                     i;
00084         char            *       name;
00085 
00086               int                     nraw,ntwi, ndark, non, noff ;
00087         int nframes=0;
00088         int nremoved=0;
00089         char* tag;
00090 
00091 
00092    cpl_frame* frame   = NULL;
00093    cpl_parameter *p; 
00094   char spat_res[FILE_NAME_SZ];
00095    char lamp_status[FILE_NAME_SZ];
00096    char band[FILE_NAME_SZ];
00097    int ins_set=0;
00098    int op=0;
00099 
00100 
00101 
00102 
00103    nframes = cpl_frameset_get_size(sof);
00104    *raw = cpl_frameset_duplicate(sof);
00105 
00106 
00107    nremoved = cpl_frameset_erase(*raw,PRO_BP_MAP);
00108    nremoved = cpl_frameset_erase(*raw,PRO_SLOPE);
00109 
00110    nraw    = cpl_frameset_get_size(*raw);
00111    if(nraw<1) {
00112      cpl_msg_error(_id,"no good raw frame in input, something wrong!");
00113      (*status)++;
00114      return;
00115    }
00116    /* Allocate structures to go into the blackboard */
00117    cfg->framelist     = cpl_malloc(nraw * sizeof(char*));
00118    cfg->frametype     = cpl_malloc(nraw * sizeof(int));
00119 
00120    /* Browse through the charmatrix to get names and file types */
00121    i=0 ;
00122    ntwi = 0 ;
00123    ndark = 0 ;
00124    non = 0 ;
00125    noff = 0 ;
00126 
00127    for (i=0 ; i<nraw ; i++) {
00128       frame = cpl_frameset_get_frame(*raw,i);
00129       name=(char*) cpl_frame_get_filename(frame);
00130       if(file_exists(name)==1) 
00131     {
00132       cfg->framelist[i]=cpl_strdup(cpl_frame_get_filename(frame));
00133       tag = (char*) cpl_frame_get_tag(frame);
00134       printf("frame tag =%s \n",tag); 
00135           if(strcmp(tag,RAW_FLAT_SKY)  == 0) 
00136         {
00137           cfg->frametype[i] = FRAME_TWI ;
00138           ntwi++;
00139           printf("Frame is twiflat\n");
00140 
00141         }
00142           else if(strcmp(tag,RAW_DARK)  == 0) 
00143         {
00144           cfg->frametype[i] = FRAME_DARK ;
00145           ndark++;
00146           printf("Frame is dark\n");
00147         }
00148           else if(strcmp(tag,RAW_ON)  == 0) 
00149         {
00150           cfg->frametype[i] = FRAME_INT_ON ;
00151           non++;
00152           printf("Frame is flat on\n");
00153         }
00154           else if(strcmp(tag,RAW_OFF)  == 0) 
00155         {
00156           cfg->frametype[i] = FRAME_INT_OFF ;
00157           noff++;
00158           printf("Frame is flat off\n");
00159         }
00160     }
00161       /* Store file name into framelist */
00162       printf("frame=%s\n",cfg->framelist[i]);
00163    }
00164    printf("Noff= %d Non= %d Ntwi= %d Ndark= %d  \n",noff,non,ntwi,ndark);
00165  
00166    /* Copy relevant information into the blackboard */
00167    cfg->nframes         = nraw ;
00168    cfg->ntwi            = ntwi ;
00169    cfg->ndark           = ndark ;
00170    cfg->non             = non ;
00171    cfg->noff            = noff ;
00172    if ( (ntwi == 0) && (ndark == 0) && (non == 0) && (noff == 0)) {
00173      cpl_msg_error(_id,"wrong input");
00174      (*status)++;
00175      return;
00176    } 
00177 
00178    strcpy(cfg -> outName, TWIFLAT_OUT_FILENAME);
00179 
00180    if(NULL != cpl_frameset_find(sof,PRO_BP_MAP)) {
00181       frame = cpl_frameset_find(sof,PRO_BP_MAP);
00182       strcpy(cfg -> mask,cpl_strdup(cpl_frame_get_filename(frame)));
00183    } else {
00184      cpl_msg_error(_id,"Frame %s not found!", PRO_BP_MAP);
00185      (*status)++;
00186      return;
00187    }
00188 
00189 
00190    nraw    = cpl_frameset_get_size(*raw);
00191    frame = cpl_frameset_get_frame(*raw,0);
00192 
00193    sinfoni_get_spatial_res(frame,spat_res);
00194    switch(sinfoni_frame_is_on(frame))
00195      {
00196 
00197     case 0: 
00198       strcpy(lamp_status,"on");
00199       break;
00200     case 1: 
00201       strcpy(lamp_status,"off");
00202       break;
00203     case -1:
00204       strcpy(lamp_status,"undefined");
00205       break;
00206     default: 
00207       strcpy(lamp_status,"undefined");
00208       break;
00209 
00210      }
00211    sinfoni_get_band(frame,band);
00212    cpl_msg_info(_id,"stat_res: %s lamp_status: %s band: %s \n",
00213                      spat_res,    lamp_status,    band);
00214 
00215    
00216    sinfoni_get_ins_set(band,&ins_set);
00217 
00218    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.general.overwrite_parameters");
00219    op = cpl_parameter_get_bool(p);
00220 
00221    if(op) {
00222       cpl_msg_info(_id,MSG_OVER_WRITE_PAR);
00223       rec_twiflat_set(cfg,cpl_cfg,ins_set);
00224    }
00225 
00226 
00227 
00228    return ;
00229 
00230 }
00231 
00232 
00233 static void     
00234 parse_section_cleanmean(twiflat_config * cfg,cpl_parameterlist * cpl_cfg)
00235 {
00236        
00237    cpl_parameter* p;
00238    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.twiflat.lower_rejection");
00239    cfg -> loReject =  cpl_parameter_get_double(p);
00240 
00241    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.twiflat.higher_rejection");
00242    cfg -> hiReject =  cpl_parameter_get_double(p);
00243 
00244    return ;
00245 }
00246 
00247 static void     
00248 parse_section_warpfix(twiflat_config * cfg,cpl_parameterlist * cpl_cfg)
00249 {
00250        
00251    cpl_parameter* p;
00252 
00253    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.twiflat.warpfix_ind");
00254    cfg -> warpfixInd =  cpl_parameter_get_bool(p);
00255 
00256    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.twiflat.poly_file");
00257    strcpy(cfg -> polyFile, cpl_parameter_get_string(p));
00258 
00259    p = cpl_parameterlist_find(cpl_cfg, "sinfoni.twiflat.warpfix_kernel");
00260    strcpy(cfg -> kernel, cpl_parameter_get_string(p));
00261 
00262    return ;
00263 }
00264 void
00265 twiflat_free(twiflat_config * cfg)
00266 {  
00267   cpl_free(cfg->framelist);
00268   cpl_free(cfg->frametype);
00269 
00270   twiflat_cfg_destroy(cfg);
00271   return;
00272 
00273 }

Generated on Wed Oct 26 13:08:56 2005 for SINFONI Pipeline Reference Manual by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001