1 /* convrt.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__31 = 31;
11 static integer c__5 = 5;
12 static integer c__3 = 3;
13 static integer c__9 = 9;
14 
15 /* $Procedure      CONVRT ( Convert Units ) */
convrt_(doublereal * x,char * in,char * out,doublereal * y,ftnlen in_len,ftnlen out_len)16 /* Subroutine */ int convrt_(doublereal *x, char *in, char *out, doublereal *
17 	y, ftnlen in_len, ftnlen out_len)
18 {
19     /* Initialized data */
20 
21     static logical first = TRUE_;
22     static char units[16*31] = "RADIANS         " "DEGREES         " "ARCMIN"
23 	    "UTES      " "ARCSECONDS      " "HOURANGLE       " "MINUTEANGLE  "
24 	    "   " "SECONDANGLE     " "METERS          " "KM              "
25 	    "CM              " "MM              " "LIGHTSECS       " "AU    "
26 	    "          " "M               " "KILOMETERS      " "CENTIMETERS  "
27 	    "   " "MILLIMETERS     " "FEET            " "INCHES          "
28 	    "STATUTE_MILES   " "NAUTICAL_MILES  " "YARDS           " "LIGHTY"
29 	    "EARS      " "PARSECS         " "SECONDS         " "MINUTES      "
30 	    "   " "HOURS           " "DAYS            " "JULIAN_YEARS    "
31 	    "TROPICAL_YEARS  " "YEARS           ";
32     static doublereal cnvrtn[31] = { 0.0,1.,.016666666666666666,
33 	    2.7777777777777778e-4,15.,.25,.0041666666666666666,1.,1e3,.01,
34 	    .001,299792458.,149597870613.68887,1.,1e3,.01,.001,.3048,.0254,
35 	    1609.344,1852.,.9144,9460730472580800.,30856775797231604.,1.,60.,
36 	    3600.,86400.,31557600.,31556925.976319999,31557600. };
37     static char type__[8*31] = "ANGLE   " "ANGLE   " "ANGLE   " "ANGLE   "
38 	    "ANGLE   " "ANGLE   " "ANGLE   " "DISTANCE" "DISTANCE" "DISTANCE"
39 	    "DISTANCE" "DISTANCE" "DISTANCE" "DISTANCE" "DISTANCE" "DISTANCE"
40 	    "DISTANCE" "DISTANCE" "DISTANCE" "DISTANCE" "DISTANCE" "DISTANCE"
41 	    "DISTANCE" "DISTANCE" "TIME    " "TIME    " "TIME    " "TIME    "
42 	    "TIME    " "TIME    " "TIME    ";
43 
44     /* System generated locals */
45     address a__1[5], a__2[3], a__3[9];
46     integer i__1[5], i__2[3], i__3, i__4, i__5[9];
47     char ch__1[101], ch__2[56], ch__3[57], ch__4[123];
48 
49     /* Builtin functions */
50     /* Subroutine */ int s_cat(char *, char **, integer *, integer *, ftnlen);
51     integer s_rnge(char *, integer, char *, integer), s_cmp(char *, char *,
52 	    ftnlen, ftnlen);
53 
54     /* Local variables */
55     doublereal temp;
56     char outu[16];
57     integer i__, j;
58     extern /* Subroutine */ int chkin_(char *, ftnlen), ucase_(char *, char *,
59 	     ftnlen, ftnlen);
60     extern integer isrchc_(char *, integer *, char *, ftnlen, ftnlen);
61     extern /* Subroutine */ int sigerr_(char *, ftnlen), chkout_(char *,
62 	    ftnlen), setmsg_(char *, ftnlen);
63     extern logical return_(void);
64     extern doublereal dpr_(void);
65     char inu[16];
66 
67 /* $ Abstract */
68 
69 /*      Take a measurement X, the units associated with */
70 /*      X, and units to which X should be converted; return Y --- */
71 /*      the value of the measurement in the output units. */
72 
73 /* $ Disclaimer */
74 
75 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
76 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
77 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
78 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
79 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
80 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
81 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
82 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
83 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
84 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
85 
86 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
87 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
88 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
89 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
90 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
91 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
92 
93 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
94 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
95 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
96 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
97 
98 /* $ Required_Reading */
99 
100 /*     None. */
101 
102 /* $ Keywords */
103 
104 /*     CONVERSION, UNITS */
105 
106 /* $ Declarations */
107 /* $ Brief_I/O */
108 
109 /*     VARIABLE  I/O  DESCRIPTION */
110 /*     --------  ---  ------------------------------------------------- */
111 /*     X          I   Number representing a measurement in some units. */
112 /*     IN         I   The units in which X is measured. */
113 /*     OUT        I   Desired units for the measurement. */
114 /*     Y          O   The measurement in the desired units. */
115 
116 /* $ Detailed_Input */
117 
118 /*     X          is a number representing a measurement in the units */
119 /*                specified by IN. */
120 
121 /*     IN         represents the units associated with a measurement X. */
122 /*                Acceptable units are: */
123 
124 /*                Angles:                 'RADIANS' */
125 /*                                        'DEGREES' */
126 /*                                        'ARCMINUTES' */
127 /*                                        'ARCSECONDS' */
128 /*                                        'HOURANGLE' */
129 /*                                        'MINUTEANGLE' */
130 /*                                        'SECONDANGLE' */
131 
132 /*                Metric Distances:       'M' */
133 /*                                        'METERS' */
134 /*                                        'KM' */
135 /*                                        'KILOMETERS' */
136 /*                                        'CM' */
137 /*                                        'CENTIMETERS' */
138 /*                                        'MM' */
139 /*                                        'MILLIMETERS' */
140 
141 /*                English Distances:      'FEET' */
142 /*                                        'INCHES' */
143 /*                                        'YARDS' */
144 /*                                        'STATUTE_MILES' */
145 /*                                        'NAUTICAL_MILES' */
146 
147 /*                Astrometric Distances:  'AU' */
148 /*                                        'PARSECS' */
149 /*                                        'LIGHTSECS' */
150 /*                                        'LIGHTYEARS' julian lightyears */
151 
152 /*                Time:                   'SECONDS' */
153 /*                                        'MINUTES' */
154 /*                                        'HOURS' */
155 /*                                        'DAYS' */
156 /*                                        'JULIAN_YEARS' */
157 /*                                        'TROPICAL_YEARS' */
158 /*                                        'YEARS' (same as julian years) */
159 
160 /*     OUT        represents the units desired for the measurement X. */
161 /*                See the description of IN. */
162 
163 /* $ Detailed_Output */
164 
165 /*     Y          is the input measurement converted to the desired */
166 /*                units. */
167 
168 
169 /* $ Parameters */
170 
171 /*     None. */
172 
173 /* $ Exceptions */
174 
175 /*     1) If the input units, output units, or both input and */
176 /*        output units are not recognized, the error */
177 /*        SPICE(UNITSNOTREC) is signaled. */
178 
179 /*     2) If the units being converted between are incompatible, the */
180 /*        error SPICE(INCOMPATIBLEUNITS) is signaled. */
181 
182 /* $ Files */
183 
184 /*     None. */
185 
186 /* $ Particulars */
187 
188 /*     This routine converts a measurement X given in units specified by */
189 /*     IN to the equivalent value Y in units specified by OUT. */
190 
191 /*     If a unit is not recognized, an error message is produced that */
192 /*     indicates which one was not recognized. */
193 
194 /*     If input and output units are incompatible (for example ANGLE */
195 /*     and DISTANCE units) and error message will be produced stating */
196 /*     the requested units and associated types. */
197 
198 /* $ Examples */
199 
200 /*     To convert 1 meter to statute miles and feet you could */
201 
202 /*        CALL CONVRT ( 1.0D0, 'METERS',        'STATUTE_MILES', MILES ) */
203 /*        CALL CONVRT ( MILES, 'STATUTE_MILES', 'FEET',          FEET  ) */
204 
205 /*     or */
206 
207 /*        CALL CONVRT ( 1.0D0, 'METERS', 'STATUTE_MILES', MILES ) */
208 /*        CALL CONVRT ( 1.0D0, 'METERS', 'FEET',          FEET  ) */
209 
210 
211 /* $ Restrictions */
212 
213 /*     You should make sure that your units are appropriate for the */
214 /*     measurement. This routine does not do any checking for over- */
215 /*     flow. Something like */
216 
217 /*        CALL ( 10.0D22, 'LIGHTYEARS', 'MM', Y ) */
218 
219 /*     will cause a floating point overflow. */
220 
221 /*     Some of the units are not "defined" quantities.  In such a case */
222 /*     a best estimate is provided as of the date of the current version */
223 /*     of this routine. Those estimated quantities are: */
224 
225 /*         1 AU    --- the astronomical unit. The value was taken from */
226 /*                     the JPL ephemeris DE125. This value is an */
227 /*                     approximation and should not be used for */
228 /*                     high-accuracy work. It agrees with the value used */
229 /*                     in the JPL planetary ephemeris DE430 */
230 /*                     (149597870.700 km) at the 100m level. */
231 
232 /*         The tropical year is the time from equinox to equinox.  This */
233 /*         varies slightly with time. */
234 
235 /*         1 PARSEC --- is dependent upon the value of the astronomical */
236 /*                      unit. */
237 
238 /* $ Literature_References */
239 
240 /*     None. */
241 
242 /* $ Author_and_Institution */
243 
244 /*     N.J. Bachman    (JPL) */
245 /*     C.A. Curzon     (JPL) */
246 /*     H.A. Neilan     (JPL) */
247 /*     W.M. Owen       (JPL) */
248 /*     W.L. Taber      (JPL) */
249 /*     I.M. Underwood  (JPL) */
250 
251 /* $ Version */
252 
253 /* -    SPICELIB Version 2.0.0, 12-MAY-2015 (NJB) */
254 
255 /*        Added support for full names of metric distance units. Added */
256 /*        support for the abbreviation 'M' indicating meters. */
257 
258 /* -    SPICELIB Version 1.0.2, 01-JUL-2014 (NJB) */
259 
260 /*        Updated the description of the AU in the Restrictions */
261 /*        section. */
262 
263 /* -    SPICELIB Version 1.0.1, 10-MAR-1992 (WLT) */
264 
265 /*        Comment section for permuted index source lines was added */
266 /*        following the header. */
267 
268 /* -    SPICELIB Version 1.0.0, 31-JAN-1990 (CAC) (WMO) (WLT) (IMU) */
269 
270 /* -& */
271 /* $ Index_Entries */
272 
273 /*     convert units */
274 
275 /* -& */
276 /* $ Revisions */
277 
278 /* -    Beta Version 1.2.0, 05-JAN-1990 (WLT) */
279 
280 /*        Data statements for double precision values were changed */
281 /*        to include a 'D' so that this routine would function properly */
282 /*        on the Univac. */
283 
284 /* -   Beta Version 1.1.0, 02-MAR-1989 (HAN) */
285 
286 /*        The variable LIGHTYEAR was changed to LTYEAR in order to */
287 /*        comply with the ANSI Fortran Standard six character */
288 /*        variable name length restriction. */
289 
290 /* -& */
291 
292 /*     SPICELIB functions */
293 
294 
295 /*     Local variables */
296 
297 
298 /*     1.0d0 divided by the sin of 1 arc second */
299 
300 
301 /*     Angular Conversions: */
302 
303 /*                 (1)  Degrees/Radians */
304 /*                 (2)  Degrees/Degrees */
305 /*                 (3)  Degrees/ARCMINUTES */
306 /*                 (4)  Degrees/ARCSECONDS */
307 
308 /*                 ()   Degrees/HOURANGLE */
309 /*                 ()   Degrees/MINUTEANGLE */
310 /*                 ()   Degrees/SECONDANGLE */
311 
312 
313 /*     DATA CNVRTN (ANG + 1)  /      DPR()   / */
314 
315 /*     This value will be loaded using the SPICELIB function DPR() */
316 /*     on the first execution of this routine. */
317 
318 
319 /*     Distance Conversions ( 8 through 17 ) */
320 
321 /*                 (+  1) Meters/Meter */
322 /*                 (+  2) Meters/Km */
323 /*                 (+  3) Meters/Cm */
324 /*                 (+  4) Meters/mm */
325 /*                 (+  5) Meters/Lightsecs */
326 /*                 (+  6) Meters/AU */
327 /*                 (+  7) Meters/Meter */
328 /*                 (+  8) Meters/Km */
329 /*                 (+  9) Meters/cm */
330 /*                 (+ 10) Meters/mm */
331 
332 
333 /*     Distance Conversions */
334 
335 /*                 (+ 11) Meters/Foot */
336 /*                 (+ 12) Meters/inch */
337 /*                 (+ 13) Meters/Statute Mile */
338 /*                 (+ 14) Meters/Nautical Mile */
339 /*                 (+ 15) Meters/Yard */
340 
341 
342 /*     Distance Conversions */
343 
344 /*                 (+ 16) Meters/LightYear */
345 /*                 (+ 17) Meters/Parsec */
346 
347 
348 /*     Time Conversions */
349 
350 /*                 (+ 1 ) seconds / second */
351 /*                 (+ 2 ) seconds / minute */
352 /*                 (+ 3 ) seconds / hour */
353 /*                 (+ 4 ) seconds / day */
354 /*                 (+ 5 ) Seconds / Julian year */
355 /*                 (+ 6 ) Seconds / Tropical year */
356 /*                 (+ 7 ) Seconds / year          --- same as Julian year */
357 
358 
359 /*     Set up the error processing. */
360 
361     if (return_()) {
362 	return 0;
363     }
364     chkin_("CONVRT", (ftnlen)6);
365     if (first) {
366 	cnvrtn[0] = dpr_();
367 	first = FALSE_;
368     }
369     ucase_(in, inu, in_len, (ftnlen)16);
370     ucase_(out, outu, out_len, (ftnlen)16);
371     i__ = isrchc_(inu, &c__31, units, (ftnlen)16, (ftnlen)16);
372     j = isrchc_(outu, &c__31, units, (ftnlen)16, (ftnlen)16);
373     if (i__ == 0 || j == 0) {
374 	if (i__ == 0 && j == 0) {
375 /* Writing concatenation */
376 	    i__1[0] = 32, a__1[0] = "CONVRT: Neither the input units ";
377 	    i__1[1] = 16, a__1[1] = inu;
378 	    i__1[2] = 21, a__1[2] = "nor the output units ";
379 	    i__1[3] = 16, a__1[3] = outu;
380 	    i__1[4] = 16, a__1[4] = "were recognized.";
381 	    s_cat(ch__1, a__1, i__1, &c__5, (ftnlen)101);
382 	    setmsg_(ch__1, (ftnlen)101);
383 	    sigerr_("SPICE(UNITSNOTREC)", (ftnlen)18);
384 	    chkout_("CONVRT", (ftnlen)6);
385 	    return 0;
386 	} else if (i__ == 0) {
387 /* Writing concatenation */
388 	    i__2[0] = 20, a__2[0] = "CONVRT: Input units ";
389 	    i__2[1] = 16, a__2[1] = inu;
390 	    i__2[2] = 20, a__2[2] = " were not recognized";
391 	    s_cat(ch__2, a__2, i__2, &c__3, (ftnlen)56);
392 	    setmsg_(ch__2, (ftnlen)56);
393 	    sigerr_("SPICE(UNITSNOTREC)", (ftnlen)18);
394 	    chkout_("CONVRT", (ftnlen)6);
395 	    return 0;
396 	} else if (j == 0) {
397 /* Writing concatenation */
398 	    i__2[0] = 21, a__2[0] = "CONVRT: Output units ";
399 	    i__2[1] = 16, a__2[1] = outu;
400 	    i__2[2] = 20, a__2[2] = " were not recognized";
401 	    s_cat(ch__3, a__2, i__2, &c__3, (ftnlen)57);
402 	    setmsg_(ch__3, (ftnlen)57);
403 	    sigerr_("SPICE(UNITSNOTREC)", (ftnlen)18);
404 	    chkout_("CONVRT", (ftnlen)6);
405 	    return 0;
406 	}
407     }
408     if (s_cmp(type__ + (((i__3 = i__ - 1) < 31 && 0 <= i__3 ? i__3 : s_rnge(
409 	    "type", i__3, "convrt_", (ftnlen)547)) << 3), type__ + (((i__4 =
410 	    j - 1) < 31 && 0 <= i__4 ? i__4 : s_rnge("type", i__4, "convrt_",
411 	    (ftnlen)547)) << 3), (ftnlen)8, (ftnlen)8) != 0) {
412 /* Writing concatenation */
413 	i__5[0] = 58, a__3[0] = "CONVRT: Incompatible units. You are attempt"
414 		"ing to convert ";
415 	i__5[1] = 16, a__3[1] = inu;
416 	i__5[2] = 6, a__3[2] = "type: ";
417 	i__5[3] = 8, a__3[3] = type__ + (((i__3 = i__ - 1) < 31 && 0 <= i__3 ?
418 		 i__3 : s_rnge("type", i__3, "convrt_", (ftnlen)549)) << 3);
419 	i__5[4] = 4, a__3[4] = " to ";
420 	i__5[5] = 16, a__3[5] = outu;
421 	i__5[6] = 6, a__3[6] = "type: ";
422 	i__5[7] = 8, a__3[7] = type__ + (((i__4 = j - 1) < 31 && 0 <= i__4 ?
423 		i__4 : s_rnge("type", i__4, "convrt_", (ftnlen)549)) << 3);
424 	i__5[8] = 1, a__3[8] = ".";
425 	s_cat(ch__4, a__3, i__5, &c__9, (ftnlen)123);
426 	setmsg_(ch__4, (ftnlen)123);
427 	sigerr_("SPICE(INCOMPATIBLEUNITS)", (ftnlen)24);
428 	chkout_("CONVRT", (ftnlen)6);
429 	return 0;
430     }
431     temp = *x * cnvrtn[(i__3 = i__ - 1) < 31 && 0 <= i__3 ? i__3 : s_rnge(
432 	    "cnvrtn", i__3, "convrt_", (ftnlen)565)];
433     *y = temp / cnvrtn[(i__3 = j - 1) < 31 && 0 <= i__3 ? i__3 : s_rnge("cnv"
434 	    "rtn", i__3, "convrt_", (ftnlen)566)];
435     chkout_("CONVRT", (ftnlen)6);
436     return 0;
437 } /* convrt_ */
438 
439