Main Page   File List  

visir_util_inputs.c

00001 /* $Id: visir_util_inputs.c,v 1.30 2006/01/04 16:27:23 llundin Exp $
00002  *
00003  * This file is part of the VISIR 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., 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA
00019  */
00020 
00021 /*
00022  * $Author: llundin $
00023  * $Date: 2006/01/04 16:27:23 $
00024  * $Revision: 1.30 $
00025  * $Name:  $
00026  */
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031 
00032 /*-----------------------------------------------------------------------------
00033                                 Includes
00034  -----------------------------------------------------------------------------*/
00035 
00036 #include <cpl.h>
00037 
00038 #include "irplib_utils.h"
00039 
00040 #include "visir_utils.h"
00041 #include "visir_pfits.h"
00042 #include "visir_dfs.h"
00043 #include "visir_inputs.h"
00044 
00045 /*-----------------------------------------------------------------------------
00046                             Functions prototypes
00047  -----------------------------------------------------------------------------*/
00048 
00049 static int visir_util_inputs_create(cpl_plugin *);
00050 static int visir_util_inputs_exec(cpl_plugin *);
00051 static int visir_util_inputs_destroy(cpl_plugin *);
00052 static int visir_util_inputs(cpl_parameterlist *, cpl_frameset *);
00053 static int visir_util_inputs_save(const cpl_imagelist *,
00054                                   const cpl_parameterlist *, cpl_frameset *);
00055 
00056 /*-----------------------------------------------------------------------------
00057                             Static variables
00058  -----------------------------------------------------------------------------*/
00059 
00060 static const char * recipename = "visir_util_inputs";
00061 
00062 static struct {
00063     /* Inputs */
00064     char        nodding[512];
00065     int         rem_glitch;
00066     int         auto_bpm;
00067     int         purge_bad;
00068 
00069     /* Outputs */
00070 } visir_util_inputs_config;
00071 
00072 static char visir_util_inputs_description[] =
00073 "This recipe recombines the chopping cubes and creates the nodded images.\n";
00074 
00075 /*-----------------------------------------------------------------------------
00076                                 Functions code
00077  -----------------------------------------------------------------------------*/
00078 
00079 /*----------------------------------------------------------------------------*/
00088 /*----------------------------------------------------------------------------*/
00089 int cpl_plugin_get_info(cpl_pluginlist * list)
00090 {
00091     cpl_recipe  *   recipe = cpl_calloc(1, sizeof(*recipe));
00092     cpl_plugin  *   plugin = &recipe->interface;
00093 
00094 
00095     if (cpl_plugin_init(plugin,
00096                     CPL_PLUGIN_API,
00097                     VISIR_BINARY_VERSION,
00098                     CPL_PLUGIN_TYPE_RECIPE,
00099                     recipename,
00100                     "Inputs images conversion to nodded images",
00101                     visir_util_inputs_description,
00102                     "Lars Lundin",
00103                     PACKAGE_BUGREPORT,
00104                     visir_get_license(),
00105                     visir_util_inputs_create,
00106                     visir_util_inputs_exec,
00107                     visir_util_inputs_destroy)) return 1;
00108 
00109     if (cpl_pluginlist_append(list, plugin)) return 1;
00110     
00111     return 0;
00112 }
00113 
00114 /*----------------------------------------------------------------------------*/
00123 /*----------------------------------------------------------------------------*/
00124 static int visir_util_inputs_create(cpl_plugin * plugin)
00125 {
00126     cpl_recipe * recipe = (cpl_recipe *)plugin;
00127 
00128     /* Verify plugin type */
00129     if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) return 1;
00130 
00131     /* Create the parameters list in the cpl_recipe object */
00132     recipe->parameters = cpl_parameterlist_new();
00133 
00134     /* Fill the parameters list */
00135     return visir_parameter_set(recipe->parameters, recipename,
00136                                VISIR_PARAM_NODPOS | VISIR_PARAM_AUTOBPM |
00137                                VISIR_PARAM_GLITCH | VISIR_PARAM_PURGE );
00138 }
00139 
00140 /*----------------------------------------------------------------------------*/
00146 /*----------------------------------------------------------------------------*/
00147 static int visir_util_inputs_exec(cpl_plugin * plugin)
00148 {
00149     cpl_recipe * recipe = (cpl_recipe *)plugin;
00150 
00151     /* Verify plugin type */
00152     if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) return 1;
00153 
00154     return visir_util_inputs(recipe->parameters, recipe->frames);
00155 }
00156 
00157 /*----------------------------------------------------------------------------*/
00163 /*----------------------------------------------------------------------------*/
00164 static int visir_util_inputs_destroy(cpl_plugin * plugin)
00165 {
00166     cpl_recipe  *   recipe = (cpl_recipe *)plugin;
00167 
00168     /* Verify plugin type */
00169     if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) return 1;
00170     cpl_parameterlist_delete(recipe->parameters);
00171     return  0;
00172 }
00173 
00174 /*----------------------------------------------------------------------------*/
00181 /*----------------------------------------------------------------------------*/
00182 static int visir_util_inputs(cpl_parameterlist   *   parlist,
00183                              cpl_frameset        *   framelist)
00184 {
00185     cpl_parameter   *   par;
00186     const char      *   badpix;
00187     const char      *   flat;
00188     cpl_frameset    *   rawframes = NULL;
00189     cpl_imagelist   *   nodded = NULL;
00190     
00191 
00192     if (cpl_error_get_code()) return cpl_error_get_code();
00193 
00194     /* Retrieve input parameters */
00195     par = cpl_parameterlist_find(parlist, "visir.visir_util_inputs.nodding");
00196     strcpy(visir_util_inputs_config.nodding, cpl_parameter_get_string(par));
00197     par = cpl_parameterlist_find(parlist, "visir.visir_util_inputs.auto_bpm");
00198     visir_util_inputs_config.auto_bpm = cpl_parameter_get_bool(par);
00199     par = cpl_parameterlist_find(parlist, "visir.visir_util_inputs.rem_glitch");
00200     visir_util_inputs_config.rem_glitch = cpl_parameter_get_bool(par);
00201     par = cpl_parameterlist_find(parlist, "visir.visir_util_inputs.purge_bad");
00202     visir_util_inputs_config.purge_bad = cpl_parameter_get_bool(par);
00203 
00204 
00205     /* Identify the RAW and CALIB frames in the input frameset */
00206     skip_if (visir_dfs_set_groups(framelist));
00207 
00208     /* Objects observation */
00209     rawframes = irplib_frameset_extract(framelist, VISIR_UTIL_INPUTS_RAW);
00210     skip_if (rawframes == NULL);
00211     
00212     /* Bad pixels calibration file */
00213     badpix = irplib_frameset_find_file(framelist, VISIR_CALIB_BPM);
00214 
00215     /* Flatfield calibration file */
00216     flat = irplib_frameset_find_file(framelist, VISIR_CALIB_FLAT);
00217 
00218 
00219     /* Combine the frames */
00220     cpl_msg_info(__func__, "Construct the nodded images");
00221     nodded = visir_inputs_combine(rawframes, badpix, flat,
00222                                   visir_util_inputs_config.nodding,
00223                                   visir_util_inputs_config.auto_bpm,
00224                                   visir_util_inputs_config.rem_glitch,
00225                                   visir_util_inputs_config.purge_bad,
00226                                   NULL,
00227                                    CPL_FALSE, 0,0, 0,0,0,0);
00228     if (nodded == NULL) {
00229         cpl_msg_error(__func__, "Cannot combine the input frames");
00230         skip_if(1);
00231     }
00232 
00233     /* Save the nodded images */
00234     cpl_msg_info(__func__, "Save the results");
00235     if (visir_util_inputs_save(nodded, parlist, framelist)) {
00236         cpl_msg_error(__func__, "Cannot save products");
00237         skip_if(1);
00238     }
00239 
00240     end_skip;
00241 
00242     cpl_frameset_delete(rawframes);
00243 
00244     cpl_imagelist_delete(nodded);
00245 
00246     return cpl_error_get_code();
00247 }
00248 
00249 /*----------------------------------------------------------------------------*/
00257 /*----------------------------------------------------------------------------*/
00258 static int visir_util_inputs_save(const cpl_imagelist     * nodded,
00259                                   const cpl_parameterlist * parlist,
00260                                   cpl_frameset            * set)
00261 {
00262 
00263     int i;
00264 
00265 
00266     skip_if (nodded == NULL);
00267    
00268     /* Save all the images of the image set */
00269     for (i=0 ; i < cpl_imagelist_get_size(nodded) ; i++) {
00270         char digits[6]; /* A ridicously high limit */
00271         /* Set the extension of the base name of the file */
00272         const int nlen =  snprintf(digits, 6, "%d", i+1);
00273 
00274         skip_if (nlen < 1 || nlen >= 6);
00275 
00276         skip_if (visir_image_save(parlist, set, cpl_imagelist_get(nodded, i),
00277                                   recipename,
00278                                   VISIR_UTIL_INPUTS_COMBINED_PROCATG,
00279                                   NULL, digits));
00280     }
00281 
00282     end_skip;
00283 
00284     return cpl_error_get_code();
00285 }

Generated on Mon Jan 23 12:16:37 2006 for VISIR Pipeline Reference Manual by doxygen1.2.18