subroutine MeanSD( n, x, mean, sd ) ! ! Return the mean and standard deviation of the array x ! ! B. Knapp, 1999-08-19 ! implicit none ! ! Input integer n real*8 x(n) ! ! Output real*8 mean, sd ! ! Local integer j real*8 sumx, sumx2 ! sumx = 0.d0 sumx2 = 0.d0 do j=1,n sumx = sumx + x(j) sumx2 = sumx2 + x(j)**2 enddo ! mean = sumx/n if ( n .gt. 1 ) then sd = sqrt( max( 0.d0, sumx2-sumx**2/n )/(n-1) ) else sd = 0.d0 endif ! return end