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
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
pub const LBCELL: i32 = -5;
/// Validate a character set
///
/// Create a valid set from a character set array.
///
/// # Required Reading
///
/// * [SETS](crate::required_reading::sets)
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// SIZE I Size (maximum cardinality) of the set.
/// N I Initial no. of (possibly non-distinct) elements.
/// A I-O Set to be validated.
/// ```
///
/// # Detailed Input
///
/// ```text
/// SIZE is the maximum cardinality (number of elements)
/// of the set.
///
/// N is the number of (possibly non-distinct) elements
/// initially contained in the array used to maintain
/// the set. N cannot be greater than the size of the
/// set.
///
///
/// A is a set.
///
///
/// On input, A contains N elements beginning at A(1).
/// To create a valid set, the elements are ordered,
/// and duplicate elements are removed. The contents
/// of A(LBCELL) through A(0) are lost during validation.
/// ```
///
/// # Detailed Output
///
/// ```text
/// A on output, is the set containing the ordered,
/// distinct values in the input array, ready for
/// use with other set routines.
/// ```
///
/// # Exceptions
///
/// ```text
/// 1) If the size of the set is too small to hold the set BEFORE
/// validation, the error SPICE(INVALIDSIZE) is signaled. The set
/// A is not modified.
/// ```
///
/// # Particulars
///
/// ```text
/// This routine is typically used to turn an array which has been
/// initialized through DATA or I/O statements into a set, which
/// can then be used with the other set routines.
///
/// Because a set is ordered and contains distinct values, to
/// create a set from an array, it is necessary to sort the array
/// into the set and remove duplicates. Once the array has been
/// sorted, duplicate elements (adjacent after sorting) are removed.
/// The size and cardinality of the set are initialized, and the
/// set is ready to go.
///
/// Because validation is done in place, there is no chance of
/// overflow.
/// ```
///
/// # Examples
///
/// ```text
/// Empty sets may be initialized with the cell routines SSIZEx.
/// Sets may also be initialized from nonempty set arrays.
/// This process, called validation, is done by the set routines
/// VALIDC and VALIDI. In the following example,
///
/// INTEGER BODIES ( LBCELL:100 )
///
/// DATA ( BODIES(I), I=1,8) / 3, 301,
/// . 3, 399,
/// . 5, 501,
/// . 6, 601, /
///
/// CALL VALIDI ( 100, 8, BODIES )
///
/// the integer set BODIES is validated. The size of BODIES set to
/// 100. The eight elements of the array (stored in elements 1-8)
/// are sorted, and duplicate elements (in this case, the number 3,
/// which appears twice) are removed, and the cardinality of the set
/// is set to the number of distinct elements, now seven. The set is
/// now ready for use with the rest of the set routines.
///
/// The previous contents of elements LBCELL through 0 are lost
/// during the process of validation.
/// ```
///
/// # Author and Institution
///
/// ```text
/// N.J. Bachman (JPL)
/// C.A. Curzon (JPL)
/// J. Diaz del Rio (ODC Space)
/// W.L. Taber (JPL)
/// I.M. Underwood (JPL)
/// ```
///
/// # Version
///
/// ```text
/// - SPICELIB Version 1.1.0, 05-AUG-2021 (JDR)
///
/// Added IMPLICIT NONE statement.
///
/// Edited the header to comply with NAIF standard.
///
/// - 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 (CAC) (WLT) (IMU) (NJB)
/// ```
///
/// # Revisions
///
/// ```text
/// - Beta Version 2.0.0, 13-MAR-1989 (NJB)
///
/// Now participates in error handling. References to RETURN,
/// CHKIN, and CHKOUT added. Check for adequate set size added.
///
/// The examples have been updated to illustrate set initialization
/// without the use of the EMPTYx routines, which have been
/// removed from the library. Errors in the examples have been
/// removed, also.
/// ```
pub fn validc(ctx: &mut SpiceContext, size: i32, n: i32, a: CharArrayMut) -> crate::Result<()> {
VALIDC(size, n, a, ctx.raw_context())?;
ctx.handle_errors()?;
Ok(())
}
//$Procedure VALIDC ( Validate a character set )
pub fn VALIDC(SIZE: i32, N: i32, A: CharArrayMut, ctx: &mut Context) -> f2rust_std::Result<()> {
let mut A = DummyCharArrayMut::new(A, None, LBCELL..);
let mut CARD: i32 = 0;
//
// SPICELIB functions
//
//
// Local variables
//
if RETURN(ctx) {
return Ok(());
} else {
CHKIN(b"VALIDC", ctx)?;
}
//
// Is the set size big enough?
//
if (N > SIZE) {
SETMSG(
b"Size of un-validated set is too small. Size is #, size required is #. ",
ctx,
);
ERRINT(b"#", SIZE, ctx);
ERRINT(b"#", N, ctx);
SIGERR(b"SPICE(INVALIDSIZE)", ctx)?;
CHKOUT(b"VALIDC", ctx)?;
return Ok(());
}
//
// Just like it says above. Order the array, and remove duplicates.
//
CARD = N;
RMDUPC(&mut CARD, A.subarray_mut(1));
//
// Set the size and cardinality of the input set.
//
SSIZEC(SIZE, A.as_arg_mut(), ctx)?;
SCARDC(CARD, A.as_arg_mut(), ctx)?;
CHKOUT(b"VALIDC", ctx)?;
Ok(())
}