1 /* vhatip.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 VHATIP ( "V-Hat", 3-d unit vector along V, in place ) */
vhatip_(doublereal * v)9 /* Subroutine */ int vhatip_(doublereal *v)
10 {
11     doublereal vmag;
12     extern doublereal vnorm_(doublereal *);
13 
14 /* $ Abstract */
15 
16 /*      Scale a three-dimensional vector to unit length. */
17 
18 /* $ Disclaimer */
19 
20 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
21 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
22 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
23 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
24 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
25 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
26 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
27 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
28 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
29 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
30 
31 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
32 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
33 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
34 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
35 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
36 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
37 
38 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
39 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
40 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
41 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
42 
43 /* $ Required_Reading */
44 
45 /*     None. */
46 
47 /* $ Keywords */
48 
49 /*     VECTOR */
50 
51 /* $ Declarations */
52 /* $ Brief_I/O */
53 
54 /*     VARIABLE  I/O  DESCRIPTION */
55 /*     --------  ---  -------------------------------------------------- */
56 /*     V         I-O  Vector to be normalized/unit vector. */
57 
58 /* $ Detailed_Input */
59 
60 /*     V        This is any double precision, 3-dimensional vector.  If */
61 /*              this vector is the zero vector, this routine will detect */
62 /*              it, and will not attempt to divide by zero. */
63 
64 /* $ Detailed_Output */
65 
66 /*     V        V contains the unit vector in the direction of the input */
67 /*              vector.  If on input V represents the zero vector, then */
68 /*              V will be returned as the zero vector. */
69 
70 /* $ Parameters */
71 
72 /*     None. */
73 
74 /* $ Exceptions */
75 
76 /*     Error free. */
77 
78 /*     1) The zero vector is returned if the input value of V is the */
79 /*        zero vector. */
80 
81 /* $ Files */
82 
83 /*     None. */
84 
85 /* $ Particulars */
86 
87 /*     This routine is provided for situation where it is convenient */
88 /*     to scale a vector to unit length in place rather than store */
89 /*     the result in a separate variable.  Note that the call */
90 
91 /*        CALL VHAT ( V, V ) */
92 
93 /*     is not permitted by the ANSI Fortran 77 standard; this routine */
94 /*     can be called instead to achieve the same result. */
95 
96 /*     VHATIP determines the magnitude of V and then, if the magnitude */
97 /*     is non-zero, divides each component of V by the magnitude.  This */
98 /*     process is highly stable over the whole range of 3-dimensional */
99 /*     vectors. */
100 
101 /* $ Examples */
102 
103 /*     The following table shows how selected vectors are mapped to */
104 /*     unit vectors */
105 
106 /*     V on input            V on output */
107 /*     ------------------    ------------------ */
108 /*     (5, 12, 0)            (5/13, 12/13, 0) */
109 /*     (1D-7, 2D-7, 2D-7)    (1/3, 2/3, 2/3) */
110 
111 /* $ Restrictions */
112 
113 /*     There is no known case whereby floating point overflow may occur. */
114 /*     Thus, no error recovery or reporting scheme is incorporated */
115 /*     into this subroutine. */
116 
117 /* $ Author_and_Institution */
118 
119 /*     N.J. Bachman    (JPL) */
120 /*     H.A. Neilan     (JPL) */
121 /*     W.M. Owen       (JPL) */
122 /*     W.L. Taber      (JPL) */
123 
124 /* $ Literature_References */
125 
126 /*     None. */
127 
128 /* $ Version */
129 
130 /* -    SPICELIB Version 1.1.0, 01-SEP-2005 (NJB) (HAN) (WMO) (WLT) */
131 
132 /* -& */
133 /* $ Index_Entries */
134 
135 /*     unitize a 3-dimensional vector in place */
136 
137 /* -& */
138 
139 /*     SPICELIB functions */
140 
141 
142 /*     Local variables */
143 
144 
145 /*     Obtain the magnitude of V. */
146 
147     vmag = vnorm_(v);
148 
149 /*     If VMAG is nonzero, then normalize. Note that this process is */
150 /*     numerically stable: overflow could only happen if VMAG were */
151 /*     small, but this could only happen if each component of V1 were */
152 /*     small. In fact, the magnitude of any vector is never less than */
153 /*     the magnitude of any component. */
154 
155     if (vmag > 0.) {
156 	v[0] /= vmag;
157 	v[1] /= vmag;
158 	v[2] /= vmag;
159     } else {
160 	v[0] = 0.;
161 	v[1] = 0.;
162 	v[2] = 0.;
163     }
164     return 0;
165 } /* vhatip_ */
166 
167