1 /* ordc.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   ORDC ( The ordinal position of an element in a set ) */
ordc_(char * item,char * set,ftnlen item_len,ftnlen set_len)9 integer ordc_(char *item, char *set, ftnlen item_len, ftnlen set_len)
10 {
11     /* System generated locals */
12     integer ret_val, i__1;
13 
14     /* Local variables */
15     extern integer cardc_(char *, ftnlen);
16     extern /* Subroutine */ int chkin_(char *, ftnlen);
17     extern integer bsrchc_(char *, integer *, char *, ftnlen, ftnlen);
18     extern /* Subroutine */ int chkout_(char *, ftnlen);
19     extern logical return_(void);
20 
21 /* $ Abstract */
22 
23 /*     The function returns the ordinal position of any given item in a */
24 /*     set.  If the item does not appear in the set, the function returns */
25 /*     zero. */
26 
27 /* $ Disclaimer */
28 
29 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
30 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
31 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
32 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
33 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
34 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
35 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
36 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
37 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
38 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
39 
40 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
41 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
42 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
43 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
44 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
45 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
46 
47 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
48 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
49 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
50 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
51 
52 /* $ Required_Reading */
53 
54 /*     SETS */
55 
56 /* $ Keywords */
57 
58 /*     SEARCH */
59 /*     SETS */
60 
61 /* $ Declarations */
62 /* $ Brief_I/O */
63 
64 /*     VARIABLE  I/O  DESCRIPTION */
65 /*     --------  ---  -------------------------------------------------- */
66 /*     ITEM       I   An item to locate within a set. */
67 /*     SET        I   A set to search for a given item. */
68 
69 /*     The function returns the ordinal position of ITEM within the SET. */
70 
71 /* $ Detailed_Input */
72 
73 /*     ITEM      Is an string to be located within a character set. */
74 
75 /*     SET       Is a properly validated SPICELIB set that is to be */
76 /*               searched for the occurrence of item. */
77 
78 /* $ Detailed_Output */
79 
80 /*     The function returns the ordinal position of ITEM within SET. */
81 /*     If ITEM is not an element of SET, the function is returned as 0. */
82 
83 /* $ Parameters */
84 
85 /*      None. */
86 
87 /* $ Exceptions */
88 
89 /*     None. */
90 
91 /* $ Files */
92 
93 /*     None. */
94 
95 /* $ Particulars */
96 
97 /*     A natural ordering can be imposed upon the elements of any */
98 /*     SPICELIB set, be it INTEGER, CHARACTER or DOUBLE PRECISION.  For */
99 /*     character strings the ASCII collating sequence serves as the */
100 /*     ordering relation, for DOUBLE PRECISION and INTEGER variables */
101 /*     the arithmetic ordering is used. */
102 
103 /*     Given any element of a set, its location within this ordered */
104 /*     sequence of elements is called its ordinal position within */
105 /*     the set. */
106 
107 /*     For illustrative purposes suppose that SET represents the set */
108 
109 /*              { 8, 1, 2, 9, 7, 4, 10 } */
110 
111 /*     The ordinal position of:     8 is 5 */
112 /*                                  1 is 1 */
113 /*                                  2 is 2 */
114 /*                                  9 is 6 */
115 /*                                  7 is 4 */
116 /*                                  4 is 3 */
117 /*                                 10 is 7 */
118 
119 /*     Given an item of the SET, this routine returns its ordinal */
120 /*     position.  If the item is not in the set, this function returns */
121 /*     a value of 0. */
122 
123 /* $ Examples */
124 
125 /*     Suppose that you wished to find the relative position of a value */
126 /*     in a large list of values stored within an array.  Say we want */
127 /*     to know the relative position of item I of ARRAY withing the */
128 /*     set of values represented in ARRAY. */
129 
130 /*     The following sequence of subroutine calls would allow you */
131 /*     determine the relative position of the value ARRAY(I). */
132 
133 /*     INTEGER               N */
134 /*     PARAMETER           ( N = something useful ) */
135 
136 /*     CHARACTER*(*)         ARRAY (         N ) */
137 /*     CHARACTER*(*)         SET   ( LBCELL: N ) */
138 /*     INTEGER               I */
139 
140 /*     INTEGER               NVALID */
141 /*     INTEGER               POSITION */
142 
143 
144 /*     set the value of NVALID to be the number of valid elements in the */
145 /*     array ARRAY */
146 
147 /*     CALL MOVEC  ( ARRAY, N,      SET(1) ) */
148 /*     CALL VALIDC ( N,     NVALID, SET    ) */
149 
150 /*     POSITION = ORDC ( ARRAY(I), SET ) */
151 
152 /*     POSITION now contains the ordinal position of ARRAY(I) within the */
153 /*     values represented in the array. */
154 
155 /* $ Restrictions */
156 
157 /*     SET must be a validated or empty set. */
158 
159 /* $ Literature_References */
160 
161 /*     None. */
162 
163 /* $ Author_and_Institution */
164 
165 /*     N.J. Bachman    (JPL) */
166 /*     C.A. Curzon     (JPL) */
167 /*     H.A. Neilan     (JPL) */
168 /*     W.L. Taber      (JPL) */
169 /*     I.M. Underwood  (JPL) */
170 
171 /* $ Version */
172 
173 /* -    SPICELIB Version 1.1.0, 17-MAY-1994 (HAN) */
174 
175 /*       If the value of the function RETURN is TRUE upon execution of */
176 /*       this module, this function is assigned a default value of */
177 /*       either 0, 0.0D0, .FALSE., or blank depending on the type of the */
178 /*       function. */
179 
180 /* -    SPICELIB Version 1.0.1, 10-MAR-1992 (WLT) */
181 
182 /*        Comment section for permuted index source lines was added */
183 /*        following the header. */
184 
185 /* -    SPICELIB Version 1.0.0, 31-JAN-1990 (CAC) (WLT) (IMU) */
186 
187 /* -& */
188 /* $ Index_Entries */
189 
190 /*     the ordinal position of an element in a set */
191 
192 /* -& */
193 /* $ Revisions */
194 
195 /* -    Beta Version 2.0.0, 13-MAR-1989 (NJB) */
196 
197 /*        Now participates in error handling.  References to RETURN, */
198 /*        CHKIN, and CHKOUT added. */
199 
200 /* -& */
201 
202 /*     SPICELIB functions */
203 
204 
205 /*     Standard error handling: */
206 
207     if (return_()) {
208 	ret_val = 0;
209 	return ret_val;
210     } else {
211 	chkin_("ORDC", (ftnlen)4);
212     }
213 
214 /*     Given the structure of sets, there's not much to do. */
215 
216     i__1 = cardc_(set, set_len);
217     ret_val = bsrchc_(item, &i__1, set + set_len * 6, item_len, set_len);
218     chkout_("ORDC", (ftnlen)4);
219     return ret_val;
220 } /* ordc_ */
221 
222