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
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
pub const LBCELL: i32 = -5;
/// Complement a DP window
///
/// Determine the complement of a double precision window with
/// respect to the interval \[LEFT,RIGHT].
///
/// # Required Reading
///
/// * [WINDOWS](crate::required_reading::windows)
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// LEFT,
/// RIGHT I Left, right endpoints of complement interval.
/// WINDOW I Input window.
/// RESULT O Complement of WINDOW with respect to [LEFT,RIGHT].
/// ```
///
/// # Detailed Input
///
/// ```text
/// LEFT,
/// RIGHT are the left and right endpoints of the complement
/// interval.
///
/// WINDOW is the window to be complemented.
/// ```
///
/// # Detailed Output
///
/// ```text
/// RESULT is the output window, containing the complement
/// of WINDOW with respect to the interval from LEFT
/// to RIGHT. If the output window is not large enough
/// to contain the result, as many intervals as will
/// fit are returned.
///
/// RESULT must be distinct from WINDOW.
/// ```
///
/// # Exceptions
///
/// ```text
/// 1) If LEFT is greater than RIGHT, the error SPICE(BADENDPOINTS)
/// is signaled.
///
/// 2) The cardinality of the input WINDOW must be even. Left
/// endpoints of stored intervals must be strictly greater than
/// preceding right endpoints. Right endpoints must be greater
/// than or equal to corresponding left endpoints. Invalid window
/// data are not diagnosed by this routine and may lead to
/// unpredictable results.
/// ```
///
/// # Particulars
///
/// ```text
/// Mathematically, the complement of a window contains those
/// points that are not contained in the window. That is, the
/// complement of the set of closed intervals
///
/// [ a(1), b(1) ], [ a(2), b(2) ], ..., [ a(n), b(n) ]
///
/// is the set of open intervals
///
/// ( -inf, a(1) ), ( b(1), a(2) ), ..., ( b(n), +inf )
///
/// Because Fortran offers no satisfactory representation of
/// infinity, we must take the complement with respect to a
/// finite interval.
///
/// In addition, Fortran offers no satisfactory floating point
/// representation of open intervals. Therefore, the complement
/// of a floating point window is closure of the set theoretical
/// complement. In short, the floating point complement of the
/// window
///
/// [ a(1), b(1) ], [ a(2), b(2) ], ..., [ a(n), b(n) ]
///
/// with respect to the interval from LEFT to RIGHT is the
/// intersection of the windows
///
/// ( -inf, a(1) ], [ b(1), a(2) ], ..., [ b(n), +inf )
///
/// and
///
/// [ LEFT, RIGHT ]
///
/// Note that floating point intervals of measure zero (singleton
/// intervals) in the original window are replaced by gaps of
/// measure zero, which are filled. Thus, complementing a floating
/// point window twice does not necessarily yield the original
/// window.
/// ```
///
/// # Examples
///
/// ```text
/// Let WINDOW contain the intervals
///
/// [ 1, 3 ] [ 7, 11 ] [ 23, 27 ]
///
/// Then the floating point complement of WINDOW with respect
/// to [2,20] contains the intervals
///
/// [ 3, 7 ] [ 11, 20 ]
///
/// and the complement with respect to [ 0, 100 ] contains
///
/// [ 0, 1 ] [ 3, 7 ] [ 11, 23 ] [ 27, 100 ]
/// ```
///
/// # Author and Institution
///
/// ```text
/// N.J. Bachman (JPL)
/// J. Diaz del Rio (ODC Space)
/// H.A. Neilan (JPL)
/// W.L. Taber (JPL)
/// I.M. Underwood (JPL)
/// ```
///
/// # Version
///
/// ```text
/// - SPICELIB Version 1.1.0, 06-JUL-2021 (JDR) (NJB)
///
/// Added IMPLICIT NONE statement.
///
/// Edited the header to comply with NAIF standard. Removed
/// unnecessary $Revisions section.
///
/// Added entry #2 in $Exceptions section.
///
/// - SPICELIB Version 1.0.1, 10-MAR-1992 (WLT)
///
/// Comment section for permuted index source lines was added
/// following the header.
///
/// - SPICELIB Version 1.0.0, 31-JAN-1990 (WLT) (IMU) (HAN) (NJB)
/// ```
pub fn wncomd(
ctx: &mut SpiceContext,
left: f64,
right: f64,
window: &[f64],
result: &mut [f64],
) -> crate::Result<()> {
WNCOMD(left, right, window, result, ctx.raw_context())?;
ctx.handle_errors()?;
Ok(())
}
//$Procedure WNCOMD ( Complement a DP window )
pub fn WNCOMD(
LEFT: f64,
RIGHT: f64,
WINDOW: &[f64],
RESULT: &mut [f64],
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let WINDOW = DummyArray::new(WINDOW, LBCELL..);
let mut RESULT = DummyArrayMut::new(RESULT, LBCELL..);
let mut CARD: i32 = 0;
let mut I: i32 = 0;
//
// SPICELIB functions
//
//
// Local variables
//
//
// Set up the error processing.
//
if RETURN(ctx) {
return Ok(());
}
CHKIN(b"WNCOMD", ctx)?;
//
// Get the cardinality of the input window.
//
CARD = CARDD(WINDOW.as_slice(), ctx)?;
//
// Empty out the result window before proceeding.
//
SCARDD(0, RESULT.as_slice_mut(), ctx)?;
//
// Check to see if the input interval is valid. If it is not, signal
// an error and return.
//
if (LEFT > RIGHT) {
SETMSG(b"WNCOMD: Left endpoint may not exceed right endpoint.", ctx);
SIGERR(b"SPICE(BADENDPOINTS)", ctx)?;
CHKOUT(b"WNCOMD", ctx)?;
return Ok(());
}
//
// There are two trivial cases: the window is empty, or it does not
// intersect the input interval. In either case, the complement is
// the entire interval.
//
if (((CARD == 0) || (WINDOW[1] >= RIGHT)) || (WINDOW[CARD] <= LEFT)) {
WNINSD(LEFT, RIGHT, RESULT.as_slice_mut(), ctx)?;
CHKOUT(b"WNCOMD", ctx)?;
return Ok(());
}
//
// Let WINDOW represent the set of intervals
//
// [a1,b1], [a2,b2], ..., [aN,bN]
//
// Then the closure of the complement of WINDOW in the reals is
//
// (-infinity,a1], [b1,a2], [b2,a3], ..., [bN, infinity)
//
// Thus the sequence of endpoints of WINDOW is also the sequence
// of finite endpoints of its complement. Moreover, these endpoints
// are simply "shifted" from their original positions in WINDOW.
// This makes finding the complement of WINDOW with respect to
// a given interval almost trivial.
//
//
// Find the first right not less than the beginning of the input
// interval.
//
I = 2;
while ((I <= CARD) && (WINDOW[I] < LEFT)) {
I = (I + 2);
}
//
// If the beginning of the input interval doesn't split an interval
// in the input window, the complement begins with LEFT.
//
if ((I <= CARD) && (WINDOW[(I - 1)] > LEFT)) {
WNINSD(LEFT, WINDOW[(I - 1)], RESULT.as_slice_mut(), ctx)?;
}
//
// Start schlepping endpoints [b(i),a(i+1)] from the input window
// to the output window. Stop when we find one of our new right
// endpoints exceeds the end of the input interval.
//
while ((!FAILED(ctx) && (I < CARD)) && (WINDOW[(I + 1)] < RIGHT)) {
WNINSD(WINDOW[I], WINDOW[(I + 1)], RESULT.as_slice_mut(), ctx)?;
I = (I + 2);
}
//
// If the end of the input interval doesn't split an interval
// in the input window, the complement ends with RIGHT.
//
if ((I <= CARD) && (WINDOW[I] < RIGHT)) {
WNINSD(WINDOW[I], RIGHT, RESULT.as_slice_mut(), ctx)?;
}
CHKOUT(b"WNCOMD", ctx)?;
Ok(())
}