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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
/// Text file, open for read
///
/// Open a text file for read access.
///
/// # Required Reading
///
/// * TEXT
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// FNAME I Name of file.
/// UNIT O Logical unit.
/// ```
///
/// # Detailed Input
///
/// ```text
/// FNAME is the name of the text file to be opened.
/// ```
///
/// # Detailed Output
///
/// ```text
/// UNIT is the logical unit connected to the opened file.
/// ```
///
/// # Exceptions
///
/// ```text
/// 1) If FNAME is a blank string, the error SPICE(BLANKFILENAME) is
/// signaled.
///
/// 2) If the file cannot be opened, the error SPICE(FILEOPENFAILED)
/// is signaled.
/// ```
///
/// # Files
///
/// ```text
/// See FNAME and UNIT above.
/// ```
///
/// # Particulars
///
/// ```text
/// In SPICELIB, a text file is formatted and sequential and may
/// contain only printable ASCII characters and blanks (ASCII 32-127).
/// When printing a text file, records are single spaced; the first
/// character will not be interpreted as a carriage control character.
///
/// TXTOPR opens an existing text file for read access and makes use
/// of the SPICELIB mechanism for coordinating use of logical units.
///
/// System Dependencies
/// ===================
///
/// The open statement will include the following keyword = value
/// pairs:
///
/// UNIT = UNIT
/// FILE = FNAME
/// FORM = 'FORMATTED'
/// ACCESS = 'SEQUENTIAL'
/// STATUS = 'OLD'
/// IOSTAT = IOSTAT
///
/// In addition, the statement will include
///
/// CARRIAGECONTROL = 'LIST'
/// READONLY
///
/// for the Vax and the OS X Absoft compiler, or
///
/// MODE = 'READ'
///
/// for the IBM pc.
/// ```
///
/// # Examples
///
/// ```text
/// The following example reads the first line from an input file,
/// 'INPUT.TXT', and writes it to an output file, 'OUTPUT.TXT'.
///
/// CALL TXTOPR ( 'INPUT.TXT', IN )
/// CALL TXTOPN ( 'OUTPUT.TXT', OUT )
///
/// READ ( IN, FMT='(A)' ) LINE
/// WRITE ( OUT, FMT='(A)' ) LINE
///
/// CLOSE ( IN )
/// CLOSE ( OUT )
/// ```
///
/// # Restrictions
///
/// ```text
/// 1) The file, FNAME, must exist prior to calling TXTOPR.
/// ```
///
/// # Literature References
///
/// ```text
/// [1] "Lahey F77L EM/32 FORTRAN Language Reference Manual", p.145.
///
/// [2] "Language Reference Manual", Absoft Fortran V3.2, page 7-12
/// (for the NeXT), 1993.
/// ```
///
/// # Author and Institution
///
/// ```text
/// N.J. Bachman (JPL)
/// J. Diaz del Rio (ODC Space)
/// J.E. McLean (JPL)
/// H.A. Neilan (JPL)
/// B.V. Semenov (JPL)
/// M.J. Spencer (JPL)
/// W.L. Taber (JPL)
/// E.D. Wright (JPL)
/// ```
///
/// # Version
///
/// ```text
/// - SPICELIB Version 2.27.0, 28-NOV-2021 (BVS)
///
/// Updated for MAC-OSX-M1-64BIT-CLANG_C.
///
/// - SPICELIB Version 2.26.0, 17-JUN-2021 (JDR)
///
/// Added IMPLICIT NONE statement.
///
/// Edited the header to comply with NAIF standard.
///
/// - SPICELIB Version 2.25.0, 10-MAR-2014 (BVS)
///
/// Updated for SUN-SOLARIS-64BIT-INTEL.
///
/// - SPICELIB Version 2.24.0, 10-MAR-2014 (BVS)
///
/// Updated for PC-LINUX-64BIT-IFORT.
///
/// - SPICELIB Version 2.23.0, 10-MAR-2014 (BVS)
///
/// Updated for PC-CYGWIN-GFORTRAN.
///
/// - SPICELIB Version 2.22.0, 10-MAR-2014 (BVS)
///
/// Updated for PC-CYGWIN-64BIT-GFORTRAN.
///
/// - SPICELIB Version 2.21.0, 10-MAR-2014 (BVS)
///
/// Updated for PC-CYGWIN-64BIT-GCC_C.
///
/// - SPICELIB Version 2.20.0, 13-MAY-2010 (BVS)
///
/// Updated for SUN-SOLARIS-INTEL.
///
/// - SPICELIB Version 2.19.0, 13-MAY-2010 (BVS)
///
/// Updated for SUN-SOLARIS-INTEL-CC_C.
///
/// - SPICELIB Version 2.18.0, 13-MAY-2010 (BVS)
///
/// Updated for SUN-SOLARIS-INTEL-64BIT-CC_C.
///
/// - SPICELIB Version 2.17.0, 13-MAY-2010 (BVS)
///
/// Updated for SUN-SOLARIS-64BIT-NATIVE_C.
///
/// - SPICELIB Version 2.16.0, 13-MAY-2010 (BVS)
///
/// Updated for PC-WINDOWS-64BIT-IFORT.
///
/// - SPICELIB Version 2.15.0, 13-MAY-2010 (BVS)
///
/// Updated for PC-LINUX-64BIT-GFORTRAN.
///
/// - SPICELIB Version 2.14.0, 13-MAY-2010 (BVS)
///
/// Updated for PC-64BIT-MS_C.
///
/// - SPICELIB Version 2.13.0, 13-MAY-2010 (BVS)
///
/// Updated for MAC-OSX-64BIT-INTEL_C.
///
/// - SPICELIB Version 2.12.0, 13-MAY-2010 (BVS)
///
/// Updated for MAC-OSX-64BIT-IFORT.
///
/// - SPICELIB Version 2.11.0, 13-MAY-2010 (BVS)
///
/// Updated for MAC-OSX-64BIT-GFORTRAN.
///
/// - SPICELIB Version 2.10.0, 18-MAR-2009 (BVS)
///
/// Updated for PC-LINUX-GFORTRAN.
///
/// - SPICELIB Version 2.9.0, 18-MAR-2009 (BVS)
///
/// Updated for MAC-OSX-GFORTRAN.
///
/// - SPICELIB Version 2.8.0, 19-FEB-2008 (BVS)
///
/// Updated for PC-LINUX-IFORT.
///
/// - SPICELIB Version 2.7.0, 14-NOV-2006 (BVS)
///
/// Updated for PC-LINUX-64BIT-GCC_C.
///
/// - SPICELIB Version 2.6.0, 14-NOV-2006 (BVS)
///
/// Updated for MAC-OSX-INTEL_C.
///
/// - SPICELIB Version 2.5.0, 14-NOV-2006 (BVS)
///
/// Updated for MAC-OSX-IFORT.
///
/// - SPICELIB Version 2.4.0, 14-NOV-2006 (BVS)
///
/// Updated for PC-WINDOWS-IFORT.
///
/// - SPICELIB Version 2.3.0, 26-OCT-2005 (BVS)
///
/// Updated for SUN-SOLARIS-64BIT-GCC_C.
///
/// - SPICELIB Version 2.2.0, 03-JAN-2005 (BVS)
///
/// Updated for PC-CYGWIN_C.
///
/// - SPICELIB Version 2.1.0, 03-JAN-2005 (BVS)
///
/// Updated for PC-CYGWIN.
///
/// - SPICELIB Version 2.0.6, 24-APR-2003 (EDW)
///
/// Added MAC-OSX-F77 to the list of platforms
/// that require READONLY to read write protected
/// kernels.
///
/// - SPICELIB Version 2.0.5, 17-JUL-2002 (BVS)
///
/// Added MAC-OSX environments.
///
/// - SPICELIB Version 2.0.4, 08-OCT-1999 (WLT)
///
/// The environment lines were expanded so that the supported
/// environments are now explicitly given. New
/// environments are WIN-NT
///
/// - SPICELIB Version 2.0.3, 16-SEP-1999 (NJB)
///
/// CSPICE environments were added. Some typos were corrected.
///
/// - SPICELIB Version 2.0.2, 28-JUL-1999 (WLT)
///
/// The environment lines were expanded so that the supported
/// environments are now explicitly given. New
/// environments are PC-DIGITAL, SGI-O32 and SGI-N32.
///
/// - SPICELIB Version 2.0.1, 18-MAR-1999 (WLT)
///
/// The environment lines were expanded so that the supported
/// environments are now explicitly given. Previously,
/// environments such as SUN-SUNOS and SUN-SOLARIS were implied
/// by the environment label SUN.
///
/// - SPICELIB Version 2.0.0, 05-APR-1998 (NJB)
///
/// References to the PC-LINUX environment were added.
///
/// - SPICELIB Version 1.3.0, 11-NOV-1993 (HAN)
///
/// Module was updated for the Silicon Graphics, DEC Alpha-OSF/1,
/// and NeXT platforms.
///
/// - SPICELIB Version 1.2.0, 12-OCT-1992 (HAN)
///
/// The code was also reformatted so that a utility program can
/// create the source file for a specific environment given a
/// master source file.
///
/// - SPICELIB Version 1.1.1, 10-MAR-1992 (WLT)
///
/// Comment section for permuted index source lines was added
/// following the header.
///
/// - SPICELIB Version 1.1.0, 13-NOV-1991 (MJS)
///
/// Module updated to allow portability to the Lahey F77L EM/32
/// FORTRAN V 4.0 environment.
///
/// - SPICELIB Version 1.0.0, 05-APR-1991 (JEM)
/// ```
///
/// # Revisions
///
/// ```text
/// - SPICELIB Version 2.0.0, 05-APR-1998 (NJB)
///
/// References to the PC-LINUX environment were added.
///
/// - SPICELIB Version 1.3.0, 11-NOV-1993 (HAN)
///
/// Module was updated for the Silicon Graphics, DEC Alpha-OSF/1,
/// and NeXT platforms.
///
/// - SPICELIB Version 1.2.0, 12-OCT-1992 (HAN)
///
/// The code was also reformatted so that a utility program can
/// create the source file for a specific environment given a
/// master source file.
///
/// - SPICELIB Version 1.1.0, 13-NOV-1991 (MJS)
///
/// Module updated to allow portability to the Lahey F77L EM/32
/// FORTRAN V 4.0 environment.
/// ```
pub fn txtopr(ctx: &mut SpiceContext, fname: &str, unit: &mut i32) -> crate::Result<()> {
TXTOPR(fname.as_bytes(), unit, ctx.raw_context())?;
ctx.handle_errors()?;
Ok(())
}
//$Procedure TXTOPR ( Text file, open for read )
pub fn TXTOPR(FNAME: &[u8], UNIT: &mut i32, ctx: &mut Context) -> f2rust_std::Result<()> {
let mut IOSTAT: i32 = 0;
//
// SPICELIB functions
//
//
// Local variables
//
//
// Standard SPICE error handling.
//
if RETURN(ctx) {
return Ok(());
} else {
CHKIN(b"TXTOPR", ctx)?;
}
if fstr::eq(FNAME, b" ") {
SETMSG(b"A blank string is unacceptable as a file name", ctx);
SIGERR(b"SPICE(BLANKFILENAME)", ctx)?;
CHKOUT(b"TXTOPR", ctx)?;
return Ok(());
}
GETLUN(UNIT, ctx)?;
{
use f2rust_std::io;
let specs = io::OpenSpecs {
unit: Some(*UNIT),
file: Some(FNAME),
form: Some(b"FORMATTED"),
access: Some(b"SEQUENTIAL"),
status: Some(b"OLD"),
..Default::default()
};
IOSTAT = io::capture_iostat(|| ctx.open(specs))?;
}
if (IOSTAT != 0) {
SETMSG(b"Could not open file #. IOSTAT was #. ", ctx);
ERRCH(b"#", FNAME, ctx);
ERRINT(b"#", IOSTAT, ctx);
SIGERR(b"SPICE(FILEOPENFAILED)", ctx)?;
CHKOUT(b"TXTOPR", ctx)?;
return Ok(());
}
CHKOUT(b"TXTOPR", ctx)?;
Ok(())
}