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
00041 #include <xsh_dfs.h>
00042
00043 #include <xsh_parameters.h>
00044 #include <xsh_drl.h>
00045 #include <xsh_msg.h>
00046 #include <xsh_pfits.h>
00047 #include <xsh_error.h>
00048
00049
00050
00051
00052
00053
00054 #define XSH_UTL_IMA_SHIFT_RECIPE_ID "xsh_util_ima_shift"
00055 #define XSH_UTL_IMA_SHIFT_RECIPE_AUTHOR "A.Modigliani"
00056 #define XSH_UTL_IMA_SHIFT_RECIPE_CONTACT "Andrea.Modigliani@eso.org"
00057 #define PRO_IMA "PRO_IMA"
00058 #define KEY_VALUE_HPRO_DID "PRO-1.15"
00059
00060
00061
00062
00063 static int xsh_util_ima_shift_create(cpl_plugin *) ;
00064 static int xsh_util_ima_shift_exec(cpl_plugin *) ;
00065 static int xsh_util_ima_shift_destroy(cpl_plugin *) ;
00066 static int xsh_util_ima_shift(cpl_parameterlist *, cpl_frameset *) ;
00067
00068
00069
00070
00071
00072 static char
00073 xsh_util_ima_shift_description_short[] = "Shift an image along X or Y";
00074 static char xsh_util_ima_shift_description[] =
00075 "This recipe performs image shift along x or y.\n"
00076 "The input file is an image tagged as 'IMA'.\n"
00077 "The output is a shifted image\n"
00078 "xsh.xsh_util_ima_shift.shiftx having alias 'shiftx'\n"
00079 "xsh.xsh_util_ima_shift.shifty having alias 'shifty'\n"
00080 "Information on relevant parameters can be found with\n"
00081 "esorex --params xsh_util_ima_shift\n"
00082 "esorex --help xsh_util_ima_shift\n"
00083 "\n";
00084
00085
00086
00087
00088
00093
00094
00096
00104
00105 int cpl_plugin_get_info(cpl_pluginlist * list)
00106 {
00107 cpl_recipe * recipe = cpl_calloc(1, sizeof *recipe ) ;
00108 cpl_plugin * plugin = &recipe->interface ;
00109
00110 cpl_plugin_init(plugin,
00111 CPL_PLUGIN_API,
00112 XSH_BINARY_VERSION,
00113 CPL_PLUGIN_TYPE_RECIPE,
00114 XSH_UTL_IMA_SHIFT_RECIPE_ID,
00115 xsh_util_ima_shift_description_short,
00116 xsh_util_ima_shift_description,
00117 XSH_UTL_IMA_SHIFT_RECIPE_AUTHOR,
00118 XSH_UTL_IMA_SHIFT_RECIPE_CONTACT,
00119 xsh_get_license(),
00120 xsh_util_ima_shift_create,
00121 xsh_util_ima_shift_exec,
00122 xsh_util_ima_shift_destroy) ;
00123
00124 cpl_pluginlist_append(list, plugin) ;
00125
00126 return 0;
00127 }
00128
00129
00138
00139 static int xsh_util_ima_shift_create(cpl_plugin * plugin)
00140 {
00141 cpl_recipe * recipe ;
00142 cpl_parameter * p ;
00143
00144
00145 xsh_init();
00146
00147
00148 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00149 recipe = (cpl_recipe *)plugin ;
00150 else return -1 ;
00151 cpl_error_reset();
00152
00153
00154
00155 recipe->parameters = cpl_parameterlist_new() ;
00156
00157
00158
00159 check( xsh_parameters_generic(XSH_UTL_IMA_SHIFT_RECIPE_ID,
00160 recipe->parameters ) ) ;
00161
00162
00163 p = cpl_parameter_new_value("xsh.xsh_util_ima_shift.shiftx",
00164 CPL_TYPE_INT,
00165 "A possible X shift",
00166 "xsh.xsh_util_ima_shiftx",0);
00167 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "shiftx") ;
00168 cpl_parameterlist_append(recipe->parameters, p) ;
00169
00170 p = cpl_parameter_new_value("xsh.xsh_util_ima_shift.shifty",
00171 CPL_TYPE_INT,
00172 "A possible Y shift",
00173 "xsh.xsh_util_ima_shifty",0);
00174 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "shifty") ;
00175 cpl_parameterlist_append(recipe->parameters, p) ;
00176
00177 cleanup:
00178
00179
00180 return 0;
00181 }
00182
00183
00189
00190 static int xsh_util_ima_shift_exec(cpl_plugin * plugin)
00191 {
00192 cpl_recipe * recipe ;
00193 int code=0;
00194 cpl_errorstate initial_errorstate = cpl_errorstate_get();
00195
00196
00197 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00198 recipe = (cpl_recipe *)plugin ;
00199 else return -1 ;
00200 cpl_error_reset();
00201
00202 code = xsh_util_ima_shift(recipe->parameters, recipe->frames) ;
00203
00204
00205 if (!cpl_errorstate_is_equal(initial_errorstate)) {
00206
00207
00208 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
00209 }
00210
00211 return code ;
00212 }
00213
00214
00220
00221 static int xsh_util_ima_shift_destroy(cpl_plugin * plugin)
00222 {
00223 cpl_recipe * recipe ;
00224
00225
00226 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00227 recipe = (cpl_recipe *)plugin ;
00228 else return -1 ;
00229
00230 cpl_parameterlist_delete(recipe->parameters) ;
00231 return 0 ;
00232 }
00233
00234
00241
00242 static int
00243 xsh_util_ima_shift( cpl_parameterlist * parlist,
00244 cpl_frameset * framelist)
00245 {
00246 cpl_parameter * param= NULL ;
00247 int shiftx=0 ;
00248 int shifty=0 ;
00249 cpl_image * ima=NULL ;
00250 char name_o[256];
00251 cpl_propertylist * plist=NULL ;
00252 cpl_frameset * raw_set=NULL;
00253 int nraw=0;
00254 int n=0;
00255 int i=0;
00256 cpl_frame* frm=NULL;
00257 const char* name=NULL;
00258
00259 xsh_msg("Welcome to XSHOOTER Pipeline release %d.%d.%d",
00260 XSH_MAJOR_VERSION,XSH_MINOR_VERSION,XSH_MICRO_VERSION);
00261
00262
00263
00264 check(param=cpl_parameterlist_find(parlist,
00265 "xsh.xsh_util_ima_shift.shiftx"));
00266 check(shiftx=cpl_parameter_get_int(param));
00267
00268 check(param=cpl_parameterlist_find(parlist,
00269 "xsh.xsh_util_ima_shift.shifty"));
00270 check(shifty=cpl_parameter_get_int(param));
00271
00272
00273 n=cpl_frameset_get_size(framelist);
00274 if(n<1) {
00275 xsh_msg_error("Empty input frame list!");
00276 goto cleanup ;
00277 }
00278
00279
00280 check_msg(raw_set=xsh_frameset_extract(framelist,XSH_IMA),
00281 "Found no input frames with tag %s",XSH_IMA);
00282 check(nraw=cpl_frameset_get_size(raw_set));
00283 if (nraw<1) {
00284 xsh_msg_error("Found no input frames with tag %s",XSH_IMA);
00285 goto cleanup;
00286 } else {
00287 for(i=0;i<nraw;i++) {
00288 check(frm=cpl_frameset_get_frame(raw_set,i));
00289 check(name=cpl_frame_get_filename(frm));
00290 check(ima=cpl_image_load(name,CPL_TYPE_FLOAT,0,0));
00291 check(cpl_image_shift(ima,shiftx,shifty));
00292 check(plist=cpl_propertylist_load(name,0));
00293 check(sprintf(name_o,"shiftx%d_shifty%d_%s",shiftx,shifty,name));
00294 xsh_msg("name_o=%s",name_o);
00295 check(cpl_image_save(ima,name_o,CPL_BPP_IEEE_FLOAT,plist,CPL_IO_DEFAULT));
00296 xsh_free_propertylist(&plist);
00297 xsh_free_image(&ima);
00298 }
00299 }
00300 xsh_free_frameset(&raw_set);
00301
00302 cleanup:
00303 xsh_free_propertylist(&plist);
00304 xsh_free_image(&ima);
00305 xsh_free_frameset(&raw_set);
00306
00307 if (cpl_error_get_code()) {
00308 return -1 ;
00309 } else {
00310 return 0 ;
00311 }
00312 }