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
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
pub const NWI: i32 = 256;
/// DAS, Fortran I/O, integer
///
/// Perform Fortran reads and writes of DAS integer records.
/// This routine operates on DAS files having native binary
/// format.
///
/// # 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 integer 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 an integer array whose contents are to be
/// written to record RECNO, if ACTION is WRITE.
/// ```
///
/// # Detailed Output
///
/// ```text
/// RECORD is an integer array whose contents are to be
/// set equal to those of record RECNO, if ACTION
/// is READ.
/// ```
///
/// # Parameters
///
/// ```text
/// NWI is the number of elements in a DAS integer 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
/// This routine may be used to write to and read from DAS files
/// having the native binary file format of the host system. The
/// routine ZZDASGDI should be used to read integer records from DAS
/// files that may have either native or non-native format.
///
/// 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 routine centralizes I/O and the concomitant error handling
/// for DAS integer 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.
/// ```
///
/// # Examples
///
/// ```text
/// 1) Read and print to the screen integer records number 10
/// through 20 from the DAS file designated by HANDLE.
///
/// INTEGER RECORD ( NWI )
/// .
/// .
/// .
///
/// CALL ZZDDHHLU ( HANDLE, 'DAS', .FALSE., UNIT )
/// CALL DASHFN ( HANDLE, NAME )
///
/// DO I = 1, 20
///
/// CALL DASIOI ( '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 array RECORD to record number
/// 10 in the DAS file designated by HANDLE.
///
///
/// INTEGER RECORD ( NWI )
///
/// .
/// .
/// .
///
/// CALL ZZDDHHLU ( HANDLE, 'DAS', .FALSE., UNIT )
/// CALL DASIOI ( 'WRITE', UNIT, 10, RECORD )
/// ```
///
/// # Restrictions
///
/// ```text
/// 1) This routine may be used only on DAS files having
/// the native binary file format of the host system.
/// ```
///
/// # 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. $Restrictions section
/// was updated.
///
/// - SPICELIB Version 1.0.0, 30-JUN-1992 (NJB) (WLT)
/// ```
pub fn dasioi(
ctx: &mut SpiceContext,
action: &str,
unit: i32,
recno: i32,
record: &mut [i32; 256],
) -> crate::Result<()> {
DASIOI(action.as_bytes(), unit, recno, record, ctx.raw_context())?;
ctx.handle_errors()?;
Ok(())
}
//$Procedure DASIOI ( DAS, Fortran I/O, integer )
pub fn DASIOI(
ACTION: &[u8],
UNIT: i32,
RECNO: i32,
RECORD: &mut [i32],
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let mut RECORD = DummyArrayMut::new(RECORD, 1..=NWI);
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()?;
for n in RECORD.iter_mut() {
*n = reader.read_i32()?;
}
reader.finish()?;
Ok(())
})?;
}
if (IOSTAT != 0) {
CHKIN(b"DASIOI", ctx)?;
SETMSG(
b"Could not read DAS integer 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"DASIOI", 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()?;
for n in RECORD.iter() {
writer.write_i32(*n)?;
}
writer.finish()?;
Ok(())
})?;
}
if (IOSTAT != 0) {
CHKIN(b"DASIOI", ctx)?;
SETMSG(
b"Could not write DAS integer 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"DASIOI", ctx)?;
return Ok(());
}
} else {
//
// The requested action is a little too weird.
//
CHKIN(b"DASIOI", ctx)?;
SETMSG(b"Action was #; should be READ or WRITE", ctx);
ERRCH(b"#", ACTION, ctx);
SIGERR(b"SPICE(UNRECOGNIZEDACTION)", ctx)?;
CHKOUT(b"DASIOI", ctx)?;
return Ok(());
}
Ok(())
}