110 if (cpl_error_get_code() != CPL_ERROR_NONE) {
174 if (cpl_error_get_code() != CPL_ERROR_NONE) {
192 const char *s1dname = NULL;
199 check( s1dname = cpl_frame_get_filename( s1d_frame));
223 check( result->
flux = cpl_image_load( s1dname, CPL_TYPE_DOUBLE, 0, 0));
224 check( result->
errs = cpl_image_load( s1dname, CPL_TYPE_DOUBLE, 0, 1));
225 check( result->
qual = cpl_image_load( s1dname, CPL_TYPE_INT, 0, 2));
228 double *flux_data = NULL;
229 double *errs_data = NULL;
230 int *qual_data = NULL;
232 cpl_vector *flux = NULL;
233 cpl_vector *errs = NULL;
234 cpl_vector *qual = NULL;
237 check( flux = cpl_vector_load( s1dname, 0));
238 check(
size = cpl_vector_get_size( flux));
239 check( errs = cpl_vector_load( s1dname, 1));
240 check( qual = cpl_vector_load( s1dname, 2));
241 check( flux_data = cpl_vector_get_data( flux));
242 check( result->
flux = cpl_image_wrap_double(
size, 1 , flux_data));
245 check( errs_data = cpl_vector_get_data( errs));
246 check( result->
errs = cpl_image_wrap_double(
size, 1, errs_data));
248 check( result->
qual = cpl_image_new (
size, 1, CPL_TYPE_INT));
249 check( qual_data = cpl_image_get_data_int( result->
qual));
250 for(i=0; i<
size; i++){
251 check( qual_data[i] = (
int)cpl_vector_get(qual,i));
257 if (cpl_error_get_code() != CPL_ERROR_NONE) {
279 const char *s1dname = NULL;
287 check( s1dname = cpl_frame_get_filename( s1d_frame));
311 check( result->
flux = cpl_image_load( s1dname, CPL_TYPE_DOUBLE, 0,
order+0));
312 check( result->
errs = cpl_image_load( s1dname, CPL_TYPE_DOUBLE, 0,
order+1));
313 check( result->
qual = cpl_image_load( s1dname, CPL_TYPE_INT, 0,
order+2));
316 double *flux_data = NULL;
317 double *errs_data = NULL;
318 int *qual_data = NULL;
320 cpl_vector *flux = NULL;
321 cpl_vector *errs = NULL;
322 cpl_vector *qual = NULL;
325 check( flux = cpl_vector_load( s1dname,
order+0));
326 check(
size = cpl_vector_get_size( flux));
327 check( errs = cpl_vector_load( s1dname,
order+1));
328 check( qual = cpl_vector_load( s1dname,
order+2));
329 check( flux_data = cpl_vector_get_data( flux));
330 check( result->
flux = cpl_image_wrap_double(
size, 1 , flux_data));
333 check( errs_data = cpl_vector_get_data( errs));
334 check( result->
errs = cpl_image_wrap_double(
size, 1, errs_data));
336 check( result->
qual = cpl_image_new (
size, 1, CPL_TYPE_INT));
337 check( qual_data = cpl_image_get_data_int( result->
qual));
338 for(i=0; i<
size; i++){
339 check( qual_data[i] = (
int)cpl_vector_get(qual,i));
345 if (cpl_error_get_code() != CPL_ERROR_NONE) {
387 res =
s->size_lambda;
472 res =
s->lambda_step;
494 check( res = cpl_image_get_data_double(
s->flux));
516 check( res = cpl_image_get_data_double(
s->errs));
538 check( res = cpl_image_get_data_int(
s->qual));
634 cpl_frame *product_frame = NULL;
641 "FLUX",
"ERRS",
"QUAL",0));
645 "FLUX",
"ERRS",
"QUAL",1));
649 "FLUX",
"ERRS",
"QUAL",2));
652 if (
s->size_slit > 1){
675 s->flux_header, CPL_IO_DEFAULT),
676 "Could not save data to %s extension 0", filename);
678 s->errs_header, CPL_IO_EXTEND),
679 "Could not save errs to %s extension 1", filename);
681 s->qual_header, CPL_IO_EXTEND),
682 "Could not save qual to %s extension 2", filename);
685 cpl_vector *flux1D = NULL;
686 cpl_vector *err1D = NULL;
687 cpl_vector *qual1D = NULL;
701 cpl_propertylist_erase_regexp(
s->flux_header,
"^CTYPE2", 0);
712 check( flux1D = cpl_vector_new_from_image_row(
s->flux, 1));
713 check( err1D = cpl_vector_new_from_image_row(
s->errs, 1));
714 check( qual1D = cpl_vector_new_from_image_row(
s->qual, 1));
716 s->flux_header, CPL_IO_DEFAULT));
718 s->errs_header, CPL_IO_EXTEND));
720 s->qual_header, CPL_IO_EXTEND));
727 check( product_frame = cpl_frame_new() ) ;
728 check( cpl_frame_set_filename( product_frame,filename ));
729 check( cpl_frame_set_type( product_frame, CPL_FRAME_TYPE_IMAGE )) ;
730 check( cpl_frame_set_level( product_frame, CPL_FRAME_LEVEL_FINAL )) ;
731 check( cpl_frame_set_group( product_frame, CPL_FRAME_GROUP_PRODUCT ));
734 if (cpl_error_get_code () != CPL_ERROR_NONE) {
736 product_frame = NULL;
738 return product_frame;
757 const char* tag,
const int order)
759 cpl_frame *product_frame = NULL;
766 if (
s->size_slit > 1){
771 s->flux_header, CPL_IO_DEFAULT),
772 "Could not save data to %s extension 0", filename);
775 s->errs_header, CPL_IO_EXTEND),
776 "Could not save errs to %s extension 1", filename);
778 s->qual_header, CPL_IO_EXTEND),
779 "Could not save qual to %s extension 2", filename);
783 cpl_vector *flux1D = NULL;
784 cpl_vector *err1D = NULL;
785 cpl_vector *qual1D = NULL;
787 check( flux1D = cpl_vector_new_from_image_row(
s->flux, 1));
788 check( err1D = cpl_vector_new_from_image_row(
s->errs, 1));
789 check( qual1D = cpl_vector_new_from_image_row(
s->qual, 1));
792 s->flux_header, CPL_IO_DEFAULT));
795 s->flux_header, CPL_IO_EXTEND));
798 s->errs_header, CPL_IO_EXTEND));
800 s->qual_header, CPL_IO_EXTEND));
807 check( product_frame = cpl_frame_new() ) ;
808 check( cpl_frame_set_filename( product_frame,filename ));
809 check( cpl_frame_set_type( product_frame, CPL_FRAME_TYPE_IMAGE )) ;
810 check( cpl_frame_set_level( product_frame, CPL_FRAME_LEVEL_FINAL )) ;
811 check( cpl_frame_set_group( product_frame, CPL_FRAME_GROUP_PRODUCT ));
814 if (cpl_error_get_code () != CPL_ERROR_NONE) {
816 product_frame = NULL;
818 return product_frame;
890 check( result->
flux = cpl_image_extract( org->
flux,1,1,size_x,size_y));
893 check( result->
errs = cpl_image_extract( org->
errs,1,1,size_x,size_y));
896 check( result->
qual = cpl_image_extract( org->
qual,1,1,size_x,size_y));
907 cpl_propertylist* phead=NULL;
911 const char* pcatg=NULL;
912 const char* fname=NULL;
923 fname=cpl_frame_get_filename(frame1d);
925 phead = cpl_propertylist_load(fname, 0);
936 cpl_ensure_code(wave_max > wave_cut, CPL_ERROR_ILLEGAL_INPUT);
937 xcut = (int) ( (wave_cut-wave_min) / wave_del + 0.5 );
938 cpl_ensure_code(xcut <= naxis1, CPL_ERROR_ILLEGAL_INPUT);
940 if (xcut == naxis1) {
941 return CPL_ERROR_NONE;
943 sprintf(oname,
"tmp_%s",fname);
955 sprintf(cmd,
"mv %s %s",oname,fname);
956 assure(system(cmd)==0,CPL_ERROR_UNSPECIFIED,
"unable to mv file");
964 return cpl_error_get_code();
971 cpl_propertylist* phead=NULL;
975 const char* pcatg=NULL;
976 const char* fname=NULL;
988 fname=cpl_frame_get_filename(frame1d);
989 next=cpl_frame_get_nextensions(frame1d);
991 phead = cpl_propertylist_load(fname, 0);
1003 cpl_ensure_code(wave_max > wave_cut, CPL_ERROR_ILLEGAL_INPUT);
1004 xcut = (int) ( (wave_cut-wave_min) / wave_del + 0.5 );
1005 cpl_ensure_code(xcut <= naxis1, CPL_ERROR_ILLEGAL_INPUT);
1008 if (xcut == naxis1) {
1009 return CPL_ERROR_NONE;
1011 sprintf(oname,
"tmp_%s",fname);
1019 for(
int i=3;i<next;i+=3) {
1029 sprintf(cmd,
"mv %s %s",oname,fname);
1030 assure(system(cmd)==0,CPL_ERROR_UNSPECIFIED,
"unable to mv file");
1038 return cpl_error_get_code();
1055 cpl_frame *product_frame = NULL;
1056 const char* tag = NULL;
1063 if (
s->size_slit > 1){
1067 s->flux_header, CPL_IO_DEFAULT),
1068 "Could not save data to %s extension 0", filename);
1070 s->errs_header, CPL_IO_EXTEND),
1071 "Could not save errs to %s extension 1", filename);
1073 s->qual_header, CPL_IO_EXTEND),
1074 "Could not save qual to %s extension 2", filename);
1077 cpl_vector *flux1D = NULL;
1078 cpl_vector *err1D = NULL;
1079 cpl_vector *qual1D = NULL;
1084 check( flux1D = cpl_vector_new_from_image_row(
s->flux, 1));
1085 check( err1D = cpl_vector_new_from_image_row(
s->errs, 1));
1086 check( qual1D = cpl_vector_new_from_image_row(
s->qual, 1));
1088 s->flux_header, CPL_IO_DEFAULT));
1090 s->errs_header, CPL_IO_EXTEND));
1092 s->qual_header, CPL_IO_EXTEND));
1099 check( product_frame = cpl_frame_new() ) ;
1100 check( cpl_frame_set_filename( product_frame,filename ));
1101 check( cpl_frame_set_type( product_frame, CPL_FRAME_TYPE_IMAGE )) ;
1102 check( cpl_frame_set_level( product_frame, CPL_FRAME_LEVEL_FINAL )) ;
1103 check( cpl_frame_set_group( product_frame, CPL_FRAME_GROUP_PRODUCT ));
1106 if (cpl_error_get_code () != CPL_ERROR_NONE) {
1108 product_frame = NULL;
1110 return product_frame;
int xsh_spectrum_get_size_lambda(xsh_spectrum *s)
Get lambda axis size of spectrum.
double xsh_spectrum_get_lambda_min(xsh_spectrum *s)
Get minimum lambda of spectrum.
xsh_spectrum * xsh_spectrum_load(cpl_frame *s1d_frame)
Load a 1D spectrum structure.
double * xsh_spectrum_get_errs(xsh_spectrum *s)
Get errs of spectrum.
cpl_image * xsh_spectrum_get_errs_ima(xsh_spectrum *s)
Get flux of spectrum as image.
double xsh_spectrum_get_lambda_step(xsh_spectrum *s)
Get bin in lambda of spectrum.
cpl_error_code xsh_spectrum_cut_dichroic_uvb(cpl_frame *frame1d)
cpl_frame * xsh_phys_spectrum_save(xsh_spectrum *s, const char *filename, xsh_instrument *instr)
save a spectrum
xsh_spectrum * xsh_spectrum_load_order(cpl_frame *s1d_frame, xsh_instrument *instr, const int order)
Load a 1D spectrum structure.
int * xsh_spectrum_get_qual(xsh_spectrum *s)
Get qual of spectrum.
int xsh_spectrum_get_size(xsh_spectrum *s)
Get size of spectrum.
xsh_spectrum * xsh_spectrum_duplicate(xsh_spectrum *org)
cpl_frame * xsh_spectrum_save(xsh_spectrum *s, const char *filename, const char *tag)
save a spectrum
cpl_error_code xsh_spectrum_orders_cut_dichroic_uvb(cpl_frame *frame1d, xsh_instrument *instr)
cpl_frame * xsh_spectrum_save_order(xsh_spectrum *s, const char *filename, const char *tag, const int order)
save a spectrum
cpl_image * xsh_spectrum_get_flux_ima(xsh_spectrum *s)
Get flux of spectrum as image.
double * xsh_spectrum_get_flux(xsh_spectrum *s)
Get flux of spectrum.
xsh_spectrum * xsh_spectrum_extract_range(xsh_spectrum *org, const double wmin, const double wmax)
cpl_image * xsh_spectrum_get_qual_ima(xsh_spectrum *s)
Get flux of spectrum as image.
xsh_spectrum * xsh_spectrum_2D_create(double lambda_min, double lambda_max, double lambda_step, double slit_min, double slit_max, double slit_step)
Create a 2D spectrum structure.
xsh_spectrum * xsh_spectrum_1D_create(double lambda_min, double lambda_max, double lambda_step)
Create a 1D spectrum structure.
double xsh_spectrum_get_lambda_max(xsh_spectrum *s)
Get maximum lambda of spectrum.
void xsh_spectrum_free(xsh_spectrum **s)
free memory associated to an 1D spectrum
int xsh_spectrum_get_size_slit(xsh_spectrum *s)
Get slit axis ize of spectrum.
#define XSH_ASSURE_NOT_ILLEGAL(cond)
#define assure(CONDITION, ERROR_CODE,...)
#define check_msg(COMMAND,...)
#define XSH_ASSURE_NOT_NULL(pointer)
cpl_error_code xsh_pfits_set_wcs2(cpl_propertylist *header, const double crpix2, const double crval2, const double cdelt2)
double xsh_pfits_get_crval2(const cpl_propertylist *plist)
find out the crval2
cpl_error_code xsh_plist_set_extra_keys(cpl_propertylist *plist, const char *hduclas1, const char *hduclas2, const char *hduclas3, const char *scidata, const char *errdata, const char *qualdata, const int type)
set hdu keys
void xsh_pfits_set_pcatg(cpl_propertylist *plist, const char *value)
Write the PCATG value.
double xsh_pfits_get_cdelt2(const cpl_propertylist *plist)
find out the cdelt2
void xsh_pfits_set_ctype1(cpl_propertylist *plist, const char *value)
Write the CTYPE1 value.
void xsh_pfits_set_extname(cpl_propertylist *plist, const char *value)
Write the EXTNAME value.
cpl_error_code xsh_pfits_set_wcs(cpl_propertylist *header, const double crpix1, const double crval1, const double cdelt1, const double crpix2, const double crval2, const double cdelt2)
const char * xsh_pfits_get_pcatg(const cpl_propertylist *plist)
find out the pcatg
double xsh_pfits_get_crpix1(const cpl_propertylist *plist)
find out the CRPIX1 value
cpl_error_code xsh_pfits_set_wcs1(cpl_propertylist *header, const double crpix1, const double crval1, const double cdelt1)
double xsh_pfits_get_cdelt1(const cpl_propertylist *plist)
find out the cdelt1
void xsh_pfits_set_cunit1(cpl_propertylist *plist, const char *value)
Write the CUNIT1 value.
void xsh_pfits_set_bunit(cpl_propertylist *plist, const char *value)
Write the BUNIT value.
int xsh_pfits_get_naxis1(const cpl_propertylist *plist)
find out the NAXIS1 value
double xsh_pfits_get_crpix2(const cpl_propertylist *plist)
find out the CRPIX2 value
double xsh_pfits_get_crval1(const cpl_propertylist *plist)
find out the crval1
int xsh_pfits_get_naxis(const cpl_propertylist *plist)
find out the NAXIS value
int xsh_pfits_get_naxis2(const cpl_propertylist *plist)
find out the NAXIS2 value
void xsh_unwrap_vector(cpl_vector **v)
Unwrap a vector and set the pointer to NULL.
void xsh_free_vector(cpl_vector **v)
Deallocate a vector and set the pointer to NULL.
void xsh_free_image(cpl_image **i)
Deallocate an image and set the pointer to NULL.
void xsh_free_frame(cpl_frame **f)
Deallocate a frame and set the pointer to NULL.
cpl_error_code xsh_set_cd_matrix2d(cpl_propertylist *plist)
Set CD matrix.
void xsh_free_propertylist(cpl_propertylist **p)
Deallocate a property list and set the pointer to NULL.
cpl_propertylist * errs_header
cpl_propertylist * flux_header
cpl_propertylist * qual_header
#define XSH_SPECTRUM_DATA_BPP
#define XSH_SPECTRUM_QUAL_BPP
#define XSH_SPECTRUM_ERRS_BPP
#define XSH_GET_TAG_FROM_ARM(TAG, instr)
#define XSH_UVB_DICHROIC_WAVE_CUT
#define XSH_NEW_PROPERTYLIST(POINTER)
#define XSH_FREE(POINTER)
#define XSH_CALLOC(POINTER, TYPE, SIZE)