1 /* validc.f -- translated by f2c (version 19980913).
2    You must link the resulting object file with the libraries:
3 	-lf2c -lm   (in that order)
4 */
5 
6 #include "f2c.h"
7 
8 /* $Procedure      VALIDC ( Validate a character set ) */
validc_(integer * size,integer * n,char * a,ftnlen a_len)9 /* Subroutine */ int validc_(integer *size, integer *n, char *a, ftnlen a_len)
10 {
11     integer card;
12     extern /* Subroutine */ int chkin_(char *, ftnlen), scardc_(integer *,
13 	    char *, ftnlen), rmdupc_(integer *, char *, ftnlen), sigerr_(char
14 	    *, ftnlen), chkout_(char *, ftnlen), ssizec_(integer *, char *,
15 	    ftnlen), setmsg_(char *, ftnlen), errint_(char *, integer *,
16 	    ftnlen);
17     extern logical return_(void);
18 
19 /* $ Abstract */
20 
21 /*      Create a valid set from a character set array. */
22 
23 /* $ Disclaimer */
24 
25 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
26 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
27 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
28 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
29 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
30 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
31 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
32 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
33 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
34 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
35 
36 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
37 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
38 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
39 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
40 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
41 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
42 
43 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
44 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
45 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
46 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
47 
48 /* $ Required_Reading */
49 
50 /*      SETS */
51 
52 /* $ Keywords */
53 
54 /*      CELLS, SETS */
55 
56 /* $ Declarations */
57 /* $ Brief_I/O */
58 
59 /*      VARIABLE  I/O  DESCRIPTION */
60 /*      --------  ---  -------------------------------------------------- */
61 /*      SIZE       I   Size (maximum cardinality) of the set. */
62 /*      N          I   Initial no. of (possibly non-distinct) elements. */
63 /*      A         I/O  Set to be validated. */
64 
65 /* $ Detailed_Input */
66 
67 /*      SIZE        is the maximum cardinality (number of elements) */
68 /*                  of the set. */
69 
70 /*      N           is the number of (possibly non-distinct) elements */
71 /*                  initially contained in the array used to maintain */
72 /*                  the set. N cannot be greater than the size of the */
73 /*                  set. */
74 
75 
76 /*      A           is a set. */
77 
78 
79 /*                  On input, A contains N elements beginning at A(1). */
80 /*                  To create a valid set, the elements are ordered, */
81 /*                  and duplicate elements are removed. The contents */
82 /*                  of A(LBCELL) through A(0) are lost during validation. */
83 
84 /* $ Detailed_Output */
85 
86 /*      A           on output, is the set containing the ordered, */
87 /*                  distinct values in the input array, ready for */
88 /*                  use with other set routines. */
89 
90 /* $ Parameters */
91 
92 /*      None. */
93 
94 /* $ Particulars */
95 
96 /*      This routine is typically used to turn an array which has been */
97 /*      initialized through DATA or I/O statements into a set, which */
98 /*      can then be used with the other set routines. */
99 
100 /*      Because a set is ordered and contains distinct values, to */
101 /*      create a set from an array, it is necessary to sort the array */
102 /*      into the set and remove duplicates. Once the array has been */
103 /*      sorted, duplicate elements (adjacent after sorting) are removed. */
104 /*      The size and cardinality of the set are initialized, and the */
105 /*      set is ready to go. */
106 
107 /*      Because validation is done in place, there is no chance of */
108 /*      overflow. */
109 
110 /* $ Examples */
111 
112 /*      Empty sets may be initialized with the cell routines SSIZEx. */
113 /*      Sets may also be initialized from nonempty set arrays. */
114 /*      This process, called validation, is done by the set routines */
115 /*      VALIDC and VALIDI. In the following example, */
116 
117 /*            INTEGER      BODIES  ( LBCELL:100 ) */
118 
119 /*            DATA       ( BODIES(I), I=1,8)       /  3, 301, */
120 /*           .                                        3, 399, */
121 /*           .                                        5, 501, */
122 /*           .                                        6, 601,  / */
123 
124 /*            CALL VALIDI ( 100, 8, BODIES ) */
125 
126 /*      the integer set BODIES is validated. The size of BODIES set to */
127 /*      100. The eight elements of the array (stored in elements 1-8) */
128 /*      are sorted, and duplicate elements (in this case, the number 3, */
129 /*      which appears twice) are removed, and the cardinality of the set */
130 /*      is set to the number of distinct elements, now seven. The set is */
131 /*      now ready for use with the rest of the set routines. */
132 
133 /*      The previous contents of elements LBCELL through 0 are lost */
134 /*      during the process of validation. */
135 
136 /* $ Restrictions */
137 
138 /*      None. */
139 
140 /* $ Exceptions */
141 
142 /*      1)   If the size of the set is too small to hold the set */
143 /*           BEFORE validation, the error SPICE(INVALIDSIZE) is */
144 /*           signalled.  The array A is not modified. */
145 
146 /* $ Files */
147 
148 /*      None. */
149 
150 /* $ Literature_References */
151 
152 /*      None. */
153 
154 /* $ Author_and_Institution */
155 
156 /*      N.J. Bachman    (JPL) */
157 /*      C.A. Curzon     (JPL) */
158 /*      W.L. Taber      (JPL) */
159 /*      I.M. Underwood  (JPL) */
160 
161 /* $ Version */
162 
163 /* -    SPICELIB Version 1.0.1, 10-MAR-1992 (WLT) */
164 
165 /*        Comment section for permuted index source lines was added */
166 /*        following the header. */
167 
168 /* -    SPICELIB Version 1.0.0, 31-JAN-1990 (CAC) (WLT) (IMU) */
169 
170 /* -& */
171 /* $ Index_Entries */
172 
173 /*     validate a character set */
174 
175 /* -& */
176 /* $ Revisions */
177 
178 /* -    Beta Version 2.0.0, 13-MAR-1989 (NJB) */
179 
180 /*        Now participates in error handling.  References to RETURN, */
181 /*        CHKIN, and CHKOUT added.  Check for adequate set size added. */
182 
183 /*        The examples have been updated to illustrate set initialization */
184 /*        without the use of the EMPTYx routines, which have been */
185 /*        removed from the library.  Errors in the examples have been */
186 /*        removed, also. */
187 
188 /* -& */
189 
190 /*     SPICELIB functions */
191 
192 
193 /*     Local variables */
194 
195     if (return_()) {
196 	return 0;
197     } else {
198 	chkin_("VALIDC", (ftnlen)6);
199     }
200 
201 /*     Is the set size big enough? */
202 
203     if (*n > *size) {
204 	setmsg_("Size of un-validated set is too small.  Size is #, size req"
205 		"uired is #. ", (ftnlen)71);
206 	errint_("#", size, (ftnlen)1);
207 	errint_("#", n, (ftnlen)1);
208 	sigerr_("SPICE(INVALIDSIZE)", (ftnlen)18);
209 	chkout_("VALIDC", (ftnlen)6);
210 	return 0;
211     }
212 
213 /*     Just like it says above. Order the array, and remove duplicates. */
214 
215     card = *n;
216     rmdupc_(&card, a + a_len * 6, a_len);
217 
218 /*     Set the size and cardinality of the input set. */
219 
220     ssizec_(size, a, a_len);
221     scardc_(&card, a, a_len);
222     chkout_("VALIDC", (ftnlen)6);
223     return 0;
224 } /* validc_ */
225 
226