1 /* beuns.f -- translated by f2c (version 19980913).
2 You must link the resulting object file with the libraries:
3 -lf2c -lm (in that order)
4 */
5
6 #include "f2c.h"
7
8 /* $Procedure BEUNS ( Be an unsigned integer? ) */
beuns_(char * string,ftnlen string_len)9 logical beuns_(char *string, ftnlen string_len)
10 {
11 /* System generated locals */
12 logical ret_val;
13
14 /* Builtin functions */
15 integer i_len(char *, ftnlen), i_indx(char *, char *, ftnlen, ftnlen),
16 s_cmp(char *, char *, ftnlen, ftnlen);
17
18 /* Local variables */
19 integer i__, l;
20 logical ok;
21 extern integer frstnb_(char *, ftnlen);
22
23 /* $ Abstract */
24
25 /* Determine whether a string represents an unsigned integer. */
26
27 /* $ Disclaimer */
28
29 /* THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
30 /* CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
31 /* GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
32 /* ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
33 /* PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
34 /* TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
35 /* WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
36 /* PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
37 /* SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
38 /* SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
39
40 /* IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
41 /* BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
42 /* LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
43 /* INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
44 /* REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
45 /* REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
46
47 /* RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
48 /* THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
49 /* CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
50 /* ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
51
52 /* $ Required_Reading */
53
54 /* WORDS */
55
56 /* $ Keywords */
57
58 /* ALPHANUMERIC */
59 /* NUMBERS */
60 /* SCANNING */
61 /* UTILITY */
62
63 /* $ Declarations */
64 /* $ Brief_I/O */
65
66 /* Variable I/O Description */
67 /* -------- --- -------------------------------------------------- */
68 /* STRING I Character string. */
69
70 /* The function returns TRUE if the string represents an unsigned */
71 /* integer. Otherwise, it returns FALSE. */
72
73 /* $ Detailed_Input */
74
75 /* STRING is any string. */
76
77 /* $ Detailed_Output */
78
79 /* If STRING contains a single word made entirely from the */
80 /* characters '0' through '9', then the function returns TRUE. */
81 /* Otherwise, it returns FALSE. */
82
83 /* $ Parameters */
84
85 /* None. */
86
87 /* $ Exceptions */
88
89 /* Error free. */
90
91 /* $ Files */
92
93 /* None. */
94
95 /* $ Particulars */
96
97 /* By definition an unsigned integer is a word made exclusively */
98 /* from the characters '0', '1', '2', '3', '4', '5', '6', '7', '8', */
99 /* and '9'. */
100
101 /* $ Examples */
102
103
104 /* Four classes of numbers recognized by the various BE functions. */
105
106 /* UNS unsigned integer */
107 /* INT integer (includes INT) */
108 /* DEC decimal number (includes UNS, INT) */
109 /* NUM number (includes UNS, INT, NUM) */
110
111 /* The following table illustrates the differences between */
112 /* the classes. (Any number of leading and trailing blanks */
113 /* are acceptable.) */
114
115 /* String Accepted by */
116 /* ------------------ ------------------ */
117 /* 0 UNS, INT, DEC, NUM */
118 /* 21 */
119 /* 21994217453648 */
120
121 /* +0 INT, DEC, NUM */
122 /* -13 */
123 /* +21946 */
124
125 /* 1.23 DEC, NUM */
126 /* 12. */
127 /* .17 */
128 /* +4.1 */
129 /* -.25 */
130
131 /* 2.3e17 NUM */
132 /* 17.D-13275849 */
133 /* -.194265E+0004 */
134
135 /* Note that the functions don't take the magnitudes of the numbers */
136 /* into account. They may accept numbers that cannot be represented */
137 /* in Fortran variables. (For example, '2.19E999999999999' probably */
138 /* exceeds the maximum floating point number on any machine, but */
139 /* is perfectly acceptable to BENUM.) */
140
141 /* The following strings are not accepted by any of the functions. */
142
143 /* String Reason */
144 /* --------------- ---------------------------------------- */
145 /* 3/4 No implied operations (rational numbers) */
146 /* 37+14 No explicit operations */
147 /* E12 Must have mantissa */
148 /* 217,346.91 No commas */
149 /* 3.14 159 264 No embedded spaces */
150 /* PI No special numbers */
151 /* FIVE No textual numbers */
152 /* CXIV No roman numerals */
153
154 /* $ Restrictions */
155
156 /* None. */
157
158 /* $ Literature_References */
159
160 /* None. */
161
162 /* $ Author_and_Institution */
163
164 /* W.L. Taber (JPL) */
165
166 /* $ Version */
167
168 /* - SPICELIB Version 1.0.0, 01-DEC-1995 (WLT) */
169
170 /* -& */
171 /* $ Index_Entries */
172
173 /* determine if a string is an unsigned integer */
174
175 /* -& */
176
177 /* SPICE functions */
178
179
180 /* Local variables */
181
182
183 /* Get the length of the string and the position of its */
184 /* first non-blank character. */
185
186 l = i_len(string, string_len);
187 i__ = frstnb_(string, string_len);
188
189 /* If there isn't a non-blank character, this isn't an */
190 /* unsigned integer. */
191
192 if (i__ == 0) {
193 ret_val = FALSE_;
194 return ret_val;
195 }
196
197 /* As far as we know right now, everything is ok. Examine */
198 /* characters until we run out of string or until we */
199 /* hit a non-digit character. */
200
201 ok = TRUE_;
202 while(ok && i__ <= l) {
203 if (i_indx("0123456789", string + (i__ - 1), (ftnlen)10, (ftnlen)1) >
204 0) {
205 ++i__;
206 } else {
207 ok = FALSE_;
208 }
209 }
210
211 /* If the string still is ok as an unsigned integer, it must be */
212 /* one... */
213
214 if (ok) {
215 ret_val = TRUE_;
216 } else {
217
218 /* ... otherwise, it's an unsigned integer if the remainder is blank. */
219
220 ret_val = s_cmp(string + (i__ - 1), " ", string_len - (i__ - 1), (
221 ftnlen)1) == 0;
222 }
223 return ret_val;
224 } /* beuns_ */
225
226