1 /* rdenci.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 /* Table of constant values */
9
10 static integer c__9 = 9;
11 static integer c__1 = 1;
12
13 /* $Procedure RDENCI ( Read encoded integers from text file ) */
rdenci_(integer * unit,integer * n,integer * data)14 /* Subroutine */ int rdenci_(integer *unit, integer *n, integer *data)
15 {
16 /* System generated locals */
17 integer i__1, i__2;
18
19 /* Builtin functions */
20 integer s_rsle(cilist *), s_rnge(char *, integer, char *, integer),
21 do_lio(integer *, integer *, char *, ftnlen), e_rsle(void);
22
23 /* Local variables */
24 char work[64*64];
25 integer i__;
26 extern /* Subroutine */ int chkin_(char *, ftnlen), errch_(char *, char *,
27 ftnlen, ftnlen);
28 logical error;
29 integer nitms;
30 extern /* Subroutine */ int hx2int_(char *, integer *, logical *, char *,
31 ftnlen, ftnlen);
32 integer itmbeg;
33 extern /* Subroutine */ int sigerr_(char *, ftnlen), chkout_(char *,
34 ftnlen);
35 char errmsg[80];
36 extern /* Subroutine */ int setmsg_(char *, ftnlen);
37 integer iostat;
38 extern /* Subroutine */ int errint_(char *, integer *, ftnlen);
39 extern logical return_(void);
40
41 /* Fortran I/O blocks */
42 static cilist io___4 = { 1, 0, 1, 0, 0 };
43
44
45 /* $ Abstract */
46
47 /* Read N encoded integers from a text file, decoding them into */
48 /* their equivalent integers. */
49
50 /* $ Disclaimer */
51
52 /* THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
53 /* CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
54 /* GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
55 /* ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
56 /* PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
57 /* TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
58 /* WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
59 /* PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
60 /* SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
61 /* SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
62
63 /* IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
64 /* BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
65 /* LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
66 /* INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
67 /* REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
68 /* REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
69
70 /* RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
71 /* THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
72 /* CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
73 /* ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
74
75 /* $ Required_Reading */
76
77 /* None. */
78
79 /* $ Keywords */
80
81 /* CONVERSION */
82 /* NUMBERS */
83 /* UTILITY */
84
85 /* $ Declarations */
86 /* $ Brief_I/O */
87
88 /* Variable I/O Description */
89 /* -------- --- -------------------------------------------------- */
90 /* UNIT I Fortran unit number of input text file. */
91 /* N I Number of integers to read and decode. */
92 /* DATA I List of decoded integers. */
93
94 /* $ Detailed_Input */
95
96 /* UNIT The Fortran unit number for a previously opened text */
97 /* file. All reading will begin at the CURRENT POSITION */
98 /* in the text file. */
99
100 /* N The number of encoded integers to be read from the */
101 /* text file attached to UNIT. */
102
103 /* $ Detailed_Output */
104
105 /* DATA List of decoded integers read from the text file */
106 /* attached to UNIT. */
107
108 /* $ Parameters */
109
110 /* None. */
111
112 /* $ Exceptions */
113
114 /* 1) If N, the number of data items, is not positive, the error */
115 /* SPICE(INVALIDARGUMENT) will be signalled. */
116
117 /* 2) If an error occurs while reading from the text file */
118 /* attached to UNIT, the error SPICE(FILEREADFAILED) will */
119 /* be signalled. */
120
121 /* 3) If an error occurs while decoding a number, the error */
122 /* SPICE(DECODINGERROR) will be signalled. */
123
124 /* $ Files */
125
126 /* See the description of UNIT in Detailed_Input. */
127
128 /* $ Particulars */
129
130 /* This routine will read N encoded integers beginning at the */
131 /* current position in a previously opened text file. The current */
132 /* position in a file is defined to be the text line immediately */
133 /* following the last text line that was written or read. The */
134 /* integers will be decoded and placed into a list of integers */
135 /* which will be passed back to the caller. The encoded integers */
136 /* are represented as quoted character strings so that a Fortran */
137 /* list directed read may be used to read the encoded values, */
138 /* rather than a formatted read with the format specifier */
139 /* FMT = '(A)'. */
140
141 /* This routine is one of a pair of routines which are used to */
142 /* encode and decode integers: */
143
144 /* WRENCI -- Encode and write integers to a file. */
145 /* RDENCI -- Read and decode integers from a file. */
146
147 /* The encoding/decoding of integers is performed to provide a */
148 /* portable means for transferring data values. */
149
150 /* Currently the encoded integers are represented as signed */
151 /* hexadecimal numbers See INT2HX.FOR and HX2INT.FOR for details. */
152
153 /* $ Examples */
154
155 /* Suppose we have the following input file which contains the values */
156 /* 1 - 100 encoded, and that the input file has already been opened */
157 /* for reading. The arrow, '-->', indicates the current position in */
158 /* the file. */
159
160 /* -->'1' '2' '3' '4' '5' '6' '7' '8' '9' 'A' 'B' 'C' 'D' 'E' */
161 /* 'F' '10' '11' '12' '13' '14' '15' '16' '17' '18' '19' */
162 /* '1A' '1B' '1C' '1D' '1E' '1F' '20' '21' '22' '23' '24' */
163 /* '25' '26' '27' '28' '29' '2A' '2B' '2C' '2D' '2E' '2F' */
164 /* '30' '31' '32' '33' '34' '35' '36' '37' '38' '39' '3A' */
165 /* '3B' '3C' '3D' '3E' '3F' '40' */
166 /* '41' '42' '43' '44' '45' '46' '47' '48' '49' '4A' '4B' */
167 /* '4C' '4D' '4E' '4F' '50' '51' '52' '53' '54' '55' '56' */
168 /* '57' '58' '59' '5A' '5B' '5C' '5D' '5E' '5F' '60' '61' */
169 /* '62' '63' '64' */
170
171 /* Then, the following code fragment would read and decode these */
172 /* 100 values. */
173
174 /* N = 100 */
175 /* CALL RDENCI( UNIT, N, DATA ) */
176
177 /* Upon returning, the array data would contain the values 1 - 100. */
178
179 /* $ Restrictions */
180
181 /* None. */
182
183 /* $ Literature_References */
184
185 /* None. */
186
187 /* $ Author_and_Institution */
188
189 /* K.R. Gehringer (JPL) */
190
191 /* $ Version */
192
193 /* - SPICELIB Version 1.0.0, 19-OCT-1992 (KRG) */
194
195 /* -& */
196 /* $ Index_Entries */
197
198 /* read and decode encoded integers from a text file */
199
200 /* -& */
201
202 /* SPICELIB functions */
203
204
205 /* Local parameters */
206
207
208 /* Local variables */
209
210
211 /* Standard SPICE error handling. */
212
213 if (return_()) {
214 return 0;
215 } else {
216 chkin_("RDENCI", (ftnlen)6);
217 }
218
219 /* Check to see if the number of data items is less than or equal */
220 /* to zero. If it is, signal an error. */
221
222 if (*n < 1) {
223 setmsg_("The number of data items to be read was not positive: #.", (
224 ftnlen)56);
225 errint_("#", n, (ftnlen)1);
226 sigerr_("SPICE(INVALIDARGUMENT)", (ftnlen)22);
227 chkout_("RDENCI", (ftnlen)6);
228 return 0;
229 }
230
231 /* Initialize the beginning location to place the decoded data */
232 /* items. */
233
234 itmbeg = 1;
235
236 /* We read in the encoded numbers in blocks of size WRKSIZ, and if */
237 /* there was not a read error we will attempt to decode the numbers. */
238 /* We signal an error if either: */
239
240 /* (1) there is a read error */
241 /* (2) there is an error decoding a number. */
242
243 /* NOTE: EOF is interpreted as a read error because we know a priori */
244 /* exactly how many data items we need to read: N. */
245
246 /* Begin decoding the encoded data items read from the input file */
247 /* in blocks of size NITMS. Each time the number of data items */
248 /* NITMS is reached, decode the encoded numbers into the data array. */
249
250 while(itmbeg <= *n) {
251
252 /* The number of items is either the size of the workspace, or */
253 /* the number of data items which remain to be processed, which */
254 /* should always be less than or equal to the size of the */
255 /* workspace. */
256
257 /* Computing MIN */
258 i__1 = 64, i__2 = *n - itmbeg + 1;
259 nitms = min(i__1,i__2);
260
261 /* Read in a block of data items to be decoded. */
262
263 io___4.ciunit = *unit;
264 iostat = s_rsle(&io___4);
265 if (iostat != 0) {
266 goto L100001;
267 }
268 i__1 = nitms;
269 for (i__ = 1; i__ <= i__1; ++i__) {
270 iostat = do_lio(&c__9, &c__1, work + (((i__2 = i__ - 1) < 64 && 0
271 <= i__2 ? i__2 : s_rnge("work", i__2, "rdenci_", (ftnlen)
272 252)) << 6), (ftnlen)64);
273 if (iostat != 0) {
274 goto L100001;
275 }
276 }
277 iostat = e_rsle();
278 L100001:
279
280 /* Check to see if we got a read error: IOSTAT .NE. 0. If we did, */
281 /* then signal an error. EOF is considered to be a read error, */
282 /* since we know exactly how many data items we expect to read. */
283
284 if (iostat != 0) {
285 setmsg_("Error reading from logical unit #, IOSTAT = #.", (ftnlen)
286 46);
287 errint_("#", unit, (ftnlen)1);
288 errint_("#", &iostat, (ftnlen)1);
289 sigerr_("SPICE(FILEREADFAILED)", (ftnlen)21);
290 chkout_("RDENCI", (ftnlen)6);
291 return 0;
292 }
293
294 /* Begin to decode the data items into the data array. Signal an */
295 /* error if we cannot decode a data item. */
296
297 i__2 = nitms;
298 for (i__ = 1; i__ <= i__2; ++i__) {
299 hx2int_(work + (((i__1 = i__ - 1) < 64 && 0 <= i__1 ? i__1 :
300 s_rnge("work", i__1, "rdenci_", (ftnlen)275)) << 6), &
301 data[itmbeg + i__ - 2], &error, errmsg, (ftnlen)64, (
302 ftnlen)80);
303 if (error) {
304 setmsg_("Decoding error occurred while attempting to decode "
305 "item #: #. #", (ftnlen)63);
306 errint_("#", &i__, (ftnlen)1);
307 errch_("#", work + (((i__1 = i__ - 1) < 64 && 0 <= i__1 ?
308 i__1 : s_rnge("work", i__1, "rdenci_", (ftnlen)281))
309 << 6), (ftnlen)1, (ftnlen)64);
310 errch_("#", errmsg, (ftnlen)1, (ftnlen)80);
311 sigerr_("SPICE(DECODINGERROR)", (ftnlen)20);
312 chkout_("RDENCI", (ftnlen)6);
313 return 0;
314 }
315 }
316
317 /* Position the data item pointer at the next location to begin */
318 /* placing the decoded items in the array DATA, and continue */
319 /* processing the until done. */
320
321 itmbeg += nitms;
322 }
323 chkout_("RDENCI", (ftnlen)6);
324 return 0;
325 } /* rdenci_ */
326
327