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
00032
00033
00038
00039
00043
00044
00045
00046
00047 #include <xsh_data_resid_tab.h>
00048 #include <xsh_utils.h>
00049 #include <xsh_error.h>
00050 #include <xsh_msg.h>
00051 #include <xsh_pfits.h>
00052 #include <cpl.h>
00053 #include <xsh_drl.h>
00054 #include <xsh_utils_table.h>
00055 #include <xsh_data_wavesol.h>
00056
00057
00058
00059
00060
00061
00083
00084 xsh_resid_tab*
00085 xsh_resid_tab_create(int size, double *lambda, double *order,
00086 double *slit, double* sn, int *slit_index,
00087 double *thpre_x, double *thpre_y,
00088 double*corr_x, double* corr_y,
00089 double *gaussian_norm,
00090 double *gaussian_fit_x, double *gaussian_fit_y,
00091 double *gaussian_sigma_x, double *gaussian_sigma_y,
00092 double *gaussian_fwhm_x, double *gaussian_fwhm_y, int* flag,
00093 xsh_wavesol *wavesol, int wavesol_type)
00094 {
00095 enum wavesol_type type = XSH_WAVESOL_GUESS;
00096 xsh_resid_tab* result = NULL;
00097 int i;
00098
00099
00100 XSH_ASSURE_NOT_ILLEGAL( size>=0);
00101 XSH_ASSURE_NOT_NULL( lambda);
00102 XSH_ASSURE_NOT_NULL( order);
00103 XSH_ASSURE_NOT_NULL( slit);
00104 XSH_ASSURE_NOT_NULL( slit_index);
00105 XSH_ASSURE_NOT_NULL( thpre_x);
00106 XSH_ASSURE_NOT_NULL( thpre_y);
00107
00108 XSH_ASSURE_NOT_NULL( gaussian_fit_x);
00109 XSH_ASSURE_NOT_NULL( gaussian_fit_y);
00110 XSH_ASSURE_NOT_NULL( gaussian_sigma_x);
00111 XSH_ASSURE_NOT_NULL( gaussian_sigma_y);
00112 XSH_ASSURE_NOT_NULL( gaussian_fwhm_x);
00113 XSH_ASSURE_NOT_NULL( gaussian_fwhm_y);
00114 XSH_ASSURE_NOT_NULL( gaussian_norm);
00115
00116 XSH_CALLOC( result, xsh_resid_tab, 1);
00117
00118 XSH_CALLOC( result->lambda, double, size);
00119 XSH_CALLOC( result->order, double, size);
00120 XSH_CALLOC( result->slit, double, size);
00121 XSH_CALLOC( result->sn, double, size);
00122 XSH_CALLOC( result->slit_index, int, size);
00123 XSH_CALLOC( result->thpre_x, double, size);
00124 XSH_CALLOC( result->thpre_y, double, size);
00125 XSH_CALLOC( result->thcor_x, double, size);
00126 XSH_CALLOC( result->thcor_y, double, size);
00127 XSH_CALLOC( result->xgauss, double, size);
00128 XSH_CALLOC( result->ygauss, double, size);
00129 XSH_CALLOC( result->sig_xgauss, double, size);
00130 XSH_CALLOC( result->sig_ygauss, double, size);
00131 XSH_CALLOC( result->norm_gauss, double, size);
00132 XSH_CALLOC( result->fwhm_xgauss, double, size);
00133 XSH_CALLOC( result->fwhm_ygauss, double, size);
00134
00135 XSH_CALLOC( result->xpoly, double, size);
00136 XSH_CALLOC( result->ypoly, double, size);
00137 if(flag) {
00138 XSH_CALLOC( result->flag, int, size);
00139 }
00140 check (result->header = cpl_propertylist_new());
00141
00142 result->size = size;
00143 result->solution_type = wavesol_type;
00144
00145 if (wavesol != NULL) {
00146 check (type = xsh_wavesol_get_type( wavesol));
00147 }
00148 else{
00149 type = XSH_WAVESOL_UNDEFINED;
00150 }
00151
00152 for( i=0; i<size; i++){
00153
00154 result->lambda[i] = lambda[i];
00155 result->order[i] = order[i];
00156 result->slit[i] = slit[i];
00157 if(sn != NULL) {
00158 result->sn[i] = sn[i];
00159 } else {
00160 result->sn[i]=0;
00161 }
00162 result->slit_index[i] = slit_index[i];
00163 result->thpre_x[i] = thpre_x[i];
00164 result->thpre_y[i] = thpre_y[i];
00165 result->thcor_x[i] = thpre_x[i]+corr_x[i];
00166 result->thcor_y[i] = thpre_y[i]+corr_y[i];
00167 result->xgauss[i] = gaussian_fit_x[i];
00168 result->ygauss[i] = gaussian_fit_y[i];
00169 result->sig_xgauss[i] = gaussian_sigma_x[i];
00170 result->sig_ygauss[i] = gaussian_sigma_y[i];
00171 result->fwhm_xgauss[i] = gaussian_fwhm_x[i];
00172 result->fwhm_ygauss[i] = gaussian_fwhm_y[i];
00173 result->norm_gauss[i] = gaussian_norm[i];
00174 if(flag) {
00175 result->flag[i] = flag[i];
00176 }
00177 if ( type == XSH_WAVESOL_2D){
00178 double polx, poly;
00179
00180 check( polx = xsh_wavesol_eval_polx( wavesol, lambda[i],
00181 order[i], slit[i]));
00182 check( poly = xsh_wavesol_eval_poly( wavesol, lambda[i],
00183 order[i], slit[i]));
00184 result->xpoly[i] = polx;
00185 result->ypoly[i] = poly;
00186 }
00187 else if ( type == XSH_WAVESOL_GUESS){
00188 check( result->xpoly[i] = xsh_wavesol_eval_polx( wavesol,
00189 lambda[i], order[i], slit[i])+result->thcor_x[i]);
00190 check( result->ypoly[i] = xsh_wavesol_eval_poly( wavesol,
00191 lambda[i], order[i], slit[i])+result->thcor_y[i]);
00192 }
00193 else{
00194 result->xpoly[i] = 0.0;
00195 result->ypoly[i] = 0.0;
00196 }
00197
00198 }
00199
00200
00201
00202
00203
00204
00205
00206
00207 cleanup:
00208 if ( cpl_error_get_code() != CPL_ERROR_NONE){
00209 xsh_resid_tab_free( &result);
00210 }
00211 return result;
00212 }
00213
00214
00215
00216 xsh_resid_tab*
00217 xsh_resid_tab_create_not_flagged(int size, double *lambda, double *order,
00218 double *slit, double* sn, int *slit_index, double *thpre_x, double *thpre_y,
00219 double*corr_x, double* corr_y, double *gaussian_norm,
00220 double *gaussian_fit_x, double *gaussian_fit_y, double *gaussian_sigma_x,
00221 double *gaussian_sigma_y, double *gaussian_fwhm_x, double *gaussian_fwhm_y,
00222 int* flag, xsh_wavesol *wavesol, int wavesol_type) {
00223 enum wavesol_type type = XSH_WAVESOL_GUESS;
00224 xsh_resid_tab* result = NULL;
00225 int i;
00226 int ngood = 0;
00227
00228
00229
00230 for (i = 0; i < size; i++) {
00231
00232 if (flag != NULL && flag[i] == 0) {
00233 ngood++;
00234 }
00235
00236 }
00237
00238
00239 XSH_ASSURE_NOT_ILLEGAL( size>=0);
00240 XSH_ASSURE_NOT_NULL( lambda);
00241 XSH_ASSURE_NOT_NULL( order);
00242 XSH_ASSURE_NOT_NULL( slit);
00243 XSH_ASSURE_NOT_NULL( slit_index);
00244 XSH_ASSURE_NOT_NULL( thpre_x);
00245 XSH_ASSURE_NOT_NULL( thpre_y);
00246
00247 XSH_ASSURE_NOT_NULL( gaussian_fit_x);
00248 XSH_ASSURE_NOT_NULL( gaussian_fit_y);
00249 XSH_ASSURE_NOT_NULL( gaussian_sigma_x);
00250 XSH_ASSURE_NOT_NULL( gaussian_sigma_y);
00251 XSH_ASSURE_NOT_NULL( gaussian_fwhm_x);
00252 XSH_ASSURE_NOT_NULL( gaussian_fwhm_y);
00253 XSH_ASSURE_NOT_NULL( gaussian_norm);
00254
00255 XSH_CALLOC( result, xsh_resid_tab, 1);
00256
00257
00258 XSH_CALLOC ( result->lambda, double, ngood);
00259 XSH_CALLOC( result->order, double, ngood);
00260 XSH_CALLOC ( result->slit, double, ngood);
00261 XSH_CALLOC( result->sn, double, ngood);
00262 XSH_CALLOC ( result->slit_index, int, ngood);
00263 XSH_CALLOC( result->thpre_x, double,ngood);
00264 XSH_CALLOC ( result->thpre_y, double, ngood);
00265 XSH_CALLOC( result->thcor_x, double,ngood);
00266 XSH_CALLOC ( result->thcor_y, double, ngood);
00267 XSH_CALLOC( result->xgauss, double, ngood);
00268 XSH_CALLOC ( result->ygauss, double, ngood);
00269 XSH_CALLOC( result->sig_xgauss, double, ngood);
00270 XSH_CALLOC ( result->sig_ygauss, double, ngood);
00271 XSH_CALLOC( result->norm_gauss,double, ngood);
00272 XSH_CALLOC ( result->fwhm_xgauss, double, ngood);
00273 XSH_CALLOC( result->fwhm_ygauss,double, ngood);
00274 XSH_CALLOC ( result->xpoly, double, ngood);
00275 XSH_CALLOC( result->ypoly, double, ngood);
00276
00277 if( flag) {
00278 XSH_CALLOC( result->flag, int, ngood);
00279 }
00280 check(result->header = cpl_propertylist_new());
00281
00282 result->size = ngood;
00283 result->solution_type = wavesol_type;
00284
00285 if (wavesol != NULL) {
00286 check(type = xsh_wavesol_get_type( wavesol));
00287 } else {
00288 type = XSH_WAVESOL_UNDEFINED;
00289 }
00290
00291
00292
00293
00294 int k = 0;
00295 for (i = 0; i < size; i++) {
00296 if (flag != NULL && flag[i] == 0) {
00297 result->lambda[k] = lambda[i];
00298 result->order[k] = order[i];
00299 result->slit[k] = slit[i];
00300 if (sn != NULL) {
00301 result->sn[k] = sn[i];
00302 } else {
00303 result->sn[k] = 0;
00304 }
00305 result->slit_index[k] = slit_index[i];
00306 result->thpre_x[k] = thpre_x[i];
00307 result->thpre_y[k] = thpre_y[i];
00308 result->thcor_x[k] = thpre_x[i] + corr_x[i];
00309 result->thcor_y[k] = thpre_y[i] + corr_y[i];
00310 result->xgauss[k] = gaussian_fit_x[i];
00311 result->ygauss[k] = gaussian_fit_y[i];
00312 result->sig_xgauss[k] = gaussian_sigma_x[i];
00313 result->sig_ygauss[k] = gaussian_sigma_y[i];
00314 result->fwhm_xgauss[k] = gaussian_fwhm_x[i];
00315 result->fwhm_ygauss[k] = gaussian_fwhm_y[i];
00316 result->norm_gauss[k] = gaussian_norm[i];
00317 if (flag) {
00318 result->flag[k] = flag[i];
00319 }
00320 if (type == XSH_WAVESOL_2D) {
00321 double polx, poly;
00322
00323 check(
00324 polx = xsh_wavesol_eval_polx( wavesol, lambda[i], order[i], slit[i]));
00325 check(
00326 poly = xsh_wavesol_eval_poly( wavesol, lambda[i], order[i], slit[i]));
00327 result->xpoly[k] = polx;
00328 result->ypoly[k] = poly;
00329 } else if (type == XSH_WAVESOL_GUESS) {
00330 check(
00331 result->xpoly[k] = xsh_wavesol_eval_polx( wavesol, lambda[i], order[i], slit[i])+result->thcor_x[k]);
00332 check(
00333 result->ypoly[k] = xsh_wavesol_eval_poly( wavesol, lambda[i], order[i], slit[i])+result->thcor_y[k]);
00334 } else {
00335 result->xpoly[k] = 0.0;
00336 result->ypoly[k] = 0.0;
00337 }
00338 k++;
00339 }
00340 }
00341
00342 cleanup: if (cpl_error_get_code() != CPL_ERROR_NONE) {
00343 xsh_resid_tab_free(&result);
00344 }
00345 return result;
00346 }
00347
00348 cpl_frame*
00349 xsh_resid_tab_erase_flagged( cpl_frame* resid,const char* name)
00350 {
00351
00352 cpl_frame* result = NULL;
00353 cpl_table* tab = NULL;
00354 cpl_table* ext = NULL;
00355 const char* fname = NULL;
00356
00357 cpl_propertylist* header=NULL;
00358
00359
00360 result=cpl_frame_duplicate(resid);
00361 check( fname = cpl_frame_get_filename( resid));
00362 tab=cpl_table_load(fname,1,0);
00363 header=cpl_propertylist_load(fname,0);
00364 cpl_table_and_selected_int(tab,XSH_RESID_TAB_TABLE_COLNAME_FLAG,
00365 CPL_GREATER_THAN,0);
00366 cpl_table_erase_selected(tab);
00367 cpl_table_save(tab,header,NULL,name,CPL_IO_DEFAULT);
00368 cpl_frame_set_filename(result,name);
00369
00370 cleanup:
00371 xsh_free_table(&ext);
00372 xsh_free_table(&tab);
00373 xsh_free_propertylist(&header);
00374
00375 return result;
00376 }
00377
00387
00388
00389 xsh_resid_tab* xsh_resid_tab_load( cpl_frame* resid_tab_frame)
00390 {
00391 xsh_resid_tab* result = NULL;
00392 cpl_table* table = NULL;
00393 const char* tablename = NULL;
00394 int i = 0;
00395 int size = 0;
00396 double *lambda = NULL;
00397 double *order = NULL;
00398 double *slit = NULL;
00399 int *slit_index = NULL;
00400 double *thx = NULL;
00401 double *thy = NULL;
00402 double *thcorx = NULL;
00403 double *thcory = NULL;
00404 double *xgauss = NULL;
00405 double *ygauss = NULL;
00406 double *sig_xgauss = NULL;
00407 double *sig_ygauss = NULL;
00408 double *fwhm_xgauss = NULL;
00409 double *fwhm_ygauss = NULL;
00410 double *norm_gauss = NULL;
00411 double *xpoly = NULL;
00412 double *ypoly = NULL;
00413 double *thanneal_x = NULL;
00414 double *thanneal_y = NULL;
00415 int* flag=NULL;
00416 int solution_type = XSH_DETECT_ARCLINES_TYPE_POLY;
00417 const char* wavesol_type = NULL;
00418
00419 XSH_ASSURE_NOT_NULL( resid_tab_frame);
00420
00421
00422 check( tablename = cpl_frame_get_filename( resid_tab_frame));
00423
00424 XSH_TABLE_LOAD( table, tablename);
00425
00426 check( size = cpl_table_get_nrow(table));
00427
00428 XSH_CALLOC( result, xsh_resid_tab, 1);
00429 check (result->header = cpl_propertylist_load( tablename, 0));
00430 wavesol_type = xsh_pfits_get_wavesoltype( result->header);
00431 if (cpl_error_get_code() == CPL_ERROR_NONE){
00432 if ( strcmp(wavesol_type, XSH_WAVESOLTYPE_MODEL)==0){
00433 solution_type = XSH_DETECT_ARCLINES_TYPE_MODEL;
00434 }
00435 }
00436 else{
00437 xsh_msg("Can't read keyword %s", XSH_WAVESOLTYPE);
00438 cpl_error_reset();
00439 }
00440 result->size = size;
00441 result->solution_type = solution_type;
00442
00443 XSH_CALLOC( lambda, double, size);
00444 XSH_CALLOC( order, double, size);
00445 XSH_CALLOC( slit, double, size);
00446 XSH_CALLOC( slit_index, int, size);
00447 XSH_CALLOC( thx, double, size);
00448 XSH_CALLOC( thy, double, size);
00449 XSH_CALLOC( thcorx, double, size);
00450 XSH_CALLOC( thcory, double, size);
00451 XSH_CALLOC( xgauss, double, size);
00452 XSH_CALLOC( ygauss, double, size);
00453 XSH_CALLOC( sig_xgauss, double, size);
00454 XSH_CALLOC( sig_ygauss, double, size);
00455 XSH_CALLOC( fwhm_xgauss, double, size);
00456 XSH_CALLOC( fwhm_ygauss, double, size);
00457 XSH_CALLOC( norm_gauss, double, size);
00458 if (solution_type == XSH_DETECT_ARCLINES_TYPE_MODEL){
00459 XSH_CALLOC( thanneal_x, double, size);
00460 XSH_CALLOC( thanneal_y, double, size);
00461 }
00462 else{
00463 XSH_CALLOC( xpoly, double, size);
00464 XSH_CALLOC( ypoly, double, size);
00465 }
00466 XSH_CALLOC( flag, int, size);
00467
00468 for(i=0; i<size;i++){
00469 int orderv, slit_indexv;
00470 double lambdav, slitv, thxv, thyv;
00471 double thcorxv=0, thcoryv=0;
00472 double xgaussv, ygaussv, xpolyv, ypolyv;
00473 double sig_xgaussv, sig_ygaussv;
00474 double fwhm_xgaussv, fwhm_ygaussv;
00475 double norm_gaussv;
00476 int flagv=0;
00477
00478 check( xsh_get_table_value( table,
00479 XSH_RESID_TAB_TABLE_COLNAME_WAVELENGTH,
00480 CPL_TYPE_DOUBLE, i, &lambdav));
00481
00482 check( xsh_get_table_value( table,
00483 XSH_RESID_TAB_TABLE_COLNAME_ORDER,
00484 CPL_TYPE_INT, i, &orderv));
00485
00486 check( xsh_get_table_value( table,
00487 XSH_RESID_TAB_TABLE_COLNAME_SLITPOSITION,
00488 CPL_TYPE_DOUBLE, i, &slitv));
00489
00490 check( xsh_get_table_value( table,
00491 XSH_RESID_TAB_TABLE_COLNAME_SLITINDEX,
00492 CPL_TYPE_INT, i, &slit_indexv));
00493
00494 check( xsh_get_table_value( table,
00495 XSH_RESID_TAB_TABLE_COLNAME_XTHPRE,
00496 CPL_TYPE_DOUBLE, i, &thxv));
00497
00498 check( xsh_get_table_value( table,
00499 XSH_RESID_TAB_TABLE_COLNAME_YTHPRE,
00500 CPL_TYPE_DOUBLE, i, &thyv));
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511 check( xsh_get_table_value( table,
00512 XSH_RESID_TAB_TABLE_COLNAME_XGAUSS,
00513 CPL_TYPE_DOUBLE, i, &xgaussv));
00514
00515 check( xsh_get_table_value( table,
00516 XSH_RESID_TAB_TABLE_COLNAME_YGAUSS,
00517 CPL_TYPE_DOUBLE, i, &ygaussv));
00518
00519 check( xsh_get_table_value( table,
00520 XSH_RESID_TAB_TABLE_COLNAME_SIGMAXGAUSS,
00521 CPL_TYPE_DOUBLE, i, &sig_xgaussv));
00522
00523 check( xsh_get_table_value( table,
00524 XSH_RESID_TAB_TABLE_COLNAME_SIGMAYGAUSS,
00525 CPL_TYPE_DOUBLE, i, &sig_ygaussv));
00526
00527
00528 check( xsh_get_table_value( table,
00529 XSH_RESID_TAB_TABLE_COLNAME_FWHMXGAUSS,
00530 CPL_TYPE_DOUBLE, i, &fwhm_xgaussv));
00531
00532 check( xsh_get_table_value( table,
00533 XSH_RESID_TAB_TABLE_COLNAME_FWHMYGAUSS,
00534 CPL_TYPE_DOUBLE, i, &fwhm_ygaussv));
00535
00536 check( xsh_get_table_value( table,
00537 XSH_RESID_TAB_TABLE_COLNAME_NORMGAUSS,
00538 CPL_TYPE_DOUBLE, i, &norm_gaussv));
00539
00540 if (solution_type == XSH_DETECT_ARCLINES_TYPE_MODEL){
00541 check( xsh_get_table_value( table,
00542 XSH_RESID_TAB_TABLE_COLNAME_XTHANNEAL,
00543 CPL_TYPE_DOUBLE, i, &xpolyv));
00544 thanneal_x[i] = xpolyv;
00545 check( xsh_get_table_value( table,
00546 XSH_RESID_TAB_TABLE_COLNAME_YTHANNEAL,
00547 CPL_TYPE_DOUBLE, i, &ypolyv));
00548 thanneal_y[i] = ypolyv;
00549 }
00550 else{
00551 check( xsh_get_table_value( table,
00552 XSH_RESID_TAB_TABLE_COLNAME_XPOLY,
00553 CPL_TYPE_DOUBLE, i, &xpolyv));
00554 xpoly[i] = xpolyv;
00555 check( xsh_get_table_value( table,
00556 XSH_RESID_TAB_TABLE_COLNAME_YPOLY,
00557 CPL_TYPE_DOUBLE, i, &ypolyv));
00558 ypoly[i] = ypolyv;
00559 }
00560 if (cpl_table_has_column(table,XSH_RESID_TAB_TABLE_COLNAME_FLAG)) {
00561 check( xsh_get_table_value( table,
00562 XSH_RESID_TAB_TABLE_COLNAME_SLITINDEX,
00563 CPL_TYPE_INT, i, &flagv));
00564 }
00565 lambda[i] = lambdav;
00566 order[i] = (double) orderv;
00567 slit[i] = slitv;
00568 slit_index[i] = slit_indexv;
00569 thx[i] = thxv;
00570 thy[i] = thyv;
00571 thcorx[i] =thcorxv;
00572 thcory[i] = thcoryv;
00573 xgauss[i] = xgaussv;
00574 ygauss[i] = ygaussv;
00575 sig_xgauss[i] = sig_xgaussv;
00576 sig_ygauss[i] = sig_ygaussv;
00577 fwhm_xgauss[i] = fwhm_xgaussv;
00578 fwhm_ygauss[i] = fwhm_ygaussv;
00579 norm_gauss[i] = norm_gaussv;
00580 flag[i]=flagv;
00581 }
00582
00583 result->lambda = lambda;
00584 result->order = order;
00585 result->slit = slit;
00586 result->slit_index = slit_index;
00587 result->thpre_x = thx;
00588 result->thpre_y = thy;
00589 result->thcor_x = thcorx;
00590 result->thcor_y = thcory;
00591 result->xgauss = xgauss;
00592 result->ygauss = ygauss;
00593 result->sig_xgauss = sig_xgauss;
00594 result->sig_ygauss = sig_ygauss;
00595 result->fwhm_xgauss = fwhm_xgauss;
00596 result->fwhm_ygauss = fwhm_ygauss;
00597 result->norm_gauss = norm_gauss;
00598 if ( solution_type == XSH_DETECT_ARCLINES_TYPE_MODEL){
00599 result->thanneal_x = thanneal_x;
00600 result->thanneal_y = thanneal_y;
00601 }
00602 else{
00603 result->xpoly = xpoly;
00604 result->ypoly = ypoly;
00605 }
00606 result->flag = flag;
00607
00608 cleanup:
00609 if (cpl_error_get_code () != CPL_ERROR_NONE) {
00610 xsh_error_msg("can't load frame %s",
00611 cpl_frame_get_filename(resid_tab_frame));
00612 xsh_resid_tab_free(&result);
00613 }
00614 XSH_TABLE_FREE( table);
00615 return result;
00616 }
00617
00618
00626
00627 void xsh_resid_tab_free( xsh_resid_tab** resid) {
00628 if ( resid && *resid) {
00629 XSH_FREE( (*resid)->lambda);
00630 XSH_FREE( (*resid)->order);
00631 XSH_FREE( (*resid)->slit);
00632 XSH_FREE( (*resid)->slit_index);
00633 XSH_FREE( (*resid)->thpre_x);
00634 XSH_FREE( (*resid)->thpre_y);
00635 XSH_FREE( (*resid)->thcor_x);
00636 XSH_FREE( (*resid)->thcor_y);
00637 XSH_FREE( (*resid)->xgauss);
00638 XSH_FREE( (*resid)->ygauss);
00639 XSH_FREE( (*resid)->sig_xgauss);
00640 XSH_FREE( (*resid)->sig_ygauss);
00641 XSH_FREE( (*resid)->fwhm_xgauss);
00642 XSH_FREE( (*resid)->fwhm_ygauss);
00643 XSH_FREE( (*resid)->norm_gauss);
00644 XSH_FREE( (*resid)->xpoly);
00645 XSH_FREE( (*resid)->ypoly);
00646 XSH_FREE( (*resid)->thanneal_x);
00647 XSH_FREE( (*resid)->thanneal_y);
00648 XSH_FREE( (*resid)->flag);
00649 if( (*resid)->sn) XSH_FREE( (*resid)->sn) ;
00650 xsh_free_propertylist( &(*resid)->header);
00651 cpl_free(*resid);
00652 *resid = NULL;
00653 }
00654
00655 }
00656
00657
00658
00667
00668 void xsh_resid_tab_log( xsh_resid_tab* resid, const char* filename)
00669 {
00670
00671 FILE* logfile = NULL;
00672 int i = 0;
00673
00674 XSH_ASSURE_NOT_NULL( resid);
00675 XSH_ASSURE_NOT_NULL( filename);
00676
00677 logfile = fopen(filename,"w");
00678
00679 if ( resid->solution_type == XSH_DETECT_ARCLINES_TYPE_POLY) {
00680 fprintf( logfile,
00681 "# lambda order slit thx, thy, gaussx, gaussy, xpoly, ypoly");
00682 for ( i=0; i< resid->size; i++){
00683 double lambda, order, slit;
00684
00685 lambda = resid->lambda[i];
00686 order = resid->order[i];
00687 slit = resid->slit[i];
00688 fprintf( logfile,
00689 "%.8lg %.8lg %.8lg %.8lg %.8lg %.8lg %.8lg %.8lg %.8lg\n",
00690 lambda, order, slit, resid->thpre_x[i], resid->thpre_y[i],
00691 resid->xgauss[i], resid->ygauss[i],
00692 resid->xpoly[i], resid->ypoly[i]
00693 );
00694 }
00695 }
00696 else{
00697 fprintf( logfile,
00698 "# lambda order slit thx, thy, gaussx, gaussy, thanneal_x, thanneal_y");
00699 for ( i=0; i< resid->size; i++){
00700 double lambda, order, slit;
00701
00702 lambda = resid->lambda[i];
00703 order = resid->order[i];
00704 slit = resid->slit[i];
00705 fprintf( logfile,
00706 "%.8lg %.8lg %.8lg %.8lg %.8lg %.8lg %.8lg %.8lg %.8lg\n",
00707 lambda, order, slit, resid->thpre_x[i], resid->thpre_y[i],
00708 resid->xgauss[i], resid->ygauss[i],
00709 resid->thanneal_x[i], resid->thanneal_y[i]
00710 );
00711 }
00712 }
00713 fclose( logfile);
00714 cleanup:
00715 return;
00716 }
00717
00718
00730
00731 cpl_frame* xsh_resid_tab_save( xsh_resid_tab* resid, const char* filename,
00732 xsh_instrument* instr,const char* tag)
00733 {
00734 cpl_frame *result = NULL ;
00735 cpl_table *table = NULL;
00736 cpl_propertylist *header = NULL;
00737 int i = 0;
00738
00739 double residx_min=0;
00740 double residx_max=0;
00741 double residx_rms=0;
00742
00743 double residy_min=0;
00744 double residy_max=0;
00745 double residy_rms=0;
00746
00747 XSH_ASSURE_NOT_NULL( resid);
00748 XSH_ASSURE_NOT_NULL( filename);
00749 XSH_ASSURE_NOT_NULL( instr);
00750
00751
00752 check( table = cpl_table_new( XSH_RESID_TAB_TABLE_NB_COL));
00753 header = resid->header;
00754
00755 if (resid->solution_type == XSH_DETECT_ARCLINES_TYPE_POLY){
00756 check( xsh_pfits_set_qc( header, &(resid->mean_diff_poly_fit_x),
00757 XSH_QC_FMTCHK_POLY_DIFFXAVG, instr));
00758 check( xsh_pfits_set_qc( header, &(resid->median_diff_poly_fit_x),
00759 XSH_QC_FMTCHK_POLY_DIFFXMED, instr));
00760 check( xsh_pfits_set_qc( header, &(resid->stdev_diff_poly_fit_x),
00761 XSH_QC_FMTCHK_POLY_DIFFXSTD, instr));
00762 check( xsh_pfits_set_qc( header, &(resid->mean_diff_poly_fit_y),
00763 XSH_QC_FMTCHK_POLY_DIFFYAVG, instr));
00764 check( xsh_pfits_set_qc( header, &(resid->median_diff_poly_fit_y),
00765 XSH_QC_FMTCHK_POLY_DIFFYMED, instr));
00766 check( xsh_pfits_set_qc( header, &(resid->stdev_diff_poly_fit_y),
00767 XSH_QC_FMTCHK_POLY_DIFFYSTD, instr));
00768 }
00769
00770
00771 XSH_TABLE_NEW_COL(table, XSH_RESID_TAB_TABLE_COLNAME_WAVELENGTH,
00772 XSH_RESID_TAB_TABLE_UNIT_WAVELENGTH, CPL_TYPE_DOUBLE);
00773
00774 XSH_TABLE_NEW_COL(table, XSH_RESID_TAB_TABLE_COLNAME_ORDER,
00775 XSH_RESID_TAB_TABLE_UNIT_ORDER, CPL_TYPE_INT);
00776
00777 XSH_TABLE_NEW_COL(table, XSH_RESID_TAB_TABLE_COLNAME_SLITPOSITION,
00778 XSH_RESID_TAB_TABLE_UNIT_SLITPOSITION, CPL_TYPE_DOUBLE);
00779
00780 XSH_TABLE_NEW_COL(table, XSH_RESID_TAB_TABLE_COLNAME_SLITINDEX,
00781 XSH_RESID_TAB_TABLE_UNIT_SLITINDEX, CPL_TYPE_INT);
00782
00783 XSH_TABLE_NEW_COL(table, XSH_RESID_TAB_TABLE_COLNAME_XTHPRE,
00784 XSH_RESID_TAB_TABLE_UNIT_XTHPRE, CPL_TYPE_DOUBLE);
00785
00786 XSH_TABLE_NEW_COL(table, XSH_RESID_TAB_TABLE_COLNAME_YTHPRE,
00787 XSH_RESID_TAB_TABLE_UNIT_YTHPRE, CPL_TYPE_DOUBLE);
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797 XSH_TABLE_NEW_COL(table, XSH_RESID_TAB_TABLE_COLNAME_XGAUSS,
00798 XSH_RESID_TAB_TABLE_UNIT_XGAUSS, CPL_TYPE_DOUBLE);
00799
00800 XSH_TABLE_NEW_COL(table, XSH_RESID_TAB_TABLE_COLNAME_YGAUSS,
00801 XSH_RESID_TAB_TABLE_UNIT_YGAUSS, CPL_TYPE_DOUBLE);
00802
00803 XSH_TABLE_NEW_COL(table, XSH_RESID_TAB_TABLE_COLNAME_SIGMAXGAUSS,
00804 XSH_RESID_TAB_TABLE_UNIT_SIGMAXGAUSS, CPL_TYPE_DOUBLE);
00805
00806 XSH_TABLE_NEW_COL(table, XSH_RESID_TAB_TABLE_COLNAME_SIGMAYGAUSS,
00807 XSH_RESID_TAB_TABLE_UNIT_SIGMAYGAUSS, CPL_TYPE_DOUBLE);
00808
00809 XSH_TABLE_NEW_COL(table, XSH_RESID_TAB_TABLE_COLNAME_FWHMXGAUSS,
00810 XSH_RESID_TAB_TABLE_UNIT_SIGMAXGAUSS, CPL_TYPE_DOUBLE);
00811
00812 XSH_TABLE_NEW_COL(table, XSH_RESID_TAB_TABLE_COLNAME_FWHMYGAUSS,
00813 XSH_RESID_TAB_TABLE_UNIT_SIGMAYGAUSS, CPL_TYPE_DOUBLE);
00814
00815 XSH_TABLE_NEW_COL(table, XSH_RESID_TAB_TABLE_COLNAME_NORMGAUSS,
00816 XSH_RESID_TAB_TABLE_UNIT_NORMGAUSS, CPL_TYPE_DOUBLE);
00817
00818 XSH_TABLE_NEW_COL(table, XSH_RESID_TAB_TABLE_COLNAME_SN,
00819 XSH_RESID_TAB_TABLE_UNIT_SN, CPL_TYPE_DOUBLE);
00820
00821 XSH_TABLE_NEW_COL(table, XSH_RESID_TAB_TABLE_COLNAME_XPOLY,
00822 XSH_RESID_TAB_TABLE_UNIT_XPOLY, CPL_TYPE_DOUBLE);
00823
00824 XSH_TABLE_NEW_COL(table, XSH_RESID_TAB_TABLE_COLNAME_YPOLY,
00825 XSH_RESID_TAB_TABLE_UNIT_YPOLY, CPL_TYPE_DOUBLE);
00826
00827 XSH_TABLE_NEW_COL(table, XSH_RESID_TAB_TABLE_COLNAME_XTHANNEAL,
00828 XSH_RESID_TAB_TABLE_UNIT_XTHANNEAL, CPL_TYPE_DOUBLE);
00829
00830 XSH_TABLE_NEW_COL(table, XSH_RESID_TAB_TABLE_COLNAME_YTHANNEAL,
00831 XSH_RESID_TAB_TABLE_UNIT_YTHANNEAL, CPL_TYPE_DOUBLE);
00832
00833 XSH_TABLE_NEW_COL(table, XSH_RESID_TAB_TABLE_COLNAME_RESIDXPOLY,
00834 XSH_RESID_TAB_TABLE_UNIT_RESIDXPOLY, CPL_TYPE_DOUBLE);
00835
00836 XSH_TABLE_NEW_COL(table, XSH_RESID_TAB_TABLE_COLNAME_RESIDYPOLY,
00837 XSH_RESID_TAB_TABLE_UNIT_RESIDYPOLY, CPL_TYPE_DOUBLE);
00838
00839 XSH_TABLE_NEW_COL(table, XSH_RESID_TAB_TABLE_COLNAME_RESIDXMODEL,
00840 XSH_RESID_TAB_TABLE_UNIT_RESIDXMODEL, CPL_TYPE_DOUBLE);
00841
00842 XSH_TABLE_NEW_COL(table, XSH_RESID_TAB_TABLE_COLNAME_RESIDYMODEL,
00843 XSH_RESID_TAB_TABLE_UNIT_RESIDYMODEL, CPL_TYPE_DOUBLE);
00844
00845 if(resid->flag) {
00846
00847 XSH_TABLE_NEW_COL(table, XSH_RESID_TAB_TABLE_COLNAME_FLAG,
00848 XSH_RESID_TAB_TABLE_UNIT_FLAG, CPL_TYPE_INT);
00849
00850 }
00851 check(cpl_table_set_size( table, resid->size));
00852
00853
00854 for (i=0; i<resid->size; i++) {
00855 double lambda, order, slit,sn;
00856 int slit_index;
00857 double thpre_x, thpre_y;
00858
00859 double xgauss, ygauss;
00860 double xpoly, ypoly;
00861 double sig_xgauss, sig_ygauss;
00862 double fwhm_xgauss, fwhm_ygauss;
00863 double norm_gauss;
00864 int flag;
00865 lambda = resid->lambda[i];
00866 order = resid->order[i];
00867 slit = resid->slit[i];
00868 sn = resid->sn[i];
00869
00870 slit_index = resid->slit_index[i];
00871 thpre_x = resid->thpre_x[i];
00872 thpre_y = resid->thpre_y[i];
00873
00874
00875 xgauss = resid->xgauss[i];
00876 ygauss = resid->ygauss[i];
00877 sig_xgauss = resid->sig_xgauss[i];
00878 sig_ygauss = resid->sig_ygauss[i];
00879 fwhm_xgauss = resid->fwhm_xgauss[i];
00880 fwhm_ygauss = resid->fwhm_ygauss[i];
00881 norm_gauss = resid->norm_gauss[i];
00882 xpoly = resid->xpoly[i];
00883 ypoly = resid->ypoly[i];
00884 if(resid->flag) {
00885 flag = resid->flag[i];
00886 }
00887 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_WAVELENGTH,
00888 i, lambda));
00889 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_SN,
00890 i, sn));
00891
00892 check(cpl_table_set(table,XSH_RESID_TAB_TABLE_COLNAME_ORDER,
00893 i, order));
00894 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_SLITPOSITION,
00895 i, slit));
00896 check(cpl_table_set_int(table,XSH_RESID_TAB_TABLE_COLNAME_SLITINDEX,
00897 i, slit_index));
00898 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_XTHPRE,
00899 i, thpre_x));
00900 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_YTHPRE,
00901 i, thpre_y));
00902
00903
00904
00905
00906
00907
00908
00909
00910 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_XGAUSS,
00911 i, xgauss));
00912 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_YGAUSS,
00913 i, ygauss));
00914 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_SIGMAXGAUSS,
00915 i, sig_xgauss));
00916 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_SIGMAYGAUSS,
00917 i, sig_ygauss));
00918
00919 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_FWHMXGAUSS,
00920 i, fwhm_xgauss));
00921 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_FWHMYGAUSS,
00922 i, fwhm_ygauss));
00923 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_NORMGAUSS,
00924 i, norm_gauss));
00925
00926 if (resid->solution_type == XSH_DETECT_ARCLINES_TYPE_POLY){
00927 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_XPOLY,
00928 i, xpoly));
00929 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_YPOLY,
00930 i, ypoly));
00931 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_RESIDXPOLY,
00932 i, xpoly-xgauss));
00933 check(cpl_table_set_double(table,XSH_RESID_TAB_TABLE_COLNAME_RESIDYPOLY,
00934 i, ypoly-ygauss));
00935 }
00936 if(resid->flag) {
00937
00938 check(cpl_table_set_int(table,XSH_RESID_TAB_TABLE_COLNAME_FLAG,
00939 i, flag));
00940 }
00941 }
00942
00943
00944 if (resid->solution_type == XSH_DETECT_ARCLINES_TYPE_POLY){
00945 check( xsh_pfits_set_wavesoltype( header, XSH_WAVESOLTYPE_POLYNOMIAL));
00946
00947 check(residx_min=cpl_table_get_column_min(table,XSH_RESID_TAB_TABLE_COLNAME_RESIDXPOLY));
00948 check(residx_max=cpl_table_get_column_max(table,XSH_RESID_TAB_TABLE_COLNAME_RESIDXPOLY));
00949 check(residx_rms=cpl_table_get_column_stdev(table,XSH_RESID_TAB_TABLE_COLNAME_RESIDXPOLY));
00950
00951 check(residy_min=cpl_table_get_column_min(table,XSH_RESID_TAB_TABLE_COLNAME_RESIDYPOLY));
00952 check(residy_max=cpl_table_get_column_max(table,XSH_RESID_TAB_TABLE_COLNAME_RESIDYPOLY));
00953 check(residy_rms=cpl_table_get_column_stdev(table,XSH_RESID_TAB_TABLE_COLNAME_RESIDYPOLY));
00954
00955 cpl_propertylist_append_double(header,"ESO QC POLY RESX_MIN",residx_min);
00956 cpl_propertylist_append_double(header,"ESO QC POLY RESX_MAX",residx_max);
00957 cpl_propertylist_append_double(header,"ESO QC POLY RESX_RMS",residx_rms);
00958
00959
00960 cpl_propertylist_append_double(header,"ESO QC POLY RESY_MIN",residy_min);
00961 cpl_propertylist_append_double(header,"ESO QC POLY RESY_MAX",residy_max);
00962 cpl_propertylist_append_double(header,"ESO QC POLY RESY_RMS",residy_rms);
00963
00964 }
00965 else{
00966 int size;
00967
00968 size = cpl_propertylist_get_size( header);
00969 XSH_REGDEBUG("write MODEL in header size %d", size);
00970 check( xsh_pfits_set_wavesoltype( header, XSH_WAVESOLTYPE_MODEL));
00971 size = cpl_propertylist_get_size( header);
00972 XSH_REGDEBUG("write MODEL in header new size %d", size);
00973
00974
00975
00976
00977 }
00978
00979
00980 XSH_REGDEBUG("save filename %s", filename);
00981 check( xsh_pfits_set_pcatg(header, tag));
00982 check( cpl_table_save(table, header,NULL,filename, CPL_IO_DEFAULT));
00983
00984
00985 check(result=xsh_frame_product(filename,
00986 tag,
00987 CPL_FRAME_TYPE_TABLE,
00988 CPL_FRAME_GROUP_PRODUCT,
00989 CPL_FRAME_LEVEL_TEMPORARY));
00990
00991
00992
00993
00994 cleanup:
00995
00996 if (cpl_error_get_code() != CPL_ERROR_NONE){
00997 xsh_free_frame(&result);
00998 }
00999 XSH_TABLE_FREE( table);
01000 return result ;
01001 }
01002
01003
01012 RESID_TAB_PROPERTY_GET ( size, int, 0)
01013
01014
01022 double * xsh_resid_tab_get_lambda_data(xsh_resid_tab *resid)
01023 {
01024 double * result = NULL ;
01025
01026 XSH_ASSURE_NOT_NULL( resid);
01027 result = resid->lambda ;
01028
01029 cleanup:
01030 return result;
01031 }
01032
01041 double * xsh_resid_tab_get_order_data(xsh_resid_tab *resid)
01042 {
01043 double * result = NULL ;
01044
01045 XSH_ASSURE_NOT_NULL( resid);
01046 result = resid->order ;
01047
01048 cleanup:
01049 return result;
01050 }
01051
01060 double * xsh_resid_tab_get_slitpos_data(xsh_resid_tab *resid)
01061 {
01062 double * result = NULL ;
01063
01064 XSH_ASSURE_NOT_NULL( resid);
01065 result = resid->slit ;
01066
01067 cleanup:
01068 return result;
01069 }
01070
01079 RESID_TAB_PROPERTY_GET ( slit_index, int*, NULL)
01080
01081
01089 double * xsh_resid_tab_get_thpre_x_data(xsh_resid_tab *resid)
01090 {
01091 double * result = NULL ;
01092
01093 XSH_ASSURE_NOT_NULL( resid);
01094 result = resid->thpre_x ;
01095
01096 cleanup:
01097 return result;
01098 }
01099
01108 double * xsh_resid_tab_get_thpre_y_data(xsh_resid_tab *resid)
01109 {
01110 double * result = NULL ;
01111
01112 XSH_ASSURE_NOT_NULL( resid);
01113 result = resid->thpre_y ;
01114
01115 cleanup:
01116 return result;
01117 }
01118
01127 double * xsh_resid_tab_get_xgauss_data(xsh_resid_tab *resid)
01128 {
01129 double * result = NULL ;
01130
01131 XSH_ASSURE_NOT_NULL( resid);
01132 result = resid->xgauss;
01133
01134 cleanup:
01135 return result;
01136 }
01137
01146 double * xsh_resid_tab_get_ygauss_data(xsh_resid_tab *resid)
01147 {
01148 double * result = NULL ;
01149
01150 XSH_ASSURE_NOT_NULL( resid);
01151 result = resid->ygauss ;
01152
01153 cleanup:
01154 return result;
01155 }
01156
01157
01158
01159 cpl_error_code
01160 xsh_frame_table_resid_merge(cpl_frame* self, cpl_frame* right,
01161 const int solution_type)
01162 {
01163 cpl_table* stab=NULL;
01164 cpl_table* rtab=NULL;
01165 cpl_propertylist* shead=NULL;
01166 cpl_propertylist* rhead=NULL;
01167 cpl_propertylist* qc_head=NULL;
01168 const char* sname=NULL;
01169 const char* rname=NULL;
01170
01171 int i=0;
01172 int srow=0;
01173 int rrow=0;
01174 double wtol=0.001;
01175
01176 double* pWaveSelf=NULL;
01177 int* pFlagSelf=NULL;
01178
01179 int* pSlitIndexSelf=NULL;
01180 int* pOrderSelf=NULL;
01181 double* pXThAnnealSelf=NULL;
01182 double* pYThAnnealSelf=NULL;
01183 double* pXpolySelf=NULL;
01184 double* pYpolySelf=NULL;
01185
01186 double* pResidXpolySelf=NULL;
01187 double* pResidYpolySelf=NULL;
01188 double* pResidXmodelSelf=NULL;
01189 double* pResidYmodelSelf=NULL;
01190
01191
01192 double* pWaveRight=NULL;
01193 int* pSlitIndexRight=NULL;
01194 int* pOrderRight=NULL;
01195 double* pXThAnnealRight=NULL;
01196 double* pYThAnnealRight=NULL;
01197 double* pXpolyRight=NULL;
01198 double* pYpolyRight=NULL;
01199
01200 double* pResidXpolyRight=NULL;
01201 double* pResidYpolyRight=NULL;
01202 double* pResidXmodelRight=NULL;
01203 double* pResidYmodelRight=NULL;
01204 double itol=0.001;
01205 int k=0;
01206
01207 sname=cpl_frame_get_filename(self);
01208 rname=cpl_frame_get_filename(right);
01209
01210
01211 shead=cpl_propertylist_load(sname,0);
01212 rhead=cpl_propertylist_load(rname,0);
01213 qc_head=cpl_propertylist_load_regexp(sname,0,"^ESO QC",0);
01214
01215 cpl_propertylist_append(rhead,qc_head);
01216 stab=cpl_table_load(sname,1,0);
01217 rtab=cpl_table_load(rname,1,0);
01218 srow=cpl_table_get_nrow(stab);
01219 rrow=cpl_table_get_nrow(stab);
01220
01221 pWaveRight=cpl_table_get_data_double(rtab,XSH_RESID_TAB_TABLE_COLNAME_WAVELENGTH);
01222 pSlitIndexRight=cpl_table_get_data_int(rtab,XSH_RESID_TAB_TABLE_COLNAME_SLITINDEX);
01223 pOrderRight=cpl_table_get_data_int(rtab,XSH_RESID_TAB_TABLE_COLNAME_ORDER);
01224 pXThAnnealRight=cpl_table_get_data_double(rtab,XSH_RESID_TAB_TABLE_COLNAME_XTHANNEAL);
01225 pYThAnnealRight=cpl_table_get_data_double(rtab,XSH_RESID_TAB_TABLE_COLNAME_YTHANNEAL);
01226
01227 pXpolyRight=cpl_table_get_data_double(rtab,XSH_RESID_TAB_TABLE_COLNAME_XPOLY);
01228 pYpolyRight=cpl_table_get_data_double(rtab,XSH_RESID_TAB_TABLE_COLNAME_YPOLY);
01229
01230 pResidXpolyRight=cpl_table_get_data_double(rtab,XSH_RESID_TAB_TABLE_COLNAME_RESIDXPOLY);
01231 pResidYpolyRight=cpl_table_get_data_double(rtab,XSH_RESID_TAB_TABLE_COLNAME_RESIDYPOLY);
01232 pResidXmodelRight=cpl_table_get_data_double(rtab,XSH_RESID_TAB_TABLE_COLNAME_RESIDXMODEL);
01233 pResidYmodelRight=cpl_table_get_data_double(rtab,XSH_RESID_TAB_TABLE_COLNAME_RESIDYMODEL);
01234
01235
01236 pWaveSelf=cpl_table_get_data_double(stab,XSH_RESID_TAB_TABLE_COLNAME_WAVELENGTH);
01237 pSlitIndexSelf=cpl_table_get_data_int(stab,XSH_RESID_TAB_TABLE_COLNAME_SLITINDEX);
01238 pOrderSelf=cpl_table_get_data_int(stab,XSH_RESID_TAB_TABLE_COLNAME_ORDER);
01239 pFlagSelf=cpl_table_get_data_int(stab,XSH_RESID_TAB_TABLE_COLNAME_FLAG);
01240
01241 pXThAnnealSelf=cpl_table_get_data_double(stab,XSH_RESID_TAB_TABLE_COLNAME_XTHANNEAL);
01242 pYThAnnealSelf=cpl_table_get_data_double(stab,XSH_RESID_TAB_TABLE_COLNAME_YTHANNEAL);
01243
01244 pXpolySelf=cpl_table_get_data_double(stab,XSH_RESID_TAB_TABLE_COLNAME_XPOLY);
01245 pYpolySelf=cpl_table_get_data_double(stab,XSH_RESID_TAB_TABLE_COLNAME_YPOLY);
01246
01247 pResidXpolySelf=cpl_table_get_data_double(stab,XSH_RESID_TAB_TABLE_COLNAME_RESIDXPOLY);
01248 pResidYpolySelf=cpl_table_get_data_double(stab,XSH_RESID_TAB_TABLE_COLNAME_RESIDYPOLY);
01249 pResidXmodelSelf=cpl_table_get_data_double(stab,XSH_RESID_TAB_TABLE_COLNAME_RESIDXMODEL);
01250 pResidYmodelSelf=cpl_table_get_data_double(stab,XSH_RESID_TAB_TABLE_COLNAME_RESIDYMODEL);
01251
01252
01253 for(i=0;i<srow;i++) {
01254
01255 for (k = 0; k < rrow; k++) {
01256 if ((fabs(pWaveSelf[i] - pWaveRight[k]) < wtol)
01257 && (fabs(pSlitIndexSelf[i] - pSlitIndexRight[k]) < itol)
01258 && (fabs(pOrderSelf[i] - pOrderRight[k]) < itol)
01259 && pFlagSelf[i] == 0) {
01260 if (solution_type == XSH_DETECT_ARCLINES_TYPE_MODEL) {
01261 pXThAnnealSelf[i] = pXThAnnealRight[k];
01262 pYThAnnealSelf[i] = pYThAnnealRight[k];
01263 pResidXmodelSelf[i] = pResidXmodelRight[k];
01264 pResidYmodelSelf[i] = pResidYmodelRight[k];
01265 } else {
01266 pXpolySelf[i] = pXpolyRight[k];
01267 pYpolySelf[i] = pYpolyRight[k];
01268 pResidXpolySelf[i] = pResidXpolyRight[k];
01269 pResidYpolySelf[i] = pResidYpolyRight[k];
01270
01271 }
01272 }
01273 }
01274 }
01275
01276 check(cpl_table_save(stab,rhead,NULL,sname,CPL_IO_DEFAULT));
01277
01278
01279 cleanup:
01280 xsh_free_table(&stab);
01281 xsh_free_table(&rtab);
01282 xsh_free_propertylist(&shead);
01283 xsh_free_propertylist(&rhead);
01284 xsh_free_propertylist(&qc_head);
01285
01286 return cpl_error_get_code();
01287
01288 }