INTEGER FUNCTION FINDC( KEY,N, LIST )
INTEGER FUNCTION FIND1( K1, N, LIST1 )
INTEGER FUNCTION FIND2( K1, K2, N, LIST1, LIST2 )
INTEGER FUNCTION FIND3( K1, K2, K3, N, LIST1, LIST2, LIST3 )
INTEGER FUNCTION FIND4( K1, K2, K3, K4,
& N, LIST1, LIST2, LIST3, LIST4 )
INTEGER FUNCTION FINDR1( X1, N, XLST1 )
INTEGER FUNCTION FINDR2( X1, X2, N, XLST1, XLST2 )
INTEGER FUNCTION FINDR3( X1, X2, X3, N, XLST1, XLST2, XLST3 )
INTEGER FUNCTION FINDR4( X1, X2, X3, X4,
& N, XLST1, XLST2, XLST3, XLST4 )
CHARACTER*(*) KEY ! key
INTEGER K1 ! first key
INTEGER K2 ! second key
INTEGER K3 ! third key
INTEGER K4 ! fourth key
INTEGER N ! table size
CHARACTER*(*) LIST( N ) ! table to search for KEY
INTEGER LIST1( N ) ! table to search for K1
INTEGER LIST2( N ) ! table to search for K2
INTEGER LIST3( N ) ! table to search for K3
INTEGER LIST4( N ) ! table to search for K4
INTEGER X1 ! first key
INTEGER X2 ! second key
INTEGER X3 ! third key
INTEGER X4 ! fourth key
INTEGER XLST1( N ) ! table to search for K1
INTEGER XLST2( N ) ! table to search for K2
INTEGER XLST3( N ) ! table to search for K3
INTEGER XLST4( N ) ! table to search for K4
int find1c( int k1,
int n,
const int *list1 ); /** look up integer in sorted key table **/
int find2c( int k1,
int k2,
int n,
const int *list1 ,
const int *list2 ) ; /** look up <K1,K2> in 2-key table **/
int find3c( int k1,
int k2,
int k3,
int n,
const int *list1 ,
const int *list2 ,
const int *list3 ) ; /** look up <K1,K2,K3> in 3-key table **/
int find4c( int k1,
int k2,
int k3,
int k4,
int n,
const int *list1 ,
const int *list2 ,
const int *list3 ,
const int *list4 ) ; /* look up <K1,K2,K3,K4> in 4-key table */
int findr1c( float x1,
int n,
const float *xlst1 ); /** look up float in sorted key table **/
int findr2c( float x1,
float x2,
int n,
const float *xlst1 ,
const float *xlst2 ) ; /** look up <X1,X2> in 2-key table **/
int findr3c( float x1,
float x2,
float x3,
int n,
const float *xlst1 ,
const float *xlst2 ,
const float *xlst3 ) ; /** look up <X1,X2,X3> in 3-key table **/
int findr4c( float x1,
float x2,
float x3,
float x4,
int n,
const float *xlst1 ,
const float *xlst2 ,
const float *xlst3 ,
const float *xlst4 ) ; /* look up <X1,X2,X3,X4> in 4-key table */
Fortran version returns Fortran subscript (1, ..., N); C version returns C subscript (0, ..., N-1). No C version of FINDC() because of the differences in Fortran and C character-strings.
See also SORTIC, SORTI1, SORTI2, SORTI3, SORTI4, SORTR1, SORTR2, SORTR3, SORTR4 for sorting key-tuple tables, and LOCATC, LOCAT1, LOCAT2, LOCAT3, LOCAT4, LOCATR1, LOCATR2, LOCATR3, LOCATR4 for determining where to insert entries into sorted key-tuple tables.
#include "iodecl3.h" for C.
Table <N, LIST1, ... > to be searched is sorted in increasing order and does not have duplicates.
...
...
INTEGER FIND2
INTEGER KEY1, KEY2
INTEGER I
!! .....here are *already-sorted* paired lists of keys:
INTEGER LIST1( 7 ), LIST2( 7 )
DATA LIST1 / 1980, 1980, 1983, 1985, 1988, 1988, 1990 /
DATA LIST2 / 3, 7, 5, 11, 1, 10, 7 /
...
!! ...in this case, key will be found at location 2
KEY1 = 1980
KEY2 = 7
I = FIND2( KEY1, KEY2, 8, LIST1, LIST2 )
IF ( I .LT. 0 ) THEN
... KEY not found in LIST1
END IF
...
!! ...in this case, key will not not found:
KEY1 = 1985
KEY2 = 7
I = FIND2( KEY1, KEY2, 8, LIST1, LIST2 )
IF ( I .LT. 0 ) THEN
... KEY not found in LIST1
END IF
...
...
#include "iodecl3.h"
#define TABLESIZE ...
...
int k1, k2, k3, k4 ;
int indx ;
int tablesize ;
int list1[TABLESIZE], list2[TABLESIZE], list3[TABLESIZE], list4[TABLESIZE]
...
/* Assume tuple-sorted keytables <list1[].list2[].list3[].list4[]>
...
if ( 0 > ( indx = find4( k1, k2, k3, k4,
TABLESIZE,
list1, list2, list3, list4 ) ) )
{
/** <k1,k2,k3,k4&g not found **/
...
}
else{
/** <k1,k2,k3,k4&g found at subscript indx **/
...
}
...
SEE ALSO: LOCAT* Binary Search-and-Insert Routines
To: Models-3/EDSS I/O API: The Help Pages