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
//
// GENERATED FILE
//
use super::*;
use f2rust_std::*;
const ZZGET: i32 = -1;
const ZZPUT: i32 = -2;
const ZZRESET: i32 = -3;
const ZZNOP: i32 = 3;
const GEN: i32 = 1;
const GF_REF: i32 = 2;
const GF_TOL: i32 = 3;
const GF_DT: i32 = 4;
const NID: i32 = 4;
struct SaveVars {
SVALUE: StackArray<f64, 4>,
INIT: bool,
FIRST: StackArray<bool, 4>,
}
impl SaveInit for SaveVars {
fn new() -> Self {
let mut SVALUE = StackArray::<f64, 4>::new(1..=NID);
let mut INIT: bool = false;
let mut FIRST = StackArray::<bool, 4>::new(1..=NID);
INIT = true;
Self {
SVALUE,
INIT,
FIRST,
}
}
}
//$Procedure ZZHOLDD ( Private --- hold a scalar DP )
pub fn ZZHOLDD(
OP: i32,
ID: i32,
OK: &mut bool,
VALUE: &mut f64,
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let save = ctx.get_vars::<SaveVars>();
let save = &mut *save.borrow_mut();
//
// SPICELIB functions
//
//
// Local variables.
//
//
// Standard SPICE error handling.
//
if RETURN(ctx) {
*VALUE = 0.0;
*OK = false;
return Ok(());
}
//
// Confirm a proper ID value.
//
if (BRCKTI(ID, 1, NID) != ID) {
*VALUE = 0.0;
*OK = false;
CHKIN(b"ZZHOLDD", ctx)?;
SETMSG(b"ID value unknown. ID value #1 not an element of [1, #2]. Confirmthe ID value exists in the zzholdd.inc parameter file.", ctx);
ERRINT(b"#1", ID, ctx);
ERRINT(b"#2", NID, ctx);
SIGERR(b"SPICE(UNKNOWNID)", ctx)?;
CHKOUT(b"ZZHOLDD", ctx)?;
return Ok(());
}
//
// Initialize the FIRST array; perform once per program run.
//
if save.INIT {
for I in 1..=NID {
save.FIRST[I] = true;
}
save.INIT = false;
}
//
// Perform the operation as described by OP.
//
if (OP == ZZGET) {
//
// Attempt to retrieve a stored double precision value for ID.
//
// - Return the value stored by a put operation and OK
// as true.
//
// - If no previous set to this ID, return value as zero and
// OK as false.
//
if save.FIRST[ID] {
*VALUE = 0.0;
*OK = false;
} else {
//
// Return the stored value.
//
*VALUE = save.SVALUE[ID];
*OK = true;
}
} else if (OP == ZZPUT) {
//
// Store a value for later use. Set FIRST to false
// so subsequent get calls will work.
//
if save.FIRST[ID] {
save.FIRST[ID] = false;
}
save.SVALUE[ID] = *VALUE;
} else if (OP == ZZRESET) {
//
// Reset FIRST( ID ) forcing a put before a get.
//
save.FIRST[ID] = true;
} else {
//
// Unknown value for 'OP'. Signal an error.
//
*VALUE = 0.0;
*OK = false;
CHKIN(b"ZZHOLDD", ctx)?;
SETMSG(
b"Unknown operation. Confirm the OP value # exists in the zzholdd.inc parameter file.",
ctx,
);
ERRINT(b"#", OP, ctx);
SIGERR(b"SPICE(UNKNOWNOP)", ctx)?;
CHKOUT(b"ZZHOLDD", ctx)?;
return Ok(());
}
Ok(())
}
pub fn ZZHOLDD_ZZPUT(
OP: i32,
ID: i32,
OK: &mut bool,
VALUE: f64,
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let save = ctx.get_vars::<SaveVars>();
let save = &mut *save.borrow_mut();
// [f2rust] ZZHOLDD(ZZPUT) shouldn't mutate VALUE, but actually
// it can do on error paths (and even if it couldn't, f2rust
// couldn't distinguish it from ZZGET cases). That mutability
// propagates outwards to the public API. To avoid that, we
// patch calls to use this PUT-only entry instead (see
// rsspice_build GrammarPatcher)
//
// Standard SPICE error handling.
//
if RETURN(ctx) {
*OK = false;
return Ok(());
}
//
// Confirm a proper ID value.
//
if (BRCKTI(ID, 1, NID) != ID) {
*OK = false;
CHKIN(b"ZZHOLDD", ctx)?;
SETMSG(b"ID value unknown. ID value #1 not an element of [1, #2]. Confirmthe ID value exists in the zzholdd.inc parameter file.", ctx);
ERRINT(b"#1", ID, ctx);
ERRINT(b"#2", NID, ctx);
SIGERR(b"SPICE(UNKNOWNID)", ctx)?;
CHKOUT(b"ZZHOLDD", ctx)?;
return Ok(());
}
//
// Initialize the FIRST array; perform once per program run.
//
if save.INIT {
for I in 1..=NID {
save.FIRST[I] = true;
}
save.INIT = false;
}
//
// Perform the operation as described by OP.
//
if (OP == ZZPUT) {
//
// Store a value for later use. Set FIRST to false
// so subsequent get calls will work.
//
if save.FIRST[ID] {
save.FIRST[ID] = false;
}
save.SVALUE[ID] = VALUE;
} else {
//
// Unknown value for 'OP'. Signal an error.
//
*OK = false;
CHKIN(b"ZZHOLDD", ctx)?;
SETMSG(
b"Unknown operation. Confirm the OP value # exists in the zzholdd.inc parameter file.",
ctx,
);
ERRINT(b"#", OP, ctx);
SIGERR(b"SPICE(UNKNOWNOP)", ctx)?;
CHKOUT(b"ZZHOLDD", ctx)?;
return Ok(());
}
Ok(())
}