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
00029
00030
00031
00032
00033
00034 #include "utl_genlookup.h"
00035 #include <eclipse.h>
00036 #include <spectrum_ops.h>
00037 #include "sinfoni_key_names.h"
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00058
00059 int si_utl_genlookup(
00060 cpl_parameterlist * parlist,
00061 cpl_frameset * framelist)
00062 {
00063 const char * fctid = "si_utl_genlookup" ;
00064 cpl_parameter * param =NULL;
00065 char * name_o=NULL ;
00066 char * name_o1=NULL ;
00067 char * name_o2=NULL ;
00068 char * name_o3=NULL ;
00069 char * name_o4=NULL ;
00070 char * name1=NULL ;
00071 char * name2=NULL ;
00072
00073 double value ;
00074 cpl_frame * frm_cube1=NULL ;
00075 cpl_frame * frm_cube2=NULL ;
00076
00077 cpl_propertylist * plist ;
00078 cpl_image * image ;
00079 cpl_frame * product_frame;
00080
00081
00082 OneCube * iCube;
00083 OneCube * jCube;
00084 Lookup * lookup;
00085 int rc=0;
00086
00087
00088 param = cpl_parameterlist_find(parlist, "sinfoni.si_utl_genlookup.name_o");
00089 name_o = (char*) cpl_parameter_get_string(param);
00090
00091
00092 param = cpl_parameterlist_find(parlist,"sinfoni.si_utl_genlookup.value");
00093 value = cpl_parameter_get_double(param) ;
00094
00095
00096
00097 if ((frm_cube1 = cpl_frameset_find(framelist, SI_UTL_GENLOOKUP_CUBE1))==NULL) {
00098 cpl_msg_error(fctid, "SOF does not have a file tagged as %s",SI_UTL_GENLOOKUP_CUBE1);
00099 return -1 ;
00100 }
00101 if ((frm_cube2 = cpl_frameset_find(framelist, SI_UTL_GENLOOKUP_CUBE1))==NULL) {
00102 cpl_msg_error(fctid, "SOF does not have a file tagged as %s",SI_UTL_GENLOOKUP_CUBE1);
00103 return -1 ;
00104 }
00105
00106
00107
00108 name1 = (char*)cpl_frame_get_filename(frm_cube1);
00109 name2 = (char*)cpl_frame_get_filename(frm_cube2);
00110
00111
00112 iCube = load_cube(name1);
00113 jCube = load_cube(name2);
00114
00115 lookup = newLookup();
00116
00117 lookup->id = iCube;
00118 lookup->jd = jCube;
00119
00120 rc = cCreateXYZ (lookup);
00121
00122 name_o1=strcat(name_o,"X.fits");
00123 name_o2=strcat(name_o,"Y.fits");
00124 name_o3=strcat(name_o,"Z.fits");
00125 name_o4=strcat(name_o,"cX.fits");
00126
00127 save_image_to_fits ( lookup->X , name_o1, -32 );
00128 save_image_to_fits ( lookup->Y , name_o2, -32 );
00129 save_image_to_fits ( lookup->Z , name_o3, -32 );
00130 save_image_to_fits ( lookup->hX, name_o4, -32 );
00131
00132 destroy_cube(iCube);
00133 destroy_cube(jCube);
00134
00135 destroy_image(lookup->X);
00136 destroy_image(lookup->Y);
00137 destroy_image(lookup->Z);
00138 destroy_image(lookup->hX);
00139
00140 destroyLookup(lookup);
00141
00142
00143
00144
00145
00146
00147
00148 product_frame = cpl_frame_new();
00149 cpl_frame_set_filename(product_frame, name_o1) ;
00150 cpl_frame_set_tag(product_frame, SI_UTL_GENLOOKUP_PROIMA1) ;
00151 cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE) ;
00152 cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT) ;
00153 cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL) ;
00154 if (cpl_error_get_code()) {
00155 cpl_msg_error(fctid, "Error while initialising the product frame") ;
00156 cpl_propertylist_delete(plist) ;
00157 cpl_frame_delete(product_frame) ;
00158 cpl_image_delete(image) ;
00159 return -1 ;
00160 }
00161
00162
00163 product_frame = cpl_frame_new();
00164 cpl_frame_set_filename(product_frame, name_o2) ;
00165 cpl_frame_set_tag(product_frame, SI_UTL_GENLOOKUP_PROIMA2) ;
00166 cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE) ;
00167 cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT) ;
00168 cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL) ;
00169 if (cpl_error_get_code()) {
00170 cpl_msg_error(fctid, "Error while initialising the product frame") ;
00171 cpl_propertylist_delete(plist) ;
00172 cpl_frame_delete(product_frame) ;
00173 cpl_image_delete(image) ;
00174 return -1 ;
00175 }
00176
00177
00178 product_frame = cpl_frame_new();
00179 cpl_frame_set_filename(product_frame, name_o3) ;
00180 cpl_frame_set_tag(product_frame, SI_UTL_GENLOOKUP_PROIMA3) ;
00181 cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE) ;
00182 cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT) ;
00183 cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL) ;
00184 if (cpl_error_get_code()) {
00185 cpl_msg_error(fctid, "Error while initialising the product frame") ;
00186 cpl_propertylist_delete(plist) ;
00187 cpl_frame_delete(product_frame) ;
00188 cpl_image_delete(image) ;
00189 return -1 ;
00190 }
00191
00192
00193 product_frame = cpl_frame_new();
00194 cpl_frame_set_filename(product_frame, name_o4) ;
00195 cpl_frame_set_tag(product_frame, SI_UTL_GENLOOKUP_PROIMA4) ;
00196 cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE) ;
00197 cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT) ;
00198 cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL) ;
00199 if (cpl_error_get_code()) {
00200 cpl_msg_error(fctid, "Error while initialising the product frame") ;
00201 cpl_propertylist_delete(plist) ;
00202 cpl_frame_delete(product_frame) ;
00203 cpl_image_delete(image) ;
00204 return -1 ;
00205 }
00206
00207
00208
00209 if (cpl_dfs_setup_product_header(plist, product_frame, framelist, parlist,
00210 "si_utl_genlookup", "SINFONI", KEY_VALUE_HPRO_DID) != CPL_ERROR_NONE) {
00211 cpl_msg_error(fctid, "Problem in the product DFS-compliance") ;
00212 cpl_propertylist_delete(plist) ;
00213 cpl_frame_delete(product_frame) ;
00214 cpl_image_delete(image) ;
00215 return -1 ;
00216 }
00217
00218
00219 if (cpl_image_save(image, name_o, CPL_BPP_DEFAULT, plist,
00220 CPL_IO_DEFAULT) != CPL_ERROR_NONE) {
00221 cpl_msg_error(fctid, "Could not save product");
00222 cpl_propertylist_delete(plist) ;
00223 cpl_frame_delete(product_frame) ;
00224 cpl_image_delete(image) ;
00225 return -1 ;
00226 }
00227 cpl_propertylist_delete(plist) ;
00228 cpl_image_delete(image) ;
00229
00230
00231 cpl_frameset_insert(framelist, product_frame) ;
00232
00233
00234 if (cpl_error_get_code())
00235 return -1 ;
00236 else
00237 return 0 ;
00238 }