c
c  @(#)diag.f	1.1
c
      SUBROUTINE DIAG(PSI,M,ave,sdv,rms,psimin,psimax)
C     CALCULATES THE DIAGNOSTICS OF THE FIELD
      DIMENSION PSI(M)
      COMMON/ME/AVERG
	data big/0.9E35/
      AVERG=0.
      SDV=0.
      IF (M .LE. 0) GOTO 50
      PSIMAX=-big
      PSIMIN=big
      AVERG=big
      IF (M .EQ. 1) GOTO 30
	do 40 i=1,m
	if(psi(i).lt.big)then
	    psimax=psi(i)
	    psimin=psi(i)
	    averg=psi(i)
	    ist=i+1
	    goto 45
	endif
40	continue
	goto 30
45	icnt=2
      DO 20 I=IST,M
	if(psi(i).gt.big)goto 20
         SDV=((ICNT-2)*SDV+(ICNT-1)*(PSI(I)-AVERG)**2/
     *    	FLOAT(ICNT))/FLOAT(ICNT-1)
         AVERG=((ICNT-1)*AVERG+PSI(I))/FLOAT(ICNT)
         IF (PSI(I) .GT. PSIMAX) PSIMAX=PSI(I)
         IF (PSI(I) .LT. PSIMIN) PSIMIN=PSI(I)
	icnt=icnt+1
   20 CONTINUE
   30 CONTINUE
      RMS=SQRT(SDV+AVERG**2)
	ave=averg
   50 CONTINUE
      RETURN
      END
