1 /* dskn02.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 /* Table of constant values */
9 
10 static logical c_false = FALSE_;
11 static integer c__9 = 9;
12 static integer c__3 = 3;
13 static integer c__19 = 19;
14 
15 /* $Procedure DSKN02 ( DSK, type 2, compute normal vector for plate ) */
dskn02_(integer * handle,integer * dladsc,integer * plid,doublereal * normal)16 /* Subroutine */ int dskn02_(integer *handle, integer *dladsc, integer *plid,
17 	doublereal *normal)
18 {
19     /* System generated locals */
20     integer i__1;
21 
22     /* Builtin functions */
23     integer s_rnge(char *, integer, char *, integer);
24 
25     /* Local variables */
26     integer unit;
27     extern /* Subroutine */ int vsub_(doublereal *, doublereal *, doublereal *
28 	    );
29     doublereal edge1[3], edge2[3];
30     extern /* Subroutine */ int zzddhhlu_(integer *, char *, logical *,
31 	    integer *, ftnlen);
32     integer i__, n;
33     extern /* Subroutine */ int dskd02_(integer *, integer *, integer *,
34 	    integer *, integer *, integer *, doublereal *), chkin_(char *,
35 	    ftnlen), dskgd_(integer *, integer *, doublereal *), dski02_(
36 	    integer *, integer *, integer *, integer *, integer *, integer *,
37 	    integer *);
38     integer plate[3];
39     extern /* Subroutine */ int dskz02_(integer *, integer *, integer *,
40 	    integer *);
41     integer start;
42     extern /* Subroutine */ int ucrss_(doublereal *, doublereal *, doublereal
43 	    *);
44     doublereal verts[9]	/* was [3][3] */;
45     extern logical failed_(void);
46     integer np, nv;
47     extern logical return_(void);
48     doublereal dskdsc[24];
49     extern /* Subroutine */ int setmsg_(char *, ftnlen), errfnm_(char *,
50 	    integer *, ftnlen), errint_(char *, integer *, ftnlen), sigerr_(
51 	    char *, ftnlen), chkout_(char *, ftnlen);
52 
53 /* $ Abstract */
54 
55 /*     Compute the unit normal vector for a specified plate from a type */
56 /*     2 DSK segment. */
57 
58 /* $ Disclaimer */
59 
60 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
61 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
62 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
63 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
64 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
65 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
66 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
67 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
68 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
69 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
70 
71 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
72 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
73 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
74 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
75 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
76 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
77 
78 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
79 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
80 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
81 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
82 
83 /* $ Required_Reading */
84 
85 /*     DAS */
86 /*     DSK */
87 
88 /* $ Keywords */
89 
90 /*     DAS */
91 /*     DSK */
92 /*     FILES */
93 
94 /* $ Declarations */
95 
96 /*     Include file dla.inc */
97 
98 /*     This include file declares parameters for DLA format */
99 /*     version zero. */
100 
101 /*        Version 3.0.1 17-OCT-2016 (NJB) */
102 
103 /*           Corrected comment: VERIDX is now described as a DAS */
104 /*           integer address rather than a d.p. address. */
105 
106 /*        Version 3.0.0 20-JUN-2006 (NJB) */
107 
108 /*           Changed name of parameter DSCSIZ to DLADSZ. */
109 
110 /*        Version 2.0.0 09-FEB-2005 (NJB) */
111 
112 /*           Changed descriptor layout to make backward pointer */
113 /*           first element.  Updated DLA format version code to 1. */
114 
115 /*           Added parameters for format version and number of bytes per */
116 /*           DAS comment record. */
117 
118 /*        Version 1.0.0 28-JAN-2004 (NJB) */
119 
120 
121 /*     DAS integer address of DLA version code. */
122 
123 
124 /*     Linked list parameters */
125 
126 /*     Logical arrays (aka "segments") in a DAS linked array (DLA) file */
127 /*     are organized as a doubly linked list.  Each logical array may */
128 /*     actually consist of character, double precision, and integer */
129 /*     components.  A component of a given data type occupies a */
130 /*     contiguous range of DAS addresses of that type.  Any or all */
131 /*     array components may be empty. */
132 
133 /*     The segment descriptors in a SPICE DLA (DAS linked array) file */
134 /*     are connected by a doubly linked list.  Each node of the list is */
135 /*     represented by a pair of integers acting as forward and backward */
136 /*     pointers.  Each pointer pair occupies the first two integers of a */
137 /*     segment descriptor in DAS integer address space.  The DLA file */
138 /*     contains pointers to the first integers of both the first and */
139 /*     last segment descriptors. */
140 
141 /*     At the DLA level of a file format implementation, there is */
142 /*     no knowledge of the data contents.  Hence segment descriptors */
143 /*     provide information only about file layout (in contrast with */
144 /*     the DAF system).  Metadata giving specifics of segment contents */
145 /*     are stored within the segments themselves in DLA-based file */
146 /*     formats. */
147 
148 
149 /*     Parameter declarations follow. */
150 
151 /*     DAS integer addresses of first and last segment linked list */
152 /*     pointer pairs.  The contents of these pointers */
153 /*     are the DAS addresses of the first integers belonging */
154 /*     to the first and last link pairs, respectively. */
155 
156 /*     The acronyms "LLB" and "LLE" denote "linked list begin" */
157 /*     and "linked list end" respectively. */
158 
159 
160 /*     Null pointer parameter. */
161 
162 
163 /*     Segment descriptor parameters */
164 
165 /*     Each segment descriptor occupies a contiguous */
166 /*     range of DAS integer addresses. */
167 
168 /*        The segment descriptor layout is: */
169 
170 /*           +---------------+ */
171 /*           | BACKWARD PTR  | Linked list backward pointer */
172 /*           +---------------+ */
173 /*           | FORWARD PTR   | Linked list forward pointer */
174 /*           +---------------+ */
175 /*           | BASE INT ADDR | Base DAS integer address */
176 /*           +---------------+ */
177 /*           | INT COMP SIZE | Size of integer segment component */
178 /*           +---------------+ */
179 /*           | BASE DP ADDR  | Base DAS d.p. address */
180 /*           +---------------+ */
181 /*           | DP COMP SIZE  | Size of d.p. segment component */
182 /*           +---------------+ */
183 /*           | BASE CHR ADDR | Base DAS character address */
184 /*           +---------------+ */
185 /*           | CHR COMP SIZE | Size of character segment component */
186 /*           +---------------+ */
187 
188 /*     Parameters defining offsets for segment descriptor elements */
189 /*     follow. */
190 
191 
192 /*     Descriptor size: */
193 
194 
195 /*     Other DLA parameters: */
196 
197 
198 /*     DLA format version.  (This number is expected to occur very */
199 /*     rarely at integer address VERIDX in uninitialized DLA files.) */
200 
201 
202 /*     Characters per DAS comment record. */
203 
204 
205 /*     End of include file dla.inc */
206 
207 
208 /*     Include file dskdsc.inc */
209 
210 /*     This include file declares parameters for DSK segment descriptors. */
211 
212 /* -       SPICELIB Version 1.0.0 08-FEB-2017 (NJB) */
213 
214 /*           Updated version info. */
215 
216 /*           22-JAN-2016 (NJB) */
217 
218 /*              Added parameter for data class 2. Changed name of data */
219 /*              class 1 parameter. Corrected data class descriptions. */
220 
221 /*           13-MAY-2010 (NJB) */
222 
223 /*              Descriptor now contains two ID codes, one for the */
224 /*              surface, one for the associated ephemeris object. This */
225 /*              supports association of multiple surfaces with one */
226 /*              ephemeris object without creating file management */
227 /*              issues. */
228 
229 /*              Room was added for coordinate system definition */
230 /*              parameters. */
231 
232 /*               Flag arrays and model ID/component entries were deleted. */
233 
234 /*            11-SEP-2008 (NJB) */
235 
236 
237 /*     DSK segment descriptors are implemented as an array of d.p. */
238 /*     numbers.  Note that each integer descriptor datum occupies one */
239 /*     d.p. value. */
240 
241 
242 
243 
244 /*     Segment descriptor parameters */
245 
246 /*     Each segment descriptor occupies a contiguous */
247 /*     range of DAS d.p. addresses. */
248 
249 /*        The DSK segment descriptor layout is: */
250 
251 /*           +---------------------+ */
252 /*           | Surface ID code     | */
253 /*           +---------------------+ */
254 /*           | Center ID code      | */
255 /*           +---------------------+ */
256 /*           | Data class code     | */
257 /*           +---------------------+ */
258 /*           | Data type           | */
259 /*           +---------------------+ */
260 /*           | Ref frame code      | */
261 /*           +---------------------+ */
262 /*           | Coord sys code      | */
263 /*           +---------------------+ */
264 /*           | Coord sys parameters|  {10 elements} */
265 /*           +---------------------+ */
266 /*           | Min coord 1         | */
267 /*           +---------------------+ */
268 /*           | Max coord 1         | */
269 /*           +---------------------+ */
270 /*           | Min coord 2         | */
271 /*           +---------------------+ */
272 /*           | Max coord 2         | */
273 /*           +---------------------+ */
274 /*           | Min coord 3         | */
275 /*           +---------------------+ */
276 /*           | Max coord 3         | */
277 /*           +---------------------+ */
278 /*           | Start time          | */
279 /*           +---------------------+ */
280 /*           | Stop time           | */
281 /*           +---------------------+ */
282 
283 /*     Parameters defining offsets for segment descriptor elements */
284 /*     follow. */
285 
286 
287 /*     Surface ID code: */
288 
289 
290 /*     Central ephemeris object NAIF ID: */
291 
292 
293 /*     Data class: */
294 
295 /*     The "data class" is a code indicating the category of */
296 /*     data contained in the segment. */
297 
298 
299 /*     Data type: */
300 
301 
302 /*     Frame ID: */
303 
304 
305 /*     Coordinate system code: */
306 
307 
308 /*     Coordinate system parameter start index: */
309 
310 
311 /*     Number of coordinate system parameters: */
312 
313 
314 /*     Ranges for coordinate bounds: */
315 
316 
317 /*     Coverage time bounds: */
318 
319 
320 /*     Descriptor size (24): */
321 
322 
323 /*     Data class values: */
324 
325 /*        Class 1 indicates a surface that can be represented as a */
326 /*                single-valued function of its domain coordinates. */
327 
328 /*                An example is a surface defined by a function that */
329 /*                maps each planetodetic longitude and latitude pair to */
330 /*                a unique altitude. */
331 
332 
333 /*        Class 2 indicates a general surface. Surfaces that */
334 /*                have multiple points for a given pair of domain */
335 /*                coordinates---for example, multiple radii for a given */
336 /*                latitude and longitude---belong to class 2. */
337 
338 
339 
340 /*     Coordinate system values: */
341 
342 /*        The coordinate system code indicates the system to which the */
343 /*        tangential coordinate bounds belong. */
344 
345 /*        Code 1 refers to the planetocentric latitudinal system. */
346 
347 /*        In this system, the first tangential coordinate is longitude */
348 /*        and the second tangential coordinate is latitude. The third */
349 /*        coordinate is radius. */
350 
351 
352 
353 /*        Code 2 refers to the cylindrical system. */
354 
355 /*        In this system, the first tangential coordinate is radius and */
356 /*        the second tangential coordinate is longitude. The third, */
357 /*        orthogonal coordinate is Z. */
358 
359 
360 
361 /*        Code 3 refers to the rectangular system. */
362 
363 /*        In this system, the first tangential coordinate is X and */
364 /*        the second tangential coordinate is Y. The third, */
365 /*        orthogonal coordinate is Z. */
366 
367 
368 
369 /*        Code 4 refers to the planetodetic/geodetic system. */
370 
371 /*        In this system, the first tangential coordinate is longitude */
372 /*        and the second tangential coordinate is planetodetic */
373 /*        latitude. The third, orthogonal coordinate is altitude. */
374 
375 
376 
377 /*     End of include file dskdsc.inc */
378 
379 
380 /*     Include file dsk02.inc */
381 
382 /*     This include file declares parameters for DSK data type 2 */
383 /*     (plate model). */
384 
385 /* -       SPICELIB Version 1.0.0 08-FEB-2017 (NJB) */
386 
387 /*          Updated version info. */
388 
389 /*           22-JAN-2016 (NJB) */
390 
391 /*              Now includes spatial index parameters. */
392 
393 /*           26-MAR-2015 (NJB) */
394 
395 /*              Updated to increase MAXVRT to 16000002. MAXNPV */
396 /*              has been changed to (3/2)*MAXPLT. Set MAXVOX */
397 /*              to 100000000. */
398 
399 /*           13-MAY-2010 (NJB) */
400 
401 /*              Updated to reflect new no-record design. */
402 
403 /*           04-MAY-2010 (NJB) */
404 
405 /*              Updated for new type 2 segment design. Now uses */
406 /*              a local parameter to represent DSK descriptor */
407 /*              size (NB). */
408 
409 /*           13-SEP-2008 (NJB) */
410 
411 /*              Updated to remove albedo information. */
412 /*              Updated to use parameter for DSK descriptor size. */
413 
414 /*           27-DEC-2006 (NJB) */
415 
416 /*              Updated to remove minimum and maximum radius information */
417 /*              from segment layout.  These bounds are now included */
418 /*              in the segment descriptor. */
419 
420 /*           26-OCT-2006 (NJB) */
421 
422 /*              Updated to remove normal, center, longest side, albedo, */
423 /*              and area keyword parameters. */
424 
425 /*           04-AUG-2006 (NJB) */
426 
427 /*              Updated to support coarse voxel grid.  Area data */
428 /*              have now been removed. */
429 
430 /*           10-JUL-2006 (NJB) */
431 
432 
433 /*     Each type 2 DSK segment has integer, d.p., and character */
434 /*     components.  The segment layout in DAS address space is as */
435 /*     follows: */
436 
437 
438 /*        Integer layout: */
439 
440 /*           +-----------------+ */
441 /*           | NV              |  (# of vertices) */
442 /*           +-----------------+ */
443 /*           | NP              |  (# of plates ) */
444 /*           +-----------------+ */
445 /*           | NVXTOT          |  (total number of voxels) */
446 /*           +-----------------+ */
447 /*           | VGREXT          |  (voxel grid extents, 3 integers) */
448 /*           +-----------------+ */
449 /*           | CGRSCL          |  (coarse voxel grid scale, 1 integer) */
450 /*           +-----------------+ */
451 /*           | VOXNPT          |  (size of voxel-plate pointer list) */
452 /*           +-----------------+ */
453 /*           | VOXNPL          |  (size of voxel-plate list) */
454 /*           +-----------------+ */
455 /*           | VTXNPL          |  (size of vertex-plate list) */
456 /*           +-----------------+ */
457 /*           | PLATES          |  (NP 3-tuples of vertex IDs) */
458 /*           +-----------------+ */
459 /*           | VOXPTR          |  (voxel-plate pointer array) */
460 /*           +-----------------+ */
461 /*           | VOXPLT          |  (voxel-plate list) */
462 /*           +-----------------+ */
463 /*           | VTXPTR          |  (vertex-plate pointer array) */
464 /*           +-----------------+ */
465 /*           | VTXPLT          |  (vertex-plate list) */
466 /*           +-----------------+ */
467 /*           | CGRPTR          |  (coarse grid occupancy pointers) */
468 /*           +-----------------+ */
469 
470 
471 
472 /*        D.p. layout: */
473 
474 /*           +-----------------+ */
475 /*           | DSK descriptor  |  DSKDSZ elements */
476 /*           +-----------------+ */
477 /*           | Vertex bounds   |  6 values (min/max for each component) */
478 /*           +-----------------+ */
479 /*           | Voxel origin    |  3 elements */
480 /*           +-----------------+ */
481 /*           | Voxel size      |  1 element */
482 /*           +-----------------+ */
483 /*           | Vertices        |  3*NV elements */
484 /*           +-----------------+ */
485 
486 
487 /*     This local parameter MUST be kept consistent with */
488 /*     the parameter DSKDSZ which is declared in dskdsc.inc. */
489 
490 
491 /*     Integer item keyword parameters used by fetch routines: */
492 
493 
494 /*     Double precision item keyword parameters used by fetch routines: */
495 
496 
497 /*     The parameters below formerly were declared in pltmax.inc. */
498 
499 /*     Limits on plate model capacity: */
500 
501 /*     The maximum number of bodies, vertices and */
502 /*     plates in a plate model or collective thereof are */
503 /*     provided here. */
504 
505 /*     These values can be used to dimension arrays, or to */
506 /*     use as limit checks. */
507 
508 /*     The value of MAXPLT is determined from MAXVRT via */
509 /*     Euler's Formula for simple polyhedra having triangular */
510 /*     faces. */
511 
512 /*     MAXVRT is the maximum number of vertices the triangular */
513 /*            plate model software will support. */
514 
515 
516 /*     MAXPLT is the maximum number of plates that the triangular */
517 /*            plate model software will support. */
518 
519 
520 /*     MAXNPV is the maximum allowed number of vertices, not taking into */
521 /*     account shared vertices. */
522 
523 /*     Note that this value is not sufficient to create a vertex-plate */
524 /*     mapping for a model of maximum plate count. */
525 
526 
527 /*     MAXVOX is the maximum number of voxels. */
528 
529 
530 /*     MAXCGR is the maximum size of the coarse voxel grid. */
531 
532 
533 /*     MAXEDG is the maximum allowed number of vertex or plate */
534 /*     neighbors a vertex may have. */
535 
536 /*     DSK type 2 spatial index parameters */
537 /*     =================================== */
538 
539 /*        DSK type 2 spatial index integer component */
540 /*        ------------------------------------------ */
541 
542 /*           +-----------------+ */
543 /*           | VGREXT          |  (voxel grid extents, 3 integers) */
544 /*           +-----------------+ */
545 /*           | CGRSCL          |  (coarse voxel grid scale, 1 integer) */
546 /*           +-----------------+ */
547 /*           | VOXNPT          |  (size of voxel-plate pointer list) */
548 /*           +-----------------+ */
549 /*           | VOXNPL          |  (size of voxel-plate list) */
550 /*           +-----------------+ */
551 /*           | VTXNPL          |  (size of vertex-plate list) */
552 /*           +-----------------+ */
553 /*           | CGRPTR          |  (coarse grid occupancy pointers) */
554 /*           +-----------------+ */
555 /*           | VOXPTR          |  (voxel-plate pointer array) */
556 /*           +-----------------+ */
557 /*           | VOXPLT          |  (voxel-plate list) */
558 /*           +-----------------+ */
559 /*           | VTXPTR          |  (vertex-plate pointer array) */
560 /*           +-----------------+ */
561 /*           | VTXPLT          |  (vertex-plate list) */
562 /*           +-----------------+ */
563 
564 
565 /*        Index parameters */
566 
567 
568 /*     Grid extent: */
569 
570 
571 /*     Coarse grid scale: */
572 
573 
574 /*     Voxel pointer count: */
575 
576 
577 /*     Voxel-plate list count: */
578 
579 
580 /*     Vertex-plate list count: */
581 
582 
583 /*     Coarse grid pointers: */
584 
585 
586 /*     Size of fixed-size portion of integer component: */
587 
588 
589 /*        DSK type 2 spatial index double precision component */
590 /*        --------------------------------------------------- */
591 
592 /*           +-----------------+ */
593 /*           | Vertex bounds   |  6 values (min/max for each component) */
594 /*           +-----------------+ */
595 /*           | Voxel origin    |  3 elements */
596 /*           +-----------------+ */
597 /*           | Voxel size      |  1 element */
598 /*           +-----------------+ */
599 
600 
601 
602 /*        Index parameters */
603 
604 /*     Vertex bounds: */
605 
606 
607 /*     Voxel grid origin: */
608 
609 
610 /*     Voxel size: */
611 
612 
613 /*     Size of fixed-size portion of double precision component: */
614 
615 
616 /*     The limits below are used to define a suggested maximum */
617 /*     size for the integer component of the spatial index. */
618 
619 
620 /*     Maximum number of entries in voxel-plate pointer array: */
621 
622 
623 /*     Maximum cell size: */
624 
625 
626 /*     Maximum number of entries in voxel-plate list: */
627 
628 
629 /*     Spatial index integer component size: */
630 
631 
632 /*     End of include file dsk02.inc */
633 
634 /* $ Brief_I/O */
635 
636 /*     Variable  I/O  Description */
637 /*     --------  ---  -------------------------------------------------- */
638 /*     HANDLE     I   DSK file handle. */
639 /*     DLADSC     I   DLA descriptor. */
640 /*     PLID       I   Plate ID. */
641 /*     NORMAL     O   Plate's unit normal vector. */
642 
643 /* $ Detailed_Input */
644 
645 /*     HANDLE         is the handle of a DSK file containing a type 2 */
646 /*                    segment from which data are to be fetched. */
647 
648 /*     DLADSC         is the DLA descriptor associated with the segment */
649 /*                    from which data are to be fetched. */
650 
651 /*     PLID           is the plate ID. Plate IDs range from 1 to NP */
652 /*                    (the number of plates). */
653 
654 /* $ Detailed_Output */
655 
656 /*     NORMAL         is the normal vector associated with the plate */
657 /*                    designated by PLID. The direction of NORMAL is */
658 /*                    determined by the order of the plate's vertices; */
659 /*                    the vertices are presumed to be ordered in the */
660 /*                    right-handed (counterclockwise) sense about the */
661 /*                    normal direction. */
662 
663 /*                    The vector has magnitude 1. */
664 
665 /*                    If an error occurs on the call, NORMAL is */
666 /*                    undefined. */
667 
668 /* $ Parameters */
669 
670 /*     See the INCLUDE files */
671 
672 /*         dla.inc */
673 /*         dsk02.inc */
674 
675 /* $ Exceptions */
676 
677 /*     1) If the input handle is invalid, the error will be diagnosed by */
678 /*        routines in the call tree of this routine. */
679 
680 /*     2) If a file read error occurs, the error will be diagnosed by */
681 /*        routines in the call tree of this routine. */
682 
683 /*     3) If the input DLA descriptor is invalid, the effect of this */
684 /*        routine is undefined. The error *may* be diagnosed by routines */
685 /*        in the call tree of this routine, but there are no guarantees. */
686 
687 /*     4) If PLID is less than 1 or greater than the number of plates */
688 /*        in the segment, the error SPICE(INDEXOUTOFRANGE) is signaled. */
689 
690 /*     5) This routine does not check for linear independence of the */
691 /*        plate's edges. The plate model is assumed to be geometrically */
692 /*        valid. */
693 
694 /* $ Files */
695 
696 /*     See input argument HANDLE. */
697 
698 /* $ Particulars */
699 
700 /*     None. */
701 
702 /* $ Examples */
703 
704 
705 /*     The numerical results shown for this example may differ across */
706 /*     platforms. The results depend on the SPICE kernels used as */
707 /*     input, the compiler and supporting libraries, and the machine */
708 /*     specific arithmetic implementation. */
709 
710 
711 /*     1) Look up all the vertices associated with each plate */
712 /*        of the model contained in a specified type 2 segment. For each */
713 /*        plate, display the plate's vertices and normal vector. */
714 
715 /*        For this example, we'll show the context of this look-up: */
716 /*        opening the DSK file for read access, traversing a trivial, */
717 /*        one-segment list to obtain the segment of interest. */
718 
719 
720 /*        Example code begins here. */
721 
722 
723 /*           PROGRAM EX1 */
724 /*           IMPLICIT NONE */
725 
726 /*           INCLUDE 'dla.inc' */
727 /*           INCLUDE 'dsk02.inc' */
728 
729 
730 /*           CHARACTER*(*)         FMT */
731 /*           PARAMETER           ( FMT    = '(1X,A,3(1XE16.9))' ) */
732 
733 
734 /*           INTEGER               BUFSIZ */
735 /*           PARAMETER           ( BUFSIZ = 10000 ) */
736 
737 /*           INTEGER               FILSIZ */
738 /*           PARAMETER           ( FILSIZ = 255 ) */
739 
740 
741 /*           CHARACTER*(FILSIZ)    DSK */
742 
743 /*           DOUBLE PRECISION      NORMAL ( 3 ) */
744 /*           DOUBLE PRECISION      VERTS  ( 3, BUFSIZ ) */
745 
746 /*           INTEGER               DLADSC ( DLADSZ ) */
747 /*           INTEGER               HANDLE */
748 /*           INTEGER               I */
749 /*           INTEGER               J */
750 /*           INTEGER               N */
751 /*           INTEGER               NNORM */
752 /*           INTEGER               NP */
753 /*           INTEGER               NREAD */
754 /*           INTEGER               NV */
755 /*           INTEGER               NVTX */
756 /*           INTEGER               PLATES  ( 3, BUFSIZ ) */
757 /*           INTEGER               PLIX */
758 /*           INTEGER               REMAIN */
759 /*           INTEGER               START */
760 
761 /*           LOGICAL               FOUND */
762 
763 /*     C */
764 /*     C     Prompt for name of DSK and open file for reading. */
765 /*     C */
766 /*           CALL PROMPT ( 'Enter DSK name > ', DSK ) */
767 
768 /*           CALL DASOPR ( DSK, HANDLE ) */
769 
770 /*           CALL DLABFS ( HANDLE, DLADSC, FOUND ) */
771 
772 /*           IF ( .NOT. FOUND ) THEN */
773 
774 /*              CALL SETMSG ( 'No segment found in file #.' ) */
775 /*              CALL ERRCH  ( '#',  DSK                     ) */
776 /*              CALL SIGERR ( 'SPICE(NOSEGMENT)'            ) */
777 
778 /*           END IF */
779 
780 /*     C */
781 /*     C     Get segment vertex and plate counts. */
782 /*     C */
783 /*           CALL DSKZ02 ( HANDLE, DLADSC, NV, NP ) */
784 
785 /*           WRITE (*,*) ' ' */
786 /*           WRITE (*,*) 'Number of vertices: ', NV */
787 /*           WRITE (*,*) 'Number of plates:   ', NP */
788 /*     C */
789 /*     C     Display the vertices of each plate. */
790 /*     C */
791 /*           REMAIN = NP */
792 /*           START  = 1 */
793 
794 /*           DO WHILE ( REMAIN .GT. 0 ) */
795 /*     C */
796 /*     C        NREAD is the number of plates we'll read on this */
797 /*     C        loop pass. */
798 /*     C */
799 /*              NREAD  = MIN ( BUFSIZ, REMAIN ) */
800 
801 /*              CALL DSKP02 ( HANDLE, DLADSC, START, NREAD, N, PLATES ) */
802 
803 /*              DO I = 1, N */
804 
805 /*                 PLIX = START + I - 1 */
806 /*     C */
807 /*     C           Read the vertices of the current plate. */
808 /*     C */
809 /*                 DO J = 1, 3 */
810 /*                    CALL DSKV02 ( HANDLE, DLADSC, PLATES(J,I), */
811 /*          .                       1,      NVTX,   VERTS (1,J)  ) */
812 /*                 END DO */
813 /*     C */
814 /*     C           Display the vertices of the current plate: */
815 /*     C */
816 /*                 WRITE (*,*  ) ' ' */
817 /*                 WRITE (*,*  ) 'Plate number: ', PLIX */
818 /*                 WRITE (*,FMT) '   Vertex 1: ', (VERTS(J,1), J = 1,3) */
819 /*                 WRITE (*,FMT) '   Vertex 2: ', (VERTS(J,2), J = 1,3) */
820 /*                 WRITE (*,FMT) '   Vertex 3: ', (VERTS(J,3), J = 1,3) */
821 
822 /*     C */
823 /*     C           Display the normal vector of the current plate: */
824 /*     C */
825 /*                 CALL DSKN02 ( HANDLE, DLADSC, PLIX, NORMAL ) */
826 
827 /*                 WRITE (*,FMT) '   Normal:   ', (NORMAL(J), J = 1,3) */
828 
829 /*              END DO */
830 
831 /*              START  = START  + NREAD */
832 /*              REMAIN = REMAIN - NREAD */
833 
834 /*           END DO */
835 
836 /*     C */
837 /*     C     Close the kernel.  This isn't necessary in a stand- */
838 /*     C     alone program, but it's good practice in subroutines */
839 /*     C     because it frees program and system resources. */
840 /*     C */
841 /*           CALL DASCLS ( HANDLE ) */
842 
843 /*           END */
844 
845 
846 /*     When this program was executed on a PC/Linux/gfortran/64bit */
847 /*     platform, using a DSK file representing a regular icosahedron, */
848 /*     the output was: */
849 
850 
851 /*     Enter DSK name > solid.bds */
852 
853 /*      Number of vertices:           12 */
854 /*      Number of plates:             20 */
855 
856 /*      Plate number:            1 */
857 /*         Vertex 1:   0.000000000E+00  0.000000000E+00  0.117557000E+01 */
858 /*         Vertex 2:   0.105146000E+01  0.000000000E+00  0.525731000E+00 */
859 /*         Vertex 3:   0.324920000E+00  0.100000000E+01  0.525731000E+00 */
860 /*         Normal:     0.491124160E+00  0.356821347E+00  0.794654382E+00 */
861 
862 /*      Plate number:            2 */
863 /*         Vertex 1:   0.000000000E+00  0.000000000E+00  0.117557000E+01 */
864 /*         Vertex 2:   0.324920000E+00  0.100000000E+01  0.525731000E+00 */
865 /*         Vertex 3:  -0.850651000E+00  0.618034000E+00  0.525731000E+00 */
866 /*         Normal:    -0.187592328E+00  0.577350079E+00  0.794654645E+00 */
867 
868 /*           ... */
869 
870 /*      Plate number:           20 */
871 /*         Vertex 1:   0.850651000E+00 -0.618034000E+00 -0.525731000E+00 */
872 /*         Vertex 2:   0.000000000E+00  0.000000000E+00 -0.117557000E+01 */
873 /*         Vertex 3:   0.850651000E+00  0.618034000E+00 -0.525731000E+00 */
874 /*         Normal:     0.607061680E+00  0.000000000E+00 -0.794654715E+00 */
875 
876 
877 /* $ Restrictions */
878 
879 /*     See Exceptions. */
880 
881 /* $ Literature_References */
882 
883 /*     None. */
884 
885 /* $ Author_and_Institution */
886 
887 /*     N.J. Bachman    (JPL) */
888 
889 /* $ Version */
890 
891 /* -    SPICELIB Version 1.0.0, 17-MAR-2016 (NJB) */
892 
893 /*        Now calls ZZDDHHLU. */
894 
895 /*        Deleted references to unused parameter. Updated */
896 /*        Examples section. */
897 
898 /*        DSKLIB Version 1.0.0, 02-JUN-2010 (NJB) */
899 
900 /* -& */
901 /* $ Index_Entries */
902 
903 /*     compute normal vector for a type 2 dsk plate */
904 
905 /* -& */
906 
907 /*     SPICELIB functions */
908 
909 
910 /*     Local variables */
911 
912     if (return_()) {
913 	return 0;
914     }
915     chkin_("DSKN02", (ftnlen)6);
916 
917 /*     Look up the DSK descriptor for this segment. */
918 
919     dskgd_(handle, dladsc, dskdsc);
920 
921 /*     Get the plate model size parameters for this segment. */
922 /*     Note that we get a segment data type check for free from */
923 /*     DSKZ02. */
924 
925     dskz02_(handle, dladsc, &nv, &np);
926 
927 /*     Check START. */
928 
929     if (*plid < 1 || *plid > np) {
930 	zzddhhlu_(handle, "DAS", &c_false, &unit, (ftnlen)3);
931 	setmsg_("Segment in DSK file # with DAS base addresses INT = #, DP ="
932 		" #, CHR = # contains # plates, so PLID must be in the range "
933 		"1:#; actual value was #.", (ftnlen)143);
934 	errfnm_("#", &unit, (ftnlen)1);
935 	errint_("#", &dladsc[2], (ftnlen)1);
936 	errint_("#", &dladsc[4], (ftnlen)1);
937 	errint_("#", &dladsc[6], (ftnlen)1);
938 	errint_("#", &np, (ftnlen)1);
939 	errint_("#", &np, (ftnlen)1);
940 	errint_("#", plid, (ftnlen)1);
941 	sigerr_("SPICE(INDEXOUTOFRANGE)", (ftnlen)22);
942 	chkout_("DSKN02", (ftnlen)6);
943 	return 0;
944     }
945 
946 /*     Look up the plate and its vertices. */
947 
948     start = (*plid - 1) * 3 + 1;
949     dski02_(handle, dladsc, &c__9, &start, &c__3, &n, plate);
950     for (i__ = 1; i__ <= 3; ++i__) {
951 	start = (plate[(i__1 = i__ - 1) < 3 && 0 <= i__1 ? i__1 : s_rnge(
952 		"plate", i__1, "dskn02_", (ftnlen)406)] - 1) * 3 + 1;
953 	dskd02_(handle, dladsc, &c__19, &start, &c__3, &n, &verts[(i__1 = i__
954 		* 3 - 3) < 9 && 0 <= i__1 ? i__1 : s_rnge("verts", i__1,
955 		"dskn02_", (ftnlen)408)]);
956     }
957     if (failed_()) {
958 	chkout_("DSKN02", (ftnlen)6);
959 	return 0;
960     }
961 
962 /*     Use the right-handed order of the vertices to determine the */
963 /*     correct choice of normal direction. */
964 
965     vsub_(&verts[3], verts, edge1);
966     vsub_(&verts[6], verts, edge2);
967     ucrss_(edge1, edge2, normal);
968     chkout_("DSKN02", (ftnlen)6);
969     return 0;
970 } /* dskn02_ */
971 
972