next up previous contents
Next: Encapsulation Up: Vector Multiplication - Array Previous: Vector Multiplication - Array

Solution

    PROGRAM Test_Outer
     IMPLICIT NONE
     INTERFACE
      FUNCTION Outer(A,B)
       REAL, INTENT(IN), DIMENSION(:) :: A, B
       REAL, DIMENSION(SIZE(A),SIZE(B)) :: Outer
      END FUNCTION Outer
     END INTERFACE
     REAL, ALLOCATABLE, DIMENSION(:) :: A
     REAL, ALLOCATABLE, DIMENSION(:) :: B
     INTEGER N_elts, istat
    
      PRINT*, "Type in size of A vector"
      READ*, N_elts
      ALLOCATE(A(N_elts), STAT=istat)
      IF (istat .NE. 0) THEN
       PRINT*, "Allocation Error"
       STOP
      END IF
    
      PRINT*, "Type in size of B vector"
      READ*, N_elts
      ALLOCATE(B(N_elts), STAT=istat)
      IF (istat .NE. 0) THEN
       PRINT*, "Allocation Error"
       STOP
      END IF
    
      CALL RANDOM_NUMBER(A)
      CALL RANDOM_NUMBER(B)
     
      PRINT*, "Outer product of A and B is:"
      PRINT*, Outer(A,B)
     
      DEALLOCATE(A)
      DEALLOCATE(B)
    
    END PROGRAM Test_Outer
    
    FUNCTION Outer(A,B)
     IMPLICIT NONE
     REAL, INTENT(IN), DIMENSION(:) :: A, B
     REAL, DIMENSION(SIZE(A),SIZE(B)) :: Outer
     INTEGER i,j
    
      DO i = 1, SIZE(A)
       DO j = 1, SIZE(B)
        Outer(i,j) = A(i) * B(j)
       END DO
      END DO
    END FUNCTION Outer


next up previous contents
Next: Encapsulation Up: Vector Multiplication - Array Previous: Vector Multiplication - Array

Adam Marshall ©University of Liverpool, 1996
Fri Dec 6 14:10:26 GMT 1996