program sample_avr
! 2008.5.15   by I. Tamagawa

 implicit none

 integer, parameter :: n=24
 integer            :: hour(n)
 real               :: pres(n), temp(n), rh(n), u(n)
 real               :: pres_m, temp_m, rh_m, u_m

 integer            :: i


open(unit=10, file='SampleData.txt')

 do i=1, n
   read(10,*) hour(i),pres(i), temp(i), rh(i), u(i)
  end do
 
close(10)
write(*,*) 'Read finished'

 call average( pres, n, pres_m )
 call average( temp, n, temp_m )
 call average( rh, n, rh_m )
 call average( u, n, u_m )

 write(*,*) 'Averages', pres_m, temp_m, rh_m, u_m
end


subroutine average( x, n, xm )
 real :: x(n)
 integer :: n
 real :: xm
 double precision :: sum
 integer :: i
 sum =0
 do i=1, n
  sum = sum + x(i)
 end do
 xm = sum/n
 return
end
