Table of contents
CSPICE_BRCKTI brackets 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.)
Given:
number the number to be bracketed.
help, number
LONG = Scalar
That is, the value of `number' is constrained to lie in the
interval bounded by `end1' and `end2'.
end1,
end2 the lower and upper bounds for `number'.
help, end1
LONG = Scalar
help, end2
LONG = Scalar
The order is not important.
the call:
brckti = cspice_brckti( number, end1, end2 )
returns:
brckti the bracketed number.
help, brckti
LONG = Scalar
That is `number', if it was already in the interval provided.
Otherwise the returned value is the nearest bound of the
interval.
None.
Any numerical results shown for these examples may differ between
platforms as the results depend on the SPICE kernels used as input
and the machine specific arithmetic implementation.
1) The following code example illustrates the operation of
cspice_brckti.
Example code begins here.
PRO brckti_ex1
;;
;; Local parameters.
;;
LISTSZ = 4
;;
;; Set the values for the example.
;;
end1 = [ 1, 1, 10, -10]
end2 = [10, 10, -10, -1]
number = [-1, 29, 3, 3]
print, format='(A)', 'Number End1 End2 Bracketed'
print, format='(A)', '------ ---- ---- ---------'
for i=0L, LISTSZ-1L do begin
print, format='(3I6,I11)', number[i], end1[i], end2[i], $
cspice_brckti( number[i], end1[i], end2[i] )
endfor
END
When this program was executed on a Mac/Intel/IDL8.x/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
cspice_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.
PRO brckti_ex2
;;
;; Prompt the user for the code identifier.
;;
usrin = ' '
read, usrin, PROMPT = 'Enter object code: '
;;
;; Convert the user input to integer.
;;
cspice_prsint, usrin, codein
;;
;; Object code must be in the range 701-705.
;;
codeok = cspice_brckti( codein, 701L, 705L )
;;
;; Display confirmation message.
;;
if ( codein ne codeok ) then begin
print, format='(A,I3,A)', 'Provided object code ', codein, $
' is out of range (701-705).'
endif else begin
print, format='(A,I3,A)', 'Provided object code ', codein, $
' is in range (701-705).'
endelse
END
When this program was executed on a Mac/Intel/IDL8.x/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).
This routine provides a shorthand notation for code fragments
like the following:
if ( end1 lt end2 ) then begin
if ( number lt end1 ) then begin
number = end1
endif else if ( number gt end2 ) then begin
number = end2
endif
endif else begin
if ( number lt end2 ) then begin
number = end2
endif else if ( number gt end1 ) then begin
number = end1
endif
endif
which occur frequently during the processing of program inputs.
1) If any of the input arguments, `number', `end1' or `end2', is
undefined, an error is signaled by the IDL error handling
system.
2) If any of the input arguments, `number', `end1' or `end2', is
not of the expected type, or it does not have the expected
dimensions and size, an error is signaled by the Icy
interface.
None.
None.
ICY.REQ
None.
J. Diaz del Rio (ODC Space)
B.V. Semenov (JPL)
E.D. Wright (JPL)
-Icy Version 1.1.0, 10-AUG-2021 (JDR) (BVS)
BUG FIX: corrected to make the order of endpoints not important
as stated in the description.
Edited the header to comply with NAIF standard. Added complete
code examples.
Added the -Parameters and -Particulars sections.
Removed reference to the routine's corresponding CSPICE header from
-Abstract section.
Added arguments' type and size information in the -I/O section.
-Icy Version 1.0.1, 19-JAN-2009 (EDW)
Edits to header text and spelling correction.
-Icy Version 1.0.0, 16-JUN-2003 (EDW)
bracket an integer value within an interval
|