1 /* zzvrtplt.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  ZZVRTPLT  ( create vertex-plate mapping ) */
zzvrtplt_(integer * nv,integer * np,integer * plates,integer * cellsz,integer * maxlst,integer * cells,integer * vrtptr,integer * nlist,integer * pltlst)9 /* Subroutine */ int zzvrtplt_(integer *nv, integer *np, integer *plates,
10 	integer *cellsz, integer *maxlst, integer *cells, integer *vrtptr,
11 	integer *nlist, integer *pltlst)
12 {
13     /* System generated locals */
14     integer i__1;
15 
16     /* Local variables */
17     extern /* Subroutine */ int zzaddlnk_(integer *, integer *, integer *,
18 	    integer *, integer *, integer *, integer *), zzinilnk_(integer *,
19 	    integer *, integer *, integer *, integer *);
20     static integer i__, j;
21     extern /* Subroutine */ int zzuntngl_(integer *, integer *, integer *,
22 	    integer *, integer *, integer *, integer *), chkin_(char *,
23 	    ftnlen);
24     static integer ncell;
25     extern logical failed_(void);
26     extern /* Subroutine */ int setmsg_(char *, ftnlen), errint_(char *,
27 	    integer *, ftnlen), sigerr_(char *, ftnlen), chkout_(char *,
28 	    ftnlen);
29     extern logical return_(void);
30 
31 /* $ Abstract */
32 
33 /*     SPICE Private routine intended solely for the support of SPICE */
34 /*     routines. Users should not call this routine directly due */
35 /*     to the volatile nature of this routine. */
36 
37 /*     Generate a data structure that represents the mapping from */
38 /*     vertices to the plates containing them. */
39 
40 /* $ Disclaimer */
41 
42 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
43 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
44 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
45 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
46 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
47 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
48 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
49 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
50 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
51 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
52 
53 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
54 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
55 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
56 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
57 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
58 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
59 
60 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
61 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
62 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
63 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
64 
65 /* $ Required_Reading */
66 
67 /*     DSK */
68 
69 /* $ Keywords */
70 
71 /*     DSK */
72 /*     PLATE */
73 /*     VERTEX */
74 
75 /* $ Declarations */
76 
77 /*     Include file dsk02.inc */
78 
79 /*     This include file declares parameters for DSK data type 2 */
80 /*     (plate model). */
81 
82 /* -       SPICELIB Version 1.0.0 08-FEB-2017 (NJB) */
83 
84 /*          Updated version info. */
85 
86 /*           22-JAN-2016 (NJB) */
87 
88 /*              Now includes spatial index parameters. */
89 
90 /*           26-MAR-2015 (NJB) */
91 
92 /*              Updated to increase MAXVRT to 16000002. MAXNPV */
93 /*              has been changed to (3/2)*MAXPLT. Set MAXVOX */
94 /*              to 100000000. */
95 
96 /*           13-MAY-2010 (NJB) */
97 
98 /*              Updated to reflect new no-record design. */
99 
100 /*           04-MAY-2010 (NJB) */
101 
102 /*              Updated for new type 2 segment design. Now uses */
103 /*              a local parameter to represent DSK descriptor */
104 /*              size (NB). */
105 
106 /*           13-SEP-2008 (NJB) */
107 
108 /*              Updated to remove albedo information. */
109 /*              Updated to use parameter for DSK descriptor size. */
110 
111 /*           27-DEC-2006 (NJB) */
112 
113 /*              Updated to remove minimum and maximum radius information */
114 /*              from segment layout.  These bounds are now included */
115 /*              in the segment descriptor. */
116 
117 /*           26-OCT-2006 (NJB) */
118 
119 /*              Updated to remove normal, center, longest side, albedo, */
120 /*              and area keyword parameters. */
121 
122 /*           04-AUG-2006 (NJB) */
123 
124 /*              Updated to support coarse voxel grid.  Area data */
125 /*              have now been removed. */
126 
127 /*           10-JUL-2006 (NJB) */
128 
129 
130 /*     Each type 2 DSK segment has integer, d.p., and character */
131 /*     components.  The segment layout in DAS address space is as */
132 /*     follows: */
133 
134 
135 /*        Integer layout: */
136 
137 /*           +-----------------+ */
138 /*           | NV              |  (# of vertices) */
139 /*           +-----------------+ */
140 /*           | NP              |  (# of plates ) */
141 /*           +-----------------+ */
142 /*           | NVXTOT          |  (total number of voxels) */
143 /*           +-----------------+ */
144 /*           | VGREXT          |  (voxel grid extents, 3 integers) */
145 /*           +-----------------+ */
146 /*           | CGRSCL          |  (coarse voxel grid scale, 1 integer) */
147 /*           +-----------------+ */
148 /*           | VOXNPT          |  (size of voxel-plate pointer list) */
149 /*           +-----------------+ */
150 /*           | VOXNPL          |  (size of voxel-plate list) */
151 /*           +-----------------+ */
152 /*           | VTXNPL          |  (size of vertex-plate list) */
153 /*           +-----------------+ */
154 /*           | PLATES          |  (NP 3-tuples of vertex IDs) */
155 /*           +-----------------+ */
156 /*           | VOXPTR          |  (voxel-plate pointer array) */
157 /*           +-----------------+ */
158 /*           | VOXPLT          |  (voxel-plate list) */
159 /*           +-----------------+ */
160 /*           | VTXPTR          |  (vertex-plate pointer array) */
161 /*           +-----------------+ */
162 /*           | VTXPLT          |  (vertex-plate list) */
163 /*           +-----------------+ */
164 /*           | CGRPTR          |  (coarse grid occupancy pointers) */
165 /*           +-----------------+ */
166 
167 
168 
169 /*        D.p. layout: */
170 
171 /*           +-----------------+ */
172 /*           | DSK descriptor  |  DSKDSZ elements */
173 /*           +-----------------+ */
174 /*           | Vertex bounds   |  6 values (min/max for each component) */
175 /*           +-----------------+ */
176 /*           | Voxel origin    |  3 elements */
177 /*           +-----------------+ */
178 /*           | Voxel size      |  1 element */
179 /*           +-----------------+ */
180 /*           | Vertices        |  3*NV elements */
181 /*           +-----------------+ */
182 
183 
184 /*     This local parameter MUST be kept consistent with */
185 /*     the parameter DSKDSZ which is declared in dskdsc.inc. */
186 
187 
188 /*     Integer item keyword parameters used by fetch routines: */
189 
190 
191 /*     Double precision item keyword parameters used by fetch routines: */
192 
193 
194 /*     The parameters below formerly were declared in pltmax.inc. */
195 
196 /*     Limits on plate model capacity: */
197 
198 /*     The maximum number of bodies, vertices and */
199 /*     plates in a plate model or collective thereof are */
200 /*     provided here. */
201 
202 /*     These values can be used to dimension arrays, or to */
203 /*     use as limit checks. */
204 
205 /*     The value of MAXPLT is determined from MAXVRT via */
206 /*     Euler's Formula for simple polyhedra having triangular */
207 /*     faces. */
208 
209 /*     MAXVRT is the maximum number of vertices the triangular */
210 /*            plate model software will support. */
211 
212 
213 /*     MAXPLT is the maximum number of plates that the triangular */
214 /*            plate model software will support. */
215 
216 
217 /*     MAXNPV is the maximum allowed number of vertices, not taking into */
218 /*     account shared vertices. */
219 
220 /*     Note that this value is not sufficient to create a vertex-plate */
221 /*     mapping for a model of maximum plate count. */
222 
223 
224 /*     MAXVOX is the maximum number of voxels. */
225 
226 
227 /*     MAXCGR is the maximum size of the coarse voxel grid. */
228 
229 
230 /*     MAXEDG is the maximum allowed number of vertex or plate */
231 /*     neighbors a vertex may have. */
232 
233 /*     DSK type 2 spatial index parameters */
234 /*     =================================== */
235 
236 /*        DSK type 2 spatial index integer component */
237 /*        ------------------------------------------ */
238 
239 /*           +-----------------+ */
240 /*           | VGREXT          |  (voxel grid extents, 3 integers) */
241 /*           +-----------------+ */
242 /*           | CGRSCL          |  (coarse voxel grid scale, 1 integer) */
243 /*           +-----------------+ */
244 /*           | VOXNPT          |  (size of voxel-plate pointer list) */
245 /*           +-----------------+ */
246 /*           | VOXNPL          |  (size of voxel-plate list) */
247 /*           +-----------------+ */
248 /*           | VTXNPL          |  (size of vertex-plate list) */
249 /*           +-----------------+ */
250 /*           | CGRPTR          |  (coarse grid occupancy pointers) */
251 /*           +-----------------+ */
252 /*           | VOXPTR          |  (voxel-plate pointer array) */
253 /*           +-----------------+ */
254 /*           | VOXPLT          |  (voxel-plate list) */
255 /*           +-----------------+ */
256 /*           | VTXPTR          |  (vertex-plate pointer array) */
257 /*           +-----------------+ */
258 /*           | VTXPLT          |  (vertex-plate list) */
259 /*           +-----------------+ */
260 
261 
262 /*        Index parameters */
263 
264 
265 /*     Grid extent: */
266 
267 
268 /*     Coarse grid scale: */
269 
270 
271 /*     Voxel pointer count: */
272 
273 
274 /*     Voxel-plate list count: */
275 
276 
277 /*     Vertex-plate list count: */
278 
279 
280 /*     Coarse grid pointers: */
281 
282 
283 /*     Size of fixed-size portion of integer component: */
284 
285 
286 /*        DSK type 2 spatial index double precision component */
287 /*        --------------------------------------------------- */
288 
289 /*           +-----------------+ */
290 /*           | Vertex bounds   |  6 values (min/max for each component) */
291 /*           +-----------------+ */
292 /*           | Voxel origin    |  3 elements */
293 /*           +-----------------+ */
294 /*           | Voxel size      |  1 element */
295 /*           +-----------------+ */
296 
297 
298 
299 /*        Index parameters */
300 
301 /*     Vertex bounds: */
302 
303 
304 /*     Voxel grid origin: */
305 
306 
307 /*     Voxel size: */
308 
309 
310 /*     Size of fixed-size portion of double precision component: */
311 
312 
313 /*     The limits below are used to define a suggested maximum */
314 /*     size for the integer component of the spatial index. */
315 
316 
317 /*     Maximum number of entries in voxel-plate pointer array: */
318 
319 
320 /*     Maximum cell size: */
321 
322 
323 /*     Maximum number of entries in voxel-plate list: */
324 
325 
326 /*     Spatial index integer component size: */
327 
328 
329 /*     End of include file dsk02.inc */
330 
331 /* $ Brief_I/O */
332 
333 /*     VARIABLE  I/O  DESCRIPTION */
334 /*     --------  ---  -------------------------------------------------- */
335 /*     NV         I   Number of vertices. */
336 /*     NP         I   Number of plates. */
337 /*     PLATES     I   Plate array. */
338 /*     CELLSZ     I   Cell array size. */
339 /*     MAXLST     I   Maximum size of output plate list. */
340 /*     CELLS     I-O  Workspace array for vertex list construction. */
341 /*     VRTPTR     O   Array of pointers, by vertex, into plate data list. */
342 /*     NLIST      O   Length of the plate data list. */
343 /*     PLTLST     O   Plate data list; first element is the number of */
344 /*                    plate IDs to follow. */
345 
346 /* $ Detailed_Input */
347 
348 /*     NV         Number of vertices. */
349 
350 /*     NP         Number of plates. */
351 
352 /*     PLATES     Plate array: this is an array of 3-tuples of */
353 /*                vertex indices. The elements */
354 
355 /*                   PLATES(1:3,I) */
356 
357 /*                are the indices of the vertices of the Ith plate. */
358 
359 
360 /*     CELLSZ     Size of cell array: explicit workspace dimension used */
361 /*                for error checking. This value should be */
362 
363 /*                   3*NP */
364 
365 /*     MAXLST     Maximum size of output plate list. This size should be */
366 
367 /*                   3*NP  +  NV */
368 
369 
370 /*     CELLS      workspace array used to construct the vertex-plate */
371 /*                mapping. */
372 
373 /* $ Detailed_Output */
374 
375 /*     CELLS      Workspace array used to construct the vertex-plate */
376 /*                mapping. */
377 
378 /*     VRTPTR     Array of pointers associating plate lists with */
379 /*                vertices. The Ith element of VRTPTR contains */
380 /*                the start index in PLTLST of the list associated with */
381 /*                the Ith vertex. */
382 
383 /*                The size of this array must be at least NV. */
384 
385 /*     NLIST      Length of the output plate data list PLTLST. */
386 
387 /*     PLTLST     Plate data list: for each vertex, there is a count */
388 /*                of associated plates, followed by the IDs of those */
389 /*                plates. The count for vertex I is located at */
390 
391 /*                   PLTLST( VRTPTR(I) ) */
392 
393 /*                The size of this array must be at least MAXLST. */
394 
395 /* $ Parameters */
396 
397 /*     See parameter declarations in */
398 
399 /*        dsk02.inc */
400 
401 /* $ Exceptions */
402 
403 /*     1)  If the input plate count NP is non-positive, the */
404 /*         error SPICE(BADPLATECOUNT) is signaled. */
405 
406 /*     2)  If the input vertex count NV is non-positive, the */
407 /*         error SPICE(BADVERTEXCOUNT) is signaled. */
408 
409 /*     3)  If the cell array size CELLSZ is less than */
410 
411 /*            3 * NP */
412 
413 /*         the error SPICE(CELLARRAYTOOSMALL) is signaled. */
414 
415 /*     4)  If the plate list size MAXPLT is less than */
416 
417 /*            ( 3 * NP ) + NV */
418 
419 /*         the error SPICE(PLATELISTTOOSMALL) is signaled. */
420 
421 /* $ Files */
422 
423 /*     None. */
424 
425 /* $ Particulars */
426 
427 /*     This routine supports the DSK type 2 spatial index */
428 /*     routines */
429 
430 /*        DSKMI2 */
431 /*        DSKSI2 */
432 
433 /* $ Examples */
434 
435 /*     See usage in DSKMI2. */
436 
437 /* $ Restrictions */
438 
439 /*     None. */
440 
441 /* $ Literature_References */
442 
443 /*     None. */
444 
445 /* $ Author_and_Institution */
446 
447 /*     N.J. Bachman    (JPL) */
448 /*     J.A. Bytof      (JPL) */
449 
450 /* $ Version */
451 
452 /* -    SPICELIB Version 1.0.0, 20-MAY-2016 (NJB) */
453 
454 /*        Updated error handling. Now ZZVRTPLT performs precise checks */
455 /*        on cell and plate array size inputs. */
456 
457 
458 /*        22-DEC-2015 (NJB) */
459 
460 /*           Renamed routine from VRTCOM to ZZVRTPLT. */
461 
462 /*           CAUTION: argument list change! Removed input workspace */
463 /*           array for pointer construction. Array was named PNTRS. */
464 
465 /*           Added error checks for input counts and sizes. */
466 
467 /*           Now calls updated 3.0.0 version of ZZUNTNGL. */
468 
469 /*        03-MAY-2014 (NJB) */
470 
471 /*           Now calls ZZ* versions of supporting routines. */
472 
473 /*           Changed argument list to include sizes of arrays. */
474 /*           Changed error handling to make use of array sizes. */
475 /*           Changed call to UNTNGL to accommodate argument */
476 /*           list change in that routine. Updated header I/O */
477 /*           descriptions. */
478 
479 /*        12-JUL-2011 (NJB) */
480 
481 /*           Argument list change: the input arrays V1, V2, V3 were */
482 /*           replaced with the input array PLATES. */
483 
484 /*        04-MAY-2010 (NJB) */
485 
486 /*           Now accepts input workspace arrays PNTRS and CELLS. */
487 /*           Changed INCLUDE file to dsk02.inc. */
488 
489 /*        08-OCT-2009 (NJB) */
490 
491 /*           Re-ordered header sections. */
492 
493 /*        04-FEB-1999 (JAB) */
494 
495 /* -& */
496 /* $ Index_Entries */
497 
498 /*     create vertex to plate map */
499 
500 /* -& */
501 
502 /*     SPICELIB functions */
503 
504 
505 /*     Local variables. */
506 
507 
508 /*     Standard SPICELIB error handling. */
509 
510     if (return_()) {
511 	return 0;
512     }
513     chkin_("ZZVRTPLT", (ftnlen)8);
514     if (*nv < 1) {
515 	setmsg_("Vertex count NV = #; count must be positive.be positive.", (
516 		ftnlen)56);
517 	errint_("#", nv, (ftnlen)1);
518 	sigerr_("SPICE(BADVERTEXCOUNT)", (ftnlen)21);
519 	chkout_("ZZVRTPLT", (ftnlen)8);
520 	return 0;
521     }
522     if (*np < 1) {
523 	setmsg_("Plate count NP = #; count must be positive.be positive.", (
524 		ftnlen)55);
525 	errint_("#", np, (ftnlen)1);
526 	sigerr_("SPICE(BADPLATECOUNT)", (ftnlen)20);
527 	chkout_("ZZVRTPLT", (ftnlen)8);
528 	return 0;
529     }
530     if (*cellsz < *np * 3) {
531 	setmsg_("Cell array size CELLSZ = #; size must be >= 3*NP. NP is the"
532 		" plate count #.", (ftnlen)74);
533 	errint_("#", cellsz, (ftnlen)1);
534 	errint_("#", np, (ftnlen)1);
535 	sigerr_("SPICE(CELLARRAYTOOSMALL)", (ftnlen)24);
536 	chkout_("ZZVRTPLT", (ftnlen)8);
537 	return 0;
538     }
539     if (*maxlst < *nv + *np * 3) {
540 	setmsg_("Plate list array size MAXPLT = #; size must be >= 3*NP + NV"
541 		", which is #. (NV = vertex count, NP = plate count.)", (
542 		ftnlen)111);
543 	errint_("#", maxlst, (ftnlen)1);
544 	i__1 = *np * 3 + *nv;
545 	errint_("#", &i__1, (ftnlen)1);
546 	sigerr_("SPICE(PLATELISTTOOSMALL)", (ftnlen)24);
547 	chkout_("ZZVRTPLT", (ftnlen)8);
548 	return 0;
549     }
550 
551 /*     Initialize pointer and cell structure. */
552 
553     zzinilnk_(nv, cellsz, &ncell, vrtptr, cells);
554     if (failed_()) {
555 	chkout_("ZZVRTPLT", (ftnlen)8);
556 	return 0;
557     }
558 
559 /*     Loop over all plate IDS. Add each plate/vertex */
560 /*     combination to the linked list. */
561 
562     i__1 = *np;
563     for (i__ = 1; i__ <= i__1; ++i__) {
564 	for (j = 1; j <= 3; ++j) {
565 
566 /*           AVAL = PLATES(J,I), vertex J of plate ID I. */
567 /*           BVAL = I, plate ID value I. */
568 
569 	    zzaddlnk_(&plates[j + i__ * 3 - 4], &i__, np, cellsz, vrtptr, &
570 		    ncell, cells);
571 	    if (failed_()) {
572 		chkout_("ZZVRTPLT", (ftnlen)8);
573 		return 0;
574 	    }
575 	}
576     }
577 
578 /*     Generate two linked lists mapping vertex ID to the plates */
579 /*     including that vertex as a member. */
580 
581 /*     VRTPTR: An array, indexed by vertex ID. For an array element, */
582 /*             VRTPTR(VERT_ID), greater than zero, the value identifies */
583 /*             an index in PLTLST, the value of that PLTLST array */
584 /*             element  equaling the number of plates that include */
585 /*             the vertex specified by the ID as a member. The */
586 /*             condition VRTPTR(VERT_ID) = -1 indicates a bug. */
587 
588 /*     PLTLST: An array, indexed by the positive entries in VRTPTR. */
589 /*             The element, N, identified by a VRTPTR value describes */
590 /*             the number of plates of which the vertex is a member. */
591 
592 /*                 N = PLTLST( VRTPTR(VERT_ID) ) */
593 
594 /*             The N elements following PLTLST( VRTPTR(VERT_ID) ), */
595 /*             contain the IDs of those plates which have the vertex */
596 /*             as a member. */
597 
598     zzuntngl_(nv, cellsz, cells, maxlst, vrtptr, nlist, pltlst);
599 
600 /*     Standard SPICE error handling. */
601 
602     chkout_("ZZVRTPLT", (ftnlen)8);
603     return 0;
604 } /* zzvrtplt_ */
605 
606