visir_util_inputs.c

00001 /* $Id: visir_util_inputs.c,v 1.54 2009/02/27 10:57:56 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: 2009/02/27 10:57:56 $
00024  * $Revision: 1.54 $
00025  * $Name: visir-3_2_2 $
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                     "This recipe recombines the chopping cubes and creates "
00060                     "the nodded images.\n");
00061 
00062 /*----------------------------------------------------------------------------*/
00066 /*----------------------------------------------------------------------------*/
00067 
00068 /*-----------------------------------------------------------------------------
00069                                 Functions code
00070  -----------------------------------------------------------------------------*/
00071 
00072 /*----------------------------------------------------------------------------*/
00079 /*----------------------------------------------------------------------------*/
00080 static int visir_util_inputs(cpl_frameset            * framelist,
00081                              const cpl_parameterlist * parlist)
00082 {
00083     irplib_framelist * allframes = NULL;
00084     irplib_framelist * rawframes = NULL;
00085     const char      *   badpix;
00086     const char      *   flat;
00087     cpl_imagelist   *   nodded = NULL;
00088     
00089 
00090     /* Identify the RAW and CALIB frames in the input frameset */
00091     skip_if (visir_dfs_set_groups(framelist));
00092 
00093     /* Objects observation */
00094     allframes = irplib_framelist_cast(framelist);
00095     skip_if(allframes == NULL);
00096     rawframes = irplib_framelist_extract(allframes, VISIR_UTIL_INPUTS_RAW);
00097     skip_if (rawframes == NULL);
00098     
00099     /* Bad pixels calibration file */
00100     badpix = irplib_frameset_find_file(framelist, VISIR_CALIB_BPM);
00101 
00102     /* Flatfield calibration file */
00103     flat = irplib_frameset_find_file(framelist, VISIR_CALIB_FLAT);
00104 
00105     skip_if(irplib_framelist_load_propertylist_all(rawframes, 0,
00106                                                    visir_property_regexp,
00107                                                    CPL_FALSE));
00108 
00109     /* Combine the frames */
00110     cpl_msg_info(cpl_func, "Construct the nodded images");
00111     nodded = visir_inputs_combine(RECIPE_STRING, parlist, rawframes, badpix, flat,
00112                                   NULL, CPL_FALSE, 0.0, 0);
00113     if (nodded == NULL) {
00114         cpl_msg_error(cpl_func, "Cannot combine the input frames");
00115         skip_if(1);
00116     }
00117 
00118     /* Save the nodded images */
00119     cpl_msg_info(cpl_func, "Save the results");
00120     skip_if (visir_util_inputs_save(framelist, parlist, nodded));
00121 
00122     end_skip;
00123 
00124     irplib_framelist_delete(allframes);
00125     irplib_framelist_delete(rawframes);
00126 
00127     cpl_imagelist_delete(nodded);
00128 
00129     return cpl_error_get_code();
00130 }
00131 
00132 /*----------------------------------------------------------------------------*/
00140 /*----------------------------------------------------------------------------*/
00141 static cpl_error_code visir_util_inputs_save(cpl_frameset            * set,
00142                                              const cpl_parameterlist * parlist,
00143                                              const cpl_imagelist     * nodded)
00144 {
00145 
00146     int    i;
00147     char * filename = NULL;
00148 
00149 
00150     bug_if (nodded == NULL);
00151    
00152     /* Save all the images of the image set */
00153     for (i=0 ; i < cpl_imagelist_get_size(nodded) ; i++) {
00154         cpl_free(filename);
00155         filename = irplib_sprintf(RECIPE_STRING "%d" CPL_DFS_FITS, i+1);
00156         skip_if (irplib_dfs_save_image(set, parlist, set,
00157                                    cpl_imagelist_get_const(nodded, i),
00158                                    CPL_BPP_IEEE_FLOAT, RECIPE_STRING,
00159                                    VISIR_UTIL_INPUTS_COMBINED_PROCATG,
00160                                    NULL, NULL, visir_pipe_id, filename));
00161     }
00162 
00163     end_skip;
00164 
00165     cpl_free(filename);
00166 
00167     return cpl_error_get_code();
00168 }

Generated on Fri Jul 3 11:15:24 2009 for VISIR Pipeline Reference Manual by  doxygen 1.5.8