MIDI Pipeline Reference Manual  2.8.3
midi_detron.c
1 /* $Id: midi_detron.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_detron_create(cpl_plugin *) ;
50 static int midi_detron_exec(cpl_plugin *) ;
51 static int midi_detron_destroy(cpl_plugin *) ;
52 static int midi_detron(cpl_parameterlist *, cpl_frameset *) ;
53 
54 /*-----------------------------------------------------------------------------
55  Static variables
56  -----------------------------------------------------------------------------*/
57 
58 static char midi_detron_description[] =
59 "The purpose of this technical recipe is to evaluate the read-out noise\n"
60 "of the detector.\n\n"
61 "Input files:\n\n"
62 " DO category: Type: Explanation: Required:\n"
63 " DETRON Raw Raw data frame Y\n\n"
64 "Output files:\n\n"
65 " DO category: Data type: Explanation:\n"
66 " REDUCED_DETRON FITS image detector read-out noise\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_detron",
92  "Evaluates the detectors Readout Noise",
93  midi_detron_description,
94  "Coorosh Sabet",
95  PACKAGE_BUGREPORT,
97  midi_detron_create,
98  midi_detron_exec,
99  midi_detron_destroy) ;
100 
101  cpl_pluginlist_append(list, plugin) ;
102 
103  return 0;
104 }
105 
106 /*----------------------------------------------------------------------------*/
114 /*----------------------------------------------------------------------------*/
115 static int midi_detron_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_detron.productDir", */
131 /* CPL_TYPE_STRING, "Product directory", "midi.midi_detron", */
132 /* "product path. don't forget ending /"); */
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_detron.plotDuration",
139  CPL_TYPE_INT, "Plot duration (-1, 0, .. 5), -1 is the prompt mode", "midi.midi_detron", 0);
140  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "intopt1") ;
141  cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ;
142  cpl_parameterlist_append(recipe->parameters, p) ;
143 */
144 
145 
146  /* Return */
147  return 0;
148 }
149 
150 /*----------------------------------------------------------------------------*/
156 /*----------------------------------------------------------------------------*/
157 static int midi_detron_exec(cpl_plugin * plugin)
158 {
159  cpl_recipe * recipe ;
160 
161  /* Get the recipe out of the plugin */
162  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
163  recipe = (cpl_recipe *)plugin ;
164  else return -1 ;
165 
166  batchNumber=0;
167  return midi_detron(recipe->parameters, recipe->frames) ;
168 }
169 
170 /*----------------------------------------------------------------------------*/
176 /*----------------------------------------------------------------------------*/
177 static int midi_detron_destroy(cpl_plugin * plugin)
178 {
179  cpl_recipe * recipe ;
180 
181  /* Get the recipe out of the plugin */
182  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
183  recipe = (cpl_recipe *)plugin ;
184  else return -1 ;
185 
186  cpl_parameterlist_delete(recipe->parameters) ;
187  return 0 ;
188 }
189 
190 /*----------------------------------------------------------------------------*/
197 /*----------------------------------------------------------------------------*/
198 static int midi_detron(
199  cpl_parameterlist *parlist,
200  cpl_frameset *frameset)
201 {
202 /* const char *fctid = "midi_detron" ; */
203 /* cpl_parameter *param ;*/
204  cpl_frame *current_frame;
205  int error=0;
206  FILE *sofPtr=NULL;
207 /* char *productDir; // In: Directory path of products */
208  int plotDuration;
209 
210  /* RETRIEVE INPUT PARAMETERS */
211 
212 /* param = cpl_parameterlist_find(parlist, "midi.midi_detron.productDir"); */
213 /* productDir = (char *) (cpl_parameter_get_string(param)); */
214 /* printf ("productDir = %s \n", productDir); */
215 /* if (cpl_error_get_code()) */
216 /* { */
217 /* cpl_msg_error(fctid, "Failed to retrieve productDir") ; */
218 /* return -1 ; */
219 /* } */
220 
221 /*
222  param = cpl_parameterlist_find(parlist, "midi.midi_detron.plotDuration");
223  plotDuration = cpl_parameter_get_int(param);
224  printf ("plotDuration = %d \n", plotDuration);
225  if ((plotDuration < -1) || (plotDuration > 5)) plotDuration = 0;
226 */
227 
228  plotDuration = 0;
229  current_frame = cpl_frameset_get_first(frameset);
230  sofPtr = fopen ("MIDI_sof.log", "w");
231  while ( current_frame && sofPtr )
232  {
233  fprintf (sofPtr, "%s \n", (char *)cpl_frame_get_filename( current_frame ));
234  current_frame = cpl_frameset_get_next( frameset );
235  } /* All frames from frameset */
236  fclose (sofPtr);
237 
238  /* NOW PERFORMING THE DATA REDUCTION */
239  executeDataReduction ("", "", "./", plotDuration, "MIDI_sof.log", &error,parlist,frameset);
240 /* executeDataReduction ("", "", productDir, plotDuration, "MIDI_sof.log", &error); */
241  if (error) return -1;
242  remove ("MIDI_sof.log");
243 
244 
245  if (CPL_ERROR_NONE != appendPropertylist("MIDI_b1_ron.pro.fits", CPL_FRAME_TYPE_IMAGE, "REDUCED_DETRON",frameset,parlist))
246  {
247  cpl_msg_error(cpl_func,"Error in appendPropertylist");
248  }
249 
250 
251  /* Return */
252  if (cpl_error_get_code())
253  return -1 ;
254  else
255  return 0 ;
256 }
257