sinfo_flat_ini.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    :   flat_ini.c
00022    Author       :   Juergen Schreiber
00023    Created on   :    Mar 04, 2002
00024    Description  :    prepare flatfield frames ini file handling for SPIFFI
00025  ---------------------------------------------------------------------------*/
00026 #ifdef HAVE_CONFIG_H
00027 #  include <config.h>
00028 #endif
00029 /*---------------------------------------------------------------------------
00030                                 Includes
00031  ---------------------------------------------------------------------------*/
00032 #include "sinfo_flat_ini.h"
00033 /*---------------------------------------------------------------------------
00034                     Functions private to this module
00035  ---------------------------------------------------------------------------*/
00036 static void     parse_section_general(dictionary *, flat_config *, int *);
00037 static void     parse_section_frames(dictionary *, flat_config *, int *);
00038 static void     parse_section_cleanmean(dictionary *, flat_config *, int *);
00039 static void     parse_section_badpixel(dictionary *, flat_config *, int *);
00040 static void     parse_section_badpix(dictionary *, flat_config *, int *);
00041 static void     parse_section_thresh(dictionary *, flat_config *, int *);
00060 flat_config * 
00061 parse_flat_ini_file(char * ini_name)
00062 {
00063         dictionary    *       sym ;
00064         flat_config   *       cfg ;
00065         int                   status ;
00066 
00067         if (!sinfo_file_exists(ini_name)) {
00068            sinfo_msg_error("cannot find ini file [%s]: aborting", ini_name) ;
00069                 return NULL ;
00070         }
00071         sym = iniparser_load(ini_name) ;
00072         if (sym == NULL) {
00073            sinfo_msg_error("in parsing ini file [%s]: aborting", ini_name) ;
00074            return NULL ;
00075         }
00076 
00077         cfg = sinfo_flat_cfg_create();
00078         if (cfg==NULL) {
00079            sinfo_msg_error("allocating flat_config struct");
00080                 iniparser_freedict(sym) ;
00081                 return NULL ;
00082         }
00083 
00084         /*
00085          * Perform sanity checks, fill up the structure with what was
00086          * found in the ini file
00087          */
00088 
00089         status = 0 ;
00090         parse_section_general   (sym, cfg, &status);
00091         parse_section_frames    (sym, cfg, &status);
00092         parse_section_cleanmean (sym, cfg, &status);
00093         parse_section_badpixel  (sym, cfg, &status); 
00094         parse_section_badpix    (sym, cfg, &status); 
00095         parse_section_thresh    (sym, cfg, &status); 
00096 
00097         iniparser_freedict(sym);
00098 
00099         if (status>0) {
00100           sinfo_msg_error("%d errors in ini file [%s]", status, ini_name);
00101                 sinfo_flat_cfg_destroy(cfg);
00102                 cfg = NULL ;
00103                 return NULL ;
00104         }
00105         return cfg ;
00106 }
00107 
00108 
00109 /*---------------------------------------------------------------------------
00110    Functions:   parse_section_xxx()
00111    In           :       symbolic table read from ini file
00112    Out          :       void
00113    Job          :       update a flat_config structure from what can be
00114                             found in the ini file.
00115    Notice       :       all of these functions update a status integer to
00116                         indicate if an error occurred, or leave it as it is if
00117                         everything went Ok.
00118 
00119         parse_section_general()
00120         parse_section_frames ()
00121         parse_section_cleanmean ()
00122         parse_section_badpixel  () 
00123         parse_section_badpix ()
00124         parse_section_thresh ()
00125 
00126  ---------------------------------------------------------------------------*/
00127 
00128 
00129 static void     parse_section_general(
00130         dictionary * sym,
00131         flat_config * cfg,
00132         int *status
00133 )
00134 {
00135         char    *       cval ;
00136         int             ival ;
00137 
00138         /*
00139          * General section
00140          */
00141         cval = iniparser_getstr(sym, "eclipse:versionnumber") ;
00142         if (cval!=NULL) {
00143            if (strcmp(cval, get_eclipse_version())) {
00144               sinfo_msg_warning("this ini file produced by version %s", cval);
00145               sinfo_msg_warning("you are running version %s", 
00146                                 get_eclipse_version());
00147                 }
00148         } else {
00149               sinfo_msg_warning("no eclipse version number found in file");
00150         }
00151 
00152         ival = iniparser_getint(sym, "general:maximummemory", -1);
00153         if (ival>0) sinfo_set_memory_parameter("max_ram", ival);
00154         ival = iniparser_getint(sym, "general:maximumswap", -1);
00155         if (ival>0) sinfo_set_memory_parameter("max_swap", ival);
00156         sinfo_set_verbose(iniparser_getboolean(sym, "general:verbose", 0));
00157         sinfo_set_debug(iniparser_getboolean(sym, "general:debug", 0));
00158 
00159         cval = iniparser_getstr(sym, "general:tmpdirname");
00160         if (cval!=NULL) {
00161                 sinfo_set_tmpdirname(cval);
00162         } else {
00163                 sinfo_set_tmpdirname(".");
00164         }
00165 
00166         ival = iniparser_getboolean(sym, "general:logfile", 0);
00167         if (ival) {
00168                 cval = iniparser_getstr(sym, "general:logfilename");
00169                 if (cval!=NULL) {
00170                         sinfo_set_logfile(1);
00171                         sinfo_set_logfilename(cval);
00172                 } else {
00173                         sinfo_set_logfile(0) ;
00174                 }
00175         }
00176         cval = iniparser_getstr(sym, "general:outname");
00177         if (cval!=NULL) {
00178                 strcpy (cfg -> outName , cval ) ;
00179         } else {
00180             sinfo_msg_error(" OutName in the .ini file was not found!\n") ;
00181             (*status)++ ;
00182         }
00183 
00184         if (sinfo_verbose_active())
00185                 sinfo_print_memory_parameters();
00186         return ;
00187 }
00188 
00189 static void     parse_section_frames(
00190         dictionary * sym,
00191         flat_config * cfg,
00192         int *status
00193 )
00194 {
00195         char            *       listname ;
00196         charmatrix      *       charm ;
00197         int                     i, j ;
00198         char            *       name,
00199                         *       type ;
00200         int                     nval, nobj, noff ;
00201         int                     nditherobj, nditheroff ;
00202         int                     found_sky ;
00203         int                     found_dither ;
00204         char            **      framelist ;
00205         int             *       frametypes ;
00206         int             *       frameposition ;
00207 
00208         listname = iniparser_getstr(sym, "general:infile");
00209         if (sinfo_is_ascii_list(listname)!=1) {
00210            sinfo_msg_error("file [%s] is not an ASCII list: aborting",listname);
00211            (*status)++ ;
00212            return ;
00213         }
00214 
00215         /* Read input char sinfo_matrix */
00216         charm = sinfo_charmatrix_read(listname);
00217         if (charm==NULL) {
00218            sinfo_msg_error("parsing input list [%s]", listname);
00219            (*status)++;
00220            return ;
00221         }
00222 
00223         /* Check input sinfo_matrix */
00224         nval = charm->ly ;
00225         for (j=0 ; j<charm->ly ; j++) {
00226            /* Check file existence */
00227            name = charmatrix_elem(charm, 0, j);
00228            if (sinfo_file_exists(name)!=1) {
00229               sinfo_msg_warning("file [%s] declared in list does not exist", 
00230                                 name);
00231               nval -- ;
00232            }
00233         }
00234         if (nval<1) {
00235            sinfo_msg_error("no valid plane found in list [%s]", listname);
00236            sinfo_charmatrix_del(charm);
00237            (*status)++ ;
00238            return ;
00239         }
00240 
00241         /* Allocate structures to go into the blackboard */
00242         framelist     = cpl_malloc(nval * sizeof(char*));
00243         frametypes    = cpl_malloc(nval * sizeof(int));
00244         frameposition = cpl_malloc(nval * sizeof(int));
00245 
00246         found_sky     = 0 ;
00247         found_dither  = 0 ;
00248         nobj          = 0 ;
00249         noff          = 0 ;
00250         nditheroff    = 0 ;
00251         nditherobj    = 0 ;
00252 
00253         /* Browse through the charmatrix to get names and file types */
00254         i = 0 ;
00255         for (j=0 ; j<charm->ly ; j++) 
00256         {
00257            name = charmatrix_elem(charm, 0, j);
00258            if (sinfo_file_exists(name)==1) 
00259            {
00260               /* Store file name into framelist */
00261               framelist[i] = cpl_strdup(name);
00262               /* Check if a file type is present */
00263               if (charm->lx>1) 
00264               {
00265                  /* Get file type */
00266                  type = charmatrix_elem(charm, 1, j);
00267                  strlwc(type);
00268                  /* Checking if the type contains 'off' or 'sky' */
00269                  if (strstr(type, "sky")!=NULL || strstr(type, "off") != NULL) 
00270                  {
00271                      frametypes[i] = FRAME_OFF ;
00272                      found_sky = 1 ;
00273                      /* Checking if the type contains 'pos1' or 'pos2' */
00274                      if (strstr(type, "2")!=NULL) 
00275                      {
00276                         frameposition[i] = FRAME_POS2 ;
00277                         found_dither = 1 ;
00278                         nditheroff++ ;
00279                      }
00280                      else 
00281                      {
00282                         frameposition[i] = FRAME_POS1 ;
00283                         noff++ ;
00284                      }
00285 
00286                   }
00287                   else  
00288                   {
00289                      frametypes[i] = FRAME_ON ;
00290                      /* Checking if the type contains 'pos1' or 'pos2' */
00291                      if (strstr(type, "2")!=NULL) 
00292                      {
00293                         frameposition[i] = FRAME_POS2 ;
00294                         found_dither = 1 ;
00295                         nditherobj++ ;
00296                      } 
00297                      else 
00298                      {
00299                         frameposition[i] = FRAME_POS1 ;
00300                         nobj++ ;
00301                      }
00302                    }
00303                 } 
00304                 else 
00305                 {
00306                    /* No type means an object */
00307                    frametypes[i] = FRAME_ON ;
00308                    /* No type means position 1 */
00309                    frameposition[i] = FRAME_POS1 ;
00310                    nobj ++ ;
00311                 }
00312                 i++ ;
00313             }
00314         }
00315         sinfo_charmatrix_del(charm);
00316 
00317         /* Copy relevant information into the blackboard */
00318         cfg->framelist       = framelist ;
00319         cfg->frametype       = frametypes ;
00320         cfg->frameposition   = frameposition ;
00321         cfg->nframes         = nval ;
00322         cfg->nobj            = nobj ;
00323         cfg->noff            = noff ;
00324         cfg->nditherobj      = nditherobj ;
00325         cfg->nditheroff      = nditheroff ;
00326         cfg->contains_sky    = found_sky ;
00327         cfg->contains_dither = found_dither ;
00328 
00329         return ;
00330 }
00331 
00332 static void     parse_section_cleanmean(
00333         dictionary * sym,
00334         flat_config * cfg,
00335         int *status )
00336 {
00337         float           dval ;
00338 
00339         dval = iniparser_getdouble(sym, "cleanmean:loreject", -1.) ;
00340         if (dval!=-1.) 
00341         {
00342             cfg -> loReject = dval ; 
00343         }
00344         else 
00345         {
00346             sinfo_msg_error(" LoReject in the .ini file was not found!\n") ;
00347             (*status)++ ;
00348         }
00349         dval = iniparser_getdouble(sym, "cleanmean:hireject", -1.) ;
00350         if (dval!=-1.) 
00351         {
00352             cfg -> hiReject = dval ; 
00353         }
00354         else 
00355         {
00356             sinfo_msg_error(" hiReject in the .ini file was not found!\n") ;
00357             (*status)++ ;
00358         }
00359         return ;
00360 }
00361 
00362 static void     parse_section_badpixel(
00363         dictionary * sym,
00364         flat_config * cfg,
00365         int *status )
00366 {
00367         int             ival ;
00368         char        *   cval ;
00369 
00370         ival = iniparser_getboolean(sym, "badpixel:interpolind", -1) ;
00371         if (ival != -1)
00372         {
00373             cfg -> interpolInd = ival ;
00374         }
00375         else
00376         {
00377             sinfo_msg_error(" interpolInd in the .ini file was not found!\n") ;
00378             (*status)++ ;
00379         }
00380         cval = iniparser_getstr(sym, "badpixel:mask") ;
00381         if (cval != NULL) 
00382         {
00383             strcpy (cfg -> mask , cval)  ;
00384         }
00385         else
00386         {
00387             sinfo_msg_error(" mask in the .ini file was not found!\n") ;
00388             (*status)++ ;
00389         }
00390         ival = iniparser_getint(sym, "badpixel:maxrad", -1) ;
00391         if (ival!=-1) 
00392         {
00393             cfg -> maxRad = ival ; 
00394         }
00395         else 
00396         {
00397             sinfo_msg_error(" MaxRad in the .ini file was not found!\n") ;
00398             (*status)++ ;
00399         }
00400         cval = iniparser_getstr(sym, "badpixel:slitposlist") ;
00401         if (cval != NULL) 
00402         {
00403             strcpy (cfg -> slitposList , cval) ;
00404         }
00405         else
00406         {
00407             sinfo_msg_error(" SlitposList in the .ini file was not found!\n") ;
00408             (*status)++ ;
00409         }
00410 }
00411 
00412 static void     parse_section_badpix(
00413         dictionary * sym,
00414         flat_config * cfg,
00415         int *status )
00416 {
00417         int             ival ;
00418         float           dval ;
00419         char       *    cval ;
00420 
00421         ival = iniparser_getboolean(sym, "badpix:badind", -1) ;
00422         if (ival != -1)
00423         {
00424             cfg -> badInd = ival ;
00425         }
00426         else
00427         {
00428             sinfo_msg_error(" badInd in the .ini file was not found!\n") ;
00429             (*status)++ ;
00430         }
00431         cval = iniparser_getstr(sym, "badpix:maskname") ;
00432         if (cval != NULL) 
00433         {
00434             strcpy (cfg -> maskname , cval) ;
00435         }
00436         else
00437         {
00438             sinfo_msg_error(" mask in the .ini file was not found!\n") ;
00439             (*status)++ ;
00440         }
00441         dval = iniparser_getdouble(sym, "badpix:sigmafactor", -1.) ;
00442         if (dval!=-1.)
00443         {
00444             cfg -> sigmaFactor = dval ;
00445         }
00446         else
00447         {
00448             sinfo_msg_error(" sigmaFactor in the .ini file was not found!\n") ;
00449             (*status)++ ;
00450         }
00451         dval = iniparser_getdouble(sym, "badpix:factor", -1.) ;
00452         if (dval!=-1.)
00453         {
00454             cfg -> factor = dval ;
00455         }
00456         else
00457         {
00458             sinfo_msg_error(" factor in the .ini file was not found!\n") ;
00459             (*status)++ ;
00460         }
00461         ival = iniparser_getint(sym, "badpix:iterations", -1) ;
00462         if (ival!=-1)
00463         {
00464             cfg -> iterations = ival ;
00465         }
00466         else
00467         {
00468             sinfo_msg_error(" iterations in the .ini file was not found!\n") ;
00469             (*status)++ ;
00470         }
00471         dval = iniparser_getdouble(sym, "badpix:badloreject", -1.) ;
00472         if (dval!=-1.)
00473         {
00474             cfg -> badLoReject = dval ;
00475         }
00476         else
00477         {
00478             sinfo_msg_error(" badLoReject in the .ini file was not found!\n") ;
00479             (*status)++ ;
00480         }
00481         dval = iniparser_getdouble(sym, "badpix:badhireject", -1.) ;
00482         if (dval!=-1.)
00483         {
00484             cfg -> badHiReject = dval ;
00485         }
00486         else
00487         {
00488             sinfo_msg_error(" badHiReject in the .ini file was not found!\n") ;
00489             (*status)++ ;
00490         }
00491         ival = iniparser_getint(sym, "badpix:llx", -1) ;
00492         if (ival!=-1)
00493         {
00494             cfg -> llx = ival ;
00495         }
00496         else
00497         {
00498             sinfo_msg_error(" factor in the .ini file was not found!\n") ;
00499             (*status)++ ;
00500         }
00501         ival = iniparser_getint(sym, "badpix:lly", -1) ;
00502         if (ival!=-1)
00503         {
00504             cfg -> lly = ival ;
00505         }
00506         else
00507         {
00508             sinfo_msg_error(" factor in the .ini file was not found!\n") ;
00509             (*status)++ ;
00510         }
00511         ival = iniparser_getint(sym, "badpix:urx", -1) ;
00512         if (ival!=-1)
00513         {
00514             cfg -> urx = ival ;
00515         }
00516         else
00517         {
00518             sinfo_msg_error(" factor in the .ini file was not found!\n") ;
00519             (*status)++ ;
00520         }
00521         ival = iniparser_getint(sym, "badpix:ury", -1) ;
00522         if (ival!=-1)
00523         {
00524             cfg -> ury = ival ;
00525         }
00526         else
00527         {
00528             sinfo_msg_error(" factor in the .ini file was not found!\n") ;
00529             (*status)++ ;
00530         }
00531         return ;
00532 }
00533 
00534 static void     parse_section_thresh(
00535         dictionary * sym,
00536         flat_config * cfg,
00537         int *status )
00538 {
00539         int             ival ;
00540         float           dval ;
00541 
00542         ival = iniparser_getboolean(sym, "thresh:threshind", -1) ;
00543         if (ival != -1)
00544         {
00545             cfg -> threshInd = ival ;
00546         }
00547         else
00548         {
00549             sinfo_msg_error(" ThreshInd in the .ini file was not found!\n") ;
00550             (*status)++ ;
00551         }
00552         dval = iniparser_getdouble(sym, "thresh:meanfactor", -1.) ;
00553         if (dval!=-1.)
00554         {
00555             cfg -> meanfactor = dval ;
00556         }
00557         else
00558         {
00559             sinfo_msg_error(" meanfactor in the .ini file was not found!\n") ;
00560             (*status)++ ;
00561         }
00562 }
00563 
00564 

Generated on 8 Mar 2011 for SINFONI Pipeline Reference Manual by  doxygen 1.6.1