1 /* lnkini.f -- translated by f2c (version 19980913).
2 You must link the resulting object file with the libraries:
3 -lf2c -lm (in that order)
4 */
5
6 #include "f2c.h"
7
8 /* $Procedure LNKINI ( LNK, initialize ) */
lnkini_(integer * size,integer * pool)9 /* Subroutine */ int lnkini_(integer *size, integer *pool)
10 {
11 /* System generated locals */
12 integer i__1;
13
14 /* Local variables */
15 integer i__;
16 extern /* Subroutine */ int chkin_(char *, ftnlen), sigerr_(char *,
17 ftnlen), chkout_(char *, ftnlen), setmsg_(char *, ftnlen),
18 errint_(char *, integer *, ftnlen);
19
20 /* $ Abstract */
21
22 /* Initialize a doubly linked list pool. */
23
24 /* $ Disclaimer */
25
26 /* THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
27 /* CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
28 /* GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
29 /* ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
30 /* PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
31 /* TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
32 /* WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
33 /* PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
34 /* SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
35 /* SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
36
37 /* IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
38 /* BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
39 /* LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
40 /* INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
41 /* REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
42 /* REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
43
44 /* RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
45 /* THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
46 /* CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
47 /* ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
48
49 /* $ Required_Reading */
50
51 /* LNK */
52
53 /* $ Keywords */
54
55 /* LIST */
56
57 /* $ Declarations */
58 /* $ Brief_I/O */
59
60 /* Variable I/O Description */
61 /* -------- --- -------------------------------------------------- */
62 /* SIZE I Number of nodes in the pool. */
63 /* POOL I-O An array that is a linked pool on output. */
64 /* LBPOOL P Lower bound of pool column indices. */
65
66 /* $ Detailed_Input */
67
68 /* SIZE is the number of nodes in the pool. */
69
70 /* POOL is an integer array that will contain the linked */
71 /* pool on output. */
72
73 /* $ Detailed_Output */
74
75 /* POOL is an initialized doubly linked list pool. */
76 /* The status of the pool is as follows: */
77
78 /* -- All nodes in the pool are on the free list. */
79
80 /* -- The free pointer indicates the first node. */
81
82 /* -- The total node count is set to the input */
83 /* value, SIZE. */
84
85 /* -- The free node count is the input value, SIZE. */
86
87 /* $ Parameters */
88
89 /* LBPOOL is the lower bound of the column indices of the POOL */
90 /* array. The columns indexed LBPOOL to 0 are reserved */
91 /* as a control area for the pool. */
92
93 /* $ Exceptions */
94
95 /* 1) If the requested number of nodes is nonpositive, the error */
96 /* SPICE(INVALIDCOUNT) is signalled. */
97
98 /* $ Files */
99
100 /* None. */
101
102 /* $ Particulars */
103
104 /* LNKINI must be called once to initialize a doubly linked list */
105 /* pool before the pool is used. LNKINI can be called at any time */
106 /* to re-initialize a doubly linked list pool. */
107
108 /* The functions */
109
110 /* LNKNFN ( LNK, number of free nodes ) and */
111 /* LNKSIZ ( LNK, size of pool ) */
112
113 /* will both return the value PLSIZE if called immediately after a */
114 /* call to LNKINI. */
115
116 /* $ Examples */
117
118 /* 1) Let POOL be a doubly linked list pool with a maximum of */
119 /* 100 nodes. POOL should be declared as follows: */
120
121 /* INTEGER LBPOOL */
122 /* PARAMETER ( LBPOOL = -5 ) */
123
124 /* INTEGER PLSIZE */
125 /* PARAMETER ( PLSIZE = 100 ) */
126
127 /* INTEGER POOL ( 2, LBPOOL : PLSIZE ) */
128
129
130 /* To initialize POOL, use the call */
131
132 /* CALL LNKINI ( PLSIZE, POOL ) */
133
134
135 /* $ Restrictions */
136
137 /* None. */
138
139 /* $ Literature_References */
140
141 /* None. */
142
143 /* $ Author_and_Institution */
144
145 /* N.J. Bachman (JPL) */
146 /* W.L. Taber (JPL) */
147
148 /* $ Version */
149
150 /* - SPICELIB Version 1.0.0, 19-DEC-1995 (NJB) (WLT) */
151
152 /* -& */
153 /* $ Index_Entries */
154
155 /* initialize linked list pool */
156
157 /* -& */
158
159 /* Local parameters */
160
161
162 /* The control area contains 3 elements. They are: */
163
164 /* The "size" of the pool, that is, the number */
165 /* of nodes in the pool. */
166
167 /* The number of free nodes in the pool. */
168
169 /* The "free pointer," which is the column index of the first free */
170 /* node. */
171
172 /* Parameters defining the row and column indices of these control */
173 /* elements are given below. */
174
175
176 /* Each assigned node consists of a backward pointer and a forward */
177 /* pointer. */
178
179 /* +-------------+ +-------------+ +-------------+ */
180 /* | forward--> | | forward--> | | forward--> | */
181 /* +-------------+ ... +-------------+ ... +-------------+ */
182 /* | <--backward | | <--backward | | <--backward | */
183 /* +-------------+ +-------------+ +-------------+ */
184
185 /* node 1 node I node SIZE */
186
187
188
189
190 /* Free nodes say that that's what they are. The way they say it */
191 /* is by containing the value FREE in their backward pointers. */
192 /* Needless to say, FREE is a value that cannot be a valid pointer. */
193
194
195 /* Local variables */
196
197
198 /* Use discovery check-in. */
199
200
201 /* The requested number of nodes must be valid. */
202
203 if (*size < 1) {
204 chkin_("LNKINI", (ftnlen)6);
205 setmsg_("A linked list cannot have # nodes.", (ftnlen)34);
206 errint_("#", size, (ftnlen)1);
207 sigerr_("SPICE(INVALIDCOUNT)", (ftnlen)19);
208 chkout_("LNKINI", (ftnlen)6);
209 return 0;
210 }
211
212 /* Initialize the pool. The free list occupies the whole pool at */
213 /* this point. */
214
215
216 /* POOL( SIZROW, SIZCOL ) is the pool size. */
217
218 pool[10] = *size;
219
220 /* POOL( NFRROW, NFRCOL ) is the number of free nodes. */
221
222 pool[11] = *size;
223
224 /* POOL( FREROW, FRECOL) is the "free" pointer. It points to the */
225 /* first free node, which is node 1. */
226
227 pool[8] = 1;
228
229 /* Initialize the backward and forward pointers. The last forward */
230 /* pointer is zero. All of the backward pointers contain the value */
231 /* FREE. */
232
233 i__1 = *size - 1;
234 for (i__ = 1; i__ <= i__1; ++i__) {
235 pool[(i__ << 1) + 10] = i__ + 1;
236 pool[(i__ << 1) + 11] = 0;
237 }
238 pool[(*size << 1) + 10] = 0;
239 pool[(*size << 1) + 11] = 0;
240 return 0;
241 } /* lnkini_ */
242
243