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 #include <string.h>
00037 #include <math.h>
00038 #include <cpl.h>
00039
00040 #include <hawki_dfs.h>
00041 #include <hawki_load.h>
00042 #include <hawki_save.h>
00043 #include <hawki_pfits.h>
00044 #include <hawki_image_stats.h>
00045 #include <hawki_utils.h>
00046
00047
00048
00049
00050
00051
00052 static int hawki_tec_filtchk_create(cpl_plugin *) ;
00053 static int hawki_tec_filtchk_exec(cpl_plugin *) ;
00054 static int hawki_tec_filtchk_destroy(cpl_plugin *) ;
00055 static int hawki_tec_filtchk(cpl_parameterlist *, cpl_frameset *) ;
00056
00057 static int hawki_tec_filtchk_frameset_stats
00058 (cpl_table ** target_stats,
00059 cpl_propertylist ** stats_stats,
00060 cpl_frameset * target_frames);
00061
00062 static int hawki_tec_filtchk_save
00063 (cpl_table ** target_stats,
00064 cpl_parameterlist * recipe_parlist,
00065 cpl_frameset * recipe_frameset,
00066 cpl_propertylist ** stats_stats,
00067 const char * calpro,
00068 const char * protype);
00069
00070
00071
00072
00073
00074 static char hawki_tec_filtchk_description[] =
00075 "hawki_tec_filtchk -- Check pairs of flats taken with different filters.\n"
00076 "The files listed in the Set Of Frames (sof-file) must be tagged:\n"
00077 "raw-file.fits "HAWKI_TEC_FLAT_RAW"\n";
00078
00079
00080
00081
00082
00083
00091
00092 int cpl_plugin_get_info(cpl_pluginlist * list)
00093 {
00094 cpl_recipe * recipe = cpl_calloc(1, sizeof(*recipe)) ;
00095 cpl_plugin * plugin = &recipe->interface ;
00096
00097 cpl_plugin_init(plugin,
00098 CPL_PLUGIN_API,
00099 HAWKI_BINARY_VERSION,
00100 CPL_PLUGIN_TYPE_RECIPE,
00101 "hawki_tec_filtchk",
00102 "Filter checking recipe",
00103 hawki_tec_filtchk_description,
00104 "Cesar Enrique Garcia Dabo",
00105 PACKAGE_BUGREPORT,
00106 hawki_get_license(),
00107 hawki_tec_filtchk_create,
00108 hawki_tec_filtchk_exec,
00109 hawki_tec_filtchk_destroy) ;
00110
00111 cpl_pluginlist_append(list, plugin) ;
00112
00113 return 0;
00114 }
00115
00116
00125
00126 static int hawki_tec_filtchk_create(cpl_plugin * plugin)
00127 {
00128 cpl_recipe * recipe ;
00129
00130
00131
00132 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00133 recipe = (cpl_recipe *)plugin ;
00134 else return -1 ;
00135
00136
00137 recipe->parameters = cpl_parameterlist_new() ;
00138
00139
00140
00141
00142
00143 return 0;
00144 }
00145
00146
00152
00153 static int hawki_tec_filtchk_exec(cpl_plugin * plugin)
00154 {
00155 cpl_recipe * recipe ;
00156
00157
00158 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00159 recipe = (cpl_recipe *)plugin ;
00160 else return -1 ;
00161
00162
00163 hawki_print_banner();
00164
00165 return hawki_tec_filtchk(recipe->parameters, recipe->frames) ;
00166 }
00167
00168
00174
00175 static int hawki_tec_filtchk_destroy(cpl_plugin * plugin)
00176 {
00177 cpl_recipe * recipe ;
00178
00179
00180 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00181 recipe = (cpl_recipe *)plugin ;
00182 else return -1 ;
00183
00184 cpl_parameterlist_delete(recipe->parameters) ;
00185 return 0 ;
00186 }
00187
00188
00195
00196 static int hawki_tec_filtchk(
00197 cpl_parameterlist * parlist,
00198 cpl_frameset * framelist)
00199 {
00200 cpl_frameset * frames ;
00201 cpl_table ** target_stats;
00202 cpl_propertylist ** stats_stats;
00203 int idet;
00204 char calpro[1024];
00205 char protype[1024];
00206
00207
00208 if (hawki_dfs_set_groups(framelist))
00209 {
00210 cpl_msg_error(__func__, "Cannot identify RAW and CALIB frames") ;
00211 return -1;
00212 }
00213
00214
00215 cpl_msg_info(__func__, "Identifying input frames");
00216 frames = hawki_extract_frameset(framelist, HAWKI_TEC_FLAT_RAW) ;
00217 snprintf(calpro, 1024, HAWKI_CALPRO_FILTERPOSCHECK_STATS);
00218 snprintf(protype, 1024, HAWKI_PROTYPE_FILTERPOSCHECK_STATS);
00219 if (frames == NULL)
00220 {
00221 cpl_msg_error(__func__,"Input files should be tagged %s",
00222 HAWKI_TEC_FLAT_RAW);
00223 return -1;
00224 }
00225
00226
00227 target_stats = cpl_malloc(HAWKI_NB_DETECTORS * sizeof(cpl_table *));
00228 stats_stats = cpl_malloc(HAWKI_NB_DETECTORS * sizeof(cpl_propertylist *));
00229 for( idet=0 ; idet<HAWKI_NB_DETECTORS ; idet++)
00230 {
00231 target_stats[idet] = cpl_table_new(cpl_frameset_get_size(frames));
00232 stats_stats[idet] = cpl_propertylist_new();
00233 }
00234 hawki_image_stats_initialize(target_stats);
00235
00236
00237 hawki_tec_filtchk_frameset_stats(target_stats, stats_stats, frames);
00238
00239
00240 hawki_tec_filtchk_save
00241 (target_stats, parlist, framelist, stats_stats, calpro, protype);
00242
00243
00244 cpl_frameset_delete(frames);
00245 for( idet=0 ; idet<HAWKI_NB_DETECTORS ; idet++)
00246 {
00247 cpl_table_delete(target_stats[idet]);
00248 cpl_propertylist_delete(stats_stats[idet]);
00249 }
00250 cpl_free(target_stats);
00251 cpl_free(stats_stats);
00252
00253
00254 if (cpl_error_get_code())
00255 {
00256 cpl_msg_error(__func__,
00257 "HAWK-I pipeline could not recover from previous errors");
00258 return -1 ;
00259 }
00260 else return 0 ;
00261 }
00262
00263
00273
00274 static int hawki_tec_filtchk_frameset_stats
00275 (cpl_table ** target_stats,
00276 cpl_propertylist ** stats_stats,
00277 cpl_frameset * target_frames)
00278 {
00279 int iframe;
00280 int nframes;
00281
00282
00283 nframes = cpl_frameset_get_size(target_frames);
00284 cpl_msg_info(__func__, "Looping the target frames: %d frames", nframes);
00285 cpl_msg_indent_more();
00286 for( iframe = 0 ; iframe < nframes ; ++iframe)
00287 {
00288
00289 cpl_frame * this_target_frame;
00290
00291
00292 cpl_msg_info(__func__, "Computing stats for frame: %d", iframe +1);
00293 this_target_frame = cpl_frameset_get_frame(target_frames, iframe);
00294 hawki_image_stats_fill_from_frame
00295 (target_stats, this_target_frame, iframe);
00296 }
00297 cpl_msg_indent_less();
00298
00299
00300 hawki_image_stats_stats(target_stats, stats_stats);
00301
00302
00303 hawki_image_stats_print(target_stats);
00304
00305 return 0;
00306 }
00307
00308
00318
00319 static int hawki_tec_filtchk_save
00320 (cpl_table ** target_stats,
00321 cpl_parameterlist * recipe_parlist,
00322 cpl_frameset * recipe_frameset,
00323 cpl_propertylist ** stats_stats,
00324 const char * calpro,
00325 const char * protype)
00326 {
00327 const cpl_frame * reference_frame;
00328 cpl_propertylist * referencelist;
00329 cpl_propertylist ** extlists;
00330 int idet;
00331 int ext_nb;
00332 const char * recipe_name = "hawki_tec_filtchk";
00333
00334
00335 reference_frame = cpl_frameset_get_first_const(recipe_frameset);
00336
00337
00338 cpl_msg_info(__func__, "Creating the keywords list") ;
00339 referencelist = cpl_propertylist_load_regexp
00340 (cpl_frame_get_filename(reference_frame), 0,HAWKI_HEADER_EXT_FORWARD,0);
00341 extlists =
00342 cpl_malloc(HAWKI_NB_DETECTORS * sizeof(cpl_propertylist*));
00343 for (idet=0 ; idet<HAWKI_NB_DETECTORS ; idet++)
00344 {
00345
00346 ext_nb=hawki_get_ext_from_detector
00347 (cpl_frame_get_filename(reference_frame), idet+1);
00348
00349
00350 extlists[idet] = cpl_propertylist_load_regexp(
00351 cpl_frame_get_filename(reference_frame), ext_nb,
00352 HAWKI_HEADER_EXT_FORWARD, 0);
00353
00354
00355 cpl_propertylist_append(extlists[idet],stats_stats[idet]);
00356 }
00357
00358
00359 hawki_tables_save(recipe_frameset,
00360 recipe_parlist,
00361 recipe_frameset,
00362 (const cpl_table **)target_stats,
00363 recipe_name,
00364 calpro,
00365 protype,
00366 (const cpl_propertylist*)referencelist,
00367 (const cpl_propertylist**)extlists,
00368 "hawki_tec_filtchk_stats.fits");
00369
00370
00371 cpl_propertylist_delete(referencelist) ;
00372 for (idet=0 ; idet<HAWKI_NB_DETECTORS ; idet++)
00373 {
00374 cpl_propertylist_delete(extlists[idet]) ;
00375 }
00376 cpl_free(extlists) ;
00377 return 0;
00378 }