MIDI Pipeline Reference Manual  2.8.3
midi_dsptrn.c
1 /* $Id: midi_dsptrn.c,v 1.6 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.6 $
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_dsptrn_create(cpl_plugin *) ;
50 static int midi_dsptrn_exec(cpl_plugin *) ;
51 static int midi_dsptrn_destroy(cpl_plugin *) ;
52 static int midi_dsptrn(cpl_parameterlist *, cpl_frameset *) ;
53 
54 /*-----------------------------------------------------------------------------
55  Static variables
56  -----------------------------------------------------------------------------*/
57 
58 static char midi_dsptrn_description[] =
59 "The purpose of this technical template is to measure the transmission\n"
60 "characteristics of the dispersive elements (Prism and Grism) in order\n"
61 "to monitor the evolution of their coatings.\n\n"
62 "Input files:\n\n"
63 " DO category: Type: Explanation: Required:\n"
64 " DSPTRN Raw Raw data frame Y\n\n"
65 "Output files:\n\n"
66 " DO category: Data type: Explanation:\n"
67 " REDUCED_DSPTRN FITS image transmission coefficient\n\n";
68 
69 /*-----------------------------------------------------------------------------
70  Functions code
71  -----------------------------------------------------------------------------*/
72 
73 /*----------------------------------------------------------------------------*/
82 /*----------------------------------------------------------------------------*/
83 int cpl_plugin_get_info(cpl_pluginlist * list)
84 {
85  cpl_recipe * recipe = cpl_calloc(1, sizeof *recipe ) ;
86  cpl_plugin * plugin = &recipe->interface ;
87 
88  cpl_plugin_init(plugin,
89  CPL_PLUGIN_API,
90  MIDI_BINARY_VERSION,
91  CPL_PLUGIN_TYPE_RECIPE,
92  "midi_dsptrn",
93  "Evaluates the dispersive characteristics of the Grism/Prism",
94  midi_dsptrn_description,
95  "Armin Gabasch",
96  PACKAGE_BUGREPORT,
98  midi_dsptrn_create,
99  midi_dsptrn_exec,
100  midi_dsptrn_destroy) ;
101 
102  cpl_pluginlist_append(list, plugin) ;
103 
104  return 0;
105 }
106 
107 /*----------------------------------------------------------------------------*/
115 /*----------------------------------------------------------------------------*/
116 static int midi_dsptrn_create(cpl_plugin * plugin)
117 {
118  cpl_recipe * recipe ;
119 /* cpl_parameter * p ;*/
120 
121  /* Check that the plugin is part of a valid recipe */
122  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
123  recipe = (cpl_recipe *)plugin ;
124  else return -1 ;
125 
126  /* Create the parameters list in the cpl_recipe object */
127  recipe->parameters = cpl_parameterlist_new() ;
128 
129  /* Fill the parameters list */
130 
131 /* p = cpl_parameter_new_value("midi.midi_dsptrn.productDir", */
132 /* CPL_TYPE_STRING, "Product directory", "midi.midi_dsptrn", */
133 /* "product path. don't forget ending /"); */
134 /* cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "stropt1") ; */
135 /* cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ; */
136 /* cpl_parameterlist_append(recipe->parameters, p) ; */
137 
138 /*
139  p = cpl_parameter_new_value("midi.midi_dsptrn.plotDuration",
140  CPL_TYPE_INT, "Plot duration (-1, 0, .. 5), -1 is the prompt mode", "midi.midi_dsptrn", 0);
141  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "intopt1") ;
142  cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ;
143  cpl_parameterlist_append(recipe->parameters, p) ;
144 */
145 
146 
147  /* Return */
148  return 0;
149 }
150 
151 /*----------------------------------------------------------------------------*/
157 /*----------------------------------------------------------------------------*/
158 static int midi_dsptrn_exec(cpl_plugin * plugin)
159 {
160 
161  cpl_recipe * recipe ;
162 
163  /* Get the recipe out of the plugin */
164  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
165  recipe = (cpl_recipe *)plugin ;
166  else return -1 ;
167 
168  batchNumber=0;
169  return midi_dsptrn(recipe->parameters, recipe->frames) ;
170 
171 }
172 
173 /*----------------------------------------------------------------------------*/
179 /*----------------------------------------------------------------------------*/
180 static int midi_dsptrn_destroy(cpl_plugin * plugin)
181 {
182  cpl_recipe * recipe ;
183 
184  /* Get the recipe out of the plugin */
185  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
186  recipe = (cpl_recipe *)plugin ;
187  else return -1 ;
188 
189  cpl_parameterlist_delete(recipe->parameters) ;
190  return 0 ;
191 }
192 
193 /*----------------------------------------------------------------------------*/
200 /*----------------------------------------------------------------------------*/
201 static int midi_dsptrn(
202  cpl_parameterlist *parlist,
203  cpl_frameset *frameset)
204 {
205 /* const char *fctid = "midi_dsptrn" ; */
206 /* cpl_parameter *param ;*/
207  cpl_frame *current_frame;
208  int error=0;
209  FILE *sofPtr=NULL;
210 /* char *productDir; // In: Directory path of products */
211  int plotDuration;
212 
213 
214  /* RETRIEVE INPUT PARAMETERS */
215 
216 /* param = cpl_parameterlist_find(parlist, "midi.midi_dsptrn.productDir"); */
217 /* productDir = (char *) (cpl_parameter_get_string(param)); */
218 /* printf ("productDir = %s \n", productDir); */
219 /* if (cpl_error_get_code()) */
220 /* { */
221 /* cpl_msg_error(fctid, "Failed to retrieve productDir") ; */
222 /* return -1 ; */
223 /* } */
224 
225 /*
226  param = cpl_parameterlist_find(parlist, "midi.midi_dsptrn.plotDuration");
227  plotDuration = cpl_parameter_get_int(param);
228  printf ("plotDuration = %d \n", plotDuration);
229  if ((plotDuration < -1) || (plotDuration > 5)) plotDuration = 0;
230 */
231 
232  plotDuration = 0;
233 
234  current_frame = cpl_frameset_get_first(frameset);
235  sofPtr = fopen ("MIDI_sof.log", "w");
236  while ( current_frame && sofPtr )
237  {
238  fprintf (sofPtr, "%s \n", (char *)cpl_frame_get_filename( current_frame ));
239  current_frame = cpl_frameset_get_next( frameset );
240  } /* All frames from frameset */
241  fclose (sofPtr);
242 
243  /* NOW PERFORMING THE DATA REDUCTION */
244  executeDataReduction ("", "", "./", plotDuration, "MIDI_sof.log", &error,parlist,frameset);
245 // executeDataReduction ("", "", productDir, plotDuration, "MIDI_sof.log", &error);
246 
247  if (error) return -1;
248  remove ("MIDI_sof.log");
249 
250 
251  if (CPL_ERROR_NONE != appendPropertylist("MIDI_b1_trn.pro.fits", CPL_FRAME_TYPE_IMAGE, "REDUCED_DSPTRN",frameset,parlist))
252  {
253  cpl_msg_error(cpl_func,"Error in appendPropertylist");
254  }
255 
256 
257 
258 
259 /* /\* ##################### *\/ */
260 /* { */
261 /* cpl_image * pImage = NULL; */
262 /* cpl_frame * pFrameProduct = NULL; */
263 /* cpl_propertylist * pHeader = NULL; */
264 
265 
266 /* const char *szProduct="MIDI_b1_trn.pro.fits"; */
267 /* const char *szRawFile="MIDI_b1_trn.pro.fits"; */
268 
269 
270 /* pImage = cpl_image_load(szRawFile, CPL_TYPE_FLOAT, 0, 0 ); */
271 
272 
273 /* pHeader = cpl_propertylist_new(); /\* ???????? *\/ */
274 /* pHeader = cpl_propertylist_load(szRawFile, 0 ); */
275 
276 
277 
278 
279 /* pFrameProduct = cpl_frame_new(); */
280 /* cpl_frame_set_filename( pFrameProduct, szProduct ); */
281 /* cpl_frame_set_type ( pFrameProduct, CPL_FRAME_TYPE_IMAGE ); */
282 /* cpl_frame_set_tag ( pFrameProduct, "REDUCED_DSPTRN" ); */
283 /* cpl_frame_set_group ( pFrameProduct, CPL_FRAME_GROUP_PRODUCT ); */
284 /* cpl_frame_set_level ( pFrameProduct, CPL_FRAME_LEVEL_FINAL ); */
285 
286 
287 /* if (CPL_ERROR_NONE != cpl_image_save(pImage, szProduct, CPL_BPP_DEFAULT, pHeader, CPL_IO_DEFAULT )) */
288 /* { */
289 /* cpl_msg_error(cpl_func,"Saving error"); */
290 /* } */
291 
292 
293 /* if (CPL_ERROR_NONE != cpl_frameset_insert( frameset, pFrameProduct )) */
294 /* { */
295 /* cpl_msg_error(cpl_func,"Error in cpl_frameset_insert"); */
296 /* } */
297 
298 /* cpl_image_delete( pImage ); */
299 /* cpl_propertylist_delete(pHeader ); */
300 
301 /* cpl_msg_info(cpl_func,"batchNumber_: %d",batchNumber); */
302 
303 /* } */
304 
305 
306 
307 /* /\* ##################### *\/ */
308 
309 
310  /* Return */
311  if (cpl_error_get_code())
312  return -1 ;
313  else
314  return 0 ;
315 }
316