! This file: ! http://ftp.aset.psu.edu/pub/ger/fortran/hdk/MatrixMultOperator.f90 ! ! Example of how to create an operator using Fortran 90/95 ! In this case .x. will be a matrix multiplication operator. ! ! by Michael Metcalf as posted at comp.lang.fortran ! with the function my_matmul rewritten by Jos R Bergervoet. ! module mxmult interface operator(.x.) module procedure my_matmul end interface contains function my_matmul(x, y) real, dimension(:, :), intent(in) :: x, y real, dimension(size(x,1), size(y,2)) :: my_matmul my_matmul = matmul(x, y) ! matmul is F90 Intrinsic Procedure. end function end module program mxmdemo ! Demonstrate with a simple example use mxmult REAL , dimension(3,3) :: A,B,C,D,E ! Initialize right-hand matrices to constant values. A= 1. ; b=2. ; c = 3. ; E = 4. D=(A.x.B.x.C)+E do I=1,3 print *, (D(I,J),J=1,3) end do ! Value of all elements of D are: 58.0 end