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
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
pub const LBCELL: i32 = -5;
/// Validate a DP window
///
/// Form a valid double precision window from the contents
/// of a window array.
///
/// # Required Reading
///
/// * [WINDOWS](crate::required_reading::windows)
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// SIZE I Size of window.
/// N I Original number of endpoints.
/// WINDOW I-O Input, output window.
/// ```
///
/// # Detailed Input
///
/// ```text
/// SIZE is the size of the window to be validated. This is the
/// maximum number of endpoints that the cell used to
/// implement the window is capable of holding at any one
/// time.
///
/// N is the original number of endpoints in the input cell.
///
/// WINDOW on input is a (possibly uninitialized) cell array of
/// maximum size SIZE containing N endpoints of (possibly
/// unordered and non-disjoint) intervals.
/// ```
///
/// # Detailed Output
///
/// ```text
/// WINDOW on output is a validated window, in which any overlapping
/// input intervals have been merged and the resulting set of
/// intervals is arranged in increasing order.
///
/// WINDOW is ready for use with any of the window routines.
/// ```
///
/// # Exceptions
///
/// ```text
/// 1) If the original number of endpoints N is odd, the error
/// SPICE(UNMATCHENDPTS) is signaled.
///
/// 2) If the original number of endpoints of the window exceeds its
/// size, the error SPICE(WINDOWTOOSMALL) is signaled.
///
/// 3) If the left endpoint is greater than the right endpoint, the
/// error SPICE(BADENDPOINTS) is signaled.
/// ```
///
/// # Particulars
///
/// ```text
/// This routine takes as input a cell array containing pairs of
/// endpoints and validates it to form a window.
///
/// On input, WINDOW is a cell of size SIZE containing N endpoints.
/// During validation, the intervals are ordered, and overlapping
/// intervals are merged. On output, the cardinality of WINDOW is
/// the number of endpoints remaining, and it is ready for use with
/// any of the window routines.
///
/// Because validation is done in place, there is no chance of
/// overflow.
///
/// Validation is primarily useful for ordering and merging
/// intervals read from input files or initialized in DATA
/// statements.
/// ```
///
/// # Examples
///
/// ```text
/// The numerical results shown for this example may differ across
/// platforms. The results depend on the SPICE kernels used as input,
/// the compiler and supporting libraries, and the machine specific
/// arithmetic implementation.
///
/// 1) Define an array containing a set of unordered and possibly
/// overlapping intervals, and validate the array as a SPICE
/// window.
///
///
/// Example code begins here.
///
///
/// PROGRAM WNVALD_EX1
/// IMPLICIT NONE
///
/// C
/// C SPICELIB functions.
/// C
/// INTEGER CARDD
/// INTEGER SIZED
///
/// C
/// C Local parameters.
/// C
/// INTEGER LBCELL
/// PARAMETER ( LBCELL = -5 )
///
/// INTEGER WINSIZ
/// PARAMETER ( WINSIZ = 20 )
///
/// INTEGER DATSIZ
/// PARAMETER ( DATSIZ = 16 )
///
/// C
/// C Local variables
/// C
/// DOUBLE PRECISION WINDOW ( LBCELL : WINSIZ )
/// DOUBLE PRECISION WINDAT ( DATSIZ )
///
/// INTEGER I
///
///
/// DATA WINDAT / 0, 0,
/// . 10, 12,
/// . 2, 7,
/// . 13, 15,
/// . 1, 5,
/// . 23, 29, 4*0 /
///
///
/// C
/// C Insert the data into the SPICE cell array.
/// C
/// CALL MOVED ( WINDAT, WINSIZ, WINDOW(1) )
///
/// C
/// C Validate the input WINDOW array as a SPICE window.
/// C
/// CALL WNVALD ( WINSIZ, DATSIZ, WINDOW )
///
/// WRITE (*,*) 'Current intervals: ', CARDD ( WINDOW ) / 2
/// WRITE (*,*) 'Maximum intervals: ', SIZED ( WINDOW ) / 2
/// WRITE (*,*)
/// WRITE (*,*) 'Intervals:'
/// WRITE (*,*)
///
/// DO I = 1, CARDD ( WINDOW ), 2
/// WRITE (*,*) WINDOW(I), WINDOW(I+1)
/// END DO
///
/// END
///
///
/// When this program was executed on a Mac/Intel/gfortran/64-bit
/// platform, the output was:
///
///
/// Current intervals: 5
/// Maximum intervals: 10
///
/// Intervals:
///
/// 0.0000000000000000 0.0000000000000000
/// 1.0000000000000000 7.0000000000000000
/// 10.000000000000000 12.000000000000000
/// 13.000000000000000 15.000000000000000
/// 23.000000000000000 29.000000000000000
/// ```
///
/// # 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, 16-MAR-2021 (JDR)
///
/// Changed argument name A to WINDOW for consistency with other
/// routines.
///
/// Added IMPLICIT NONE statement.
///
/// Edited the header to comply to NAIF standard. Created complete
/// code example from code fragment and added example's problem
/// statement.
///
/// Improved description of argument WINDOW in $Detailed_Output.
///
/// Removed unnecessary $Revisions section.
///
/// - SPICELIB Version 1.1.1, 30-JUL-2002 (NJB)
///
/// Fixed bugs in example program.
///
/// - SPICELIB Version 1.1.0, 14-AUG-1995 (HAN)
///
/// Fixed a character string that continued over two lines.
/// The "//" characters were missing. The Alpha/OpenVMS compiler
/// issued a warning regarding this incorrect statement syntax.
///
/// - 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)
/// ```
pub fn wnvald(ctx: &mut SpiceContext, size: i32, n: i32, window: &mut [f64]) -> crate::Result<()> {
WNVALD(size, n, window, ctx.raw_context())?;
ctx.handle_errors()?;
Ok(())
}
//$Procedure WNVALD ( Validate a DP window )
pub fn WNVALD(SIZE: i32, N: i32, WINDOW: &mut [f64], ctx: &mut Context) -> f2rust_std::Result<()> {
let mut WINDOW = DummyArrayMut::new(WINDOW, LBCELL..);
let mut LEFT: f64 = 0.0;
let mut RIGHT: f64 = 0.0;
let mut I: i32 = 0;
//
// SPICELIB functions
//
//
// Local variables
//
//
// Setting up error processing.
//
if RETURN(ctx) {
return Ok(());
}
CHKIN(b"WNVALD", ctx)?;
//
// First, some error checks. The number of endpoints must be even,
// and smaller than the reported size of the window.
//
if ODD(N) {
SETMSG(b"WNVALD: Unmatched endpoints", ctx);
SIGERR(b"SPICE(UNMATCHENDPTS)", ctx)?;
CHKOUT(b"WNVALD", ctx)?;
return Ok(());
} else if (N > SIZE) {
SETMSG(b"WNVALD: Inconsistent value for SIZE.", ctx);
SIGERR(b"SPICE(WINDOWTOOSMALL)", ctx)?;
CHKOUT(b"WNVALD", ctx)?;
return Ok(());
}
//
// Taking the easy way out, we will simply insert each new interval
// as we happen upon it. We can do this safely in place. The output
// window can't possibly contain more intervals than the input array.
//
// What can go wrong is this: a left endpoint might be greater than
// the corresponding left endpoint. This is a boo-boo, and should be
// reported.
//
SSIZED(SIZE, WINDOW.as_slice_mut(), ctx)?;
SCARDD(0, WINDOW.as_slice_mut(), ctx)?;
I = 1;
while (I < N) {
LEFT = WINDOW[I];
RIGHT = WINDOW[(I + 1)];
if (LEFT > RIGHT) {
SETMSG(b"WNVALD: Left endpoint may not exceed right endpoint.", ctx);
SIGERR(b"SPICE(BADENDPOINTS)", ctx)?;
CHKOUT(b"WNVALD", ctx)?;
return Ok(());
}
WNINSD(LEFT, RIGHT, WINDOW.as_slice_mut(), ctx)?;
I = (I + 2);
}
CHKOUT(b"WNVALD", ctx)?;
Ok(())
}