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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
pub const LBCELL: i32 = -5;
/// Compare two DP windows
///
/// Compare two double precision windows.
///
/// # Required Reading
///
/// * [WINDOWS](crate::required_reading::windows)
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// A I First window.
/// OP I Comparison operator.
/// B I Second window.
///
/// The function returns the result of comparison: A (OP) B.
/// ```
///
/// # Detailed Input
///
/// ```text
/// A,
/// B are SPICE windows, each of which contains zero or more
/// intervals.
///
/// OP is a comparison operator, indicating the way in which the
/// input sets are to be compared. OP may be any of the
/// following:
///
/// Operator Meaning
/// -------- -------------------------------------------
/// '=' A = B is .TRUE. if A and B are equal
/// (contain the same intervals).
///
/// '<>' A <> B is .TRUE. if A and B are not equal.
///
/// '<=' A <= B is .TRUE. if A is a subset of B.
///
/// '<' A < B is .TRUE. if A is a proper subset
/// of B.
///
/// '>=' A >= B is .TRUE. if B is a subset of A.
///
/// '>' A > B is .TRUE. if B is a proper subset
/// of A.
/// ```
///
/// # Detailed Output
///
/// ```text
/// The function returns the result of the comparison.
/// ```
///
/// # Exceptions
///
/// ```text
/// 1) If the relational operator is not recognized, the error
/// SPICE(INVALIDOPERATION) is signaled.
///
/// 2) The cardinality of the input windows 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
/// This function returns .TRUE. whenever the specified relationship
/// between the input windows, A and B, is satisfied. For example,
/// the expression
///
/// WNRELD ( NEEDED, '<=', AVAIL )
///
/// is .TRUE. whenever the window NEEDED is a subset of the window
/// AVAIL. One window is a subset of another window if each of
/// the intervals in the first window is included in one of the
/// intervals in the second window. In addition, the first window
/// is a proper subset of the second if the second window contains
/// at least one point not contained in the first window. (Thus,
/// '<' implies '<=', and '>' implies '>='.)
///
/// The following pairs of expressions are equivalent.
///
/// WNRELD ( A, '>', B )
/// WNRELD ( B, '<', A )
///
/// WNRELD ( A, '>=', B )
/// WNRELD ( B, '<=', A )
/// ```
///
/// # Examples
///
/// ```text
/// Let A contain the intervals
///
/// [ 1, 3 ] [ 7, 11 ] [ 23, 27 ]
///
/// Let B and C contain the intervals
///
/// [ 1, 2 ] [ 9, 9 ] [ 24, 27 ]
///
/// Let D contain the intervals
///
/// [ 5, 10 ] [ 15, 25 ]
///
/// Finally, let E and F be empty windows (containing no intervals).
///
/// Because B and C contain the same intervals,
///
/// WNRELD ( B, '=', C )
/// WNRELD ( B, '<=', C )
/// WNRELD ( B, '>=', C )
///
/// are all true, while
///
/// WNRELD ( B, '<>', C )
///
/// is .FALSE. Because neither B nor C contains any points not also
/// contained by the other, neither is a proper subset of the other.
/// Thus,
///
/// WNRELD ( B, '<', C )
/// WNRELD ( B, '>', C )
///
/// are both false.
///
/// Every point contained in B and C is also contained in A. Thus,
///
/// WNRELD ( B, '<=', A )
/// WNRELD ( A, '>=', C )
///
/// are both true. In addition, A contains points not contained in
/// B and C. (That is, the differences A-B and A-C are not empty.)
/// Thus, B and C are proper subsets of A as well, and
///
/// WNRELD ( B, '<', A )
/// WNRELD ( A, '>', B )
///
/// are both true.
///
/// Although A and D have points in common, neither contains the
/// other. Thus
///
/// WNRELD ( A, '=', D )
/// WNRELD ( A, '<=', D )
/// WNRELD ( A, '>=', D )
///
/// are all false.
///
/// In addition, any window is equal to itself, a subset of itself,
/// and a superset of itself. Thus,
///
/// WNRELD ( A, '=', A )
/// WNRELD ( A, '<=', A )
/// WNRELD ( A, '>=', A )
///
/// are always true. However, no window is a proper subset or a
/// proper superset of itself. Thus,
///
/// WNRELD ( A, '<', A )
/// WNRELD ( A, '>', A )
///
/// are always false.
///
/// Finally, an empty window is a a proper subset of any window
/// except another empty window. Thus,
///
/// WNRELD ( E, '<', A )
///
/// is .TRUE., but
///
/// WNRELD ( E, '<', F )
///
/// is .FALSE.
/// ```
///
/// # 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.2.0, 24-AUG-2021 (JDR) (NJB)
///
/// Added IMPLICIT NONE statement.
///
/// Edited the header to comply with NAIF standard. Added entry #2
/// in $Exceptions section.
///
/// - SPICELIB Version 1.1.0, 17-MAY-1994 (HAN)
///
/// Set the default function value to either 0, 0.0D0, .FALSE.,
/// or blank depending on the type of the function.
///
/// - 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)
/// ```
///
/// # Revisions
///
/// ```text
/// - Beta Version 2.0.0, 02-FEB-1989 (HAN)
///
/// If the relational operator is not recognized, an error is
/// signaled. The previous version returned .FALSE. as the
/// function value, and no error was signaled.
///
/// Also, the $Required_Reading section has been changed to
/// include WINDOWS as the required reading for the module.
/// ```
pub fn wnreld(ctx: &mut SpiceContext, a: &[f64], op: &str, b: &[f64]) -> crate::Result<bool> {
let ret = WNRELD(a, op.as_bytes(), b, ctx.raw_context())?;
ctx.handle_errors()?;
Ok(ret)
}
//$Procedure WNRELD ( Compare two DP windows )
pub fn WNRELD(A: &[f64], OP: &[u8], B: &[f64], ctx: &mut Context) -> f2rust_std::Result<bool> {
let A = DummyArray::new(A, LBCELL..);
let B = DummyArray::new(B, LBCELL..);
let mut WNRELD: bool = false;
let mut ACARD: i32 = 0;
let mut BCARD: i32 = 0;
let mut EQUAL: bool = false;
let mut SUBSET: bool = false;
//
// SPICELIB functions
//
//
// Local variables
//
//
// Standard SPICE error handling.
//
if RETURN(ctx) {
WNRELD = false;
return Ok(WNRELD);
} else {
CHKIN(b"WNRELD", ctx)?;
WNRELD = false;
}
//
// Find the cardinality of the input windows.
//
ACARD = CARDD(A.as_slice(), ctx)?;
BCARD = CARDD(B.as_slice(), ctx)?;
//
// A and B are equal if they contain exactly the same intervals.
// We need to know this for nearly every relationship, so find out
// before going any further.
//
if (ACARD != BCARD) {
EQUAL = false;
} else {
EQUAL = true;
for I in 1..=ACARD {
EQUAL = (EQUAL && (A[I] == B[I]));
}
}
//
// Simple equality and inequality are trivial at this point.
//
if fstr::eq(OP, b"=") {
WNRELD = EQUAL;
} else if fstr::eq(OP, b"<>") {
WNRELD = !EQUAL;
//
// Subsets are a little trickier. A is a subset of B if every
// interval in A is included in B. In addition, A is a proper
// subset if A and B are not equal.
//
} else if (fstr::eq(OP, b"<=") || fstr::eq(OP, b"<")) {
SUBSET = true;
for I in intrinsics::range(1, ACARD, 2) {
SUBSET = (SUBSET && WNINCD(A[I], A[(I + 1)], B.as_slice(), ctx)?);
}
if fstr::eq(OP, b"<=") {
WNRELD = SUBSET;
} else {
WNRELD = (SUBSET && !EQUAL);
}
//
// A and B change places here...
//
} else if (fstr::eq(OP, b">=") || fstr::eq(OP, b">")) {
SUBSET = true;
for I in intrinsics::range(1, BCARD, 2) {
SUBSET = (SUBSET && WNINCD(B[I], B[(I + 1)], A.as_slice(), ctx)?);
}
if fstr::eq(OP, b">=") {
WNRELD = SUBSET;
} else {
WNRELD = (SUBSET && !EQUAL);
}
//
// An unrecognized operator always fails.
//
} else {
SETMSG(b"Relational operator, *, is not recognized.", ctx);
ERRCH(b"*", OP, ctx);
SIGERR(b"SPICE(INVALIDOPERATION)", ctx)?;
CHKOUT(b"WNRELD", ctx)?;
return Ok(WNRELD);
}
CHKOUT(b"WNRELD", ctx)?;
Ok(WNRELD)
}