lamp_ini.c

00001 
00002 /*----------------------------------------------------------------------------
00003    
00004    File name    :   lamp_ini.c
00005    Author       :   Juergen Schreiber
00006    Created on   :   Mar 08, 2002
00007    Description  :   prepare lamp spectrum frames ini file handling for SPIFFI
00008 
00009  ---------------------------------------------------------------------------*/
00010 
00011 
00012 
00013 /*---------------------------------------------------------------------------
00014                                 Includes
00015  ---------------------------------------------------------------------------*/
00016 
00017 #include "lamp_ini.h"
00018 
00019 /*---------------------------------------------------------------------------
00020                     Functions private to this module
00021  ---------------------------------------------------------------------------*/
00022 
00023 static void     parse_section_general(dictionary *, lamp_config *, int *);
00024 static void     parse_section_resampling(dictionary *, lamp_config *, int *);
00025 static void     parse_section_extractspectrum(dictionary *, lamp_config *, int *);
00026 
00027 /*-------------------------------------------------------------------------*/
00041 /*--------------------------------------------------------------------------*/
00042 
00043 
00044 
00045 int generateLamp_ini_file(
00046     char * ini_name,
00047     char * name_i,
00048     char * name_o,
00049         char * name_c
00050 )
00051 {
00052     FILE * ini_file ;
00053 
00054     if (file_exists(ini_name)) {
00055         cpl_msg_warning("generateLamp_ini_file","overwriting %s", ini_name) ;
00056     }
00057     if ((ini_file = fopen(ini_name, "w")) == (FILE*)NULL) {
00058         cpl_msg_error("generateLamp_ini_file","cannot create .ini file %s", ini_name) ;
00059         return -1 ;
00060     }
00061 
00062     fprintf(ini_file,
00063 "#\n"
00064 "# Configuration file for the extraction of a halogen lamp spectrumn"
00065 "#\n") ;
00066 
00067     fprintf(ini_file, "#\n\n[Eclipse]\n") ;
00068     fprintf(ini_file, "VersionNumber = %s\n\n", get_eclipse_version()) ;
00069     fprintf(ini_file,
00070 "\n"
00071 "#\n"
00072 "# ----- [General] configures various software stuff\n"
00073 "#\n"
00074 "# This section is not mandatory. All eclipse routines\n"
00075 "# should be set once for all in a .eclipse-rc file.\n"
00076 "# If you choose to use the variables here, they will\n"
00077 "# override the settings you have in the environment.\n"
00078 "# See the eclipse installation manual to see what\n"
00079 "# these variables refer to.\n"
00080 "#\n"
00081 "\n"
00082 "[General]\n"
00083 "# MaximumMemory = 512 ;   integer, maximum megs to allocate in RAM\n"
00084 "# MaximumSwap   = 2048 ;  integer, maximum megs to allocate in swap\n"
00085 "# TmpDirName    = .   ;   path to temporary directory\n"
00086 "\n"
00087 "Verbose       = no ;   verbose mode activation\n"
00088 "Debug         = no ;   debug mode activation\n"
00089 "\n"
00090 "# LogFile       = yes ;   activate message logging to a file\n"
00091 "# LogFileName   = /tmp/spiffi-log ;  log file name\n"
00092 "\n"
00093 "\n") ;
00094     fprintf(ini_file,
00095 "#\n"
00096 "# the following are the names given in the argument of the python script\n"
00097 "#\n"
00098 "\n") ;
00099         fprintf(ini_file,
00100 "InFrame   = %s ; input file name\n" 
00101 "Wavemapim = %s ; file name of the wavelength map\n" 
00102 "OutName   = %s ; name of output fits file\n"
00103 , name_i, name_c, name_o ) ;
00104 
00105     fprintf(ini_file,
00106 "#\n"
00107 "# [Resampling] resamples the spectra to a given pixel length\n"
00108 "# ExtractSpectrum] takes the clean mean along the spatial pixels \n"
00109 "# by avoiding the bad pixel positions and delivers the final halogen lamp\n" "# spectrum\n"
00110 "\n"
00111 "[Resampling]\n"
00112 "Ncoeffs               = 3 ;     number of coefficients for the polynomial\n" "             interpolation\n"
00113 "Nrows                 = 2560 ;  number of image rows in the resampled frame\n"
00114 "               (2560 for single frames, 5120 for dithered)\n"
00115 "[ExtractSpectrum]\n"
00116 "LoReject              = 0.1 ;   percentage of rejected low intensity pixels\n"
00117 "               before averaging\n" 
00118 "HiReject              = 0.1 ;   percentage of rejected high intensity pixels\n"
00119 "               before averaging\n" 
00120 "CountsToIntensity     = 1. ;    intensity conversion factor: counts per\n"
00121 "               intensity unit\n" 
00122 "\n"
00123 "\n") ;
00124 
00125     fclose(ini_file) ;
00126     return 0 ;
00127 }
00128 
00129 
00130 /*-------------------------------------------------------------------------*/
00141 /*--------------------------------------------------------------------------*/
00142 
00143 lamp_config * parse_lamp_ini_file(char * ini_name)
00144 {
00145         dictionary    *       sym ;
00146         lamp_config   *       cfg ;
00147         int                   status ;
00148 
00149         if (!file_exists(ini_name)) {
00150                 cpl_msg_error("parse_lamp_ini_file","cannot find ini file [%s]: aborting", ini_name) ;
00151                 return NULL ;
00152         }
00153         sym = iniparser_load(ini_name) ;
00154         if (sym == NULL) {
00155                 cpl_msg_error("parse_lamp_ini_file","in parsing ini file [%s]: aborting", ini_name) ;
00156                 return NULL ;
00157         }
00158 
00159         cfg = lamp_cfg_create();
00160         if (cfg==NULL) {
00161                 cpl_msg_error("parse_lamp_ini_file","allocating lamp_config struct");
00162                 iniparser_freedict(sym) ;
00163                 return NULL ;
00164         }
00165 
00166         /*
00167          * Perform sanity checks, fill up the structure with what was
00168          * found in the ini file
00169          */
00170 
00171         status = 0 ;
00172         parse_section_general   (sym, cfg, &status);
00173         parse_section_resampling    (sym, cfg, &status);
00174         parse_section_extractspectrum (sym, cfg, &status);
00175 
00176         iniparser_freedict(sym);
00177 
00178         if (status>0) {
00179                 cpl_msg_error("parse_lamp_ini_file","%d errors in ini file [%s]", status, ini_name);
00180                 lamp_cfg_destroy(cfg);
00181                 cfg = NULL ;
00182                 return NULL ;
00183         }
00184         return cfg ;
00185 }
00186 
00187 
00188 /*---------------------------------------------------------------------------
00189    Functions:   parse_section_xxx()
00190    In           :       symbolic table read from ini file
00191    Out          :       void
00192    Job          :       update a lamp_config structure from what can be
00193                             found in the ini file.
00194    Notice       :       all of these functions update a status integer to
00195                             indicate if an error occurred, or leave it as it is if
00196                             everything went Ok.
00197 
00198         parse_section_general()
00199         parse_section_resampling ()
00200         parse_section_extractspectrum ()
00201 
00202  ---------------------------------------------------------------------------*/
00203 
00204 
00205 static void     parse_section_general(
00206         dictionary * sym,
00207         lamp_config * cfg,
00208         int *status
00209 )
00210 {
00211         char    *       cval ;
00212         int             ival ;
00213 
00214         /*
00215          * General section
00216          */
00217         cval = iniparser_getstr(sym, "eclipse:versionnumber") ;
00218         if (cval!=NULL) {
00219                 if (strcmp(cval, get_eclipse_version())) {
00220                         cpl_msg_warning("parse_lamp_ini_file","this ini file produced by version %s", cval);
00221                         cpl_msg_warning("parse_lamp_ini_file","you are running version %s", get_eclipse_version());
00222                 }
00223         } else {
00224                 cpl_msg_warning("parse_lamp_ini_file","no eclipse version number found in file");
00225         }
00226 
00227         ival = iniparser_getint(sym, "general:maximummemory", -1);
00228         if (ival>0) set_memory_parameter("max_ram", ival);
00229         ival = iniparser_getint(sym, "general:maximumswap", -1);
00230         if (ival>0) set_memory_parameter("max_swap", ival);
00231         set_verbose(iniparser_getboolean(sym, "general:verbose", 0));
00232         set_debug(iniparser_getboolean(sym, "general:debug", 0));
00233 
00234         cval = iniparser_getstr(sym, "general:tmpdirname");
00235         if (cval!=NULL) {
00236                 set_tmpdirname(cval);
00237         } else {
00238                 set_tmpdirname(".");
00239         }
00240 
00241         ival = iniparser_getboolean(sym, "general:logfile", 0);
00242         if (ival) {
00243                 cval = iniparser_getstr(sym, "general:logfilename");
00244                 if (cval!=NULL) {
00245                         set_logfile(1);
00246                         set_logfilename(cval);
00247                 } else {
00248                         set_logfile(0) ;
00249                 }
00250         }
00251         cval = iniparser_getstr(sym, "general:inframe");
00252         if (cval!=NULL) {
00253                 strcpy (cfg -> inFrame , cval ) ;
00254         } else {
00255             cpl_msg_error("parse_section_general:"," InFrame in the .ini file was not found!\n") ;
00256             (*status)++ ;
00257         }
00258         cval = iniparser_getstr(sym, "general:wavemapim");
00259         if (cval!=NULL) {
00260                 strcpy (cfg -> wavemapim , cval ) ;
00261         } else {
00262             cpl_msg_error("parse_section_general:"," Wavemapim in the .ini file was not found!\n") ;
00263             (*status)++ ;
00264         }
00265 
00266         cval = iniparser_getstr(sym, "general:outname");
00267         if (cval!=NULL) {
00268                 strcpy (cfg -> outName , cval );
00269         } else {
00270             cpl_msg_error("parse_section_general:"," OutName in the .ini file was not found!\n") ;
00271             (*status)++ ;
00272         }
00273 
00274         if (verbose_active())
00275                 print_memory_parameters();
00276         return ;
00277 }
00278 
00279 static void     parse_section_resampling(
00280         dictionary * sym,
00281         lamp_config * cfg,
00282         int *status
00283 )
00284 {
00285         int             ival ;
00286 
00287         ival = iniparser_getint(sym, "resampling:ncoeffs", -1) ;
00288         if (ival != -1)
00289         {
00290             cfg -> ncoeffs = ival ;
00291         }
00292         else
00293         {
00294             cpl_msg_error("parse_section_resampling:"," ncoeffs in the .ini file was not found!\n") ;
00295             (*status)++ ;
00296         }
00297 
00298         ival = iniparser_getint(sym, "resampling:nrows", -1) ;
00299         if (ival != -1)
00300         {
00301             cfg -> nrows = ival ;
00302         }
00303         else
00304         {
00305             cpl_msg_error("parse_section_resampling:"," nrows in the .ini file was not found!\n") ;
00306             (*status)++ ;
00307         }
00308 
00309         return ;
00310 
00311 }
00312 
00313 static void     parse_section_extractspectrum(
00314         dictionary * sym,
00315         lamp_config * cfg,
00316         int *status )
00317 {
00318         float           dval ;
00319 
00320         dval = iniparser_getdouble(sym, "extractspectrum:loreject", -1.) ;
00321         if (dval!=-1.)
00322         {
00323             cfg -> loReject = dval ;
00324         }
00325         else
00326         {
00327             cpl_msg_error("parse_section_extractspectrum:"," LoReject in the .ini file was not found!\n") ;
00328             (*status)++ ;
00329         }
00330         dval = iniparser_getdouble(sym, "extractspectrum:hireject", -1.) ;
00331         if (dval!=-1.)
00332         {
00333             cfg -> hiReject = dval ;
00334         }
00335         else
00336         {
00337             cpl_msg_error("parse_section_extractspectrum:"," hiReject in the .ini file was not found!\n") ;
00338             (*status)++ ;
00339         }
00340         dval = iniparser_getdouble(sym, "extractspectrum:countstointensity", -1.) ;
00341         if (dval!=-1.)
00342         {
00343             cfg -> countsToIntensity = dval ;
00344         }
00345         else
00346         {
00347             cpl_msg_error("parse_section_extractspectrum:"," CountsToIntensity in the .ini file was not found!\n") ;
00348             (*status)++ ;
00349         }
00350 
00351         return ;
00352 }
00353 

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