CRIRES Pipeline Reference Manual 2.3.18
crires_util_genypos.c
1/* $Id: crires_util_genypos.c,v 1.2 2012-10-09 08:18:01 yjung Exp $
2 *
3 * This file is part of the CRIRES 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: yjung $
23 * $Date: 2012-10-09 08:18:01 $
24 * $Revision: 1.2 $
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 "crires_recipe.h"
37
38/*-----------------------------------------------------------------------------
39 Define
40 -----------------------------------------------------------------------------*/
41
42#define RECIPE_STRING "crires_util_genypos"
43
44/*-----------------------------------------------------------------------------
45 Functions prototypes
46 -----------------------------------------------------------------------------*/
47
48static int crires_util_genypos_save(cpl_table *, const cpl_parameterlist *,
49 cpl_frameset *);
50
51static char crires_util_genypos_description[] =
52"This recipe is used to generate the FITS table with the Y positions.\n"
53"The sof file contains the names of the input ASCII file\n"
54"tagged with "CRIRES_UTIL_GENYPOS_RAW".\n"
55"The ASCII file must contain two columns:\n"
56"1st: Chip Number\n"
57"2nd: Y Position\n"
58"The ASCII file is in the catalogs/ directory of the CRIRES distribution.\n"
59"This recipe produces 1 file:\n"
60"First product: the table with the positions.\n"
61" (PRO TYPE = "CRIRES_PROTYPE_YPOS")\n" ;
62
63CRIRES_RECIPE_DEFINE(crires_util_genypos, 0,
64 "Generate Y Positions FITS table",
65 crires_util_genypos_description) ;
66
67/*-----------------------------------------------------------------------------
68 Static variables
69 -----------------------------------------------------------------------------*/
70
71/*-----------------------------------------------------------------------------
72 Functions code
73 -----------------------------------------------------------------------------*/
74
75/*----------------------------------------------------------------------------*/
84/*----------------------------------------------------------------------------*/
85static int crires_util_genypos(
86 cpl_frameset * framelist,
87 const cpl_parameterlist * parlist)
88{
89 cpl_bivector * bivec ;
90 double * pbivec_x ;
91 double * pbivec_y ;
92 cpl_bivector * bivec_fill ;
93 double * pbivec_fill_x ;
94 double * pbivec_fill_y ;
95 cpl_frame * cur_frame ;
96 int nvals, nb_new_vals ;
97 double wavel ;
98 cpl_table * tab ;
99 int i ;
100
101 /* Identify the RAW and CALIB frames in the input frameset */
102 if (crires_dfs_set_groups(framelist, NULL)) {
103 cpl_msg_error(__func__, "Cannot identify RAW and CALIB frames") ;
104 return -1 ;
105 }
106
107 /* Load the file */
108 cur_frame = cpl_frameset_get_position(framelist, 0) ;
109 if ((bivec=cpl_bivector_read(cpl_frame_get_filename(cur_frame)))==NULL) {
110 cpl_msg_error(__func__, "Cannot load the file in the bivector") ;
111 return -1 ;
112 }
113 nvals = cpl_bivector_get_size(bivec) ;
114
115 /* Allocate the data container */
116 tab = cpl_table_new(nvals) ;
117 cpl_table_wrap_double(tab, cpl_bivector_get_x_data(bivec),
118 CRIRES_CHIP_NB) ;
119 cpl_table_wrap_double(tab, cpl_bivector_get_y_data(bivec),
120 CRIRES_COL_DETPOSY) ;
121
122 /* Save the table */
123 cpl_msg_info(__func__, "Saving the table with %d rows", nvals) ;
124 if (crires_util_genypos_save(tab, parlist, framelist) == -1) {
125 cpl_msg_error(__func__, "Cannot write the table") ;
126 cpl_bivector_delete(bivec) ;
127 cpl_table_unwrap(tab, CRIRES_CHIP_NB) ;
128 cpl_table_unwrap(tab, CRIRES_COL_DETPOSY) ;
129 cpl_table_delete(tab) ;
130 return -1 ;
131 }
132 cpl_bivector_delete(bivec) ;
133 cpl_table_unwrap(tab, CRIRES_CHIP_NB) ;
134 cpl_table_unwrap(tab, CRIRES_COL_DETPOSY) ;
135 cpl_table_delete(tab) ;
136 return 0 ;
137}
138
139/*----------------------------------------------------------------------------*/
147/*----------------------------------------------------------------------------*/
148static int crires_util_genypos_save(
149 cpl_table * out_table,
150 const cpl_parameterlist * parlist,
151 cpl_frameset * set)
152{
153 cpl_propertylist * plist ;
154
155 plist = cpl_propertylist_new();
156 cpl_propertylist_append_string(plist, "INSTRUME", "CRIRES") ;
157 cpl_propertylist_append_string(plist, CPL_DFS_PRO_CATG,
158 CRIRES_CALPRO_THAR_POS) ;
159 cpl_propertylist_append_string(plist, CPL_DFS_PRO_TYPE,
160 CRIRES_PROTYPE_YPOS) ;
161
162 if (cpl_dfs_save_table(set, NULL, parlist, set, NULL, out_table,
163 NULL, "crires_util_genypos", plist, NULL,
164 PACKAGE "/" PACKAGE_VERSION,
165 "crires_util_genypos.fits") != CPL_ERROR_NONE) {
166 cpl_msg_error(__func__, "Cannot save the table") ;
167 return -1 ;
168 }
169 cpl_propertylist_delete(plist) ;
170
171 /* Return */
172 return 0 ;
173}