MIDI Pipeline Reference Manual  2.8.3
midi_fringe_all.c
1 /* $Id: midi_fringe_all.c,v 1.14 2011-02-10 14:46:35 agabasch Exp $
2  *
3  * This file is part of the MIDI Pipeline
4  * Copyright (C) 2002,2003 European Southern Observatory
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 
21 /*
22  * $Author: agabasch $
23  * $Date: 2011-02-10 14:46:35 $
24  * $Revision: 1.14 $
25  * $Name: not supported by cvs2svn $
26  */
27 
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 
32 /*-----------------------------------------------------------------------------
33  Includes
34  -----------------------------------------------------------------------------*/
35 
36 #include <cpl.h>
37 #include <stdio.h>
38 #include <string.h>
39 #include "midi_utils.h"
40 #include "midi_pfits.h"
41 #include "midi_dfs.h"
42 #include "midiControl.h"
43 #include "midiGlobal.h"
44 #include "midiAppendPropertylist.h"
45 
46 /*-----------------------------------------------------------------------------
47  Functions prototypes
48  -----------------------------------------------------------------------------*/
49 
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 *) ;
54 
55 /*-----------------------------------------------------------------------------
56  Static variables
57  -----------------------------------------------------------------------------*/
58 
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";
64 
65 /*-----------------------------------------------------------------------------
66  Functions code
67  -----------------------------------------------------------------------------*/
68 
69 /*----------------------------------------------------------------------------*/
78 /*----------------------------------------------------------------------------*/
79 int cpl_plugin_get_info(cpl_pluginlist * list)
80 {
81  cpl_recipe * recipe = cpl_calloc(1, sizeof *recipe ) ;
82  cpl_plugin * plugin = &recipe->interface ;
83 
84  cpl_plugin_init(plugin,
85  CPL_PLUGIN_API,
86  MIDI_BINARY_VERSION,
87  CPL_PLUGIN_TYPE_RECIPE,
88  "midi_fringe_all",
89  "Computes Visibilities and Transfer Functions",
90  midi_fringe_all_description,
91  "Armin Gabasch",
92  PACKAGE_BUGREPORT,
94  midi_fringe_all_create,
95  midi_fringe_all_exec,
96  midi_fringe_all_destroy) ;
97 
98  cpl_pluginlist_append(list, plugin) ;
99 
100  return 0;
101 }
102 
103 /*----------------------------------------------------------------------------*/
111 /*----------------------------------------------------------------------------*/
112 static int midi_fringe_all_create(cpl_plugin * plugin)
113 {
114  cpl_recipe * recipe ;
115  cpl_parameter * p ;
116 
117  /* Check that the plugin is part of a valid recipe */
118  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
119  recipe = (cpl_recipe *)plugin ;
120  else return -1 ;
121 
122  /* Create the parameters list in the cpl_recipe object */
123  recipe->parameters = cpl_parameterlist_new() ;
124 
125  /* Fill the parameters list */
126 
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) ;
131 
132 
133 /*
134  p = cpl_parameter_new_value("midi.midi_fringe_all.checkSof", CPL_TYPE_BOOL,
135  "Do homogeneity checks on the SOF","midi.midi_fringe_all", TRUE);
136  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "checkSof") ;
137  cpl_parameterlist_append(recipe->parameters, p) ;
138 */
139 
140  /* Return */
141  return 0;
142 }
143 
144 /*----------------------------------------------------------------------------*/
150 /*----------------------------------------------------------------------------*/
151 static int midi_fringe_all_exec(cpl_plugin * plugin)
152 {
153  cpl_recipe * recipe ;
154 
155  /* Get the recipe out of the plugin */
156  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
157  recipe = (cpl_recipe *)plugin ;
158  else return -1 ;
159 
160  batchNumber=0;
161  return midi_fringe_all(recipe->parameters, recipe->frames) ;
162 }
163 
164 /*----------------------------------------------------------------------------*/
170 /*----------------------------------------------------------------------------*/
171 static int midi_fringe_all_destroy(cpl_plugin * plugin)
172 {
173  cpl_recipe * recipe ;
174 
175  /* Get the recipe out of the plugin */
176  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
177  recipe = (cpl_recipe *)plugin ;
178  else return -1 ;
179 
180  cpl_parameterlist_delete(recipe->parameters) ;
181  return 0 ;
182 }
183 
184 /*----------------------------------------------------------------------------*/
191 /*----------------------------------------------------------------------------*/
192 static int midi_fringe_all(
193  cpl_parameterlist *parlist,
194  cpl_frameset *frameset)
195 {
196 /*
197  const char *fctid = "midi_fringe_all" ;
198  cpl_parameter *param;
199 */
200  cpl_frame *current_frame;
201  int error=0;
202  FILE *sofPtr=NULL;
203  int plotDuration;
204  char * system_call=NULL;
205 
206 
207  /* Identify the RAW and CALIB frames in the input frameset */
208  cpl_ensure_code(midi_dfs_set_groups(frameset) == CPL_ERROR_NONE,
209  cpl_error_get_code());
210 
211 
212 
213 
214  /* RETRIEVE INPUT PARAMETERS */
215 
216  plotDuration = 0;
217 
218  current_frame = cpl_frameset_get_first(frameset);
219  sofPtr = fopen ("MIDI_sof.log", "w");
220  while ( current_frame && sofPtr )
221  {
222  fprintf (sofPtr, "%s \n", (char *)cpl_frame_get_filename( current_frame ));
223  current_frame = cpl_frameset_get_next( frameset );
224  } /* All frames from frameset */
225  fclose (sofPtr);
226  system("sort -o MIDI_sof.log MIDI_sof.log");
227  /* NOW PERFORMING THE DATA REDUCTION */
228  executeDataReduction (MIDI_CALIBTEMP, MIDI_MASKS, "./", plotDuration, "MIDI_sof.log", &error,parlist,frameset);
229 /* executeDataReduction (calibTempDir, maskFileDir, productDir, plotDuration, "MIDI_sof.log", &error); */
230  if (error) return -1;
231  remove ("MIDI_sof.log");
232 
233 
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))
236  {
237  cpl_msg_error(cpl_func,"Error in appendPropertylist_table");
238  }
239  }
240 
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))
243  {
244  cpl_msg_error(cpl_func,"Error in appendPropertylist");
245  }
246  }
247 
248 
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))
251  {
252  cpl_msg_error(cpl_func,"Error in appendPropertylist_table");
253  }
254  }
255 
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))
258  {
259  cpl_msg_error(cpl_func,"Error in appendPropertylist");
260  }
261  }
262 
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))
265  {
266  cpl_msg_error(cpl_func,"Error in appendPropertylist");
267  }
268 
269  }
270 
271 
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))
274  {
275  cpl_msg_error(cpl_func,"Error in appendPropertylist_table");
276  }
277  }
278 
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))
281  {
282  cpl_msg_error(cpl_func,"Error in appendPropertylist");
283  }
284  }
285 
286 
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))
289  {
290  cpl_msg_error(cpl_func,"Error in appendPropertylist_table");
291  }
292  }
293 
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))
296  {
297  cpl_msg_error(cpl_func,"Error in appendPropertylist");
298  }
299  }
300 
301 /* Create a clone of the Product file and append plt files for visualisation */
302 
303 
304  if (strcmp (batchTemplate, "HIGH_SENS_CALIB") == 0){
305 
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);
321 
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);
328 
329 
330  struct plots plotfiles_scans[] =
331  {{"MIDI_b1_hsc.PeakScanChannelaveraged.plt", "Peakflux_Scan"}};
332  int dimen_scans = sizeof(plotfiles_scans)/sizeof(struct plots);
333 
334 
335 
336 
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))
338  {
339  cpl_msg_error(cpl_func,"Error in appending aditional files");
340  }
341 
342 
343  }
344 
345 
346  if (strcmp (batchTemplate, "HIGH_SENS_SCIENCE") == 0){
347 
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);
363 
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);
370 
371  struct plots plotfiles_scans[] =
372  {{"MIDI_b1_hss.PeakScanChannelaveraged.plt", "Peakflux_Scan"}};
373  int dimen_scans = sizeof(plotfiles_scans)/sizeof(struct plots);
374 
375 
376 
377 
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))
379  {
380  cpl_msg_error(cpl_func,"Error in appending aditional files");
381  }
382 
383 
384  }
385 
386 
387 
388 
389  if (strcmp (batchTemplate, "SCI_PHOT_CALIB") == 0){
390 
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);
406 
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);
413 
414 
415  struct plots plotfiles_scans[] =
416  {{"MIDI_b1_spc.PeakScanChannelaveraged.plt", "Peakflux_Scan"}};
417  int dimen_scans = sizeof(plotfiles_scans)/sizeof(struct plots);
418 
419 
420 
421 
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))
423  {
424  cpl_msg_error(cpl_func,"Error in appending aditional files");
425  }
426 
427 
428  }
429 
430  if (strcmp (batchTemplate, "SCI_PHOT_SCIENCE") == 0){
431 
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);
447 
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);
454 
455 
456  struct plots plotfiles_scans[] =
457  {{"MIDI_b1_sps.PeakScanChannelaveraged.plt", "Peakflux_Scan"}};
458  int dimen_scans = sizeof(plotfiles_scans)/sizeof(struct plots);
459 
460 
461 
462 
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))
464  {
465  cpl_msg_error(cpl_func,"Error in appending aditional files");
466  }
467 
468 
469  }
470 
471 
472  /* Be sure to remove a possible transfer function file /tmp/MIDI_trf.fits !! */
473  if (strcmp (batchTemplate, "SCI_PHOT_SCIENCE") == 0 || strcmp (batchTemplate, "HIGH_SENS_SCIENCE") == 0){
474 
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);
480  }
481  }
482 
483 
484  /* Return */
485  if (cpl_error_get_code())
486  return -1 ;
487  else
488  return 0 ;
489 }