rsspice/generated/spicelib/mxm.rs
1//
2// GENERATED FILE
3//
4
5use super::*;
6use crate::SpiceContext;
7use f2rust_std::*;
8
9/// Matrix times matrix, 3x3
10///
11/// Multiply two 3x3 matrices.
12///
13/// # Brief I/O
14///
15/// ```text
16///  VARIABLE  I/O  DESCRIPTION
17///  --------  ---  --------------------------------------------------
18///  M1         I   3x3 double precision matrix.
19///  M2         I   3x3 double precision matrix.
20///  MOUT       O   The 3x3 double precision matrix product M1*M2.
21/// ```
22///
23/// # Detailed Input
24///
25/// ```text
26///  M1       is an arbitrary 3x3 double precision matrix.
27///
28///  M2       is an arbitrary 3x3 double precision matrix.
29/// ```
30///
31/// # Detailed Output
32///
33/// ```text
34///  MOUT     is a 3x3 double precision matrix. MOUT is the product
35///           M1*M2.
36/// ```
37///
38/// # Exceptions
39///
40/// ```text
41///  Error free.
42/// ```
43///
44/// # Particulars
45///
46/// ```text
47///  The code reflects precisely the following mathematical expression
48///
49///     For each value of the subscripts I and J from 1 to 3:
50///
51///                       3
52///                    .-----
53///                     \
54///        MOUT(I,J) =   )  M1(I,K) * M2(K,J)
55///                     /
56///                    '-----
57///                      K=1
58/// ```
59///
60/// # Examples
61///
62/// ```text
63///  The numerical results shown for this example may differ across
64///  platforms. The results depend on the SPICE kernels used as
65///  input, the compiler and supporting libraries, and the machine
66///  specific arithmetic implementation.
67///
68///  1) Given two 3x3 double precision matrices, compute their
69///     product.
70///
71///
72///     Example code begins here.
73///
74///
75///           PROGRAM MXM_EX1
76///           IMPLICIT NONE
77///
78///     C
79///     C     Local variables.
80///     C
81///           DOUBLE PRECISION      M1   ( 3, 3 )
82///           DOUBLE PRECISION      M2   ( 3, 3 )
83///           DOUBLE PRECISION      MOUT ( 3, 3 )
84///
85///           INTEGER               I
86///           INTEGER               J
87///
88///     C
89///     C     Define M1 and M2.
90///     C
91///           DATA                  M1   /  1.0D0, -1.0D0,  0.0D0,
92///          .                              1.0D0,  1.0D0,  0.0D0,
93///          .                              0.0D0,  0.0D0,  1.0D0  /
94///
95///           DATA                  M2   /  1.0D0,  0.0D0,  0.0D0,
96///          .                              0.0D0,  1.0D0, -1.0D0,
97///          .                              0.0D0,  1.0D0,  1.0D0  /
98///
99///     C
100///     C     Compute M1 times M2.
101///     C
102///           CALL MXM ( M1, M2, MOUT )
103///
104///           WRITE(*,'(A)') 'M1:'
105///           DO I=1, 3
106///
107///              WRITE(*,'(3F16.7)') ( M1(I,J), J=1,3 )
108///
109///           END DO
110///
111///           WRITE(*,*)
112///           WRITE(*,'(A)') 'M2:'
113///           DO I=1, 3
114///
115///              WRITE(*,'(3F16.7)') ( M2(I,J), J=1,3 )
116///
117///           END DO
118///
119///           WRITE(*,*)
120///           WRITE(*,'(A)') 'M1 times M2:'
121///           DO I=1, 3
122///
123///              WRITE(*,'(3F16.7)') ( MOUT(I,J), J=1,3 )
124///
125///           END DO
126///
127///           END
128///
129///
130///     When this program was executed on a Mac/Intel/gfortran/64-bit
131///     platform, the output was:
132///
133///
134///     M1:
135///            1.0000000       1.0000000       0.0000000
136///           -1.0000000       1.0000000       0.0000000
137///            0.0000000       0.0000000       1.0000000
138///
139///     M2:
140///            1.0000000       0.0000000       0.0000000
141///            0.0000000       1.0000000       1.0000000
142///            0.0000000      -1.0000000       1.0000000
143///
144///     M1 times M2:
145///            1.0000000       1.0000000       1.0000000
146///           -1.0000000       1.0000000       1.0000000
147///            0.0000000      -1.0000000       1.0000000
148/// ```
149///
150/// # Author and Institution
151///
152/// ```text
153///  N.J. Bachman       (JPL)
154///  J. Diaz del Rio    (ODC Space)
155///  W.M. Owen          (JPL)
156///  W.L. Taber         (JPL)
157/// ```
158///
159/// # Version
160///
161/// ```text
162/// -    SPICELIB Version 1.1.0, 06-JUL-2021 (JDR)
163///
164///         Added IMPLICIT NONE statement.
165///
166///         Edited the header to comply with NAIF standard. Added complete
167///         code example based on existing example.
168///
169/// -    SPICELIB Version 1.0.2, 22-APR-2010 (NJB)
170///
171///         Header correction: assertions that the output
172///         can overwrite the input have been removed.
173///
174/// -    SPICELIB Version 1.0.1, 10-MAR-1992 (WLT)
175///
176///         Comment section for permuted index source lines was added
177///         following the header.
178///
179/// -    SPICELIB Version 1.0.0, 31-JAN-1990 (WMO)
180/// ```
181pub fn mxm(m1: &[[f64; 3]; 3], m2: &[[f64; 3]; 3], mout: &mut [[f64; 3]; 3]) {
182    MXM(
183        m1.as_flattened(),
184        m2.as_flattened(),
185        mout.as_flattened_mut(),
186    );
187}
188
189//$Procedure MXM ( Matrix times matrix, 3x3 )
190pub fn MXM(M1: &[f64], M2: &[f64], MOUT: &mut [f64]) {
191    let M1 = DummyArray2D::new(M1, 1..=3, 1..=3);
192    let M2 = DummyArray2D::new(M2, 1..=3, 1..=3);
193    let mut MOUT = DummyArrayMut2D::new(MOUT, 1..=3, 1..=3);
194    let mut PRODM = StackArray2D::<f64, 9>::new(1..=3, 1..=3);
195
196    //
197    // Local variables
198    //
199
200    //
201    // Perform the matrix multiplication
202    //
203    for I in 1..=3 {
204        for J in 1..=3 {
205            PRODM[[I, J]] = (((M1[[I, 1]] * M2[[1, J]]) + (M1[[I, 2]] * M2[[2, J]]))
206                + (M1[[I, 3]] * M2[[3, J]]));
207        }
208    }
209    //
210    // Move the result into MOUT
211    //
212    MOVED(PRODM.as_slice(), 9, MOUT.as_slice_mut());
213}