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
//
// GENERATED FILE
//

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

const LSTCHR: i32 = 255;

struct SaveVars {
    EQCHR: bool,
    NECHR: bool,
    UVALUE: StackArray<i32, 256>,
    I: i32,
    J: i32,
    FIRST: bool,
}

impl SaveInit for SaveVars {
    fn new() -> Self {
        let mut EQCHR: bool = false;
        let mut NECHR: bool = false;
        let mut UVALUE = StackArray::<i32, 256>::new(0..=LSTCHR);
        let mut I: i32 = 0;
        let mut J: i32 = 0;
        let mut FIRST: bool = false;

        FIRST = true;

        Self {
            EQCHR,
            NECHR,
            UVALUE,
            I,
            J,
            FIRST,
        }
    }
}

/// Equivalent characters
///
/// Return .TRUE. if two given characters are equivalent when the
/// case of the characters is ignored.
///
/// # Brief I/O
///
/// ```text
///  VARIABLE  I/O  DESCRIPTION
///  --------  ---  --------------------------------------------------
///  A          I   one of the characters to check
///  B          I   the other character to check
///
///  The function returns .TRUE. if the characters are equivalent
/// ```
///
/// # Detailed Input
///
/// ```text
///  A,
///  B        are two characters that are to be compared to see
///           if they are the same letter (although possibly
///           having different case such as 'a' and 'A')
/// ```
///
/// # Detailed Output
///
/// ```text
///  The function returns the value .TRUE. if the two input characters
///  are the same or can be made the same by converting both to
///  upper or lower case.
/// ```
///
/// # Exceptions
///
/// ```text
///  Error free.
/// ```
///
/// # Particulars
///
/// ```text
///  This is a utility routine for comparing two characters to
///  see if they are the same when converted to upper case. It
///  is particularly useful when writing string analysis routines
///  that should be case insensitive. Instead of writing the
///  expression
///
///     A .EQ. B
///
///  use the expression
///
///     EQCHR ( A, B )
///
///  in all tests of equivalence for characters.
/// ```
///
/// # Examples
///
/// ```text
///  Suppose you want to determine whether or not two strings
///  are the same if differences in the case of letters are ignored.
///  The following code fragment shows how you can use this routine
///  to check for the equivalence of character strings.
///
///     MORE  = .TRUE.
///     SAME  = .TRUE.
///     L1    =  LEN(STR1)
///     L2    =  LEN(STR2)
///     CHECK = MIN ( L1, L2 )
///
///     DO WHILE ( SAME .AND. MORE )
///
///        SAME = EQCHR( STR1(I:I), STR2(I:I) )
///        I    = I + 1
///        MORE = I .LT. CHECK
///
///     END DO
///
///     IF ( .NOT. SAME ) THEN
///
///        There's nothing to do, we already know the strings
///        are not the same.
///
///     ELSE IF ( L1 .LT. L2 ) THEN
///
///        The only way the strings can be regarded as being equal
///        is if the extra unchecked characters in STR2 are all blank.
///
///        SAME = STR2(I:) .EQ. ' '
///
///     ELSE
///
///        Same test as previous one but with STR1 this time.
///
///        SAME = STR1(I:) .EQ. ' '
///
///     END IF
/// ```
///
/// # Author and Institution
///
/// ```text
///  J. Diaz del Rio    (ODC Space)
///  W.L. Taber         (JPL)
///  E.D. Wright        (JPL)
/// ```
///
/// # Version
///
/// ```text
/// -    SPICELIB Version 2.0.1, 26-OCT-2021 (JDR)
///
///         Edited the header to comply with NAIF standard.
///
/// -    SPICELIB Version 2.0.0, 17-SEP-1998 (EDW)
///
///         Replace the UVALUE data statement with a loop to fill
///         UVALUE. The Absoft Mac compiler failed to compile the
///         data statement correctly, and so this function failed
///         to work properly in all situations on the Mac. The
///         corrects the problem and functions on all platforms.
///
/// -    SPICELIB Version 1.0.0, 16-MAY-1995 (WLT)
/// ```
pub fn eqchr(ctx: &mut SpiceContext, a: char, b: char) -> bool {
    let ret = EQCHR(
        &[u8::try_from(a).unwrap()],
        &[u8::try_from(b).unwrap()],
        ctx.raw_context(),
    );
    ret
}

//$Procedure EQCHR (Equivalent characters)
pub fn EQCHR(A: &[u8], B: &[u8], ctx: &mut Context) -> bool {
    let save = ctx.get_vars::<SaveVars>();
    let save = &mut *save.borrow_mut();

    let A = &A[..1 as usize];
    let B = &B[..1 as usize];

    //
    // Entry points.
    //
    //
    // Range of characters
    //
    //
    // Local Variables
    //
    // The array UVALUE contains the ICHAR values for the upper case
    // version of each character.
    //

    //
    // The first time through the loop we set the upper case values
    // for each of the lower case letters.
    //
    if save.FIRST {
        {
            let m1__: i32 = 0;
            let m2__: i32 = LSTCHR;
            let m3__: i32 = 1;
            save.I = m1__;
            for _ in 0..((m2__ - m1__ + m3__) / m3__) as i32 {
                save.UVALUE[save.I] = save.I;
                save.I += m3__;
            }
        }

        save.FIRST = false;

        save.UVALUE[intrinsics::ICHAR(b"a")] = intrinsics::ICHAR(b"A");
        save.UVALUE[intrinsics::ICHAR(b"b")] = intrinsics::ICHAR(b"B");
        save.UVALUE[intrinsics::ICHAR(b"c")] = intrinsics::ICHAR(b"C");
        save.UVALUE[intrinsics::ICHAR(b"d")] = intrinsics::ICHAR(b"D");
        save.UVALUE[intrinsics::ICHAR(b"e")] = intrinsics::ICHAR(b"E");
        save.UVALUE[intrinsics::ICHAR(b"f")] = intrinsics::ICHAR(b"F");
        save.UVALUE[intrinsics::ICHAR(b"g")] = intrinsics::ICHAR(b"G");
        save.UVALUE[intrinsics::ICHAR(b"h")] = intrinsics::ICHAR(b"H");
        save.UVALUE[intrinsics::ICHAR(b"i")] = intrinsics::ICHAR(b"I");
        save.UVALUE[intrinsics::ICHAR(b"j")] = intrinsics::ICHAR(b"J");
        save.UVALUE[intrinsics::ICHAR(b"k")] = intrinsics::ICHAR(b"K");
        save.UVALUE[intrinsics::ICHAR(b"l")] = intrinsics::ICHAR(b"L");
        save.UVALUE[intrinsics::ICHAR(b"m")] = intrinsics::ICHAR(b"M");
        save.UVALUE[intrinsics::ICHAR(b"n")] = intrinsics::ICHAR(b"N");
        save.UVALUE[intrinsics::ICHAR(b"o")] = intrinsics::ICHAR(b"O");
        save.UVALUE[intrinsics::ICHAR(b"p")] = intrinsics::ICHAR(b"P");
        save.UVALUE[intrinsics::ICHAR(b"q")] = intrinsics::ICHAR(b"Q");
        save.UVALUE[intrinsics::ICHAR(b"r")] = intrinsics::ICHAR(b"R");
        save.UVALUE[intrinsics::ICHAR(b"s")] = intrinsics::ICHAR(b"S");
        save.UVALUE[intrinsics::ICHAR(b"t")] = intrinsics::ICHAR(b"T");
        save.UVALUE[intrinsics::ICHAR(b"u")] = intrinsics::ICHAR(b"U");
        save.UVALUE[intrinsics::ICHAR(b"v")] = intrinsics::ICHAR(b"V");
        save.UVALUE[intrinsics::ICHAR(b"w")] = intrinsics::ICHAR(b"W");
        save.UVALUE[intrinsics::ICHAR(b"x")] = intrinsics::ICHAR(b"X");
        save.UVALUE[intrinsics::ICHAR(b"y")] = intrinsics::ICHAR(b"Y");
        save.UVALUE[intrinsics::ICHAR(b"z")] = intrinsics::ICHAR(b"Z");
    }

    save.I = intrinsics::ICHAR(A);
    save.J = intrinsics::ICHAR(B);

    if ((save.I > LSTCHR) || (save.J > LSTCHR)) {
        save.EQCHR = (save.I == save.J);
    } else {
        save.EQCHR = (save.UVALUE[save.I] == save.UVALUE[save.J]);
    }

    save.EQCHR
}

/// Not Equivalent characters
///
/// Return .TRUE. if two given characters are not equivalent if the
/// case of the characters is ignored.
///
/// # Brief I/O
///
/// ```text
///  VARIABLE  I/O  DESCRIPTION
///  --------  ---  --------------------------------------------------
///  A          I   one of the characters to check
///  B          I   the other character to check
///
///  The function returns .TRUE. if the characters are not equivalent
/// ```
///
/// # Detailed Input
///
/// ```text
///  A,
///  B        are two characters that are to be compared to see
///           if they are different letters. Letters that have
///           the same value when converted to uppercase are
///           considered to be equivalent.
/// ```
///
/// # Detailed Output
///
/// ```text
///  The function returns the value .FALSE. if the two input characters
///  are the same or can be made the same by converting both to
///  upper or lower case. Otherwise it returns .TRUE.
/// ```
///
/// # Exceptions
///
/// ```text
///  Error free.
/// ```
///
/// # Particulars
///
/// ```text
///  This routine simply determines the truth value of .NOT. EQCHR.
///  See the entry point EQCHR for a discussion of that function.
/// ```
///
/// # Examples
///
/// ```text
///  Suppose you want to determine whether or not two strings
///  are the same up to differences in case. The following
///  code fragment shows how you can use this routine to check
///  for the equivalence of character strings.
///
///     MORE  = .TRUE.
///     SAME  = .TRUE.
///     L1    =  LEN(STR1)
///     L2    =  LEN(STR2)
///     CHECK = MIN ( L1, L2 )
///
///     DO WHILE ( SAME .AND. MORE )
///
///        IF ( NECHR(STR1(I:I),STR2(I:I) ) THEN
///           SAME = .FALSE.
///        END IF
///
///        I    = I + 1
///        MORE = I .LT. CHECK
///
///     END DO
///
///     IF ( .NOT. SAME ) THEN
///
///        There's nothing to do, we already know the strings
///        are not the same.
///
///     ELSE IF ( L1 .LT. L2 ) THEN
///
///        The only way the strings can be regarded as being equal
///        is if the extra unchecked characters in STR2 are all blank.
///
///        SAME = STR2(I:) .EQ. ' '
///
///     ELSE
///
///        Same test as previous one but with STR1 this time.
///
///        SAME = STR1(I:) .EQ. ' '
///
///     END IF
/// ```
///
/// # Author and Institution
///
/// ```text
///  J. Diaz del Rio    (ODC Space)
///  W.L. Taber         (JPL)
///  E.D. Wright        (JPL)
/// ```
///
/// # Version
///
/// ```text
/// -    SPICELIB Version 1.0.1, 26-OCT-2021 (JDR)
///
///         Edited the header to comply with NAIF standard.
///
/// -    SPICELIB Version 1.0.0, 17-SEP-1998 (EDW)
///
///         Replace the UVALUE data statement with a loop to fill
///         UVALUE. The Absoft Mac compiler failed to compile the
///         data statement correctly, and so this function failed
///         to work properly in all situations on the Mac. The
///         corrects the problem and functions on all platforms.
///
/// -    SPICELIB Version 1.0.0, 16-MAY-1995 (WLT)
/// ```
pub fn nechr(ctx: &mut SpiceContext, a: char, b: char) -> bool {
    let ret = NECHR(
        &[u8::try_from(a).unwrap()],
        &[u8::try_from(b).unwrap()],
        ctx.raw_context(),
    );
    ret
}

//$Procedure NECHR (Not Equivalent characters)
pub fn NECHR(A: &[u8], B: &[u8], ctx: &mut Context) -> bool {
    let save = ctx.get_vars::<SaveVars>();
    let save = &mut *save.borrow_mut();

    let A = &A[..1 as usize];
    let B = &B[..1 as usize];

    if save.FIRST {
        save.FIRST = false;

        {
            let m1__: i32 = 0;
            let m2__: i32 = LSTCHR;
            let m3__: i32 = 1;
            save.I = m1__;
            for _ in 0..((m2__ - m1__ + m3__) / m3__) as i32 {
                save.UVALUE[save.I] = save.I;
                save.I += m3__;
            }
        }

        save.UVALUE[intrinsics::ICHAR(b"a")] = intrinsics::ICHAR(b"A");
        save.UVALUE[intrinsics::ICHAR(b"b")] = intrinsics::ICHAR(b"B");
        save.UVALUE[intrinsics::ICHAR(b"c")] = intrinsics::ICHAR(b"C");
        save.UVALUE[intrinsics::ICHAR(b"d")] = intrinsics::ICHAR(b"D");
        save.UVALUE[intrinsics::ICHAR(b"e")] = intrinsics::ICHAR(b"E");
        save.UVALUE[intrinsics::ICHAR(b"f")] = intrinsics::ICHAR(b"F");
        save.UVALUE[intrinsics::ICHAR(b"g")] = intrinsics::ICHAR(b"G");
        save.UVALUE[intrinsics::ICHAR(b"h")] = intrinsics::ICHAR(b"H");
        save.UVALUE[intrinsics::ICHAR(b"i")] = intrinsics::ICHAR(b"I");
        save.UVALUE[intrinsics::ICHAR(b"j")] = intrinsics::ICHAR(b"J");
        save.UVALUE[intrinsics::ICHAR(b"k")] = intrinsics::ICHAR(b"K");
        save.UVALUE[intrinsics::ICHAR(b"l")] = intrinsics::ICHAR(b"L");
        save.UVALUE[intrinsics::ICHAR(b"m")] = intrinsics::ICHAR(b"M");
        save.UVALUE[intrinsics::ICHAR(b"n")] = intrinsics::ICHAR(b"N");
        save.UVALUE[intrinsics::ICHAR(b"o")] = intrinsics::ICHAR(b"O");
        save.UVALUE[intrinsics::ICHAR(b"p")] = intrinsics::ICHAR(b"P");
        save.UVALUE[intrinsics::ICHAR(b"q")] = intrinsics::ICHAR(b"Q");
        save.UVALUE[intrinsics::ICHAR(b"r")] = intrinsics::ICHAR(b"R");
        save.UVALUE[intrinsics::ICHAR(b"s")] = intrinsics::ICHAR(b"S");
        save.UVALUE[intrinsics::ICHAR(b"t")] = intrinsics::ICHAR(b"T");
        save.UVALUE[intrinsics::ICHAR(b"u")] = intrinsics::ICHAR(b"U");
        save.UVALUE[intrinsics::ICHAR(b"v")] = intrinsics::ICHAR(b"V");
        save.UVALUE[intrinsics::ICHAR(b"w")] = intrinsics::ICHAR(b"W");
        save.UVALUE[intrinsics::ICHAR(b"x")] = intrinsics::ICHAR(b"X");
        save.UVALUE[intrinsics::ICHAR(b"y")] = intrinsics::ICHAR(b"Y");
        save.UVALUE[intrinsics::ICHAR(b"z")] = intrinsics::ICHAR(b"Z");
    }

    save.I = intrinsics::ICHAR(A);
    save.J = intrinsics::ICHAR(B);

    if ((save.I > LSTCHR) || (save.J > LSTCHR)) {
        save.NECHR = (save.I != save.J);
    } else {
        save.NECHR = (save.UVALUE[save.I] != save.UVALUE[save.J]);
    }

    save.NECHR
}