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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
/// Bracket an integer value within an interval
///
/// Bracket an integer number. That is, given a number and an
/// acceptable interval, make sure that the number is contained in the
/// interval. (If the number is already in the interval, leave it
/// alone. If not, set it to the nearest endpoint of the interval.)
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// NUMBER I Number to be bracketed.
/// END1 I One of the bracketing endpoints for NUMBER.
/// END2 I The other bracketing endpoint for NUMBER.
///
/// The function returns the bracketed number.
/// ```
///
/// # Detailed Input
///
/// ```text
/// NUMBER is the number to be bracketed. That is, the
/// value of NUMBER is constrained to lie in the
/// interval bounded by END1 and END2.
///
/// END1,
/// END2 are the lower and upper bounds for NUMBER. The
/// order is not important.
/// ```
///
/// # Detailed Output
///
/// ```text
/// The function returns the bracketed number. That is NUMBER, if it
/// was already in the interval provided. Otherwise the returned
/// value is the nearest bound of the interval.
/// ```
///
/// # Exceptions
///
/// ```text
/// Error free.
/// ```
///
/// # Particulars
///
/// ```text
/// This routine provides a shorthand notation for code fragments
/// like the following:
///
/// IF ( END1 .LT. END2 ) THEN
/// IF ( NUMBER .LT. END1 ) THEN
/// NUMBER = END1
/// ELSE IF ( NUMBER .GT. END2 ) THEN
/// NUMBER = END2
/// END IF
/// ELSE
/// IF ( NUMBER .LT. END2 ) THEN
/// NUMBER = END2
/// ELSE IF ( NUMBER .GT. END1 ) THEN
/// NUMBER = END1
/// END IF
/// END IF
///
/// which occur frequently during the processing of program inputs.
/// ```
///
/// # Examples
///
/// ```text
/// The numerical results shown for these examples may differ across
/// platforms. The results depend on the SPICE kernels used as
/// input, the compiler and supporting libraries, and the machine
/// specific arithmetic implementation.
///
/// 1) The following code example illustrates the operation of
/// BRCKTI.
///
/// Example code begins here.
///
///
/// PROGRAM BRCKTI_EX1
/// IMPLICIT NONE
///
/// C
/// C SPICELIB functions.
/// C
/// INTEGER BRCKTI
///
/// C
/// C Local parameters.
/// C
/// INTEGER LISTSZ
/// PARAMETER ( LISTSZ = 4 )
///
/// C
/// C Local variables.
/// C
/// INTEGER END1 ( LISTSZ )
/// INTEGER END2 ( LISTSZ )
/// INTEGER I
/// INTEGER NUMBER ( LISTSZ )
///
/// C
/// C Set the values for the example.
/// C
/// DATA END1 / 1, 1, 10, -10 /
/// DATA END2 / 10, 10, -10, -1 /
/// DATA NUMBER / -1, 29, 3, 3 /
///
///
/// WRITE(*,'(A)') 'Number End1 End2 Bracketed'
/// WRITE(*,'(A)') '------ ---- ---- ---------'
///
/// DO I = 1, LISTSZ
///
/// WRITE(*,'(3I6,I11)') NUMBER(I), END1(I), END2(I),
/// . BRCKTI ( NUMBER(I), END1(I), END2(I) )
///
/// END DO
///
///
/// END
///
///
/// When this program was executed on a Mac/Intel/gfortran/64-bit
/// platform, the output was:
///
///
/// Number End1 End2 Bracketed
/// ------ ---- ---- ---------
/// -1 1 10 1
/// 29 1 10 10
/// 3 10 -10 3
/// 3 -10 -1 -1
///
///
/// 2) The following code example illustrates a typical use for
/// BRCKTI: force an identifier to be within a range. Note that
/// this code assumes that the user provided value is a valid
/// integer number.
///
///
/// Example code begins here.
///
///
/// PROGRAM BRCKTI_EX2
/// IMPLICIT NONE
///
/// C
/// C SPICELIB functions.
/// C
/// INTEGER BRCKTI
///
/// C
/// C Local parameters.
/// C
/// INTEGER KWDSZ
/// PARAMETER ( KWDSZ = 30 )
///
/// C
/// C Local variables.
/// C
/// CHARACTER*(KWDSZ) USRIN
///
/// INTEGER CODEIN
/// INTEGER CODEOK
///
/// C
/// C Prompt the user for the code identifier.
/// C
/// CALL PROMPT ( 'Enter object code: ', USRIN )
///
/// C
/// C Convert the user input to integer.
/// C
/// CALL PRSINT ( USRIN, CODEIN )
///
/// C
/// C Object code must be in the range 701-705.
/// C
/// CODEOK = BRCKTI ( CODEIN, 701, 705 )
///
/// C
/// C Display confirmation message.
/// C
/// IF ( CODEIN .NE. CODEOK ) THEN
///
/// WRITE(*,'(A,I3,A)') 'Provided object code ', CODEIN,
/// . ' is out of range (701-705).'
///
/// ELSE
///
/// WRITE(*,'(A,I3,A)') 'Provided object code ', CODEIN,
/// . ' is in range (701-705).'
///
/// END IF
///
/// END
///
///
/// When this program was executed on a Mac/Intel/gfortran/64-bit
/// platform, using '710' as user provided input, the output was:
///
///
/// Enter object code: 710
/// Provided object code 710 is out of range (701-705).
/// ```
///
/// # Author and Institution
///
/// ```text
/// J. Diaz del Rio (ODC Space)
/// B.V. Semenov (JPL)
/// W.L. Taber (JPL)
/// I.M. Underwood (JPL)
/// ```
///
/// # Version
///
/// ```text
/// - SPICELIB Version 1.1.0, 08-AUG-2021 (JDR) (BVS)
///
/// Added IMPLICIT NONE statement.
///
/// Edited the header to comply with NAIF standard. Added complete
/// code examples based on existing code fragment.
///
/// Updated code fragment in $Particulars to show that the
/// order of endpoints is not important.
///
/// - 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 (IMU) (WLT)
/// ```
///
/// # Revisions
///
/// ```text
/// - Beta Version 1.1.0, 30-DEC-1988 (WLT)
///
/// The routine was modified so that the order of the endpoints
/// of the bracketing interval is not needed. The routine now
/// determines which is the left endpoint and which is the
/// right and acts appropriately.
/// ```
pub fn brckti(number: i32, end1: i32, end2: i32) -> i32 {
let ret = BRCKTI(number, end1, end2);
ret
}
//$Procedure BRCKTI ( Bracket an integer value within an interval )
pub fn BRCKTI(NUMBER: i32, END1: i32, END2: i32) -> i32 {
let mut BRCKTI: i32 = 0;
//
// What else is there to say?
//
if (END1 < END2) {
BRCKTI = intrinsics::MAX0(&[END1, intrinsics::MIN0(&[END2, NUMBER])]);
} else {
BRCKTI = intrinsics::MAX0(&[END2, intrinsics::MIN0(&[END1, NUMBER])]);
}
BRCKTI
}