midi_dsptrn.c

00001 /* $Id: midi_dsptrn.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_dsptrn_create(cpl_plugin *) ;
00050 static int midi_dsptrn_exec(cpl_plugin *) ;
00051 static int midi_dsptrn_destroy(cpl_plugin *) ;
00052 static int midi_dsptrn(cpl_parameterlist *, cpl_frameset *) ;
00053 
00054 /*-----------------------------------------------------------------------------
00055                             Static variables
00056  -----------------------------------------------------------------------------*/
00057 
00058 static char midi_dsptrn_description[] =
00059 "The purpose of this technical template is to measure the transmission\n"
00060 "characteristics of the dispersive elements (Prism and Grism) in order\n"
00061 "to monitor the evolution of their coatings.\n\n"
00062 "Input files:\n\n"
00063 "  DO category:               Type:       Explanation:         Required:\n"
00064 "  DSPTRN                     Raw         Raw data frame          Y\n\n"
00065 "Output files:\n\n"
00066 "  DO category:               Data type:  Explanation:\n"
00067 "  REDUCED_DSPTRN             FITS image  transmission coefficient\n\n";
00068 
00069 /*-----------------------------------------------------------------------------
00070                                 Functions code
00071  -----------------------------------------------------------------------------*/
00072 
00073 /*----------------------------------------------------------------------------*/
00082 /*----------------------------------------------------------------------------*/
00083 int cpl_plugin_get_info(cpl_pluginlist * list)
00084 {
00085     cpl_recipe  *   recipe = cpl_calloc(1, sizeof *recipe ) ;
00086     cpl_plugin  *   plugin = &recipe->interface ;
00087 
00088     cpl_plugin_init(plugin,
00089                     CPL_PLUGIN_API,
00090                     MIDI_BINARY_VERSION,
00091                     CPL_PLUGIN_TYPE_RECIPE,
00092                     "midi_dsptrn",
00093                     "Evaluates the dispersive characteristics of the Grism/Prism",
00094                     midi_dsptrn_description,
00095                     "Armin Gabasch",
00096                     PACKAGE_BUGREPORT,
00097                     midi_get_license(),
00098                     midi_dsptrn_create,
00099                     midi_dsptrn_exec,
00100                     midi_dsptrn_destroy) ;
00101 
00102     cpl_pluginlist_append(list, plugin) ;
00103     
00104     return 0;
00105 }
00106 
00107 /*----------------------------------------------------------------------------*/
00115 /*----------------------------------------------------------------------------*/
00116 static int midi_dsptrn_create(cpl_plugin * plugin)
00117 {
00118     cpl_recipe      * recipe ;
00119 /*    cpl_parameter   * p ;*/
00120 
00121     /* Check that the plugin is part of a valid recipe */
00122     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
00123         recipe = (cpl_recipe *)plugin ;
00124     else return -1 ;
00125 
00126     /* Create the parameters list in the cpl_recipe object */
00127     recipe->parameters = cpl_parameterlist_new() ; 
00128     
00129     /* Fill the parameters list */
00130 
00131 /*     p = cpl_parameter_new_value("midi.midi_dsptrn.productDir",  */
00132 /*      CPL_TYPE_STRING, "Product directory", "midi.midi_dsptrn", */
00133 /*      "product path. don't forget ending /"); */
00134 /*     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "stropt1") ; */
00135 /*     cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ; */
00136 /*     cpl_parameterlist_append(recipe->parameters, p) ; */
00137 
00138 /*
00139     p = cpl_parameter_new_value("midi.midi_dsptrn.plotDuration", 
00140         CPL_TYPE_INT, "Plot duration (-1, 0, .. 5), -1 is the prompt mode", "midi.midi_dsptrn", 0);
00141     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "intopt1") ;
00142     cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ;
00143     cpl_parameterlist_append(recipe->parameters, p) ;
00144 */
00145 
00146 
00147     /* Return */
00148     return 0;
00149 }
00150 
00151 /*----------------------------------------------------------------------------*/
00157 /*----------------------------------------------------------------------------*/
00158 static int midi_dsptrn_exec(cpl_plugin * plugin)
00159 {
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_dsptrn(recipe->parameters, recipe->frames) ;
00170 
00171 }
00172 
00173 /*----------------------------------------------------------------------------*/
00179 /*----------------------------------------------------------------------------*/
00180 static int midi_dsptrn_destroy(cpl_plugin * plugin)
00181 {
00182     cpl_recipe  *   recipe ;
00183     
00184     /* Get the recipe out of the plugin */
00185     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
00186         recipe = (cpl_recipe *)plugin ;
00187     else return -1 ;
00188 
00189     cpl_parameterlist_delete(recipe->parameters) ; 
00190     return 0 ;
00191 }
00192 
00193 /*----------------------------------------------------------------------------*/
00200 /*----------------------------------------------------------------------------*/
00201 static int midi_dsptrn(
00202     cpl_parameterlist   *parlist, 
00203     cpl_frameset        *frameset)
00204 {
00205 /*  const char      *fctid = "midi_dsptrn" ; */
00206 /*  cpl_parameter   *param ;*/
00207     cpl_frame       *current_frame;
00208     int             error=0;
00209     FILE            *sofPtr=NULL;
00210 /*  char            *productDir;    // In: Directory path of products */
00211     int             plotDuration;
00212 
00213 
00214     /* RETRIEVE INPUT PARAMETERS */
00215 
00216 /*     param = cpl_parameterlist_find(parlist, "midi.midi_dsptrn.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_dsptrn.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 
00247     if (error) return -1;
00248     remove ("MIDI_sof.log");
00249         
00250         
00251         if (CPL_ERROR_NONE !=  appendPropertylist("MIDI_b1_trn.pro.fits", CPL_FRAME_TYPE_IMAGE, "REDUCED_DSPTRN",frameset,parlist))
00252         {
00253            cpl_msg_error(cpl_func,"Error in appendPropertylist");
00254         }
00255         
00256          
00257 
00258 
00259 /* /\* ##################### *\/ */
00260 /*         { */
00261 /*            cpl_image  * pImage        = NULL; */
00262 /*            cpl_frame  * pFrameProduct = NULL; */
00263 /*            cpl_propertylist  *   pHeader = NULL; */
00264 
00265 
00266 /*            const char *szProduct="MIDI_b1_trn.pro.fits"; */
00267 /*            const char *szRawFile="MIDI_b1_trn.pro.fits"; */
00268 
00269 
00270 /*            pImage = cpl_image_load(szRawFile, CPL_TYPE_FLOAT, 0, 0 ); */
00271 
00272  
00273 /*            pHeader = cpl_propertylist_new(); /\* ????????  *\/ */
00274 /*            pHeader = cpl_propertylist_load(szRawFile, 0 ); */
00275  
00276 
00277 
00278           
00279 /*            pFrameProduct = cpl_frame_new(); */
00280 /*            cpl_frame_set_filename( pFrameProduct, szProduct ); */
00281 /*            cpl_frame_set_type    ( pFrameProduct, CPL_FRAME_TYPE_IMAGE ); */
00282 /*            cpl_frame_set_tag     ( pFrameProduct, "REDUCED_DSPTRN" ); */
00283 /*            cpl_frame_set_group   ( pFrameProduct, CPL_FRAME_GROUP_PRODUCT ); */
00284 /*            cpl_frame_set_level   ( pFrameProduct, CPL_FRAME_LEVEL_FINAL ); */
00285   
00286  
00287 /*            if (CPL_ERROR_NONE != cpl_image_save(pImage, szProduct, CPL_BPP_DEFAULT, pHeader, CPL_IO_DEFAULT )) */
00288 /*            { */
00289 /*               cpl_msg_error(cpl_func,"Saving error"); */
00290 /*            } */
00291 
00292 
00293 /*            if (CPL_ERROR_NONE != cpl_frameset_insert( frameset, pFrameProduct )) */
00294 /*            { */
00295 /*               cpl_msg_error(cpl_func,"Error in cpl_frameset_insert"); */
00296 /*            } */
00297            
00298 /*            cpl_image_delete( pImage ); */
00299 /*            cpl_propertylist_delete(pHeader );  */
00300            
00301 /*            cpl_msg_info(cpl_func,"batchNumber_: %d",batchNumber); */
00302 
00303 /*       } */
00304 
00305 
00306 
00307 /* /\* ##################### *\/ */
00308 
00309 
00310     /* Return */
00311     if (cpl_error_get_code()) 
00312         return -1 ;
00313     else 
00314         return 0 ;
00315 }
00316 

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