Portability Function: Performs a binary search of a sorted one-dimensional array for a specified element. The array elements cannot be derived types or structures.
Module: USE IFPORT
Syntax
IFPORT.F90
, specify type and kind for numeric arrays:Constant | Type of array |
---|---|
SRT$INTEGER1 | INTEGER(1) |
SRT$INTEGER2 | INTEGER(2) or equivalent |
SRT$INTEGER4 | INTEGER(4) or equivalent |
SRT$INTEGER8 | INTEGER(8) or equivalent |
SRT$REAL4 | REAL(4) or equivalent |
SRT$REAL8 | REAL(8) or equivalent |
SRT$REAL16 | REAL(16) or equivalent |
If the value provided in size is not a symbolic constant and is less than 32,767, the array is assumed to be a character array with size characters per element.
Results
The result type is INTEGER(4). It is an array index of the matched entry, or 0 if the entry is not found.
The array must be sorted in ascending order before being searched.
The location of the array and the element to be found must both be passed by address using the LOC function. This defeats Fortran type checking, so you must make certain that the length and size arguments are correct, and that size is the same for the element to be found and the array searched.
If you pass invalid arguments, BSEARCHQQ attempts to search random parts of memory. If the memory it attempts to search is not allocated to the current process, the program is halted, and you receive a General Protection Violation message.
Compatibility
CONSOLE STANDARD GRAPHICS QUICKWIN GRAPHICS WINDOWS DLL LIB
See Also
Example
USE IFPORT
INTEGER(4) array(10), length
INTEGER(4) result, target
length = SIZE(array)
...
result = BSEARCHQQ(LOC(target),LOC(array),length,SRT$INTEGER4)