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

Table of contents

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

       bsrchc_c ( Binary search for a character string )

       SpiceInt bsrchc_c ( ConstSpiceChar  * value,
                           SpiceInt          ndim,
                           SpiceInt          arrlen,
                           const void      * array   )

#### Abstract

       Do a binary search for a given value within a character string array,
       assumed to be in nondecreasing order. 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   Key value to be found in `array'.
       ndim       I   Dimension of `array'.
       arrlen     I   Declared length of the strings in `array'.
       array      I   Character string array to search.

       The function returns the index of the first matching array element
       or -1 if the value is not found.

#### Detailed_Input

       value       is the key value to be found in the array. Trailing
                   blanks in this key are not significant: string matches
                   found by this routine do not require trailing blanks in
                   value to match those in the corresponding element of
                   array.

       ndim        is the number of elements in the input array.

       arrlen      is the declared length of the strings in the input
                   string array, including null terminators. The input
                   array should be declared with dimension

                      [ndim][arrlen]

       array       is the array of character strings to be searched. Trailing
                   blanks in the strings in this array are not significant.
                   The elements in `array' are assumed to sorted according to
                   the ASCII collating sequence..

#### Detailed_Output

       The function returns the index of the specified value in the input
       array. Indices range from 0 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 ndim < 1, the value of the function is -1. This is not
           considered an error.

       2)  If the `value' input string pointer is null, the error
           SPICE(NULLPOINTER) is signaled. The function returns the
           value -1.

       3)  If the `array' input array pointer is null, the error
           SPICE(NULLPOINTER) is signaled. The function returns the
           value -1.

       4)  If the `array' input array strings have length less than two
           characters, the error SPICE(EMPTYSTRING) is signaled. The
           function returns the value -1.

#### Files

       None.

#### Particulars

       A binary search is performed on the input array. 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 be a character array of dimension

         [5][arrlen]

       which contains the following elements:

          "BOHR"
          "EINSTEIN"
          "FEYNMAN"
          "GALILEO"
          "NEWTON"

       Then

          bsrchc_c ( "NEWTON",   5, arrlen, array )    ==   4
          bsrchc_c ( "EINSTEIN", 5, arrlen, array )    ==   1
          bsrchc_c ( "GALILEO",  5, arrlen, array )    ==   3
          bsrchc_c ( "Galileo",  5, arrlen, array )    ==  -1
          bsrchc_c ( "BETHE",    5, arrlen, array )    ==  -1

#### Restrictions

       1)  `array' is assumed to be sorted in increasing order according to
           the ASCII collating sequence. If this condition is not met,
           the results of bsrchc_c are unpredictable.

       2)  String comparisons performed by this routine are Fortran-style:
           trailing blanks in the input array or key value are ignored.
           This gives consistent behavior with CSPICE code generated by
           the f2c translator, as well as with the Fortran SPICE Toolkit.

           Note that this behavior is not identical to that of the ANSI
           C library functions strcmp and strncmp.

#### Literature_References

       None.

#### Author_and_Institution

       N.J. Bachman        (JPL)
       J. Diaz del Rio     (ODC Space)
       W.M. Owen           (JPL)

#### Version

       -CSPICE Version 1.2.0, 01-NOV-2021 (JDR)

           Changed the input argument name "lenvals" to "arrlen" for consistency
           with other routines.

           Edited the header to comply with NAIF standard.

       -CSPICE Version 1.1.0, 07-MAR-2009 (NJB)

           This file now includes the header file f2cMang.h.
           This header supports name mangling of f2c library
           functions.

           Header sections were re-ordered.

       -CSPICE Version 1.0.0, 26-AUG-2002 (NJB) (WMO)

#### Index_Entries

       search in a character array

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

    Fri Dec 31 18:41:02 2021