UVES Pipeline Reference Manual  5.5.5b3
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  uves_mflat_define_parameters_body(parameters,"uves_cal_tflat" );
93 
94  /*******************
95  * Reduce. *
96  ******************/
97  if (uves_propagate_parameters_step(UVES_REDUCE_ID, parameters,
98  make_str(UVES_TFLAT_ID), NULL) != 0)
99  {
100  return -1;
101  }
102 
103  /* For TFLAT reduction: average extraction, no sky subtraction */
104  {
105  const char *param = "average";
106  bool bool_param;
107 
108  if (uves_set_parameter_default(parameters,
109  make_str(UVES_TFLAT_ID), "reduce.extract.method",
110  CPL_TYPE_STRING, &param) != CPL_ERROR_NONE)
111  {
112  return -1;
113  }
114 
115  bool_param = false;
116  if (uves_set_parameter_default(parameters,
117  make_str(UVES_TFLAT_ID), "reduce.skysub",
118  CPL_TYPE_BOOL, &bool_param) != CPL_ERROR_NONE)
119  {
120  return -1;
121  }
122  }
123 
124  return (cpl_error_get_code() != CPL_ERROR_NONE);
125 }
126 
127 /*----------------------------------------------------------------------------*/
134 /*----------------------------------------------------------------------------*/
135 static void
136 UVES_CONCAT2X(UVES_TFLAT_ID,exe)(cpl_frameset *frames,
137  const cpl_parameterlist *parameters,
138  const char *starttime)
139 {
140  uves_msg("Creating master tflat");
141  check_nomsg( uves_mflat_exe_body(frames, parameters,
142  starttime,
143  make_str(UVES_TFLAT_ID)) );
144 
145  uves_msg("Reducing first raw tflat");
146  check_nomsg( uves_reduce_scired(frames, parameters, make_str(UVES_TFLAT_ID), starttime) );
147 
148  /* The MASTER_TFLAT was reclassified as CALIB by the reduction step.
149  But it is actually a product of this recipe, so retag it */
150  {
151  enum uves_chip chip;
152  int blue;
153  const char* PROCESS_CHIP=NULL;
154  cpl_frame *f = NULL;
155  check( uves_get_parameter(parameters, NULL, "uves", "process_chip", CPL_TYPE_STRING, &PROCESS_CHIP),
156  "Could not read parameter");
157  uves_string_toupper((char*)PROCESS_CHIP);
158 
159  /* Loop over all possible MASTER_TFLATs */
160  for (blue = 0; blue <= 1; blue++)
161  {
162  for (chip = uves_chip_get_first(blue);
163  chip != UVES_CHIP_INVALID;
164  chip = uves_chip_get_next(chip))
165  {
166 
167  if(strcmp(PROCESS_CHIP,"REDU") == 0) {
168  chip = uves_chip_get_next(chip);
169  }
170 
171  f = cpl_frameset_find(frames, UVES_MASTER_TFLAT(chip));
172  if (f != NULL)
173  {
174  cpl_frame_set_group(f, CPL_FRAME_GROUP_PRODUCT);
175  }
176 
177  f = cpl_frameset_find(frames, UVES_BKG_FLAT(chip));
178  if (f != NULL)
179  {
180  cpl_frame_set_group(f, CPL_FRAME_GROUP_PRODUCT);
181  }
182  }
183 
184  if(strcmp(PROCESS_CHIP,"REDL") == 0) {
185  chip = uves_chip_get_next(chip);
186  }
187 
188  }
189  }
190 
191  cleanup:
192  return;
193 }
194 
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