File: palPolmo.c

package info (click to toggle)
starlink-pal 0.9.8-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 1,808 kB
  • sloc: ansic: 6,689; makefile: 128; sh: 81
file content (190 lines) | stat: -rw-r--r-- 6,278 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*
*+
*  Name:
*     palPolmo

*  Purpose:
*     Correct for polar motion

*  Language:
*     Starlink ANSI C

*  Type of Module:
*     Library routine

*  Invocation:
*     palPolmo ( double elongm, double phim, double xp, double yp,
*                double *elong, double *phi, double *daz );

*  Arguments:
*     elongm = double (Given)
*        Mean logitude of the observer (radians, east +ve)
*     phim = double (Given)
*        Mean geodetic latitude of the observer (radians)
*     xp = double (Given)
*        Polar motion x-coordinate (radians)
*     yp = double (Given)
*        Polar motion y-coordinate (radians)
*     elong = double * (Returned)
*        True longitude of the observer (radians, east +ve)
*     phi = double * (Returned)
*        True geodetic latitude of the observer (radians)
*     daz = double * (Returned)
*        Azimuth correction (terrestrial-celestial, radians)

*  Description:
*     Polar motion:  correct site longitude and latitude for polar
*     motion and calculate azimuth difference between celestial and
*     terrestrial poles.

*  Authors:
*     PTW: Patrick Wallace (STFC)
*     TIMJ: Tim Jenness (Cornell)
*     {enter_new_authors_here}

*  Notes:
*     - "Mean" longitude and latitude are the (fixed) values for the
*       site's location with respect to the IERS terrestrial reference
*       frame;  the latitude is geodetic.  TAKE CARE WITH THE LONGITUDE
*       SIGN CONVENTION.  The longitudes used by the present routine
*       are east-positive, in accordance with geographical convention
*       (and right-handed).  In particular, note that the longitudes
*       returned by the sla_OBS routine are west-positive, following
*       astronomical usage, and must be reversed in sign before use in
*       the present routine.
*
*     - XP and YP are the (changing) coordinates of the Celestial
*       Ephemeris Pole with respect to the IERS Reference Pole.
*       XP is positive along the meridian at longitude 0 degrees,
*       and YP is positive along the meridian at longitude
*       270 degrees (i.e. 90 degrees west).  Values for XP,YP can
*       be obtained from IERS circulars and equivalent publications;
*       the maximum amplitude observed so far is about 0.3 arcseconds.
*
*     - "True" longitude and latitude are the (moving) values for
*       the site's location with respect to the celestial ephemeris
*       pole and the meridian which corresponds to the Greenwich
*       apparent sidereal time.  The true longitude and latitude
*       link the terrestrial coordinates with the standard celestial
*       models (for precession, nutation, sidereal time etc).
*
*     - The azimuths produced by sla_AOP and sla_AOPQK are with
*       respect to due north as defined by the Celestial Ephemeris
*       Pole, and can therefore be called "celestial azimuths".
*       However, a telescope fixed to the Earth measures azimuth
*       essentially with respect to due north as defined by the
*       IERS Reference Pole, and can therefore be called "terrestrial
*       azimuth".  Uncorrected, this would manifest itself as a
*       changing "azimuth zero-point error".  The value DAZ is the
*       correction to be added to a celestial azimuth to produce
*       a terrestrial azimuth.
*
*     - The present routine is rigorous.  For most practical
*       purposes, the following simplified formulae provide an
*       adequate approximation:
*
*       elong = elongm+xp*cos(elongm)-yp*sin(elongm)
*       phi   = phim+(xp*sin(elongm)+yp*cos(elongm))*tan(phim)
*       daz   = -sqrt(xp*xp+yp*yp)*cos(elongm-atan2(xp,yp))/cos(phim)
*
*       An alternative formulation for DAZ is:
*
*       x = cos(elongm)*cos(phim)
*       y = sin(elongm)*cos(phim)
*       daz = atan2(-x*yp-y*xp,x*x+y*y)
*
*     - Reference:  Seidelmann, P.K. (ed), 1992.  "Explanatory Supplement
*                   to the Astronomical Almanac", ISBN 0-935702-68-7,
*                   sections 3.27, 4.25, 4.52.

*  History:
*     2000-11-30 (PTW):
*        SLALIB implementation.
*     2014-10-18 (TIMJ):
*        Initial version in C.
*     {enter_further_changes_here}

*  Copyright:
*     Copyright (C) 2000 Rutherford Appleton Laboratory.
*     Copyright (C) 2014 Cornell University
*     All Rights Reserved.

*  Licence:
*     This program is free software; you can redistribute it and/or
*     modify it under the terms of the GNU General Public License as
*     published by the Free Software Foundation; either version 3 of
*     the License, or (at your option) any later version.
*
*     This program is distributed in the hope that it will be
*     useful, but WITHOUT ANY WARRANTY; without even the implied
*     warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
*     PURPOSE. See the GNU General Public License for more details.
*
*     You should have received a copy of the GNU General Public License
*     along with this program.  If not, see <http://www.gnu.org/licenses/>.

*  Bugs:
*     {note_any_bugs_here}
*-
*/

#include <math.h>

#include "pal.h"

void palPolmo ( double elongm, double phim, double xp, double yp,
                double *elong, double *phi, double *daz ) {

  double  sel,cel,sph,cph,xm,ym,zm,xnm,ynm,znm,
    sxp,cxp,syp,cyp,zw,xt,yt,zt,xnt,ynt;

  /*  Site mean longitude and mean geodetic latitude as a Cartesian vector */
  sel=sin(elongm);
  cel=cos(elongm);
  sph=sin(phim);
  cph=cos(phim);

  xm=cel*cph;
  ym=sel*cph;
  zm=sph;

  /*  Rotate site vector by polar motion, Y-component then X-component */
  sxp=sin(xp);
  cxp=cos(xp);
  syp=sin(yp);
  cyp=cos(yp);

  zw=(-ym*syp+zm*cyp);

  xt=xm*cxp-zw*sxp;
  yt=ym*cyp+zm*syp;
  zt=xm*sxp+zw*cxp;

  /*  Rotate also the geocentric direction of the terrestrial pole (0,0,1) */
  xnm=-sxp*cyp;
  ynm=syp;
  znm=cxp*cyp;

  cph=sqrt(xt*xt+yt*yt);
  if (cph == 0.0) xt=1.0;
  sel=yt/cph;
  cel=xt/cph;

  /*  Return true longitude and true geodetic latitude of site */
  if (xt != 0.0 || yt != 0.0) {
    *elong=atan2(yt,xt);
  } else {
    *elong=0.0;
  }
  *phi=atan2(zt,cph);

  /*  Return current azimuth of terrestrial pole seen from site position */
  xnt=(xnm*cel+ynm*sel)*zt-znm*cph;
  ynt=-xnm*sel+ynm*cel;
  if (xnt != 0.0 || ynt != 0.0) {
    *daz=atan2(-ynt,-xnt);
  } else {
    *daz=0.0;
  }

}