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
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
const LMSGLN: i32 = (23 * 80);
const SMSGLN: i32 = 25;
/// Insert Integer into Error Message Text
///
/// Substitute an integer for the first occurrence of a marker found
/// in the current long error message.
///
/// # Required Reading
///
/// * [ERROR](crate::required_reading::error)
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// MARKER I A substring of the error message to be replaced.
/// INTNUM I The integer to substitute for MARKER.
/// ```
///
/// # Detailed Input
///
/// ```text
/// MARKER is a character string which marks a position in
/// the long error message where a character string
/// representing an integer is to be substituted.
/// Leading and trailing blanks in MARKER are not
/// significant.
///
/// Case IS significant; 'XX' is considered to be
/// a different marker from 'xx'.
///
/// INTNUM is an integer whose character representation will
/// be substituted for the first occurrence of MARKER
/// in the long error message. This occurrence of the
/// substring indicated by MARKER will be removed, and
/// replaced by a character string, with no leading or
/// trailing blanks, representing INTNUM.
/// ```
///
/// # Parameters
///
/// ```text
/// LMSGLN is the maximum length of the long error message. See
/// the include file errhnd.inc for the value of LMSGLN.
/// ```
///
/// # Exceptions
///
/// ```text
/// 1) This routine does not detect any errors.
///
/// However, this routine is part of the SPICELIB error
/// handling mechanism.
/// ```
///
/// # Particulars
///
/// ```text
/// This routine updates the current long error message. If no marker
/// is found, (e.g., in the case that the long error message is
/// blank), the routine has no effect. If multiple instances of the
/// marker designated by MARKER are found, only the first one is
/// replaced.
///
/// If the character string resulting from the substitution
/// exceeds the maximum length of the long error message, the
/// characters on the right are lost. No error is signaled.
///
/// This routine has no effect if changes to the long message
/// are not allowed.
/// ```
///
/// # 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) Create a user-defined error message, including both the
/// short and long messages, providing the value of two integer
/// variables within the long message, and signal the error.
///
///
/// Example code begins here.
///
///
/// PROGRAM ERRINT_EX1
/// IMPLICIT NONE
///
/// C
/// C Set long error message, with two different MARKER
/// C strings where the value of the integer variables
/// C will go. Our markers are '#' and 'XX'.
/// C
/// CALL SETMSG ( 'LONG MESSAGE. Invalid operation value. '
/// . // ' The value was #. Left endpoint '
/// . // 'exceeded right endpoint. The left '
/// . // 'endpoint was: XX. The right endpoint '
/// . // 'was: XX.' )
///
/// C
/// C Insert the integer number where the # is now.
/// C
/// CALL ERRINT ( '#', 5 )
///
/// C
/// C Insert now an integer variable in the long message where
/// C the first XX is now.
/// C
/// CALL ERRINT ( 'XX', 910 )
///
/// C
/// C Signal the error.
/// C
/// CALL SIGERR ( 'SPICE(USERDEFINED)' )
///
/// END
///
///
/// When this program was executed on a Mac/Intel/gfortran/64-bit
/// platform, the output was:
///
///
/// ============================================================***
///
/// Toolkit version: N0066
///
/// SPICE(USERDEFINED) --
///
/// LONG MESSAGE. Invalid operation value. The value was 5. Left***
/// exceeded right endpoint. The left endpoint was: 910. The right
/// endpoint was: XX.
///
/// Oh, by the way: The SPICELIB error handling actions are USER-
/// TAILORABLE. You can choose whether the Toolkit aborts or co***
/// when errors occur, which error messages to output, and where***
/// the output. Please read the ERROR "Required Reading" file, ***
/// the routines ERRACT, ERRDEV, and ERRPRT.
///
/// ============================================================***
///
///
/// Warning: incomplete output. 6 lines extended past the right
/// margin of the header and have been truncated. These lines are
/// marked by "***" at the end of each line.
///
///
/// Note that the execution of this program produces the error
/// SPICE(USERDEFINED), which follows the NAIF standard as
/// described in the ERROR required reading.
/// ```
///
/// # Restrictions
///
/// ```text
/// 1) The caller must ensure that the message length, after
/// substitution is performed, doesn't exceed LMSGLN characters.
/// ```
///
/// # Author and Institution
///
/// ```text
/// N.J. Bachman (JPL)
/// J. Diaz del Rio (ODC Space)
/// W.L. Taber (JPL)
/// ```
///
/// # Version
///
/// ```text
/// - SPICELIB Version 2.2.0, 17-JUN-2021 (JDR)
///
/// Changed input argument name INTEGR to INTNUM consistency with
/// other routines.
///
/// Added IMPLICIT NONE statement.
///
/// Edited the header to comply with NAIF standard. Removed
/// unnecessary $Revisions section. Added complete code example
/// based on existing fragments.
///
/// - SPICELIB Version 2.1.0, 29-JUL-1997 (NJB)
///
/// Maximum length of the long error message is now represented
/// by the parameter LMSGLN. Miscellaneous format changes to the
/// header, code and in-line comments were made.
///
/// - SPICELIB Version 1.0.1, 10-MAR-1992 (WLT)
///
/// Comment section for permuted index source lines was added
/// following the header.
///
/// - SPICELIB Version 1.0.0, 31-JAN-1990 (NJB)
/// ```
pub fn errint(ctx: &mut SpiceContext, marker: &str, intnum: i32) {
ERRINT(marker.as_bytes(), intnum, ctx.raw_context());
}
//$Procedure ERRINT ( Insert Integer into Error Message Text )
pub fn ERRINT(MARKER: &[u8], INTNUM: i32, ctx: &mut Context) {
let mut LNGMSG = [b' '; LMSGLN as usize];
let mut TMPMSG = [b' '; LMSGLN as usize];
let mut ISTRNG = [b' '; 11 as usize];
let mut STRPOS: i32 = 0;
//
// SPICELIB functions
//
//
// Local Variables:
//
//
// Changes to the long error message have to be allowed, or we
// do nothing.
//
if !ALLOWD(ctx) {
return;
}
//
// MARKER has to have some non-blank characters, or we do nothing.
//
if (LASTNB(MARKER) == 0) {
return;
}
//
// Get a copy of the current long error message. Convert INTNUM
// to a character string.
//
GETLMS(&mut LNGMSG, ctx);
INTSTR(INTNUM, &mut ISTRNG, ctx);
//
// Locate the leftmost occurrence of MARKER, if there is one
// (ignoring leading and trailing blanks):
//
STRPOS = intrinsics::INDEX(
&LNGMSG,
fstr::substr(MARKER, FRSTNB(MARKER)..=LASTNB(MARKER)),
);
if (STRPOS == 0) {
return;
} else {
//
// We put together TMPMSG, a copy of LNGMSG with MARKER
// replaced by the character representation of INTNUM:
//
if (STRPOS > 1) {
if (((STRPOS + LASTNB(MARKER)) - FRSTNB(MARKER)) < LASTNB(&LNGMSG)) {
//
// There's more of the long message after the marker...
//
fstr::assign(
&mut TMPMSG,
&fstr::concat(
&fstr::concat(
fstr::substr(&LNGMSG, 1..=(STRPOS - 1)),
fstr::substr(&ISTRNG, 1..=LASTNB(&ISTRNG)),
),
fstr::substr(
&LNGMSG,
(((STRPOS + LASTNB(MARKER)) - FRSTNB(MARKER)) + 1)..,
),
),
);
} else {
fstr::assign(
&mut TMPMSG,
&fstr::concat(
fstr::substr(&LNGMSG, 1..=(STRPOS - 1)),
fstr::substr(&ISTRNG, 1..=LASTNB(&ISTRNG)),
),
);
}
} else {
//
// We're starting with the integer, so we know it fits...
//
if ((LASTNB(MARKER) - FRSTNB(MARKER)) < LASTNB(&LNGMSG)) {
//
// There's more of the long message after the marker...
//
fstr::assign(
&mut TMPMSG,
&fstr::concat(
fstr::substr(&ISTRNG, 1..=LASTNB(&ISTRNG)),
fstr::substr(
&LNGMSG,
(((STRPOS + LASTNB(MARKER)) - FRSTNB(MARKER)) + 1)..,
),
),
);
} else {
//
// The marker's the whole string:
//
fstr::assign(&mut TMPMSG, &ISTRNG);
}
}
//
// Update the long message:
//
PUTLMS(&TMPMSG, ctx);
}
}