File: palRdplan.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 (224 lines) | stat: -rw-r--r-- 5,595 bytes parent folder | download | duplicates (3)
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*
*+
*  Name:
*     palRdplan

*  Purpose:
*     Approximate topocentric apparent RA,Dec of a planet

*  Language:
*     Starlink ANSI C

*  Type of Module:
*     Library routine

*  Invocation:
*     void palRdplan( double date, int np, double elong, double phi,
*                     double * ra, double * dec, double * diam );

*  Arguments:
*     date = double (Given)
*        MJD of observation (JD-2400000.5) in TDB. For all practical
*        purposes TT can be used instead of TDB, and for many applications
*        UT will do (except for the Moon).
*     np = int (Given)
*        Planet: 1 = Mercury
*                2 = Venus
*                3 = Moon
*                4 = Mars
*                5 = Jupiter
*                6 = Saturn
*                7 = Uranus
*                8 = Neptune
*             else = Sun
*     elong = double (Given)
*        Observer's east longitude (radians)
*     phi = double (Given)
*        Observer's geodetic latitude (radians)
*     ra = double * (Returned)
*        RA (topocentric apparent, radians)
*     dec = double * (Returned)
*        Dec (topocentric apparent, radians)
*     diam = double * (Returned)
*        Angular diameter (equatorial, radians)

*  Description:
*     Approximate topocentric apparent RA,Dec of a planet, and its
*     angular diameter.

*  Authors:
*     PTW: Patrick T. Wallace
*     TIMJ: Tim Jenness (JAC, Hawaii)
*     {enter_new_authors_here}

*  Notes:
*     - Unlike with slaRdplan, Pluto is not supported.
*     - The longitude and latitude allow correction for geocentric
*       parallax.  This is a major effect for the Moon, but in the
*       context of the limited accuracy of the present routine its
*       effect on planetary positions is small (negligible for the
*       outer planets).  Geocentric positions can be generated by
*       appropriate use of the routines palDmoon and eraPlan94.

*  History:
*     2012-03-07 (TIMJ):
*        Initial version, with some documentation from SLA/F.
*        Adapted with permission from the Fortran SLALIB library.
*     {enter_further_changes_here}

*  Copyright:
*     Copyright (C) 1997 Rutherford Appleton Laboratory
*     Copyright (C) 2012 Science and Technology Facilities Council.
*     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, write to the Free Software
*     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
*     MA 02110-1301, USA.

*  Bugs:
*     {note_any_bugs_here}
*-
*/

#include <math.h>

#include "pal.h"
#include "palmac.h"
#include "pal1sofa.h"

void palRdplan( double date, int np, double elong, double phi,
                double * ra, double * dec, double * diam ) {

  /* AU in km */
  const double AUKM = 1.49597870e8;

  /* Equatorial radii (km) */
  const double EQRAU[] = {
    696000.0, /* Sun */
      2439.7,
      6051.9,
      1738,
      3397,
     71492,
     60268,
     25559,
     24764
  };

  /* Local variables */
  int i, j;
  double stl;
  double vgm[6];
  double v[6];
  double rmat[3][3];
  double vse[6];
  double vsg[6];
  double vsp[6];
  double vgo[6];
  double dx,dy,dz,r,tl;

  /* Classify np */
  if (np < 0 || np > 8 ) np=0;  /* Sun */

  /* Approximate local sidereal time */
  stl = palGmst( date - palDt( palEpj(date)) / 86400.0) + elong;

  /* Geocentre to Moon (mean of date) */
  palDmoon( date, v );

  /* Nutation to true of date */
  palNut( date, rmat );
  eraRxp( rmat, v, vgm );
  eraRxp( rmat, &(v[3]), &(vgm[3]) );

  /* Moon? */
  if (np == 3) {

    /* geocentre to Moon (true of date) */
    for (i=0; i<6; i++) {
      v[i] = vgm[i];
    }

  } else {

    /* Not moon: precession/nutation matrix J2000 to date */
    palPrenut( 2000.0, date, rmat );

    /* Sun to Earth-Moon Barycentre (J2000) */
    palPlanet( date, 3, v, &j );

    /* Precession and nutation to date */
    eraRxp( rmat, v, vse );
    eraRxp( rmat, &(v[3]), &(vse[3]) );

    /* Sun to geocentre (true of date) */
    for (i=0; i<6; i++) {
      vsg[i] = vse[i] - 0.012150581 * vgm[i];
    }

    /* Sun ? */
    if (np == 0) {

      /* Geocentre to Sun */
      for (i=0; i<6; i++) {
        v[i] = -vsg[i];
      }

    } else {

      /* Sun to Planet (J2000) */
      palPlanet( date, np, v, &j );

      /* Precession and nutation to date */
      eraRxp( rmat, v, vsp );
      eraRxp( rmat, &(v[3]), &(vsp[3]) );

      /* Geocentre to planet */
      for (i=0; i<6; i++) {
        v[i] = vsp[i] - vsg[i];
      }

    }

  }

  /* Refer to origina at the observer */
  palPvobs( phi, 0.0, stl, vgo );
  for (i=0; i<6; i++) {
    v[i] -= vgo[i];
  }

  /* Geometric distance (AU) */
  dx = v[0];
  dy = v[1];
  dz = v[2];
  r = sqrt( dx*dx + dy*dy + dz*dz );

  /* Light time */
  tl = PAL__CR * r;

  /* Correct position for planetary aberration */
  for (i=0; i<3; i++) {
    v[i] -= tl * v[i+3];
  }

  /* To RA,Dec */
  eraC2s( v, ra, dec );
  *ra = eraAnp( *ra );

  /* Angular diameter (radians) */
  *diam = 2.0 * asin( EQRAU[np] / (r * AUKM ) );

}