00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifdef HAVE_CONFIG_H
00028 #include <config.h>
00029 #endif
00030
00031
00036
00037
00041
00042
00043
00044
00045 #include <math.h>
00046 #include <xsh_data_spectrum.h>
00047 #include <xsh_utils.h>
00048 #include <xsh_error.h>
00049 #include <xsh_msg.h>
00050 #include <xsh_pfits.h>
00051 #include <xsh_dfs.h>
00052 #include <cpl.h>
00053
00054
00055
00056
00057
00058
00068
00069 xsh_spectrum* xsh_spectrum_1D_create( double lambda_min, double lambda_max,
00070 double lambda_step)
00071 {
00072 xsh_spectrum* result = NULL;
00073
00074
00075
00076 XSH_ASSURE_NOT_ILLEGAL( lambda_min >= 0.0 && lambda_min <= lambda_max);
00077 XSH_ASSURE_NOT_ILLEGAL( lambda_step >=0);
00078
00079 XSH_CALLOC(result, xsh_spectrum,1);
00080
00081 result->lambda_min = lambda_min;
00082 result->lambda_max = lambda_max;
00083 result->lambda_step = lambda_step;
00084
00085 XSH_NEW_PROPERTYLIST( result->flux_header);
00086 check( xsh_pfits_set_crpix1( result->flux_header, 1.0));
00087 check( xsh_pfits_set_crval1( result->flux_header, lambda_min));
00088 check( xsh_pfits_set_cdelt1( result->flux_header, lambda_step));
00089 check( xsh_pfits_set_ctype1( result->flux_header, "LINEAR"));
00090
00091 XSH_NEW_PROPERTYLIST( result->errs_header);
00092 check( xsh_pfits_set_extname ( result->errs_header, "ERRS"));
00093 check( xsh_pfits_set_crpix1( result->errs_header, 1.0));
00094 check( xsh_pfits_set_crval1( result->errs_header, lambda_min));
00095 check( xsh_pfits_set_cdelt1( result->errs_header, lambda_step));
00096 check( xsh_pfits_set_ctype1( result->errs_header, "LINEAR"));
00097
00098 XSH_NEW_PROPERTYLIST( result->qual_header);
00099 check( xsh_pfits_set_extname ( result->qual_header, "QUAL"));
00100
00101
00102 result->size_lambda = (int)((lambda_max-lambda_min)/lambda_step+0.5)+1;
00103 result->size_slit = 1;
00104 result->slit_min = 0;
00105 result->slit_max = 0;
00106 result->size = result->size_lambda;
00107
00108 check( result->flux = cpl_image_new( result->size_lambda, 1,
00109 CPL_TYPE_DOUBLE));
00110 check( result->errs = cpl_image_new( result->size_lambda, 1,
00111 CPL_TYPE_DOUBLE));
00112 check( result->qual = cpl_image_new( result->size_lambda, 1,
00113 CPL_TYPE_INT));
00114
00115 cleanup:
00116 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00117 xsh_spectrum_free(&result);
00118 }
00119 return result;
00120 }
00121
00122
00135
00136 xsh_spectrum* xsh_spectrum_2D_create( double lambda_min, double lambda_max,
00137 double lambda_step, double slit_min, double slit_max, double slit_step)
00138 {
00139 xsh_spectrum* result = NULL;
00140
00141
00142 XSH_ASSURE_NOT_ILLEGAL( lambda_min >= 0.0 && lambda_min <= lambda_max);
00143 XSH_ASSURE_NOT_ILLEGAL( lambda_step >=0);
00144 XSH_ASSURE_NOT_ILLEGAL( slit_min <= slit_max);
00145 XSH_ASSURE_NOT_ILLEGAL( slit_step >=0);
00146
00147
00148 XSH_CALLOC(result, xsh_spectrum,1);
00149
00150 result->lambda_min = lambda_min;
00151 result->lambda_max = lambda_max;
00152 result->lambda_step = lambda_step;
00153 result->slit_min = slit_min;
00154 result->slit_max = slit_max;
00155 result->slit_step = slit_step;
00156
00157 XSH_NEW_PROPERTYLIST( result->flux_header);
00158 check( xsh_pfits_set_crpix1( result->flux_header, 1.0));
00159 check( xsh_pfits_set_crval1( result->flux_header, lambda_min));
00160 check( xsh_pfits_set_cdelt1( result->flux_header, lambda_step));
00161 check( xsh_pfits_set_crpix2( result->flux_header, 1.0));
00162 check( xsh_pfits_set_crval2( result->flux_header, slit_min));
00163 check( xsh_pfits_set_cdelt2( result->flux_header, slit_step));
00164 check( xsh_pfits_set_ctype1( result->flux_header, "LINEAR"));
00165 check( xsh_pfits_set_ctype2( result->flux_header, "LINEAR"));
00166 check(xsh_set_cd_matrix2d(result->flux_header));
00167
00168 XSH_NEW_PROPERTYLIST( result->errs_header);
00169 check( xsh_pfits_set_extname ( result->errs_header, "ERRS"));
00170 XSH_NEW_PROPERTYLIST( result->qual_header);
00171 check( xsh_pfits_set_extname ( result->qual_header, "QUAL"));
00172
00173
00174 result->size_lambda = (int)((lambda_max-lambda_min)/lambda_step+0.5)+1;
00175 result->size_slit = (int)((slit_max-slit_min)/slit_step+0.5)+1;
00176 result->size = result->size_lambda * result->size_slit;
00177 check( result->flux = cpl_image_new( result->size_lambda, result->size_slit,
00178 CPL_TYPE_DOUBLE));
00179 check( result->errs = cpl_image_new( result->size_lambda, result->size_slit,
00180 CPL_TYPE_DOUBLE));
00181 check( result->qual = cpl_image_new( result->size_lambda, result->size_slit,
00182 CPL_TYPE_INT));
00183
00184 cleanup:
00185 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00186 xsh_spectrum_free(&result);
00187 }
00188 return result;
00189 }
00190
00191
00192
00201
00202 xsh_spectrum* xsh_spectrum_load( cpl_frame* s1d_frame,
00203 xsh_instrument* instr)
00204 {
00205 xsh_spectrum* result = NULL;
00206 const char *s1dname = NULL;
00207 int naxis;
00208
00209 XSH_ASSURE_NOT_NULL( s1d_frame);
00210 XSH_ASSURE_NOT_NULL( instr);
00211
00212 XSH_ASSURE_NOT_ILLEGAL(cpl_frame_get_nextensions(s1d_frame) == 2);
00213
00214 check( s1dname = cpl_frame_get_filename( s1d_frame));
00215
00216 XSH_CALLOC(result, xsh_spectrum,1);
00217
00218 check( result->flux_header = cpl_propertylist_load( s1dname,0));
00219 check( result->errs_header = cpl_propertylist_load( s1dname,1));
00220 check( result->qual_header = cpl_propertylist_load( s1dname,2));
00221
00222 check( result->lambda_min = xsh_pfits_get_crval1( result->flux_header));
00223 check( result->lambda_step = xsh_pfits_get_cdelt1( result->flux_header));
00224 check( result->size = xsh_pfits_get_naxis1( result->flux_header));
00225 check( result->size_lambda = xsh_pfits_get_naxis1( result->flux_header));
00226 result->lambda_max = result->lambda_min+
00227 (result->lambda_step*result->size-1);
00228
00229 check( naxis = xsh_pfits_get_naxis( result->flux_header));
00230
00231 if (naxis > 1){
00232 check( result->slit_min = xsh_pfits_get_crval2( result->flux_header));
00233 check( result->slit_step = xsh_pfits_get_cdelt2( result->flux_header));
00234 check( result->size_slit = xsh_pfits_get_naxis2( result->flux_header));
00235 result->slit_max = result->slit_min+
00236 result->slit_step*(result->size_slit-1);
00237
00238 check( result->flux = cpl_image_load( s1dname, CPL_TYPE_DOUBLE, 0, 0));
00239 check( result->errs = cpl_image_load( s1dname, CPL_TYPE_DOUBLE, 0, 1));
00240 check( result->qual = cpl_image_load( s1dname, CPL_TYPE_INT, 0, 2));
00241 }
00242 else{
00243 double *flux_data = NULL;
00244 double *errs_data = NULL;
00245 int *qual_data = NULL;
00246 int i;
00247 cpl_vector *flux = NULL;
00248 cpl_vector *errs = NULL;
00249 cpl_vector *qual = NULL;
00250 int size = 0;
00251
00252 check( flux = cpl_vector_load( s1dname, 0));
00253 check( size = cpl_vector_get_size( flux));
00254 check( errs = cpl_vector_load( s1dname, 1));
00255 check( qual = cpl_vector_load( s1dname, 2));
00256 check( flux_data = cpl_vector_get_data( flux));
00257 check( result->flux = cpl_image_wrap_double( size, 1 , flux_data));
00258 xsh_unwrap_vector( &flux);
00259
00260 check( errs_data = cpl_vector_get_data( errs));
00261 check( result->errs = cpl_image_wrap_double( size, 1, errs_data));
00262
00263 check( result->qual = cpl_image_new ( size, 1, CPL_TYPE_INT));
00264 check( qual_data = cpl_image_get_data_int( result->qual));
00265 for(i=0; i< size; i++){
00266 check( qual_data[i] = (int)cpl_vector_get(qual,i));
00267 }
00268 xsh_unwrap_vector( &errs);
00269 xsh_free_vector( &qual);
00270 }
00271 cleanup:
00272 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00273 xsh_spectrum_free(&result);
00274 }
00275 return result;
00276 }
00277
00278
00279
00288
00289 xsh_spectrum* xsh_spectrum_load_order( cpl_frame* s1d_frame,
00290 xsh_instrument* instr,
00291 const int order)
00292 {
00293 xsh_spectrum* result = NULL;
00294 const char *s1dname = NULL;
00295 int naxis;
00296
00297 XSH_ASSURE_NOT_NULL( s1d_frame);
00298 XSH_ASSURE_NOT_NULL( instr);
00299
00300
00301
00302 check( s1dname = cpl_frame_get_filename( s1d_frame));
00303
00304 XSH_CALLOC(result, xsh_spectrum,1);
00305
00306 check( result->flux_header = cpl_propertylist_load( s1dname,order+0));
00307 check( result->errs_header = cpl_propertylist_load( s1dname,order+1));
00308 check( result->qual_header = cpl_propertylist_load( s1dname,order+2));
00309
00310 check( result->lambda_min = xsh_pfits_get_crval1( result->flux_header));
00311 check( result->lambda_step = xsh_pfits_get_cdelt1( result->flux_header));
00312 check( result->size = xsh_pfits_get_naxis1( result->flux_header));
00313 check( result->size_lambda = xsh_pfits_get_naxis1( result->flux_header));
00314 result->lambda_max = result->lambda_min+
00315 (result->lambda_step*result->size-1);
00316
00317 check( naxis = xsh_pfits_get_naxis( result->flux_header));
00318
00319 if (naxis > 1){
00320 check( result->slit_min = xsh_pfits_get_crval2( result->flux_header));
00321 check( result->slit_step = xsh_pfits_get_cdelt2( result->flux_header));
00322 check( result->size_slit = xsh_pfits_get_naxis2( result->flux_header));
00323 result->slit_max = result->slit_min+
00324 result->slit_step*(result->size_slit-1);
00325
00326 check( result->flux = cpl_image_load( s1dname, CPL_TYPE_DOUBLE, 0,order+0));
00327 check( result->errs = cpl_image_load( s1dname, CPL_TYPE_DOUBLE, 0,order+1));
00328 check( result->qual = cpl_image_load( s1dname, CPL_TYPE_INT, 0, order+2));
00329 }
00330 else{
00331 double *flux_data = NULL;
00332 double *errs_data = NULL;
00333 int *qual_data = NULL;
00334 int i;
00335 cpl_vector *flux = NULL;
00336 cpl_vector *errs = NULL;
00337 cpl_vector *qual = NULL;
00338 int size = 0;
00339
00340 check( flux = cpl_vector_load( s1dname, order+0));
00341 check( size = cpl_vector_get_size( flux));
00342 check( errs = cpl_vector_load( s1dname, order+1));
00343 check( qual = cpl_vector_load( s1dname, order+2));
00344 check( flux_data = cpl_vector_get_data( flux));
00345 check( result->flux = cpl_image_wrap_double( size, 1 , flux_data));
00346 xsh_unwrap_vector( &flux);
00347
00348 check( errs_data = cpl_vector_get_data( errs));
00349 check( result->errs = cpl_image_wrap_double( size, 1, errs_data));
00350
00351 check( result->qual = cpl_image_new ( size, 1, CPL_TYPE_INT));
00352 check( qual_data = cpl_image_get_data_int( result->qual));
00353 for(i=0; i< size; i++){
00354 check( qual_data[i] = (int)cpl_vector_get(qual,i));
00355 }
00356 xsh_unwrap_vector( &errs);
00357 xsh_free_vector( &qual);
00358 }
00359 cleanup:
00360 if (cpl_error_get_code() != CPL_ERROR_NONE) {
00361 xsh_spectrum_free(&result);
00362 }
00363 return result;
00364 }
00365
00366
00374
00375 int xsh_spectrum_get_size( xsh_spectrum* s)
00376 {
00377 int res=0;
00378
00379 XSH_ASSURE_NOT_NULL( s);
00380
00381 res = s->size;
00382
00383 cleanup:
00384 return res;
00385 }
00386
00387
00395
00396 int xsh_spectrum_get_size_lambda( xsh_spectrum* s)
00397 {
00398 int res=0;
00399
00400 XSH_ASSURE_NOT_NULL( s);
00401
00402 res = s->size_lambda;
00403
00404 cleanup:
00405 return res;
00406 }
00407
00408
00409
00417
00418 int xsh_spectrum_get_size_slit( xsh_spectrum* s)
00419 {
00420 int res=0;
00421
00422 XSH_ASSURE_NOT_NULL( s);
00423
00424 res = s->size_slit;
00425
00426 cleanup:
00427 return res;
00428 }
00429
00430
00438
00439 double xsh_spectrum_get_lambda_min( xsh_spectrum* s)
00440 {
00441 double res=0.0;
00442
00443 XSH_ASSURE_NOT_NULL( s);
00444
00445 res = s->lambda_min;
00446
00447 cleanup:
00448 return res;
00449 }
00450
00451
00459
00460 double xsh_spectrum_get_lambda_max( xsh_spectrum* s)
00461 {
00462 double res=0.0;
00463
00464 XSH_ASSURE_NOT_NULL( s);
00465
00466 res = s->lambda_max;
00467
00468 cleanup:
00469 return res;
00470 }
00471
00472
00480
00481 double xsh_spectrum_get_lambda_step( xsh_spectrum* s)
00482 {
00483 double res=0.0;
00484
00485 XSH_ASSURE_NOT_NULL( s);
00486
00487 res = s->lambda_step;
00488
00489 cleanup:
00490 return res;
00491 }
00492
00493
00494
00502
00503 double* xsh_spectrum_get_flux( xsh_spectrum* s)
00504 {
00505 double *res=NULL;
00506
00507 XSH_ASSURE_NOT_NULL( s);
00508
00509 check( res = cpl_image_get_data_double( s->flux));
00510
00511 cleanup:
00512 return res;
00513 }
00514
00515
00516
00524
00525 double* xsh_spectrum_get_errs( xsh_spectrum* s)
00526 {
00527 double *res=NULL;
00528
00529 XSH_ASSURE_NOT_NULL( s);
00530
00531 check( res = cpl_image_get_data_double( s->errs));
00532
00533 cleanup:
00534 return res;
00535 }
00536
00537
00538
00546
00547 int* xsh_spectrum_get_qual( xsh_spectrum* s)
00548 {
00549 int* res = NULL;
00550
00551 XSH_ASSURE_NOT_NULL( s);
00552
00553 check( res = cpl_image_get_data_int( s->qual));
00554
00555 cleanup:
00556 return res;
00557 }
00558
00559
00565
00566 void xsh_spectrum_free( xsh_spectrum** s)
00567 {
00568 if (s && *s){
00569 xsh_free_propertylist( &((*s)->flux_header));
00570 xsh_free_propertylist( &((*s)->errs_header));
00571 xsh_free_propertylist( &((*s)->qual_header));
00572 xsh_free_image( &((*s)->flux));
00573 xsh_free_image( &((*s)->errs));
00574 xsh_free_image( &((*s)->qual));
00575 XSH_FREE( (*s));
00576 }
00577 }
00578
00579
00589
00590 cpl_frame* xsh_spectrum_save( xsh_spectrum* s, const char* filename,
00591 const char* tag)
00592 {
00593 cpl_frame *product_frame = NULL;
00594
00595 XSH_ASSURE_NOT_NULL(s);
00596 XSH_ASSURE_NOT_NULL(filename);
00597
00598
00599
00600 if ( s->size_slit > 1){
00601
00602 check( xsh_pfits_set_pcatg( s->flux_header, tag));
00603 check_msg (cpl_image_save ( s->flux, filename, XSH_SPECTRUM_DATA_BPP,
00604 s->flux_header, CPL_IO_DEFAULT),
00605 "Could not save data to %s extension 0", filename);
00606 check_msg (cpl_image_save ( s->errs, filename, XSH_SPECTRUM_ERRS_BPP,
00607 s->errs_header, CPL_IO_EXTEND),
00608 "Could not save errs to %s extension 1", filename);
00609 check_msg (cpl_image_save ( s->qual, filename, XSH_SPECTRUM_QUAL_BPP,
00610 s->qual_header, CPL_IO_EXTEND),
00611 "Could not save qual to %s extension 2", filename);
00612 }
00613 else{
00614 cpl_vector *flux1D = NULL;
00615 cpl_vector *err1D = NULL;
00616 cpl_vector *qual1D = NULL;
00617
00618 check( flux1D = cpl_vector_new_from_image_row( s->flux, 1));
00619 check( err1D = cpl_vector_new_from_image_row( s->errs, 1));
00620 check( qual1D = cpl_vector_new_from_image_row( s->qual, 1));
00621 check( cpl_vector_save( flux1D, filename, XSH_SPECTRUM_DATA_BPP,
00622 s->flux_header, CPL_IO_DEFAULT));
00623 check( cpl_vector_save( err1D, filename, XSH_SPECTRUM_ERRS_BPP,
00624 s->errs_header, CPL_IO_EXTEND));
00625 check( cpl_vector_save( qual1D, filename, XSH_SPECTRUM_QUAL_BPP,
00626 s->qual_header, CPL_IO_EXTEND));
00627 xsh_free_vector( &flux1D);
00628 xsh_free_vector( &err1D);
00629 xsh_free_vector( &qual1D);
00630 }
00631
00632
00633 check( product_frame = cpl_frame_new() ) ;
00634 check( cpl_frame_set_filename( product_frame,filename ));
00635 check( cpl_frame_set_type( product_frame, CPL_FRAME_TYPE_IMAGE )) ;
00636 check( cpl_frame_set_level( product_frame, CPL_FRAME_LEVEL_FINAL )) ;
00637 check( cpl_frame_set_group( product_frame, CPL_FRAME_GROUP_PRODUCT ));
00638
00639 cleanup:
00640 if (cpl_error_get_code () != CPL_ERROR_NONE) {
00641 xsh_free_frame(&product_frame);
00642 product_frame = NULL;
00643 }
00644 return product_frame;
00645 }
00646
00647
00648
00649
00650
00661
00662 cpl_frame* xsh_spectrum_save_order( xsh_spectrum* s, const char* filename,
00663 const char* tag,const int order)
00664 {
00665 cpl_frame *product_frame = NULL;
00666
00667 XSH_ASSURE_NOT_NULL(s);
00668 XSH_ASSURE_NOT_NULL(filename);
00669
00670
00671
00672 if ( s->size_slit > 1){
00673
00674 check( xsh_pfits_set_pcatg( s->flux_header, tag));
00675 if(order==0) {
00676 check_msg (cpl_image_save ( s->flux, filename, XSH_SPECTRUM_DATA_BPP,
00677 s->flux_header, CPL_IO_DEFAULT),
00678 "Could not save data to %s extension 0", filename);
00679 } else {
00680 check_msg (cpl_image_save ( s->errs, filename, XSH_SPECTRUM_ERRS_BPP,
00681 s->errs_header, CPL_IO_EXTEND),
00682 "Could not save errs to %s extension 1", filename);
00683 check_msg (cpl_image_save ( s->qual, filename, XSH_SPECTRUM_QUAL_BPP,
00684 s->qual_header, CPL_IO_EXTEND),
00685 "Could not save qual to %s extension 2", filename);
00686 }
00687 }
00688 else{
00689 cpl_vector *flux1D = NULL;
00690 cpl_vector *err1D = NULL;
00691 cpl_vector *qual1D = NULL;
00692
00693 check( flux1D = cpl_vector_new_from_image_row( s->flux, 1));
00694 check( err1D = cpl_vector_new_from_image_row( s->errs, 1));
00695 check( qual1D = cpl_vector_new_from_image_row( s->qual, 1));
00696 if(order==0) {
00697 check( cpl_vector_save( flux1D, filename, XSH_SPECTRUM_DATA_BPP,
00698 s->flux_header, CPL_IO_DEFAULT));
00699 } else {
00700 check( cpl_vector_save( flux1D, filename, XSH_SPECTRUM_DATA_BPP,
00701 s->flux_header, CPL_IO_DEFAULT));
00702 }
00703 check( cpl_vector_save( err1D, filename, XSH_SPECTRUM_ERRS_BPP,
00704 s->errs_header, CPL_IO_EXTEND));
00705 check( cpl_vector_save( qual1D, filename, XSH_SPECTRUM_QUAL_BPP,
00706 s->qual_header, CPL_IO_EXTEND));
00707 xsh_free_vector( &flux1D);
00708 xsh_free_vector( &err1D);
00709 xsh_free_vector( &qual1D);
00710 }
00711
00712
00713 check( product_frame = cpl_frame_new() ) ;
00714 check( cpl_frame_set_filename( product_frame,filename ));
00715 check( cpl_frame_set_type( product_frame, CPL_FRAME_TYPE_IMAGE )) ;
00716 check( cpl_frame_set_level( product_frame, CPL_FRAME_LEVEL_FINAL )) ;
00717 check( cpl_frame_set_group( product_frame, CPL_FRAME_GROUP_PRODUCT ));
00718
00719 cleanup:
00720 if (cpl_error_get_code () != CPL_ERROR_NONE) {
00721 xsh_free_frame(&product_frame);
00722 product_frame = NULL;
00723 }
00724 return product_frame;
00725 }
00726
00727
00728 xsh_spectrum * xsh_spectrum_duplicate( xsh_spectrum * org )
00729 {
00730 xsh_spectrum * result = NULL ;
00731
00732 XSH_ASSURE_NOT_NULL( org ) ;
00733
00734
00735
00736 XSH_CALLOC( result, xsh_spectrum, 1 ) ;
00737
00738 result->lambda_min = org->lambda_min;
00739 result->lambda_max = org->lambda_max;
00740 result->lambda_step = org->lambda_step;
00741 result->size_lambda = org->size_lambda ;
00742 result->slit_min = org->slit_min;
00743 result->slit_max = org->slit_max;
00744 result->size = org->size;
00745 result->size_slit = org->size_slit ;
00746 check( result->flux = cpl_image_duplicate( org->flux ) ) ;
00747 check( result->flux_header = cpl_propertylist_duplicate( org->flux_header ));
00748 check( result->errs = cpl_image_duplicate( org->errs ) ) ;
00749 check( result->errs_header = cpl_propertylist_duplicate( org->errs_header ));
00750 check( result->qual = cpl_image_duplicate( org->qual ) ) ;
00751 check( result->qual_header = cpl_propertylist_duplicate( org->qual_header ));
00752
00753 cleanup:
00754 return result ;
00755 }
00766
00767 cpl_frame* xsh_phys_spectrum_save( xsh_spectrum* s, const char* filename,
00768 xsh_instrument* instr)
00769 {
00770 cpl_frame *product_frame = NULL;
00771 const char* tag = NULL;
00772
00773 XSH_ASSURE_NOT_NULL(s);
00774 XSH_ASSURE_NOT_NULL(filename);
00775
00776
00777
00778 if ( s->size_slit > 1){
00779 tag = XSH_GET_TAG_FROM_ARM( XSH_PHYS_MERGE2D, instr);
00780 check( xsh_pfits_set_pcatg( s->flux_header, tag));
00781 check_msg (cpl_image_save ( s->flux, filename, XSH_SPECTRUM_DATA_BPP,
00782 s->flux_header, CPL_IO_DEFAULT),
00783 "Could not save data to %s extension 0", filename);
00784 check_msg (cpl_image_save ( s->errs, filename, XSH_SPECTRUM_ERRS_BPP,
00785 s->errs_header, CPL_IO_EXTEND),
00786 "Could not save errs to %s extension 1", filename);
00787 check_msg (cpl_image_save ( s->qual, filename, XSH_SPECTRUM_QUAL_BPP,
00788 s->qual_header, CPL_IO_EXTEND),
00789 "Could not save qual to %s extension 2", filename);
00790 }
00791 else{
00792 cpl_vector *flux1D = NULL;
00793 cpl_vector *err1D = NULL;
00794 cpl_vector *qual1D = NULL;
00795
00796 tag = XSH_GET_TAG_FROM_ARM( XSH_PHYS_MERGE1D, instr);
00797
00798 check( xsh_pfits_set_pcatg( s->flux_header, tag));
00799 check( flux1D = cpl_vector_new_from_image_row( s->flux, 1));
00800 check( err1D = cpl_vector_new_from_image_row( s->errs, 1));
00801 check( qual1D = cpl_vector_new_from_image_row( s->qual, 1));
00802 check( cpl_vector_save( flux1D, filename, XSH_SPECTRUM_DATA_BPP,
00803 s->flux_header, CPL_IO_DEFAULT));
00804 check( cpl_vector_save( err1D, filename, XSH_SPECTRUM_ERRS_BPP,
00805 s->errs_header, CPL_IO_EXTEND));
00806 check( cpl_vector_save( qual1D, filename, XSH_SPECTRUM_QUAL_BPP,
00807 s->qual_header, CPL_IO_EXTEND));
00808 xsh_free_vector( &flux1D);
00809 xsh_free_vector( &err1D);
00810 xsh_free_vector( &qual1D);
00811 }
00812
00813
00814 check( product_frame = cpl_frame_new() ) ;
00815 check( cpl_frame_set_filename( product_frame,filename ));
00816 check( cpl_frame_set_type( product_frame, CPL_FRAME_TYPE_IMAGE )) ;
00817 check( cpl_frame_set_level( product_frame, CPL_FRAME_LEVEL_FINAL )) ;
00818 check( cpl_frame_set_group( product_frame, CPL_FRAME_GROUP_PRODUCT ));
00819
00820 cleanup:
00821 if (cpl_error_get_code () != CPL_ERROR_NONE) {
00822 xsh_free_frame(&product_frame);
00823 product_frame = NULL;
00824 }
00825 return product_frame;
00826 }
00827
00828