56int GRAVI_BASE_TEL[6][2] = { {0,1}, {0,2}, {0,3}, {1,2}, {1,3}, {2,3} };
60int GRAVI_TRI_BASE[6][2][2] = { {{1,3},{2,4}}, {{0,3},{2,5}}, {{0,4},{1,5}}, {{0,1},{4,5}}, {{0,2},{3,5}}, {{1,2},{3,4}}};
61int GRAVI_TRI_SIGN[6][2][2] = { {{1,-1},{1,-1}}, {{1,1},{1,-1}}, {{1,1},{1,1}}, {{-1,1},{1,-1}}, {{-1,1},{1,1}}, {{-1,1},{-1,1}} };
64int GRAVI_CLO_TEL[4][3] = {{0,1,2}, {0,1,3}, {0,2,3}, {1,2,3}};
68int GRAVI_CLO_BASE[4][3] = {{0,3,1}, {0,4,2}, {1,5,2}, {3,5,4}};
72 {
"DATA1",
"DATA2",
"DATA3",
"DATA4",
"DATA5",
"DATA6",
"DATA7",
"DATA8",
"DATA9",
"DATA10",
73 "DATA11",
"DATA12",
"DATA13",
"DATA14",
"DATA15",
"DATA16",
"DATA17",
"DATA18",
"DATA19",
"DATA20",
74 "DATA21",
"DATA22",
"DATA23",
"DATA24",
"DATA25",
"DATA26",
"DATA27",
"DATA28",
"DATA29",
"DATA30",
75 "DATA31",
"DATA32",
"DATA33",
"DATA34",
"DATA35",
"DATA36",
"DATA37",
"DATA38",
"DATA39",
"DATA40",
76 "DATA41",
"DATA42",
"DATA43",
"DATA44",
"DATA45",
"DATA46",
"DATA47",
"DATA48",
"DATA49",
"DATA50"};
80 {
"DATAERR1",
"DATAERR2",
"DATAERR3",
"DATAERR4",
"DATAERR5",
"DATAERR6",
"DATAERR7",
"DATAERR8",
"DATAERR9",
"DATAERR10",
81 "DATAERR11",
"DATAERR12",
"DATAERR13",
"DATAERR14",
"DATAERR15",
"DATAERR16",
"DATAERR17",
"DATAERR18",
"DATAERR19",
"DATAERR20",
82 "DATAERR21",
"DATAERR22",
"DATAERR23",
"DATAERR24",
"DATAERR25",
"DATAERR26",
"DATAERR27",
"DATAERR28",
"DATAERR29",
"DATAERR30",
83 "DATAERR31",
"DATAERR32",
"DATAERR33",
"DATAERR34",
"DATAERR35",
"DATAERR36",
"DATAERR37",
"DATAERR38",
"DATAERR39",
"DATAERR40",
84 "DATAERR41",
"DATAERR42",
"DATAERR43",
"DATAERR44",
"DATAERR45",
"DATAERR46",
"DATAERR47",
"DATAERR48",
"DATAERR49",
"DATAERR50"};
106 const char * gravi_license =
107 "This file is part of the GRAVI Instrument Pipeline\n"
108 "Copyright (C) 2002,2003 European Southern Observatory\n"
110 "This program is free software; you can redistribute it and/or modify\n"
111 "it under the terms of the GNU General Public License as published by\n"
112 "the Free Software Foundation; either version 2 of the License, or\n"
113 "(at your option) any later version.\n"
115 "This program is distributed in the hope that it will be useful,\n"
116 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
117 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
118 "GNU General Public License for more details.\n"
120 "You should have received a copy of the GNU General Public License\n"
121 "along with this program; if not, write to the Free Software\n"
122 "Foundation, Inc., 59 Temple Place, Suite 330, Boston, \n"
123 "MA 02111-1307 USA" ;
124 return gravi_license ;
129 cpl_msg_warning (component,
"***********************************************");
130 cpl_msg_warning (component,
" ");
131 cpl_msg_warning (component,
" %s ", msg);
132 cpl_msg_warning (component,
" ");
133 cpl_msg_warning (component,
"***********************************************");
134 return CPL_ERROR_NONE;
156 cpl_ensure (nwave>0, CPL_ERROR_ILLEGAL_INPUT, NULL);
157 cpl_ensure (nrow>0, CPL_ERROR_ILLEGAL_INPUT, NULL);
158 cpl_ensure (oi_name, CPL_ERROR_NULL_INPUT, NULL);
163 cpl_table * oi_table = NULL;
168 oi_table = cpl_table_new(nrow * 6);
170 cpl_table_new_column (oi_table,
"TARGET_ID", CPL_TYPE_INT);
171 cpl_table_set_column_savetype(oi_table,
"TARGET_ID", CPL_TYPE_SHORT);
172 if (init) cpl_table_fill_column_window_int (oi_table,
"TARGET_ID", 0, nrow * 6, 0);
174 cpl_table_new_column (oi_table,
"TIME", CPL_TYPE_DOUBLE);
175 if (init) cpl_table_fill_column_window_double (oi_table,
"TIME", 0, nrow * 6, 0);
176 cpl_table_set_column_unit (oi_table,
"TIME",
"s");
178 cpl_table_new_column (oi_table,
"MJD", CPL_TYPE_DOUBLE);
179 if (init) cpl_table_fill_column_window_double (oi_table,
"MJD", 0, nrow * 6, 0.0);
180 cpl_table_set_column_unit (oi_table,
"MJD",
"d");
182 cpl_table_new_column (oi_table,
"INT_TIME", CPL_TYPE_DOUBLE);
183 if(init) cpl_table_fill_column_window_double (oi_table,
"INT_TIME", 0, nrow * 6, 0.0);
184 cpl_table_set_column_unit (oi_table,
"INT_TIME",
"s");
186 cpl_table_new_column_array (oi_table,
"VISDATA", CPL_TYPE_DOUBLE_COMPLEX, nwave);
187 cpl_table_set_column_unit (oi_table,
"VISDATA",
"e");
188 cpl_table_new_column_array (oi_table,
"VISERR", CPL_TYPE_DOUBLE_COMPLEX, nwave);
189 cpl_table_set_column_unit (oi_table,
"VISERR",
"e");
191 cpl_table_new_column_array (oi_table,
"VISAMP", CPL_TYPE_DOUBLE, nwave);
192 cpl_table_new_column_array (oi_table,
"VISAMPERR", CPL_TYPE_DOUBLE, nwave);
194 cpl_table_new_column_array (oi_table,
"VISPHI", CPL_TYPE_DOUBLE, nwave);
195 cpl_table_set_column_unit (oi_table,
"VISPHI",
"deg");
197 cpl_table_new_column_array (oi_table,
"VISPHIERR", CPL_TYPE_DOUBLE, nwave);
198 cpl_table_set_column_unit (oi_table,
"VISPHIERR",
"deg");
200 cpl_table_new_column_array (oi_table,
"RVIS", CPL_TYPE_DOUBLE, nwave);
201 cpl_table_set_column_unit (oi_table,
"RVIS",
"e");
203 cpl_table_new_column_array (oi_table,
"RVISERR", CPL_TYPE_DOUBLE, nwave);
204 cpl_table_set_column_unit (oi_table,
"RVISERR",
"e");
206 cpl_table_new_column_array (oi_table,
"IVIS", CPL_TYPE_DOUBLE, nwave);
207 cpl_table_set_column_unit (oi_table,
"IVIS",
"e");
209 cpl_table_new_column_array (oi_table,
"IVISERR", CPL_TYPE_DOUBLE, nwave);
210 cpl_table_set_column_unit (oi_table,
"IVISERR",
"e");
212 cpl_table_new_column (oi_table,
"UCOORD", CPL_TYPE_DOUBLE);
213 if(init) cpl_table_fill_column_window_double (oi_table,
"UCOORD", 0, nrow * 6, 0.0);
214 cpl_table_set_column_unit (oi_table,
"UCOORD",
"m");
216 cpl_table_new_column (oi_table,
"VCOORD", CPL_TYPE_DOUBLE);
217 if(init) cpl_table_fill_column_window_double (oi_table,
"VCOORD", 0, nrow * 6, 0.0);
218 cpl_table_set_column_unit (oi_table,
"VCOORD",
"m");
220 cpl_table_new_column_array (oi_table,
"STA_INDEX", CPL_TYPE_INT, 2);
221 cpl_table_set_column_savetype(oi_table,
"STA_INDEX", CPL_TYPE_SHORT);
224 oi_table = cpl_table_new(nrow * 6);
225 cpl_table_new_column (oi_table,
"TARGET_ID", CPL_TYPE_INT);
226 cpl_table_set_column_savetype(oi_table,
"TARGET_ID", CPL_TYPE_SHORT);
227 if(init) cpl_table_fill_column_window_int (oi_table,
"TARGET_ID", 0, nrow * 6, 0);
228 cpl_table_new_column (oi_table,
"TIME", CPL_TYPE_DOUBLE);
229 if(init) cpl_table_fill_column_window_double (oi_table,
"TIME", 0, nrow * 6, 0);
230 cpl_table_set_column_unit (oi_table,
"TIME",
"s");
231 cpl_table_new_column (oi_table,
"MJD", CPL_TYPE_DOUBLE);
232 if(init) cpl_table_fill_column_window_double (oi_table,
"MJD", 0, nrow * 6, 0.0);
233 cpl_table_set_column_unit (oi_table,
"MJD",
"d");
234 cpl_table_new_column (oi_table,
"INT_TIME", CPL_TYPE_DOUBLE);
235 if(init) cpl_table_fill_column_window_double (oi_table,
"INT_TIME",
237 cpl_table_set_column_unit (oi_table,
"INT_TIME",
"s");
238 cpl_table_new_column_array (oi_table,
"VIS2DATA",
239 CPL_TYPE_DOUBLE, nwave);
241 cpl_table_new_column_array (oi_table,
"VIS2ERR",
242 CPL_TYPE_DOUBLE, nwave);
243 cpl_table_new_column (oi_table,
"UCOORD", CPL_TYPE_DOUBLE);
244 if(init) cpl_table_fill_column_window_double (oi_table,
"UCOORD",
246 cpl_table_set_column_unit (oi_table,
"UCOORD",
"m");
247 cpl_table_new_column (oi_table,
"VCOORD", CPL_TYPE_DOUBLE);
248 if(init) cpl_table_fill_column_window_double (oi_table,
"VCOORD",
250 cpl_table_set_column_unit (oi_table,
"VCOORD",
"m");
252 cpl_table_new_column_array (oi_table,
"STA_INDEX", CPL_TYPE_INT, 2);
253 cpl_table_set_column_savetype(oi_table,
"STA_INDEX", CPL_TYPE_SHORT);
256 oi_table = cpl_table_new(nrow * 4);
257 cpl_table_new_column (oi_table,
"TARGET_ID", CPL_TYPE_INT);
258 cpl_table_set_column_savetype(oi_table,
"TARGET_ID", CPL_TYPE_SHORT);
259 if(init) cpl_table_fill_column_window_int (oi_table,
"TARGET_ID",
261 cpl_table_new_column (oi_table,
"TIME", CPL_TYPE_DOUBLE);
262 if(init) cpl_table_fill_column_window_double (oi_table,
"TIME", 0, nrow * 4, 0);
263 cpl_table_set_column_unit (oi_table,
"TIME",
"s");
264 cpl_table_new_column (oi_table,
"MJD", CPL_TYPE_DOUBLE);
265 if(init) cpl_table_fill_column_window_double (oi_table,
"MJD", 0, nrow * 4, 0.0);
266 cpl_table_set_column_unit (oi_table,
"MJD",
"d");
267 cpl_table_new_column (oi_table,
"INT_TIME", CPL_TYPE_DOUBLE);
268 cpl_table_set_column_unit (oi_table,
"INT_TIME",
"s");
269 if(init) cpl_table_fill_column_window_double (oi_table,
"INT_TIME",
271 cpl_table_new_column_array (oi_table,
"T3AMP", CPL_TYPE_DOUBLE, nwave);
272 cpl_table_new_column_array (oi_table,
"T3AMPERR", CPL_TYPE_DOUBLE, nwave);
273 cpl_table_new_column_array (oi_table,
"T3PHI", CPL_TYPE_DOUBLE, nwave);
274 cpl_table_set_column_unit (oi_table,
"T3PHI",
"deg");
275 cpl_table_new_column_array (oi_table,
"T3PHIERR",
276 CPL_TYPE_DOUBLE, nwave);
277 cpl_table_set_column_unit (oi_table,
"T3PHIERR",
"deg");
278 cpl_table_new_column (oi_table,
"U1COORD", CPL_TYPE_DOUBLE);
279 if(init) cpl_table_fill_column_window_double (oi_table,
"U1COORD",
281 cpl_table_set_column_unit (oi_table,
"U1COORD",
"m");
282 cpl_table_new_column (oi_table,
"V1COORD", CPL_TYPE_DOUBLE);
283 if(init) cpl_table_fill_column_window_double (oi_table,
"V1COORD",
285 cpl_table_set_column_unit (oi_table,
"V1COORD",
"m");
286 cpl_table_new_column (oi_table,
"U2COORD", CPL_TYPE_DOUBLE);
287 if(init) cpl_table_fill_column_window_double (oi_table,
"U2COORD",
289 cpl_table_set_column_unit (oi_table,
"U2COORD",
"m");
290 cpl_table_new_column (oi_table,
"V2COORD", CPL_TYPE_DOUBLE);
291 if(init) cpl_table_fill_column_window_double (oi_table,
"V2COORD",
293 cpl_table_set_column_unit (oi_table,
"V2COORD",
"m");
294 cpl_table_new_column_array (oi_table,
"STA_INDEX", CPL_TYPE_INT, 3);
295 cpl_table_set_column_savetype(oi_table,
"STA_INDEX", CPL_TYPE_SHORT);
298 oi_table = cpl_table_new(nrow * 4);
299 cpl_table_new_column (oi_table,
"TARGET_ID", CPL_TYPE_INT);
300 cpl_table_set_column_savetype(oi_table,
"TARGET_ID", CPL_TYPE_SHORT);
301 if(init) cpl_table_fill_column_window_int (oi_table,
"TARGET_ID",
303 cpl_table_new_column (oi_table,
"TIME", CPL_TYPE_DOUBLE);
304 cpl_table_set_column_unit (oi_table,
"TIME",
"s");
305 if(init) cpl_table_fill_column_window_double (oi_table,
"TIME", 0, nrow * 4, 0);
306 cpl_table_new_column (oi_table,
"MJD", CPL_TYPE_DOUBLE);
307 cpl_table_set_column_unit (oi_table,
"MJD",
"d");
308 if(init) cpl_table_fill_column_window_double (oi_table,
"MJD", 0, nrow * 4, 0.0);
309 cpl_table_new_column (oi_table,
"INT_TIME", CPL_TYPE_DOUBLE);
310 cpl_table_set_column_unit (oi_table,
"INT_TIME",
"s");
311 if(init) cpl_table_fill_column_window_double (oi_table,
"INT_TIME",
313 cpl_table_new_column_array (oi_table,
"FLUX",CPL_TYPE_DOUBLE, nwave);
314 cpl_table_set_column_unit (oi_table,
"FLUX",
"e");
315 cpl_table_new_column_array (oi_table,
"FLUXERR",CPL_TYPE_DOUBLE, nwave);
316 cpl_table_set_column_unit (oi_table,
"FLUXERR",
"e");
317 cpl_table_new_column (oi_table,
"STA_INDEX", CPL_TYPE_INT);
318 cpl_table_set_column_savetype(oi_table,
"STA_INDEX", CPL_TYPE_SHORT);
319 if(init) cpl_table_fill_column_window_int (oi_table,
"STA_INDEX",
323 cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_INPUT,
324 "The name of the table is incorrect");
329 cpl_table_new_column_array (oi_table,
"FLAG", CPL_TYPE_INT, nwave);
330 cpl_table_set_column_savetype(oi_table,
"FLAG", CPL_TYPE_BOOL);
331 cpl_array * bool_array = cpl_array_new(nwave, CPL_TYPE_INT);
332 cpl_array_fill_window_int(bool_array, 0, nwave, CPL_FALSE);
333 cpl_table_fill_column_window_array (oi_table,
"FLAG",
334 0, cpl_table_get_nrow(oi_table), bool_array);
335 cpl_array_delete (bool_array);
363 cpl_ensure (imaging_detector, CPL_ERROR_NULL_INPUT, -1);
364 cpl_ensure (region>=0 && region<48, CPL_ERROR_ILLEGAL_INPUT, -1);
366 const char * regname_i;
368 const char * bases[6]={
"12",
"13",
"14",
"23",
"24",
"34"};
369 const char * bases_inv[6]={
"21",
"31",
"41",
"32",
"42",
"43"};
373 regname_i = cpl_table_get_string(imaging_detector,
"REGNAME", region);
375 for (base=0; base<6; base++){
376 if (!(strncmp(bases[base], regname_i, 2)) || !(strncmp(bases_inv[base], regname_i, 2))){
380 cpl_msg_error (cpl_func,
"Cannot find the baseline of region %s", regname_i);
401 cpl_ensure (imaging_detector, CPL_ERROR_NULL_INPUT, 0);
402 cpl_ensure (base>=0 && base<=5, CPL_ERROR_ILLEGAL_INPUT, 0);
404 cpl_size n_region = cpl_table_get_nrow (imaging_detector);
408 for (cpl_size reg = 0; reg < n_region; reg ++) {
409 const char * regname = cpl_table_get_string (imaging_detector,
"REGNAME", reg);
412 if ( (regname[0] == basename[0] && regname[1] == basename[1]) ||
413 (regname[0] == basename[1] && regname[1] == basename[0]) ) {
416 const cpl_array * port = cpl_table_get_array (imaging_detector,
"PORTS", reg);
417 cpl_ensure (port, CPL_ERROR_ILLEGAL_INPUT, 0);
420 if (cpl_array_get_int (port, 0, NULL) < cpl_array_get_int (port, 1, NULL))
return 1;
421 if (cpl_array_get_int (port, 0, NULL) > cpl_array_get_int (port, 1, NULL))
return -1;
447 cpl_ensure (imaging_detector, CPL_ERROR_NULL_INPUT, -1);
448 cpl_ensure (region>=0 && region<48, CPL_ERROR_ILLEGAL_INPUT, -1);
451 const char * regname_i;
452 regname_i = cpl_table_get_string (imaging_detector,
"REGNAME", region);
455 if (regname_i[5] ==
'S' || regname_i[5] ==
'C')
return 0;
456 if (regname_i[5] ==
'P')
return 1;
458 cpl_msg_error (cpl_func,
"Cannot find the polarisation of region %s", regname_i);
481 cpl_ensure (imaging_detector, CPL_ERROR_NULL_INPUT, -1);
482 cpl_ensure (region>=0 && region<48, CPL_ERROR_ILLEGAL_INPUT, -1);
485 const char * regname_i;
486 regname_i = cpl_table_get_string (imaging_detector,
"REGNAME", region);
489 if (regname_i[3] ==
'A')
return 0;
490 if (regname_i[3] ==
'B')
return 1;
491 if (regname_i[3] ==
'C')
return 2;
492 if (regname_i[3] ==
'D')
return 3;
494 cpl_msg_error (cpl_func,
"Cannot find the phaseid of region %s", regname_i);
514 cpl_ensure (imaging_detector, CPL_ERROR_NULL_INPUT, -1);
515 cpl_ensure (region>=0 && region<48, CPL_ERROR_ILLEGAL_INPUT, -1);
516 cpl_ensure (beam==0 || beam==1, CPL_ERROR_ILLEGAL_INPUT, -1);
519 const char * regname_i;
520 regname_i = cpl_table_get_string (imaging_detector,
"REGNAME", region);
521 cpl_ensure (regname_i, CPL_ERROR_ILLEGAL_INPUT, -1);
524 char *ptr, str[2] =
"0";
525 str[0] = regname_i[beam];
528 long tel = strtol (str, &ptr, 10) - 1;
530 cpl_ensure (tel>=0 && tel<4, CPL_ERROR_ILLEGAL_INPUT, -1);
553 cpl_ensure (imaging_detector, CPL_ERROR_NULL_INPUT, -1);
554 cpl_ensure (region>=0 && region<48, CPL_ERROR_ILLEGAL_INPUT, -1);
557 const char * regname_i;
558 regname_i = cpl_table_get_string (imaging_detector,
"REGNAME", region);
562 if (regname_i[3] ==
'A')
return 'A';
563 if (regname_i[3] ==
'B')
return 'B';
564 if (regname_i[3] ==
'C')
return 'C';
565 if (regname_i[3] ==
'D')
return 'D';
567 cpl_msg_error (cpl_func,
"Cannot find the phase of region %s", regname_i);
586 cpl_ensure (img_det, CPL_ERROR_NULL_INPUT, -1);
588 for (cpl_size reg = 0 ; reg < cpl_table_get_nrow (img_det); reg++) {
613 cpl_ensure (
wave_data, CPL_ERROR_NULL_INPUT, -1);
614 cpl_ensure (lambda_max>lambda_min, CPL_ERROR_ILLEGAL_INPUT, -1);
615 cpl_ensure (lambda_min>1e-6 && lambda_min<3e-6, CPL_ERROR_ILLEGAL_INPUT, -1);
616 cpl_ensure (lambda_max>1e-6 && lambda_max<3e-6, CPL_ERROR_ILLEGAL_INPUT, -1);
618 int n_wave = cpl_table_get_column_depth (
wave_data,
"DATA1");
619 int n_region = cpl_table_get_ncol (
wave_data);
621 double wave, max_wave=0., min_wave = 3*pow(10, -6);
622 double sc_medium_res, sc_high_res, sc_low_res;
623 cpl_size ind_min=0, ind_max=n_wave-1;
627 while ((lambda_min-max_wave >= 0.0001*pow(10, -6)) && (ind_min < n_wave)) {
628 for (
int region=0; region < n_region; region++){
630 wave=cpl_array_get(cpl_table_get_array(
wave_data, regname, 0), ind_min, NULL);
631 if (wave >=max_wave) max_wave=wave;
640 while ((lambda_max-min_wave <= -0.0001*pow(10, -6)) && (ind_max >= 0)) {
641 for (
int region=0; region < n_region; region++){
643 wave=cpl_array_get(cpl_table_get_array(
wave_data, regname, 0), ind_max, NULL);
644 if (wave <=min_wave) min_wave=wave;
653 cpl_array * all_steps = cpl_array_new (n_region * (n_wave-1), CPL_TYPE_DOUBLE);
654 for (
int region=0; region < n_region; region++) {
656 for (wave=0; wave < n_wave-1; wave ++)
657 cpl_array_set (all_steps, region*(n_wave-1)+wave, fabs (cpl_array_get (data, wave+1, NULL) - cpl_array_get (data, wave, NULL) ));
660 double res = cpl_array_get_median (all_steps);
661 FREE (cpl_array_delete, all_steps);
664 n_element = ind_max-ind_min+1;
678 sc_low_res = 0.0418181818 * pow(10, -6);
679 sc_medium_res = 0.0022009569 * pow(10, -6);
680 sc_high_res = 0.0002642248 * pow(10, -6);
684 if (( res >= 0.95*sc_low_res) && (res <= 1.05*sc_low_res)) {
685 n_element = round(((lambda_max-lambda_min)/sc_low_res) + 2);
686 cpl_msg_info (cpl_func,
"Chosen SC LOW spectral resolution element = %e m, n_element = %i", sc_low_res, n_element);
691 if ((res >= 0.95*sc_medium_res ) && (res <= 1.05*sc_medium_res)) {
692 n_element = round(((lambda_max-lambda_min)/sc_medium_res) + 1);
693 cpl_msg_info (cpl_func,
"Chosen SC MEDIUM fixed spectral element = %e m, n_element = %i", sc_medium_res, n_element);
699 if ((res >= 0.9*sc_high_res ) && (res <= 1.1*sc_high_res)) {
700 n_element = round(((lambda_max-lambda_min)/sc_high_res) + 1);
701 cpl_msg_info (cpl_func,
"Chosen SC HIGH fixed spectral element = %e m, n_element = %i", sc_high_res, n_element);
706 cpl_msg_info (cpl_func,
"min=%e, max=%e, n=%f, res=%e, n=%i", lambda_min, lambda_max, (lambda_max-lambda_min)/res, res, n_element);
709 if (n_element > n_wave)
729 cpl_ensure (img_profile, CPL_ERROR_NULL_INPUT, NULL);
760 cpl_vector * vector, * vect, * vect_mean;
762 cpl_size nx = cpl_image_get_size_x (img_profile);
763 cpl_size ny = cpl_image_get_size_y (img_profile);
765 vect_mean = cpl_vector_new_from_image_row (img_profile, 1);
766 for (cpl_size i = 2; i <= ny; i++) {
767 vect = cpl_vector_new_from_image_row (img_profile, i);
768 cpl_vector_add (vect_mean, vect);
769 cpl_vector_delete (vect);
772 cpl_vector_divide_scalar (vect_mean, ny);
774 vector = cpl_vector_filter_median_create (vect_mean, 2);
777 vector = cpl_vector_filter_median_create (vect_mean, 5);
780 double max = cpl_vector_get_max (vector);
784 int i_2 = nx, i_1 = 0;
785 for (cpl_size i = 1; i < nx - 1; i++){
786 if (cpl_vector_get (vector, i) > sig){
788 if ((cpl_vector_get (vector, i - 1) > sig) && (cpl_vector_get (vector, i + 1) < sig))
793 for (cpl_size i = 1; i < nx - 1; i++){
794 if (cpl_vector_get (vector, nx - i) > sig){
796 if ((cpl_vector_get (vector, nx - i - 1) < sig) && (cpl_vector_get (vector, nx - i + 1) > sig))
804 if (i_1 < 0) i_1 = 0;
805 if (i_2 >= nx) i_2 = nx-1;
808 int * dim = cpl_malloc (2 *
sizeof (
int));
812 cpl_vector_delete (vect_mean);
813 cpl_vector_delete (vector);
828short gravi_sta_index(
int gravi_input, cpl_table * optical_train_table, cpl_table * array_geometry_table)
831 cpl_ensure (optical_train_table, CPL_ERROR_NULL_INPUT, 0);
832 cpl_ensure (array_geometry_table, CPL_ERROR_NULL_INPUT, 0);
835 switch (gravi_input) {
849 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
850 "impossible GRAVITY input");
858 for (row=0; row < cpl_table_get_nrow(optical_train_table); ++row) {
859 if (cpl_table_get_int(optical_train_table,
"VALUE2", row, &null) ==
864 if (row >= cpl_table_get_nrow(optical_train_table)) {
865 cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
866 "lab input not found in optical train table");
871 tel_name = cpl_sprintf (
"%s",cpl_table_get_string(optical_train_table,
"TEL_NAME", row));
875 int cur = strlen (tel_name);
877 if (tel_name[cur-1] ==
' ') {
885 char * cur_name = NULL;
888 for (row = 0; (!found) && (row < cpl_table_get_nrow(optical_train_table)); ++row) {
890 cur_name = cpl_sprintf (
"%s",cpl_table_get_string(array_geometry_table,
"TEL_NAME", row));
893 int cur = strlen (cur_name);
895 if (cur_name[cur-1] ==
' ') {
900 if (!strcmp (tel_name, cur_name)) found=1;
901 FREE (cpl_free, cur_name);
905 FREE (cpl_free, tel_name);
908 cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
909 "telescope not found in array geometry");
914 short res = cpl_table_get_int(array_geometry_table,
"STA_INDEX", row, &null);
916 cpl_msg_debug(cpl_func,
"gravi_input=%i; lab_input=%i; sta_index=%i", gravi_input, lab_input, res);
925 cpl_ensure (
header, CPL_ERROR_ILLEGAL_INPUT, -1);
931 if ( !cpl_propertylist_has (
header, key) ) {
934 if ( !cpl_propertylist_has (
header, key) ) {
935 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
"Missing shutter");
940 return cpl_propertylist_get_bool (
header, key);
945 cpl_ensure (
header, CPL_ERROR_ILLEGAL_INPUT, -1);
958 cpl_ensure (
header, CPL_ERROR_ILLEGAL_INPUT, -1);
965 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
966 "More than one shutter open, or none");
972 cpl_ensure (
header, CPL_ERROR_ILLEGAL_INPUT, -1);
981 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
982 "More than two shutter open, or less");
988 cpl_ensure (datas, CPL_ERROR_ILLEGAL_INPUT, -1);
991 if ( nb_datas != 4 )
return 0;
994 int is_open[] = {0,0,0,0};
995 for (cpl_size f = 0 ; f < 4 ; f++) {
1003 cpl_msg_info (cpl_func,
"is_open = %i %i %i %i", is_open[0], is_open[1], is_open[2], is_open[3]);
1007 for (cpl_size f = 0 ; f < 4 ; f++)
if (is_open[f] != 1) check *= 0;
1015 return cpl_table_get_column_depth (table,
"DATA1");
1020 cpl_ensure (table, CPL_ERROR_NULL_INPUT, -1);
1022 cpl_size nregion = 0;
1023 for (cpl_size col = 0; col < 48 ; col++) {
1024 nregion += cpl_table_has_column (table,
GRAVI_DATA[col]);
1044 cpl_ensure (table, CPL_ERROR_NULL_INPUT, 0);
1047 cpl_size n_row = cpl_table_get_nrow (table);
1050 for (cpl_size reg = 0; reg < n_reg ; reg++) {
1052 cpl_size size = cpl_table_get_column_depth (table,
GRAVI_DATA[reg]);
1053 cpl_array ** arrays = cpl_table_get_data_array ((cpl_table *)table,
GRAVI_DATA[reg]);
1055 for (cpl_size row=0; row < n_row ; row++)
1056 flux += cpl_array_get_mean (arrays[row]) * size;
1083 cpl_ensure (opd, CPL_ERROR_NULL_INPUT, NULL);
1084 cpl_ensure (wave>=0 && wave<nwave, CPL_ERROR_ILLEGAL_INPUT, NULL);
1087 double delta_lambda = (nwave >
GRAVI_LBD_FTSC) ? 0.45 / nwave * 3 : 0.13;
1088 double lambda = 2.0 + 0.45 / nwave * wave;
1091 double coh_len= (lambda*lambda) / delta_lambda * 1.e-6;
1093 long nrow = cpl_vector_get_size (opd);
1094 cpl_vector * envelope = cpl_vector_new (nrow);
1097 for (
long row = 0; row < nrow; row++){
1098 double value = cpl_vector_get (opd, row);
1099 cpl_vector_set (envelope, row, exp(-1*(value*value)/(coh_len*coh_len/2.)));
1119 cpl_ensure (imglist, CPL_ERROR_NULL_INPUT, 0);
1121 cpl_size size = cpl_imagelist_get_size (imglist);
1124 for (cpl_size row = 0; row < size; row ++)
1125 flux += cpl_image_get_flux (cpl_imagelist_get_const (imglist, row));
1147 cpl_size *first, cpl_size *nobs)
1149 cpl_ensure_code (oi_table, CPL_ERROR_NULL_INPUT);
1151 cpl_size cfirst = 0, cnobs = 0;
1152 cpl_size nrow = cpl_table_get_nrow (oi_table) /
ntel;
1153 double * lkdt = cpl_table_get_data_double (oi_table,
"LKDT_MET_FC");
1154 cpl_ensure_code (lkdt, CPL_ERROR_ILLEGAL_INPUT);
1156 for (cpl_size row = 1; row < nrow; row++) {
1159 for (cpl_size tel = 0; tel <
ntel; tel++)
1160 if (lkdt[row*
ntel+tel] != lkdt[(row-1)*
ntel+tel]) cfirst = row;
1163 cnobs = row - cfirst + 1;
1164 if (cnobs > *nobs) {*nobs = cnobs; *first = cfirst;}
1167 return CPL_ERROR_NONE;
1172 cpl_ensure (gravi_beam >=0 && gravi_beam < 4, CPL_ERROR_ILLEGAL_INPUT, 0);
1173 cpl_ensure (
header, CPL_ERROR_NULL_INPUT, 0);
1178 for (iss = 1; iss<=4; iss++) {
1179 sprintf (name,
"ESO ISS CONF INPUT%i", iss);
1180 if ( cpl_propertylist_get_int (
header, name) ==
1184 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
1185 "Could not find CONF INPUT for beam %i",
1193 cpl_ensure (gravi_beam >=0 && gravi_beam < 4, CPL_ERROR_ILLEGAL_INPUT, NULL);
1194 cpl_ensure (
header, CPL_ERROR_NULL_INPUT, NULL);
1197 for (
int iss = 1; iss<=4; iss++) {
1199 sprintf (name,
"ESO ISS CONF INPUT%i", iss);
1200 if ( !cpl_propertylist_has (
header, name))
continue;
1202 if ( cpl_propertylist_get_int (
header, name) ==
1205 sprintf (name,
"ESO ISS CONF T%iNAME", iss);
1206 if ( !cpl_propertylist_has (
header, name))
continue;
1208 return cpl_propertylist_get_string (
header, name);
1212 cpl_msg_debug (cpl_func,
"Telscope name cannot be find in header");
1224 double dist = acos ( sin (c_dec) * sin (dec) + cos (c_dec) * cos (dec) * cos (ra - c_ra) );
1227 dist = dist / CPL_MATH_PI * 180 * 3600;
1228 cpl_msg_info (cpl_func,
"Distance from GC: %g [as]", dist);
1230 if (dist > 20.0)
return CPL_ERROR_NONE;
1232 cpl_msg_info (cpl_func,
"*****************************************************************************************");
1234 cpl_msg_info (cpl_func,
" You are reducing data on the Galactic Center !!!! ");
1236 cpl_msg_info (cpl_func,
" MAY THE FRINGES BE WITH YOU !!!! ");
1241 cpl_msg_info (cpl_func,
" `....:/:::--://+/:--:/::--.-`````` ");
1242 cpl_msg_info (cpl_func,
" `.-://::.-----::/+oohyso/++:/:::.-.-://-.` ");
1243 cpl_msg_info (cpl_func,
" ```.:/:+o+/::/+ooossoo+oosso++::+/:://:+:osso//-`` ");
1244 cpl_msg_info (cpl_func,
" ```.:+ooos+:/+shddhhhysosooso+o++ooo/+sso+////:///:-` ");
1245 cpl_msg_info (cpl_func,
" ``.-:+yso/::+shdhhddhysssyhyhyyyysoyso+shys+o////::++:.` ");
1246 cpl_msg_info (cpl_func,
" `.-/+++syo//+syhdddddhhyyhddhhyyyhysyhyysyhdss+o+/o++:/+/:-.` ");
1247 cpl_msg_info (cpl_func,
" `:/ss++oo/osyhddddmmmdddhddmdhhyhhhhhhhhyssyyoo/s+:+hoo/:://-.` ");
1248 cpl_msg_info (cpl_func,
" `-+ss+oo++oyddmmmmmNNmddddddddhhhdhhhhhhyyyyy+o++so/ssyys+/+o+-.` ");
1249 cpl_msg_info (cpl_func,
" `.+oysssosshdmmmmmmmdmddddhhddddddysssssyysyso+///+osysyoyyo+os+:. ");
1250 cpl_msg_info (cpl_func,
" `-/syosyyydmmdddhhhyhhhhhhyhhddhso////+ssoo+/:----/:+oshs+ss++sso/` ");
1251 cpl_msg_info (cpl_func,
" `:oyyohdhdmmdyyyysssssooo+oo+++/:----:/+::::-...---../ohho/so/osoo:` ");
1252 cpl_msg_info (cpl_func,
" `./yyyhmdNNmhyssssoo+++//:::::-------------.......--..-/yyy/+ssoooo+-` ");
1253 cpl_msg_info (cpl_func,
" `.ohshmmmNNdyoooooo++///::-:------------..........-----:shss+oooo+so/. ");
1254 cpl_msg_info (cpl_func,
" `-syshmmNNNdsooooo+++//:::--------------...........----:+hhsss/++++o/. ");
1255 cpl_msg_info (cpl_func,
" `+syhdmNNNhsoooo++++/::::-----.-------..............---/dhyso++++oo:. ");
1256 cpl_msg_info (cpl_func,
" -yhhmmNNNhyooo+++++//::::--....-------...-........---:/ddhs/+/o+o+:`` ");
1257 cpl_msg_info (cpl_func,
" `shdmNMNmdysoo+++++/////:::------------------......---:smh+/+/++o/.` ");
1258 cpl_msg_info (cpl_func,
" `oydmNMMmhyo+++++ooo+++++///::---:::::://///////:...--:sNd++o:/o+:. ");
1259 cpl_msg_info (cpl_func,
" `+ydmmNMNhy++ooyhhhhdddddhyo++/:-://+shdddddhhyys+-..-:sNdoss//o/-` ");
1260 cpl_msg_info (cpl_func,
" osmdmNMmhsoyyddmmmdddmmmmdhyy+:::/oshdmmmddhhhyso+/--:sNmhhy++o:`` ");
1261 cpl_msg_info (cpl_func,
" +hmmNNNmyohhhhhhhyyhhhdhhdhdh+:--:oyhddhdddhhyysso/:::smmdhhoo/-` ");
1262 cpl_msg_info (cpl_func,
" `yhmNNmmhsyhyhhdmmmNmdyhdddddhs:--+ydyhhdhdmmmddhso+/y/+yhhhs+//+` ");
1263 cpl_msg_info (cpl_func,
" `yhhdmNNdoshshdddhhddhssyhydmd+-.-/ydysyysyhhyosyhy+:s-/dmh+///ss. ");
1264 cpl_msg_info (cpl_func,
" .syyhdNNh+oysssyyyyyssssyyyhhy/-.-:ossoosyysso++//////-:sds/:--/o. ");
1265 cpl_msg_info (cpl_func,
" -sssyhddo+oooosssssssssssssyys/-..-:///++osoo++///::----/s/+/---+` ");
1266 cpl_msg_info (cpl_func,
" `oosshyy++ooo+++ooooo++++ossso+--.-::::-::/+///::-------:+/so+/--` ");
1267 cpl_msg_info (cpl_func,
" :+ossshsosooo++////:://+osso+/:-..-:::-----------------//-:+/:-. ");
1268 cpl_msg_info (cpl_func,
" -+ososhhsyssoo+///::::/+sso++:--...-::---------:::--::/o:--://-` ");
1269 cpl_msg_info (cpl_func,
" -++osshmhyyysoo+//////+osso++/---...-::---------::::::sy/::::--` ");
1270 cpl_msg_info (cpl_func,
" `o++sshdhyyyyysooo++/+osyssso///:--:/:+/---:---::::::/ys/:/:.--` ");
1271 cpl_msg_info (cpl_func,
" :/osyhhyyyyyyssooo++oyyyhdmhysssoohy++so/:::::/:::::::+o+::... ");
1272 cpl_msg_info (cpl_func,
" `+oossyysyyhyyssooosyssshdmmddddyso/::/oyo/////////::://::---` ");
1273 cpl_msg_info (cpl_func,
" .+sssoosyyyyyysoosyssssyhhhhhhhs++/////oys++++++//::/+///:.` ");
1274 cpl_msg_info (cpl_func,
" `..`.syhyyyysssyyssssssssooss+//::////ohs++++++/::/.``` ");
1275 cpl_msg_info (cpl_func,
" +yyyhyysssssyyssssyssoooooo++///+osyo++++//:-:` ");
1276 cpl_msg_info (cpl_func,
" -syyhyysossyhdmmdhhyyyyysyshddhyssss+++++/:::: ");
1277 cpl_msg_info (cpl_func,
" `syyyyysosssyhddyso+//+++o+oso+/++o+//+++/:::. ");
1278 cpl_msg_info (cpl_func,
" :yyyyysossssssssso++++++/++//////++/+++//::. ");
1279 cpl_msg_info (cpl_func,
" `+yyyyysssssssyssssssosso+///////++++++///-` ");
1280 cpl_msg_info (cpl_func,
" `syyyhyysssssyyyysssssso++///////++/++//:. ");
1281 cpl_msg_info (cpl_func,
" .syhhhyysyyssssooooo+++///////////+++//:. ");
1282 cpl_msg_info (cpl_func,
" .shhyyyssssooo++///:::::/::/://++o+//:-. ");
1283 cpl_msg_info (cpl_func,
" `+yyyyssooooo+/////:::::::://++oo+/::-. ");
1284 cpl_msg_info (cpl_func,
" -yhyyssssso++/+++++//////++osso//::--` ");
1285 cpl_msg_info (cpl_func,
" -hhhhyyyyysooosssooo++oosyyso+/:::--. ");
1286 cpl_msg_info (cpl_func,
" /hddddddhhhyyyyyyyyyyyhhyys+//:::---. ");
1287 cpl_msg_info (cpl_func,
" `ohdmmmmmmmmmmmmdddddhhyyso+//:::----. ");
1288 cpl_msg_info (cpl_func,
" .yhddmmmmmmmmdddhyyyyssso+///:::----.` ");
1289 cpl_msg_info (cpl_func,
" :hhdddddddhhhyyyssoooooo++/:::::--....` ");
1290 cpl_msg_info (cpl_func,
" `ohdhhhhhhyyyysssooooooo++//::::---.--.` ");
1291 cpl_msg_info (cpl_func,
" .yhhhyyyyyyyyyyssssssoo++//:::::--......` ");
1292 cpl_msg_info (cpl_func,
" `.-:hhdhhyyyyhhyyyyssssoo+++//:::::---.......-+ssoo- ");
1293 cpl_msg_info (cpl_func,
" ``.-/oyhmsmmhdddhyhyyyyysssssooo+++///:::::---......:+dNNNd. ");
1294 cpl_msg_info (cpl_func,
" ```.-/+syhmNNNNNydMdhhhdhyyssssssoooooooo+++///::::------:+ymNNNmdy/```` ");
1295 cpl_msg_info (cpl_func,
" ``.--:/+oyhdmNNNNNNNNNNNNoMMhhhhhhyssssssooosooo+++++////:::---:+ymNNNNmy/-:oyhho/- ");
1296 cpl_msg_info (cpl_func,
"``-/sydmmmmNNNNNNNNNNNNNNNNNNdyMNhyhhhhyssooooooooooo++++++/////::+ymNNNNNh+-:odmmmmmmmm ");
1297 cpl_msg_info (cpl_func,
"sdmmmmNNNNNNNNNNNNNNNNNNNNNNNsdMNyyhhhhhysssooooooso+++++++++//+ydNMMMNms:-odNNNNNNmmmmm ");
1298 cpl_msg_info (cpl_func,
"mNNNNNNNNNNNNNNNNNNNNNNNNNNMNomMNyyhhhhhhyyyssooooooo++++++++ydNMMMMNh+-+hNNNNNNNNNNNmmm ");
1299 cpl_msg_info (cpl_func,
"NNNNNNNNNNNNNNNNNNNNNNNNNNMMM+mMMmhhhhhhhyyysssooooooo+++oydNMMMMNms:/ymNNNNNNNNNNNNNNNm ");
1300 cpl_msg_info (cpl_func,
"NNNNNNNNNNMMMNNNNNNNNNNNNNMMMshMMMmdhhhhhyyyyssoooooooshmNMMMMMNh+:smNNNNNNNNNNNNNNNNNNN ");
1301 cpl_msg_info (cpl_func,
"MMNNNNNNMMMMMMNNNNNNNNNNNMMMMd+MMMMmdhhhhyyyysoooooshmMMMMMMNh+:odNNNNNNNNNNNNNNNNNNNNNN ");
1302 cpl_msg_info (cpl_func,
"MMMMMMMMMMMMMMMMMMMNNNNMMMMMMN:mMMMNmhhdhhhyysooydNMMMMMMNy+:odNMMNNNNNNNNNNNNNNNNNNNNNN ");
1303 cpl_msg_info (cpl_func,
"MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMy/MMMMMdhhhyyyyhdNMMMMMNms//sdNMMMNNMNNNNNNNNNNNNNNNNNNNNN ");
1304 cpl_msg_info (cpl_func,
"MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMN/oMMMMMmdhhmNMMMMMMNho/+yNMMMMMMMMMNNNNNNNNNNNNNNNNNNNNNN ");
1305 cpl_msg_info (cpl_func,
" coutesis: The GRAVITY pipeline team ");
1306 cpl_msg_info (cpl_func,
"*****************************************************************************************");
1307 return CPL_ERROR_NONE;
typedefCPL_BEGIN_DECLS struct _gravi_data_ gravi_data
#define gravi_data_get_header(data)
cpl_msg_debug(cpl_func, "Spectra has <50 pixels -> don't flat")
cpl_propertylist * header
cpl_msg_info(cpl_func, "Compute WAVE_SCAN for %s", GRAVI_TYPE(type_data))
#define GRAVI_OI_VIS2_EXT
#define GRAVI_OI_FLUX_EXT
#define CPLCHECK_INT(msg)
#define gravi_msg_function_exit(flag)
#define FREE(function, variable)
#define CPLCHECK_NUL(msg)
#define gravi_msg_function_start(flag)
#define GRAVI_SHUTTER_KEY
double gravi_dec_to_rad(const char *stri)
double gravi_ra_to_rad(const char *stri)
int gravi_conf_get_iss(int gravi_beam, cpl_propertylist *header)
cpl_error_code gravi_msg_warning(const char *component, const char *msg)
cpl_error_code gravi_dump_the_boss(double ra, double dec)
int gravi_region_get_pol(cpl_table *imaging_detector, int region)
Return the polarisation id of a region.
char gravi_region_get_phase(cpl_table *imaging_detector, int region)
Return the phase character of a region.
int gravi_get_shutter(cpl_propertylist *header, int tel)
int gravi_region_get_phaseid(cpl_table *imaging_detector, int region)
Return the phase id of a region.
int gravi_region_get_base(cpl_table *imaging_detector, int region)
Return the base of a region.
char GRAVI_BASE_NAME[6][3]
double gravi_imagelist_get_flux(const cpl_imagelist *imglist)
Return the total flux in imagelist.
cpl_size gravi_spectrum_get_nwave(const cpl_table *table)
double gravi_spectrum_get_flux(const cpl_table *table)
Return the total flux in DATA# regions.
int gravi_check_shutter(cpl_propertylist *header, int t0, int t1, int t2, int t3)
const char * gravi_get_license(void)
Get the pipeline copyright and license.
char GRAVI_DATAERR[50][10]
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.
int GRAVI_TRI_SIGN[6][2][2]
const char * gravi_conf_get_telname(int gravi_beam, cpl_propertylist *header)
int GRAVI_TRI_BASE[6][2][2]
cpl_size gravi_spectrum_get_nregion(const cpl_table *table)
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.
cpl_vector * gravi_compute_envelope(const cpl_vector *opd, int wave, int nwave)
Compute the envelope value.
int * gravi_image_extract_dimension(cpl_image *img_profile)
Compute startx and nx of the illuminated part of the image.
int gravi_get_shutter_id(cpl_propertylist *header)
int gravi_get_region(cpl_table *img_det, int base, char phase, int pol)
Find the region matching base, phase and pol.
int gravi_data_check_shutter_beam(gravi_data **datas, int nb_datas)
char GRAVI_CLO_NAME[4][4]
cpl_table * gravi_table_oi_create(int nwave, int nrow, const char *oi_name)
Create the oi table (oi_vis, oi_vis2, oi_t3)
int gravi_region_get_base_sign(cpl_table *imaging_detector, int base)
Return the sign of a base by looking at the PORT order.
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.
int gravi_get_shutter_baseid(cpl_propertylist *header)
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.