




      SUBROUTINE OTH203 (AVE,SDEV)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'ESPACE.INC'
      INTEGER       IAA, IAT, IBINS(21), IS, IUSE, IUNIT, LIMIT
      REAL          SDEV, VAR, SKEW, CURT, A, B, Q, SIGA, SIGB, CHI2, 
     +              X(20), Y(20), BMIN, ADEV, AVE
      LOGICAL       GVFISF, GOTFILE, GVFFOP







      CALL GVSRT0 (PRPVAL,NUMAAT)
      AVE=-999.9
      SDEV=-999.9
      IUNIT=0



      IF (WIFPAR(279).EQ.0) THEN
         IF (GVFISF('MURTHY_SUCKS')) CALL GVSDEL ('MURTHY_SUCKS')
         IF (.NOT.GOTFILE(IUNIT,'MURTHY_SUCKS')) GOTO 998
      END IF



      DO 20 IAA=1,NUMAAF



         DO 10 IAT=PNTAAS(IAA),PNTAAE(IAA)
            IF (.NOT.ISATOK(IAT).OR.PROTON(IAT)) GOTO 10
            IF (.NOT.ISATOK(IAT)) THEN
               PRPVAL(IAA)=PRPVAL(IAA)-10000.0
            ELSE
               PRPVAL(IAA)=PRPVAL(IAA)+XBFACT(IAT)
            END IF
 10      CONTINUE



         PRPVAL(IAA)=PRPVAL(IAA)/FLOAT(ATPRAA(RESTYP(IAA)))
 20   CONTINUE



      IUSE=0
      CALL GVSRTI (X,20)
      DO 40 IAA=1,NUMAAF-20
         IF (PRPVAL(IAA).LE.0.0) GOTO 40
         Y(1)=PRPVAL(IAA)
         BMIN=999.9
         DO 28 IS=1,19
            Y(IS+1)=PRPVAL(IAA+IS)
 28      CONTINUE
         DO 38 IS=10,20
            CALL FIT (X,Y,IS,A,B,SIGA,SIGB,CHI2,Q)
            IF (ABS(B).LT.ABS(BMIN)) BMIN=B
 38      CONTINUE
         IUSE=IUSE+1
         PRPVAL(IUSE)=BMIN
 40   CONTINUE





      LIMIT=75
      IF (WIFPAR(279).GT.1) LIMIT=40
      IF (IUSE.GE.LIMIT) THEN
         CALL GVSRAV (PRPVAL,IUSE,AVE,ADEV,SDEV,VAR,SKEW,CURT)

         IF (WIFPAR(279).EQ.0) THEN
            CALL GVSPRS (AVE,ADEV,SDEV,SKEW,CURT)
            CALL GVSPRSN (IUNIT,IUSE,AVE,ADEV,SDEV,SKEW,CURT)
            CALL GVSHUT (PRPVAL,IUSE,IBINS,21)
         END IF
      END IF



  998 CONTINUE
      IF (IUNIT.NE.0) CALL GVSCLF (IUNIT)



      RETURN
      END   

      SUBROUTINE FIT (X,Y,NDATA,A,B,SIGA,SIGB,CHI2,Q)



      DIMENSION X(NDATA),Y(NDATA)
      SX=0.
      SY=0.
      ST2=0.
      B=0.
      DO 12 I=1,NDATA
         SX=SX+X(I)
         SY=SY+Y(I)
 12   CONTINUE
      SS=FLOAT(NDATA)
      SXOSS=SX/SS
      DO 14 I=1,NDATA
         T=X(I)-SXOSS
         ST2=ST2+T*T
         B=B+T*Y(I)
 14   CONTINUE
      B=B/ST2
      A=(SY-SX*B)/SS
      SIGA=SQRT((1.+SX*SX/(SS*ST2))/SS)
      SIGB=SQRT(1./ST2)
      CHI2=0.
      DO 15 I=1,NDATA
         CHI2=CHI2+(Y(I)-A-B*X(I))**2
 15   CONTINUE
      Q=1.
      SIGDAT=SQRT(CHI2/(NDATA-2))
      SIGA=SIGA*SIGDAT
      SIGB=SIGB*SIGDAT
      
      RETURN
      END
