GRAVI Pipeline Reference Manual  1.2.3
gravi_utils.h
1 /* $Id: gravi_utils.c,v 1.10 2011/05/31 06:10:40 nazouaoui Exp $
2  *
3  * This file is part of the GRAVI 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 #ifndef GRAVI_UTILS_H
22 #define GRAVI_UTILS_H
23 
24 /*-----------------------------------------------------------------------------
25  Includes
26  -----------------------------------------------------------------------------*/
27 
28 #include <cpl.h>
29 #include"gravi_data.h"
30 
31 /*-----------------------------------------------------------------------------
32  Macros
33  -----------------------------------------------------------------------------*/
34 
35 /* Manipulate bits */
36 #define gravi_bit_set(number, pos) do{(number) |= (1 << ((int)pos));}while(0)
37 #define gravi_bit_clear(number, pos) do{(number) &= (~(1 << ((int)pos)));}while(0)
38 #define gravi_bit_get(number, pos) (1 & ((number) >> ((int)pos)))
39 
40 
41 /* Check the CPL errorstate and rise a new error */
42 #define CPLCHECK(msg) do{int code; if( (code=cpl_error_get_code ()) ) { cpl_msg_error(cpl_func,msg); cpl_error_set_message(cpl_func, code, msg); }} while (0)
43 
44 /* Check the CPL errorstate and goto exit the cpl error code */
45 #define CPLCHECK_MSG(msg) do{int code; if( (code=cpl_error_get_code ()) ) { cpl_msg_error(cpl_func,msg); return cpl_error_set_message(cpl_func, code, msg); }} while (0)
46 
47 /* Check the CPL errorstate and goto exit as NULL */
48 #define CPLCHECK_NUL(msg) do{int code; if( (code=cpl_error_get_code ()) ) { cpl_msg_error(cpl_func,msg); cpl_error_set_message(cpl_func, code, msg); return NULL; }} while (0)
49 
50 /* Check the CPL errorstate and goto exit the cpl error code as int */
51 #define CPLCHECK_INT(msg) do{int code; if( (code=cpl_error_get_code ()) ) { cpl_msg_error(cpl_func,msg); cpl_error_set_message(cpl_func, code, msg); return code; }} while (0)
52 
53 /* Check the CPL errorstate and goto 'clean' */
54 #define CPLCHECK_CLEAN(msg) do{int code; if( (code=cpl_error_get_code ()) ) { cpl_msg_error(cpl_func,msg); cpl_error_set_message(cpl_func, code, msg); goto cleanup; }} while (0)
55 
56 /* Check the CPL errorstate and goto 'tag' */
57 #define CPLCHECK_GOTO(msg,tag) do{int code; if( (code=cpl_error_get_code ()) ) { cpl_msg_error(cpl_func,msg); cpl_error_set_message(cpl_func, code, msg); goto tag; }} while (0)
58 
59 /* Check the CPL errorstate and goto 'clean' */
60 #define ERROR_CLEAN(code,msg) do{cpl_msg_error(cpl_func,msg); cpl_error_set_message(cpl_func, code, msg); goto cleanup;} while (0)
61 
62 /* Check the CPL errorstate and goto exit as NULL */
63 #define CHECK_NUL(flag,msg) do{ if( flag ) { cpl_msg_error(cpl_func,msg); cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, msg); return NULL; }} while (0)
64 
65 /* Check the CPL errorstate and goto exit the cpl error code */
66 #define CHECK_MSG(flag,msg) do{ if( flag ) { cpl_msg_error(cpl_func,msg); return cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT, msg); }} while (0)
67 
68 /* Protected memory free */
69 #define FREE(function,variable) do{ if (variable) { function(variable); variable=NULL;} } while (0)
70 
71 /* Protected memory free of an array of variable */
72 #define FREELOOP(function,variable,n) do{ if (variable) { for (int iloopfree = 0 ; iloopfree < n; iloopfree++) { if (variable[iloopfree]) { function( variable[iloopfree] ); variable[iloopfree] = NULL; } } if (variable) { cpl_free (variable); variable = NULL; } } } while (0)
73 
74 /* Get a the short filename */
75 #define FILESHORT(file) (strrchr(file, '/') ? strrchr(file, '/') + 1 : file)
76 
77 #define TEST_MESSAGE cpl_msg_info (cpl_func,">>>>>>> TEST <<<<<<<")
78 
79 
80 /* Much faster than pow (data, 2) on my compilator */
81 #define gravi_pow2(data) data*data
82 
83 /* Timer function to enter and exit function */
84 # define gravi_msg_function_start(flag) clock_t timer_function = clock(); do{ if(flag) cpl_msg_info(cpl_func,"Start function %s", cpl_func); }while(0)
85 # define gravi_msg_function_exit(flag) do{ if(flag) cpl_msg_info(cpl_func,"Exit function %s (%.6f s)",cpl_func,(double)(clock()-timer_function)/(double)CLOCKS_PER_SEC); }while(0)
86 
87 /* Test shutters all open or all closed */
88 # define gravi_data_get_shutter(data,tel) gravi_get_shutter (gravi_data_get_header(data),tel)
89 # define gravi_data_check_shutter(data,t0,t1,t2,t3) gravi_check_shutter (gravi_data_get_header(data), t0,t1,t2,t3)
90 # define gravi_data_check_shutter_closed(data) gravi_check_shutter (gravi_data_get_header(data), 0,0,0,0)
91 # define gravi_data_check_shutter_open(data) gravi_check_shutter (gravi_data_get_header(data), 1,1,1,1)
92 # define gravi_spectrum_get_npol(table) (gravi_spectrum_get_nregion (table) > 24 ? 2 : 1)
93 
94 
95 /*-----------------------------------------------------------------------------
96  Defines and Static variables
97  -----------------------------------------------------------------------------*/
98 
99 /*
100  * Baseline and telescope order.
101  * Also define closing triangles of each baseline
102  * and closure phases
103  */
104 
105 extern int GRAVI_BASE_TEL[6][2];
106 extern char GRAVI_BASE_NAME[6][3];
107 extern int GRAVI_TRI_BASE[6][2][2];
108 extern int GRAVI_TRI_SIGN[6][2][2];
109 extern int GRAVI_CLO_BASE[4][3];
110 extern int GRAVI_CLO_TEL[4][3];
111 extern char GRAVI_CLO_NAME[4][4];
112 extern char GRAVI_DATA[50][7];
113 extern char GRAVI_DATAERR[50][10];
114 
115 #define GRAVI_LBD_FTSC 6
116 
117 /* MATH */
118 #define GRAVI_MATH_RAD_MAS 4.848136811095360246362499795228298560267887751251691952347755e-09
119 
120 /*
121  * Lab input connected to each GRAVITY input window
122  */
123 #define GRAVI_LABINPUT_1 7
124 #define GRAVI_LABINPUT_2 5
125 #define GRAVI_LABINPUT_3 3
126 #define GRAVI_LABINPUT_4 1
127 extern int GRAVI_LABINPUT[4];
128 
129 
130 #define SHUTTER_KEY "IPAG INS SHUT" //"GRAVITY SHUT"
131 #define SHUTTER_KEY1 "IPAG INS SHUT1 ST" //"GRAVITY SHUT 1"
132 #define SHUTTER_KEY2 "IPAG INS SHUT2 ST" //"GRAVITY SHUT 2"
133 #define SHUTTER_KEY3 "IPAG INS SHUT3 ST" //"GRAVITY SHUT 3"
134 #define SHUTTER_KEY4 "IPAG INS SHUT4 ST" //"GRAVITY SHUT 4"
135 #define GRAVI_SHUTTER_KEY "ESO INS SHUT"
136 #define GRAVI_SHUTTER_KEY1 "ESO INS SHUT 1"
137 #define GRAVI_SHUTTER_KEY2 "ESO INS SHUT 2"
138 #define GRAVI_SHUTTER_KEY3 "ESO INS SHUT 3"
139 #define GRAVI_SHUTTER_KEY4 "ESO INS SHUT 4"
140 #define POLAR_1 "S"
141 #define POLAR_2 "P"
142 #define POLAR_3 "C"
143 #define GRAVI_POLAR(pol,npol) (npol==1 ? "C" : (pol==0 ? "S" : "P") )
144 #define PHASE_1 "A"
145 #define PHASE_2 "B"
146 #define PHASE_3 "C"
147 #define PHASE_4 "D"
148 #define COHERENCE "COHERENCE"
149 #define TRANSMISSION "TRANSMISSION"
150 #define PHASE "PHASE"
151 
152 #define SQR(a) ((sqrarg=(a)) == 0.0 ? 0.0 : sqrarg*sqrarg)
153 #define SIGN(a,b) ((b) >= 0.0 ? fabs(a) : -fabs(a))
154 #define IMIN(a,b) (((a) < (b)) ? (a) : (b))
155 
156 /*-----------------------------------------------------------------------------
157  Public prototypes
158  -----------------------------------------------------------------------------*/
159 
160 const char * gravi_get_license (void) ;
161 cpl_error_code gravi_msg_warning (const char * component, const char * msg);
162 cpl_error_code gravi_dump_the_boss (double ra, double dec);
163 
164 int gravi_get_shutter (cpl_propertylist *, int);
165 int gravi_check_shutter (cpl_propertylist *, int, int, int, int);
166 int gravi_data_check_shutter_beam (gravi_data ** datas, int nb_datas);
167 int gravi_get_shutter_id (cpl_propertylist * header);
168 int gravi_get_shutter_baseid (cpl_propertylist * header);
169 
170 int gravi_region_get_base(cpl_table *imaging_detector, int region);
171 int gravi_region_get_pol (cpl_table *imaging_detector, int region);
172 int gravi_get_region (cpl_table *img_det, int base, char phase, int pol);
173 int gravi_region_get_tel (cpl_table *imaging_detector, int region, int beam);
174 int gravi_region_get_phaseid (cpl_table *imaging_detector, int region);
175 char gravi_region_get_phase (cpl_table *imaging_detector, int region);
176 int gravi_region_get_base_sign (cpl_table *imaging_detector, int base);
177 
178 int gravi_wave_get_nlambda (cpl_table *wave_data, double lambda_min, double lambda_max);
179 
180 cpl_table * gravi_table_oi_create (int , int , const char * );
181 
182 int * gravi_image_extract_dimension (cpl_image * );
183 
184 short gravi_sta_index (int gravi_input, cpl_table * optical_train_table, cpl_table * array_geometry_table);
185 
186 cpl_size gravi_spectrum_get_nregion (const cpl_table * table);
187 cpl_size gravi_spectrum_get_nwave (const cpl_table * table);
188 
189 double gravi_spectrum_get_flux (const cpl_table * table);
190 double gravi_imagelist_get_flux (const cpl_imagelist * imglist);
191 
192 cpl_error_code gravi_lkdt_get_sequence (cpl_table * oi_table,
193  cpl_size ntel,
194  cpl_size *first,
195  cpl_size *nobs);
196 
197 cpl_vector * gravi_compute_envelope (const cpl_vector * opd, int wave, int n_wave);
198 
199 int gravi_conf_get_iss (int gravi_beam, cpl_propertylist * header);
200 const char * gravi_conf_get_telname (int gravi_beam, cpl_propertylist * header);
201 
202 
203 #endif
short gravi_sta_index(int gravi_input, cpl_table *optical_train_table, cpl_table *array_geometry_table)
Retrieve STA_INDEX corresponding to a given input.
Definition: gravi_utils.c:828
int gravi_region_get_pol(cpl_table *imaging_detector, int region)
Return the polarisation id of a region.
Definition: gravi_utils.c:445
int gravi_region_get_base(cpl_table *imaging_detector, int region)
Return the base of a region.
Definition: gravi_utils.c:361
int gravi_region_get_base_sign(cpl_table *imaging_detector, int base)
Return the sign of a base by looking at the PORT order.
Definition: gravi_utils.c:399
cpl_error_code gravi_lkdt_get_sequence(cpl_table *oi_table, cpl_size ntel, cpl_size *first, cpl_size *nobs)
Return the longuest sequence with constant LKDT.
Definition: gravi_utils.c:1145
double gravi_imagelist_get_flux(const cpl_imagelist *imglist)
Return the total flux in imagelist.
Definition: gravi_utils.c:1117
cpl_vector * gravi_compute_envelope(const cpl_vector *opd, int wave, int n_wave)
Compute the envelope value.
Definition: gravi_utils.c:1081
int gravi_get_region(cpl_table *img_det, int base, char phase, int pol)
Find the region matching base, phase and pol.
Definition: gravi_utils.c:584
int * gravi_image_extract_dimension(cpl_image *)
Compute startx and nx of the illuminated part of the image.
Definition: gravi_utils.c:727
int gravi_region_get_phaseid(cpl_table *imaging_detector, int region)
Return the phase id of a region.
Definition: gravi_utils.c:479
const char * gravi_get_license(void)
Get the pipeline copyright and license.
Definition: gravi_utils.c:104
double gravi_spectrum_get_flux(const cpl_table *table)
Return the total flux in DATA# regions.
Definition: gravi_utils.c:1042
char gravi_region_get_phase(cpl_table *imaging_detector, int region)
Return the phase character of a region.
Definition: gravi_utils.c:551
int gravi_region_get_tel(cpl_table *imaging_detector, int region, int beam)
Return the telescope id (0,1,2,3) in a beam of a region.
Definition: gravi_utils.c:512
int gravi_wave_get_nlambda(cpl_table *wave_data, double lambda_min, double lambda_max)
Get the number of spectral element between lambdamin et lambdamax.
Definition: gravi_utils.c:611
cpl_table * gravi_table_oi_create(int, int, const char *)
Create the oi table (oi_vis, oi_vis2, oi_t3)
Definition: gravi_utils.c:153