1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
//! # Cells
//!
//! Last revised on 2017 MAR 13 by N. J. Bachman.
//!
//!
//!
//!
//!
//! ## Abstract
//!
//! Cells are SPICE data structures that are vectors of type double
//! precision, integer, or character type carrying with them their own
//! dimension and knowledge of how many components have been used.
//!
//!
//!
//!
//!
//! ## Introduction
//!
//! A "cell array"' is an array dimensioned from LBCELL to CMAX, where
//! LBCELL is the standard lower bound of a cell (currently -5) and CMAX is
//! the maximum number of elements that the cell is allowed to contain at
//! any one time---that is, the maximum cardinality of the cell.
//!
//! A "cell"' is a cell array in which elements LBCELL through 0 contain
//! information about whatever is stored in the rest of the array. CMAX is
//! stored in this part of the cell, as is CCUR, the current cardinality of
//! the cell. For character cells, these values are encoded into character
//! strings. The SPICELIB cell's compact representation allows the user to
//! declare, pass, and otherwise manipulate cells without having to keep
//! track of separate pointers and dimensions for each cell array. Thus, a
//! routine to merge the contents of two arrays into a third, when coded
//! using cells, looks like this
//!
//!
//!
//! ```text
//! CALL MERGE ( OLD, NEW, TOTAL )
//! ```
//!
//! instead of like this
//!
//!
//!
//! ```text
//! CALL MERGE ( OLD, N_OLD, NEW, N_NEW, MAX_TOTAL, TOTAL, N_TOTAL )
//! ```
//!
//! This is especially convenient for arrays that need to be passed as
//! arguments through several levels of subprograms. Frequently, such arrays
//! are placed in common blocks to avoid the proliferation of pointers and
//! dimensions in calling sequences. This also remedies one of the serious
//! flaws in the implementation of Fortran arrays---the inability of a
//! subprogram to determine the size of an argument array into which it is
//! to place values. Since the size of a cell is always available,
//! subroutines that manipulate cells can always check for overflow
//! conditions.
//!
//!
//!
//!
//!
//! ## Naming Conventions
//!
//! The type of a cell is the same as the type of the cell array. In
//! general, cell routines come in groups of three, the last letter of which
//! indicates the cell type. We will refer to the generic routines by
//! substituting an "x"' for the last letter. Thus, CARDx may be any of the
//! following: [CARDC](crate::raw::cardc), [CARDD](crate::raw::cardd), or [CARDI](crate::raw::cardi). In specific contexts, we will use the
//! specific names of routines. Before a cell can be used, it must be
//! initialized. During initialization, the size is set to the maximum
//! cardinality of the cell, the current cardinality is set to zero, and the
//! remaining control information becomes undefined. A cell need be
//! initialized only once, after which it may be used freely. (This assumes,
//! of course, that routines which manipulate the cells remember to reset
//! the cardinality when appropriate.)
//!
//! The subroutine SSIZEx is used to initialize a cell, as shown below.
//!
//!
//!
//! ```text
//! INTEGER LBCELL
//! PARAMETER ( LBCELL = -5 )
//!
//! DOUBLE PRECISION X ( LBCELL:100 )
//! DOUBLE PRECISION TEMP ( LBCELL:100 )
//! .
//! .
//!
//! CALL SSIZED ( 100, X )
//! CALL SSIZED ( 100, TEMP )
//! ```
//!
//! We strongly recommend that you use a parameter, LBCELL, to declare the
//! lower bounds of cells, as shown above.
//!
//!
//!
//!
//!
//! ## Using Cells
//!
//! SPICELIB cells may be populated using the APPNDx routines. These
//! routines "append" a datum to a cell: they insert a specified data item
//! into the lowest-indexed free slot in the data area of the cell array.
//! The APPNDx routines automatically update the cell's cardinality to
//! reflect the addition of the new datum.
//!
//! To append three double precision numbers onto an empty double precision
//! cell, we could use the code fragment
//!
//!
//!
//! ```text
//! INTEGER LBCELL
//! PARAMETER ( LBCELL = -5 )
//!
//! DOUBLE PRECISION X ( LBCELL : 100 )
//!
//! CALL SSIZED ( 100, X )
//!
//! CALL APPNDD ( 0.D0, X )
//! CALL APPNDD ( 0.D0, X )
//! CALL APPNDD ( 1.D0, X )
//! ```
//!
//! Another subroutine SCARDx is used to adjust the cardinality of a cell.
//! This is necessary when directly inserting items into or removing items
//! from a cell, as shown below.
//!
//!
//!
//! ```text
//! CALL SSIZED ( 100, X )
//!
//! X(1) = 0.D0
//! X(2) = 0.D0
//! X(3) = 1.D0
//!
//! CALL SCARDD ( 3, X )
//! ```
//!
//! SSIZEx and SCARDx should always be used in lieu of altering the contents
//! of elements LBCELL through 0 directly.
//!
//! The subroutine COPYx copies the elements of one cell to another cell.
//! This can be useful for modifying temporary or working cells, or for
//! saving copies of cells which are about to be changed. For example,
//!
//!
//!
//! ```text
//! INTEGER LBCELL
//! PARAMETER ( LBCELL = -5 )
//!
//! DOUBLE PRECISION X ( LBCELL : 100 )
//! DOUBLE PRECISION TEMP ( LBCELL : 100 )
//!
//! CALL SSIZED ( 100, X )
//! CALL SSIZED ( 100, TEMP )
//!
//! CALL COPYD ( X, TEMP )
//! ```
//!
//! copies the contents of X into TEMP. In this case, the cells are the same
//! size (each can hold up to 100 elements), so the operation will always
//! succeed. In general, if the output cell is not large enough to hold the
//! contents of the input cell, as many elements as will fit are inserted
//! into the output cell, and the SPICELIB error handling mechanism reports
//! the number of excess elements.
//!
//! An extra check is performed by [COPYC](crate::raw::copyc), which copies character cells. In
//! order to avoid truncation problems, [COPYC](crate::raw::copyc) verifies that the operation
//! can be performed without losing any of the non-blank characters in the
//! original cell. The loss of one or more non-blank characters is reported
//! through the SPICELIB error handling mechanism.
//!
//! The integer function CARDx returns the cardinality of a cell. This may
//! be used to determine whether a cell is empty or not. (The cardinality of
//! an empty cell is zero.) It may also be used to assist in accessing the
//! elements of a cell individually, as in the following example.
//!
//!
//!
//! ```text
//! WRITE (6,*) 'Winners of the Nobel Prize for Physics:'
//!
//! DO I = 1, CARDC ( NOBEL )
//! WRITE (6,*) NOBEL(I)
//! END DO
//! ```
//!
//! The integer function SIZEx returns the size (maximum cardinality) of a
//! cell. This is useful primarily for predicting situations in which
//! overflow can occur, as in the following example.
//!
//!
//!
//! ```text
//! IF ( CARDC ( WINNERS ) .LE. SIZEC ( NOBEL ) ) THEN
//! CALL COPYC ( WINNERS, NOBEL )
//! ELSE
//! .
//! .
//! .
//! END IF
//! ```
//!
//!
//! ## Character Cells
//!
//! As we mentioned earlier, the size and cardinality of a cell are stored
//! in the control area of the cell (elements LBCELL through 0). For numeric
//! data types, this is accomplished by simple assignment. However, in the
//! case of cell arrays of type character, the values for the size and
//! cardinality must be encoded into character strings.
//!
//! This is done by storing the numbers in base CHBASE, where CHBASE is the
//! number of distinct characters in the character set supported by the host
//! machine and compiler. (In ASCII environments, CHBASE is always at least
//! 128, and may be as high as 256.) The numbers are encoded and decoded by
//! subroutines [ENCHAR](crate::raw::enchar) and [DECHAR](crate::raw::dechar) respectively. The value of parameter
//! MINLEN (declared in [ENCHAR](crate::raw::enchar)) constrains the minimum length of the
//! elements in a cell array. The nominal value for MINLEN is 5. Given this
//! value,
//!
//!
//!
//! ```text
//! INTEGER LBCELL
//! PARAMETER ( LBCELL = -5 )
//!
//! CHARACTER*5 NAMES ( LBCELL:1000 )
//! ```
//!
//! is a legal cell declaration, while
//!
//!
//!
//! ```text
//! INTEGER LBCELL
//! PARAMETER ( LBCELL = -5 )
//!
//! CHARACTER*4 NAMES ( LBCELL:1000 )
//! ```
//!
//! is not.
//!
//!
//!
//!
//!
//! ## Cell-based data types
//!
//! SPICELIB contains several extended data types based on cells. For
//! example, one family of routines uses cells to implement algebraic sets
//! of all types (character, integer, double precision). Another uses double
//! precision cells to manipulate collections of closed intervals of the
//! real numbers, called windows.
//!
//! All of these data types are supported by routines designed to manipulate
//! them. However, because they are based on cells, all of these data types
//! can be manipulated by the general cell routines as well. Thus, COPYx can
//! be used to copy sets and windows, just as it can be used to copy vanilla
//! cells.
//!
//!
//!
//!
//!
//! # Summary
//!
//! The following table summarizes the SPICELIB cell routines.
//!
//!
//!
//! * SSIZEx ( SIZE, CELL )
//!
//!
//! Initialize (set the size of) a cell.
//!
//! * SCARDx ( CARD, CELL )
//!
//!
//! Set the cardinality of a cell.
//!
//! * SIZEx ( CELL )
//!
//!
//! Return the size of a cell.
//!
//! * CARDx ( CELL )
//!
//!
//! Return the cardinality of a cell.
//!
//! * COPYx ( ORIG, COPY )
//!
//!
//! Copy the contents of a cell.
//!
//! * APPNDx ( ITEM, CELL )
//!
//!
//! Append an item to a cell.
//!
//!
//! # Appendix A --- Revision History
//!
//!
//!
//!
//!
//! ### 2017 MAR 13 by N. J. Bachman
//!
//! Moved revision history to this appendix.
//!
//! Updated description of the element reference macros.
//!
//! Updated references to CSPICE cell "append" routines to name individual
//! routines rather than to refer to them using the notation
//!
//!
//!
//! ```text
//! appndx_c
//! ```
//!
//! Fixed typos.
//!
//!
//!
//!
//!
//! ### 2002 SEP 04 by N. J. Bachman
//!
//! Made minor changes to formatting and wording.
//!
//!
//!
//!
//!