40 #include <hawki_dfs.h>
41 #include <hawki_load.h>
42 #include <hawki_save.h>
43 #include <hawki_pfits.h>
44 #include <hawki_image_stats.h>
45 #include <hawki_utils.h>
55 int cpl_plugin_get_info(cpl_pluginlist * list);
57 static int hawki_tec_filtchk_create(cpl_plugin *) ;
58 static int hawki_tec_filtchk_exec(cpl_plugin *) ;
59 static int hawki_tec_filtchk_destroy(cpl_plugin *) ;
60 static int hawki_tec_filtchk(cpl_parameterlist *, cpl_frameset *) ;
62 static int hawki_tec_filtchk_frameset_stats
63 (cpl_table ** target_stats,
64 cpl_propertylist ** stats_stats,
65 cpl_frameset * target_frames);
67 static int hawki_tec_filtchk_save
68 (cpl_table ** target_stats,
69 cpl_parameterlist * recipe_parlist,
70 cpl_frameset * recipe_frameset,
71 cpl_propertylist ** stats_stats,
73 const char * protype);
79 static char hawki_tec_filtchk_description[] =
80 "hawki_tec_filtchk -- Check pairs of flats taken with different filters.\n"
81 "The files listed in the Set Of Frames (sof-file) must be tagged:\n"
82 "raw-file.fits "HAWKI_TEC_FLAT_RAW
"\n";
97 int cpl_plugin_get_info(cpl_pluginlist * list)
99 cpl_recipe * recipe = cpl_calloc(1,
sizeof(*recipe)) ;
100 cpl_plugin * plugin = &recipe->interface ;
102 cpl_plugin_init(plugin,
104 HAWKI_BINARY_VERSION,
105 CPL_PLUGIN_TYPE_RECIPE,
107 "Filter checking recipe",
108 hawki_tec_filtchk_description,
109 "Cesar Enrique Garcia Dabo",
112 hawki_tec_filtchk_create,
113 hawki_tec_filtchk_exec,
114 hawki_tec_filtchk_destroy) ;
116 cpl_pluginlist_append(list, plugin) ;
131 static int hawki_tec_filtchk_create(cpl_plugin * plugin)
133 cpl_recipe * recipe ;
137 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
138 recipe = (cpl_recipe *)plugin ;
142 recipe->parameters = cpl_parameterlist_new() ;
143 if (recipe->parameters == NULL)
160 static int hawki_tec_filtchk_exec(cpl_plugin * plugin)
162 cpl_recipe * recipe ;
165 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
166 recipe = (cpl_recipe *)plugin ;
172 return hawki_tec_filtchk(recipe->parameters, recipe->frames) ;
182 static int hawki_tec_filtchk_destroy(cpl_plugin * plugin)
184 cpl_recipe * recipe ;
187 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
188 recipe = (cpl_recipe *)plugin ;
191 cpl_parameterlist_delete(recipe->parameters) ;
203 static int hawki_tec_filtchk(
204 cpl_parameterlist * parlist,
205 cpl_frameset * framelist)
207 cpl_frameset * frames ;
208 cpl_table ** target_stats;
209 cpl_propertylist ** stats_stats;
217 cpl_msg_error(__func__,
"Cannot identify RAW and CALIB frames") ;
222 cpl_msg_info(__func__,
"Identifying input frames");
224 snprintf(calpro, 1024, HAWKI_CALPRO_FILTERPOSCHECK_STATS);
225 snprintf(protype, 1024, HAWKI_PROTYPE_FILTERPOSCHECK_STATS);
228 cpl_msg_error(__func__,
"Input files should be tagged %s",
234 target_stats = cpl_malloc(HAWKI_NB_DETECTORS *
sizeof(cpl_table *));
235 stats_stats = cpl_malloc(HAWKI_NB_DETECTORS *
sizeof(cpl_propertylist *));
236 for( idet=0 ; idet<HAWKI_NB_DETECTORS ; idet++)
238 target_stats[idet] = cpl_table_new(cpl_frameset_get_size(frames));
239 stats_stats[idet] = cpl_propertylist_new();
244 hawki_tec_filtchk_frameset_stats(target_stats, stats_stats, frames);
247 hawki_tec_filtchk_save
248 (target_stats, parlist, framelist, stats_stats, calpro, protype);
251 cpl_frameset_delete(frames);
252 for( idet=0 ; idet<HAWKI_NB_DETECTORS ; idet++)
254 cpl_table_delete(target_stats[idet]);
255 cpl_propertylist_delete(stats_stats[idet]);
257 cpl_free(target_stats);
258 cpl_free(stats_stats);
261 if (cpl_error_get_code())
263 cpl_msg_error(__func__,
264 "HAWK-I pipeline could not recover from previous errors");
281 static int hawki_tec_filtchk_frameset_stats
282 (cpl_table ** target_stats,
283 cpl_propertylist ** stats_stats,
284 cpl_frameset * target_frames)
290 nframes = cpl_frameset_get_size(target_frames);
291 cpl_msg_info(__func__,
"Looping the target frames: %d frames", nframes);
292 cpl_msg_indent_more();
293 for( iframe = 0 ; iframe < nframes ; ++iframe)
296 cpl_frame * this_target_frame;
299 cpl_msg_info(__func__,
"Computing stats for frame: %d", iframe +1);
300 this_target_frame = cpl_frameset_get_frame(target_frames, iframe);
302 (target_stats, this_target_frame, iframe);
304 cpl_msg_indent_less();
310 hawki_image_stats_print(target_stats);
326 static int hawki_tec_filtchk_save
327 (cpl_table ** target_stats,
328 cpl_parameterlist * recipe_parlist,
329 cpl_frameset * recipe_frameset,
330 cpl_propertylist ** stats_stats,
332 const char * protype)
334 const cpl_frame * reference_frame;
335 cpl_propertylist * referencelist;
336 cpl_propertylist ** extlists;
339 const char * recipe_name =
"hawki_tec_filtchk";
342 reference_frame = cpl_frameset_get_first_const(recipe_frameset);
345 cpl_msg_info(__func__,
"Creating the keywords list") ;
346 referencelist = cpl_propertylist_load_regexp
347 (cpl_frame_get_filename(reference_frame), 0,HAWKI_HEADER_EXT_FORWARD,0);
349 cpl_malloc(HAWKI_NB_DETECTORS *
sizeof(cpl_propertylist*));
350 for (idet=0 ; idet<HAWKI_NB_DETECTORS ; idet++)
354 (cpl_frame_get_filename(reference_frame), idet+1);
357 extlists[idet] = cpl_propertylist_load_regexp(
358 cpl_frame_get_filename(reference_frame), ext_nb,
359 HAWKI_HEADER_EXT_FORWARD, 0);
362 cpl_propertylist_append(extlists[idet],stats_stats[idet]);
369 (
const cpl_table **)target_stats,
373 (
const cpl_propertylist*)referencelist,
374 (
const cpl_propertylist**)extlists,
375 "hawki_tec_filtchk_stats.fits");
378 cpl_propertylist_delete(referencelist) ;
379 for (idet=0 ; idet<HAWKI_NB_DETECTORS ; idet++)
381 cpl_propertylist_delete(extlists[idet]) ;