1 /*
2 
3 -Procedure appndi_c ( Append an item to an integer cell )
4 
5 -Abstract
6 
7    Append an item to an integer cell.
8 
9 -Disclaimer
10 
11    THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE
12    CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S.
13    GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE
14    ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE
15    PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS"
16    TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY
17    WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A
18    PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC
19    SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE
20    SOFTWARE AND RELATED MATERIALS, HOWEVER USED.
21 
22    IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA
23    BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT
24    LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND,
25    INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS,
26    REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE
27    REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY.
28 
29    RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF
30    THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY
31    CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE
32    ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE.
33 
34 -Required_Reading
35 
36    CELLS
37 
38 -Keywords
39 
40    CELLS
41 
42 */
43 
44 
45 #include "SpiceUsr.h"
46 #include "SpiceZmc.h"
47 
48 
appndi_c(SpiceInt item,SpiceCell * cell)49    void appndi_c ( SpiceInt        item,
50                    SpiceCell     * cell )
51 
52 
53 /*
54 
55 -Brief_I/O
56 
57    VARIABLE  I/O  DESCRIPTION
58    --------  ---  --------------------------------------------------
59    item       I   The item to append.
60    cell      I/O  The cell to which item will be appended.
61 
62 -Detailed_Input
63 
64    item       is an integer value which is to be appended to cell.
65 
66    cell       is an integer SpiceCell to which item will be appended.
67 
68 -Detailed_Output
69 
70    cell       is the input SpiceCell with item appended.  item is the
71               last member of cell.
72 
73               If cell is actually a CSPICE set on input and ceases to
74               qualify as a set as result of the requested append
75               operation, the isSet member of cell will be set to
76               SPICEFALSE.
77 -Parameters
78 
79    None.
80 
81 -Files
82 
83    None.
84 
85 -Exceptions
86 
87    1) If the input cell argument doesn't have integer data type,
88       the error SPICE(TYPEMISMATCH) is signaled.
89 
90    2) If the cell is not big enough to accommodate the addition
91       of a new element, the error SPICE(CELLTOOSMALL) is signaled.
92 
93 -Particulars
94 
95    None.
96 
97 -Examples
98 
99    1)  In the following example, the element 34 is appended to
100        the integer cell fibNums.
101 
102          #include "SpiceUsr.h"
103                 .
104                 .
105                 .
106          /.
107          Declare the cell with maximum number of elements MAXSIZ.
108          ./
109          SPICEINT_CELL ( fibNums, MAXSIZ );
110                 .
111                 .
112                 .
113          /.
114          Before appending 34, the cell contains:
115 
116             Element 0: == 1
117             Element 1: == 1
118             Element 2: == 2
119             Element 3: == 3
120             Element 4: == 5
121             Element 5: == 8
122             Element 6: == 13
123             Element 7: == 21
124 
125          The following call appends the element 34 at index 8, and
126          updates the cardinality.
127          ./
128 
129          appndi_c ( 34, &fibNums );
130 
131 
132 -Restrictions
133 
134    None.
135 
136 -Literature_References
137 
138    None.
139 
140 -Author_and_Institution
141 
142    N.J. Bachman    (JPL)
143    H.A. Neilan     (JPL)
144 
145 -Version
146 
147    -CSPICE Version 1.0.0, 01-AUG-2002 (NJB) (HAN)
148 
149 -Index_Entries
150 
151    append an item to an integer cell
152 
153 -&
154 */
155 
156 { /* Begin appndi_c */
157 
158 
159    /*
160    Use discovery check-in.
161    */
162    if ( return_c() )
163    {
164       return;
165    }
166 
167    /*
168    Make sure we're working with an integer cell.
169    */
170    CELLTYPECHK ( CHK_DISCOVER, "appndi_c", SPICE_INT, cell );
171 
172 
173    if ( cell->card == cell->size )
174    {
175       chkin_c  ( "appndi_c"                                        );
176       setmsg_c ( "The cell cannot accomodate the addition of the "
177                  "element *"                                       );
178       errint_c ( "*", item                                         );
179       sigerr_c ( "SPICE(CELLTOOSMALL)"                             );
180       chkout_c ( "appndi_c"                                        );
181       return;
182    }
183 
184 
185    /*
186    Initialize the cell if necessary.
187    */
188    CELLINIT ( cell );
189 
190 
191    /*
192    The item must be strictly greater than its predecessor, or
193    the input cell is no longer a set.
194    */
195    if (  ( cell->isSet ) && ( cell->card > 0 )  )
196    {
197       if (  item  <=  SPICE_CELL_ELEM_I(cell, cell->card-1)  )
198       {
199          cell->isSet = SPICEFALSE;
200       }
201    }
202 
203 
204    /*
205    Append the item to the cell and increment the cell's cardinality.
206    */
207    SPICE_CELL_SET_I ( item, cell->card, cell );
208 
209    (cell->card) ++;
210 
211 
212    /*
213    Sync the cell.
214    */
215    zzsynccl_c ( C2F, cell );
216 
217 
218 } /* End appndi_c */
219