37 #include <casu_utils.h>
38 #include <casu_mods.h>
40 #include "vircam_utils.h"
41 #include "vircam_dfs.h"
42 #include "vircam_mods.h"
43 #include "vircam_pfits.h"
47 static int vircam_lincor_create(cpl_plugin *) ;
48 static int vircam_lincor_exec(cpl_plugin *) ;
49 static int vircam_lincor_destroy(cpl_plugin *) ;
50 static int vircam_lincor_test(cpl_parameterlist *, cpl_frameset *) ;
51 static int vircam_lincor_save(cpl_frameset *framelist,
52 cpl_parameterlist *parlist);
53 static void vircam_lincor_init(
void);
54 static void vircam_lincor_tidy(
void);
62 } vircam_lincor_config;
73 static cpl_frame *product_frame = NULL;
75 static char vircam_lincor_description[] =
76 "vircam_lincor -- VIRCAM linearity correction test recipe.\n\n"
77 "Linearity correct an input frame using a pre-existing channel table\n\n"
78 "The program accepts the following files in the SOF:\n\n"
80 " -----------------------------------------------------------------------\n"
81 " %-21s A input uncorrected image\n"
82 " %-21s A channel table\n"
143 int cpl_plugin_get_info(cpl_pluginlist *list) {
144 cpl_recipe *recipe = cpl_calloc(1,
sizeof(*recipe));
145 cpl_plugin *plugin = &recipe->interface;
146 char alldesc[SZ_ALLDESC];
147 (void)snprintf(alldesc,SZ_ALLDESC,vircam_lincor_description,
148 VIRCAM_TEST_SCIENCE_RAW,VIRCAM_CAL_CHANTAB);
150 cpl_plugin_init(plugin,
152 VIRCAM_BINARY_VERSION,
153 CPL_PLUGIN_TYPE_RECIPE,
155 "VIRCAM linearisation test recipe [test]",
160 vircam_lincor_create,
162 vircam_lincor_destroy);
164 cpl_pluginlist_append(list,plugin);
180 static int vircam_lincor_create(cpl_plugin *plugin) {
186 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
187 recipe = (cpl_recipe *)plugin;
193 recipe->parameters = cpl_parameterlist_new();
197 p = cpl_parameter_new_range(
"vircam.vircam_lincor.extenum",
199 "Extension number to be done, 0 == all",
200 "vircam.vircam_lincor",1,0,16);
201 cpl_parameter_set_alias(p,CPL_PARAMETER_MODE_CLI,
"ext");
202 cpl_parameterlist_append(recipe->parameters,p);
217 static int vircam_lincor_exec(cpl_plugin *plugin) {
222 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
223 recipe = (cpl_recipe *)plugin;
227 return(vircam_lincor_test(recipe->parameters,recipe->frames));
239 static int vircam_lincor_destroy(cpl_plugin *plugin) {
244 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
245 recipe = (cpl_recipe *)plugin;
249 cpl_parameterlist_delete(recipe->parameters);
262 static int vircam_lincor_test(cpl_parameterlist *parlist,
263 cpl_frameset *framelist) {
264 const char *fctid=
"vircam_lincor";
266 int jst,jfn,status,j,ndit;
268 cpl_propertylist *pp;
272 if (framelist == NULL || cpl_frameset_get_size(framelist) <= 0) {
273 cpl_msg_error(fctid,
"Input framelist NULL or has no input data");
279 vircam_lincor_init();
283 p = cpl_parameterlist_find(parlist,
"vircam.vircam_lincor.extenum");
284 vircam_lincor_config.extenum = cpl_parameter_get_int(p);
289 cpl_msg_error(fctid,
"Cannot identify RAW and CALIB frames");
290 vircam_lincor_tidy();
298 cpl_msg_error(fctid,
"Cannot labelise the input frames");
299 vircam_lincor_tidy();
303 VIRCAM_CAL_CHANTAB)) == NULL) {
304 cpl_msg_info(fctid,
"No channel table found -- cannot continue");
305 vircam_lincor_tidy();
309 VIRCAM_TEST_SCIENCE_RAW)) == NULL) {
310 cpl_msg_info(fctid,
"No raw image found -- cannot continue");
311 vircam_lincor_tidy();
317 pp = cpl_propertylist_load(cpl_frame_get_filename(ps.img),0);
319 cpl_msg_error(fctid,
"No value for NDIT available");
320 freepropertylist(pp);
321 vircam_lincor_tidy();
324 cpl_propertylist_delete(pp);
332 if (jst == -1 || jfn == -1) {
333 cpl_msg_error(fctid,
"Unable to continue");
334 vircam_lincor_tidy();
341 for (j = jst; j <= jfn; j++) {
342 isfirst = (j == jst);
348 if (ps.img == NULL || ps.chanf == NULL) {
349 vircam_lincor_tidy();
355 cpl_msg_info(fctid,
"Doing the linearisation for extension %" CPL_SIZE_FORMAT,
358 if (status != CASU_OK) {
359 vircam_lincor_tidy();
365 cpl_msg_info(fctid,
"Saving results for extension %" CPL_SIZE_FORMAT,
367 if (vircam_lincor_save(framelist,parlist) != 0) {
368 vircam_lincor_tidy();
377 vircam_lincor_tidy();
391 static int vircam_lincor_save(cpl_frameset *framelist,
392 cpl_parameterlist *parlist) {
393 const char *recipeid =
"vircam_lincor";
394 const char *fctid =
"vircam_lincor_save";
395 const char *outfile =
"lincor.fits";
396 cpl_propertylist *plist;
405 product_frame = cpl_frame_new();
406 cpl_frame_set_filename(product_frame,outfile);
407 cpl_frame_set_tag(product_frame,VIRCAM_PRO_SIMPLE_TEST);
408 cpl_frame_set_type(product_frame,CPL_FRAME_TYPE_IMAGE);
409 cpl_frame_set_group(product_frame,CPL_FRAME_GROUP_PRODUCT);
410 cpl_frame_set_level(product_frame,CPL_FRAME_LEVEL_FINAL);
416 parlist,(
char *)recipeid,
417 "?Dictionary?",NULL,0);
421 if (cpl_image_save(NULL,outfile,CPL_TYPE_UCHAR,plist,
422 CPL_IO_DEFAULT) != CPL_ERROR_NONE) {
423 cpl_msg_error(fctid,
"Cannot save product PHU");
424 cpl_frame_delete(product_frame);
427 cpl_frameset_insert(framelist,product_frame);
437 (
char *)recipeid,
"?Dictionary?",NULL);
442 plist,CPL_IO_EXTEND) != CPL_ERROR_NONE) {
443 cpl_msg_error(fctid,
"Cannot save product image extension");
457 static void vircam_lincor_init(
void) {
472 static void vircam_lincor_tidy(
void) {
473 freespace(ps.labels);
cpl_image * casu_fits_get_image(casu_fits *p)
casu_fits * casu_fits_load(cpl_frame *frame, cpl_type type, int nexten)
cpl_propertylist * casu_fits_get_phu(casu_fits *p)
cpl_propertylist * casu_fits_get_ehu(casu_fits *p)
casu_tfits * casu_tfits_load(cpl_frame *table, int nexten)
cpl_frame * casu_frameset_subgroup_1(cpl_frameset *frameset, cpl_size *labels, cpl_size nlab, const char *tag)
Extract a frame of a given label from a frameset.
int casu_compare_tags(const cpl_frame *frame1, const cpl_frame *frame2)
Compare input tags.
int vircam_lincor(casu_fits *infile, casu_tfits *lchantab, int kconst, int ndit, int *status)
Apply linearity curves to data.
int vircam_dfs_set_groups(cpl_frameset *set)
void vircam_dfs_set_product_primary_header(cpl_propertylist *plist, cpl_frame *frame, cpl_frameset *frameset, cpl_parameterlist *parlist, char *recipeid, const char *dict, cpl_frame *inherit, int synch)
void vircam_dfs_set_product_exten_header(cpl_propertylist *plist, cpl_frame *frame, cpl_frameset *frameset, cpl_parameterlist *parlist, char *recipeid, const char *dict, cpl_frame *inherit)
int vircam_pfits_get_ndit(const cpl_propertylist *plist, int *ndit)
Get the value of NDIT.
const char * vircam_get_license(void)
void vircam_exten_range(int inexten, const cpl_frame *fr, int *out1, int *out2)