36 #include "sinfo_functions.h"
37 #include "sinfo_new_cube_ops.h"
38 #include "sinfo_utl_cube2ima.h"
39 #include "sinfo_key_names.h"
40 #include <sinfo_error.h>
41 #include <sinfo_utils_wrappers.h>
72 int sinfo_utl_cube2ima(
73 cpl_parameterlist * parlist,
74 cpl_frameset * framelist)
76 cpl_parameter * param =NULL ;
77 const char * name_i =NULL;
78 const char * name_o =NULL;
90 cpl_frame * frm_cub=NULL ;
92 cpl_propertylist * plist=NULL ;
93 cpl_frame * product_frame=NULL;
95 cpl_imagelist * cube=NULL;
101 name_o =
"out_ima.fits";
104 check_nomsg(param = cpl_parameterlist_find(parlist,
105 "sinfoni.sinfo_utl_cube2ima.ws"));
106 check_nomsg(ws = cpl_parameter_get_double(param)) ;
109 check_nomsg(param = cpl_parameterlist_find(parlist,
110 "sinfoni.sinfo_utl_cube2ima.we"));
111 check_nomsg(we = cpl_parameter_get_double(param)) ;
114 check(sinfo_dfs_set_groups(framelist),
115 "Cannot identify RAW and CALIB frames");
118 check(frm_cub = cpl_frameset_find(framelist, SI_UTL_CUBE2IMA_CUBE),
119 "SOF does not have a file tagged as %s",SI_UTL_CUBE2IMA_CUBE);
121 check_nomsg(name_i = cpl_frame_get_filename(frm_cub));
123 plist=cpl_propertylist_load(name_i,0);
124 naxis3=sinfo_pfits_get_naxis3(plist);
125 wd=sinfo_pfits_get_cdelt3(plist);
126 wc=sinfo_pfits_get_crval3(plist);
127 sinfo_free_propertylist(&plist);
129 lams=wc-naxis3*wd/2+wd;
130 lame=lams+(naxis3-2)*wd;
132 check_nomsg(param = cpl_parameterlist_find(parlist,
133 "sinfoni.sinfo_utl_cube2ima.ws"));
135 if(ws != cpl_parameter_get_default_double(param)) {
140 else if (ws >= lame) {
148 check_nomsg(param = cpl_parameterlist_find(parlist,
149 "sinfoni.sinfo_utl_cube2ima.we"));
150 if(we != cpl_parameter_get_default_double(param)) {
155 else if (we <= lams) {
163 check(plist=cpl_propertylist_load(cpl_frame_get_filename(frm_cub),0),
164 "Cannot read the FITS header") ;
167 check_nomsg(cube = cpl_imagelist_load((
char*)name_i,CPL_TYPE_FLOAT,0));
168 if(NULL==(img=sinfo_new_average_cube_to_image_between_waves(cube,wd,wc,
171 "range [%f,%f] um",ws,we) ;
173 sinfo_free_imagelist(&cube);
174 sinfo_free_propertylist(&plist);
177 sinfo_free_imagelist(&cube);
181 check_nomsg(product_frame = cpl_frame_new());
182 check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
183 check_nomsg(cpl_frame_set_tag(product_frame, SI_UTL_CUBE2IMA_PROIMA)) ;
184 check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE)) ;
185 check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT)) ;
186 check(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL),
187 "Error while initialising the product frame") ;
191 check_nomsg(cpl_propertylist_erase_regexp(plist,
"^ESO PRO CATG",0));
192 check(cpl_dfs_setup_product_header(plist,
196 "si_sinfo_utl_cube2ima",
198 KEY_VALUE_HPRO_DID,NULL),
199 "Problem in the product DFS-compliance") ;
202 check_nomsg(cpl_propertylist_erase_regexp(plist,
"^CTYPE3",0));
203 check_nomsg(cpl_propertylist_erase_regexp(plist,
"^CRPIX3",0));
204 check_nomsg(cpl_propertylist_erase_regexp(plist,
"^CRVAL3",0));
205 check_nomsg(cpl_propertylist_erase_regexp(plist,
"^CDELT3",0));
206 check_nomsg(cpl_propertylist_erase_regexp(plist,
"^CUNIT3",0));
208 check(cpl_image_save(img,
213 "Could not save product");
215 check_nomsg(sinfo_free_propertylist(&plist)) ;
218 check_nomsg(cpl_frameset_insert(framelist, product_frame)) ;
219 check_nomsg(sinfo_free_image(&img)) ;
224 sinfo_free_imagelist(&cube);
225 sinfo_free_propertylist(&plist);
226 sinfo_free_image(&img);
228 if (cpl_error_get_code())