!####################################################################
      subroutine stdmaxmeanmin(nsamp0,xvar0,std,fmean,xmin,xmax)
      implicit none
      integer nsamp,j,nsamp0
      double precision xvar(nsamp0),std,fmean,xmin,xmax,
     &  xvar0(nsamp0),gap
      parameter(gap=-9999.0d0)
     
      nsamp=0
      do j=1,nsamp0        
        if(dabs(xvar0(j)-gap).gt.1.0d-5)then
          nsamp=nsamp+1
          xvar(nsamp)=xvar0(j)
        endif
      enddo
      if(nsamp.lt.1)then
        std=gap
        fmean=gap
        xmin=gap
        xmax=gap
        return
      endif
      fmean=0.0d0
      xmin=xvar(1)
      xmax=xvar(1)
      do j=1,nsamp
        fmean=fmean+xvar(j)
        if(xvar(j).gt.xmax)then
          xmax=xvar(j)
        endif
        if(xvar(j).lt.xmin)then
          xmin=xvar(j)
        endif
      enddo
      fmean=fmean/dble(nsamp)
      std=0.0d0
      do j=1,nsamp
        std=std+(xvar(j)-fmean)*(xvar(j)-fmean)       
      enddo
      if(nsamp.gt.1)std=dsqrt(std/dble(nsamp-1))
      end
