GRAVI Pipeline Reference Manual 1.9.2
Loading...
Searching...
No Matches
gravi_utils.h
Go to the documentation of this file.
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#define GRAVI_NBASE 6 // Number of baselines
106extern int GRAVI_BASE_TEL[GRAVI_NBASE][2];
107extern char GRAVI_BASE_NAME[GRAVI_NBASE][3];
108extern int GRAVI_TRI_BASE[GRAVI_NBASE][2][2];
109extern int GRAVI_TRI_SIGN[GRAVI_NBASE][2][2];
110extern int GRAVI_CLO_BASE[4][3];
111extern int GRAVI_CLO_TEL[4][3];
112extern char GRAVI_CLO_NAME[4][4];
113extern char GRAVI_DATA[50][7];
114extern char GRAVI_DATAERR[50][10];
115
116#define GRAVI_LBD_FTSC 6
117
118/* MATH */
119#define GRAVI_MATH_RAD_MAS 4.848136811095360246362499795228298560267887751251691952347755e-09
120
121/*
122 * Lab input connected to each GRAVITY input window
123 */
124#define GRAVI_LABINPUT_1 7
125#define GRAVI_LABINPUT_2 5
126#define GRAVI_LABINPUT_3 3
127#define GRAVI_LABINPUT_4 1
128extern int GRAVI_LABINPUT[4];
129
130
131#define SHUTTER_KEY "IPAG INS SHUT" //"GRAVITY SHUT"
132#define SHUTTER_KEY1 "IPAG INS SHUT1 ST" //"GRAVITY SHUT 1"
133#define SHUTTER_KEY2 "IPAG INS SHUT2 ST" //"GRAVITY SHUT 2"
134#define SHUTTER_KEY3 "IPAG INS SHUT3 ST" //"GRAVITY SHUT 3"
135#define SHUTTER_KEY4 "IPAG INS SHUT4 ST" //"GRAVITY SHUT 4"
136#define GRAVI_SHUTTER_KEY "ESO INS SHUT"
137#define GRAVI_SHUTTER_KEY1 "ESO INS SHUT 1"
138#define GRAVI_SHUTTER_KEY2 "ESO INS SHUT 2"
139#define GRAVI_SHUTTER_KEY3 "ESO INS SHUT 3"
140#define GRAVI_SHUTTER_KEY4 "ESO INS SHUT 4"
141#define POLAR_1 "S"
142#define POLAR_2 "P"
143#define POLAR_3 "C"
144#define GRAVI_POLAR(pol,npol) (npol==1 ? "C" : (pol==0 ? "S" : "P") )
145#define PHASE_1 "A"
146#define PHASE_2 "B"
147#define PHASE_3 "C"
148#define PHASE_4 "D"
149#define COHERENCE "COHERENCE"
150#define TRANSMISSION "TRANSMISSION"
151#define PHASE "PHASE"
152
153#define SQR(a) ((sqrarg=(a)) == 0.0 ? 0.0 : sqrarg*sqrarg)
154#define SIGN(a,b) ((b) >= 0.0 ? fabs(a) : -fabs(a))
155#define IMIN(a,b) (((a) < (b)) ? (a) : (b))
156
157/*-----------------------------------------------------------------------------
158 Public prototypes
159 -----------------------------------------------------------------------------*/
160
161const char * gravi_get_license (void) ;
162cpl_error_code gravi_msg_warning (const char * component, const char * msg);
163cpl_error_code gravi_dump_the_boss (double ra, double dec);
164
165int gravi_get_shutter (cpl_propertylist *, int);
166int gravi_check_shutter (cpl_propertylist *, int, int, int, int);
167int gravi_data_check_shutter_beam (gravi_data ** datas, int nb_datas);
168int gravi_get_shutter_id (cpl_propertylist * header);
169int gravi_get_shutter_baseid (cpl_propertylist * header);
170
171int gravi_region_get_base(cpl_table *imaging_detector, int region);
172int gravi_region_get_pol (cpl_table *imaging_detector, int region);
173int gravi_get_region (cpl_table *img_det, int base, char phase, int pol);
174int gravi_region_get_tel (cpl_table *imaging_detector, int region, int beam);
175int gravi_region_get_phaseid (cpl_table *imaging_detector, int region);
176char gravi_region_get_phase (cpl_table *imaging_detector, int region);
177int gravi_region_get_base_sign (cpl_table *imaging_detector, int base);
178
179int gravi_wave_get_nlambda (cpl_table *wave_data, double lambda_min, double lambda_max);
180
181cpl_table * gravi_table_oi_create (int , int , const char * );
182
183int * gravi_image_extract_dimension (cpl_image * );
184
185short gravi_sta_index (int gravi_input, cpl_table * optical_train_table, cpl_table * array_geometry_table);
186
187cpl_size gravi_spectrum_get_nregion (const cpl_table * table);
188cpl_size gravi_spectrum_get_nwave (const cpl_table * table);
189
190double gravi_spectrum_get_flux (const cpl_table * table);
191double gravi_imagelist_get_flux (const cpl_imagelist * imglist);
192
193cpl_error_code gravi_lkdt_get_sequence (cpl_table * oi_table,
194 cpl_size ntel,
195 cpl_size *first,
196 cpl_size *nobs);
197
198cpl_vector * gravi_compute_envelope (const cpl_vector * opd, int wave, int n_wave);
199
200int gravi_conf_get_iss (int gravi_beam, cpl_propertylist * header);
201const char * gravi_conf_get_telname (int gravi_beam, cpl_propertylist * header);
202
203
204#endif
typedefCPL_BEGIN_DECLS struct _gravi_data_ gravi_data
Definition: gravi_data.h:39
const cpl_size ntel
gravi_data * wave_data
Definition: gravi_old.c:1994
cpl_propertylist * header
Definition: gravi_old.c:2004
#define GRAVI_NBASE
Definition: gravi_utils.h:105
int GRAVI_TRI_SIGN[GRAVI_NBASE][2][2]
Definition: gravi_utils.c:61
int gravi_conf_get_iss(int gravi_beam, cpl_propertylist *header)
Definition: gravi_utils.c:1170
cpl_error_code gravi_msg_warning(const char *component, const char *msg)
Definition: gravi_utils.c:127
cpl_error_code gravi_dump_the_boss(double ra, double dec)
Definition: gravi_utils.c:1217
int gravi_region_get_pol(cpl_table *imaging_detector, int region)
Return the polarisation id of a region.
Definition: gravi_utils.c:445
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_get_shutter(cpl_propertylist *, int)
Definition: gravi_utils.c:923
int gravi_region_get_phaseid(cpl_table *imaging_detector, int region)
Return the phase id of a region.
Definition: gravi_utils.c:479
int gravi_region_get_base(cpl_table *imaging_detector, int region)
Return the base of a region.
Definition: gravi_utils.c:361
char GRAVI_BASE_NAME[GRAVI_NBASE][3]
Definition: gravi_utils.c:57
double gravi_imagelist_get_flux(const cpl_imagelist *imglist)
Return the total flux in imagelist.
Definition: gravi_utils.c:1117
int GRAVI_CLO_TEL[4][3]
Definition: gravi_utils.c:64
cpl_size gravi_spectrum_get_nwave(const cpl_table *table)
Definition: gravi_utils.c:1013
double gravi_spectrum_get_flux(const cpl_table *table)
Return the total flux in DATA# regions.
Definition: gravi_utils.c:1042
int gravi_check_shutter(cpl_propertylist *, int, int, int, int)
Definition: gravi_utils.c:943
const char * gravi_get_license(void)
Get the pipeline copyright and license.
Definition: gravi_utils.c:104
char GRAVI_DATAERR[50][10]
Definition: gravi_utils.c:79
char GRAVI_DATA[50][7]
Definition: gravi_utils.c:71
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
const char * gravi_conf_get_telname(int gravi_beam, cpl_propertylist *header)
Definition: gravi_utils.c:1191
cpl_size gravi_spectrum_get_nregion(const cpl_table *table)
Definition: gravi_utils.c:1018
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_LABINPUT[4]
Definition: gravi_utils.c:88
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_BASE_TEL[GRAVI_NBASE][2]
Definition: gravi_utils.c:56
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_get_shutter_id(cpl_propertylist *header)
Definition: gravi_utils.c:956
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_data_check_shutter_beam(gravi_data **datas, int nb_datas)
Definition: gravi_utils.c:986
char GRAVI_CLO_NAME[4][4]
Definition: gravi_utils.c:65
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
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
int GRAVI_TRI_BASE[GRAVI_NBASE][2][2]
Definition: gravi_utils.c:60
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
int GRAVI_CLO_BASE[4][3]
Definition: gravi_utils.c:68
int gravi_get_shutter_baseid(cpl_propertylist *header)
Definition: gravi_utils.c:970
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