rsspice 0.1.0

Pure Rust port of the SPICE Toolkit for space geometry
Documentation
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
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
//
// GENERATED FILE
//

use super::*;
use crate::SpiceContext;
use f2rust_std::*;

/// Get the components from two-line elements
///
/// Parse the "lines" of a two-line element set, returning the
/// elements in units suitable for use in SPICE software.
///
/// # Brief I/O
///
/// ```text
///  VARIABLE  I/O  DESCRIPTION
///  --------  ---  --------------------------------------------------
///  FRSTYR     I   Year of earliest representable two-line elements.
///  LINES      I   A pair of "lines" containing two-line elements.
///  EPOCH      O   The epoch of the elements in seconds past J2000.
///  ELEMS      O   The elements converted to SPICE units.
/// ```
///
/// # Detailed Input
///
/// ```text
///  FRSTYR   is the first year possible for two-line elements.
///           Since two-line elements allow only two digits for
///           the year, some conventions must be followed concerning
///           which century the two digits refer to. FRSTYR
///           is the year of the earliest representable elements.
///           The two-digit year is mapped to the year in
///           the interval from FRSTYR to FRSTYR + 99 that
///           has the same last two digits as the two digit
///           year in the element set. For example if FRSTYR
///           is set to 1960  then the two digit years are mapped
///           as shown in the table below:
///
///              Two-line         Maps to
///              element year
///                 00            2000
///                 01            2001
///                 02            2002
///                  .              .
///                  .              .
///                  .              .
///                 58            2058
///                 59            2059
///                --------------------
///                 60            1960
///                 61            1961
///                 62            1962
///                  .              .
///                  .              .
///                  .              .
///                 99            1999
///
///           Note that if Space Command should decide to represent
///           years in 21st century as 100 + the last two digits
///           of the year (for example: 2015 is represented as 115)
///           instead of simply dropping the first two digits of
///           the year, this routine will correctly map the year
///           as long as you set FRSTYR to some value between 1900
///           and 1999.
///
///  LINES    is a pair of lines of text that comprise a Space
///           command "two-line element" set. These text lines
///           should be the same as they are presented in the
///           two-line element files available from Space Command
///           (formerly NORAD). See $Particulars for a detailed
///           description of the format.
/// ```
///
/// # Detailed Output
///
/// ```text
///  EPOCH    is the epoch of the two-line elements supplied via
///           the input array LINES. EPOCH is returned in TDB
///           seconds past J2000.
///
///  ELEMS    is an array containing the elements from the two-line
///           set supplied via the array LINES. The elements are
///           in units suitable for use by the SPICE routines
///           EV2LIN and SPKW10.
///
///           Also note that the elements XNDD6O and BSTAR
///           incorporate the exponential factor present in the
///           input two-line elements in LINES. (See $Particulars
///           below).
///
///              ELEMS (  1 ) = NDT20 in radians/minute**2
///              ELEMS (  2 ) = NDD60 in radians/minute**3
///              ELEMS (  3 ) = BSTAR
///              ELEMS (  4 ) = INCL  in radians
///              ELEMS (  5 ) = NODE0 in radians
///              ELEMS (  6 ) = ECC
///              ELEMS (  7 ) = OMEGA in radians
///              ELEMS (  8 ) = M0    in radians
///              ELEMS (  9 ) = N0    in radians/minute
///              ELEMS ( 10 ) = EPOCH of the elements in seconds
///                             past ephemeris epoch J2000.
/// ```
///
/// # Exceptions
///
/// ```text
///  1)  If an error occurs while trying to parse the two-line element
///      set, the error SPICE(BADTLE) is signaled and a description of
///      the detected issue in the "two-line element" set is reported
///      on the long error message.
/// ```
///
/// # Files
///
/// ```text
///  You must have loaded a SPICE leapseconds kernel into the
///  kernel pool prior to calling this routine.
/// ```
///
/// # Particulars
///
/// ```text
///     This routine parses a Space Command Two-line element set and
///     returns the orbital elements properly scaled and in units
///     suitable for use by other SPICE software. Input elements
///     are provided in two-lines in accordance with the format
///     required by the two-line element sets available from Space
///     Command (formerly NORAD). See [1] and [2] for details.
///
///     Each of these lines is 69 characters long. The following table
///     define each of the individual fields for lines 1 and 2.
///
///        Line  Column  Type  Description
///        ----  ------  ----  ------------------------------------------
///          1      01     N   Line number of Element Data (always 1)
///          1    03-07    N   Satellite number (NORAD catalog number)
///          1      08     A   Classification (U:Unclassified; S:Secret)
///          1    10-11    N   International designator (last two digits
///                            of launch year).
///          1    12-14    N   International designator (launch number of
///                            the year).
///          1    15-17    A   International designator (piece of the
///                            launch)
///          1    19-20    N   Epoch year (last two digits of year).
///          1    21-32    N   Epoch (day of the year and portion of the
///                            day)
///          1    34-43    N   NDT20: first time derivative of Mean
///                                   Motion
///          1    45-52    N   NDD60: Second time derivative of Mean
///                                   Motion (decimal point assumed)
///          1    54-61    N   BSTAR drag term (decimal point assumed)
///          1      63     N   Ephemeris type
///          1    65-68    N   Element number
///          1      69     N   Checksum.
///
///          2      01     N   Line number of Element Data (always 2)
///          2    03-07    N   Satellite number (must be the same as in
///                            line 1)
///          2    09-16    N   INCL: Inclination, in degrees
///          2    18-25    N   NODE0: Right Ascension of the Ascending
///                                   Node, in degrees
///          2    27-33    N   ECC: Eccentricity (decimal point assumed)
///          2    35-42    N   OMEGA: Argument of Perigee, in degrees
///          2    44-51    N   M0: Mean Anomaly, in degrees
///          2    53-63    N   N0: Mean Motion (revolutions per day)
///          2    64-68    N   Revolution number at epoch
///          2      69     N   Checksum
///
///     The column type A indicates "characters A-Z", the type N means
///     "numeric."
///
///     Column refers to the substring within the line, e.g.
///
///
///  1 22076U 92052A   97173.53461370 -.00000038  00000-0  10000-3 0   594
///  2 22076  66.0378 163.4372 0008359 278.7732  81.2337 12.80930736227550
///  ^
///  123456789012345678901234567890123456789012345678901234567890123456789
///           1         2         3         4         5         6
///
///
///        In this example, the satellite number (column 03-07) is 22076.
///
///
///     The "raw" elements used by this routine in the first lines are
///     described in detail below as in several instances exponents and
///     decimal points are implied. Note that the input units are
///     degrees, degrees/day**n and revolutions/day.
///
///     The epoch (column 19-32; line 1) has a format NNNNN.NNNNNNNN,
///     where:
///
///                Fraction
///            DOY  of day
///            --- --------
///          NNNNN.NNNNNNNN
///          --
///        Year
///
///     An epoch of 00001.00000000 corresponds to 00:00:00 UTC on
///     2000 January 01.
///
///     The first derivative of Mean Motion (column 34-43, line 1), has
///     a format +.NNNNNNNN, where the first character could be either a
///     plus sign, a minus sign or a space.
///
///     The second derivative of Mean Motion (column 45-52, line 1) and
///     the BSTAR drag term (see [1] for details -- column 54-61, line 1)
///     have a format +NNNNN-N, where the first character could be either
///     a plus sign, a minus sign or a space, the decimal point is
///     assumed, and the exponent is marked by the sign (+/-) at
///     character 6 (column 51 and 60 for the second derivative and BSTAR
///     drag term respectively).
///
///     The "raw" elements in the second line consists primarily of mean
///     elements calculated using the SGP4/SDP4 orbital model (See [1]).
///     The Inclination, the Right Ascension of the Ascending Node, the
///     Argument of Perigee and the Mean Anomaly have units of degrees
///     and can range from 0 up to 360 degrees, except for the
///     Inclination that ranges from 0 to 180 degrees. The Eccentricity
///     value is provided with an assumed leading decimal point. For
///     example, a value of 9790714 corresponds to an eccentricity of
///     0.9790714. The Mean motion is measured in revolutions per day and
///     its format is NN.NNNNNNN.
///
///     This routine extracts these values, "inserts" the implied
///     decimal points and exponents and then converts the inputs
///     to units of radians, radians/minute, radians/minute**2, and
///     radians/minute**3
/// ```
///
/// # 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) Suppose that you have collected the two-line element data
///     for a spacecraft with NORAD ID 18123. The following example
///     code demonstrates how you could go about creating a type 10
///     SPK segment.
///
///     Use the meta-kernel shown below to load the required SPICE
///     kernels.
///
///
///        KPL/MK
///
///        File name: getelm_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
///           ---------           ------------------------------------
///           naif0012.tls        Leapseconds
///           geophysical.ker     geophysical constants for evaluation
///                               of two-line element sets.
///
///        The geophysical.ker is a PCK file that is provided with the
///        SPICE toolkit under the "/data" directory.
///
///        \begindata
///
///           KERNELS_TO_LOAD = ( 'naif0012.tls',
///                               'geophysical.ker'  )
///
///        \begintext
///
///        End of meta-kernel
///
///
///     Example code begins here.
///
///
///           PROGRAM GETELM_EX1
///           IMPLICIT NONE
///
///     C
///     C     SPICELIB functions.
///     C
///           DOUBLE PRECISION      SPD
///
///     C
///     C     Local parameters.
///     C
///           INTEGER               NAMLEN
///           PARAMETER           ( NAMLEN = 40               )
///
///           INTEGER               PNAMLN
///           PARAMETER           ( PNAMLN = 2                )
///
///           CHARACTER*(*)         SPK10
///           PARAMETER           ( SPK10  = 'getelm_ex1.bsp' )
///
///           INTEGER               TLELLN
///           PARAMETER           ( TLELLN = 69               )
///
///     C
///     C     The SPK type 10 segment will contain 18 two-line
///     C     elements sets for the NORAD spacecraft 18123 with
///     C     respect to the Earth (ID 399) in the J2000 reference
///     C     frame.
///     C
///     C     As stated in the naif_ids required reading, for Earth
///     C     orbiting spacecraft lacking a DSN identification code,
///     C     the NAIF ID is derived from the tracking ID assigned to
///     C     it by NORAD via:
///     C
///     C        NAIF ID = -100000 - NORAD ID code
///     C
///           INTEGER               TLESSZ
///           PARAMETER           ( TLESSZ = 9       )
///
///           INTEGER               BODY
///           PARAMETER           ( BODY   = -118123 )
///
///           INTEGER               CENTER
///           PARAMETER           ( CENTER = 399     )
///
///           CHARACTER*(*)         FRMNAM
///           PARAMETER           ( FRMNAM = 'J2000' )
///
///     C
///     C     Local variables.
///     C
///           CHARACTER*(NAMLEN)    IFNAME
///           CHARACTER*(PNAMLN)    NOADPN ( 8           )
///           CHARACTER*(NAMLEN)    SEGID
///           CHARACTER*(TLELLN)    TLE    ( 2  * TLESSZ )
///
///           DOUBLE PRECISION      CONSTS ( 8           )
///           DOUBLE PRECISION      ELEMS  ( 10 * TLESSZ )
///           DOUBLE PRECISION      EPOCHS (      TLESSZ )
///           DOUBLE PRECISION      FIRST
///           DOUBLE PRECISION      LAST
///
///           INTEGER               HANDLE
///           INTEGER               I
///           INTEGER               N
///           INTEGER               NCOMCH
///
///     C
///     C     These are the variables that will hold the constants
///     C     required by SPK type 10. These constants are available
///     C     from the loaded PCK file, which provides the actual
///     C     values and units as used by NORAD propagation model.
///     C
///     C        Constant   Meaning
///     C        --------   ------------------------------------------
///     C        J2         J2 gravitational harmonic for Earth.
///     C        J3         J3 gravitational harmonic for Earth.
///     C        J4         J4 gravitational harmonic for Earth.
///     C        KE         Square root of the GM for Earth.
///     C        QO         High altitude bound for atmospheric model.
///     C        SO         Low altitude bound for atmospheric model.
///     C        ER         Equatorial radius of the Earth.
///     C        AE         Distance units/earth radius.
///     C
///           DATA          NOADPN  /  'J2', 'J3', 'J4', 'KE',
///          .                         'QO', 'SO', 'ER', 'AE'  /
///
///     C
///     C     Define the Two-Line Element sets.
///     C
///           TLE(1)  = '1 18123U 87 53  A 87324.61041692 -.00000023'
///          .      //                   '  00000-0 -75103-5 0 00675'
///           TLE(2)  = '2 18123  98.8296 152.0074 0014950 168.7820 '
///          .      //                   '191.3688 14.12912554 21686'
///           TLE(3)  = '1 18123U 87 53  A 87326.73487726  .00000045'
///          .      //                   '  00000-0  28709-4 0 00684'
///           TLE(4)  = '2 18123  98.8335 154.1103 0015643 163.5445 '
///          .      //                   '196.6235 14.12912902 21988'
///           TLE(5)  = '1 18123U 87 53  A 87331.40868801  .00000104'
///          .      //                   '  00000-0  60183-4 0 00690'
///           TLE(6)  = '2 18123  98.8311 158.7160 0015481 149.9848 '
///          .      //                   '210.2220 14.12914624 22644'
///           TLE(7)  = '1 18123U 87 53  A 87334.24129978  .00000086'
///          .      //                   '  00000-0  51111-4 0 00702'
///           TLE(8)  = '2 18123  98.8296 161.5054 0015372 142.4159 '
///          .      //                   '217.8089 14.12914879 23045'
///           TLE(9)  = '1 18123U 87 53  A 87336.93227900 -.00000107'
///          .      //                   '  00000-0 -52860-4 0 00713'
///           TLE(10) = '2 18123  98.8317 164.1627 0014570 135.9191 '
///          .      //                   '224.2321 14.12910572 23425'
///           TLE(11) = '1 18123U 87 53  A 87337.28635487  .00000173'
///          .      //                   '  00000-0  10226-3 0 00726'
///           TLE(12) = '2 18123  98.8284 164.5113 0015289 133.5979 '
///          .      //                   '226.6438 14.12916140 23475'
///           TLE(13) = '1 18123U 87 53  A 87339.05673569  .00000079'
///          .      //                   '  00000-0  47069-4 0 00738'
///           TLE(14) = '2 18123  98.8288 166.2585 0015281 127.9985 '
///          .      //                   '232.2567 14.12916010 24908'
///           TLE(15) = '1 18123U 87 53  A 87345.43010859  .00000022'
///          .      //                   '  00000-0  16481-4 0 00758'
///           TLE(16) = '2 18123  98.8241 172.5226 0015362 109.1515 '
///          .      //                   '251.1323 14.12915487 24626'
///           TLE(17) = '1 18123U 87 53  A 87349.04167543  .00000042'
///          .      //                   '  00000-0  27370-4 0 00764'
///           TLE(18) = '2 18123  98.8301 176.1010 0015565 100.0881 '
///          .      //                   '260.2047 14.12916361 25138'
///
///     C
///     C     Load the PCK file that provides the geophysical
///     C     constants required for the evaluation of the two-line
///     C     elements sets. Load also an LSK, as it is required by
///     C     GETELM to perform time conversions. Use a metakernel for
///     C     convenience.
///     C
///           CALL FURNSH ( 'getelm_ex1.tm' )
///
///     C
///     C     Retrieve the data from the kernel, and place it on
///     C     the CONSTS array.
///     C
///           DO I = 1, 8
///
///              CALL BODVCD ( CENTER, NOADPN(I), 1, N, CONSTS(I) )
///
///           END DO
///
///     C
///     C     Convert the Two Line Elements lines to the
///     C     element sets.
///     C
///           DO I = 1, TLESSZ
///
///              CALL GETELM ( 1950,      TLE( (I-1)*2 + 1 ),
///          .                 EPOCHS(I), ELEMS( (I-1)*10 + 1 ) )
///
///           END DO
///
///     C
///     C     Define the beginning and end of the segment to be
///     C     -/+ 12 hours from the first and last epochs,
///     C     respectively.
///     C
///           FIRST = EPOCHS(1     ) - 0.5D0 * SPD()
///           LAST  = EPOCHS(TLESSZ) + 0.5D0 * SPD()
///
///     C
///     C     NCOMCH is the number of characters to reserve for the
///     C     kernel's comment area. This example doesn't write
///     C     comments, so set to zero.
///     C
///           NCOMCH = 0
///
///     C
///     C     Internal file name and segment ID.
///     C
///           IFNAME = 'Test for type 10 SPK internal file name'
///           SEGID  = 'SPK type 10 test segment'
///
///     C
///     C     Open a new SPK file.
///     C
///           CALL SPKOPN( SPK10, IFNAME, NCOMCH, HANDLE )
///
///     C
///     C     Now add the segment.
///     C
///           CALL SPKW10 ( HANDLE, BODY,  CENTER, FRMNAM,
///          .              FIRST,  LAST,  SEGID,  CONSTS,
///          .              TLESSZ, ELEMS, EPOCHS         )
///
///     C
///     C     Close the SPK file.
///     C
///           CALL SPKCLS ( HANDLE )
///
///           END
///
///
///     When this program is executed, no output is presented on
///     screen. After run completion, a new SPK type 10 exists in
///     the output directory.
///
///
///  2) Suppose you have a set of two-line elements for the LUME 1
///     cubesat. This example shows how you can use this routine
///     together with the routine EVSGP4 to propagate a state to an
///     epoch of interest.
///
///     Use the meta-kernel from the previous example to load the
///     required SPICE kernels.
///
///
///     Example code begins here.
///
///
///           PROGRAM GETELM_EX2
///           IMPLICIT NONE
///
///     C
///     C     Local parameters.
///     C
///           CHARACTER*(*)         TIMSTR
///           PARAMETER           ( TIMSTR = '2020-05-26 02:25:00' )
///
///           INTEGER               PNAMLN
///           PARAMETER           ( PNAMLN = 2  )
///
///           INTEGER               TLELLN
///           PARAMETER           ( TLELLN = 69 )
///
///     C
///     C     The LUME-1 cubesat is an Earth orbiting object; set
///     C     the center ID to the Earth ID.
///     C
///           INTEGER               CENTER
///           PARAMETER           ( CENTER  = 399     )
///
///     C
///     C     Local variables.
///     C
///           CHARACTER*(PNAMLN)    NOADPN ( 8  )
///           CHARACTER*(TLELLN)    TLE    ( 2  )
///
///           DOUBLE PRECISION      ELEMS  ( 10 )
///           DOUBLE PRECISION      EPOCH
///           DOUBLE PRECISION      ET
///           DOUBLE PRECISION      GEOPHS ( 8  )
///           DOUBLE PRECISION      STATE  ( 6  )
///
///           INTEGER               I
///           INTEGER               N
///
///     C
///     C     These are the variables that will hold the constants
///     C     required by EV2LIN. These constants are available from
///     C     the loaded PCK file, which provides the actual values
///     C     and units as used by NORAD propagation model.
///     C
///     C        Constant   Meaning
///     C        --------   ------------------------------------------
///     C        J2         J2 gravitational harmonic for Earth.
///     C        J3         J3 gravitational harmonic for Earth.
///     C        J4         J4 gravitational harmonic for Earth.
///     C        KE         Square root of the GM for Earth.
///     C        QO         High altitude bound for atmospheric model.
///     C        SO         Low altitude bound for atmospheric model.
///     C        ER         Equatorial radius of the Earth.
///     C        AE         Distance units/earth radius.
///     C
///           DATA          NOADPN  /  'J2', 'J3', 'J4', 'KE',
///          .                         'QO', 'SO', 'ER', 'AE'  /
///
///     C
///     C     Define the Two-Line Element set for LUME-1.
///     C
///           TLE(1)  = '1 43908U 18111AJ  20146.60805006  .00000806'
///          .      //                   '  00000-0  34965-4 0  9999'
///           TLE(2)  = '2 43908  97.2676  47.2136 0020001 220.6050 '
///          .      //                   '139.3698 15.24999521 78544'
///
///     C
///     C     Load the PCK file that provides the geophysical
///     C     constants required for the evaluation of the two-line
///     C     elements sets. Load also an LSK, as it is required by
///     C     GETELM to perform time conversions. Use a metakernel for
///     C     convenience.
///     C
///           CALL FURNSH ( 'getelm_ex1.tm' )
///
///     C
///     C     Retrieve the data from the kernel, and place it on
///     C     the GEOPHS array.
///     C
///           DO I = 1, 8
///
///              CALL BODVCD ( CENTER, NOADPN(I), 1, N, GEOPHS(I) )
///
///           END DO
///
///     C
///     C     Convert the Two Line Elements lines to the element sets.
///     C     Set the lower bound for the years to be the beginning
///     C     of the space age.
///     C
///           CALL GETELM ( 1957, TLE, EPOCH, ELEMS )
///
///     C
///     C     Now propagate the state using EV2LIN to the epoch of
///     C     interest.
///     C
///           CALL STR2ET ( TIMSTR, ET )
///           CALL EVSGP4 ( ET, GEOPHS, ELEMS, STATE )
///
///     C
///     C     Display the results.
///     C
///           WRITE(*,'(2A)')       'Epoch   : ', TIMSTR
///           WRITE(*,'(A,3F16.8)') 'Position:', (STATE(I), I=1,3)
///           WRITE(*,'(A,3F16.8)') 'Velocity:', (STATE(I), I=4,6)
///
///
///           END
///
///
///     When this program was executed on a Mac/Intel/gfortran/64-bit
///     platform, the output was:
///
///
///     Epoch   : 2020-05-26 02:25:00
///     Position:  -4644.60403398  -5038.95025539   -337.27141116
///     Velocity:     -0.45719025      0.92884817     -7.55917355
/// ```
///
/// # Restrictions
///
/// ```text
///  1)  The format of the two-line elements suffer from a "millennium"
///      problem --- only two digits are used for the year of the
///      elements. It is not clear how Space Command will deal with
///      this problem. NAIF hopes that by adjusting the input FRSTYR
///      you should be able to use this routine well into the 21st
///      century.
///
///      The approach taken to mapping the two-digit year to the
///      full year is given by the code below. Here, YR is the
///      integer obtained by parsing the two-digit year from the first
///      line of the elements.
///
///         BEGYR = (FRSTYR/100)*100
///         YEAR  = BEGYR + YR
///
///         IF ( YEAR .LT. FRSTYR ) THEN
///            YEAR = YEAR + 100
///         END IF
///
///      This mapping will be changed if future two-line element
///      representations make this method of computing the full year
///      inaccurate.
/// ```
///
/// # Literature References
///
/// ```text
///  [1]  F. Hoots and R. Roehrich, "Spacetrack Report #3: Models for
///       Propagation of the NORAD Element Sets," U.S. Air Force
///       Aerospace Defense Command, Colorado Springs, CO, 1980.
///
///  [2]  "SDC/SCC Two Card Element Set - Transmission Format,"
///       ADCOM/DO Form 12.
///
///  [3]  F. Hoots, "Spacetrack Report #6: Models for Propagation of
///       Space Command Element Sets,"  U.S. Air Force Aerospace
///       Defense Command, Colorado Springs, CO, 1986.
///
///  [4]  F. Hoots, P. Schumacher and R. Glover, "History of Analytical
///       Orbit Modeling in the U. S. Space Surveillance System,"
///       Journal of Guidance, Control, and Dynamics. 27(2):174-185,
///       2004.
///
///  [5]  D. Vallado, P. Crawford, R. Hujsak and T. Kelso, "Revisiting
///       Spacetrack Report #3," paper AIAA 2006-6753 presented at the
///       AIAA/AAS Astrodynamics Specialist Conference, Keystone, CO.,
///       August 21-24, 2006.
/// ```
///
/// # Author and Institution
///
/// ```text
///  J. Diaz del Rio    (ODC Space)
///  W.L. Taber         (JPL)
///  E.D. Wright        (JPL)
/// ```
///
/// # Version
///
/// ```text
/// -    SPICELIB Version 3.1.0, 06-NOV-2021 (JDR) (MCS)
///
///         Changed the output array declaration from assumed-size array
///         to a constant size array.
///
///         Edited the header to comply with NAIF standard. Added complete
///         code examples; second one based on existing code fragments.
///
///         Corrected the input element names in ELEMS.
///
///         Updated $Particulars to describe in detail the TLE format,
///         $Restrictions to provide indications on the "millennium"
///         problem of TLE data, and $Literature_References to point to
///         the sources of the detailed documentation.
///
/// -    SPICELIB Version 3.0.0, 30-MAR-2004 (EDW)
///
///         Routine now passes inputs to ZZGETELM then responds to
///         any error condition.
///
/// -    SPICELIB Version 2.0.0, 03-MAR-2000 (WLT)
///
///         The routine was modified to check that all of the terms
///         in the two-line element set are parsed correctly.
///
/// -    SPICELIB Version 1.0.0, 26-JUN-1997 (WLT)
/// ```
pub fn getelm(
    ctx: &mut SpiceContext,
    frstyr: i32,
    lines: CharArray,
    epoch: &mut f64,
    elems: &mut [f64; 10],
) -> crate::Result<()> {
    GETELM(frstyr, lines, epoch, elems, ctx.raw_context())?;
    ctx.handle_errors()?;
    Ok(())
}

//$Procedure GETELM ( Get the components from two-line elements )
pub fn GETELM(
    FRSTYR: i32,
    LINES: CharArray,
    EPOCH: &mut f64,
    ELEMS: &mut [f64],
    ctx: &mut Context,
) -> f2rust_std::Result<()> {
    let LINES = DummyCharArray::new(LINES, None, 1..=2);
    let mut ELEMS = DummyArrayMut::new(ELEMS, 1..=10);
    let mut OK: bool = false;
    let mut ERROR = [b' '; 256 as usize];

    //
    // Spicelib functions
    //

    //
    // Local variables
    //

    //
    // Standard SPICE error handling.
    //
    if RETURN(ctx) {
        return Ok(());
    }

    CHKIN(b"GETELM", ctx)?;

    //
    // Pass the input to the parse routine...
    //
    ZZGETELM(
        FRSTYR,
        LINES.as_arg(),
        EPOCH,
        ELEMS.as_slice_mut(),
        &mut OK,
        &mut ERROR,
        ctx,
    )?;

    //
    // ...check for an error parsing the TLE pair. Signal an
    // error if OK equals .FALSE.
    //
    if !OK {
        SETMSG(b"Error in TLE set. #", ctx);
        ERRCH(b"#", &ERROR, ctx);
        SIGERR(b"SPICE(BADTLE)", ctx)?;
        CHKOUT(b"GETELM", ctx)?;
        return Ok(());
    }

    CHKOUT(b"GETELM", ctx)?;
    Ok(())
}