1 /* zztrvlnk.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 ZZTRVLNK ( Traverse AB cell linked-list ) */
zztrvlnk_(integer * aval,integer * maxa,integer * pntrs,integer * cellsz,integer * cells,integer * maxb,integer * nb,integer * blist)9 /* Subroutine */ int zztrvlnk_(integer *aval, integer *maxa, integer *pntrs,
10 integer *cellsz, integer *cells, integer *maxb, integer *nb, integer *
11 blist)
12 {
13 integer i__;
14 extern /* Subroutine */ int chkin_(char *, ftnlen), sigerr_(char *,
15 ftnlen), chkout_(char *, ftnlen), setmsg_(char *, ftnlen),
16 errint_(char *, integer *, ftnlen);
17 extern logical return_(void);
18 integer ptr;
19
20 /* $ Abstract */
21
22 /* SPICE Private routine intended solely for the support of SPICE */
23 /* routines. Users should not call this routine directly due */
24 /* to the volatile nature of this routine. */
25
26 /* Traverse an AB pool linked list, searching for all cells that are */
27 /* associated with a specified A-value. Store the B-values of these */
28 /* cells in an array. */
29
30 /* $ Disclaimer */
31
32 /* THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
33 /* CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
34 /* GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
35 /* ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
36 /* PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
37 /* TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
38 /* WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
39 /* PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
40 /* SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
41 /* SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
42
43 /* IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
44 /* BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
45 /* LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
46 /* INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
47 /* REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
48 /* REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
49
50 /* RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
51 /* THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
52 /* CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
53 /* ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
54
55 /* $ Required_Reading */
56
57 /* None. */
58
59 /* $ Keywords */
60
61 /* linked list */
62
63 /* $ Declarations */
64 /* $ Brief_I/O */
65
66 /* VARIABLE I/O DESCRIPTION */
67 /* -------- --- -------------------------------------------------- */
68 /* AVAL I A-value index associated with pool entry. */
69 /* MAXA I Size of PNTRS array. */
70 /* PNTRS I A-value pointer array. */
71 /* CELLSZ I Number of cells in cell array. */
72 /* CELLS I Cell array. */
73 /* MAXB I Size of BLIST array. */
74 /* NB O Number of B values found. */
75 /* BLIST O List of B values. */
76
77 /* $ Detailed_Input */
78
79 /* AVAL is an index associated with a pool entry. AVAL */
80 /* is the index of the Ith value of a finite set "A." */
81 /* AVAL is an index into the PNTRS array. */
82
83 /* MAXA Size of PNTRS array. */
84
85 /* PNTRS is an array of integers acting as pointers into the */
86 /* cell array. The element at index I of PNTRS points to */
87 /* the head of a linked list in CELLS that associates */
88 /* B-values with the index I. Here I is the "A value." */
89
90 /* If there are no values associated with the Ith A value, */
91 /* PNTRS(I) is null (-1). */
92
93
94 /* CELLSZ is the number of cells in the cell array. The array */
95 /* has dimensions */
96
97 /* (2, CELLSZ) */
98
99 /* CELLS is the input cell array. The element */
100
101 /* CELLS ( 1, PNTRS(AVAL) ) */
102
103 /* contains a B-value associated with AVAL. The element */
104
105 /* CELLS ( 2, PNTRS(AVAL) ) */
106
107 /* is a pointer to the next node of the list associated */
108 /* with AVAL, or is null (-1) if the list contains only */
109 /* one element. The pointer element of the last list node */
110 /* for AVAL is null. */
111
112 /* MAXB is the size of the output B-value list. */
113
114 /* $ Detailed_Output */
115
116 /* NB is the number of nodes in the list associated with */
117 /* AVAL. */
118
119 /* BLIST is an array containing the B-values of the nodes */
120 /* associated with AVAL. There is one entry in BLIST for */
121 /* each node in the list associated with AVAL; the list */
122 /* may contain duplicates. */
123
124 /* $ Parameters */
125
126 /* None. */
127
128 /* $ Exceptions */
129
130 /* 1) If the array index AVAL is less than 1 or exceeds the */
131 /* declared size of the PNTR array, the error */
132 /* SPICE(INDEXOUTOFRANGE) is signaled. Occurrence of this error */
133 /* may result from the fine voxel scale being too small for the */
134 /* data. */
135
136 /* 2) If the size of the output BLIST array is non-positive, the */
137 /* error SPICE(INVALIDSIZE) is signaled. */
138
139 /* 3) If an element of the PNTRS array is larger than the length */
140 /* CELLSZ of the cell array, the error SPICE(POINTEROUTOFRANGE) */
141 /* is signaled. */
142
143 /* 4) If the number of output list entries exceeds the size MAXB of */
144 /* the output list array, the error SPICE(BARRAYTOOSMALL) is */
145 /* signaled. */
146
147 /* $ Files */
148
149 /* None. */
150
151 /* $ Particulars */
152
153 /* The AB list routines support manipulation of a data structure that */
154 /* represents a one-to-many mapping from a set A to a set B. Each */
155 /* element of set A is mapped to a set of values from B, where the */
156 /* range values are represented by a linked list of entries in the */
157 /* cell array. */
158
159 /* The elements of set B associated with the Ith element of A are */
160 /* stored in a linked list of cells starting with the cell */
161 /* consisting of elements */
162
163 /* CELLS(*,PNTRS(I)) */
164
165 /* The set A is really an abstraction: it's just some finite set */
166 /* with size in the range 1:MAXA. The input AVAL is not a member of */
167 /* A but rather just an index into A. For consistency with existing */
168 /* code, the name AVAL has been retained. */
169
170 /* The fact that B values are stored in linked lists enables a */
171 /* program to store entries for A-B associations in random order. */
172 /* For example, in the process of constructing DSK type 2 segments, */
173 /* the of non-empty fine voxels intersected by a given plate can be */
174 /* computed; then an entry representing a voxel-plate association */
175 /* can be made for each fine voxel in the set. In this case, the */
176 /* set "A" is the set of fine voxels belonging to non-empty coarse */
177 /* voxels. */
178
179 /* This routine supports creation of DSK type 2 segments. It is used */
180 /* for creation of both voxel-plate association data structures and */
181 /* of vertex-plate association data structures. */
182
183 /* $ Examples */
184
185 /* See usage in the routine ZZUNTNGL. */
186
187 /* $ Restrictions */
188
189 /* None. */
190
191 /* $ Literature_References */
192
193 /* None. */
194
195 /* $ Author_and_Institution */
196
197 /* N.J. Bachman (JPL) */
198 /* J.A. Bytof (JPL) */
199
200 /* $ Version */
201
202 /* - SPICELIB Version 1.0.0, 23-AUG-2016 (NJB) */
203
204 /* 07-JAN-2016 (NJB) */
205
206 /* Strengthened check on invalid pointer. Renamed argument MAXCEL */
207 /* to CELLSZ. Updated header comments. */
208
209 /* 26-MAR-2015 (NJB) */
210
211 /* Updated long error messages to improve accuracy. */
212
213 /* Header update: added description of MAXB input */
214 /* argument. Updated description of MAXA input */
215 /* argument. Filled out Exceptions section. */
216
217 /* 30-APR-2014 (NJB) */
218
219 /* Changed argument list: each array argument now */
220 /* has an associated argument giving its size. */
221 /* Updated error checking to check array indices */
222 /* against array sizes. */
223
224 /* 08-OCT-2009 (NJB) */
225
226 /* Re-ordered header sections. */
227
228 /* 11-JUN-2004 (EDW) */
229
230 /* Added check on AVAL to ensure it's smaller */
231 /* than the size of MAXA. */
232
233 /* 26-AUG-2002 (BVS) */
234
235 /* Replaced WRITE with normal error reporting calls. */
236
237 /* 03-FEB-1999 (JAB) */
238
239
240 /* -& */
241 /* $ Index_Entries */
242
243 /* AB cells */
244
245 /* -& */
246
247 /* Standard SPICE error handling. */
248
249 if (return_()) {
250 return 0;
251 }
252 chkin_("ZZTRVLNK", (ftnlen)8);
253 if (*aval < 1 || *aval > *maxa) {
254 setmsg_("Index AVAL is out of range. Index = #1. Valid range = 1:#2.",
255 (ftnlen)59);
256 errint_("#1", aval, (ftnlen)2);
257 errint_("#2", maxa, (ftnlen)2);
258 sigerr_("SPICE(INDEXOUTOFRANGE)", (ftnlen)22);
259 chkout_("ZZTRVLNK", (ftnlen)8);
260 return 0;
261 }
262 if (*maxb < 1) {
263 setmsg_("Maximum output list size MAXB is invalid. MAXB = #1.", (
264 ftnlen)52);
265 errint_("#1", maxb, (ftnlen)2);
266 sigerr_("SPICE(INVALIDSIZE)", (ftnlen)18);
267 chkout_("ZZTRVLNK", (ftnlen)8);
268 return 0;
269 }
270 *nb = 0;
271 blist[0] = 0;
272 ptr = pntrs[*aval - 1];
273 while(ptr != -1) {
274 if (ptr < -1 || ptr == 0 || ptr > *cellsz) {
275 setmsg_("Value in PNTRS array is not a valid index in the cell a"
276 "rray.Value = #1. Array size = #2.", (ftnlen)88);
277 errint_("#1", &ptr, (ftnlen)2);
278 errint_("#2", cellsz, (ftnlen)2);
279 sigerr_("SPICE(POINTEROUTOFRANGE)", (ftnlen)24);
280 chkout_("ZZTRVLNK", (ftnlen)8);
281 return 0;
282 }
283 ++(*nb);
284 if (*nb > *maxb) {
285 setmsg_("Output value count is larger than B-list array room. Co"
286 "unt = #1. Output array room = #2. Input pointer index wa"
287 "s #3. Input pointer list size was #4. Last pointer was #"
288 "5. Cell size was #6.", (ftnlen)187);
289 errint_("#1", nb, (ftnlen)2);
290 errint_("#2", maxb, (ftnlen)2);
291 errint_("#3", aval, (ftnlen)2);
292 errint_("#4", maxa, (ftnlen)2);
293 errint_("#5", &ptr, (ftnlen)2);
294 errint_("#6", cellsz, (ftnlen)2);
295 sigerr_("SPICE(BARRAYTOOSMALL)", (ftnlen)21);
296 chkout_("ZZTRVLNK", (ftnlen)8);
297 return 0;
298 }
299 blist[*nb - 1] = cells[(ptr << 1) - 2];
300 i__ = cells[(ptr << 1) - 1];
301 ptr = i__;
302 }
303
304 /* Standard SPICE error handling. */
305
306 chkout_("ZZTRVLNK", (ftnlen)8);
307 return 0;
308 } /* zztrvlnk_ */
309
310