1 /* vnorm.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      VNORM ( Vector norm, 3 dimensions ) */
vnorm_(doublereal * v1)9 doublereal vnorm_(doublereal *v1)
10 {
11     /* System generated locals */
12     doublereal ret_val, d__1, d__2, d__3;
13 
14     /* Builtin functions */
15     double sqrt(doublereal);
16 
17     /* Local variables */
18     doublereal v1max;
19 
20 /* $ Abstract */
21 
22 /*      Compute the magnitude of a double precision, 3-dimensional */
23 /*      vector. */
24 
25 /* $ Disclaimer */
26 
27 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
28 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
29 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
30 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
31 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
32 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
33 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
34 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
35 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
36 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
37 
38 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
39 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
40 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
41 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
42 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
43 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
44 
45 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
46 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
47 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
48 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
49 
50 /* $ Required_Reading */
51 
52 /*     None. */
53 
54 /* $ Keywords */
55 
56 /*      VECTOR */
57 
58 /* $ Declarations */
59 /* $ Brief_I/O */
60 
61 /*      VARIABLE  I/O  DESCRIPTION */
62 /*      --------  ---  -------------------------------------------------- */
63 /*       V1        I     Vector whose magnitude is to be found. */
64 
65 /* $ Detailed_Input */
66 
67 /*      V1      This may be any 3-dimensional, double precision vector. */
68 
69 /* $ Detailed_Output */
70 
71 /*      VNORM is the magnitude of V1 calculated in a numerically stable */
72 /*      way. */
73 
74 /* $ Parameters */
75 
76 /*     None. */
77 
78 /* $ Particulars */
79 
80 /*      VNORM finds the component of V1 whose magnitude is the largest. */
81 /*      If the absolute magnitude of that component indicates that a */
82 /*      numeric overflow would occur when it is squared, or if it */
83 /*      indicates that an underflow would occur when square (giving a */
84 /*      magnitude of zero) then the following expression is used: */
85 
86 /*      VNORM = V1MAX * MAGNITUDE OF [ (1/V1MAX)*V1 ] */
87 
88 /*      Otherwise a simpler expression is used: */
89 
90 /*      VNORM = MAGNITUDE OF [ V1 ] */
91 
92 /*      Beyond the logic described above, no further checking of the */
93 /*      validity of the input is performed. */
94 
95 /* $ Examples */
96 
97 /*      The following table show the correlation between various input */
98 /*      vectors V1 and VNORM: */
99 
100 /*      V1                                    VNORM */
101 /*      ----------------------------------------------------------------- */
102 /*      (1.D0, 2.D0, 2.D0)                     3.D0 */
103 /*      (5.D0, 12.D0, 0.D0)                   13.D0 */
104 /*      (-5.D-17, 0.0D0, 12.D-17)             13.D-17 */
105 
106 /* $ Restrictions */
107 
108 /*      None. */
109 
110 /* $ Exceptions */
111 
112 /*      Error free. */
113 
114 /* $ Files */
115 
116 /*      None. */
117 
118 /* $ Author_and_Institution */
119 
120 /*      W.M. Owen       (JPL) */
121 
122 /* $ Literature_References */
123 
124 /*      None. */
125 
126 /* $ Version */
127 
128 /* -     SPICELIB Version 1.0.1, 10-MAR-1992 (WLT) */
129 
130 /*         Comment section for permuted index source lines was added */
131 /*         following the header. */
132 
133 /* -     SPICELIB Version 1.0.0, 31-JAN-1990 (WMO) */
134 
135 /* -& */
136 /* $ Index_Entries */
137 
138 /*     norm of 3-dimensional vector */
139 
140 /* -& */
141 
142 /*  Determine the maximum component of the vector. */
143 
144 /* Computing MAX */
145     d__1 = abs(v1[0]), d__2 = abs(v1[1]), d__1 = max(d__1,d__2), d__2 = abs(
146 	    v1[2]);
147     v1max = max(d__1,d__2);
148 
149 /*  If the vector is zero, return zero; otherwise normalize first. */
150 /*  Normalizing helps in the cases where squaring would cause overflow */
151 /*  or underflow.  In the cases where such is not a problem it not worth */
152 /*  it to optimize further. */
153 
154     if (v1max == 0.) {
155 	ret_val = 0.;
156     } else {
157 /* Computing 2nd power */
158 	d__1 = v1[0] / v1max;
159 /* Computing 2nd power */
160 	d__2 = v1[1] / v1max;
161 /* Computing 2nd power */
162 	d__3 = v1[2] / v1max;
163 	ret_val = v1max * sqrt(d__1 * d__1 + d__2 * d__2 + d__3 * d__3);
164     }
165 
166     return ret_val;
167 } /* vnorm_ */
168 
169