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 lstlei_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
       lstlei_c ( Last integer element less than or equal to )

       SpiceInt lstlei_c ( SpiceInt            x,
                           SpiceInt            n,
                           ConstSpiceInt     * array )
#### Abstract
       Find the index of the largest array element less than or equal
       to a given integer `x' in an array of non-decreasing integers.
#### Required_Reading
       None.
#### Keywords
       ARRAY
       SEARCH
#### Brief_I/O
       VARIABLE  I/O  DESCRIPTION
       --------  ---  --------------------------------------------------
       x          I   Upper bound value to search against.
       n          I   Number of elements in `array'.
       array      I   Array of possible lower bounds.

       The function returns the index of the last element of `array' that
       is less than or equal to `x'.
#### Detailed_Input
       x           is an integer value acting as an upper bound: the element
                   of `array' that is the greatest element less than or equal
                   to `x' is to be found.

       n           is the total number of elements in `array'.

       array       is an array of integers that forms a non-decreasing
                   sequence. The elements of array need not be distinct.
#### Detailed_Output
       The function returns the index of the highest-indexed element in
       the input array that is less than or equal to `x'. The routine
       assumes the array elements are sorted in non-decreasing order.

       Indices range from 0 to n-1.

       If all elements of `array' are greater than `x', the routine returns
       the value -1. If `n' is less than or equal to zero, the routine
       returns the value -1.
#### Parameters
       None.
#### Exceptions
       Error free.

       1)  If `n' is less than or equal to zero, the function returns -1.
           This case is not treated as an error.

       2)  If the input array is not sorted in non-decreasing order, the
           output of this routine is undefined. No error is signaled.
#### Files
       None.
#### Particulars
       This routine uses a binary search algorithm and so requires
       at most on the order of

          log (n)
             2

       steps to compute the value of lstlei_c.

       Note: If you need to find the first element of the array that is
       greater than `x', simply add 1 to the result returned by this
       function and check to see if the result is within the array bounds
       given by `n'.
#### Examples
       1)  Let array be assigned the following values:

              array[0] = -2;
              array[1] = -2;
              array[2] =  0;
              array[3] =  1;
              array[4] =  1;
              array[5] = 11;

           The table below demonstrates the behavior of lstlei_c:

                        Call                       Returned Value
              =========================            ==============
              lstlei_c ( -3, 6, array )                -1

              lstlei_c ( -2, 6, array )                 1

              lstlei_c (  0, 6, array )                 2

              lstlei_c (  1, 6, array )                 4

              lstlei_c ( 12, 6, array )                 5
#### Restrictions
       1)  If the sequence of integer numbers in the input array `array' is
           not non-decreasing, the program will run to completion but the
           index found will not mean anything.
#### Literature_References
       None.
#### Author_and_Institution
       N.J. Bachman        (JPL)
       J. Diaz del Rio     (ODC Space)
       W.L. Taber          (JPL)
#### Version
       -CSPICE Version 1.0.1, 01-NOV-2021 (JDR)

           Edited the header to comply with NAIF standard. Improved
           -Detailed_Input, -Detailed_Output, -Particulars, -Exceptions and
           -Restrictions sections.

       -CSPICE Version 1.0.0, 10-JUL-2002 (NJB) (WLT)
#### Index_Entries
       last integer element less_than_or_equal_to
#### Link to routine lstlei_c source file lstlei_c.c

    Fri Dec 31 18:41:09 2021