1 /* spkpos.f -- translated by f2c (version 19980913).
2    You must link the resulting object file with the libraries:
3 	-lf2c -lm   (in that order)
4 */
5 
6 #include "f2c.h"
7 
8 /* $Procedure SPKPOS ( S/P Kernel, position ) */
spkpos_(char * targ,doublereal * et,char * ref,char * abcorr,char * obs,doublereal * ptarg,doublereal * lt,ftnlen targ_len,ftnlen ref_len,ftnlen abcorr_len,ftnlen obs_len)9 /* Subroutine */ int spkpos_(char *targ, doublereal *et, char *ref, char *
10 	abcorr, char *obs, doublereal *ptarg, doublereal *lt, ftnlen targ_len,
11 	 ftnlen ref_len, ftnlen abcorr_len, ftnlen obs_len)
12 {
13     /* Initialized data */
14 
15     static logical first = TRUE_;
16 
17     extern /* Subroutine */ int zzbods2c_(integer *, char *, integer *,
18 	    logical *, char *, integer *, logical *, ftnlen, ftnlen),
19 	    zzctruin_(integer *), chkin_(char *, ftnlen);
20     integer obsid;
21     extern /* Subroutine */ int errch_(char *, char *, ftnlen, ftnlen);
22     logical found;
23     static logical svfnd1, svfnd2;
24     static integer svctr1[2], svctr2[2];
25     integer targid;
26     extern /* Subroutine */ int sigerr_(char *, ftnlen), chkout_(char *,
27 	    ftnlen);
28     static integer svtgid;
29     extern /* Subroutine */ int setmsg_(char *, ftnlen);
30     static integer svobsi;
31     static char svtarg[36], svobsn[36];
32     extern /* Subroutine */ int spkezp_(integer *, doublereal *, char *, char
33 	    *, integer *, doublereal *, doublereal *, ftnlen, ftnlen);
34     extern logical return_(void);
35 
36 /* $ Abstract */
37 
38 /*     Return the position of a target body relative to an observing */
39 /*     body, optionally corrected for light time (planetary aberration) */
40 /*     and stellar aberration. */
41 
42 /* $ Disclaimer */
43 
44 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
45 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
46 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
47 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
48 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
49 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
50 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
51 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
52 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
53 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
54 
55 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
56 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
57 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
58 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
59 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
60 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
61 
62 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
63 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
64 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
65 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
66 
67 /* $ Required_Reading */
68 
69 /*     SPK */
70 /*     NAIF_IDS */
71 /*     FRAMES */
72 /*     TIME */
73 
74 /* $ Keywords */
75 
76 /*     EPHEMERIS */
77 
78 /* $ Declarations */
79 /* $ Abstract */
80 
81 /*     The parameters below form an enumerated list of the recognized */
82 /*     frame types.  They are: INERTL, PCK, CK, TK, DYN.  The meanings */
83 /*     are outlined below. */
84 
85 /* $ Disclaimer */
86 
87 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
88 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
89 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
90 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
91 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
92 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
93 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
94 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
95 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
96 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
97 
98 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
99 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
100 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
101 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
102 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
103 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
104 
105 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
106 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
107 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
108 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
109 
110 /* $ Parameters */
111 
112 /*     INERTL      an inertial frame that is listed in the routine */
113 /*                 CHGIRF and that requires no external file to */
114 /*                 compute the transformation from or to any other */
115 /*                 inertial frame. */
116 
117 /*     PCK         is a frame that is specified relative to some */
118 /*                 INERTL frame and that has an IAU model that */
119 /*                 may be retrieved from the PCK system via a call */
120 /*                 to the routine TISBOD. */
121 
122 /*     CK          is a frame defined by a C-kernel. */
123 
124 /*     TK          is a "text kernel" frame.  These frames are offset */
125 /*                 from their associated "relative" frames by a */
126 /*                 constant rotation. */
127 
128 /*     DYN         is a "dynamic" frame.  These currently are */
129 /*                 parameterized, built-in frames where the full frame */
130 /*                 definition depends on parameters supplied via a */
131 /*                 frame kernel. */
132 
133 /*     ALL         indicates any of the above classes. This parameter */
134 /*                 is used in APIs that fetch information about frames */
135 /*                 of a specified class. */
136 
137 
138 /* $ Author_and_Institution */
139 
140 /*     N.J. Bachman    (JPL) */
141 /*     W.L. Taber      (JPL) */
142 
143 /* $ Literature_References */
144 
145 /*     None. */
146 
147 /* $ Version */
148 
149 /* -    SPICELIB Version 4.0.0, 08-MAY-2012 (NJB) */
150 
151 /*       The parameter ALL was added to support frame fetch APIs. */
152 
153 /* -    SPICELIB Version 3.0.0, 28-MAY-2004 (NJB) */
154 
155 /*       The parameter DYN was added to support the dynamic frame class. */
156 
157 /* -    SPICELIB Version 2.0.0, 12-DEC-1996 (WLT) */
158 
159 /*        Various unused frames types were removed and the */
160 /*        frame time TK was added. */
161 
162 /* -    SPICELIB Version 1.0.0, 10-DEC-1995 (WLT) */
163 
164 /* -& */
165 
166 /*     End of INCLUDE file frmtyp.inc */
167 
168 /* $ Abstract */
169 
170 /*     This include file defines the dimension of the counter */
171 /*     array used by various SPICE subsystems to uniquely identify */
172 /*     changes in their states. */
173 
174 /* $ Disclaimer */
175 
176 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
177 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
178 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
179 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
180 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
181 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
182 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
183 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
184 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
185 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
186 
187 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
188 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
189 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
190 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
191 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
192 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
193 
194 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
195 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
196 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
197 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
198 
199 /* $ Parameters */
200 
201 /*     CTRSIZ      is the dimension of the counter array used by */
202 /*                 various SPICE subsystems to uniquely identify */
203 /*                 changes in their states. */
204 
205 /* $ Author_and_Institution */
206 
207 /*     B.V. Semenov    (JPL) */
208 
209 /* $ Literature_References */
210 
211 /*     None. */
212 
213 /* $ Version */
214 
215 /* -    SPICELIB Version 1.0.0, 29-JUL-2013 (BVS) */
216 
217 /* -& */
218 
219 /*     End of include file. */
220 
221 /* $ Brief_I/O */
222 
223 /*     Variable  I/O  Description */
224 /*     --------  ---  -------------------------------------------------- */
225 /*     TARG       I   Target body name. */
226 /*     ET         I   Observer epoch. */
227 /*     REF        I   Reference frame of output position vector. */
228 /*     ABCORR     I   Aberration correction flag. */
229 /*     OBS        I   Observing body name. */
230 /*     PTARG      O   Position of target. */
231 /*     LT         O   One way light time between observer and target. */
232 
233 /* $ Detailed_Input */
234 
235 /*     TARG        is the name of a target body.  Optionally, you may */
236 /*                 supply the integer ID code for the object as an */
237 /*                 integer string.  For example both 'MOON' and '301' */
238 /*                 are legitimate strings that indicate the moon is the */
239 /*                 target body. */
240 
241 /*                 The target and observer define a position vector */
242 /*                 which points from the observer to the target. */
243 
244 /*     ET          is the ephemeris time, expressed as seconds past */
245 /*                 J2000 TDB, at which the position of the target body */
246 /*                 relative to the observer is to be computed.  ET */
247 /*                 refers to time at the observer's location. */
248 
249 /*     REF         is the name of the reference frame relative to which */
250 /*                 the output position vector should be expressed. This */
251 /*                 may be any frame supported by the SPICE system, */
252 /*                 including built-in frames (documented in the Frames */
253 /*                 Required Reading) and frames defined by a loaded */
254 /*                 frame kernel (FK). */
255 
256 /*                 When REF designates a non-inertial frame, the */
257 /*                 orientation of the frame is evaluated at an epoch */
258 /*                 dependent on the selected aberration correction. See */
259 /*                 the description of the output position vector PTARG */
260 /*                 for details. */
261 
262 /*     ABCORR      indicates the aberration corrections to be applied to */
263 /*                 the position of the target body to account for */
264 /*                 one-way light time and stellar aberration.  See the */
265 /*                 discussion in the Particulars section for */
266 /*                 recommendations on how to choose aberration */
267 /*                 corrections. */
268 
269 /*                 ABCORR may be any of the following: */
270 
271 /*                    'NONE'     Apply no correction. Return the */
272 /*                               geometric position of the target body */
273 /*                               relative to the observer. */
274 
275 /*                 The following values of ABCORR apply to the */
276 /*                 "reception" case in which photons depart from the */
277 /*                 target's location at the light-time corrected epoch */
278 /*                 ET-LT and *arrive* at the observer's location at ET: */
279 
280 /*                    'LT'       Correct for one-way light time (also */
281 /*                               called "planetary aberration") using a */
282 /*                               Newtonian formulation. This correction */
283 /*                               yields the position of the target at */
284 /*                               the moment it emitted photons arriving */
285 /*                               at the observer at ET. */
286 
287 /*                               The light time correction uses an */
288 /*                               iterative solution of the light time */
289 /*                               equation (see Particulars for details). */
290 /*                               The solution invoked by the 'LT' option */
291 /*                               uses one iteration. */
292 
293 /*                    'LT+S'     Correct for one-way light time and */
294 /*                               stellar aberration using a Newtonian */
295 /*                               formulation. This option modifies the */
296 /*                               position obtained with the 'LT' option */
297 /*                               to account for the observer's velocity */
298 /*                               relative to the solar system */
299 /*                               barycenter. The result is the apparent */
300 /*                               position of the target---the position */
301 /*                               as seen by the observer. */
302 
303 /*                    'CN'       Converged Newtonian light time */
304 /*                               correction. In solving the light time */
305 /*                               equation, the 'CN' correction iterates */
306 /*                               until the solution converges (three */
307 /*                               iterations on all supported platforms). */
308 /*                               Whether the 'CN+S' solution is */
309 /*                               substantially more accurate than the */
310 /*                               'LT' solution depends on the geometry */
311 /*                               of the participating objects and on the */
312 /*                               accuracy of the input data. In all */
313 /*                               cases this routine will execute more */
314 /*                               slowly when a converged solution is */
315 /*                               computed. See the Particulars section */
316 /*                               below for a discussion of precision of */
317 /*                               light time corrections. */
318 
319 /*                    'CN+S'     Converged Newtonian light time */
320 /*                               correction and stellar aberration */
321 /*                               correction. */
322 
323 
324 /*                 The following values of ABCORR apply to the */
325 /*                 "transmission" case in which photons *depart* from */
326 /*                 the observer's location at ET and arrive at the */
327 /*                 target's location at the light-time corrected epoch */
328 /*                 ET+LT: */
329 
330 /*                    'XLT'      "Transmission" case:  correct for */
331 /*                               one-way light time using a Newtonian */
332 /*                               formulation. This correction yields the */
333 /*                               position of the target at the moment it */
334 /*                               receives photons emitted from the */
335 /*                               observer's location at ET. */
336 
337 /*                    'XLT+S'    "Transmission" case:  correct for */
338 /*                               one-way light time and stellar */
339 /*                               aberration using a Newtonian */
340 /*                               formulation. This option modifies the */
341 /*                               position obtained with the 'XLT' option */
342 /*                               to account for the observer's velocity */
343 /*                               relative to the solar system */
344 /*                               barycenter. The computed target */
345 /*                               position indicates the direction that */
346 /*                               photons emitted from the observer's */
347 /*                               location must be "aimed" to hit the */
348 /*                               target. */
349 
350 /*                    'XCN'      "Transmission" case:  converged */
351 /*                               Newtonian light time correction. */
352 
353 /*                    'XCN+S'    "Transmission" case:  converged */
354 /*                               Newtonian light time correction and */
355 /*                               stellar aberration correction. */
356 
357 
358 /*                 Neither special nor general relativistic effects are */
359 /*                 accounted for in the aberration corrections applied */
360 /*                 by this routine. */
361 
362 /*                 Case and blanks are not significant in the string */
363 /*                 ABCORR. */
364 
365 /*     OBS         is the name of an observing body.  Optionally, you */
366 /*                 may supply the ID code of the object as an integer */
367 /*                 string. For example, both 'EARTH' and '399' are */
368 /*                 legitimate strings to supply to indicate the */
369 /*                 observer is Earth. */
370 
371 /* $ Detailed_Output */
372 
373 /*     PTARG       is a Cartesian 3-vector representing the position of */
374 /*                 the target body relative to the specified observer. */
375 /*                 PTARG is corrected for the specified aberrations, and */
376 /*                 is expressed with respect to the reference frame */
377 /*                 specified by REF.  The three components of PTARG */
378 /*                 represent the x-, y- and z-components of the target's */
379 /*                 position. */
380 
381 /*                 PTARG points from the observer's location at ET to */
382 /*                 the aberration-corrected location of the target. */
383 /*                 Note that the sense of this position vector is */
384 /*                 independent of the direction of radiation travel */
385 /*                 implied by the aberration correction. */
386 
387 /*                 Units are always km. */
388 
389 /*                 Non-inertial frames are treated as follows: letting */
390 /*                 LTCENT be the one-way light time between the observer */
391 /*                 and the central body associated with the frame, the */
392 /*                 orientation of the frame is evaluated at ET-LTCENT, */
393 /*                 ET+LTCENT, or ET depending on whether the requested */
394 /*                 aberration correction is, respectively, for received */
395 /*                 radiation, transmitted radiation, or is omitted. */
396 /*                 LTCENT is computed using the method indicated by */
397 /*                 ABCORR. */
398 
399 /*     LT          is the one-way light time between the observer and */
400 /*                 target in seconds. If the target position is */
401 /*                 corrected for aberrations, then LT is the one-way */
402 /*                 light time between the observer and the light time */
403 /*                 corrected target location. */
404 
405 /* $ Parameters */
406 
407 /*     None. */
408 
409 /* $ Exceptions */
410 
411 /*     1) If name of target or observer cannot be translated to its */
412 /*        NAIF ID code, the error SPICE(IDCODENOTFOUND) is signaled. */
413 
414 /*     2) If the reference frame REF is not a recognized reference */
415 /*        frame the error 'SPICE(UNKNOWNFRAME)' is signaled. */
416 
417 /*     3) If the loaded kernels provide insufficient data to */
418 /*        compute the requested position vector, the deficiency will */
419 /*        be diagnosed by a routine in the call tree of this routine. */
420 
421 /*     4) If an error occurs while reading an SPK or other kernel file, */
422 /*        the error  will be diagnosed by a routine in the call tree */
423 /*        of this routine. */
424 
425 /* $ Files */
426 
427 /*     This routine computes positions using SPK files that have been */
428 /*     loaded into the SPICE system, normally via the kernel loading */
429 /*     interface routine FURNSH. See the routine FURNSH and the SPK */
430 /*     and KERNEL Required Reading for further information on loading */
431 /*     (and unloading) kernels. */
432 
433 /*     If the output position PTARG is to be expressed relative to a */
434 /*     non-inertial frame, or if any of the ephemeris data used to */
435 /*     compute PTARG are expressed relative to a non-inertial frame in */
436 /*     the SPK files providing those data, additional kernels may be */
437 /*     needed to enable the reference frame transformations required to */
438 /*     compute the position.  Normally these additional kernels are PCK */
439 /*     files or frame kernels.  Any such kernels must already be loaded */
440 /*     at the time this routine is called. */
441 
442 /* $ Particulars */
443 
444 /*     This routine is part of the user interface to the SPICE ephemeris */
445 /*     system.  It allows you to retrieve position information for any */
446 /*     ephemeris object relative to any other in a reference frame that */
447 /*     is convenient for further computations. */
448 
449 /*     This routine is identical in function to the routine SPKEZP */
450 /*     except that it allows you to refer to ephemeris objects by name */
451 /*     (via a character string). */
452 
453 
454 /*     Aberration corrections */
455 /*     ====================== */
456 
457 /*     In space science or engineering applications one frequently */
458 /*     wishes to know where to point a remote sensing instrument, such */
459 /*     as an optical camera or radio antenna, in order to observe or */
460 /*     otherwise receive radiation from a target.  This pointing problem */
461 /*     is complicated by the finite speed of light:  one needs to point */
462 /*     to where the target appears to be as opposed to where it actually */
463 /*     is at the epoch of observation.  We use the adjectives */
464 /*     "geometric," "uncorrected," or "true" to refer to an actual */
465 /*     position or state of a target at a specified epoch.  When a */
466 /*     geometric position or state vector is modified to reflect how it */
467 /*     appears to an observer, we describe that vector by any of the */
468 /*     terms "apparent," "corrected," "aberration corrected," or "light */
469 /*     time and stellar aberration corrected." The SPICE Toolkit can */
470 /*     correct for two phenomena affecting the apparent location of an */
471 /*     object:  one-way light time (also called "planetary aberration") */
472 /*     and stellar aberration. */
473 
474 /*     One-way light time */
475 /*     ------------------ */
476 
477 /*     Correcting for one-way light time is done by computing, given an */
478 /*     observer and observation epoch, where a target was when the */
479 /*     observed photons departed the target's location.  The vector from */
480 /*     the observer to this computed target location is called a "light */
481 /*     time corrected" vector.  The light time correction depends on the */
482 /*     motion of the target relative to the solar system barycenter, but */
483 /*     it is independent of the velocity of the observer relative to the */
484 /*     solar system barycenter. Relativistic effects such as light */
485 /*     bending and gravitational delay are not accounted for in the */
486 /*     light time correction performed by this routine. */
487 
488 /*     Stellar aberration */
489 /*     ------------------ */
490 
491 /*     The velocity of the observer also affects the apparent location */
492 /*     of a target:  photons arriving at the observer are subject to a */
493 /*     "raindrop effect" whereby their velocity relative to the observer */
494 /*     is, using a Newtonian approximation, the photons' velocity */
495 /*     relative to the solar system barycenter minus the velocity of the */
496 /*     observer relative to the solar system barycenter.  This effect is */
497 /*     called "stellar aberration."  Stellar aberration is independent */
498 /*     of the velocity of the target.  The stellar aberration formula */
499 /*     used by this routine does not include (the much smaller) */
500 /*     relativistic effects. */
501 
502 /*     Stellar aberration corrections are applied after light time */
503 /*     corrections:  the light time corrected target position vector is */
504 /*     used as an input to the stellar aberration correction. */
505 
506 /*     When light time and stellar aberration corrections are both */
507 /*     applied to a geometric position vector, the resulting position */
508 /*     vector indicates where the target "appears to be" from the */
509 /*     observer's location. */
510 
511 /*     As opposed to computing the apparent position of a target, one */
512 /*     may wish to compute the pointing direction required for */
513 /*     transmission of photons to the target.  This also requires */
514 /*     correction of the geometric target position for the effects of */
515 /*     light time and stellar aberration, but in this case the */
516 /*     corrections are computed for radiation traveling *from* the */
517 /*     observer to the target. */
518 
519 /*     The "transmission" light time correction yields the target's */
520 /*     location as it will be when photons emitted from the observer's */
521 /*     location at ET arrive at the target.  The transmission stellar */
522 /*     aberration correction is the inverse of the traditional stellar */
523 /*     aberration correction:  it indicates the direction in which */
524 /*     radiation should be emitted so that, using a Newtonian */
525 /*     approximation, the sum of the velocity of the radiation relative */
526 /*     to the observer and of the observer's velocity, relative to the */
527 /*     solar system barycenter, yields a velocity vector that points in */
528 /*     the direction of the light time corrected position of the target. */
529 
530 /*     One may object to using the term "observer" in the transmission */
531 /*     case, in which radiation is emitted from the observer's location. */
532 /*     The terminology was retained for consistency with earlier */
533 /*     documentation. */
534 
535 /*     Below, we indicate the aberration corrections to use for some */
536 /*     common applications: */
537 
538 /*        1) Find the apparent direction of a target for a remote-sensing */
539 /*           observation. */
540 
541 /*              Use 'LT+S' or 'CN+S: apply both light time and stellar */
542 /*              aberration corrections. */
543 
544 /*           Note that using light time corrections alone ('LT' or 'CN') */
545 /*           is generally not a good way to obtain an approximation to */
546 /*           an apparent target vector: since light time and stellar */
547 /*           aberration corrections often partially cancel each other, */
548 /*           it may be more accurate to use no correction at all than to */
549 /*           use light time alone. */
550 
551 
552 /*        2) Find the corrected pointing direction to radiate a signal */
553 /*           to a target. This computation is often applicable for */
554 /*           implementing communications sessions. */
555 
556 /*              Use 'XLT+S' or 'XCN+S: apply both light time and stellar */
557 /*              aberration corrections for transmission. */
558 
559 
560 /*        3) Compute the apparent position of a target body relative */
561 /*           to a star or other distant object. */
562 
563 /*              Use 'LT', 'CN', 'LT+S', or 'CN+S' as needed to match the */
564 /*              correction applied to the position of the distant */
565 /*              object. For example, if a star position is obtained from */
566 /*              a catalog, the position vector may not be corrected for */
567 /*              stellar aberration. In this case, to find the angular */
568 /*              separation of the star and the limb of a planet, the */
569 /*              vector from the observer to the planet should be */
570 /*              corrected for light time but not stellar aberration. */
571 
572 
573 /*        4) Obtain an uncorrected position vector derived directly from */
574 /*           data in an SPK file. */
575 
576 /*              Use 'NONE'. */
577 
578 
579 /*        5) Use a geometric position vector as a low-accuracy estimate */
580 /*           of the apparent position for an application where execution */
581 /*           speed is critical. */
582 
583 /*              Use 'NONE'. */
584 
585 
586 /*        6) While this routine cannot perform the relativistic */
587 /*           aberration corrections required to compute positions */
588 /*           with the highest possible accuracy, it can supply the */
589 /*           geometric positions required as inputs to these */
590 /*           computations. */
591 
592 /*              Use 'NONE', then apply high-accuracy aberration */
593 /*              corrections (not available in the SPICE Toolkit). */
594 
595 
596 /*     Below, we discuss in more detail how the aberration corrections */
597 /*     applied by this routine are computed. */
598 
599 /*        Geometric case */
600 /*        ============== */
601 
602 /*        SPKPOS begins by computing the geometric position T(ET) of the */
603 /*        target body relative to the solar system barycenter (SSB). */
604 /*        Subtracting the geometric position of the observer O(ET) gives */
605 /*        the geometric position of the target body relative to the */
606 /*        observer. The one-way light time, LT, is given by */
607 
608 /*                  | T(ET) - O(ET) | */
609 /*           LT = ------------------- */
610 /*                          c */
611 
612 /*        The geometric relationship between the observer, target, and */
613 /*        solar system barycenter is as shown: */
614 
615 
616 /*           SSB ---> O(ET) */
617 /*            |      / */
618 /*            |     / */
619 /*            |    / */
620 /*            |   /  T(ET) - O(ET) */
621 /*            V  V */
622 /*           T(ET) */
623 
624 
625 /*        The returned position vector is */
626 
627 /*           T(ET) - O(ET) */
628 
629 
630 
631 /*        Reception case */
632 /*        ============== */
633 
634 /*        When any of the options 'LT', 'CN', 'LT+S', 'CN+S' is selected */
635 /*        for ABCORR, SPKPOS computes the position of the target body at */
636 /*        epoch ET-LT, where LT is the one-way light time.  Let T(t) and */
637 /*        O(t) represent the positions of the target and observer */
638 /*        relative to the solar system barycenter at time t; then LT is */
639 /*        the solution of the light-time equation */
640 
641 /*                  | T(ET-LT) - O(ET) | */
642 /*           LT = ------------------------                            (1) */
643 /*                           c */
644 
645 /*        The ratio */
646 
647 /*            | T(ET) - O(ET) | */
648 /*          ---------------------                                     (2) */
649 /*                    c */
650 
651 /*        is used as a first approximation to LT; inserting (2) into the */
652 /*        right hand side of the light-time equation (1) yields the */
653 /*        "one-iteration" estimate of the one-way light time ("LT"). */
654 /*        Repeating the process until the estimates of LT converge */
655 /*        yields the "converged Newtonian" light time estimate ("CN"). */
656 
657 /*        Subtracting the geometric position of the observer O(ET) gives */
658 /*        the position of the target body relative to the observer: */
659 /*        T(ET-LT) - O(ET). */
660 
661 /*           SSB ---> O(ET) */
662 /*            | \     | */
663 /*            |  \    | */
664 /*            |   \   | T(ET-LT) - O(ET) */
665 /*            |    \  | */
666 /*            V     V V */
667 /*           T(ET)  T(ET-LT) */
668 
669 /*        The light time corrected position vector is */
670 
671 /*           T(ET-LT) - O(ET) */
672 
673 /*        If correction for stellar aberration is requested, the target */
674 /*        position is rotated toward the solar system barycenter- */
675 /*        relative velocity vector of the observer.  The rotation is */
676 /*        computed as follows: */
677 
678 /*           Let r be the light time corrected vector from the observer */
679 /*           to the object, and v be the velocity of the observer with */
680 /*           respect to the solar system barycenter. Let w be the angle */
681 /*           between them. The aberration angle phi is given by */
682 
683 /*              sin(phi) = v sin(w) / c */
684 
685 /*           Let h be the vector given by the cross product */
686 
687 /*              h = r X v */
688 
689 /*           Rotate r by phi radians about h to obtain the apparent */
690 /*           position of the object. */
691 
692 
693 /*        Transmission case */
694 /*        ================== */
695 
696 /*        When any of the options 'XLT', 'XCN', 'XLT+S', 'XCN+S' is */
697 /*        selected, SPKPOS computes the position of the target body T at */
698 /*        epoch ET+LT, where LT is the one-way light time.  LT is the */
699 /*        solution of the light-time equation */
700 
701 /*                  | T(ET+LT) - O(ET) | */
702 /*           LT = ------------------------                            (3) */
703 /*                            c */
704 
705 /*        Subtracting the geometric position of the observer, O(ET), */
706 /*        gives the position of the target body relative to the */
707 /*        observer: T(ET-LT) - O(ET). */
708 
709 /*                   SSB --> O(ET) */
710 /*                  / |    * */
711 /*                 /  |  *  T(ET+LT) - O(ET) */
712 /*                /   |* */
713 /*               /   *| */
714 /*              V  V  V */
715 /*          T(ET+LT)  T(ET) */
716 
717 /*        The light-time corrected position vector is */
718 
719 /*           T(ET+LT) - O(ET) */
720 
721 /*        If correction for stellar aberration is requested, the target */
722 /*        position is rotated away from the solar system barycenter- */
723 /*        relative velocity vector of the observer. The rotation is */
724 /*        computed as in the reception case, but the sign of the */
725 /*        rotation angle is negated. */
726 
727 
728 /*     Precision of light time corrections */
729 /*     =================================== */
730 
731 /*        Corrections using one iteration of the light time solution */
732 /*        ---------------------------------------------------------- */
733 
734 /*        When the requested aberration correction is 'LT', 'LT+S', */
735 /*        'XLT', or 'XLT+S', only one iteration is performed in the */
736 /*        algorithm used to compute LT. */
737 
738 /*        The relative error in this computation */
739 
740 /*           | LT_ACTUAL - LT_COMPUTED |  /  LT_ACTUAL */
741 
742 /*        is at most */
743 
744 /*            (V/C)**2 */
745 /*           ---------- */
746 /*            1 - (V/C) */
747 
748 /*        which is well approximated by (V/C)**2, where V is the */
749 /*        velocity of the target relative to an inertial frame and C is */
750 /*        the speed of light. */
751 
752 /*        For nearly all objects in the solar system V is less than 60 */
753 /*        km/sec. The value of C is ~300000 km/sec. Thus the */
754 /*        one-iteration solution for LT has a potential relative error */
755 /*        of not more than 4e-8. This is a potential light time error of */
756 /*        approximately 2e-5 seconds per astronomical unit of distance */
757 /*        separating the observer and target. Given the bound on V cited */
758 /*        above: */
759 
760 /*           As long as the observer and target are separated by less */
761 /*           than 50 astronomical units, the error in the light time */
762 /*           returned using the one-iteration light time corrections is */
763 /*           less than 1 millisecond. */
764 
765 /*           The magnitude of the corresponding position error, given */
766 /*           the above assumptions, may be as large as (V/C)**2 * the */
767 /*           distance between the observer and the uncorrected target */
768 /*           position: 300 km or equivalently 6 km/AU. */
769 
770 /*        In practice, the difference between positions obtained using */
771 /*        one-iteration and converged light time is usually much smaller */
772 /*        than the value computed above and can be insignificant. For */
773 /*        example, for the spacecraft Mars Reconnaissance Orbiter and */
774 /*        Mars Express, the position error for the one-iteration light */
775 /*        time correction, applied to the spacecraft-to-Mars center */
776 /*        vector, is at the 1 cm level. */
777 
778 /*        Comparison of results obtained using the one-iteration and */
779 /*        converged light time solutions is recommended when adequacy of */
780 /*        the one-iteration solution is in doubt. */
781 
782 
783 /*        Converged corrections */
784 /*        --------------------- */
785 
786 /*        When the requested aberration correction is 'CN', 'CN+S', */
787 /*        'XCN', or 'XCN+S', as many iterations as are required for */
788 /*        convergence are performed in the computation of LT. Usually */
789 /*        the solution is found after three iterations. The relative */
790 /*        error present in this case is at most */
791 
792 /*            (V/C)**4 */
793 /*           ---------- */
794 /*            1 - (V/C) */
795 
796 /*        which is well approximated by (V/C)**4. */
797 
798 /*           The precision of this computation (ignoring round-off */
799 /*           error) is better than 4e-11 seconds for any pair of objects */
800 /*           less than 50 AU apart, and having speed relative to the */
801 /*           solar system barycenter less than 60 km/s. */
802 
803 /*           The magnitude of the corresponding position error, given */
804 /*           the above assumptions, may be as large as (V/C)**4 * the */
805 /*           distance between the observer and the uncorrected target */
806 /*           position: 1.2 cm at 50 AU or equivalently 0.24 mm/AU. */
807 
808 /*        However, to very accurately model the light time between */
809 /*        target and observer one must take into account effects due to */
810 /*        general relativity. These may be as high as a few hundredths */
811 /*        of a millisecond for some objects. */
812 
813 
814 /*     Relativistic Corrections */
815 /*     ========================= */
816 
817 /*     This routine does not attempt to perform either general or */
818 /*     special relativistic corrections in computing the various */
819 /*     aberration corrections.  For many applications relativistic */
820 /*     corrections are not worth the expense of added computation */
821 /*     cycles.  If however, your application requires these additional */
822 /*     corrections we suggest you consult the astronomical almanac (page */
823 /*     B36) for a discussion of how to carry out these corrections. */
824 
825 
826 /* $ Examples */
827 
828 /*     1)  Load a planetary ephemeris SPK, then look up a series of */
829 /*         geometric positions of the moon relative to the earth, */
830 /*         referenced to the J2000 frame. */
831 
832 
833 /*               IMPLICIT NONE */
834 /*         C */
835 /*         C     Local constants */
836 /*         C */
837 /*               CHARACTER*(*)         FRAME */
838 /*               PARAMETER           ( FRAME  = 'J2000' ) */
839 
840 /*               CHARACTER*(*)         ABCORR */
841 /*               PARAMETER           ( ABCORR = 'NONE' ) */
842 
843 /*         C */
844 /*         C     The name of the SPK file shown here is fictitious; */
845 /*         C     you must supply the name of an SPK file available */
846 /*         C     on your own computer system. */
847 /*         C */
848 /*               CHARACTER*(*)         SPK */
849 /*               PARAMETER           ( SPK    = 'planet.bsp' ) */
850 
851 /*         C */
852 /*         C     ET0 represents the date 2000 Jan 1 12:00:00 TDB. */
853 /*         C */
854 /*               DOUBLE PRECISION      ET0 */
855 /*               PARAMETER           ( ET0    = 0.0D0 ) */
856 
857 /*         C */
858 /*         C     Use a time step of 1 hour; look up 100 positions. */
859 /*         C */
860 /*               DOUBLE PRECISION      STEP */
861 /*               PARAMETER           ( STEP   = 3600.0D0 ) */
862 
863 /*               INTEGER               MAXITR */
864 /*               PARAMETER           ( MAXITR = 100 ) */
865 
866 /*               CHARACTER*(*)         OBSRVR */
867 /*               PARAMETER           ( OBSRVR = 'Earth' ) */
868 
869 /*               CHARACTER*(*)         TARGET */
870 /*               PARAMETER           ( TARGET = 'Moon' ) */
871 
872 /*         C */
873 /*         C     Local variables */
874 /*         C */
875 /*               DOUBLE PRECISION      ET */
876 /*               DOUBLE PRECISION      LT */
877 /*               DOUBLE PRECISION      POS ( 3 ) */
878 
879 /*               INTEGER               I */
880 
881 /*         C */
882 /*         C     Load the SPK file. */
883 /*         C */
884 /*               CALL FURNSH ( SPK ) */
885 
886 /*         C */
887 /*         C     Step through a series of epochs, looking up a */
888 /*         C     position vector at each one. */
889 /*         C */
890 /*               DO I = 1, MAXITR */
891 
892 /*                  ET = ET0 + (I-1)*STEP */
893 
894 /*                  CALL SPKPOS ( TARGET, ET, FRAME, ABCORR, OBSRVR, */
895 /*              .                 POS,    LT                        ) */
896 
897 /*                  WRITE (*,*) 'ET = ', ET */
898 /*                  WRITE (*,*) 'J2000 x-position (km):   ', POS(1) */
899 /*                  WRITE (*,*) 'J2000 y-position (km):   ', POS(2) */
900 /*                  WRITE (*,*) 'J2000 z-position (km):   ', POS(3) */
901 /*                  WRITE (*,*) ' ' */
902 
903 /*               END DO */
904 
905 /*               END */
906 
907 
908 /* $ Restrictions */
909 
910 /*     None. */
911 
912 /* $ Literature_References */
913 
914 /*     SPK Required Reading. */
915 
916 /* $ Author_and_Institution */
917 
918 /*     C.H. Acton      (JPL) */
919 /*     B.V. Semenov    (JPL) */
920 /*     N.J. Bachman    (JPL) */
921 /*     W.L. Taber      (JPL) */
922 
923 /* $ Version */
924 
925 /* -    SPICELIB Version 3.1.0, 03-JUL-2014 (NJB) (BVS) */
926 
927 /*        Discussion of light time corrections was updated. Assertions */
928 /*        that converged light time corrections are unlikely to be */
929 /*        useful were removed. */
930 
931 /*     Last update was 19-SEP-2013 (BVS) */
932 
933 /*        Updated to save the input body names and ZZBODTRN state */
934 /*        counters and to do name-ID conversions only if the counters */
935 /*        have changed. */
936 
937 /* -    SPICELIB Version 3.0.3, 04-APR-2008 (NJB) */
938 
939 /*        Corrected minor error in description of XLT+S aberration */
940 /*        correction. */
941 
942 /* -    SPICELIB Version 3.0.2, 20-OCT-2003 (EDW) */
943 
944 /*        Added mention that LT returns in seconds. */
945 
946 /* -    SPICELIB Version 3.0.1, 29-JUL-2003 (NJB) (CHA) */
947 
948 /*        Various minor header changes were made to improve clarity. */
949 
950 /* -    SPICELIB Version 3.0.0, 31-DEC-2001 (NJB) */
951 
952 /*        Updated to handle aberration corrections for transmission */
953 /*        of radiation.  Formerly, only the reception case was */
954 /*        supported.  The header was revised and expanded to explain */
955 /*        the functionality of this routine in more detail. */
956 
957 /* -    SPICELIB Version 1.0.0, 03-MAR-1999 (WLT) */
958 
959 /* -& */
960 /* $ Index_Entries */
961 
962 /*     using body names get position relative to an observer */
963 /*     get position relative observer corrected for aberrations */
964 /*     read ephemeris data */
965 /*     read trajectory data */
966 
967 /* -& */
968 /* $ Revisions */
969 
970 /*     None. */
971 
972 /* -& */
973 
974 /*     SPICELIB functions */
975 
976 
977 /*     Saved body name length. */
978 
979 
980 /*     Local variables */
981 
982 
983 /*     Saved name/ID item declarations. */
984 
985 
986 /*     Saved name/ID items. */
987 
988 
989 /*     Initial values. */
990 
991 
992 /*     Standard SPICE error handling. */
993 
994     if (return_()) {
995 	return 0;
996     } else {
997 	chkin_("SPKPOS", (ftnlen)6);
998     }
999 
1000 /*     Initialization. */
1001 
1002     if (first) {
1003 
1004 /*        Initialize counters. */
1005 
1006 	zzctruin_(svctr1);
1007 	zzctruin_(svctr2);
1008 	first = FALSE_;
1009     }
1010 
1011 /*     Starting from translation of target name to its code */
1012 
1013     zzbods2c_(svctr1, svtarg, &svtgid, &svfnd1, targ, &targid, &found, (
1014 	    ftnlen)36, targ_len);
1015     if (! found) {
1016 	setmsg_("The target, '#', is not a recognized name for an ephemeris "
1017 		"object. The cause of this problem may be that you need an up"
1018 		"dated version of the SPICE toolkit. Alternatively you may ca"
1019 		"ll SPKEZP directly if you know the SPICE id-codes for both '"
1020 		"#' and '#' ", (ftnlen)250);
1021 	errch_("#", targ, (ftnlen)1, targ_len);
1022 	errch_("#", targ, (ftnlen)1, targ_len);
1023 	errch_("#", obs, (ftnlen)1, obs_len);
1024 	sigerr_("SPICE(IDCODENOTFOUND)", (ftnlen)21);
1025 	chkout_("SPKPOS", (ftnlen)6);
1026 	return 0;
1027     }
1028 
1029 /*     Now do the same for observer. */
1030 
1031     zzbods2c_(svctr2, svobsn, &svobsi, &svfnd2, obs, &obsid, &found, (ftnlen)
1032 	    36, obs_len);
1033     if (! found) {
1034 	setmsg_("The observer, '#', is not a recognized name for an ephemeri"
1035 		"s object. The cause of this problem may be that you need an "
1036 		"updated version of the SPICE toolkit. Alternatively you may "
1037 		"call SPKEZP directly if you know the SPICE id-codes for both"
1038 		" '#' and '#' ", (ftnlen)252);
1039 	errch_("#", obs, (ftnlen)1, obs_len);
1040 	errch_("#", targ, (ftnlen)1, targ_len);
1041 	errch_("#", obs, (ftnlen)1, obs_len);
1042 	sigerr_("SPICE(IDCODENOTFOUND)", (ftnlen)21);
1043 	chkout_("SPKPOS", (ftnlen)6);
1044 	return 0;
1045     }
1046 
1047 /*     After all translations are done we can call SPKEZP. */
1048 
1049     spkezp_(&targid, et, ref, abcorr, &obsid, ptarg, lt, ref_len, abcorr_len);
1050     chkout_("SPKPOS", (ftnlen)6);
1051     return 0;
1052 } /* spkpos_ */
1053 
1054