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
//
// GENERATED FILE
//
use super::*;
use f2rust_std::*;
pub const LBCELL: i32 = -5;
const INCLEN: i32 = 2;
//$Procedure ZZGFWSTS ( Private --- GF, sift first window thru second )
pub fn ZZGFWSTS(
WNDW1: &[f64],
WNDW2: &[f64],
INCLSN: &[u8],
WNDW3: &mut [f64],
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let WNDW1 = DummyArray::new(WNDW1, LBCELL..);
let WNDW2 = DummyArray::new(WNDW2, LBCELL..);
let mut WNDW3 = DummyArrayMut::new(WNDW3, LBCELL..);
let mut LOCINC = [b' '; INCLEN as usize];
let mut BEGP1: i32 = 0;
let mut BEGP2: i32 = 0;
let mut BEGP3: i32 = 0;
let mut ENDP1: i32 = 0;
let mut ENDP2: i32 = 0;
let mut ENDP3: i32 = 0;
let mut MAXPTS: i32 = 0;
let mut OVFLOW: i32 = 0;
let mut SIZE1: i32 = 0;
let mut SIZE2: i32 = 0;
let mut CLOSED: bool = false;
let mut KEEP: bool = false;
let mut LEFT: bool = false;
let mut OPEN: bool = false;
let mut RIGHT: bool = false;
//
// SPICELIB functions
//
//
// Local parameters
//
//
// Local Variables
//
//
// Standard SPICE error handling.
//
if RETURN(ctx) {
return Ok(());
}
CHKIN(b"ZZGFWSTS", ctx)?;
//
// Store the maximum number of endpoints that can be loaded into
// WNDW3
//
MAXPTS = SIZED(WNDW3.as_slice(), ctx)?;
SSIZED(MAXPTS, WNDW3.as_slice_mut(), ctx)?;
//
// Find the number of endpoints in each of the input windows.
//
SIZE1 = CARDD(WNDW1.as_slice(), ctx)?;
SIZE2 = CARDD(WNDW2.as_slice(), ctx)?;
//
// Initialize the place holders for each of the input windows.
//
BEGP1 = 1;
BEGP2 = 1;
ENDP1 = 2;
ENDP2 = 2;
BEGP3 = -1;
ENDP3 = 0;
CMPRSS(b" ", 0, INCLSN, &mut LOCINC);
OPEN = fstr::eq(&LOCINC, b"()");
LEFT = fstr::eq(&LOCINC, b"[)");
RIGHT = fstr::eq(&LOCINC, b"(]");
CLOSED = fstr::eq(&LOCINC, b"[]");
if !(((OPEN || LEFT) || RIGHT) || CLOSED) {
SETMSG(b"The value of the inclusion flag must be one of the following: \'[]\', \'[)\', \'(]\', or \'()\'. However the value supplied was \'#\'. ", ctx);
ERRCH(b"#", INCLSN, ctx);
SIGERR(b"SPICE(UNKNOWNINCLUSION)", ctx)?;
CHKOUT(b"ZZGFWSTS", ctx)?;
return Ok(());
}
//
// We haven't had a chance to overflow yet.
//
OVFLOW = 0;
while ((BEGP1 < SIZE1) && (BEGP2 < SIZE2)) {
//
// Using the current interval endpoints determine the overlap of
// the two intervals.
//
if (WNDW1[ENDP1] < WNDW2[BEGP2]) {
//
// the end of the first interval precedes the beginning of the
// second
//
BEGP1 = (BEGP1 + 2);
ENDP1 = (ENDP1 + 2);
} else if (WNDW2[ENDP2] < WNDW1[BEGP1]) {
//
// the end of the second interval precedes the beginning of the
// first
//
BEGP2 = (BEGP2 + 2);
ENDP2 = (ENDP2 + 2);
} else {
//
// the intervals intersect. Is the first contained in the
// second?
//
if CLOSED {
KEEP = ((WNDW1[BEGP1] >= WNDW2[BEGP2]) && (WNDW1[ENDP1] <= WNDW2[ENDP2]));
} else if OPEN {
KEEP = ((WNDW1[BEGP1] > WNDW2[BEGP2]) && (WNDW1[ENDP1] < WNDW2[ENDP2]));
} else if LEFT {
KEEP = ((WNDW1[BEGP1] >= WNDW2[BEGP2]) && (WNDW1[ENDP1] < WNDW2[ENDP2]));
} else if RIGHT {
KEEP = ((WNDW1[BEGP1] > WNDW2[BEGP2]) && (WNDW1[ENDP1] <= WNDW2[ENDP2]));
}
if KEEP {
BEGP3 = (BEGP3 + 2);
ENDP3 = (ENDP3 + 2);
if (BEGP3 < MAXPTS) {
//
// Adequate room is left in WNDW3 to include this
// interval
//
WNDW3[BEGP3] = WNDW1[BEGP1];
WNDW3[ENDP3] = WNDW1[ENDP1];
} else {
OVFLOW = (OVFLOW + 2);
}
}
//
// Determine which window pointers to increment
//
if (WNDW1[ENDP1] < WNDW2[ENDP2]) {
//
// The first interval lies before the end of the second
//
BEGP1 = (BEGP1 + 2);
ENDP1 = (ENDP1 + 2);
} else if (WNDW2[ENDP2] < WNDW1[ENDP1]) {
//
// The second interval lies before the end of the first
//
BEGP2 = (BEGP2 + 2);
ENDP2 = (ENDP2 + 2);
} else {
//
// The first and second intervals end at the same place
//
BEGP1 = (BEGP1 + 2);
ENDP1 = (ENDP1 + 2);
BEGP2 = (BEGP2 + 2);
ENDP2 = (ENDP2 + 2);
}
}
}
if (OVFLOW > 0) {
SETMSG(b"The output window does not have sufficient memory to contain the result of sifting the two given windows. The output window requires space for # more values than what has been provided. ", ctx);
ERRINT(b"#", OVFLOW, ctx);
SIGERR(b"SPICE(OUTOFROOM)", ctx)?;
} else {
SCARDD(ENDP3, WNDW3.as_slice_mut(), ctx)?;
}
CHKOUT(b"ZZGFWSTS", ctx)?;
Ok(())
}