rsspice/generated/spicelib/validc.rs
1//
2// GENERATED FILE
3//
4
5use super::*;
6use crate::SpiceContext;
7use f2rust_std::*;
8
9pub const LBCELL: i32 = -5;
10
11/// Validate a character set
12///
13/// Create a valid set from a character set array.
14///
15/// # Required Reading
16///
17/// * [SETS](crate::required_reading::sets)
18///
19/// # Brief I/O
20///
21/// ```text
22///  VARIABLE  I/O  DESCRIPTION
23///  --------  ---  --------------------------------------------------
24///  SIZE       I   Size (maximum cardinality) of the set.
25///  N          I   Initial no. of (possibly non-distinct) elements.
26///  A         I-O  Set to be validated.
27/// ```
28///
29/// # Detailed Input
30///
31/// ```text
32///  SIZE     is the maximum cardinality (number of elements)
33///           of the set.
34///
35///  N        is the number of (possibly non-distinct) elements
36///           initially contained in the array used to maintain
37///           the set. N cannot be greater than the size of the
38///           set.
39///
40///
41///  A        is a set.
42///
43///
44///           On input, A contains N elements beginning at A(1).
45///           To create a valid set, the elements are ordered,
46///           and duplicate elements are removed. The contents
47///           of A(LBCELL) through A(0) are lost during validation.
48/// ```
49///
50/// # Detailed Output
51///
52/// ```text
53///  A        on output, is the set containing the ordered,
54///           distinct values in the input array, ready for
55///           use with other set routines.
56/// ```
57///
58/// # Exceptions
59///
60/// ```text
61///  1)  If the size of the set is too small to hold the set BEFORE
62///      validation, the error SPICE(INVALIDSIZE) is signaled. The set
63///      A is not modified.
64/// ```
65///
66/// # Particulars
67///
68/// ```text
69///  This routine is typically used to turn an array which has been
70///  initialized through DATA or I/O statements into a set, which
71///  can then be used with the other set routines.
72///
73///  Because a set is ordered and contains distinct values, to
74///  create a set from an array, it is necessary to sort the array
75///  into the set and remove duplicates. Once the array has been
76///  sorted, duplicate elements (adjacent after sorting) are removed.
77///  The size and cardinality of the set are initialized, and the
78///  set is ready to go.
79///
80///  Because validation is done in place, there is no chance of
81///  overflow.
82/// ```
83///
84/// # Examples
85///
86/// ```text
87///  Empty sets may be initialized with the cell routines SSIZEx.
88///  Sets may also be initialized from nonempty set arrays.
89///  This process, called validation, is done by the set routines
90///  VALIDC and VALIDI. In the following example,
91///
92///        INTEGER      BODIES  ( LBCELL:100 )
93///
94///        DATA       ( BODIES(I), I=1,8)       /  3, 301,
95///       .                                        3, 399,
96///       .                                        5, 501,
97///       .                                        6, 601,  /
98///
99///        CALL VALIDI ( 100, 8, BODIES )
100///
101///  the integer set BODIES is validated. The size of BODIES set to
102///  100. The eight elements of the array (stored in elements 1-8)
103///  are sorted, and duplicate elements (in this case, the number 3,
104///  which appears twice) are removed, and the cardinality of the set
105///  is set to the number of distinct elements, now seven. The set is
106///  now ready for use with the rest of the set routines.
107///
108///  The previous contents of elements LBCELL through 0 are lost
109///  during the process of validation.
110/// ```
111///
112/// # Author and Institution
113///
114/// ```text
115///  N.J. Bachman       (JPL)
116///  C.A. Curzon        (JPL)
117///  J. Diaz del Rio    (ODC Space)
118///  W.L. Taber         (JPL)
119///  I.M. Underwood     (JPL)
120/// ```
121///
122/// # Version
123///
124/// ```text
125/// -    SPICELIB Version 1.1.0, 05-AUG-2021 (JDR)
126///
127///         Added IMPLICIT NONE statement.
128///
129///         Edited the header to comply with NAIF standard.
130///
131/// -    SPICELIB Version 1.0.1, 10-MAR-1992 (WLT)
132///
133///         Comment section for permuted index source lines was added
134///         following the header.
135///
136/// -    SPICELIB Version 1.0.0, 31-JAN-1990 (CAC) (WLT) (IMU) (NJB)
137/// ```
138///
139/// # Revisions
140///
141/// ```text
142/// -    Beta Version 2.0.0, 13-MAR-1989 (NJB)
143///
144///         Now participates in error handling. References to RETURN,
145///         CHKIN, and CHKOUT added. Check for adequate set size added.
146///
147///         The examples have been updated to illustrate set initialization
148///         without the use of the EMPTYx routines, which have been
149///         removed from the library. Errors in the examples have been
150///         removed, also.
151/// ```
152pub fn validc(ctx: &mut SpiceContext, size: i32, n: i32, a: CharArrayMut) -> crate::Result<()> {
153    VALIDC(size, n, a, ctx.raw_context())?;
154    ctx.handle_errors()?;
155    Ok(())
156}
157
158//$Procedure VALIDC ( Validate a character set )
159pub fn VALIDC(SIZE: i32, N: i32, A: CharArrayMut, ctx: &mut Context) -> f2rust_std::Result<()> {
160    let mut A = DummyCharArrayMut::new(A, None, LBCELL..);
161    let mut CARD: i32 = 0;
162
163    //
164    // SPICELIB functions
165    //
166
167    //
168    // Local variables
169    //
170
171    if RETURN(ctx) {
172        return Ok(());
173    } else {
174        CHKIN(b"VALIDC", ctx)?;
175    }
176
177    //
178    // Is the set size big enough?
179    //
180    if (N > SIZE) {
181        SETMSG(
182            b"Size of un-validated set is too small.  Size is #, size required is #. ",
183            ctx,
184        );
185
186        ERRINT(b"#", SIZE, ctx);
187        ERRINT(b"#", N, ctx);
188        SIGERR(b"SPICE(INVALIDSIZE)", ctx)?;
189        CHKOUT(b"VALIDC", ctx)?;
190        return Ok(());
191    }
192
193    //
194    // Just like it says above. Order the array, and remove duplicates.
195    //
196    CARD = N;
197    RMDUPC(&mut CARD, A.subarray_mut(1));
198
199    //
200    // Set the size and cardinality of the input set.
201    //
202    SSIZEC(SIZE, A.as_arg_mut(), ctx)?;
203    SCARDC(CARD, A.as_arg_mut(), ctx)?;
204
205    CHKOUT(b"VALIDC", ctx)?;
206    Ok(())
207}