sinfo_utl_eff.c

00001 /* $Id: sinfo_utl_eff.c,v 1.7 2010/02/18 19:14:41 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: 2010/02/18 19:14:41 $
00024  * $Revision: 1.7 $
00025  * $Log: sinfo_utl_eff.c,v $
00026  * Revision 1.7  2010/02/18 19:14:41  amodigli
00027  * some bug fixes
00028  *
00029  * Revision 1.6  2010/02/08 07:14:34  amodigli
00030  * changed sinfo_utl_efficiency API
00031  *
00032  * Revision 1.5  2009/12/15 15:07:32  kmirny
00033  * efficiency update
00034  *
00035  * Revision 1.4  2009/07/27 12:37:43  amodigli
00036  * removed parlist from sinfo_utl_efficiency() API as not used
00037  *
00038  * Revision 1.3  2009/07/14 14:45:03  kmirny
00039  * new recipe parameters
00040  *
00041  * Revision 1.2  2009/06/12 14:20:20  kmirny
00042  * updating SINFONI efficiency calculation
00043  *
00044  * Revision 1.1  2009/06/10 14:57:14  kmirny
00045  * sinfoni efficiency utility recipe
00046  *
00047  */
00048 
00049 #ifdef HAVE_CONFIG_H
00050 #include <config.h>
00051 #endif
00052 
00053 /*-----------------------------------------------------------------------------
00054                                 Includes
00055  ----------------------------------------------------------------------------*/
00056 #include <string.h>
00057 
00058 /* cpl */
00059 #include <cpl.h>
00060 
00061 /* irplib */
00062 #include <irplib_utils.h>
00063 
00064 #include <sinfo_tpl_utils.h>
00065 #include <sinfo_pfits.h>
00066 #include <sinfo_tpl_dfs.h>
00067 #include <sinfo_key_names.h>
00068 #include <sinfo_pro_types.h>
00069 #include <sinfo_ref_types.h>
00070 #include <sinfo_functions.h>
00071 #include <sinfo_msg.h>
00072 #include <sinfo_error.h>
00073 #include <sinfo_utils_wrappers.h>
00074 #include <sinfo_utl_efficiency.h>
00075 
00076 /*-----------------------------------------------------------------------------
00077                             Functions prototypes
00078  ----------------------------------------------------------------------------*/
00079 
00080 static int sinfo_utl_eff_create(cpl_plugin *) ;
00081 static int sinfo_utl_eff_exec(cpl_plugin *) ;
00082 static int sinfo_utl_eff_destroy(cpl_plugin *) ;
00083 static int sinfo_utl_eff(cpl_parameterlist *, cpl_frameset *) ;
00084 
00085 /*-----------------------------------------------------------------------------
00086                             Static variables
00087  ----------------------------------------------------------------------------*/
00088 
00089 static char sinfo_utl_eff_description[] =
00090 "This recipe calculate a efficiency\n"
00091 "esorex --params sinfo_utl_eff\n"
00092 "esorex --help sinfo_utl_eff\n"
00093 "\n";
00094 
00095 
00096 
00097 /*-----------------------------------------------------------------------------
00098                                 Functions code
00099  ----------------------------------------------------------------------------*/
00100 /*---------------------------------------------------------------------------*/
00104 /*---------------------------------------------------------------------------*/
00105 
00107 /*---------------------------------------------------------------------------*/
00115 /*---------------------------------------------------------------------------*/
00116 int cpl_plugin_get_info(cpl_pluginlist * list)
00117 {
00118     cpl_recipe  *   recipe = cpl_calloc(1, sizeof *recipe ) ;
00119     cpl_plugin  *   plugin = &recipe->interface ;
00120 
00121     cpl_plugin_init(plugin,
00122                     CPL_PLUGIN_API,
00123                     SINFONI_BINARY_VERSION,
00124                     CPL_PLUGIN_TYPE_RECIPE,
00125                     "sinfo_utl_eff",
00126                     "Produce a table with efficiency",
00127                     sinfo_utl_eff_description,
00128                     "Konstantin Mirny",
00129                     "kmirny@eso.org",
00130                     sinfo_get_license(),
00131                     sinfo_utl_eff_create,
00132                     sinfo_utl_eff_exec,
00133                     sinfo_utl_eff_destroy) ;
00134 
00135     cpl_pluginlist_append(list, plugin) ;
00136 
00137     return 0;
00138 }
00139 
00140 /*---------------------------------------------------------------------------*/
00149 /*---------------------------------------------------------------------------*/
00150 static int sinfo_utl_eff_create(cpl_plugin * plugin)
00151 {
00152     cpl_recipe      * recipe ;
00153 
00154     /* Get the recipe out of the plugin */
00155     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00156         recipe = (cpl_recipe *)plugin ;
00157     else return -1 ;
00158     cpl_error_reset();
00159     irplib_reset();
00160 
00161     /* Create the parameters list in the cpl_recipe object */
00162     recipe->parameters = cpl_parameterlist_new() ;
00163 
00164     /* Fill the parameters list */
00165 
00166 
00167         /* Return */
00168     return 0;
00169 }
00170 
00171 /*---------------------------------------------------------------------------*/
00177 /*---------------------------------------------------------------------------*/
00178 static int sinfo_utl_eff_exec(cpl_plugin * plugin)
00179 {
00180     cpl_recipe  *   recipe ;
00181      int code=0;
00182      cpl_errorstate initial_errorstate = cpl_errorstate_get();
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     cpl_error_reset();
00189     irplib_reset();
00190     code = sinfo_utl_eff(recipe->parameters, recipe->frames) ;
00191 
00192 
00193     if (!cpl_errorstate_is_equal(initial_errorstate)) {
00194         /* Dump the error history since recipe execution start.
00195            At this point the recipe cannot recover from the error */
00196         cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
00197     }
00198 
00199     return code ;
00200 }
00201 
00202 /*---------------------------------------------------------------------------*/
00208 /*---------------------------------------------------------------------------*/
00209 static int sinfo_utl_eff_destroy(cpl_plugin * plugin)
00210 {
00211     cpl_recipe  *   recipe ;
00212 
00213     /* Get the recipe out of the plugin */
00214     if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00215         recipe = (cpl_recipe *)plugin ;
00216     else return -1 ;
00217 
00218     cpl_parameterlist_delete(recipe->parameters) ;
00219     return 0 ;
00220 }
00221 
00222 /*---------------------------------------------------------------------------*/
00229 /*---------------------------------------------------------------------------*/
00230 static int
00231 sinfo_utl_eff( cpl_parameterlist   *   parlist,
00232                cpl_frameset        *   framelist)
00233 {
00234 
00235    const char          *   name_o = NULL ;
00236 
00237    cpl_frame*               product_frame = 0;
00238    cpl_propertylist    *   plist = NULL ;
00239    int pos = 0;
00240    int npos = 0;
00241    cpl_frame* frm_sci=NULL;
00242    cpl_frame* frm_atm_ext=NULL;
00243    cpl_frame* frm_std_cat=NULL;
00244    cpl_table* eff_tbl=NULL;
00245 
00246    sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d",
00247              SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
00248    ck0(sinfo_dfs_set_groups(framelist),"Cannot indentify RAW and CALIB frames");
00249 
00250    /* HOW TO GET THE VALUE OF A FITS KEYWORD */
00251    check(plist=cpl_propertylist_new(),"Cannot create a Property List");
00252 
00253 
00254    /* Now performing the data reduction */
00255    name_o = "eff_res.fits" ;
00256 
00257    check_nomsg(frm_sci=cpl_frameset_find (framelist, PRO_STD_STAR_SPECTRA));
00258    check_nomsg(frm_std_cat=cpl_frameset_find (framelist, FLUX_STD_CATALOG));
00259    check_nomsg(frm_atm_ext=cpl_frameset_find (framelist, EXTCOEFF_TABLE));
00260    sinfo_msg("frm_sci=%p frm_std=%p frm_atm_ext=%p",frm_sci,frm_std_cat,frm_atm_ext);
00261    check_nomsg(eff_tbl=sinfo_efficiency_compute(frm_sci,frm_std_cat,frm_atm_ext));
00262    npos = cpl_frameset_get_size(framelist);
00263    for (pos = 0; pos < npos; pos++)
00264    {
00265       cpl_frame* pframe = cpl_frameset_get_frame(framelist, pos);
00266       cpl_frame_group group = cpl_frame_get_group(pframe);
00267       if (CPL_FRAME_GROUP_PRODUCT == group)
00268       {
00269          check_nomsg(cpl_frame_set_group (pframe, CPL_FRAME_GROUP_CALIB));
00270       }
00271    }
00272    /* Create product frame */
00273    check_nomsg(product_frame = cpl_frame_new());
00274    check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
00275    check_nomsg(cpl_frame_set_tag(product_frame,"sinfo_efficiency" )) ;
00276    check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_TABLE)) ;
00277    check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT)) ;
00278    check(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL),
00279          "Error while initialising the product frame") ;
00280 
00281    /* Add DataFlow keywords */
00282    check_nomsg(cpl_propertylist_erase_regexp(plist, "^ESO PRO CATG",0));
00283    /* Log the saved file in the input frameset */
00284    check_nomsg(cpl_frameset_insert(framelist, product_frame)) ;
00285    check(cpl_dfs_setup_product_header(plist,
00286                                       product_frame,
00287                                       framelist,
00288                                       parlist,
00289                                       "sinfo_utl_eff",
00290                                       "SINFONI",
00291                                       KEY_VALUE_HPRO_DID,NULL),
00292          "Problem in the product DFS-compliance") ;
00293    sinfo_free_propertylist(&plist) ;
00294 
00295   cleanup:
00296    sinfo_free_propertylist(&plist) ;
00297    return (cpl_error_get_code()) ? -1 : 0;
00298 }

Generated on 8 Mar 2011 for SINFONI Pipeline Reference Manual by  doxygen 1.6.1