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
//
// GENERATED FILE
//
use super::*;
use f2rust_std::*;
const FTSIZE: i32 = 5000;
const RSVUNT: i32 = 2;
const SCRUNT: i32 = 1;
const UTSIZE: i32 = ((20 + SCRUNT) + RSVUNT);
const READ: i32 = 1;
const WRITE: i32 = 2;
const SCRTCH: i32 = 3;
const NEW: i32 = 4;
const NUMAMH: i32 = 4;
const BIGI3E: i32 = 1;
const LTLI3E: i32 = 2;
const VAXGFL: i32 = 3;
const VAXDFL: i32 = 4;
const NUMBFF: i32 = 4;
const STRSIZ: i32 = 8;
const STRLEN: i32 = ((STRSIZ + 1) * NUMBFF);
const DAF: i32 = 1;
const DAS: i32 = 2;
const NUMARC: i32 = 2;
const RECL: i32 = 1024;
const FILEN: i32 = 255;
const CBFSIZ: i32 = 1024;
//$Procedure ZZDDHGTU ( Private --- DDH Get Unit )
pub fn ZZDDHGTU(
UTCST: &mut [i32],
UTHAN: &mut [i32],
UTLCK: &mut [bool],
UTLUN: &mut [i32],
NUT: &mut i32,
UINDEX: &mut i32,
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let mut UTCST = DummyArrayMut::new(UTCST, 1..);
let mut UTHAN = DummyArrayMut::new(UTHAN, 1..);
let mut UTLCK = DummyArrayMut::new(UTLCK, 1..);
let mut UTLUN = DummyArrayMut::new(UTLUN, 1..);
let mut I: i32 = 0;
let mut ORDERV = StackArray::<i32, 23>::new(1..=UTSIZE);
let mut DONE: bool = false;
//
// SPICELIB Functions
//
//
// Local Variables
//
//
// Standard SPICE discovery error handling.
//
if RETURN(ctx) {
return Ok(());
}
//
// First check the case when the unit table is completely empty.
//
if (*NUT == 0) {
*NUT = 1;
*UINDEX = 1;
UTCST[*UINDEX] = 0;
UTHAN[*UINDEX] = 0;
UTLCK[*UINDEX] = false;
GETLUN(&mut UTLUN[*UINDEX], ctx)?;
//
// Check FAILED to see if GETLUN signaled an error. If so, then
// return an invalid unit to the caller.
//
if FAILED(ctx) {
UTLUN[*UINDEX] = -1;
return Ok(());
}
//
// If we end up here, then GETLUN succeeded and we have the new
// unit. Now return.
//
return Ok(());
}
//
// If we reach here, then the table contains at least one entry.
// Order the table rows by cost.
//
ORDERI(UTCST.as_slice(), *NUT, ORDERV.as_slice_mut());
//
// Now check to for '0' cost rows as this indicates rows whose
// logical units are reserved for this suite of routines usage,
// but are not currently assigned a file.
//
if (UTCST[ORDERV[1]] <= 0) {
*UINDEX = ORDERV[1];
//
// '0' cost rows end up in the unit table as the result of a
// row deletion, occurring when excess files are present.
// When this process occurs, the logical unit listed in this
// row is reserved for this module's usage only with RESLUN.
// Free it, since we're about to reassign it.
//
FRELUN(UTLUN[*UINDEX], ctx);
return Ok(());
}
//
// Now if no '0' cost rows exist, check to see if we can
// expand the table.
//
if (*NUT < UTSIZE) {
//
// Now increment NUT and set UINDEX.
//
*NUT = (*NUT + 1);
*UINDEX = *NUT;
//
// Prepare the default values for the new row.
//
UTCST[*UINDEX] = 0;
UTHAN[*UINDEX] = 0;
UTLCK[*UINDEX] = false;
GETLUN(&mut UTLUN[*UINDEX], ctx)?;
//
// Check FAILED to see if GETLUN signaled an error. If so, then
// return an invalid unit to the caller.
//
if FAILED(ctx) {
UTLUN[*UINDEX] = -1;
return Ok(());
}
//
// If we end up here, then GETLUN worked properly. Now return.
//
return Ok(());
}
//
// If we reach here, then we have no zero-cost rows and a full unit
// table. Now it's time to determine which entry in the table to
// bump. We do this by stepping through the order vector until
// we find the first 'non-locked' row.
//
I = 0;
DONE = false;
while (!DONE && (I != *NUT)) {
I = (I + 1);
DONE = !UTLCK[ORDERV[I]];
}
//
// Before going any further, signal an error if we discover
// we have not found a row.
//
if !DONE {
*UINDEX = 0;
CHKIN(b"ZZDDHGTU", ctx)?;
SETMSG(b"The unit table is full and all entries are locked. This should never happen. Contact NAIF.", ctx);
SIGERR(b"SPICE(BUG)", ctx)?;
CHKOUT(b"ZZDDHGTU", ctx)?;
return Ok(());
}
//
// Clear UTCST and UTHAN since we intend to disconnect
// the unit upon return.
//
UTCST[ORDERV[I]] = 0;
UTHAN[ORDERV[I]] = 0;
//
// Set UINDEX and CLSLUN, then return.
//
*UINDEX = ORDERV[I];
//
// At this point we need to close the unit from the row of interest.
//
{
use f2rust_std::io;
let specs = io::CloseSpecs {
unit: Some(UTLUN[*UINDEX]),
..Default::default()
};
ctx.close(specs)?;
}
Ok(())
}