!//////////////////////////////////////////////////////////////
!//
!// mean.f90
!//
!// Program to calculate the mean value from
!// a data set
!//
!//////////////////////////////////////////////////////////////

PROGRAM mean
  !// Prevent implicit declarations of vatriables
  IMPLICIT NONE
  !// Variable declarations
  !// A constant value (length of array)
  INTEGER, PARAMETER                       :: N = 10
  !// An array of real values N items long
  REAL,DIMENSION(N)                        :: array
  !// A help variable
  REAL                                     :: s
  !// the mean value of the array
  REAL                                     :: X_M
  !// An index variable
  INTEGER                                  :: i
  !// Initialize the array with values from 1 to 10
  array = (/1.,2.,3.,4.,5.,6.,7.,8.,9.,10./)
  !// Set the variable s to zero. Note the . after the 0
  !// This tells the compiler that this is a floating point
  !// value and not an integer
  s = 0.
  !// Loop through all elements in the array
  DO i = 1, N
    !// Sum up the value of all the elements
    s = s + array(i)
  END DO
  !// Calculate the mean value of the array
  X_M = s/N
  !// Display the mean value on the screen
  PRINT *, X_M
END PROGRAM mean