rsspice/generated/spicelib/
beint.rs

1//
2// GENERATED FILE
3//
4
5use super::*;
6use crate::SpiceContext;
7use f2rust_std::*;
8
9/// Be an Integer?
10///
11/// Determine whether a string represents an integer.
12///
13/// # Brief I/O
14///
15/// ```text
16///  VARIABLE  I/O  DESCRIPTION
17///  --------  ---  --------------------------------------------------
18///  STRING     I   Character string.
19///
20///  The function returns .TRUE. if the string represents an integer.
21///  Otherwise, it returns .FALSE.
22/// ```
23///
24/// # Detailed Input
25///
26/// ```text
27///  STRING   is any string.
28/// ```
29///
30/// # Detailed Output
31///
32/// ```text
33///  If the input string contains an integer (as defined in
34///  $Particulars below), the function returns .TRUE. Otherwise,
35///  the function returns .FALSE.
36/// ```
37///
38/// # Exceptions
39///
40/// ```text
41///  Error free.
42/// ```
43///
44/// # Particulars
45///
46/// ```text
47///  An integer may be either of the following:
48///
49///     1) An unsigned integer (as defined by function BEUNS).
50///
51///     2) A sign ('+' or '-') followed by an unsigned
52///        integer.
53/// ```
54///
55/// # Examples
56///
57/// ```text
58///  Four classes of numbers recognized by the various BE functions.
59///
60///     UNS      unsigned integer
61///     INT      integer                (includes INT)
62///     DEC      decimal number         (includes UNS, INT)
63///     NUM      number                 (includes UNS, INT, NUM)
64///
65///  The following table illustrates the differences between
66///  the classes. (Any number of leading and trailing blanks
67///  are acceptable.)
68///
69///     String                  Accepted by
70///     ------------------      ------------------
71///     0                       UNS, INT, DEC, NUM
72///     21
73///     21994217453648
74///
75///     +0                      INT, DEC, NUM
76///     -13
77///     +21946
78///
79///     1.23                    DEC, NUM
80///     12.
81///     .17
82///     +4.1
83///     -.25
84///
85///     2.3e17                  NUM
86///     17.D-13275849
87///     -.194265E+0004
88///
89///  Note that the functions don't take the magnitudes of the numbers
90///  into account. They may accept numbers that cannot be represented
91///  in Fortran variables. (For example, '2.19E999999999999' probably
92///  exceeds the maximum floating point number on any machine, but
93///  is perfectly acceptable to BENUM.)
94///
95///  The following strings are not accepted by any of the functions.
96///
97///     String             Reason
98///     ---------------    ----------------------------------------
99///     3/4                No implied operations (rational numbers)
100///     37+14              No explicit operations
101///     E12                Must have mantissa
102///     217,346.91         No commas
103///     3.14 159 264       No embedded spaces
104///     PI                 No special numbers
105///     FIVE               No textual numbers
106///     CXIV               No roman numerals
107/// ```
108///
109/// # Author and Institution
110///
111/// ```text
112///  J. Diaz del Rio    (ODC Space)
113///  W.L. Taber         (JPL)
114/// ```
115///
116/// # Version
117///
118/// ```text
119/// -    SPICELIB Version 1.1.0, 24-NOV-2021 (JDR)
120///
121///         Added IMPLICIT NONE statement.
122///
123///         Edited the header to comply with NAIF standard.
124///
125/// -    SPICELIB Version 1.0.0, 01-DEC-1995 (WLT)
126/// ```
127pub fn beint(string: &str) -> bool {
128    let ret = BEINT(string.as_bytes());
129    ret
130}
131
132//$Procedure BEINT  ( Be an Integer? )
133pub fn BEINT(STRING: &[u8]) -> bool {
134    let mut BEINT: bool = false;
135    let mut I: i32 = 0;
136    let mut L: i32 = 0;
137    let mut LETTER = [b' '; 1 as usize];
138
139    //
140    // Find the first non-blank character and the length of the
141    // string.
142    //
143    L = intrinsics::LEN(STRING);
144    I = FRSTNB(STRING);
145
146    //
147    // If there isn't a non-blank character, this isn't an
148    // integer.
149    //
150    if (I == 0) {
151        BEINT = false;
152        return BEINT;
153    }
154
155    //
156    // Copy the first non-blank letter in the string.
157    //
158    fstr::assign(&mut LETTER, fstr::substr(STRING, I..=I));
159
160    if (I < L) {
161        //
162        // The first character is not the last, so we might start with
163        // a plus or minus.  If so the rest must be an unsigned integer.
164        //
165        if (fstr::eq(&LETTER, b"+") || fstr::eq(&LETTER, b"-")) {
166            I = (I + 1);
167
168            if fstr::ne(fstr::substr(STRING, I..=I), b" ") {
169                BEINT = BEUNS(fstr::substr(STRING, I..));
170            } else {
171                BEINT = false;
172            }
173        } else {
174            //
175            // If the first character isn't plus (+) or minus (-)
176            // the string must be an unsigned integer if its going
177            // to be an integer.
178            //
179            BEINT = BEUNS(fstr::substr(STRING, I..));
180        }
181    } else {
182        //
183        // If the first (non-blank) character is the last one, then
184        // it must be an unsigned integer, for the string to
185        // represent an integer.
186        //
187        BEINT = BEUNS(&LETTER);
188    }
189
190    BEINT
191}