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
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
pub const FILEN: i32 = 128;
/// Insert filename into long error message text
///
/// Substitute the first occurrence of a marker in the current long
/// error message with the name of the file attached to the logical
/// unit number.
///
/// # Required Reading
///
/// * [ERROR](crate::required_reading::error)
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// MARKER I A substring in the error message that is to be
/// replaced.
/// UNIT I Logical unit number attached to a file.
/// FILEN P Maximum length of filename.
/// ```
///
/// # Detailed Input
///
/// ```text
/// MARKER is a character string which marks a position in
/// the long error message where a character string
/// is to be substituted. Leading and trailing blanks
/// in MARKER are not significant.
///
/// Case IS significant; 'XX' is considered to be
/// a different marker from 'xx'.
///
/// UNIT is the logical unit number attached to a file.
/// ```
///
/// # Parameters
///
/// ```text
/// FILEN is the maximum file name length that can be
/// accommodated by this routine.
/// ```
///
/// # Exceptions
///
/// ```text
/// Error free.
///
/// 1) If the logical unit number is not attached to a file, the
/// string inserted into the long error message is:
///
/// '<unavailable from the system>'
///
/// 2) If the FORTRAN INQUIRE statement fails to execute properly,
/// the string inserted into the long error message is:
///
/// '<unavailable from the system>'
/// ```
///
/// # Files
///
/// ```text
/// See "Detailed_Input" description of the variable UNIT.
/// ```
///
/// # Examples
///
/// ```text
/// 1. The following code fragment reads a record from a file
/// then checks to see if the read was successful. If the
/// read failed, an error message is constructed that
/// specifies the record number, the filename and the value
/// of IOSTAT.
///
/// ERRFNM is used to replace the marker in the long error
/// message with the name of the file.
///
///
/// READ ( UNIT, REC=RECNUM, IOSTAT=IOSTAT ) RECORD
///
/// IF ( IOSTAT .NE. 0 ) THEN
///
/// CALL SETMSG ( 'Error reading record number # from ' //
/// . 'file FILENAME. The value of IOSTAT ' //
/// . 'was #.' )
///
/// CALL ERRINT ( '#', RECNUM )
/// CALL ERRFNM ( 'FILENAME', UNIT )
/// CALL ERRINT ( '#', IOSTAT )
/// CALL SIGERR ( 'SPICE(READFAILURE)' )
/// CALL CHKOUT ( 'SAMPLE' )
/// RETURN
///
/// END IF
///
///
/// If the unit is attached to the file SAMPLE.DAT, RECNUM
/// is 15 and IOSTAT is 36, and the INQUIRE statement in
/// this routine executed successfully, the long error
/// message is:
///
/// 'Error reading record number 15 from file SAMPLE.DAT.
/// The value of IOSTAT was 36.'
///
///
/// If the unit is not attached to a file or if the INQUIRE
/// statement in this routine failed to execute successfully,
/// the long error message is:
///
/// 'Error reading record number 15 from file
/// <unavailable from the system>. The value of IOSTAT
/// was 36.'
///
///
/// 2. Note that the case of the marker is significant. The following
/// code fragment contains a call to ERRFNM using a marker
/// that does not appear in the long error message.
///
///
/// READ ( UNIT, REC=RECNUM, IOSTAT=IOSTAT ) RECORD
///
/// IF ( IOSTAT .NE. 0 ) THEN
///
/// CALL SETMSG ( 'Error reading record number # from ' //
/// . 'file FILENAME. The value of IOSTAT ' //
/// . 'was #.' )
///
/// CALL ERRINT ( '#', RECNUM )
/// CALL ERRFNM ( 'filename', UNIT )
/// CALL ERRINT ( '#', IOSTAT )
/// CALL SIGERR ( 'SPICE(READFAILURE)' )
/// CALL CHKOUT ( 'SAMPLE' )
/// RETURN
///
/// END IF
///
///
/// If the marker is not found, ERRFNM does not substitute
/// the filename for the marker. The long error message in
/// this case is:
///
/// 'Error reading record number 15 from file FILENAME.
/// The value of IOSTAT was 36.'
/// ```
///
/// # Restrictions
///
/// ```text
/// 1) The filename length is restricted by the parameter FILEN.
/// ```
///
/// # Author and Institution
///
/// ```text
/// J. Diaz del Rio (ODC Space)
/// H.A. Neilan (JPL)
/// W.L. Taber (JPL)
/// ```
///
/// # Version
///
/// ```text
/// - SPICELIB Version 1.1.0, 02-JUN-2021 (JDR)
///
/// Added IMPLICIT NONE statement.
///
/// Edited the header to comply with NAIF standard.
///
/// - SPICELIB Version 1.0.1, 10-MAR-1992 (WLT)
///
/// Comment section for permuted index source lines was added
/// following the header.
///
/// - SPICELIB Version 1.0.0, 05-APR-1991 (HAN)
/// ```
pub fn errfnm(ctx: &mut SpiceContext, marker: &str, unit: i32) -> crate::Result<()> {
ERRFNM(marker.as_bytes(), unit, ctx.raw_context())?;
ctx.handle_errors()?;
Ok(())
}
//$Procedure ERRFNM ( Insert filename into long error message text )
pub fn ERRFNM(MARKER: &[u8], UNIT: i32, ctx: &mut Context) -> f2rust_std::Result<()> {
let mut NAME = [b' '; FILEN as usize];
let mut IOSTAT: i32 = 0;
//
// Local variables
//
//
// Initialize the variables.
//
fstr::assign(&mut NAME, b" ");
//
// Get the name of the file attached to the logical unit number.
//
{
use f2rust_std::io;
let specs = io::InquireSpecs {
unit: Some(UNIT),
name: Some(&mut NAME),
..Default::default()
};
IOSTAT = io::capture_iostat(|| ctx.inquire(specs))?;
}
//
// If the INQUIRE statement executed successfully and the unit
// was attached to a file, we have a filename.
//
// If the INQUIRE statement didn't execute successfully the value
// of IOSTAT is not equal to zero. If the unit is not connected to
// a file the filename is blank. If either of these two things
// are true, we must construct a string indicating that the
// filename was unavailable from the system.
//
if ((IOSTAT != 0) || fstr::eq(&NAME, b" ")) {
fstr::assign(&mut NAME, b"<unavailable from the system>");
}
//
// Let the error handling routine take it from here.
//
ERRCH(MARKER, &NAME, ctx);
Ok(())
}