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 #include <string.h>
00036
00037
00038 #include <cpl.h>
00039
00040 #include <xsh_dfs.h>
00041 #include <xsh_data_pre.h>
00042 #include <xsh_parameters.h>
00043 #include <xsh_drl.h>
00044 #include <xsh_msg.h>
00045 #include <xsh_pfits.h>
00046 #include <xsh_error.h>
00047
00048
00049
00050
00051
00052
00053
00054 #define XSH_UTL_IMA_FSTEXT_RECIPE_ID "xsh_util_ima_getextno"
00055 #define XSH_UTL_IMA_FSTEXT_RECIPE_AUTHOR "A.Modigliani"
00056 #define XSH_UTL_IMA_FSTEXT_RECIPE_CONTACT "Andrea.Modigliani@eso.org"
00057 #define PRO_IMA "PRO_IMA_UVB"
00058 #define KEY_VALUE_HPRO_DID "PRO-1.15"
00059
00060
00061
00062
00063 static int xsh_util_ima_getextno_create(cpl_plugin *) ;
00064 static int xsh_util_ima_getextno_exec(cpl_plugin *) ;
00065 static int xsh_util_ima_getextno_destroy(cpl_plugin *) ;
00066 static int xsh_util_ima_getextno(cpl_parameterlist *, cpl_frameset *) ;
00067
00068
00069
00070
00071
00072 static char
00073 xsh_util_ima_getextno_description_short[] =
00074 "Extract extention extno from input image";
00075 static char xsh_util_ima_getextno_description[] =
00076 "Extract extention extno from input image.\n"
00077 "extno is an input parameter.\n"
00078 "xsh.xsh_util_ima_getextno.extno having alias 'extno' and default 0\n"
00079 "Information on relevant parameters can be found with\n"
00080 "esorex --params xsh_util_ima_getextno\n"
00081 "esorex --help xsh_util_ima_getextno\n"
00082 "\n";
00083
00084
00085
00086
00087
00092
00093
00095
00103
00104 int cpl_plugin_get_info(cpl_pluginlist * list)
00105 {
00106 cpl_recipe * recipe = cpl_calloc(1, sizeof *recipe ) ;
00107 cpl_plugin * plugin = &recipe->interface ;
00108
00109 cpl_plugin_init(plugin,
00110 CPL_PLUGIN_API,
00111 XSH_BINARY_VERSION,
00112 CPL_PLUGIN_TYPE_RECIPE,
00113 XSH_UTL_IMA_FSTEXT_RECIPE_ID,
00114 xsh_util_ima_getextno_description_short,
00115 xsh_util_ima_getextno_description,
00116 XSH_UTL_IMA_FSTEXT_RECIPE_AUTHOR,
00117 XSH_UTL_IMA_FSTEXT_RECIPE_CONTACT,
00118 xsh_get_license(),
00119 xsh_util_ima_getextno_create,
00120 xsh_util_ima_getextno_exec,
00121 xsh_util_ima_getextno_destroy) ;
00122
00123 cpl_pluginlist_append(list, plugin) ;
00124
00125 return 0;
00126 }
00127
00128
00137
00138 static int xsh_util_ima_getextno_create(cpl_plugin * plugin)
00139 {
00140 cpl_recipe * recipe ;
00141 cpl_parameter * p ;
00142
00143
00144 xsh_init();
00145
00146
00147 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00148 recipe = (cpl_recipe *)plugin ;
00149 else return -1 ;
00150 cpl_error_reset();
00151
00152
00153
00154 recipe->parameters = cpl_parameterlist_new() ;
00155
00156
00157
00158 check( xsh_parameters_generic(XSH_UTL_IMA_FSTEXT_RECIPE_ID,
00159 recipe->parameters ) ) ;
00160 xsh_parameters_decode_bp(XSH_UTL_IMA_FSTEXT_RECIPE_ID,recipe->parameters,-1);
00161
00162 p = cpl_parameter_new_value("xsh.xsh_util_ima_getextno.extno",
00163 CPL_TYPE_INT,
00164 "Extention to extract",
00165 "xsh.xsh_util_ima_getextno",0);
00166 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "extno") ;
00167 cpl_parameterlist_append(recipe->parameters, p) ;
00168
00169 cleanup:
00170
00171
00172 return 0;
00173 }
00174
00175
00181
00182 static int xsh_util_ima_getextno_exec(cpl_plugin * plugin)
00183 {
00184 cpl_recipe * recipe ;
00185 int code=0;
00186 cpl_errorstate initial_errorstate = cpl_errorstate_get();
00187
00188
00189 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00190 recipe = (cpl_recipe *)plugin ;
00191 else return -1 ;
00192 cpl_error_reset();
00193
00194 code = xsh_util_ima_getextno(recipe->parameters, recipe->frames) ;
00195
00196
00197 if (!cpl_errorstate_is_equal(initial_errorstate)) {
00198
00199
00200 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
00201 }
00202
00203 return code ;
00204 }
00205
00206
00212
00213 static int xsh_util_ima_getextno_destroy(cpl_plugin * plugin)
00214 {
00215 cpl_recipe * recipe ;
00216
00217
00218 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00219 recipe = (cpl_recipe *)plugin ;
00220 else return -1 ;
00221
00222 cpl_parameterlist_delete(recipe->parameters) ;
00223 return 0 ;
00224 }
00225
00226
00233
00234 static int
00235 xsh_util_ima_getextno( cpl_parameterlist * parlist,
00236 cpl_frameset * frames)
00237 {
00238 cpl_parameter * param= NULL ;
00239 cpl_frame* frm=NULL;
00240 cpl_image* ima=NULL;
00241 cpl_propertylist* plist=NULL;
00242
00243 int extno=0;
00244 int nfrm=0;
00245 const char* name=NULL;
00246 char new_name[256];
00247 xsh_msg("Welcome to XSHOOTER Pipeline release %d.%d.%d",
00248 XSH_MAJOR_VERSION,XSH_MINOR_VERSION,XSH_MICRO_VERSION);
00249
00250
00251
00252 check(param=cpl_parameterlist_find(parlist,
00253 "xsh.xsh_util_ima_getextno.extno"));
00254 check(extno=cpl_parameter_get_int(param));
00255
00256 nfrm=cpl_frameset_get_size(frames);
00257
00258 for (frm = cpl_frameset_get_first(frames);
00259 frm != NULL;
00260 frm = cpl_frameset_get_next(frames)) {
00261 check(name=cpl_frame_get_filename(frm));
00262 plist=cpl_propertylist_load(name,0);
00263 sprintf(new_name,"ext%d_%s",extno,name);
00264 xsh_msg("new_name=%s",new_name);
00265 check(ima=cpl_image_load(name,CPL_TYPE_FLOAT,0,extno));
00266 check(cpl_image_save(ima,new_name,CPL_BPP_IEEE_FLOAT,plist,
00267 CPL_IO_DEFAULT));
00268 xsh_free_image(&ima);
00269 xsh_free_propertylist(&plist);
00270 }
00271
00272 cleanup:
00273 xsh_free_image(&ima);
00274
00275
00276 if (cpl_error_get_code()) {
00277 return -1 ;
00278 } else {
00279 return 0 ;
00280 }
00281
00282 }