VIRCAM Pipeline  2.3.10
vircam_dfs.c
1 /* $Id: vircam_dfs.c,v 1.43 2013-10-15 16:32:50 jim Exp $
2  *
3  * This file is part of the VIRCAM Pipeline
4  * Copyright (C) 2015 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: jim $
23  * $Date: 2013-10-15 16:32:50 $
24  * $Revision: 1.43 $
25  * $Name: not supported by cvs2svn $
26  */
27 
28 
29 /* Includes */
30 
31 #ifdef HAVE_CONFIG_H
32 #include <config.h>
33 #endif
34 
35 #include <string.h>
36 #include <cpl.h>
37 
38 #include "vircam_dfs.h"
39 #include "vircam_utils.h"
40 
41 #define PACKSZ 1024
42 #define DELEXTN "^(ESO.INS |ESO.OBS |ESO.TEL |INSTRUME|PIPEFILE|ORIGIN" \
43  "|TELESCOP|OBJECT|RA|DEC|EPOCH|EQUINOX|DATAMD5|RADECSYS" \
44  "|RADESYS|HDRVER|DATE-OBS|MJD-OBS|UTC|LST|PI-COI|OBSERVER).*$"
45 
46 #define REGFIX "^(ORIGIN|TELESCOP|INSTRUME|OBJECT|RA|DEC|EPOCH|EQUINOX" \
47  "|RADECSYS|RADESYS|DATE-OBS|MJD-OBS|UTC|LST|PI-COI|OBSERVER)$"
48 
63 /*----------------------------------------------------------------------------*/
69 /*----------------------------------------------------------------------------*/
70 static cpl_error_code vircam_dfs_rename_ref_frame(cpl_propertylist * list) {
71  if (!list) return CPL_ERROR_NULL_INPUT;
72 
73  if (cpl_propertylist_has(list, "RADECSYS")) {
74  if (cpl_propertylist_has(list, "RADESYS"))
75  cpl_propertylist_erase(list, "RADECSYS");
76  else {
77  char * radec_val = cpl_strdup(cpl_propertylist_get_string(
78  list, "RADECSYS"));
79  char * radec_com = cpl_strdup(cpl_propertylist_get_comment(
80  list, "RADECSYS"));
81  cpl_propertylist_erase(list, "RADECSYS");
82  cpl_propertylist_update_string(list, "RADESYS", radec_val);
83  cpl_propertylist_set_comment(list, "RADESYS", radec_com);
84  cpl_free(radec_val);
85  cpl_free(radec_com);
86  }
87  }
88  return cpl_error_get_code();
89 }
90 
91 /*---------------------------------------------------------------------------*/
113 /*---------------------------------------------------------------------------*/
114 
115 extern int vircam_dfs_set_groups(cpl_frameset *set) {
116  cpl_frame *cur_frame;
117  const char *tag;
118  const char *fctid = "vircam_dfs_set_groups";
119  int nframes,i;
120 
121  /* Check entries */
122 
123  if (set == NULL)
124  return(CASU_FATAL);
125 
126  /* Initialize */
127 
128  nframes = cpl_frameset_get_size(set);
129 
130  /* Loop on frames */
131 
132  for (i = 0; i < nframes; i++) {
133  cur_frame = cpl_frameset_get_position(set,i);
134  tag = cpl_frame_get_tag(cur_frame);
135 
136  /* RAW frames */
137 
138  if (!strcmp(tag,VIRCAM_DARKCUR_RAW) ||
139  !strcmp(tag,VIRCAM_DARK_RAW) ||
140  !strcmp(tag,VIRCAM_NOISE_FLAT_RAW) ||
141  !strcmp(tag,VIRCAM_NOISE_DARK_RAW) ||
142  !strcmp(tag,VIRCAM_DOME_RAW) ||
143  !strcmp(tag,VIRCAM_SCI_OBJECT_RAW) ||
144  !strcmp(tag,VIRCAM_SCI_OBJECT_EXT_RAW) ||
145  !strcmp(tag,VIRCAM_OFFSET_SKY_RAW) ||
146  !strcmp(tag,VIRCAM_TEST_SCIENCE_RAW) ||
147  !strcmp(tag,VIRCAM_LIN_DOME_RAW) ||
148  !strcmp(tag,VIRCAM_LIN_DOME_CHECK) ||
149  !strcmp(tag,VIRCAM_LIN_DARK_RAW) ||
150  !strcmp(tag,VIRCAM_LIN_DARK_CHECK) ||
151  !strcmp(tag,VIRCAM_ILLUM_RAW) ||
152  !strcmp(tag,VIRCAM_RESET_RAW) ||
153  !strcmp(tag,VIRCAM_STD_OBJECT_RAW) ||
154  !strcmp(tag,VIRCAM_TWI_RAW) ||
155  !strcmp(tag,VIRCAM_PRO_OBJCAT_SCI) ||
156  !strcmp(tag,VIRCAM_PRO_CONF_SCI) ||
157  !strcmp(tag,VIRCAM_PRO_JITTERED_SCI))
158  cpl_frame_set_group(cur_frame,CPL_FRAME_GROUP_RAW);
159 
160  /* CALIB frames */
161 
162  else if (!strcmp(tag,VIRCAM_CAL_RESET) ||
163  !strcmp(tag,VIRCAM_CAL_DARK) ||
164  !strcmp(tag,VIRCAM_CAL_DOME_FLAT) ||
165  !strcmp(tag,VIRCAM_CAL_TWILIGHT_FLAT) ||
166  !strcmp(tag,VIRCAM_CAL_CONF) ||
167  !strcmp(tag,VIRCAM_CAL_BPM) ||
168  !strcmp(tag,VIRCAM_CAL_FRINGE) ||
169  !strcmp(tag,VIRCAM_CAL_CHANTAB) ||
170  !strcmp(tag,VIRCAM_CAL_READGAINFILE) ||
171  !strcmp(tag,VIRCAM_CAL_CHANTAB_INIT) ||
172  !strcmp(tag,VIRCAM_CAL_PHOTTAB) ||
173  !strcmp(tag,VIRCAM_CAL_STDTAB) ||
174  !strcmp(tag,VIRCAM_CAL_OBJCAT) ||
175  !strcmp(tag,VIRCAM_CAL_MSTDTAB) ||
176  !strcmp(tag,VIRCAM_CAL_2MASS) ||
177  !strcmp(tag,VIRCAM_CAL_SCHL_N) ||
178  !strcmp(tag,VIRCAM_CAL_SCHL_S) ||
179  !strcmp(tag,VIRCAM_CAL_REFCAT) ||
180  !strcmp(tag,VIRCAM_CAL_SKY) ||
181  !strcmp(tag,VIRCAM_CAL_OBJMASK) ||
182  !strcmp(tag,VIRCAM_REF_RESET) ||
183  !strcmp(tag,VIRCAM_REF_DARK) ||
184  !strcmp(tag,VIRCAM_REF_DOME_FLAT) ||
185  !strcmp(tag,VIRCAM_REF_TWILIGHT_FLAT))
186  cpl_frame_set_group(cur_frame,CPL_FRAME_GROUP_CALIB);
187  else
188  cpl_msg_info(fctid,"No such tag as %s in frame %s",tag,
189  cpl_frame_get_filename(cur_frame));
190  }
191  return(CASU_OK);
192 }
193 
194 /*---------------------------------------------------------------------------*/
225 /*---------------------------------------------------------------------------*/
226 
227 extern void vircam_dfs_set_product_primary_header(cpl_propertylist *plist,
228  cpl_frame *frame,
229  cpl_frameset *frameset,
230  cpl_parameterlist *parlist,
231  char *recipeid,
232  const char *dict,
233  cpl_frame *inherit,
234  int synch) {
235  const char *fctid="vircam_dfs_set_product_primary_header";
236  char package[PACKSZ];
237  cpl_propertylist *pcopy;
238 
239  /* Get the package name and version */
240 
241  (void)snprintf(package,PACKSZ,"%s/%s",PACKAGE,PACKAGE_VERSION);
242 
243  /* Make a copy of the input propertylist so that we can restore the
244  time and position dependent headers back to the way they were before
245  cpl_dfs_setup_product_header worked on it. */
246 
247  pcopy = cpl_propertylist_duplicate(plist);
248 
249  /* Add the data-flow keywords */
250 
251  if (cpl_dfs_setup_product_header(plist,frame,frameset,parlist,recipeid,
252  package,dict,inherit) != CPL_ERROR_NONE) {
253  cpl_msg_warning(fctid,
254  "Problem with the product primary DFS compliance -- %s",
255  cpl_error_get_message());
256  cpl_error_reset();
257  }
258 
259  /* Now fix the time/position information back to the way it was */
260 
261  if (synch)
262  cpl_propertylist_copy_property_regexp(plist,
263  (const cpl_propertylist *)pcopy,
264  REGFIX,0);
265  cpl_propertylist_erase_regexp(plist, "HDRVER", 0);
266  vircam_dfs_rename_ref_frame(plist);
267  cpl_propertylist_delete(pcopy);
268 }
269 
270 /*---------------------------------------------------------------------------*/
297 /*---------------------------------------------------------------------------*/
298 
299 extern void vircam_dfs_set_product_exten_header(cpl_propertylist *plist,
300  cpl_frame *frame,
301  cpl_frameset *frameset,
302  cpl_parameterlist *parlist,
303  char *recipeid,
304  const char *dict,
305  cpl_frame *inherit) {
306  const char *fctid="vircam_dfs_set_product_exten_header";
307  char package[PACKSZ];
308 
309  /* Get the package name and version */
310 
311  (void)snprintf(package,PACKSZ,"%s/%s",PACKAGE,PACKAGE_VERSION);
312 
313  /* Add the data-flow keywords */
314 
315  if (cpl_dfs_setup_product_header(plist,frame,frameset,parlist,recipeid,
316  package,dict,inherit) != CPL_ERROR_NONE) {
317  cpl_msg_warning(fctid,
318  "Problem with the product extn DFS compliance -- %s",
319  cpl_error_get_message());
320  cpl_error_reset();
321  }
322 
323  /* Remove the stuff that isn't supposed to be here */
324 
325  cpl_propertylist_erase_regexp(plist,DELEXTN,0);
326 
327  /* ensure RADESYS & EQUINOX are inherited from PHU, if necessary */
328  cpl_errorstate state = cpl_errorstate_get();
329  cpl_wcs * wcs = cpl_wcs_new_from_propertylist(plist);
330  if (wcs) {
331  cpl_propertylist_update_bool(plist, "INHERIT", 1);
332  cpl_propertylist_set_comment(plist, "INHERIT",
333  "denotes the INHERIT keyword convention");
334  cpl_wcs_delete(wcs);
335  }
336  cpl_errorstate_set(state);
337 
338 }
339 
342 /*
343 
344 $Log: not supported by cvs2svn $
345 Revision 1.42 2010/09/10 11:22:44 jim
346 Added VIRCAM_CAL_SKY entry
347 
348 Revision 1.41 2010/01/31 18:59:54 jim
349 Removed references to master sky
350 
351 Revision 1.40 2009/09/22 12:27:01 jim
352 Added entry for raw offset sky exposures
353 
354 Revision 1.39 2009/09/09 09:44:54 jim
355 Modified in final ditch effort to get headers right...
356 
357 Revision 1.38 2009/03/02 20:00:10 jim
358 Uses new version of cpl_dfs_set_product_header
359 
360 Revision 1.37 2008/11/02 14:33:11 jim
361 Modified vircam_dfs_set_product_primary_header so that critical positional
362 and timing data are not overwritten
363 
364 Revision 1.36 2008/10/21 08:37:15 jim
365 Added VIRCAM_PRO_SKYMAP_SCI, VIRCAM_CAL_SKY and VIRCAM_CAL_SKY_MASK
366 
367 Revision 1.35 2008/10/07 11:21:56 jim
368 Fixed regexp again...
369 
370 Revision 1.34 2008/09/30 11:34:14 jim
371 modified definition of DELEXTN
372 
373 Revision 1.33 2008/09/29 11:20:17 jim
374 Modified to keep PRO keywords in the primary header. Extended the list of
375 items to be removed from the extension header.
376 
377 Revision 1.32 2007/11/20 09:37:56 jim
378 Added VIRCAM_LIN_DOME_CHECK and VIRCAM_LIN_DARK_CHECK
379 
380 Revision 1.31 2007/10/19 06:55:06 jim
381 Modifications made to use new method for directing the recipes to the
382 standard catalogues using the sof
383 
384 Revision 1.30 2007/08/23 09:00:59 jim
385 Removed annoying error messages in the product header routines which used
386 to tell you if it couldn't find stuff to erase.
387 
388 Revision 1.29 2007/04/23 12:50:22 jim
389 Added VIRCAM_TEST_SCIENCE_RAW
390 
391 Revision 1.28 2007/04/04 10:34:42 jim
392 Complete rewrite of the dfs tags
393 
394 Revision 1.27 2007/03/23 10:53:22 jim
395 Fixed little documentation errors
396 
397 Revision 1.26 2007/03/01 12:42:41 jim
398 Modified slightly after code checking
399 
400 Revision 1.25 2007/02/15 11:53:45 jim
401 Added type CHANNEL_TABLE_INIT
402 
403 Revision 1.24 2007/02/05 13:54:00 jim
404 Added REFERENCE tags
405 
406 Revision 1.23 2007/01/17 23:53:43 jim
407 Modified to remove INS, OBS and TEL structures from extension headers
408 
409 Revision 1.22 2006/12/06 12:58:57 jim
410 Added MASTER_FRINGE
411 
412 Revision 1.21 2006/11/28 20:57:05 jim
413 Added ILLUM types
414 
415 Revision 1.20 2006/10/05 09:22:59 jim
416 Small modifications to a couple of cpl calls to bring them into line with
417 cpl v3.0
418 
419 Revision 1.19 2006/07/04 09:19:04 jim
420 replaced all sprintf statements with snprintf
421 
422 Revision 1.18 2006/06/14 14:13:58 jim
423 fixed minor doc problem
424 
425 Revision 1.17 2006/06/13 21:26:02 jim
426 Added VIRCAM_CALIB_READNOISE_FILE
427 
428 Revision 1.16 2006/05/24 13:33:56 jim
429 Added VIRCAM_PHOTTAB
430 
431 Revision 1.15 2006/05/18 12:32:23 jim
432 Added channel table and object catalogue to calib list
433 
434 Revision 1.14 2006/04/27 09:46:27 jim
435 Modified to conform to new dictionary
436 
437 Revision 1.13 2006/04/26 09:39:35 jim
438 Fixes the pipeline id to the header
439 
440 Revision 1.12 2006/04/25 13:47:59 jim
441 Modified calls to vircam_dfs_set_product_*_header routines
442 
443 Revision 1.11 2006/04/20 11:19:22 jim
444 *** empty log message ***
445 
446 Revision 1.10 2006/03/22 13:14:24 jim
447 Sorted data categories
448 
449 Revision 1.9 2006/02/27 13:53:32 jim
450 Added new categories to vircam_dfs_set_groups
451 
452 Revision 1.8 2006/02/18 11:45:01 jim
453 Added vircam_dfs_set_product_primary_header and
454 vircam_dfs_set_product_exten_header
455 
456 Revision 1.7 2006/01/23 10:30:49 jim
457 Mainly documentation mods
458 
459 Revision 1.6 2005/12/14 22:17:33 jim
460 Updated docs
461 
462 Revision 1.5 2005/11/29 14:56:36 jim
463 Added a few new categories
464 
465 Revision 1.4 2005/11/25 09:56:14 jim
466 Tidied up some more documentation
467 
468 Revision 1.3 2005/11/03 13:28:48 jim
469 All sorts of changes to tighten up error handling
470 
471 Revision 1.2 2005/09/20 15:07:46 jim
472 Fixed a few bugs and added a few things
473 
474 Revision 1.1.1.1 2005/08/05 08:29:09 jim
475 Initial import
476 
477 
478 */
int vircam_dfs_set_groups(cpl_frameset *set)
Definition: vircam_dfs.c:115
void vircam_dfs_set_product_primary_header(cpl_propertylist *plist, cpl_frame *frame, cpl_frameset *frameset, cpl_parameterlist *parlist, char *recipeid, const char *dict, cpl_frame *inherit, int synch)
Definition: vircam_dfs.c:227
void vircam_dfs_set_product_exten_header(cpl_propertylist *plist, cpl_frame *frame, cpl_frameset *frameset, cpl_parameterlist *parlist, char *recipeid, const char *dict, cpl_frame *inherit)
Definition: vircam_dfs.c:299