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


