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
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
/// Check ID string
///
/// Validate an ID string: check for non-printing characters
/// or excessive non-blank length.
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// CLASS I A description of the class to which ID belongs.
/// MAXLEN I Maximum allowed non-blank length of ID.
/// ID I The ID string to be validated.
/// ```
///
/// # Detailed Input
///
/// ```text
/// CLASS is a descriptive string indicating the type of
/// object represented by ID. Examples are
/// 'SPK segment identifier', 'DAF internal file name',
/// or 'EK table name'.
///
/// If the input ID is found to be invalid, CLASS is
/// used in the error message generated by this
/// routine.
///
/// MAXLEN is the maximum allowed non-blank length of the
/// input ID string. If ID has any non-blank
/// characters at positions greater than MAXLEN,
/// an error will be signaled.
///
/// ID is the input ID string to be checked. In order
/// to be considered valid, ID must contain only
/// printing characters and must satisfy the condition
///
/// LASTNB( ID ) < MAXLEN
/// -
/// ```
///
/// # Detailed Output
///
/// ```text
/// None. See $Particulars for a description of the effect of this
/// routine.
/// ```
///
/// # Exceptions
///
/// ```text
/// 1) If ID contains any nonprintable characters, the error
/// SPICE(NONPRINTABLECHARS) is signaled.
///
/// 2) If MAXLEN is non-positive, the error SPICE(INVALIDCOUNT) is
/// signaled.
///
/// 3) If ID contains any non-blank characters past position
/// MAXLEN, the error SPICE(IDSTRINGTOOLONG) is signaled.
///
/// 4) If CLASS contains any non-printing characters, the error
/// SPICE(NONPRINTABLECHARS) is signaled.
///
/// 5) CLASS is allowed to be blank. The word 'ID' is used in
/// place of the class string in any error messages in this
/// case.
///
/// 6) The error messages output by this routine have a maximum
/// length of 320 characters. If substitution of CLASS and
/// ID into the long messages causes overflow, the messages
/// will be truncated on the right.
/// ```
///
/// # Particulars
///
/// ```text
/// This routine operates by side effects: it validates an ID string
/// and signals an error if the ID has either of the following
/// problems:
///
/// - There are non-printing characters in the ID string.
///
/// - The last non-blank character in the string occurs at a
/// location having index higher than a specified value.
///
/// The error message signaled by this routine contains the offending
/// ID string and indicates the class of item to which ID belongs.
/// The form of the message is:
///
/// The <CLASS> <'ID'> is invalid; <reason>
/// ```
///
/// # Examples
///
/// ```text
/// 1) If
///
/// CLASS = 'segment identifier'
/// MAXLEN = 40
///
/// and
///
/// ID = 'Example EK created on March 28, 1995 by NJB/NAIF'
///
/// the error message
///
/// The segment identifier 'Example EK created on March 28,
/// 1995 by NJB/NAIF' is invalid; the last non-blank character
/// is located at position 48.
///
/// will be signaled.
/// ```
///
/// # Author and Institution
///
/// ```text
/// N.J. Bachman (JPL)
/// J. Diaz del Rio (ODC Space)
/// ```
///
/// # Version
///
/// ```text
/// - SPICELIB Version 1.1.0, 02-JUN-2021 (JDR)
///
/// Added IMPLICIT NONE statement.
///
/// Edited the header to comply with NAIF standard.
///
/// - SPICELIB Version 1.0.0, 16-JUN-1995 (NJB)
/// ```
pub fn chckid(ctx: &mut SpiceContext, class: &str, maxlen: i32, id: &str) -> crate::Result<()> {
CHCKID(class.as_bytes(), maxlen, id.as_bytes(), ctx.raw_context())?;
ctx.handle_errors()?;
Ok(())
}
//$Procedure CHCKID ( Check ID string )
pub fn CHCKID(CLASS: &[u8], MAXLEN: i32, ID: &[u8], ctx: &mut Context) -> f2rust_std::Result<()> {
let mut CHRCOD: i32 = 0;
let mut I: i32 = 0;
let mut L: i32 = 0;
//
// SPICELIB functions
//
//
// Local variables
//
//
// Standard SPICE error handling.
//
if RETURN(ctx) {
return Ok(());
} else {
CHKIN(b"CHCKID", ctx)?;
}
//
// Check CLASS before trying to use it in an error message.
//
I = FRSTNP(CLASS);
if (I > 0) {
CHRCOD = intrinsics::ICHAR(fstr::substr(CLASS, I..=I));
SETMSG(b"The class string \'#\' is invalid; this string contains a non-printing character (ICHAR = #) at position #.", ctx);
ERRCH(b"#", CLASS, ctx);
ERRINT(b"#", CHRCOD, ctx);
ERRINT(b"#", I, ctx);
SIGERR(b"SPICE(NONPRINTABLECHARS)", ctx)?;
CHKOUT(b"CHCKID", ctx)?;
return Ok(());
}
//
// MAXLEN must be a sensible value.
//
if (MAXLEN < 1) {
SETMSG(
b"Non-blank length limit MAXLEN should be positive but was #.",
ctx,
);
ERRINT(b"#", MAXLEN, ctx);
SIGERR(b"SPICE(INVALIDCOUNT)", ctx)?;
CHKOUT(b"CHCKID", ctx)?;
return Ok(());
}
L = LASTNB(ID);
//
// The ID must not be too long.
//
if (L > MAXLEN) {
SETMSG(b"The # \'#\' is invalid; the last non-blank character is located at position #; the maximum allowed length is #.", ctx);
if fstr::ne(CLASS, b" ") {
ERRCH(b"#", CLASS, ctx);
} else {
ERRCH(b"#", b"ID", ctx);
}
ERRCH(b"#", ID, ctx);
ERRINT(b"#", L, ctx);
ERRINT(b"#", MAXLEN, ctx);
SIGERR(b"SPICE(IDSTRINGTOOLONG)", ctx)?;
CHKOUT(b"CHCKID", ctx)?;
return Ok(());
}
//
// Look for non-printing characters in ID.
//
I = FRSTNP(ID);
if (I > 0) {
CHRCOD = intrinsics::ICHAR(fstr::substr(ID, I..=I));
SETMSG(b"The # \'#\' is invalid; this string contains a non-printing character (ICHAR = #) at position #.", ctx);
if fstr::ne(CLASS, b" ") {
ERRCH(b"#", CLASS, ctx);
} else {
ERRCH(b"#", b"ID", ctx);
}
ERRCH(b"#", ID, ctx);
ERRINT(b"#", CHRCOD, ctx);
ERRINT(b"#", I, ctx);
SIGERR(b"SPICE(NONPRINTABLECHARS)", ctx)?;
CHKOUT(b"CHCKID", ctx)?;
return Ok(());
}
CHKOUT(b"CHCKID", ctx)?;
Ok(())
}