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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
//
// GENERATED FILE
//
use super::*;
use f2rust_std::*;
//$Procedure T_BGODAF ( BINGO: Process DAF files to alternate BFFs )
pub fn T_BGODAF(
INAME: &[u8],
ONAME: &[u8],
OBFF: i32,
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let mut CREC = [b' '; 1024 as usize];
let mut IDWORD = [b' '; 8 as usize];
let mut IFNAME = [b' '; 60 as usize];
let mut DPREC = StackArray::<f64, 128>::new(1..=128);
let mut BWARD: i32 = 0;
let mut FREE: i32 = 0;
let mut FWARD: i32 = 0;
let mut I: i32 = 0;
let mut INHAN: i32 = 0;
let mut INUNIT: i32 = 0;
let mut IOSTAT: i32 = 0;
let mut ND: i32 = 0;
let mut NI: i32 = 0;
let mut NXTDSC: i32 = 0;
let mut STPREC: i32 = 0;
let mut UNIT: i32 = 0;
let mut WORD: i32 = 0;
let mut FOUND: bool = false;
//
// SPICELIB Functions
//
//
// Local Variables
//
//
// Standard SPICE error handling
//
if spicelib::RETURN(ctx) {
return Ok(());
} else {
spicelib::CHKIN(b"T_BGODAF", ctx)?;
}
//
// Open INAME for read access.
//
spicelib::DAFOPR(INAME, &mut INHAN, ctx)?;
//
// Create ONAME.
//
T_DAFOPN(ONAME, OBFF, &mut UNIT, ctx)?;
//
// Read INAME's file record, we need everything so use the very low
// level reader.
//
spicelib::ZZDAFGFR(
INHAN,
&mut IDWORD,
&mut ND,
&mut NI,
&mut IFNAME,
&mut FWARD,
&mut BWARD,
&mut FREE,
&mut FOUND,
ctx,
)?;
if !FOUND {
spicelib::DAFCLS(INHAN, ctx)?;
testutil::KILFIL(ONAME, ctx)?;
spicelib::SETMSG(b"Unable to find file record.", ctx);
spicelib::SIGERR(b"SPICE(DAFREADFAILURE)", ctx)?;
spicelib::CHKOUT(b"T_BGODAF", ctx)?;
return Ok(());
}
//
// Dump the file record into ONAME. We add the FTP string
// regardless... all new toolkits create files with the FTP
// string.
//
T_DAFWFR(
UNIT, OBFF, &IDWORD, ND, NI, &IFNAME, FWARD, BWARD, FREE, true, ctx,
)?;
//
// Now just copy all the records between the file record and
// FWARD. This is valid at the moment for all supported
// platforms, but may need to change in the future.
//
spicelib::ZZDDHHLU(INHAN, b"DAF", false, &mut INUNIT, ctx)?;
{
let m1__: i32 = 2;
let m2__: i32 = (FWARD - 1);
let m3__: i32 = 1;
I = m1__;
for _ in 0..((m2__ - m1__ + m3__) / m3__) as i32 {
{
use f2rust_std::{
data::Val,
io::{self, Reader},
};
let mut reader = io::UnformattedReader::new(ctx.io_unit(INUNIT)?, Some(I))?;
IOSTAT = io::capture_iostat(|| {
reader.start()?;
reader.read_str(&mut CREC)?;
reader.finish()?;
Ok(())
})?;
}
if (IOSTAT != 0) {
spicelib::DAFCLS(INHAN, ctx)?;
testutil::KILFIL(ONAME, ctx)?;
spicelib::SETMSG(b"Unable to read comment record, #.", ctx);
spicelib::ERRINT(b"#", I, ctx);
spicelib::SIGERR(b"SPICE(DAFREADFAILURE)", ctx)?;
spicelib::CHKOUT(b"T_BGODAF", ctx)?;
return Ok(());
}
{
use f2rust_std::{
data::Val,
io::{self, Writer},
};
let mut writer = io::UnformattedWriter::new(ctx.io_unit(UNIT)?, Some(I))?;
IOSTAT = io::capture_iostat(|| {
writer.start()?;
writer.write_str(&CREC)?;
writer.finish()?;
Ok(())
})?;
}
if (IOSTAT != 0) {
spicelib::DAFCLS(INHAN, ctx)?;
testutil::KILFIL(ONAME, ctx)?;
spicelib::SETMSG(b"Unable to write comment record, #.", ctx);
spicelib::ERRINT(b"#", I, ctx);
spicelib::SIGERR(b"SPICE(DAFWRITEFAILURE)", ctx)?;
spicelib::CHKOUT(b"T_BGODAF", ctx)?;
return Ok(());
}
I += m3__;
}
}
//
// Now process the summary, name, and data records. The record
// FREE points to is the last record to be processed.
//
spicelib::DAFARW(FREE, &mut STPREC, &mut WORD, ctx)?;
I = FWARD;
NXTDSC = FWARD;
while (I < STPREC) {
//
// See if the record we are currently processing is a
// descriptor record.
//
if (I == NXTDSC) {
spicelib::ZZDAFGSR(INHAN, I, ND, NI, DPREC.as_slice_mut(), &mut FOUND, ctx)?;
if !FOUND {
spicelib::DAFCLS(INHAN, ctx)?;
testutil::KILFIL(ONAME, ctx)?;
spicelib::SETMSG(b"Unable to read summary record, #.", ctx);
spicelib::ERRINT(b"#", I, ctx);
spicelib::SIGERR(b"SPICE(DAFREADFAILURE)", ctx)?;
spicelib::CHKOUT(b"T_BGODAF", ctx)?;
return Ok(());
}
NXTDSC = (DPREC[1] as i32);
T_DAFWSR(
UNIT,
I,
OBFF,
ND,
NI,
(DPREC[1] as i32),
(DPREC[2] as i32),
(DPREC[3] as i32),
DPREC.subarray(4),
ctx,
)?;
//
// Every summary record is followed by a name record...
//
I = (I + 1);
{
use f2rust_std::{
data::Val,
io::{self, Reader},
};
let mut reader = io::UnformattedReader::new(ctx.io_unit(INUNIT)?, Some(I))?;
IOSTAT = io::capture_iostat(|| {
reader.start()?;
reader.read_str(&mut CREC)?;
reader.finish()?;
Ok(())
})?;
}
if (IOSTAT != 0) {
spicelib::DAFCLS(INHAN, ctx)?;
testutil::KILFIL(ONAME, ctx)?;
spicelib::SETMSG(b"Unable to read name record, #.", ctx);
spicelib::ERRINT(b"#", I, ctx);
spicelib::SIGERR(b"SPICE(DAFREADFAILURE)", ctx)?;
spicelib::CHKOUT(b"T_BGODAF", ctx)?;
return Ok(());
}
{
use f2rust_std::{
data::Val,
io::{self, Writer},
};
let mut writer = io::UnformattedWriter::new(ctx.io_unit(UNIT)?, Some(I))?;
IOSTAT = io::capture_iostat(|| {
writer.start()?;
writer.write_str(&CREC)?;
writer.finish()?;
Ok(())
})?;
}
if (IOSTAT != 0) {
spicelib::DAFCLS(INHAN, ctx)?;
testutil::KILFIL(ONAME, ctx)?;
spicelib::SETMSG(b"Unable to write name record, #.", ctx);
spicelib::ERRINT(b"#", I, ctx);
spicelib::SIGERR(b"SPICE(DAFWRITEFAILURE)", ctx)?;
spicelib::CHKOUT(b"T_BGODAF", ctx)?;
return Ok(());
}
//
// Otherwise we are dealing with a data record.
//
} else {
spicelib::ZZDAFGDR(INHAN, I, DPREC.as_slice_mut(), &mut FOUND, ctx)?;
if !FOUND {
spicelib::DAFCLS(INHAN, ctx)?;
testutil::KILFIL(ONAME, ctx)?;
spicelib::SETMSG(b"Unable to read data record, #.", ctx);
spicelib::ERRINT(b"#", I, ctx);
spicelib::SIGERR(b"SPICE(DAFREADFAILURE)", ctx)?;
spicelib::CHKOUT(b"T_BGODAF", ctx)?;
return Ok(());
}
T_DAFWDR(UNIT, I, OBFF, 128, DPREC.as_slice(), ctx)?;
}
//
// Next record.
//
I = (I + 1);
}
//
// Process the last data record, only translate up to (FREE-1)'s
// address.
//
spicelib::ZZDAFGDR(INHAN, STPREC, DPREC.as_slice_mut(), &mut FOUND, ctx)?;
//
// Do not worry if STPREC was not found, it is possible (but
// very unlikely) that FREE points to a record that has yet
// to be created.
//
if FOUND {
T_DAFWDR(UNIT, I, OBFF, (WORD - 1), DPREC.as_slice(), ctx)?;
}
//
// Clean up.
//
spicelib::DAFCLS(INHAN, ctx)?;
//
// Check FAILED() in case something has gone awry. If it has delete
// ONAME.
//
if spicelib::FAILED(ctx) {
testutil::KILFIL(ONAME, ctx)?;
} else {
{
use f2rust_std::io;
let specs = io::CloseSpecs {
unit: Some(UNIT),
..Default::default()
};
ctx.close(specs)?;
}
}
spicelib::CHKOUT(b"T_BGODAF", ctx)?;
Ok(())
}