The LOCAT Routines

Fortran version:

Fortran-90 generic routine LOCATE() for I/O API-3.2: compiler selects the appropriate type-specific form depending upon the number and types of the keys and key-lists:
    INTEGER FUNCTION LOCATE( KEY1[,...,] N, LIST1[,...] )
        INTEGER  N              !   table size
        <type>   KEY1[, ...]
        <type>   LIST1(N)[, ...]

Type-specific forms:

    INTEGER FUNCTION LOCATC( KEY,N, LIST )

    INTEGER FUNCTION LOCAT1( K1, N, LIST1 )
    INTEGER FUNCTION LOCAT2( K1, K2, N, LIST1, LIST2 )
    INTEGER FUNCTION LOCAT3( K1, K2, K3, N, LIST1, LIST2, LIST3 )
    INTEGER FUNCTION LOCAT4( K1, K2, K3, K4, 
 &                          N, LIST1, LIST2, LIST3, LIST4 )

    INTEGER FUNCTION LOCATL1( L1, N, LLST1 )
    INTEGER FUNCTION LOCATL2( L1, L2, N, LLST1, LLST2 )
    INTEGER FUNCTION LOCATL3( L1, L2, L3, N, LLST1, LLST2, LLST3 )
    INTEGER FUNCTION LOCATL4( L1, L2, L3, L4, 
 &                          N, LLST1, LLST2, LLST3, LLST4 )

    INTEGER FUNCTION LOCATR1( X1, N, XLST1 )
    INTEGER FUNCTION LOCATR2( X1, X2, N, XLST1, XLST2 )
    INTEGER FUNCTION LOCATR3( X1, X2, X3, N, XLST1, XLST2, XLST3 )
    INTEGER FUNCTION LOCATR4( X1, X2, X3, X4, 
 &                          N, XLST1, XLST2, XLST3, XLST4 )

        CHARACTER*(*), INTENT(IN   ) :: KEY           !  key string
        INTEGER      , INTENT(IN   ) :: K1            !  first  key
        INTEGER      , INTENT(IN   ) :: K2            !  second key
        INTEGER      , INTENT(IN   ) :: K3            !  third  key
        INTEGER      , INTENT(IN   ) :: K4            !  fourth key
        INTEGER(8)   , INTENT(IN   ) :: L1            !  first  Ley
        INTEGER(8)   , INTENT(IN   ) :: L2            !  second Ley
        INTEGER(8)   , INTENT(IN   ) :: L3            !  third  Ley
        INTEGER(8)   , INTENT(IN   ) :: L4            !  fourth Ley
        REAL         , INTENT(IN   ) :: X1            !  first  key
        REAL         , INTENT(IN   ) :: X2            !  second key
        REAL         , INTENT(IN   ) :: X3            !  third  key
        REAL         , INTENT(IN   ) :: X4            !  fourth key
        INTEGER      , INTENT(IN   ) :: N             !  table size
        CHARACTER*(*), INTENT(IN   ) :: CLIST( N )    !  table to search for KEY
        INTEGER      , INTENT(IN   ) :: LIST1( N )    !  table to search for K1
        INTEGER      , INTENT(IN   ) :: LIST2( N )    !  table to search for K2
        INTEGER      , INTENT(IN   ) :: LIST3( N )    !  table to search for K3
        INTEGER      , INTENT(IN   ) :: LIST4( N )    !  table to search for K4
        INTEGER(8)   , INTENT(IN   ) :: LLST1( N )    !  table to search for L1
        INTEGER(8)   , INTENT(IN   ) :: LLST2( N )    !  table to search for L2
        INTEGER(8)   , INTENT(IN   ) :: LLST3( N )    !  table to search for L3
        INTEGER(8)   , INTENT(IN   ) :: LLST4( N )    !  table to search for L4
        REAL         , INTENT(IN   ) :: XLST1( N )    !  table to search for X1
        REAL         , INTENT(IN   ) :: XLST2( N )    !  table to search for X2
        REAL         , INTENT(IN   ) :: XLST3( N )    !  table to search for X3
        REAL         , INTENT(IN   ) :: XLST4( N )    !  table to search for X4

C version:

    int locat1c( int        k1,
                int        n,
                const int *list1 ); /** look up integer in sorted key table **/

    int locat2c( int        k1,
                int        k2,
                int        n, 
                const int *list1 ,
                const int *list2 ) ; /** look up <K1,K2> in 2-key table **/

    int locat3c( 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 locat4c( 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 locatr1c( float        x1,
                 int          n,
                 const float *xlst1 ); /** look up float in sorted key table **/

    int locatr2c( float        x1,
                 float        x2,
                 int          n, 
                 const float *xlst1 ,
                 const float *xlst2 ) ; /** look up <X1,X2> in 2-key table **/

    int locatr3c( 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 locatr4c( 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 */

Summary:

Return subscript at which the target character-string, integer, or real key-tuple should be inserted into a sorted key-tuple table, or negative number -1 in case the key is already present.

Fortran version returns Fortran subscript (1, ..., N); C version returns C subscript (0, ..., N-1).

For Fortran-90 generic LOCATE(), declarations and interface checking:

    USE M3UTILIO
    

See also

SORTIC, SORTI1, SORTI2, SORTI3, SORTI4, SORTR1, SORTR2, SORTR3, SORTR4 for sorting key-tuple tables, and
FINDCC, FINDC1, FINDC2, FINDC3, FINDC4, FINDCR1, FINDCR2, FINDCR3, FINDCR4 for determining where to find entries in sorted key-tuple tables.

Preconditions:

#include "iodecl3.h" for C.

Table <N, LIST1, ... > to be searched is sorted in increasing order and does not have duplicates.

Fortran Usage:

    ...
    USE M3UTILIO
    ...
    INTEGER       KEY
    INTEGER       I
    INTEGER       LIST1( 10 )
    DATA          LIST1 / 1980, 1983, 1985, 1988, 1990 /
    ...
    I = LOCAT1( KEY, 5, LIST1 )
    IF ( I .EQ. -1 ) THEN
        ... KEY already present in LIST1
    ELSE
        .... KEY would insert at location I for expanded table LIST1
    END IF
    ...

C Usage:

    ...
    #include "iodecl3.h"                          
    ...
    int  k1, k2, k3, k4 ;
    int  indx ;
    ...
    if ( -1 == ( indx = locat4( k1, k2, k3, k4, 
                                tablesize, 
                                list1, list2, list3, list4 ) ) )
        {
        /** <K1,K2,K3,K4&g already present **/
        ...
        }
    else{
        /** <K1,K2,K3,K4&g belongs at subscript indx  **/
        ...
        }
    ...


Previous: LEN2

Next: LUSTR

Up: Utility Routines

SEE ALSO: FIND* Binary Search Routines

SEE ALSO: LOCAT*Sort Routines

To: Models-3/EDSS I/O API: The Help Pages