MIDI Pipeline Reference Manual  2.8.3
midi_wavecal.c
1 /* $Id: midi_wavecal.c,v 1.7 2010-05-28 09:16:01 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: 2010-05-28 09:16:01 $
24  * $Revision: 1.7 $
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 "midi_utils.h"
39 #include "midi_pfits.h"
40 #include "midi_dfs.h"
41 #include "midiControl.h"
42 #include "midiGlobal.h"
43 #include "midiAppendPropertylist.h"
44 
45 /*-----------------------------------------------------------------------------
46  Functions prototypes
47  -----------------------------------------------------------------------------*/
48 
49 static int midi_wavecal_create(cpl_plugin *) ;
50 static int midi_wavecal_exec(cpl_plugin *) ;
51 static int midi_wavecal_destroy(cpl_plugin *) ;
52 static int midi_wavecal(cpl_parameterlist *, cpl_frameset *) ;
53 
54 /*-----------------------------------------------------------------------------
55  Static variables
56  -----------------------------------------------------------------------------*/
57 
58 static char midi_wavecal_description[] =
59 "The purpose of this technical recipe is to facilitate calibration of the\n"
60 "detector channels.\n\n"
61 "Input files:\n\n"
62 " DO category: Type: Explanation: Required:\n"
63 " WAVECAL Raw Raw data frame Y\n\n"
64 "Output files:\n\n"
65 " DO category: Data type: Explanation:\n"
66 " REDUCED_WAVECAL FITS image transmission coefficient\n\n";
67 
68 /*-----------------------------------------------------------------------------
69  Functions code
70  -----------------------------------------------------------------------------*/
71 
72 /*----------------------------------------------------------------------------*/
81 /*----------------------------------------------------------------------------*/
82 int cpl_plugin_get_info(cpl_pluginlist * list)
83 {
84  cpl_recipe * recipe = cpl_calloc(1, sizeof *recipe ) ;
85  cpl_plugin * plugin = &recipe->interface ;
86 
87  cpl_plugin_init(plugin,
88  CPL_PLUGIN_API,
89  MIDI_BINARY_VERSION,
90  CPL_PLUGIN_TYPE_RECIPE,
91  "midi_wavecal",
92  "Produces Wavelength Calibration databases",
93  midi_wavecal_description,
94  "Coorosh Sabet",
95  PACKAGE_BUGREPORT,
97  midi_wavecal_create,
98  midi_wavecal_exec,
99  midi_wavecal_destroy) ;
100 
101  cpl_pluginlist_append(list, plugin) ;
102 
103  return 0;
104 }
105 
106 /*----------------------------------------------------------------------------*/
114 /*----------------------------------------------------------------------------*/
115 static int midi_wavecal_create(cpl_plugin * plugin)
116 {
117  cpl_recipe * recipe ;
118 /* cpl_parameter * p ;*/
119 
120  /* Check that the plugin is part of a valid recipe */
121  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
122  recipe = (cpl_recipe *)plugin ;
123  else return -1 ;
124 
125  /* Create the parameters list in the cpl_recipe object */
126  recipe->parameters = cpl_parameterlist_new() ;
127 
128  /* Fill the parameters list */
129 /*
130  p = cpl_parameter_new_value("midi.midi_wavecal.calibTempDir",
131  CPL_TYPE_STRING, "CalibDB directory", "midi.midi_wavecal",
132  MIDI_CALIBTEMP);
133  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "stropt1") ;
134  cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ;
135  cpl_parameterlist_append(recipe->parameters, p) ;
136 */
137 
138 /* p = cpl_parameter_new_value("midi.midi_wavecal.productDir", */
139 /* CPL_TYPE_STRING, "Product directory", "midi.midi_wavecal", */
140 /* "product path. don't forget ending /"); */
141 /* cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "stropt2") ; */
142 /* cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ; */
143 /* cpl_parameterlist_append(recipe->parameters, p) ; */
144 
145 /*
146  p = cpl_parameter_new_value("midi.midi_wavecal.plotDuration",
147  CPL_TYPE_INT, "Plot duration (-1, 0, .. 5) -1 is the prompt mode", "midi.midi_wavecal", 0);
148  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "intopt2") ;
149  cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ;
150  cpl_parameterlist_append(recipe->parameters, p) ;
151 */
152 
153 
154  /* Return */
155  return 0;
156 }
157 
158 /*----------------------------------------------------------------------------*/
164 /*----------------------------------------------------------------------------*/
165 static int midi_wavecal_exec(cpl_plugin * plugin)
166 {
167  cpl_recipe * recipe ;
168 
169  /* Get the recipe out of the plugin */
170  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
171  recipe = (cpl_recipe *)plugin ;
172  else return -1 ;
173 
174  batchNumber=0;
175  return midi_wavecal(recipe->parameters, recipe->frames) ;
176 }
177 
178 /*----------------------------------------------------------------------------*/
184 /*----------------------------------------------------------------------------*/
185 static int midi_wavecal_destroy(cpl_plugin * plugin)
186 {
187  cpl_recipe * recipe ;
188 
189  /* Get the recipe out of the plugin */
190  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
191  recipe = (cpl_recipe *)plugin ;
192  else return -1 ;
193 
194  cpl_parameterlist_delete(recipe->parameters) ;
195  return 0 ;
196 }
197 
198 /*----------------------------------------------------------------------------*/
205 /*----------------------------------------------------------------------------*/
206 static int midi_wavecal(
207  cpl_parameterlist *parlist,
208  cpl_frameset *frameset)
209 {
210 /*
211  const char *fctid = "midi_wavecal" ;
212  cpl_parameter *param ;
213 */
214  cpl_frame *current_frame;
215 /* char *calibTempDir; // In: Directory path of calib_temp*/
216  int error=0;
217  FILE *sofPtr=NULL;
218 /* char *productDir; // In: Directory path of products */
219  int plotDuration;
220 
221  /* RETRIEVE INPUT PARAMETERS */
222 /*
223  param = cpl_parameterlist_find(parlist, "midi.midi_wavecal.calibTempDir");
224  calibTempDir = (char *) (cpl_parameter_get_string(param));
225  printf ("calibTempDir = %s \n", calibTempDir);
226  if (cpl_error_get_code())
227  {
228  cpl_msg_error(fctid, "Failed to retrieve calibTempDir") ;
229  return -1 ;
230  }
231 */
232 
233 /* param = cpl_parameterlist_find(parlist, "midi.midi_wavecal.productDir"); */
234 /* productDir = (char *) (cpl_parameter_get_string(param)); */
235 /* printf ("productDir = %s \n", productDir); */
236 /* if (cpl_error_get_code()) */
237 /* { */
238 /* cpl_msg_error(fctid, "Failed to retrieve productDir") ; */
239 /* return -1 ; */
240 /* } */
241 
242 /*
243  param = cpl_parameterlist_find(parlist, "midi.midi_wavecal.plotDuration");
244  plotDuration = cpl_parameter_get_int(param);
245  printf ("plotDuration = %d \n", plotDuration);
246  if ((plotDuration < -1) || (plotDuration > 5)) plotDuration = 0;
247 */
248 
249  plotDuration = 0;
250 
251  current_frame = cpl_frameset_get_first(frameset);
252  sofPtr = fopen ("MIDI_sof.log", "w");
253  while ( current_frame && sofPtr )
254  {
255  fprintf (sofPtr, "%s \n", (char *)cpl_frame_get_filename( current_frame ));
256  current_frame = cpl_frameset_get_next( frameset );
257  } /* All frames from frameset */
258  fclose (sofPtr);
259 
260  /* NOW PERFORMING THE DATA REDUCTION */
261  executeDataReduction (MIDI_CALIBTEMP, "", "./", plotDuration, "MIDI_sof.log", &error,parlist,frameset);
262 /* executeDataReduction (calibTempDir, "", productDir, plotDuration, "MIDI_sof.log", &error); */
263  if (error) return -1;
264  remove ("MIDI_sof.log");
265 
266  if (CPL_ERROR_NONE != appendPropertylist("MIDI_b1_wav.pro.fits", CPL_FRAME_TYPE_IMAGE, "REDUCED_WAVECAL",frameset,parlist))
267  {
268  cpl_msg_error(cpl_func,"Error in appendPropertylist");
269  }
270 
271 
272  /* Return */
273  if (cpl_error_get_code())
274  return -1 ;
275  else
276  return 0 ;
277 }
278