MIDI Pipeline Reference Manual  2.8.3
geometry.c
1 /******************************************************************************
2 *******************************************************************************
3 * European Southern Observatory
4 * VLTI MIDI Data Reduction Software
5 *
6 * Module name: geometry.c
7 * Description: Contains routines for all geometrical routines
8 *
9 * History:
10 * 14-Nov-03 (csabet) Created
11 *******************************************************************************
12 ******************************************************************************/
13 
14 /******************************************************************************
15 * Compiler directives
16 ******************************************************************************/
17 
18 /******************************************************************************
19 * Include files
20 ******************************************************************************/
21 #include <math.h>
22 #include "geometry.h"
23 #include <stdio.h>
24 #include <cpl.h>
25 #include "midiGlobal.h"
26 #include "midiLib.h"
27 
28 /**********************************************************
29 * Constant definitions
30 **********************************************************/
31 
32 /**********************************************************
33 * Global Variables
34 **********************************************************/
35 
36 /*============================ C O D E A R E A ===========================*/
37 
38 
39 /******************************************************************************
40 * European Southern Observatory
41 * VLTI MIDI Data Reduction Software
42 *
43 * Module name: computeUVW
44 * Input/Output: See function arguments to avoid duplication
45 * Description: Computes the uvw coordinates. The base algorithm is taken from VINCI
46 *
47 * History:
48 * 13-Nov-03 (csabet) Created
49 ******************************************************************************/
50 void computeUVW (
51  double t1x, /* In: Station coordinates relative to the array centre */
52  double t1y, /* In: Station coordinates relative to the array centre */
53  double t1z, /* In: Station coordinates relative to the array centre */
54  double t2x, /* In: Station coordinates relative to the array centre */
55  double t2y, /* In: Station coordinates relative to the array centre */
56  double t2z, /* In: Station coordinates relative to the array centre */
57  double time, /* In: time */
58  double RA, /* In: Right Ascension */
59  double Dec, /* In: Declanation */
60  UVW *uvw) /* Ou: uvw Coordinates */
61 
62 {
63 
64  /* Local Declarations
65  --------------------*/
66  const char routine[] = "computeUVW";
67  double GST, LST, T0, T, UTdate, UTtime, julianDate, hourAngle, dx, dy, dz,
68  ihar, decr, cha, sha, cdec, sdec, clat, slat;
69 
70  /* Algorithm
71  -----------*/
72  if (diagnostic > 4)cpl_msg_info(cpl_func,"Invoking routine '%s' \n", routine);
73  if (diagnostic > 4) fprintf(midiReportPtr, "Invoking routine '%s' \n", routine);
74 
75 /* TO_DO_MIDI_DRS I am not sure about the "time" used in the following statement. csabet 14-Nov-03 */
76 /* In VINCI it is given by (julianDate = Batch_on_processed->scan_data[I].time + 2400000.5); */
77 /* Here I am using the UTC derived from the primary header of the FITS file */
78 // csabet 29-Sep-04. We have decided to use MJD-OBS from the primary header
79 
80  julianDate = time + 2400000.5;
81 
82  if ((julianDate - floor (julianDate)) > 0.5)
83  UTdate = floor (julianDate) + 0.5;
84  else
85  UTdate = floor (julianDate) - 0.5;
86 
87  /* Greenwich Mean Time (UTC) in decimal hours */
88  UTtime = 24.0 * (julianDate - UTdate);
89 
90  T = (UTdate - 2451545.0) / 36525.0;
91  T0 = 6.697374558 + (2400.051336 * T) + (0.000025862 * T * T) + (UTtime * 1.0027379093);
92  GST = 24 * (T0 / 24.0 - floor (T0 / 24.0));
93 
94  /* LST = local_sidereal */
95  LST = GST - LONGITUDE_PARANAL * (12.0 / MIDI_PI);
96  if (LST < 0) LST = LST + 24.0;
97  LST = 24 * (LST / 24.0 - floor (LST / 24.0));
98 
99  /* Beware: RA and Dec are in degrees ! */
100  hourAngle = LST - RA * 12.0 / 180.0;
101 
102  dx = t2x - t1x;
103  dy = t2y - t1y;
104  dz = t2z - t1z;
105 
106  ihar = hourAngle * MIDI_PI / 12.0;
107  decr = Dec * MIDI_PI / 180.0;
108  cha = cos (ihar);
109  sha = sin (ihar);
110  cdec = cos (decr);
111  sdec = sin (decr);
112  clat = cos (LATITUDE_PARANAL);
113  slat = sin (LATITUDE_PARANAL);
114 
115  uvw->uCoord = dx * cha - dy * (slat * sha) + dz * (clat * sha);
116  uvw->vCoord = dx * (sha * sdec) + dy * (slat * cha * sdec + clat * cdec) - dz * (clat * cha * sdec - slat * cdec);
117 
118  return;
119 }
120 /*****************************************************************************/