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
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
pub const LBCELL: i32 = -5;
/// The ordinal position of an element in a set
///
/// Return the ordinal position of a given item in a set. If the
/// item does not appear in the set, return zero.
///
/// # Required Reading
///
/// * [SETS](crate::required_reading::sets)
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// ITEM I An item to locate within a set.
/// SET I A set to search for a given item.
///
/// The function returns the ordinal position of ITEM within the SET.
/// ```
///
/// # Detailed Input
///
/// ```text
/// ITEM is an integer value to be located within a set.
///
/// SET is a properly validated SPICE set that is to be
/// searched for the occurrence of ITEM.
/// ```
///
/// # Detailed Output
///
/// ```text
/// The function returns the ordinal position of ITEM within SET.
/// Ordinal positions range from 1 to N, where N is the cardinality of
/// the set.
///
/// If ITEM is not an element of SET, the function return 0.
/// ```
///
/// # Exceptions
///
/// ```text
/// 1) If the input set has invalid cardinality, an error is signaled
/// by a routine in the call tree of this routine. ORDI returns an
/// unspecified value in this case.
///
/// 2) If the input set has invalid size, an error is signaled by a
/// routine in the call tree of this routine. ORDI returns an
/// unspecified value in this case.
/// ```
///
/// # Particulars
///
/// ```text
/// A natural ordering can be imposed upon the elements of any
/// SPICE set, be it INTEGER, CHARACTER or DOUBLE PRECISION. For
/// character strings the ASCII collating sequence serves as the
/// ordering relation, for DOUBLE PRECISION and INTEGER variables
/// the arithmetic ordering is used.
///
/// Given any element of a set, its location within this ordered
/// sequence of elements is called its ordinal position within
/// the set.
///
/// For illustrative purposes suppose that SET represents the set
///
/// { 8, 1, 2, 9, 7, 4, 10 }
///
/// The ordinal position of: 8 is 5
/// 1 is 1
/// 2 is 2
/// 9 is 6
/// 7 is 4
/// 4 is 3
/// 10 is 7
///
/// Given an item of the SET, this routine returns its ordinal
/// position. If the item is not in the set, this function returns
/// a value of 0.
/// ```
///
/// # Examples
///
/// ```text
/// Suppose that you wished to find the relative position of a value
/// in a large list of values stored within an array. Say we want
/// to know the relative position of item I of ARRAY withing the
/// set of values represented in ARRAY.
///
/// The following sequence of subroutine calls would allow you
/// determine the relative position of the value ARRAY(I).
///
/// INTEGER N
/// PARAMETER ( N = something useful )
///
/// INTEGER ARRAY ( N )
/// INTEGER SET ( LBCELL: N )
/// INTEGER I
///
/// INTEGER NVALID
/// INTEGER POSITION
///
/// set the value of NVALID to be the number of valid elements in the
/// array ARRAY
///
/// CALL MOVEI ( ARRAY, N, SET(1) )
/// CALL VALIDI ( N, NVALID, SET )
///
/// POSITION = ORDI ( ARRAY(I), SET )
///
/// POSITION now contains the ordinal position of ARRAY(I) within the
/// values represented in the array.
/// ```
///
/// # Restrictions
///
/// ```text
/// 1) SET must be a validated or empty set.
/// ```
///
/// # Author and Institution
///
/// ```text
/// N.J. Bachman (JPL)
/// C.A. Curzon (JPL)
/// J. Diaz del Rio (ODC Space)
/// H.A. Neilan (JPL)
/// W.L. Taber (JPL)
/// I.M. Underwood (JPL)
/// ```
///
/// # Version
///
/// ```text
/// - SPICELIB Version 1.2.0, 26-OCT-2021 (JDR)
///
/// Added IMPLICIT NONE statement.
///
/// Edited the header to comply with NAIF standard. Extended
/// $Detailed_Output and $Exceptions section.
///
/// Removed unnecessary $Revisions section.
///
/// - SPICELIB Version 1.1.0, 17-MAY-1994 (HAN)
///
/// If the value of the function RETURN is .TRUE. upon execution of
/// this module, this function is assigned a default value of
/// either 0, 0.0D0, .FALSE., or blank depending on the type of the
/// function.
///
/// - 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)
/// ```
pub fn ordi(ctx: &mut SpiceContext, item: i32, set: &[i32]) -> crate::Result<i32> {
let ret = ORDI(item, set, ctx.raw_context())?;
ctx.handle_errors()?;
Ok(ret)
}
//$Procedure ORDI ( The ordinal position of an element in a set )
pub fn ORDI(ITEM: i32, SET: &[i32], ctx: &mut Context) -> f2rust_std::Result<i32> {
let SET = DummyArray::new(SET, LBCELL..);
let mut ORDI: i32 = 0;
//
// SPICELIB functions
//
//
// Standard error handling:
//
if RETURN(ctx) {
ORDI = 0;
return Ok(ORDI);
} else {
CHKIN(b"ORDI", ctx)?;
}
//
// Given the structure of sets, there's not much to do.
//
ORDI = BSRCHI(ITEM, CARDI(SET.as_slice(), ctx)?, SET.subarray(1));
CHKOUT(b"ORDI", ctx)?;
Ok(ORDI)
}