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

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

const MSGLEN: i32 = 80;

/// Surface and body strings to surface ID code
///
/// Translate a surface string, together with a body string, to the
/// corresponding surface ID code. The input strings may contain
/// names or integer ID codes.
///
/// # Required Reading
///
/// * [DSK](crate::required_reading::dsk)
/// * [NAIF_IDS](crate::required_reading::naif_ids)
///
/// # Brief I/O
///
/// ```text
///  VARIABLE  I/O  DESCRIPTION
///  --------  ---  --------------------------------------------------
///  SRFSTR     I   Surface name or ID string.
///  BODSTR     I   Body name or ID string.
///  CODE       O   Integer surface ID code.
///  FOUND      O   Flag indicating whether surface ID was found.
/// ```
///
/// # Detailed Input
///
/// ```text
///  SRFSTR   is a string designating a surface. SRFSTR may contain
///           a surface name or a string representation of the
///           surface's integer ID code.
///
///           If, for the body specified by BODSTR, multiple surface
///           names are associated with one surface ID code, then any
///           of these names may be used as the value of SRFSTR.
///
///           Case and leading and trailing blanks in a surface name
///           are not significant. Sequences of consecutive embedded
///           blanks are considered equivalent to a single blank.
///           For example, all of the strings below are considered
///           to be equivalent:
///
///              'MGS MOLA 128 PIXEL/DEG'
///              'MGS MOLA 128 pixel/deg'
///              'MGS MOLA 128 PIXEL/DEG   '
///              'MGS MOLA 128    PIXEL/DEG'
///              '   MGS MOLA 128 PIXEL/DEG'
///
///           However,
///
///              'MGSMOLA 128PIXEL/DEG'
///
///           is not equivalent to the names above.
///
///
///  BODSTR   is a string designating the body associated with the
///           input surface string. BODSTR may contain a body name
///           or a string representation of the body's integer ID
///           code. For example, BODSTR may contain
///
///              '1000012'
///
///           instead of
///
///              '67P/CHURYUMOV-GERASIMENKO (1969 R1)'
///
///           Case and leading and trailing blanks in a name are not
///           significant. The treatment of blanks in BODSTR is the
///           same as for SRFSTR.
/// ```
///
/// # Detailed Output
///
/// ```text
///  CODE     is integer ID code of the surface designated by
///           SRFSTR, for the body designated by BODSTR, if for this
///           body an association exists between the input surface
///           string and a surface ID code. CODE is defined if and
///           only if the output flag FOUND is .TRUE.
///
///  FOUND    is a logical flag that is .TRUE. if a surface code
///           corresponding to the input strings was found and
///           .FALSE. otherwise.
/// ```
///
/// # Exceptions
///
/// ```text
///  1)  If the input surface string does not map to an ID code
///      and does not represent an integer, the output CODE is
///      undefined and the output FOUND is set to .FALSE.
///
///      This case is not treated as an error.
///
///  2)  If the input body string does not map to an ID code and does
///      not represent an integer, the output CODE is undefined and
///      the output FOUND is set to .FALSE.
///
///      This case is not treated as an error.
/// ```
///
/// # Files
///
/// ```text
///  Surface name-to-ID mappings may be defined at run time by loading
///  text kernels containing kernel variable assignments of the form
///
///     NAIF_SURFACE_NAME += ( <surface name 1>, ... )
///     NAIF_SURFACE_CODE += ( <surface code 1>, ... )
///     NAIF_SURFACE_BODY += ( <body code 1>,    ... )
///
///  Above, the Ith elements of the lists on the assignments' right
///  hand sides together define the Ith surface name/ID mapping.
///
///  The same effect can be achieved using assignments formatted as
///  follows:
///
///     NAIF_SURFACE_NAME += <surface name 1>
///     NAIF_SURFACE_CODE += <surface code 1>
///     NAIF_SURFACE_BODY += <body code 1>
///
///     NAIF_SURFACE_NAME += <surface name 2>
///     NAIF_SURFACE_CODE += <surface code 2>
///     NAIF_SURFACE_BODY += <body code 2>
///
///        ...
///
///  Note the use of the
///
///     +=
///
///  operator; this operator appends to rather than overwrites the
///  kernel variable named on the left hand side of the assignment.
/// ```
///
/// # Particulars
///
/// ```text
///  Surfaces are always associated with bodies (which usually are
///  ephemeris objects). For any given body, a mapping between surface
///  names and surface ID codes can be established.
///
///  Bodies serve to disambiguate surface names and ID codes: the set
///  of surface names and surface ID codes for a given body can be
///  thought of as belonging to a name space. A given surface ID code
///  or surface name may be used for surfaces of multiple bodies,
///  without conflict.
///
///  Associations between surface names and ID codes are always made
///  via kernel pool assignments; there are no built-in associations.
///
///  SRFS2C is one of four related subroutines:
///
///     SRFS2C      Surface string and body string to surface ID code
///     SRFSCC      Surface string and body ID code to surface ID code
///     SRFC2S      Surface ID code and body ID code to surface string
///     SRFCSS      Surface ID code and body string to surface string
///
///  SRFS2C, SRFC2S, SRFSCC, and SRFCSS perform translations between
///  surface strings and their corresponding integer ID codes.
///
///  Refer to naif_ids.req for details concerning adding new surface
///  name/code associations at run time by loading text kernels.
/// ```
///
/// # Examples
///
/// ```text
///  The formatting of the results shown for this example may differ
///  across platforms.
///
///  1) Supposed a text kernel has been loaded that contains
///     the following assignments:
///
///        NAIF_SURFACE_NAME += ( 'MGS MOLA  64 pixel/deg',
///                               'MGS MOLA 128 pixel/deg',
///                               'PHOBOS GASKELL Q512'     )
///        NAIF_SURFACE_CODE += (   1,   2,    1 )
///        NAIF_SURFACE_BODY += ( 499, 499,  401 )
///
///     Translate each surface and body string pair to the
///     associated surface ID code. Also perform a translation
///     for a surface name having no matching ID and for
///     a body string having no matching body ID code.
///
///     Use the meta-kernel shown below to define the required SPICE
///     kernel variables.
///
///
///        KPL/MK
///
///        File: srfs2c_ex1.tm
///
///        This meta-kernel is intended to support operation of SPICE
///        example programs. The file contents shown here should not be
///        assumed to contain adequate or correct versions of data
///        required by SPICE-based user applications.
///
///
///        \begindata
///
///        NAIF_SURFACE_NAME += ( 'MGS MOLA  64 pixel/deg',
///                               'MGS MOLA 128 pixel/deg',
///                               'PHOBOS GASKELL Q512'     )
///        NAIF_SURFACE_CODE += (   1,   2,    1 )
///        NAIF_SURFACE_BODY += ( 499, 499,  401 )
///
///        \begintext
///
///
///     Example code begins here.
///
///
///           PROGRAM SRFS2C_EX1
///           IMPLICIT NONE
///
///           INCLUDE 'srftrn.inc'
///
///           INTEGER               FILSIZ
///           PARAMETER           ( FILSIZ = 255 )
///
///           INTEGER               NCASE
///           PARAMETER           ( NCASE = 8 )
///
///           INTEGER               BDNMLN
///           PARAMETER           ( BDNMLN = 36 )
///
///           CHARACTER*(BDNMLN)    BODSTR ( NCASE )
///           CHARACTER*(FILSIZ)    META
///           CHARACTER*(SFNMLN)    SRFSTR ( NCASE )
///
///           INTEGER               I
///           INTEGER               SURFID
///
///           LOGICAL               FOUND
///
///
///           DATA  ( SRFSTR(I), BODSTR(I), I = 1, NCASE )  /
///          .
///          .        'MGS MOLA  64 pixel/deg',    'MARS',
///          .        'PHOBOS GASKELL Q512',       'PHOBOS',
///          .        'MGS MOLA 128 pixel/deg',    'MARS',
///          .        'MGS MOLA  64 pixel/deg',    '499',
///          .        '1',                         'PHOBOS',
///          .        '2',                         '499',
///          .        'ZZZ',                       'MARS',
///          .        '1',                         'ZZZ'    /
///
///
///           META = 'srfs2c_ex1.tm'
///
///           CALL FURNSH ( META )
///
///           WRITE (*,*) ' '
///
///           DO I = 1, NCASE
///
///              CALL SRFS2C ( SRFSTR(I), BODSTR(I),
///          .                 SURFID,    FOUND     )
///
///              WRITE (*,*) 'surface string   = ', SRFSTR(I)
///              WRITE (*,*) 'body string      = ', BODSTR(I)
///              WRITE (*,*) 'surface ID found = ', FOUND
///
///              IF ( FOUND ) THEN
///                 WRITE (*,*) 'surface ID       = ', SURFID
///              END IF
///
///              WRITE (*,*) ' '
///
///           END DO
///
///           END
///
///
///     When this program was executed on a Mac/Intel/gfortran/64-bit
///     platform, the output was:
///
///
///      surface string   = MGS MOLA  64 pixel/deg
///      body string      = MARS
///      surface ID found =  T
///      surface ID       =            1
///
///      surface string   = PHOBOS GASKELL Q512
///      body string      = PHOBOS
///      surface ID found =  T
///      surface ID       =            1
///
///      surface string   = MGS MOLA 128 pixel/deg
///      body string      = MARS
///      surface ID found =  T
///      surface ID       =            2
///
///      surface string   = MGS MOLA  64 pixel/deg
///      body string      = 499
///      surface ID found =  T
///      surface ID       =            1
///
///      surface string   = 1
///      body string      = PHOBOS
///      surface ID found =  T
///      surface ID       =            1
///
///      surface string   = 2
///      body string      = 499
///      surface ID found =  T
///      surface ID       =            2
///
///      surface string   = ZZZ
///      body string      = MARS
///      surface ID found =  F
///
///      surface string   = 1
///      body string      = ZZZ
///      surface ID found =  F
/// ```
///
/// # Author and Institution
///
/// ```text
///  N.J. Bachman       (JPL)
///  J. Diaz del Rio    (ODC Space)
///  B.V. Semenov       (JPL)
///  E.D. Wright        (JPL)
/// ```
///
/// # Version
///
/// ```text
/// -    SPICELIB Version 1.0.1, 22-OCT-2021 (JDR) (NJB)
///
///         Edited the header to comply with NAIF standard.
///
///         Updated description of SRFSTR to indicate that any
///         surface name alias may be used.
///
/// -    SPICELIB Version 1.0.0, 14-JAN-2016 (NJB) (EDW) (BVS)
/// ```
pub fn srfs2c(
    ctx: &mut SpiceContext,
    srfstr: &str,
    bodstr: &str,
    code: &mut i32,
    found: &mut bool,
) -> crate::Result<()> {
    SRFS2C(
        srfstr.as_bytes(),
        bodstr.as_bytes(),
        code,
        found,
        ctx.raw_context(),
    )?;
    ctx.handle_errors()?;
    Ok(())
}

//$Procedure SRFS2C ( Surface and body strings to surface ID code )
pub fn SRFS2C(
    SRFSTR: &[u8],
    BODSTR: &[u8],
    CODE: &mut i32,
    FOUND: &mut bool,
    ctx: &mut Context,
) -> f2rust_std::Result<()> {
    let mut ERRMSG = [b' '; MSGLEN as usize];
    let mut BODYID: i32 = 0;
    let mut PTR: i32 = 0;

    //
    // SPICELIB functions
    //

    //
    // Local parameters
    //

    //
    // Local variables
    //

    if RETURN(ctx) {
        return Ok(());
    }

    CHKIN(b"SRFS2C", ctx)?;

    //
    // No result has been found yet.
    //
    *FOUND = false;

    //
    // Obtain a body ID string.
    //
    BODS2C(BODSTR, &mut BODYID, FOUND, ctx)?;

    if FAILED(ctx) {
        CHKOUT(b"SRFS2C", ctx)?;
        return Ok(());
    }

    if *FOUND {
        //
        // We have the body ID.
        //
        // Try to translate the input name to a known surface ID code.
        //
        ZZSRFN2C(SRFSTR, BODYID, CODE, FOUND, ctx)?;

        if FAILED(ctx) {
            CHKOUT(b"SRFS2C", ctx)?;
            return Ok(());
        }

        if !*FOUND {
            //
            // The surface string could not be mapped to an ID code.
            //
            // It's possible the name is a string representation of an
            // integer, for example, '999'.  If so, find the equivalent
            // datum of INTEGER type.
            //
            NPARSI(SRFSTR, CODE, &mut ERRMSG, &mut PTR, ctx);
            //
            // If the string parsed as an integer, PTR is zero;
            // otherwise it's non-zero.
            //
            *FOUND = (PTR == 0);
        }
    }
    //
    // CODE and FOUND are set.
    //
    CHKOUT(b"SRFS2C", ctx)?;
    Ok(())
}