si_rec_scicubecreate.c

00001 /* $Id: si_rec_scicubecreate.c,v 1.11 2005/10/08 10:34:50 amodigli Exp $
00002  *
00003  * This file is part of the CPL (Common Pipeline Library)
00004  * Copyright (C) 2002 European Southern Observatory
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library 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 GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 /*
00021  * $Author: amodigli $
00022  * $Date: 2005/10/08 10:34:50 $
00023  * $Revision: 1.11 $
00024  * $Name:  $
00025  */
00026 
00027  /****************************************************************
00028   *           Object Data reduction                              *
00029   ****************************************************************/
00030 #include <strings.h>
00031 #include <string.h>
00032 #include <stdio.h>
00033 
00034 /*-----------------------------------------------------------------------------
00035                                 Includes
00036  -----------------------------------------------------------------------------*/
00037 
00038 #ifdef HAVE_CONFIG_H
00039 #include <config.h>          /* allows the program compilation */
00040 #endif
00041 #include <cxmacros.h>
00042 #include <cxtypes.h>
00043 #include <cxmessages.h>     /* defines message level types */
00044 #include <cpl_memory.h>       /* defines memory allocation functions */
00045 
00046 #include <cpl_parameterlist.h>    /* defines parlist structure */
00047 #include <cpl_msg.h>  /* defines different messaging functions */
00048 
00049 
00050 #include <cpl_recipe.h>     /* recipe plugin definitions */
00051 #include <cpl_plugin.h>     /* memory allocations functions */
00052 #include <cpl_pluginlist.h> /* memory allocations functions */
00053 #include <cpl_frameset.h>   /* defines operations on frames */
00054 #include <sinfoni_pro_types.h>
00055 
00056 #include <sinfoni_general_config.h>
00057 #include <sinfoni_fake_config.h>
00058 #include <sinfoni_prepare_stacked_frames_config.h>
00059 #include <sinfoni_cube_create_config.h>
00060 #include <prepare_stacked_frames.h>
00061 #include <cubecreate.h>
00062 #include <create_resampled.h>
00063 #include <sinfoni_tpl_utils.h>
00064 #include <sinfoni_tpl_dfs.h>
00065 #include <sinfoni_memory.h>
00066 
00067 /*-----------------------------------------------------------------------------
00068                             Functions prototypes
00069  -----------------------------------------------------------------------------*/
00070 
00071 static cxint si_rec_scicubecreate(cpl_parameterlist *, cpl_frameset *);
00072 
00073 
00074 const char * sinfoni_get_licence(void);
00075 cxint si_rec_scicubecreate_create(cpl_plugin *plugin);
00076 cxint si_rec_scicubecreate_exec(cpl_plugin *plugin);
00077 cxint si_rec_scicubecreate_destroy(cpl_plugin *plugin);
00078 static cxint si_rec_scicubecreate(cpl_parameterlist *config, cpl_frameset *set);
00079 int cpl_plugin_get_info(cpl_pluginlist *list);
00080 
00081 /*-----------------------------------------------------------------------------
00082                             Static variables
00083  -----------------------------------------------------------------------------*/
00084 
00085 static char si_rec_scibubecreate_description[] =
00086 "This recipe performs science data reduction.\n"
00087 "The input files are science object and sky frames with tags OBJECT_NODDING and SKY_NODDING\n"
00088 "Master calibration frames:\n"
00089 "A corresponding (band,preoptics) wavelength map image with tag WAVE_MAP\n"
00090 "A corresponding (band,preoptics) master flat field with tag MASTER_FLAT_LAMP\n"
00091 "A corresponding (band,preoptics) master bad pixel map with tag MASTER_BP_MAP\n"
00092 "A corresponding (band,preoptics) slitlets position frame with tag SLIT_POS\n"
00093 "A corresponding (band) distortion table with tag DISTORTION\n"
00094 "A corresponding (band) slitlet distance table with tag SLITLETS_DISTANCE\n"
00095 "The output is an image resulting from the IMA1 op IMA2 where op indicates\n"
00096 "A reference table with the position of the first  column with tag FIRST_COLUMN\n"
00097 "Relevant outputs are:\n"
00098 "combined cubes (PRO.CATG=x_OBS x=STD,OBJ,PSF)\n"
00099 "reconstructed cube (PRO.CATG=COADD_x_OBS x=STD,OBJ,PSF)\n"
00100 "An average along Z of the reconstructed cube (PRO.CATG=MED_x_OBS x=STD,OBJ,PSF)\n"
00101 "The bad pixel map associated to the cube (PRO.CATG=BP_MAP_COADD_x_OBS x=STD,OBJ,PSF)\n"
00102 "Information on relevant parameters can be found with"
00103 "esorex --params si_rec_scicubecreate"
00104 "esorex --help si_rec_scicubecreate"
00105 "\n";
00106 
00107 /*-----------------------------------------------------------------------------
00108                                 Functions code
00109  -----------------------------------------------------------------------------*/
00110 
00111 cxint
00112 si_rec_scicubecreate_create(cpl_plugin *plugin)
00113 {
00114 
00115   /*
00116    * We have to provide the option we accept to the application.
00117    * We need to setup our parameter list and hook it into the recipe
00118    * interface.
00119    */
00120   cpl_recipe *recipe = (cpl_recipe *)plugin;
00121   recipe->parameters = cpl_parameterlist_new();
00122   if(recipe->parameters == NULL) {
00123     return 1;
00124   }
00125 
00126   /*
00127    * Fill the parameter list.
00128    */
00129   sinfoni_general_config_add(recipe->parameters);
00130   sinfoni_prepare_stacked_frames_config_add(recipe->parameters);
00131   sinfoni_cubecreate_config_add(recipe->parameters); 
00132   sinfoni_fake_config_add(config);
00133   return 0;
00134 
00135 }
00136 
00137 cxint
00138 si_rec_scicubecreate_exec(cpl_plugin *plugin)
00139 {
00140  
00141   cpl_recipe *recipe = (cpl_recipe *) plugin;
00142   if(recipe->parameters == NULL) {
00143     return 1;
00144   }
00145   if(recipe->frames == NULL) {
00146     return 1;
00147   }
00148   cpl_error_reset();
00149   return si_rec_scicubecreate(recipe->parameters, recipe->frames);
00150 
00151 }
00152 
00153 cxint
00154 si_rec_scicubecreate_destroy(cpl_plugin *plugin)
00155 {
00156   cpl_recipe *recipe = (cpl_recipe *) plugin;
00157   /*
00158    * We just destroy what was created during the plugin initializzation phase
00159    * i.e. the parameter list. The frame set is managed by the application which
00160    * called us, so that we must not touch it.
00161    */
00162 
00163   cpl_parameterlist_delete(recipe->parameters);
00164 
00165   return 0;
00166 
00167 }
00168 
00169 
00170 int
00171 cpl_plugin_get_info(cpl_pluginlist *list)
00172 {
00173 
00174   cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
00175   cpl_plugin *plugin = &recipe->interface;
00176 
00177   cpl_plugin_init(plugin,
00178           CPL_PLUGIN_API,
00179           SINFONI_BINARY_VERSION,
00180           CPL_PLUGIN_TYPE_RECIPE,
00181           "si_rec_scicubecreate",
00182           "Science data reduction",
00183           si_rec_scicubecreate_description,
00184           "Andrea Modigliani",
00185           "Andrea.Modigliani@eso.org",
00186           sinfoni_get_licence(),
00187           si_rec_scicubecreate_create,
00188           si_rec_scicubecreate_exec,
00189           si_rec_scicubecreate_destroy);
00190 
00191   cpl_pluginlist_append(list, plugin);
00192 
00193   return 0;
00194 
00195 }
00196 
00197 
00198 /*
00199  * The actual recipe actually start here.
00200  */
00201 
00202 static cxint
00203 si_rec_scicubecreate(cpl_parameterlist *config, cpl_frameset *set)
00204 {
00205   const cxchar *_id = "si_rec_scicubecreate";
00206    char name_s   [FILE_NAME_SZ];
00207   int  ind =0;
00208   cpl_parameter *p;                    
00209 
00210   /* 
00211    cpl_parameterlist_dump(config); 
00212   */
00213    if(sinfoni_dfs_set_groups(set)) {
00214        cpl_msg_error(_id, "Cannot indentify RAW and CALIB frames") ;
00215        return -1;
00216    }
00217 
00218      /* =============================================================== 
00219         ARC LAMP FRAMES STACKING 
00220         =============================================================== */
00221 
00222     {
00223     cpl_msg_info (_id,"running") ; 
00224         if ( -1 == (ind = prepare_stacked_frames(config, set, PRO_WAVE_LAMP_STACKED ) ) )
00225         {
00226         cpl_msg_error(_id," no: %d\n", ind) ;
00227         return -1 ;
00228     }
00229     cpl_msg_info (_id,"success") ; 
00230     }    
00231 
00232 
00233      /* =============================================================== 
00234         SCI CUBE GENERATION 
00235         =============================================================== */
00236 
00237      p = cpl_parameterlist_find(config, "sinfoni.cubecreate.method");
00238      strcpy(name_s, cpl_parameter_get_string(p));
00239      cpl_msg_info(_id,"Method=%s\n",name_s);
00240 
00241 
00242     {
00243     if ( 0 == strcmp(name_s,"Normal") )
00244     {
00245             cpl_msg_info(_id,"Running");
00246             if ( -1 == (ind = cubecreate( config, set ) ) )
00247         {
00248             cpl_msg_error(_id,"no: %d\n", ind) ;
00249         return -1 ;
00250         }
00251             else
00252         {
00253           cpl_msg_info(_id,"success");
00254         }
00255     }
00256     else if ( 0 == strcmp (name_s, "Resampled") )
00257     {
00258             cpl_msg_info(_id,"Running");
00259         if ( -1 == (ind = create_resampled( config, set ) ) )
00260         {
00261             cpl_msg_error(_id,"no: %d\n", ind) ;
00262         return -1 ;
00263         }
00264             cpl_msg_info(_id,"success");
00265     }
00266     else
00267     {
00268         cpl_msg_error(_id,"wrong name recipe method given!\n") ;
00269         return -1 ;
00270     }
00271     }    
00272     return 0 ;
00273 
00274 }
00275 
00276 

Generated on Wed Oct 26 13:08:54 2005 for SINFONI Pipeline Reference Manual by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001