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
00039 #include <xsh_drl.h>
00040 #include <xsh_pfits.h>
00041 #include <xsh_pfits_qc.h>
00042 #include <xsh_utils.h>
00043 #include <xsh_data_order.h>
00044 #include <xsh_error.h>
00045 #include <xsh_utils.h>
00046 #include <xsh_msg.h>
00047 #include <xsh_data_pre.h>
00048 #include <xsh_data_order.h>
00049 #include <xsh_data_wavesol.h>
00050 #include <xsh_data_resid_tab.h>
00051 #include <xsh_data_wavemap.h>
00052 #include <xsh_data_spectralformat.h>
00053 #include <xsh_model_io.h>
00054 #include <xsh_model_kernel.h>
00055 #include <cpl.h>
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 void xsh_create_map( cpl_frame *dispsol_frame, cpl_frame *ordertab_frame,
00078 cpl_frame *pre_frame, xsh_instrument *instrument, cpl_frame **wavemap_frame,
00079 cpl_frame **slitmap_frame,const char* rec_prefix)
00080 {
00081 xsh_dispersol_list *dispersol_tab = NULL;
00082 xsh_pre *pre = NULL;
00083 char wavemap_tag[80];
00084 char slitmap_tag[80];
00085
00086 XSH_ASSURE_NOT_NULL( dispsol_frame);
00087 XSH_ASSURE_NOT_NULL( ordertab_frame);
00088 XSH_ASSURE_NOT_NULL( pre_frame);
00089 XSH_ASSURE_NOT_NULL( instrument);
00090 XSH_ASSURE_NOT_NULL( wavemap_frame);
00091 XSH_ASSURE_NOT_NULL( slitmap_frame);
00092
00093
00094 check( pre = xsh_pre_load( pre_frame, instrument));
00095 check( dispersol_tab = xsh_dispersol_list_load( dispsol_frame,
00096 instrument));
00097 sprintf(wavemap_tag,"%s_%s",
00098 rec_prefix,XSH_GET_TAG_FROM_ARM( XSH_WAVE_MAP_POLY, instrument));
00099 sprintf(slitmap_tag,"%s_%s",
00100 rec_prefix,XSH_GET_TAG_FROM_ARM( XSH_SLIT_MAP_POLY, instrument));
00101
00102 check( *wavemap_frame = xsh_dispersol_list_to_wavemap( dispersol_tab,
00103 ordertab_frame, pre, instrument,wavemap_tag));
00104 check( *slitmap_frame = xsh_dispersol_list_to_slitmap( dispersol_tab,
00105 ordertab_frame,
00106 pre, instrument,
00107 slitmap_tag));
00108
00109 cleanup:
00110 xsh_dispersol_list_free( &dispersol_tab);
00111 xsh_pre_free( &pre);
00112 return;
00113 }
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126 void xsh_create_model_map( cpl_frame* model_frame, xsh_instrument* instrument,
00127 const char* wtag, const char* stag,
00128 cpl_frame **wavemap_frame,
00129 cpl_frame **slitmap_frame)
00130 {
00131 xsh_xs_3 model_config;
00132
00133
00134 XSH_ASSURE_NOT_NULL( model_frame);
00135 XSH_ASSURE_NOT_NULL( instrument);
00136 XSH_ASSURE_NOT_NULL( wavemap_frame);
00137 XSH_ASSURE_NOT_NULL( slitmap_frame);
00138 XSH_ASSURE_NOT_NULL( wtag);
00139 XSH_ASSURE_NOT_NULL( stag);
00140
00141 check( xsh_model_config_load_best( model_frame, &model_config));
00142
00143
00144
00145
00146
00147
00148 check( xsh_model_binxy( &model_config, instrument->binx,
00149 instrument->biny));
00150
00151 check(xsh_model_maps_create(&model_config,instrument,wtag,stag,
00152 wavemap_frame,slitmap_frame));
00153
00154
00155
00156
00157
00158
00159
00160 cleanup:
00161
00162
00163 return;
00164 }
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194 cpl_frame *
00195 xsh_create_poly_wavemap( cpl_frame *pre_frame,
00196 cpl_frame *wave_tab_2d_frame,
00197 cpl_frame *order_tab_frame,
00198 cpl_frame *spectral_format_frame,
00199 xsh_dispersol_param *dispsol_par,
00200 xsh_instrument * instrument,
00201 const char * wm_tag,
00202 cpl_frame **dispersol_frame,
00203 cpl_frame** slitmap_frame)
00204 {
00205 xsh_pre *pre = NULL;
00206 xsh_spectralformat_list *spec_list = NULL;
00207 xsh_wavesol *wave_tab_2d = NULL;
00208 cpl_frame *result = NULL ;
00209 float slit_step = 1.5;
00210 float lambda_step = 0.1;
00211 float sol_min_lambda=0, sol_max_lambda=0;
00212 float sol_min_slit, sol_max_slit;
00213 int sol_min_order, sol_max_order;
00214 int i, idx, size, slit_size;
00215 double j, k;
00216 double *vlambda = NULL, *vslit = NULL, *vorder = NULL;
00217 double *pos_x = NULL, *pos_y = NULL;
00218
00219 xsh_wavemap_list *wm_list = NULL ;
00220 int binx, biny ;
00221 char wm_name[80];
00222
00223
00224 XSH_ASSURE_NOT_NULL( wave_tab_2d_frame);
00225 XSH_ASSURE_NOT_NULL( order_tab_frame);
00226 XSH_ASSURE_NOT_NULL( spectral_format_frame);
00227 XSH_ASSURE_NOT_NULL( dispsol_par);
00228 XSH_ASSURE_NOT_NULL( instrument);
00229 XSH_ASSURE_NOT_NULL( dispersol_frame);
00230
00231
00232 if (pre_frame != NULL){
00233 check( pre = xsh_pre_load( pre_frame, instrument));
00234 }
00235
00236 check( binx = xsh_instrument_get_binx( instrument )) ;
00237 check( biny = xsh_instrument_get_biny( instrument )) ;
00238
00239 check( spec_list = xsh_spectralformat_list_load( spectral_format_frame,
00240 instrument));
00241 check( wave_tab_2d = xsh_wavesol_load( wave_tab_2d_frame,
00242 instrument ));
00243
00244 check( xsh_wavesol_set_bin_x( wave_tab_2d, binx ) ) ;
00245 check( xsh_wavesol_set_bin_y( wave_tab_2d, binx ) ) ;
00246
00247 sol_min_lambda = wave_tab_2d->min_lambda;
00248 sol_max_lambda = wave_tab_2d->max_lambda;
00249 sol_min_order = wave_tab_2d->min_order;
00250 sol_max_order = wave_tab_2d->max_order;
00251 sol_min_slit = wave_tab_2d->min_slit;
00252 sol_max_slit = wave_tab_2d->max_slit;
00253 xsh_msg("sol lambda %f,%f order %d,%d slit %f,%f",
00254 sol_min_lambda,sol_max_lambda, sol_min_order, sol_max_order,
00255 sol_min_slit, sol_max_slit);
00256
00257
00258 slit_size = (int)((sol_max_slit-sol_min_slit)/slit_step)+1;
00259
00260 size=0;
00261 for( i=0; i< spec_list->size; i++){
00262 float lambda_min, lambda_max;
00263 int lambda_size;
00264
00265 lambda_min = spec_list->list[i].lambda_min_full;
00266 lambda_max = spec_list->list[i].lambda_max_full;
00267 XSH_ASSURE_NOT_ILLEGAL_MSG(lambda_max>= lambda_min,
00268 "lambda_max< lambda_min!! Check input spectralformat table, columns WLMAXFUL and WLMINFUL");
00269 lambda_size = (int)((lambda_max-lambda_min)/lambda_step)+1;
00270 size += lambda_size*slit_size;
00271 }
00272 xsh_msg_dbg_medium( "size %d", size ) ;
00273
00274 idx = 0;
00275 XSH_MALLOC( vorder, double, size);
00276 XSH_MALLOC( vlambda, double, size);
00277 XSH_MALLOC( vslit, double, size);
00278 XSH_MALLOC( pos_x, double, size);
00279 XSH_MALLOC( pos_y, double, size);
00280
00281 for( i=0; i< spec_list->size; i++){
00282 double absorder;
00283 float lambda_min, lambda_max;
00284
00285 absorder= (double)spec_list->list[i].absorder;
00286 lambda_min = spec_list->list[i].lambda_min_full;
00287 lambda_max = spec_list->list[i].lambda_max_full;
00288 xsh_msg("order %f lambda %f-%f",absorder, lambda_min, lambda_max);
00289
00290 for(j=lambda_min; j <= lambda_max; j+=lambda_step){
00291 for( k=sol_min_slit; k <= sol_max_slit; k+=slit_step){
00292 double x, y;
00293
00294 check( x = xsh_wavesol_eval_polx( wave_tab_2d, j, absorder, k));
00295 check( y = xsh_wavesol_eval_poly( wave_tab_2d, j, absorder, k));
00296 vorder[idx] = absorder;
00297 vlambda[idx] = j;
00298 vslit[idx] = k;
00299 pos_x[idx] = x;
00300 pos_y[idx] = y;
00301 idx++;
00302 }
00303 }
00304 xsh_msg_dbg_medium( "i %d idx %d / %d", i, idx, size);
00305 }
00306
00307 if ( xsh_debug_level_get() >= XSH_DEBUG_LEVEL_MEDIUM){
00308 FILE *test = NULL;
00309 int itest;
00310
00311 test = fopen( "wavemap_grid.log", "w");
00312 for( itest=0; itest < size; itest++){
00313 fprintf(test, "%f %f\n", pos_x[itest], pos_y[itest]);
00314 }
00315 fclose(test);
00316 }
00317
00318
00319 check( wm_list = xsh_wavemap_list_create( instrument));
00320 #if 0
00321 check( xsh_wavemap_list_compute( vlambda, pos_x, pos_y, size,
00322 vorder, wm_par, wm_list));
00323 #else
00324
00325
00326
00327
00328
00329
00330 check( xsh_wavemap_list_compute_poly( vlambda, vslit, pos_x, pos_y, idx,
00331 vorder, dispsol_par, wm_list));
00332 #endif
00333 sprintf(wm_name,"%s.fits",wm_tag);
00334 check( result = xsh_wavemap_list_save_poly( wm_list, order_tab_frame,
00335 pre, instrument, wm_tag, dispersol_frame, slitmap_frame));
00336 if ( pre != NULL){
00337 check( xsh_add_temporary_file( wm_name));
00338 check( cpl_frame_set_tag( result,wm_tag));
00339 check( cpl_frame_set_tag( *slitmap_frame,
00340 XSH_GET_TAG_FROM_ARM( XSH_SLIT_MAP_POLY, instrument)));
00341 }
00342 cleanup:
00343
00344 XSH_FREE( vorder);
00345 XSH_FREE( vlambda);
00346 XSH_FREE( vslit);
00347 XSH_FREE( pos_x);
00348 XSH_FREE( pos_y);
00349 xsh_pre_free( &pre);
00350 xsh_spectralformat_list_free( &spec_list);
00351 xsh_wavesol_free( &wave_tab_2d);
00352 xsh_wavemap_list_free( &wm_list);
00353 return result;
00354 }
00355
00356
00357
00358 cpl_frame*
00359 xsh_create_dispersol_physmod(cpl_frame *pre_frame,
00360 cpl_frame *order_tab_frame,
00361 cpl_frame* mod_cfg_frame,
00362 cpl_frame* wave_map_frame,
00363 cpl_frame* slit_map_frame,
00364 xsh_dispersol_param *dispsol_param,
00365 cpl_frame* spectral_format_frame,
00366 xsh_instrument* instrument)
00367 {
00368
00369
00370 xsh_pre *pre = NULL;
00371 cpl_frame* disp_frame=NULL;
00372 xsh_spectralformat_list *spec_list = NULL;
00373 int binx=0, biny=0 ;
00374 xsh_xs_3 model_config;
00375 int slit_size=0;
00376 int slit_step=1.5;
00377
00378
00379 float sol_min_lambda=0, sol_max_lambda=0;
00380 float sol_min_slit=0, sol_max_slit=0;
00381 int sol_min_order=0, sol_max_order=0;
00382 cpl_image* wmap_ima=NULL;
00383 cpl_image* smap_ima=NULL;
00384 const char* name=NULL;
00385 int size=0;
00386 int i=0;
00387 int idx=0;
00388 float lambda_step=0.1;
00389
00390 double *vlambda = NULL, *vslit = NULL, *vorder = NULL;
00391 double *pos_x = NULL, *pos_y = NULL;
00392 double j=0;
00393 double k=0;
00394
00395 xsh_wavemap_list *wm_list = NULL ;
00396 cpl_frame* result=NULL;
00397 char wm_tag[80];
00398 char wm_name[80];
00399
00400
00401 XSH_ASSURE_NOT_NULL_MSG(mod_cfg_frame,"Null model cfg frame!");
00402 XSH_ASSURE_NOT_NULL_MSG(spectral_format_frame,"Null spectral format frame!");
00403 XSH_ASSURE_NOT_NULL_MSG( instrument,"Null instrument setting!");
00404
00405 if (pre_frame != NULL){
00406 check( pre = xsh_pre_load( pre_frame, instrument));
00407 }
00408
00409
00410 check( binx = xsh_instrument_get_binx( instrument )) ;
00411 check( biny = xsh_instrument_get_biny( instrument )) ;
00412 check(spec_list=xsh_spectralformat_list_load(spectral_format_frame,
00413 instrument));
00414 check( xsh_model_config_load_best( mod_cfg_frame, &model_config));
00415 check( xsh_model_binxy( &model_config, instrument->binx,
00416 instrument->biny));
00417
00418 name=cpl_frame_get_filename(wave_map_frame);
00419 wmap_ima=cpl_image_load(name,CPL_TYPE_FLOAT,0,0);
00420
00421 name=cpl_frame_get_filename(slit_map_frame);
00422 smap_ima=cpl_image_load(name,CPL_TYPE_FLOAT,0,0);
00423
00424
00425 sol_min_lambda = cpl_image_get_min(wmap_ima);
00426 sol_max_lambda = cpl_image_get_max(wmap_ima);
00427 xsh_free_image(&wmap_ima);
00428
00429 sol_min_slit = cpl_image_get_min(smap_ima);
00430 sol_max_slit = cpl_image_get_max(smap_ima);
00431 xsh_free_image(&smap_ima);
00432
00433
00434 slit_size = (int)((sol_max_slit-sol_min_slit)/slit_step)+1;
00435
00436 size=0;
00437 for( i=0; i< spec_list->size; i++){
00438 float lambda_min, lambda_max;
00439 int lambda_size;
00440
00441 sol_min_order = (sol_min_order > spec_list->list[i].absorder) ? spec_list->list[i].absorder : sol_min_order;
00442 sol_max_order = (sol_max_order < spec_list->list[i].absorder) ? spec_list->list[i].absorder : sol_max_order;
00443
00444 lambda_min = spec_list->list[i].lambda_min_full;
00445 lambda_max = spec_list->list[i].lambda_max_full;
00446 XSH_ASSURE_NOT_ILLEGAL_MSG(lambda_max>= lambda_min,
00447 "lambda_max< lambda_min!! Check input spectralformat table, columns WLMAXFUL and WLMINFUL");
00448 lambda_size = (int)((lambda_max-lambda_min)/lambda_step)+1;
00449 size += lambda_size*slit_size;
00450 }
00451 xsh_msg_dbg_medium( "size %d", size ) ;
00452
00453
00454
00455
00456 idx = 0;
00457 XSH_MALLOC( vorder, double, size);
00458 XSH_MALLOC( vlambda, double, size);
00459 XSH_MALLOC( vslit, double, size);
00460 XSH_MALLOC( pos_x, double, size);
00461 XSH_MALLOC( pos_y, double, size);
00462
00463 for( i=0; i< spec_list->size; i++){
00464 double absorder;
00465 float lambda_min, lambda_max;
00466 int morder=0;
00467
00468 absorder= (double)spec_list->list[i].absorder;
00469 morder= spec_list->list[i].absorder;
00470 lambda_min = spec_list->list[i].lambda_min_full;
00471 lambda_max = spec_list->list[i].lambda_max_full;
00472 xsh_msg("order %f lambda %f-%f",absorder, lambda_min, lambda_max);
00473
00474 for(j=lambda_min; j <= lambda_max; j+=lambda_step){
00475 for( k=sol_min_slit; k <= sol_max_slit; k+=slit_step){
00476 double x, y;
00477 xsh_model_get_xy(&model_config,instrument,j,morder,k,&x,&y);
00478 vorder[idx] = absorder;
00479 vlambda[idx] = j;
00480 vslit[idx] = k;
00481 pos_x[idx] = x;
00482 pos_y[idx] = y;
00483 idx++;
00484 }
00485 }
00486 xsh_msg_dbg_medium( "i %d idx %d / %d", i, idx, size);
00487 }
00488
00489 if ( xsh_debug_level_get() >= XSH_DEBUG_LEVEL_MEDIUM){
00490 FILE *test = NULL;
00491 int itest;
00492
00493 test = fopen( "wavemap_grid.log", "w");
00494 for( itest=0; itest < size; itest++){
00495 fprintf(test, "%f %f\n", pos_x[itest], pos_y[itest]);
00496 }
00497 fclose(test);
00498 }
00499
00500
00501 check( wm_list = xsh_wavemap_list_create( instrument));
00502
00503 check( xsh_wavemap_list_compute_poly( vlambda, vslit, pos_x, pos_y, idx,
00504 vorder, dispsol_param, wm_list));
00505
00506 sprintf(wm_tag,"WAVE_MAP_POLY_%s",xsh_instrument_arm_tostring(instrument));
00507 sprintf(wm_name,"%s.fits",wm_name);
00508 check( result = xsh_wavemap_list_save_poly( wm_list, order_tab_frame,
00509 pre, instrument, wm_tag,
00510 &disp_frame, &slit_map_frame));
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521 cleanup:
00522 xsh_free_image(&wmap_ima);
00523 xsh_free_image(&smap_ima);
00524
00525 XSH_FREE( vorder);
00526 XSH_FREE( vlambda);
00527 XSH_FREE( vslit);
00528 XSH_FREE( pos_x);
00529 XSH_FREE( pos_y);
00530 xsh_pre_free( &pre);
00531 xsh_spectralformat_list_free( &spec_list);
00532 xsh_wavemap_list_free( &wm_list);
00533 return disp_frame;
00534 }
00535
00536
00537
00549
00550
00551 cpl_error_code
00552 xsh_wavemap_qc(cpl_frame* frm_map,const cpl_frame* frm_tab)
00553 {
00554 int sx=0;
00555 int sy=0;
00556 double* cx=NULL;
00557 double* cy=NULL;
00558 int wx=0;
00559 int wy=0;
00560 cpl_image* ima=NULL;
00561 const char* name_tab=NULL;
00562 const char* name_map=NULL;
00563 char qc_wlen[40];
00564 double* pima=NULL;
00565 cpl_propertylist* plist=NULL;
00566 cpl_table* tab=NULL;
00567 cpl_table* ext=NULL;
00568
00569 double wlen=0;
00570 int ord_min=0;
00571 int ord_max=0;
00572 int i=0;
00573 int next=0;
00574
00575 XSH_ASSURE_NOT_NULL(frm_map);
00576 XSH_ASSURE_NOT_NULL(frm_tab);
00577 check(name_tab=cpl_frame_get_filename(frm_tab));
00578 check(tab=cpl_table_load(name_tab,2,0));
00579 check(ord_min=cpl_table_get_column_min(tab,"ABSORDER"));
00580 check(ord_max=cpl_table_get_column_max(tab,"ABSORDER"));
00581
00582
00583 name_map=cpl_frame_get_filename(frm_map);
00584 ima=cpl_image_load(name_map,CPL_TYPE_DOUBLE,0,0);
00585 pima=cpl_image_get_data_double(ima);
00586 sx=cpl_image_get_size_x(ima);
00587 sy=cpl_image_get_size_y(ima);
00588 plist=cpl_propertylist_load(name_map,0);
00589 for(i=ord_min;i<=ord_max;i++) {
00590 next=cpl_table_and_selected_int(tab,"ABSORDER",CPL_EQUAL_TO,i);;
00591 ext=cpl_table_extract_selected(tab);
00592 cx=cpl_table_get_data_double(ext,"CENTER_X");
00593 cy=cpl_table_get_data_double(ext,"CENTER_Y");
00594 wx=cx[next/2];
00595 wy=cy[next/2];
00596 wlen=pima[wx+sx*wy];
00597 sprintf(qc_wlen,"%s%d",XSH_QC_WMAP_WAVEC,i);
00598 cpl_propertylist_append_double(plist,qc_wlen,wlen);
00599 xsh_free_table(&ext);
00600 cpl_table_select_all(tab);
00601
00602 }
00603
00604 check(xsh_update_pheader_in_image_multi(frm_map,plist));
00605
00606 cleanup:
00607 xsh_free_image(&ima);
00608 xsh_free_table(&tab);
00609 xsh_free_table(&ext);
00610 xsh_free_propertylist(&plist);
00611 return cpl_error_get_code();
00612 }
00613
00614
00615
00627
00628
00629 cpl_error_code
00630 xsh_wavetab_qc(cpl_frame* frm_tab, const int is_poly)
00631 {
00632
00633 cpl_table* ext=NULL;
00634 const char* name_tab=NULL;
00635 cpl_table* tab=NULL;
00636 cpl_table* tbl=NULL;
00637 int nsel=0;
00638 int ord_min=0;
00639 int ord_max=0;
00640 int i=0;
00641 int j=0;
00642 cpl_vector* loc_vec=NULL;
00643 double* pvec=NULL;
00644 double* pvec_all_ord=NULL;
00645 double* py=NULL;
00646 double ymin=0;
00647 double ymax=0;
00648 double ymin_all=FLT_MAX;
00649 double ymax_all=FLT_MIN;
00650
00651 double ymed=0;
00652 double yavg=0;
00653 char qc_line[40];
00654 cpl_propertylist* plist=NULL;
00655 cpl_vector* vec_all_ord=NULL;
00656 int ymin_all_ord=0;
00657 int ymax_all_ord=0;
00658
00659 XSH_ASSURE_NOT_NULL(frm_tab);
00660
00661 check(name_tab=cpl_frame_get_filename(frm_tab));
00662 check(tab=cpl_table_load(name_tab,1,0));
00663 check(ord_min=cpl_table_get_column_min(tab,"Order"));
00664 check(ord_max=cpl_table_get_column_max(tab,"Order"));
00665 check(plist=cpl_propertylist_load(name_tab,0));
00666
00667 check(nsel=cpl_table_and_selected_int(tab,"Slit_index",CPL_EQUAL_TO,4));
00668 check(ext=cpl_table_extract_selected(tab));
00669
00670 check(vec_all_ord=cpl_vector_new(ord_max-ord_min+1));
00671 check(pvec_all_ord=cpl_vector_get_data(vec_all_ord));
00672
00673 for(i=ord_min;i<=ord_max;i++) {
00674 check(nsel=cpl_table_and_selected_int(ext,"Order",CPL_EQUAL_TO,i));
00675 check(tbl=cpl_table_extract_selected(ext));
00676
00677 if(nsel>1) {
00678 check(loc_vec=cpl_vector_new(nsel-1));
00679 check(pvec=cpl_vector_get_data(loc_vec));
00680
00681 if(is_poly) {
00682 py=cpl_table_get_data_double(tbl,"Ypoly");
00683 } else {
00684 py=cpl_table_get_data_double(tbl,"Ythanneal");
00685 }
00686
00687 for(j=0;j<nsel-1;j++) {
00688 pvec[j]=fabs(py[j+1]-py[j]);
00689
00690 if(pvec[j]>ymax_all) {
00691 ymax_all=pvec[j];
00692 ymax_all_ord=i;
00693 }
00694 if(pvec[j]<ymin_all) {
00695 ymin_all=pvec[j];
00696 ymin_all_ord=i;
00697 }
00698
00699
00700 }
00701
00702 check(ymin=cpl_vector_get_min(loc_vec));
00703 check(ymax=cpl_vector_get_max(loc_vec));
00704 check(ymed=cpl_vector_get_median(loc_vec));
00705 check(yavg=cpl_vector_get_mean(loc_vec));
00706 check(pvec_all_ord[i-ord_min]=yavg);
00707
00708
00709
00710 sprintf(qc_line,"%s%d",XSH_QC_LINE_DIFMIN,i);
00711 check(cpl_propertylist_append_double(plist,qc_line,ymin));
00712 check(cpl_propertylist_set_comment(plist,qc_line,XSH_QC_LINE_DIFMIN_C));
00713
00714 sprintf(qc_line,"%s%d",XSH_QC_LINE_DIFMAX,i);
00715 check(cpl_propertylist_append_double(plist,qc_line,ymax));
00716 check(cpl_propertylist_set_comment(plist,qc_line,XSH_QC_LINE_DIFMAX_C));
00717
00718 sprintf(qc_line,"%s%d",XSH_QC_LINE_DIFMED,i);
00719 check(cpl_propertylist_append_double(plist,qc_line,ymed));
00720 check(cpl_propertylist_set_comment(plist,qc_line,XSH_QC_LINE_DIFMED_C));
00721
00722 sprintf(qc_line,"%s%d",XSH_QC_LINE_DIFAVG,i);
00723 check(cpl_propertylist_append_double(plist,qc_line,yavg));
00724 check(cpl_propertylist_set_comment(plist,qc_line,XSH_QC_LINE_DIFAVG_C));
00725
00726 xsh_free_vector(&loc_vec);
00727 } else {
00728 xsh_msg_warning("Too few values of 'Slit_index=4' for Order=%d",i);
00729 xsh_msg_warning("No %s (and similar) QC parameters can be generated for order %d",XSH_QC_LINE_DIFMIN,i);
00730 }
00731 check(cpl_table_select_all(ext));
00732 xsh_free_table(&tbl);
00733 }
00734 check(yavg=cpl_vector_get_mean(vec_all_ord));
00735 check(ymax=cpl_vector_get_max(vec_all_ord));
00736 check(ymed=cpl_vector_get_median(vec_all_ord));
00737 check(ymin=cpl_vector_get_min(vec_all_ord));
00738
00739
00740
00741 sprintf(qc_line,"%s",XSH_QC_LINE_DIFMIN);
00742 check(cpl_propertylist_append_double(plist,qc_line,ymin_all));
00743 check(cpl_propertylist_set_comment(plist,qc_line,XSH_QC_LINE_DIFMIN_C));
00744
00745 sprintf(qc_line,"%s",XSH_QC_LINE_DIFMIN_ORD);
00746 check(cpl_propertylist_append_int(plist,qc_line,ymin_all_ord));
00747 check(cpl_propertylist_set_comment(plist,qc_line,XSH_QC_LINE_DIFMIN_C));
00748
00749 sprintf(qc_line,"%s",XSH_QC_LINE_DIFMAX);
00750 check(cpl_propertylist_append_double(plist,qc_line,ymax_all));
00751 check(cpl_propertylist_set_comment(plist,qc_line,XSH_QC_LINE_DIFMAX_C));
00752
00753 sprintf(qc_line,"%s",XSH_QC_LINE_DIFMAX_ORD);
00754 check(cpl_propertylist_append_int(plist,qc_line,ymax_all_ord));
00755 check(cpl_propertylist_set_comment(plist,qc_line,XSH_QC_LINE_DIFMAX_C));
00756
00757 sprintf(qc_line,"%s",XSH_QC_LINE_DIFMED);
00758 check(cpl_propertylist_append_double(plist,qc_line,ymed));
00759 check(cpl_propertylist_set_comment(plist,qc_line,XSH_QC_LINE_DIFMED_C));
00760
00761 sprintf(qc_line,"%s",XSH_QC_LINE_DIFAVG);
00762 check(cpl_propertylist_append_double(plist,qc_line,yavg));
00763 check(cpl_propertylist_set_comment(plist,qc_line,XSH_QC_LINE_DIFAVG_C));
00764
00765 check(cpl_table_select_all(tab));
00766 check(cpl_table_save(tab, plist, NULL,name_tab, CPL_IO_DEFAULT));
00767
00768 cleanup:
00769 xsh_free_table(&tab);
00770 xsh_free_table(&ext);
00771 xsh_free_table(&tbl);
00772 xsh_free_vector(&loc_vec);
00773 xsh_free_vector(&vec_all_ord);
00774 xsh_free_propertylist(&plist);
00775
00776
00777 return cpl_error_get_code();
00778
00779 }
00780