midi_refpix.c

00001 /* $Id: midi_refpix.c,v 1.6 2010/05/28 09:16:01 agabasch Exp $
00002  *
00003  * This file is part of the MIDI Pipeline
00004  * Copyright (C) 2002,2003 European Southern Observatory
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00021 /*
00022  * $Author: agabasch $
00023  * $Date: 2010/05/28 09:16:01 $
00024  * $Revision: 1.6 $
00025  * $Name: midi-2_8_0 $
00026  */
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031 
00032 /*-----------------------------------------------------------------------------
00033                                 Includes
00034  -----------------------------------------------------------------------------*/
00035 
00036 #include <cpl.h>
00037 #include <stdio.h>
00038 #include "midi_utils.h"
00039 #include "midi_pfits.h"
00040 #include "midi_dfs.h"
00041 #include "midiControl.h"
00042 #include "midiGlobal.h"
00043 #include "midiAppendPropertylist.h"
00044 
00045 /*-----------------------------------------------------------------------------
00046                             Functions prototypes
00047  -----------------------------------------------------------------------------*/
00048 
00049 static int midi_refpix_create(cpl_plugin *) ;
00050 static int midi_refpix_exec(cpl_plugin *) ;
00051 static int midi_refpix_destroy(cpl_plugin *) ;
00052 static int midi_refpix(cpl_parameterlist *, cpl_frameset *) ;
00053 
00054 /*-----------------------------------------------------------------------------
00055                             Static variables
00056  -----------------------------------------------------------------------------*/
00057 
00058 static char midi_refpix_description[] =
00059 "The purpose of this technical template is to evaluate the reference\n"
00060 "positions of the VLTI beams on the MIDI detector for the fine positioning\n"
00061 "of the target. The reference pixels of MIDI are the pixels of the detector\n"
00062 "onto which the centroids of the target images must fall in order to ensure\n"
00063 "a proper beam overlap.\n\n"
00064 "Input files:\n\n"
00065 "  DO category:               Type:       Explanation:         Required:\n"
00066 "  REFPIX                     Raw         Raw data frame          Y\n\n"
00067 "Output files:\n\n"
00068 "  DO category:               Data type:  Explanation:\n"
00069 "  REDUCED_ REFPIX            FITS image  reference pixel description (header)"
00070 "\n\n";
00071 
00072 /*-----------------------------------------------------------------------------
00073                                 Functions code
00074  -----------------------------------------------------------------------------*/
00075 
00076 /*----------------------------------------------------------------------------*/
00085 /*----------------------------------------------------------------------------*/
00086 int cpl_plugin_get_info(cpl_pluginlist * list)
00087 {
00088     cpl_recipe  *   recipe = cpl_calloc(1, sizeof *recipe ) ;
00089     cpl_plugin  *   plugin = &recipe->interface ;
00090 
00091     cpl_plugin_init(plugin,
00092                     CPL_PLUGIN_API,
00093                     MIDI_BINARY_VERSION,
00094                     CPL_PLUGIN_TYPE_RECIPE,
00095                     "midi_refpix",
00096                     "Evaluates the reference positions of the VLTI beams",
00097                     midi_refpix_description,
00098                     "Coorosh Sabet",
00099                     PACKAGE_BUGREPORT,
00100                     midi_get_license(),
00101                     midi_refpix_create,
00102                     midi_refpix_exec,
00103                     midi_refpix_destroy) ;
00104 
00105     cpl_pluginlist_append(list, plugin) ;
00106     
00107     return 0;
00108 }
00109 
00110 /*----------------------------------------------------------------------------*/
00118 /*----------------------------------------------------------------------------*/
00119 static int midi_refpix_create(cpl_plugin * plugin)
00120 {
00121     cpl_recipe      * recipe ;
00122 /*    cpl_parameter   * p ;*/
00123 
00124     /* Check that the plugin is part of a valid recipe */
00125     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
00126         recipe = (cpl_recipe *)plugin ;
00127     else return -1 ;
00128 
00129     /* Create the parameters list in the cpl_recipe object */
00130     recipe->parameters = cpl_parameterlist_new() ; 
00131     
00132     /* Fill the parameters list */
00133 
00134 /*     p = cpl_parameter_new_value("midi.midi_refpix.productDir",  */
00135 /*      CPL_TYPE_STRING, "Product directory", "midi.midi_refpix", */
00136 /*      "product path. don't forget ending /"); */
00137 /*     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "stropt1") ; */
00138 /*     cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ; */
00139 /*     cpl_parameterlist_append(recipe->parameters, p) ; */
00140 
00141 /*
00142     p = cpl_parameter_new_value("midi.midi_refpix.plotDuration", 
00143         CPL_TYPE_INT, "Plot duration (-1, 0, .. 5), -1 is the prompt mode", "midi.midi_refpix", 0);
00144     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "intopt1") ;
00145     cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ;
00146     cpl_parameterlist_append(recipe->parameters, p) ;
00147 */
00148 
00149 
00150     /* Return */
00151     return 0;
00152 }
00153 
00154 /*----------------------------------------------------------------------------*/
00160 /*----------------------------------------------------------------------------*/
00161 static int midi_refpix_exec(cpl_plugin * plugin)
00162 {
00163     cpl_recipe  *   recipe ;
00164     
00165     /* Get the recipe out of the plugin */
00166     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
00167         recipe = (cpl_recipe *)plugin ;
00168     else return -1 ;
00169 
00170     batchNumber=0;
00171     return midi_refpix(recipe->parameters, recipe->frames) ;
00172 }
00173 
00174 /*----------------------------------------------------------------------------*/
00180 /*----------------------------------------------------------------------------*/
00181 static int midi_refpix_destroy(cpl_plugin * plugin)
00182 {
00183     cpl_recipe  *   recipe ;
00184     
00185     /* Get the recipe out of the plugin */
00186     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
00187         recipe = (cpl_recipe *)plugin ;
00188     else return -1 ;
00189 
00190     cpl_parameterlist_delete(recipe->parameters) ; 
00191     return 0 ;
00192 }
00193 
00194 /*----------------------------------------------------------------------------*/
00201 /*----------------------------------------------------------------------------*/
00202 static int midi_refpix(
00203     cpl_parameterlist   *parlist, 
00204     cpl_frameset        *frameset)
00205 {
00206 /*  const char      *fctid = "midi_refpix" ; */
00207 /*  cpl_parameter   *param ;*/
00208     cpl_frame       *current_frame;
00209     int             error=0;
00210     FILE            *sofPtr=NULL;
00211 /*  char            *productDir;    // In: Directory path of products */
00212     int             plotDuration;
00213 
00214     /* RETRIEVE INPUT PARAMETERS */
00215 
00216 /*     param = cpl_parameterlist_find(parlist, "midi.midi_refpix.productDir"); */
00217 /*     productDir = (char *) (cpl_parameter_get_string(param)); */
00218 /*  printf ("productDir = %s \n", productDir); */
00219 /*     if (cpl_error_get_code()) */
00220 /*  { */
00221 /*         cpl_msg_error(fctid, "Failed to retrieve productDir") ; */
00222 /*         return -1 ; */
00223 /*     } */
00224 
00225 /*
00226     param = cpl_parameterlist_find(parlist, "midi.midi_refpix.plotDuration");
00227     plotDuration = cpl_parameter_get_int(param);
00228     printf ("plotDuration = %d \n", plotDuration);
00229     if ((plotDuration < -1) || (plotDuration > 5)) plotDuration = 0;
00230 */
00231 
00232     plotDuration = 0;
00233 
00234     current_frame = cpl_frameset_get_first(frameset);
00235     sofPtr = fopen ("MIDI_sof.log", "w");
00236     while ( current_frame && sofPtr )
00237     {   
00238         fprintf (sofPtr, "%s \n", (char *)cpl_frame_get_filename( current_frame ));
00239         current_frame = cpl_frameset_get_next( frameset );
00240     } /* All frames from frameset */
00241     fclose (sofPtr);
00242      
00243     /* NOW PERFORMING THE DATA REDUCTION */
00244     executeDataReduction ("", "", "./", plotDuration, "MIDI_sof.log", &error,parlist,frameset);
00245 /*  executeDataReduction ("", "", productDir, plotDuration, "MIDI_sof.log", &error); */
00246     if (error) return -1;
00247     remove ("MIDI_sof.log");
00248 
00249         if (CPL_ERROR_NONE !=  appendPropertylist("MIDI_b1_pix.pro.fits", CPL_FRAME_TYPE_IMAGE, "REDUCED_REFPIX",frameset,parlist))
00250         {
00251            cpl_msg_error(cpl_func,"Error in appendPropertylist");
00252         }
00253 
00254 
00255     /* Return */
00256     if (cpl_error_get_code()) 
00257         return -1 ;
00258     else 
00259         return 0 ;
00260 }
00261 

Generated on 15 Mar 2012 for MIDI Pipeline Reference Manual by  doxygen 1.6.1