vircam_dfs.c

00001 /* $Id: vircam_dfs.c,v 1.42 2010/09/10 11:22:44 jim Exp $
00002  *
00003  * This file is part of the VIRCAM Pipeline
00004  * Copyright (C) 2005 Cambridge Astronomy Survey Unit
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00021 /*
00022  * $Author: jim $
00023  * $Date: 2010/09/10 11:22:44 $
00024  * $Revision: 1.42 $
00025  * $Name: v1-1-0 $
00026  */
00027 
00028 
00029 /* Includes */
00030 
00031 #ifdef HAVE_CONFIG_H
00032 #include <config.h>
00033 #endif
00034 
00035 #include <string.h>
00036 #include <cpl.h>
00037 
00038 #include "vircam_dfs.h"
00039 #include "vircam_utils.h"
00040 
00041 #define PACKSZ 1024
00042 #define DELEXTN "^(ESO.INS |ESO.OBS |ESO.TEL |INSTRUME|PIPEFILE|ORIGIN" \
00043                 "|TELESCOP|OBJECT|RA|DEC|EPOCH|EQUINOX|DATAMD5|RADECSYS" \
00044                 "|DATE-OBS|MJD-OBS|UTC|LST|PI-COI|OBSERVER).*$"
00045 
00046 #define REGFIX "^(ORIGIN|TELESCOP|INSTRUME|OBJECT|RA|DEC|EPOCH|EQUINOX" \
00047     "|RADECSYS|DATE-OBS|MJD-OBS|UTC|LST|PI-COI|OBSERVER)$"
00048 
00063 /*---------------------------------------------------------------------------*/
00085 /*---------------------------------------------------------------------------*/
00086 
00087 extern int vircam_dfs_set_groups(cpl_frameset *set) {
00088     cpl_frame *cur_frame;
00089     const char *tag;
00090     const char *fctid = "vircam_dfs_set_groups";
00091     int nframes,i;
00092 
00093     /* Check entries */
00094 
00095     if (set == NULL) 
00096         return(VIR_FATAL); 
00097     
00098     /* Initialize */
00099 
00100     nframes = cpl_frameset_get_size(set);
00101 
00102     /* Loop on frames */
00103 
00104     for (i = 0; i < nframes; i++) {
00105         cur_frame = cpl_frameset_get_frame(set,i);
00106         tag = cpl_frame_get_tag(cur_frame);
00107        
00108         /* RAW frames */
00109 
00110         if (!strcmp(tag,VIRCAM_CROSSTALK_RAW) ||
00111             !strcmp(tag,VIRCAM_DARK_RAW)  ||
00112             !strcmp(tag,VIRCAM_DARKCUR_RAW)  ||
00113             !strcmp(tag,VIRCAM_NOISE_FLAT_RAW) ||
00114             !strcmp(tag,VIRCAM_NOISE_DARK_RAW) ||
00115             !strcmp(tag,VIRCAM_DOME_RAW) ||
00116             !strcmp(tag,VIRCAM_SCI_OBJECT_RAW) || 
00117             !strcmp(tag,VIRCAM_SCI_OBJECT_EXT_RAW) || 
00118             !strcmp(tag,VIRCAM_OFFSET_SKY_RAW) ||
00119             !strcmp(tag,VIRCAM_TEST_SCIENCE_RAW) || 
00120             !strcmp(tag,VIRCAM_LIN_DOME_RAW) ||
00121             !strcmp(tag,VIRCAM_LIN_DOME_CHECK) ||
00122             !strcmp(tag,VIRCAM_LIN_DARK_RAW) ||
00123             !strcmp(tag,VIRCAM_LIN_DARK_CHECK) ||
00124             !strcmp(tag,VIRCAM_ILLUM_RAW) ||
00125             !strcmp(tag,VIRCAM_PERSIST_OBJ_RAW) ||
00126             !strcmp(tag,VIRCAM_PERSIST_DARK_RAW) ||
00127             !strcmp(tag,VIRCAM_RESET_RAW) ||
00128             !strcmp(tag,VIRCAM_STD_OBJECT_RAW) ||
00129             !strcmp(tag,VIRCAM_TWI_RAW))
00130             cpl_frame_set_group(cur_frame,CPL_FRAME_GROUP_RAW);
00131 
00132         /* CALIB frames */
00133 
00134         else if (!strcmp(tag,VIRCAM_CAL_RESET) ||
00135                  !strcmp(tag,VIRCAM_CAL_DARK) ||
00136                  !strcmp(tag,VIRCAM_CAL_DOME_FLAT) ||
00137                  !strcmp(tag,VIRCAM_CAL_TWILIGHT_FLAT) ||
00138                  !strcmp(tag,VIRCAM_CAL_CONF) ||
00139                  !strcmp(tag,VIRCAM_CAL_BPM) ||
00140                  !strcmp(tag,VIRCAM_CAL_FRINGE) ||
00141                  !strcmp(tag,VIRCAM_CAL_CHANTAB) ||
00142                  !strcmp(tag,VIRCAM_CAL_READGAINFILE) ||
00143                  !strcmp(tag,VIRCAM_CAL_CHANTAB_INIT) ||
00144                  !strcmp(tag,VIRCAM_CAL_PHOTTAB) ||
00145                  !strcmp(tag,VIRCAM_CAL_STDTAB) ||
00146                  !strcmp(tag,VIRCAM_CAL_OBJCAT) ||
00147                  !strcmp(tag,VIRCAM_CAL_MSTDTAB) ||
00148                  !strcmp(tag,VIRCAM_CAL_2MASS) ||
00149                  !strcmp(tag,VIRCAM_CAL_REFCAT) ||
00150                  !strcmp(tag,VIRCAM_CAL_SKY) ||
00151                  !strcmp(tag,VIRCAM_REF_RESET) ||
00152                  !strcmp(tag,VIRCAM_REF_DARK) ||
00153                  !strcmp(tag,VIRCAM_REF_DOME_FLAT) ||
00154                  !strcmp(tag,VIRCAM_REF_TWILIGHT_FLAT))
00155             cpl_frame_set_group(cur_frame,CPL_FRAME_GROUP_CALIB);
00156         else 
00157             cpl_msg_info(fctid,"No such tag as %s in frame %s",tag,
00158                          cpl_frame_get_filename(cur_frame));
00159     }
00160     return(VIR_OK);
00161 }
00162 
00163 /*---------------------------------------------------------------------------*/
00194 /*---------------------------------------------------------------------------*/
00195 
00196 extern void vircam_dfs_set_product_primary_header(cpl_propertylist *plist,
00197                                                   cpl_frame *frame,
00198                                                   cpl_frameset *frameset,
00199                                                   cpl_parameterlist *parlist,
00200                                                   char *recipeid, 
00201                                                   const char *dict,
00202                                                   cpl_frame *inherit,
00203                                                   int synch) {
00204     const char *fctid="vircam_dfs_set_product_primary_header";
00205     char package[PACKSZ];
00206     cpl_propertylist *pcopy;
00207 
00208     /* Get the package name and version */
00209 
00210     (void)snprintf(package,PACKSZ,"%s/%s",PACKAGE,PACKAGE_VERSION);
00211 
00212     /* Make a copy of the input propertylist so that we can restore the 
00213        time and position dependent headers back to the way they were before
00214        cpl_dfs_setup_product_header worked on it. */
00215 
00216     pcopy = cpl_propertylist_duplicate(plist);
00217 
00218     /* Add the data-flow keywords */
00219 
00220     if (cpl_dfs_setup_product_header(plist,frame,frameset,parlist,recipeid,
00221                                      package,dict,inherit) != CPL_ERROR_NONE) {
00222         cpl_msg_warning(fctid,
00223                         "Problem with the product primary DFS compliance -- %s",
00224                         cpl_error_get_message());
00225         cpl_error_reset();
00226     }
00227 
00228     /* Now fix the time/position information back to the way it was */
00229 
00230     if (synch) 
00231         cpl_propertylist_copy_property_regexp(plist,
00232                                               (const cpl_propertylist *)pcopy,
00233                                               REGFIX,0);
00234     cpl_propertylist_delete(pcopy);
00235 }
00236 
00237 /*---------------------------------------------------------------------------*/
00264 /*---------------------------------------------------------------------------*/
00265 
00266 extern void vircam_dfs_set_product_exten_header(cpl_propertylist *plist,
00267                                                 cpl_frame *frame,
00268                                                 cpl_frameset *frameset,
00269                                                 cpl_parameterlist *parlist,
00270                                                 char *recipeid, 
00271                                                 const char *dict,
00272                                                 cpl_frame *inherit) {
00273     const char *fctid="vircam_dfs_set_product_exten_header";
00274     char package[PACKSZ];
00275 
00276     /* Get the package name and version */
00277 
00278     (void)snprintf(package,PACKSZ,"%s/%s",PACKAGE,PACKAGE_VERSION);
00279 
00280     /* Add the data-flow keywords */
00281 
00282     if (cpl_dfs_setup_product_header(plist,frame,frameset,parlist,recipeid,
00283                                      package,dict,inherit) != CPL_ERROR_NONE) {
00284         cpl_msg_warning(fctid,
00285                         "Problem with the product extn DFS compliance -- %s",
00286                         cpl_error_get_message());
00287         cpl_error_reset();
00288     }
00289 
00290     /* Remove the stuff that isn't supposed to be here */
00291 
00292     cpl_propertylist_erase_regexp(plist,DELEXTN,0);
00293 
00294 }
00295 
00298 /*
00299 
00300 $Log: vircam_dfs.c,v $
00301 Revision 1.42  2010/09/10 11:22:44  jim
00302 Added VIRCAM_CAL_SKY entry
00303 
00304 Revision 1.41  2010/01/31 18:59:54  jim
00305 Removed references to master sky
00306 
00307 Revision 1.40  2009/09/22 12:27:01  jim
00308 Added entry for raw offset sky exposures
00309 
00310 Revision 1.39  2009/09/09 09:44:54  jim
00311 Modified in final ditch effort to get headers right...
00312 
00313 Revision 1.38  2009/03/02 20:00:10  jim
00314 Uses new version of cpl_dfs_set_product_header
00315 
00316 Revision 1.37  2008/11/02 14:33:11  jim
00317 Modified vircam_dfs_set_product_primary_header so that critical positional
00318 and timing data are not overwritten
00319 
00320 Revision 1.36  2008/10/21 08:37:15  jim
00321 Added VIRCAM_PRO_SKYMAP_SCI, VIRCAM_CAL_SKY and VIRCAM_CAL_SKY_MASK
00322 
00323 Revision 1.35  2008/10/07 11:21:56  jim
00324 Fixed regexp again...
00325 
00326 Revision 1.34  2008/09/30 11:34:14  jim
00327 modified definition of DELEXTN
00328 
00329 Revision 1.33  2008/09/29 11:20:17  jim
00330 Modified to keep PRO keywords in the primary header. Extended the list of
00331 items to be removed from the extension header.
00332 
00333 Revision 1.32  2007/11/20 09:37:56  jim
00334 Added VIRCAM_LIN_DOME_CHECK and VIRCAM_LIN_DARK_CHECK
00335 
00336 Revision 1.31  2007/10/19 06:55:06  jim
00337 Modifications made to use new method for directing the recipes to the
00338 standard catalogues using the sof
00339 
00340 Revision 1.30  2007/08/23 09:00:59  jim
00341 Removed annoying error messages in the product header routines which used
00342 to tell you if it couldn't find stuff to erase.
00343 
00344 Revision 1.29  2007/04/23 12:50:22  jim
00345 Added VIRCAM_TEST_SCIENCE_RAW
00346 
00347 Revision 1.28  2007/04/04 10:34:42  jim
00348 Complete rewrite of the dfs tags
00349 
00350 Revision 1.27  2007/03/23 10:53:22  jim
00351 Fixed little documentation errors
00352 
00353 Revision 1.26  2007/03/01 12:42:41  jim
00354 Modified slightly after code checking
00355 
00356 Revision 1.25  2007/02/15 11:53:45  jim
00357 Added type CHANNEL_TABLE_INIT
00358 
00359 Revision 1.24  2007/02/05 13:54:00  jim
00360 Added REFERENCE tags
00361 
00362 Revision 1.23  2007/01/17 23:53:43  jim
00363 Modified to remove INS, OBS and TEL structures from extension headers
00364 
00365 Revision 1.22  2006/12/06 12:58:57  jim
00366 Added MASTER_FRINGE
00367 
00368 Revision 1.21  2006/11/28 20:57:05  jim
00369 Added ILLUM types
00370 
00371 Revision 1.20  2006/10/05 09:22:59  jim
00372 Small modifications to a couple of cpl calls to bring them into line with
00373 cpl v3.0
00374 
00375 Revision 1.19  2006/07/04 09:19:04  jim
00376 replaced all sprintf statements with snprintf
00377 
00378 Revision 1.18  2006/06/14 14:13:58  jim
00379 fixed minor doc problem
00380 
00381 Revision 1.17  2006/06/13 21:26:02  jim
00382 Added VIRCAM_CALIB_READNOISE_FILE
00383 
00384 Revision 1.16  2006/05/24 13:33:56  jim
00385 Added VIRCAM_PHOTTAB
00386 
00387 Revision 1.15  2006/05/18 12:32:23  jim
00388 Added channel table and object catalogue to calib list
00389 
00390 Revision 1.14  2006/04/27 09:46:27  jim
00391 Modified to conform to new dictionary
00392 
00393 Revision 1.13  2006/04/26 09:39:35  jim
00394 Fixes the pipeline id to the header
00395 
00396 Revision 1.12  2006/04/25 13:47:59  jim
00397 Modified calls to vircam_dfs_set_product_*_header routines
00398 
00399 Revision 1.11  2006/04/20 11:19:22  jim
00400 *** empty log message ***
00401 
00402 Revision 1.10  2006/03/22 13:14:24  jim
00403 Sorted data categories
00404 
00405 Revision 1.9  2006/02/27 13:53:32  jim
00406 Added new categories to vircam_dfs_set_groups
00407 
00408 Revision 1.8  2006/02/18 11:45:01  jim
00409 Added vircam_dfs_set_product_primary_header and
00410 vircam_dfs_set_product_exten_header
00411 
00412 Revision 1.7  2006/01/23 10:30:49  jim
00413 Mainly documentation mods
00414 
00415 Revision 1.6  2005/12/14 22:17:33  jim
00416 Updated docs
00417 
00418 Revision 1.5  2005/11/29 14:56:36  jim
00419 Added a few new categories
00420 
00421 Revision 1.4  2005/11/25 09:56:14  jim
00422 Tidied up some more documentation
00423 
00424 Revision 1.3  2005/11/03 13:28:48  jim
00425 All sorts of changes to tighten up error handling
00426 
00427 Revision 1.2  2005/09/20 15:07:46  jim
00428 Fixed a few bugs and added a few things
00429 
00430 Revision 1.1.1.1  2005/08/05 08:29:09  jim
00431 Initial import
00432 
00433 
00434 */

Generated on 7 Feb 2011 for VIRCAM Pipeline by  doxygen 1.6.1