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
00037
00038
00039 #include "sinfo_functions.h"
00040
00041 #include "sinfo_new_cube_ops.h"
00042 #include "sinfo_utl_cube2ima.h"
00043 #include "sinfo_key_names.h"
00044 #include <sinfo_error.h>
00045 #include <sinfo_utils_wrappers.h>
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00068
00075
00076 int sinfo_utl_cube2ima(
00077 cpl_parameterlist * parlist,
00078 cpl_frameset * framelist)
00079 {
00080 cpl_parameter * param =NULL ;
00081 const char * name_i =NULL;
00082 const char * name_o =NULL;
00083
00084 double ws=0 ;
00085 double we=0 ;
00086 double wc=0 ;
00087 double wd=0 ;
00088
00089
00090 int naxis3=0;
00091 double lams=0;
00092 double lame=0;
00093
00094 cpl_frame * frm_cub=NULL ;
00095
00096 cpl_propertylist * plist=NULL ;
00097 cpl_frame * product_frame=NULL;
00098
00099 cpl_imagelist * cube=NULL;
00100 cpl_image * img=NULL;
00101
00102
00103
00104
00105 name_o ="out_ima.fits";
00106
00107
00108 check_nomsg(param = cpl_parameterlist_find(parlist,
00109 "sinfoni.sinfo_utl_cube2ima.ws"));
00110 check_nomsg(ws = cpl_parameter_get_double(param)) ;
00111
00112
00113 check_nomsg(param = cpl_parameterlist_find(parlist,
00114 "sinfoni.sinfo_utl_cube2ima.we"));
00115 check_nomsg(we = cpl_parameter_get_double(param)) ;
00116
00117
00118 check(sinfo_dfs_set_groups(framelist),
00119 "Cannot identify RAW and CALIB frames");
00120
00121
00122 check(frm_cub = cpl_frameset_find(framelist, SI_UTL_CUBE2IMA_CUBE),
00123 "SOF does not have a file tagged as %s",SI_UTL_CUBE2IMA_CUBE);
00124
00125 check_nomsg(name_i = cpl_frame_get_filename(frm_cub));
00126
00127 plist=cpl_propertylist_load(name_i,0);
00128 naxis3=sinfo_pfits_get_naxis3(plist);
00129 wd=sinfo_pfits_get_cdelt3(plist);
00130 wc=sinfo_pfits_get_crval3(plist);
00131 sinfo_free_propertylist(&plist);
00132
00133 lams=wc-naxis3*wd/2+wd;
00134 lame=lams+(naxis3-2)*wd;
00135
00136 check_nomsg(param = cpl_parameterlist_find(parlist,
00137 "sinfoni.sinfo_utl_cube2ima.ws"));
00138
00139 if(ws != cpl_parameter_get_default_double(param)) {
00140 if (ws < lams) {
00141 sinfo_msg_warning("ws =%f too low set it to %f",ws,lams);
00142 ws=lams;
00143 }
00144 else if (ws >= lame) {
00145 sinfo_msg_warning("ws =%f too high set it to %f",ws,lams);
00146 ws=lams;
00147 }
00148 } else {
00149 ws=lams;
00150 }
00151
00152 check_nomsg(param = cpl_parameterlist_find(parlist,
00153 "sinfoni.sinfo_utl_cube2ima.we"));
00154 if(we != cpl_parameter_get_default_double(param)) {
00155 if (we > lame) {
00156 sinfo_msg_warning("we =%f too low set it to %f",we,lame);
00157 we=lame;
00158 }
00159 else if (we <= lams) {
00160 sinfo_msg_warning("we =%f too low set it to %f",we,lame);
00161 we=lame;
00162 }
00163 } else {
00164 we=lame;
00165 }
00166
00167 check(plist=cpl_propertylist_load(cpl_frame_get_filename(frm_cub),0),
00168 "Cannot read the FITS header") ;
00169
00170
00171 check_nomsg(cube = cpl_imagelist_load((char*)name_i,CPL_TYPE_FLOAT,0));
00172 if(NULL==(img=sinfo_new_average_cube_to_image_between_waves(cube,wd,wc,
00173 ws,we))) {
00174 sinfo_msg_error("Cannot average cube to image in wavelength "
00175 "range [%f,%f] um",ws,we) ;
00176
00177 sinfo_free_imagelist(&cube);
00178 sinfo_free_propertylist(&plist);
00179
00180 }
00181 sinfo_free_imagelist(&cube);
00182
00183
00184
00185 check_nomsg(product_frame = cpl_frame_new());
00186 check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
00187 check_nomsg(cpl_frame_set_tag(product_frame, SI_UTL_CUBE2IMA_PROIMA)) ;
00188 check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE)) ;
00189 check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT)) ;
00190 check(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL),
00191 "Error while initialising the product frame") ;
00192
00193
00194
00195 check_nomsg(cpl_propertylist_erase_regexp(plist, "^ESO PRO CATG",0));
00196
00197 check(cpl_dfs_setup_product_header(plist,
00198 product_frame,
00199 framelist,
00200 parlist,
00201 "si_sinfo_utl_cube2ima",
00202 "SINFONI",
00203 KEY_VALUE_HPRO_DID),
00204 "Problem in the product DFS-compliance") ;
00205
00206
00207 check_nomsg(cpl_propertylist_erase_regexp(plist, "^CTYPE3",0));
00208 check_nomsg(cpl_propertylist_erase_regexp(plist, "^CRPIX3",0));
00209 check_nomsg(cpl_propertylist_erase_regexp(plist, "^CRVAL3",0));
00210 check_nomsg(cpl_propertylist_erase_regexp(plist, "^CDELT3",0));
00211 check_nomsg(cpl_propertylist_erase_regexp(plist, "^CUNIT3",0));
00212
00213 check(cpl_image_save(img,
00214 name_o,
00215 CPL_BPP_DEFAULT,
00216 plist,
00217 CPL_IO_DEFAULT),
00218 "Could not save product");
00219
00220 check_nomsg(sinfo_free_propertylist(&plist)) ;
00221
00222
00223 check_nomsg(cpl_frameset_insert(framelist, product_frame)) ;
00224 check_nomsg(sinfo_free_image(&img)) ;
00225
00226
00227
00228 cleanup:
00229 sinfo_free_imagelist(&cube);
00230 sinfo_free_propertylist(&plist);
00231 sinfo_free_image(&img);
00232
00233 if (cpl_error_get_code())
00234 return -1 ;
00235 else
00236 return 0 ;
00237 }