!-----------------------------------------------------------------------------
Subroutine Ave_Std(X, N, Mean, Std)
Integer :: N, i, icount
Real :: X(N), Mean, Std
Mean=0.; Std=0.; icount=0
Do i=1, N
   if (X(i)/=Miss) then
      icount=icount+1; Mean=Mean+X(i); Std=Std+X(i)*X(i)
   endif
Enddo
if (icount>0) then
   Mean=Mean/real(icount); Std=SQRT(Std/real(icount)-Mean*Mean)
else
   Mean=Miss; Std=Miss
endif
End Subroutine Ave_Std
!-----------------------------------------------------------------------------

