! This is a basic starting shell for your programs MODULE const INTEGER, PARAMETER :: dp = KIND(1.0d0), sp = KIND(1.0e0) REAL(KIND=dp), PARAMETER :: dpi = 3.141592653589793d0 END MODULE const ! PROGRAM prog USE const IMPLICIT NONE ! ! HW 15, 2 ! ! Compute mean and standard deviation of a set of integers with ! only one pass through the datafile ! INTEGER :: n,total1,rvalue,total2 REAL(kind=dp) :: avg,stdev ! 1 pass version ! ! For this program, both quantites can be computed using 1 pass through ! the read loop. See the formula about 1/2 down the Wikipedia page ! on standard deviation. ! Set mean accumulation variable (total1) and standard deviation accumulation ! variable (total2) to 0. Set number of values to 0. ! ! Total2 can be an integer for this version of the formula. total1 = 0 total2 = 0 n = 0 ! Open the data file. OPEN(10,file='hw15b.in') ! First read loop to get the mean DO READ(10,*,END=100) rvalue total1 = total1 + rvalue total2 = total2 + rvalue**2 n = n + 1 ENDDO 100 CONTINUE avg = total1/DBLE(n) stdev = SQRT((total2/DBLE(n) - avg**2) WRITE(*,*) 'avg = ',avg WRITE(*,*) 'stdev = ',stdev WRITE(*,*) 'n = ',n ! Close data file and end CLOSE(10) END PROGRAM prog !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! avg = -0.49299999999999999 ! stdev = 5.7822873204678062 ! n = 15000