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
00028 #ifdef HAVE_CONFIG_H
00029 # include <config.h>
00030 #endif
00031
00032
00033
00034
00035
00036 #include <string.h>
00037
00038 #include "sinfo_utl_spectrum_wavelength_shift.h"
00039 #include "sinfo_spectrum_ops.h"
00040 #include "sinfo_shift_images.h"
00041 #include "sinfo_key_names.h"
00042 #include "sinfo_error.h"
00043 #include "sinfo_utils_wrappers.h"
00044 #include "sinfo_msg.h"
00045
00046
00047
00048
00049
00050
00051
00060
00061
00062
00063
00064
00071
00072 int sinfo_utl_spectrum_wavelength_shift(
00073 cpl_parameterlist * parlist,
00074 cpl_frameset * framelist)
00075 {
00076 cpl_parameter * param =NULL;
00077 const char * method =NULL;
00078 const char * name_i =NULL;
00079 const char * name_o =NULL;
00080
00081 double shift=0 ;
00082
00083 cpl_frame * frm_spct=NULL ;
00084
00085 cpl_propertylist * plist=NULL ;
00086
00087 cpl_frame * product_frame=NULL;
00088 cpl_image * image_o=NULL;
00089 cpl_image * image_i=NULL;
00090 cpl_image * image_s=NULL;
00091
00092 double* sub_shift=NULL;
00093
00094
00095
00096
00097 name_o = "out_ima.fits";
00098
00099
00100 check_nomsg(param = cpl_parameterlist_find(parlist,
00101 "sinfoni.sinfo_utl_spectrum_arith.method"));
00102 check_nomsg(method = cpl_parameter_get_string(param));
00103
00104
00105 check_nomsg(param = cpl_parameterlist_find(parlist,
00106 "sinfoni.sinfo_utl_spectrum_wavelength_shift.shift"));
00107 check_nomsg(shift = cpl_parameter_get_double(param));
00108
00109
00110
00111 check(frm_spct = cpl_frameset_find(framelist,
00112 SI_UTL_SPECTRUM_WAVELENGTH_SHIFT_SPECTRUM),
00113 "SOF does not have a file tagged as %s",
00114 SI_UTL_SPECTRUM_WAVELENGTH_SHIFT_SPECTRUM);
00115
00116 check(plist=cpl_propertylist_load(cpl_frame_get_filename(frm_spct),
00117 0),"Cannot read the FITS header") ;
00118
00119
00120 check_nomsg(name_i = cpl_frame_get_filename(frm_spct));
00121 check_nomsg(image_i= cpl_image_load ((char*)name_i,CPL_TYPE_FLOAT,0,0));
00122 sub_shift = sinfo_new_doublearray(1);
00123 sinfo_new_doublearray_set_value(sub_shift, 0., 0);
00124 cknull(image_s = sinfo_new_shift_image_in_spec (image_i, shift, sub_shift),
00125 "error in sinfo_new_shift_image_in_spec()");
00126
00127 shift = sinfo_new_doublearray_get_value(sub_shift, 0);
00128
00129 if (strcmp(method,"S")==0) {
00130
00131 cknull(image_o = sinfo_new_fine_shift_image_in_spec_cubic_spline (
00132 image_s, shift ),
00133 "error in fine_shift_image_in_spec_cubic_spline()");
00134
00135 } else if (strcmp(method,"P")==0) {
00136 cknull(image_o = sinfo_new_fine_shift_image_in_spec_poly(
00137 image_s,shift,2),
00138 "error in sinfo_fineShiftImageInSpecPoly()");
00139
00140
00141
00142
00143
00144
00145
00146 } else {
00147 sinfo_msg_error("wrong method %s",method);
00148 goto cleanup;
00149 }
00150
00151
00152
00153
00154
00155 check_nomsg(product_frame = cpl_frame_new());
00156 check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
00157 check_nomsg(cpl_frame_set_tag(product_frame,
00158 SI_UTL_SPECTRUM_WAVELENGTH_SHIFT_PROSPECTRUM)) ;
00159 check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE));
00160 check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT)) ;
00161 check_nomsg(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL)) ;
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174 check(cpl_image_save(image_o, name_o, CPL_BPP_IEEE_FLOAT, plist,
00175 CPL_IO_DEFAULT),"Could not save product");
00176 check_nomsg(cpl_frameset_insert(framelist, product_frame));
00177 cleanup:
00178 sinfo_free_image(&image_i);
00179 sinfo_free_image(&image_o);
00180 sinfo_free_image(&image_s);
00181 if(sub_shift != NULL) sinfo_new_destroy_doublearray(sub_shift);
00182 sinfo_free_propertylist(&plist);
00183
00184 if (cpl_error_get_code())
00185 return -1 ;
00186 else
00187 return 0 ;
00188 }