!! Barlow and Barnett, Computing for Scientists 1998
!! page 104                  C++ and Fortran 90
! altered by Jim Crumley to add INTENT statements

! simple program showing an example of subroutines

PROGRAM analysis

  REAL , DIMENSION(10) :: data
  REAL , EXTERNAL :: mean
  CALL get_data(data , 10)
  PRINT * ,'Average ', mean(data , 10)
  STOP ' normal exit : analysis '
END PROGRAM analysis

SUBROUTINE get_data(dat , n)
  INTEGER :: j 
  INTEGER, INTENT(IN) ::  n
  REAL, INTENT(OUT), DIMENSION(n) :: dat
  DO j = 1 , n
    READ * , dat(j)
  ENDDO
  RETURN
END SUBROUTINE get_data

REAL FUNCTION mean(a , m)
  INTEGER, INTENT(IN) :: m
  REAL, INTENT(IN), DIMENSION(:) :: a
  REAL :: sum=0.0
  DO j = 1 , m
    sum = sum + a(j)
  ENDDO
  mean = sum / REAL(m)
  RETURN
END FUNCTION mean


