1 /* brcktd.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 BRCKTD (Bracket a double precision value within an interval) */
brcktd_(doublereal * number,doublereal * end1,doublereal * end2)9 doublereal brcktd_(doublereal *number, doublereal *end1, doublereal *end2)
10 {
11 /* System generated locals */
12 doublereal ret_val, d__1, d__2;
13
14 /* $ Abstract */
15
16 /* Bracket a number. That is, given a number and an acceptable */
17 /* interval, make sure that the number is contained in the */
18 /* interval. (If the number is already in the interval, leave it */
19 /* alone. If not, set it to the nearest endpoint of the interval.) */
20
21 /* $ Disclaimer */
22
23 /* THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
24 /* CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
25 /* GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
26 /* ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
27 /* PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
28 /* TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
29 /* WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
30 /* PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
31 /* SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
32 /* SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
33
34 /* IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
35 /* BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
36 /* LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
37 /* INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
38 /* REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
39 /* REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
40
41 /* RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
42 /* THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
43 /* CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
44 /* ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
45
46 /* $ Required_Reading */
47
48 /* None. */
49
50 /* $ Keywords */
51
52 /* INTERVALS, NUMBERS, UTILITY */
53
54 /* $ Declarations */
55 /* $ Brief_I/O */
56
57 /* VARIABLE I/O DESCRIPTION */
58 /* -------- --- -------------------------------------------------- */
59 /* NUMBER I Number to be bracketed. */
60 /* END1 I One of the bracketing endpoints for NUMBER. */
61 /* END2 I The other bracketing endpoint for NUMBER. */
62 /* BRCKTD O Bracketed number. */
63
64 /* $ Detailed_Input */
65
66 /* NUMBER is the number to be bracketed. That is, the */
67 /* value of NUMBER is constrained to lie in the */
68 /* interval bounded by END1 and END2. */
69
70 /* END1, */
71 /* END2 are the lower and upper bounds for NUMBER. The */
72 /* order is not important. */
73
74 /* $ Detailed_Output */
75
76 /* BRCKTD is NUMBER, if it was already in the interval */
77 /* provided. Otherwise it is the value of the nearest */
78 /* bound of the interval. */
79
80 /* $ Parameters */
81
82 /* None. */
83
84 /* $ Particulars */
85
86 /* This routine provides a shorthand notation for code fragments */
87 /* like the following */
88
89 /* IF ( NUMBER .LT. END1 ) THEN */
90 /* NUMBER = END1 */
91 /* ELSE IF ( NUMBER .GT. END2 ) THEN */
92 /* NUMBER = END2 */
93 /* END IF */
94
95 /* which occur frequently during the processing of program inputs. */
96
97 /* $ Examples */
98
99 /* The following illustrate the operation of BRCKTD. */
100
101 /* BRCKTD ( -1.D0, 1.D0, 10.D0 ) = 1.D0 */
102 /* BRCKTD ( 29.D0, 1.D0, 10.D0 ) = 10.D0 */
103 /* BRCKTD ( 3.D0, -10.D0, 10.D0 ) = 3.D0 */
104 /* BRCKTD ( 3.D0, -10.D0, -1.D0 ) = -1.D0 */
105
106 /* The following code fragment illustrates a typical use for BRCKTD. */
107
108 /* C */
109 /* C Star magnitude limit must be in the range 0-10. */
110 /* C */
111 /* READ (5,*) MAGLIM */
112 /* MAGLIM = BRCKTD ( MAGLIM, 0.D0, 10.D0 ) */
113
114 /* $ Restrictions */
115
116 /* None. */
117
118 /* $ Exceptions */
119
120 /* Error free. */
121
122 /* $ Files */
123
124 /* None. */
125
126 /* $ Author_and_Institution */
127
128 /* W.L. Taber (JPL) */
129 /* I.M. Underwood (JPL) */
130
131 /* $ Literature_References */
132
133 /* None. */
134
135 /* $ Version */
136
137 /* - SPICELIB Version 1.0.1, 10-MAR-1992 (WLT) */
138
139 /* Comment section for permuted index source lines was added */
140 /* following the header. */
141
142 /* - SPICELIB Version 1.0.0, 31-JAN-1990 (IMU) */
143
144 /* -& */
145 /* $ Index_Entries */
146
147 /* bracket a d.p. value within an interval */
148
149 /* -& */
150 /* $ Revisions */
151
152 /* - Beta Version 1.1.0, 30-DEC-1988 (WLT) */
153
154 /* The routine was modified so that the order of the endpoints */
155 /* of the bracketing interval is not needed. The routine now */
156 /* determines which is the left endpoint and which is the */
157 /* right and acts appropriately. */
158
159 /* -& */
160
161 /* What else is there to say? */
162
163 if (*end1 < *end2) {
164 /* Computing MAX */
165 d__1 = *end1, d__2 = min(*end2,*number);
166 ret_val = max(d__1,d__2);
167 } else {
168 /* Computing MAX */
169 d__1 = *end2, d__2 = min(*end1,*number);
170 ret_val = max(d__1,d__2);
171 }
172 return ret_val;
173 } /* brcktd_ */
174
175