      REAL*8 DUMMY, PIV(500), ACT(500), SUM, SUMSQ, SUMCUB, SUMQUAR
	REAL*8  SQ, SSQ, QR
	REAL*8  SQ0,SQ1
      INTEGER GOOD(500),N,IDUMMY,i
      CHARACTER FILENAME*200

      READ *,FILENAME
      OPEN(113, file=FILENAME)
      OPEN(100, file='fun-minpiv.act')

 10   CONTINUE
      N=N+1
      READ(113,*,END=9990) ACT(N)
      GOTO 10
 9990 CONTINUE

 11   CONTINUE
      READ(100,*,END=9991),N,DUMMY,IDUMMY
      GOOD(N)=IDUMMY
      PIV(N)=DUMMY
      GOTO 11
 9991 CONTINUE

      N=0
      DO 20 I=1,500
         IF (GOOD(I).NE.1) GOTO 20
	 IF (PIV(I).LE.0.1) GOTO 20
         N=N+1
         DUMMY=ACT(I)
         SUM=SUM+DUMMY
         SUMSQ=SUMSQ+DUMMY*DUMMY
         SUMCUB=SUMCUB+DUMMY*DUMMY*DUMMY
         SUMQUAR=SUMQUAR+DUMMY*DUMMY*DUMMY*DUMMY
C
C	VARIANCE=SIGMA^2=(STD DEV)^2=SQ^2
C
	 SSQ=( ((SUMSQ) - (SUM/N)**2)/(N**2) )**0.5
	 SQ0=( ((SUMSQ) - (SUM/N)**2)/(N) )**0.5
	 SQ=( ((SUMSQ/N) - (SUM/N)**2) )
	 QR=( (SUMQUAR/N) - 4*(SUMCUB/N)*(SUM/N) +6*(SUMSQ/N)*(SUM/N)**2
     +         -3*(SUM/N)**4 ) 
 20      PRINT *,I,N,' AVG=',SUM/N, SQ**0.5, QR**0.25 
      END



