sinfo_utl_cube_arith.c

00001 /* $Id: sinfo_utl_cube_arith.c,v 1.10 2007/10/26 09:40:28 amodigli Exp $
00002  *
00003  * This file is part of the SINFONI 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: amodigli $
00023  * $Date: 2007/10/26 09:40:28 $
00024  * $Revision: 1.10 $
00025  * $Name: HEAD $
00026  */
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031 
00032 /*-----------------------------------------------------------------------------
00033                                 Includes
00034  ----------------------------------------------------------------------------*/
00035 #include <string.h>
00036 
00037 /* cpl */
00038 #include <cpl.h>
00039 /* irplib */
00040 #include <irplib_utils.h>
00041 
00042 #include <sinfo_tpl_utils.h>
00043 #include <sinfo_pfits.h>
00044 #include <sinfo_tpl_dfs.h>
00045 #include <sinfo_utl_cube_arith.h>
00046 #include <sinfo_msg.h>
00047 
00048 /*-----------------------------------------------------------------------------
00049                             Functions prototypes
00050  ----------------------------------------------------------------------------*/
00051 
00052 static int sinfo_utl_cube_arith_create(cpl_plugin *) ;
00053 static int sinfo_utl_cube_arith_exec(cpl_plugin *) ;
00054 static int sinfo_utl_cube_arith_destroy(cpl_plugin *) ;
00055 
00056 /*-----------------------------------------------------------------------------
00057                             Static variables
00058  ----------------------------------------------------------------------------*/
00059 
00060 static char sinfo_utl_cube_arith_description1[] =
00061 "This recipe perform cube arithmetics.\n"
00062 "If parameter value is specified the input frame is a cube \n"
00063 "in a sof file with tag CUBE\n"
00064 "Else the input files are a cube and an images or a spectrum\n"
00065 "their associated tags should be respectively CUBE, IMA or SPECTRUM.\n"
00066 "The output is a cube with tag PRO_CUBE resulting from the operation \n"
00067 "CUBE op IMA or \n"
00068 "CUBE op SPECTRUM or\n"
00069 "CUBE op value where op indicates\n"
00070 "the operation to be performed\n";
00071 
00072 
00073 static char sinfo_utl_cube_arith_description2[] =
00074 "Information on relevant parameters can be found with\n"
00075 "esorex --params sinfo_utl_cube_arith\n"
00076 "esorex --help sinfo_utl_cube_arith\n"
00077 "\n";
00078 
00079 static char sinfo_utl_cube_arith_description[600];
00080 
00081 
00082 
00083 /*-----------------------------------------------------------------------------
00084                                 Functions code
00085  ----------------------------------------------------------------------------*/
00086 /*---------------------------------------------------------------------------*/
00090 /*---------------------------------------------------------------------------*/
00092 /*---------------------------------------------------------------------------*/
00100 /*---------------------------------------------------------------------------*/
00101 int cpl_plugin_get_info(cpl_pluginlist * list)
00102 {
00103     cpl_recipe  *   recipe = cpl_calloc(1, sizeof *recipe ) ;
00104     cpl_plugin  *   plugin = &recipe->interface ;
00105 
00106     strcpy(sinfo_utl_cube_arith_description,sinfo_utl_cube_arith_description1);
00107     strcat(sinfo_utl_cube_arith_description,sinfo_utl_cube_arith_description2);
00108 
00109     cpl_plugin_init(plugin,
00110                     CPL_PLUGIN_API,
00111                     SINFONI_BINARY_VERSION,
00112                     CPL_PLUGIN_TYPE_RECIPE,
00113                     "sinfo_utl_cube_arith",
00114                     "Cube arithmetics",
00115                     sinfo_utl_cube_arith_description,
00116                     "Andrea Modigliani",
00117                     "Andrea.Modigliani@eso.org",
00118                     sinfo_get_license(),
00119                     sinfo_utl_cube_arith_create,
00120                     sinfo_utl_cube_arith_exec,
00121                     sinfo_utl_cube_arith_destroy) ;
00122 
00123     cpl_pluginlist_append(list, plugin) ;
00124     
00125     return 0;
00126 }
00127 
00128 /*---------------------------------------------------------------------------*/
00137 /*---------------------------------------------------------------------------*/
00138 static int sinfo_utl_cube_arith_create(cpl_plugin * plugin)
00139 {
00140     cpl_recipe      * recipe ;
00141     cpl_parameter   * p ;
00142 
00143     /* Get the recipe out of the plugin */
00144     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
00145         recipe = (cpl_recipe *)plugin ;
00146     else return -1 ;
00147     cpl_error_reset();
00148     irplib_reset();
00149     /* Create the parameters list in the cpl_recipe object */
00150     recipe->parameters = cpl_parameterlist_new() ; 
00151 
00152     /* Fill the parameters list */
00153     /* --stropt */
00154     p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube_arith.op", 
00155                                 CPL_TYPE_STRING, 
00156                                 "A possible operation: "
00157                                 "`/','*','+' or `-'", 
00158                                 "sinfoni.sinfo_utl_cube_arith","/");
00159     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "op") ;
00160     cpl_parameterlist_append(recipe->parameters, p) ;
00161 
00162 
00163     /* --doubleopt */
00164     /*
00165     p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube_arith.temperature", 
00166                                  CPL_TYPE_DOUBLE, "Black Body Temperature", 
00167                                  "sinfoni.sinfo_utl_cube_arith", 100000.) ;
00168     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "temp") ;
00169     cpl_parameterlist_append(recipe->parameters, p) ;
00170     */
00171 
00172     p = cpl_parameter_new_value("sinfoni.sinfo_utl_cube_arith.value", 
00173                                 CPL_TYPE_DOUBLE, "A constant to add", 
00174                                 "sinfoni.sinfo_utl_cube_arith", 99999.0) ;
00175     cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "value") ;
00176     cpl_parameterlist_append(recipe->parameters, p) ;
00177  
00178     /* Return */
00179     return 0;
00180 }
00181 
00182 /*---------------------------------------------------------------------------*/
00188 /*---------------------------------------------------------------------------*/
00189 static int sinfo_utl_cube_arith_exec(cpl_plugin * plugin)
00190 {
00191     cpl_recipe  *   recipe ;
00192     int code=0;
00193     cpl_errorstate initial_errorstate = cpl_errorstate_get();
00194 
00195     /* Get the recipe out of the plugin */
00196     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
00197         recipe = (cpl_recipe *)plugin ;
00198     else return -1 ;
00199       sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d",
00200         SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
00201 
00202     code = sinfo_utl_cube_arith(recipe->parameters, recipe->frames) ;
00203 
00204     if (!cpl_errorstate_is_equal(initial_errorstate)) {                      
00205         /* Dump the error history since recipe execution start.                
00206            At this point the recipe cannot recover from the error */           
00207         cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);              
00208     } 
00209     return code;
00210 }
00211 
00212 /*---------------------------------------------------------------------------*/
00218 /*---------------------------------------------------------------------------*/
00219 static int sinfo_utl_cube_arith_destroy(cpl_plugin * plugin)
00220 {
00221     cpl_recipe  *   recipe ;
00222 
00223     /* Get the recipe out of the plugin */
00224     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE) 
00225         recipe = (cpl_recipe *)plugin ;
00226     else return -1 ;
00227 
00228     cpl_parameterlist_delete(recipe->parameters) ; 
00229     return 0 ;
00230 }

Generated on 3 Mar 2013 for SINFONI Pipeline Reference Manual by  doxygen 1.6.1