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 if (cpl_error_get_code()) return -1 ;
00254 else return 0 ;
00255 }
00256
00257
00267
00268 static int hawki_tec_filtchk_frameset_stats
00269 (cpl_table ** target_stats,
00270 cpl_propertylist ** stats_stats,
00271 cpl_frameset * target_frames)
00272 {
00273 int iframe;
00274 int nframes;
00275
00276
00277 nframes = cpl_frameset_get_size(target_frames);
00278 cpl_msg_info(__func__, "Looping the target frames: %d frames", nframes);
00279 cpl_msg_indent_more();
00280 for( iframe = 0 ; iframe < nframes ; ++iframe)
00281 {
00282
00283 cpl_frame * this_target_frame;
00284
00285
00286 cpl_msg_info(__func__, "Computing stats for frame: %d", iframe +1);
00287 this_target_frame = cpl_frameset_get_frame(target_frames, iframe);
00288 hawki_image_stats_fill_from_frame
00289 (target_stats, this_target_frame, iframe);
00290 }
00291 cpl_msg_indent_less();
00292
00293
00294 hawki_image_stats_stats(target_stats, stats_stats);
00295
00296
00297 hawki_image_stats_print(target_stats);
00298
00299 return 0;
00300 }
00301
00302
00312
00313 static int hawki_tec_filtchk_save
00314 (cpl_table ** target_stats,
00315 cpl_parameterlist * recipe_parlist,
00316 cpl_frameset * recipe_frameset,
00317 cpl_propertylist ** stats_stats,
00318 const char * calpro,
00319 const char * protype)
00320 {
00321 const cpl_frame * reference_frame;
00322 cpl_propertylist * referencelist;
00323 cpl_propertylist ** extlists;
00324 int idet;
00325 int ext_nb;
00326 const char * recipe_name = "hawki_tec_filtchk";
00327
00328
00329 reference_frame = cpl_frameset_get_first_const(recipe_frameset);
00330
00331
00332 cpl_msg_info(__func__, "Creating the keywords list") ;
00333 referencelist = cpl_propertylist_load_regexp
00334 (cpl_frame_get_filename(reference_frame), 0,HAWKI_HEADER_EXT_FORWARD,0);
00335 extlists =
00336 cpl_malloc(HAWKI_NB_DETECTORS * sizeof(cpl_propertylist*));
00337 for (idet=0 ; idet<HAWKI_NB_DETECTORS ; idet++)
00338 {
00339
00340 ext_nb=hawki_get_ext_from_detector
00341 (cpl_frame_get_filename(reference_frame), idet+1);
00342
00343
00344 extlists[idet] = cpl_propertylist_load_regexp(
00345 cpl_frame_get_filename(reference_frame), ext_nb,
00346 HAWKI_HEADER_EXT_FORWARD, 0);
00347
00348
00349 cpl_propertylist_append(extlists[idet],stats_stats[idet]);
00350 }
00351
00352
00353 hawki_tables_save(recipe_frameset,
00354 recipe_parlist,
00355 recipe_frameset,
00356 (const cpl_table **)target_stats,
00357 recipe_name,
00358 calpro,
00359 protype,
00360 (const cpl_propertylist*)referencelist,
00361 (const cpl_propertylist**)extlists,
00362 "hawki_tec_filtchk_stats.fits");
00363
00364
00365 cpl_propertylist_delete(referencelist) ;
00366 for (idet=0 ; idet<HAWKI_NB_DETECTORS ; idet++)
00367 {
00368 cpl_propertylist_delete(extlists[idet]) ;
00369 }
00370 cpl_free(extlists) ;
00371 return 0;
00372 }