UVES Pipeline Reference Manual  5.4.6
uves_physmod_chop_otab.c
1 
2 /* *
3  * This file is part of the ESO UVES Pipeline *
4  * Copyright (C) 2004,2005 European Southern Observatory *
5  * *
6  * This library 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, 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA *
19  * */
20 
21 /*
22  * $Author: amodigli $
23  * $Date: 2010-09-24 09:32:07 $
24  * $Revision: 1.14 $
25  * $Name: not supported by cvs2svn $
26  * $Log: not supported by cvs2svn $
27  * Revision 1.12 2008/11/06 14:36:27 amodigli
28  * fixed mem leaks
29  *
30  * Revision 1.11 2008/05/13 08:44:32 amodigli
31  * added check on guess order table spectral format size
32  *
33  * Revision 1.10 2008/05/01 09:44:10 amodigli
34  * modify table after chop
35  *
36  * Revision 1.9 2007/06/06 08:17:33 amodigli
37  * replace tab with 4 spaces
38  *
39  * Revision 1.8 2007/05/16 16:32:55 amodigli
40  * changed factor from 0.05to 0.075
41  *
42  * Revision 1.7 2007/04/24 12:50:29 jmlarsen
43  * Replaced cpl_propertylist -> uves_propertylist which is much faster
44  *
45  * Revision 1.6 2006/11/06 15:19:41 jmlarsen
46  * Removed unused include directives
47  *
48  * Revision 1.5 2006/07/28 14:51:26 amodigli
49  * fixed some bugs on improper table selection
50  *
51  * Revision 1.4 2006/06/05 08:51:55 amodigli
52  * cleaned some warnings from static checks
53  *
54  * Revision 1.3 2006/05/09 15:42:48 amodigli
55  * safer way to do selection
56  *
57  * Revision 1.2 2006/05/08 15:42:16 amodigli
58  * allow to specify order column label
59  *
60  * Revision 1.1 2006/02/03 07:46:30 jmlarsen
61  * Moved recipe implementations to ./uves directory
62  *
63  * Revision 1.5 2006/01/19 08:47:24 jmlarsen
64  * Inserted missing doxygen end tag
65  *
66  * Revision 1.4 2006/01/16 08:01:57 amodigli
67  *
68  * Added stability check
69  *
70  * Revision 1.3 2006/01/09 14:05:42 amodigli
71  * Fixed doxigen warnings
72  *
73  * Revision 1.2 2006/01/03 16:57:13 amodigli
74  * Fixed bug
75  *
76  * Revision 1.1 2006/01/03 14:47:53 amodigli
77  *
78  * Added uves_physmod_chop_otab.h .c to match MIDAS
79  *
80  * Revision 1.3 2005/12/19 16:17:55 jmlarsen
81  * Replaced bool -> int
82  *
83  */
84 
85 /*----------------------------------------------------------------------------*/
89 /*----------------------------------------------------------------------------*/
92 #ifdef HAVE_CONFIG_H
93 # include <config.h>
94 #endif
95 
96 /*-----------------------------------------------------------------------------
97  Includes
98  -----------------------------------------------------------------------------*/
99 #include <uves_physmod_chop_otab.h>
100 
101 #include <uves_utils_wrappers.h>
102 #include <uves_pfits.h>
103 #include <uves_error.h>
104 
105 /*-----------------------------------------------------------------------------
106  Defines
107  -----------------------------------------------------------------------------*/
108 /*-----------------------------------------------------------------------------
109  Functions prototypes
110  ----------------------------------------------------------------------------*/
111 /*-----------------------------------------------------------------------------
112  Static variables
113  -----------------------------------------------------------------------------*/
114 
115 /*-----------------------------------------------------------------------------
116  Functions code
117  -----------------------------------------------------------------------------*/
118 
119 /*----------------------------------------------------------------------------*/
134 /*----------------------------------------------------------------------------*/
135 
137  enum uves_chip chip,
138  cpl_table** ord_tbl,
139  const char* col_name,
140  int * ord_min,
141  int * ord_max)
142 {
143 
144  int nx=0;
145  int ny=0;
146 
147  double xbox[2]={0,0};
148  double ybox[2]={0,0};
149  const double fct=0.075;
150  const double add=50.;
151  cpl_table* tmp_tbl1=NULL;
152  cpl_table* tmp_tbl2=NULL;
153 
154  /* note those are swapped */
155  check (ny = uves_pfits_get_nx(raw_header,chip),
156  "Could not read nx from input header");
157  check (nx = uves_pfits_get_ny(raw_header,chip),
158  "Could not read ny from input header");
159 
160  xbox[0]=(double)(nx/2-nx*fct);
161  xbox[1]=(double)(nx/2+nx*fct);
162  ybox[0]=add;
163  ybox[1]=(double)(ny-add);
164 
165  uves_msg_debug("NX=%d NY=%d",nx,ny);
166  uves_msg_debug("xbox=%f,%f ybox=%f,%f",xbox[0],xbox[1],ybox[0],ybox[1]);
167 
168  check(tmp_tbl1=uves_extract_table_rows(*ord_tbl,"X",CPL_GREATER_THAN,xbox[0]),
169  "Error selecting X");
170 
171  check(tmp_tbl2=uves_extract_table_rows(tmp_tbl1,"X",CPL_LESS_THAN,xbox[1]),
172  "Error selecting X");
173  uves_free_table(&tmp_tbl1);
174 
175  check_nomsg(*ord_min=(int)cpl_table_get_column_min(tmp_tbl2,col_name));
176  check_nomsg(*ord_max=(int)cpl_table_get_column_max(tmp_tbl2,col_name));
177  uves_free_table(&tmp_tbl2);
178  uves_msg_debug("ord_min=%d ord_max=%d",*ord_min,*ord_max);
179 
180  check(tmp_tbl1=uves_extract_table_rows(*ord_tbl,col_name,
181  CPL_NOT_GREATER_THAN,*ord_max),
182  "Error selecting Order");
183  uves_free_table(ord_tbl);
184  check(*ord_tbl=uves_extract_table_rows(tmp_tbl1,col_name,
185  CPL_NOT_LESS_THAN,*ord_min),
186  "Error selecting Order");
187 
188 
189  cleanup:
190  uves_free_table(&tmp_tbl1);
191  uves_free_table(&tmp_tbl2);
192 
193  return 0;
194 
195 }
int uves_pfits_get_nx(const uves_propertylist *plist, enum uves_chip chip)
Find out the OUT1 NX or OUT4 NX.
Definition: uves_pfits.c:2126
int uves_pfits_get_ny(const uves_propertylist *plist, enum uves_chip chip)
Find out the OUT1 NY or OUT4 NY.
Definition: uves_pfits.c:2155
#define check_nomsg(CMD)
Definition: uves_error.h:204
int uves_physmod_chop_otab(const uves_propertylist *raw_header, enum uves_chip chip, cpl_table **ord_tbl, const char *col_name, int *ord_min, int *ord_max)
Chop off orders which are not fully in the detector chip.
#define uves_msg_debug(...)
Print a debug message.
Definition: uves_msg.h:97
#define check(CMD,...)
Definition: uves_error.h:198