UVES Pipeline Reference Manual  5.4.6
uves_tflat_impl.c
1 /* *
2  * This file is part of the ESO UVES Pipeline *
3  * Copyright (C) 2004,2005 European Southern Observatory *
4  * *
5  * This library is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the Free Software *
17  * Foundation, 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA *
18  * */
19 
20 /*
21  * $Author: amodigli $
22  * $Date: 2010-04-08 10:47:27 $
23  * $Revision: 1.26 $
24  * $Name: not supported by cvs2svn $
25  */
26 #ifdef HAVE_CONFIG_H
27 # include <config.h>
28 #endif
29 
30 /*----------------------------------------------------------------------------*/
36 /*----------------------------------------------------------------------------*/
37 
38 /*-----------------------------------------------------------------------------
39  Includes
40  -----------------------------------------------------------------------------*/
41 
42 #include <uves_reduce_mflat.h>
43 #include <uves_reduce_scired.h>
44 #include <uves_parameters.h>
45 #include <uves_utils_wrappers.h>
46 #include <uves_dfs.h>
47 #include <uves_recipe.h>
48 #include <uves.h>
49 #include <uves_error.h>
50 #include <uves_msg.h>
51 
52 #include <cpl.h>
53 #include <string.h>
54 /*-----------------------------------------------------------------------------
55  Functions prototypes
56  -----------------------------------------------------------------------------*/
57 static int
58 uves_tflat_define_parameters(cpl_parameterlist *parameters);
59 
60 /*-----------------------------------------------------------------------------
61  Recipe standard code
62  -----------------------------------------------------------------------------*/
63 #define cpl_plugin_get_info uves_tflat_get_info
64 UVES_RECIPE_DEFINE(
65  UVES_TFLAT_ID, UVES_TFLAT_DOM, uves_tflat_define_parameters,
66  "Jonas M. Larsen", "cpl@eso.org",
67  "Reduces a TFLAT frame",
68  "This recipe reduces a TFLAT_xxx frame (xxx = BLUE,RED). This is\n"
69  "achieved by\n"
70  "1) combining all provided TFLAT frames to a MASTER_TFLAT frame, then\n"
71  "2) doing a normal science reduction on the first input TFLAT frame\n"
72  "Input frames are raw TFLAT_xxx frames, and: \n"
73  "order table(s) for each chip, ORDER_TABLE_xxxx (where xxxx=BLUE, REDL, REDU),\n"
74  "line table(s) for each chip, LINE_TABLE_xxxx, a master bias frame,\n"
75  "MASTER_BIAS_xxxx, a master flat, MASTER_FLAT_xxxx, \n");
76 
78 /*-----------------------------------------------------------------------------
79  Functions code
80  -----------------------------------------------------------------------------*/
81 /*----------------------------------------------------------------------------*/
87 /*----------------------------------------------------------------------------*/
88 static int
89 uves_tflat_define_parameters(cpl_parameterlist *parameters)
90 {
91 
92  int res=0;
93  res=uves_mflat_define_parameters_body(parameters,"uves_cal_tflat" );
94 
95  /*******************
96  * Reduce. *
97  ******************/
98  if (uves_propagate_parameters_step(UVES_REDUCE_ID, parameters,
99  make_str(UVES_TFLAT_ID), NULL) != 0)
100  {
101  return -1;
102  }
103 
104  /* For TFLAT reduction: average extraction, no sky subtraction */
105  {
106  const char *param = "average";
107  bool bool_param;
108 
109  if (uves_set_parameter_default(parameters,
110  make_str(UVES_TFLAT_ID), "reduce.extract.method",
111  CPL_TYPE_STRING, &param) != CPL_ERROR_NONE)
112  {
113  return -1;
114  }
115 
116  bool_param = false;
117  if (uves_set_parameter_default(parameters,
118  make_str(UVES_TFLAT_ID), "reduce.skysub",
119  CPL_TYPE_BOOL, &bool_param) != CPL_ERROR_NONE)
120  {
121  return -1;
122  }
123  }
124 
125  return (cpl_error_get_code() != CPL_ERROR_NONE);
126 }
127 
128 /*----------------------------------------------------------------------------*/
135 /*----------------------------------------------------------------------------*/
136 static void
137 UVES_CONCAT2X(UVES_TFLAT_ID,exe)(cpl_frameset *frames,
138  const cpl_parameterlist *parameters,
139  const char *starttime)
140 {
141  uves_msg("Creating master tflat");
142  check_nomsg( uves_mflat_exe_body(frames, parameters,
143  starttime,
144  make_str(UVES_TFLAT_ID)) );
145 
146  uves_msg("Reducing first raw tflat");
147  check_nomsg( uves_reduce_scired(frames, parameters, make_str(UVES_TFLAT_ID), starttime) );
148 
149  /* The MASTER_TFLAT was reclassified as CALIB by the reduction step.
150  But it is actually a product of this recipe, so retag it */
151  {
152  enum uves_chip chip;
153  int blue;
154  const char* PROCESS_CHIP=NULL;
155  cpl_frame *f = NULL;
156  check( uves_get_parameter(parameters, NULL, "uves", "process_chip", CPL_TYPE_STRING, &PROCESS_CHIP),
157  "Could not read parameter");
158  uves_string_toupper((char*)PROCESS_CHIP);
159 
160  /* Loop over all possible MASTER_TFLATs */
161  for (blue = 0; blue <= 1; blue++)
162  {
163  for (chip = uves_chip_get_first(blue);
164  chip != UVES_CHIP_INVALID;
165  chip = uves_chip_get_next(chip))
166  {
167 
168  if(strcmp(PROCESS_CHIP,"REDU") == 0) {
169  chip = uves_chip_get_next(chip);
170  }
171 
172  f = cpl_frameset_find(frames, UVES_MASTER_TFLAT(chip));
173  if (f != NULL)
174  {
175  cpl_frame_set_group(f, CPL_FRAME_GROUP_PRODUCT);
176  }
177 
178  f = cpl_frameset_find(frames, UVES_BKG_FLAT(chip));
179  if (f != NULL)
180  {
181  cpl_frame_set_group(f, CPL_FRAME_GROUP_PRODUCT);
182  }
183  }
184 
185  if(strcmp(PROCESS_CHIP,"REDL") == 0) {
186  chip = uves_chip_get_next(chip);
187  }
188 
189  }
190  }
191 
192  cleanup:
193  return;
194 }
195 
int uves_mflat_define_parameters_body(cpl_parameterlist *parameters, const char *recipe_id)
Setup the recipe options.
void uves_reduce_scired(cpl_frameset *frames, const cpl_parameterlist *parameters, const char *recipe_id, const char *starttime)
Get the command line options and execute the data reduction.
#define check_nomsg(CMD)
Definition: uves_error.h:204
#define uves_msg(...)
Print a message on 'info' or 'debug' level.
Definition: uves_msg.h:119
void uves_mflat_exe_body(cpl_frameset *frames, const cpl_parameterlist *parameters, const char *starttime, const char *recipe_id)
Get the command line options and execute the data reduction.
enum uves_chip uves_chip_get_first(bool blue)
Get first chip for blue or red arm.
Definition: uves_chip.c:92
enum uves_chip uves_chip_get_next(enum uves_chip chip)
Get next chip.
Definition: uves_chip.c:108
const char * uves_string_toupper(char *s)
Convert all lowercase characters in a string into uppercase characters.
Definition: uves_utils.c:1493
#define check(CMD,...)
Definition: uves_error.h:198