SINFONI Pipeline Reference Manual  2.5.2
sinfo_tpl_dfs.c
1 /* $Id: sinfo_tpl_dfs.c,v 1.13 2012-03-03 10:17:31 amodigli Exp $
2  *
3  * This file is part of the SINFONI Pipeline
4  * Copyright (C) 2002,2003 European Southern Observatory
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 
21 /*
22  * $Author: amodigli $
23  * $Date: 2012-03-03 10:17:31 $
24  * $Revision: 1.13 $
25  * $Name: not supported by cvs2svn $
26  */
27 
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 
32 /*-----------------------------------------------------------------------------
33  Includes
34  -----------------------------------------------------------------------------*/
35 
36 #include <string.h>
37 #include <math.h>
38 
39 #include <cpl.h>
40 #include "sinfo_utilities.h"
41 
42 #include "sinfo_tpl_dfs.h"
43 #include "sinfo_pro_types.h"
44 #include "sinfo_raw_types.h"
45 #include "sinfo_ref_types.h"
46 #include "sinfo_error.h"
47 #include "sinfo_msg.h"
48 
50 /*----------------------------------------------------------------------------*/
56 /*----------------------------------------------------------------------------*/
57 
58 /*----------------------------------------------------------------------------*/
68 /*----------------------------------------------------------------------------*/
69 static int
70 sinfo_dfs_files_dont_exist(cpl_frameset *frameset)
71 {
72  const char *func = "dfs_files_dont_exist";
73  cpl_frame *frame;
74 
75  if (frameset == NULL ) {
76  cpl_error_set(func, CPL_ERROR_NULL_INPUT);
77  return 1;
78  }
79 
80  if (cpl_frameset_is_empty(frameset)) {
81  return 0;
82  }
83 
84  frame = cpl_frameset_get_first(frameset);
85 
86  while (frame) {
87  if (access(cpl_frame_get_filename(frame), F_OK)) {
88  cpl_msg_error(func, "File %s (%s) was not found",
89  cpl_frame_get_filename(frame),
90  cpl_frame_get_tag(frame));
91  cpl_error_set(func, CPL_ERROR_FILE_NOT_FOUND);
92  }
93 
94  frame = cpl_frameset_get_next(frameset);
95  }
96 
97  if (cpl_error_get_code())
98  return 1;
99 
100  return 0;
101 }
102 
103 /*----------------------------------------------------------------------------*/
109 /*----------------------------------------------------------------------------*/
110 int
111 sinfo_dfs_set_groups(cpl_frameset * set)
112 {
113  cpl_frame * cur_frame = NULL;
114  const char * tag = NULL;
115  int nframes = 0;
116  int i = 0;
117 
118  sinfo_skip_if(cpl_error_get_code());
119 
120  /* Check entries */
121  if (set == NULL )
122  return -1;
123 
124  /* Initialize */
125  nframes = cpl_frameset_get_size(set);
126 
127  /* Loop on frames */
128  for (i = 0; i < nframes; i++) {
129  cur_frame = cpl_frameset_get_frame(set, i);
130  tag = cpl_frame_get_tag(cur_frame);
131  if (cpl_error_get_code())
132  break;
133  if (tag == NULL )
134  sinfo_msg_warning("Frame %d has no tag", i);
135  /* RAW frames */
136  else if (!strcmp(tag, RAW_LINEARITY_LAMP) || !strcmp(tag, RAW_ON)
137  || !strcmp(tag, RAW_OFF) || !strcmp(tag, RAW_DARK)
138  || !strcmp(tag, RAW_FIBRE_NS)
139  || !strcmp(tag, RAW_FIBRE_PSF)
140  || !strcmp(tag, RAW_FIBRE_DARK)
141  || !strcmp(tag, RAW_FLAT_NS)
142  || !strcmp(tag, RAW_WAVE_NS)
143  || !strcmp(tag, RAW_FLAT_LAMP)
144  || !strcmp(tag, RAW_WAVE_LAMP)
145  || !strcmp(tag, RAW_PSF_CALIBRATOR)
146  || !strcmp(tag, RAW_SKY_PSF_CALIBRATOR)
147  || !strcmp(tag, RAW_STD) || !strcmp(tag, RAW_SKY)
148  || !strcmp(tag, RAW_SKY_STD)
149  || !strcmp(tag, RAW_OBJECT_NODDING)
150  || !strcmp(tag, RAW_SKY_NODDING)
151  || !strcmp(tag, RAW_OBJECT_JITTER)
152  || !strcmp(tag, RAW_SKY_JITTER)
153  || !strcmp(tag, RAW_PUPIL_LAMP)
154  || !strcmp(tag, RAW_IMAGE_PRE_OBJECT)
155  || !strcmp(tag, RAW_IMAGE_PRE_SKY)
156  || !strcmp(tag, RAW_OBJECT_SKYSPIDER))
157  cpl_frame_set_group(cur_frame, CPL_FRAME_GROUP_RAW);
158  /* CALIB frames */
159  else if (!strcmp(tag, PRO_BP_MAP_HP)
160  || !strcmp(tag, SINFO_UTL_STDSTARS_RAW)
161  || !strcmp(tag, SINFO_CALIB_STDSTARS)
162  || !strcmp(tag, SINFO_CALIB_SED)
163  || !strcmp(tag, PRO_BP_MAP_NL)
164  || !strcmp(tag, PRO_BP_MAP_NO)
165  || !strcmp(tag, PRO_BP_MAP_DI)
166  || !strcmp(tag, PRO_BP_MAP_NL)
167  || !strcmp(tag, PRO_BP_MAP_NO)
168  || !strcmp(tag, PRO_BP_MAP) || !strcmp(tag, PRO_ILL_COR)
169  || !strcmp(tag, PRO_MASTER_BP_MAP)
170  || !strcmp(tag, PRO_MASTER_DARK)
171  || !strcmp(tag, PRO_DISTORTION)
172  || !strcmp(tag, PRO_SLITLETS_DISTANCE)
173  || !strcmp(tag, PRO_MASTER_FLAT_LAMP)
174  || !strcmp(tag, PRO_SLIT_POS)
175  || !strcmp(tag, PRO_SLIT_POS_GUESS)
176  || !strcmp(tag, PRO_FIRST_COL)
177  || !strcmp(tag, PRO_WAVE_MAP)
178  || !strcmp(tag, REF_LINE_ARC)
179  || !strcmp(tag, DRS_SETUP_WAVE)
180  || !strcmp(tag, EXTCOEFF_TABLE)
181  || !strcmp(tag, FLUX_STD_TABLE)
182  || !strcmp(tag, FLUX_STD_CATALOG)
183  || !strcmp(tag, PRO_IMA) || !strcmp(tag, PRO_CUBE)
184  || !strcmp(tag, REF_BP_MAP)
185  || !strcmp(tag, PRO_SKY_DUMMY)
186  || !strcmp(tag, PRO_REF_ATM_REF_CORR)
187  || !strcmp(tag, PRO_SPECTRUM))
188  cpl_frame_set_group(cur_frame, CPL_FRAME_GROUP_CALIB);
189  else if (!strcmp(tag, PRO_OBS_OBJ) || !strcmp(tag, PRO_MED_OBS_OBJ)
190  || !strcmp(tag, PRO_OBS_STD)
191  || !strcmp(tag, PRO_MED_OBS_STD)
192  || !strcmp(tag, PRO_OBS_PSF)
193  || !strcmp(tag, PRO_MED_OBS_PSF)
194  || !strcmp(tag, PRO_COADD_OBJ)
195  || !strcmp(tag, PRO_COADD_STD)
196  || !strcmp(tag, PRO_COADD_PSF)
197  || !strcmp(tag, PRO_COADD_PUPIL)
198  || !strcmp(tag, PRO_MED_COADD_OBJ)
199  || !strcmp(tag, PRO_MED_COADD_STD)
200  || !strcmp(tag, PRO_MED_COADD_PSF)
201  || !strcmp(tag, PRO_MED_COADD_PUPIL)
202  || !strcmp(tag, PRO_MASK_COADD_OBJ)
203  || !strcmp(tag, PRO_MASK_COADD_STD)
204  || !strcmp(tag, PRO_MASK_COADD_PSF)
205  || !strcmp(tag, PRO_MASK_COADD_PUPIL)
206  || !strcmp(tag, PRO_PSF_CALIBRATOR_STACKED)
207  || !strcmp(tag, PRO_SKY_PSF_CALIBRATOR_STACKED)
208  || !strcmp(tag, PRO_AO_PERFORMANCE)
209  || !strcmp(tag, PRO_ENC_ENERGY) || !strcmp(tag, PRO_PSF)
210  || !strcmp(tag, PRO_STD_STAR_SPECTRA)
211  || !strcmp(tag, PRO_STD_STAR_SPECTRUM)
212  || !strcmp(tag, PRO_MFLAT_CUBE)
213  || !strcmp(tag, PRO_MFLAT_AVG)
214  || !strcmp(tag, PRO_MFLAT_MED)
215  || !strcmp(tag, PRO_STACK_MFLAT_DIST)
216  || !strcmp(tag, PRO_WAVE_LAMP_STACKED)
217  || !strcmp(tag, PRO_FIBRE_NS_STACKED_OFF)
218  || !strcmp(tag, PRO_FIBRE_NS_STACKED_ON)
219  || !strcmp(tag, PRO_FIBRE_NS_STACKED)
220  || !strcmp(tag, PRO_SLITLETS_POS_PREDIST)
221  || !strcmp(tag, PRO_OBS_SKY)
222  || !strcmp(tag, PRO_SKY_MED)
223  || !strcmp(tag, PRO_FIBRE_NS_STACKED_DIST))
224  cpl_frame_set_group(cur_frame, CPL_FRAME_GROUP_PRODUCT);
225  else
226  sinfo_msg_warning("Frame %d has unknown tag: %s", i, tag);
227  }
228  ck0_nomsg(sinfo_dfs_files_dont_exist(set));
229  sinfo_skip_if(i != nframes);
230 
231  sinfo_end_skip;
232 
233  if (cpl_error_get_code())
234  sinfo_msg_error("Could not identify RAW and CALIB frames (in "
235  "frame set of size %d)", nframes);
236 
237  return cpl_error_get_code();
238 }
239