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
00027
00028 #ifdef HAVE_CONFIG_H
00029 # include <config.h>
00030 #endif
00031
00032
00033
00034
00035
00036
00037 #include <string.h>
00038 #include "sinfo_wavecal_ini_by_cpl.h"
00039 #include "sinfo_raw_types.h"
00040 #include "sinfo_pro_types.h"
00041 #include "sinfo_ref_types.h"
00042 #include "sinfo_hidden.h"
00043 #include "sinfo_functions.h"
00044 #include "sinfo_utils.h"
00045
00046
00047
00048
00049 static void
00050 parse_section_frames ( wave_config *, cpl_parameterlist* cpl_cfg, cpl_frameset* sof,
00051 cpl_frameset** raw, int* status );
00052
00053 static void
00054 parse_section_findlines ( wave_config *, cpl_parameterlist* cpl_cfg );
00055 static void
00056 parse_section_wavecalib ( wave_config *, cpl_parameterlist* cpl_cfg );
00057 static void
00058 parse_section_wavemap ( wave_config *, cpl_parameterlist* cpl_cfg );
00059 static void
00060 parse_section_qclog ( wave_config *, cpl_parameterlist* cpl_cfg );
00061 static void
00062 parse_section_fitslits ( wave_config *, cpl_parameterlist* cpl_cfg );
00063
00064
00065
00074
00092
00093
00094
00095
00096
00107
00108
00109 wave_config *
00110 sinfo_parse_cpl_input_wave ( cpl_parameterlist* cpl_cfg,
00111 cpl_frameset* sof, cpl_frameset** raw )
00112 {
00113
00114 int status=0;
00115 wave_config * cfg= sinfo_wave_cfg_create();
00116
00117
00118
00119
00120
00121 parse_section_findlines ( cfg, cpl_cfg );
00122 parse_section_wavecalib ( cfg, cpl_cfg );
00123 parse_section_wavemap ( cfg, cpl_cfg );
00124 parse_section_fitslits ( cfg, cpl_cfg );
00125 parse_section_qclog ( cfg, cpl_cfg );
00126 parse_section_frames ( cfg, cpl_cfg, sof, raw, &status );
00127
00128 if ( status > 0 )
00129 {
00130 sinfo_msg_error ( "parsing cpl input" );
00131 sinfo_wave_cfg_destroy ( cfg );
00132 cfg = NULL ;
00133 return NULL ;
00134 }
00135 return cfg ;
00136 }
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159 static void
00160 parse_section_frames ( wave_config * cfg,cpl_parameterlist* cpl_cfg, cpl_frameset* sof,
00161 cpl_frameset** raw, int* status )
00162 {
00163 cpl_frame* frame = NULL;
00164 char spat_res[FILE_NAME_SZ];
00165 char lamp_status[FILE_NAME_SZ];
00166 char band[FILE_NAME_SZ];
00167 int ins_set=0;
00168 int nraw=0;
00169 cpl_parameter* p=NULL;
00170 cpl_table* drs_tab=NULL;
00171 wcal* w=sinfo_wcal_new();
00172 int check=0;
00173
00174 sinfo_extract_raw_frames_type ( sof,raw,PRO_WAVE_LAMP_STACKED );
00175 nraw=cpl_frameset_get_size ( *raw );
00176 if ( nraw==0 )
00177 {
00178 sinfo_extract_raw_frames_type ( sof,raw,PRO_WAVE_NS_STACKED );
00179 }
00180 nraw=cpl_frameset_get_size ( *raw );
00181 if ( nraw==0 )
00182 {
00183 sinfo_extract_raw_frames_type ( sof,raw,PRO_WAVE_SLITPOS_STACKED );
00184 }
00185
00186 nraw=cpl_frameset_get_size ( *raw );
00187 if ( nraw==0 )
00188 {
00189 sinfo_msg ( "Frame %s or %s or %s not found!",
00190 PRO_WAVE_LAMP_STACKED,PRO_WAVE_NS_STACKED,PRO_WAVE_SLITPOS_STACKED );
00191 ( *status ) ++;
00192 return ;
00193 }
00194
00195 frame = cpl_frameset_get_frame ( *raw,0 );
00196 sinfo_get_spatial_res ( frame,spat_res );
00197
00198 switch ( sinfo_frame_is_on ( frame ) )
00199 {
00200 case 0:
00201 strcpy ( lamp_status,"on" );
00202 break;
00203 case 1:
00204 strcpy ( lamp_status,"off" );
00205 break;
00206 case -1:
00207 strcpy ( lamp_status,"undefined" );
00208 break;
00209 default:
00210 strcpy ( lamp_status,"undefined" );
00211 break;
00212
00213
00214 }
00215
00216 sinfo_get_band ( frame,band );
00217 sinfo_msg ( "Spatial resolution: %s lamp status: %s band: %s \n",
00218 spat_res, lamp_status, band );
00219
00220
00221 sinfo_get_ins_set ( band,&ins_set );
00222 if ( NULL != cpl_frameset_find ( sof,PRO_WAVE_LAMP_STACKED ) )
00223 {
00224 frame = cpl_frameset_find ( sof,PRO_WAVE_LAMP_STACKED );
00225 strcpy ( cfg -> inFrame,cpl_frame_get_filename ( frame ) );
00226 }
00227 else if ( NULL != cpl_frameset_find ( sof,PRO_WAVE_NS_STACKED ) )
00228 {
00229 frame = cpl_frameset_find ( sof,PRO_WAVE_NS_STACKED );
00230 strcpy ( cfg -> inFrame,cpl_frame_get_filename ( frame ) );
00231 }
00232 else if ( NULL != cpl_frameset_find ( sof,PRO_WAVE_SLITPOS_STACKED ) )
00233 {
00234 frame = cpl_frameset_find ( sof,PRO_WAVE_SLITPOS_STACKED );
00235 strcpy ( cfg -> inFrame,cpl_frame_get_filename ( frame ) );
00236 }
00237 else
00238 {
00239 sinfo_msg_error ( "Frame %s or %s not found! Exit!",
00240 PRO_WAVE_LAMP_STACKED,PRO_WAVE_NS_STACKED );
00241 ( *status ) ++;
00242 return;
00243 }
00244
00245
00246 if ( NULL != cpl_frameset_find ( sof,DRS_SETUP_WAVE ) )
00247 {
00248 frame = cpl_frameset_find ( sof,DRS_SETUP_WAVE );
00249 strcpy ( cfg -> drs_setup,cpl_frame_get_filename ( frame ) );
00250 drs_tab = cpl_table_load ( cfg->drs_setup,1,0 );
00251 w->wstart=cpl_table_get_double ( drs_tab,"W_START",ins_set,&check );
00252 w->wgdisp1=cpl_table_get_double ( drs_tab,"W_DISP1",ins_set,&check );
00253 w->wgdisp2=cpl_table_get_double ( drs_tab,"W_DISP2",ins_set,&check );
00254 w->hw=cpl_table_get_int ( drs_tab,"W_HW",ins_set,&check );
00255 w->fwhm=cpl_table_get_double ( drs_tab,"W_FWHM",ins_set,&check );
00256 w->min_amp=cpl_table_get_double ( drs_tab,"W_MIN_AMP",ins_set,&check );
00257
00258
00259
00260
00261
00262
00263
00264 w->low_pos=cpl_table_get_int ( drs_tab,"W_LOW_POS",ins_set,&check );
00265 w->hig_pos=cpl_table_get_int ( drs_tab,"W_HI_POS",ins_set,&check );
00266
00267 cfg -> guessBeginWavelength = w->wstart;
00268 cfg -> guessDispersion1 = w->wgdisp1;
00269 cfg -> guessDispersion2 = w->wgdisp2;
00270 p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.half_width" );
00271 if ( sinfo_parameter_get_default_flag ( p ) == 0 )
00272 {
00273
00274 cfg -> halfWidth = w->hw;
00275 }
00276 else
00277 {
00278
00279 }
00280
00281 p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.fwhm" );
00282 if ( sinfo_parameter_get_default_flag ( p ) == 0 )
00283 {
00284 cfg -> fwhm = w->fwhm;
00285
00286 }
00287 else
00288 {
00289
00290 }
00291 p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.min_amplitude" );
00292 if ( sinfo_parameter_get_default_flag ( p ) == 0 )
00293 {
00294 cfg -> minAmplitude = w->min_amp;
00295
00296 }
00297 else
00298 {
00299
00300 }
00301
00302
00303
00304
00305
00306
00307
00308 cfg -> loPos = w->low_pos;
00309 cfg -> hiPos = w->hig_pos;
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327 sinfo_wcal_delete ( w );
00328 cpl_table_delete ( drs_tab );
00329 if ( -1 == sinfo_check_rec_status ( 0 ) )
00330 {
00331 ( *status ) ++;
00332 return;
00333 }
00334
00335 }
00336 else
00337 {
00338 sinfo_msg_error ( "Frame %s not found! Exit!", DRS_SETUP_WAVE );
00339 ( *status ) ++;
00340 return;
00341 }
00342
00343
00344 if ( NULL != cpl_frameset_find ( sof,REF_LINE_OH ) )
00345 {
00346 frame = cpl_frameset_find ( sof,REF_LINE_OH );
00347 strcpy ( cfg -> lineList,cpl_frame_get_filename ( frame ) );
00348 }
00349 else if ( NULL != cpl_frameset_find ( sof,REF_LINE_ARC ) )
00350 {
00351 frame = cpl_frameset_find ( sof,REF_LINE_ARC );
00352 strcpy ( cfg -> lineList,cpl_frame_get_filename ( frame ) );
00353 }
00354 else
00355 {
00356 sinfo_msg_error ( "Frame %s not found! Exit!", REF_LINE_ARC );
00357 ( *status ) ++;
00358 return;
00359 }
00360
00361
00362 if ( NULL != cpl_frameset_find ( sof,PRO_SLIT_POS_GUESS ) )
00363 {
00364 frame = cpl_frameset_find ( sof,PRO_SLIT_POS_GUESS );
00365 strcpy ( cfg -> slitposGuessName,cpl_frame_get_filename ( frame ) );
00366 }
00367 else
00368 {
00369 sinfo_msg ( "Frame %s not found!", PRO_SLIT_POS_GUESS );
00370 }
00371
00372 if ( cfg -> writeParInd ==0 )
00373 {
00374 if ( NULL != cpl_frameset_find ( sof,PRO_WAVE_PAR_LIST ) )
00375 {
00376 frame = cpl_frameset_find ( sof,PRO_WAVE_PAR_LIST );
00377 strcpy ( cfg -> paramsList,cpl_frame_get_filename ( frame ) );
00378 }
00379 else
00380 {
00381 sinfo_msg ( "Frame %s not found!", PRO_WAVE_PAR_LIST );
00382 ( *status ) ++;
00383 return ;
00384 }
00385
00386 }
00387 else
00388 {
00389
00390 strcpy ( cfg -> paramsList, WAVECAL_FIT_PARAMS_OUT_FILENAME );
00391 sinfo_msg ( "cfg -> paramsList %s not given\n",cfg -> paramsList );
00392
00393 }
00394
00395
00396
00397 if ( cfg -> calibIndicator == 0 )
00398 {
00399 if ( NULL != cpl_frameset_find ( sof,PRO_WAVE_COEF_SLIT ) )
00400 {
00401 frame = cpl_frameset_find ( sof,PRO_WAVE_COEF_SLIT );
00402 strcpy ( cfg -> coeffsName,cpl_frame_get_filename ( frame ) );
00403 }
00404 else
00405 {
00406 sinfo_msg_error ( "Frame %s not found! Exit!", PRO_WAVE_COEF_SLIT );
00407 ( *status ) ++;
00408 return;
00409 }
00410 }
00411 else
00412 {
00413
00414 strcpy ( cfg -> coeffsName, WAVECAL_COEFF_SLIT_OUT_FILENAME );
00415 sinfo_msg ( "cfg -> coeffsName %s not given\n",cfg -> coeffsName );
00416
00417 }
00418
00419 strcpy ( cfg -> outName, WAVECAL_OUT_FILENAME );
00420 strcpy ( cfg -> slitposName, WAVECAL_SLIT_POS_OUT_FILENAME );
00421
00422 return;
00423 }
00424
00425
00426 static void
00427 parse_section_findlines ( wave_config * cfg,cpl_parameterlist* cpl_cfg )
00428 {
00429
00430 cpl_parameter* p;
00431
00432 p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.calib_indicator" );
00433 cfg -> calibIndicator = cpl_parameter_get_bool ( p );
00434
00435 p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.min_diff" );
00436 cfg -> mindiff = cpl_parameter_get_double ( p );
00437
00438 p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.half_width" );
00439 cfg -> halfWidth = cpl_parameter_get_int ( p );
00440
00441 p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.sigma" );
00442 cfg -> sigma = cpl_parameter_get_double ( p );
00443
00444 return ;
00445 }
00446
00447 static void
00448 parse_section_wavecalib ( wave_config * cfg,cpl_parameterlist* cpl_cfg )
00449 {
00450 cpl_parameter* p;
00451
00452 p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.fwhm" );
00453 cfg -> fwhm = cpl_parameter_get_double ( p );
00454
00455 p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.min_amplitude" );
00456 cfg -> minAmplitude = cpl_parameter_get_double ( p );
00457
00458 p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.max_residual" );
00459 cfg -> maxResidual = cpl_parameter_get_double ( p );
00460
00461 p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.n_a_coefficients" );
00462 cfg -> nrDispCoefficients = cpl_parameter_get_int ( p );
00463
00464 p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.n_b_coefficients" );
00465 cfg -> nrCoefCoefficients = cpl_parameter_get_int ( p );
00466
00467 p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.sigma_factor" );
00468 cfg -> sigmaFactor = cpl_parameter_get_double ( p );
00469
00470 p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.write_coeffs_ind" );
00471 cfg -> writeCoeffsInd = cpl_parameter_get_bool ( p );
00472
00473 p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.write_par_ind" );
00474 cfg -> writeParInd = cpl_parameter_get_bool ( p );
00475
00476 cfg -> nslitlets = NSLITLETS;
00477
00478 p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.pixel_dist" );
00479 cfg -> pixeldist = cpl_parameter_get_int ( p );
00480
00481 p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.pixel_tol" );
00482 cfg -> pixel_tolerance = cpl_parameter_get_double ( p );
00483
00484 }
00485
00486 static void
00487 parse_section_wavemap ( wave_config * cfg,cpl_parameterlist* cpl_cfg )
00488 {
00489 cpl_parameter* p;
00490
00491 p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.wave_map_ind" );
00492 cfg -> wavemapInd = cpl_parameter_get_bool ( p );
00493
00494 p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.mag_factor" );
00495 cfg -> magFactor = cpl_parameter_get_int ( p );
00496
00497
00498 }
00499
00500 static void
00501 parse_section_fitslits ( wave_config * cfg,cpl_parameterlist* cpl_cfg )
00502 {
00503
00504 cpl_parameter* p;
00505
00506 p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.slit_pos_indicator" );
00507 cfg -> slitposIndicator = cpl_parameter_get_bool ( p );
00508
00509 p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.fit_boltz_indicator" );
00510 cfg -> fitBoltzIndicator = cpl_parameter_get_bool ( p );
00511
00512 p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.fit_edge_indicator" );
00513 cfg -> fitEdgeIndicator = cpl_parameter_get_bool ( p );
00514
00515 p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.estimate_indicator" );
00516 cfg -> estimateIndicator = cpl_parameter_get_bool ( p );
00517
00518 cfg -> loPos = 750;
00519 cfg -> hiPos = 1000;
00520
00521 p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.box_length" );
00522 cfg -> boxLength = cpl_parameter_get_int ( p );
00523
00524 p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.y_box" );
00525 cfg -> yBox = cpl_parameter_get_double ( p );
00526
00527 p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.diff_tol" );
00528 cfg -> diffTol = cpl_parameter_get_double ( p );
00529
00530
00531
00532
00533
00534
00535 }
00536
00537 static void
00538 parse_section_qclog ( wave_config * cfg, cpl_parameterlist* cpl_cfg )
00539 {
00540 cpl_parameter* p;
00541
00542 p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.qc_thresh_min" );
00543 cfg -> qc_thresh_min = cpl_parameter_get_int ( p );
00544
00545
00546 p = cpl_parameterlist_find ( cpl_cfg, "sinfoni.wavecal.qc_thresh_max" );
00547 cfg -> qc_thresh_max = cpl_parameter_get_int ( p );
00548
00549
00550 }
00551
00552 void
00553 sinfo_wavecal_free ( wave_config ** cfg )
00554 {
00555 if ( *cfg != NULL )
00556 {
00557 sinfo_wave_cfg_destroy ( *cfg );
00558 *cfg=NULL;
00559 }
00560 return;
00561
00562 }
00563
00564