00001 /* $Id: midi_wavecal.c,v 1.7 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.7 $ 00025 * $Name: midi-2_8_2 $ 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_wavecal_create(cpl_plugin *) ; 00050 static int midi_wavecal_exec(cpl_plugin *) ; 00051 static int midi_wavecal_destroy(cpl_plugin *) ; 00052 static int midi_wavecal(cpl_parameterlist *, cpl_frameset *) ; 00053 00054 /*----------------------------------------------------------------------------- 00055 Static variables 00056 -----------------------------------------------------------------------------*/ 00057 00058 static char midi_wavecal_description[] = 00059 "The purpose of this technical recipe is to facilitate calibration of the\n" 00060 "detector channels.\n\n" 00061 "Input files:\n\n" 00062 " DO category: Type: Explanation: Required:\n" 00063 " WAVECAL Raw Raw data frame Y\n\n" 00064 "Output files:\n\n" 00065 " DO category: Data type: Explanation:\n" 00066 " REDUCED_WAVECAL FITS image transmission coefficient\n\n"; 00067 00068 /*----------------------------------------------------------------------------- 00069 Functions code 00070 -----------------------------------------------------------------------------*/ 00071 00072 /*----------------------------------------------------------------------------*/ 00081 /*----------------------------------------------------------------------------*/ 00082 int cpl_plugin_get_info(cpl_pluginlist * list) 00083 { 00084 cpl_recipe * recipe = cpl_calloc(1, sizeof *recipe ) ; 00085 cpl_plugin * plugin = &recipe->interface ; 00086 00087 cpl_plugin_init(plugin, 00088 CPL_PLUGIN_API, 00089 MIDI_BINARY_VERSION, 00090 CPL_PLUGIN_TYPE_RECIPE, 00091 "midi_wavecal", 00092 "Produces Wavelength Calibration databases", 00093 midi_wavecal_description, 00094 "Coorosh Sabet", 00095 PACKAGE_BUGREPORT, 00096 midi_get_license(), 00097 midi_wavecal_create, 00098 midi_wavecal_exec, 00099 midi_wavecal_destroy) ; 00100 00101 cpl_pluginlist_append(list, plugin) ; 00102 00103 return 0; 00104 } 00105 00106 /*----------------------------------------------------------------------------*/ 00114 /*----------------------------------------------------------------------------*/ 00115 static int midi_wavecal_create(cpl_plugin * plugin) 00116 { 00117 cpl_recipe * recipe ; 00118 /* cpl_parameter * p ;*/ 00119 00120 /* Check that the plugin is part of a valid recipe */ 00121 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 00122 recipe = (cpl_recipe *)plugin ; 00123 else return -1 ; 00124 00125 /* Create the parameters list in the cpl_recipe object */ 00126 recipe->parameters = cpl_parameterlist_new() ; 00127 00128 /* Fill the parameters list */ 00129 /* 00130 p = cpl_parameter_new_value("midi.midi_wavecal.calibTempDir", 00131 CPL_TYPE_STRING, "CalibDB directory", "midi.midi_wavecal", 00132 MIDI_CALIBTEMP); 00133 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "stropt1") ; 00134 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ; 00135 cpl_parameterlist_append(recipe->parameters, p) ; 00136 */ 00137 00138 /* p = cpl_parameter_new_value("midi.midi_wavecal.productDir", */ 00139 /* CPL_TYPE_STRING, "Product directory", "midi.midi_wavecal", */ 00140 /* "product path. don't forget ending /"); */ 00141 /* cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "stropt2") ; */ 00142 /* cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ; */ 00143 /* cpl_parameterlist_append(recipe->parameters, p) ; */ 00144 00145 /* 00146 p = cpl_parameter_new_value("midi.midi_wavecal.plotDuration", 00147 CPL_TYPE_INT, "Plot duration (-1, 0, .. 5) -1 is the prompt mode", "midi.midi_wavecal", 0); 00148 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "intopt2") ; 00149 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV) ; 00150 cpl_parameterlist_append(recipe->parameters, p) ; 00151 */ 00152 00153 00154 /* Return */ 00155 return 0; 00156 } 00157 00158 /*----------------------------------------------------------------------------*/ 00164 /*----------------------------------------------------------------------------*/ 00165 static int midi_wavecal_exec(cpl_plugin * plugin) 00166 { 00167 cpl_recipe * recipe ; 00168 00169 /* Get the recipe out of the plugin */ 00170 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 00171 recipe = (cpl_recipe *)plugin ; 00172 else return -1 ; 00173 00174 batchNumber=0; 00175 return midi_wavecal(recipe->parameters, recipe->frames) ; 00176 } 00177 00178 /*----------------------------------------------------------------------------*/ 00184 /*----------------------------------------------------------------------------*/ 00185 static int midi_wavecal_destroy(cpl_plugin * plugin) 00186 { 00187 cpl_recipe * recipe ; 00188 00189 /* Get the recipe out of the plugin */ 00190 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 00191 recipe = (cpl_recipe *)plugin ; 00192 else return -1 ; 00193 00194 cpl_parameterlist_delete(recipe->parameters) ; 00195 return 0 ; 00196 } 00197 00198 /*----------------------------------------------------------------------------*/ 00205 /*----------------------------------------------------------------------------*/ 00206 static int midi_wavecal( 00207 cpl_parameterlist *parlist, 00208 cpl_frameset *frameset) 00209 { 00210 /* 00211 const char *fctid = "midi_wavecal" ; 00212 cpl_parameter *param ; 00213 */ 00214 cpl_frame *current_frame; 00215 /* char *calibTempDir; // In: Directory path of calib_temp*/ 00216 int error=0; 00217 FILE *sofPtr=NULL; 00218 /* char *productDir; // In: Directory path of products */ 00219 int plotDuration; 00220 00221 /* RETRIEVE INPUT PARAMETERS */ 00222 /* 00223 param = cpl_parameterlist_find(parlist, "midi.midi_wavecal.calibTempDir"); 00224 calibTempDir = (char *) (cpl_parameter_get_string(param)); 00225 printf ("calibTempDir = %s \n", calibTempDir); 00226 if (cpl_error_get_code()) 00227 { 00228 cpl_msg_error(fctid, "Failed to retrieve calibTempDir") ; 00229 return -1 ; 00230 } 00231 */ 00232 00233 /* param = cpl_parameterlist_find(parlist, "midi.midi_wavecal.productDir"); */ 00234 /* productDir = (char *) (cpl_parameter_get_string(param)); */ 00235 /* printf ("productDir = %s \n", productDir); */ 00236 /* if (cpl_error_get_code()) */ 00237 /* { */ 00238 /* cpl_msg_error(fctid, "Failed to retrieve productDir") ; */ 00239 /* return -1 ; */ 00240 /* } */ 00241 00242 /* 00243 param = cpl_parameterlist_find(parlist, "midi.midi_wavecal.plotDuration"); 00244 plotDuration = cpl_parameter_get_int(param); 00245 printf ("plotDuration = %d \n", plotDuration); 00246 if ((plotDuration < -1) || (plotDuration > 5)) plotDuration = 0; 00247 */ 00248 00249 plotDuration = 0; 00250 00251 current_frame = cpl_frameset_get_first(frameset); 00252 sofPtr = fopen ("MIDI_sof.log", "w"); 00253 while ( current_frame && sofPtr ) 00254 { 00255 fprintf (sofPtr, "%s \n", (char *)cpl_frame_get_filename( current_frame )); 00256 current_frame = cpl_frameset_get_next( frameset ); 00257 } /* All frames from frameset */ 00258 fclose (sofPtr); 00259 00260 /* NOW PERFORMING THE DATA REDUCTION */ 00261 executeDataReduction (MIDI_CALIBTEMP, "", "./", plotDuration, "MIDI_sof.log", &error,parlist,frameset); 00262 /* executeDataReduction (calibTempDir, "", productDir, plotDuration, "MIDI_sof.log", &error); */ 00263 if (error) return -1; 00264 remove ("MIDI_sof.log"); 00265 00266 if (CPL_ERROR_NONE != appendPropertylist("MIDI_b1_wav.pro.fits", CPL_FRAME_TYPE_IMAGE, "REDUCED_WAVECAL",frameset,parlist)) 00267 { 00268 cpl_msg_error(cpl_func,"Error in appendPropertylist"); 00269 } 00270 00271 00272 /* Return */ 00273 if (cpl_error_get_code()) 00274 return -1 ; 00275 else 00276 return 0 ; 00277 } 00278