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
//
// GENERATED FILE
//
use super::*;
use f2rust_std::*;
const WDSIZE: i32 = 32;
const LBCELL: i32 = -5;
const MAXIDS: i32 = 10;
struct SaveVars {
DTSIZE: StackArray<i32, 7>,
KNOWN: StackArray<i32, 16>,
PASSED: StackArray<i32, 16>,
FIRST: bool,
}
impl SaveInit for SaveVars {
fn new() -> Self {
let mut DTSIZE = StackArray::<i32, 7>::new(1..=7);
let mut KNOWN = StackArray::<i32, 16>::new(LBCELL..=MAXIDS);
let mut PASSED = StackArray::<i32, 16>::new(LBCELL..=MAXIDS);
let mut FIRST: bool = false;
FIRST = true;
Self {
DTSIZE,
KNOWN,
PASSED,
FIRST,
}
}
}
//$Procedure ZZSCLK ( Is there and SCLK for a CKID )
pub fn ZZSCLK(CKID: i32, SCLKID: i32, ctx: &mut Context) -> f2rust_std::Result<bool> {
let save = ctx.get_vars::<SaveVars>();
let save = &mut *save.borrow_mut();
let mut ZZSCLK: bool = false;
let mut SCLK = [b' '; WDSIZE as usize];
let mut SCLKVR = ActualCharArray::new(WDSIZE, 1..=7);
let mut TYPE = [b' '; WDSIZE as usize];
let mut AGENT = [b' '; WDSIZE as usize];
let mut N: i32 = 0;
let mut KEEPID: bool = false;
let mut UPDATE: bool = false;
let mut WATCH: bool = false;
let mut FOUND: bool = false;
// SPICELIB Functions
//
//
// Local Variables
//
ZZSCLK = false;
//
// Standard SPICE error handling.
//
if RETURN(ctx) {
return Ok(ZZSCLK);
}
CHKIN(b"ZZSCLK", ctx)?;
if save.FIRST {
save.FIRST = false;
save.DTSIZE[1] = 1;
save.DTSIZE[2] = 1;
save.DTSIZE[3] = 1;
save.DTSIZE[4] = 1;
save.DTSIZE[5] = 3;
save.DTSIZE[6] = 1;
save.DTSIZE[7] = 1;
SSIZEI(MAXIDS, save.KNOWN.as_slice_mut(), ctx)?;
SSIZEI(MAXIDS, save.PASSED.as_slice_mut(), ctx)?;
}
//
// We've got a text kernel (or meta kernel). See if there is an
// SCLK kernel loaded for the CKID provided in the calling inputs.
// If not, we'll use the default -CKID/1000 for the SCLK ID.
//
INTSTR(-SCLKID, &mut SCLK, ctx);
fstr::assign(&mut AGENT, &fstr::concat(b"ZZSCLK", &SCLK));
//
// See if this is an ID-code we've encountered before. If it
// is we can make use of stored knowledge about this ID-code.
//
if ELEMI(SCLKID, save.KNOWN.as_slice(), ctx)? {
WATCH = false;
KEEPID = true;
CVPOOL(&AGENT, &mut UPDATE, ctx)?;
} else if (CARDI(save.KNOWN.as_slice(), ctx)? < SIZEI(save.KNOWN.as_slice(), ctx)?) {
//
// The SCLKID specified is not in the list of SCLKIDs for
// this routine and there is room left in the pool of
// SCLKIDs to keep track of one more. Put this ID into
// the list of known IDS
//
INSRTI(SCLKID, save.KNOWN.as_slice_mut(), ctx)?;
UPDATE = true;
WATCH = true;
KEEPID = true;
} else {
UPDATE = true;
KEEPID = false;
WATCH = false;
}
if !UPDATE {
//
// Nothing has changed in the kernel pool w.r.t this agent.
// The test for an SCLK will not have changed either.
//
ZZSCLK = ELEMI(SCLKID, save.PASSED.as_slice(), ctx)?;
CHKOUT(b"ZZSCLK", ctx)?;
return Ok(ZZSCLK);
}
//
// If we are still here, we need to look in the kernel pool
// to see if we have an SCLK for this object.
//
// Construct all of the expected SCLK variables are
// available for this SCLK.
//
fstr::assign(SCLKVR.get_mut(1), &fstr::concat(b"SCLK_DATA_TYPE_", &SCLK));
fstr::assign(SCLKVR.get_mut(2), &fstr::concat(b"SCLK01_N_FIELDS_", &SCLK));
fstr::assign(SCLKVR.get_mut(3), &fstr::concat(b"SCLK01_MODULI_", &SCLK));
fstr::assign(SCLKVR.get_mut(4), &fstr::concat(b"SCLK01_OFFSETS_", &SCLK));
fstr::assign(
SCLKVR.get_mut(5),
&fstr::concat(b"SCLK01_COEFFICIENTS_", &SCLK),
);
fstr::assign(
SCLKVR.get_mut(6),
&fstr::concat(b"SCLK_PARTITION_START_", &SCLK),
);
fstr::assign(
SCLKVR.get_mut(7),
&fstr::concat(b"SCLK_PARTITION_END_", &SCLK),
);
//
// If we are supposed to watch for this agent, we add him to
// the list of kernel pool agents.
//
if WATCH {
SWPOOL(&AGENT, 7, SCLKVR.as_arg(), ctx)?;
CVPOOL(&AGENT, &mut UPDATE, ctx)?;
}
//
// Check for all of the required variables and structure in
// the kernel pool.
//
for I in 1..=7 {
DTPOOL(&SCLKVR[I], &mut FOUND, &mut N, &mut TYPE, ctx)?;
if ((!FOUND || fstr::ne(&TYPE, b"N")) || (((N / save.DTSIZE[I]) * save.DTSIZE[I]) != N)) {
//
// We don't have adequate SCLK data for the specified
// object. Remove this AGENT from the list of agents
// that have passed the test.
//
REMOVI(SCLKID, save.PASSED.as_slice_mut(), ctx)?;
CHKOUT(b"ZZSCLK", ctx)?;
return Ok(ZZSCLK);
}
}
//
// Once we get to this point, we know we have SCLK data. If
// there is room to WATCH for this agent,
//
if KEEPID {
INSRTI(SCLKID, save.PASSED.as_slice_mut(), ctx)?;
}
//
// As far as we can tell, everything looks ok.
//
ZZSCLK = true;
CHKOUT(b"ZZSCLK", ctx)?;
Ok(ZZSCLK)
}