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
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
/// Read a text line from a logical unit
///
/// Read a single line of text from the Fortran logical unit UNIT,
/// reporting the end of file if it occurs.
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// UNIT I The Fortran unit number to use for input.
/// LINE O The line read from the file.
/// EOF O A logical flag indicating the end of file.
/// ```
///
/// # Detailed Input
///
/// ```text
/// UNIT is the Fortran unit number for the input. This may
/// be either the unit number for the terminal, or the
/// unit number of a previously opened text file.
/// ```
///
/// # Detailed Output
///
/// ```text
/// LINE is the next text line encountered when reading from UNIT.
///
/// If the length of the character string LINE is shorter
/// than the length of the current line in the text file, the
/// line is truncated on the right by the Fortran READ
/// statement, filling LINE with the first LEN(LINE)
/// characters from the current line in the file.
///
/// If an error or the end of file occurs during the
/// attempt to read from UNIT, the value of this variable
/// is not guaranteed.
///
/// EOF is .TRUE. if the end of file ( IOSTAT < 0 ) is
/// encountered during the attempt to read from unit UNIT.
/// Otherwise, this variable will be set to .FALSE.
/// ```
///
/// # Exceptions
///
/// ```text
/// This routine only checks in with the error handler in the event
/// that an error occurred. (Discovery check in)
///
/// 1) If an error occurs while attempting to read from the text file
/// attached to UNIT, the error SPICE(FILEREADFAILED) is signaled.
/// ```
///
/// # Particulars
///
/// ```text
/// This routine will read a single line, a text record, from the
/// logical unit UNIT. UNIT may be the terminal, or it may be a
/// logical unit number obtained from a Fortran OPEN or INQUIRE
/// statement. This routine will set a logical flag, EOF, on output
/// if the end of the file is encountered during the read attempt.
/// ```
///
/// # Examples
///
/// ```text
/// CALL READLN ( UNIT, LINE, EOF )
///
/// IF ( EOF ) THEN
/// < The end of file, deal with it appropriately >
/// END IF
///
/// You now have a line of text from unit UNIT.
/// ```
///
/// # Author and Institution
///
/// ```text
/// J. Diaz del Rio (ODC Space)
/// K.R. Gehringer (JPL)
/// ```
///
/// # Version
///
/// ```text
/// - SPICELIB Version 1.1.0, 12-AUG-2021 (JDR)
///
/// Added IMPLICIT NONE statement.
///
/// Edited the header to comply with NAIF standard. Removed
/// unnecessary $Version history entries for Beta versions.
///
/// - SPICELIB Version 1.0.0, 20-DEC-1995 (KRG)
/// ```
pub fn readln(
ctx: &mut SpiceContext,
unit: i32,
line: &mut str,
eof: &mut bool,
) -> crate::Result<()> {
READLN(
unit,
fstr::StrBytes::new(line).as_mut(),
eof,
ctx.raw_context(),
)?;
ctx.handle_errors()?;
Ok(())
}
//$Procedure READLN ( Read a text line from a logical unit )
pub fn READLN(
UNIT: i32,
LINE: &mut [u8],
EOF: &mut bool,
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let mut IOSTAT: i32 = 0;
//
// Local variables
//
//
// Standard SPICE error handling.
//
//
// Read in the next line from the text file attached to UNIT.
//
{
use f2rust_std::{
data::Val,
io::{self, Reader},
};
let mut reader = io::FormattedReader::new(ctx.io_unit(UNIT)?, None, b"(A)")?;
IOSTAT = io::capture_iostat(|| {
reader.start()?;
reader.read_str(LINE)?;
reader.finish()?;
Ok(())
})?;
}
//
// Check to see if we got a read error, and signal it if we did.
//
if (IOSTAT > 0) {
CHKIN(b"READLN", ctx)?;
SETMSG(b"Error reading from file: #. IOSTAT = #.", ctx);
ERRFNM(b"#", UNIT, ctx)?;
ERRINT(b"#", IOSTAT, ctx);
SIGERR(b"SPICE(FILEREADFAILED)", ctx)?;
CHKOUT(b"READLN", ctx)?;
return Ok(());
}
//
// Check to see if we got the end of file, and set the logical
// flag EOF if we did.
//
if (IOSTAT < 0) {
*EOF = true;
} else {
*EOF = false;
}
Ok(())
}