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
//
// GENERATED FILE
//
use super::*;
use f2rust_std::*;
pub const MAXDEG: i32 = 35;
struct SaveVars {
MINV: ActualArray2D<f64>,
PRVDEG: i32,
}
impl SaveInit for SaveVars {
fn new() -> Self {
let mut MINV = ActualArray2D::<f64>::new(1..=MAXDEG, 1..=MAXDEG);
let mut PRVDEG: i32 = 0;
PRVDEG = -1;
Self { MINV, PRVDEG }
}
}
//$Procedure T_PD2DT ( Polynomial derivatives to difference table )
pub fn T_PD2DT(
DEGP: i32,
PDERIV: &mut [f64],
WORK: &mut [f64],
DIFTAB: &mut [f64],
ctx: &mut Context,
) {
let save = ctx.get_vars::<SaveVars>();
let save = &mut *save.borrow_mut();
let mut PDERIV = DummyArrayMut::new(PDERIV, 0..=DEGP);
let mut WORK = DummyArrayMut2D::new(WORK, 0..=(DEGP - 1), 0..=(DEGP - 1));
let mut DIFTAB = DummyArrayMut::new(DIFTAB, 0..=DEGP);
let mut FACT: f64 = 0.0;
let mut DEGPSQ: i32 = 0;
let mut SIGN: i32 = 0;
let mut USEMNV: bool = false;
//
//
// Non-SPICELIB functions
//
//
// Local variables
//
//
// Saved variables
//
//
// Initial values
//
//
// The first element of the difference table is just the
// constant term from the polynomial.
//
DIFTAB[0] = PDERIV[0];
//
// Use the work space array to build the mystery matrix
//
// -1
// M
//
//
// The (j,k) entry of the mystery matrix is
//
//
// k-j
// (-1) * ( <k choose j> )
//
//
// for k >= j. The lower triangular portion of the matrix is
// identically zero.
//
if ((DEGP == save.PRVDEG) && (DEGP <= MAXDEG)) {
//
// We can use the previously computed matrix MINV.
//
USEMNV = true;
} else {
DEGPSQ = (DEGP * DEGP);
spicelib::CLEARD(DEGPSQ, WORK.as_slice_mut());
for J in 0..=(DEGP - 1) {
SIGN = 1;
for K in J..=(DEGP - 1) {
WORK[[J, K]] = (SIGN * T_CHOOSE(K, J)) as f64;
SIGN = -SIGN;
}
}
if (DEGP <= MAXDEG) {
spicelib::MOVED(WORK.as_slice(), DEGPSQ, save.MINV.as_slice_mut());
}
USEMNV = false;
}
//
// Divide the jth element of PDERIV by j!.
//
FACT = 1 as f64;
for J in 1..=DEGP {
FACT = ((J as f64) * FACT);
PDERIV[J] = (PDERIV[J] / FACT);
}
//
// Now left-multiply our vector of polynomial derivatives by
// the mystery matrix.
//
if USEMNV {
spicelib::MXVG(
save.MINV.as_slice(),
PDERIV.subarray(1),
DEGP,
DEGP,
DIFTAB.subarray_mut(1),
);
} else {
spicelib::MXVG(
WORK.as_slice(),
PDERIV.subarray(1),
DEGP,
DEGP,
DIFTAB.subarray_mut(1),
);
}
save.PRVDEG = DEGP;
}