40 #include "gravi_utils.h"
41 #include "gravi_pfits.h"
42 #include "gravi_dfs.h"
43 #include "gravi_calib.h"
44 #include "gravi_vis.h"
45 #include "gravi_data.h"
54 static int gravi_single_create(cpl_plugin *);
55 static int gravi_single_exec(cpl_plugin *);
56 static int gravi_single_destroy(cpl_plugin *);
57 static int gravi_single(cpl_frameset *,
const cpl_parameterlist *);
63 static char gravi_single_description[] =
64 "This recipe is associated to the observing template in single field mode.\n"
65 "Its aim is to reduce the raw interferometric data acquired on calibrator or \n"
66 "science targets and to compute the intrumental visibility.\n"
67 "The output OIFITS file contains the values of the complex visibilities, \n"
68 "squared visibilities and the closure phases.\n"
69 "Description DO category\n"
71 " Master dark " DARK
"\n"
72 " Master flat " FLAT
"\n"
73 " Bad pixel map " BAD
"\n"
74 " Master wave " WAVE
"\n"
75 " Master p2vm " P2VM
"\n"
76 " Raw observation file " GRAVI_SINGLE_CALIB
" or "
77 GRAVI_SINGLE_SCIENCE
"\n"
79 " Sky file (one or more) " SINGLE_SCI_SKY_RAW
" or "
80 SINGLE_CAL_SKY_RAW
"\n"
83 " Master sky (one per input sky) " SKY
"\n"
84 " Raw Visibilities " VIS_SINGLE_CALIB
" or " VIS_SINGLE_SCIENCE
"\n"
86 " Preprocessed files (--preproc-file) " PREPROC
"\n"
87 " Non averaged visibilities (--p2vmreduced-file) " P2VMREDUCED
"\n"
105 int cpl_plugin_get_info(cpl_pluginlist * list)
107 cpl_recipe * recipe = cpl_calloc(1,
sizeof *recipe );
108 cpl_plugin * plugin = &recipe->interface;
110 if (cpl_plugin_init(plugin,
112 GRAVI_BINARY_VERSION,
113 CPL_PLUGIN_TYPE_RECIPE,
115 "This recipe is used to compute the squared visibility",
116 gravi_single_description,
117 "Firstname Lastname",
122 gravi_single_destroy)) {
123 cpl_msg_error(cpl_func,
"Plugin initialization failed");
124 (void)cpl_error_set_where(cpl_func);
128 if (cpl_pluginlist_append(list, plugin)) {
129 cpl_msg_error(cpl_func,
"Error adding plugin to list");
130 (void)cpl_error_set_where(cpl_func);
146 static int gravi_single_create(cpl_plugin * plugin)
152 if (cpl_error_get_code() != CPL_ERROR_NONE) {
153 cpl_msg_error(cpl_func,
"%s():%d: An error is already set: %s",
154 cpl_func, __LINE__, cpl_error_get_where());
155 return (
int)cpl_error_get_code();
158 if (plugin == NULL) {
159 cpl_msg_error(cpl_func,
"Null plugin");
160 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
164 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
165 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
166 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
170 recipe = (cpl_recipe *)plugin;
173 recipe->parameters = cpl_parameterlist_new();
174 if (recipe->parameters == NULL) {
175 cpl_msg_error(cpl_func,
"Parameter list allocation failed");
176 cpl_ensure_code(0, (
int)CPL_ERROR_ILLEGAL_OUTPUT);
182 p = cpl_parameter_new_value(
"gravi.preproc_param.preproc_file",
183 CPL_TYPE_BOOL,
"Save the preprocessed file",
"gravi.preproc_param", FALSE);
184 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"preproc-file");
185 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
186 cpl_parameterlist_append(recipe->parameters, p);
189 p = cpl_parameter_new_value(
"gravi.preproc_param.p2vmreduced_file",
190 CPL_TYPE_BOOL,
"Save the file with non averaged visibilities",
"gravi.preproc_param", FALSE);
191 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"p2vmreduced-file");
192 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
193 cpl_parameterlist_append(recipe->parameters, p);
196 p = cpl_parameter_new_value(
"gravi.vis_reduce.vis_correction",
197 CPL_TYPE_BOOL,
"Correction of visibilities looses",
"gravi.vis_reduce", FALSE);
198 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"vis-correction");
199 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
200 cpl_parameterlist_append(recipe->parameters, p);
203 p = cpl_parameter_new_value(
"gravi.snr_threshold_ft",
204 CPL_TYPE_DOUBLE,
"SNR threshold for fringe detection in FT (>0)",
"gravi.vis_reduce", 3.0);
205 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"snr-threshold-ft");
206 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
207 cpl_parameterlist_append(recipe->parameters, p);
210 p = cpl_parameter_new_value(
"gravi.fringedet_threshold_sc",
211 CPL_TYPE_DOUBLE,
"Fringe-detection ratio threshold to accept SC frame (0..1)",
"gravi.vis_reduce", 0.8);
212 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"fringedet-threshold-sc");
213 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
214 cpl_parameterlist_append(recipe->parameters, p);
217 p = cpl_parameter_new_value(
"gravi.debias_sc",
218 CPL_TYPE_BOOL,
"Subtrast the V2 bias from SC",
"gravi", TRUE);
219 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"debias-sc");
220 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
221 cpl_parameterlist_append(recipe->parameters, p);
224 p = cpl_parameter_new_value(
"gravi.debias_ft",
225 CPL_TYPE_BOOL,
"Subtrast the V2 bias from FT",
"gravi", TRUE);
226 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"debias-ft");
227 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
228 cpl_parameterlist_append(recipe->parameters, p);
231 p = cpl_parameter_new_value(
"gravi.use_met",
232 CPL_TYPE_BOOL,
"Use the metrology to rephase the SC data in real-time",
"gravi", FALSE);
233 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"use-met");
234 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
235 cpl_parameterlist_append(recipe->parameters, p);
238 p = cpl_parameter_new_value(
"gravi.vis_flat",
239 CPL_TYPE_BOOL,
"Flat the OIVIS by the VIS_FLAT file",
"gravi", TRUE);
240 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"vis-flat");
241 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
242 cpl_parameterlist_append(recipe->parameters, p);
254 static int gravi_single_exec(cpl_plugin * plugin)
259 cpl_errorstate initial_errorstate = cpl_errorstate_get();
262 if (cpl_error_get_code() != CPL_ERROR_NONE) {
263 cpl_msg_error(cpl_func,
"%s():%d: An error is already set: %s",
264 cpl_func, __LINE__, cpl_error_get_where());
265 return (
int)cpl_error_get_code();
268 if (plugin == NULL) {
269 cpl_msg_error(cpl_func,
"Null plugin");
270 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
274 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
275 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
276 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
280 recipe = (cpl_recipe *)plugin;
283 if (recipe->parameters == NULL) {
284 cpl_msg_error(cpl_func,
"Recipe invoked with NULL parameter list");
285 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
287 if (recipe->frames == NULL) {
288 cpl_msg_error(cpl_func,
"Recipe invoked with NULL frame set");
289 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
293 recipe_status = gravi_single(recipe->frames, recipe->parameters);
297 if (cpl_dfs_update_product_header(recipe->frames)) {
299 recipe_status = (int)cpl_error_get_code();
303 if (!cpl_errorstate_is_equal(initial_errorstate)) {
306 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
309 return recipe_status;
319 static int gravi_single_destroy(cpl_plugin * plugin)
323 if (plugin == NULL) {
324 cpl_msg_error(cpl_func,
"Null plugin");
325 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
329 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
330 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
331 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
335 recipe = (cpl_recipe *)plugin;
337 cpl_parameterlist_delete(recipe->parameters);
352 static int gravi_single(cpl_frameset * frameset,
353 const cpl_parameterlist * parlist)
355 cpl_frameset * recipe_frameset=NULL, * wave_frameset=NULL, * dark_frameset=NULL,
356 * darkcalib_frameset=NULL, * skyframeset=NULL,
357 * gain_frameset=NULL, * p2vm_frameset=NULL, * badpix_frameset=NULL, *used_frameset=NULL,
358 * visflat_frameset=NULL;
359 cpl_propertylist * applist=NULL, * primary_hdr=NULL, * primary_hdr_dark=NULL, * wave_plist=NULL, *bad_primary_hdr=NULL;
360 cpl_table * detector_table=NULL;
361 cpl_frame * frame=NULL;
362 const cpl_parameter * p=NULL, * p_=NULL;
363 cpl_parameter * par=NULL;
364 char * out_dark=NULL, * preproc_name=NULL;
365 const char * frame_tag=NULL, * filename=NULL, * temp=NULL;
366 gravi_data * p2vm_map=NULL, * data=NULL, * darkOrSky_map=NULL, * wave_map=NULL, * dark_map=NULL,
367 * profile_map=NULL, * badpix_map=NULL, * vis_flat=NULL;
368 gravi_data ** calib_datas=NULL;
369 gravi_data * preproc_data=NULL;
370 gravi_data ** raw_data=NULL, * p2vm_reduce=NULL;
371 gravi_data * oi_vis=NULL;
372 darkOrSky_map = NULL, wave_map = NULL;
373 int nb_frame, i, j, nwave_ft, nwave_sc, n_region;
377 char * vis_name=NULL;
380 cpl_msg_set_time_on();
381 cpl_msg_set_component_on();
382 cpl_msg_info(cpl_func,
"Start function -- cleanup");
389 cpl_ensure_code(gravi_dfs_set_groups(frameset) == CPL_ERROR_NONE,
390 cpl_error_get_code()) ;
392 p2vm_frameset = gravi_frameset_extract_p2vm_file(frameset);
395 recipe_frameset = gravi_frameset_extract_single_data(frameset);
396 darkcalib_frameset = gravi_frameset_extract_dark_file(frameset);
397 wave_frameset = gravi_frameset_extract_wave_file(frameset);
398 dark_frameset = gravi_frameset_extract_dark(frameset);
399 gain_frameset = gravi_frameset_extract_flat_file(frameset);
400 badpix_frameset = gravi_frameset_extract_badpix(frameset);
401 skyframeset = gravi_frameset_extract_single_sky_data (frameset);
402 visflat_frameset = gravi_frameset_extract_visflat(frameset);
407 if (cpl_frameset_is_empty(recipe_frameset)) {
408 cpl_error_set_message(cpl_func, CPL_ERROR_INVALID_TYPE,
409 "No SINGLE frame on the frameset");
415 if ((cpl_frameset_is_empty(p2vm_frameset)) ||
416 (cpl_frameset_is_empty(wave_frameset)) ||
417 (cpl_frameset_is_empty(gain_frameset))) {
418 cpl_error_set_message(cpl_func, CPL_ERROR_INVALID_TYPE,
419 "No P2VM or FLAT or WAVE file on the frameset") ;
424 nb_frame = cpl_frameset_get_size(recipe_frameset);
430 if (!cpl_frameset_is_empty(dark_frameset)) {
432 frame = cpl_frameset_get_position(dark_frameset, 0);
433 filename = cpl_frame_get_filename(frame);
435 cpl_msg_info (cpl_func,
"File %s is a raw DARK file", FILESHORT(filename));
436 data = gravi_data_load(filename);
439 primary_hdr = gravi_data_get_propertylist(data, GRAVI_PRIMARY_HDR_NAME_EXT);
440 shutter = gravi_shutters_check(primary_hdr);
441 if (!((shutter[0] == 0) && (shutter[1] == 0) &&
442 (shutter[2] == 0) && (shutter[3] == 0))){
443 cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_OUTPUT,
"Shutter problem in the DARK");
448 dark_map = gravi_compute_dark(data);
450 CPLCHECK_CLEAN(
"Could not compute the DARK map");
453 primary_hdr_dark = gravi_data_get_propertylist(dark_map,
454 GRAVI_PRIMARY_HDR_NAME_EXT);
455 applist = gravi_propertylist_get_qc (primary_hdr_dark);
456 cpl_propertylist_append_string(applist, CPL_DFS_PRO_CATG, DARK);
459 out_dark = gravi_data_product_name (filename,
"dark");
461 gravi_data_save(dark_map, frameset, out_dark, parlist,
462 dark_frameset, frame,
"gravi_single", applist);
464 CPLCHECK_CLEAN(
"Could not save the DARK map");
466 FREE (cpl_propertylist_delete,applist);
467 FREE (gravi_data_delete,data);
468 FREE (cpl_free,shutter);
472 else if (!cpl_frameset_is_empty(darkcalib_frameset)) {
474 frame = cpl_frameset_get_position(darkcalib_frameset, 0);
475 filename = cpl_frame_get_filename(frame);
477 cpl_msg_info (cpl_func,
"File %s is a master DARK file already computed", FILESHORT(filename));
478 dark_map = gravi_data_load(filename);
479 cpl_frameset_insert (dark_frameset, cpl_frame_duplicate (frame));
484 cpl_msg_info (cpl_func,
"There is no DARK in the frame set");
490 if (!cpl_frameset_is_empty(skyframeset)) {
493 frame = cpl_frameset_get_position(skyframeset, 0);
494 filename = cpl_frame_get_filename(frame);
496 cpl_msg_info (cpl_func,
"File %s is a raw SKY file", FILESHORT(filename));
498 data = gravi_data_load(filename);
499 primary_hdr = gravi_data_get_propertylist(data, GRAVI_PRIMARY_HDR_NAME_EXT);
502 darkOrSky_map = gravi_compute_dark(data);
503 FREE (gravi_data_delete,data);
505 CPLCHECK_CLEAN(
"Error while computing the darkOrSky_map");
508 cpl_frameset_insert (dark_frameset, cpl_frame_duplicate (frame));
510 primary_hdr_dark = gravi_data_get_propertylist(darkOrSky_map,
511 GRAVI_PRIMARY_HDR_NAME_EXT);
513 applist = gravi_propertylist_get_qc (primary_hdr_dark);
515 cpl_propertylist_append_string(applist, CPL_DFS_PRO_CATG, SKY);
518 out_dark = gravi_data_product_name (filename,
"sky");
520 gravi_data_save(darkOrSky_map, frameset, out_dark, parlist,
521 skyframeset, frame,
"gravi_single", applist);
523 CPLCHECK_CLEAN(
"Could not save the darkOrSky_map");
525 FREE (cpl_propertylist_delete,applist);
526 FREE (cpl_free,out_dark);
528 else if (testDarkSky) {
529 darkOrSky_map = dark_map;
532 cpl_msg_info (cpl_func,
"There is no sky in the frame set");
535 cpl_error_set_message(cpl_func, CPL_ERROR_INVALID_TYPE,
"No dark or sky frames in the frameset");
539 FREE (cpl_frameset_delete,skyframeset);
545 if (!cpl_frameset_is_empty(badpix_frameset)){
548 frame = cpl_frameset_get_position(badpix_frameset, 0);
549 filename = cpl_frame_get_filename(frame);
551 cpl_msg_info (cpl_func,
"File %s is a BAD pixel map", FILESHORT(filename));
552 badpix_map = gravi_data_load(filename);
556 badpix_map = gravi_compute_badpix(darkOrSky_map, parlist);
558 CPLCHECK_CLEAN(
"Could not compute the BAD pixel map");
561 bad_primary_hdr = gravi_data_get_propertylist (badpix_map, GRAVI_PRIMARY_HDR_NAME_EXT);
562 applist = gravi_propertylist_get_qc (bad_primary_hdr);
564 cpl_propertylist_append_string(applist, CPL_DFS_PRO_CATG, BAD);
566 frame = cpl_frameset_get_position (dark_frameset, 0);
568 gravi_data_save (badpix_map, frameset,
"gravi_bad_map.fits", parlist,
569 dark_frameset, frame,
"gravi_single", applist);
571 CPLCHECK_CLEAN(
"Could not save the BAD pixel map");
573 FREE (cpl_propertylist_delete, applist);
580 frame = cpl_frameset_get_position(gain_frameset, 0);
581 filename = cpl_frame_get_filename(frame);
583 cpl_msg_info (cpl_func,
"File %s is a master FLAT already computed", FILESHORT(filename));
584 profile_map = gravi_data_load(filename);
590 frame = cpl_frameset_get_position(wave_frameset, 0);
591 filename = cpl_frame_get_filename(frame);
593 cpl_msg_info (cpl_func,
"File %s is a master WAVE map already computed", FILESHORT(filename));
594 wave_map = gravi_data_load(filename);
597 if ((wave_map == NULL) || (profile_map == NULL)) {
598 cpl_error_set_message(cpl_func, CPL_ERROR_INVALID_TYPE,
"No WAVE or FLAT frames in the frameset");
606 frame = cpl_frameset_get_position(p2vm_frameset, 0);
607 filename = cpl_frame_get_filename(frame);
609 cpl_msg_info (cpl_func,
"File %s is a P2VM file already computed", FILESHORT(filename));
610 p2vm_map = gravi_data_load (filename);
612 CPLCHECK_CLEAN(
"Error while loading the P2VM map");
617 if (!cpl_frameset_is_empty(visflat_frameset))
619 frame = cpl_frameset_get_position(visflat_frameset, 0);
620 filename = cpl_frame_get_filename(frame);
621 cpl_msg_info (cpl_func,
"File %s is a VIS_FLAT already computed", FILESHORT(filename));
622 vis_flat = gravi_data_load(filename);
630 detector_table = gravi_data_get_table (p2vm_map, GRAVI_IMAGING_DETECTOR_FT_EXT);
631 n_region = cpl_table_get_nrow(detector_table);
633 wave_plist = gravi_data_get_oi_propertylist
634 (p2vm_map, GRAVI_OI_WAVE_SWITCH(GRAVI_TYPE_SC),
635 GRAVI_SPECTRO_SWITCH(GRAVI_TYPE_SC,0,2));
636 nwave_sc = gravi_pfits_get_nwave (wave_plist);
637 wave_plist = gravi_data_get_oi_propertylist (p2vm_map,
638 GRAVI_OI_WAVE_SWITCH(GRAVI_TYPE_FT),
639 GRAVI_SPECTRO_SWITCH(GRAVI_TYPE_FT,0,2));
640 nwave_ft = gravi_pfits_get_nwave (wave_plist);
643 wave_plist = gravi_data_get_oi_propertylist
644 (p2vm_map, GRAVI_OI_WAVE_SWITCH(GRAVI_TYPE_SC), GRAVI_SPECTRO_SWITCH(GRAVI_TYPE_SC,0,1));
645 nwave_sc = gravi_pfits_get_nwave (wave_plist);
646 wave_plist = gravi_data_get_oi_propertylist (p2vm_map,
647 GRAVI_OI_WAVE_SWITCH(GRAVI_TYPE_FT), GRAVI_SPECTRO_SWITCH(GRAVI_TYPE_FT,0,1));
648 nwave_ft = gravi_pfits_get_nwave (wave_plist);
651 primary_hdr = gravi_data_get_propertylist (wave_map, GRAVI_PRIMARY_HDR_NAME_EXT);
653 CPLCHECK_CLEAN(
"Missed one the preproc parameters");
662 calib_datas = cpl_malloc(nb_calfile *
sizeof(gravi_data *));
664 calib_datas[0] = darkOrSky_map;
665 calib_datas[1] = wave_map;
666 calib_datas[2] = profile_map;
667 calib_datas[3] = badpix_map;
669 calib_datas[4] = dark_map;
672 used_frameset=cpl_frameset_new();
673 cpl_frameset_join(used_frameset, cpl_frameset_duplicate(dark_frameset));
674 cpl_frameset_join(used_frameset, cpl_frameset_duplicate(badpix_frameset));
675 cpl_frameset_join(used_frameset, cpl_frameset_duplicate(wave_frameset));
676 cpl_frameset_join(used_frameset, cpl_frameset_duplicate(gain_frameset));
677 cpl_frameset_join(used_frameset, cpl_frameset_duplicate(p2vm_frameset));
679 p = cpl_parameterlist_find_const(parlist,
"gravi.preproc_param.preproc_file");
681 p_ = cpl_parameterlist_find_const(parlist,
"gravi.preproc_param.p2vmreduced_file");
687 oi_vis = gravi_data_new(0);
688 primary_hdr = gravi_data_get_propertylist (p2vm_map,
689 GRAVI_PRIMARY_HDR_NAME_EXT);
691 const char * resol_p2vm = gravi_pfits_get_resolution (primary_hdr);
692 const char * resol_file;
700 for (thread = 0; thread < nb_frame; thread++){
702 frame = cpl_frameset_get_position (recipe_frameset, thread);
703 frame_tag = cpl_frame_get_tag (frame);
704 filename = cpl_frame_get_filename (frame);
706 data = gravi_data_load(filename);
707 primary_hdr = gravi_data_get_propertylist (data,
708 GRAVI_PRIMARY_HDR_NAME_EXT);
712 shutter = gravi_shutters_check(primary_hdr);
713 resol_file = gravi_pfits_get_resolution (primary_hdr);
716 if ((shutter [0] != 1) || (shutter [1] != 1) ||
717 (shutter [2] != 1) || (shutter [3] != 1)) {
718 cpl_msg_warning( cpl_func,
"RAW data shutters: %d-%d-%d-%d",
719 shutter[0], shutter[1], shutter[2], shutter[3] );
722 cpl_msg_info (cpl_func,
"Preprocessing of the single"
723 " field file %s", FILESHORT(filename));
725 preproc_data = gravi_preproc(data, calib_datas, nb_calfile, p2vm_map, parlist);
727 FREE (gravi_data_delete,data);
728 FREE (cpl_free,shutter);
730 CPLCHECK_CLEAN(
"Cannot preproc the data");
733 if (cpl_parameter_get_bool(p)){
735 preproc_name = gravi_data_product_name (filename,
"preproc");
736 cpl_frameset * preproc_frame = cpl_frameset_new ();
737 cpl_frameset_insert (preproc_frame, cpl_frame_duplicate (frame));
738 cpl_frameset_join(preproc_frame, cpl_frameset_duplicate(used_frameset));
740 applist = gravi_propertylist_get_qc (gravi_data_get_propertylist
741 (preproc_data, GRAVI_PRIMARY_HDR_NAME_EXT));
743 cpl_propertylist_append_string(applist, CPL_DFS_PRO_CATG, PREPROC);
745 gravi_data_save(preproc_data, frameset, preproc_name, parlist,
746 preproc_frame, frame,
"gravi_single", applist);
748 CPLCHECK_CLEAN(
"Cannot save the PREPROC product");
750 FREE (cpl_free,preproc_name);
751 FREE (cpl_propertylist_delete,applist);
752 FREE (cpl_frameset_delete,preproc_frame);
757 cpl_msg_info (cpl_func,
"Application of the p2vm to file %s", FILESHORT(filename));
758 p2vm_reduce = gravi_p2vm_reduce (preproc_data, p2vm_map,
"gravi_single", parlist);
759 FREE (gravi_data_delete,preproc_data);
761 CPLCHECK_CLEAN(
"Cannot apply p2vm to the preproc data");
766 gravi_compute_tau0 (p2vm_reduce);
770 cpl_msg_info (cpl_func,
"Computing the average visibilities of file %s", FILESHORT(filename));
771 gravi_vis_reduce (oi_vis, p2vm_reduce, nb_vis, parlist,
"gravi_single");
773 CPLCHECK_CLEAN(
"Cannot average the visibilities");
777 cpl_msg_info( cpl_func,
"Compute the QC TF parameters" );
778 cpl_errorstate prestate = cpl_errorstate_get();
780 gravi_data * oi_tf = gravi_compute_tf( oi_vis );
782 cpl_propertylist_copy_property_regexp( gravi_data_get_propertylist (oi_vis, GRAVI_PRIMARY_HDR_NAME_EXT),
783 gravi_data_get_propertylist (oi_tf, GRAVI_PRIMARY_HDR_NAME_EXT),
785 FREE (gravi_data_delete,oi_tf);
788 if( cpl_error_get_code() ) {
789 cpl_msg_warning(cpl_func,
"Cannot compute the QC TF parameters for this observation");
790 cpl_errorstate_dump (prestate, 0, NULL);
795 if (cpl_parameter_get_bool(p_)){
796 cpl_msg_info( cpl_func,
"Save the p2vmreduced file" );
799 char * p2vm_name = gravi_data_product_name (filename,
"p2vmreduced");
801 cpl_frameset * p2vmreduced_frame = cpl_frameset_new ();
802 cpl_frameset_insert (p2vmreduced_frame, cpl_frame_duplicate (frame));
803 cpl_frameset_join(p2vmreduced_frame, cpl_frameset_duplicate(used_frameset));
804 applist = gravi_propertylist_get_qc (gravi_data_get_propertylist
805 (p2vm_reduce, GRAVI_PRIMARY_HDR_NAME_EXT));
807 if ((strcmp(frame_tag, SINGLE_CAL_SKY_RAW) == 0) ||
808 (strcmp(frame_tag, SINGLE_SCI_SKY_RAW) == 0))
809 cpl_propertylist_append_string(applist, CPL_DFS_PRO_CATG, SKYREDUCED);
811 cpl_propertylist_append_string(applist, CPL_DFS_PRO_CATG, P2VMREDUCED);
813 gravi_data_save(p2vm_reduce, frameset, p2vm_name, parlist,
814 p2vmreduced_frame, frame,
"gravi_single", applist);
816 CPLCHECK_CLEAN(
"Cannot save the P2VMREDUCED product");
818 FREE (cpl_free,p2vm_name);
819 FREE (cpl_propertylist_delete,applist);
820 FREE (cpl_frameset_delete,p2vmreduced_frame);
824 cpl_msg_info(cpl_func,
"Free the p2vmreduced");
825 FREE (gravi_data_delete,p2vm_reduce);
831 if (gravi_param_get_bool(parlist,
"gravi.vis_flat")) {
834 cpl_msg_info (cpl_func,
"Perform the visibility flat with the provided VIS_FLAT file");
835 gravi_flat_vis (oi_vis, vis_flat);
836 CPLCHECK_CLEAN(
"Cannot flat the OI_VIS");
840 cpl_msg_warning (cpl_func,
"vis-flat option requested but no VIS_FLAT in the frameset");
847 frame = cpl_frameset_get_position (recipe_frameset, 0);
848 frame_tag = cpl_frame_get_tag (frame);
849 primary_hdr = gravi_data_get_propertylist(oi_vis,
850 GRAVI_PRIMARY_HDR_NAME_EXT);
851 applist = gravi_propertylist_get_qc (primary_hdr);
853 cpl_propertylist_append_int(applist, GRAVI_NIGHT_OBS,
854 cpl_propertylist_get_int (primary_hdr, GRAVI_NIGHT_OBS));
855 cpl_propertylist_append_string(applist,
"DATE-OBS",
856 cpl_propertylist_get_string (primary_hdr,
"DATE-OBS"));
859 if ((strcmp(frame_tag, GRAVI_SINGLE_CALIB) == 0)) {
860 vis_name = gravi_data_product_name (filename,
"singlecal");
861 cpl_propertylist_append_string(applist, CPL_DFS_PRO_CATG, VIS_SINGLE_CALIB);
863 else if ((strcmp(frame_tag, GRAVI_SINGLE_SCIENCE) == 0)) {
864 vis_name = gravi_data_product_name (filename,
"singlesci");
865 cpl_propertylist_append_string(applist, CPL_DFS_PRO_CATG, VIS_SINGLE_SCIENCE);
868 vis_name = gravi_data_product_name (filename,
"singlesci");
869 cpl_propertylist_append_string(applist, CPL_DFS_PRO_CATG, VIS_SINGLE_SCIENCE);
872 cpl_frameset_join (recipe_frameset, cpl_frameset_duplicate (used_frameset));
874 gravi_data_save(oi_vis, frameset, vis_name, parlist,
875 recipe_frameset, frame,
"gravi_single", applist);
877 CPLCHECK_CLEAN(
"Cannot save the VIS product");
885 cpl_msg_info(cpl_func,
"Memory cleanup");
887 FREE (gravi_data_delete,dark_map);
888 FREE (gravi_data_delete,data);
889 FREE (cpl_free,shutter);
890 FREE (cpl_free,preproc_name);
891 FREE (gravi_data_delete,preproc_data);
892 FREE (gravi_data_delete,profile_map);
893 FREE (gravi_data_delete,darkOrSky_map);
894 FREE (gravi_data_delete,wave_map);
895 FREE (gravi_data_delete,badpix_map);
896 FREE (gravi_data_delete,p2vm_map);
897 FREE (gravi_data_delete,vis_flat);
898 FREE (cpl_frameset_delete,darkcalib_frameset);
899 FREE (cpl_frameset_delete,wave_frameset);
900 FREE (cpl_frameset_delete,dark_frameset);
901 FREE (cpl_frameset_delete,gain_frameset);
902 FREE (cpl_frameset_delete,badpix_frameset);
903 FREE (gravi_data_delete,p2vm_reduce);
904 FREE (cpl_free,calib_datas);
905 FREE (cpl_free,vis_name);
906 FREE (cpl_propertylist_delete,applist);
907 FREE (gravi_data_delete,oi_vis);
908 FREE (cpl_frameset_delete,p2vm_frameset);
909 FREE (cpl_frameset_delete,visflat_frameset);
910 FREE (cpl_frameset_delete,recipe_frameset);
911 FREE (cpl_frameset_delete,used_frameset);
913 cpl_msg_info(cpl_func,
"Exit function");
914 return (
int)cpl_error_get_code();