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
00029 #ifdef HAVE_CONFIG_H
00030 #include <config.h>
00031 #endif
00032
00033
00044
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 #include <xsh_error.h>
00057
00058 #include <xsh_utils.h>
00059 #include <xsh_msg.h>
00060
00061 #include <xsh_dfs.h>
00062 #include <xsh_pfits.h>
00063 #include <xsh_utils_table.h>
00064 #include <xsh_data_resid_tab.h>
00065
00066 #include <xsh_data_order.h>
00067 #include <xsh_drl.h>
00068 #include <xsh_drl_check.h>
00069 #include <xsh_model_kernel.h>
00070 #include <xsh_model_arm_constants.h>
00071
00072
00073
00074 #include <cpl.h>
00075
00076
00077
00078 #include <xsh_data_arclist.h>
00079
00080
00081
00082
00083 #define RECIPE_ID "xsh_predict"
00084 #define RECIPE_AUTHOR "P.Goldoni, L.Guglielmi, R. Haigron, F. Royer, P. Bristow, D. Bramich, A. Modigliani"
00085 #define RECIPE_CONTACT "amodigli@eso.org"
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095 static int xsh_predict_create(cpl_plugin *);
00096 static int xsh_predict_exec(cpl_plugin *);
00097 static int xsh_predict_destroy(cpl_plugin *);
00098
00099
00100 static void xsh_predict(cpl_parameterlist *, cpl_frameset *);
00101
00102
00103
00104
00105 static char xsh_predict_description_short[] =
00106 "Compute a first guess dispersion solution and order table";
00107
00108 static char xsh_predict_description[] =
00109 "This recipe creates a wavelength solution and an order table.\n\
00110 Input Frames :\n\
00111 - [UVB, VIS] One RAW frame (Format = RAW, Tag = FMTCHK_arm)\n\
00112 - [NIR] Two RAW frames ((Format = RAW, Tag = FMTCHK_arm_ON,\
00113 FMTCHK_arm_OFF)\n\
00114 - A spectral format table (Format = PRE, Tag = SPECTRAL_FORMAT_TAB_arm)\n\
00115 - An arc line list (Format = TABLE, Tag = ARC_LINE_LIST_arm)\n\
00116 - [UVB,VIS,OPTIONAL] A master bias (Format = PRE, Tag = MASTER_BIAS_arm)\n\
00117 - [UVB,VIS,OPTIONAL] A master dark (Format = PRE, Tag = MASTER_DARK_arm)\n\
00118 - [OPTIONAL] A reference badpixel map (Format = QUP, Tag = BP_MAP_RP_arm)\n\
00119 - [OPTIONAL] A non-linear badpixel map (Format = QUP, Tag = BP_MAP_NL_arm)\n\
00120 - [OPTIONAL] Reference list to monitor line intensity (Tag = ARC_LINE_LIST_INTMON_arm)\n \
00121 - [poly mode] A theoretical map (Format = TABLE, Tag = THEO_TAB_SING_arm)\n\
00122 - [physical model mode] A model cfg table (Format = TABLE, Tag = XSH_MOD_CFG_TAB_arm)\n\
00123 Products : \n\
00124 - [poly mode] A wavelength solution (Format = TABLE, PRO.CATG = \
00125 WAVE_TAB_GUESS_arm)\n\
00126 - An order table, PRO.CATG = ORDER_TAB_GUESS_arm\n\
00127 (if at least degree+1 points are found in each order).\n \
00128 - A line identification residual table, PRO.CATG = FMTCHK_RESID_TAB_LINES_arm\n\
00129 - The bias subtracted formatcheck frame, PRO.CATG = FMTCHK_ON_arm\n\
00130 - [physical model mode]An optimized model configuration table, PRO.CATG = XSH_MOD_CFG_OPT_FMT_ARM\n\
00131 Prepare the frames.\n\
00132 For UVB,VIS :\n\
00133 Subtract Master Bias.\n\
00134 Subtract Master Dark\n\
00135 For NIR:\n\
00136 Subtract ON OFF\n\
00137 Compute guess order table and wavelength solution\n";
00138
00139
00140
00141
00142
00151
00152
00153 int cpl_plugin_get_info(cpl_pluginlist *list) {
00154 cpl_recipe *recipe = NULL;
00155 cpl_plugin *plugin = NULL;
00156
00157 recipe = cpl_calloc(1, sizeof(*recipe));
00158 if ( recipe == NULL ){
00159 return -1;
00160 }
00161
00162 plugin = &recipe->interface ;
00163
00164 cpl_plugin_init(plugin,
00165 CPL_PLUGIN_API,
00166 XSH_BINARY_VERSION,
00167 CPL_PLUGIN_TYPE_RECIPE,
00168 RECIPE_ID,
00169 xsh_predict_description_short,
00170 xsh_predict_description,
00171 RECIPE_AUTHOR,
00172 RECIPE_CONTACT,
00173 xsh_get_license(),
00174 xsh_predict_create,
00175 xsh_predict_exec,
00176 xsh_predict_destroy);
00177
00178 cpl_pluginlist_append(list, plugin);
00179
00180 return (cpl_error_get_code() != CPL_ERROR_NONE);
00181 }
00182
00183
00193
00194
00195 static int xsh_predict_create(cpl_plugin *plugin){
00196 cpl_recipe *recipe = NULL;
00197 xsh_clipping_param detarc_clip_param = { 2.0, 10, 0.7, 0, 0.3};
00198 xsh_detect_arclines_param detarc_param = {6, 3, 0, 5, 5, 0, 2, 5.0,
00199 XSH_GAUSSIAN_METHOD, FALSE};
00200 char paramname[256];
00201 cpl_parameter* p=NULL;
00202 const int ival=DECODE_BP_FLAG_DEF;
00203
00204 xsh_init();
00205
00206
00207 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin");
00208
00209
00210 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
00211 CPL_ERROR_TYPE_MISMATCH,
00212 "Plugin is not a recipe");
00213
00214 recipe = (cpl_recipe *)plugin;
00215
00216
00217 recipe->parameters = cpl_parameterlist_new();
00218 assure( recipe->parameters != NULL,
00219 CPL_ERROR_ILLEGAL_OUTPUT,
00220 "Memory allocation failed!");
00221
00222
00223 check( xsh_parameters_generic( RECIPE_ID, recipe->parameters ) ) ;
00224 xsh_parameters_decode_bp(RECIPE_ID,recipe->parameters,ival);
00225 check( xsh_parameters_pre_overscan( RECIPE_ID, recipe->parameters ) ) ;
00226
00227
00228
00229 check(xsh_parameters_detect_arclines_create(RECIPE_ID,recipe->parameters,
00230 detarc_param));
00231 check(xsh_parameters_clipping_detect_arclines_create(RECIPE_ID,
00232 recipe->parameters, detarc_clip_param));
00233
00234
00235
00236
00237 check( xsh_parameters_new_int( recipe->parameters, RECIPE_ID,
00238 "model-maxit",1000,
00239 "Number/10 of annealing iterations "
00240 "if in physical model mode."));
00241
00242 check( xsh_parameters_new_double( recipe->parameters, RECIPE_ID,
00243 "model-anneal-factor",1.0,
00244 "Multiplier applied to the automatic "
00245 "parameter ranges (i.e. when scenario!=0). "
00246 "For routine operations should be 1.0. "
00247 "(physical model mode)."));
00248
00249
00250 sprintf(paramname,"xsh.%s.%s",RECIPE_ID,"model-scenario");
00251
00252
00253 check(p=cpl_parameter_new_enum(paramname,CPL_TYPE_INT,
00254 "selects preset flag and range combinations "
00255 "appropriate to common scenarios: \n"
00256
00257
00258 " 0 - No scenario, input cfg flags and limits "
00259 "used.\n"
00260 " 1 - scenario appropriate for the startup "
00261 "recipe (large ranges for parameters "
00262 "affecting single ph exposures, dist "
00263 "coeff fixed).\n"
00264 " 2 - Like 1, but includes parameters "
00265 "affecting all ph positions.\n"
00266 " 3 - Scenario for use in fine tuning cfg "
00267 "to match routine single pinhole exposures. "
00268 "All parameters affecting 1ph exposures "
00269 "except dist coeffs are included and "
00270 "parameter ranges are small. (For use by "
00271 "predict in 1ph case).\n"
00272 " 4 - Like 3 but includes parameters "
00273 "affecting all ph positions (Standard for "
00274 "use by predict in 9ph case and 2dmap). \n"
00275
00276
00277 ,RECIPE_ID,3,9,-1,0,1,2,3,4,5,6,8));
00278
00279
00280 check(cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,
00281 "model-scenario"));
00282 check(cpl_parameterlist_append(recipe->parameters,p));
00283 cleanup:
00284 if ( cpl_error_get_code() != CPL_ERROR_NONE ){
00285 xsh_error_dump(CPL_MSG_ERROR);
00286 return 1;
00287 }
00288 else {
00289 return 0;
00290 }
00291 }
00292
00293
00299
00300
00301 static int xsh_predict_exec(cpl_plugin *plugin) {
00302 cpl_recipe *recipe = NULL;
00303
00304
00305 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin" );
00306
00307
00308 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
00309 CPL_ERROR_TYPE_MISMATCH, "Plugin is not a recipe");
00310
00311 recipe = (cpl_recipe *)plugin;
00312
00313
00314 xsh_predict(recipe->parameters, recipe->frames);
00315
00316 cleanup:
00317 if ( cpl_error_get_code() != CPL_ERROR_NONE ) {
00318 xsh_error_dump(CPL_MSG_ERROR);
00319 cpl_error_reset();
00320 return 1;
00321 }
00322 else {
00323 return 0;
00324 }
00325 }
00326
00327
00333
00334 static int xsh_predict_destroy(cpl_plugin *plugin)
00335 {
00336 cpl_recipe *recipe = NULL;
00337
00338
00339 assure( plugin != NULL, CPL_ERROR_NULL_INPUT, "Null plugin" );
00340
00341
00342 assure( cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE,
00343 CPL_ERROR_TYPE_MISMATCH, "Plugin is not a recipe");
00344
00345 recipe = (cpl_recipe *)plugin;
00346
00347 xsh_free_parameterlist(&recipe->parameters);
00348
00349 cleanup:
00350 if (cpl_error_get_code() != CPL_ERROR_NONE)
00351 {
00352 return 1;
00353 }
00354 else
00355 {
00356 return 0;
00357 }
00358 }
00359
00360
00368
00369 static void xsh_predict(cpl_parameterlist* parameters, cpl_frameset* frameset)
00370 {
00371 const char* recipe_tags[1] = {XSH_FMTCHK};
00372 int recipe_tags_size = 1;
00373 char tag[256];
00374
00375 xsh_clipping_param* detect_arclines_clipping = NULL;
00376 xsh_detect_arclines_param* detect_arclines_p = NULL;
00377
00378
00379 cpl_frameset* raws = NULL;
00380 cpl_frameset* calib = NULL;
00381 cpl_frameset* on = NULL;
00382 cpl_frameset* off = NULL;
00383 cpl_frameset* on_off = NULL;
00384 cpl_frame* predict_rmbias = NULL;
00385 cpl_frame* predict_rmdark = NULL;
00386 xsh_instrument* instrument = NULL;
00387 int solution_type=XSH_DETECT_ARCLINES_TYPE_MODEL;
00388
00389 cpl_frame* model_config_frame = NULL;
00390 cpl_frame* spectralformat_frame = NULL;
00391 cpl_frame* bpmap = NULL;
00392 cpl_frame* master_bias = NULL;
00393 cpl_frame* master_dark = NULL;
00394 cpl_frame* theo_tab_sing = NULL;
00395 cpl_frame* resid_map = NULL;
00396 cpl_frame* resid_dan = NULL;
00397 cpl_frame* resid_tab_orders_frame = NULL;
00398 cpl_frame *wave_tab_guess_frame = NULL;
00399 cpl_frame *order_tab_recov_frame = NULL;
00400 cpl_frame* arclines = NULL;
00401 cpl_frame* clean_arclines = NULL;
00402 cpl_frame* guess_order_table = NULL;
00403 cpl_frame* guess_wavesol = NULL;
00404 const char* filename=NULL;
00405 cpl_frame* MODEL_CONF_OPT_frame=NULL;
00406
00407 int maxit=200;
00408
00409 int scenario=3;
00410
00411 char paramname[256];
00412 cpl_parameter * p =NULL;
00413 int pre_overscan_corr=0;
00414 cpl_frame * line_intmon = NULL ;
00415 double exptime=0;
00416 cpl_propertylist* plist=NULL;
00417 cpl_boolean mode_phys;
00418 int resid_name_sw=0;
00419
00420
00421
00422 check( xsh_begin( frameset, parameters, &instrument, &raws, &calib,
00423 recipe_tags, recipe_tags_size,
00424 RECIPE_ID, XSH_BINARY_VERSION,
00425 xsh_predict_description_short ) ) ;
00426 check( xsh_instrument_set_mode( instrument, XSH_MODE_SLIT));
00427
00428 xsh_recipe_params_check(parameters,instrument,RECIPE_ID);
00429
00430
00431
00432 mode_phys=xsh_mode_is_physmod(calib,instrument);
00433 check(bpmap=xsh_check_load_master_bpmap(calib,instrument,RECIPE_ID));
00434 check( arclines = xsh_find_arc_line_list( calib, instrument));
00435 check( spectralformat_frame = xsh_find_frame_with_tag( calib,
00436 XSH_SPECTRAL_FORMAT, instrument));
00437
00438
00439 if (!mode_phys) {
00440 theo_tab_sing = xsh_find_frame_with_tag( calib, XSH_THEO_TAB_SING,
00441 instrument);
00442 wave_tab_guess_frame = xsh_find_frame_with_tag( calib, XSH_WAVE_TAB_GUESS,
00443 instrument);
00444 order_tab_recov_frame = xsh_find_frame_with_tag( calib, XSH_ORDER_TAB_RECOV,
00445 instrument);
00446 solution_type = XSH_DETECT_ARCLINES_TYPE_POLY;
00447 } else {
00448 if( NULL == (model_config_frame = xsh_find_frame_with_tag( calib,
00449 XSH_MOD_CFG_TAB,
00450 instrument))){
00451
00452
00453 model_config_frame=xsh_find_frame_with_tag( calib, XSH_MOD_CFG_OPT_REC,
00454 instrument);
00455 }
00456 solution_type = XSH_DETECT_ARCLINES_TYPE_MODEL;
00457 }
00458
00459
00460 if ( xsh_instrument_get_arm(instrument) != XSH_ARM_NIR){
00461
00462 XSH_ASSURE_NOT_ILLEGAL_MSG(cpl_frameset_get_size(raws) == 1,
00463 "Provide one formatcheck frame for UVB,VIS arm");
00464 if((master_bias = xsh_find_frame_with_tag(calib,XSH_MASTER_BIAS,
00465 instrument)) == NULL) {
00466
00467 xsh_msg_warning("Frame %s not provided",XSH_MASTER_BIAS);
00468 xsh_error_reset();
00469 }
00470
00471 if((master_dark = xsh_find_frame_with_tag(calib,XSH_MASTER_DARK,
00472 instrument)) == NULL){
00473 xsh_msg_warning("Frame %s not provided",XSH_MASTER_DARK);
00474 xsh_error_reset();
00475 }
00476 }
00477
00478 else {
00479
00480 check(xsh_dfs_split_nir(raws,&on,&off));
00481 XSH_ASSURE_NOT_ILLEGAL_MSG(cpl_frameset_get_size(on) == 1,
00482 "Provide one formatcheck on frame for NIR arm");
00483 XSH_ASSURE_NOT_ILLEGAL_MSG(cpl_frameset_get_size(off) == 1,
00484 "Provide one formatcheck off frame for NIR arm");
00485 }
00486 check( xsh_instrument_update_from_spectralformat( instrument,
00487 spectralformat_frame));
00488
00489
00490 if((line_intmon = xsh_find_frame_with_tag( calib, XSH_ARC_LINE_LIST_INTMON,
00491 instrument)) == NULL) {
00492 xsh_error_reset();
00493 }
00494
00495
00496
00497 check(detect_arclines_clipping =
00498 xsh_parameters_clipping_detect_arclines_get(RECIPE_ID, parameters));
00499 check(detect_arclines_p = xsh_parameters_detect_arclines_get(RECIPE_ID,
00500 parameters));
00501 check( pre_overscan_corr = xsh_parameters_get_int( parameters, RECIPE_ID,
00502 "pre-overscan-corr"));
00503
00504
00505
00506
00507
00508
00509 if ( xsh_instrument_get_arm(instrument) != XSH_ARM_NIR){
00510 cpl_frame* fmtchk = NULL;
00511
00512
00513 check(xsh_prepare( raws, bpmap, master_bias, XSH_FMTCHK, instrument,
00514 pre_overscan_corr,CPL_TRUE));
00515 check(fmtchk = cpl_frameset_get_first(raws));
00516
00517 if(master_bias != NULL) {
00518
00519 check(predict_rmbias = xsh_subtract_bias(fmtchk,master_bias,
00520 instrument,"FMTCHK_",
00521 pre_overscan_corr,0));
00522 } else {
00523 predict_rmbias =cpl_frame_duplicate(fmtchk);
00524 }
00525
00526 if(master_dark != NULL) {
00527
00528 filename = xsh_stringcat_any( "FMTCHK_DARK_",
00529 xsh_instrument_arm_tostring( instrument ),
00530 ".fits", NULL ) ;
00531
00532
00533 check(predict_rmdark = xsh_subtract_dark(predict_rmbias, master_dark,
00534 filename, instrument));
00535 } else {
00536 predict_rmdark =cpl_frame_duplicate(predict_rmbias);
00537 }
00538
00539 }
00540
00541 else{
00542
00543 check(xsh_prepare(on,bpmap, NULL, "ON", instrument,pre_overscan_corr,CPL_TRUE));
00544
00545 check(xsh_prepare(off,bpmap, NULL, "OFF", instrument,pre_overscan_corr,CPL_TRUE));
00546
00547
00548 check(on_off = xsh_subtract_nir_on_off(on, off, instrument));
00549 check(predict_rmdark = cpl_frame_duplicate(
00550 cpl_frameset_get_first(on_off)));
00551 }
00552
00553 if ( xsh_instrument_get_arm(instrument) != XSH_ARM_NIR){
00554 check(xsh_check_input_is_unbinned(predict_rmdark));
00555 }
00556 plist=cpl_propertylist_load(cpl_frame_get_filename(predict_rmdark),0);
00557 exptime=xsh_pfits_get_exptime(plist);
00558 xsh_free_propertylist(&plist);
00559
00560 xsh_msg("Calling the xsh_detect_arclines");
00561
00562
00563
00564 if(model_config_frame!=NULL) {
00565 resid_name_sw=1;
00566 }
00567 check( xsh_detect_arclines_dan( predict_rmdark, theo_tab_sing,
00568 arclines, wave_tab_guess_frame,
00569 order_tab_recov_frame,
00570 model_config_frame,
00571 spectralformat_frame,
00572 &resid_tab_orders_frame,
00573 &clean_arclines, &guess_wavesol,
00574 &resid_dan, XSH_SOLUTION_RELATIVE,
00575 detect_arclines_p,
00576 detect_arclines_clipping,
00577 instrument,RECIPE_ID,0,resid_name_sw));
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589 resid_map = cpl_frame_duplicate(resid_dan);
00590 cpl_table* resid = NULL;
00591 cpl_table* ext = NULL;
00592 const char* fname = NULL;
00593 char rtag[256];
00594 char fout[256];
00595 cpl_propertylist* phead = NULL;
00596 cpl_propertylist* xhead = NULL;
00597
00598 fname = cpl_frame_get_filename(resid_dan);
00599 resid = cpl_table_load(fname, 1, 0);
00600 phead = cpl_propertylist_load(fname, 0);
00601
00602 cpl_propertylist* qhead = NULL;
00603 qhead=cpl_propertylist_new();
00604 fname = cpl_frame_get_filename(clean_arclines);
00605 plist = cpl_propertylist_load(fname, 0);
00606 cpl_propertylist_copy_property_regexp(qhead, plist, "ESO QC*",0);
00607 cpl_propertylist_append(phead,qhead);
00608 xsh_free_propertylist(&qhead);
00609
00610 sprintf(rtag, "FMTCHK_RESID_TAB_LINES_GFIT_%s",
00611 xsh_instrument_arm_tostring(instrument));
00612 sprintf(fout, "%s.fits", rtag);
00613
00614 cpl_table_and_selected_int(resid, "Flag", CPL_EQUAL_TO, 0);
00615 ext = cpl_table_extract_selected(resid);
00616 cpl_table_save(ext, phead, xhead, fout, CPL_IO_DEFAULT);
00617 xsh_free_table(&resid);
00618 cpl_frame_set_filename(resid_map, fout);
00619 cpl_frame_set_tag(resid_map, rtag);
00620 if(model_config_frame != NULL) {
00621 xsh_add_temporary_file(fout);
00622 }
00623 xsh_free_propertylist(&phead);
00624 xsh_free_table(&ext);
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642 double ann_fac=1.0;
00643 if ( model_config_frame != NULL){
00644 xsh_msg("Produce new config file");
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661 sprintf(paramname,"xsh.%s.%s",RECIPE_ID, "model-maxit");
00662 check(p = cpl_parameterlist_find(parameters,paramname));
00663 check(maxit=cpl_parameter_get_int(p));
00664
00665 sprintf(paramname,"xsh.%s.%s",RECIPE_ID, "model-anneal-factor");
00666 check(p = cpl_parameterlist_find(parameters,paramname));
00667 check(ann_fac=cpl_parameter_get_double(p));
00668
00669 sprintf(paramname,"xsh.%s.%s",RECIPE_ID, "model-scenario");
00670 check(p = cpl_parameterlist_find(parameters,paramname));
00671 check(scenario=cpl_parameter_get_int(p));
00672 xsh_msg("maxit=%d ann_fac=%g scenario=%d",maxit,ann_fac,scenario);
00673
00674 check(MODEL_CONF_OPT_frame=xsh_model_pipe_anneal( model_config_frame, resid_map,
00675 maxit,ann_fac,scenario,1));
00676
00677 }
00678
00679 check( guess_order_table=xsh_create_order_table(predict_rmdark,
00680 spectralformat_frame,
00681 resid_tab_orders_frame,
00682 clean_arclines,
00683 detect_arclines_p,
00684 detect_arclines_clipping,
00685 instrument));
00686
00687
00688 if(line_intmon) {
00689 check(xsh_wavecal_qclog_intmon(resid_map,line_intmon,exptime,instrument));
00690 }
00691
00692
00693
00694
00695 xsh_msg("Saving products");
00696
00697
00698
00699
00700 if ( guess_wavesol != NULL){
00701 check(xsh_add_product_table( guess_wavesol, frameset,
00702 parameters, RECIPE_ID, instrument,NULL));
00703 }
00704 if ( guess_order_table != NULL){
00705 check(xsh_add_product_table( guess_order_table, frameset,
00706 parameters, RECIPE_ID, instrument,NULL));
00707 }
00708 if(model_config_frame == NULL) {
00709 check(xsh_wavetab_qc(resid_map,true));
00710 } else {
00711 check(xsh_wavetab_qc(resid_map,false));
00712 }
00713
00714
00715 if(model_config_frame!=NULL) {
00716
00717 check(xsh_frame_table_resid_merge(resid_dan,resid_map,solution_type));
00718
00719
00720
00721
00722 cpl_table* tab=NULL;
00723 cpl_propertylist* header=NULL;
00724 const char* name=cpl_frame_get_filename(resid_dan);
00725 tab=cpl_table_load(name,1,0);
00726 header=cpl_propertylist_load(name,0);
00727 if(xsh_instrument_get_arm(instrument) == XSH_ARM_NIR){
00728 cpl_table_add_scalar(tab,XSH_RESID_TAB_TABLE_COLNAME_XTHPRE,-0.125);
00729 cpl_table_add_scalar(tab,XSH_RESID_TAB_TABLE_COLNAME_XGAUSS,-0.125);
00730 cpl_table_add_scalar(tab,XSH_RESID_TAB_TABLE_COLNAME_XTHANNEAL,-0.125);
00731 } else if(xsh_instrument_get_arm(instrument) == XSH_ARM_UVB){
00732 cpl_table_add_scalar(tab,XSH_RESID_TAB_TABLE_COLNAME_XTHPRE,+0.51);
00733 cpl_table_add_scalar(tab,XSH_RESID_TAB_TABLE_COLNAME_XGAUSS,+0.51);
00734 cpl_table_add_scalar(tab,XSH_RESID_TAB_TABLE_COLNAME_XTHANNEAL,+0.51);
00735 }
00736 cpl_table_save(tab,header,NULL,name,CPL_IO_DEFAULT);
00737 xsh_free_propertylist(&header);
00738 xsh_free_table(&tab);
00739 check(xsh_add_product_table( resid_dan, frameset,parameters, RECIPE_ID,
00740 instrument,NULL));
00741
00742
00743
00744
00745 } else {
00746 check(xsh_add_product_table( resid_map, frameset,parameters, RECIPE_ID,
00747 instrument,NULL));
00748
00749 }
00750
00751 sprintf(tag,"%s_ON",XSH_FMTCHK);
00752 if ( xsh_instrument_get_arm(instrument) != XSH_ARM_NIR){
00753
00754 check(xsh_add_product_image(predict_rmbias,frameset,parameters,
00755 RECIPE_ID,instrument,tag));
00756
00757 } else {
00758
00759 check(xsh_add_product_image(predict_rmdark,frameset,parameters,
00760 RECIPE_ID,instrument,tag));
00761 }
00762 if ( model_config_frame != NULL){
00763 check(xsh_add_product_table(MODEL_CONF_OPT_frame,frameset,parameters,
00764 RECIPE_ID, instrument,NULL));
00765 }
00766
00767 xsh_msg("xsh_predict success !!");
00768
00769 cleanup:
00770 xsh_end( RECIPE_ID, frameset, parameters );
00771 XSH_FREE(detect_arclines_clipping);
00772 XSH_FREE(detect_arclines_p);
00773 xsh_free_frameset(&raws);
00774 xsh_free_frameset(&calib);
00775 xsh_free_frameset(&on);
00776 xsh_free_frameset(&off);
00777 xsh_free_frameset(&on_off);
00778 xsh_free_frame(&guess_order_table);
00779 xsh_free_frame(&clean_arclines);
00780 xsh_free_frame(&resid_tab_orders_frame);
00781 xsh_free_frame(&resid_map);
00782 xsh_free_frame(&resid_dan);
00783 xsh_free_frame(&guess_wavesol);
00784 xsh_free_frame(&predict_rmbias);
00785 xsh_free_frame(&predict_rmdark);
00786 xsh_free_frame(&MODEL_CONF_OPT_frame);
00787 xsh_free_frame(&bpmap);
00788 xsh_free_propertylist(&plist);
00789
00790 xsh_instrument_free(&instrument);
00791 return;
00792 }
00793