1 /* wnvald.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 integer c__0 = 0;
11 
12 /* $Procedure      WNVALD ( Validate a DP window ) */
wnvald_(integer * size,integer * n,doublereal * a)13 /* Subroutine */ int wnvald_(integer *size, integer *n, doublereal *a)
14 {
15     doublereal left;
16     integer i__;
17     extern /* Subroutine */ int chkin_(char *, ftnlen);
18     doublereal right;
19     extern /* Subroutine */ int scardd_(integer *, doublereal *), sigerr_(
20 	    char *, ftnlen), chkout_(char *, ftnlen), ssized_(integer *,
21 	    doublereal *), setmsg_(char *, ftnlen), wninsd_(doublereal *,
22 	    doublereal *, doublereal *);
23     extern logical return_(void), odd_(integer *);
24 
25 /* $ Abstract */
26 
27 /*     Form a valid double precision window from the contents */
28 /*     of a window 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 /*     WINDOWS */
58 
59 /* $ Keywords */
60 
61 /*     WINDOWS */
62 
63 /* $ Declarations */
64 /* $ Brief_I/O */
65 
66 /*     VARIABLE  I/O  DESCRIPTION */
67 /*     --------  ---  -------------------------------------------------- */
68 /*     SIZE       I   Size of window. */
69 /*     N          I   Original number of endpoints. */
70 /*     A         I,O  Input, output window. */
71 
72 /* $ Detailed_Input */
73 
74 /*     SIZE        is the size of the window to be validated. This */
75 /*                 is the maximum number of endpoints that the cell */
76 /*                 used to implement the window is capable of holding */
77 /*                 at any one time. */
78 
79 /*     N           is the original number of endpoints in the input */
80 /*                 cell. */
81 
82 /*     A           on input, is a (possibly uninitialized) cell array */
83 /*                 SIZE containing N endpoints of (possibly unordered */
84 /*                 and non-disjoint) intervals. */
85 
86 /* $ Detailed_Output */
87 
88 /*     A           on output, is a window containing the union of the */
89 /*                 intervals in the input cell. */
90 
91 
92 /* $ Parameters */
93 
94 /*     None. */
95 
96 /* $ Particulars */
97 
98 /*     This routine takes as input a cell array containing pairs of */
99 /*     endpoints and validates it to form a window. */
100 
101 /*     On input, A is a cell of size SIZE containing N endpoints. */
102 /*     During validation, the intervals are ordered, and overlapping */
103 /*     intervals are merged. On output, the cardinality of A is */
104 /*     the number of endpoints remaining, and it is ready for use with */
105 /*     any of the window routines. */
106 
107 /*     Because validation is done in place, there is no chance of */
108 /*     overflow. */
109 
110 /*     Validation is primarily useful for ordering and merging */
111 /*     intervals read from input files or initialized in DATA */
112 /*     statements. */
113 
114 /* $ Examples */
115 
116 /*     The following small program */
117 
118 /*            INTEGER               CARDD */
119 /*            INTEGER               SIZED */
120 
121 /*            DOUBLE PRECISION      WINDOW  ( LBCELL:20 ) */
122 
123 /*            DATA                  WINDOW  /  0,  0, */
124 /*           .                                10, 12, */
125 /*                                             2,  7, */
126 /*                                            13, 15, */
127 /*                                             1,  5, */
128 /*                                            23, 29,   8*0 / */
129 
130 /*            CALL WNVALD ( 20, 10, WINDOW ) */
131 
132 /*            WRITE (6,*) 'Current intervals: ', CARDD ( WINDOW ) / 2 */
133 /*            WRITE (6,*) 'Maximum intervals: ', SIZED ( WINDOW ) / 2 */
134 /*            WRITE (6,*) */
135 /*            WRITE (6,*) 'Intervals:' */
136 /*            WRITE (6,*) */
137 
138 /*            DO I = 1, CARDD ( WINDOW ), 2 */
139 /*               WRITE (6,*) WINDOW(I), WINDOW(I+1) */
140 /*            END DO */
141 
142 /*            END */
143 
144 /*     produces the following output (possibly formatted differently). */
145 
146 /*            Current intervals:        5 */
147 /*            Maximum intervals:       10 */
148 
149 /*            Intervals: */
150 
151 /*             0.000000000000000     0.000000000000000 */
152 /*             1.000000000000000     7.000000000000000 */
153 /*             10.00000000000000     12.00000000000000 */
154 /*             13.00000000000000     15.00000000000000 */
155 /*             23.00000000000000     29.00000000000000 */
156 
157 /* $ Exceptions */
158 
159 /*     1. If the number of endpoints N is odd, the error */
160 /*        SPICE(UNMATCHENDPTS) is signalled. */
161 
162 /*     2. If the number of end points of the window exceeds its size, the */
163 /*        error SPICE(WINDOWTOOSMALL) is signalled. */
164 
165 /*     3. If the left endpoint is greater than the right endpoint, the */
166 /*        error SPICE(BADENDPOINTS) is signalled. */
167 
168 /* $ Files */
169 
170 /*     None. */
171 
172 /* $ Restrictions */
173 
174 /*     None. */
175 
176 /* $ Literature_References */
177 
178 /*     None. */
179 
180 /* $ Author_and_Institution */
181 
182 /*     N.J. Bachman    (JPL) */
183 /*     H.A. Neilan     (JPL) */
184 /*     W.L. Taber      (JPL) */
185 /*     I.M. Underwood  (JPL) */
186 
187 /* $ Version */
188 
189 /* -    SPICELIB Version 1.1.1, 30-JUL-2002 (NJB) */
190 
191 /*        Fixed bugs in example program. */
192 
193 /* -    SPICELIB Version 1.1.0, 14-AUG-1995 (HAN) */
194 
195 /*        Fixed a character string that continued over two lines. */
196 /*        The "//" characters were missing. The Alpha/OpenVMS compiler */
197 /*        issued a warning regarding this incorrect statement syntax. */
198 
199 /* -    SPICELIB Version 1.0.1, 10-MAR-1992 (WLT) */
200 
201 /*        Comment section for permuted index source lines was added */
202 /*        following the header. */
203 
204 /* -    SPICELIB Version 1.0.0, 31-JAN-1990 (WLT) (IMU) */
205 
206 /* -& */
207 /* $ Index_Entries */
208 
209 /*     validate a d.p. window */
210 
211 /* -& */
212 /* $ Revisions */
213 
214 /* -    SPICELIB Version 1.1.0, 14-AUG-1995 (HAN) */
215 
216 /*        Fixed a character string that continued over two lines. */
217 /*        The "//" characters were missing. The Alpha/OpenVMS compiler */
218 /*        issued a warning regarding this incorrect statement syntax. */
219 
220 /* -    Beta Version 1.1.0, 17-FEB-1989 (HAN) (NJB) */
221 
222 /*        Contents of the Required_Reading section was */
223 /*        changed from "None." to "WINDOWS".  Also, the */
224 /*        declaration of the unused function FAILED was */
225 /*        removed. */
226 /* -& */
227 
228 /*     SPICELIB functions */
229 
230 
231 /*     Local variables */
232 
233 
234 /*     Setting up error processing. */
235 
236     if (return_()) {
237 	return 0;
238     }
239     chkin_("WNVALD", (ftnlen)6);
240 
241 /*     First, some error checks. The number of endpoints must be even, */
242 /*     and smaller than the reported size of the window. */
243 
244     if (odd_(n)) {
245 	setmsg_("WNVALD: Unmatched endpoints", (ftnlen)27);
246 	sigerr_("SPICE(UNMATCHENDPTS)", (ftnlen)20);
247 	chkout_("WNVALD", (ftnlen)6);
248 	return 0;
249     } else if (*n > *size) {
250 	setmsg_("WNVALD: Inconsistent value for SIZE.", (ftnlen)36);
251 	sigerr_("SPICE(WINDOWTOOSMALL)", (ftnlen)21);
252 	chkout_("WNVALD", (ftnlen)6);
253 	return 0;
254     }
255 
256 /*     Taking the easy way out, we will simply insert each new interval */
257 /*     as we happen upon it. We can do this safely in place. The output */
258 /*     window can't possibly contain more intervals than the input array. */
259 
260 /*     What can go wrong is this: a left endpoint might be greater than */
261 /*     the corresponding left endpoint. This is a boo-boo, and should be */
262 /*     reported. */
263 
264     ssized_(size, a);
265     scardd_(&c__0, a);
266     i__ = 1;
267     while(i__ < *n) {
268 	left = a[i__ + 5];
269 	right = a[i__ + 6];
270 	if (left > right) {
271 	    setmsg_("WNVALD: Left endpoint may not exceed right endpoint.", (
272 		    ftnlen)52);
273 	    sigerr_("SPICE(BADENDPOINTS)", (ftnlen)19);
274 	    chkout_("WNVALD", (ftnlen)6);
275 	    return 0;
276 	}
277 	wninsd_(&left, &right, a);
278 	i__ += 2;
279     }
280     chkout_("WNVALD", (ftnlen)6);
281     return 0;
282 } /* wnvald_ */
283 
284