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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
pub const UBEL: i32 = 9;
const CTRPOS: i32 = 1;
const MAJPOS: i32 = 4;
const MINPOS: i32 = 7;
/// Ellipse to center and generating vectors
///
/// Convert a SPICE ellipse to a center vector and two generating
/// vectors. The selected generating vectors are semi-axes of the
/// ellipse.
///
/// # Required Reading
///
/// * [ELLIPSES](crate::required_reading::ellipses)
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// ELLIPS I A SPICE ellipse.
/// CENTER,
/// SMAJOR,
/// SMINOR O Center and semi-axes of ELLIPS.
/// ```
///
/// # Detailed Input
///
/// ```text
/// ELLIPS is a SPICE ellipse.
/// ```
///
/// # Detailed Output
///
/// ```text
/// CENTER,
/// SMAJOR,
/// SMINOR are, respectively, a center vector, a semi-major
/// axis vector, and a semi-minor axis vector that
/// generate the input ellipse. This ellipse is the
/// set of points
///
/// CENTER + cos(theta) SMAJOR + sin(theta) SMINOR
///
/// where theta ranges over the interval (-pi, pi].
/// ```
///
/// # Exceptions
///
/// ```text
/// Error free.
/// ```
///
/// # Particulars
///
/// ```text
/// SPICE ellipses serve to simplify calling sequences and reduce
/// the chance for error in declaring and describing argument lists
/// involving ellipses.
///
/// The set of ellipse conversion routines is
///
/// CGV2EL ( Center and generating vectors to ellipse )
/// EL2CGV ( Ellipse to center and generating vectors )
///
/// A word about the output of this routine: the semi-major axis of
/// an ellipse is a vector of largest possible magnitude in the set
///
/// cos(theta) VEC1 + sin(theta) VEC2,
///
/// where theta is in the interval (-pi, pi]. There are two such
/// vectors; they are additive inverses of each other. The semi-minor
/// axis is an analogous vector of smallest possible magnitude. The
/// semi-major and semi-minor axes are orthogonal to each other. If
/// SMAJOR and SMINOR are choices of semi-major and semi-minor axes,
/// then the input ellipse can also be represented as the set of
/// points
///
///
/// CENTER + cos(theta) SMAJOR + sin(theta) SMINOR
///
/// where theta ranges over the interval (-pi, pi].
/// ```
///
/// # Examples
///
/// ```text
/// The numerical results shown for these examples may differ across
/// platforms. The results depend on the SPICE kernels used as
/// input, the compiler and supporting libraries, and the machine
/// specific arithmetic implementation.
///
/// 1) Given a SPICE ellipse structure, extract its components into
/// independent variables.
///
///
/// Example code begins here.
///
///
/// PROGRAM EL2CGV_EX1
/// IMPLICIT NONE
///
/// C
/// C Local constants.
/// C
/// INTEGER UBEL
/// PARAMETER ( UBEL = 9 )
///
/// C
/// C Local variables.
/// C
/// DOUBLE PRECISION CENTER ( 3 )
/// DOUBLE PRECISION ECENTR ( 3 )
/// DOUBLE PRECISION ELLIPS ( UBEL )
/// DOUBLE PRECISION SMAJOR ( 3 )
/// DOUBLE PRECISION SMINOR ( 3 )
/// DOUBLE PRECISION VEC1 ( 3 )
/// DOUBLE PRECISION VEC2 ( 3 )
///
/// INTEGER I
///
/// C
/// C Define the center and two linearly independent
/// C generating vectors of an ellipse (the vectors need not
/// C be linearly independent).
/// C
/// DATA CENTER / -1.D0, 1.D0, -1.D0 /
///
/// DATA VEC1 / 1.D0, 1.D0, 1.D0 /
///
/// DATA VEC2 / 1.D0, -1.D0, 1.D0 /
///
/// C
/// C Create the ELLIPS.
/// C
/// CALL CGV2EL ( CENTER, VEC1, VEC2, ELLIPS )
///
/// C
/// C In a real application, please use SPICELIB API EL2CGV
/// C to retrieve the center and generating vectors from the
/// C ellipse structure (see next block).
/// C
/// WRITE(*,'(A)') 'SPICE ellipse:'
/// WRITE(*,'(A,3F10.6)') ' Semi-minor axis:',
/// . ( ELLIPS(I), I=7,9 )
/// WRITE(*,'(A,3F10.6)') ' Semi-major axis:',
/// . ( ELLIPS(I), I=4,6 )
/// WRITE(*,'(A,3F10.6)') ' Center :',
/// . ( ELLIPS(I), I=1,3 )
/// WRITE(*,*) ' '
///
/// C
/// C Obtain the center and generating vectors from the
/// C ELLIPS.
/// C
/// CALL EL2CGV ( ELLIPS, ECENTR, SMAJOR, SMINOR )
///
/// WRITE(*,'(A)') 'SPICE ellipse (using EL2CGV):'
/// WRITE(*,'(A,3F10.6)') ' Semi-minor axis:', SMINOR
/// WRITE(*,'(A,3F10.6)') ' Semi-major axis:', SMAJOR
/// WRITE(*,'(A,3F10.6)') ' Center :', ECENTR
///
/// END
///
///
/// When this program was executed on a Mac/Intel/gfortran/64-bit
/// platform, the output was:
///
///
/// SPICE ellipse:
/// Semi-minor axis: 0.000000 1.414214 0.000000
/// Semi-major axis: 1.414214 -0.000000 1.414214
/// Center : -1.000000 1.000000 -1.000000
///
/// SPICE ellipse (using EL2CGV):
/// Semi-minor axis: 0.000000 1.414214 0.000000
/// Semi-major axis: 1.414214 -0.000000 1.414214
/// Center : -1.000000 1.000000 -1.000000
///
///
/// 2) Given an ellipsoid and a viewpoint exterior to it, calculate
/// the limb ellipse as seen from that viewpoint.
///
///
/// Example code begins here.
///
///
/// PROGRAM EL2CGV_EX2
/// IMPLICIT NONE
///
/// C
/// C Local constants.
/// C
/// INTEGER UBEL
/// PARAMETER ( UBEL = 9 )
///
/// C
/// C Local variables.
/// C
/// DOUBLE PRECISION A
/// DOUBLE PRECISION B
/// DOUBLE PRECISION C
/// DOUBLE PRECISION ECENTR ( 3 )
/// DOUBLE PRECISION LIMB ( UBEL )
/// DOUBLE PRECISION SMAJOR ( 3 )
/// DOUBLE PRECISION SMINOR ( 3 )
/// DOUBLE PRECISION VIEWPT ( 3 )
///
/// C
/// C Define a viewpoint exterior to the ellipsoid.
/// C
/// DATA VIEWPT / 2.D0, 0.D0, 0.D0 /
///
/// C
/// C Define an ellipsoid.
/// C
/// A = SQRT( 2.D0 )
/// B = 2.D0 * SQRT( 2.D0 )
/// C = SQRT( 2.D0 )
///
/// C
/// C Calculate the limb ellipse as seen by from the
/// C viewpoint.
/// C
/// CALL EDLIMB ( A, B, C, VIEWPT, LIMB )
///
/// C
/// C Output the structure components.
/// C
/// CALL EL2CGV ( LIMB, ECENTR, SMAJOR, SMINOR )
///
/// WRITE(*,'(A)') 'Limb ellipse as seen from viewpoint:'
/// WRITE(*,'(A,3F11.6)') ' Semi-minor axis:', SMINOR
/// WRITE(*,'(A,3F11.6)') ' Semi-major axis:', SMAJOR
/// WRITE(*,'(A,3F11.6)') ' Center :', ECENTR
///
/// END
///
///
/// When this program was executed on a Mac/Intel/gfortran/64-bit
/// platform, the output was:
///
///
/// Limb ellipse as seen from viewpoint:
/// Semi-minor axis: 0.000000 0.000000 -1.000000
/// Semi-major axis: 0.000000 2.000000 -0.000000
/// Center : 1.000000 0.000000 0.000000
/// ```
///
/// # Author and Institution
///
/// ```text
/// N.J. Bachman (JPL)
/// J. Diaz del Rio (ODC Space)
/// W.L. Taber (JPL)
/// ```
///
/// # Version
///
/// ```text
/// - SPICELIB Version 1.1.0, 24-AUG-2021 (JDR)
///
/// Added IMPLICIT NONE statement.
///
/// Edited the header to comply with NAIF standard.
/// Added complete code example.
///
/// - SPICELIB Version 1.0.1, 10-MAR-1992 (WLT)
///
/// Comment section for permuted index source lines was added
/// following the header.
///
/// - SPICELIB Version 1.0.0, 02-NOV-1990 (NJB)
/// ```
pub fn el2cgv(
ellips: &[f64; 9],
center: &mut [f64; 3],
smajor: &mut [f64; 3],
sminor: &mut [f64; 3],
) {
EL2CGV(ellips, center, smajor, sminor);
}
//$Procedure EL2CGV ( Ellipse to center and generating vectors )
pub fn EL2CGV(ELLIPS: &[f64], CENTER: &mut [f64], SMAJOR: &mut [f64], SMINOR: &mut [f64]) {
let ELLIPS = DummyArray::new(ELLIPS, 1..=UBEL);
let mut CENTER = DummyArrayMut::new(CENTER, 1..=3);
let mut SMAJOR = DummyArrayMut::new(SMAJOR, 1..=3);
let mut SMINOR = DummyArrayMut::new(SMINOR, 1..=3);
//
// Local parameters
//
//
// SPICE ellipses contain a center vector, a semi-major
// axis vector, and a semi-minor axis vector. These are
// located, respectively, in elements
//
// CTRPOS through CTRPOS + 1
//
// MAJPOS through MAJPOS + 1
//
// MINPOS through MINPOS + 1
//
//
//
// The center of the ellipse is held in the first three elements.
// The semi-major and semi-minor axes come next.
//
VEQU(ELLIPS.subarray(CTRPOS), CENTER.as_slice_mut());
VEQU(ELLIPS.subarray(MAJPOS), SMAJOR.as_slice_mut());
VEQU(ELLIPS.subarray(MINPOS), SMINOR.as_slice_mut());
}