39 #include "midi_utils.h"
40 #include "midi_pfits.h"
42 #include "midiControl.h"
43 #include "midiGlobal.h"
44 #include "midiAppendPropertylist.h"
50 static int midi_fringe_all_create(cpl_plugin *) ;
51 static int midi_fringe_all_exec(cpl_plugin *) ;
52 static int midi_fringe_all_destroy(cpl_plugin *) ;
53 static int midi_fringe_all(cpl_parameterlist *, cpl_frameset *) ;
59 static char midi_fringe_all_description[] =
60 "This recipe is able to compute Uncalibrated Visibilities, Transfer Functions\n"
61 "and Calibrated Visibilities for HIGH_SENS and SCI_PHOT input data.\n"
62 "As the input frames and the output products of this recipe are manifold, the\n"
63 "user should refer to the pipeline manual for a detailed description \n\n";
81 cpl_recipe * recipe = cpl_calloc(1,
sizeof *recipe ) ;
82 cpl_plugin * plugin = &recipe->interface ;
84 cpl_plugin_init(plugin,
87 CPL_PLUGIN_TYPE_RECIPE,
89 "Computes Visibilities and Transfer Functions",
90 midi_fringe_all_description,
94 midi_fringe_all_create,
96 midi_fringe_all_destroy) ;
98 cpl_pluginlist_append(list, plugin) ;
112 static int midi_fringe_all_create(cpl_plugin * plugin)
114 cpl_recipe * recipe ;
118 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
119 recipe = (cpl_recipe *)plugin ;
123 recipe->parameters = cpl_parameterlist_new() ;
127 p = cpl_parameter_new_value(
"midi.midi_fringe_all.checkSof",
128 CPL_TYPE_BOOL,
"Do homogeneity checks on the SOF ",
"midi.midi_fringe_all", TRUE) ;
129 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"checkSof") ;
130 cpl_parameterlist_append(recipe->parameters, p) ;
151 static int midi_fringe_all_exec(cpl_plugin * plugin)
153 cpl_recipe * recipe ;
156 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
157 recipe = (cpl_recipe *)plugin ;
161 return midi_fringe_all(recipe->parameters, recipe->frames) ;
171 static int midi_fringe_all_destroy(cpl_plugin * plugin)
173 cpl_recipe * recipe ;
176 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
177 recipe = (cpl_recipe *)plugin ;
180 cpl_parameterlist_delete(recipe->parameters) ;
192 static int midi_fringe_all(
193 cpl_parameterlist *parlist,
194 cpl_frameset *frameset)
200 cpl_frame *current_frame;
204 char * system_call=NULL;
209 cpl_error_get_code());
218 current_frame = cpl_frameset_get_first(frameset);
219 sofPtr = fopen (
"MIDI_sof.log",
"w");
220 while ( current_frame && sofPtr )
222 fprintf (sofPtr,
"%s \n", (
char *)cpl_frame_get_filename( current_frame ));
223 current_frame = cpl_frameset_get_next( frameset );
226 system(
"sort -o MIDI_sof.log MIDI_sof.log");
228 executeDataReduction (MIDI_CALIBTEMP, MIDI_MASKS,
"./", plotDuration,
"MIDI_sof.log", &error,parlist,frameset);
230 if (error)
return -1;
231 remove (
"MIDI_sof.log");
234 if (strcmp (batchTemplate,
"SCI_PHOT_CALIB") == 0){
235 if (CPL_ERROR_NONE != appendPropertylist_table(
"MIDI_b1_spc.pro.fits", CPL_FRAME_TYPE_TABLE,
"REDUCED_DISPERSED_SCIPHOT",frameset,parlist))
237 cpl_msg_error(cpl_func,
"Error in appendPropertylist_table");
241 if (strcmp (batchTemplate,
"SCI_PHOT_CALIB") == 0){
242 if (CPL_ERROR_NONE != appendPropertylist(
"MIDI_b1_spc.waf.fits", CPL_FRAME_TYPE_IMAGE,
"WATERFALL",frameset,parlist))
244 cpl_msg_error(cpl_func,
"Error in appendPropertylist");
249 if (strcmp (batchTemplate,
"SCI_PHOT_SCIENCE") == 0){
250 if (CPL_ERROR_NONE != appendPropertylist_table(
"MIDI_b1_sps.pro.fits", CPL_FRAME_TYPE_TABLE,
"REDUCED_DISPERSED_SCIPHOT",frameset,parlist))
252 cpl_msg_error(cpl_func,
"Error in appendPropertylist_table");
256 if (strcmp (batchTemplate,
"SCI_PHOT_SCIENCE") == 0){
257 if (CPL_ERROR_NONE != appendPropertylist(
"MIDI_b1_sps.waf.fits", CPL_FRAME_TYPE_IMAGE,
"WATERFALL",frameset,parlist))
259 cpl_msg_error(cpl_func,
"Error in appendPropertylist");
263 if (strcmp (batchTemplate,
"SCI_PHOT_KAPPA") == 0){
264 if (CPL_ERROR_NONE != appendPropertylist(
"MIDI_b1_spk.pro.fits", CPL_FRAME_TYPE_IMAGE,
"KAPPA_MATRIX",frameset,parlist))
266 cpl_msg_error(cpl_func,
"Error in appendPropertylist");
272 if (strcmp (batchTemplate,
"HIGH_SENS_CALIB") == 0){
273 if (CPL_ERROR_NONE != appendPropertylist_table(
"MIDI_b1_hsc.pro.fits", CPL_FRAME_TYPE_TABLE,
"REDUCED_DISPERSED",frameset,parlist))
275 cpl_msg_error(cpl_func,
"Error in appendPropertylist_table");
279 if (strcmp (batchTemplate,
"HIGH_SENS_CALIB") == 0){
280 if (CPL_ERROR_NONE != appendPropertylist(
"MIDI_b1_hsc.waf.fits", CPL_FRAME_TYPE_IMAGE,
"WATERFALL",frameset,parlist))
282 cpl_msg_error(cpl_func,
"Error in appendPropertylist");
287 if (strcmp (batchTemplate,
"HIGH_SENS_SCIENCE") == 0){
288 if (CPL_ERROR_NONE != appendPropertylist_table(
"MIDI_b1_hss.pro.fits", CPL_FRAME_TYPE_TABLE,
"REDUCED_DISPERSED",frameset,parlist))
290 cpl_msg_error(cpl_func,
"Error in appendPropertylist_table");
294 if (strcmp (batchTemplate,
"HIGH_SENS_SCIENCE") == 0){
295 if (CPL_ERROR_NONE != appendPropertylist(
"MIDI_b1_hss.waf.fits", CPL_FRAME_TYPE_IMAGE,
"WATERFALL",frameset,parlist))
297 cpl_msg_error(cpl_func,
"Error in appendPropertylist");
304 if (strcmp (batchTemplate,
"HIGH_SENS_CALIB") == 0){
306 struct plots plotfiles_lambda[] =
307 {{
"MIDI_b1_hsc.WaveCalibCombined.plt",
"Lambda"},
308 {
"MIDI_b1_hsc.NormalizedUncalibVisCombined.plt",
"Visibility"},
309 {
"MIDI_b1_hsc.NormalizedUncalibVisErrCombined.plt",
"VisibilityErr"},
310 {
"MIDI_b1_hsc.PhotomADATA1.plt",
"PhotomADATA1"},
311 {
"MIDI_b1_hsc.PhotomAErrDATA1.plt",
"PhotomAErrDATA1"},
312 {
"MIDI_b1_hsc.PhotomADATA2.plt",
"PhotomADATA2"},
313 {
"MIDI_b1_hsc.PhotomAErrDATA2.plt",
"PhotomAErrDATA2"},
314 {
"MIDI_b1_hsc.PhotomBDATA1.plt",
"PhotomBDATA1"},
315 {
"MIDI_b1_hsc.PhotomBErrDATA1.plt",
"PhotomBErrDATA1"},
316 {
"MIDI_b1_hsc.PhotomBDATA2.plt",
"PhotomBDATA2"},
317 {
"MIDI_b1_hsc.PhotomBErrDATA2.plt",
"PhotomBErrDATA2"},
318 {
"MIDI_b1_hsc.MeanInterfCleanDATA1.plt",
"MeanInterfDATA1"},
319 {
"MIDI_b1_hsc.MeanInterfCleanDATA2.plt",
"MeanInterfDATA2"}};
320 int dimen_lambda =
sizeof(plotfiles_lambda)/
sizeof(
struct plots);
322 struct plots plotfiles_frames[] =
323 {{
"MIDI_b1_hsc.PhotomACleanDATA1.plt",
"PhotomA_DATA1"},
324 {
"MIDI_b1_hsc.PhotomACleanDATA2.plt",
"PhotomA_DATA2"},
325 {
"MIDI_b1_hsc.PhotomBCleanDATA1.plt",
"PhotomB_DATA1"},
326 {
"MIDI_b1_hsc.PhotomBCleanDATA2.plt",
"PhotomB_DATA2"}};
327 int dimen_frames =
sizeof(plotfiles_frames)/
sizeof(
struct plots);
330 struct plots plotfiles_scans[] =
331 {{
"MIDI_b1_hsc.PeakScanChannelaveraged.plt",
"Peakflux_Scan"}};
332 int dimen_scans =
sizeof(plotfiles_scans)/
sizeof(
struct plots);
337 if (CPL_ERROR_NONE != appendPropertylist_statistics(
"MIDI_b1_hsc.pro.fits",
"MIDI_b1_hsc.stat.fits",CPL_FRAME_TYPE_TABLE,
"REDUCED_STAT_HS",frameset,parlist,plotfiles_lambda,plotfiles_frames,plotfiles_scans,dimen_lambda,dimen_frames,dimen_scans))
339 cpl_msg_error(cpl_func,
"Error in appending aditional files");
346 if (strcmp (batchTemplate,
"HIGH_SENS_SCIENCE") == 0){
348 struct plots plotfiles_lambda[] =
349 {{
"MIDI_b1_hss.WaveCalibCombined.plt",
"Lambda"},
350 {
"MIDI_b1_hss.NormalizedUncalibVisCombined.plt",
"Visibility"},
351 {
"MIDI_b1_hss.NormalizedUncalibVisErrCombined.plt",
"VisibilityErr"},
352 {
"MIDI_b1_hss.PhotomADATA1.plt",
"PhotomADATA1"},
353 {
"MIDI_b1_hss.PhotomAErrDATA1.plt",
"PhotomAErrDATA1"},
354 {
"MIDI_b1_hss.PhotomADATA2.plt",
"PhotomADATA2"},
355 {
"MIDI_b1_hss.PhotomAErrDATA2.plt",
"PhotomAErrDATA2"},
356 {
"MIDI_b1_hss.PhotomBDATA1.plt",
"PhotomBDATA1"},
357 {
"MIDI_b1_hss.PhotomBErrDATA1.plt",
"PhotomBErrDATA1"},
358 {
"MIDI_b1_hss.PhotomBDATA2.plt",
"PhotomBDATA2"},
359 {
"MIDI_b1_hss.PhotomBErrDATA2.plt",
"PhotomBErrDATA2"},
360 {
"MIDI_b1_hss.MeanInterfCleanDATA1.plt",
"MeanInterfDATA1"},
361 {
"MIDI_b1_hss.MeanInterfCleanDATA2.plt",
"MeanInterfDATA2"}};
362 int dimen_lambda =
sizeof(plotfiles_lambda)/
sizeof(
struct plots);
364 struct plots plotfiles_frames[] =
365 {{
"MIDI_b1_hss.PhotomACleanDATA1.plt",
"PhotomA_DATA1"},
366 {
"MIDI_b1_hss.PhotomACleanDATA2.plt",
"PhotomA_DATA2"},
367 {
"MIDI_b1_hss.PhotomBCleanDATA1.plt",
"PhotomB_DATA1"},
368 {
"MIDI_b1_hss.PhotomBCleanDATA2.plt",
"PhotomB_DATA2"}};
369 int dimen_frames =
sizeof(plotfiles_frames)/
sizeof(
struct plots);
371 struct plots plotfiles_scans[] =
372 {{
"MIDI_b1_hss.PeakScanChannelaveraged.plt",
"Peakflux_Scan"}};
373 int dimen_scans =
sizeof(plotfiles_scans)/
sizeof(
struct plots);
378 if (CPL_ERROR_NONE != appendPropertylist_statistics(
"MIDI_b1_hss.pro.fits",
"MIDI_b1_hss.stat.fits",CPL_FRAME_TYPE_TABLE,
"REDUCED_STAT_HS",frameset,parlist,plotfiles_lambda,plotfiles_frames,plotfiles_scans,dimen_lambda,dimen_frames,dimen_scans))
380 cpl_msg_error(cpl_func,
"Error in appending aditional files");
389 if (strcmp (batchTemplate,
"SCI_PHOT_CALIB") == 0){
391 struct plots plotfiles_lambda[] =
392 {{
"MIDI_b1_spc.WaveCalibCombined.plt",
"Lambda"},
393 {
"MIDI_b1_spc.NormalizedUncalibVisCombined.plt",
"Visibility"},
394 {
"MIDI_b1_spc.NormalizedUncalibVisErrCombined.plt",
"VisibilityErr"},
395 {
"MIDI_b1_spc.PhotomADATA1.plt",
"PhotomADATA1"},
396 {
"MIDI_b1_spc.PhotomAErrDATA1.plt",
"PhotomAErrDATA1"},
397 {
"MIDI_b1_spc.PhotomIDATA2.plt",
"PhotomIDATA2"},
398 {
"MIDI_b1_spc.PhotomIErrDATA2.plt",
"PhotomIErrDATA2"},
399 {
"MIDI_b1_spc.PhotomIDATA3.plt",
"PhotomIDATA3"},
400 {
"MIDI_b1_spc.PhotomIErrDATA3.plt",
"PhotomIErrDATA3"},
401 {
"MIDI_b1_spc.PhotomBDATA4.plt",
"PhotomBDATA4"},
402 {
"MIDI_b1_spc.PhotomBErrDATA4.plt",
"PhotomBErrDATA4"},
403 {
"MIDI_b1_spc.MeanInterfCleanDATA1.plt",
"MeanInterfDATA1"},
404 {
"MIDI_b1_spc.MeanInterfCleanDATA2.plt",
"MeanInterfDATA2"}};
405 int dimen_lambda =
sizeof(plotfiles_lambda)/
sizeof(
struct plots);
407 struct plots plotfiles_frames[] =
408 {{
"MIDI_b1_spc.PhotomACleanDATA1.plt",
"PhotomA_DATA1"},
409 {
"MIDI_b1_spc.InterfCleanDATA2.plt",
"PhotomI_DATA2"},
410 {
"MIDI_b1_spc.InterfCleanDATA3.plt",
"PhotomI_DATA3"},
411 {
"MIDI_b1_spc.PhotomBCleanDATA4.plt",
"PhotomB_DATA4"}};
412 int dimen_frames =
sizeof(plotfiles_frames)/
sizeof(
struct plots);
415 struct plots plotfiles_scans[] =
416 {{
"MIDI_b1_spc.PeakScanChannelaveraged.plt",
"Peakflux_Scan"}};
417 int dimen_scans =
sizeof(plotfiles_scans)/
sizeof(
struct plots);
422 if (CPL_ERROR_NONE != appendPropertylist_statistics(
"MIDI_b1_spc.pro.fits",
"MIDI_b1_spc.stat.fits",CPL_FRAME_TYPE_TABLE,
"REDUCED_STAT_SP",frameset,parlist,plotfiles_lambda,plotfiles_frames,plotfiles_scans,dimen_lambda,dimen_frames,dimen_scans))
424 cpl_msg_error(cpl_func,
"Error in appending aditional files");
430 if (strcmp (batchTemplate,
"SCI_PHOT_SCIENCE") == 0){
432 struct plots plotfiles_lambda[] =
433 {{
"MIDI_b1_sps.WaveCalibCombined.plt",
"Lambda"},
434 {
"MIDI_b1_sps.NormalizedUncalibVisCombined.plt",
"Visibility"},
435 {
"MIDI_b1_sps.NormalizedUncalibVisErrCombined.plt",
"VisibilityErr"},
436 {
"MIDI_b1_sps.PhotomADATA1.plt",
"PhotomADATA1"},
437 {
"MIDI_b1_sps.PhotomAErrDATA1.plt",
"PhotomAErrDATA1"},
438 {
"MIDI_b1_sps.PhotomIDATA2.plt",
"PhotomIDATA2"},
439 {
"MIDI_b1_sps.PhotomIErrDATA2.plt",
"PhotomIErrDATA2"},
440 {
"MIDI_b1_sps.PhotomIDATA3.plt",
"PhotomIDATA3"},
441 {
"MIDI_b1_sps.PhotomIErrDATA3.plt",
"PhotomIErrDATA3"},
442 {
"MIDI_b1_sps.PhotomBDATA4.plt",
"PhotomBDATA4"},
443 {
"MIDI_b1_sps.PhotomBErrDATA4.plt",
"PhotomBErrDATA4"},
444 {
"MIDI_b1_sps.MeanInterfCleanDATA1.plt",
"MeanInterfDATA1"},
445 {
"MIDI_b1_sps.MeanInterfCleanDATA2.plt",
"MeanInterfDATA2"}};
446 int dimen_lambda =
sizeof(plotfiles_lambda)/
sizeof(
struct plots);
448 struct plots plotfiles_frames[] =
449 {{
"MIDI_b1_sps.PhotomACleanDATA1.plt",
"PhotomA_DATA1"},
450 {
"MIDI_b1_sps.InterfCleanDATA2.plt",
"PhotomI_DATA2"},
451 {
"MIDI_b1_sps.InterfCleanDATA3.plt",
"PhotomI_DATA3"},
452 {
"MIDI_b1_sps.PhotomBCleanDATA4.plt",
"PhotomB_DATA4"}};
453 int dimen_frames =
sizeof(plotfiles_frames)/
sizeof(
struct plots);
456 struct plots plotfiles_scans[] =
457 {{
"MIDI_b1_sps.PeakScanChannelaveraged.plt",
"Peakflux_Scan"}};
458 int dimen_scans =
sizeof(plotfiles_scans)/
sizeof(
struct plots);
463 if (CPL_ERROR_NONE != appendPropertylist_statistics(
"MIDI_b1_sps.pro.fits",
"MIDI_b1_sps.stat.fits",CPL_FRAME_TYPE_TABLE,
"REDUCED_STAT_SP",frameset,parlist,plotfiles_lambda,plotfiles_frames,plotfiles_scans,dimen_lambda,dimen_frames,dimen_scans))
465 cpl_msg_error(cpl_func,
"Error in appending aditional files");
473 if (strcmp (batchTemplate,
"SCI_PHOT_SCIENCE") == 0 || strcmp (batchTemplate,
"HIGH_SENS_SCIENCE") == 0){
475 system_call=cpl_sprintf(
"rm -f /tmp/MIDI_trf.fits");
476 if (system(system_call)==0){
477 cpl_msg_info(cpl_func,
"Removing possible transfer function file /tmp/MIDI_trf.fits");
478 cpl_msg_info(cpl_func,system_call);
479 cpl_free(system_call);
485 if (cpl_error_get_code())