!     ------------------------------------------------------------------
!
!     second.f95
!
!
!     Created on Wed May 14 17:38:42 2008
!     Copyright (c) 2008 MyCompany. All rights reserved.
!
!
!     ------------------------------------------------------------------
	program StandardDev
! no dimension version with averaging 
	implicit none
	integer, parameter :: n=24
	integer	:: hour, i
	real		:: pr, te, rh, u
	real*8		:: pr_m, te_m, rh_m, u_m
 	real*8		:: pr_a, te_a, rh_a, u_a
	real*8		:: pr_bu, te_bu, rh_bu, u_bu
	real*8		:: pr_sd, te_sd, rh_sd, u_sd
	 
	pr_m = 0 ; te_m = 0 ; rh_m = 0 ; u_m = 0
	pr_a = 0 ; te_a = 0 ; rh_a = 0 ; u_a = 0
	pr_bu = 0 ; te_bu = 0 ; rh_bu = 0 ; u_bu = 0
	pr_sd = 0 ; te_sd = 0 ; rh_sd = 0 ; u_sd = 0
	
	open(unit=10, file='SampleData.txt')
	 do i=1, n
	 read(10,*) hour, pr, te, rh, u
	   pr_m = pr_m + pr
	   te_m = te_m + te
	   rh_m = rh_m + rh
 	    u_m =  u_m +  u
   	 end do

	close(10)
   	
	pr_a = pr_m / real(n)
	te_a = te_m / real(n)
	rh_a = rh_m / real(n)
	u_a  =  u_m / real(n)

!	calc breakup
	open(unit=20, file='SampleData.txt')
	 do i=1,n
	 read(20,*) hour, pr, te, rh, u
	      pr_bu = pr_bu + (pr - pr_a)**2
	      te_bu = te_bu + (te - te_a)**2
	      rh_bu = rh_bu + (rh - rh_a)**2
	       u_bu =  u_bu + ( u -  u_a)**2
	  end do
	  
	close(20)

	pr_sd = sqrt(pr_bu / (real(n-1)))
	te_sd = sqrt(te_bu / (real(n-1)))
	rh_sd = sqrt(rh_bu / (real(n-1)))
	 u_sd = sqrt( u_bu / (real(n-1)))

	write(*,'(1x,a25,f10.5,a25,f10.5)') 'air pressure: ave = ', pr_a,' standard deviation = ', pr_sd
	write(*,'(1x,a25,f10.5,a25,f10.5)') 'temperature: ave = ', te_a,' standard deviation = ', te_sd
	write(*,'(1x,a25,f10.5,a25,f10.5)') 'relative humidity: ave = ', rh_a,' standard deviation = ', rh_sd
	write(*,'(1x,a25,f10.5,a25,f10.5)') 'wind velocity: ave = ', u_a,' standard deviation = ', u_sd

	pause

	end program StandardDev

