Index Page bschoi_c

A B C D E F G H I J K L M N O P Q R S T U V W X

Procedure Abstract Required_Reading Keywords Brief_I/O Detailed_Input | Detailed_Output Parameters Exceptions Files Particulars Examples | Restrictions Literature_References Author_and_Institution Version Index_Entries

#### Procedure

       SpiceInt bschoi_c ( SpiceInt          value,
                           SpiceInt          ndim,
                           ConstSpiceInt   * array,
                           ConstSpiceInt   * order  )

#### Abstract

       Do a binary search for a given value within an integer array,
       accompanied by an order vector.  Return the index of the
       matching array entry, or -1 if the key value is not found.

#### Required_Reading

       None.

#### Keywords

       ARRAY,  SEARCH

#### Brief_I/O

       VARIABLE  I/O  DESCRIPTION
       --------  ---  --------------------------------------------------
       value      I   Value to find in array.
       ndim       I   Dimension of array.
       array      I   Array to be searched.
       order      I   Order vector.

       The function returns the index of value in array, or -1 if the value
       is not found.

#### Detailed_Input

       value       is the value to be found in the input array.

       ndim        is the number of elements in the input array.

       array       is the array to be searched.

       order       is an order vector which can be used to access the elements
                   of array in order.  The contents of order are a permutation
                   of the sequence of integers ranging from zero to ndim-1.

#### Detailed_Output

       The function returns the index of the input value in the input array.
       Indices range from zero to ndim-1.

       If the input array does not contain the specified value, the function
       returns -1.

       If the input array contains more than one occurrence of the specified
       value, the returned index may point to any of the occurrences.

#### Parameters

       None.

#### Exceptions

       1) If memory cannot be allocated to create a Fortran-style version of
          the input order vector, the error SPICE(MALLOCFAILED) is signaled.
          The function returns -1 in this case.

       2) If ndim < 1 the value of the function is -1. This is not an error.

#### Files

       None.

#### Particulars

       A binary search is performed on the input array, whose order is given
       by an associated order vector.  If an element of the array is found to
       match the input value, the index of that element is returned. If no
       matching element is found, -1 is returned.

#### Examples

       Let array and order contain the following elements:

          array         order
          -----------   -----
            100             1
              1             2
             10             0
          10000             4
           1000             3

       Then

          bschoi_c (  1000, 5, array, order )  ==   4
          bschoi_c (     1, 5, array, order )  ==   1
          bschoi_c ( 10000, 5, array, order )  ==   3
          bschoi_c (    -1, 5, array, order )  ==  -1
          bschoi_c (    17, 5, array, order )  ==  -1

       That is,

          array[4] ==  1000
          array[1] ==     1
          array[3] == 10000

#### Restrictions

       The input order vector is assumed give the order of the elements of the
       input array in increasing order. If this condition is not met, the
       results of bschoi_c are unpredictable.

#### Literature_References

       None.

#### Author_and_Institution

       N.J. Bachman    (JPL)
       W.L. Taber      (JPL)
       I.M. Underwood  (JPL)

#### Version

       -CSPICE Version 1.0.0, 10-JUL-2002 (NJB) (WLT) (IMU)

#### Index_Entries

       binary search for an integer value

#### Link to routine bschoi_c source file bschoi_c.c

    Wed Apr  5 17:54:29 2017