1 /* dskrb2.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 doublereal c_b4 = .33333333333333331;
11 
12 /* $Procedure DSKRB2 ( DSK, determine range bounds for plate set ) */
dskrb2_(integer * nv,doublereal * vrtces,integer * np,integer * plates,integer * corsys,doublereal * corpar,doublereal * mncor3,doublereal * mxcor3)13 /* Subroutine */ int dskrb2_(integer *nv, doublereal *vrtces, integer *np,
14 	integer *plates, integer *corsys, doublereal *corpar, doublereal *
15 	mncor3, doublereal *mxcor3)
16 {
17     /* Initialized data */
18 
19     static doublereal origin[3] = { 0.,0.,0. };
20 
21     /* System generated locals */
22     integer i__1;
23     doublereal d__1, d__2;
24 
25     /* Local variables */
26     doublereal maxd, dist, f;
27     integer i__;
28     extern /* Subroutine */ int chkin_(char *, ftnlen);
29     doublereal pnear[3];
30     extern doublereal dpmin_(void), dpmax_(void), vdist_(doublereal *,
31 	    doublereal *);
32     extern /* Subroutine */ int pltnp_(doublereal *, doublereal *, doublereal
33 	    *, doublereal *, doublereal *, doublereal *);
34     extern doublereal vnorm_(doublereal *);
35     extern /* Subroutine */ int vlcom3_(doublereal *, doublereal *,
36 	    doublereal *, doublereal *, doublereal *, doublereal *,
37 	    doublereal *);
38     extern logical failed_(void);
39     doublereal re;
40     extern /* Subroutine */ int recgeo_(doublereal *, doublereal *,
41 	    doublereal *, doublereal *, doublereal *, doublereal *);
42     doublereal center[3];
43     extern /* Subroutine */ int chkout_(char *, ftnlen), setmsg_(char *,
44 	    ftnlen), errint_(char *, integer *, ftnlen), sigerr_(char *,
45 	    ftnlen);
46     extern logical return_(void);
47     doublereal alt, lat, lon;
48 
49 /* $ Abstract */
50 
51 /*     Determine range bounds for a set of triangular plates to */
52 /*     be stored in a type 2 DSK segment. */
53 
54 /* $ Disclaimer */
55 
56 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
57 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
58 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
59 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
60 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
61 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
62 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
63 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
64 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
65 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
66 
67 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
68 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
69 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
70 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
71 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
72 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
73 
74 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
75 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
76 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
77 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
78 
79 /* $ Required_Reading */
80 
81 /*     DSK */
82 
83 /* $ Keywords */
84 
85 /*     DAS */
86 /*     DSK */
87 /*     FILES */
88 /*     PLATE */
89 /*     TOPOGRAPHY */
90 
91 /* $ Declarations */
92 
93 /*     Include file dskdsc.inc */
94 
95 /*     This include file declares parameters for DSK segment descriptors. */
96 
97 /* -       SPICELIB Version 1.0.0 08-FEB-2017 (NJB) */
98 
99 /*           Updated version info. */
100 
101 /*           22-JAN-2016 (NJB) */
102 
103 /*              Added parameter for data class 2. Changed name of data */
104 /*              class 1 parameter. Corrected data class descriptions. */
105 
106 /*           13-MAY-2010 (NJB) */
107 
108 /*              Descriptor now contains two ID codes, one for the */
109 /*              surface, one for the associated ephemeris object. This */
110 /*              supports association of multiple surfaces with one */
111 /*              ephemeris object without creating file management */
112 /*              issues. */
113 
114 /*              Room was added for coordinate system definition */
115 /*              parameters. */
116 
117 /*               Flag arrays and model ID/component entries were deleted. */
118 
119 /*            11-SEP-2008 (NJB) */
120 
121 
122 /*     DSK segment descriptors are implemented as an array of d.p. */
123 /*     numbers.  Note that each integer descriptor datum occupies one */
124 /*     d.p. value. */
125 
126 
127 
128 
129 /*     Segment descriptor parameters */
130 
131 /*     Each segment descriptor occupies a contiguous */
132 /*     range of DAS d.p. addresses. */
133 
134 /*        The DSK segment descriptor layout is: */
135 
136 /*           +---------------------+ */
137 /*           | Surface ID code     | */
138 /*           +---------------------+ */
139 /*           | Center ID code      | */
140 /*           +---------------------+ */
141 /*           | Data class code     | */
142 /*           +---------------------+ */
143 /*           | Data type           | */
144 /*           +---------------------+ */
145 /*           | Ref frame code      | */
146 /*           +---------------------+ */
147 /*           | Coord sys code      | */
148 /*           +---------------------+ */
149 /*           | Coord sys parameters|  {10 elements} */
150 /*           +---------------------+ */
151 /*           | Min coord 1         | */
152 /*           +---------------------+ */
153 /*           | Max coord 1         | */
154 /*           +---------------------+ */
155 /*           | Min coord 2         | */
156 /*           +---------------------+ */
157 /*           | Max coord 2         | */
158 /*           +---------------------+ */
159 /*           | Min coord 3         | */
160 /*           +---------------------+ */
161 /*           | Max coord 3         | */
162 /*           +---------------------+ */
163 /*           | Start time          | */
164 /*           +---------------------+ */
165 /*           | Stop time           | */
166 /*           +---------------------+ */
167 
168 /*     Parameters defining offsets for segment descriptor elements */
169 /*     follow. */
170 
171 
172 /*     Surface ID code: */
173 
174 
175 /*     Central ephemeris object NAIF ID: */
176 
177 
178 /*     Data class: */
179 
180 /*     The "data class" is a code indicating the category of */
181 /*     data contained in the segment. */
182 
183 
184 /*     Data type: */
185 
186 
187 /*     Frame ID: */
188 
189 
190 /*     Coordinate system code: */
191 
192 
193 /*     Coordinate system parameter start index: */
194 
195 
196 /*     Number of coordinate system parameters: */
197 
198 
199 /*     Ranges for coordinate bounds: */
200 
201 
202 /*     Coverage time bounds: */
203 
204 
205 /*     Descriptor size (24): */
206 
207 
208 /*     Data class values: */
209 
210 /*        Class 1 indicates a surface that can be represented as a */
211 /*                single-valued function of its domain coordinates. */
212 
213 /*                An example is a surface defined by a function that */
214 /*                maps each planetodetic longitude and latitude pair to */
215 /*                a unique altitude. */
216 
217 
218 /*        Class 2 indicates a general surface. Surfaces that */
219 /*                have multiple points for a given pair of domain */
220 /*                coordinates---for example, multiple radii for a given */
221 /*                latitude and longitude---belong to class 2. */
222 
223 
224 
225 /*     Coordinate system values: */
226 
227 /*        The coordinate system code indicates the system to which the */
228 /*        tangential coordinate bounds belong. */
229 
230 /*        Code 1 refers to the planetocentric latitudinal system. */
231 
232 /*        In this system, the first tangential coordinate is longitude */
233 /*        and the second tangential coordinate is latitude. The third */
234 /*        coordinate is radius. */
235 
236 
237 
238 /*        Code 2 refers to the cylindrical system. */
239 
240 /*        In this system, the first tangential coordinate is radius and */
241 /*        the second tangential coordinate is longitude. The third, */
242 /*        orthogonal coordinate is Z. */
243 
244 
245 
246 /*        Code 3 refers to the rectangular system. */
247 
248 /*        In this system, the first tangential coordinate is X and */
249 /*        the second tangential coordinate is Y. The third, */
250 /*        orthogonal coordinate is Z. */
251 
252 
253 
254 /*        Code 4 refers to the planetodetic/geodetic system. */
255 
256 /*        In this system, the first tangential coordinate is longitude */
257 /*        and the second tangential coordinate is planetodetic */
258 /*        latitude. The third, orthogonal coordinate is altitude. */
259 
260 
261 
262 /*     End of include file dskdsc.inc */
263 
264 /* $ Brief_I/O */
265 
266 /*     Variable  I/O  Description */
267 /*     --------  ---  -------------------------------------------------- */
268 /*     NV         I   Number of vertices. */
269 /*     VRTCES     I   Vertices. */
270 /*     NP         I   Number of plates. */
271 /*     PLATES     I   Plates. */
272 /*     CORSYS     I   DSK coordinate system code. */
273 /*     CORPAR     I   DSK coordinate system parameters. */
274 /*     MNCOR3     O   Lower bound on range of third coordinate. */
275 /*     MXCOR3     O   Upper bound on range of third coordinate. */
276 
277 /* $ Detailed_Input */
278 
279 /*     NV          is the number of vertices belonging to the input */
280 /*                 set of plates. */
281 
282 
283 /*     VRTCES      is an array of coordinates of the vertices. The Ith */
284 /*                 vertex occupies elements (1:3,I) of this array. */
285 
286 
287 /*     NP          is the number of plates in the input plate set. */
288 
289 
290 /*     PLATES      is an array representing the triangular plates of a */
291 /*                 shape model. The elements of PLATES are vertex */
292 /*                 indices; vertex indices are 1-based. The vertex */
293 /*                 indices of the Ith plate occupy elements (1:3,I) of */
294 /*                 this array. */
295 
296 /*     CORSYS      is an integer parameter identifying the coordinate */
297 /*                 system in which the bounds are to be computed. The */
298 /*                 bounds apply to the third coordinate in each system: */
299 
300 /*                    Latitudinal:           radius */
301 /*                    Planetodetic:          altitude */
302 /*                    Rectangular:           Z */
303 
304 
305 /*     CORPAR     is an array of parameters associated with the */
306 /*                coordinate system. Currently the only supported system */
307 /*                that has associated parameters is the planetodetic */
308 /*                system. For planetodetic coordinates, */
309 
310 /*                   CORPAR(1) is the equatorial radius */
311 
312 /*                   CORPAR(2) is the flattening coefficient. Let RE and */
313 /*                   RP represent, respectively, the equatorial and */
314 /*                   polar radii of the reference ellipsoid of the */
315 /*                   system. Then */
316 
317 /*                       CORPAR(2) = ( RE - RP ) / RE */
318 
319 /* $ Detailed_Output */
320 
321 /*     MNCOR3    is a lower bound on the range of the third coordinate */
322 /*               of the system identified by CORSYS and CORPAR, taken */
323 /*               over all plates. */
324 
325 /*               For latitudinal and rectangular coordinates, MNCOR3 */
326 /*               is the greatest lower bound of the third coordinate. */
327 
328 /*               For planetodetic coordinates, MNCOR3 is an */
329 /*               approximation: it is less than or equal to the greatest */
330 /*               lower bound. */
331 
332 /*     MXCOR3    is the least upper bound on the range of the third */
333 /*               coordinate of the system identified by CORSYS and */
334 /*               CORPAR, taken over all plates. */
335 
336 
337 /* $ Parameters */
338 
339 /*     See the include file dskdsc.inc for declarations of the public DSK */
340 /*     type 2 parameters used by this routine. */
341 
342 /* $ Exceptions */
343 
344 /*     1)  If the input coordinate system is not recognized, the */
345 /*         error SPICE(NOTSUPPORTED) is signaled. */
346 
347 /*     2)  If a conversion from rectangular to planetodetic coordinates */
348 /*         fails, the error will be signaled by a routine in the call */
349 /*         tree of this routine. */
350 
351 /* $ Files */
352 
353 /*     None. */
354 
355 /* $ Particulars */
356 
357 /*     Users planning to create DSK files should consider whether the */
358 /*     SPICE DSK creation utility MKDSK may be suitable for their needs. */
359 
360 /*     This routine supports use of the DSK type 2 segment writer DSKW02 */
361 /*     by computing bounds on the range of the third coordinates of */
362 /*     the input plate set. */
363 
364 /* $ Examples */
365 
366 /*     The numerical results shown for this example may differ across */
367 /*     platforms. The results depend on the SPICE kernels used as */
368 /*     input, the compiler and supporting libraries, and the machine */
369 /*     specific arithmetic implementation. */
370 
371 /*     1) Create a three-segment DSK file using plate model data for */
372 /*        Phobos. Use latitudinal, rectangular, and planetodetic */
373 /*        coordinates in the respective segments. This is not a */
374 /*        realistic example, but it serves to demonstrate use of */
375 /*        the supported coordinate systems. */
376 
377 /*        For simplicity, use an existing DSK file to provide the */
378 /*        input plate and vertex data. The selected input file has one */
379 /*        segment. */
380 
381 
382 /*     C */
383 /*     C     Example program for DSKW02, DSKMI2, and DSKRB2 */
384 /*     C */
385 /*     C        Create a three-segment DSK file using plate model data */
386 /*     C        for Phobos. Use latitudinal, rectangular, and */
387 /*     C        planetodetic coordinates in the respective segments. */
388 /*     C */
389 /*     C        For simplicity, use an existing DSK file to provide the */
390 /*     C        input plate and vertex data. The selected input file has */
391 /*     C        one segment. */
392 /*     C */
393 /*     C           Version 1.0.0 22-JAN-2016 (NJB) */
394 /*     C */
395 /*           PROGRAM EX1 */
396 /*           IMPLICIT NONE */
397 
398 /*           INCLUDE 'dla.inc' */
399 /*           INCLUDE 'dskdsc.inc' */
400 /*           INCLUDE 'dsk02.inc' */
401 
402 /*     C */
403 /*     C     SPICELIB functions */
404 /*     C */
405 /*           DOUBLE PRECISION      JYEAR */
406 /*           DOUBLE PRECISION      PI */
407 /*     C */
408 /*     C     Local parameters */
409 /*     C */
410 /*           INTEGER               FRNMLN */
411 /*           PARAMETER           ( FRNMLN = 32 ) */
412 
413 /*           INTEGER               NSEG */
414 /*           PARAMETER           ( NSEG   = 3 ) */
415 
416 /*           INTEGER               NAMLEN */
417 /*           PARAMETER           ( NAMLEN = 20 ) */
418 
419 /*           INTEGER               FILSIZ */
420 /*           PARAMETER           ( FILSIZ = 255 ) */
421 
422 /*           INTEGER               LNSIZE */
423 /*           PARAMETER           ( LNSIZE = 80 ) */
424 
425 /*           INTEGER               NCOR */
426 /*           PARAMETER           ( NCOR   = 4 ) */
427 
428 /*     C */
429 /*     C     Local variables */
430 /*     C */
431 /*           CHARACTER*(NAMLEN)    CORNAM ( NCOR ) */
432 /*           CHARACTER*(FILSIZ)    DSK */
433 /*           CHARACTER*(FRNMLN)    FRAME */
434 /*           CHARACTER*(FILSIZ)    INDSK */
435 /*           CHARACTER*(LNSIZE)    LINE */
436 /*     C */
437 /*     C     Note: the values of MAXVRT and MAXPLT declared */
438 /*     C     in dsk02.inc, and the integer spatial index */
439 /*     C     dimension SPAISZ are very large. Smaller buffers */
440 /*     C     can be used for most applications. */
441 /*     C */
442 /*           DOUBLE PRECISION      CORPAR ( NSYPAR ) */
443 /*           DOUBLE PRECISION      F */
444 /*           DOUBLE PRECISION      FINSCL */
445 /*           DOUBLE PRECISION      FIRST */
446 /*           DOUBLE PRECISION      LAST */
447 /*           DOUBLE PRECISION      MNCOR1 */
448 /*           DOUBLE PRECISION      MNCOR2 */
449 /*           DOUBLE PRECISION      MNCOR3 */
450 /*           DOUBLE PRECISION      MXCOR1 */
451 /*           DOUBLE PRECISION      MXCOR2 */
452 /*           DOUBLE PRECISION      MXCOR3 */
453 /*           DOUBLE PRECISION      RE */
454 /*           DOUBLE PRECISION      RP */
455 /*           DOUBLE PRECISION      SPAIXD ( IXDFIX ) */
456 /*           DOUBLE PRECISION      VRTCES ( 3, MAXVRT ) */
457 
458 /*           INTEGER               CENTER */
459 /*           INTEGER               CORSCL */
460 /*           INTEGER               CORSYS */
461 /*           INTEGER               DCLASS */
462 /*           INTEGER               DLADSC ( DLADSZ ) */
463 /*           INTEGER               HANDLE */
464 /*           INTEGER               INHAN */
465 /*           INTEGER               NP */
466 /*           INTEGER               NV */
467 /*           INTEGER               PLATES ( 3, MAXPLT ) */
468 /*           INTEGER               SEGNO */
469 /*           INTEGER               SPAIXI ( SPAISZ ) */
470 /*           INTEGER               SURFID */
471 /*           INTEGER               VOXPSZ */
472 /*           INTEGER               VOXLSZ */
473 /*           INTEGER               WORK   ( 2, MAXCEL ) */
474 /*           INTEGER               WORKSZ */
475 
476 /*           LOGICAL               FOUND */
477 /*     C */
478 /*     C     Saved variables */
479 /*     C */
480 /*     C     Save all large arrays to avoid stack problems. */
481 /*     C */
482 /*           SAVE */
483 /*     C */
484 /*     C     Initial values */
485 /*     C */
486 /*           DATA                  CORNAM / 'radius', */
487 /*          .                               'Z-coordinate', */
488 /*          .                               'Z-coordinate', */
489 /*          .                               'altitude'     / */
490 
491 /*     C */
492 /*     C     Assign names of input and output DSK files. */
493 /*     C */
494 /*           INDSK = 'phobos_3_3.bds' */
495 /*           DSK   = 'phobos_3_3_3seg.bds' */
496 /*     C */
497 /*     C     Open input DSK for read access; find first segment. */
498 /*     C */
499 /*           CALL DASOPR ( INDSK, INHAN ) */
500 /*           CALL DLABFS ( INHAN, DLADSC, FOUND ) */
501 /*     C */
502 /*     C     Fetch vertices and plates from input DSK file. */
503 /*     C */
504 /*           WRITE (*,*) 'Reading input data...' */
505 
506 /*           CALL DSKV02 ( INHAN, DLADSC, 1, MAXVRT, NV, VRTCES ) */
507 /*           CALL DSKP02 ( INHAN, DLADSC, 1, MAXPLT, NP, PLATES ) */
508 
509 /*           WRITE (*,*) 'Done.' */
510 /*     C */
511 /*     C     Set input array sizes required by DSKMI2. */
512 /*     C */
513 /*           VOXPSZ = MAXVXP */
514 /*           VOXLSZ = MXNVLS */
515 /*           WORKSZ = MAXCEL */
516 /*     C */
517 /*     C     Set fine and coarse voxel scales. (These usually */
518 /*     C     need to determined by experimentation.) */
519 /*     C */
520 /*           FINSCL = 5.D0 */
521 /*           CORSCL = 4 */
522 /*     C */
523 /*     C     Open a new DSK file. */
524 /*     C */
525 /*           CALL DSKOPN ( DSK, DSK, 0, HANDLE ) */
526 /*     C */
527 /*     C     Create three segments and add them to the file. */
528 /*     C */
529 /*           DO SEGNO = 1, NSEG */
530 /*     C */
531 /*     C        Create spatial index. */
532 /*     C */
533 /*              WRITE (*,*) 'Creating segment ', SEGNO */
534 /*              WRITE (*,*) 'Creating spatial index...' */
535 
536 /*              CALL DSKMI2 ( NV,     VRTCES, NP,     PLATES, FINSCL, */
537 /*          .                 CORSCL, WORKSZ, VOXPSZ, VOXLSZ, .TRUE., */
538 /*          .                 SPAISZ, WORK,   SPAIXD, SPAIXI          ) */
539 
540 /*              WRITE (*,*) 'Done.' */
541 /*     C */
542 /*     C        Set up inputs describing segment attributes: */
543 /*     C */
544 /*     C        - Central body: Phobos */
545 /*     C        - Surface ID code: user's choice. */
546 /*     C          We use the segment number here. */
547 /*     C        - Data class: general (arbitrary) shape */
548 /*     C        - Body-fixed reference frame */
549 /*     C        - Time coverage bounds (TBD) */
550 /*     C */
551 /*              CENTER = 401 */
552 /*              SURFID = SEGNO */
553 /*              DCLASS = GENCLS */
554 /*              FRAME  = 'IAU_PHOBOS' */
555 
556 /*              FIRST = -50 * JYEAR() */
557 /*              LAST  =  50 * JYEAR() */
558 /*     C */
559 /*     C        Set the coordinate system and coordinate system */
560 /*     C        bounds based on the segment index. */
561 /*     C */
562 /*     C        Zero out the coordinate parameters to start. */
563 /*     C */
564 /*              CALL CLEARD ( NSYPAR, CORPAR ) */
565 
566 /*              IF ( SEGNO .EQ. 1 ) THEN */
567 /*     C */
568 /*     C           Use planetocentric latitudinal coordinates. Set */
569 /*     C           the longitude and latitude bounds. */
570 /*     C */
571 /*                 CORSYS = LATSYS */
572 
573 /*                 MNCOR1 = -PI() */
574 /*                 MXCOR1 =  PI() */
575 /*                 MNCOR2 = -PI()/2 */
576 /*                 MXCOR2 =  PI()/2 */
577 
578 /*              ELSE IF ( SEGNO .EQ. 2 ) THEN */
579 /*     C */
580 /*     C           Use rectangular coordinates. Set the */
581 /*     C           X and Y bounds. */
582 /*     C */
583 /*     C           The bounds shown here were derived from */
584 /*     C           the plate data. They lie slightly outside */
585 /*     C           of the range spanned by the plates. */
586 /*     C */
587 /*                 CORSYS = RECSYS */
588 
589 /*                 MNCOR1 = -1.3D0 */
590 /*                 MXCOR1 =  1.31D0 */
591 /*                 MNCOR2 = -1.21D0 */
592 /*                 MXCOR2 =  1.2D0 */
593 
594 /*              ELSE */
595 /*     C */
596 /*     C           Set the coordinate system to planetodetic. */
597 /*     C */
598 /*                 CORSYS    = PDTSYS */
599 
600 /*                 MNCOR1    = -PI() */
601 /*                 MXCOR1    =  PI() */
602 /*                 MNCOR2    = -PI()/2 */
603 /*                 MXCOR2    =  PI()/2 */
604 /*     C */
605 /*     C           We'll use equatorial and polar radii from */
606 /*     C           pck00010.tpc. These normally would be fetched */
607 /*     C           at run time, but for simplicity, we'll use */
608 /*     C           hard-coded values. */
609 
610 /*                 RE        = 13.0D0 */
611 /*                 RP        =  9.1D0 */
612 /*                 F         = ( RE - RP ) / RE */
613 
614 /*                 CORPAR(1) = RE */
615 /*                 CORPAR(2) = F */
616 
617 /*              END IF */
618 /*     C */
619 /*     C        Compute plate model radius bounds. */
620 /*     C */
621 /*              LINE = 'Computing # bounds of plate set...' */
622 
623 /*              CALL REPMC ( LINE, '#', CORNAM(CORSYS), LINE ) */
624 /*              WRITE (*,*) LINE */
625 
626 /*              CALL DSKRB2 ( NV,     VRTCES, NP,     PLATES, */
627 /*          .                 CORSYS, CORPAR, MNCOR3, MXCOR3 ) */
628 
629 /*              WRITE (*,*) 'Done.' */
630 /*     C */
631 /*     C        Write the segment to the file. */
632 /*     C */
633 /*              WRITE (*,*) 'Writing segment...' */
634 
635 /*              CALL DSKW02 ( HANDLE, */
636 /*          .                 CENTER, SURFID, DCLASS, FRAME,  CORSYS, */
637 /*          .                 CORPAR, MNCOR1, MXCOR1, MNCOR2, MXCOR2, */
638 /*          .                 MNCOR3, MXCOR3, FIRST,  LAST,   NV, */
639 /*          .                 VRTCES, NP,     PLATES, SPAIXD, SPAIXI ) */
640 
641 /*              WRITE (*,*) 'Done.' */
642 
643 /*           END DO */
644 /*     C */
645 /*     C     Segregate the data records in the DSK file and */
646 /*     C     close the file. */
647 /*     C */
648 /*           WRITE (*,*) 'Segregating and closing DSK file...' */
649 
650 /*           CALL DSKCLS ( HANDLE, .TRUE. ) */
651 
652 /*           WRITE (*,*) 'Done.' */
653 /*           END */
654 
655 
656 /* $ Restrictions */
657 
658 /*     1) For planetodetic coordinates, the computation of the lower */
659 /*        altitude bound requires that the surface at altitude MNCOR3 be */
660 /*        convex. This is the case for realistic geometries, but can */
661 /*        be false if a plate is very large compared to the overall */
662 /*        shape model. */
663 
664 /* $ Literature_References */
665 
666 /*     None. */
667 
668 /* $ Author_and_Institution */
669 
670 /*     N.J. Bachman    (JPL) */
671 
672 /* $ Version */
673 
674 /* -    SPICELIB Version 1.0.0, 04-APR-2017 (NJB) */
675 
676 /*       22-JAN-2016 (NJB) */
677 
678 /*         Original version. */
679 /* -& */
680 /* $ Index_Entries */
681 
682 /*     compute range bounds for type 2 dsk segment */
683 
684 /* -& */
685 
686 /*     SPICELIB functions */
687 
688 
689 /*     Local parameters */
690 
691 
692 
693 /*     Local variables */
694 
695 
696 /*     Saved variables */
697 
698 
699 /*     Initial values */
700 
701     if (return_()) {
702 	return 0;
703     }
704     chkin_("DSKRB2", (ftnlen)6);
705     if (*corsys == 1) {
706 
707 /*        The coordinate system is latitudinal. */
708 
709 /*        Compute radius bounds. Start with the maximum radius. */
710 /*        This is simply the maximum norm of the vertices. */
711 
712 	*mxcor3 = 0.;
713 	i__1 = *nv;
714 	for (i__ = 1; i__ <= i__1; ++i__) {
715 /* Computing MAX */
716 	    d__1 = vnorm_(&vrtces[i__ * 3 - 3]);
717 	    *mxcor3 = max(d__1,*mxcor3);
718 	}
719 
720 /*        Compute the minimum radius of the plate set. */
721 
722 	*mncor3 = dpmax_();
723 	i__1 = *np;
724 	for (i__ = 1; i__ <= i__1; ++i__) {
725 	    pltnp_(origin, &vrtces[plates[i__ * 3 - 3] * 3 - 3], &vrtces[
726 		    plates[i__ * 3 - 2] * 3 - 3], &vrtces[plates[i__ * 3 - 1]
727 		    * 3 - 3], pnear, &dist);
728 	    *mncor3 = min(dist,*mncor3);
729 	}
730     } else if (*corsys == 3) {
731 
732 /*        The coordinate system is rectangular. Compute the range */
733 /*        of Z-coordinates of the plates. */
734 
735 	*mncor3 = dpmax_();
736 	*mxcor3 = dpmin_();
737 	i__1 = *nv;
738 	for (i__ = 1; i__ <= i__1; ++i__) {
739 /* Computing MIN */
740 	    d__1 = *mncor3, d__2 = vrtces[i__ * 3 - 1];
741 	    *mncor3 = min(d__1,d__2);
742 /* Computing MAX */
743 	    d__1 = *mxcor3, d__2 = vrtces[i__ * 3 - 1];
744 	    *mxcor3 = max(d__1,d__2);
745 	}
746     } else if (*corsys == 4) {
747 
748 /*        The coordinate system is planetodetic. Compute the range */
749 /*        of altitudes of the plates. */
750 
751 	re = corpar[0];
752 	f = corpar[1];
753 	*mxcor3 = dpmin_();
754 	*mncor3 = dpmax_();
755 
756 /*        The maximum altitude is attained at a plate vertex. */
757 
758 	i__1 = *nv;
759 	for (i__ = 1; i__ <= i__1; ++i__) {
760 	    recgeo_(&vrtces[i__ * 3 - 3], &re, &f, &lon, &lat, &alt);
761 	    if (failed_()) {
762 		chkout_("DSKRB2", (ftnlen)6);
763 		return 0;
764 	    }
765 	    *mxcor3 = max(*mxcor3,alt);
766 	}
767 
768 /*        For the Ith plate, let DMAX(I) be the maximum distance between */
769 /*        the plate's center and any of the plate's vertices. */
770 
771 /*        The minimum altitude is greater than or equal to */
772 /*        the minimum of */
773 
774 /*           {altitude of the Ith plate's center - DMAX(I)} */
775 
776 /*        taken over all plates. */
777 
778 	i__1 = *np;
779 	for (i__ = 1; i__ <= i__1; ++i__) {
780 	    vlcom3_(&c_b4, &vrtces[plates[i__ * 3 - 3] * 3 - 3], &c_b4, &
781 		    vrtces[plates[i__ * 3 - 2] * 3 - 3], &c_b4, &vrtces[
782 		    plates[i__ * 3 - 1] * 3 - 3], center);
783 /* Computing MAX */
784 	    d__1 = vdist_(&vrtces[plates[i__ * 3 - 3] * 3 - 3], center), d__2
785 		    = vdist_(&vrtces[plates[i__ * 3 - 2] * 3 - 3], center),
786 		    d__1 = max(d__1,d__2), d__2 = vdist_(&vrtces[plates[i__ *
787 		    3 - 1] * 3 - 3], center);
788 	    maxd = max(d__1,d__2);
789 	    recgeo_(center, &re, &f, &lon, &lat, &alt);
790 	    if (failed_()) {
791 		chkout_("DSKRB2", (ftnlen)6);
792 		return 0;
793 	    }
794 /* Computing MIN */
795 	    d__1 = *mncor3, d__2 = alt - maxd;
796 	    *mncor3 = min(d__1,d__2);
797 	}
798     } else {
799 	setmsg_("Coordinate system # is not supported.", (ftnlen)37);
800 	errint_("#", corsys, (ftnlen)1);
801 	sigerr_("SPICE(NOTSUPPORTED)", (ftnlen)19);
802 	chkout_("DSKRB2", (ftnlen)6);
803 	return 0;
804     }
805     chkout_("DSKRB2", (ftnlen)6);
806     return 0;
807 } /* dskrb2_ */
808 
809