



      SUBROUTINE GVSHIS (ROW,NUM,IBINS,NUMBIN)









      IMPLICIT      NONE
      INTEGER       NUM, NUMBIN, I, INDX
      REAL          ROW(NUM), ROWMAX, ROWMIN, GVFMAX, GVFMIN, STEP
      INTEGER       IBINS(NUMBIN)







      IF (NUM.LE.0) THEN
         CALL GVSTTB ('?M0144')
         GOTO 998
      END IF
      IF (NUM.EQ.1) THEN
         CALL GVSTTB ('?M0145')
         GOTO 998
      END IF



      CALL GVSIT0 (IBINS,NUMBIN)



      ROWMAX=GVFMAX(ROW,NUM)
      ROWMIN=GVFMIN(ROW,NUM)
      STEP=(ROWMAX-ROWMIN)/FLOAT(NUMBIN)



      DO 100 I=1,NUM
         INDX=NINT((ROW(I)-ROWMIN)/STEP+1.0)
         IBINS(INDX)=IBINS(INDX)+1
  100 CONTINUE



  998 CONTINUE


      RETURN
      END
      SUBROUTINE GVSHMS (ROW,NUM,IBINS,NUMBIN,ROWMIN,ROWMAX)









      IMPLICIT      NONE
      INTEGER       NUM, NUMBIN, I, INDX
      REAL          ROW(NUM), ROWMAX, ROWMIN, STEP
      INTEGER       IBINS(NUMBIN)







      IF (NUM.LE.0) THEN
         CALL GVSTTB ('?M0144')
         GOTO 998
      END IF
      IF (NUM.EQ.1) THEN
         CALL GVSTTB ('?M0145')
         GOTO 998
      END IF



      CALL GVSIT0 (IBINS,NUMBIN)



      STEP=(ROWMAX-ROWMIN)/FLOAT(NUMBIN)



      DO 100 I=1,NUM
         INDX=NINT((ROW(I)-ROWMIN)/STEP+1.0)
         INDX=MAX(INDX,1)
         INDX=MIN(NUMBIN,INDX)
         IBINS(INDX)=IBINS(INDX)+1
  100 CONTINUE



  998 CONTINUE


      RETURN
      END
      INTEGER FUNCTION GVFMIP(ROW,NUM)







      IMPLICIT      NONE
      INTEGER       NUM, I
      REAL          ROW(NUM), ROWMIN







      GVFMIP=1
      ROWMIN=ROW(1)



      DO 10 I=1,NUM
         IF (ROW(I).LT.ROWMIN) THEN
            GVFMIP=I
            ROWMIN=ROW(I)
         END IF
   10 CONTINUE





      RETURN
      END      
      INTEGER FUNCTION GVFMAP(ROW,NUM)







      IMPLICIT      NONE
      INTEGER       NUM, I
      REAL          ROW(NUM), ROWMAX







      GVFMAP=1
      ROWMAX=ROW(1)



      DO 10 I=1,NUM
         IF (ROW(I).GT.ROWMAX) THEN
            GVFMAP=I
            ROWMAX=ROW(I)
         END IF
   10 CONTINUE





      RETURN
      END      
      SUBROUTINE GVSHUT (ROW,NUM,IBINS,NUMBIN)









      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       NUM, NUMBIN, IND, MAXBIN, I, J, CHRCNT
      REAL          ROW(NUM), ROWMAX, ROWMIN, STEP, GVFMIN, GVFMAX
      INTEGER       IBINS(NUMBIN),GVFIMX
      LOGICAL       GVFFOP
      CHARACTER*1   CHARS(40)
      SAVE          CHARS
      DATA CHARS    /40*'='/







      IF (NUM.LE.0) THEN
         CALL GVSTTB ('?M0144')
         GOTO 998
      END IF
      IF (NUM.EQ.1) THEN
         CALL GVSTTB ('?M0145')
         GOTO 998
      END IF



      CALL GVSIT0 (IBINS,NUMBIN)



      ROWMAX=GVFMAX(ROW,NUM)
      ROWMIN=GVFMIN(ROW,NUM)
      STEP=(ROWMAX-ROWMIN)/FLOAT(NUMBIN)



      IF (ABS(STEP).LT.0.00001) THEN
         CALL GVSTTE ('?M0142')
         GOTO 998
      END IF



      DO 10 I=1,NUM
         IND=NINT((ROW(I)-ROWMIN)/STEP)+1
         IND=MAX(IND,1)
         IND=MIN(IND,NUMBIN)
         IBINS(IND)=IBINS(IND)+1
   10 CONTINUE



      MAXBIN=GVFIMX(IBINS,NUMBIN)



      DO 20 I=1,NUMBIN
         CHRCNT=IBINS(I)*39/MAXBIN
         IF (CHRCNT.GE.1) THEN
            CALL GVSFMT ('?FMT743')
            WRITE (6,FMT,ERR=999) ROWMIN+(I-1)*STEP,ROWMIN+I*STEP,
     +       IBINS(I),(CHARS(J),J=1,CHRCNT)
            IF (GVFFOP(16)) WRITE (16,FMT,ERR=999) ROWMIN+(I-1)*STEP,
     +       ROWMIN+I*STEP,IBINS(I),(CHARS(J),J=1,CHRCNT)
         ELSE
            CALL GVSFMT ('?FMT743A')
            WRITE (6,FMT,ERR=999) ROWMIN+(I-1)*STEP,ROWMIN+I*STEP,
     +       IBINS(I)
            IF (GVFFOP(16)) WRITE (16,FMT,ERR=999) ROWMIN+(I-1)*STEP,
     +       ROWMIN+I*STEP,IBINS(I)
         END IF
   20 CONTINUE
      GOTO 998



 999  CONTINUE
      CALL GVSEIW ('GVSHUT')



  998 CONTINUE


      RETURN
      END
      SUBROUTINE GVSHUT2 (ROW,NUM,IBINS,NUMBIN,ROWMIN,ROWMAX,INMBIN)









      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       NUM, NUMBIN, IND, MAXBIN, I, J, GVFPOS, IPOS,
     +              IBINS(NUMBIN), GVFIMX, INMBIN
      REAL          ROW(NUM), ROWMAX, ROWMIN, STEP
      CHARACTER*1   CHARS(40)
      SAVE          CHARS
      DATA CHARS    /40*'='/







      IF (NUM.LE.0) THEN
         CALL GVSTTB ('?M0144')
         GOTO 998
      END IF
      IF (NUM.EQ.1) THEN
         CALL GVSTTB ('?M0145')
         GOTO 998
      END IF



      CALL GVSIT0 (IBINS,NUMBIN)



      STEP=(ROWMAX-ROWMIN)/FLOAT(NUMBIN)



      IF (ABS(STEP).LT.0.00001) THEN
         CALL GVSTTE ('?M0142')
         GOTO 998
      END IF



      DO 10 I=1,NUM
         IND=NINT((ROW(I)-ROWMIN)/STEP+1.0)
         IND=MAX(IND,1)
         IND=MIN(IND,NUMBIN)
         IBINS(IND)=IBINS(IND)+1
   10 CONTINUE



      IF (INMBIN.EQ.0) THEN
         MAXBIN=GVFIMX(IBINS,NUMBIN)
      ELSE
         MAXBIN=INMBIN
      END IF



      DO 20 I=1,NUMBIN
         CALL GVSFMT ('?FMT219')
         CALL GVSCTB (LINE,80)
         WRITE (LINE,FMT,ERR=999) ROWMIN+(I-1)*STEP,ROWMIN+
     +    I*STEP,(CHARS(J),J=1,IBINS(I)*39/MAXBIN+1)
         IPOS=GVFPOS(LINE,' = ')
         IF (IPOS.NE.0) LINE(IPOS+1:IPOS+1)='.'
         CALL GVSTT6 (LINE)
   20 CONTINUE
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('GVSHUT2')



  998 CONTINUE


      RETURN
      END
      SUBROUTINE GVSHLT (ROW,BOOLS,NUM,IBINS,NUMBIN)









      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       NUM, NUMBIN, IND, MAXBIN, I, J, GVFCBT
      REAL          ROW(NUM), ROWMAX, ROWMIN, STEP
      INTEGER       IBINS(NUMBIN),GVFIMX
      LOGICAL       GVFFOP, BOOLS(NUM)
      CHARACTER*1   CHARS(40)
      SAVE          CHARS
      DATA CHARS    /40*'='/







      IF (NUM.LE.0) THEN
         CALL GVSTTB ('?M0144')
         GOTO 998
      END IF
      IF (NUM.EQ.1) THEN
         CALL GVSTTB ('?M0145')
         GOTO 998
      END IF
      IF (GVFCBT(BOOLS,NUM).LE.1) THEN
         CALL GVSTTE ('?M0143')
         GOTO 998
      END IF



      CALL GVSIT0 (IBINS,NUMBIN)



      ROWMAX=-1.E9
      ROWMIN=1.E9
      DO 4 I=1,NUM
         IF (BOOLS(I)) THEN
            ROWMAX=ROW(I)
            ROWMIN=ROW(I)
            GOTO 5
         END IF
    4 CONTINUE
    5 DO 6 I=1,NUM
         IF (BOOLS(I)) THEN
            ROWMAX=MAX(ROWMAX,ROW(I))
            ROWMIN=MIN(ROWMIN,ROW(I))
         END IF
    6 CONTINUE
      STEP=(ROWMAX-ROWMIN)/FLOAT(NUMBIN)



      IF (ABS(STEP).LT.0.00001) THEN
         CALL GVSTTE ('?M0142')
         GOTO 998
      END IF



      DO 10 I=1,NUM
         IF (BOOLS(I)) THEN
            IND=NINT((ROW(I)-ROWMIN)/STEP+1.0)
            IND=MAX(IND,1)
            IND=MIN(IND,NUMBIN)
            IBINS(IND)=IBINS(IND)+1
         END IF
   10 CONTINUE



      MAXBIN=GVFIMX(IBINS,NUMBIN)



      DO 20 I=1,NUMBIN
         CALL GVSFMT ('?FMT744')
         WRITE (6,FMT,ERR=999) ROWMIN+(I-1)*STEP,ROWMIN+I*STEP,
     +    (CHARS(J),J=1,IBINS(I)*39/MAXBIN+1)
         IF (GVFFOP(16)) WRITE (16,FMT,ERR=999) ROWMIN+(I-1)*STEP,
     +    ROWMIN+I*STEP,(CHARS(J),J=1,IBINS(I)*39/MAXBIN+1)
   20 CONTINUE
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('GVSHLT')



  998 CONTINUE


      RETURN
      END
      SUBROUTINE GVS2AV (IROW,N,AVE,ADEV,SDEV,VAR,SKEW,CURT)



















      IMPLICIT      NONE
      INTEGER       N, J
      INTEGER*2     IROW(N)
      REAL          S,P, AVE,ADEV,SDEV,VAR,SKEW,CURT







      IF (N.LE.1) THEN
         CALL GVSTTI ('?M1035',N)
         GOTO 998
      END IF



      S=0.0
      DO 10 J=1,N
         S=S+IROW(J)
   10 CONTINUE
      AVE=S/N



      ADEV=0.
      VAR=0.
      SKEW=0.
      CURT=0.
      DO 20 J=1,N
         S=IROW(J)-AVE
         ADEV=ADEV+ABS(S)
         P=S*S
         VAR=VAR+P
         P=P*S
         SKEW=SKEW+P
         P=P*S
         CURT=CURT+P
   20 CONTINUE
      ADEV=ADEV/N
      VAR=VAR/(N-1)
      SDEV=SQRT(VAR)
      IF (VAR.NE.0.) THEN
         SKEW=SKEW/(N*SDEV**3)
         CURT=CURT/(N*VAR**2)-3.
      ELSE
         SKEW=0.0
         CURT=0.0
      END IF



  998 CONTINUE


      RETURN
      END

      SUBROUTINE GVSIAV (IROW,N,AVE,ADEV,SDEV,VAR,SKEW,CURT)



















      IMPLICIT      NONE
      INTEGER       N, J
      INTEGER       IROW(N)
      REAL          S,P, AVE,ADEV,SDEV,VAR,SKEW,CURT







      IF (N.LE.1) THEN
         CALL GVSTTI ('?M1034',N)
         GOTO 998
      END IF



      S=0.0
      DO 10 J=1,N
         S=S+IROW(J)
   10 CONTINUE
      AVE=S/N



      ADEV=0.
      VAR=0.
      SKEW=0.
      CURT=0.
      DO 20 J=1,N
         S=IROW(J)-AVE
         ADEV=ADEV+ABS(S)
         P=S*S
         VAR=VAR+P
         P=P*S
         SKEW=SKEW+P
         P=P*S
         CURT=CURT+P
   20 CONTINUE
      ADEV=ADEV/N
      VAR=VAR/(N-1)
      SDEV=SQRT(VAR)
      IF (VAR.NE.0.) THEN
         SKEW=SKEW/(N*SDEV**3)
         CURT=CURT/(N*VAR**2)-3.
      ELSE
         SKEW=0.0
         CURT=0.0
      END IF



  998 CONTINUE


      RETURN
      END
      SUBROUTINE GVSPMM (ROW,NUM)







      IMPLICIT      NONE
      INTEGER       NUM
      REAL          ROW(NUM), GVFMAX, GVFMIN







      CALL GVSTTI ('?TLSST8',NUM)
      CALL GVSTTR ('?TLSST6',GVFMIN(ROW,NUM))
      CALL GVSTTR ('?TLSST7',GVFMAX(ROW,NUM))





      RETURN
      END
      SUBROUTINE GVSPML (ROW,BOOLS,NUM)









      IMPLICIT      NONE
      INTEGER       NUM, I
      REAL          ROW(NUM), PMLMAX, PMLMIN, GVFMAX, GVFMIN
      LOGICAL       BOOLS(NUM), FOUND







      FOUND=.FALSE.
      DO 10 I=1,NUM
         IF (BOOLS(I)) THEN
            PMLMAX=ROW(I)
            PMLMIN=ROW(I)
            FOUND=.TRUE.
            GOTO 11
         END IF
   10 CONTINUE
   11 CONTINUE



      IF (FOUND) THEN
         DO 20 I=1,NUM
            IF (BOOLS(I)) THEN
               PMLMAX=MAX(PMLMAX,ROW(I))
               PMLMIN=MIN(PMLMIN,ROW(I))
            END IF
   20    CONTINUE
      END IF



      IF (FOUND) THEN
         CALL GVSTTR2 ('?TLSST6',GVFMIN(ROW,NUM),PMLMIN)
         CALL GVSTTR2 ('?TLSST7',GVFMAX(ROW,NUM),PMLMAX)
      ELSE
         CALL GVSTTR ('?TLSST6',GVFMIN(ROW,NUM))
         CALL GVSTTR ('?TLSST7',GVFMAX(ROW,NUM))
      END IF





      RETURN
      END
      SUBROUTINE GVSPRS (AVE,ADEV,SDEV,SKEW,CURT)














      IMPLICIT      NONE
      REAL          AVE, ADEV, SDEV, SKEW, CURT







      CALL GVSTTR ('?TLSST1',AVE)
      CALL GVSTTR ('?TLSST2',ADEV)
      CALL GVSTTR ('?TLSST3',SDEV)
      CALL GVSTTR ('?TLSST4',SKEW)
      CALL GVSTTR ('?TLSST5',CURT)





      RETURN
      END
      SUBROUTINE GVSPRSN (IUNIT,NUM,AVE,ADEV,SDEV,SKEW,CURT)















      IMPLICIT      NONE
      INTEGER       NUM, ZERO, ONE, IUNIT
      REAL          AVE, ADEV, SDEV, SKEW, CURT
      LOGICAL       GVFFOP, GVFIBN







      IF (NUM.EQ.0) THEN
         ZERO=0
         CALL GVSTTI ('?TLSST0',ZERO)
         CALL GVSTT6 ('?TLSST-')
         GOTO 998
      ELSE IF (NUM.EQ.1) THEN
         ONE=1
         CALL GVSTTI ('?TLSST0',ONE)
         CALL GVSTT6 ('?TLSST-')
         GOTO 998
      END IF
      IF (IUNIT.NE.6) THEN
         IF (.NOT.GVFIBN(IUNIT,1,100)) THEN
            CALL GVSTTI ('?M4176',IUNIT)
            GOTO 998
         END IF
      END IF
      IF (.NOT.GVFFOP(IUNIT)) THEN
         CALL GVSTTB ('?M4176')
         GOTO 998
      END IF



      CALL GVSTUI (IUNIT,'?TLSST0',NUM)
      CALL GVSTUR (IUNIT,'?TLSST1',AVE)
      CALL GVSTUR (IUNIT,'?TLSST2',ADEV)
      CALL GVSTUR (IUNIT,'?TLSST3',SDEV)
      CALL GVSTUR (IUNIT,'?TLSST4',SKEW)
      CALL GVSTUR (IUNIT,'?TLSST5',CURT)



 998  CONTINUE


      RETURN
      END
      SUBROUTINE GVSPRSU (IUNIT,AVE,ADEV,SDEV,SKEW,CURT)














      IMPLICIT      NONE
      INTEGER       IUNIT
      REAL          AVE, ADEV, SDEV, SKEW, CURT







      CALL GVSTTRU (IUNIT,'?TLSST1',AVE)
      CALL GVSTTRU (IUNIT,'?TLSST2',ADEV)
      CALL GVSTTRU (IUNIT,'?TLSST3',SDEV)
      CALL GVSTTRU (IUNIT,'?TLSST4',SKEW)
      CALL GVSTTRU (IUNIT,'?TLSST5',CURT)





      RETURN
      END
      SUBROUTINE GVSRAV (ROW,N,AVE,ADEV,SDEV,VAR,SKEW,CURT)



















      IMPLICIT      NONE
      INTEGER       N, J
      REAL          ROW(N), S, P, AVE, ADEV, SDEV, VAR, SKEW, CURT







      IF (N.LE.1) THEN
         CALL GVSTTI ('?M1031',N)
         GOTO 998
      END IF



      S=0.0
      DO 10 J=1,N
         S=S+ROW(J)
   10 CONTINUE
      AVE=S/N



      ADEV=0.0
      VAR=0.0
      SKEW=0.0
      CURT=0.0
      DO 20 J=1,N
         S=ROW(J)-AVE
         ADEV=ADEV+ABS(S)
         P=S*S
         VAR=VAR+P
         P=P*S
         SKEW=SKEW+P
         P=P*S
         CURT=CURT+P
   20 CONTINUE
      ADEV=ADEV/N
      VAR=VAR/(N-1)
      SDEV=SQRT(VAR)
      IF (VAR.NE.0.0) THEN
         SKEW=SKEW/(N*SDEV**3)
         CURT=CURT/(N*VAR**2)-3.
      ELSE
         SKEW=0.0
         CURT=0.0
      END IF



  998 CONTINUE


      RETURN
      END
      SUBROUTINE GVSRIV (ROW,N,AVE,ADEV,SDEV,VAR,SKEW,CURT)



















      IMPLICIT      NONE
      INTEGER       N
      INTEGER       ROW(N), J
      REAL          S, P, AVE, ADEV, SDEV, VAR, SKEW, CURT







      IF (N.LE.1) THEN
         CALL GVSTTI ('?M1031',N)
         GOTO 998
      END IF



      S=0.0
      DO 10 J=1,N
         S=S+FLOAT(ROW(J))
   10 CONTINUE
      AVE=S/FLOAT(N)



      ADEV=0.0
      VAR=0.0
      SKEW=0.0
      CURT=0.0
      DO 20 J=1,N
         S=FLOAT(ROW(J))-AVE
         ADEV=ADEV+ABS(S)
         P=S*S
         VAR=VAR+P
         P=P*S
         SKEW=SKEW+P
         P=P*S
         CURT=CURT+P
   20 CONTINUE
      ADEV=ADEV/FLOAT(N)
      VAR=VAR/(FLOAT(N)-1.0)
      SDEV=SQRT(VAR)
      IF (VAR.NE.0.0) THEN
         SKEW=SKEW/(FLOAT(N)*SDEV**3)
         CURT=CURT/(FLOAT(N)*VAR**2)-3.
      ELSE
         SKEW=0.0
         CURT=0.0
      END IF



  998 CONTINUE


      RETURN
      END
      SUBROUTINE GVSRLV (ROW,BOOLS,N,AVE,ADEV,SDEV,VAR,SKEW,CURT)




















      IMPLICIT      NONE
      INTEGER       N, J, IUSED
      REAL          ROW(N), S, P, AVE, ADEV, SDEV, VAR, SKEW, CURT
      LOGICAL       BOOLS(N)







      IF (N.LE.1) THEN
         CALL GVSTTI ('?M1032',N)
         GOTO 998
      END IF



      AVE=0
      ADEV=0
      SDEV=0
      VAR=0
      SKEW=0
      CURT=0



      S=0.0
      IUSED=0
      DO 10 J=1,N
         IF (BOOLS(J)) THEN
            S=S+ROW(J)
            IUSED=IUSED+1
         END IF
   10 CONTINUE
      IF (IUSED.LE.0) THEN
         CALL GVSTTE ('?M1033')
         GOTO 998
      END IF
      AVE=S/IUSED



      DO 20 J=1,N
         IF (.NOT.BOOLS(J)) GOTO 20
         S=ROW(J)-AVE
         ADEV=ADEV+ABS(S)
         P=S*S
         VAR=VAR+P
         P=P*S
         SKEW=SKEW+P
         P=P*S
         CURT=CURT+P
   20 CONTINUE
      ADEV=ADEV/IUSED
      IF (IUSED.GT.1) THEN
         VAR=VAR/(IUSED-1)
      ELSE
         VAR=0.0
      END IF
      SDEV=SQRT(VAR)
      IF (VAR.GT.0.0) THEN
         SKEW=SKEW/(IUSED*(SDEV**3))
         CURT=CURT/(IUSED*(VAR**2))-3.
      ELSE
         SKEW=0.0
         CURT=0.0
      END IF



  998 CONTINUE


      RETURN
      END
      SUBROUTINE GVSSAV (ROW,AVE,NUM)









      IMPLICIT      NONE
      INTEGER       NUM
      REAL          ROW(NUM), ROWSUM, AVE, GVFRSM







      ROWSUM=GVFRSM(ROW,NUM)



      IF (ABS(ROWSUM).LT.0.00001) GOTO 998
      CALL GVSVXC (ROW,AVE/ROWSUM,NUM)



  998 CONTINUE


      RETURN
      END
      SUBROUTINE GVSR4S (ROW,NUM)

















      IMPLICIT      NONE
      INTEGER       NUM, IPNT, JPNT
      REAL          ROW(NUM), AVE, ADEV, SDEV, VAR, SKEW, CURT







      IF (NUM.LE.10) GOTO 998



      IPNT=1



      CALL GVSRAV (ROW,NUM,AVE,ADEV,SDEV,VAR,SKEW,CURT)



 10   CONTINUE
         IF (ABS(ROW(IPNT)-AVE)/SDEV.GT.4.0) THEN
            IF (IPNT.EQ.NUM) THEN
               NUM=NUM-1
               GOTO 998
            END IF
            DO 20 JPNT=IPNT,NUM-1
               ROW(JPNT)=ROW(JPNT+1)
 20         CONTINUE
            NUM=NUM-1
         END IF
         IPNT=IPNT+1
         IF (IPNT.GT.NUM) GOTO 998
      GOTO 10



  998 CONTINUE


      RETURN
      END   
