Example #1
0
File: ordd_c.c Project: Dbelsa/coft
   SpiceInt ordd_c ( SpiceDouble     item,
                     SpiceCell     * set  )

/*

-Brief_I/O
 
   VARIABLE  I/O  DESCRIPTION 
   --------  ---  -------------------------------------------------- 
   item       I   An item to locate within a set. 
   set        I   A set to search for a given item. 
 
   The function returns the ordinal position of item within the set. 
 
-Detailed_Input
 
   item      is a double precision number to be located within a set. 
 
   set       is a double precision CSPICE set that is to be searched
             for the occurrence of item.
 
             set must be declared as a double precision SpiceCell.

-Detailed_Output
 
   The function returns the ordinal position of item within set. 
   Ordinal positions range from 0 to N-1, where N is the cardinality
   of the set.

   If item is not an element of set, the function returns -1. 
 
-Parameters
 
   None. 
 
-Exceptions
  
   1) If the input set argument is a SpiceCell of type other than
      double precision, the error SPICE(TYPEMISMATCH) is signaled.
 
   2) If the input set argument does not qualify as a CSPICE set, 
      the error SPICE(NOTASET) will be signaled.  CSPICE sets have
      their data elements sorted in increasing order and contain
      no duplicate data elements.

-Files
 
   None. 
 
-Particulars
 
   A natural ordering can be imposed upon the elements of any 
   CSPICE set, be it integer, character or double precision.  For 
   character strings the ASCII collating sequence serves as the 
   ordering relation, for double precision and integer variables 
   the arithmetic ordering is used. 
 
   Given any element of a set, its location within this ordered 
   sequence of elements is called its ordinal position within 
   the set. 

   In common mathematical usage, ordinal positions of elements
   in a set of cardinality N range from 1 to N.  In C programs,
   it is much more convenient to use the range 0 to N-1; this is
   the convention used in CSPICE.
 
   For illustrative purposes suppose that set represents the set 
 
      { 8, 1, 2, 9, 7, 4, 10 } 
 
   The ordinal position of:    

       8 is 4 
       1 is 0 
       2 is 1 
       9 is 5 
       7 is 3 
       4 is 2 
      10 is 6 
  
-Examples
 
   1) Obtain the ordinal positions shown in the table of the Particulars
      section above.

         
         #include "SpiceUsr.h"

         int main()
         {
            /.
            Declare a double precision set and populate it with 
            the elements shown above.
            ./
            #define MAXSIZ         7

            SPICEDOUBLE_CELL ( set, MAXSIZ );

            SpiceDouble            inputs [MAXSIZ] = 
                                   {
                                      8.0, 1.0, 2.0, 9.0, 7.0, 4.0, 10.0
                                   };

            SpiceDouble            expected [MAXSIZ] = 
                                   {
                                      4.0, 0.0, 1.0, 5.0, 3.0, 2.0, 6.0
                                   };

            SpiceInt               i;
            SpiceDouble            dElt;


            /.
            Create the set.
            ./

            for ( i = 0;  i < MAXSIZ;  i++ )
            {
               insrtd_c ( inputs[i], &set );
            }

            /.
            Examine the ordinal positions of the set's elements.
            Extract each element and verify that ordd_c gives the
            index at which the element is located.
            ./

            for ( i = 0;  i < card_c(&set);  i++ )
            {
               dElt = inputs[i];

               if (  ordd_c(dElt, &set)  !=  expected[i]  )
               {
                  setmsg_c ( "Position of # was expected to be # "
                             "but was actually #."                 );
                  errdp_c  ( "#",  dElt                            );
                  errdp_c  ( "#",  expected[i]                     );
                  errint_c ( "#",  ordd_c(dElt,&set)               );
                  sigerr_c ( "INVALID LOCATION"                    );
               }
            }

            return ( 0 );
         }


-Restrictions
 
   None.
 
-Literature_References
 
   None. 
 
-Author_and_Institution
 
   N.J. Bachman    (JPL) 
   C.A. Curzon     (JPL) 
   H.A. Neilan     (JPL) 
   W.L. Taber      (JPL) 
   I.M. Underwood  (JPL) 
 
-Version
 
   -CSPICE Version 1.0.0, 07-AUG-2002 (NJB) (CAC) (HAN) (WLT) (IMU)

-Index_Entries
 
   the ordinal position of an element in a set 
 
-&
*/

{ /* Begin ordd_c */
                     

   /*
   Use discovery check-in. 

   Make sure we're working with a double precision cell. 
   */
   CELLTYPECHK_VAL ( CHK_DISCOVER, "ordd_c", SPICE_DP, set, -1 );

   /*
   Initialize the set if necessary. 
   */
   CELLINIT ( set );

   /*
   Make sure the cell is really a set. 
   */
   CELLISSETCHK_VAL ( CHK_DISCOVER, "ordd_c", set, -1 );

   /*
   The routine bsrchd_c returns the index of the item in the set,
   or -1 if the item is not present.
   */
   return (  bsrchd_c ( item,  set->card,  set->data ) );


} /* End ordd_c */
Example #2
0
   SpiceBoolean wnelmd_c ( SpiceDouble    point,
                           SpiceCell    * window ) 

/*

-Brief_I/O

   VARIABLE  I/O  DESCRIPTION 
   --------  ---  -------------------------------------------------- 
   point      I   Input point. 
   window     I   Input window. 

   The function returns SPICETRUE if point is an element of window. 
 
-Detailed_Input

   point       is a point, which may or may not be contained in 
               one of the intervals in window. 

   window      is a CSPICE window containing zero or more intervals. 

               window must be declared as a double precision SpiceCell.
 
-Detailed_Output
 
   The function returns SPICETRUE if the input point is an element of 
   the input window---that is, if 

      a(i)  <  point  <  b(i) 
            -         - 

   for some interval [ a(i), b(i) ] in window---and returns SPICEFALSE 
   otherwise. 
 
-Parameters
 
   None. 
 
-Exceptions
  
   1) If the input window does not have double precision type,
      the error SPICE(TYPEMISMATCH) is signaled.
 
-Files
 
   None. 
 
-Particulars
 
   None. 
 
-Examples
 
   Let a contain the intervals 

      [ 1, 3 ]  [ 7, 11 ]  [ 23, 27 ] 

   Then the following expressions take the value SPICETRUE

      wnelmd_c ( 1.0, &window );
      wnelmd_c ( 9.0, &window );

   and the following expressions take the value SPICEFALSE

      wnelmd_c (  0.0, &window );
      wnelmd_c ( 13.0, &window );
      wnelmd_c ( 29.0, &window );

-Restrictions
 
   None. 
 
-Literature_References
 
   None. 
 
-Author_and_Institution
 
   N.J. Bachman    (JPL)
   H.A. Neilan     (JPL) 
   W.L. Taber      (JPL) 
   I.M. Underwood  (JPL) 
 
-Version
 
   -CSPICE Version 1.0.0, 29-JUL-2002 (NJB) (HAN) (WLT) (IMU)

-Index_Entries
 
   element of a d.p. window 
 
-&
*/

{ /* Begin wnelmd_c */

   /*
   Local variables 
   */
   SpiceBoolean            retval;


   /*
   Use discovery check-in.

   Make sure cell data type is d.p. 
   */
   CELLTYPECHK_VAL ( CHK_DISCOVER, 
                     "wnelmd_c", SPICE_DP, window, SPICEFALSE );

   /*
   Initialize the cell if necessary. 
   */
   CELLINIT ( window );
   
   /*
   Let the f2c'd routine do the work. 
   */
   retval = wnelmd_ ( (doublereal * ) &point,
                      (doublereal * ) (window->base) );

   return   ( retval );

} /* End wnelmd_c */
Example #3
0
   SpiceBoolean elemd_c ( SpiceDouble     item,
                          SpiceCell     * set   )

/*

-Brief_I/O
 
   VARIABLE  I/O  DESCRIPTION 
   --------  ---  -------------------------------------------------- 
   item       I   Item to be tested. 
   set        I   Set to be tested. 

   The function returns SPICETRUE if item is an element of set. 
 
-Detailed_Input
 
   item        is an item which may or may not be an element of 
               the input set. 
 
 
   set         is a CSPICE set.  set must be declared as a double
               precision SpiceCell.  
 
-Detailed_Output

   The function returns SPICETRUE if item is a member of the set, 
   and returns SPICEFALSE otherwise. 
 
-Parameters
 
   None. 
 
-Exceptions
  
   1) If the input set argument does not qualify as a CSPICE set, 
      the error SPICE(NOTASET) will be signaled.  CSPICE sets have
      their data elements sorted in increasing order and contain
      no duplicate data elements.

   2) If the input set does not have double precision data type, 
      the error SPICE(TYPEMISMATCH will be signaled.
 
-Files
 
   None. 
 
-Particulars
 
   This routine uses a binary search to check for the presence in the set
   of the specified item.
 
-Examples
 
   Let set contain the elements

      { -1.0, 0.0, 1.0, 3.0, 5.0 }

   The the following expressions have the value SPICETRUE
      
      elemd_c ( -1.0, &set )
      elemd_c (  0.0, &set )
      elemd_c (  3.0, &set )

   and the following expressions have the value SPICEFALSE

      elemd_c ( -2.0, &set )
      elemd_c (  2.0, &set )
      elemd_c (  6.0, &set )

-Restrictions
 
   None. 
 
-Literature_References
 
   None. 
 
-Author_and_Institution
 
   N.J. Bachman    (JPL) 
   C.A. Curzon     (JPL) 
   H.A. Neilan     (JPL) 
   W.L. Taber      (JPL) 
   I.M. Underwood  (JPL) 
 
-Version
 
   -CSPICE Version 1.0.0, 07-AUG-2002 (NJB) (CAC) (HAN) (WLT) (IMU)

-Index_Entries
 
   element of a d.p. set 
 
-&
*/
{

   /*
   Use discovery check-in. 

   Make sure we're working with a double precision cell. 
   */
   CELLTYPECHK_VAL ( CHK_DISCOVER, "elemd_c", SPICE_DP, set, SPICEFALSE );

   /*
   Make sure the input cell is a set.
   */
   CELLISSETCHK_VAL ( CHK_DISCOVER, "elemd_c", set, SPICEFALSE );

   /*
   Initialize the set if necessary. 
   */
   CELLINIT ( set );

   /*
   The routine bsrchd_c returns the index of the item in the set,
   or -1 if the item is not present.
   */
   return (  bsrchd_c ( item,  set->card,  set->data )  !=  -1 );
}
Example #4
0
   SpiceInt ordc_c ( ConstSpiceChar  * item,
                     SpiceCell       * set   )
/*

-Brief_I/O
 
   VARIABLE  I/O  DESCRIPTION 
   --------  ---  -------------------------------------------------- 
   item       I   An item to locate within a set. 
   set        I   A set to search for a given item. 
 
   The function returns the ordinal position of item within the set. 
 
-Detailed_Input
 
   item      is a character string to be located within a set. 
             Trailing blanks are not significant in the comparison.
 

   set       is an integer CSPICE set that is to be searched for the
             occurrence of item.  Trailing blanks are not significant 
             in the comparison.
 
             set must be declared as a character SpiceCell.

-Detailed_Output
 
   The function returns the ordinal position of item within set. 
   Ordinal positions range from 0 to N-1, where N is the cardinality
   of the set.

   If item is not an element of set, the function returns -1. 
 
-Parameters
 
   None. 
 
-Exceptions
  
   1) If the input set argument is a SpiceCell of type other than
      character, the error SPICE(TYPEMISMATCH) is signaled.
 
   2) If the input set argument does not qualify as a CSPICE set, 
      the error SPICE(NOTASET) will be signaled.  CSPICE sets have
      their data elements sorted in increasing order and contain
      no duplicate data elements.

   3) If the input string pointer is null, the error SPICE(NULLPOINTER)
      is signaled.


-Files
 
   None. 
 
-Particulars
 
   A natural ordering can be imposed upon the elements of any 
   CSPICE set, be it integer, character or double precision.  For 
   character strings the ASCII collating sequence serves as the 
   ordering relation, for double precision and integer variables 
   the arithmetic ordering is used. 
 
   Given any element of a set, its location within this ordered 
   sequence of elements is called its ordinal position within 
   the set. 

   In common mathematical usage, ordinal positions of elements
   in a set of cardinality N range from 1 to N.  In C programs,
   it is much more convenient to use the range 0 to N-1; this is
   the convention used in CSPICE.
 
   For illustrative purposes suppose that set represents the set 
 
      { "8", "1", "2", "9", "7", "4", "10" } 
 
   The ordinal position of:    

       "8" is 5 
       "1" is 0 
       "2" is 2 
       "9" is 6 
       "7" is 4 
       "4" is 3 
      "10" is 1 
  
-Examples
 
   1) Obtain the ordinal positions shown in the table of the Particulars
      section above.

         
         #include "SpiceUsr.h"

         int main()
         {
            /.
            Declare an integer set and populate it with the elements
            shown above.
            ./
            #define MAXSIZ         7
            #define ITMLEN         10

            SPICECHAR_CELL ( set, MAXSIZ, ITMLEN );

            SpiceChar            * cElt;

            SpiceChar              inputs [MAXSIZ][ITMLEN] = 
                                   {
                                      "8", "1", "2", "9", "7", "4", "10"
                                   };

            SpiceInt               expected [MAXSIZ] = 
                                   {
                                      5, 0, 2, 6, 4, 3, 1
                                   };

            SpiceInt               i;


            /.
            Create the set.
            ./

            for ( i = 0;  i < MAXSIZ;  i++ )
            {
               insrtc_c ( inputs[i], &set );
            }

            /.
            Examine the ordinal positions of the set's elements.
            Extract each element and verify that ordc_c gives the
            index at which the element is located.
            ./

            for ( i = 0;  i < card_c(&set);  i++ )
            {
               cElt = inputs[i];

               if (  ordc_c(cElt, &set)  !=  expected[i]  )
               {
                  setmsg_c ( "Position of # was expected to be # "
                             "but was actually #."                 );
                  errch_c  ( "#",  cElt                            );
                  errint_c ( "#",  expected[i]                     );
                  errint_c ( "#",  ordc_c(cElt,&set)               );
                  sigerr_c ( "INVALID LOCATION"                    );
               }
            }

            return ( 0 );
         }


-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.
 
-Literature_References
 
   None. 
 
-Author_and_Institution
 
   N.J. Bachman    (JPL) 
   C.A. Curzon     (JPL) 
   H.A. Neilan     (JPL) 
   W.L. Taber      (JPL) 
   I.M. Underwood  (JPL) 
 
-Version
 
   -CSPICE Version 1.0.0, 21-AUG-2002 (NJB) (CAC) (HAN) (WLT) (IMU)

-Index_Entries
 
   the ordinal position of an element in a set 
 
-&
*/
{
   /*
   Use discovery check-in. 

   Check the input string pointer to make sure it's not null.
   */
   CHKPTR_VAL ( CHK_DISCOVER, "ordc_c", item, -1 );


   /*
   Make sure we're working with a character cell. 
   */
   CELLTYPECHK_VAL ( CHK_DISCOVER, "ordc_c", SPICE_CHR, set, -1 );


   /*
   Initialize the set if necessary. 
   */
   CELLINIT ( set );

   /*
   Make sure the cell is really a set. 
   */
   CELLISSETCHK_VAL ( CHK_DISCOVER, "ordc_c", set, -1 );

   /*
   The routine bsrchc_c returns the index of the item in the set,
   or -1 if the item is not present.
   */
   return (  bsrchc_c ( item,  set->card,  set->length,  set->data )  );
}