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
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
pub const LBCELL: i32 = -5;
/// Cardinality of a double precision window
///
/// Return the cardinality (number of intervals) of a double
/// precision window.
///
/// # Required Reading
///
/// * [WINDOWS](crate::required_reading::windows)
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// WINDOW I Input window.
///
/// The function returns the cardinality of the input window.
/// ```
///
/// # Detailed Input
///
/// ```text
/// WINDOW is a window containing zero or more intervals.
/// ```
///
/// # Detailed Output
///
/// ```text
/// The function returns the cardinality of (number of intervals in)
/// the input window.
/// ```
///
/// # Exceptions
///
/// ```text
/// 1) If the number of elements in WINDOW is not even,
/// the error SPICE(INVALIDSIZE) is signaled.
/// ```
///
/// # Particulars
///
/// ```text
/// The window cardinality (WNCARD) function simply wraps a CARD call
/// then divides the result by 2. A common error when using the SPICE
/// windows function is to use the CARDD value as the number of
/// window intervals rather than the CARDD/2 value.
/// ```
///
/// # 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) The following code example demonstrates how to insert an
/// interval into an existing double precision SPICE window, and
/// how to loop over all its intervals to extract their left and
/// right points.
///
///
/// Example code begins here.
///
///
/// PROGRAM WNCARD_EX1
/// IMPLICIT NONE
///
/// C
/// C SPICELIB functions.
/// C
/// INTEGER WNCARD
///
/// C
/// C Local parameters.
/// C
/// INTEGER LBCELL
/// PARAMETER ( LBCELL = -5 )
///
/// INTEGER WNSIZE
/// PARAMETER ( WNSIZE = 10 )
///
/// C
/// C Local variables.
/// C
/// DOUBLE PRECISION WINDOW ( LBCELL:WNSIZE )
/// DOUBLE PRECISION LEFT
/// DOUBLE PRECISION RIGHT
///
/// INTEGER I
///
/// C
/// C Validate the window with size WNSIZE and zero elements.
/// C
/// CALL WNVALD( WNSIZE, 0, WINDOW )
///
/// C
/// C Insert the intervals
/// C
/// C [ 1, 3 ] [ 7, 11 ] [ 23, 27 ]
/// C
/// C into WINDOW.
/// C
/// CALL WNINSD( 1.D0, 3.D0, WINDOW )
/// CALL WNINSD( 7.D0, 11.D0, WINDOW )
/// CALL WNINSD( 23.D0, 27.D0, WINDOW )
///
/// C
/// C Loop over the number of intervals in WINDOW, output
/// C the LEFT and RIGHT endpoints for each interval.
/// C
/// DO I=1, WNCARD(WINDOW)
///
/// CALL WNFETD( WINDOW, I, LEFT, RIGHT )
///
/// WRITE(*,'(A,I2,2(A,F8.3),A)') 'Interval', I,
/// . ' [', LEFT,',', RIGHT, ']'
///
/// END DO
///
/// END
///
///
/// When this program was executed on a Mac/Intel/gfortran/64-bit
/// platform, the output was:
///
///
/// Interval 1 [ 1.000, 3.000]
/// Interval 2 [ 7.000, 11.000]
/// Interval 3 [ 23.000, 27.000]
/// ```
///
/// # Author and Institution
///
/// ```text
/// J. Diaz del Rio (ODC Space)
/// E.D. Wright (JPL)
/// ```
///
/// # Version
///
/// ```text
/// - SPICELIB Version 1.1.0, 06-JUL-2021 (JDR)
///
/// Added IMPLICIT NONE statement.
///
/// Updated to remove unnecessary lines of code in the
/// Standard SPICE error handling CHKIN statements.
///
/// Edited the header to comply to NAIF standard. Created complete
/// code example from code fragment and added example's problem
/// statement.
///
/// - SPICELIB Version 1.0.1, 24-APR-2010 (EDW)
///
/// Minor edit to code comments eliminating typo.
///
/// - SPICELIB Version 1.0.0, 10-AUG-2007 (EDW)
/// ```
pub fn wncard(ctx: &mut SpiceContext, window: &[f64]) -> crate::Result<i32> {
let ret = WNCARD(window, ctx.raw_context())?;
ctx.handle_errors()?;
Ok(ret)
}
//$Procedure WNCARD ( Cardinality of a double precision window )
pub fn WNCARD(WINDOW: &[f64], ctx: &mut Context) -> f2rust_std::Result<i32> {
let WINDOW = DummyArray::new(WINDOW, LBCELL..);
let mut WNCARD: i32 = 0;
//
// SPICELIB functions
//
//
// Standard SPICE error handling.
//
if RETURN(ctx) {
WNCARD = 0;
return Ok(WNCARD);
}
CHKIN(b"WNCARD", ctx)?;
WNCARD = CARDD(WINDOW.as_slice(), ctx)?;
//
// Confirm the cardinality as an even integer.
//
if !EVEN(WNCARD) {
SETMSG(b"Invalid window size, a window should have an even number of elements. The size was #.", ctx);
ERRINT(b"#", WNCARD, ctx);
SIGERR(b"SPICE(INVALIDSIZE)", ctx)?;
CHKOUT(b"WNCARD", ctx)?;
WNCARD = 0;
return Ok(WNCARD);
}
//
// Set return value. Cardinality in a SPICE window sense
// means the number of intervals, half the cell
// cardinality value.
//
WNCARD = (WNCARD / 2);
CHKOUT(b"WNCARD", ctx)?;
Ok(WNCARD)
}