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
//
// GENERATED FILE
//
use super::*;
use crate::SpiceContext;
use f2rust_std::*;
const CTRSIZ: i32 = 2;
const FRNMLN: i32 = 32;
struct SaveVars {
SVCTR1: StackArray<i32, 2>,
SVFROM: Vec<u8>,
SVFCOD: i32,
SVCTR2: StackArray<i32, 2>,
SVTO: Vec<u8>,
SVTCDE: i32,
FIRST: bool,
}
impl SaveInit for SaveVars {
fn new() -> Self {
let mut SVCTR1 = StackArray::<i32, 2>::new(1..=CTRSIZ);
let mut SVFROM = vec![b' '; FRNMLN as usize];
let mut SVFCOD: i32 = 0;
let mut SVCTR2 = StackArray::<i32, 2>::new(1..=CTRSIZ);
let mut SVTO = vec![b' '; FRNMLN as usize];
let mut SVTCDE: i32 = 0;
let mut FIRST: bool = false;
FIRST = true;
Self {
SVCTR1,
SVFROM,
SVFCOD,
SVCTR2,
SVTO,
SVTCDE,
FIRST,
}
}
}
/// Position Transformation Matrix
///
/// Return the matrix that transforms position vectors from one
/// specified frame to another at a specified epoch.
///
/// # Required Reading
///
/// * [FRAMES](crate::required_reading::frames)
///
/// # Brief I/O
///
/// ```text
/// VARIABLE I/O DESCRIPTION
/// -------- --- --------------------------------------------------
/// FROM I Name of the frame to transform from.
/// TO I Name of the frame to transform to.
/// ET I Epoch of the rotation matrix.
/// ROTATE O A rotation matrix.
/// ```
///
/// # Detailed Input
///
/// ```text
/// FROM is the name of a reference frame in which a position
/// vector is known.
///
/// TO is the name of a reference frame in which it is desired
/// to represent a position vector.
///
/// ET is the epoch in ephemeris seconds past the epoch of J2000
/// (TDB) at which the position transformation matrix ROTATE
/// should be evaluated.
/// ```
///
/// # Detailed Output
///
/// ```text
/// ROTATE is the matrix that transforms position vectors from
/// the reference frame FROM to the frame TO at epoch ET.
/// If (x, y, z) is a position relative to the frame FROM
/// then the vector ( x', y', z') is the same position
/// relative to the frame TO at epoch ET. Here the
/// vector ( x', y', z' ) is defined by the equation:
///
/// .- -. .- -. .- -.
/// | x' | | | | x |
/// | y' | = | ROTATE | | y |
/// | z' | | | | z |
/// `- -' `- -' `- -'
/// ```
///
/// # Exceptions
///
/// ```text
/// 1) If sufficient information has not been supplied via loaded
/// SPICE kernels to compute the transformation between the
/// two frames, an error is signaled by a routine
/// in the call tree of this routine.
///
/// 2) If either frame FROM or TO is not recognized, the error
/// SPICE(UNKNOWNFRAME) is signaled.
/// ```
///
/// # Particulars
///
/// ```text
/// This routine provides the user level interface to computing
/// position transformations from one reference frame to another.
///
/// Note that the reference frames may be inertial or non-inertial.
/// However, the user must take care that sufficient SPICE kernel
/// information is loaded to provide a complete position
/// transformation path from the FROM frame to the TO frame.
///
/// A common type of reference frame transformation is one from one
/// time-dependent frame to another, where the orientations of the
/// frames are computed at different epochs. For example, a remote
/// sensing application may compute the transformation from a target
/// body-fixed frame, with its orientation evaluated at the epoch of
/// photon emission, to a spacecraft instrument frame, with its
/// orientation evaluated at the epoch of photon reception. The
/// SPICELIB routine PXFRM2 computes this type of frame
/// transformation.
/// ```
///
/// # Examples
///
/// ```text
/// Suppose that you have geodetic coordinates of a station on the
/// surface of the earth and that you need the inertial (J2000)
/// position of this station. The following code fragment
/// illustrates how to transform the position of the station to a
/// J2000 position.
///
/// CALL BODVRD ( 'EARTH', RADII, 3, N, ABC )
///
/// EQUATR = ABC(1)
/// POLAR = ABC(3)
/// F = (EQUATR - POLAR) / EQUATR
///
/// CALL GEOREC ( LONG, LAT, 0.0D0, EQUATR, F, EPOS )
///
/// CALL PXFORM ( 'IAU_EARTH', 'J2000', ET, ROTATE )
/// CALL MXV ( ROTATE, EPOS, JPOS )
///
/// The position JPOS is the desired J2000 position of the station.
/// ```
///
/// # Author and Institution
///
/// ```text
/// C.H. Acton (JPL)
/// N.J. Bachman (JPL)
/// J. Diaz del Rio (ODC Space)
/// B.V. Semenov (JPL)
/// W.L. Taber (JPL)
/// ```
///
/// # Version
///
/// ```text
/// - SPICELIB Version 1.1.1, 09-AUG-2021 (NJB) (JDR)
///
/// Edited the header to comply with NAIF standard. Updated the
/// $Particulars header section to mention PXFRM2.
///
/// - SPICELIB Version 1.1.0, 23-SEP-2013 (BVS)
///
/// Updated to save the input frame names and POOL state counters
/// and to do frame name-ID conversions only if the counters have
/// changed.
///
/// - SPICELIB Version 1.0.3, 27-FEB-2008 (BVS)
///
/// Added FRAMES to the $Required_Reading section.
///
/// - SPICELIB Version 1.0.2, 23-OCT-2005 (NJB)
///
/// Header example had invalid flattening factor computation;
/// this was corrected. Reference to BODVAR in header was
/// replaced with reference to BODVRD.
///
/// - SPICELIB Version 1.0.1, 29-JUL-2003 (NJB) (CHA)
///
/// Various header corrections were made.
///
/// - SPICELIB Version 1.0.0, 05-APR-1999 (WLT)
/// ```
pub fn pxform(
ctx: &mut SpiceContext,
from: &str,
to: &str,
et: f64,
rotate: &mut [[f64; 3]; 3],
) -> crate::Result<()> {
PXFORM(
from.as_bytes(),
to.as_bytes(),
et,
rotate.as_flattened_mut(),
ctx.raw_context(),
)?;
ctx.handle_errors()?;
Ok(())
}
//$Procedure PXFORM ( Position Transformation Matrix )
pub fn PXFORM(
FROM: &[u8],
TO: &[u8],
ET: f64,
ROTATE: &mut [f64],
ctx: &mut Context,
) -> f2rust_std::Result<()> {
let save = ctx.get_vars::<SaveVars>();
let save = &mut *save.borrow_mut();
let mut ROTATE = DummyArrayMut2D::new(ROTATE, 1..=3, 1..=3);
let mut FCODE: i32 = 0;
let mut TCODE: i32 = 0;
//
// Spicelib Functions
//
//
// Local parameters.
//
//
// Saved frame name length.
//
//
// Local Variables.
//
//
// Saved frame name/ID item declarations.
//
//
// Saved frame name/ID items.
//
//
// Initial values.
//
//
// Standard SPICE error handling.
//
if RETURN(ctx) {
return Ok(());
}
CHKIN(b"PXFORM", ctx)?;
//
// Initialization.
//
if save.FIRST {
//
// Initialize counters.
//
ZZCTRUIN(save.SVCTR1.as_slice_mut(), ctx);
ZZCTRUIN(save.SVCTR2.as_slice_mut(), ctx);
save.FIRST = false;
}
ZZNAMFRM(
save.SVCTR1.as_slice_mut(),
&mut save.SVFROM,
&mut save.SVFCOD,
FROM,
&mut FCODE,
ctx,
)?;
ZZNAMFRM(
save.SVCTR2.as_slice_mut(),
&mut save.SVTO,
&mut save.SVTCDE,
TO,
&mut TCODE,
ctx,
)?;
//
// Only non-zero id-codes are legitimate frame id-codes. Zero
// indicates that the frame wasn't recognized.
//
if ((FCODE != 0) && (TCODE != 0)) {
REFCHG(FCODE, TCODE, ET, ROTATE.as_slice_mut(), ctx)?;
} else if ((FCODE == 0) && (TCODE == 0)) {
SETMSG(
b"Neither of the frames # or # was recognized as a known reference frame. ",
ctx,
);
ERRCH(b"#", FROM, ctx);
ERRCH(b"#", TO, ctx);
SIGERR(b"SPICE(UNKNOWNFRAME)", ctx)?;
} else if (FCODE == 0) {
SETMSG(
b"The frame # was not recognized as a known reference frame. ",
ctx,
);
ERRCH(b"#", FROM, ctx);
SIGERR(b"SPICE(UNKNOWNFRAME)", ctx)?;
} else if (TCODE == 0) {
SETMSG(
b"The frame # was not recognized as a known reference frame. ",
ctx,
);
ERRCH(b"#", TO, ctx);
SIGERR(b"SPICE(UNKNOWNFRAME)", ctx)?;
}
CHKOUT(b"PXFORM", ctx)?;
Ok(())
}