MIDI Pipeline Reference Manual  2.8.3
midi_detlin.c
1 /* $Id: midi_detlin.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 /*-----------------------------------------------------------------------------
47  Functions prototypes
48  -----------------------------------------------------------------------------*/
49 
50 static int midi_detlin_create(cpl_plugin *) ;
51 static int midi_detlin_exec(cpl_plugin *) ;
52 static int midi_detlin_destroy(cpl_plugin *) ;
53 static int midi_detlin(cpl_parameterlist *, cpl_frameset *) ;
54 
55 /*-----------------------------------------------------------------------------
56  Static variables
57  -----------------------------------------------------------------------------*/
58 
59 static char midi_detlin_description[] =
60 "The purpose of this technical template is to evaluate the linearity of the\n"
61 "detector, i.e. the relationship between the detector counts and the number\n"
62 "of photons.\n\n"
63 "Input files:\n\n"
64 " DO category: Type: Explanation: Required:\n"
65 " DETLIN Raw Raw data frame Y\n\n"
66 "Output files:\n\n"
67 " DO category: Data type: Explanation:\n"
68 " REDUCED_DETLIN FITS image linearity coefficient in the header\n"
69 "\n";
70 
71 /*-----------------------------------------------------------------------------
72  Functions code
73  -----------------------------------------------------------------------------*/
74 
75 /*----------------------------------------------------------------------------*/
84 /*----------------------------------------------------------------------------*/
85 int cpl_plugin_get_info(cpl_pluginlist * list)
86 {
87  cpl_recipe * recipe = cpl_calloc(1, sizeof *recipe ) ;
88  cpl_plugin * plugin = &recipe->interface ;
89 
90  cpl_plugin_init(plugin,
91  CPL_PLUGIN_API,
92  MIDI_BINARY_VERSION,
93  CPL_PLUGIN_TYPE_RECIPE,
94  "midi_detlin",
95  "Evaluates the detector linearity",
96  midi_detlin_description,
97  "Coorosh Sabet",
98  PACKAGE_BUGREPORT,
100  midi_detlin_create,
101  midi_detlin_exec,
102  midi_detlin_destroy) ;
103 
104  cpl_pluginlist_append(list, plugin) ;
105 
106  return 0;
107 }
108 
109 /*----------------------------------------------------------------------------*/
117 /*----------------------------------------------------------------------------*/
118 static int midi_detlin_create(cpl_plugin * plugin)
119 {
120  cpl_recipe * recipe ;
121 /* cpl_parameter * p ;*/
122 
123  /* Check that the plugin is part of a valid recipe */
124  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
125  recipe = (cpl_recipe *)plugin ;
126  else return -1 ;
127 
128  /* Create the parameters list in the cpl_recipe object */
129  recipe->parameters = cpl_parameterlist_new() ;
130 
131  /* Fill the parameters list */
132 /* p = cpl_parameter_new_value("midi.midi_detlin.productDir", */
133 /* CPL_TYPE_STRING, "Product directory", "midi.midi_detlin", */
134 /* "product path. don't forget ending /"); */
135 /* cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "stropt1") ; */
136 /* cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ; */
137 /* cpl_parameterlist_append(recipe->parameters, p) ; */
138 
139 /*
140  p = cpl_parameter_new_value("midi.midi_detlin.plotDuration",
141  CPL_TYPE_INT, "Plot duration (-1, 0, .. 5), -1 is the prompt mode", "midi.midi_detlin", 0);
142  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "intopt1") ;
143  cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ;
144  cpl_parameterlist_append(recipe->parameters, p) ;
145 */
146 
147 
148  /* Return */
149  return 0;
150 }
151 
152 /*----------------------------------------------------------------------------*/
158 /*----------------------------------------------------------------------------*/
159 static int midi_detlin_exec(cpl_plugin * plugin)
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_detlin(recipe->parameters, recipe->frames) ;
170 }
171 
172 /*----------------------------------------------------------------------------*/
178 /*----------------------------------------------------------------------------*/
179 static int midi_detlin_destroy(cpl_plugin * plugin)
180 {
181  cpl_recipe * recipe ;
182 
183  /* Get the recipe out of the plugin */
184  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
185  recipe = (cpl_recipe *)plugin ;
186  else return -1 ;
187 
188  cpl_parameterlist_delete(recipe->parameters) ;
189  return 0 ;
190 }
191 
192 /*----------------------------------------------------------------------------*/
199 /*----------------------------------------------------------------------------*/
200 static int midi_detlin(
201  cpl_parameterlist *parlist,
202  cpl_frameset *frameset)
203 {
204 /* const char *fctid = "midi_detlin" ; */
205 /* cpl_parameter *param ;*/
206  cpl_frame *current_frame;
207  int error=0;
208  FILE *sofPtr=NULL;
209 /* char *productDir; // In: Directory path of products */
210  int plotDuration;
211 
212  /* RETRIEVE INPUT PARAMETERS */
213 /* param = cpl_parameterlist_find(parlist, "midi.midi_detlin.productDir"); */
214 /* productDir = (char *) (cpl_parameter_get_string(param)); */
215 /* printf ("productDir = %s \n", productDir); */
216 /* if (cpl_error_get_code()) */
217 /* { */
218 /* cpl_msg_error(fctid, "Failed to retrieve productDir") ; */
219 /* return -1 ; */
220 /* } */
221 
222 /*
223  param = cpl_parameterlist_find(parlist, "midi.midi_detlin.plotDuration");
224  plotDuration = cpl_parameter_get_int(param);
225  printf ("plotDuration = %d \n", plotDuration);
226  if ((plotDuration < -1) || (plotDuration > 5)) plotDuration = 0;
227 */
228 
229  plotDuration = 0;
230 
231  current_frame = cpl_frameset_get_first(frameset);
232  sofPtr = fopen ("MIDI_sof.log", "w");
233  while ( current_frame && sofPtr )
234  {
235  fprintf (sofPtr, "%s \n", (char *)cpl_frame_get_filename( current_frame ));
236  current_frame = cpl_frameset_get_next( frameset );
237  } /* All frames from frameset */
238  fclose (sofPtr);
239 
240  /* NOW PERFORMING THE DATA REDUCTION */
241  executeDataReduction ("", "", "./", plotDuration, "MIDI_sof.log", &error,parlist,frameset);
242 /* executeDataReduction ("", "", productDir, plotDuration, "MIDI_sof.log", &error); */
243  if (error) return -1;
244  remove ("MIDI_sof.log");
245 
246 
247  if (CPL_ERROR_NONE != appendPropertylist("MIDI_b1_lin.pro.fits", CPL_FRAME_TYPE_IMAGE, "REDUCED_DETLIN",frameset,parlist))
248  {
249  cpl_msg_error(cpl_func,"Error in appendPropertylist");
250  }
251 
252 
253  /* Return */
254  if (cpl_error_get_code())
255  return -1 ;
256  else
257  return 0 ;
258 }