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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
/// Two states defining a frame transformation
///
/// Find the state transformation from a base frame to the
/// right-handed frame defined by two state vectors: one state
/// vector defining a specified axis and a second state vector
/// defining a specified coordinate plane.
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- -------------------------------------------------
/// AXDEF I State defining a principal axis.
/// INDEXA I Principal axis number of AXDEF (X=1, Y=2, Z=3).
/// PLNDEF I State defining (with AXDEF) a principal plane.
/// INDEXP I Second axis number (with INDEXA) of principal
/// plane.
/// XFORM O Output state transformation matrix.
/// ```
///
/// # Detailed Input
///
/// ```text
/// AXDEF is a "generalized" state vector defining one of the
/// principal axes of a reference frame. This vector
/// consists of three components of a vector-valued
/// function of one independent variable `t' followed by
/// the derivatives of the components with respect to that
/// variable:
///
/// ( a, b, c, da/dt, db/dt, dc/dt )
///
/// This routine treats the input states as unitless, but
/// in most applications the input states represent
/// quantities that have associated units. The first three
/// components must have the same units, and the units of
/// the last three components must be compatible with
/// those of the first three: if the first three
/// components of AXDEF
///
/// ( a, b, c )
///
/// have units U and `t' has units T, then the units of
/// AXDEF normally would be
///
/// ( U, U, U, U/T, U/T, U/T )
///
/// Note that the direction and angular velocity defined
/// by AXDEF are actually independent of U, so scaling
/// AXDEF doesn't affect the output of this routine.
///
/// AXDEF could represent position and velocity; it could
/// also represent velocity and acceleration. AXDEF could
/// for example represent the velocity and acceleration of
/// a time-dependent position vector ( x(t), y(t), z(t) ),
/// in which case AXDEF would be defined by
///
/// a = dx/dt
/// b = dy/dt
/// c = dz/dt
///
/// 2 2
/// da/dt = d x / dt
///
/// 2 2
/// db/dt = d y / dt
///
/// 2 2
/// dc/dt = d z / dt
///
/// Below, we'll call the normalized (unit length) version
/// of
///
/// ( a, b, c )
///
/// the "direction" of AXDEF.
///
/// We call the frame relative to which AXDEF is specified
/// the "base frame." The input state PLNDEF must be
/// specified relative to the same base frame.
///
/// INDEXA is the index of the reference frame axis that is
/// parallel to the direction of AXDEF.
///
/// INDEXA Axis
/// ------ ----
/// 1 X
/// 2 Y
/// 3 Z
///
/// PLNDEF is a state vector defining (with AXDEF) a principal
/// plane of the reference frame. This vector consists
/// of three components followed by their derivatives with
/// respect to the independent variable `t' associated with
/// AXDEF, so PLNDEF is
///
/// ( e, f, g, de/dt, df/dt, dg/dt )
///
/// Below, we'll call the unitized version of
///
/// ( e, f, g )
///
/// the "direction" of PLNDEF.
///
/// The second axis of the principal plane containing the
/// direction vectors of AXDEF and PLNDEF is perpendicular
/// to the first axis and has positive dot product with
/// the direction vector of PLNDEF.
///
/// The first three components of PLNDEF must have the
/// same units, and the units of the last three components
/// must be compatible with those of the first three: if
/// the first three components of PLNDEF
///
/// ( e, f, g )
///
/// have units U2 and `t' has units T, then the units of
/// PLNDEF normally would be
///
/// ( U2, U2, U2, U2/T, U2/T, U2/T )
///
/// Note that ***for meaningful results, the angular
/// velocities defined by AXDEF and PLNDEF must both have
/// units of 1/T.***
///
/// As with AXDEF, scaling PLNDEF doesn't affect the
/// output of this routine.
///
/// AXDEF and PLNDEF must be specified relative to a
/// common reference frame, which we call the "base
/// frame."
///
/// INDEXP is the index of second axis of the principal frame
/// determined by AXDEF and PLNDEF. The association of
/// integer values and axes is the same as for INDEXA.
/// ```
///
/// # Detailed Output
///
/// ```text
/// XFORM is the 6x6 matrix that transforms states from the
/// frame relative to which AXDEF and PLNDEF are specified
/// (the "base frame") to the frame whose axes and
/// derivative are determined by AXDEF, PLNDEF, INDEXA and
/// INDEXP.
///
/// The matrix XFORM has the structure shown below:
///
/// .- -.
/// | : |
/// | R : 0 |
/// | : |
/// | .......:.......|
/// | : |
/// | dR/dt : R |
/// | : |
/// `- -'
///
/// where R is a rotation matrix that is a function of
/// the independent variable associated with AXDEF and
/// PLNDEF, and where dR/dt is the derivative of R
/// with respect to that independent variable.
/// ```
///
/// # Exceptions
///
/// ```text
/// 1) If INDEXA or INDEXP is not in the set {1,2,3}, the error
/// SPICE(BADINDEX) is signaled.
///
/// 2) If INDEXA and INDEXP are the same, the error
/// SPICE(UNDEFINEDFRAME) is signaled.
///
/// 3) If the cross product of the vectors AXDEF and PLNDEF is zero,
/// the error SPICE(DEPENDENTVECTORS) is signaled.
/// ```
///
/// # Particulars
///
/// ```text
/// Given two linearly independent state vectors AXDEF and PLNDEF,
/// define vectors DIR1 and DIR2 by
///
/// DIR1 = ( AXDEF(1), AXDEF(2), AXDEF(3) )
/// DIR2 = ( PLNDEF(1), PLNDEF(2), PLNDEF(3) )
///
/// Then there is a unique right-handed reference frame F having:
///
/// DIR1 lying along the INDEXA axis.
///
/// DIR2 lying in the INDEXA-INDEXP coordinate plane, such that
/// the dot product of DIR2 with the positive INDEXP axis is
/// positive.
///
/// This routine determines the 6x6 matrix that transforms states
/// from the base frame used to represent the input vectors to the
/// the frame F determined by AXDEF and PLNDEF. Thus a state vector
///
/// S = ( x, y, z, dx/dt, dy/dt, dz/dt )
/// base
///
/// in the input reference frame will be transformed to
///
/// S = XFORM * S
/// F base
///
/// in the frame F determined by AXDEF and PLNDEF.
/// ```
///
/// # Examples
///
/// ```text
/// The numerical results shown for this example 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) The time-dependent Sun-Canopus reference frame associated with
/// a spacecraft uses the spacecraft-sun state to define the Z axis
/// and the Canopus direction to define the X-Z plane.
///
/// Find the apparent position of the Earth as seen from the Mars
/// Reconnaissance Orbiter spacecraft (MRO) at a specified time,
/// relative to the Sun-Canopus reference frame associated with
/// MRO.
///
/// Use the meta-kernel shown below to load the required SPICE
/// kernels.
///
///
/// KPL/MK
///
/// File: twovxf_ex1.tm
///
/// This meta-kernel is intended to support operation of SPICE
/// example programs. The kernels shown here should not be
/// assumed to contain adequate or correct versions of data
/// required by SPICE-based user applications.
///
/// In order for an application to use this meta-kernel, the
/// kernels referenced here must be present in the user's
/// current working directory.
///
/// The names and contents of the kernels referenced
/// by this meta-kernel are as follows:
///
/// File name Contents
/// --------- --------
/// naif0012.tls Leapseconds
/// de430.bsp Planetary ephemeris
/// mro_psp4_ssd_mro95a.bsp MRO ephemeris
///
/// \begindata
///
/// KERNELS_TO_LOAD = ( 'naif0012.tls',
/// 'de430.bsp',
/// 'mro_psp4_ssd_mro95a.bsp' )
///
/// \begintext
///
/// End of meta-kernel
///
///
/// Example code begins here.
///
///
/// PROGRAM TWOVXF_EX1
/// IMPLICIT NONE
///
/// C
/// C SPICELIB functions
/// C
/// DOUBLE PRECISION RPD
/// DOUBLE PRECISION JYEAR
///
/// C
/// C Local parameters
/// C
/// CHARACTER*(*) META
/// PARAMETER ( META = 'twovxf_ex1.tm' )
///
/// C
/// C Define the Right Ascension and Declination, and the
/// C proper motion in both coordinates, of Canopus, relative
/// C to the J2000 frame at J2000 epoch, in degrees and
/// C arcsecond/yr respectively. Note that the values used here
/// C may not be suitable for real applications.
/// C
/// DOUBLE PRECISION RAJ2K
/// PARAMETER ( RAJ2K = 90.3991968556D0 )
///
/// DOUBLE PRECISION DECJ2K
/// PARAMETER ( DECJ2K = -52.6956610556D0 )
///
/// DOUBLE PRECISION PMRA
/// PARAMETER ( PMRA = 19.93D-3 )
///
/// DOUBLE PRECISION PMDEC
/// PARAMETER ( PMDEC = 23.24D-3 )
///
/// C
/// C Local variables
/// C
/// DOUBLE PRECISION CANREC ( 3 )
/// DOUBLE PRECISION DEC
/// DOUBLE PRECISION ET
/// DOUBLE PRECISION LT
/// DOUBLE PRECISION PCANO ( 3 )
/// DOUBLE PRECISION RA
/// DOUBLE PRECISION RPMRA
/// DOUBLE PRECISION RPMDEC
/// DOUBLE PRECISION STATE ( 6 )
/// DOUBLE PRECISION STCANO ( 6 )
/// DOUBLE PRECISION STERTH ( 6 )
/// DOUBLE PRECISION STSUN ( 6 )
/// DOUBLE PRECISION XFISC ( 6, 6 )
/// DOUBLE PRECISION XFORM ( 3, 3 )
///
/// INTEGER I
///
/// C
/// C Load kernel files via the meta-kernel.
/// C
/// CALL FURNSH ( META )
///
/// C
/// C Convert the TDB input time string to seconds past
/// C J2000, TDB.
/// C
/// CALL STR2ET ( '2007 SEP 30 00:00:00 TDB', ET )
///
/// C
/// C Define an approximate "state vector" for Canopus using
/// C the J2000-relative, unit direction vector toward Canopus
/// C at a specified time ET (time is needed to compute proper
/// C motion) as position and the zero vector as velocity.
/// C
/// CALL CONVRT ( PMRA, 'ARCSECONDS', 'RADIANS', RPMRA )
/// CALL CONVRT ( PMDEC, 'ARCSECONDS', 'RADIANS', RPMDEC )
///
/// RA = RAJ2K * RPD() + RPMRA * ET/JYEAR()
/// DEC = DECJ2K * RPD() + RPMDEC * ET/JYEAR()
///
/// CALL RADREC ( 1.D0, RA, DEC, PCANO )
///
/// C
/// C Compute MRO geometric velocity w.r.t. the Solar System
/// C Barycenter, and use it to correct the Canopus direction
/// C for stellar aberration.
/// C
/// CALL SPKEZR ( 'MRO', ET, 'J2000', 'NONE',
/// . 'SSB', STATE, LT )
///
/// CALL STELAB ( PCANO, STATE(4), STCANO )
///
/// CALL VPACK ( 0.D0, 0.D0, 0.D0, STCANO(4) )
///
/// C
/// C Let STSUN be the J2000-relative apparent state of the Sun
/// C relative to the spacecraft at ET.
/// C
/// CALL SPKEZR ( 'SUN', ET, 'J2000', 'CN+S',
/// . 'MRO', STSUN, LT )
///
/// C
/// C The matrix XFISC transforms states from J2000 frame
/// C to the Sun-Canopus reference frame at ET.
/// C
/// CALL TWOVXF ( STSUN, 3, STCANO, 1, XFISC )
///
/// C
/// C Compute the apparent state of the Earth as seen from MRO
/// C in the J2000 frame at ET and transform that vector into
/// C the Sun-Canopus reference frame.
/// C
/// CALL SPKEZR ( 'EARTH', ET, 'J2000', 'CN+S',
/// . 'MRO', STATE, LT )
///
/// CALL MXVG ( XFISC, STATE, 6, 6, STERTH )
///
/// C
/// C Display the results.
/// C
/// WRITE(*,'(A)') 'Earth as seen from MRO in Sun-Canopus '
/// . // 'frame (km and km/s):'
/// WRITE(*,'(A,3F16.3)') ' position:',
/// . ( STERTH(I), I=1,3 )
/// WRITE(*,'(A,3F16.3)') ' velocity:',
/// . ( STERTH(I), I=4,6 )
///
/// END
///
///
/// When this program was executed on a Mac/Intel/gfortran/64-bit
/// platform, the output was:
///
///
/// Earth as seen from MRO in Sun-Canopus frame (km and km/s):
/// position: -16659764.322 97343706.915 106745539.738
/// velocity: 2.691 -10.345 -7.877
/// ```
///
/// # Author and Institution
///
/// ```text
/// N.J. Bachman (JPL)
/// J. Diaz del Rio (ODC Space)
/// W.M. Owen (JPL)
/// W.L. Taber (JPL)
/// ```
///
/// # Version
///
/// ```text
/// - SPICELIB Version 1.1.0, 03-SEP-2020 (JDR)
///
/// Added IMPLICIT NONE statement.
///
/// Edited the header to comply with NAIF standard. Added complete
/// code example, based on existing fragment.
///
/// - SPICELIB Version 1.0.0, 18-DEC-2004 (NJB) (WMO) (WLT)
/// ```
pub fn twovxf(
ctx: &mut SpiceContext,
axdef: &[f64; 6],
indexa: i32,
plndef: &[f64; 6],
indexp: i32,
xform: &mut [[f64; 6]; 6],
) -> crate::Result<()> {
TWOVXF(
axdef,
indexa,
plndef,
indexp,
xform.as_flattened_mut(),
ctx.raw_context(),
)?;
ctx.handle_errors()?;
Ok(())
}
//$Procedure TWOVXF ( Two states defining a frame transformation )
pub fn TWOVXF(
AXDEF: &[f64],
INDEXA: i32,
PLNDEF: &[f64],
INDEXP: i32,
XFORM: &mut [f64],
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let AXDEF = DummyArray::new(AXDEF, 1..=6);
let PLNDEF = DummyArray::new(PLNDEF, 1..=6);
let mut XFORM = DummyArrayMut2D::new(XFORM, 1..=6, 1..=6);
let mut XI = StackArray2D::<f64, 36>::new(1..=6, 1..=6);
//
// SPICELIB functions
//
//
// Local Variables
//
//
// Standard SPICE error handling
//
if RETURN(ctx) {
return Ok(());
}
CHKIN(b"TWOVXF", ctx)?;
//
// Get the matrix XI that transforms states from the frame
// defined by AXDEF and PLNDEF to their base frame.
//
ZZTWOVXF(
AXDEF.as_slice(),
INDEXA,
PLNDEF.as_slice(),
INDEXP,
XI.as_slice_mut(),
ctx,
)?;
//
// Invert XI.
//
INVSTM(XI.as_slice(), XFORM.as_slice_mut(), ctx)?;
CHKOUT(b"TWOVXF", ctx)?;
Ok(())
}