      PROGRAM vector                        ! illustrate use of arrays
      IMPLICIT NONE
      REAL*8 a(3), b(3)
      CALL initial(a,b)
      CALL dot(a,b)
      CALL cross(a,b)
      END
C
      SUBROUTINE initial(a,b)
      IMPLICIT NONE
      REAL*8 a(3), b(3)
      a(1) = 2
      a(2) = -3
      a(3) = -4
      b(1) = 6
      b(2) = 5
      b(3) = 1
      END
C
      SUBROUTINE dot(a,b)
      IMPLICIT NONE
      REAL*8 dot_product, a(3), b(3)
      INTEGER i
      dot_product = 0
      DO i = 1, 3
         dot_product = dot_product + a(i)*b(i)
      END DO
      WRITE(*,*) 'scalar product = ', dot_product
      END
C
      SUBROUTINE cross(r,s)
*     arrays can be defined in main program or subroutine
*     note use of dummy variables
      IMPLICIT NONE
      REAL*8 cross_product(3), r(3), s(3)
      INTEGER component, i, j
      DO component = 1, 3
         i = mod(component,3) + 1
         j = mod(i,3) + 1
         cross_product(component) = r(i)*s(j) - s(i)*r(j)
      END DO
      WRITE(*,*)
      WRITE(*,*) 'three components of the vector product:'
      WRITE(*,*) '           x            y            z '
      DO component = 1, 3
         WRITE(*,'(1X,F12.6,$)') cross_product(component)
      END DO
      END
