visir_util_inputs.c

00001 /* $Id: visir_util_inputs.c,v 1.56 2010/07/22 11:52:28 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: 2010/07/22 11:52:28 $
00024  * $Revision: 1.56 $
00025  * $Name: HEAD $
00026  */
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031 
00032 /*-----------------------------------------------------------------------------
00033                                 Includes
00034  -----------------------------------------------------------------------------*/
00035 
00036 #include "visir_recipe.h"
00037 
00038 
00039 
00040 /*-----------------------------------------------------------------------------
00041                                 Defines
00042  -----------------------------------------------------------------------------*/
00043 
00044 #define RECIPE_STRING   "visir_util_inputs"
00045 
00046 /*-----------------------------------------------------------------------------
00047                             Private Functions prototypes
00048  -----------------------------------------------------------------------------*/
00049 
00050 static cpl_error_code visir_util_inputs_save(cpl_frameset *,
00051                                              const cpl_parameterlist *,
00052                                              const cpl_imagelist *);
00053 
00054 VISIR_RECIPE_DEFINE(visir_util_inputs,
00055                     VISIR_PARAM_NODPOS | VISIR_PARAM_AUTOBPM |  
00056                     VISIR_PARAM_STRIPITE | VISIR_PARAM_STRIPMOR |
00057                     VISIR_PARAM_GLITCH | VISIR_PARAM_PURGE,
00058                     "Conversion of raw images to nodded images",
00059                     "The files listed in the Set Of Frames (sof-file) "
00060                     "must be tagged:\n"
00061                     "VISIR-raw-file.fits " VISIR_UTIL_INPUTS_RAW
00062                     "\nAdditionally, a bad pixel map\n"
00063                     "may be added to the Set Of Frames "
00064                     "with tag: " VISIR_CALIB_BPM "."
00065                     "\nAdditionally, a flat field\n"
00066                     "may be added to the Set Of Frames "
00067                     "with tag: " VISIR_CALIB_FLAT ".\n"
00068                     "\nThe product(s) will have a FITS card\n"
00069                     "'HIERARCH ESO PRO CATG' with a value of:\n"
00070                     VISIR_UTIL_INPUTS_COMBINED_PROCATG);
00071 
00072 /*----------------------------------------------------------------------------*/
00076 /*----------------------------------------------------------------------------*/
00077 
00078 /*-----------------------------------------------------------------------------
00079                                 Functions code
00080  -----------------------------------------------------------------------------*/
00081 
00082 /*----------------------------------------------------------------------------*/
00089 /*----------------------------------------------------------------------------*/
00090 static int visir_util_inputs(cpl_frameset            * framelist,
00091                              const cpl_parameterlist * parlist)
00092 {
00093     irplib_framelist * allframes = NULL;
00094     irplib_framelist * rawframes = NULL;
00095     const char      *   badpix;
00096     const char      *   flat;
00097     cpl_imagelist   *   nodded = NULL;
00098     
00099 
00100     /* Identify the RAW and CALIB frames in the input frameset */
00101     skip_if (visir_dfs_set_groups(framelist));
00102 
00103     /* Objects observation */
00104     allframes = irplib_framelist_cast(framelist);
00105     skip_if(allframes == NULL);
00106     rawframes = irplib_framelist_extract(allframes, VISIR_UTIL_INPUTS_RAW);
00107     skip_if (rawframes == NULL);
00108     
00109     /* Bad pixels calibration file */
00110     badpix = irplib_frameset_find_file(framelist, VISIR_CALIB_BPM);
00111 
00112     /* Flatfield calibration file */
00113     flat = irplib_frameset_find_file(framelist, VISIR_CALIB_FLAT);
00114 
00115     skip_if(irplib_framelist_load_propertylist_all(rawframes, 0,
00116                                                    visir_property_regexp,
00117                                                    CPL_FALSE));
00118 
00119     /* Combine the frames */
00120     cpl_msg_info(cpl_func, "Construct the nodded images");
00121     nodded = visir_inputs_combine(RECIPE_STRING, parlist, rawframes, badpix, flat,
00122                                   NULL, CPL_FALSE, 0.0, 0);
00123     if (nodded == NULL) {
00124         cpl_msg_error(cpl_func, "Cannot combine the input frames");
00125         skip_if(1);
00126     }
00127 
00128     /* Save the nodded images */
00129     cpl_msg_info(cpl_func, "Save the results");
00130     skip_if (visir_util_inputs_save(framelist, parlist, nodded));
00131 
00132     end_skip;
00133 
00134     irplib_framelist_delete(allframes);
00135     irplib_framelist_delete(rawframes);
00136 
00137     cpl_imagelist_delete(nodded);
00138 
00139     return cpl_error_get_code();
00140 }
00141 
00142 /*----------------------------------------------------------------------------*/
00150 /*----------------------------------------------------------------------------*/
00151 static cpl_error_code visir_util_inputs_save(cpl_frameset            * set,
00152                                              const cpl_parameterlist * parlist,
00153                                              const cpl_imagelist     * nodded)
00154 {
00155 
00156     int    i;
00157     char * filename = NULL;
00158 
00159 
00160     bug_if (nodded == NULL);
00161    
00162     /* Save all the images of the image set */
00163     for (i=0 ; i < cpl_imagelist_get_size(nodded) ; i++) {
00164         cpl_free(filename);
00165         filename = cpl_sprintf(RECIPE_STRING "%d" CPL_DFS_FITS, i+1);
00166         skip_if (irplib_dfs_save_image(set, parlist, set,
00167                                    cpl_imagelist_get_const(nodded, i),
00168                                    CPL_BPP_IEEE_FLOAT, RECIPE_STRING,
00169                                    VISIR_UTIL_INPUTS_COMBINED_PROCATG,
00170                                    NULL, NULL, visir_pipe_id, filename));
00171     }
00172 
00173     end_skip;
00174 
00175     cpl_free(filename);
00176 
00177     return cpl_error_get_code();
00178 }

Generated on Thu Mar 24 11:59:40 2011 for VISIR Pipeline Reference Manual by  doxygen 1.5.8