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
//
// GENERATED FILE
//
use super::*;
use f2rust_std::*;
struct SaveVars {
SEQNCE: StackArray<i32, 5>,
}
impl SaveInit for SaveVars {
fn new() -> Self {
let mut SEQNCE = StackArray::<i32, 5>::new(1..=5);
{
use f2rust_std::data::Val;
let mut clist = [Val::I(1), Val::I(2), Val::I(3), Val::I(1), Val::I(2)].into_iter();
SEQNCE
.iter_mut()
.for_each(|n| *n = clist.next().unwrap().into_i32());
debug_assert!(clist.next().is_none(), "DATA not fully initialised");
}
Self { SEQNCE }
}
}
//$Procedure ZZTWOVXF ( Two states defining a frame transformation )
pub fn ZZTWOVXF(
AXDEF: &[f64],
INDEXA: i32,
PLNDEF: &[f64],
INDEXP: i32,
XFORM: &mut [f64],
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let save = ctx.get_vars::<SaveVars>();
let save = &mut *save.borrow_mut();
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 TMPSTA = StackArray::<f64, 6>::new(1..=6);
let mut I1: i32 = 0;
let mut I2: i32 = 0;
let mut I3: i32 = 0;
//
// SPICELIB functions
//
//
// Local Variables
//
//
// Saved variables
//
//
// Initial values
//
//
// Standard SPICE error handling
//
if RETURN(ctx) {
return Ok(());
}
CHKIN(b"ZZTWOVXF", ctx)?;
//
// Check for obvious bad inputs.
//
if ((intrinsics::MAX0(&[INDEXP, INDEXA]) > 3) || (intrinsics::MIN0(&[INDEXP, INDEXA]) < 1)) {
SETMSG(b"The definition indices must lie in the range from 1 to 3. The value of INDEXA was #. The value of INDEXP was #. ", ctx);
ERRINT(b"#", INDEXA, ctx);
ERRINT(b"#", INDEXP, ctx);
SIGERR(b"SPICE(BADINDEX)", ctx)?;
CHKOUT(b"ZZTWOVXF", ctx)?;
return Ok(());
} else if (INDEXA == INDEXP) {
SETMSG(b"The values of INDEXA and INDEXP were the same, namely #. They are required to be different.", ctx);
ERRINT(b"#", INDEXA, ctx);
SIGERR(b"SPICE(UNDEFINEDFRAME)", ctx)?;
CHKOUT(b"ZZTWOVXF", ctx)?;
return Ok(());
}
//
// Get indices for right-handed axes:
//
// First AXDEF ...
//
I1 = INDEXA;
//
// ... then the other two.
//
I2 = save.SEQNCE[(INDEXA + 1)];
I3 = save.SEQNCE[(INDEXA + 2)];
//
// Column I1 of XFORM contains a unit vector parallel to AXDEF and
// the derivative of the unit vector.
//
DVHAT(AXDEF.as_slice(), XFORM.subarray_mut([1, I1]));
//
// Obtain columns I2 and I3 of XFORM using cross products.
// Which order to use depends on whether INDEXP = I2 (next axis in
// right-handed order) or INDEXP = I3 (previous axis in right-handed
// order).
//
// Select column indices...
//
if (INDEXP == I2) {
//
// We compute the third axis in the sequence, then the second.
//
DUCRSS(
AXDEF.as_slice(),
PLNDEF.as_slice(),
XFORM.subarray_mut([1, I3]),
);
DUCRSS(
XFORM.subarray([1, I3]),
AXDEF.as_slice(),
TMPSTA.as_slice_mut(),
);
MOVED(TMPSTA.as_slice(), 6, XFORM.subarray_mut([1, I2]));
} else {
DUCRSS(
PLNDEF.as_slice(),
AXDEF.as_slice(),
XFORM.subarray_mut([1, I2]),
);
DUCRSS(
AXDEF.as_slice(),
XFORM.subarray([1, I2]),
TMPSTA.as_slice_mut(),
);
MOVED(TMPSTA.as_slice(), 6, XFORM.subarray_mut([1, I3]));
}
//
// ...and compute the output frame's non-principal unit basis
// vectors and the derivatives of these vectors.
//
//
// At this point, we've filled in the left half of XFORM.
//
// The upper right block is the 3x3 zero matrix.
// The lower right block matches the upper left block.
//
CLEARD(3, XFORM.subarray_mut([1, 4]));
CLEARD(3, XFORM.subarray_mut([1, 5]));
CLEARD(3, XFORM.subarray_mut([1, 6]));
for J in 1..=3 {
for I in 1..=3 {
XFORM[[(3 + I), (3 + J)]] = XFORM[[I, J]];
}
}
//
// Finally, check to see that we actually got something non-zero in
// the first three components of at least one of the columns
// XFORM(1,I2) and XFORM(1,I3) (we need only check one of them since
// they are related by a cross product).
//
if VZERO(XFORM.subarray([1, I2])) {
SETMSG(b"The direction vectors associated with states AXDEF and PLNDEF are linearly dependent.", ctx);
SIGERR(b"SPICE(DEPENDENTVECTORS)", ctx)?;
CHKOUT(b"ZZTWOVXF", ctx)?;
return Ok(());
}
CHKOUT(b"ZZTWOVXF", ctx)?;
Ok(())
}