1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
/// Latitudinal to cylindrical coordinates
///
/// Convert from latitudinal coordinates to cylindrical coordinates.
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// RADIUS I Distance of a point from the origin.
/// LON I Angle of the point from the XZ plane in radians.
/// LAT I Angle of the point from the XY plane in radians.
/// R O Distance of the point from the Z axis.
/// CLON O Angle of the point from the XZ plane in radians.
/// Z O Height of the point above the XY plane.
/// ```
///
/// # Detailed Input
///
/// ```text
/// RADIUS is the distance of a point from the origin.
///
/// LON is the angle of the point from the XZ plane in
/// radians.
///
/// LAT is the angle of the point from the XY plane in
/// radians.
/// ```
///
/// # Detailed Output
///
/// ```text
/// R is the distance of the point from the Z-axis.
///
/// CLON is the angle of the point from the XZ plane in
/// radians. CLON is set equal to LON.
///
/// Z is the height of the point above the XY plane.
/// ```
///
/// # Exceptions
///
/// ```text
/// Error free.
/// ```
///
/// # Particulars
///
/// ```text
/// This routine returns the cylindrical coordinates of a point
/// whose position is input in latitudinal coordinates.
///
/// Latitudinal coordinates are defined by a distance from a central
/// reference point, an angle from a reference meridian, and an angle
/// above the equator of a sphere centered at the central reference
/// point.
/// ```
///
/// # Examples
///
/// ```text
/// The numerical results shown for these examples may differ across
/// platforms. The results depend on the SPICE kernels used as
/// input, the compiler and supporting libraries, and the machine
/// specific arithmetic implementation.
///
/// 1) Compute the latitudinal coordinates of the position of the Moon
/// as seen from the Earth, and convert them to cylindrical and
/// rectangular coordinates.
///
/// Use the meta-kernel shown below to load the required SPICE
/// kernels.
///
///
/// KPL/MK
///
/// File name: latcyl_ex1.tm
///
/// This meta-kernel is intended to support operation of SPICE
/// example programs. The kernels shown here should not be
/// assumed to contain adequate or correct versions of data
/// required by SPICE-based user applications.
///
/// In order for an application to use this meta-kernel, the
/// kernels referenced here must be present in the user's
/// current working directory.
///
/// The names and contents of the kernels referenced
/// by this meta-kernel are as follows:
///
/// File name Contents
/// --------- --------
/// de421.bsp Planetary ephemeris
/// naif0012.tls Leapseconds
///
///
/// \begindata
///
/// KERNELS_TO_LOAD = ( 'de421.bsp',
/// 'naif0012.tls' )
///
/// \begintext
///
/// End of meta-kernel
///
///
/// Example code begins here.
///
///
/// PROGRAM LATCYL_EX1
/// IMPLICIT NONE
///
/// C
/// C SPICELIB functions
/// C
/// DOUBLE PRECISION DPR
///
/// C
/// C Local parameters
/// C
/// CHARACTER*(*) FMT1
/// PARAMETER ( FMT1 = '(A,F20.8)' )
///
/// C
/// C Local variables
/// C
/// DOUBLE PRECISION CLON
/// DOUBLE PRECISION ET
/// DOUBLE PRECISION LAT
/// DOUBLE PRECISION LON
/// DOUBLE PRECISION LT
/// DOUBLE PRECISION POS ( 3 )
/// DOUBLE PRECISION RADIUS
/// DOUBLE PRECISION RECTAN ( 3 )
/// DOUBLE PRECISION R
/// DOUBLE PRECISION Z
///
/// C
/// C Load SPK and LSK kernels, use a meta kernel for
/// C convenience.
/// C
/// CALL FURNSH ( 'latcyl_ex1.tm' )
///
/// C
/// C Look up the geometric state of the Moon as seen from
/// C the Earth at 2017 Mar 20, relative to the J2000
/// C reference frame.
/// C
/// CALL STR2ET ( '2017 Mar 20', ET )
///
/// CALL SPKPOS ( 'Moon', ET, 'J2000', 'NONE',
/// . 'Earth', POS, LT )
///
/// C
/// C Convert the position vector POS to latitudinal
/// C coordinates.
/// C
/// CALL RECLAT ( POS, RADIUS, LON, LAT )
///
/// C
/// C Convert the latitudinal coordinates to cylindrical.
/// C
/// CALL LATCYL ( RADIUS, LON, LAT, R, CLON, Z )
///
/// C
/// C Convert the cylindrical coordinates to rectangular.
/// C
/// CALL CYLREC ( R, CLON, Z, RECTAN )
///
///
/// WRITE(*,*) ' '
/// WRITE(*,*) 'Original rectangular coordinates:'
/// WRITE(*,*) ' '
/// WRITE(*,FMT1) ' X (km): ', POS(1)
/// WRITE(*,FMT1) ' Y (km): ', POS(2)
/// WRITE(*,FMT1) ' Z (km): ', POS(3)
/// WRITE(*,*) ' '
/// WRITE(*,*) 'Latitudinal coordinates:'
/// WRITE(*,*) ' '
/// WRITE(*,FMT1) ' Radius (km): ', RADIUS
/// WRITE(*,FMT1) ' Longitude (deg): ', LON*DPR()
/// WRITE(*,FMT1) ' Latitude (deg): ', LAT*DPR()
/// WRITE(*,*) ' '
/// WRITE(*,*) 'Cylindrical coordinates:'
/// WRITE(*,*) ' '
/// WRITE(*,FMT1) ' Radius (km): ', R
/// WRITE(*,FMT1) ' Longitude (deg): ', CLON*DPR()
/// WRITE(*,FMT1) ' Z (km): ', Z
/// WRITE(*,*) ' '
/// WRITE(*,*) 'Rectangular coordinates from CYLREC:'
/// WRITE(*,*) ' '
/// WRITE(*,FMT1) ' X (km): ', RECTAN(1)
/// WRITE(*,FMT1) ' Y (km): ', RECTAN(2)
/// WRITE(*,FMT1) ' Z (km): ', RECTAN(3)
/// WRITE(*,*) ' '
///
/// END
///
///
/// When this program was executed on a Mac/Intel/gfortran/64-bit
/// platform, the output was:
///
///
/// Original rectangular coordinates:
///
/// X (km): -55658.44323296
/// Y (km): -379226.32931475
/// Z (km): -126505.93063865
///
/// Latitudinal coordinates:
///
/// Radius (km): 403626.33912495
/// Longitude (deg): -98.34959789
/// Latitude (deg): -18.26566077
///
/// Cylindrical coordinates:
///
/// Radius (km): 383289.01777726
/// Longitude (deg): -98.34959789
/// Z (km): -126505.93063865
///
/// Rectangular coordinates from CYLREC:
///
/// X (km): -55658.44323296
/// Y (km): -379226.32931475
/// Z (km): -126505.93063865
///
///
/// 2) Create a table showing a variety of latitudinal coordinates
/// and the corresponding cylindrical coordinates.
///
/// Corresponding latitudinal and cylindrical coordinates are
/// listed to three decimal places. Input and output angles are
/// in degrees.
///
///
/// Example code begins here.
///
///
/// PROGRAM LATCYL_EX2
/// IMPLICIT NONE
///
/// C
/// C SPICELIB functions
/// C
/// DOUBLE PRECISION DPR
/// DOUBLE PRECISION RPD
///
/// C
/// C Local parameters.
/// C
/// INTEGER NREC
/// PARAMETER ( NREC = 11 )
///
/// C
/// C Local variables.
/// C
/// DOUBLE PRECISION CLON
/// DOUBLE PRECISION LAT ( NREC )
/// DOUBLE PRECISION LON ( NREC )
/// DOUBLE PRECISION RADIUS ( NREC )
/// DOUBLE PRECISION R
/// DOUBLE PRECISION RLAT
/// DOUBLE PRECISION RLON
/// DOUBLE PRECISION Z
///
/// INTEGER I
///
/// C
/// C Define the input latitudinal coordinates. Angles in
/// C degrees.
/// C
///
/// DATA RADIUS / 0.D0, 1.D0, 1.D0,
/// . 1.D0, 1.4142D0, 1.D0,
/// . 1.D0, 1.D0, 1.4142D0,
/// . 1.D0, 0.D0 /
///
/// DATA LON / 0.D0, 0.D0, 90.D0,
/// . 0.D0, 180.D0, -90.D0,
/// . 0.D0, 45.D0, 180.D0,
/// . 180.D0, 33.D0 /
///
/// DATA LAT / 90.D0, 0.D0, 0.D0,
/// . 90.D0, 45.D0, 0.D0,
/// . -90.D0, 0.D0, -45.D0,
/// . 90.D0, 0.D0 /
///
/// C
/// C Print the banner.
/// C
/// WRITE(*,*) ' RADIUS LON LAT '
/// . // ' R CLON Z '
/// WRITE(*,*) ' ------- ------- ------- '
/// . // ' ------- ------- ------- '
///
/// C
/// C Do the conversion. Output angles in degrees.
/// C
/// DO I = 1, NREC
///
/// RLON = LON(I) * RPD()
/// RLAT = LAT(I) * RPD()
///
/// CALL LATCYL( RADIUS(I), RLON, RLAT, R, CLON, Z )
///
/// WRITE (*,'(6F9.3)') RADIUS(I), LON(I), LAT(I),
/// . R, CLON * DPR(), Z
///
/// END DO
///
/// END
///
///
/// When this program was executed on a Mac/Intel/gfortran/64-bit
/// platform, the output was:
///
///
/// RADIUS LON LAT R CLON Z
/// ------- ------- ------- ------- ------- -------
/// 0.000 0.000 90.000 0.000 0.000 0.000
/// 1.000 0.000 0.000 1.000 0.000 0.000
/// 1.000 90.000 0.000 1.000 90.000 0.000
/// 1.000 0.000 90.000 0.000 0.000 1.000
/// 1.414 180.000 45.000 1.000 180.000 1.000
/// 1.000 -90.000 0.000 1.000 -90.000 0.000
/// 1.000 0.000 -90.000 0.000 0.000 -1.000
/// 1.000 45.000 0.000 1.000 45.000 0.000
/// 1.414 180.000 -45.000 1.000 180.000 -1.000
/// 1.000 180.000 90.000 0.000 180.000 1.000
/// 0.000 33.000 0.000 0.000 33.000 0.000
///
///
/// 3) Other than the obvious conversion between coordinate systems
/// this routine could be used to obtain the axial projection
/// from a sphere to a cylinder about the z-axis that contains
/// the equator of the sphere.
///
/// Such a projection is valuable because it preserves the
/// areas between regions on the sphere and their projections to
/// the cylinder.
///
///
/// Example code begins here.
///
///
/// PROGRAM LATCYL_EX3
/// IMPLICIT NONE
///
/// C
/// C SPICELIB functions
/// C
/// DOUBLE PRECISION DPR
/// DOUBLE PRECISION RPD
///
/// C
/// C Local parameters
/// C
/// CHARACTER*(*) FMT1
/// PARAMETER ( FMT1 = '(A,F23.11)' )
///
/// C
/// C Local variables
/// C
/// DOUBLE PRECISION CLON
/// DOUBLE PRECISION LAT
/// DOUBLE PRECISION LON
/// DOUBLE PRECISION RADIUS
/// DOUBLE PRECISION R
/// DOUBLE PRECISION Z
///
/// C
/// C Define the point whose projection is to be
/// C computed.
/// C
/// RADIUS = 100.D0
/// LON = 45.D0 * RPD()
/// LAT = -12.5D0 * RPD()
///
/// C
/// C Convert the latitudinal coordinates to cylindrical.
/// C
/// CALL LATCYL ( RADIUS, LON, LAT, R, CLON, Z )
///
/// WRITE(*,*) 'Coordinates of the projected point on '
/// . // 'cylinder:'
/// WRITE(*,*) ' '
/// WRITE(*,FMT1) ' Radius (km): ', R
/// WRITE(*,FMT1) ' Longitude (deg): ', CLON*DPR()
/// WRITE(*,FMT1) ' Z (km): ', Z
///
/// END
///
///
/// When this program was executed on a Mac/Intel/gfortran/64-bit
/// platform, the output was:
///
///
/// Coordinates of the projected point on cylinder:
///
/// Radius (km): 97.62960071199
/// Longitude (deg): 45.00000000000
/// Z (km): -21.64396139381
/// ```
///
/// # Author and Institution
///
/// ```text
/// J. Diaz del Rio (ODC Space)
/// B.V. Semenov (JPL)
/// W.L. Taber (JPL)
/// ```
///
/// # Version
///
/// ```text
/// - SPICELIB Version 1.1.0, 06-JUL-2021 (JDR)
///
/// Changed the argument names LONG and LONGC to LON and CLON for
/// consistency with other routines.
///
/// Added IMPLICIT NONE statement.
///
/// Edited the header to comply with NAIF standard. Removed
/// unnecessary $Revisions section.
///
/// Added complete code examples.
///
/// - SPICELIB Version 1.0.2, 26-JUL-2016 (BVS)
///
/// Minor headers edits.
///
/// - SPICELIB Version 1.0.1, 10-MAR-1992 (WLT)
///
/// Comment section for permuted index source lines was added
/// following the header.
///
/// - SPICELIB Version 1.0.0, 31-JAN-1990 (WLT)
/// ```
pub fn latcyl(radius: f64, lon: f64, lat: f64, r: &mut f64, clon: &mut f64, z: &mut f64) {
LATCYL(radius, lon, lat, r, clon, z);
}
//$Procedure LATCYL ( Latitudinal to cylindrical coordinates )
pub fn LATCYL(RADIUS: f64, LON: f64, LAT: f64, R: &mut f64, CLON: &mut f64, Z: &mut f64) {
let mut RH: f64 = 0.0;
let mut ZZ: f64 = 0.0;
//
// Local variables
//
//
// Convert to cylindrical, storing in temporary variables
//
RH = (RADIUS * f64::cos(LAT));
ZZ = (RADIUS * f64::sin(LAT));
//
// Move the results to output variables.
//
*CLON = LON;
*R = RH;
*Z = ZZ;
}