MIDI Pipeline Reference Manual  2.8.3
midi_refpix.c
1 /* $Id: midi_refpix.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_refpix_create(cpl_plugin *) ;
50 static int midi_refpix_exec(cpl_plugin *) ;
51 static int midi_refpix_destroy(cpl_plugin *) ;
52 static int midi_refpix(cpl_parameterlist *, cpl_frameset *) ;
53 
54 /*-----------------------------------------------------------------------------
55  Static variables
56  -----------------------------------------------------------------------------*/
57 
58 static char midi_refpix_description[] =
59 "The purpose of this technical template is to evaluate the reference\n"
60 "positions of the VLTI beams on the MIDI detector for the fine positioning\n"
61 "of the target. The reference pixels of MIDI are the pixels of the detector\n"
62 "onto which the centroids of the target images must fall in order to ensure\n"
63 "a proper beam overlap.\n\n"
64 "Input files:\n\n"
65 " DO category: Type: Explanation: Required:\n"
66 " REFPIX Raw Raw data frame Y\n\n"
67 "Output files:\n\n"
68 " DO category: Data type: Explanation:\n"
69 " REDUCED_ REFPIX FITS image reference pixel description (header)"
70 "\n\n";
71 
72 /*-----------------------------------------------------------------------------
73  Functions code
74  -----------------------------------------------------------------------------*/
75 
76 /*----------------------------------------------------------------------------*/
85 /*----------------------------------------------------------------------------*/
86 int cpl_plugin_get_info(cpl_pluginlist * list)
87 {
88  cpl_recipe * recipe = cpl_calloc(1, sizeof *recipe ) ;
89  cpl_plugin * plugin = &recipe->interface ;
90 
91  cpl_plugin_init(plugin,
92  CPL_PLUGIN_API,
93  MIDI_BINARY_VERSION,
94  CPL_PLUGIN_TYPE_RECIPE,
95  "midi_refpix",
96  "Evaluates the reference positions of the VLTI beams",
97  midi_refpix_description,
98  "Coorosh Sabet",
99  PACKAGE_BUGREPORT,
101  midi_refpix_create,
102  midi_refpix_exec,
103  midi_refpix_destroy) ;
104 
105  cpl_pluginlist_append(list, plugin) ;
106 
107  return 0;
108 }
109 
110 /*----------------------------------------------------------------------------*/
118 /*----------------------------------------------------------------------------*/
119 static int midi_refpix_create(cpl_plugin * plugin)
120 {
121  cpl_recipe * recipe ;
122 /* cpl_parameter * p ;*/
123 
124  /* Check that the plugin is part of a valid recipe */
125  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
126  recipe = (cpl_recipe *)plugin ;
127  else return -1 ;
128 
129  /* Create the parameters list in the cpl_recipe object */
130  recipe->parameters = cpl_parameterlist_new() ;
131 
132  /* Fill the parameters list */
133 
134 /* p = cpl_parameter_new_value("midi.midi_refpix.productDir", */
135 /* CPL_TYPE_STRING, "Product directory", "midi.midi_refpix", */
136 /* "product path. don't forget ending /"); */
137 /* cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "stropt1") ; */
138 /* cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ; */
139 /* cpl_parameterlist_append(recipe->parameters, p) ; */
140 
141 /*
142  p = cpl_parameter_new_value("midi.midi_refpix.plotDuration",
143  CPL_TYPE_INT, "Plot duration (-1, 0, .. 5), -1 is the prompt mode", "midi.midi_refpix", 0);
144  cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "intopt1") ;
145  cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ;
146  cpl_parameterlist_append(recipe->parameters, p) ;
147 */
148 
149 
150  /* Return */
151  return 0;
152 }
153 
154 /*----------------------------------------------------------------------------*/
160 /*----------------------------------------------------------------------------*/
161 static int midi_refpix_exec(cpl_plugin * plugin)
162 {
163  cpl_recipe * recipe ;
164 
165  /* Get the recipe out of the plugin */
166  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
167  recipe = (cpl_recipe *)plugin ;
168  else return -1 ;
169 
170  batchNumber=0;
171  return midi_refpix(recipe->parameters, recipe->frames) ;
172 }
173 
174 /*----------------------------------------------------------------------------*/
180 /*----------------------------------------------------------------------------*/
181 static int midi_refpix_destroy(cpl_plugin * plugin)
182 {
183  cpl_recipe * recipe ;
184 
185  /* Get the recipe out of the plugin */
186  if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
187  recipe = (cpl_recipe *)plugin ;
188  else return -1 ;
189 
190  cpl_parameterlist_delete(recipe->parameters) ;
191  return 0 ;
192 }
193 
194 /*----------------------------------------------------------------------------*/
201 /*----------------------------------------------------------------------------*/
202 static int midi_refpix(
203  cpl_parameterlist *parlist,
204  cpl_frameset *frameset)
205 {
206 /* const char *fctid = "midi_refpix" ; */
207 /* cpl_parameter *param ;*/
208  cpl_frame *current_frame;
209  int error=0;
210  FILE *sofPtr=NULL;
211 /* char *productDir; // In: Directory path of products */
212  int plotDuration;
213 
214  /* RETRIEVE INPUT PARAMETERS */
215 
216 /* param = cpl_parameterlist_find(parlist, "midi.midi_refpix.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_refpix.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  if (error) return -1;
247  remove ("MIDI_sof.log");
248 
249  if (CPL_ERROR_NONE != appendPropertylist("MIDI_b1_pix.pro.fits", CPL_FRAME_TYPE_IMAGE, "REDUCED_REFPIX",frameset,parlist))
250  {
251  cpl_msg_error(cpl_func,"Error in appendPropertylist");
252  }
253 
254 
255  /* Return */
256  if (cpl_error_get_code())
257  return -1 ;
258  else
259  return 0 ;
260 }
261