



      SUBROUTINE SC8001

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'HSTINC.INC'
      LOGICAL       CHKTODO, ANYQUA
      EXTERNAL      PDBC55, PDBC57
      EXTERNAL      PDBC59







      CALL TEXSECT ('?CHKM05')



      ANYQUA=.FALSE.



      IF (CHKTODO('INO')) CALL SC8002
      IF (CHKTODO('IOP')) CALL PDBC51 (PDBC59)




      IF (CHKTODO('QUA').AND.WIFPAR(931).GT.0) THEN
         WIFPAR(562)=0
         CALL QUA028 (1,NUMAAF)
         IF (CHKTODO('QPL')) CALL PDBC51 (PDBC55)
         ANYQUA=.TRUE.
      END IF



      IF (CHKTODO('NQA').AND.WIFPAR(930).GT.0) THEN
         CALL WIFPUSHPPP (590,1)
         CALL NQA017 (1,NUMAAF)
         CALL WIFPOPPPP (590)
         HSTDON=.FALSE.
         CALL DSP001 (.FALSE.)
         IF (CHKTODO('NQP')) CALL PDBC51 (PDBC57)
         ANYQUA=.TRUE.
      END IF
      IF (.NOT.ANYQUA) WIFPAR(942)=-999999





      RETURN
      END   
      SUBROUTINE SC8002



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'RESULT.INC'
      INCLUDE       'PDBINC.INC'
      INTEGER       TAG(MAXAA), IAA, IAT, IRT, NUM, ITAG, NTAG,
     +              LUN, IERR, IS, IE, IRT1, IMOD, ACTIVE, NUMMDL,
     +              NNUM(MAXMODEL)
      REAL          RESAV(MAXAA), SUM2, FRC, AVERAGE, STANDARDDEV,
     +              AVE(MAXTYP), STD(MAXTYP), NSUM2(MAXMODEL), SUM
      LOGICAL       GVFFOP, ISSOUPCA, GVFRIN







      IF (NUMAAF.LT.1) THEN
         CALL GVSTTE ('?SOUSML')
         GOTO 998
      END IF
      IF (ISSOUPCA()) THEN
         CALL GVSTTE ('?R00219')
         GOTO 998
      END IF



      CALL CDB013 ('INOCHKERR','INOCHKNEU',' ')



      CALL GVSROF (LUN,IERR)
      IF (IERR.NE.0) GOTO 998
      CALL GVSCCC (LINE,WHERIS,'INOUTF.DAT')



      CALL GVSOPF (LINE,LUN,'OLD')
      IF (.NOT.GVFFOP(LUN)) GOTO 998
      CALL GVSFMT ('?FMT1141')
      DO 200 IRT=1,MAXTYP
         READ (LUN,FMT,ERR=999) IRT1,AVERAGE,STANDARDDEV
         AVE(IRT1)=AVERAGE
         STD(IRT1)=STANDARDDEV
  200 CONTINUE
      CALL GVSCLF (LUN)



      CALL ENVPROT



      NTAG=0
      DO 90 IAA=1,NUMAAF
         IRT=RESTYP(IAA)
         IF (IRT.LE.0.OR.IRT.GT.MAXTYP) THEN
            PRPVAL(IAA)=1.0
            GOTO 90
         END IF
         SUM=0.0
         NUM=0
         CALL WIF041 (IAA)
         DO 80 IAT=PNTAAS(IAA),PNTAAE(IAA)
            IF (PINIAA(IAT).EQ.1) GOTO 80
            IF (PINIAA(IAT).EQ.3) GOTO 80
            IF (PINIAA(IAT).EQ.4) GOTO 80
            IF (.NOT.ISATOK(IAT)) GOTO 80
            IF (PROTON(IAT)) GOTO 80
            SUM=SUM+ACCESS(IAT)
            NUM=NUM+1
   80    CONTINUE



         NTAG=NTAG+1
         TAG(NTAG)=IAA
         IF (NUM.GT.0) THEN
            RESAV(NTAG)=SUM/FLOAT(NUM)
         ELSE
            RESAV(NTAG)=0
         END IF
   90 CONTINUE



      CALL GVSORT (RESAV,NTAG,TAG)
      CALL GVSRTC (PRPVAL,-999.9,NUMAAT)
      NUM=0
      SUM2=0.0
      CALL GVSIT0 (NNUM,MAXMODEL)
      CALL GVSRT0 (NSUM2,MAXMODEL)
      DO 70 ITAG=1,NTAG
         IAA=TAG(ITAG)
         IRT=RESTYP(IAA)
         IF (IRT.LE.0.OR.IRT.GT.MAXTYP) GOTO 70





         IS=ITAG
   73    IF (IS.GT.1) THEN
            IF (RESAV(IS-1).GT.RESAV(ITAG)-0.3) THEN
               IS=IS-1
               GOTO 73
            END IF
         END IF
         IE=ITAG
   76    IF (IE.LT.NTAG) THEN
            IF (RESAV(IE+1).LT.RESAV(ITAG)+0.3) THEN
               IE=IE+1
               GOTO 76
            END IF
         END IF
         FRC=(FLOAT(IS+IE)/2.0-1.0)/FLOAT(NTAG)



         PRPVAL(IAA)=(FRC-AVE(IRT))/STD(IRT)



         NUM=NUM+1
         SUM2=SUM2+PRPVAL(IAA)**2
         IF (MODNMB(IAA).GT.0.AND.MODNMB(IAA).LE.MAXMODEL) THEN
            NNUM(MODNMB(IAA))=NNUM(MODNMB(IAA))+1
            NSUM2(MODNMB(IAA))=NSUM2(MODNMB(IAA))+PRPVAL(IAA)**2
         END IF
   70 CONTINUE



      DO 83 IAA=1,NUMAAF
         IF (.NOT.GVFRIN(PRPVAL(IAA),-25.0,25.0)) THEN
            IF (IAA.EQ.1) THEN
               PRPVAL(IAA)=PRPVAL(IAA+1)
            ELSE IF (IAA.EQ.NUMAAF) THEN
               PRPVAL(IAA)=PRPVAL(IAA-1)
            ELSE
               PRPVAL(IAA)=(PRPVAL(IAA-1)+PRPVAL(IAA+1))/2.0
            END IF
         END IF
 83   CONTINUE



      CALL CDB012



      IF (NUM.GT.0) THEN
         GENRVL(36)=SQRT(SUM2/FLOAT(NUM))
      ELSE
         GENRVL(36)=-999.9
      END IF



      IF (GENRVL(36).GT.1.16) THEN
         CALL PDBMES ('INOUTHIGH')
         
      ELSE IF (GENRVL(36).GT.0.0) THEN
         CALL PDBMES ('INOUTOK')
      ELSE 
         CALL PDBMES ('NOINOUT')
      END IF



      ACTIVE=0
      DO 300 IMOD=1,NUMMDL()
         IF (NNUM(IMOD).GT.0) THEN
            ACTIVE=ACTIVE+1
            NMRVAL(1,IMOD)=SQRT(NSUM2(IMOD)/FLOAT(NNUM(IMOD)))
         ELSE
            NMRVAL(1,IMOD)=-999.9
         END IF
  300 CONTINUE
      VALACT=1
      IF (ACTIVE.GT.1) CALL PDBMES ('INONMR')
      GOTO 998



  999 CONTINUE
      CALL GVSTTE ('?R00211')



  998 CONTINUE
      CALL GVSCLF (LUN)


      RETURN
      END
