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
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
/// DAF, read character record
///
/// Read the contents of a character record from a DAF.
///
/// # Required Reading
///
/// * [DAF](crate::required_reading::daf)
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// HANDLE I Handle of DAF.
/// RECNO I Record number of character record.
/// CREC O Character record.
/// ```
///
/// # Detailed Input
///
/// ```text
/// HANDLE is the handle associated with a DAF.
///
/// RECNO is the record number of a character record within
/// the file.
/// ```
///
/// # Detailed Output
///
/// ```text
/// CREC contains the first 1000 characters of the specified
/// record from the specified file.
/// ```
///
/// # Exceptions
///
/// ```text
/// 1) If the declared length of CREC is not 1000 characters,
/// the error SPICE(DAFBADRECLEN) is signaled.
///
/// 2) If the specified record cannot (for some reason) be read,
/// the error SPICE(DAFCRNOTFOUND) is signaled.
/// ```
///
/// # Particulars
///
/// ```text
/// Unlike double precision records, character records are
/// not buffered. Also, while failing to find a specific double
/// precision record is indicated through the calling sequence,
/// failing to find a character record results in an error.
/// ```
///
/// # Examples
///
/// ```text
/// In the following example, matching summary and name records are
/// read from a DAF:
///
/// CALL DAFGDR ( HANDLE, NEXT, DREC, FOUND )
/// CALL DAFRCR ( HANDLE, NEXT+1, CREC )
///
/// Note that a character record always immediately follows a summary
/// record.
/// ```
///
/// # Restrictions
///
/// ```text
/// 1) This routine is only used to read records on environments
/// whose characters are a single byte in size. Updates
/// to this routine and routines in its call tree may be
/// required to properly handle other cases.
/// ```
///
/// # Author and Institution
///
/// ```text
/// J. Diaz del Rio (ODC Space)
/// H.A. Neilan (JPL)
/// W.L. Taber (JPL)
/// F.S. Turner (JPL)
/// I.M. Underwood (JPL)
/// ```
///
/// # Version
///
/// ```text
/// - SPICELIB Version 2.1.0, 17-JUN-2021 (JDR)
///
/// Added IMPLICIT NONE statement.
///
/// Edited the header to comply with NAIF standard. Moved DAF
/// required reading from $Literature_References to
/// $Required_Reading section.
///
/// - SPICELIB Version 2.0.0, 16-NOV-2001 (FST)
///
/// Updated this routine to make proper use of the new
/// handle manager functionality installed underneath
/// DAF.
///
/// - SPICELIB Version 1.0.2, 10-MAR-1992 (WLT)
///
/// Comment section for permuted index source lines was added
/// following the header.
///
/// - SPICELIB Version 1.0.1, 22-MAR-1990 (HAN)
///
/// Literature references added to the header.
///
/// - SPICELIB Version 1.0.0, 31-JAN-1990 (IMU)
/// ```
///
/// # Revisions
///
/// ```text
/// - SPICELIB Version 2.0.0, 16-NOV-2001 (FST)
///
/// This routine now makes use of the handle manager
/// code. A call to DAFSIH was inserted just after
/// the standard SPICE error handling code at the
/// head of the module. This was done to insure that
/// the caller is referring to a legitimately loaded
/// DAF. The penalty for performing this check is
/// a binary search on the number of loaded files,
/// which should be small compared to the actual READ
/// performed below.
///
/// The call to DAFHLU has been replaced with ZZDDHHLU,
/// since calls to DAFHLU locks handles to their logical
/// units.
/// ```
pub fn dafrcr(
ctx: &mut SpiceContext,
handle: i32,
recno: i32,
crec: &mut str,
) -> crate::Result<()> {
DAFRCR(
handle,
recno,
fstr::StrBytes::new(crec).as_mut(),
ctx.raw_context(),
)?;
ctx.handle_errors()?;
Ok(())
}
//$Procedure DAFRCR ( DAF, read character record )
pub fn DAFRCR(
HANDLE: i32,
RECNO: i32,
CREC: &mut [u8],
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let mut UNIT: i32 = 0;
let mut IOSTAT: i32 = 0;
//
// SPICELIB functions
//
//
// Local variables
//
//
// Standard SPICE error handling.
//
if RETURN(ctx) {
return Ok(());
} else {
CHKIN(b"DAFRCR", ctx)?;
}
//
// Check to be sure that HANDLE is attached to a file that is open
// with read access. If the call fails, check out and return.
//
DAFSIH(HANDLE, b"READ", ctx)?;
if FAILED(ctx) {
CHKOUT(b"DAFRCR", ctx)?;
return Ok(());
}
//
// Now make certain that the string to receive the contents of
// the character record is the appropriate length.
//
if (intrinsics::LEN(CREC) != 1000) {
SETMSG(
b"Expected length of character record is 1000. Passed string has length #",
ctx,
);
ERRINT(b"#", intrinsics::LEN(CREC), ctx);
SIGERR(b"SPICE(DAFBADCRECLEN)", ctx)?;
} else {
//
// Retrieve a logical unit for this handle. This has the
// side-effect of locking this UNIT to HANDLE.
//
ZZDDHHLU(HANDLE, b"DAF", false, &mut UNIT, ctx)?;
if FAILED(ctx) {
CHKOUT(b"DAFRCR", ctx)?;
return Ok(());
}
{
use f2rust_std::{
data::Val,
io::{self, Reader},
};
let mut reader = io::UnformattedReader::new(ctx.io_unit(UNIT)?, Some(RECNO))?;
IOSTAT = io::capture_iostat(|| {
reader.start()?;
reader.read_str(CREC)?;
reader.finish()?;
Ok(())
})?;
}
if (IOSTAT != 0) {
SETMSG(b"Could not read record #. IOSTAT was #.", ctx);
ERRINT(b"#", RECNO, ctx);
ERRINT(b"#", IOSTAT, ctx);
SIGERR(b"SPICE(DAFCRNOTFOUND)", ctx)?;
}
}
CHKOUT(b"DAFRCR", ctx)?;
Ok(())
}