1 /* vrel.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  VREL ( Vector relative difference, 3 dimensions ) */
vrel_(doublereal * v1,doublereal * v2)9 doublereal vrel_(doublereal *v1, doublereal *v2)
10 {
11     /* System generated locals */
12     doublereal ret_val, d__1, d__2;
13 
14     /* Local variables */
15     extern doublereal vdist_(doublereal *, doublereal *), vnorm_(doublereal *)
16 	    ;
17     doublereal denorm, nunorm;
18 
19 /* $ Abstract */
20 
21 /*   Return the relative difference between two 3-dimensional vectors. */
22 
23 /* $ Disclaimer */
24 
25 /*     THIS SOFTWARE AND ANY RELATED MATERIALS WERE CREATED BY THE */
26 /*     CALIFORNIA INSTITUTE OF TECHNOLOGY (CALTECH) UNDER A U.S. */
27 /*     GOVERNMENT CONTRACT WITH THE NATIONAL AERONAUTICS AND SPACE */
28 /*     ADMINISTRATION (NASA). THE SOFTWARE IS TECHNOLOGY AND SOFTWARE */
29 /*     PUBLICLY AVAILABLE UNDER U.S. EXPORT LAWS AND IS PROVIDED "AS-IS" */
30 /*     TO THE RECIPIENT WITHOUT WARRANTY OF ANY KIND, INCLUDING ANY */
31 /*     WARRANTIES OF PERFORMANCE OR MERCHANTABILITY OR FITNESS FOR A */
32 /*     PARTICULAR USE OR PURPOSE (AS SET FORTH IN UNITED STATES UCC */
33 /*     SECTIONS 2312-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE */
34 /*     SOFTWARE AND RELATED MATERIALS, HOWEVER USED. */
35 
36 /*     IN NO EVENT SHALL CALTECH, ITS JET PROPULSION LABORATORY, OR NASA */
37 /*     BE LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING, BUT NOT */
38 /*     LIMITED TO, INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, */
39 /*     INCLUDING ECONOMIC DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, */
40 /*     REGARDLESS OF WHETHER CALTECH, JPL, OR NASA BE ADVISED, HAVE */
41 /*     REASON TO KNOW, OR, IN FACT, SHALL KNOW OF THE POSSIBILITY. */
42 
43 /*     RECIPIENT BEARS ALL RISK RELATING TO QUALITY AND PERFORMANCE OF */
44 /*     THE SOFTWARE AND ANY RELATED MATERIALS, AND AGREES TO INDEMNIFY */
45 /*     CALTECH AND NASA FOR ALL THIRD-PARTY CLAIMS RESULTING FROM THE */
46 /*     ACTIONS OF RECIPIENT IN THE USE OF THE SOFTWARE. */
47 
48 /* $ Required_Reading */
49 
50 /*   None. */
51 
52 /* $ Keywords */
53 
54 /*     MATH */
55 /*     VECTOR */
56 
57 /* $ Declarations */
58 /* $ Brief_I/O */
59 
60 /*     Variable  I/O  Description */
61 /*     --------  ---  -------------------------------------------------- */
62 /*      V1,V2     I   Input vectors. */
63 
64 /* $ Detailed_Input */
65 
66 /*      V1, V2        are two 3-dimensional vectors for which the */
67 /*                    relative difference is to be computed. */
68 
69 /* $ Detailed_Output */
70 
71 /*      VREL          is the relative difference between V1 and V2. */
72 /*                    It is defined as: */
73 /*                                             || V1 - V2 || */
74 /*                              VREL   =   ---------------------- */
75 /*                                         MAX ( ||V1||, ||V2|| ) */
76 
77 /*                    where || X || indicates the Euclidean norm of */
78 /*                    the vector X. */
79 
80 /*                    VREL assumes values in the range [0,2]. If both */
81 /*                    V1 and V2 are zero vectors then VREL is defined */
82 /*                    to be zero. */
83 
84 
85 /* $ Parameters */
86 
87 /*     None. */
88 
89 /* $ Exceptions */
90 
91 /*     Error free. */
92 
93 /*     If both V1 and V2 are zero vectors then VREL is defined */
94 /*     to be zero. */
95 
96 /* $ Files */
97 
98 /*     None. */
99 
100 /* $ Particulars */
101 
102 /*     This function computes the relative difference between two */
103 /*     3-dimensional vectors as defined above. */
104 
105 /*     The function VRELG may be used to find the relative difference */
106 /*     for two vectors of general dimension. */
107 
108 /* $ Examples */
109 
110 /*     This example code fragment computes the relative difference */
111 /*     between the geometric and light time corrected state of Io */
112 /*     with respect to Voyager 2 at a given UTC time. */
113 
114 /*     C */
115 /*     C     The NAIF integer code for Io is 501 and the code for */
116 /*     C     Voyager 2 is -32. */
117 /*     C */
118 
119 /*           INTEGER               IO */
120 /*           PARAMETER           ( IO  = 501 ) */
121 
122 /*           INTEGER               VG2 */
123 /*           PARAMETER           ( VG2 = -32 ) */
124 
125 /*     C */
126 /*     C     Spicelib function */
127 /*     C */
128 /*           DOUBLE PRECISION      VREL */
129 /*     C */
130 /*     C     Local variables */
131 /*     C */
132 /*           DOUBLE PRECISION      STATE ( 6 ) */
133 /*           DOUBLE PRECISION      POS1  ( 3 ) */
134 /*           DOUBLE PRECISION      POS2  ( 3 ) */
135 /*           DOUBLE PRECISION      DIFF */
136 /*           DOUBLE PRECISION      LT */
137 /*           DOUBLE PRECISION      ET */
138 
139 /*           INTEGER               HANDLE */
140 
141 /*           CHARACTER*(20)        UTC */
142 
143 /*           DATA                  UTC / '1979 JUN 25 12:00:00' / */
144 
145 /*     C */
146 /*     C     Load the sample SPK ephemeris file. */
147 /*     C */
148 /*           CALL SPKLEF ( 'VG2_JUP.BSP', HANDLE ) */
149 /*     C */
150 /*     C     Convert the UTC time string to ephemeris time. */
151 /*     C */
152 /*           CALL UTC2ET ( UTC, ET ) */
153 /*     C */
154 /*     C     First calculate the geometric state and then the light */
155 /*     C     time corrected state. */
156 /*     C */
157 /*           CALL SPKEZ ( IO, ET, 'J2000', 'NONE', VG2, STATE, LT ) */
158 
159 /*           CALL VEQU  ( STATE, POS1 ) */
160 
161 /*           CALL SPKEZ ( IO, ET, 'J2000', 'LT', VG2, STATE, LT ) */
162 
163 /*           CALL VEQU  ( STATE, POS2 ) */
164 /*     C */
165 /*     C     Call VREL to find the relative difference between the */
166 /*     C     two states. */
167 /*     C */
168 /*           DIFF = VREL ( POS1, POS2 ) */
169 
170 /*           . */
171 /*           . */
172 /*           . */
173 
174 /* $ Restrictions */
175 
176 /*     None. */
177 
178 /* $ Literature_References */
179 
180 /*     None. */
181 
182 /* $ Author_and_Institution */
183 
184 /*     J.M. Lynch     (JPL) */
185 
186 /* $ Version */
187 
188 /* -    SPICELIB Version 1.0.0, 15-JUN-1992 (JML) */
189 
190 /* -& */
191 /* $ Index_Entries */
192 
193 /*     relative difference of 3-dimensional vectors */
194 
195 /* -& */
196 
197 /*     SPICELIB functions */
198 
199 
200 /*     Local variables */
201 
202 
203 /*     If the numerator is zero then set VREL equal to zero. Otherwise, */
204 /*     perform the rest of the calculation. */
205 
206 /*     This handles the case where both vectors are zero vectors since */
207 /*     the distance between them will be zero. */
208 
209     nunorm = vdist_(v1, v2);
210     if (nunorm == 0.) {
211 	ret_val = 0.;
212     } else {
213 /* Computing MAX */
214 	d__1 = vnorm_(v1), d__2 = vnorm_(v2);
215 	denorm = max(d__1,d__2);
216 	ret_val = nunorm / denorm;
217     }
218     return ret_val;
219 } /* vrel_ */
220 
221