Skip to main content

rsspice/generated/spicelib/
errint.rs

1//
2// GENERATED FILE
3//
4
5use super::*;
6use crate::SpiceContext;
7use f2rust_std::*;
8
9const LMSGLN: i32 = (23 * 80);
10const SMSGLN: i32 = 25;
11
12/// Insert Integer into Error Message Text
13///
14/// Substitute an integer for the first occurrence of a marker found
15/// in the current long error message.
16///
17/// # Required Reading
18///
19/// * [ERROR](crate::required_reading::error)
20///
21/// # Brief I/O
22///
23/// ```text
24///  VARIABLE  I/O  DESCRIPTION
25///  --------  ---  --------------------------------------------------
26///  MARKER     I   A substring of the error message to be replaced.
27///  INTNUM     I   The integer to substitute for MARKER.
28/// ```
29///
30/// # Detailed Input
31///
32/// ```text
33///  MARKER   is a character string which marks a position in
34///           the long error message where a character string
35///           representing an integer is to be substituted.
36///           Leading and trailing blanks in MARKER are not
37///           significant.
38///
39///           Case IS significant;  'XX' is considered to be
40///           a different marker from 'xx'.
41///
42///  INTNUM   is an integer whose character representation will
43///           be substituted for the first occurrence of MARKER
44///           in the long error message. This occurrence of the
45///           substring indicated by MARKER will be removed, and
46///           replaced by a character string, with no leading or
47///           trailing blanks, representing INTNUM.
48/// ```
49///
50/// # Parameters
51///
52/// ```text
53///  LMSGLN   is the maximum length of the long error message. See
54///           the include file errhnd.inc for the value of LMSGLN.
55/// ```
56///
57/// # Exceptions
58///
59/// ```text
60///  1)  This routine does not detect any errors.
61///
62///      However, this routine is part of the SPICELIB error
63///      handling mechanism.
64/// ```
65///
66/// # Particulars
67///
68/// ```text
69///  This routine updates the current long error message. If no marker
70///  is found, (e.g., in the case that the long error message is
71///  blank), the routine has no effect. If multiple instances of the
72///  marker designated by MARKER are found, only the first one is
73///  replaced.
74///
75///  If the character string resulting from the substitution
76///  exceeds the maximum length of the long error message, the
77///  characters on the right are lost. No error is signaled.
78///
79///  This routine has no effect if changes to the long message
80///  are not allowed.
81/// ```
82///
83/// # Examples
84///
85/// ```text
86///  The numerical results shown for this example may differ across
87///  platforms. The results depend on the SPICE kernels used as
88///  input, the compiler and supporting libraries, and the machine
89///  specific arithmetic implementation.
90///
91///  1) Create a user-defined error message, including both the
92///     short and long messages, providing the value of two integer
93///     variables within the long message, and signal the error.
94///
95///
96///     Example code begins here.
97///
98///
99///           PROGRAM ERRINT_EX1
100///           IMPLICIT NONE
101///
102///     C
103///     C     Set long error message, with two different MARKER
104///     C     strings where the value of the integer variables
105///     C     will go.  Our markers are '#' and 'XX'.
106///     C
107///           CALL SETMSG ( 'LONG MESSAGE.  Invalid operation value. '
108///          .         //   '  The value was #.  Left endpoint '
109///          .         //   'exceeded right endpoint.  The left '
110///          .         //   'endpoint was:  XX.  The right endpoint '
111///          .         //   'was:  XX.' )
112///
113///     C
114///     C     Insert the integer number where the # is now.
115///     C
116///           CALL ERRINT ( '#',  5  )
117///
118///     C
119///     C     Insert now an integer variable in the long message where
120///     C     the first XX is now.
121///     C
122///           CALL ERRINT ( 'XX', 910 )
123///
124///     C
125///     C     Signal the error.
126///     C
127///           CALL SIGERR ( 'SPICE(USERDEFINED)' )
128///
129///           END
130///
131///
132///     When this program was executed on a Mac/Intel/gfortran/64-bit
133///     platform, the output was:
134///
135///
136///     ============================================================***
137///
138///     Toolkit version: N0066
139///
140///     SPICE(USERDEFINED) --
141///
142///     LONG MESSAGE. Invalid operation value. The value was 5. Left***
143///     exceeded right endpoint. The left endpoint was: 910. The right
144///     endpoint was: XX.
145///
146///     Oh, by the way:  The SPICELIB error handling actions are USER-
147///     TAILORABLE.  You can choose whether the Toolkit aborts or co***
148///     when errors occur, which error messages to output, and where***
149///     the output.  Please read the ERROR "Required Reading" file, ***
150///     the routines ERRACT, ERRDEV, and ERRPRT.
151///
152///     ============================================================***
153///
154///
155///     Warning: incomplete output. 6 lines extended past the right
156///     margin of the header and have been truncated. These lines are
157///     marked by "***" at the end of each line.
158///
159///
160///     Note that the execution of this program produces the error
161///     SPICE(USERDEFINED), which follows the NAIF standard as
162///     described in the ERROR required reading.
163/// ```
164///
165/// # Restrictions
166///
167/// ```text
168///  1)  The caller must ensure that the message length, after
169///      substitution is performed, doesn't exceed LMSGLN characters.
170/// ```
171///
172/// # Author and Institution
173///
174/// ```text
175///  N.J. Bachman       (JPL)
176///  J. Diaz del Rio    (ODC Space)
177///  W.L. Taber         (JPL)
178/// ```
179///
180/// # Version
181///
182/// ```text
183/// -    SPICELIB Version 2.2.0, 17-JUN-2021 (JDR)
184///
185///         Changed input argument name INTEGR to INTNUM consistency with
186///         other routines.
187///
188///         Added IMPLICIT NONE statement.
189///
190///         Edited the header to comply with NAIF standard. Removed
191///         unnecessary $Revisions section. Added complete code example
192///         based on existing fragments.
193///
194/// -    SPICELIB Version 2.1.0, 29-JUL-1997 (NJB)
195///
196///         Maximum length of the long error message is now represented
197///         by the parameter LMSGLN. Miscellaneous format changes to the
198///         header, code and in-line comments were made.
199///
200/// -    SPICELIB Version 1.0.1, 10-MAR-1992 (WLT)
201///
202///         Comment section for permuted index source lines was added
203///         following the header.
204///
205/// -    SPICELIB Version 1.0.0, 31-JAN-1990 (NJB)
206/// ```
207pub fn errint(ctx: &mut SpiceContext, marker: &str, intnum: i32) {
208    ERRINT(marker.as_bytes(), intnum, ctx.raw_context());
209}
210
211//$Procedure ERRINT ( Insert Integer into Error Message Text )
212pub fn ERRINT(MARKER: &[u8], INTNUM: i32, ctx: &mut Context) {
213    let mut LNGMSG = [b' '; LMSGLN as usize];
214    let mut TMPMSG = [b' '; LMSGLN as usize];
215    let mut ISTRNG = [b' '; 11 as usize];
216    let mut STRPOS: i32 = 0;
217
218    //
219    // SPICELIB functions
220    //
221
222    //
223    // Local Variables:
224    //
225
226    //
227    // Changes to the long error message have to be allowed, or we
228    // do nothing.
229    //
230    if !ALLOWD(ctx) {
231        return;
232    }
233
234    //
235    // MARKER has to have some non-blank characters, or we do nothing.
236    //
237    if (LASTNB(MARKER) == 0) {
238        return;
239    }
240
241    //
242    // Get a copy of the current long error message.  Convert INTNUM
243    // to a character string.
244    //
245    GETLMS(&mut LNGMSG, ctx);
246    INTSTR(INTNUM, &mut ISTRNG, ctx);
247
248    //
249    // Locate the leftmost occurrence of MARKER, if there is one
250    // (ignoring leading and trailing blanks):
251    //
252    STRPOS = intrinsics::INDEX(
253        &LNGMSG,
254        fstr::substr(MARKER, FRSTNB(MARKER)..=LASTNB(MARKER)),
255    );
256
257    if (STRPOS == 0) {
258        return;
259    } else {
260        //
261        // We put together TMPMSG, a copy of LNGMSG with MARKER
262        // replaced by the character representation of INTNUM:
263        //
264
265        if (STRPOS > 1) {
266            if (((STRPOS + LASTNB(MARKER)) - FRSTNB(MARKER)) < LASTNB(&LNGMSG)) {
267                //
268                // There's more of the long message after the marker...
269                //
270                fstr::assign(
271                    &mut TMPMSG,
272                    &fstr::concat(
273                        &fstr::concat(
274                            fstr::substr(&LNGMSG, 1..=(STRPOS - 1)),
275                            fstr::substr(&ISTRNG, 1..=LASTNB(&ISTRNG)),
276                        ),
277                        fstr::substr(
278                            &LNGMSG,
279                            (((STRPOS + LASTNB(MARKER)) - FRSTNB(MARKER)) + 1)..,
280                        ),
281                    ),
282                );
283            } else {
284                fstr::assign(
285                    &mut TMPMSG,
286                    &fstr::concat(
287                        fstr::substr(&LNGMSG, 1..=(STRPOS - 1)),
288                        fstr::substr(&ISTRNG, 1..=LASTNB(&ISTRNG)),
289                    ),
290                );
291            }
292        } else {
293            //
294            // We're starting with the integer, so we know it fits...
295            //
296            if ((LASTNB(MARKER) - FRSTNB(MARKER)) < LASTNB(&LNGMSG)) {
297                //
298                // There's more of the long message after the marker...
299                //
300                fstr::assign(
301                    &mut TMPMSG,
302                    &fstr::concat(
303                        fstr::substr(&ISTRNG, 1..=LASTNB(&ISTRNG)),
304                        fstr::substr(
305                            &LNGMSG,
306                            (((STRPOS + LASTNB(MARKER)) - FRSTNB(MARKER)) + 1)..,
307                        ),
308                    ),
309                );
310            } else {
311                //
312                // The marker's the whole string:
313                //
314                fstr::assign(&mut TMPMSG, &ISTRNG);
315            }
316        }
317        //
318        // Update the long message:
319        //
320        PUTLMS(&TMPMSG, ctx);
321    }
322}