m_ens_stat.F90 664 Bytes
module m_ens_stat
contains
subroutine ens_stat(mem,ave,var,nrsamp)
   use mod_dimensions
   use mod_states
   implicit none
   integer, intent(in) :: nrsamp
   type(states),  intent(in)  :: mem(nrsamp)
   type(states),  intent(out) :: ave,var
   integer iens
   real scale,scale1

   if (nrsamp == 1) then
      print *,'ens_stat: no point with statistics when nrsamp=1'
      return
   endif
   scale=1.0/float(nrsamp)
   scale1=1.0/float(nrsamp-1)

   ave=0.0
   var=0.0

   do iens=1,nrsamp
      ave=ave+mem(iens)
      var=var+mem(iens)*mem(iens)
   enddo

   var=scale1*(var-scale*ave*ave)
   ave = scale * ave

end subroutine ens_stat
end module m_ens_stat