CRIRES Pipeline Reference Manual  2.3.2
crires_util_genypos.c
00001 /* $Id: crires_util_genypos.c,v 1.2 2012-10-09 08:18:01 yjung Exp $
00002  *
00003  * This file is part of the CRIRES Pipeline
00004  * Copyright (C) 2002,2003 European Southern Observatory
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: yjung $
00023  * $Date: 2012-10-09 08:18:01 $
00024  * $Revision: 1.2 $
00025  * $Name: not supported by cvs2svn $
00026  */
00027 
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031 
00032 /*-----------------------------------------------------------------------------
00033                                 Includes
00034  -----------------------------------------------------------------------------*/
00035 
00036 #include "crires_recipe.h"
00037 
00038 /*-----------------------------------------------------------------------------
00039                                 Define
00040  -----------------------------------------------------------------------------*/
00041 
00042 #define RECIPE_STRING "crires_util_genypos"
00043 
00044 /*-----------------------------------------------------------------------------
00045                             Functions prototypes
00046  -----------------------------------------------------------------------------*/
00047 
00048 static int crires_util_genypos_save(cpl_table *, const cpl_parameterlist *, 
00049         cpl_frameset *);
00050 
00051 static char crires_util_genypos_description[] =
00052 "This recipe is used to generate the FITS table with the Y positions.\n"
00053 "The sof file contains the names of the input ASCII file\n"
00054 "tagged with "CRIRES_UTIL_GENYPOS_RAW".\n"
00055 "The ASCII file must contain two columns:\n"
00056 "1st: Chip Number\n"
00057 "2nd: Y Position\n"
00058 "The ASCII file is in the catalogs/ directory of the CRIRES distribution.\n"
00059 "This recipe produces 1 file:\n"
00060 "First product:     the table with the positions.\n"
00061 "                   (PRO TYPE = "CRIRES_PROTYPE_YPOS")\n" ;
00062 
00063 CRIRES_RECIPE_DEFINE(crires_util_genypos, 0,
00064         "Generate Y Positions FITS table",
00065         crires_util_genypos_description) ;
00066 
00067 /*-----------------------------------------------------------------------------
00068                             Static variables
00069  -----------------------------------------------------------------------------*/
00070 
00071 /*-----------------------------------------------------------------------------
00072                                 Functions code
00073  -----------------------------------------------------------------------------*/
00074 
00075 /*----------------------------------------------------------------------------*/
00084 /*----------------------------------------------------------------------------*/
00085 static int crires_util_genypos(
00086         cpl_frameset            *   framelist,
00087         const cpl_parameterlist *   parlist)
00088 {
00089     cpl_bivector    *   bivec ;
00090     double          *   pbivec_x ;
00091     double          *   pbivec_y ;
00092     cpl_bivector    *   bivec_fill ;
00093     double          *   pbivec_fill_x ;
00094     double          *   pbivec_fill_y ;
00095     cpl_frame       *   cur_frame ;
00096     int                 nvals, nb_new_vals ;
00097     double              wavel ;
00098     cpl_table       *   tab ;
00099     int                 i ;
00100 
00101     /* Identify the RAW and CALIB frames in the input frameset */
00102     if (crires_dfs_set_groups(framelist, NULL)) {
00103         cpl_msg_error(__func__, "Cannot identify RAW and CALIB frames") ;
00104         return -1 ;
00105     }
00106    
00107     /* Load the file */
00108     cur_frame = cpl_frameset_get_position(framelist, 0) ;
00109     if ((bivec=cpl_bivector_read(cpl_frame_get_filename(cur_frame)))==NULL) {
00110         cpl_msg_error(__func__, "Cannot load the file in the bivector") ;
00111         return -1 ;
00112     }
00113     nvals = cpl_bivector_get_size(bivec) ;
00114     
00115     /* Allocate the data container */
00116     tab = cpl_table_new(nvals) ;
00117     cpl_table_wrap_double(tab, cpl_bivector_get_x_data(bivec),
00118             CRIRES_CHIP_NB) ;
00119     cpl_table_wrap_double(tab, cpl_bivector_get_y_data(bivec), 
00120             CRIRES_COL_DETPOSY) ;
00121    
00122     /* Save the table */
00123     cpl_msg_info(__func__, "Saving the table with %d rows", nvals) ;
00124     if (crires_util_genypos_save(tab, parlist, framelist) == -1) {
00125         cpl_msg_error(__func__, "Cannot write the table") ;
00126         cpl_bivector_delete(bivec) ;
00127         cpl_table_unwrap(tab, CRIRES_CHIP_NB) ;
00128         cpl_table_unwrap(tab, CRIRES_COL_DETPOSY) ;
00129         cpl_table_delete(tab) ;
00130         return -1 ;
00131     }
00132     cpl_bivector_delete(bivec) ;
00133     cpl_table_unwrap(tab, CRIRES_CHIP_NB) ;
00134     cpl_table_unwrap(tab, CRIRES_COL_DETPOSY) ;
00135     cpl_table_delete(tab) ;
00136     return 0 ;
00137 }
00138 
00139 /*----------------------------------------------------------------------------*/
00147 /*----------------------------------------------------------------------------*/
00148 static int crires_util_genypos_save(
00149         cpl_table               *   out_table,
00150         const cpl_parameterlist *   parlist,
00151         cpl_frameset            *   set)
00152 {
00153     cpl_propertylist    *   plist ;
00154 
00155     plist = cpl_propertylist_new();
00156     cpl_propertylist_append_string(plist, "INSTRUME", "CRIRES") ;
00157     cpl_propertylist_append_string(plist, CPL_DFS_PRO_CATG, 
00158             CRIRES_CALPRO_THAR_POS) ;
00159     cpl_propertylist_append_string(plist, CPL_DFS_PRO_TYPE, 
00160             CRIRES_PROTYPE_YPOS) ;
00161 
00162     if (cpl_dfs_save_table(set, NULL, parlist, set, NULL, out_table,
00163                 NULL, "crires_util_genypos", plist, NULL,
00164                 PACKAGE "/" PACKAGE_VERSION,
00165                 "crires_util_genypos.fits") != CPL_ERROR_NONE) {
00166         cpl_msg_error(__func__, "Cannot save the table") ;
00167         return -1 ;
00168     }
00169     cpl_propertylist_delete(plist) ;
00170 
00171     /* Return */
00172     return 0 ;
00173 }