Пример #1
0
   SpiceInt lstltc_c ( ConstSpiceChar  * string,
                       SpiceInt          n,   
                       SpiceInt          lenvals,
                       const void      * array   ) 
/*

-Brief_I/O
 
   VARIABLE  I/O  DESCRIPTION 
   --------  ---  -------------------------------------------------- 
   string     I   Upper bound value to search against.
   n          I   Number elements in array.
   lenvals    I   String length.
   array      I   Array of possible lower bounds.

   The function returns the index of the last element of array that
   is lexically less than string. 
 
-Detailed_Input
 
   string      is a string acting as an upper bound:  the array element
               that is lexically the greatest element less than string
               is to be found.  Trailing blanks in this bound value are
               not significant.

   n           is the dimension of the array. 

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

                  [n][lenvals]

   array       is the array of character strings to be searched.
               Trailing blanks in the strings in this array are not
               significant. The strings must be sorted in
               non-decreasing order. 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 lexically less than string.  The routine assumes
   the array elements are sorted in non-decreasing order.
 
   If all elements of the input array are greater than or equal to the
   specified upper bound string, the function returns -1.

-Parameters
 
    None. 
 
-Exceptions
 
   1) If ndim < 1 the function value is -1.  This is not considered
      an error.

   2) If input key value pointer is null, the error SPICE(NULLPOINTER) will 
      be signaled.  The function returns -1.
 
   3) The input key value may have length zero.  This case is not
      considered an error.

   4) If the input array pointer is null,  the error SPICE(NULLPOINTER) will 
      be signaled.  The function returns -1.

   5) If the input array string's length is less than 2, the error
      SPICE(STRINGTOOSHORT) will be signaled.  The function returns -1.
 
-Files
 
   None. 
 
-Particulars
 
   Note:  If you need to find the first element of the array that
          is greater than or equal to string, 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
 
   Let array be a character array of dimension 

      [5][lenvals]

   which contains the following elements:

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

   Then

      lstltc_c ( "NEWTON",   5, lenvals, array )    ==   3
      lstltc_c ( "EINSTEIN", 5, lenvals, array )    ==   0
      lstltc_c ( "GALILEO",  5, lenvals, array )    ==   2
      lstltc_c ( "Galileo",  5, lenvals, array )    ==   3
      lstltc_c ( "BETHE",    5, lenvals, array )    ==  -1
 
-Restrictions
 
   1)  The input array is assumed to be sorted in increasing order. 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) 
   H.A. Neilan     (JPL) 
   W.L. Taber      (JPL) 
 
-Version
 
   -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.

   -CSPICE Version 1.0.0, 22-JUL-2002 (NJB) (HAN) (WLT)

-Index_Entries
 
   last character element less_than
 
-&
*/

{ /* Begin lstltc_c */

   /*
   f2c library utility prototypes 
   */
   logical          l_gt   (char *a, char *b, ftnlen la, ftnlen lb ); 
   logical          l_le   (char *a, char *b, ftnlen la, ftnlen lb ); 
   logical          l_lt   (char *a, char *b, ftnlen la, ftnlen lb ); 

   /*
   Local macros 
   */
   #define ARRAY( i )     (  ( (SpiceChar *)array ) + (i)*lenvals  )


   /*
   Local variables
   */
   SpiceInt                begin;
   SpiceInt                end;
   SpiceInt                items;
   SpiceInt                j;
   SpiceInt                keylen;
   SpiceInt                middle;



   /*
   Use discovery check-in.

   Return immediately if the array dimension is non-positive. 
   */
   if ( n < 1 ) 
   {
      return ( -1 );
   }

   /*
   Make sure the pointer for the key value is non-null 
   and that the length is adequate.  
   */
   CHKPTR_VAL ( CHK_DISCOVER, "lstltc_c", string, -1 );

   
   /*
   Make sure the pointer for the string array is non-null 
   and that the length lenvals is sufficient.  
   */
   CHKOSTR_VAL ( CHK_DISCOVER, "lstltc_c", array, lenvals, -1 );   


   /*
   Return if none of the array's elements are less than the key value. 
   */
   keylen = strlen(string);

   begin  = 0;
   end    = n - 1;

   if (  l_le( ( char * )string, 
               ( char * )ARRAY(begin), 
               ( ftnlen )keylen, 
               ( ftnlen )strlen(ARRAY(begin)) )  )
   {
      return ( -1 );
   }


   /*
   Return if the key string is greater than all of the array's elements. 
   */
   if (  l_gt( ( char * )string, 
               ( char * )ARRAY(end), 
               ( ftnlen )keylen, 
               ( ftnlen )strlen(ARRAY(end)) )  )
   {
      return ( end );
   }


   /*
   Do a binary search for the specified key value. 

   At this point, string is greater than the first element of array and
   less than or equal to the last element of array.
   */
   items  = n;

   while ( items > 2 )
   {
      /*
      Check the middle element. 
      */
      j      = items / 2;
      middle = begin + j;

 
      /*
      Narrow the search area.
      */
      if (  l_lt ( (char    * ) ARRAY(middle),  
                   (char    * ) string,
                   (ftnlen    ) strlen( ARRAY(middle) ),
                   (ftnlen    ) keylen                   )  )
      {
         /*
         The middle element is less than string.
         */
         begin = middle;
      }
      else
      {
         end   = middle;
      }

      items = end - begin + 1;

      /*
      At this point, string is greater than the array element at index
      begin and is less than or equal to the element at index end.
      */
   }

   /*
   The element at index begin is the winner.
   */   
   return ( begin );

 
} /* End lstltc_c */
Пример #2
0
   SpiceInt esrchc_c ( ConstSpiceChar  * value,
                       SpiceInt          ndim,
                       SpiceInt          lenvals,
                       const void      * array    )                    
/*

-Brief_I/O
 
   VARIABLE  I/O              DESCRIPTION 
   --------  ---  -------------------------------------------------- 
   value      I   Key value to be found in array. 
   ndim       I   Dimension of array. 
   lenvals    I   String length.
   array      I   Character string array to search. 
 
   The function returns the index of the first array entry 
   equivalent to value, or -1 if none is 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 dimension of the array. 

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

                  [ndim][lenvals]
 
   array       is the array of character srings to be searched.  Trailing
               blanks in the strings in this array are not significant.   
 
-Detailed_Output
 
   The function returns the index of the first element of the 
   input array equivalent to the input value, or -1 if the 
   array contains no such elements. 
 
   Two strings are equivalent if they contain the same characters 
   in the same order, when blanks are ignored and uppercase and 
   lowercase characters are considered equal. 
 
-Parameters
 
   None. 
 
-Exceptions
 
   1) If ndim < 1 the function value is -1.  This is not considered
      an error.

   2) If input key value pointer is null, the error SPICE(NULLPOINTER) will 
      be signaled.  The function returns -1.
  
   3) The input key value may have length zero.  This case is not
      considered an error.

   4) If the input array pointer is null,  the error SPICE(NULLPOINTER) will 
      be signaled.  The function returns -1.

   5) If the input array string's length is less than 2, the error
      SPICE(STRINGTOOSHORT) will be signaled.  The function returns -1.
 
-Files
 
   None. 
 
-Particulars
 
   esrchc_c is identical to isrchc_c, except that it looks for 
   the first equivalent string (as defined by eqstr_c) instead 
   of the first identical one. 
 
-Examples
 
   Let array be declared with dimension

      [NDIM][STRLEN]

   and contain the following elements: 
 
      array[0] == "This" 
      array[1] == "little" 
      array[2] == "piggy" 
      array[3] == "went" 
      array[4] == "to" 
      array[5] == "market" 
 
   Then 
 
      esrchc_c ( "PIGGY",      NDIM,  STRLEN,  array )  ==  2
      esrchc_c ( " LiTtLe  ",  NDIM,  STRLEN,  array )  ==  1 
      esrchc_c ( "W e n t",    NDIM,  STRLEN,  array )  ==  3 
      esrchc_c ( "mall",       NDIM,  STRLEN,  array )  == -1 
 
-Restrictions
 
   None.
 
-Literature_References
 
   None. 
 
-Author_and_Institution
 
   N.J. Bachman    (JPL)
   I.M. Underwood  (JPL) 
 
-Version
 
   -CSPICE Version 1.0.0, 22-JUL-2002 (NJB) (IMU)

-Index_Entries
 
   search array for equivalent character_string 
 
-&
*/

{ /* Begin esrchc_c */


   /*
   Local macros 
   */
   #define ARRAY( i )     (  ( (SpiceChar *)array ) + (i)*lenvals  )

   /*
   Local variables
   */
   SpiceInt                i;
   

   /*
   Use discovery check-in.

   Return immediately if the array dimension is non-positive. 
   */
   if ( ndim < 1 ) 
   {
      return ( -1 );
   }


   /*
   Make sure the input pointer for the key value is non-null 
   and that the length is adequate.  
   */
   CHKPTR_VAL ( CHK_DISCOVER, "esrchc_c", value, -1 );

   
   /*
   Make sure the input pointer for the string array is non-null 
   and that the length lenvals is sufficient.  
   */
   CHKOSTR_VAL ( CHK_DISCOVER, "esrchc_c", array, lenvals, -1 );
   

   for ( i = 0;  i < ndim;  i++ )
   {
      if (  eqstr_c( value, ARRAY(i) )  )
      {
         return ( i );
      }
   }

   /*
   Indicate no match was found. 
   */
   return ( -1 );



} /* End esrchc_c */
Пример #3
0
   SpiceInt isrchc_c ( ConstSpiceChar  * value,
                       SpiceInt          ndim,   
                       SpiceInt          lenvals,
                       const void      * array   ) 
/*

-Brief_I/O
 
   VARIABLE  I/O              DESCRIPTION 
   --------  ---  -------------------------------------------------- 
   value      I   Key value to be found in array. 
   ndim       I   Dimension of array. 
   lenvals    I   String length.
   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 dimension of the array. 

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

                  [ndim][lenvals]
 
   array       is the array of character srings to be searched.  Trailing
               blanks in the strings in this array are not significant.
 
-Detailed_Output
 
   The function returns the index of the first matching array 
   element in array. If value is not found, isrchc_c returns -1. 
 
-Parameters
 
   None. 
 
-Exceptions
 
   1) If ndim < 1 the function value is -1.  This is not considered
      an error.

   2) If input key value pointer is null, the error SPICE(NULLPOINTER) will 
      be signaled.  The function returns -1.
 
   3) The input key value may have length zero.  This case is not
      considered an error.

   4) If the input array pointer is null,  the error SPICE(NULLPOINTER) will 
      be signaled.  The function returns -1.

   5) If the input array string's length is less than 2, the error
      SPICE(STRINGTOOSHORT) will be signaled.  The function returns -1.
 
-Files
 
   None.
 
-Particulars
 
   None. 
 
-Examples
 
   The following table shows the value of isrchc_c given the contents 
   of array and value: 
 
      array                 value     isrchc_c 
    -----------------       -----     -------- 
    "1", "0", "4", "2"       "4"          2
    "1", "0", "4", "2"       "2"          3 
    "1", "0", "4", "2"       "3"         -1 
 
-Restrictions
 
   1)  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.
     
   None. 
 
-Literature_References
 
   None 
 
-Author_and_Institution
 
   N.J. Bachman    (JPL)
   W.M. Owen       (JPL) 
 
-Version
 
 
   -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, 22-JUL-2002 (NJB) (WMO)

-Index_Entries
 
   search in a character array 
 
-&
*/

{ /* Begin isrchc_c */


   /*
   f2c library utility prototypes 
   */
   extern integer   s_cmp  (char *a, char *b, ftnlen la, ftnlen lb ); 

   /*
   Local macros 
   */
   #define ARRAY( i )     (  ( (SpiceChar *)array ) + i*lenvals  )

   /*
   Local variables
   */
   SpiceInt                i;
   

   /*
   Use discovery check-in.

   Return immediately if the array dimension is non-positive. 
   */
   if ( ndim < 1 ) 
   {
      return ( -1 );
   }


   /*
   Make sure the input pointer for the key value is non-null 
   and that the length is adequate.  
   */
   CHKPTR_VAL ( CHK_DISCOVER, "isrchc_c", value, -1 );

   
   /*
   Make sure the input pointer for the string array is non-null 
   and that the length lenvals is sufficient.  
   */
   CHKOSTR_VAL ( CHK_DISCOVER, "isrchc_c", array, lenvals, -1 );
   

   for ( i = 0;  i < ndim;  i++ )
   {
      if (  s_cmp ( (char   *) value,
                    (char   *) ARRAY(i),
                    (ftnlen  ) strlen(value),
                    (ftnlen  ) strlen(ARRAY(i)) )  == 0  )
      {
         return ( i );
      }
   }

   /*
   Indicate no match was found. 
   */
   return ( -1 );


} /* End isrchc_c */
Пример #4
0
   SpiceInt bsrchc_c ( ConstSpiceChar  * value,
                       SpiceInt          ndim,   
                       SpiceInt          lenvals,
                       const void      * array   ) 
/*

-Brief_I/O
 
   VARIABLE  I/O              DESCRIPTION 
   --------  ---  -------------------------------------------------- 
   value      I   Key value to be found in array. 
   ndim       I   Dimension of array. 
   lenvals    I   String length.
   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 that in the corresponding element of array.

   ndim        is the dimension of the array. 

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

                  [ndim][lenvals]

   array       is the array of character srings to be searched.  Trailing
               blanks in the strings in this array are not significant.
 
-Detailed_Output
  
   The function returns the index of the specified value in the input array. 
   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 ndim < 1 the function value is -1.  This is not considered
      an error.

   2) If input key value pointer is null, the error SPICE(NULLPOINTER) will 
      be signaled.  The function returns -1.

   3) The input key value may have length zero.  This case is not
      considered an error.

   4) If the input array pointer is null,  the error SPICE(NULLPOINTER) will 
      be signaled.  The function returns -1.

   5) If the input array string's length is less than 2, the error
      SPICE(STRINGTOOSHORT) will be signaled.  The function returns -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][lenvals]

   which contains the following elements:

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

   Then

      bsrchc_c ( "NEWTON",   5, lenvals, array )    ==   4
      bsrchc_c ( "EINSTEIN", 5, lenvals, array )    ==   1
      bsrchc_c ( "GALILEO",  5, lenvals, array )    ==   3
      bsrchc_c ( "Galileo",  5, lenvals, array )    ==  -1
      bsrchc_c ( "BETHE",    5, lenvals, array )    ==  -1
 
-Restrictions
 
   1)  The input array is assumed to be sorted in increasing order. 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)
   W.M. Owen       (JPL) 
 
-Version
 
   -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 
 
-&
*/

{ /* Begin bsrchc_c */

   /*
   f2c library utility prototypes 
   */
   logical          l_lt   (char *a, char *b, ftnlen la, ftnlen lb ); 
   extern integer   s_cmp  (char *a, char *b, ftnlen la, ftnlen lb ); 

   /*
   Local macros 
   */
   #define ARRAY( i )     (  ( (SpiceChar *)array ) + (i)*lenvals  )


   /*
   Local variables
   */
   SpiceInt                i;
   SpiceInt                keylen;
   SpiceInt                left;
   SpiceInt                order;
   SpiceInt                right;


   /*
   Use discovery check-in.

   Return immediately if the array dimension is non-positive. 
   */
   if ( ndim < 1 ) 
   {
      return ( -1 );
   }


   /*
   Make sure the pointer for the key value is non-null 
   and that the length is adequate.  
   */
   CHKPTR_VAL ( CHK_DISCOVER, "bsrchc_c", value, -1 );

   
   /*
   Make sure the pointer for the string array is non-null 
   and that the length lenvals is sufficient.  
   */
   CHKOSTR_VAL ( CHK_DISCOVER, "bsrchc_c", array, lenvals, -1 );   

  
   /*
   Do a binary search for the specified key value. 
   */
   keylen = strlen(value);

   left   = 0;
   right  = ndim - 1;

   while ( left <= right )
   {
      /*
      Check the middle element. 
      */
      i  =  ( left + right ) / 2;

      /*
      The f2c library function s_cmp performs a Fortran-style 
      lexical order comparison.  A negative return value indicates
      the first argument is less than the second, a return value
      of zero indicates equality, and a positive value indicates
      the second argument is greater.
      */
      order =  (SpiceInt) s_cmp ( (char    * ) value, 
                                  (char    * ) ARRAY(i),
                                  (ftnlen    ) keylen,
                                  (ftnlen    ) strlen(ARRAY(i)) );

      /*
      If the middle element matches, return its location.
      */
      if ( order == 0 )
      {
         return ( i );
      }
 
      /*
      Otherwise, narrow the search area.
      */
      else if ( order < 0 )
      {
         /*
         value is less than the middle element. 
         */
         right = i - 1;
      }

      else
      {
         left  = i + 1;
      }

   }

   /*
   If the search area is empty, indicate the value was not found.
   */   
   return ( -1 );


} /* End bsrchc_c */