예제 #1
0
   void insrti_c ( SpiceInt        item,
                   SpiceCell     * set  )

/*

-Brief_I/O
 
   VARIABLE  I/O  DESCRIPTION 
   --------  ---  -------------------------------------------------- 
   item       I   Item to be inserted. 
   set       I/O  Insertion set. 
 
-Detailed_Input
 
   item        is an item which is to be inserted into the 
               specified set. item may or may not already 
               be an element of the set. 


   set         is a CSPICE set.  set must be declared as an integer
               SpiceCell. 

               On input, set  may or may not contain the input item 
               as an element. 
 
-Detailed_Output

   set         on output contains the union of the input set and 
               the singleton set containing the input item.
 
-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 insertion of the element into the set causes an excess 
      of elements, the error SPICE(SETEXCESS) is signaled. 
 
   3) 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
 
   None. 
 
-Examples
 
   1) In the following example, the NAIF ID code of Pluto is removed from 
      the integer set planets and inserted into the integer set 
      asteroids. 

         #include "SpiceUsr.h"
                .
                .
                .
         /.
         Declare the sets with maximum number of elements MAXSIZ.
         ./
         SPICEINT_CELL ( planets,   MAXSIZ );
         SPICEINT_CELL ( asteroids, MAXSIZ );
                .
                .
                .
         removi_c ( 999, &planets   );
         insrti_c ( 999, &asteroids ); 


      If 999 is not an element of planets, then the contents of 
      planets are not changed. Similarly, if 999 is already an 
      element of asteroids, the contents of asteroids remain unchanged. 

-Restrictions
 
   None. 

-Literature_References
 
   None. 
 
-Author_and_Institution
 
   N.J. Bachman    (JPL) 
   C.A. Curzon     (JPL) 
   W.L. Taber      (JPL) 
   I.M. Underwood  (JPL) 
 
-Version
 
   -CSPICE Version 2.0.0, 01-NOV-2005 (NJB)

       Long error message was updated to include size of
       set into which insertion was attempted.
 
   -CSPICE Version 1.0.0, 07-AUG-2002 (NJB) (CAC) (WLT) (IMU)

-Index_Entries
 
   insert an item into an integer set 
 
-&
*/
{
   /*
   local variables
   */
   SpiceBoolean            inSet;
   
   SpiceInt                i;
   SpiceInt              * idata;
   SpiceInt                loc;


   /*
   Use discovery check-in. 
   */
   
   /*
   Make sure we're working with an integer cell. 
   */
   CELLTYPECHK ( CHK_DISCOVER, "insrti_c", SPICE_INT, set );

   idata = (SpiceInt *) (set->data);

   /*
   Make sure the cell is really a set. 
   */
   CELLISSETCHK ( CHK_DISCOVER, "insrti_c", set );
 
   /*
   Initialize the set if necessary. 
   */
   CELLINIT ( set );
 
   /*
   Is the item already in the set? If not, it needs to be inserted.
   */
   loc   =  lstlei_c ( item,  set->card,  idata );

   inSet =  (  loc  >  -1  ) && ( item == idata[loc] );
 
   if ( inSet )
   {
      return;
   }

   /*
   It's an error if the set has no room left. 
   */
   if ( set->card == set->size )
   {
      chkin_c  ( "insrti_c"                                       );
      setmsg_c ( "An element could not be inserted into the set "
                 "due to lack of space; set size is #."           );
      errint_c ( "#", set->size                                   );
      sigerr_c ( "SPICE(SETEXCESS)"                               );
      chkout_c ( "insrti_c"                                       );
      return;
   }

   /*
   Make room by moving the items that come after item in the set. 
   Insert the item after index loc.
   */
   
   for (  i = (set->card);   i > loc+1;   i--  )
   {
      idata[i] = idata[i-1];
   }

   idata[loc+1] = item;

   /*
   Increment the set's cardinality.
   */
   (set->card) ++;

   /*
   Sync the set. 
   */
   zzsynccl_c ( C2F, set );
}
예제 #2
0
파일: insrtc_c.c 프로젝트: Dbelsa/coft
   void insrtc_c ( ConstSpiceChar  * item,
                   SpiceCell       * set   )

/*

-Brief_I/O
 
   VARIABLE  I/O  DESCRIPTION 
   --------  ---  -------------------------------------------------- 
   item       I   Item to be inserted. 
   set       I/O  Insertion set. 
 
-Detailed_Input
 
   item        is an item which is to be inserted into the specified
               set. item may or may not already be an element of the
               set.  Trailing blanks in item are not significant.


   set         is a CSPICE set.  set must be declared as a character
               SpiceCell. 

               On input, set  may or may not contain the input item 
               as an element. 
 
-Detailed_Output

   set         on output contains the union of the input set and 
               the singleton set containing the input item.
 
-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 insertion of the element into the set causes an excess 
      of elements, the error SPICE(SETEXCESS) is signaled. 
 
   3) 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.

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

-Files
 
   None. 
 
-Particulars
 
   None. 
 
-Examples
 
   1) In the following example, the element "PLUTO" is removed from 
      the character set planets and inserted into the character set 
      asteroids. 

         #include "SpiceUsr.h"
                .
                .
                .
         /.
         Declare the sets with string length NAMLEN and with maximum
         number of elements MAXSIZ.
         ./
         SPICECHAR_CELL ( planets,   MAXSIZ, NAMLEN );
         SPICECHAR_CELL ( asteroids, MAXSIZ, NAMLEN );
                .
                .
                .
         removc_c ( "PLUTO", &planets   );
         insrtc_c ( "PLUTO", &asteroids ); 


      If "PLUTO" is not an element of planets, then the contents of 
      planets are not changed. Similarly, if "PLUTO" is already an 
      element of asteroids, the contents of asteroids remain unchanged. 

      Because inserting an element into a set can increase the 
      cardinality of the set, an error may occur in the insertion 
      routines. 
 
-Restrictions
 
   1)  String comparisons performed by this routine are Fortran-style:
       trailing blanks in the input set 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) 
   W.L. Taber      (JPL) 
   I.M. Underwood  (JPL) 
 
-Version
 
   -CSPICE Version 2.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 2.0.0, 01-NOV-2005 (NJB)
         
       Bug fix:  when the item to be inserted would, after
       truncation to the set's string length, match an item
       already in the set, no insertion is performed.  Previously
       the truncated string was inserted, corrupting the set.

       Long error message was updated to include size of
       set into which insertion was attempted.
         
   -CSPICE Version 1.0.0, 21-AUG-2002 (NJB) (CAC) (WLT) (IMU)

-Index_Entries
 
   insert an item into a character set 
 
-&
*/
{
   /*
   f2c library utility prototypes 
   */
   extern integer   s_cmp  (char *a, char *b, ftnlen la, ftnlen lb ); 


   /*
   Local macros 
   */
   #define ARRAY( i )    (  (SpiceChar *)(set->data) + (i)*(set->length)  )


   /*
   local variables
   */
   SpiceBoolean            inSet;

   SpiceChar             * cdata;

   SpiceInt                i;
   SpiceInt                loc;
   SpiceInt                slen;



   /*
   Use discovery check-in. 

   Check the input string pointer to make sure it's not null.
   */
   CHKPTR ( CHK_DISCOVER, "insrtc_c", item );


   /*
   Make sure we're working with a character cell. 
   */
   CELLTYPECHK ( CHK_DISCOVER, "insrtc_c", SPICE_CHR, set );


   /*
   Make sure the input cell is a set.
   */
   CELLISSETCHK ( CHK_DISCOVER, "insrtc_c", set );


   /*
   Initialize the set if it's not already initialized.
   */
   CELLINIT ( set );


   /*
   Let slen be the effective string length of the input item.
   Characters beyond the string length of the set are ignored.
   */
   slen = mini_c ( 2, set->length, strlen(item) );


   /*
   Is the item already in the set? If not, it needs to be inserted.
   */
   cdata =  (SpiceChar *) (set->data);

   /*
   The following call will give the location of the last element
   less than or equal to the item to be inserted.  If the item
   differs from an element of the set only in characters that would
   be truncated, no insertion will occur.  Even in this case, the
   insertion point `loc' returned by lstlec_c will be correct.
   */
   loc   =  lstlec_c ( item,  set->card,  set->length,  cdata );

   inSet =     (  loc  >  -1  ) 

            && (  s_cmp( (SpiceChar *)item,  ARRAY(loc), 
                          slen,              strlen(ARRAY(loc)) ) == 0  );
 
   if ( inSet )
   {
      return;
   }

   
   /*
   It's an error if the set has no room left. 
   */
   if ( set->card == set->size )
   {
      chkin_c  ( "insrtc_c"                                       );
      setmsg_c ( "An element could not be inserted into the set "
                 "due to lack of space; set size is #."           );
      errint_c ( "#", set->size                                   );
      sigerr_c ( "SPICE(SETEXCESS)"                               );
      chkout_c ( "insrtc_c"                                       );
      return;
   }


   /*
   Make room by moving the items that come after index loc in the set. 
   Insert the item after index loc.
   */
   for (  i = (set->card);   i > (loc+1);   i--  )
   {
      SPICE_CELL_SET_C( ARRAY(i-1), i, set );
   }

   /*
   This insertion macro will truncate the item to be inserted, if 
   necessary.  The input item will be null-terminated.
   */
   SPICE_CELL_SET_C( item, loc+1, set );


   /*
   Increment the set's cardinality.
   */
   (set->card) ++;

}
예제 #3
0
   void removd_c ( SpiceDouble     item,
                   SpiceCell     * set  )

/*

-Brief_I/O
 
   VARIABLE  I/O  DESCRIPTION 
   --------  ---  -------------------------------------------------- 
   item       I   Item to be removed. 
   set       I/O  Removal set. 
 
-Detailed_Input
 
   item        is an item which is to be removed from the specified
               set. item may or may not already be an element of the
               set.


   set         is a CSPICE set.  set must be declared as a double
               precision SpiceCell.
 
               On input, set may or may not contain the input item 
               as an element. 
 
-Detailed_Output
 
   set         on output contains the difference of the input set and
               the input item. If the item is not an element of the
               set, the set is not changed.
 
-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
 
   None. 
 
-Examples
 
   1) In the following code fragment, a list of camera exposure
      durations are taken from the array expList and inserted into the
      set expDur.

      We then update the set by removing the element 30.0 and 
      inserting 20.0 in its place.


         #include "SpiceUsr.h"
                .
                .
                .
         /.
         The number of list items is NLIST.
         ./
         SpiceDouble        expList[NLIST] = 
                            { 
                               0.5, 2.0, 0.5, 30.0, 0.01, 30.0 
                            };

         /.
         Declare the set with maximum number of elements MAXSIZ.
         ./
         SPICEDOUBLE_CELL ( expDur,   MAXSIZ );
                .
                .
                .
         for ( i = 0;  i < NLIST;  i++ )
         {
            insrtd_c ( expList[i], &expDur );
         }
        
         /.
         At this point expDur contains the set

           { 0.01, 0.5, 2.0, 30.0 }

         ./
                .
                .
                .
         /. 
         Update the exposure set by replacing 30.0 with 20.0.
         ./
         removd_c ( 30.0, &expDur );
         insrtd_c ( 20.0, &expDur ); 


-Restrictions
 
   None. 
 
-Literature_References
 
   None. 
 
-Author_and_Institution

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

-Index_Entries
 
   remove an item from a d.p. set 
 
-&
*/
{
   /*
   local variables
   */
   SpiceBoolean            inSet;

   SpiceDouble           * ddata;
   
   SpiceInt                i;
   SpiceInt                loc;


   /*
   Use discovery check-in. 

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

   ddata = (SpiceDouble *) (set->data);


   /*
   Make sure the cell is really a set. 
   */
   CELLISSETCHK ( CHK_DISCOVER, "removd_c", set );


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


   /*
   Is the item in the set? If not, we're done now.
   */
   loc   =  lstled_c ( item,  set->card,  ddata );

   inSet =  (  loc  >  -1  ) && ( item == ddata[loc] );
 
   if ( !inSet )
   {
      return;
   }

   
   /*
   Shift the set's contents to overwrite the slot at index loc.
   */   
   for (  i = loc;   i < (set->card) - 1;   i++  )
   {
      ddata[i] = ddata[i+1];
   }


   /*
   Decrement the set's cardinality.
   */
   (set->card) --;

   /*
   Sync the set. 
   */
   zzsynccl_c ( C2F, set );
}