/*

-Procedure removc_c ( Remove an item from a character set )

-Abstract
 
   Remove an item from a character set.
 
-Disclaimer

   THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE
   CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S.
   GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE
   ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE
   PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS"
   TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY
   WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A
   PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC
   SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE
   SOFTWARE AND RELATED MATERIALS, HOWEVER USED.

   IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA
   BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT
   LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND,
   INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS,
   REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE
   REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY.

   RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF
   THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY
   CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE
   ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE.

-Required_Reading
 
   SETS 
 
-Keywords
 
   CELLS, SETS 
 
*/

   #include "SpiceUsr.h"
   #include "SpiceZfc.h"
   #include "SpiceZmc.h"
   #include "f2cMang.h"


   void removc_c ( ConstSpiceChar  * 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.  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 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
      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
 
   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. 
 
-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 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, 07-AUG-2002 (NJB) (CAC) (WLT) (IMU)

-Index_Entries
 
   remove an item from 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;


   /*
   Use discovery check-in. 
   */

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


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


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


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


   /*
   Is the item in the set? If not, we're done now.
   */
   cdata =  (SpiceChar *) (set->data);

   loc   =  lstlec_c ( item,  set->card,  set->length,  cdata );

   inSet =       (  loc  >  -1  ) 

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

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


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

}

