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 #ifdef HAVE_CONFIG_H
00028 #include <config.h>
00029 #endif
00030
00031
00036
00037
00041
00042
00043
00044
00045 #include <xsh_data_resid_tab.h>
00046 #include <xsh_utils.h>
00047 #include <xsh_error.h>
00048 #include <xsh_msg.h>
00049 #include <xsh_pfits.h>
00050 #include <cpl.h>
00051 #include <xsh_drl.h>
00052 #include <xsh_utils_table.h>
00053 #include <xsh_data_wavesol.h>
00054
00055
00056
00057
00058
00059
00081
00082 xsh_resid_tab* xsh_resid_tab_create(int size, double *lambda, double *order,
00083 double *slit, int *slit_index,
00084 double *thpre_x, double *thpre_y, double*corr_x, double* corr_y,
00085 double *gaussian_fit_x, double *gaussian_fit_y, double *gaussian_sigma_x,
00086 double *gaussian_sigma_y, xsh_wavesol *wavesol, int wavesol_type)
00087 {
00088 enum wavesol_type type = XSH_WAVESOL_GUESS;
00089 xsh_resid_tab* result = NULL;
00090 int i;
00091
00092
00093 XSH_ASSURE_NOT_ILLEGAL( size>=0);
00094 XSH_ASSURE_NOT_NULL( lambda);
00095 XSH_ASSURE_NOT_NULL( order);
00096 XSH_ASSURE_NOT_NULL( slit);
00097 XSH_ASSURE_NOT_NULL( slit_index);
00098 XSH_ASSURE_NOT_NULL( thpre_x);
00099 XSH_ASSURE_NOT_NULL( thpre_y);
00100 XSH_ASSURE_NOT_NULL( gaussian_fit_x);
00101 XSH_ASSURE_NOT_NULL( gaussian_fit_y);
00102 XSH_ASSURE_NOT_NULL( gaussian_sigma_x);
00103 XSH_ASSURE_NOT_NULL( gaussian_sigma_y);
00104
00105
00106 XSH_CALLOC( result, xsh_resid_tab, 1);
00107
00108 XSH_CALLOC( result->lambda, double, size);
00109 XSH_CALLOC( result->order, double, size);
00110 XSH_CALLOC( result->slit, double, size);
00111 XSH_CALLOC( result->slit_index, int, size);
00112 XSH_CALLOC( result->thpre_x, double, size);
00113 XSH_CALLOC( result->thpre_y, double, size);
00114 XSH_CALLOC( result->thcor_x, double, size);
00115 XSH_CALLOC( result->thcor_y, double, size);
00116 XSH_CALLOC( result->xgauss, double, size);
00117 XSH_CALLOC( result->ygauss, double, size);
00118 XSH_CALLOC( result->sig_xgauss, double, size);
00119 XSH_CALLOC( result->sig_ygauss, double, size);
00120 XSH_CALLOC( result->xpoly, double, size);
00121 XSH_CALLOC( result->ypoly, double, size);
00122 check (result->header = cpl_propertylist_new());
00123
00124 result->size = size;
00125 result->solution_type = wavesol_type;
00126
00127 if (wavesol != NULL) {
00128 check (type = xsh_wavesol_get_type( wavesol));
00129 }
00130 else{
00131 type = XSH_WAVESOL_UNDEFINED;
00132 }
00133
00134 for( i=0; i<size; i++){
00135 result->lambda[i] = lambda[i];
00136 result->order[i] = order[i];
00137 result->slit[i] = slit[i];
00138 result->slit_index[i] = slit_index[i];
00139 result->thpre_x[i] = thpre_x[i];
00140 result->thpre_y[i] = thpre_y[i];
00141 result->thcor_x[i] = thpre_x[i]+corr_x[i];
00142 result->thcor_y[i] = thpre_y[i]+corr_y[i];
00143 result->xgauss[i] = gaussian_fit_x[i];
00144 result->ygauss[i] = gaussian_fit_y[i];
00145 result->sig_xgauss[i] = gaussian_sigma_x[i];
00146 result->sig_ygauss[i] = gaussian_sigma_y[i];
00147
00148 if ( type == XSH_WAVESOL_2D){
00149 double polx, poly;
00150
00151 check( polx = xsh_wavesol_eval_polx( wavesol, lambda[i],
00152 order[i], slit[i]));
00153 check( poly = xsh_wavesol_eval_poly( wavesol, lambda[i],
00154 order[i], slit[i]));
00155 result->xpoly[i] = polx;
00156 result->ypoly[i] = poly;
00157 }
00158 else if ( type == XSH_WAVESOL_GUESS){
00159 check( result->xpoly[i] = xsh_wavesol_eval_polx( wavesol,
00160 lambda[i], order[i], slit[i])+result->thcor_x[i]);
00161 check( result->ypoly[i] = xsh_wavesol_eval_poly( wavesol,
00162 lambda[i], order[i], slit[i])+result->thcor_y[i]);
00163 }
00164 else{
00165 result->xpoly[i] = 0.0;
00166 result->ypoly[i] = 0.0;
00167 }
00168 }
00169
00170
00171
00172
00173
00174
00175
00176 cleanup:
00177 if ( cpl_error_get_code() != CPL_ERROR_NONE){
00178 xsh_resid_tab_free( &result);
00179 }
00180 return result;
00181 }
00182
00183
00193
00194
00195 xsh_resid_tab* xsh_resid_tab_load( cpl_frame* resid_tab_frame)
00196 {
00197 xsh_resid_tab* result = NULL;
00198 cpl_table* table = NULL;
00199 const char* tablename = NULL;
00200 int i = 0;
00201 int size = 0;
00202 double *lambda = NULL;
00203 double *order = NULL;
00204 double *slit = NULL;
00205 int *slit_index = NULL;
00206 double *thx = NULL;
00207 double *thy = NULL;
00208 double *thcorx = NULL;
00209 double *thcory = NULL;
00210 double *xgauss = NULL;
00211 double *ygauss = NULL;
00212 double *sig_xgauss = NULL;
00213 double *sig_ygauss = NULL;
00214 double *xpoly = NULL;
00215 double *ypoly = NULL;
00216 double *thanneal_x = NULL;
00217 double *thanneal_y = NULL;
00218 int solution_type = XSH_DETECT_ARCLINES_TYPE_POLY;
00219 const char* wavesol_type = NULL;
00220
00221 XSH_ASSURE_NOT_NULL( resid_tab_frame);
00222
00223
00224 check( tablename = cpl_frame_get_filename( resid_tab_frame));
00225
00226 XSH_TABLE_LOAD( table, tablename);
00227
00228 check( size = cpl_table_get_nrow(table));
00229
00230 XSH_CALLOC( result, xsh_resid_tab, 1);
00231 check (result->header = cpl_propertylist_load( tablename, 0));
00232 wavesol_type = xsh_pfits_get_wavesoltype( result->header);
00233 if (cpl_error_get_code() == CPL_ERROR_NONE){
00234 if ( strcmp(wavesol_type, XSH_WAVESOLTYPE_MODEL)==0){
00235 solution_type = XSH_DETECT_ARCLINES_TYPE_MODEL;
00236 }
00237 }
00238 else{
00239 xsh_msg("Can't read keyword %s", XSH_WAVESOLTYPE);
00240 cpl_error_reset();
00241 }
00242 result->size = size;
00243 result->solution_type = solution_type;
00244
00245 XSH_CALLOC( lambda, double, size);
00246 XSH_CALLOC( order, double, size);
00247 XSH_CALLOC( slit, double, size);
00248 XSH_CALLOC( slit_index, int, size);
00249 XSH_CALLOC( thx, double, size);
00250 XSH_CALLOC( thy, double, size);
00251 XSH_CALLOC( thcorx, double, size);
00252 XSH_CALLOC( thcory, double, size);
00253 XSH_CALLOC( xgauss, double, size);
00254 XSH_CALLOC( ygauss, double, size);
00255 XSH_CALLOC( sig_xgauss, double, size);
00256 XSH_CALLOC( sig_ygauss, double, size);
00257 if (solution_type == XSH_DETECT_ARCLINES_TYPE_MODEL){
00258 XSH_CALLOC( thanneal_x, double, size);
00259 XSH_CALLOC( thanneal_y, double, size);
00260 }
00261 else{
00262 XSH_CALLOC( xpoly, double, size);
00263 XSH_CALLOC( ypoly, double, size);
00264 }
00265
00266 for(i=0; i<size;i++){
00267 int orderv, slit_indexv;
00268 double lambdav, slitv, thxv, thyv, thcorxv, thcoryv;
00269 double xgaussv, ygaussv, xpolyv, ypolyv;
00270 double sig_xgaussv, sig_ygaussv;
00271
00272
00273 check( xsh_get_table_value( table,
00274 XSH_RESID_TAB_TABLE_COLNAME_WAVELENGTH,
00275 CPL_TYPE_DOUBLE, i, &lambdav));
00276
00277 check( xsh_get_table_value( table,
00278 XSH_RESID_TAB_TABLE_COLNAME_ORDER,
00279 CPL_TYPE_INT, i, &orderv));
00280
00281 check( xsh_get_table_value( table,
00282 XSH_RESID_TAB_TABLE_COLNAME_SLITPOSITION,
00283 CPL_TYPE_DOUBLE, i, &slitv));
00284
00285 check( xsh_get_table_value( table,
00286 XSH_RESID_TAB_TABLE_COLNAME_SLITINDEX,
00287 CPL_TYPE_INT, i, &slit_indexv));
00288
00289 check( xsh_get_table_value( table,
00290 XSH_RESID_TAB_TABLE_COLNAME_XTHPRE,
00291 CPL_TYPE_DOUBLE, i, &thxv));
00292
00293 check( xsh_get_table_value( table,
00294 XSH_RESID_TAB_TABLE_COLNAME_YTHPRE,
00295 CPL_TYPE_DOUBLE, i, &thyv));
00296
00297 check( xsh_get_table_value( table,
00298 XSH_RESID_TAB_TABLE_COLNAME_XTHCOR,
00299 CPL_TYPE_DOUBLE, i, &thcorxv));
00300
00301 check( xsh_get_table_value( table,
00302 XSH_RESID_TAB_TABLE_COLNAME_YTHCOR,
00303 CPL_TYPE_DOUBLE, i, &thcoryv));
00304
00305 check( xsh_get_table_value( table,
00306 XSH_RESID_TAB_TABLE_COLNAME_XGAUSS,
00307 CPL_TYPE_DOUBLE, i, &xgaussv));
00308
00309 check( xsh_get_table_value( table,
00310 XSH_RESID_TAB_TABLE_COLNAME_YGAUSS,
00311 CPL_TYPE_DOUBLE, i, &ygaussv));
00312
00313 check( xsh_get_table_value( table,
00314 XSH_RESID_TAB_TABLE_COLNAME_SIGMAXGAUSS,
00315 CPL_TYPE_DOUBLE, i, &sig_xgaussv));
00316
00317 check( xsh_get_table_value( table,
00318 XSH_RESID_TAB_TABLE_COLNAME_SIGMAYGAUSS,
00319 CPL_TYPE_DOUBLE, i, &sig_ygaussv));
00320
00321 if (solution_type == XSH_DETECT_ARCLINES_TYPE_MODEL){
00322 check( xsh_get_table_value( table,
00323 XSH_RESID_TAB_TABLE_COLNAME_XTHANNEAL,
00324 CPL_TYPE_DOUBLE, i, &xpolyv));
00325 thanneal_x[i] = xpolyv;
00326 check( xsh_get_table_value( table,
00327 XSH_RESID_TAB_TABLE_COLNAME_YTHANNEAL,
00328 CPL_TYPE_DOUBLE, i, &ypolyv));
00329 thanneal_y[i] = ypolyv;
00330 }
00331 else{
00332 check( xsh_get_table_value( table,
00333 XSH_RESID_TAB_TABLE_COLNAME_XPOLY,
00334 CPL_TYPE_DOUBLE, i, &xpolyv));
00335 xpoly[i] = xpolyv;
00336 check( xsh_get_table_value( table,
00337 XSH_RESID_TAB_TABLE_COLNAME_YPOLY,
00338 CPL_TYPE_DOUBLE, i, &ypolyv));
00339 ypoly[i] = ypolyv;
00340 }
00341 lambda[i] = lambdav;
00342 order[i] = (double) orderv;
00343 slit[i] = slitv;
00344 slit_index[i] = slit_indexv;
00345 thx[i] = thxv;
00346 thy[i] = thyv;
00347 thcorx[i] =thcorxv;
00348 thcory[i] = thcoryv;
00349 xgauss[i] = xgaussv;
00350 ygauss[i] = ygaussv;
00351 sig_xgauss[i] = sig_xgaussv;
00352 sig_ygauss[i] = sig_ygaussv;
00353 }
00354
00355 result->lambda = lambda;
00356 result->order = order;
00357 result->slit = slit;
00358 result->slit_index = slit_index;
00359 result->thpre_x = thx;
00360 result->thpre_y = thy;
00361 result->thcor_x = thcorx;
00362 result->thcor_y = thcory;
00363 result->xgauss = xgauss;
00364 result->ygauss = ygauss;
00365 result->sig_xgauss = sig_xgauss;
00366 result->sig_ygauss = sig_ygauss;
00367 if ( solution_type == XSH_DETECT_ARCLINES_TYPE_MODEL){
00368 result->thanneal_x = thanneal_x;
00369 result->thanneal_y = thanneal_y;
00370 }
00371 else{
00372 result->xpoly = xpoly;
00373 result->ypoly = ypoly;
00374 }
00375
00376 cleanup:
00377 if (cpl_error_get_code () != CPL_ERROR_NONE) {
00378 xsh_error_msg("can't load frame %s",
00379 cpl_frame_get_filename(resid_tab_frame));
00380 xsh_resid_tab_free(&result);
00381 }
00382 XSH_TABLE_FREE( table);
00383 return result;
00384 }
00385
00386
00394
00395 void xsh_resid_tab_free( xsh_resid_tab** resid) {
00396 if ( resid && *resid) {
00397 XSH_FREE( (*resid)->lambda);
00398 XSH_FREE( (*resid)->order);
00399 XSH_FREE( (*resid)->slit);
00400 XSH_FREE( (*resid)->slit_index);
00401 XSH_FREE( (*resid)->thpre_x);
00402 XSH_FREE( (*resid)->thpre_y);
00403 XSH_FREE( (*resid)->thcor_x);
00404 XSH_FREE( (*resid)->thcor_y);
00405 XSH_FREE( (*resid)->xgauss);
00406 XSH_FREE( (*resid)->ygauss);
00407 XSH_FREE( (*resid)->sig_xgauss);
00408 XSH_FREE( (*resid)->sig_ygauss);
00409 XSH_FREE( (*resid)->xpoly);
00410 XSH_FREE( (*resid)->ypoly);
00411 XSH_FREE( (*resid)->thanneal_x);
00412 XSH_FREE( (*resid)->thanneal_y);
00413 xsh_free_propertylist( &(*resid)->header);
00414 cpl_free(*resid);
00415 }
00416 *resid = NULL;
00417 }
00418
00419
00420
00429
00430 void xsh_resid_tab_log( xsh_resid_tab* resid, const char* filename)
00431 {
00432
00433 FILE* logfile = NULL;
00434 int i = 0;
00435
00436 XSH_ASSURE_NOT_NULL( resid);
00437 XSH_ASSURE_NOT_NULL( filename);
00438
00439 logfile = fopen(filename,"w");
00440
00441 if ( resid->solution_type == XSH_DETECT_ARCLINES_TYPE_POLY) {
00442 fprintf( logfile,
00443 "# lambda order slit thx, thy, gaussx, gaussy, xpoly, ypoly");
00444 for ( i=0; i< resid->size; i++){
00445 double lambda, order, slit;
00446
00447 lambda = resid->lambda[i];
00448 order = resid->order[i];
00449 slit = resid->slit[i];
00450 fprintf( logfile,
00451 "%.8lg %.8lg %.8lg %.8lg %.8lg %.8lg %.8lg %.8lg %.8lg\n",
00452 lambda, order, slit, resid->thpre_x[i], resid->thpre_y[i],
00453 resid->xgauss[i], resid->ygauss[i],
00454 resid->xpoly[i], resid->ypoly[i]
00455 );
00456 }
00457 }
00458 else{
00459 fprintf( logfile,
00460 "# lambda order slit thx, thy, gaussx, gaussy, thanneal_x, thanneal_y");
00461 for ( i=0; i< resid->size; i++){
00462 double lambda, order, slit;
00463
00464 lambda = resid->lambda[i];
00465 order = resid->order[i];
00466 slit = resid->slit[i];
00467 fprintf( logfile,
00468 "%.8lg %.8lg %.8lg %.8lg %.8lg %.8lg %.8lg %.8lg %.8lg\n",
00469 lambda, order, slit, resid->thpre_x[i], resid->thpre_y[i],
00470 resid->xgauss[i], resid->ygauss[i],
00471 resid->thanneal_x[i], resid->thanneal_y[i]
00472 );
00473 }
00474 }
00475 fclose( logfile);
00476 cleanup:
00477 return;
00478 }
00479
00480
00492
00493 cpl_frame* xsh_resid_tab_save( xsh_resid_tab* resid, const char* filename,
00494 xsh_instrument* instr,const char* tag)
00495 {
00496 cpl_frame *result = NULL ;
00497 cpl_table *table = NULL;
00498 cpl_propertylist *header = NULL;
00499 int i = 0;
00500
00501 double residx_min=0;
00502 double residx_max=0;
00503 double residx_rms=0;
00504
00505 double residy_min=0;
00506 double residy_max=0;
00507 double residy_rms=0;
00508
00509 XSH_ASSURE_NOT_NULL( resid);
00510 XSH_ASSURE_NOT_NULL( filename);
00511 XSH_ASSURE_NOT_NULL( instr);
00512
00513
00514 check( table = cpl_table_new( XSH_RESID_TAB_TABLE_NB_COL));
00515 header = resid->header;
00516
00517 if (resid->solution_type == XSH_DETECT_ARCLINES_TYPE_POLY){
00518 check( xsh_pfits_set_qc( header, &(resid->mean_diff_poly_fit_x),
00519 XSH_QC_FMTCHK_POLY_DIFFXAVG, instr));
00520 check( xsh_pfits_set_qc( header, &(resid->median_diff_poly_fit_x),
00521 XSH_QC_FMTCHK_POLY_DIFFXMED, instr));
00522 check( xsh_pfits_set_qc( header, &(resid->stdev_diff_poly_fit_x),
00523 XSH_QC_FMTCHK_POLY_DIFFXSTD, instr));
00524 check( xsh_pfits_set_qc( header, &(resid->mean_diff_poly_fit_y),
00525 XSH_QC_FMTCHK_POLY_DIFFYAVG, instr));
00526 check( xsh_pfits_set_qc( header, &(resid->median_diff_poly_fit_y),
00527 XSH_QC_FMTCHK_POLY_DIFFYMED, instr));
00528 check( xsh_pfits_set_qc( header, &(resid->stdev_diff_poly_fit_y),
00529 XSH_QC_FMTCHK_POLY_DIFFYSTD, instr));
00530 }
00531
00532
00533 XSH_TABLE_NEW_COL(table, XSH_RESID_TAB_TABLE_COLNAME_WAVELENGTH,
00534 XSH_RESID_TAB_TABLE_UNIT_WAVELENGTH, CPL_TYPE_DOUBLE);
00535
00536 XSH_TABLE_NEW_COL(table, XSH_RESID_TAB_TABLE_COLNAME_ORDER,
00537 XSH_RESID_TAB_TABLE_UNIT_ORDER, CPL_TYPE_INT);
00538
00539 XSH_TABLE_NEW_COL(table, XSH_RESID_TAB_TABLE_COLNAME_SLITPOSITION,
00540 XSH_RESID_TAB_TABLE_UNIT_SLITPOSITION, CPL_TYPE_DOUBLE);
00541
00542 XSH_TABLE_NEW_COL(table, XSH_RESID_TAB_TABLE_COLNAME_SLITINDEX,
00543 XSH_RESID_TAB_TABLE_UNIT_SLITINDEX, CPL_TYPE_INT);
00544
00545 XSH_TABLE_NEW_COL(table, XSH_RESID_TAB_TABLE_COLNAME_XTHPRE,
00546 XSH_RESID_TAB_TABLE_UNIT_XTHPRE, CPL_TYPE_DOUBLE);
00547
00548 XSH_TABLE_NEW_COL(table, XSH_RESID_TAB_TABLE_COLNAME_YTHPRE,
00549 XSH_RESID_TAB_TABLE_UNIT_YTHPRE, CPL_TYPE_DOUBLE);
00550
00551 XSH_TABLE_NEW_COL(table, XSH_RESID_TAB_TABLE_COLNAME_XTHCOR,
00552 XSH_RESID_TAB_TABLE_UNIT_XTHCOR, CPL_TYPE_DOUBLE);
00553
00554 XSH_TABLE_NEW_COL(table, XSH_RESID_TAB_TABLE_COLNAME_YTHCOR,
00555 XSH_RESID_TAB_TABLE_UNIT_YTHCOR, CPL_TYPE_DOUBLE);
00556
00557 XSH_TABLE_NEW_COL(table, XSH_RESID_TAB_TABLE_COLNAME_XGAUSS,
00558 XSH_RESID_TAB_TABLE_UNIT_XGAUSS, CPL_TYPE_DOUBLE);
00559
00560 XSH_TABLE_NEW_COL(table, XSH_RESID_TAB_TABLE_COLNAME_YGAUSS,
00561 XSH_RESID_TAB_TABLE_UNIT_YGAUSS, CPL_TYPE_DOUBLE);
00562
00563 XSH_TABLE_NEW_COL(table, XSH_RESID_TAB_TABLE_COLNAME_SIGMAXGAUSS,
00564 XSH_RESID_TAB_TABLE_UNIT_SIGMAXGAUSS, CPL_TYPE_DOUBLE);
00565
00566 XSH_TABLE_NEW_COL(table, XSH_RESID_TAB_TABLE_COLNAME_SIGMAYGAUSS,
00567 XSH_RESID_TAB_TABLE_UNIT_SIGMAYGAUSS, CPL_TYPE_DOUBLE);
00568
00569 XSH_TABLE_NEW_COL(table, XSH_RESID_TAB_TABLE_COLNAME_XPOLY,
00570 XSH_RESID_TAB_TABLE_UNIT_XPOLY, CPL_TYPE_DOUBLE);
00571
00572 XSH_TABLE_NEW_COL(table, XSH_RESID_TAB_TABLE_COLNAME_YPOLY,
00573 XSH_RESID_TAB_TABLE_UNIT_YPOLY, CPL_TYPE_DOUBLE);
00574
00575 XSH_TABLE_NEW_COL(table, XSH_RESID_TAB_TABLE_COLNAME_XTHANNEAL,
00576 XSH_RESID_TAB_TABLE_UNIT_XTHANNEAL, CPL_TYPE_DOUBLE);
00577
00578 XSH_TABLE_NEW_COL(table, XSH_RESID_TAB_TABLE_COLNAME_YTHANNEAL,
00579 XSH_RESID_TAB_TABLE_UNIT_YTHANNEAL, CPL_TYPE_DOUBLE);
00580
00581 XSH_TABLE_NEW_COL(table, XSH_RESID_TAB_TABLE_COLNAME_RESIDXPOLY,
00582 XSH_RESID_TAB_TABLE_UNIT_RESIDXPOLY, CPL_TYPE_DOUBLE);
00583
00584 XSH_TABLE_NEW_COL(table, XSH_RESID_TAB_TABLE_COLNAME_RESIDYPOLY,
00585 XSH_RESID_TAB_TABLE_UNIT_RESIDYPOLY, CPL_TYPE_DOUBLE);
00586
00587 XSH_TABLE_NEW_COL(table, XSH_RESID_TAB_TABLE_COLNAME_RESIDXMODEL,
00588 XSH_RESID_TAB_TABLE_UNIT_RESIDXMODEL, CPL_TYPE_DOUBLE);
00589
00590 XSH_TABLE_NEW_COL(table, XSH_RESID_TAB_TABLE_COLNAME_RESIDYMODEL,
00591 XSH_RESID_TAB_TABLE_UNIT_RESIDYMODEL, CPL_TYPE_DOUBLE);
00592
00593 check(cpl_table_set_size( table, resid->size));
00594
00595
00596 for (i=0; i<resid->size; i++) {
00597 double lambda, order, slit;
00598 int slit_index;
00599 double thpre_x, thpre_y;
00600 double thcor_x, thcor_y;
00601 double xgauss, ygauss;
00602 double xpoly, ypoly;
00603 double sig_xgauss, sig_ygauss;
00604
00605 lambda = resid->lambda[i];
00606 order = resid->order[i];
00607 slit = resid->slit[i];
00608 slit_index = resid->slit_index[i];
00609 thpre_x = resid->thpre_x[i];
00610 thpre_y = resid->thpre_y[i];
00611 thcor_x = resid->thcor_x[i];
00612 thcor_y = resid->thcor_y[i];
00613 xgauss = resid->xgauss[i];
00614 ygauss = resid->ygauss[i];
00615 sig_xgauss = resid->sig_xgauss[i];
00616 sig_ygauss = resid->sig_ygauss[i];
00617 xpoly = resid->xpoly[i];
00618 ypoly = resid->ypoly[i];
00619
00620 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_WAVELENGTH,
00621 i, lambda));
00622 check(cpl_table_set(table,XSH_RESID_TAB_TABLE_COLNAME_ORDER,
00623 i, order));
00624 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_SLITPOSITION,
00625 i, slit));
00626 check(cpl_table_set_int(table,XSH_RESID_TAB_TABLE_COLNAME_SLITINDEX,
00627 i, slit_index));
00628 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_XTHPRE,
00629 i, thpre_x));
00630 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_YTHPRE,
00631 i, thpre_y));
00632 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_XTHCOR,
00633 i, thcor_x));
00634 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_YTHCOR,
00635 i, thcor_y));
00636 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_XGAUSS,
00637 i, xgauss));
00638 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_YGAUSS,
00639 i, ygauss));
00640 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_SIGMAXGAUSS,
00641 i, sig_xgauss));
00642 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_SIGMAYGAUSS,
00643 i, sig_ygauss));
00644 if (resid->solution_type == XSH_DETECT_ARCLINES_TYPE_POLY){
00645 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_XPOLY,
00646 i, xpoly));
00647 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_YPOLY,
00648 i, ypoly));
00649 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_RESIDXPOLY,
00650 i, xpoly-xgauss));
00651 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_RESIDYPOLY,
00652 i, ypoly-ygauss));
00653 }
00654 }
00655
00656
00657 if (resid->solution_type == XSH_DETECT_ARCLINES_TYPE_POLY){
00658 check( xsh_pfits_set_wavesoltype( header, XSH_WAVESOLTYPE_POLYNOMIAL));
00659
00660 check(residx_min=cpl_table_get_column_min(table,XSH_RESID_TAB_TABLE_COLNAME_RESIDXPOLY));
00661 check(residx_max=cpl_table_get_column_max(table,XSH_RESID_TAB_TABLE_COLNAME_RESIDXPOLY));
00662 check(residx_rms=cpl_table_get_column_stdev(table,XSH_RESID_TAB_TABLE_COLNAME_RESIDXPOLY));
00663
00664 check(residy_min=cpl_table_get_column_min(table,XSH_RESID_TAB_TABLE_COLNAME_RESIDYPOLY));
00665 check(residy_max=cpl_table_get_column_max(table,XSH_RESID_TAB_TABLE_COLNAME_RESIDYPOLY));
00666 check(residy_rms=cpl_table_get_column_stdev(table,XSH_RESID_TAB_TABLE_COLNAME_RESIDYPOLY));
00667
00668 cpl_propertylist_append_double(header,"ESO QC POLY RESX_MIN",residx_min);
00669 cpl_propertylist_append_double(header,"ESO QC POLY RESX_MAX",residx_max);
00670 cpl_propertylist_append_double(header,"ESO QC POLY RESX_RMS",residx_rms);
00671
00672
00673 cpl_propertylist_append_double(header,"ESO QC POLY RESY_MIN",residy_min);
00674 cpl_propertylist_append_double(header,"ESO QC POLY RESY_MAX",residy_max);
00675 cpl_propertylist_append_double(header,"ESO QC POLY RESY_RMS",residy_rms);
00676
00677 }
00678 else{
00679 int size;
00680
00681 size = cpl_propertylist_get_size( header);
00682 XSH_REGDEBUG("write MODEL in header size %d", size);
00683 check( xsh_pfits_set_wavesoltype( header, XSH_WAVESOLTYPE_MODEL));
00684 size = cpl_propertylist_get_size( header);
00685 XSH_REGDEBUG("write MODEL in header new size %d", size);
00686
00687
00688
00689
00690 }
00691
00692
00693 XSH_REGDEBUG("save filename %s", filename);
00694 check( xsh_pfits_set_pcatg(header, tag));
00695 check( cpl_table_save(table, header,NULL,filename, CPL_IO_DEFAULT));
00696
00697
00698 check(result=xsh_frame_product(filename,
00699 tag,
00700 CPL_FRAME_TYPE_TABLE,
00701 CPL_FRAME_GROUP_PRODUCT,
00702 CPL_FRAME_LEVEL_TEMPORARY));
00703
00704
00705 check (xsh_add_temporary_file( filename));
00706
00707 cleanup:
00708
00709 if (cpl_error_get_code() != CPL_ERROR_NONE){
00710 xsh_free_frame(&result);
00711 }
00712 XSH_TABLE_FREE( table);
00713 return result ;
00714 }
00715
00716
00725 RESID_TAB_PROPERTY_GET ( size, int, 0)
00726
00727
00735 double * xsh_resid_tab_get_lambda_data(xsh_resid_tab *resid)
00736 {
00737 double * result = NULL ;
00738
00739 XSH_ASSURE_NOT_NULL( resid);
00740 result = resid->lambda ;
00741
00742 cleanup:
00743 return result;
00744 }
00745
00754 double * xsh_resid_tab_get_order_data(xsh_resid_tab *resid)
00755 {
00756 double * result = NULL ;
00757
00758 XSH_ASSURE_NOT_NULL( resid);
00759 result = resid->order ;
00760
00761 cleanup:
00762 return result;
00763 }
00764
00773 double * xsh_resid_tab_get_slitpos_data(xsh_resid_tab *resid)
00774 {
00775 double * result = NULL ;
00776
00777 XSH_ASSURE_NOT_NULL( resid);
00778 result = resid->slit ;
00779
00780 cleanup:
00781 return result;
00782 }
00783
00792 RESID_TAB_PROPERTY_GET ( slit_index, int*, NULL)
00793
00794
00802 double * xsh_resid_tab_get_thpre_x_data(xsh_resid_tab *resid)
00803 {
00804 double * result = NULL ;
00805
00806 XSH_ASSURE_NOT_NULL( resid);
00807 result = resid->thpre_x ;
00808
00809 cleanup:
00810 return result;
00811 }
00812
00821 double * xsh_resid_tab_get_thpre_y_data(xsh_resid_tab *resid)
00822 {
00823 double * result = NULL ;
00824
00825 XSH_ASSURE_NOT_NULL( resid);
00826 result = resid->thpre_y ;
00827
00828 cleanup:
00829 return result;
00830 }
00831
00840 double * xsh_resid_tab_get_xgauss_data(xsh_resid_tab *resid)
00841 {
00842 double * result = NULL ;
00843
00844 XSH_ASSURE_NOT_NULL( resid);
00845 result = resid->xgauss;
00846
00847 cleanup:
00848 return result;
00849 }
00850
00859 double * xsh_resid_tab_get_ygauss_data(xsh_resid_tab *resid)
00860 {
00861 double * result = NULL ;
00862
00863 XSH_ASSURE_NOT_NULL( resid);
00864 result = resid->ygauss ;
00865
00866 cleanup:
00867 return result;
00868 }
00869