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
00029
00030 #ifdef HAVE_CONFIG_H
00031 #include <config.h>
00032 #endif
00033
00034 #include <stdio.h>
00035 #include <cpl.h>
00036
00037 #include "vircam_utils.h"
00038 #include "vircam_dfs.h"
00039 #include "vircam_fits.h"
00040 #include "vircam_mods.h"
00041 #include "vircam_paf.h"
00042
00043
00044
00045 static int vircam_matchxy_create(cpl_plugin *);
00046 static int vircam_matchxy_exec(cpl_plugin *);
00047 static int vircam_matchxy_destroy(cpl_plugin *);
00048 static int vircam_matchxy_test(cpl_parameterlist *, cpl_frameset *);
00049 static int vircam_matchxy_save(void);
00050 static void vircam_matchxy_init(void);
00051 static void vircam_matchxy_tidy(void);
00052
00053 static struct {
00054
00055
00056
00057 int extenum;
00058
00059
00060
00061 float xoff;
00062 float yoff;
00063 int nm;
00064
00065 } vircam_matchxy_config;
00066
00067
00068 static struct {
00069 cpl_size *labels;
00070 cpl_frameset *catlist;
00071 cpl_frame *cat1;
00072 cpl_frame *cat2;
00073 vir_tfits *cat1f;
00074 vir_tfits *cat2f;
00075 } ps;
00076
00077
00078 static char vircam_matchxy_description[] =
00079 "vircam_matchxy -- VIRCAM recipe to test vircam_matchxy.\n\n"
00080 "Match a catalogue with another to get x,y offsets\n\n"
00081 "The program accepts the following files in the SOF:\n\n"
00082 " Tag Description\n"
00083 " -----------------------------------------------------------------------\n"
00084 " %-21s Input catalogues of objects extracted from an image\n"
00085 "\n";
00086
00125
00126
00127
00135
00136
00137 int cpl_plugin_get_info(cpl_pluginlist *list) {
00138 cpl_recipe *recipe = cpl_calloc(1,sizeof(*recipe));
00139 cpl_plugin *plugin = &recipe->interface;
00140 char alldesc[SZ_ALLDESC];
00141 (void)snprintf(alldesc,SZ_ALLDESC,vircam_matchxy_description,
00142 VIRCAM_CAL_OBJCAT);
00143
00144 cpl_plugin_init(plugin,
00145 CPL_PLUGIN_API,
00146 VIRCAM_BINARY_VERSION,
00147 CPL_PLUGIN_TYPE_RECIPE,
00148 "vircam_matchxy",
00149 "VIRCAM catalogue matching test recipe [test]",
00150 alldesc,
00151 "Jim Lewis",
00152 "jrl@ast.cam.ac.uk",
00153 vircam_get_license(),
00154 vircam_matchxy_create,
00155 vircam_matchxy_exec,
00156 vircam_matchxy_destroy);
00157
00158 cpl_pluginlist_append(list,plugin);
00159
00160 return(0);
00161 }
00162
00163
00172
00173
00174 static int vircam_matchxy_create(cpl_plugin *plugin) {
00175 cpl_recipe *recipe;
00176 cpl_parameter *p;
00177
00178
00179
00180 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00181 recipe = (cpl_recipe *)plugin;
00182 else
00183 return(-1);
00184
00185
00186
00187 recipe->parameters = cpl_parameterlist_new();
00188
00189
00190
00191 p = cpl_parameter_new_range("vircam.vircam_matchxy.extenum",
00192 CPL_TYPE_INT,
00193 "Extension number to be done, 0 == all",
00194 "vircam.vircam_matchxy",1,0,16);
00195 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,"ext");
00196 cpl_parameterlist_append(recipe->parameters,p);
00197
00198
00199
00200 return(0);
00201 }
00202
00203
00209
00210
00211 static int vircam_matchxy_exec(cpl_plugin *plugin) {
00212 cpl_recipe *recipe;
00213
00214
00215
00216 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00217 recipe = (cpl_recipe *)plugin;
00218 else
00219 return(-1);
00220
00221 return(vircam_matchxy_test(recipe->parameters,recipe->frames));
00222 }
00223
00224
00230
00231
00232 static int vircam_matchxy_destroy(cpl_plugin *plugin) {
00233 cpl_recipe *recipe ;
00234
00235
00236
00237 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00238 recipe = (cpl_recipe *)plugin;
00239 else
00240 return(-1);
00241
00242 cpl_parameterlist_delete(recipe->parameters);
00243 return(0);
00244 }
00245
00246
00253
00254
00255 static int vircam_matchxy_test(cpl_parameterlist *parlist,
00256 cpl_frameset *framelist) {
00257 const char *fctid="vircam_matchxy";
00258 cpl_parameter *p;
00259 int jst,jfn,status,j;
00260 cpl_size nlab;
00261 cpl_table *out;
00262
00263
00264
00265 if (framelist == NULL || cpl_frameset_get_size(framelist) <= 0) {
00266 cpl_msg_error(fctid,"Input framelist NULL or has no input data");
00267 return(-1);
00268 }
00269
00270
00271
00272 vircam_matchxy_init();
00273
00274
00275
00276 p = cpl_parameterlist_find(parlist,"vircam.vircam_matchxy.extenum");
00277 vircam_matchxy_config.extenum = cpl_parameter_get_int(p);
00278
00279
00280
00281 if (vircam_dfs_set_groups(framelist) != VIR_OK) {
00282 cpl_msg_error(fctid,"Cannot identify RAW and CALIB frames");
00283 vircam_matchxy_tidy();
00284 return(-1);
00285 }
00286
00287
00288
00289 if ((ps.labels = cpl_frameset_labelise(framelist,vircam_compare_tags,
00290 &nlab)) == NULL) {
00291 cpl_msg_error(fctid,"Cannot labelise the input frames");
00292 vircam_matchxy_tidy();
00293 return(-1);
00294 }
00295 if ((ps.catlist = vircam_frameset_subgroup(framelist,ps.labels,nlab,
00296 VIRCAM_CAL_OBJCAT)) == NULL) {
00297 cpl_msg_error(fctid,"No object catalogues found -- cannot continue");
00298 vircam_matchxy_tidy();
00299 return(-1);
00300 }
00301 ps.cat1 = cpl_frameset_get_frame(ps.catlist,0);
00302 ps.cat2 = cpl_frameset_get_frame(ps.catlist,1);
00303 if (ps.cat1 == NULL || ps.cat2 == NULL) {
00304 cpl_msg_error(fctid,"List does not contain two object catalogues");
00305 vircam_matchxy_tidy();
00306 return(-1);
00307 }
00308
00309
00310
00311
00312
00313 vircam_exten_range(vircam_matchxy_config.extenum,
00314 (const cpl_frame *)ps.cat1,&jst,&jfn);
00315 if (jst == -1 || jfn == -1) {
00316 cpl_msg_error(fctid,"Unable to continue");
00317 vircam_matchxy_tidy();
00318 return(-1);
00319 }
00320
00321
00322
00323 status = VIR_OK;
00324 for (j = jst; j <= jfn; j++) {
00325
00326
00327
00328 ps.cat1f = vircam_tfits_load(ps.cat1,j);
00329 ps.cat2f = vircam_tfits_load(ps.cat2,j);
00330 if (ps.cat1f == NULL || ps.cat2f == NULL) {
00331 cpl_msg_warning(fctid,"No matching done");
00332 continue;
00333 }
00334
00335
00336
00337 cpl_msg_info(fctid,"Doing the matching for extension %" CPL_SIZE_FORMAT,
00338 (cpl_size)j);
00339 (void)vircam_matchxy(vircam_tfits_get_table(ps.cat1f),
00340 vircam_tfits_get_table(ps.cat2f),200.0,
00341 &(vircam_matchxy_config.xoff),
00342 &(vircam_matchxy_config.yoff),
00343 &(vircam_matchxy_config.nm),&out,&status);
00344 freetable(out);
00345 if (status != VIR_OK) {
00346 cpl_msg_warning(fctid,"No matching results done");
00347 status = VIR_OK;
00348 }
00349
00350
00351
00352 cpl_msg_info(fctid,"Saving results for extension %" CPL_SIZE_FORMAT,
00353 (cpl_size)j);
00354 if (vircam_matchxy_save() != 0)
00355 cpl_msg_warning(fctid,"No matching results saved");
00356
00357
00358
00359 freetfits(ps.cat1f);
00360 freetfits(ps.cat2f);
00361 }
00362 vircam_matchxy_tidy();
00363 return(0);
00364 }
00365
00366
00371
00372
00373 static int vircam_matchxy_save(void) {
00374 const char *fctid = "vircam_matchxy_save";
00375 const char *outfile = "matchxy";
00376 cpl_propertylist *p,*p2,*p3;
00377
00378
00379
00380 p = vircam_tfits_get_ehu(ps.cat1f);
00381
00382
00383
00384
00385 cpl_propertylist_update_string(p,"DATE-OBS","ABC");
00386
00387
00388
00389 p2 = vircam_paf_req_items(p);
00390 p3 = vircam_paf_phu_items(vircam_tfits_get_phu(ps.cat1f));
00391 vircam_merge_propertylists(p2,p3);
00392 freepropertylist(p3);
00393
00394
00395
00396 cpl_propertylist_update_float(p2,"ESO QC XOFF",vircam_matchxy_config.xoff);
00397 cpl_propertylist_set_comment(p2,"ESO QC XOFF",
00398 "Calculated X offset (pixels)");
00399 cpl_propertylist_update_float(p2,"ESO QC YOFF",vircam_matchxy_config.yoff);
00400 cpl_propertylist_set_comment(p2,"ESO QC YOFF",
00401 "Calculated Y offset (pixels)");
00402 cpl_propertylist_update_int(p2,"ESO QC NUMMATCH",
00403 vircam_matchxy_config.nm);
00404 cpl_propertylist_set_comment(p2,"ESO QC NUMMATCH",
00405 "Number of matching objects");
00406
00407
00408
00409 if (vircam_paf_print((char *)outfile,"VIRCAM/vircam_matchxy",
00410 "Test output file",p2) != VIR_OK) {
00411 cpl_msg_error(fctid,"Unable to write PAF");
00412 cpl_propertylist_delete(p2);
00413 return(-1);
00414 }
00415 cpl_propertylist_delete(p2);
00416 return(0);
00417 }
00418
00419
00420
00421
00425
00426
00427 static void vircam_matchxy_init(void) {
00428 ps.labels = NULL;
00429 ps.cat1 = NULL;
00430 ps.cat2 = NULL;
00431 ps.cat1f = NULL;
00432 ps.cat2f = NULL;
00433 ps.catlist = NULL;
00434 }
00435
00436
00437
00441
00442
00443 static void vircam_matchxy_tidy(void) {
00444 freespace(ps.labels);
00445 freetfits(ps.cat1f);
00446 freetfits(ps.cat2f);
00447 freeframeset(ps.catlist);
00448 }
00449
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503