



      SUBROUTINE SC6001

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      LOGICAL       CHKTODO
      EXTERNAL      PDBC52







      CALL TEXSECT ('?CHKM28')



      IF (CHKTODO('PUC')) CALL PUC010



      IF (CHKTODO('CHI')) THEN
         CALL CHI006 (1,NUMAAF)

      END IF



      IF (CHKTODO('RAM')) THEN
         CALL SC6002
      ELSE
         WIFPAR(942)=-999999
      END IF



      IF (CHKTODO('OME')) CALL SC6003



      IF (CHKTODO('C12')) THEN
         CALL SC6004
      ELSE
         WIFPAR(942)=-999999
      END IF



      IF (CHKTODO('FLP')) CALL SC6005



      IF (CHKTODO('ROT')) CALL SC6006



      IF (CHKTODO('BBC')) THEN
         CALL SC6007
      ELSE
         WIFPAR(942)=-999999
      END IF





      RETURN
      END   
      SUBROUTINE SC6002



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'CHIANG.INC'
      INCLUDE       'DATBAS.INC'
      INCLUDE       'ESPACE.INC'
      INCLUDE       'HSTINC.INC'
      INCLUDE       'RESULT.INC'
      INCLUDE       'PDBINC.INC'
      INTEGER       SZ, CW, ES0, ESZ, IERR
      PARAMETER     (CW=5)
      PARAMETER     (SZ=360/CW)
      PARAMETER     (ES0=100001)
      PARAMETER     (ESZ=ES0+3*MAXADB*MAXSEQ+SZ**2-1)
      INTEGER       D1(MAXADB,MAXSEQ), D2(MAXADB,MAXSEQ), IND, I1, I2,
     +              IRT, IST, IAA, INANG, CST, ACTIVE, NUMMDL, IMOD,
     +              ILHST(MAXADB,MAXSEQ), J1, J2, K1, K2, NNUM(MAXMODEL)
      REAL          NUM, SUM, SUM2, AVER, STDEV, GVFRTD, BONK(SZ,SZ),
     +              NSUM(MAXMODEL)
      CHARACTER*3   ST
      LOGICAL       INTERRUPTED, HASPROTEIN
      EQUIVALENCE   (D1,   ESPACE(ES0))
      EQUIVALENCE   (D2,   ESPACE(ES0+1*MAXADB*MAXSEQ))
      EQUIVALENCE   (ILHST,ESPACE(ES0+2*MAXADB*MAXSEQ))
      EQUIVALENCE   (BONK, ESPACE(ES0+3*MAXADB*MAXSEQ))



      IND(INANG)=MOD((INANG+180)/CW,SZ)+1







      IF (.NOT.HASPROTEIN()) THEN
         IF (WIFPAR(1127).EQ.0) CALL PDBMES ('R00116')
         GOTO 998
      END IF



      CALL ESPSET (ES0,ESZ,57)



      CALL CDB013 ('RAMCHKERR','RAMCHKNEU',' ')



      CALL GVSCCC (LINE,FILDIR(27),'ALLPHI.PHI')
      CALL SCN203B (LINE,'INTEGER',IERR)
      IF (IERR.NE.0) GOTO 998
      CALL GVSCPI (D1,GENVI4,MAXADB*MAXSEQ)
      CALL GVSCCC (LINE,FILDIR(27),'ALLPSI.PSI')
      CALL SCN203B (LINE,'INTEGER',IERR)
      IF (IERR.NE.0) GOTO 998
      CALL GVSCPI (D2,GENVI4,MAXADB*MAXSEQ)



      ST='SH '
      CALL DSP003A (ILHST)



      CALL GVSRTC (PRPVAL,-999.9,NUMAAT)



      CALL CHI004



      CALL DSP003



      DO 100 IST=1,3
         DO 200 IRT=20,0,-1



            CST=ICHAR(ST(IST:IST))
            DO 500 IAA=1,NUMAAF
               IF (IRT.EQ.0) THEN
                  IF (RESTYP(IAA).GT.20.OR.RESTYP(IAA).LT.1) GOTO 500
               ELSE
                  IF (RESTYP(IAA).NE.IRT) GOTO 500
               END IF
               IF (ICHAR(LOCHST(IAA)).NE.CST) GOTO 500
               IF (PRPVAL(IAA).GT.-100.0) GOTO 500
               IF (ABS(CHIANG(1,IAA)).GT.5.0) GOTO 500
               IF (ABS(CHIANG(2,IAA)).GT.5.0) GOTO 500
               GOTO 550
  500       CONTINUE



            GOTO 200



  550       CONTINUE
            CALL SC6008 (IST,IRT,AVER,STDEV)
            IF (INTERRUPTED()) GOTO 998



            IF (AVER.LT.2.0.AND.IRT.NE.6.AND.
     +       IRT.NE.13.AND.IRT.NE.21.AND.IRT.NE.0) GOTO 200



            DO 600 IAA=1,NUMAAT
               IF (IRT.EQ.0) THEN
                  IF (RESTYP(IAA).GT.20.OR.RESTYP(IAA).LT.1) GOTO 600
               ELSE
                  IF (RESTYP(IAA).NE.IRT) GOTO 600
               END IF
               IF (ICHAR(LOCHST(IAA)).NE.CST) GOTO 600
               IF (PRPVAL(IAA).GT.-100.0) GOTO 600
               IF (ABS(CHIANG(1,IAA)).GT.5.0) GOTO 600
               IF (ABS(CHIANG(2,IAA)).GT.5.0) GOTO 600
               K1=NINT(GVFRTD(CHIANG(1,IAA)))
               K2=NINT(GVFRTD(CHIANG(2,IAA)))
               IF (K1.EQ.-180) K1=180
               IF (K2.EQ.-180) K2=180
               PRPVAL(IAA)=0.0
               DO 610 J1=K1-5,K1+5
                  I1=IND(J1)
                  IF (I1.LE.0) THEN
                     PRINT*,'I1=0',IAA,K1,J1
                     GOTO 610
                  END IF
                  DO 620 J2=K2-5,K2+5
                     I2=IND(J2)
                     IF (I2.LE.0) THEN
                        PRINT*,'I2=0',IAA,K1,K2,J1,J2,I1,I2
                     ELSE
                        PRPVAL(IAA)=PRPVAL(IAA)+BONK(I1,I2)/121.0
                     END IF
  620             CONTINUE
  610          CONTINUE
               PRPVAL(IAA)=(PRPVAL(IAA)-AVER)/STDEV
               IF (PRPVAL(IAA).LT.-3.0) THEN
                  CALL DIF002 (6,IAA,PRPVAL(IAA))
               END IF
  600       CONTINUE
  200    CONTINUE
  100 CONTINUE



      SUM=0.0
      SUM2=0.0
      NUM=0
      CALL GVSIT0 (NNUM,MAXMODEL)
      CALL GVSRT0 (NSUM,MAXMODEL)
      DO 700 IAA=1,NUMAAF
         IF (PRPVAL(IAA).GT.-100.0) THEN
            NUM=NUM+1
            SUM=SUM+PRPVAL(IAA)
            SUM2=SUM2+PRPVAL(IAA)**2
            IF (MODNMB(IAA).GT.0.AND.MODNMB(IAA).LE.MAXMODEL) THEN
               NNUM(MODNMB(IAA))=NNUM(MODNMB(IAA))+1
               NSUM(MODNMB(IAA))=NSUM(MODNMB(IAA))+PRPVAL(IAA)
            END IF
         END IF
  700 CONTINUE
      IF (NUM.GT.0) THEN




         IF (WIFPAR(919).EQ.0) THEN
            GENRVL(29)=(SUM/NUM-SIGMAP(1))/SIGMAP(2)
         ELSE
            GENRVL(29)=SUM/NUM
         END IF



         CALL GVSTTR ('?PDHDR37',GENRVL(29))
         IF (GENRVL(29).LT.-4.0) THEN
            IF (WIFPAR(1127).EQ.0) CALL PDBMES ('RAMAZBAD')
         ELSE IF (GENRVL(29).LT.-3.0) THEN
            IF (WIFPAR(1127).EQ.0) CALL PDBMES ('RAMAZPOOR')
         ELSE
            IF (WIFPAR(1127).EQ.0) CALL PDBMES ('RAMAZOK')
         END IF
      END IF



      ACTIVE=0
      DO 400 IMOD=1,NUMMDL()
         IF (NNUM(IMOD).GT.0) THEN
            ACTIVE=ACTIVE+1
            NMRVAL(1,IMOD)=(NSUM(IMOD)/NNUM(IMOD)-SIGMAP(1))/SIGMAP(2)
         ELSE
            NMRVAL(1,IMOD)=-999.9
         END IF
  400 CONTINUE
      VALACT=1
      IF (ACTIVE.GT.1.AND.WIFPAR(1127).EQ.0) CALL PDBMES ('RAMNMR')



      CALL CDB012



      CALL ESPKIL (ES0,ESZ,57,'SC6002')



  998 CONTINUE


      RETURN
      END
      SUBROUTINE SC6003



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'CHIANG.INC'
      INCLUDE       'PDBINC.INC'
      INCLUDE       'RESULT.INC'
      INTEGER       IAA, IRT, NUM, NNUM(MAXMODEL), IMOD, NUMMDL, ACTIVE
      LOGICAL       HASPROTEIN
      REAL          SUM, SUM2, OME, AVER, STDEV, GVFRTD, GVFSQR,
     +              NSUM2(MAXMODEL), NSUM(MAXMODEL)







      IF (.NOT.HASPROTEIN()) THEN
         CALL PDBMES ('R00116')
         GOTO 998
      END IF



      CALL CHI004



      NUM=0
      SUM=0.0
      SUM2=0.0
      CALL GVSIT0 (NNUM,MAXMODEL)
      CALL GVSRT0 (NSUM,MAXMODEL)
      CALL GVSRT0 (NSUM2,MAXMODEL)



      DO 100 IAA=1,NUMAAF
         IRT=RESTYP(IAA)
         IF (IRT.LT.1.OR.IRT.GT.20) GOTO 100
         IF (ABS(CHIANG(3,IAA)).GT.5.00) GOTO 100
         IF (ABS(CHIANG(3,IAA)).LT.1.57) GOTO 100
         OME=GVFRTD(CHIANG(3,IAA))
         IF (OME.LT.0.0) OME=OME+360.0
         NUM=NUM+1
         SUM=SUM+OME
         SUM2=SUM2+OME**2
         IF (MODNMB(IAA).GT.0.AND.MODNMB(IAA).LE.MAXMODEL) THEN
            NNUM(MODNMB(IAA))=NNUM(MODNMB(IAA))+1
            NSUM(MODNMB(IAA))=NSUM(MODNMB(IAA))+OME
            NSUM2(MODNMB(IAA))=NSUM2(MODNMB(IAA))+OME**2
         END IF
  100 CONTINUE



      FIXLST(9)=0.0
      IF (NUM.GT.2) THEN
         AVER=SUM/NUM
         STDEV=GVFSQR((SUM2-SUM**2/NUM)/(NUM-1))
         CALL GVSTTR2 ('?R00275',AVER,STDEV)
         GENRVL(30)=STDEV
         IF (STDEV.LT.4.0) THEN
            CALL GVSTT6 ('?R00276')
            CALL PDBMES ('OMETIGHT')
            FIXLST(9)=GENRVL(30)
         ELSE IF (STDEV.GT.7.0) THEN
            CALL GVSTT6 ('?R00276')
            CALL PDBMES ('OMELOOSE')
            FIXLST(9)=GENRVL(30)
         ELSE
            CALL PDBMES ('OMEDEVOK')
         END IF
      END IF



      ACTIVE=0
      DO 300 IMOD=1,NUMMDL()
         IF (NNUM(IMOD).GT.1) THEN
            ACTIVE=ACTIVE+1
            NMRVAL(1,IMOD)=GVFSQR((NSUM2(IMOD)-NSUM(IMOD)**2/
     +       NNUM(IMOD))/(NNUM(IMOD)-1))
         ELSE
            NMRVAL(1,IMOD)=-999.9
         END IF
  300 CONTINUE
      VALACT=1
      IF (ACTIVE.GT.1) CALL PDBMES ('OMENMR')



  998 CONTINUE


      RETURN
      END
      SUBROUTINE SC6004



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'CHIANG.INC'
      INCLUDE       'DATBAS.INC'
      INCLUDE       'ESPACE.INC'
      INCLUDE       'HSTINC.INC'
      INCLUDE       'PDBINC.INC'
      INCLUDE       'RESULT.INC'
      INTEGER       SZ, CW, ES0, ESZ
      PARAMETER     (CW=5)
      PARAMETER     (SZ=360/CW)
      PARAMETER     (ES0=100001)
      PARAMETER     (ESZ=ES0+3*MAXADB*MAXSEQ+SZ**2-1)
      INTEGER       D1(MAXADB,MAXSEQ), D2(MAXADB,MAXSEQ), IND, I1, I2, 
     +              IRT, IST, IAA, INANG, CST, NNUM(MAXMODEL), ACTIVE,
     +              ILHST(MAXADB,MAXSEQ), J1, J2, K1, K2, IMOD,
     +              IERR, NUMMDL
      REAL          SUM, SUM2, NUM, AVER, STDEV, GVFRTD, BONK(SZ,SZ),
     +              NSUM(MAXMODEL)
      CHARACTER*3   ST
      LOGICAL       INTERRUPTED, HASPROTEIN, WIFROK
      EQUIVALENCE   (D1,   ESPACE(ES0))
      EQUIVALENCE   (D2,   ESPACE(ES0+1*MAXADB*MAXSEQ))
      EQUIVALENCE   (ILHST,ESPACE(ES0+2*MAXADB*MAXSEQ))
      EQUIVALENCE   (BONK, ESPACE(ES0+3*MAXADB*MAXSEQ))



      IND(INANG)=MOD((INANG+180)/CW,SZ)+1







      IF (.NOT.HASPROTEIN()) THEN
         CALL PDBMES ('R00116')
         GOTO 998
      END IF
      WIFPAR(156)=1



      ST='SH '
      CALL DSP003A (ILHST)



      CALL GVSRTC (PRPVAL,-999.9,NUMAAT)



      CALL CHI004



      CALL DSP003




      CALL ESPSET (ES0,ESZ,57)



      CALL CDB013 ('C12CHKERR','C12CHKNEU',' ')




      CALL GVSCCC (LINE2,FILDIR(27),'CHI001.CHI')
      CALL SCN203B (LINE2,'INTEGER',IERR)
      IF (IERR.NE.0) GOTO 998
      CALL GVSCPI (D1,GENVI4,MAXADB*MAXSEQ)
      CALL GVSCCC (LINE2,FILDIR(27),'CHI002.CHI')
      CALL SCN203B (LINE2,'INTEGER',IERR)
      IF (IERR.NE.0) GOTO 998
      CALL GVSCPI (D2,GENVI4,MAXADB*MAXSEQ)



      DO 100 IST=1,3
         DO 200 IRT=1,20
            IF (IRT.EQ.1.OR.IRT.EQ.6.OR.IRT.EQ.13.OR.IRT.EQ.21) GOTO 200
            CST=ICHAR(ST(IST:IST))



            CST=ICHAR(ST(IST:IST))
            DO 500 IAA=1,NUMAAT
               IF (RESTYP(IAA).NE.IRT) GOTO 500
               IF (ICHAR(LOCHST(IAA)).NE.CST) GOTO 500
               IF (PRPVAL(IAA).GT.-100.0) GOTO 500
               GOTO 550
  500       CONTINUE



            GOTO 200



  550       CONTINUE
            CALL SC6008 (IST,IRT,AVER,STDEV)
            IF (INTERRUPTED()) GOTO 998



            DO 600 IAA=1,NUMAAT
               IF (RESTYP(IAA).NE.IRT) GOTO 600
               IF (.NOT.WIFROK(IAA)) GOTO 600
               IF (ICHAR(LOCHST(IAA)).NE.CST) GOTO 600
               IF (PRPVAL(IAA).GT.-100.0) GOTO 600
               K1=NINT(GVFRTD(CHIANG(4,IAA)))
               K2=NINT(GVFRTD(CHIANG(5,IAA)))
               IF (K1.EQ.-180) K1=180
               IF (K2.EQ.-180) K2=180
               PRPVAL(IAA)=0.0
               DO 610 J1=K1-5,K1+5
                  I1=IND(J1)
                  DO 620 J2=K2-5,K2+5
                     I2=IND(J2)
                     PRPVAL(IAA)=PRPVAL(IAA)+BONK(I1,I2)/121.0
  620             CONTINUE
  610          CONTINUE
               PRPVAL(IAA)=(PRPVAL(IAA)-AVER)/STDEV
               IF (PRPVAL(IAA).LT.-3.0) THEN
                  CALL DIF002 (6,IAA,PRPVAL(IAA))
               END IF
  600       CONTINUE
  200    CONTINUE
  100 CONTINUE



      SUM=0.0
      SUM2=0.0
      NUM=0
      CALL GVSIT0 (NNUM,MAXMODEL)
      CALL GVSRT0 (NSUM,MAXMODEL)
      DO 700 IAA=1,NUMAAF
         IF (PRPVAL(IAA).GT.-100.0) THEN
            NUM=NUM+1
            SUM=SUM+PRPVAL(IAA)
            SUM2=SUM2+PRPVAL(IAA)**2
            IF (MODNMB(IAA).GT.0.AND.MODNMB(IAA).LE.MAXMODEL) THEN
               NNUM(MODNMB(IAA))=NNUM(MODNMB(IAA))+1
               NSUM(MODNMB(IAA))=NSUM(MODNMB(IAA))+PRPVAL(IAA)
            END IF
         END IF
  700 CONTINUE



      IF (NUM.GT.0) THEN




         IF (WIFPAR(919).EQ.0) THEN
            GENRVL(31)=(SUM/NUM-SIGMAP(3))/SIGMAP(4)
         ELSE
            GENRVL(31)=SUM/NUM
         END IF



         CALL GVSTTR ('?PDHDR38',GENRVL(31))
         IF (GENRVL(31).LT.-4.0) THEN
            CALL PDBMES ('CHI12BAD')
         ELSE IF (GENRVL(31).LT.-3.0) THEN
            CALL PDBMES ('CHI12POOR')
         ELSE
            CALL PDBMES ('CHI12OK')
         END IF
      END IF



      ACTIVE=0
      DO 300 IMOD=1,NUMMDL()
         IF (NNUM(IMOD).GT.0) THEN
            ACTIVE=ACTIVE+1
            NMRVAL(1,IMOD)=(NSUM(IMOD)/NNUM(IMOD)-SIGMAP(3))/SIGMAP(4)
         ELSE
            NMRVAL(1,IMOD)=-999.9
         END IF
  300 CONTINUE
      VALACT=1
      IF (ACTIVE.GT.1) CALL PDBMES ('C12NMR')



      CALL CDB012



      CALL ESPKIL (ES0,ESZ,57,'SC6004')



  998 CONTINUE
      WIFPAR(156)=0


      RETURN
      END
      SUBROUTINE SC6005



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'ETMINC.INC'
      INCLUDE       'PDBINC.INC'
      INTEGER       IAA, ISOUP, MAXIAA, GVFLEN
      REAL          MAXVAL
      LOGICAL       HASPROTEIN, WIFISA, MEMBND
      CHARACTER*23  DIF001, IAAS







      IF (.NOT.HASPROTEIN()) THEN
         CALL PDBMES ('R00016')
         GOTO 998
      END IF
      IF (NUMAAF.LT.5) THEN
         CALL GVSTTE ('?>5AA')
         GOTO 998
      END IF



      CALL WIF415
      IF (WIFPAR(51).NE.5) CALL WIF019 (5)
      CALL WIFPUSHPPP (564,1)
      WIFPAR(524)=1
      CALL GVSRTC (PRPVAL,-1000.0,MAXAA)
      CALL GVSBTF (WRK1TF,MAXAA)



      CALL CDB013 ('BADBBOX','NEUBBOX','GOODBBOX')



      DO 21 ISOUP=1,NUMSOU
         IF (.NOT.WIFISA(ISOUP)) GOTO 21
         IF (SOUADM(3,ISOUP).LT.5) GOTO 21
         DO 10 IAA=SOUADM(1,ISOUP)+2,SOUADM(2,ISOUP)-2
            MEMBND=NOBOND(IAA)
            NOBOND(IAA)=.TRUE.
            CALL WIF407 (IAA,PRPVAL(IAA))
            NOBOND(IAA)=MEMBND
            ETMTOT(MAXETM,IAA)=FLOAT(WIFPAR(54))
            IAAS=DIF001(IAA)
            CALL GVSCTB (LINE92,92)
            IF (PRPVAL(IAA).GT.5.0.OR.WIFPAR(54).LT.10) THEN
               PRPVAL(IAA)=-1000.0
               CALL GVSFMT ('?FMT575')
               WRITE (LINE92,FMT,ERR=997) IAAS,WIFPAR(54)
            ELSE
               CALL GVSFMT ('?FMT574')
               WRITE (LINE92,FMT,ERR=997) IAAS,PRPVAL(IAA),WIFPAR(54)
            END IF
   10    CONTINUE
   21 CONTINUE



 30   CONTINUE
      MAXVAL=1.5
      MAXIAA=0
      DO 20 IAA=1,NUMAAF
         IF (.NOT.WRK1TF(IAA).AND.PRPVAL(IAA).GT.MAXVAL) THEN
            MAXVAL=PRPVAL(IAA)
            MAXIAA=IAA
         END IF
 20   CONTINUE
      IF (MAXIAA.GT.0) THEN
         IAA=MAXIAA
         CALL PDBC92A (IAA,0)
         WRITE (LINE2,PDBFMT,ERR=999) LINE92(1:GVFLEN(LINE92)),
     +    PRPVAL(IAA),NINT(ETMTOT(MAXETM,IAA))
         CALL PDBC93 (LINE2)
         WRK1TF(IAA)=.TRUE.
         GOTO 30
      END IF



      CALL CDB012



      CALL WIFPOPPPP (564)
      GOTO 998



  997 CONTINUE
      CALL GVSEIW ('SC6005')
      GOTO 998



  999 CONTINUE
      CALL GVSTTE ('?R00010')



  998 CONTINUE


      RETURN
      END
      SUBROUTINE SC6006


















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'PDBINC.INC'
      INTEGER       ISOUP, IAA, ILOW, GVFLEN
      REAL          LOWVAL
      LOGICAL       WIFIRA, HASPROTEIN, WIFISA
      CHARACTER*23  DIF001, IAAS







      IF (.NOT.HASPROTEIN()) THEN
         CALL PDBMES ('R00017')
         GOTO 998
      END IF



      CALL GRTVIN
      CALL GVSRTC (PRPVAL,-999.9,MAXAA)
      CALL GVSBTF (WRK1TF,MAXAA)
      CALL WIF019 (5)



      CALL CDB013 ('ROTNOK','ROTNEU','ROTOK')



      DO 20 ISOUP=1,NUMSOU
         IF (.NOT.WIFISA(ISOUP)) GOTO 20
         IF (SOUADM(3,ISOUP).LT.5) GOTO 20
         DO 10 IAA=SOUADM(1,ISOUP)+2,SOUADM(2,ISOUP)-2



            IF (.NOT.WIFIRA(IAA)) GOTO 10



            IF (RESTYP(IAA).GT.20) GOTO 10




            CALL DGM004C (IAA,RESTYP(IAA),PRPVAL(IAA))
            PRPVAL(IAA)=PRPVAL(IAA)*FLOAT(WIFPAR(55))/
     +       MAX(FLOAT(WIFPAR(54)),1.0)
            WRK1TF(IAA)=(PRPVAL(IAA).LT.0.999)



            IF (RESTYP(IAA).EQ.6.OR.RESTYP(IAA).EQ.13.OR.
     +          RESTYP(IAA).EQ.1.OR.RESTYP(IAA).EQ.21.OR.
     +          WIFPAR(54).LE.10) THEN
               PRPVAL(IAA)=-999.0
               WRK1TF(IAA)=.FALSE.
            END IF



            IAAS=DIF001(IAA)
            IF (PRPVAL(IAA).GT.-90.0) THEN
               CALL GVSFMT ('?FMT1139')
               WRITE (LINE,FMT,ERR=999) IAAS,PRPVAL(IAA),WIFPAR(54)
            ELSE
               CALL GVSFMT ('?FMT1140')
               WRITE (LINE,FMT,ERR=999) IAAS,WIFPAR(54)
            END IF
            IF (WIFPAR(279).EQ.0) CALL GVSTT6 (LINE)



            CALL GRTVIN
   10    CONTINUE
   20 CONTINUE



      CALL GVSBTT (WRK1TF,NUMAAF)
   60 CONTINUE
      LOWVAL=0.40
      ILOW=0
      DO 50 IAA=3,NUMAAF-2
         IF (WRK1TF(IAA).AND.
     +        PRPVAL(IAA).LT.LOWVAL.AND.PRPVAL(IAA).GT.-90.0) THEN
            LOWVAL=PRPVAL(IAA)
            ILOW=IAA
         END IF
   50 CONTINUE
      IF (ILOW.GT.0) THEN
         IAA=ILOW
         WRK1TF(IAA)=.FALSE.
         CALL PDBC92A (IAA,0)
         WRITE (LINE2,PDBFMT,ERR=999) LINE92(1:GVFLEN(LINE92)),
     +    PRPVAL(IAA)
         CALL PDBC93 (LINE2)
         GOTO 60
      END IF



      CALL CDB012
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('SC6006')



  998 CONTINUE


      RETURN
      END
      SUBROUTINE SC6007



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC' 
      INCLUDE       'ESPACE.INC'
      INTEGER       NUMHIT(MAXAA)
      LOGICAL       HASPROTEIN
      EQUIVALENCE   (NUMHIT,ESPACE(MAXESP-300000+1))







      IF (.NOT.HASPROTEIN()) THEN
         CALL PDBMES ('R00121')
         GOTO 998
      END IF
      CALL ESPSET (MAXESP-300000+1,MAXESP-300000+1+2*MAXAA,58)



      CALL DSP001 (.FALSE.)
      CALL DSP003
      CALL WIF412
      CALL PRP014B (1,NUMAAF,NUMHIT)
      CALL WIF413



      CALL SC6009 (NUMHIT)
      CALL SC6010



      CALL ESPKIL (MAXESP-300000+1,MAXESP-300000+1+2*MAXAA,
     + 58,'SC6007')



  998 CONTINUE


      RETURN
      END
      SUBROUTINE SC6008 (IST,IRT,AVER,STDEV)



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'DATBAS.INC'
      INCLUDE       'ESPACE.INC'
      INTEGER       SZ, CW, ES0
      PARAMETER     (CW=5)
      PARAMETER     (SZ=360/CW)
      PARAMETER     (ES0=100001)
      INTEGER       D1(MAXADB,MAXSEQ), D2(MAXADB,MAXSEQ), IND, I1, I2, 
     +              IRT, IST, IAA, ISEQ, INANG, J1, J2,
     +              ILHST(MAXADB,MAXSEQ)
      REAL          SUM, SUM2, NUM, AVER, STDEV, BONK(SZ,SZ)
      LOGICAL       JACKIT
      EQUIVALENCE   (D1,   ESPACE(ES0))
      EQUIVALENCE   (D2,   ESPACE(ES0+1*MAXADB*MAXSEQ))
      EQUIVALENCE   (ILHST,ESPACE(ES0+2*MAXADB*MAXSEQ))
      EQUIVALENCE   (BONK, ESPACE(ES0+3*MAXADB*MAXSEQ))



      IND(INANG)=MOD((INANG+180)/CW,SZ)+1







      CALL GVSRT0 (BONK,SZ**2)



      DO 300 ISEQ=1,NBINDB



         IF (JACKIT(ISEQ,2)) GOTO 300
         DO 400 IAA=1,NAAFIL(ISEQ)
            IF (IRT.EQ.0) THEN
               IF (ALLSEQ(IAA,ISEQ).EQ.13.OR.
     +             ALLSEQ(IAA,ISEQ).EQ.21.OR.
     +             ALLSEQ(IAA,ISEQ).EQ.6) GOTO 400
            ELSE
               IF (ALLSEQ(IAA,ISEQ).NE.IRT) GOTO 400
            END IF
            IF (ILHST(IAA,ISEQ).NE.IST) GOTO 400
            IF (ABS(D1(IAA,ISEQ)).GT.500) GOTO 400
            IF (ABS(D2(IAA,ISEQ)).GT.500) GOTO 400
            IF (D1(IAA,ISEQ).EQ.-180) D1(IAA,ISEQ)=180
            IF (D2(IAA,ISEQ).EQ.-180) D2(IAA,ISEQ)=180
            DO 420 J1=D1(IAA,ISEQ)-5,D1(IAA,ISEQ)+5
               I1=IND(J1)
               DO 410 J2=D2(IAA,ISEQ)-5,D2(IAA,ISEQ)+5
                  I2=IND(J2)
                  BONK(I1,I2)=BONK(I1,I2)+1.0/121.0
  410          CONTINUE
  420       CONTINUE
  400    CONTINUE
  300 CONTINUE



      SUM=0.0
      SUM2=0.0
      NUM=0.0
      DO 490 I2=1,SZ
         DO 480 I1=1,SZ
            NUM=NUM+BONK(I1,I2)
            SUM=SUM+BONK(I1,I2)**2
            SUM2=SUM2+BONK(I1,I2)**3
  480    CONTINUE
  490 CONTINUE
      IF (NUM.LT.2) THEN
         CALL GVSTTB ('?R00291')
         AVER=0.0
         STDEV=1000.0
      ELSE
         AVER=SUM/NUM
         STDEV=SQRT((SUM2-SUM**2/NUM)/(NUM-1))
      END IF





      RETURN
      END
      SUBROUTINE SC6009 (NUMHIT)



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'PDBINC.INC'
      INTEGER       NUMHIT(MAXAA), IAA, I, GVFLEN







      CALL CDB013 ('BBNOK','BBNEU','BBOK')



      DO 160 I=0,2
         DO 150 IAA=3,NUMAAF-2
            IF (NUMHIT(IAA).EQ.I) THEN
               CALL PDBC92A (IAA,0)
               WRITE (BIGLIN,PDBFMT,ERR=999) LINE92(1:GVFLEN(LINE92)),
     +          NUMHIT(IAA)
               CALL PDBC93 (BIGLIN)
            END IF
  150    CONTINUE
  160 CONTINUE




      CALL GVSRTC (PRPVAL,-1000.0,NUMAAT)
      DO 250 IAA=3,NUMAAF-2
         PRPVAL(IAA)=FLOAT(NUMHIT(IAA))
  250 CONTINUE



      CALL CDB012
      GOTO 998



 999  CONTINUE
      CALL GVSEIW ('SC6009')
      CALL GVST6C ('?M5122',PDBFMT,.FALSE.)
      CALL GVST6C ('?M5127',LINE92,.FALSE.)
      CALL GVSTTI ('?M5128',NUMHIT)



 998  CONTINUE


      RETURN
      END
      SUBROUTINE SC6010



















      IMPLICIT      NONE
      INCLUDE       'RESULT.INC'









      IF (GENRVL(34).LT.-4.0) THEN
         CALL PDBMES ('BADBBC')
      ELSE IF (GENRVL(34).LT.-2.0) THEN
         CALL PDBMES ('POORBBC')
      ELSE
         CALL PDBMES ('OKBBC')
      END IF


















            
      RETURN
      END
      SUBROUTINE SC6011



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'PDBINC.INC'
      INTEGER       IAA, IAT, IHAT
      REAL          VALUE, CHI001, GVFRTD
      LOGICAL       ANY







      IF (WIFPAR(84).EQ.0) GOTO 998



      CALL GVSRTC (PRPVAL,-9999.9,NUMAAT)



      ANY=.FALSE.
      DO 100 IAA=1,NUMAAF
         IF (RESTYP(IAA).EQ.3) THEN
            IAT=PNTAAS(IAA)+7
         ELSE IF (RESTYP(IAA).EQ.4) THEN
            IAT=PNTAAS(IAA)+8
         ELSE 
            GOTO 100
         END IF
         IF (.NOT.ISATOK(IAT)) GOTO 100
         IHAT=BOUND_TO(1,IAT)
         IF (IHAT.EQ.0) IHAT=BOUND_TO(2,IAT)
         IF (IHAT.EQ.0) GOTO 100
         IF (.NOT.ANY) THEN
            ANY=.TRUE.
            CALL CDB013 ('GLUASPHER','GLUASPHN','GLUASPHOK')
         END IF
         VALUE=GVFRTD(CHI001(IAT-3,IAT-2,IAT,IHAT))
         IF (ABS(VALUE).LT.160.0) THEN
            CALL PDBC92A (IAA,0)
            WRITE (LINE2,PDBFMT,ERR=999) LINE92(1:23),VALUE
            CALL PDBC93 (LINE2)
            PRPVAL(IAA)=ABS(VALUE)
         END IF
  100 CONTINUE
      IF (ANY) CALL CDB012
      GOTO 998



 999  CONTINUE
      CALL GVSEIW ('SC6011')



  998 CONTINUE


      RETURN
      END
