1 /* pgrrec.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 /* Table of constant values */
9 
10 static integer c__1 = 1;
11 static integer c__0 = 0;
12 
13 /* $Procedure      PGRREC ( Planetographic to rectangular ) */
pgrrec_(char * body,doublereal * lon,doublereal * lat,doublereal * alt,doublereal * re,doublereal * f,doublereal * rectan,ftnlen body_len)14 /* Subroutine */ int pgrrec_(char *body, doublereal *lon, doublereal *lat,
15 	doublereal *alt, doublereal *re, doublereal *f, doublereal *rectan,
16 	ftnlen body_len)
17 {
18     /* Initialized data */
19 
20     static logical first = TRUE_;
21 
22     /* Builtin functions */
23     integer s_cmp(char *, char *, ftnlen, ftnlen);
24 
25     /* Local variables */
26     extern /* Subroutine */ int zzbods2c_(integer *, char *, integer *,
27 	    logical *, char *, integer *, logical *, ftnlen, ftnlen),
28 	    zzctruin_(integer *);
29     integer n;
30     extern /* Subroutine */ int chkin_(char *, ftnlen), errch_(char *, char *,
31 	     ftnlen, ftnlen);
32     logical found;
33     extern /* Subroutine */ int errdp_(char *, doublereal *, ftnlen);
34     integer sense;
35     extern /* Subroutine */ int repmi_(char *, char *, integer *, char *,
36 	    ftnlen, ftnlen, ftnlen);
37     static logical svfnd1;
38     static integer svctr1[2];
39     extern /* Subroutine */ int georec_(doublereal *, doublereal *,
40 	    doublereal *, doublereal *, doublereal *, doublereal *);
41     integer bodyid;
42     static integer svbdid;
43     doublereal geolon;
44     extern /* Subroutine */ int gcpool_(char *, integer *, integer *, integer
45 	    *, char *, logical *, ftnlen, ftnlen);
46     char kvalue[80];
47     extern /* Subroutine */ int sigerr_(char *, ftnlen), chkout_(char *,
48 	    ftnlen);
49     char pmkvar[32], pgrlon[4];
50     extern /* Subroutine */ int setmsg_(char *, ftnlen);
51     static char svbody[36];
52     extern /* Subroutine */ int ljucrs_(integer *, char *, char *, ftnlen,
53 	    ftnlen);
54     extern integer plnsns_(integer *);
55     extern logical return_(void);
56 
57 /* $ Abstract */
58 
59 /*     Convert planetographic coordinates to rectangular coordinates. */
60 
61 /* $ Disclaimer */
62 
63 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
64 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
65 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
66 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
67 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
68 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
69 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
70 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
71 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
72 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
73 
74 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
75 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
76 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
77 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
78 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
79 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
80 
81 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
82 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
83 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
84 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
85 
86 /* $ Required_Reading */
87 
88 /*     KERNEL */
89 /*     NAIF_IDS */
90 /*     PCK */
91 
92 /* $ Keywords */
93 
94 /*     CONVERSION */
95 /*     COORDINATES */
96 /*     GEOMETRY */
97 /*     MATH */
98 
99 /* $ Declarations */
100 /* $ Abstract */
101 
102 /*     This include file defines the dimension of the counter */
103 /*     array used by various SPICE subsystems to uniquely identify */
104 /*     changes in their states. */
105 
106 /* $ Disclaimer */
107 
108 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
109 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
110 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
111 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
112 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
113 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
114 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
115 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
116 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
117 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
118 
119 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
120 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
121 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
122 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
123 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
124 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
125 
126 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
127 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
128 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
129 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
130 
131 /* $ Parameters */
132 
133 /*     CTRSIZ      is the dimension of the counter array used by */
134 /*                 various SPICE subsystems to uniquely identify */
135 /*                 changes in their states. */
136 
137 /* $ Author_and_Institution */
138 
139 /*     B.V. Semenov    (JPL) */
140 
141 /* $ Literature_References */
142 
143 /*     None. */
144 
145 /* $ Version */
146 
147 /* -    SPICELIB Version 1.0.0, 29-JUL-2013 (BVS) */
148 
149 /* -& */
150 
151 /*     End of include file. */
152 
153 /* $ Brief_I/O */
154 
155 /*     VARIABLE  I/O  DESCRIPTION */
156 /*     --------  ---  -------------------------------------------------- */
157 /*     BODY       I   Body with which coordinate system is associated. */
158 /*     LON        I   Planetographic longitude of a point (radians). */
159 /*     LAT        I   Planetographic latitude of a point (radians). */
160 /*     ALT        I   Altitude of a point above reference spheroid. */
161 /*     RE         I   Equatorial radius of the reference spheroid. */
162 /*     F          I   Flattening coefficient. */
163 /*     RECTAN     O   Rectangular coordinates of the point. */
164 
165 /* $ Detailed_Input */
166 
167 /*     BODY       Name of the body with which the planetographic */
168 /*                coordinate system is associated. */
169 
170 /*                BODY is used by this routine to look up from the */
171 /*                kernel pool the prime meridian rate coefficient giving */
172 /*                the body's spin sense.  See the Files and Particulars */
173 /*                header sections below for details. */
174 
175 /*     LON        Planetographic longitude of the input point.  This is */
176 /*                the angle between the prime meridian and the meridian */
177 /*                containing the input point.  For bodies having */
178 /*                prograde (aka direct) rotation, the direction of */
179 /*                increasing longitude is positive west:  from the +X */
180 /*                axis of the rectangular coordinate system toward the */
181 /*                -Y axis.  For bodies having retrograde rotation, the */
182 /*                direction of increasing longitude is positive east: */
183 /*                from the +X axis toward the +Y axis. */
184 
185 /*                The earth, moon, and sun are exceptions: */
186 /*                planetographic longitude is measured positive east for */
187 /*                these bodies. */
188 
189 /*                The default interpretation of longitude by this */
190 /*                and the other planetographic coordinate conversion */
191 /*                routines can be overridden; see the discussion in */
192 /*                Particulars below for details. */
193 
194 /*                Longitude is measured in radians. On input, the range */
195 /*                of longitude is unrestricted. */
196 
197 /*     LAT        Planetographic latitude of the input point.  For a */
198 /*                point P on the reference spheroid, this is the angle */
199 /*                between the XY plane and the outward normal vector at */
200 /*                P. For a point P not on the reference spheroid, the */
201 /*                planetographic latitude is that of the closest point */
202 /*                to P on the spheroid. */
203 
204 /*                Latitude is measured in radians.  On input, the */
205 /*                range of latitude is unrestricted. */
206 
207 /*     ALT        Altitude of point above the reference spheroid. */
208 /*                Units of ALT must match those of RE. */
209 
210 /*     RE         Equatorial radius of a reference spheroid.  This */
211 /*                spheroid is a volume of revolution:  its horizontal */
212 /*                cross sections are circular.  The shape of the */
213 /*                spheroid is defined by an equatorial radius RE and */
214 /*                a polar radius RP.  Units of RE must match those of */
215 /*                ALT. */
216 
217 /*     F          Flattening coefficient = */
218 
219 /*                   (RE-RP) / RE */
220 
221 /*                where RP is the polar radius of the spheroid, and the */
222 /*                units of RP match those of RE. */
223 
224 /* $ Detailed_Output */
225 
226 /*     RECTAN     The rectangular coordinates of the input point.  See */
227 /*                the discussion below in the Particulars header section */
228 /*                for details. */
229 
230 /*                The units associated with RECTAN are those associated */
231 /*                with the inputs ALT and RE. */
232 
233 /* $ Parameters */
234 
235 /*     None. */
236 
237 /* $ Exceptions */
238 
239 /*     1) If the body name BODY cannot be mapped to a NAIF ID code, */
240 /*        and if BODY is not a string representation of an integer, */
241 /*        the error SPICE(IDCODENOTFOUND) will be signaled. */
242 
243 /*     2) If the kernel variable */
244 
245 /*           BODY<ID code>_PGR_POSITIVE_LON */
246 
247 /*        is present in the kernel pool but has a value other */
248 /*        than one of */
249 
250 /*            'EAST' */
251 /*            'WEST' */
252 
253 /*        the error SPICE(INVALIDOPTION) will be signaled.  Case */
254 /*        and blanks are ignored when these values are interpreted. */
255 
256 /*     3) If polynomial coefficients for the prime meridian of BODY */
257 /*        are not available in the kernel pool, and if the kernel */
258 /*        variable BODY<ID code>_PGR_POSITIVE_LON is not present in */
259 /*        the kernel pool, the error SPICE(MISSINGDATA) will be signaled. */
260 
261 /*     4) If the equatorial radius is non-positive, the error */
262 /*        SPICE(VALUEOUTOFRANGE) is signaled. */
263 
264 /*     5) If the flattening coefficient is greater than or equal to one, */
265 /*        the error SPICE(VALUEOUTOFRANGE) is signaled. */
266 
267 /* $ Files */
268 
269 /*     This routine expects a kernel variable giving BODY's prime */
270 /*     meridian angle as a function of time to be available in the */
271 /*     kernel pool.  Normally this item is provided by loading a PCK */
272 /*     file.  The required kernel variable is named */
273 
274 /*        BODY<body ID>_PM */
275 
276 /*     where <body ID> represents a string containing the NAIF integer */
277 /*     ID code for BODY.  For example, if BODY is 'JUPITER', then */
278 /*     the name of the kernel variable containing the prime meridian */
279 /*     angle coefficients is */
280 
281 /*        BODY599_PM */
282 
283 /*     See the PCK Required Reading for details concerning the prime */
284 /*     meridian kernel variable. */
285 
286 /*     The optional kernel variable */
287 
288 /*        BODY<body ID>_PGR_POSITIVE_LON */
289 
290 /*     also is normally defined via loading a text kernel. When this */
291 /*     variable is present in the kernel pool, the prime meridian */
292 /*     coefficients for BODY are not required by this routine. See the */
293 /*     Particulars section below for details. */
294 
295 /* $ Particulars */
296 
297 /*     Given the planetographic coordinates of a point, this routine */
298 /*     returns the body-fixed rectangular coordinates of the point.  The */
299 /*     body-fixed rectangular frame is that having the X-axis pass */
300 /*     through the 0 degree latitude 0 degree longitude direction, the */
301 /*     Z-axis pass through the 90 degree latitude direction, and the */
302 /*     Y-axis equal to the cross product of the unit Z-axis and X-axis */
303 /*     vectors. */
304 
305 /*     The planetographic definition of latitude is identical to the */
306 /*     planetodetic (also called "geodetic" in SPICE documentation) */
307 /*     definition. In the planetographic coordinate system, latitude is */
308 /*     defined using a reference spheroid.  The spheroid is */
309 /*     characterized by an equatorial radius and a polar radius. For a */
310 /*     point P on the spheroid, latitude is defined as the angle between */
311 /*     the X-Y plane and the outward surface normal at P.  For a point P */
312 /*     off the spheroid, latitude is defined as the latitude of the */
313 /*     nearest point to P on the spheroid.  Note if P is an interior */
314 /*     point, for example, if P is at the center of the spheroid, there */
315 /*     may not be a unique nearest point to P. */
316 
317 /*     In the planetographic coordinate system, longitude is defined */
318 /*     using the spin sense of the body.  Longitude is positive to the */
319 /*     west if the spin is prograde and positive to the east if the spin */
320 /*     is retrograde.  The spin sense is given by the sign of the first */
321 /*     degree term of the time-dependent polynomial for the body's prime */
322 /*     meridian Euler angle "W":  the spin is retrograde if this term is */
323 /*     negative and prograde otherwise.  For the sun, planets, most */
324 /*     natural satellites, and selected asteroids, the polynomial */
325 /*     expression for W may be found in a SPICE PCK kernel. */
326 
327 /*     The earth, moon, and sun are exceptions: planetographic longitude */
328 /*     is measured positive east for these bodies. */
329 
330 /*     If you wish to override the default sense of positive longitude */
331 /*     for a particular body, you can do so by defining the kernel */
332 /*     variable */
333 
334 /*        BODY<body ID>_PGR_POSITIVE_LON */
335 
336 /*     where <body ID> represents the NAIF ID code of the body. This */
337 /*     variable may be assigned either of the values */
338 
339 /*        'WEST' */
340 /*        'EAST' */
341 
342 /*     For example, you can have this routine treat the longitude */
343 /*     of the earth as increasing to the west using the kernel */
344 /*     variable assignment */
345 
346 /*        BODY399_PGR_POSITIVE_LON = 'WEST' */
347 
348 /*     Normally such assignments are made by placing them in a text */
349 /*     kernel and loading that kernel via FURNSH. */
350 
351 /*     The definition of this kernel variable controls the behavior of */
352 /*     the SPICELIB planetographic routines */
353 
354 /*        PGRREC */
355 /*        RECPGR */
356 /*        DPGRDR */
357 /*        DRDPGR */
358 
359 /*     It does not affect the other SPICELIB coordinate conversion */
360 /*     routines. */
361 
362 /* $ Examples */
363 
364 /*     Numerical results shown for this example may differ between */
365 /*     platforms as the results depend on the SPICE kernels used as */
366 /*     input and the machine specific arithmetic implementation. */
367 
368 
369 /*     1) Find the rectangular coordinates of the point having Mars */
370 /*        planetographic coordinates: */
371 
372 /*           longitude = 90 degrees west */
373 /*           latitude  = 45 degrees north */
374 /*           altitude  = 300 km */
375 
376 
377 /*                 PROGRAM EX1 */
378 /*                 IMPLICIT NONE */
379 /*           C */
380 /*           C     SPICELIB functions */
381 /*           C */
382 /*                 DOUBLE PRECISION      RPD */
383 /*           C */
384 /*           C     Local variables */
385 /*           C */
386 /*                 DOUBLE PRECISION      ALT */
387 /*                 DOUBLE PRECISION      F */
388 /*                 DOUBLE PRECISION      LAT */
389 /*                 DOUBLE PRECISION      LON */
390 /*                 DOUBLE PRECISION      RADII  ( 3 ) */
391 /*                 DOUBLE PRECISION      RE */
392 /*                 DOUBLE PRECISION      RECTAN ( 3 ) */
393 /*                 DOUBLE PRECISION      RP */
394 
395 /*                 INTEGER               N */
396 /*           C */
397 /*           C     Load a PCK file containing a triaxial */
398 /*           C     ellipsoidal shape model and orientation */
399 /*           C     data for Mars. */
400 /*           C */
401 /*                 CALL FURNSH ( 'pck00008.tpc' ) */
402 
403 /*           C */
404 /*           C     Look up the radii for Mars.  Although we */
405 /*           C     omit it here, we could first call BADKPV */
406 /*           C     to make sure the variable BODY499_RADII */
407 /*           C     has three elements and numeric data type. */
408 /*           C     If the variable is not present in the kernel */
409 /*           C     pool, BODVRD will signal an error. */
410 /*           C */
411 /*                 CALL BODVRD ( 'MARS', 'RADII', 3, N, RADII ) */
412 
413 /*           C */
414 /*           C     Compute flattening coefficient. */
415 /*           C */
416 /*                 RE  =  RADII(1) */
417 /*                 RP  =  RADII(3) */
418 /*                 F   =  ( RE - RP ) / RE */
419 
420 /*           C */
421 /*           C     Do the conversion.  Note that we must provide */
422 /*           C     longitude and latitude in radians. */
423 /*           C */
424 /*                 LON =  90.D0 * RPD() */
425 /*                 LAT =  45.D0 * RPD() */
426 /*                 ALT =   3.D2 */
427 
428 /*                 CALL PGRREC ( 'MARS', LON, LAT, ALT, RE, F, RECTAN ) */
429 
430 /*                 WRITE (*,*) ' ' */
431 /*                 WRITE (*,*) 'Planetographic coordinates:' */
432 /*                 WRITE (*,*) ' ' */
433 /*                 WRITE (*,*) '  Longitude (deg)        = ', LON / RPD() */
434 /*                 WRITE (*,*) '  Latitude  (deg)        = ', LAT / RPD() */
435 /*                 WRITE (*,*) '  Altitude  (km)         = ', ALT */
436 /*                 WRITE (*,*) ' ' */
437 /*                 WRITE (*,*) 'Ellipsoid shape parameters: ' */
438 /*                 WRITE (*,*) ' ' */
439 /*                 WRITE (*,*) '  Equatorial radius (km) = ', RE */
440 /*                 WRITE (*,*) '  Polar radius      (km) = ', RP */
441 /*                 WRITE (*,*) '  Flattening coefficient = ', F */
442 /*                 WRITE (*,*) ' ' */
443 /*                 WRITE (*,*) 'Rectangular coordinates:' */
444 /*                 WRITE (*,*) ' ' */
445 /*                 WRITE (*,*) '  X (km)                 = ', RECTAN(1) */
446 /*                 WRITE (*,*) '  Y (km)                 = ', RECTAN(2) */
447 /*                 WRITE (*,*) '  Z (km)                 = ', RECTAN(3) */
448 /*                 WRITE (*,*) ' ' */
449 
450 /*                 END */
451 
452 
453 /*        Output from this program should be similar to the following */
454 /*        (rounding and formatting differ across platforms): */
455 
456 /*           Planetographic coordinates: */
457 
458 /*             Longitude (deg)        =   90. */
459 /*             Latitude  (deg)        =   45. */
460 /*             Altitude  (km)         =   300. */
461 
462 /*           Ellipsoid shape parameters: */
463 
464 /*             Equatorial radius (km) =   3396.19 */
465 /*             Polar radius      (km) =   3376.2 */
466 /*             Flattening coefficient =   0.00588600756 */
467 
468 /*           Rectangular coordinates: */
469 
470 /*             X (km)                 =   1.60465003E-13 */
471 /*             Y (km)                 =  -2620.67891 */
472 /*             Z (km)                 =   2592.40891 */
473 
474 
475 /*     2) Below is a table showing a variety of rectangular coordinates */
476 /*        and the corresponding Mars planetographic coordinates.  The */
477 /*        values are computed using the reference spheroid having radii */
478 
479 /*           Equatorial radius:    3397 */
480 /*           Polar radius:         3375 */
481 
482 /*        Note:  the values shown above may not be current or suitable */
483 /*               for your application. */
484 
485 
486 /*        Corresponding rectangular and planetographic coordinates are */
487 /*        listed to three decimal places. */
488 
489 
490 /*    RECTAN(1)    RECTAN(2)   RECTAN(3)    LON        LAT         ALT */
491 /*    ------------------------------------------------------------------ */
492 /*     3397.000      0.000      0.000       0.000      0.000       0.000 */
493 /*    -3397.000      0.000      0.000     180.000      0.000       0.000 */
494 /*    -3407.000      0.000      0.000     180.000      0.000      10.000 */
495 /*    -3387.000      0.000      0.000     180.000      0.000     -10.000 */
496 /*        0.000  -3397.000      0.000      90.000      0.000       0.000 */
497 /*        0.000   3397.000      0.000     270.000      0.000       0.000 */
498 /*        0.000      0.000   3375.000       0.000     90.000       0.000 */
499 /*        0.000      0.000  -3375.000       0.000    -90.000       0.000 */
500 /*        0.000      0.000      0.000       0.000     90.000   -3375.000 */
501 
502 
503 
504 /*     3)  Below we show the analogous relationships for the earth, */
505 /*         using the reference ellipsoid radii */
506 
507 /*            Equatorial radius:    6378.140 */
508 /*            Polar radius:         6356.750 */
509 
510 /*         Note the change in longitudes for points on the +/- Y axis */
511 /*         for the earth vs the Mars values. */
512 
513 
514 /*    RECTAN(1)    RECTAN(2)   RECTAN(3)    LON        LAT         ALT */
515 /*    ------------------------------------------------------------------ */
516 /*     6378.140      0.000      0.000       0.000      0.000       0.000 */
517 /*    -6378.140      0.000      0.000     180.000      0.000       0.000 */
518 /*    -6388.140      0.000      0.000     180.000      0.000      10.000 */
519 /*    -6368.140      0.000      0.000     180.000      0.000     -10.000 */
520 /*        0.000  -6378.140      0.000     270.000      0.000       0.000 */
521 /*        0.000   6378.140      0.000      90.000      0.000       0.000 */
522 /*        0.000      0.000   6356.750       0.000     90.000       0.000 */
523 /*        0.000      0.000  -6356.750       0.000    -90.000       0.000 */
524 /*        0.000      0.000      0.000       0.000     90.000   -6356.750 */
525 
526 
527 /* $ Restrictions */
528 
529 /*     None. */
530 
531 /* $ Literature_References */
532 
533 /*     None. */
534 
535 /* $ Author_and_Institution */
536 
537 /*     C.H. Acton      (JPL) */
538 /*     N.J. Bachman    (JPL) */
539 /*     H.A. Neilan     (JPL) */
540 /*     B.V. Semenov    (JPL) */
541 /*     W.L. Taber      (JPL) */
542 
543 /* $ Version */
544 
545 /* -    SPICELIB Version 1.1.0, 21-SEP-2013 (BVS) */
546 
547 /*        Updated to save the input body name and ZZBODTRN state */
548 /*        counter and to do name-ID conversion only if the counter */
549 /*        has changed. */
550 
551 /*        Updated to call LJUCRS instead of CMPRSS/UCASE. */
552 
553 /* -    SPICELIB Version 1.0.0, 26-DEC-2004 (CHA) (NJB) (HAN) (BVS) (WLT) */
554 
555 /* -& */
556 /* $ Index_Entries */
557 
558 /*     convert planetographic to rectangular coordinates */
559 
560 /* -& */
561 
562 /*     SPICELIB functions */
563 
564 
565 /*     Local parameters */
566 
567 
568 /*     Saved body name length. */
569 
570 
571 /*     Local variables */
572 
573 
574 /*     Saved name/ID item declarations. */
575 
576 
577 /*     Saved name/ID items. */
578 
579 
580 /*     Initial values. */
581 
582 
583 /*     Standard SPICE error handling. */
584 
585     if (return_()) {
586 	return 0;
587     }
588     chkin_("PGRREC", (ftnlen)6);
589 
590 /*     Initialization. */
591 
592     if (first) {
593 
594 /*        Initialize counter. */
595 
596 	zzctruin_(svctr1);
597 	first = FALSE_;
598     }
599 
600 /*     Convert the body name to an ID code. */
601 
602     zzbods2c_(svctr1, svbody, &svbdid, &svfnd1, body, &bodyid, &found, (
603 	    ftnlen)36, body_len);
604     if (! found) {
605 	setmsg_("The value of the input argument BODY is #, this is not a re"
606 		"cognized name of an ephemeris object. The cause of this prob"
607 		"lem may be that you need an updated version of the SPICE Too"
608 		"lkit. ", (ftnlen)185);
609 	errch_("#", body, (ftnlen)1, body_len);
610 	sigerr_("SPICE(IDCODENOTFOUND)", (ftnlen)21);
611 	chkout_("PGRREC", (ftnlen)6);
612 	return 0;
613     }
614 
615 /*     The equatorial radius must be positive. If not, signal an error */
616 /*     and check out. */
617 
618     if (*re <= 0.) {
619 	setmsg_("Equatorial radius was #.", (ftnlen)24);
620 	errdp_("#", re, (ftnlen)1);
621 	sigerr_("SPICE(VALUEOUTOFRANGE)", (ftnlen)22);
622 	chkout_("PGRREC", (ftnlen)6);
623 	return 0;
624     }
625 
626 /*     If the flattening coefficient is greater than 1, the polar radius */
627 /*     is negative. If F is equal to 1, the polar radius is zero. Either */
628 /*     case is a problem, so signal an error and check out. */
629 
630     if (*f >= 1.) {
631 	setmsg_("Flattening coefficient was #.", (ftnlen)29);
632 	errdp_("#", f, (ftnlen)1);
633 	sigerr_("SPICE(VALUEOUTOFRANGE)", (ftnlen)22);
634 	chkout_("PGRREC", (ftnlen)6);
635 	return 0;
636     }
637 
638 /*     Look up the longitude sense override variable from the */
639 /*     kernel pool. */
640 
641     repmi_("BODY#_PGR_POSITIVE_LON", "#", &bodyid, pmkvar, (ftnlen)22, (
642 	    ftnlen)1, (ftnlen)32);
643     gcpool_(pmkvar, &c__1, &c__1, &n, kvalue, &found, (ftnlen)32, (ftnlen)80);
644     if (found) {
645 
646 /*        Make sure we recognize the value of PGRLON. */
647 
648 	ljucrs_(&c__0, kvalue, pgrlon, (ftnlen)80, (ftnlen)4);
649 	if (s_cmp(pgrlon, "EAST", (ftnlen)4, (ftnlen)4) == 0) {
650 	    sense = 1;
651 	} else if (s_cmp(pgrlon, "WEST", (ftnlen)4, (ftnlen)4) == 0) {
652 	    sense = -1;
653 	} else {
654 	    setmsg_("Kernel variable # may have the values EAST or WEST.  Ac"
655 		    "tual value was #.", (ftnlen)72);
656 	    errch_("#", pmkvar, (ftnlen)1, (ftnlen)32);
657 	    errch_("#", kvalue, (ftnlen)1, (ftnlen)80);
658 	    sigerr_("SPICE(INVALIDOPTION)", (ftnlen)20);
659 	    chkout_("PGRREC", (ftnlen)6);
660 	    return 0;
661 	}
662     } else {
663 
664 /*        Look up the spin sense of the body's prime meridian. */
665 
666 	sense = plnsns_(&bodyid);
667 
668 /*        If the required prime meridian rate was not available, */
669 /*        PLNSNS returns the code 0.  Here we consider this situation */
670 /*        to be an error. */
671 
672 	if (sense == 0) {
673 	    repmi_("BODY#_PM", "#", &bodyid, pmkvar, (ftnlen)8, (ftnlen)1, (
674 		    ftnlen)32);
675 	    setmsg_("Prime meridian rate coefficient defined by kernel varia"
676 		    "ble # is required but not available for body #. ", (
677 		    ftnlen)103);
678 	    errch_("#", pmkvar, (ftnlen)1, (ftnlen)32);
679 	    errch_("#", body, (ftnlen)1, body_len);
680 	    sigerr_("SPICE(MISSINGDATA)", (ftnlen)18);
681 	    chkout_("PGRREC", (ftnlen)6);
682 	    return 0;
683 	}
684 
685 /*        Handle the special cases:  earth, moon, and sun. */
686 
687 	if (bodyid == 399 || bodyid == 301 || bodyid == 10) {
688 	    sense = 1;
689 	}
690     }
691 
692 /*     At this point, SENSE is set to +/- 1. */
693 
694 /*     Adjust the longitude according to the sense of the body's */
695 /*     spin, or according to the override value if one is provided. */
696 /*     We want positive east longitude. */
697 
698     geolon = sense * *lon;
699 
700 /*     Now that we have geodetic longitude in hand, convert the geodetic */
701 /*     equivalent of the input coordinates to rectangular coordinates. */
702 
703     georec_(&geolon, lat, alt, re, f, rectan);
704     chkout_("PGRREC", (ftnlen)6);
705     return 0;
706 } /* pgrrec_ */
707 
708