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
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
/// Body ID code to string translation
///
/// Translate a body ID code to either the corresponding name
/// or if no name to ID code mapping exists, the string
/// representation of the body ID value.
///
/// # Required Reading
///
/// * [NAIF_IDS](crate::required_reading::naif_ids)
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// CODE I Integer ID code to translate to a string.
/// NAME O String corresponding to CODE.
/// ```
///
/// # Detailed Input
///
/// ```text
/// CODE is the integer code for a body: planet, satellite,
/// barycenter, spacecraft, asteroid, comet, or
/// other ephemeris object.
/// ```
///
/// # Detailed Output
///
/// ```text
/// NAME is the string name of the body identified by CODE
/// if a mapping between CODE and a body name exists
/// within SPICE.
///
/// If CODE has more than one translation, then the
/// most recently defined NAME corresponding to CODE
/// is returned. NAME will have the exact format (case
/// and blanks) as when the name/code pair was defined.
///
/// If the input value of CODE does not map to a body
/// name, NAME returns the string representation
/// of CODE.
/// ```
///
/// # Parameters
///
/// ```text
/// MAXL is the maximum allowable length of a body name. The
/// current value of this parameter is 36. See the SPICELIB
/// include file zzbodtrn.inc for details.
/// ```
///
/// # Exceptions
///
/// ```text
/// 1) If there is any problem with the body name-ID mapping kernel
/// variables present in the kernel pool, an error is signaled by
/// a routine in the call tree of this routine.
/// ```
///
/// # Files
///
/// ```text
/// Body-name mappings may be defined at run time by loading text
/// kernels containing kernel variable assignments of the form
///
/// NAIF_BODY_NAME += ( <name 1>, ... )
/// NAIF_BODY_CODE += ( <code 1>, ... )
///
/// See naif_ids.req for details.
/// ```
///
/// # Particulars
///
/// ```text
/// BODC2S is one of five related subroutines,
///
/// BODS2C Body string to code
/// BODC2S Body code to string
/// BODN2C Body name to code
/// BODC2N Body code to name
/// BODDEF Body name/code definition
///
/// BODS2C, BODC2S, BODN2C, and BODC2N perform translations between
/// body names and their corresponding integer ID codes which are
/// used in SPICE files and routines.
///
/// BODS2C is a slightly more general version of BODN2C: support
/// for strings containing ID codes in string format enables a caller
/// to identify a body using a string, even when no name is
/// associated with that body.
///
/// BODC2S is a general version of BODC2N; the routine returns either
/// the name assigned in the body ID to name mapping or a string
/// representation of the CODE value if no mapping exists.
///
/// BODDEF assigns a body name to ID mapping. The mapping has
/// priority in name-to-ID and ID-to-name translations.
///
/// Refer to naif_ids.req for the list of name/code associations built
/// into SPICE, and for details concerning adding new name/code
/// associations at run time by loading text kernels.
/// ```
///
/// # Examples
///
/// ```text
/// The numerical results shown for this example 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) Apply the BODC2S call to several IDs representing codes
/// included in the default SPICE ID-name lists and codes not
/// included in the list.
///
/// Example code begins here.
///
///
/// PROGRAM BODC2S_EX1
/// IMPLICIT NONE
///
/// C
/// C Local variables.
/// C
/// CHARACTER*(32) NAME
/// INTEGER CODE (7)
/// INTEGER I
///
/// C
/// C Assign an array of body IDs. Not all the listed IDs
/// C map to a body name.
/// C
/// CODE(1) = 399
/// CODE(2) = 0
/// CODE(3) = 3
/// CODE(4) = -77
/// CODE(5) = 11
/// CODE(6) = -1
/// CODE(7) = 6000001
///
/// C
/// C Loop over the CODE array, call BODC2S for each
/// C element of CODE.
/// C
/// WRITE(*,*) 'Code Name'
/// WRITE(*,*) '------- -----------------------'
///
/// DO I= 1, 7
///
/// CALL BODC2S( CODE(I), NAME )
///
/// WRITE(*, '(I8,3x,A)' ) CODE(I), NAME
///
/// END DO
///
/// END
///
///
/// When this program was executed on a Mac/Intel/gfortran/64-bit
/// platform, the output was:
///
///
/// Code Name
/// ------- -----------------------
/// 399 EARTH
/// 0 SOLAR SYSTEM BARYCENTER
/// 3 EARTH BARYCENTER
/// -77 GALILEO ORBITER
/// 11 11
/// -1 GEOTAIL
/// 6000001 6000001
///
///
/// Note that the codes 11 and 6000001 did not map to a name so the
/// call returns as NAME the string expression of the codes.
/// ```
///
/// # Author and Institution
///
/// ```text
/// J. Diaz del Rio (ODC Space)
/// B.V. Semenov (JPL)
/// E.D. Wright (JPL)
/// ```
///
/// # Version
///
/// ```text
/// - SPICELIB Version 1.1.0, 07-JUL-2021 (JDR)
///
/// Added IMPLICIT NONE statement.
///
/// Edited the header to comply with NAIF standard. Fixed minor
/// typos in header. Added description of MAXL parameter. Added
/// $Exceptions and $Restrictions.
///
/// - SPICELIB Version 1.0.1, 18-APR-2014 (BVS)
///
/// Minor header edits.
///
/// - SPICELIB Version 1.0.0, 10-APR-2010 (EDW)
/// ```
pub fn bodc2s(ctx: &mut SpiceContext, code: i32, name: &mut str) -> crate::Result<()> {
BODC2S(code, fstr::StrBytes::new(name).as_mut(), ctx.raw_context())?;
ctx.handle_errors()?;
Ok(())
}
//$Procedure BODC2S ( Body ID code to string translation )
pub fn BODC2S(CODE: i32, NAME: &mut [u8], ctx: &mut Context) -> f2rust_std::Result<()> {
let mut FOUND: bool = false;
//
// SPICELIB functions
//
//
// Local variables
//
//
// Standard SPICELIB error handling.
//
if RETURN(ctx) {
return Ok(());
}
CHKIN(b"BODC2S", ctx)?;
//
// Fortran. No type check available for CODE. Bother.
//
//
// Attempt to translate the input CODE to a name. Use
// the private routine ZZBODC2N.
//
ZZBODC2N(CODE, NAME, &mut FOUND, ctx)?;
if FOUND {
//
// Success. CODE maps to NAME. Return.
//
CHKOUT(b"BODC2S", ctx)?;
return Ok(());
}
//
// If execution reaches this level, the SPICE body ID
// to name mapping lacks an assignment for CODE. Convert
// CODE to a string representation of the integer value.
//
INTSTR(CODE, NAME, ctx);
CHKOUT(b"BODC2S", ctx)?;
Ok(())
}