! PROGRAM P73 ! ! IMPLICIT NONE REAL :: M1(3,4),M2(4,2),M3(3,2) ! INTERFACE SUBROUTINE MATSIN(M1,M2,I1,J1,I2,J2) IMPLICIT NONE REAL, INTENT(IN OUT) :: M1(:,:),M2(:,:) INTEGER, INTENT(IN) :: J1,J2,I1,I2 END SUBROUTINE MATSIN END INTERFACE ! INTERFACE SUBROUTINE MULT(M1,M2,M3,I1,J1,J2) IMPLICIT NONE REAL, INTENT(IN OUT) :: M1(:,:),M2(:,:),M3(:,:) INTEGER, INTENT(IN) :: I1,J1,J2 END SUBROUTINE MULT END INTERFACE ! INTERFACE SUBROUTINE PRNMAT(M3,IMAX,JMAX) IMPLICIT NONE REAL, INTENT(IN OUT) :: M3(:,:) INTEGER, INTENT(IN) :: IMAX,JMAX END SUBROUTINE PRNMAT END INTERFACE ! PRINT *,'This is Program P73 - Matrix multiplication' PRINT *,'PROGRAM IS READING DATA INTO ARRAYS' CALL MATSIN(M1,M2,3,4,4,2) CALL PRNMAT(M1,3,4) CALL PRNMAT(M2,4,2) PRINT *,'NOW MULTIPLYING MATRICES' CALL MULT(M1,M2,M3,3,4,2) PRINT *,'SOLUTION:' CALL PRNMAT(M3,3,2) STOP END PROGRAM P73 ! SUBROUTINE MATSIN(M1,M2,I1,J1,I2,J2) ! IMPLICIT NONE REAL, INTENT(IN OUT) :: M1(:,:),M2(:,:) INTEGER, INTENT(IN) :: J1,J2,I1,I2 INTEGER :: I,J ! ! READ IN M1 ! ONE PER CARD ! L1: DO I=1,I1 READ *,(M1(I,J),J=1,J1) END DO L1 ! ! READ IN M2 ! ONE ROW/CARD ! LOOP: DO I=1,I2 READ *,(M2(I,J),J=1,J2) END DO LOOP RETURN END SUBROUTINE MATSIN ! ! ! SUBROUTINE MULT(M1,M2,M3,I1,J1,J2) ! IMPLICIT NONE REAL, INTENT(IN OUT) :: M1(:,:),M2(:,:),M3(:,:) INTEGER, INTENT(IN) :: J1,J2,I1 INTEGER :: I,J,K ! ! Now, we will multiply the two matrices ! ! M3=0.0 DO K=1,J2 DO I=1,J1 DO J=1,I1 M3(J,K) = M3(J,K) + M1(J,I) * M2(I,K) END DO END DO END DO RETURN END SUBROUTINE MULT ! ! ! SUBROUTINE PRNMAT(M3,IMAX,JMAX) ! IMPLICIT NONE REAL, INTENT(IN OUT) :: M3(:,:) INTEGER, INTENT(IN) :: IMAX,JMAX INTEGER :: I,J ! ! L3: DO I=1,IMAX PRINT *,(M3(I,J),J=1,JMAX) END DO L3 PRINT *,' ' ! RETURN END SUBROUTINE PRNMAT