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 xsh_free_propertylist(&(new->header));
00271 new->header = cpl_propertylist_duplicate( old->header ) ;
00272 new->instrument = xsh_instrument_duplicate( old->instrument ) ;
00273
00274 cleanup:
00275 return new ;
00276 }
00277
00278
00287
00288 #if 0
00289 xsh_rec_list* xsh_rec_list_load(cpl_frame* frame,
00290 xsh_instrument* instrument)
00291 {
00292 xsh_rec_list* result = NULL;
00293 const char * tablename = NULL ;
00294 const cpl_table * table = NULL;
00295 cpl_propertylist* header = NULL;
00296 int max_nlambda = 0, max_nslit = 0 ;
00297 int i ;
00298
00299
00300 XSH_ASSURE_NOT_NULL(frame);
00301 XSH_ASSURE_NOT_NULL(instrument);
00302
00303
00304 check(tablename = cpl_frame_get_filename(frame));
00305 xsh_msg_dbg_low( "Rectified Frame: %s", tablename ) ;
00306
00307
00308 XSH_TABLE_LOAD( table, tablename);
00309
00310 check(result = xsh_rec_list_create(instrument));
00311
00312 check(header = cpl_propertylist_load(tablename,0));
00313 check(cpl_propertylist_append(result->header, header));
00314
00315 XSH_ASSURE_NOT_ILLEGAL(result->size == cpl_table_get_nrow(table));
00316
00317 for(i=0;i<result->size;i++) {
00318 int nb, k, order, depth, nlambda, nslit ;
00319 const cpl_array * data_array ;
00320 const float * farray = NULL ;
00321 const int * iarray = NULL ;
00322
00323
00324 check(xsh_get_table_value(table, XSH_REC_TABLE_COLNAME_ORDER,
00325 CPL_TYPE_INT, i, &order));
00326 result->list[i].order = order ;
00327 check(xsh_get_table_value(table, XSH_REC_TABLE_COLNAME_NLAMBDA,
00328 CPL_TYPE_INT, i, &nlambda ));
00329 result->list[i].nlambda = nlambda ;
00330 check(xsh_get_table_value(table, XSH_REC_TABLE_COLNAME_NSLIT,
00331 CPL_TYPE_INT, i, &nslit ));
00332 result->list[i].nslit = nslit ;
00333 if ( nslit > max_nslit ) max_nslit = nslit ;
00334 if ( nlambda > max_nlambda ) max_nlambda = nlambda ;
00335
00336 xsh_msg_dbg_high( "Order %d (%d): nslt = %d, nlambda = %d", i, order,
00337 nslit, nlambda ) ;
00338
00339 xsh_rec_list_set_data_size( result, i, order, nlambda, nslit ) ;
00340 depth = nlambda*nslit ;
00341
00342 check( data_array = cpl_table_get_array( table,
00343 XSH_REC_TABLE_COLNAME_FLUX1,
00344 i )) ;
00345 nb = cpl_array_get_size( data_array ) ;
00346 XSH_ASSURE_NOT_ILLEGAL( nb >= depth ) ;
00347
00348
00349 check( farray = cpl_array_get_data_float_const( data_array ) ) ;
00350 for( k = 0 ; k<depth ; k++ ) *(result->list[i].data1+k) = *farray++ ;
00351
00352 farray = NULL ;
00353 check( data_array = cpl_table_get_array( table,
00354 XSH_REC_TABLE_COLNAME_ERRS1,
00355 i )) ;
00356 check( nb = cpl_array_get_size( data_array ) ) ;
00357
00358 check( farray = cpl_array_get_data_float_const( data_array ) ) ;
00359 for( k = 0 ; k<depth ; k++ ) *(result->list[i].errs1+k) = *farray++ ;
00360
00361 check( data_array = cpl_table_get_array( table,
00362 XSH_REC_TABLE_COLNAME_QUAL1,
00363 i )) ;
00364 nb = cpl_array_get_size( data_array ) ;
00365
00366 iarray = cpl_array_get_data_int_const( data_array ) ;
00367 for( k = 0 ; k<depth ; k++ ) *(result->list[i].qual1+k) = *iarray++ ;
00368
00369 }
00370 xsh_msg_dbg_high( "Max Lambda: %d, Max Slit: %d", max_nlambda, max_nslit ) ;
00371
00372 result->max_nlambda = max_nlambda ;
00373 result->max_nslit = max_nslit ;
00374
00375
00376 cleanup:
00377 return result;
00378 }
00379 #else
00380 xsh_rec_list* xsh_rec_list_load(cpl_frame* frame,
00381 xsh_instrument* instrument)
00382 {
00383 xsh_rec_list* result = NULL;
00384 const char * tablename = NULL ;
00385 cpl_table * table = NULL;
00386 cpl_propertylist* header = NULL;
00387 int nbext, i ;
00388 int size;
00389
00390
00391 XSH_ASSURE_NOT_NULL(frame);
00392 XSH_ASSURE_NOT_NULL(instrument);
00393
00394
00395 check(tablename = cpl_frame_get_filename(frame));
00396 xsh_msg_dbg_low( "Loading Rectified Frame: %s", tablename ) ;
00397
00398 check( size = cpl_frame_get_nextensions( frame));
00399
00400
00401
00402 XSH_CALLOC(result, xsh_rec_list, 1);
00403 result->size = size;
00404 XSH_ASSURE_NOT_ILLEGAL(result->size > 0);
00405 result->instrument = instrument;
00406
00407 XSH_CALLOC( result->list, xsh_rec, result->size);
00408
00409 XSH_NEW_PROPERTYLIST( result->header);
00410
00411 check(header = cpl_propertylist_load(tablename,0));
00412 check(cpl_propertylist_append(result->header, header));
00413
00414
00415
00416
00417 xsh_free_propertylist(&header);
00418
00419 nbext = size;
00420
00421 xsh_msg_dbg_medium( " Nb of extensions: %d", nbext ) ;
00422
00423 for( i = 0 ; i<nbext ; i++ ) {
00424 int nb, k, order, depth, nlambda, nslit ;
00425 const cpl_array * data_array ;
00426 const float * farray = NULL ;
00427 const int * iarray = NULL ;
00428
00429 check( table = cpl_table_load( tablename, i+1, 0 ) ) ;
00430 check(xsh_get_table_value(table, XSH_REC_TABLE_COLNAME_ORDER,
00431 CPL_TYPE_INT, 0, &order));
00432
00433 result->list[i].order = order ;
00434 check(xsh_get_table_value(table, XSH_REC_TABLE_COLNAME_NLAMBDA,
00435 CPL_TYPE_INT, 0, &nlambda ));
00436 result->list[i].nlambda = nlambda ;
00437 check(xsh_get_table_value(table, XSH_REC_TABLE_COLNAME_NSLIT,
00438 CPL_TYPE_INT, 0, &nslit ));
00439 result->list[i].nslit = nslit ;
00440 xsh_rec_list_set_data_size( result, i, order, nlambda, nslit ) ;
00441
00442 if (nslit > 1){
00443 check( xsh_table_get_array_float( table, XSH_REC_TABLE_COLNAME_SLIT,
00444 result->list[i].slit, nslit));
00445 }
00446 else{
00447 check(xsh_get_table_value(table, XSH_REC_TABLE_COLNAME_SLIT,
00448 CPL_TYPE_FLOAT, 0, result->list[i].slit ));
00449 }
00450 check( xsh_table_get_array_double( table, XSH_REC_TABLE_COLNAME_LAMBDA,
00451 result->list[i].lambda, nlambda));
00452
00453
00454 depth = nlambda*nslit ;
00455
00456 check( data_array = cpl_table_get_array( table,
00457 XSH_REC_TABLE_COLNAME_FLUX1,
00458 0 )) ;
00459 nb = cpl_array_get_size( data_array ) ;
00460 XSH_ASSURE_NOT_ILLEGAL( nb == depth ) ;
00461
00462
00463 check( farray = cpl_array_get_data_float_const( data_array ) ) ;
00464 for( k = 0 ; k<depth ; k++ ) *(result->list[i].data1+k) = *farray++ ;
00465
00466 farray = NULL ;
00467 check( data_array = cpl_table_get_array( table,
00468 XSH_REC_TABLE_COLNAME_ERRS1,
00469 0 )) ;
00470 check( nb = cpl_array_get_size( data_array ) ) ;
00471
00472 check( farray = cpl_array_get_data_float_const( data_array ) ) ;
00473 for( k = 0 ; k<depth ; k++ ) *(result->list[i].errs1+k) = *farray++ ;
00474
00475 check( data_array = cpl_table_get_array( table,
00476 XSH_REC_TABLE_COLNAME_QUAL1,
00477 0 )) ;
00478 nb = cpl_array_get_size( data_array ) ;
00479
00480 iarray = cpl_array_get_data_int_const( data_array ) ;
00481 for( k = 0 ; k<depth ; k++ ) *(result->list[i].qual1+k) = *iarray++ ;
00482
00483 xsh_msg_dbg_low( " Loaded, order %d, nlambda %d, nslit %d",
00484 order, nlambda, nslit ) ;
00485
00486 cpl_table_delete( table ) ;
00487 }
00488
00489 cleanup:
00490 xsh_free_propertylist(&header);
00491 return result ;
00492 }
00493 #endif
00494
00495
00496 xsh_rec_list* xsh_rec_list_load_eso(cpl_frame* frame,
00497 xsh_instrument* instrument)
00498 {
00499 xsh_rec_list* result = NULL;
00500 const char * imagelist_name = NULL ;
00501 cpl_image * ima_data = NULL;
00502 cpl_image * ima_errs = NULL;
00503 cpl_image * ima_qual = NULL;
00504 cpl_propertylist* header = NULL;
00505 cpl_propertylist* hdata=NULL;
00506 cpl_propertylist* herrs=NULL;
00507 cpl_propertylist* hqual=NULL;
00508 const char* ext_name=NULL;
00509
00510 int nbext, i,j ;
00511 int size;
00512
00513
00514 XSH_ASSURE_NOT_NULL(frame);
00515 XSH_ASSURE_NOT_NULL(instrument);
00516
00517
00518
00519 check(imagelist_name = cpl_frame_get_filename(frame));
00520 xsh_msg_dbg_low( "Loading Rectified Frame: %s", imagelist_name ) ;
00521
00522 check( nbext = cpl_frame_get_nextensions( frame));
00523
00524
00525 size=(nbext+1)/3;
00526
00527
00528
00529 XSH_CALLOC(result, xsh_rec_list, 1);
00530 result->size = size;
00531 XSH_ASSURE_NOT_ILLEGAL(result->size > 0);
00532 result->instrument = instrument;
00533
00534 XSH_CALLOC( result->list, xsh_rec, result->size);
00535
00536 XSH_NEW_PROPERTYLIST( result->header);
00537
00538
00539 check(header = cpl_propertylist_load(imagelist_name,0));
00540 check(cpl_propertylist_append(result->header, header));
00541
00542 xsh_free_propertylist(&header);
00543
00544
00545
00546 xsh_msg_dbg_medium( " Nb of extensions: %d", nbext ) ;
00547
00548
00549 for( i = 0,j=0 ; j<nbext ; i++, j+=3 ) {
00550 int k, order, depth, nlambda, nslit ;
00551 const float * farray = NULL ;
00552 const int * iarray = NULL ;
00553 double s_step=0;
00554 double w_step=0;
00555 double s_start=0;
00556 double w_start=0;
00557 int sx=0;
00558 int sy=0;
00559
00560 check(ima_data=cpl_image_load(imagelist_name,XSH_PRE_DATA_TYPE,0,j+0));
00561 check(ima_errs=cpl_image_load(imagelist_name,XSH_PRE_ERRS_TYPE,0,j+1));
00562 check(ima_qual=cpl_image_load(imagelist_name,XSH_PRE_QUAL_TYPE,0,j+2));
00563
00564 check( hdata = cpl_propertylist_load( imagelist_name, j+0 ) ) ;
00565 check( herrs = cpl_propertylist_load( imagelist_name, j+1 ) ) ;
00566 check( hqual = cpl_propertylist_load( imagelist_name, j+2 ) ) ;
00567 check(ext_name=xsh_pfits_get_extname(herrs));
00568 order=10*(ext_name[3]-48)+(ext_name[4]-48);
00569
00570
00571
00572 result->list[i].order = order ;
00573
00574 nlambda=xsh_pfits_get_naxis1(herrs);
00575 nslit=xsh_pfits_get_naxis2(herrs);
00576
00577 w_step=xsh_pfits_get_cdelt1(herrs);
00578 s_step=xsh_pfits_get_cdelt2(herrs);
00579
00580 w_start=xsh_pfits_get_crval1(herrs);
00581 s_start=xsh_pfits_get_crval2(herrs);
00582
00583 result->list[i].nlambda = nlambda ;
00584 result->list[i].nslit = nslit ;
00585
00586 xsh_rec_list_set_data_size( result, i, order, nlambda, nslit ) ;
00587
00588
00589 if (nslit > 1){
00590 for(k=0;k<nslit;k++) {
00591 *(result->list[i].slit+k)=(s_start+k*s_step);
00592 }
00593 }
00594 else{
00595 for(k=0;k<nslit;k++) {
00596 *(result->list[i].slit+k)=0;
00597 }
00598 }
00599
00600
00601 for(k=0;k<nlambda;k++) {
00602 *(result->list[i].lambda+k)=(w_start+k*w_step);
00603 }
00604
00605 depth = nlambda*nslit ;
00606
00607
00608 check( farray = cpl_image_get_data_float( ima_data)) ;
00609 sx = cpl_image_get_size_x( ima_data ) ;
00610 sy = cpl_image_get_size_y( ima_data ) ;
00611 XSH_ASSURE_NOT_ILLEGAL( sx*sy == depth ) ;
00612
00613 for( k = 0 ; k<depth ; k++ ) *(result->list[i].data1+k) = *farray++ ;
00614 farray = NULL ;
00615
00616
00617 check( farray = cpl_image_get_data_float( ima_errs)) ;
00618 for( k = 0 ; k<depth ; k++ ) *(result->list[i].errs1+k) = *farray++ ;
00619
00620
00621 check( iarray = cpl_image_get_data_int( ima_qual)) ;
00622 for( k = 0 ; k<depth ; k++ ) *(result->list[i].qual1+k) = *iarray++ ;
00623
00624 xsh_msg_dbg_low( " Loaded, order %d, nlambda %d, nslit %d",
00625 order, nlambda, nslit ) ;
00626
00627 xsh_free_image( &ima_data ) ;
00628 xsh_free_image( &ima_errs ) ;
00629 xsh_free_image( &ima_qual ) ;
00630 xsh_free_propertylist( &hdata ) ;
00631 xsh_free_propertylist( &herrs ) ;
00632 xsh_free_propertylist( &hqual ) ;
00633
00634 }
00635
00636 cleanup:
00637 xsh_free_image( &ima_data ) ;
00638 xsh_free_image( &ima_errs ) ;
00639 xsh_free_image( &ima_qual ) ;
00640 xsh_free_propertylist( &hdata ) ;
00641 xsh_free_propertylist( &herrs ) ;
00642 xsh_free_propertylist( &hqual ) ;
00643
00644 xsh_free_propertylist(&header);
00645
00646 return result ;
00647 }
00648
00649
00650
00651
00652
00666
00667 cpl_frame * xsh_rec_list_frame_invert( cpl_frame * rec_frame,
00668 const char *tag, xsh_instrument *instrument)
00669 {
00670 cpl_frame *result = NULL;
00671 xsh_rec_list *rec_list = NULL;
00672 int norders, order;
00673 float *data = NULL;
00674 char fname[256];
00675
00676
00677 XSH_ASSURE_NOT_NULL( rec_frame);
00678 XSH_ASSURE_NOT_NULL( tag);
00679 XSH_ASSURE_NOT_NULL( instrument);
00680
00681 check( rec_list = xsh_rec_list_load( rec_frame, instrument));
00682
00683
00684 norders = rec_list->size;
00685 for( order = 0; order < norders; order++) {
00686 int i;
00687 int img_size, nlambda, nslit;
00688
00689 check( nlambda = xsh_rec_list_get_nlambda( rec_list, order));
00690 check( nslit = xsh_rec_list_get_nslit( rec_list, order));
00691 img_size = nlambda * nslit;
00692
00693 check( data = xsh_rec_list_get_data1( rec_list, order ) ) ;
00694 for( i = 0 ; i< img_size ; i++, data++ ) {
00695 *data *= -1.;
00696 }
00697 }
00698
00699
00700 sprintf( fname,"%s.fits", tag);
00701 check( result = xsh_rec_list_save( rec_list, fname, tag, 0 ) ) ;
00702
00703 cleanup:
00704 xsh_rec_list_free( &rec_list ) ;
00705 return result ;
00706 }
00707
00708
00713
00714 void xsh_rec_list_free(xsh_rec_list** list)
00715 {
00716 if (list != NULL && *list != NULL ) {
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726 int i ;
00727 xsh_rec_list * plist = NULL;
00728
00729 plist = *list;
00730
00731
00732 for (i = 0; i < plist->size; i++) {
00733 xsh_rec * pr = &(plist->list[i]) ;
00734
00735 xsh_msg_dbg_high( "Freeing order index %d", i ) ;
00736 if ( pr == NULL ) continue ;
00737 xsh_msg_dbg_high( " Abs Order: %d", pr->order ) ;
00738 cpl_free( pr->slit ) ;
00739 cpl_free( pr->lambda ) ;
00740 cpl_free( pr->data1 ) ;
00741 cpl_free( pr->errs1 ) ;
00742 cpl_free( pr->qual1 ) ;
00743 }
00744 if ((*list)->list){
00745 cpl_free((*list)->list);
00746 }
00747
00748 xsh_free_propertylist(&((*list)->header));
00749 cpl_free(*list);
00750 *list = NULL;
00751 }
00752 }
00753
00754
00755
00756
00762
00763 cpl_propertylist * xsh_rec_list_get_header(xsh_rec_list* list)
00764 {
00765 cpl_propertylist * res = NULL;
00766
00767 XSH_ASSURE_NOT_NULL(list);
00768 res = list->header;
00769 cleanup:
00770 return res;
00771 }
00772
00781 int xsh_rec_list_get_nslit( xsh_rec_list* list, int idx )
00782 {
00783 int res = 0 ;
00784
00785 XSH_ASSURE_NOT_NULL(list);
00786 res = list->list[idx].nslit ;
00787
00788 cleanup:
00789 return res ;
00790 }
00791
00800 int xsh_rec_list_get_order( xsh_rec_list* list, int idx )
00801 {
00802 int res = 0 ;
00803
00804 XSH_ASSURE_NOT_NULL(list);
00805 res = list->list[idx].order ;
00806
00807 cleanup:
00808 return res ;
00809 }
00810
00819 int xsh_rec_list_get_nlambda( xsh_rec_list* list, int idx )
00820 {
00821 int res = 0 ;
00822
00823 XSH_ASSURE_NOT_NULL( list);
00824 res = list->list[idx].nlambda ;
00825
00826 cleanup:
00827 return res ;
00828 }
00829
00838 float * xsh_rec_list_get_slit( xsh_rec_list* list, int idx )
00839 {
00840 float * res = NULL ;
00841
00842 XSH_ASSURE_NOT_NULL(list);
00843 res = list->list[idx].slit ;
00844
00845 cleanup:
00846 return res ;
00847 }
00848
00849
00857 double xsh_rec_list_get_slit_min( xsh_rec_list* list)
00858 {
00859 double res = 0 ;
00860
00861 XSH_ASSURE_NOT_NULL(list);
00862 res = list->slit_min ;
00863
00864 cleanup:
00865 return res ;
00866 }
00867
00868
00869
00877 double xsh_rec_list_get_slit_max( xsh_rec_list* list)
00878 {
00879 double res = 0 ;
00880
00881 XSH_ASSURE_NOT_NULL(list);
00882 res = list->slit_max ;
00883
00884 cleanup:
00885 return res ;
00886 }
00887
00888
00889 double xsh_rec_list_get_lambda_min( xsh_rec_list* list)
00890 {
00891 double lambda_min = 10000;
00892 int i;
00893
00894 XSH_ASSURE_NOT_NULL( list);
00895
00896 for( i=0; i< list->size; i++){
00897 if ( list->list[i].lambda != NULL){
00898 double lambda;
00899
00900 lambda = list->list[i].lambda[0];
00901 if ( lambda < lambda_min){
00902 lambda_min = lambda;
00903 }
00904 }
00905 }
00906
00907 cleanup:
00908 return lambda_min;
00909 }
00910
00911 double xsh_rec_list_get_lambda_max( xsh_rec_list* list)
00912 {
00913 double lambda_max =0.0;
00914 int i;
00915
00916 XSH_ASSURE_NOT_NULL( list);
00917
00918 for( i=0; i< list->size; i++){
00919 if ( list->list[i].lambda != NULL){
00920 double lambda;
00921
00922 lambda = list->list[i].lambda[list->list[i].nlambda-1];
00923 if ( lambda > lambda_max){
00924 lambda_max = lambda;
00925 }
00926 }
00927 }
00928 cleanup:
00929 return lambda_max;
00930 }
00931
00932
00941 cpl_error_code xsh_rec_list_set_slit_min( xsh_rec_list* list, const double val)
00942 {
00943
00944 XSH_ASSURE_NOT_NULL(list);
00945 list->slit_min = val;
00946
00947 cleanup:
00948 return cpl_error_get_code() ;
00949 }
00950
00951
00952
00961 cpl_error_code xsh_rec_list_set_slit_max( xsh_rec_list* list,const double val)
00962 {
00963
00964 XSH_ASSURE_NOT_NULL(list);
00965 list->slit_max = val;
00966
00967 cleanup:
00968 return cpl_error_get_code() ;
00969 }
00970
00971
00980 double* xsh_rec_list_get_lambda( xsh_rec_list* list, int idx )
00981 {
00982 double* res = NULL ;
00983
00984 XSH_ASSURE_NOT_NULL(list);
00985 res = list->list[idx].lambda ;
00986
00987 cleanup:
00988 return res ;
00989 }
00990
00999 float * xsh_rec_list_get_data1( xsh_rec_list* list, int idx )
01000 {
01001 float * res = NULL ;
01002
01003 XSH_ASSURE_NOT_NULL(list);
01004 res = list->list[idx].data1 ;
01005
01006 cleanup:
01007 return res ;
01008 }
01009
01018 float * xsh_rec_list_get_errs1( xsh_rec_list* list, int idx )
01019 {
01020 float * res = NULL ;
01021
01022 XSH_ASSURE_NOT_NULL(list);
01023 res = list->list[idx].errs1 ;
01024
01025 cleanup:
01026 return res ;
01027 }
01028
01037 int * xsh_rec_list_get_qual1( xsh_rec_list* list, int idx )
01038 {
01039 int * res = NULL ;
01040
01041 XSH_ASSURE_NOT_NULL(list);
01042 res = list->list[idx].qual1 ;
01043
01044 cleanup:
01045 return res ;
01046 }
01047
01048
01049
01065
01066 cpl_frame* xsh_rec_list_save( xsh_rec_list* list, const char* filename,
01067 const char* tag, int is_temp)
01068 {
01069 cpl_frame * result = NULL ;
01070 cpl_table * table = NULL;
01071 int nlambda = 0, nslit = 0, depth = 0;
01072 cpl_array * dim = NULL, * temp_array = NULL ;
01073 int i, k, order;
01074 unsigned mode = CPL_IO_DEFAULT;
01075
01076
01077 XSH_ASSURE_NOT_NULL( list);
01078 XSH_ASSURE_NOT_NULL( filename);
01079 XSH_ASSURE_NOT_ILLEGAL( list->size > 0);
01080
01081
01082 for( i = 0 ; i < list->size ; i++ ) {
01083
01084 nlambda = list->list[i].nlambda;
01085 nslit = list->list[i].nslit;
01086 depth = nlambda*nslit;
01087 order = list->list[i].order;
01088
01089
01090 if (depth == 0){
01091 continue;
01092 }
01093 check( table = cpl_table_new( 1));
01094
01095
01096 check(cpl_table_new_column( table, XSH_REC_TABLE_COLNAME_ORDER,
01097 CPL_TYPE_INT));
01098 check(cpl_table_new_column( table, XSH_REC_TABLE_COLNAME_NLAMBDA,
01099 CPL_TYPE_INT));
01100 check(cpl_table_new_column( table, XSH_REC_TABLE_COLNAME_NSLIT,
01101 CPL_TYPE_INT));
01102 check(cpl_table_new_column_array( table, XSH_REC_TABLE_COLNAME_LAMBDA,
01103 CPL_TYPE_DOUBLE, nlambda));
01104 check(cpl_table_new_column_array( table, XSH_REC_TABLE_COLNAME_SLIT,
01105 CPL_TYPE_FLOAT, nslit));
01106 check(cpl_table_new_column_array( table, XSH_REC_TABLE_COLNAME_FLUX1,
01107 CPL_TYPE_FLOAT, depth));
01108 check( cpl_table_new_column_array( table, XSH_REC_TABLE_COLNAME_ERRS1,
01109 CPL_TYPE_FLOAT, depth));
01110 check( cpl_table_new_column_array( table, XSH_REC_TABLE_COLNAME_QUAL1,
01111 CPL_TYPE_INT, depth));
01112
01113
01114 check( dim = cpl_array_new( 1, CPL_TYPE_INT)) ;
01115 cpl_array_set_int( dim, 0, nlambda);
01116 check( cpl_table_set_column_dimensions(
01117 table, XSH_REC_TABLE_COLNAME_LAMBDA, dim));
01118 cpl_array_set_int( dim, 0, nslit);
01119 check( cpl_table_set_column_dimensions( table,
01120 XSH_REC_TABLE_COLNAME_SLIT, dim));
01121 xsh_free_array( &dim);
01122
01123 check( dim = cpl_array_new( 2, CPL_TYPE_INT)) ;
01124 cpl_array_set_int( dim, 0, nlambda);
01125 cpl_array_set_int( dim, 1, nslit);
01126
01127 check( cpl_table_set_column_dimensions( table,
01128 XSH_REC_TABLE_COLNAME_FLUX1, dim));
01129 check( cpl_table_set_column_dimensions( table,
01130 XSH_REC_TABLE_COLNAME_ERRS1, dim));
01131 check( cpl_table_set_column_dimensions( table,
01132 XSH_REC_TABLE_COLNAME_QUAL1, dim));
01133 xsh_free_array( &dim);
01134
01135
01136 check( cpl_table_set_int( table, XSH_REC_TABLE_COLNAME_ORDER, 0,
01137 order));
01138 check( cpl_table_set_int( table, XSH_REC_TABLE_COLNAME_NLAMBDA, 0,
01139 nlambda));
01140 check( cpl_table_set_int( table, XSH_REC_TABLE_COLNAME_NSLIT, 0,
01141 nslit));
01142
01143
01144 check ( temp_array = cpl_array_new( nslit, CPL_TYPE_FLOAT));
01145 for( k = 0 ; k<nslit ; k++ ) {
01146 check( cpl_array_set_float( temp_array, k,
01147 *(list->list[i].slit+k)));
01148 }
01149
01150 check( cpl_table_set_array( table, XSH_REC_TABLE_COLNAME_SLIT, 0,
01151 temp_array));
01152 xsh_free_array( &temp_array);
01153
01154
01155 check( temp_array = cpl_array_new( nlambda, CPL_TYPE_DOUBLE));
01156 for( k = 0 ; k<nlambda ; k++ ) {
01157 check( cpl_array_set_double( temp_array, k,
01158 *(list->list[i].lambda+k)));
01159 }
01160
01161 check( cpl_table_set_array( table, XSH_REC_TABLE_COLNAME_LAMBDA, 0,
01162 temp_array));
01163 xsh_free_array( &temp_array);
01164
01165
01166 check( temp_array = cpl_array_new( depth, CPL_TYPE_FLOAT));
01167 for( k = 0 ; k<depth ; k++ ) {
01168 check( cpl_array_set_float( temp_array, k,
01169 *(list->list[i].data1+k) ) ) ;
01170 }
01171 check( cpl_table_set_array( table, XSH_REC_TABLE_COLNAME_FLUX1, 0,
01172 temp_array));
01173
01174 for( k = 0 ; k<depth ; k++ ) {
01175 check( cpl_array_set_float( temp_array, k,
01176 *(list->list[i].errs1+k) ) ) ;
01177 }
01178 check( cpl_table_set_array( table, XSH_REC_TABLE_COLNAME_ERRS1, 0,
01179 temp_array));
01180 xsh_free_array( &temp_array);
01181
01182 check( temp_array = cpl_array_new( depth, CPL_TYPE_INT));
01183 for( k = 0 ; k<depth ; k++ ) {
01184 check( cpl_array_set_int( temp_array, k,
01185 *(list->list[i].qual1+k)));
01186 }
01187 check( cpl_table_set_array( table, XSH_REC_TABLE_COLNAME_QUAL1, 0,
01188 temp_array));
01189 xsh_free_array( &temp_array ) ;
01190
01191
01192
01193 xsh_pfits_set_bunit(list->header,XSH_BUNIT_FLUX_REL_C);
01194 check( cpl_table_save( table, list->header, NULL, filename, mode));
01195 mode = CPL_IO_EXTEND;
01196 XSH_TABLE_FREE( table);
01197 }
01198
01199
01200 check( result = xsh_frame_product( filename, tag, CPL_FRAME_TYPE_IMAGE,
01201 CPL_FRAME_GROUP_PRODUCT, CPL_FRAME_LEVEL_FINAL));
01202
01203
01204
01205
01206
01207
01208
01209 cleanup:
01210 XSH_TABLE_FREE( table);
01211 xsh_free_array( &temp_array);
01212 return result ;
01213 }
01214
01215
01216
01229
01230 void xsh_rec_list_update_header( xsh_rec_list *rec_list, xsh_pre *pre,
01231 xsh_rectify_param *rec_par, const char* pro_catg)
01232 {
01233 double lambda_min, lambda_max;
01234
01235
01236 XSH_ASSURE_NOT_NULL( rec_list);
01237 XSH_ASSURE_NOT_NULL( pre);
01238 XSH_ASSURE_NOT_NULL( rec_par);
01239
01240
01241 check( cpl_propertylist_append( rec_list->header, pre->data_header));
01242
01243
01244 check( xsh_pfits_set_rectify_bin_lambda( rec_list->header,
01245 rec_par->rectif_bin_lambda));
01246 check( xsh_pfits_set_rectify_bin_space( rec_list->header,
01247 rec_par->rectif_bin_space));
01248
01249 check( lambda_min = xsh_rec_list_get_lambda_min( rec_list));
01250 check( lambda_max = xsh_rec_list_get_lambda_max( rec_list));
01251
01252 check( xsh_pfits_set_rectify_lambda_min(rec_list->header,
01253 lambda_min)) ;
01254 check( xsh_pfits_set_rectify_lambda_max(rec_list->header,
01255 lambda_max));
01256
01257 check( xsh_pfits_set_rectify_space_min( rec_list->header,
01258 rec_list->slit_min));
01259 check( xsh_pfits_set_rectify_space_max( rec_list->header,
01260 rec_list->slit_max));
01261 check( xsh_pfits_set_pcatg( rec_list->header, pro_catg));
01262
01263 cleanup:
01264 return;
01265 }
01266
01267
01268
01269
01285
01286 cpl_frame* xsh_rec_list_save_table( xsh_rec_list* list, const char* filename,
01287 const char* tag, int is_temp)
01288 {
01289 cpl_frame * result = NULL ;
01290 cpl_table * table = NULL;
01291 int nlambda = 0, nslit = 0, depth = 0;
01292 cpl_array * dim = NULL, * temp_array = NULL ;
01293 int i, k, order;
01294 unsigned mode = CPL_IO_DEFAULT;
01295
01296
01297 XSH_ASSURE_NOT_NULL( list);
01298 XSH_ASSURE_NOT_NULL( filename);
01299 XSH_ASSURE_NOT_ILLEGAL( list->size > 0);
01300
01301
01302 for( i = 0 ; i < list->size ; i++ ) {
01303
01304 nlambda = list->list[i].nlambda;
01305 nslit = list->list[i].nslit;
01306 depth = nlambda*nslit;
01307 order = list->list[i].order;
01308
01309
01310 if (depth == 0){
01311 continue;
01312 }
01313 check( table = cpl_table_new( 1));
01314
01315
01316 check(cpl_table_new_column( table, XSH_REC_TABLE_COLNAME_ORDER,
01317 CPL_TYPE_INT));
01318 check(cpl_table_new_column( table, XSH_REC_TABLE_COLNAME_NLAMBDA,
01319 CPL_TYPE_INT));
01320 check(cpl_table_new_column( table, XSH_REC_TABLE_COLNAME_NSLIT,
01321 CPL_TYPE_INT));
01322 check(cpl_table_new_column_array( table, XSH_REC_TABLE_COLNAME_LAMBDA,
01323 CPL_TYPE_DOUBLE, nlambda));
01324 check(cpl_table_new_column_array( table, XSH_REC_TABLE_COLNAME_SLIT,
01325 CPL_TYPE_FLOAT, nslit));
01326
01327
01328 check( dim = cpl_array_new( 1, CPL_TYPE_INT)) ;
01329 cpl_array_set_int( dim, 0, nlambda);
01330 check( cpl_table_set_column_dimensions(
01331 table, XSH_REC_TABLE_COLNAME_LAMBDA, dim));
01332 cpl_array_set_int( dim, 0, nslit);
01333 check( cpl_table_set_column_dimensions( table,
01334 XSH_REC_TABLE_COLNAME_SLIT, dim));
01335 xsh_free_array( &dim);
01336
01337 check( dim = cpl_array_new( 2, CPL_TYPE_INT)) ;
01338 cpl_array_set_int( dim, 0, nlambda);
01339 cpl_array_set_int( dim, 1, nslit);
01340
01341 xsh_free_array( &dim);
01342
01343
01344 check( cpl_table_set_int( table, XSH_REC_TABLE_COLNAME_ORDER, 0,
01345 order));
01346 check( cpl_table_set_int( table, XSH_REC_TABLE_COLNAME_NLAMBDA, 0,
01347 nlambda));
01348 check( cpl_table_set_int( table, XSH_REC_TABLE_COLNAME_NSLIT, 0,
01349 nslit));
01350
01351
01352 check ( temp_array = cpl_array_new( nslit, CPL_TYPE_FLOAT));
01353 for( k = 0 ; k<nslit ; k++ ) {
01354 check( cpl_array_set_float( temp_array, k,
01355 *(list->list[i].slit+k)));
01356 }
01357
01358 check( cpl_table_set_array( table, XSH_REC_TABLE_COLNAME_SLIT, 0,
01359 temp_array));
01360 xsh_free_array( &temp_array);
01361
01362
01363 check( temp_array = cpl_array_new( nlambda, CPL_TYPE_DOUBLE));
01364 for( k = 0 ; k<nlambda ; k++ ) {
01365 check( cpl_array_set_double( temp_array, k,
01366 *(list->list[i].lambda+k)));
01367 }
01368
01369 check( cpl_table_set_array( table, XSH_REC_TABLE_COLNAME_LAMBDA, 0,
01370 temp_array));
01371 xsh_free_array( &temp_array);
01372
01373
01374
01375 check( cpl_table_save( table, list->header, NULL, filename, mode));
01376 mode = CPL_IO_EXTEND;
01377 XSH_TABLE_FREE( table);
01378 }
01379
01380
01381 check( result = xsh_frame_product( filename, tag, CPL_FRAME_TYPE_TABLE,
01382 CPL_FRAME_GROUP_PRODUCT, CPL_FRAME_LEVEL_FINAL));
01383
01384 if ( is_temp == CPL_TRUE){
01385 check( cpl_frame_set_level( result, CPL_FRAME_LEVEL_TEMPORARY));
01386 xsh_add_temporary_file( filename);
01387 }
01388
01389 cleanup:
01390 XSH_TABLE_FREE( table);
01391 xsh_free_array( &temp_array);
01392 return result ;
01393 }
01394
01395
01396
01397
01407
01408 cpl_frame*
01409 xsh_rec_list_save2(xsh_rec_list* list,const char* filename, const char* tag)
01410 {
01411
01412 cpl_table * table = NULL;
01413 int nlambda, nslit, depth ;
01414 cpl_array * temp_array = NULL ;
01415 int i, k, order ;
01416
01417 cpl_image* img_lambda=NULL;
01418 cpl_image* img_slit=NULL;
01419
01420 cpl_image* img_flux=NULL;
01421 cpl_image* img_err=NULL;
01422 cpl_image* img_qual=NULL;
01423 cpl_frame* result=NULL;
01424
01425
01426
01427 double* plambda=NULL;
01428 float* pslit=NULL;
01429
01430 float* pflux=NULL;
01431 float* perr=NULL;
01432 int* pqual=NULL;
01433 double cdelt1=0;
01434 double cdelt2=0;
01435 double crpix1=0;
01436 double crpix2=0;
01437 double crval1=0;
01438 double crval2=0;
01439
01440 char data_extname[20];
01441 char errs_extname[20];
01442 char qual_extname[20];
01443 unsigned mode = CPL_IO_DEFAULT;
01444 cpl_propertylist *header_data = NULL;
01445 cpl_propertylist *header_errs = NULL;
01446 cpl_propertylist *header_qual = NULL;
01447
01448
01449 XSH_ASSURE_NOT_NULL( list);
01450 XSH_ASSURE_NOT_NULL( filename);
01451 XSH_ASSURE_NOT_ILLEGAL( list->size > 0 ) ;
01452
01453
01454 for( i = 0; i < list->size ; i++ ) {
01455 nlambda = list->list[i].nlambda ;
01456 nslit = list->list[i].nslit ;
01457 depth = nlambda*nslit ;
01458 order = list->list[i].order ;
01459
01460 xsh_msg_dbg_high("depth %d : %dx%d", depth, nslit, nlambda);
01461
01462
01463 if (depth == 0){
01464 continue;
01465 }
01466 check( header_data = cpl_propertylist_duplicate( list->header));
01467 header_errs=cpl_propertylist_new();
01468 header_qual=cpl_propertylist_new();
01469
01470 check(img_lambda=cpl_image_new(nlambda,1,CPL_TYPE_DOUBLE));
01471 check(img_slit=cpl_image_new(nslit,1,CPL_TYPE_FLOAT));
01472 check(img_flux=cpl_image_new(nlambda,nslit,CPL_TYPE_FLOAT));
01473 check(img_err=cpl_image_new(nlambda,nslit,CPL_TYPE_FLOAT));
01474 check(img_qual=cpl_image_new(nlambda,nslit,CPL_TYPE_INT));
01475
01476 check(plambda=cpl_image_get_data_double(img_lambda));
01477 check(pslit=cpl_image_get_data_float(img_slit));
01478 check(pflux=cpl_image_get_data_float(img_flux));
01479 check(perr=cpl_image_get_data_float(img_err));
01480 check(pqual=cpl_image_get_data_int(img_qual));
01481
01482 for( k = 0 ; k<nslit ; k++ ) {
01483 pslit[k]= (*(list->list[i].slit+k) ) ;
01484 }
01485 for( k = 0 ; k<nlambda ; k++ ) {
01486 plambda[k]= (*(list->list[i].lambda+k) ) ;
01487 }
01488
01489 if (nlambda > 1){
01490 cdelt1=plambda[1]-plambda[0];
01491 crpix1=1.;
01492 crval1=plambda[0];
01493 check( xsh_pfits_set_crpix1( header_data, crpix1));
01494 check( xsh_pfits_set_crval1( header_data, crval1));
01495 check( xsh_pfits_set_cdelt1( header_data, cdelt1));
01496 check( cpl_propertylist_append_string( header_data,"CTYPE1","LINEAR"));
01497
01498
01499 check( xsh_pfits_set_crpix1( header_errs, crpix1));
01500 check( xsh_pfits_set_crval1( header_errs, crval1));
01501 check( xsh_pfits_set_cdelt1( header_errs, cdelt1));
01502 check( cpl_propertylist_append_string( header_errs,"CTYPE1","LINEAR"));
01503
01504 check( xsh_pfits_set_crpix1( header_qual, crpix1));
01505 check( xsh_pfits_set_crval1( header_qual, crval1));
01506 check( xsh_pfits_set_cdelt1( header_qual, cdelt1));
01507 check( cpl_propertylist_append_string( header_qual,"CTYPE1","LINEAR"));
01508
01509
01510 xsh_msg_dbg_high("write axis 1 : %f %f %f", crpix1, crval1, cdelt1);
01511
01512
01513 }
01514
01515 for( k = 0 ; k<depth ; k++ ) {
01516 pflux[k]= (*(list->list[i].data1+k) ) ;
01517 perr[k]= (*(list->list[i].errs1+k) ) ;
01518 pqual[k]= (*(list->list[i].qual1+k) ) ;
01519 }
01520
01521
01522 crpix2=1.;
01523 crval2=pslit[0];
01524 if ( nslit > 1){
01525 xsh_msg_dbg_high("nslit %d", nslit);
01526 cdelt2=pslit[1]-pslit[0];
01527 } else {
01528 cdelt2=0;
01529 }
01530
01531 xsh_pfits_set_wcs(header_data,crpix1,crval1,cdelt1,crpix2,crval2,cdelt2);
01532 xsh_pfits_set_extract_slit_min( header_data,list->slit_min);
01533 xsh_pfits_set_extract_slit_max( header_data,list->slit_max);
01534
01535
01536 xsh_pfits_set_wcs(header_errs,crpix1,crval1,cdelt1,crpix2,crval2,cdelt2);
01537 xsh_pfits_set_extract_slit_min( header_errs,list->slit_min);
01538 xsh_pfits_set_extract_slit_max( header_errs,list->slit_max);
01539
01540 xsh_pfits_set_wcs(header_qual,crpix1,crval1,cdelt1,crpix2,crval2,cdelt2);
01541 xsh_pfits_set_extract_slit_min( header_qual,list->slit_min);
01542 xsh_pfits_set_extract_slit_max( header_qual,list->slit_max);
01543
01544 sprintf(data_extname,"ORD%d_FLUX",order);
01545 sprintf(errs_extname,"ORD%d_ERRS",order);
01546 sprintf(qual_extname,"ORD%d_QUAL",order);
01547 xsh_msg_dbg_high("extname %s", data_extname);
01548
01549 xsh_pfits_set_bunit(header_data,XSH_BUNIT_FLUX_REL_C);
01550 check( xsh_pfits_set_extname( header_data, data_extname));
01551 check(xsh_plist_set_extra_keys(header_data,"IMAGE","DATA","RMSE",
01552 data_extname,errs_extname,qual_extname,0));
01553
01554 check(cpl_image_save(img_flux,filename, CPL_BPP_IEEE_FLOAT,
01555 header_data, mode));
01556
01557
01558 xsh_pfits_set_bunit(header_errs,XSH_BUNIT_FLUX_REL_C);
01559 xsh_pfits_set_extname( header_errs, errs_extname);
01560 check(xsh_plist_set_extra_keys(header_errs,"IMAGE","DATA","RMSE",
01561 data_extname,errs_extname,qual_extname,1));
01562 check(cpl_image_save(img_err,filename, CPL_BPP_IEEE_FLOAT,
01563 header_errs, CPL_IO_EXTEND)) ;
01564
01565
01566 xsh_pfits_set_bunit(header_qual,XSH_BUNIT_NONE_C);
01567 xsh_pfits_set_extname( header_qual,qual_extname);
01568 check(xsh_plist_set_extra_keys(header_qual,"IMAGE","DATA","RMSE",
01569 data_extname,errs_extname,qual_extname,2));
01570 check(cpl_image_save(img_qual, filename, XSH_PRE_QUAL_BPP,
01571 header_qual, CPL_IO_EXTEND)) ;
01572
01573 mode = CPL_IO_EXTEND;
01574
01575 xsh_free_image(&img_lambda);
01576 xsh_free_image(&img_slit);
01577 xsh_free_image(&img_flux);
01578 xsh_free_image(&img_err);
01579 xsh_free_image(&img_qual);
01580 xsh_free_propertylist( &header_data);
01581 xsh_free_propertylist( &header_errs);
01582 xsh_free_propertylist( &header_qual);
01583
01584 }
01585
01586 check(result=xsh_frame_product(filename,tag,CPL_FRAME_TYPE_IMAGE,
01587 CPL_FRAME_GROUP_PRODUCT,
01588 CPL_FRAME_LEVEL_FINAL));
01589 cleanup:
01590 xsh_free_propertylist( &header_data);
01591 XSH_TABLE_FREE( table);
01592 xsh_free_array( &temp_array ) ;
01593 return result ;
01594 }
01595
01596
01597
01598
01599
01600 void xsh_rec_get_nod_kw( cpl_frame * rec_frame, double * throw,
01601 double * jitter,
01602 double * reloffset, double * cumoffset )
01603 {
01604 cpl_propertylist * header ;
01605 const char *fname = NULL ;
01606 double val ;
01607
01608 XSH_ASSURE_NOT_NULL( rec_frame ) ;
01609 check( fname = cpl_frame_get_filename( rec_frame ) ) ;
01610 check( header = cpl_propertylist_load( fname, 0 ) ) ;
01611
01612 val = xsh_pfits_get_nodthrow( header ) ;
01613 if ( cpl_error_get_code() == CPL_ERROR_NONE ) {
01614 *throw = val ;
01615 }
01616 else cpl_error_reset() ;
01617
01618 val = xsh_pfits_get_nod_jitterwidth( header ) ;
01619 if ( cpl_error_get_code() == CPL_ERROR_NONE ) {
01620 *jitter = val ;
01621 }
01622 else
01623 cpl_error_reset() ;
01624
01625 val = xsh_pfits_get_nod_reloffset( header ) ;
01626 if ( cpl_error_get_code() == CPL_ERROR_NONE ) {
01627 *reloffset = val ;
01628 }
01629 else cpl_error_reset() ;
01630
01631 val = xsh_pfits_get_nod_cumoffset( header ) ;
01632 if ( cpl_error_get_code() == CPL_ERROR_NONE ) {
01633 *cumoffset = val ;
01634 }
01635 else cpl_error_reset() ;
01636
01637 cleanup:
01638 xsh_free_propertylist( &header ) ;
01639 return ;
01640 }
01641