uves_tflat_impl.c

00001 /*                                                                              *
00002  *   This file is part of the ESO UVES Pipeline                                 *
00003  *   Copyright (C) 2004,2005 European Southern Observatory                      *
00004  *                                                                              *
00005  *   This library is free software; you can redistribute it and/or modify       *
00006  *   it under the terms of the GNU General Public License as published by       *
00007  *   the Free Software Foundation; either version 2 of the License, or          *
00008  *   (at your option) any later version.                                        *
00009  *                                                                              *
00010  *   This program is distributed in the hope that it will be useful,            *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of             *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
00013  *   GNU General Public License for more details.                               *
00014  *                                                                              *
00015  *   You should have received a copy of the GNU General Public License          *
00016  *   along with this program; if not, write to the Free Software                *
00017  *   Foundation, 51 Franklin St, Fifth Floor, Boston, MA  02111-1307  USA       *
00018  *                                                                              */
00019  
00020 /*
00021  * $Author: amodigli $
00022  * $Date: 2007/10/05 16:01:45 $
00023  * $Revision: 1.18 $
00024  * $Name: uves-3_4_5 $
00025  * $Log: uves_tflat_impl.c,v $
00026  * Revision 1.18  2007/10/05 16:01:45  amodigli
00027  * using proces_chip parameter to process or not a given RED chip
00028  *
00029  * Revision 1.17  2007/08/21 13:08:26  jmlarsen
00030  * Removed irplib_access module, largely deprecated by CPL-4
00031  *
00032  * Revision 1.16  2007/06/11 13:28:26  jmlarsen
00033  * Changed recipe contact address to cpl at eso.org
00034  *
00035  * Revision 1.15  2007/06/08 13:06:16  jmlarsen
00036  * Send bug reports to Andrea
00037  *
00038  * Revision 1.14  2007/06/06 08:17:33  amodigli
00039  * replace tab with 4 spaces
00040  *
00041  * Revision 1.13  2007/05/14 08:09:48  amodigli
00042  * updated input frames and tag description in recipe man page
00043  *
00044  * Revision 1.12  2007/02/09 13:44:30  jmlarsen
00045  * Use defines for recipe id
00046  *
00047  * Revision 1.11  2007/02/09 09:00:06  jmlarsen
00048  * Use defines rather than hard-coded recipe names
00049  *
00050  * Revision 1.10  2006/11/15 15:02:15  jmlarsen
00051  * Implemented const safe workarounds for CPL functions
00052  *
00053  * Revision 1.8  2006/11/15 14:04:08  jmlarsen
00054  * Removed non-const version of parameterlist_get_first/last/next which is
00055  * already in CPL, added const-safe wrapper, unwrapper and deallocator functions
00056  *
00057  * Revision 1.7  2006/11/13 12:48:35  jmlarsen
00058  * Changed interface of uves_reduce_mflat to support FLAMES
00059  *
00060  * Revision 1.6  2006/11/06 15:19:42  jmlarsen
00061  * Removed unused include directives
00062  *
00063  * Revision 1.5  2006/10/17 12:33:02  jmlarsen
00064  * Added semicolon at UVES_RECIPE_DEFINE invocation
00065  *
00066  * Revision 1.4  2006/10/09 13:01:13  jmlarsen
00067  * Use macro to define recipe interface functions
00068  *
00069  * Revision 1.3  2006/10/02 08:33:36  jmlarsen
00070  * Re-tag MASTER_TFLAT as product after the science reduction
00071  *
00072  * Revision 1.2  2006/09/27 15:08:45  jmlarsen
00073  * Fixed doc. bug
00074  *
00075  * Revision 1.1  2006/09/27 13:23:38  jmlarsen
00076  * Added tflat recipe
00077  *
00078  */
00079 #ifdef HAVE_CONFIG_H
00080 #  include <config.h>
00081 #endif
00082 
00083 /*----------------------------------------------------------------------------*/
00089 /*----------------------------------------------------------------------------*/
00090 
00091 /*-----------------------------------------------------------------------------
00092                                 Includes
00093  -----------------------------------------------------------------------------*/
00094 
00095 #include <uves_reduce_mflat.h>
00096 #include <uves_reduce_scired.h>
00097 #include <uves_parameters.h>
00098 #include <uves_utils_wrappers.h>
00099 #include <uves_dfs.h>
00100 #include <uves_recipe.h>
00101 #include <uves.h>
00102 #include <uves_error.h>
00103 #include <uves_msg.h>
00104 
00105 #include <cpl.h>
00106 
00107 /*-----------------------------------------------------------------------------
00108                             Functions prototypes
00109  -----------------------------------------------------------------------------*/
00110 static int
00111 uves_tflat_define_parameters(cpl_parameterlist *parameters);
00112 
00113 /*-----------------------------------------------------------------------------
00114                             Recipe standard code
00115  -----------------------------------------------------------------------------*/
00116 #define cpl_plugin_get_info uves_tflat_get_info
00117 UVES_RECIPE_DEFINE(
00118     UVES_TFLAT_ID, UVES_TFLAT_DOM, uves_tflat_define_parameters,
00119     "Jonas M. Larsen", "cpl@eso.org",
00120     "Reduces a TFLAT frame",
00121     "This recipe reduces a TFLAT_xxx frame (xxx = BLUE,RED). This is\n"
00122     "achieved by\n"
00123     "1) combining all provided TFLAT frames to a MASTER_TFLAT frame, then\n"
00124     "2) doing a normal science reduction on the first input TFLAT frame\n"
00125     "Input frames are raw TFLAT_xxx  frames, and: \n"
00126     "order table(s) for each chip, ORDER_TABLE_xxxx (where xxxx=BLUE, REDL, REDU),\n"
00127     "line table(s) for each chip, LINE_TABLE_xxxx, a master bias frame,\n"
00128     "MASTER_BIAS_xxxx, a master flat, MASTER_FLAT_xxxx, \n");
00129 
00131 /*-----------------------------------------------------------------------------
00132                               Functions code
00133  -----------------------------------------------------------------------------*/
00134 /*----------------------------------------------------------------------------*/
00140 /*----------------------------------------------------------------------------*/
00141 static int
00142 uves_tflat_define_parameters(cpl_parameterlist *parameters)
00143 {
00144     /*****************
00145      *    General    *
00146      *****************/
00147     if (uves_define_global_parameters(parameters) != CPL_ERROR_NONE)
00148         {
00149             return -1;
00150         }
00151 
00152     /***********************************
00153      *  Spline back.sub. (master flat) *
00154      ***********************************/
00155     
00156     if (uves_propagate_parameters_step(UVES_BACKSUB_ID, parameters, 
00157                        make_str(UVES_TFLAT_ID), NULL) != 0)
00158     {
00159         return -1;
00160     }
00161 
00162     /*******************
00163      *  Reduce.        *
00164      ******************/
00165     if (uves_propagate_parameters_step(UVES_REDUCE_ID, parameters,
00166                                        make_str(UVES_TFLAT_ID), NULL) != 0)
00167         {
00168             return -1;
00169         }
00170 
00171     /* For TFLAT reduction: average extraction, no sky subtraction */
00172     {
00173     const char *param = "average";
00174     bool bool_param;
00175 
00176     if (uves_set_parameter_default(parameters, 
00177                        make_str(UVES_TFLAT_ID), "reduce.extract.method",
00178                        CPL_TYPE_STRING, &param) != CPL_ERROR_NONE)
00179         {
00180         return -1;
00181         }
00182 
00183     bool_param = false;
00184     if (uves_set_parameter_default(parameters, 
00185                        make_str(UVES_TFLAT_ID), "reduce.skysub",
00186                        CPL_TYPE_BOOL, &bool_param) != CPL_ERROR_NONE)
00187         {
00188         return -1;
00189         }
00190     }
00191     
00192     return (cpl_error_get_code() != CPL_ERROR_NONE);
00193 }
00194 
00195 /*----------------------------------------------------------------------------*/
00202 /*----------------------------------------------------------------------------*/
00203 static void
00204 IRPLIB_CONCAT2X(UVES_TFLAT_ID,exe)(cpl_frameset *frames,
00205                    const cpl_parameterlist *parameters, 
00206                    const char *starttime)
00207 {
00208     uves_msg("Creating master tflat");
00209     check_nomsg( uves_mflat_exe_body(frames, parameters, 
00210                      starttime,
00211                      make_str(UVES_TFLAT_ID)) );
00212 
00213     uves_msg("Reducing first raw tflat");
00214     check_nomsg( uves_reduce_scired(frames, parameters, make_str(UVES_TFLAT_ID), starttime) );
00215 
00216     /* The MASTER_TFLAT was reclassified as CALIB by the reduction step.
00217        But it is actually a product of this recipe, so retag it */
00218     {
00219       enum uves_chip chip;
00220       int blue;
00221       const char* PROCESS_CHIP=NULL;
00222       check( uves_get_parameter(parameters, NULL, "uves", "process_chip", CPL_TYPE_STRING, &PROCESS_CHIP),
00223          "Could not read parameter");
00224 
00225       /* Loop over all possible MASTER_TFLATs */
00226       for (blue = 0; blue <= 1; blue++)
00227         {
00228       for (chip = uves_chip_get_first(blue);
00229            chip != UVES_CHIP_INVALID;
00230            chip = uves_chip_get_next(chip))
00231             {
00232 
00233           if(strcmp(PROCESS_CHIP,"redu") == 0) {
00234         chip = uves_chip_get_next(chip);
00235           }
00236 
00237           cpl_frame *f = cpl_frameset_find(frames, UVES_MASTER_TFLAT(chip));
00238           if (f != NULL)
00239                 {
00240           cpl_frame_set_group(f, CPL_FRAME_GROUP_PRODUCT);
00241                 }
00242             
00243           f = cpl_frameset_find(frames, UVES_BKG_FLAT(chip));
00244           if (f != NULL)
00245                 {
00246           cpl_frame_set_group(f, CPL_FRAME_GROUP_PRODUCT);
00247                 }
00248             }
00249 
00250       if(strcmp(PROCESS_CHIP,"redl") == 0) {
00251         chip = uves_chip_get_next(chip);
00252       }
00253 
00254         }
00255     }
00256 
00257   cleanup:
00258     return;
00259 }
00260 

Generated on Thu Nov 15 14:32:31 2007 for UVES Pipeline Reference Manual by  doxygen 1.5.1