M01NBF searches an ordered vector of integer numbers and returns the index of the first value equal to the sought-after item.
M01NBF is based on Professor Niklaus Wirth's implementation of the Binary Search algorithm (see
Wirth (2004)), but with two modifications. First, if the sought-after item is less than the value of the first element of the array to be searched,
is returned. Second, if a value equal to the sought-after item is not found, the index of the immediate lower value is returned.
If on entry
or
, explanatory error messages are output on the current error message unit (as defined by
X04AAF).
Not applicable.
Not applicable.
The argument
VALID should be used with caution. Set it to .FALSE. only if you are confident that the other arguments are correct, in particular that array
IV is in fact arranged in ascending order. If you wish to search the same array
IV many times, you are recommended to set
VALID to .TRUE. on first call of M01NBF and to .FALSE. on subsequent calls, in order to minimize the amount of time spent checking
IV, which may be significant if
IV is large.
This example reads a list of integer numbers and sought-after items and performs the search for these items.