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
00035
00036
00040
00041
00042
00043 #include <string.h>
00044 #include <math.h>
00045 #include <xsh_utils_table.h>
00046 #include <xsh_data_rec.h>
00047 #include <xsh_error.h>
00048 #include <xsh_msg.h>
00049 #include <xsh_pfits.h>
00050 #include <xsh_dfs.h>
00051 #include <cpl.h>
00052
00053
00054
00055
00062 void xsh_rec_list_dump( xsh_rec_list * list,
00063 const char * fname )
00064 {
00065 int i ;
00066 FILE * fout = NULL;
00067
00068 XSH_ASSURE_NOT_NULL( list) ;
00069 if ( fname == NULL ) {
00070 fout = stdout;
00071 }
00072 else {
00073 fout = fopen( fname, "w" ) ;
00074 }
00075 XSH_ASSURE_NOT_NULL( fout ) ;
00076
00077 fprintf( fout, "Rec List. Nb of orders: %d\n", list->size ) ;
00078 for( i = 0 ; i<list->size ; i++ ) {
00079 fprintf( fout, " Entry %2d: Order %d, Nlambda: %d, Nslit: %d\n",
00080 i, list->list[i].order, list->list[i].nlambda,
00081 list->list[i].nslit ) ;
00082 }
00083
00084 cleanup:
00085 if ( fname != NULL && fout != NULL ) fclose( fout ) ;
00086 return ;
00087 }
00088
00089
00090
00099
00100 xsh_rec_list* xsh_rec_list_create(xsh_instrument* instr)
00101 {
00102 xsh_rec_list *result = NULL;
00103 XSH_ARM xsh_arm;
00104 int size;
00105
00106
00107 XSH_ASSURE_NOT_NULL( instr);
00108
00109
00110 xsh_arm = xsh_instrument_get_arm( instr) ;
00111
00112
00113 if ( instr->config != NULL )
00114 size = instr->config->orders;
00115 else if( xsh_arm == XSH_ARM_UVB){
00116 size = XSH_REC_TABLE_NB_UVB_ORDERS;
00117 }
00118 else if ( xsh_arm == XSH_ARM_VIS){
00119 size = XSH_REC_TABLE_NB_VIS_ORDERS;
00120 }
00121 else if ( xsh_arm == XSH_ARM_NIR){
00122 size = XSH_REC_TABLE_NB_NIR_ORDERS;
00123 }
00124 else {
00125 size = 0;
00126 }
00127 check(result = xsh_rec_list_create_with_size( size, instr));
00128
00129 cleanup:
00130 if ( cpl_error_get_code() != CPL_ERROR_NONE) {
00131 xsh_rec_list_free( &result);
00132 }
00133 return result;
00134 }
00135
00136
00146
00147 xsh_rec_list* xsh_rec_list_create_with_size(int size, xsh_instrument* instr)
00148 {
00149 xsh_rec_list* result = NULL;
00150
00151
00152 XSH_ASSURE_NOT_NULL( instr);
00153 XSH_ASSURE_NOT_ILLEGAL( size > 0);
00154
00155
00156 XSH_CALLOC(result, xsh_rec_list, 1);
00157
00158
00159 result->size = size;
00160
00161 XSH_ASSURE_NOT_ILLEGAL(result->size > 0);
00162 result->instrument = instr;
00163 XSH_CALLOC( result->list, xsh_rec, result->size);
00164 XSH_NEW_PROPERTYLIST( result->header);
00165 result->slit_min = 0.0;
00166 result->slit_max = 0.0;
00167 result->nslit = 0;
00168
00169 cleanup:
00170 if ( cpl_error_get_code() != CPL_ERROR_NONE) {
00171 xsh_rec_list_free( &result);
00172 }
00173 return result;
00174 }
00175
00190
00191 void xsh_rec_list_set_data_size( xsh_rec_list * list, int idx, int absorder,
00192 int nlambda, int ns )
00193 {
00194 xsh_rec * prec = NULL ;
00195 int depth ;
00196
00197 XSH_ASSURE_NOT_NULL( list) ;
00198 XSH_ASSURE_NOT_ILLEGAL( idx < list->size);
00199 XSH_CMP_INT( idx, >=, 0, "Index not in range",);
00200 XSH_CMP_INT( idx, <, list->size, "Index not in range",);
00201 XSH_CMP_INT( ns, >, 0, "Check size in slit",);
00202 XSH_CMP_INT( nlambda, >, 0, "Check size in lambda",);
00203
00204 prec = &list->list[idx] ;
00205 XSH_ASSURE_NOT_NULL( prec);
00206
00207
00208
00209 depth = nlambda*ns;
00210
00211 prec->order = absorder;
00212 prec->nlambda = nlambda;
00213 prec->nslit = ns;
00214 xsh_msg_dbg_high( "Rec Data Size: nlambda: %d, ns: %d, depth: %d",
00215 nlambda, ns, depth);
00216 XSH_CALLOC( prec->slit, float, ns) ;
00217 XSH_CALLOC( prec->lambda, double, nlambda);
00218 XSH_CALLOC( prec->data1, float, depth);
00219 XSH_CALLOC( prec->errs1, float, depth);
00220 XSH_CALLOC( prec->qual1, int, depth);
00221
00222 cleanup:
00223 return ;
00224 }
00225
00226 xsh_rec_list * xsh_rec_list_duplicate( xsh_rec_list * old,
00227 xsh_instrument * instrument )
00228 {
00229 xsh_rec_list * new = NULL ;
00230 int nb_orders, order ;
00231
00232 check( new = xsh_rec_list_create( instrument ) ) ;
00233
00234
00235 nb_orders = old->size ;
00236 for( order = 0 ; order < nb_orders ; order++ ) {
00237 int absorder, nslit, nlambda ;
00238 float * fold, * fnew ;
00239 int * iold, * inew ;
00240 double * dold, * dnew ;
00241
00242 absorder = xsh_rec_list_get_order( old, order ) ;
00243 nslit = xsh_rec_list_get_nslit( old, order ) ;
00244 nlambda = xsh_rec_list_get_nlambda( old, order ) ;
00245
00246 check( xsh_rec_list_set_data_size( new, order, absorder, nlambda, nslit ));
00247
00248
00249 fold = xsh_rec_list_get_data1( old, order ) ;
00250 fnew = xsh_rec_list_get_data1( new, order ) ;
00251 memcpy( fnew, fold, nlambda*nslit*sizeof( float ) ) ;
00252
00253 fold = xsh_rec_list_get_errs1( old, order ) ;
00254 fnew = xsh_rec_list_get_errs1( new, order ) ;
00255 memcpy( fnew, fold, nlambda*nslit*sizeof( float ) ) ;
00256
00257 iold = xsh_rec_list_get_qual1( old, order ) ;
00258 inew = xsh_rec_list_get_qual1( new, order ) ;
00259 memcpy( inew, iold, nlambda*nslit*sizeof( int ) ) ;
00260
00261 fold = xsh_rec_list_get_slit( old, order ) ;
00262 fnew = xsh_rec_list_get_slit( new, order ) ;
00263 memcpy( fnew, fold, nslit*sizeof( float ) ) ;
00264
00265 dold = xsh_rec_list_get_lambda( old, order ) ;
00266 dnew = xsh_rec_list_get_lambda( new, order ) ;
00267 memcpy( dnew, dold, nlambda*sizeof( double ) ) ;
00268 }
00269
00270 new->header = cpl_propertylist_duplicate( old->header ) ;
00271 new->instrument = xsh_instrument_duplicate( old->instrument ) ;
00272
00273 cleanup:
00274 return new ;
00275 }
00276
00277
00286
00287 #if 0
00288 xsh_rec_list* xsh_rec_list_load(cpl_frame* frame,
00289 xsh_instrument* instrument)
00290 {
00291 xsh_rec_list* result = NULL;
00292 const char * tablename = NULL ;
00293 const cpl_table * table = NULL;
00294 cpl_propertylist* header = NULL;
00295 int max_nlambda = 0, max_nslit = 0 ;
00296 int i ;
00297
00298
00299 XSH_ASSURE_NOT_NULL(frame);
00300 XSH_ASSURE_NOT_NULL(instrument);
00301
00302
00303 check(tablename = cpl_frame_get_filename(frame));
00304 xsh_msg_dbg_low( "Rectified Frame: %s", tablename ) ;
00305
00306
00307 XSH_TABLE_LOAD( table, tablename);
00308
00309 check(result = xsh_rec_list_create(instrument));
00310
00311 check(header = cpl_propertylist_load(tablename,0));
00312 check(cpl_propertylist_append(result->header, header));
00313
00314 XSH_ASSURE_NOT_ILLEGAL(result->size == cpl_table_get_nrow(table));
00315
00316 for(i=0;i<result->size;i++) {
00317 int nb, k, order, depth, nlambda, nslit ;
00318 const cpl_array * data_array ;
00319 const float * farray = NULL ;
00320 const int * iarray = NULL ;
00321
00322
00323 check(xsh_get_table_value(table, XSH_REC_TABLE_COLNAME_ORDER,
00324 CPL_TYPE_INT, i, &order));
00325 result->list[i].order = order ;
00326 check(xsh_get_table_value(table, XSH_REC_TABLE_COLNAME_NLAMBDA,
00327 CPL_TYPE_INT, i, &nlambda ));
00328 result->list[i].nlambda = nlambda ;
00329 check(xsh_get_table_value(table, XSH_REC_TABLE_COLNAME_NSLIT,
00330 CPL_TYPE_INT, i, &nslit ));
00331 result->list[i].nslit = nslit ;
00332 if ( nslit > max_nslit ) max_nslit = nslit ;
00333 if ( nlambda > max_nlambda ) max_nlambda = nlambda ;
00334
00335 xsh_msg_dbg_high( "Order %d (%d): nslt = %d, nlambda = %d", i, order,
00336 nslit, nlambda ) ;
00337
00338 xsh_rec_list_set_data_size( result, i, order, nlambda, nslit ) ;
00339 depth = nlambda*nslit ;
00340
00341 check( data_array = cpl_table_get_array( table,
00342 XSH_REC_TABLE_COLNAME_FLUX1,
00343 i )) ;
00344 nb = cpl_array_get_size( data_array ) ;
00345 XSH_ASSURE_NOT_ILLEGAL( nb >= depth ) ;
00346
00347
00348 check( farray = cpl_array_get_data_float_const( data_array ) ) ;
00349 for( k = 0 ; k<depth ; k++ ) *(result->list[i].data1+k) = *farray++ ;
00350
00351 farray = NULL ;
00352 check( data_array = cpl_table_get_array( table,
00353 XSH_REC_TABLE_COLNAME_ERRS1,
00354 i )) ;
00355 check( nb = cpl_array_get_size( data_array ) ) ;
00356
00357 check( farray = cpl_array_get_data_float_const( data_array ) ) ;
00358 for( k = 0 ; k<depth ; k++ ) *(result->list[i].errs1+k) = *farray++ ;
00359
00360 check( data_array = cpl_table_get_array( table,
00361 XSH_REC_TABLE_COLNAME_QUAL1,
00362 i )) ;
00363 nb = cpl_array_get_size( data_array ) ;
00364
00365 iarray = cpl_array_get_data_int_const( data_array ) ;
00366 for( k = 0 ; k<depth ; k++ ) *(result->list[i].qual1+k) = *iarray++ ;
00367
00368 }
00369 xsh_msg_dbg_high( "Max Lambda: %d, Max Slit: %d", max_nlambda, max_nslit ) ;
00370
00371 result->max_nlambda = max_nlambda ;
00372 result->max_nslit = max_nslit ;
00373
00374
00375 cleanup:
00376 return result;
00377 }
00378 #else
00379 xsh_rec_list* xsh_rec_list_load(cpl_frame* frame,
00380 xsh_instrument* instrument)
00381 {
00382 xsh_rec_list* result = NULL;
00383 const char * tablename = NULL ;
00384 cpl_table * table = NULL;
00385 cpl_propertylist* header = NULL;
00386 int nbext, i ;
00387 int size;
00388
00389
00390 XSH_ASSURE_NOT_NULL(frame);
00391 XSH_ASSURE_NOT_NULL(instrument);
00392
00393
00394 check(tablename = cpl_frame_get_filename(frame));
00395 xsh_msg_dbg_low( "Loading Rectified Frame: %s", tablename ) ;
00396
00397 check( size = cpl_frame_get_nextensions( frame));
00398
00399
00400
00401 XSH_CALLOC(result, xsh_rec_list, 1);
00402 result->size = size;
00403 XSH_ASSURE_NOT_ILLEGAL(result->size > 0);
00404 result->instrument = instrument;
00405
00406 XSH_CALLOC( result->list, xsh_rec, result->size);
00407
00408 XSH_NEW_PROPERTYLIST( result->header);
00409
00410 check(header = cpl_propertylist_load(tablename,0));
00411 check(cpl_propertylist_append(result->header, header));
00412
00413
00414
00415
00416 xsh_free_propertylist(&header);
00417
00418 nbext = size;
00419
00420 xsh_msg_dbg_medium( " Nb of extensions: %d", nbext ) ;
00421
00422 for( i = 0 ; i<nbext ; i++ ) {
00423 int nb, k, order, depth, nlambda, nslit ;
00424 const cpl_array * data_array ;
00425 const float * farray = NULL ;
00426 const int * iarray = NULL ;
00427
00428 check( table = cpl_table_load( tablename, i+1, 0 ) ) ;
00429 check(xsh_get_table_value(table, XSH_REC_TABLE_COLNAME_ORDER,
00430 CPL_TYPE_INT, 0, &order));
00431
00432 result->list[i].order = order ;
00433 check(xsh_get_table_value(table, XSH_REC_TABLE_COLNAME_NLAMBDA,
00434 CPL_TYPE_INT, 0, &nlambda ));
00435 result->list[i].nlambda = nlambda ;
00436 check(xsh_get_table_value(table, XSH_REC_TABLE_COLNAME_NSLIT,
00437 CPL_TYPE_INT, 0, &nslit ));
00438 result->list[i].nslit = nslit ;
00439 xsh_rec_list_set_data_size( result, i, order, nlambda, nslit ) ;
00440
00441 if (nslit > 1){
00442 check( xsh_table_get_array_float( table, XSH_REC_TABLE_COLNAME_SLIT,
00443 result->list[i].slit, nslit));
00444 }
00445 else{
00446 check(xsh_get_table_value(table, XSH_REC_TABLE_COLNAME_SLIT,
00447 CPL_TYPE_FLOAT, 0, result->list[i].slit ));
00448 }
00449 check( xsh_table_get_array_double( table, XSH_REC_TABLE_COLNAME_LAMBDA,
00450 result->list[i].lambda, nlambda));
00451
00452
00453 depth = nlambda*nslit ;
00454
00455 check( data_array = cpl_table_get_array( table,
00456 XSH_REC_TABLE_COLNAME_FLUX1,
00457 0 )) ;
00458 nb = cpl_array_get_size( data_array ) ;
00459 XSH_ASSURE_NOT_ILLEGAL( nb == depth ) ;
00460
00461
00462 check( farray = cpl_array_get_data_float_const( data_array ) ) ;
00463 for( k = 0 ; k<depth ; k++ ) *(result->list[i].data1+k) = *farray++ ;
00464
00465 farray = NULL ;
00466 check( data_array = cpl_table_get_array( table,
00467 XSH_REC_TABLE_COLNAME_ERRS1,
00468 0 )) ;
00469 check( nb = cpl_array_get_size( data_array ) ) ;
00470
00471 check( farray = cpl_array_get_data_float_const( data_array ) ) ;
00472 for( k = 0 ; k<depth ; k++ ) *(result->list[i].errs1+k) = *farray++ ;
00473
00474 check( data_array = cpl_table_get_array( table,
00475 XSH_REC_TABLE_COLNAME_QUAL1,
00476 0 )) ;
00477 nb = cpl_array_get_size( data_array ) ;
00478
00479 iarray = cpl_array_get_data_int_const( data_array ) ;
00480 for( k = 0 ; k<depth ; k++ ) *(result->list[i].qual1+k) = *iarray++ ;
00481
00482 xsh_msg_dbg_low( " Loaded, order %d, nlambda %d, nslit %d",
00483 order, nlambda, nslit ) ;
00484
00485 cpl_table_delete( table ) ;
00486 }
00487
00488 cleanup:
00489 xsh_free_propertylist(&header);
00490 return result ;
00491 }
00492 #endif
00493
00494
00495 xsh_rec_list* xsh_rec_list_load_eso(cpl_frame* frame,
00496 xsh_instrument* instrument)
00497 {
00498 xsh_rec_list* result = NULL;
00499 const char * imagelist_name = NULL ;
00500 cpl_image * ima_data = NULL;
00501 cpl_image * ima_errs = NULL;
00502 cpl_image * ima_qual = NULL;
00503 cpl_propertylist* header = NULL;
00504 cpl_propertylist* hdata=NULL;
00505 cpl_propertylist* herrs=NULL;
00506 cpl_propertylist* hqual=NULL;
00507 const char* ext_name=NULL;
00508
00509 int nbext, i,j ;
00510 int size;
00511
00512
00513 XSH_ASSURE_NOT_NULL(frame);
00514 XSH_ASSURE_NOT_NULL(instrument);
00515
00516
00517
00518 check(imagelist_name = cpl_frame_get_filename(frame));
00519 xsh_msg_dbg_low( "Loading Rectified Frame: %s", imagelist_name ) ;
00520
00521 check( nbext = cpl_frame_get_nextensions( frame));
00522
00523
00524 size=(nbext+1)/3;
00525
00526
00527
00528 XSH_CALLOC(result, xsh_rec_list, 1);
00529 result->size = size;
00530 XSH_ASSURE_NOT_ILLEGAL(result->size > 0);
00531 result->instrument = instrument;
00532
00533 XSH_CALLOC( result->list, xsh_rec, result->size);
00534
00535 XSH_NEW_PROPERTYLIST( result->header);
00536
00537
00538 check(header = cpl_propertylist_load(imagelist_name,0));
00539 check(cpl_propertylist_append(result->header, header));
00540
00541 xsh_free_propertylist(&header);
00542
00543
00544
00545 xsh_msg_dbg_medium( " Nb of extensions: %d", nbext ) ;
00546
00547
00548 for( i = 0,j=0 ; j<nbext ; i++, j+=3 ) {
00549 int k, order, depth, nlambda, nslit ;
00550 const float * farray = NULL ;
00551 const int * iarray = NULL ;
00552 double s_step=0;
00553 double w_step=0;
00554 double s_start=0;
00555 double w_start=0;
00556 int sx=0;
00557 int sy=0;
00558
00559 check(ima_data=cpl_image_load(imagelist_name,XSH_PRE_DATA_TYPE,0,j+0));
00560 check(ima_errs=cpl_image_load(imagelist_name,XSH_PRE_ERRS_TYPE,0,j+1));
00561 check(ima_qual=cpl_image_load(imagelist_name,XSH_PRE_QUAL_TYPE,0,j+2));
00562
00563 check( hdata = cpl_propertylist_load( imagelist_name, j+0 ) ) ;
00564 check( herrs = cpl_propertylist_load( imagelist_name, j+1 ) ) ;
00565 check( hqual = cpl_propertylist_load( imagelist_name, j+2 ) ) ;
00566 check(ext_name=xsh_pfits_get_extname(herrs));
00567 order=10*(ext_name[3]-48)+(ext_name[4]-48);
00568
00569
00570
00571 result->list[i].order = order ;
00572
00573 nlambda=xsh_pfits_get_naxis1(herrs);
00574 nslit=xsh_pfits_get_naxis2(herrs);
00575
00576 w_step=xsh_pfits_get_cdelt1(herrs);
00577 s_step=xsh_pfits_get_cdelt2(herrs);
00578
00579 w_start=xsh_pfits_get_crval1(herrs);
00580 s_start=xsh_pfits_get_crval2(herrs);
00581
00582 result->list[i].nlambda = nlambda ;
00583 result->list[i].nslit = nslit ;
00584
00585 xsh_rec_list_set_data_size( result, i, order, nlambda, nslit ) ;
00586
00587
00588 if (nslit > 1){
00589 for(k=0;k<nslit;k++) {
00590 *(result->list[i].slit+k)=(s_start+k*s_step);
00591 }
00592 }
00593 else{
00594 for(k=0;k<nslit;k++) {
00595 *(result->list[i].slit+k)=0;
00596 }
00597 }
00598
00599
00600 for(k=0;k<nlambda;k++) {
00601 *(result->list[i].lambda+k)=(w_start+k*w_step);
00602 }
00603
00604 depth = nlambda*nslit ;
00605
00606
00607 check( farray = cpl_image_get_data_float( ima_data)) ;
00608 sx = cpl_image_get_size_x( ima_data ) ;
00609 sy = cpl_image_get_size_y( ima_data ) ;
00610 XSH_ASSURE_NOT_ILLEGAL( sx*sy == depth ) ;
00611
00612 for( k = 0 ; k<depth ; k++ ) *(result->list[i].data1+k) = *farray++ ;
00613 farray = NULL ;
00614
00615
00616 check( farray = cpl_image_get_data_float( ima_errs)) ;
00617 for( k = 0 ; k<depth ; k++ ) *(result->list[i].errs1+k) = *farray++ ;
00618
00619
00620 check( iarray = cpl_image_get_data_int( ima_qual)) ;
00621 for( k = 0 ; k<depth ; k++ ) *(result->list[i].qual1+k) = *iarray++ ;
00622
00623 xsh_msg_dbg_low( " Loaded, order %d, nlambda %d, nslit %d",
00624 order, nlambda, nslit ) ;
00625
00626 xsh_free_image( &ima_data ) ;
00627 xsh_free_image( &ima_errs ) ;
00628 xsh_free_image( &ima_qual ) ;
00629 xsh_free_propertylist( &hdata ) ;
00630 xsh_free_propertylist( &herrs ) ;
00631 xsh_free_propertylist( &hqual ) ;
00632
00633 }
00634
00635 cleanup:
00636 xsh_free_image( &ima_data ) ;
00637 xsh_free_image( &ima_errs ) ;
00638 xsh_free_image( &ima_qual ) ;
00639 xsh_free_propertylist( &hdata ) ;
00640 xsh_free_propertylist( &herrs ) ;
00641 xsh_free_propertylist( &hqual ) ;
00642
00643 xsh_free_propertylist(&header);
00644
00645 return result ;
00646 }
00647
00648
00649
00650
00651
00665
00666 cpl_frame * xsh_rec_list_frame_invert( cpl_frame * rec_frame,
00667 const char *tag, xsh_instrument *instrument)
00668 {
00669 cpl_frame *result = NULL;
00670 xsh_rec_list *rec_list = NULL;
00671 int norders, order;
00672 float *data = NULL;
00673 char fname[256];
00674
00675
00676 XSH_ASSURE_NOT_NULL( rec_frame);
00677 XSH_ASSURE_NOT_NULL( tag);
00678 XSH_ASSURE_NOT_NULL( instrument);
00679
00680 check( rec_list = xsh_rec_list_load( rec_frame, instrument));
00681
00682
00683 norders = rec_list->size;
00684 for( order = 0; order < norders; order++) {
00685 int i;
00686 int img_size, nlambda, nslit;
00687
00688 check( nlambda = xsh_rec_list_get_nlambda( rec_list, order));
00689 check( nslit = xsh_rec_list_get_nslit( rec_list, order));
00690 img_size = nlambda * nslit;
00691
00692 check( data = xsh_rec_list_get_data1( rec_list, order ) ) ;
00693 for( i = 0 ; i< img_size ; i++, data++ ) {
00694 *data *= -1.;
00695 }
00696 }
00697
00698
00699 sprintf( fname,"%s.fits", tag);
00700 check( result = xsh_rec_list_save( rec_list, fname, tag, 0 ) ) ;
00701
00702 cleanup:
00703 xsh_rec_list_free( &rec_list ) ;
00704 return result ;
00705 }
00706
00707
00712
00713 void xsh_rec_list_free(xsh_rec_list** list)
00714 {
00715 if (list != NULL && *list != NULL ) {
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725 int i ;
00726 xsh_rec_list * plist = NULL;
00727
00728 plist = *list;
00729
00730
00731 for (i = 0; i < plist->size; i++) {
00732 xsh_rec * pr = &(plist->list[i]) ;
00733
00734 xsh_msg_dbg_high( "Freeing order index %d", i ) ;
00735 if ( pr == NULL ) continue ;
00736 xsh_msg_dbg_high( " Abs Order: %d", pr->order ) ;
00737 cpl_free( pr->slit ) ;
00738 cpl_free( pr->lambda ) ;
00739 cpl_free( pr->data1 ) ;
00740 cpl_free( pr->errs1 ) ;
00741 cpl_free( pr->qual1 ) ;
00742 }
00743 if ((*list)->list){
00744 cpl_free((*list)->list);
00745 }
00746
00747 xsh_free_propertylist(&((*list)->header));
00748 cpl_free(*list);
00749 *list = NULL;
00750 }
00751 }
00752
00753
00754
00755
00761
00762 cpl_propertylist * xsh_rec_list_get_header(xsh_rec_list* list)
00763 {
00764 cpl_propertylist * res = NULL;
00765
00766 XSH_ASSURE_NOT_NULL(list);
00767 res = list->header;
00768 cleanup:
00769 return res;
00770 }
00771
00780 int xsh_rec_list_get_nslit( xsh_rec_list* list, int idx )
00781 {
00782 int res = 0 ;
00783
00784 XSH_ASSURE_NOT_NULL(list);
00785 res = list->list[idx].nslit ;
00786
00787 cleanup:
00788 return res ;
00789 }
00790
00799 int xsh_rec_list_get_order( xsh_rec_list* list, int idx )
00800 {
00801 int res = 0 ;
00802
00803 XSH_ASSURE_NOT_NULL(list);
00804 res = list->list[idx].order ;
00805
00806 cleanup:
00807 return res ;
00808 }
00809
00818 int xsh_rec_list_get_nlambda( xsh_rec_list* list, int idx )
00819 {
00820 int res = 0 ;
00821
00822 XSH_ASSURE_NOT_NULL( list);
00823 res = list->list[idx].nlambda ;
00824
00825 cleanup:
00826 return res ;
00827 }
00828
00837 float * xsh_rec_list_get_slit( xsh_rec_list* list, int idx )
00838 {
00839 float * res = NULL ;
00840
00841 XSH_ASSURE_NOT_NULL(list);
00842 res = list->list[idx].slit ;
00843
00844 cleanup:
00845 return res ;
00846 }
00847
00848
00856 double xsh_rec_list_get_slit_min( xsh_rec_list* list)
00857 {
00858 double res = 0 ;
00859
00860 XSH_ASSURE_NOT_NULL(list);
00861 res = list->slit_min ;
00862
00863 cleanup:
00864 return res ;
00865 }
00866
00867
00868
00876 double xsh_rec_list_get_slit_max( xsh_rec_list* list)
00877 {
00878 double res = 0 ;
00879
00880 XSH_ASSURE_NOT_NULL(list);
00881 res = list->slit_max ;
00882
00883 cleanup:
00884 return res ;
00885 }
00886
00887
00888 double xsh_rec_list_get_lambda_min( xsh_rec_list* list)
00889 {
00890 double lambda_min = 10000;
00891 int i;
00892
00893 XSH_ASSURE_NOT_NULL( list);
00894
00895 for( i=0; i< list->size; i++){
00896 if ( list->list[i].lambda != NULL){
00897 double lambda;
00898
00899 lambda = list->list[i].lambda[0];
00900 if ( lambda < lambda_min){
00901 lambda_min = lambda;
00902 }
00903 }
00904 }
00905
00906 cleanup:
00907 return lambda_min;
00908 }
00909
00910 double xsh_rec_list_get_lambda_max( xsh_rec_list* list)
00911 {
00912 double lambda_max =0.0;
00913 int i;
00914
00915 XSH_ASSURE_NOT_NULL( list);
00916
00917 for( i=0; i< list->size; i++){
00918 if ( list->list[i].lambda != NULL){
00919 double lambda;
00920
00921 lambda = list->list[i].lambda[list->list[i].nlambda-1];
00922 if ( lambda > lambda_max){
00923 lambda_max = lambda;
00924 }
00925 }
00926 }
00927 cleanup:
00928 return lambda_max;
00929 }
00930
00931
00940 cpl_error_code xsh_rec_list_set_slit_min( xsh_rec_list* list, const double val)
00941 {
00942
00943 XSH_ASSURE_NOT_NULL(list);
00944 list->slit_min = val;
00945
00946 cleanup:
00947 return cpl_error_get_code() ;
00948 }
00949
00950
00951
00960 cpl_error_code xsh_rec_list_set_slit_max( xsh_rec_list* list,const double val)
00961 {
00962
00963 XSH_ASSURE_NOT_NULL(list);
00964 list->slit_max = val;
00965
00966 cleanup:
00967 return cpl_error_get_code() ;
00968 }
00969
00970
00979 double* xsh_rec_list_get_lambda( xsh_rec_list* list, int idx )
00980 {
00981 double* res = NULL ;
00982
00983 XSH_ASSURE_NOT_NULL(list);
00984 res = list->list[idx].lambda ;
00985
00986 cleanup:
00987 return res ;
00988 }
00989
00998 float * xsh_rec_list_get_data1( xsh_rec_list* list, int idx )
00999 {
01000 float * res = NULL ;
01001
01002 XSH_ASSURE_NOT_NULL(list);
01003 res = list->list[idx].data1 ;
01004
01005 cleanup:
01006 return res ;
01007 }
01008
01017 float * xsh_rec_list_get_errs1( xsh_rec_list* list, int idx )
01018 {
01019 float * res = NULL ;
01020
01021 XSH_ASSURE_NOT_NULL(list);
01022 res = list->list[idx].errs1 ;
01023
01024 cleanup:
01025 return res ;
01026 }
01027
01036 int * xsh_rec_list_get_qual1( xsh_rec_list* list, int idx )
01037 {
01038 int * res = NULL ;
01039
01040 XSH_ASSURE_NOT_NULL(list);
01041 res = list->list[idx].qual1 ;
01042
01043 cleanup:
01044 return res ;
01045 }
01046
01047
01048
01064
01065 cpl_frame* xsh_rec_list_save( xsh_rec_list* list, const char* filename,
01066 const char* tag, int is_temp)
01067 {
01068 cpl_frame * result = NULL ;
01069 cpl_table * table = NULL;
01070 int nlambda = 0, nslit = 0, depth = 0;
01071 cpl_array * dim = NULL, * temp_array = NULL ;
01072 int i, k, order;
01073 unsigned mode = CPL_IO_DEFAULT;
01074
01075
01076 XSH_ASSURE_NOT_NULL( list);
01077 XSH_ASSURE_NOT_NULL( filename);
01078 XSH_ASSURE_NOT_ILLEGAL( list->size > 0);
01079
01080
01081 for( i = 0 ; i < list->size ; i++ ) {
01082
01083 nlambda = list->list[i].nlambda;
01084 nslit = list->list[i].nslit;
01085 depth = nlambda*nslit;
01086 order = list->list[i].order;
01087
01088
01089 if (depth == 0){
01090 continue;
01091 }
01092 check( table = cpl_table_new( 1));
01093
01094
01095 check(cpl_table_new_column( table, XSH_REC_TABLE_COLNAME_ORDER,
01096 CPL_TYPE_INT));
01097 check(cpl_table_new_column( table, XSH_REC_TABLE_COLNAME_NLAMBDA,
01098 CPL_TYPE_INT));
01099 check(cpl_table_new_column( table, XSH_REC_TABLE_COLNAME_NSLIT,
01100 CPL_TYPE_INT));
01101 check(cpl_table_new_column_array( table, XSH_REC_TABLE_COLNAME_LAMBDA,
01102 CPL_TYPE_DOUBLE, nlambda));
01103 check(cpl_table_new_column_array( table, XSH_REC_TABLE_COLNAME_SLIT,
01104 CPL_TYPE_FLOAT, nslit));
01105 check(cpl_table_new_column_array( table, XSH_REC_TABLE_COLNAME_FLUX1,
01106 CPL_TYPE_FLOAT, depth));
01107 check( cpl_table_new_column_array( table, XSH_REC_TABLE_COLNAME_ERRS1,
01108 CPL_TYPE_FLOAT, depth));
01109 check( cpl_table_new_column_array( table, XSH_REC_TABLE_COLNAME_QUAL1,
01110 CPL_TYPE_INT, depth));
01111
01112
01113 check( dim = cpl_array_new( 1, CPL_TYPE_INT)) ;
01114 cpl_array_set_int( dim, 0, nlambda);
01115 check( cpl_table_set_column_dimensions(
01116 table, XSH_REC_TABLE_COLNAME_LAMBDA, dim));
01117 cpl_array_set_int( dim, 0, nslit);
01118 check( cpl_table_set_column_dimensions( table,
01119 XSH_REC_TABLE_COLNAME_SLIT, dim));
01120 xsh_free_array( &dim);
01121
01122 check( dim = cpl_array_new( 2, CPL_TYPE_INT)) ;
01123 cpl_array_set_int( dim, 0, nlambda);
01124 cpl_array_set_int( dim, 1, nslit);
01125
01126 check( cpl_table_set_column_dimensions( table,
01127 XSH_REC_TABLE_COLNAME_FLUX1, dim));
01128 check( cpl_table_set_column_dimensions( table,
01129 XSH_REC_TABLE_COLNAME_ERRS1, dim));
01130 check( cpl_table_set_column_dimensions( table,
01131 XSH_REC_TABLE_COLNAME_QUAL1, dim));
01132 xsh_free_array( &dim);
01133
01134
01135 check( cpl_table_set_int( table, XSH_REC_TABLE_COLNAME_ORDER, 0,
01136 order));
01137 check( cpl_table_set_int( table, XSH_REC_TABLE_COLNAME_NLAMBDA, 0,
01138 nlambda));
01139 check( cpl_table_set_int( table, XSH_REC_TABLE_COLNAME_NSLIT, 0,
01140 nslit));
01141
01142
01143 check ( temp_array = cpl_array_new( nslit, CPL_TYPE_FLOAT));
01144 for( k = 0 ; k<nslit ; k++ ) {
01145 check( cpl_array_set_float( temp_array, k,
01146 *(list->list[i].slit+k)));
01147 }
01148
01149 check( cpl_table_set_array( table, XSH_REC_TABLE_COLNAME_SLIT, 0,
01150 temp_array));
01151 xsh_free_array( &temp_array);
01152
01153
01154 check( temp_array = cpl_array_new( nlambda, CPL_TYPE_DOUBLE));
01155 for( k = 0 ; k<nlambda ; k++ ) {
01156 check( cpl_array_set_double( temp_array, k,
01157 *(list->list[i].lambda+k)));
01158 }
01159
01160 check( cpl_table_set_array( table, XSH_REC_TABLE_COLNAME_LAMBDA, 0,
01161 temp_array));
01162 xsh_free_array( &temp_array);
01163
01164
01165 check( temp_array = cpl_array_new( depth, CPL_TYPE_FLOAT));
01166 for( k = 0 ; k<depth ; k++ ) {
01167 check( cpl_array_set_float( temp_array, k,
01168 *(list->list[i].data1+k) ) ) ;
01169 }
01170 check( cpl_table_set_array( table, XSH_REC_TABLE_COLNAME_FLUX1, 0,
01171 temp_array));
01172
01173 for( k = 0 ; k<depth ; k++ ) {
01174 check( cpl_array_set_float( temp_array, k,
01175 *(list->list[i].errs1+k) ) ) ;
01176 }
01177 check( cpl_table_set_array( table, XSH_REC_TABLE_COLNAME_ERRS1, 0,
01178 temp_array));
01179 xsh_free_array( &temp_array);
01180
01181 check( temp_array = cpl_array_new( depth, CPL_TYPE_INT));
01182 for( k = 0 ; k<depth ; k++ ) {
01183 check( cpl_array_set_int( temp_array, k,
01184 *(list->list[i].qual1+k)));
01185 }
01186 check( cpl_table_set_array( table, XSH_REC_TABLE_COLNAME_QUAL1, 0,
01187 temp_array));
01188 xsh_free_array( &temp_array ) ;
01189
01190
01191
01192 check( cpl_table_save( table, list->header, NULL, filename, mode));
01193 mode = CPL_IO_EXTEND;
01194 XSH_TABLE_FREE( table);
01195 }
01196
01197
01198 check( result = xsh_frame_product( filename, tag, CPL_FRAME_TYPE_IMAGE,
01199 CPL_FRAME_GROUP_PRODUCT, CPL_FRAME_LEVEL_FINAL));
01200
01201 if ( is_temp == CPL_TRUE){
01202 check( cpl_frame_set_level( result, CPL_FRAME_LEVEL_TEMPORARY));
01203 xsh_add_temporary_file( filename);
01204 }
01205
01206 cleanup:
01207 XSH_TABLE_FREE( table);
01208 xsh_free_array( &temp_array);
01209 return result ;
01210 }
01211
01212
01213
01226
01227 void xsh_rec_list_update_header( xsh_rec_list *rec_list, xsh_pre *pre,
01228 xsh_rectify_param *rec_par, const char* pro_catg)
01229 {
01230 double lambda_min, lambda_max;
01231
01232
01233 XSH_ASSURE_NOT_NULL( rec_list);
01234 XSH_ASSURE_NOT_NULL( pre);
01235 XSH_ASSURE_NOT_NULL( rec_par);
01236
01237
01238 check( cpl_propertylist_append( rec_list->header, pre->data_header));
01239
01240
01241 check( xsh_pfits_set_rectify_bin_lambda( rec_list->header,
01242 rec_par->rectif_bin_lambda));
01243 check( xsh_pfits_set_rectify_bin_space( rec_list->header,
01244 rec_par->rectif_bin_space));
01245
01246 check( lambda_min = xsh_rec_list_get_lambda_min( rec_list));
01247 check( lambda_max = xsh_rec_list_get_lambda_max( rec_list));
01248
01249 check( xsh_pfits_set_rectify_lambda_min(rec_list->header,
01250 lambda_min)) ;
01251 check( xsh_pfits_set_rectify_lambda_max(rec_list->header,
01252 lambda_max));
01253
01254 check( xsh_pfits_set_rectify_space_min( rec_list->header,
01255 rec_list->slit_min));
01256 check( xsh_pfits_set_rectify_space_max( rec_list->header,
01257 rec_list->slit_max));
01258 check( xsh_pfits_set_pcatg( rec_list->header, pro_catg));
01259
01260 cleanup:
01261 return;
01262 }
01263
01264
01265
01266
01282
01283 cpl_frame* xsh_rec_list_save_table( xsh_rec_list* list, const char* filename,
01284 const char* tag, int is_temp)
01285 {
01286 cpl_frame * result = NULL ;
01287 cpl_table * table = NULL;
01288 int nlambda = 0, nslit = 0, depth = 0;
01289 cpl_array * dim = NULL, * temp_array = NULL ;
01290 int i, k, order;
01291 unsigned mode = CPL_IO_DEFAULT;
01292
01293
01294 XSH_ASSURE_NOT_NULL( list);
01295 XSH_ASSURE_NOT_NULL( filename);
01296 XSH_ASSURE_NOT_ILLEGAL( list->size > 0);
01297
01298
01299 for( i = 0 ; i < list->size ; i++ ) {
01300
01301 nlambda = list->list[i].nlambda;
01302 nslit = list->list[i].nslit;
01303 depth = nlambda*nslit;
01304 order = list->list[i].order;
01305
01306
01307 if (depth == 0){
01308 continue;
01309 }
01310 check( table = cpl_table_new( 1));
01311
01312
01313 check(cpl_table_new_column( table, XSH_REC_TABLE_COLNAME_ORDER,
01314 CPL_TYPE_INT));
01315 check(cpl_table_new_column( table, XSH_REC_TABLE_COLNAME_NLAMBDA,
01316 CPL_TYPE_INT));
01317 check(cpl_table_new_column( table, XSH_REC_TABLE_COLNAME_NSLIT,
01318 CPL_TYPE_INT));
01319 check(cpl_table_new_column_array( table, XSH_REC_TABLE_COLNAME_LAMBDA,
01320 CPL_TYPE_DOUBLE, nlambda));
01321 check(cpl_table_new_column_array( table, XSH_REC_TABLE_COLNAME_SLIT,
01322 CPL_TYPE_FLOAT, nslit));
01323
01324
01325 check( dim = cpl_array_new( 1, CPL_TYPE_INT)) ;
01326 cpl_array_set_int( dim, 0, nlambda);
01327 check( cpl_table_set_column_dimensions(
01328 table, XSH_REC_TABLE_COLNAME_LAMBDA, dim));
01329 cpl_array_set_int( dim, 0, nslit);
01330 check( cpl_table_set_column_dimensions( table,
01331 XSH_REC_TABLE_COLNAME_SLIT, dim));
01332 xsh_free_array( &dim);
01333
01334 check( dim = cpl_array_new( 2, CPL_TYPE_INT)) ;
01335 cpl_array_set_int( dim, 0, nlambda);
01336 cpl_array_set_int( dim, 1, nslit);
01337
01338 xsh_free_array( &dim);
01339
01340
01341 check( cpl_table_set_int( table, XSH_REC_TABLE_COLNAME_ORDER, 0,
01342 order));
01343 check( cpl_table_set_int( table, XSH_REC_TABLE_COLNAME_NLAMBDA, 0,
01344 nlambda));
01345 check( cpl_table_set_int( table, XSH_REC_TABLE_COLNAME_NSLIT, 0,
01346 nslit));
01347
01348
01349 check ( temp_array = cpl_array_new( nslit, CPL_TYPE_FLOAT));
01350 for( k = 0 ; k<nslit ; k++ ) {
01351 check( cpl_array_set_float( temp_array, k,
01352 *(list->list[i].slit+k)));
01353 }
01354
01355 check( cpl_table_set_array( table, XSH_REC_TABLE_COLNAME_SLIT, 0,
01356 temp_array));
01357 xsh_free_array( &temp_array);
01358
01359
01360 check( temp_array = cpl_array_new( nlambda, CPL_TYPE_DOUBLE));
01361 for( k = 0 ; k<nlambda ; k++ ) {
01362 check( cpl_array_set_double( temp_array, k,
01363 *(list->list[i].lambda+k)));
01364 }
01365
01366 check( cpl_table_set_array( table, XSH_REC_TABLE_COLNAME_LAMBDA, 0,
01367 temp_array));
01368 xsh_free_array( &temp_array);
01369
01370
01371
01372 check( cpl_table_save( table, list->header, NULL, filename, mode));
01373 mode = CPL_IO_EXTEND;
01374 XSH_TABLE_FREE( table);
01375 }
01376
01377
01378 check( result = xsh_frame_product( filename, tag, CPL_FRAME_TYPE_TABLE,
01379 CPL_FRAME_GROUP_PRODUCT, CPL_FRAME_LEVEL_FINAL));
01380
01381 if ( is_temp == CPL_TRUE){
01382 check( cpl_frame_set_level( result, CPL_FRAME_LEVEL_TEMPORARY));
01383 xsh_add_temporary_file( filename);
01384 }
01385
01386 cleanup:
01387 XSH_TABLE_FREE( table);
01388 xsh_free_array( &temp_array);
01389 return result ;
01390 }
01391
01392
01393
01394
01404
01405 cpl_frame*
01406 xsh_rec_list_save2(xsh_rec_list* list,const char* filename, const char* tag)
01407 {
01408
01409 cpl_table * table = NULL;
01410 int nlambda, nslit, depth ;
01411 cpl_array * temp_array = NULL ;
01412 int i, k, order ;
01413
01414 cpl_image* img_lambda=NULL;
01415 cpl_image* img_slit=NULL;
01416
01417 cpl_image* img_flux=NULL;
01418 cpl_image* img_err=NULL;
01419 cpl_image* img_qual=NULL;
01420 cpl_frame* result=NULL;
01421
01422
01423
01424 double* plambda=NULL;
01425 float* pslit=NULL;
01426
01427 float* pflux=NULL;
01428 float* perr=NULL;
01429 int* pqual=NULL;
01430 double cdelt1=0;
01431 double cdelt2=0;
01432 double crpix1=0;
01433 double crpix2=0;
01434 double crval1=0;
01435 double crval2=0;
01436
01437 char extname[20];
01438 unsigned mode = CPL_IO_DEFAULT;
01439 cpl_propertylist *header = NULL;
01440
01441
01442 XSH_ASSURE_NOT_NULL( list);
01443 XSH_ASSURE_NOT_NULL( filename);
01444 XSH_ASSURE_NOT_ILLEGAL( list->size > 0 ) ;
01445
01446
01447 for( i = 0; i < list->size ; i++ ) {
01448 nlambda = list->list[i].nlambda ;
01449 nslit = list->list[i].nslit ;
01450 depth = nlambda*nslit ;
01451 order = list->list[i].order ;
01452
01453 xsh_msg_dbg_high("depth %d : %dx%d", depth, nslit, nlambda);
01454
01455
01456 if (depth == 0){
01457 continue;
01458 }
01459 check( header = cpl_propertylist_duplicate( list->header));
01460
01461 check(img_lambda=cpl_image_new(nlambda,1,CPL_TYPE_DOUBLE));
01462 check(img_slit=cpl_image_new(nslit,1,CPL_TYPE_FLOAT));
01463 check(img_flux=cpl_image_new(nlambda,nslit,CPL_TYPE_FLOAT));
01464 check(img_err=cpl_image_new(nlambda,nslit,CPL_TYPE_FLOAT));
01465 check(img_qual=cpl_image_new(nlambda,nslit,CPL_TYPE_INT));
01466
01467 check(plambda=cpl_image_get_data_double(img_lambda));
01468 check(pslit=cpl_image_get_data_float(img_slit));
01469 check(pflux=cpl_image_get_data_float(img_flux));
01470 check(perr=cpl_image_get_data_float(img_err));
01471 check(pqual=cpl_image_get_data_int(img_qual));
01472
01473 for( k = 0 ; k<nslit ; k++ ) {
01474 pslit[k]= (*(list->list[i].slit+k) ) ;
01475 }
01476 for( k = 0 ; k<nlambda ; k++ ) {
01477 plambda[k]= (*(list->list[i].lambda+k) ) ;
01478 }
01479
01480 if (nlambda > 1){
01481 cdelt1=plambda[1]-plambda[0];
01482 crpix1=1.;
01483 crval1=plambda[0];
01484 check( xsh_pfits_set_crpix1( header, crpix1));
01485 check( xsh_pfits_set_crval1( header, crval1));
01486 check( xsh_pfits_set_cdelt1( header, cdelt1));
01487 check( cpl_propertylist_append_string( header,"CTYPE1","LINEAR"));
01488 xsh_msg_dbg_high("write axis 1 : %f %f %f", crpix1, crval1, cdelt1);
01489 }
01490
01491 for( k = 0 ; k<depth ; k++ ) {
01492 pflux[k]= (*(list->list[i].data1+k) ) ;
01493 perr[k]= (*(list->list[i].errs1+k) ) ;
01494 pqual[k]= (*(list->list[i].qual1+k) ) ;
01495 }
01496
01497
01498
01499 xsh_msg_dbg_high("nslit %d", nslit);
01500 crpix2=1.;
01501 crval2=pslit[0];
01502 cdelt2=pslit[1]-pslit[0];
01503 xsh_pfits_set_crpix2( header, crpix2);
01504 xsh_pfits_set_crval2( header, crval2);
01505 xsh_pfits_set_cdelt2( header, cdelt2);
01506 cpl_propertylist_append_string( header,"CTYPE2","LINEAR");
01507
01508 xsh_pfits_set_extract_slit_min( header,list->slit_min);
01509 xsh_pfits_set_extract_slit_max( header,list->slit_max);
01510
01511
01512 sprintf(extname,"ORD%d_FLUX",order);
01513 xsh_msg_dbg_high("extname %s", extname);
01514
01515 check( xsh_pfits_set_extname( header, extname));
01516
01517 check(cpl_image_save(img_flux,filename, CPL_BPP_IEEE_FLOAT,
01518 header, mode));
01519
01520 sprintf(extname,"ORD%d_ERRS",order);
01521 xsh_pfits_set_extname( header, extname);
01522 check(cpl_image_save(img_err,filename, CPL_BPP_IEEE_FLOAT,
01523 header, CPL_IO_EXTEND)) ;
01524
01525 sprintf(extname,"ORD%d_QUAL",order);
01526 xsh_pfits_set_extname( header,extname);
01527 check(cpl_image_save(img_qual, filename, XSH_PRE_QUAL_BPP,
01528 header, CPL_IO_EXTEND)) ;
01529
01530 mode = CPL_IO_EXTEND;
01531
01532 xsh_free_image(&img_lambda);
01533 xsh_free_image(&img_slit);
01534 xsh_free_image(&img_flux);
01535 xsh_free_image(&img_err);
01536 xsh_free_image(&img_qual);
01537 xsh_free_propertylist( &header);
01538 }
01539
01540 check(result=xsh_frame_product(filename,tag,CPL_FRAME_TYPE_IMAGE,
01541 CPL_FRAME_GROUP_PRODUCT,
01542 CPL_FRAME_LEVEL_FINAL));
01543 cleanup:
01544 xsh_free_propertylist( &header);
01545 XSH_TABLE_FREE( table);
01546 xsh_free_array( &temp_array ) ;
01547 return result ;
01548 }
01549
01550
01551
01552
01553
01554 void xsh_rec_get_nod_kw( cpl_frame * rec_frame, double * throw,
01555 double * jitter,
01556 double * reloffset, double * cumoffset )
01557 {
01558 cpl_propertylist * header ;
01559 const char *fname = NULL ;
01560 double val ;
01561
01562 XSH_ASSURE_NOT_NULL( rec_frame ) ;
01563 check( fname = cpl_frame_get_filename( rec_frame ) ) ;
01564 check( header = cpl_propertylist_load( fname, 0 ) ) ;
01565
01566 val = xsh_pfits_get_nodthrow( header ) ;
01567 if ( cpl_error_get_code() == CPL_ERROR_NONE ) {
01568 *throw = val ;
01569 }
01570 else cpl_error_reset() ;
01571
01572 val = xsh_pfits_get_nod_jitterwidth( header ) ;
01573 if ( cpl_error_get_code() == CPL_ERROR_NONE ) {
01574 *jitter = val ;
01575 }
01576 else
01577 cpl_error_reset() ;
01578
01579 val = xsh_pfits_get_nod_reloffset( header ) ;
01580 if ( cpl_error_get_code() == CPL_ERROR_NONE ) {
01581 *reloffset = val ;
01582 }
01583 else cpl_error_reset() ;
01584
01585 val = xsh_pfits_get_nod_cumoffset( header ) ;
01586 if ( cpl_error_get_code() == CPL_ERROR_NONE ) {
01587 *cumoffset = val ;
01588 }
01589 else cpl_error_reset() ;
01590
01591 cleanup:
01592 xsh_free_propertylist( &header ) ;
01593 return ;
01594 }
01595