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
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
pub const NWC: i32 = 1024;
/// DAS, Fortran I/O, character
///
/// Perform Fortran reads and writes of DAS character records.
///
/// # Required Reading
///
/// * [DAS](crate::required_reading::das)
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// ACTION I Action to take (read or write).
/// UNIT I Fortran unit connected to DAS file.
/// RECNO I Number of record to read or write.
/// RECORD I-O DAS character record.
/// ```
///
/// # Detailed Input
///
/// ```text
/// ACTION is a character string specifying whether to read
/// from or write to the specified DAS file. Possible
/// values are:
///
/// 'READ'
/// 'WRITE'
///
/// Case and leading or trailing blanks are not
/// significant.
///
///
/// UNIT is the Fortran unit number connected to the DAS
/// file that is to be read or written. Given the
/// handle of the DAS file, the unit number can be
/// obtained using ZZDDHHLU.
///
/// RECNO is the Fortran record number of the record to be
/// read or written.
///
/// RECORD is a character array whose contents are to be
/// written to record RECNO, if ACTION is WRITE.
/// ```
///
/// # Detailed Output
///
/// ```text
/// RECORD is a character array whose contents are to be
/// set equal to those of record RECNO, if ACTION is
/// READ.
/// ```
///
/// # Parameters
///
/// ```text
/// NWC is the number of characters in a DAS character
/// record.
/// ```
///
/// # Exceptions
///
/// ```text
/// 1) If the value of ACTION is not recognized, the error
/// SPICE(UNRECOGNIZEDACTION) is signaled.
///
/// 2) If a Fortran read error occurs, the error
/// SPICE(DASFILEREADFAILED) is signaled.
///
/// 3) If a Fortran write error occurs, the error
/// SPICE(DASFILEWRITEFAILED) is signaled.
/// ```
///
/// # Files
///
/// ```text
/// See the description of the argument UNIT in $Detailed_Input.
/// ```
///
/// # Particulars
///
/// ```text
/// Normally, routines outside of SPICELIB will not need to call this
/// routine directly. Writes to DAS files should be performed using
/// the DASADx and DASUDx routines; reads should be performed using
/// the DASRDx routines.
///
/// This routines centralizes I/O and the concomitant error handling
/// for DAS character records.
///
/// Although most DAS routines use file handles to identify DAS
/// files, this routine uses Fortran logical units for this purpose.
/// Using unit numbers allows the DASIOx routines to be called from
/// any DAS routine, including entry points of DASFM. (DASFM
/// contains as entry points the routines DASHLU and DASLUH, which
/// map between handles and unit numbers.)
/// ```
///
/// # Examples
///
/// ```text
/// 1) Read and print to the screen character records number 10
/// through 20 from the DAS file designated by HANDLE.
///
/// CHARACTER*(NWC) RECORD
///
/// .
/// .
/// .
///
/// CALL ZZDDHHLU ( HANDLE, 'DAS', .FALSE., UNIT )
/// CALL DASHFN ( HANDLE, NAME )
///
/// DO I = 1, 20
///
/// CALL DASIOC ( 'READ', UNIT, 10, RECORD )
///
/// LABEL = 'Contents of the # record in DAS file #: '
///
/// CALL REPMOT ( LABEL, '#', I, 'L', LABEL )
/// CALL REPMC ( LABEL, '#', NAME, LABEL )
///
/// WRITE (*,*) LABEL
/// WRITE (*,*) ' '
/// WRITE (*,*) RECORD
///
/// END DO
///
///
///
/// 2) Write the contents of the string RECORD to record number
/// 10 in the DAS file designated by HANDLE.
///
///
/// CHARACTER*(NWC) RECORD
///
/// .
/// .
/// .
///
/// CALL ZZDDHHLU ( HANDLE, 'DAS', .FALSE., UNIT )
/// CALL DASIOC ( 'WRITE', UNIT, 10, RECORD )
/// ```
///
/// # Author and Institution
///
/// ```text
/// N.J. Bachman (JPL)
/// J. Diaz del Rio (ODC Space)
/// W.L. Taber (JPL)
/// ```
///
/// # Version
///
/// ```text
/// - SPICELIB Version 1.1.0, 12-AUG-2021 (JDR)
///
/// Added IMPLICIT NONE statement.
///
/// Edited the header to comply with NAIF standard.
///
/// - SPICELIB Version 1.0.1, 05-FEB-2015 (NJB)
///
/// Header was updated to refer to ZZDDHHLU.
///
/// - SPICELIB Version 1.0.0, 30-JUN-1992 (NJB) (WLT)
/// ```
pub fn dasioc(
ctx: &mut SpiceContext,
action: &str,
unit: i32,
recno: i32,
record: &mut [u8; 1024],
) -> crate::Result<()> {
DASIOC(action.as_bytes(), unit, recno, record, ctx.raw_context())?;
ctx.handle_errors()?;
Ok(())
}
//$Procedure DASIOC ( DAS, Fortran I/O, character )
pub fn DASIOC(
ACTION: &[u8],
UNIT: i32,
RECNO: i32,
RECORD: &mut [u8],
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let RECORD = &mut RECORD[..NWC as usize];
let mut IOSTAT: i32 = 0;
//
// SPICELIB functions
//
//
// Local variables
//
//
// Use discovery check-in.
//
if RETURN(ctx) {
return Ok(());
}
if EQSTR(ACTION, b"READ") {
//
// We're supposed to read the file.
//
{
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(RECORD)?;
reader.finish()?;
Ok(())
})?;
}
if (IOSTAT != 0) {
CHKIN(b"DASIOC", ctx)?;
SETMSG(
b"Could not read DAS character record. File = # Record number = #. IOSTAT = #.",
ctx,
);
ERRFNM(b"#", UNIT, ctx)?;
ERRINT(b"#", RECNO, ctx);
ERRINT(b"#", IOSTAT, ctx);
SIGERR(b"SPICE(DASFILEREADFAILED)", ctx)?;
CHKOUT(b"DASIOC", ctx)?;
return Ok(());
}
} else if EQSTR(ACTION, b"WRITE") {
//
// We're supposed to write to the file.
//
{
use f2rust_std::{
data::Val,
io::{self, Writer},
};
let mut writer = io::UnformattedWriter::new(ctx.io_unit(UNIT)?, Some(RECNO))?;
IOSTAT = io::capture_iostat(|| {
writer.start()?;
writer.write_str(RECORD)?;
writer.finish()?;
Ok(())
})?;
}
if (IOSTAT != 0) {
CHKIN(b"DASIOC", ctx)?;
SETMSG(
b"Could not write DAS character record. File = # Record number = #. IOSTAT = #.",
ctx,
);
ERRFNM(b"#", UNIT, ctx)?;
ERRINT(b"#", RECNO, ctx);
ERRINT(b"#", IOSTAT, ctx);
SIGERR(b"SPICE(DASFILEWRITEFAILED)", ctx)?;
CHKOUT(b"DASIOC", ctx)?;
return Ok(());
}
} else {
//
// The requested action is a little too weird.
//
CHKIN(b"DASIOC", ctx)?;
SETMSG(b"Action was #; should be READ or WRITE", ctx);
ERRCH(b"#", ACTION, ctx);
SIGERR(b"SPICE(UNRECOGNIZEDACTION)", ctx)?;
CHKOUT(b"DASIOC", ctx)?;
return Ok(());
}
Ok(())
}