Index Page
ordi_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 ordi_c ( SpiceInt        item,
                     SpiceCell     * set   )

Abstract

 
   The function returns the ordinal position of any given item in an
   integer set.  If the item does not appear in the set, the function
   returns -1.
 

Required_Reading

 
   SETS 
 

Keywords

 
   SEARCH 
   SETS 
 

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 an integer to be located within a set. 
 
   set       is an integer CSPICE set that is to be searched for the
             occurrence of item.
 
             set must be declared as an integer 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
      integer, 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 an integer set and populate it with the elements
            shown above.
            ./
            #define MAXSIZ         7

            SPICEINT_CELL ( set,   MAXSIZ );

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

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

            SpiceInt               i;
            SpiceInt               iElt;


            /.
            Create the set.
            ./

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

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

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

               if (  ordi_c(iElt, &set)  !=  expected[i]  )
               {
                  setmsg_c ( "Position of # was expected to be # "
                             "but was actually #."                 );
                  errint_c ( "#",  iElt                            );
                  errint_c ( "#",  expected[i]                     );
                  errint_c ( "#",  ordi_c(iElt,&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 
 
Wed Apr  5 17:54:40 2017