87 double *pmx,
double *pmy,
89 cpl_table * eop_table,
93 cpl_ensure_code (eop_table, CPL_ERROR_NULL_INPUT);
94 cpl_ensure_code (
header, CPL_ERROR_NULL_INPUT);
95 cpl_ensure_code (n>0, CPL_ERROR_ILLEGAL_INPUT);
96 cpl_ensure_code (mjd, CPL_ERROR_NULL_INPUT);
97 cpl_ensure_code (pmx, CPL_ERROR_NULL_INPUT);
98 cpl_ensure_code (pmy, CPL_ERROR_NULL_INPUT);
99 cpl_ensure_code (dut, CPL_ERROR_NULL_INPUT);
102 cpl_vector *vmjd = cpl_vector_wrap (n, mjd);
103 cpl_vector *vpmx = cpl_vector_wrap (n, pmx);
104 cpl_vector *vpmy = cpl_vector_wrap (n, pmy);
105 cpl_vector *vdut = cpl_vector_wrap (n, dut);
108 if (cpl_vector_get_min (vmjd) < cpl_table_get_column_min (eop_table,
"MJD") ||
109 cpl_vector_get_max (vmjd) > cpl_table_get_column_max (eop_table,
"MJD"))
111 cpl_msg_warning (cpl_func,
"Some MJD are outside the EOP_PARAM range (MJD=%.2f, %.2f..%.2f). Use EOP and DUT=0.0s",
112 cpl_vector_get_mean (vmjd),
113 cpl_table_get_column_min (eop_table,
"MJD"),
114 cpl_table_get_column_max (eop_table,
"MJD"));
115 cpl_vector_unwrap (vmjd);
116 cpl_vector_unwrap (vpmx);
117 cpl_vector_unwrap (vpmy);
118 cpl_vector_unwrap (vdut);
120 return CPL_ERROR_NONE;
124 if(cpl_vector_get_max (vmjd) > cpl_propertylist_get_double (
header,
"ESO QC EOP MJD LAST FINAL"))
126 cpl_msg_warning (cpl_func,
"Some MJD are inside the EOP_PARAM prediction range...");
130 cpl_size nrow = cpl_table_get_nrow (eop_table);
131 cpl_vector * eop_mjd = cpl_vector_wrap (nrow, cpl_table_get_data_double (eop_table,
"MJD"));
132 cpl_vector * eop_pmx = cpl_vector_wrap (nrow, cpl_table_get_data_double (eop_table,
"PMX"));
133 cpl_vector * eop_pmy = cpl_vector_wrap (nrow, cpl_table_get_data_double (eop_table,
"PMY"));
134 cpl_vector * eop_dut = cpl_vector_wrap (nrow, cpl_table_get_data_double (eop_table,
"DUT"));
137 cpl_bivector *mjd_pmx = cpl_bivector_wrap_vectors (vmjd, vpmx);
138 cpl_bivector *eop_mjd_pmx = cpl_bivector_wrap_vectors (eop_mjd, eop_pmx);
139 cpl_bivector_interpolate_linear (mjd_pmx, eop_mjd_pmx);
140 cpl_bivector_unwrap_vectors (mjd_pmx);
141 cpl_bivector_unwrap_vectors (eop_mjd_pmx);
143 cpl_bivector *mjd_pmy = cpl_bivector_wrap_vectors (vmjd, vpmy);
144 cpl_bivector *eop_mjd_pmy = cpl_bivector_wrap_vectors (eop_mjd, eop_pmy);
145 cpl_bivector_interpolate_linear (mjd_pmy, eop_mjd_pmy);
146 cpl_bivector_unwrap_vectors (mjd_pmy);
147 cpl_bivector_unwrap_vectors (eop_mjd_pmy);
149 cpl_bivector *mjd_dut = cpl_bivector_wrap_vectors (vmjd, vdut);
150 cpl_bivector *eop_mjd_dut = cpl_bivector_wrap_vectors (eop_mjd, eop_dut);
151 cpl_bivector_interpolate_linear (mjd_dut, eop_mjd_dut);
152 cpl_bivector_unwrap_vectors (mjd_dut);
153 cpl_bivector_unwrap_vectors (eop_mjd_dut);
156 cpl_msg_info(cpl_func,
"EOP averages: MJD=%.2f DUT1=%.3f PMX=%.3farcsec PMY=%.3farcsec",
157 cpl_vector_get_mean (vmjd), cpl_vector_get_mean (vdut),
158 cpl_vector_get_mean (vpmx), cpl_vector_get_mean (vpmy));
161 cpl_vector_unwrap (vmjd);
162 cpl_vector_unwrap (vpmx);
163 cpl_vector_unwrap (vpmy);
164 cpl_vector_unwrap (vdut);
165 cpl_vector_unwrap (eop_mjd);
166 cpl_vector_unwrap (eop_pmx);
167 cpl_vector_unwrap (eop_pmy);
168 cpl_vector_unwrap (eop_dut);
173 return CPL_ERROR_NONE;
229 cpl_propertylist *
header,
230 cpl_table * eop_table,
231 cpl_propertylist * eop_header,
233 cpl_table * array_table)
236 cpl_ensure_code (input_table, CPL_ERROR_NULL_INPUT);
237 cpl_ensure_code (
header, CPL_ERROR_NULL_INPUT);
240 if (save_pointing > 0) {
241 cpl_msg_info (cpl_func,
"Will save [E_U,E_V,E_W,E_AZ,E_ZD]");
244 if (array_table != NULL) {
245 cpl_msg_info (cpl_func,
"Will compute [UCOORD,VCOORD]");
251 double t_skip = 1./24/3600, mjd0 = -1.0, mjd1 = -1.0;
252 cpl_msg_info (cpl_func,
"Compute pointing with full ERFA every %.2f s",t_skip*24*3600.0);
263 int tel1=0;
while ( cpl_table_get (array_table,
"STA_INDEX", tel1, NULL) !=
gravi_table_get_value (input_table,
"STA_INDEX", base, 0) ) tel1++;
264 int tel2=0;
while ( cpl_table_get (array_table,
"STA_INDEX", tel2, NULL) !=
gravi_table_get_value (input_table,
"STA_INDEX", base, 1) ) tel2++;
269 uCoord = cpl_table_get_data_double (input_table,
"UCOORD");
270 vCoord = cpl_table_get_data_double (input_table,
"VCOORD");
274 double *mjd = cpl_table_get_data_double (input_table,
"MJD");
275 double mean_mjd = cpl_table_get_column_mean (input_table,
"MJD");
284 cpl_msg_info (cpl_func,
"Saving E_U, E_V, E_W, E_AZ, E_ZD");
285 cpl_table_new_column_array (input_table,
"E_U", CPL_TYPE_DOUBLE, 3);
286 cpl_table_new_column_array (input_table,
"E_V", CPL_TYPE_DOUBLE, 3);
287 cpl_table_new_column_array (input_table,
"E_W", CPL_TYPE_DOUBLE, 3);
288 cpl_table_new_column_array (input_table,
"E_AZ", CPL_TYPE_DOUBLE, 3);
289 cpl_table_new_column_array (input_table,
"E_ZD", CPL_TYPE_DOUBLE, 3);
290 p_u = cpl_table_get_data_array (input_table,
"E_U");
291 p_v = cpl_table_get_data_array (input_table,
"E_V");
292 p_w = cpl_table_get_data_array (input_table,
"E_W");
293 p_az = cpl_table_get_data_array (input_table,
"E_AZ");
294 p_zd = cpl_table_get_data_array (input_table,
"E_ZD");
295 CPLCHECK_MSG (
"Cannot create [E_U, E_V, E_W, E_AZ, E_ZD]");
305 double dut1 = 0, pmx = 0, pmy = 0;
306 if (eop_table != NULL) {
308 eop_table, eop_header);
311 cpl_msg_warning (cpl_func,
"No EOP_PARAM. Use EOP and DUT=0.0s");
326 double eps = 10.0 / 3600.0 * CPL_MATH_RAD_DEG;
328 double eUb[3], eVb[3], eWb[3], eZb[3];
329 double eWo_up[3], eWo_um[3], eWo_vp[3], eWo_vm[3];
330 double eWb_up[3], eWb_um[3], eWb_vp[3], eWb_vm[3];
331 double rb_up, db_up, rb_um, db_um, rb_vp, db_vp, rb_vm, db_vm;
332 double eUo[3], eVo[3], eWo[3], eAZo[3], eZDo[3];
333 double ez[3] = {0.0, 0.0, 1.0};
335 double pressure = 0.0;
336 double temperature = 0.0;
337 double humidity = 0.0;
338 double wavelength = 0.0;
342 cpl_size n_row = cpl_table_get_nrow (input_table);
343 for (cpl_size row = 0 ; row < n_row ; row++) {
346 if (mjd[row] != mjd1 ) {
350 if ( fabs (mjd[row]-mjd0) > t_skip ) {
351 eraApco13 (2400000.5, mjd[row], dut1, lon, lat, elev,
352 pmx/3600.0*CPL_MATH_RAD_DEG, pmy/3600.0*CPL_MATH_RAD_DEG,
353 pressure, temperature, humidity, wavelength,
358 eraAper13 (2400000.5, mjd[row] + dut1/(24.0*3600.0), &astrom);
361 eraPmpx(rc, dc, pmr, pmd, parallax, sysvel, astrom.pmt, astrom.eb, eWb);
362 eraC2s(eWb, &rb, &db);
365 eraS2c(0.0, CPL_MATH_PI/2.0, eZb);
366 eraPxp(eZb, eWb, eUb);
367 eraPn(eUb, &norm, eUb);
368 eraPxp(eWb, eUb, eVb);
375 eraC2s(eWb_up, &rb_up, &db_up);
376 eraC2s(eWb_um, &rb_um, &db_um);
377 eraC2s(eWb_vp, &rb_vp, &db_vp);
378 eraC2s(eWb_vm, &rb_vm, &db_vm);
382 eraAtboq (rb_up, db_up, &astrom, eWo_up);
383 eraAtboq (rb_um, db_um, &astrom, eWo_um);
384 eraAtboq (rb_vp, db_vp, &astrom, eWo_vp);
385 eraAtboq (rb_vm, db_vm, &astrom, eWo_vm);
388 eraPxp(eWo_up, eWo_um, eUo);
389 eraPxp(eWo, eUo, eUo);
390 eraSxp(1./(2.0*eps), eUo, eUo);
391 eraPxp(eWo_vp, eWo_vm, eVo);
392 eraPxp(eWo, eVo, eVo);
393 eraSxp(1./(2.0*eps), eVo, eVo);
396 eraPxp(eWo, ez, eAZo);
397 eraPn(eAZo, &norm, eAZo);
400 eraPxp(eWo, eAZo, eZDo);
401 eraPn(eZDo, &norm, eZDo);
406 if (mjd[row] != mjd1 ) {
407 double * eU = cpl_malloc (
sizeof(
double) * 3);
408 double * eV = cpl_malloc (
sizeof(
double) * 3);
409 double * eW = cpl_malloc (
sizeof(
double) * 3);
410 double * eAZ = cpl_malloc (
sizeof(
double) * 3);
411 double * eZD = cpl_malloc (
sizeof(
double) * 3);
412 for ( cpl_size c = 0; c < 3; c++) {
421 p_u[row] = cpl_array_wrap_double (eU, 3);
422 p_v[row] = cpl_array_wrap_double (eV, 3);
423 p_w[row] = cpl_array_wrap_double (eW, 3);
424 p_az[row] = cpl_array_wrap_double (eAZ, 3);
425 p_zd[row] = cpl_array_wrap_double (eZD, 3);
427 p_u[row] = cpl_array_duplicate (p_u [row-1]);
428 p_v[row] = cpl_array_duplicate (p_v [row-1]);
429 p_w[row] = cpl_array_duplicate (p_w [row-1]);
430 p_az[row] = cpl_array_duplicate (p_az[row-1]);
431 p_zd[row] = cpl_array_duplicate (p_zd[row-1]);
439 double n_air = 1.0002028;
442 uCoord[row] = (eUo[0] * baseline[base][0] + eUo[1] * baseline[base][1] + eUo[2] * baseline[base][2])/n_air;
443 vCoord[row] = (eVo[0] * baseline[base][0] + eVo[1] * baseline[base][1] + eVo[2] * baseline[base][2])/n_air;
451 return CPL_ERROR_NONE;
469 cpl_ensure_code (p2vmred_data, CPL_ERROR_NULL_INPUT);
478 int type_data, ntype_data = 2;
479 for (type_data = 0; type_data < ntype_data ; type_data ++) {
496 if ((npol > 1) && (type_data==
GRAVI_SC)) {
497 cpl_msg_debug (cpl_func,
"Duplicate in the 2nd polarisation");
500 cpl_table_duplicate_column (oi_vis_1,
"E_U", oi_vis,
"E_U");
501 cpl_table_duplicate_column (oi_vis_1,
"E_V", oi_vis,
"E_V");
502 cpl_table_duplicate_column (oi_vis_1,
"E_W", oi_vis,
"E_W");
503 cpl_table_duplicate_column (oi_vis_1,
"E_AZ", oi_vis,
"E_AZ");
504 cpl_table_duplicate_column (oi_vis_1,
"E_ZD", oi_vis,
"E_ZD");
511 cpl_msg_info (cpl_func,
"Duplicate in the 2nd polarisation");
514 cpl_table_copy_data_double (oi_vis_1,
"UCOORD", cpl_table_get_data_double (oi_vis,
"UCOORD"));
515 cpl_table_copy_data_double (oi_vis_1,
"VCOORD", cpl_table_get_data_double (oi_vis,
"VCOORD"));
522 return CPL_ERROR_NONE;