midi_detlin.c

00001 /* $Id: midi_detlin.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_7_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 /*-----------------------------------------------------------------------------
00047                             Functions prototypes
00048  -----------------------------------------------------------------------------*/
00049 
00050 static int midi_detlin_create(cpl_plugin *) ;
00051 static int midi_detlin_exec(cpl_plugin *) ;
00052 static int midi_detlin_destroy(cpl_plugin *) ;
00053 static int midi_detlin(cpl_parameterlist *, cpl_frameset *) ;
00054 
00055 /*-----------------------------------------------------------------------------
00056                             Static variables
00057  -----------------------------------------------------------------------------*/
00058 
00059 static char midi_detlin_description[] =
00060 "The purpose of this technical template is to evaluate the linearity of the\n"
00061 "detector, i.e. the relationship between the detector counts and the number\n"
00062 "of photons.\n\n"
00063 "Input files:\n\n"
00064 "  DO category:               Type:       Explanation:         Required:\n"
00065 "  DETLIN                     Raw         Raw data frame          Y\n\n"
00066 "Output files:\n\n"
00067 "  DO category:               Data type:  Explanation:\n"
00068 "  REDUCED_DETLIN             FITS image  linearity coefficient in the header\n"
00069 "\n";
00070 
00071 /*-----------------------------------------------------------------------------
00072                                 Functions code
00073  -----------------------------------------------------------------------------*/
00074 
00075 /*----------------------------------------------------------------------------*/
00084 /*----------------------------------------------------------------------------*/
00085 int cpl_plugin_get_info(cpl_pluginlist * list)
00086 {
00087     cpl_recipe  *   recipe = cpl_calloc(1, sizeof *recipe ) ;
00088     cpl_plugin  *   plugin = &recipe->interface ;
00089 
00090     cpl_plugin_init(plugin,
00091                     CPL_PLUGIN_API,
00092                     MIDI_BINARY_VERSION,
00093                     CPL_PLUGIN_TYPE_RECIPE,
00094                     "midi_detlin",
00095                     "Evaluates the detector linearity",
00096                     midi_detlin_description,
00097                     "Coorosh Sabet",
00098                     PACKAGE_BUGREPORT,
00099                     midi_get_license(),
00100                     midi_detlin_create,
00101                     midi_detlin_exec,
00102                     midi_detlin_destroy) ;
00103 
00104     cpl_pluginlist_append(list, plugin) ;
00105     
00106     return 0;
00107 }
00108 
00109 /*----------------------------------------------------------------------------*/
00117 /*----------------------------------------------------------------------------*/
00118 static int midi_detlin_create(cpl_plugin * plugin)
00119 {
00120     cpl_recipe      * recipe ;
00121 /*    cpl_parameter   * p ;*/
00122 
00123     /* Check that the plugin is part of a valid recipe */
00124     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
00125         recipe = (cpl_recipe *)plugin ;
00126     else return -1 ;
00127 
00128     /* Create the parameters list in the cpl_recipe object */
00129     recipe->parameters = cpl_parameterlist_new() ; 
00130     
00131     /* Fill the parameters list */
00132 /*     p = cpl_parameter_new_value("midi.midi_detlin.productDir",  */
00133 /*      CPL_TYPE_STRING, "Product directory", "midi.midi_detlin", */
00134 /*      "product path. don't forget ending /"); */
00135 /*     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "stropt1") ; */
00136 /*     cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ; */
00137 /*     cpl_parameterlist_append(recipe->parameters, p) ; */
00138 
00139 /*
00140     p = cpl_parameter_new_value("midi.midi_detlin.plotDuration", 
00141         CPL_TYPE_INT, "Plot duration (-1, 0, .. 5), -1 is the prompt mode", "midi.midi_detlin", 0);
00142     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "intopt1") ;
00143     cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ;
00144     cpl_parameterlist_append(recipe->parameters, p) ;
00145 */
00146 
00147 
00148     /* Return */
00149     return 0;
00150 }
00151 
00152 /*----------------------------------------------------------------------------*/
00158 /*----------------------------------------------------------------------------*/
00159 static int midi_detlin_exec(cpl_plugin * plugin)
00160 {
00161     cpl_recipe  *   recipe ;
00162     
00163     /* Get the recipe out of the plugin */
00164     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
00165         recipe = (cpl_recipe *)plugin ;
00166     else return -1 ;
00167 
00168     batchNumber=0;
00169     return midi_detlin(recipe->parameters, recipe->frames) ;
00170 }
00171 
00172 /*----------------------------------------------------------------------------*/
00178 /*----------------------------------------------------------------------------*/
00179 static int midi_detlin_destroy(cpl_plugin * plugin)
00180 {
00181     cpl_recipe  *   recipe ;
00182     
00183     /* Get the recipe out of the plugin */
00184     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
00185         recipe = (cpl_recipe *)plugin ;
00186     else return -1 ;
00187 
00188     cpl_parameterlist_delete(recipe->parameters) ; 
00189     return 0 ;
00190 }
00191 
00192 /*----------------------------------------------------------------------------*/
00199 /*----------------------------------------------------------------------------*/
00200 static int midi_detlin(
00201     cpl_parameterlist   *parlist, 
00202     cpl_frameset        *frameset)
00203 {
00204 /*  const char      *fctid = "midi_detlin" ; */
00205 /*  cpl_parameter   *param ;*/
00206     cpl_frame       *current_frame;
00207     int             error=0;
00208     FILE            *sofPtr=NULL;
00209 /*  char            *productDir;    // In: Directory path of products */
00210     int             plotDuration;
00211 
00212     /* RETRIEVE INPUT PARAMETERS */
00213 /*     param = cpl_parameterlist_find(parlist, "midi.midi_detlin.productDir"); */
00214 /*     productDir = (char *) (cpl_parameter_get_string(param)); */
00215 /*  printf ("productDir = %s \n", productDir); */
00216 /*     if (cpl_error_get_code()) */
00217 /*  { */
00218 /*         cpl_msg_error(fctid, "Failed to retrieve productDir") ; */
00219 /*         return -1 ; */
00220 /*     } */
00221 
00222 /*
00223     param = cpl_parameterlist_find(parlist, "midi.midi_detlin.plotDuration");
00224     plotDuration = cpl_parameter_get_int(param);
00225     printf ("plotDuration = %d \n", plotDuration);
00226     if ((plotDuration < -1) || (plotDuration > 5)) plotDuration = 0;
00227 */
00228 
00229     plotDuration = 0;
00230 
00231     current_frame = cpl_frameset_get_first(frameset);
00232     sofPtr = fopen ("MIDI_sof.log", "w");
00233     while ( current_frame && sofPtr )
00234     {   
00235         fprintf (sofPtr, "%s \n", (char *)cpl_frame_get_filename( current_frame ));
00236         current_frame = cpl_frameset_get_next( frameset );
00237     } /* All frames from frameset */
00238     fclose (sofPtr);
00239      
00240     /* NOW PERFORMING THE DATA REDUCTION */
00241     executeDataReduction ("", "", "./", plotDuration, "MIDI_sof.log", &error,parlist,frameset);
00242 /*  executeDataReduction ("", "", productDir, plotDuration, "MIDI_sof.log", &error); */
00243     if (error) return -1;
00244     remove ("MIDI_sof.log");
00245 
00246 
00247         if (CPL_ERROR_NONE !=  appendPropertylist("MIDI_b1_lin.pro.fits", CPL_FRAME_TYPE_IMAGE, "REDUCED_DETLIN",frameset,parlist))
00248         {
00249            cpl_msg_error(cpl_func,"Error in appendPropertylist");
00250         }
00251 
00252 
00253     /* Return */
00254     if (cpl_error_get_code()) 
00255         return -1 ;
00256     else 
00257         return 0 ;
00258 }

Generated on 11 Feb 2011 for MIDI Pipeline Reference Manual by  doxygen 1.6.1