1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
/// Vector relative difference, 3 dimensions
///
/// Return the relative difference between two 3-dimensional vectors.
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// V1,
/// V2 I Input vectors.
///
/// The function returns the relative difference between two
/// 3-dimensional vectors.
/// ```
///
/// # Detailed Input
///
/// ```text
/// V1,
/// V2 are two 3-dimensional vectors for which the relative
/// difference is to be computed.
/// ```
///
/// # Detailed Output
///
/// ```text
/// The function returns the relative difference between the two input
/// 3-dimensional vectors V1 and V2.
///
/// It is defined as:
///
/// || V1 - V2 ||
/// VREL = ------------------------
/// MAX ( ||V1||, ||V2|| )
///
/// where ||X|| indicates the Euclidean norm of the vector X.
///
/// VREL assumes values in the range [0,2]. If both V1 and V2 are zero
/// vectors then VREL is defined to be zero.
/// ```
///
/// # Exceptions
///
/// ```text
/// Error free.
///
/// 1) If both V1 and V2 are zero vectors, then VREL is defined
/// to be zero.
/// ```
///
/// # Particulars
///
/// ```text
/// This function computes the relative difference between two
/// 3-dimensional vectors as defined above.
///
/// The function VRELG may be used to find the relative difference
/// for two vectors of general dimension.
/// ```
///
/// # Examples
///
/// ```text
/// This example code fragment computes the relative difference
/// between the geometric and light time corrected state of Io
/// with respect to Voyager 2 at a given UTC time.
///
/// C
/// C The NAIF integer code for Io is 501 and the code for
/// C Voyager 2 is -32.
/// C
///
/// INTEGER IO
/// PARAMETER ( IO = 501 )
///
/// INTEGER VG2
/// PARAMETER ( VG2 = -32 )
///
/// C
/// C SPICELIB function
/// C
/// DOUBLE PRECISION VREL
/// C
/// C Local variables
/// C
/// DOUBLE PRECISION STATE ( 6 )
/// DOUBLE PRECISION POS1 ( 3 )
/// DOUBLE PRECISION POS2 ( 3 )
/// DOUBLE PRECISION DIFF
/// DOUBLE PRECISION LT
/// DOUBLE PRECISION ET
///
/// INTEGER HANDLE
///
/// CHARACTER*(20) UTC
///
/// DATA UTC / '1979 JUN 25 12:00:00' /
///
/// C
/// C Load the sample SPK ephemeris file.
/// C
/// CALL SPKLEF ( 'VG2_JUP.BSP', HANDLE )
/// C
/// C Convert the UTC time string to ephemeris time.
/// C
/// CALL UTC2ET ( UTC, ET )
/// C
/// C First calculate the geometric state and then the light
/// C time corrected state.
/// C
/// CALL SPKEZ ( IO, ET, 'J2000', 'NONE', VG2, STATE, LT )
///
/// CALL VEQU ( STATE, POS1 )
///
/// CALL SPKEZ ( IO, ET, 'J2000', 'LT', VG2, STATE, LT )
///
/// CALL VEQU ( STATE, POS2 )
/// C
/// C Call VREL to find the relative difference between the
/// C two states.
/// C
/// DIFF = VREL ( POS1, POS2 )
///
/// .
/// .
/// .
/// ```
///
/// # Author and Institution
///
/// ```text
/// J. Diaz del Rio (ODC Space)
/// J.M. Lynch (JPL)
/// ```
///
/// # Version
///
/// ```text
/// - SPICELIB Version 1.1.0, 12-AUG-2021 (JDR)
///
/// Added IMPLICIT NONE statement.
///
/// Edited the header to comply with NAIF standard.
///
/// - SPICELIB Version 1.0.0, 15-JUN-1992 (JML)
/// ```
pub fn vrel(v1: &[f64; 3], v2: &[f64; 3]) -> f64 {
let ret = VREL(v1, v2);
ret
}
//$Procedure VREL ( Vector relative difference, 3 dimensions )
pub fn VREL(V1: &[f64], V2: &[f64]) -> f64 {
let V1 = DummyArray::new(V1, 1..=3);
let V2 = DummyArray::new(V2, 1..=3);
let mut VREL: f64 = 0.0;
let mut NUNORM: f64 = 0.0;
let mut DENORM: f64 = 0.0;
//
// SPICELIB functions
//
//
// Local variables
//
//
// If the numerator is zero then set VREL equal to zero. Otherwise,
// perform the rest of the calculation.
//
// This handles the case where both vectors are zero vectors since
// the distance between them will be zero.
//
NUNORM = VDIST(V1.as_slice(), V2.as_slice());
if (NUNORM == 0.0) {
VREL = 0.0;
} else {
DENORM = intrinsics::DMAX1(&[VNORM(V1.as_slice()), VNORM(V2.as_slice())]);
VREL = (NUNORM / DENORM);
}
VREL
}