00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifdef HAVE_CONFIG_H
00027 # include <config.h>
00028 #endif
00029
00030
00031
00032 #include "sinfo_lamp_ini.h"
00033
00034
00035
00036 static void parse_section_general(dictionary *, lamp_config *, int *);
00037 static void parse_section_resampling(dictionary *, lamp_config *, int *);
00038 static void
00039 parse_section_extractspectrum(dictionary *, lamp_config *, int *);
00040
00049
00065
00066
00067
00068
00069 int generateLamp_ini_file(
00070 char * ini_name,
00071 char * name_i,
00072 char * name_o,
00073 char * name_c
00074 )
00075 {
00076 FILE * ini_file ;
00077
00078 if (sinfo_file_exists(ini_name)) {
00079 sinfo_msg_warning("overwriting %s", ini_name) ;
00080 }
00081 if ((ini_file = fopen(ini_name, "w")) == (FILE*)NULL) {
00082 sinfo_msg_error("cannot create .ini file %s", ini_name) ;
00083 return -1 ;
00084 }
00085
00086 fprintf(ini_file,
00087 "#\n"
00088 "# Configuration file for the extraction of a halogen lamp spectrumn"
00089 "#\n") ;
00090
00091 fprintf(ini_file, "#\n\n[Eclipse]\n") ;
00092 fprintf(ini_file, "VersionNumber = %s\n\n", get_eclipse_version()) ;
00093 fprintf(ini_file,
00094 "\n"
00095 "#\n"
00096 "# ----- [General] configures various software stuff\n"
00097 "#\n"
00098 "# This section is not mandatory. All eclipse routines\n"
00099 "# should be set once for all in a .eclipse-rc file.\n"
00100 "# If you choose to use the variables here, they will\n"
00101 "# override the settings you have in the environment.\n"
00102 "# See the eclipse installation manual to see what\n"
00103 "# these variables refer to.\n"
00104 "#\n"
00105 "\n"
00106 "[General]\n"
00107 "# MaximumMemory = 512 ; integer, maximum megs to allocate in RAM\n"
00108 "# MaximumSwap = 2048 ; integer, maximum megs to allocate in swap\n"
00109 "# TmpDirName = . ; path to temporary directory\n"
00110 "\n"
00111 "Verbose = no ; verbose mode activation\n"
00112 "Debug = no ; debug mode activation\n"
00113 "\n"
00114 "# LogFile = yes ; activate message logging to a file\n"
00115 "# LogFileName = /tmp/spiffi-log ; log file name\n"
00116 "\n"
00117 "\n") ;
00118 fprintf(ini_file,
00119 "#\n"
00120 "# the following are the names given in the argument of the python script\n"
00121 "#\n"
00122 "\n") ;
00123 fprintf(ini_file,
00124 "InFrame = %s ; input file name\n"
00125 "Wavemapim = %s ; file name of the wavelength map\n"
00126 "OutName = %s ; name of output fits file\n"
00127 , name_i, name_c, name_o ) ;
00128
00129 fprintf(ini_file,
00130 "#\n"
00131 "# [Resampling] resamples the spectra to a given pixel length\n"
00132 "# ExtractSpectrum] takes the clean mean along the spatial pixels \n"
00133 "# by avoiding the bad pixel positions and delivers the final \n"
00134 "# halogen lamp\n" "# spectrum\n"
00135 "\n"
00136 "[Resampling]\n"
00137 "Ncoeffs = 3 ; number of coefficients for the polynomial\n"
00138 " interpolation\n"
00139 "Nrows = 2560 ; number of image rows in the resampled frame\n"
00140 " (2560 for single frames, 5120 for dithered)\n"
00141 "[ExtractSpectrum]\n"
00142 "LoReject = 0.1 ; percentage of rejected low intensity pixels\n"
00143 " before averaging\n"
00144 "HiReject = 0.1 ; percentage of rejected high intensity pixels\n"
00145 " before averaging\n"
00146 "CountsToIntensity = 1. ; intensity conversion factor: counts per\n"
00147 " intensity unit\n"
00148 "\n"
00149 "\n") ;
00150
00151 fclose(ini_file) ;
00152 return 0 ;
00153 }
00154
00155
00156
00167
00168
00169 lamp_config * parse_lamp_ini_file(char * ini_name)
00170 {
00171 dictionary * sym ;
00172 lamp_config * cfg ;
00173 int status ;
00174
00175 if (!sinfo_file_exists(ini_name)) {
00176 sinfo_msg_error("cannot find ini file [%s]: aborting", ini_name) ;
00177 return NULL ;
00178 }
00179 sym = iniparser_load(ini_name) ;
00180 if (sym == NULL) {
00181 sinfo_msg_error("in parsing ini file [%s]: aborting", ini_name) ;
00182 return NULL ;
00183 }
00184
00185 cfg = sinfo_lamp_cfg_create();
00186 if (cfg==NULL) {
00187 sinfo_msg_error("allocating lamp_config struct");
00188 iniparser_freedict(sym) ;
00189 return NULL ;
00190 }
00191
00192
00193
00194
00195
00196
00197 status = 0 ;
00198 parse_section_general (sym, cfg, &status);
00199 parse_section_resampling (sym, cfg, &status);
00200 parse_section_extractspectrum (sym, cfg, &status);
00201
00202 iniparser_freedict(sym);
00203
00204 if (status>0) {
00205 sinfo_msg_error("%d errors in ini file [%s]", status, ini_name);
00206 sinfo_lamp_cfg_destroy(cfg);
00207 cfg = NULL ;
00208 return NULL ;
00209 }
00210 return cfg ;
00211 }
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231 static void
00232 parse_section_general(
00233 dictionary * sym,
00234 lamp_config * cfg,
00235 int *status
00236 )
00237 {
00238 char * cval ;
00239 int ival ;
00240
00241
00242
00243
00244 cval = iniparser_getstr(sym, "eclipse:versionnumber") ;
00245 if (cval!=NULL) {
00246 if (strcmp(cval, get_eclipse_version())) {
00247 sinfo_msg_warning("this ini file produced by version %s", cval);
00248 sinfo_msg_warning("you are running version %s",
00249 get_eclipse_version());
00250 }
00251 } else {
00252 sinfo_msg_warning("no eclipse version number found in file");
00253 }
00254
00255 ival = iniparser_getint(sym, "general:maximummemory", -1);
00256 if (ival>0) sinfo_set_memory_parameter("max_ram", ival);
00257 ival = iniparser_getint(sym, "general:maximumswap", -1);
00258 if (ival>0) sinfo_set_memory_parameter("max_swap", ival);
00259 sinfo_set_verbose(iniparser_getboolean(sym, "general:verbose", 0));
00260 sinfo_set_debug(iniparser_getboolean(sym, "general:debug", 0));
00261
00262 cval = iniparser_getstr(sym, "general:tmpdirname");
00263 if (cval!=NULL) {
00264 sinfo_set_tmpdirname(cval);
00265 } else {
00266 sinfo_set_tmpdirname(".");
00267 }
00268
00269 ival = iniparser_getboolean(sym, "general:logfile", 0);
00270 if (ival) {
00271 cval = iniparser_getstr(sym, "general:logfilename");
00272 if (cval!=NULL) {
00273 sinfo_set_logfile(1);
00274 sinfo_set_logfilename(cval);
00275 } else {
00276 sinfo_set_logfile(0) ;
00277 }
00278 }
00279 cval = iniparser_getstr(sym, "general:inframe");
00280 if (cval!=NULL) {
00281 strcpy (cfg -> inFrame , cval ) ;
00282 } else {
00283 sinfo_msg_error(" InFrame in the .ini file was not found!\n") ;
00284 (*status)++ ;
00285 }
00286 cval = iniparser_getstr(sym, "general:wavemapim");
00287 if (cval!=NULL) {
00288 strcpy (cfg -> wavemapim , cval ) ;
00289 } else {
00290 sinfo_msg_error(" Wavemapim in the .ini file was not found!\n") ;
00291 (*status)++ ;
00292 }
00293
00294 cval = iniparser_getstr(sym, "general:outname");
00295 if (cval!=NULL) {
00296 strcpy (cfg -> outName , cval );
00297 } else {
00298 sinfo_msg_error(" OutName in the .ini file was not found!\n") ;
00299 (*status)++ ;
00300 }
00301
00302 if (sinfo_verbose_active())
00303 sinfo_print_memory_parameters();
00304 return ;
00305 }
00306
00307 static void parse_section_resampling(
00308 dictionary * sym,
00309 lamp_config * cfg,
00310 int *status
00311 )
00312 {
00313 int ival ;
00314
00315 ival = iniparser_getint(sym, "resampling:ncoeffs", -1) ;
00316 if (ival != -1)
00317 {
00318 cfg -> ncoeffs = ival ;
00319 }
00320 else
00321 {
00322 sinfo_msg_error(" ncoeffs in the .ini file was not found!\n") ;
00323 (*status)++ ;
00324 }
00325
00326 ival = iniparser_getint(sym, "resampling:nrows", -1) ;
00327 if (ival != -1)
00328 {
00329 cfg -> nrows = ival ;
00330 }
00331 else
00332 {
00333 sinfo_msg_error(" nrows in the .ini file was not found!\n") ;
00334 (*status)++ ;
00335 }
00336
00337 return ;
00338
00339 }
00340
00341 static void parse_section_extractspectrum(
00342 dictionary * sym,
00343 lamp_config * cfg,
00344 int *status )
00345 {
00346 float dval ;
00347
00348 dval = iniparser_getdouble(sym, "extractspectrum:loreject", -1.) ;
00349 if (dval!=-1.)
00350 {
00351 cfg -> loReject = dval ;
00352 }
00353 else
00354 {
00355 sinfo_msg_error(" LoReject in the .ini file was not found!\n") ;
00356 (*status)++ ;
00357 }
00358 dval = iniparser_getdouble(sym, "extractspectrum:hireject", -1.) ;
00359 if (dval!=-1.)
00360 {
00361 cfg -> hiReject = dval ;
00362 }
00363 else
00364 {
00365 sinfo_msg_error(" hiReject in the .ini file was not found!\n") ;
00366 (*status)++ ;
00367 }
00368 dval=iniparser_getdouble(sym,"extractspectrum:countstointensity",-1.);
00369 if (dval!=-1.)
00370 {
00371 cfg -> countsToIntensity = dval ;
00372 }
00373 else
00374 {
00375 sinfo_msg_error("CountsToIntensity in the .ini file was not found!");
00376 (*status)++ ;
00377 }
00378
00379 return ;
00380 }
00381