



      SUBROUTINE CHI000 (DONE)


















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'OPTION.INC'
      LOGICAL       DONE







      IF (OPTIN.EQ.MEN6COD(6)) GOTO 998
      CALL MEN002 (OPTIN,DONE)



  998 CONTINUE


      RETURN
      END



      SUBROUTINE CHI003 (IFT1,IFT2)


















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'CHIANG.INC'
      REAL          GVFRTD
      INTEGER       IFT1, IFT2, IAA, I, IERR
      LOGICAL       WIFIRR
      CHARACTER*23  DIF001, IAAS










      CALL CHI004



      CALL GVSBTF (WRK1TF,MAXAA)
      IF (IFT1.NE.0) THEN
         DO 10 IAA=IFT1,IFT2
            WRK1TF(IAA)=.TRUE.
   10    CONTINUE
      ELSE
         CALL WIFWTF (' ',IERR)
         IF (IERR.NE.0) GOTO 998
      END IF



      CALL GVSNL6 (1)
      CALL GVSTT6 ('?CHIHED')
      CALL GVSNL6 (1)



      CALL GVSFMT ('?FMT295')
      DO 20 IAA=1,NUMAAF
         IF (.NOT.WRK1TF(IAA)) GOTO 20
         IAAS=DIF001(IAA)
         IF (RESTYP(IAA).LE.0) THEN
            CALL GVSTTI ('?CHIB02',IAA)
         ELSE IF (WIFIRR(IAA)) THEN
            WRITE (BIGLIN,FMT,ERR=999) IAAS,
     +       (GVFRTD(CHIANG(I,IAA)),I=1,3+CHIUSE(RESTYP(IAA)))
            CALL GVSTT6 (BIGLIN)
         ELSE 
            WRITE (BIGLIN,FMT,ERR=999) IAAS,
     +       (GVFRTD(CHIANG(I,IAA)),I=1,CHIUSE(RESTYP(IAA)))
            CALL GVSTT6 (BIGLIN)
         END IF
   20 CONTINUE
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('CHI003')



  998 CONTINUE


      RETURN
      END
      SUBROUTINE CHI004

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'CHIANG.INC'
      REAL          GVFDTR
      INTEGER       ISOUP, IAA
      LOGICAL       WIFIR6, WIFIRA







      IF (NUMAAF.LT.1) GOTO 998



      DO 5 IAA=1,NUMAAT
         CHIANG(1,IAA)=GVFDTR(999.9)
         CHIANG(2,IAA)=GVFDTR(999.9)
         CHIANG(3,IAA)=GVFDTR(999.9)
         CHIANG(4,IAA)=0.0
         CHIANG(5,IAA)=0.0
         CHIANG(6,IAA)=0.0
         CHIANG(7,IAA)=0.0
         CHIANG(8,IAA)=0.0
    5 CONTINUE



      DO 100 ISOUP=1,NUMSOU



         IF (RESTYP(SOUADM(1,ISOUP)).LE.0) GOTO 100
         IF (WIFIR6(SOUADM(1,ISOUP))) THEN
            CALL CHI004A (SOUADM(1,ISOUP))
            GOTO 100
         END IF




         IF (SOUADM(1,ISOUP).EQ.SOUADM(2,ISOUP)) GOTO 100
         DO 50 IAA=SOUADM(1,ISOUP),SOUADM(2,ISOUP)
            IF (WIFIRA(IAA)) CALL CHI012 (IAA)
 50      CONTINUE
 100  CONTINUE



 998  CONTINUE


      RETURN
      END
      SUBROUTINE CHI004A (IAA)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'CHIANG.INC'
      INTEGER       IAA, ICHI
      REAL          CHI001
      LOGICAL       WIFIRR







      CALL GVSRT0 (CHIANG(1,IAA),8)



      IF (.NOT.WIFIRR(IAA)) GOTO 998



      DO 10 ICHI=1,MIN(CHIUSE(RESTYP(IAA)),8)
         IF (CHICON(1,ICHI,RESTYP(IAA)).EQ.0) GOTO 998
         CHIANG(ICHI,IAA)=CHI001(
     +    (PNTAAS(IAA)-1+CHICON(1,ICHI,RESTYP(IAA))),
     +    (PNTAAS(IAA)-1+CHICON(2,ICHI,RESTYP(IAA))),
     +    (PNTAAS(IAA)-1+CHICON(3,ICHI,RESTYP(IAA))),
     +    (PNTAAS(IAA)-1+CHICON(4,ICHI,RESTYP(IAA))))
   10 CONTINUE



  998 CONTINUE


      RETURN
      END
      SUBROUTINE CHI006 (JFT1,JFT2)


















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      LOGICAL       HASPROTEIN
      INTEGER       IFT1, IFT2, JFT1, JFT2








      IF (.NOT.HASPROTEIN()) THEN
         CALL PDBMES ('R00015')
         GOTO 998
      END IF
      IF (NUMAAF.LT.3) THEN
         CALL GVSTTE ('?STRB01')
         GOTO 998
      END IF



      CALL SETIFT (IFT1,IFT2,JFT1,JFT2)
      IF (IFT1.EQ.0) GOTO 998



      IF (WIFPAR(279).EQ.0) CALL SHOWTEXT ('?CHIEVT')



      CALL CHI006A (IFT1,IFT2)
      CALL CHI006B (IFT1,IFT2)



  998 CONTINUE


      RETURN
      END
      SUBROUTINE CHI006A (IFT1,IFT2)





















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'CHIANG.INC'
      INCLUDE       'ESPACE.INC'   
      INCLUDE       'PDBINC.INC'
      INTEGER       I, IFT1, IFT2, IERR, TAG(MAXAA), IAA, ITEMP, 
     +              IAATYP, GVFLEN, IUNIT
      REAL          VALUE(8,20,360), SIGMA(20), VALNOR(20),
     +              SUMAA, GVFRTD, VAL(MAXAA)
      LOGICAL       GVFIBN, WIFROK
      CHARACTER*23  IAAS, DIF001
      EQUIVALENCE   (TAG,   ESPACE(1001))
      EQUIVALENCE   (VAL,   ESPACE(1001+MAXAA))
      EQUIVALENCE   (VALUE, ESPACE(1001+2*MAXAA))







      IUNIT=0
      CALL ESPSET (1001,1000+2*MAXAA+8*20*360,8)
      CALL GVSRTC (PRPVAL,-1000.0,MAXAA)



      CALL GVSROF (IUNIT,IERR)
      IF (IUNIT.EQ.0.OR.IERR.NE.0) GOTO 997
      CALL SETFILNAM (LINE,'EVACHI.CHI',IERR)
      IF (IERR.NE.0) GOTO 997
      CALL GETFILE (IUNIT,' ',LINE,IERR)
      IF (IERR.NE.0) GOTO 997



      CALL GVSFMT ('?FMT387')
      READ (IUNIT,FMT,ERR=999) VALUE
      CALL GVSFMT ('?FMT388')
      DO 10 I=1,20
         READ (IUNIT,FMT,ERR=999) VALNOR(I),SIGMA(I)
   10 CONTINUE
      IF (IUNIT.NE.0) CALL GVSCLF (IUNIT)



      CALL CHI004



      CALL CDB013 ('BADCHIS','NEUCHIS','OKCHIS')



      CALL GVSFMT ('?FMT389')
      DO 60 IAA=IFT1,IFT2



         IF (CHAINN(1,IAA).NE.2) GOTO 60
         IAATYP=RESTYP(IAA)
         IF (.NOT.GVFIBN(IAATYP,1,20)) GOTO 60
         IF (.NOT.WIFROK(IAA)) GOTO 60



         SUMAA=0.0
         DO 50 I=1,CHIUSE(IAATYP)+3
            IF (I.EQ.3) GOTO 50
            ITEMP=NINT(GVFRTD(CHIANG(I,IAA))+180.5)
            IF (ITEMP.LT.1) ITEMP=1
            IF (ITEMP.GT.360) ITEMP=360
            SUMAA=SUMAA+VALUE(I,IAATYP,ITEMP)
   50    CONTINUE



         PRPVAL(IAA)=(SUMAA-VALNOR(RESTYP(IAA)))/SIGMA(RESTYP(IAA))



         IF (WIFPAR(279).LT.1) THEN
            IAAS=DIF001(IAA)
            WRITE (LINE,FMT,ERR=998) IAAS,PRPVAL(IAA)
            CALL GVSTT6 (LINE)
         END IF
   60 CONTINUE



      DO 100 I=1,NUMAAF
         IF (PRPVAL(I).GT.-999.0) THEN
            VAL(I)=PRPVAL(I)
         ELSE
            VAL(I)=1000.0
         END IF
         TAG(I)=I
  100 CONTINUE
      CALL GVSORT (VAL,NUMAAF,TAG)



      DO 300 I=1,NUMAAF
         IAA=TAG(I)
         IF (PRPVAL(IAA).GT.-2.0.OR.PRPVAL(IAA).LT.-999.9) THEN
            PRPVAL(IAA)=0
            GOTO 301
         END IF
         CALL PDBS51 (IAA,4.1,4.0,50.0)
         CALL PDBC92A (IAA,0)
         WRITE (LINE2,PDBFMT,ERR=998) LINE92(1:GVFLEN(LINE92)),
     +    PRPVAL(IAA)
         CALL PDBC93 (LINE2)
  300 CONTINUE
  301 CONTINUE



      CALL CDB012



      CALL ESPKIL (1001,1000+2*MAXAA+8*20*360,8,'CHI006A')
      GOTO 996



  999 CONTINUE
      CALL GVSTTE ('?M1600')
      GOTO 996



  998 CONTINUE
      CALL GVSEIW ('CHI006A')
      GOTO 996



  997 CONTINUE
      CALL GVSTTE ('?M1601')



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


      RETURN
      END
      SUBROUTINE CHI006B (IFT1,IFT2)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'CHIANG.INC'
      INCLUDE       'PDBINC.INC'
      LOGICAL       GVFIBN, GVFRIN
      REAL          GVFRTD
      INTEGER       IFT1, IFT2, GVFLEN, LENLIN, IAA, IAATYP
      CHARACTER*23  IAAS, DIF001







      CALL CHI004



      CALL CDB013 ('BADCHI2',' ','OKCHI2')



      DO 60 IAA=IFT1,IFT2



         IF (CHAINN(1,IAA).NE.2) GOTO 60
         IAATYP=RESTYP(IAA)
         IF (.NOT.GVFIBN(IAATYP,1,20)) GOTO 60



         CALL GVSCTB (LINE2,80)
         CALL CHI007 (IAA)








         IF (ONESA3(IAA+1).NE.'PRO '.AND.ONESA3(IAA+1).NE.'HYP ') THEN



            IF (GVFRIN(GVFRTD(CHIANG(3,IAA)),-165.4,164.4)) THEN
               IF (GVFLEN(LINE2).EQ.0) THEN
                  CALL GVSCPC (LINE2,'?M1429')
               ELSE
                  CALL GVSCPC (LINE2,'?M1430')
               END IF
            END IF
         ELSE
            IF (ABS(CHIANG(3,IAA)).LT.90.0) THEN



               IF (GVFRIN(GVFRTD(CHIANG(3,IAA)),-160.8,159.8)) THEN
                  IF (GVFLEN(LINE2).EQ.0) THEN
                     CALL GVSCPC (LINE2,'?M1431')
                  ELSE
                     CALL GVSCPC (LINE2,'?M1432')
                  END IF
               END IF
            ELSE



               IF (.NOT.GVFRIN(GVFRTD(CHIANG(3,IAA)),-27.4,26.0)) THEN
                  IF (GVFLEN(LINE2).EQ.0) THEN
                     CALL GVSCPC (LINE2,'?M1433')
                  ELSE
                     CALL GVSCPC (LINE2,'?M1434')
                  END IF
               END IF
            END IF
         END IF



         LENLIN=GVFLEN(LINE2)
         IF (LENLIN.GT.0) THEN
            CALL PDBC92A (IAA,0)
            WRITE (BIGLIN,PDBFMT,ERR=998) LINE92(1:GVFLEN(LINE92)),
     +       LINE2(1:MIN(43,LENLIN))
            CALL PDBS51 (IAA,4.1,4.0,100.0)
            CALL PDBC93 (BIGLIN)
            IF (WIFPAR(279).LT.1) THEN



               IAAS=DIF001(IAA)
               CALL GVSFMT ('?FMT390')
               WRITE (BIGLIN,FMT,ERR=998) IAAS,LINE2(1:MIN(43,LENLIN))
               CALL GVSTT6 (BIGLIN)
            END IF
         END IF
   60 CONTINUE



      CALL CDB012
      GOTO 997



  998 CONTINUE
      CALL GVSEIW ('CHI006B')



  997 CONTINUE



      RETURN
      END
      SUBROUTINE CHI006D (IFT1,IFT2)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'CHIANG.INC'
      LOGICAL       GVFIBN, GVFRIN
      REAL          GVFRTD
      INTEGER       IFT1, IFT2, GVFLEN, LENLIN, IAA, IAATYP
      CHARACTER*23  IAAS, DIF001







      CALL GVSNL6 (1)
      CALL GVSTT6 ('?M1553')
      CALL GVSNL6 (1)



      DO 60 IAA=IFT1,IFT2



         IF (CHAINN(1,IAA).NE.2) GOTO 60
         IAATYP=RESTYP(IAA)
         IF (.NOT.GVFIBN(IAATYP,1,20)) GOTO 60



         CALL GVSCTB (LINE2,80)
         CALL CHI007 (IAA)








         IF (ONESA3(IAA+1).NE.'PRO '.AND.ONESA3(IAA+1).NE.'HYP ') THEN



            IF (GVFRIN(GVFRTD(CHIANG(3,IAA)),-165.4,164.4)) THEN
               IF (GVFLEN(LINE2).EQ.0) THEN
                  CALL GVSCPC (LINE2,'?M1429')
               ELSE
                  CALL GVSCPC (LINE2,'?M1430')
               END IF
            END IF
         ELSE
            IF (ABS(CHIANG(3,IAA)).LT.90.0) THEN



               IF (GVFRIN(GVFRTD(CHIANG(3,IAA)),-160.8,159.8)) THEN
                  IF (GVFLEN(LINE2).EQ.0) THEN
                     CALL GVSCPC (LINE2,'?M1431')
                  ELSE
                     CALL GVSCPC (LINE2,'?M1432')
                  END IF
               END IF
            ELSE



               IF (.NOT.GVFRIN(GVFRTD(CHIANG(3,IAA)),-27.4,26.0)) THEN
                  IF (GVFLEN(LINE2).EQ.0) THEN
                     CALL GVSCPC (LINE2,'?M1433')
                  ELSE
                     CALL GVSCPC (LINE2,'?M1434')
                  END IF
               END IF
            END IF
         END IF



         LENLIN=GVFLEN(LINE2)
         IAAS=DIF001(IAA)
         CALL GVSFMT ('?FMT390')
         WRITE (BIGLIN,FMT,ERR=998) IAAS,LINE2(1:MAX(1,LENLIN))
         CALL GVSTT6 (BIGLIN)
   60 CONTINUE
      GOTO 997



  998 CONTINUE
      CALL GVSEIW ('CHI006D')



  997 CONTINUE


      RETURN
      END
      SUBROUTINE CHI007 (IAA)



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'CHIANG.INC'
      INTEGER       IPSI, IPHI, IAA, COMMAA(37,37), GLYCIN(37,37)
      REAL          PHI, PSI, GVFRTD
      SAVE          COMMAA, GLYCIN
      DATA COMMAA  /0,12*1,25*0,12*1,24*0,
     +              334*0,15*1,21*0,
     +              0,15*1,22*0,2*1,10*2,3*1,21*0,
     +              0,6*1,6*2,3*1,27*0,10*1,21*0, 
     +              6*0,9*1,27*0,9*1,23*0,
     +              4*0,9*1,27*0,9*1,25*0,
     +              2*0,10*1,11*0,1,14*0,10*1,11*0,2*1,13*0,
     +              0,10*1,11*0,2*1,14*0,9 *1,12*0,2*1,13*0,
     +              0,9*1,12*0,2*1,14*0,10*1,11*0,2*1,13*0, 
     +              0,12*1,9*0,2*1,14*0,15*1,6*0,2*1,13*0,
     +              0,2*1,10*2,3*1,7*0,1,14*0,2*1,10*2,3*1,21*0,
     +              0,2*1,10*2,3*1,22*0,2*1,10*2,3*1,21*0,
     +              0,2*1,10*2,3*1,22*0,3*1,9*2,2*1,22*0, 
     +              0,3*1,9*2,2*1,23*0,4*1,8*2,1,23*0,
     +              0,13*1,23*0 / 
      DATA GLYCIN  /4*1,9*2,1,10*0,1,8*2,8*1,9*2,11*0,9*2,4*1,
     +              3*1,10*2,10*0,1,9*2,6*1,10*2,1,10*0,1,9*2,4*1,
     +              12*2,11*0,1,10*2,2*1,13*2,11*0,1,13*2,12*2,11*0,1,
     +              25*2,1,10*0,1,13*2,13*2,10*0,1,26*2,1,10*0,1,12*2, 
     +              13*2,1,11*0,2*1,23*2,1,11*0,2*1,10*2, 
     +              13*2,1,11*0,3*1,22*2,1,12*0,2*1,9*2,
     +              1,6*0,1,5*2,1,12*0,2*1,8*2,1,8*0,6*1,13*0,9*1,0,
     +              8*0,6*1,13*0,7*1,8*0,9*1,9*0,9*1,5*0,4*0,9*1,11*0,
     +              9*1,9*0,9*1,9*0,9*1,5*0,3*0,7*1,13*0,6*1,9*0,9*1,
     +              13*0,6*1,8*0,1,8*2,2*1,12*0,1,5*2,1,6*0,1,9*2,2*1,
     +              12*0,1,13*2,9*2,3*1,11*0,1,23*2,2*1,11*0,1,13*2,
     +              10*2,2*1,11*0,1,25*2,1,10*0,1,13*2,13*2,1,10*0,26*2,
     +              1,10*0,1,12*2,13*2,1,11*0,25*2,1,11*0,12*2, 
     +              2,2*1,10*2,1,11*0,12*2,4*1,9*2,1,10*0,1,10*2,2*1, 
     +              4*1,9*2,1,10*0,10*2,7*1,9*2,11*0,9*2,4*1, 
     +              4*1,8*2,1,10*0,1,9*2,4*1  / 







      CALL GVSCTB (LINE2,80)
      PHI  = GVFRTD(CHIANG(1,IAA))+180.0
      PSI  = GVFRTD(CHIANG(2,IAA))+180.0
      IPHI = NINT(PHI/10.0)+1
      IPSI = NINT(PSI/10.0)+1



      IF (IPHI.LT.1.OR.IPHI.GT.37) THEN
         CALL GVSSTX (LINE2,'?CHIPHI')
         GOTO 998
      END IF



      IF (IPSI.LT.1.OR.IPSI.GT.37) THEN
         CALL GVSSTX (LINE2,'?CHIPSI')
         GOTO 998
      END IF



      IF (ONESA3(IAA)(1:3).EQ.'GLY') THEN
         IF (GLYCIN(IPHI,IPSI).EQ.0) THEN
            CALL GVSSTX (LINE2,'?CHIPPI')
            PRPVAL(IAA)=1.0
            GOTO 998
         END IF
      ELSE IF (COMMAA(IPHI,IPSI).EQ.0) THEN
         CALL GVSSTX (LINE2,'?CHIPPI')
         PRPVAL(IAA)=1.0
         GOTO 998
      END IF



      IF (ONESA3(IAA)(1:3).EQ.'PRO'.OR.ONESA3(IAA)(1:3).EQ.'HYP') THEN
         IF (PHI.LT.100.0 .OR. PHI.GT.140.0) THEN
            CALL GVSSTX (LINE2,'?CHIPRO')
            PRPVAL(IAA)=2.0
            GOTO 998
         END IF
      END IF



      IF (ONESA3(IAA+1)(1:3).NE.'PRO'.OR.PSI.GT.60) GOTO 998
      IF (ONESA3(IAA+1)(1:3).NE.'HYP'.OR.PSI.GT.60) GOTO 998
      IF (ONESA3(IAA)(1:3).EQ.'GLY'.AND.PSI.LT.60) GOTO 998
      CALL GVSSTX (LINE2,'?CHISPR')
      PRPVAL(IAA)=3.0



  998 CONTINUE


      RETURN
      END

      SUBROUTINE CHI009 (IAATYP,IANG)



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'CHIANG.INC'
      INTEGER       IANG, ITOUSE, Ierr, IAATYP
      LOGICAL       GVFIBN
      CHARACTER*1   CINP
      CHARACTER*8   CTOTAL
      SAVE          CTOTAL
      DATA CTOTAL   /'FPO12345'/







      IANG=0
      ITOUSE=CHIUSE(IAATYP)+3



      IF (IAATYP.LE.0) THEN
         CALL GVSTTB ('?CHIB06')
         GOTO 998
      END IF



   10 CONTINUE
      CALL GVSSTX (LINE,'?CHIGNN')
      CALL GVSSTX (LINE(51:58),CTOTAL)
      LINE(60:60)=')'
      CALL GVSRDB (LINE)
      CALL IPROMPT (LINE)
      CALL NEEDWORD (CINP,' ',IERR)
      IF (IERR.EQ.1) GOTO 998
      CALL GVSCUC (CINP)



      IANG=INDEX(CTOTAL,CINP)
      IF (.NOT.GVFIBN(IANG,1,ITOUSE)) THEN
         CALL GVSTTE ('?CHIB08')
         CALL GVSTT6 (AANAME(IAATYP))
         GOTO 10
      END IF



      IF (IANG.GT.3) THEN
         IF (TORCON(1,IANG-3,IAATYP).EQ.0) THEN
            CALL GVSTTE ('?CHIB09')
            IANG=0
            GOTO 998
         END IF
      END IF



  998 CONTINUE


      RETURN
      END
      SUBROUTINE CHI010 (IAA,IANG,ANGL)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'CHIANG.INC'
      LOGICAL       WIFIR1, WIFIR3
      INTEGER       IAA, IANG, IAT, ITOR, IAAR, LOCIAT
      REAL          BASIS(3), VECTOR(3), RMAT(3,3), ANGL, ANGLE,
     +              GVFRTD, GVFDTR, GVF2PI







      IF (RESTYP(IAA).GT.0.AND.IAA.GT.NUMAAF) THEN
         CALL CHI010A (IAA,IANG,ANGL)
         GOTO 998
      END IF



      IF (RESTYP(IAA).EQ.0) GOTO 998
      IF (IANG.EQ.1.AND.WIFIR1(IAA)) THEN
         CALL GVSTTE ('?CHIB10')
         GOTO 998
      END IF
      IF (IANG.EQ.2.AND.WIFIR3(IAA)) THEN
         CALL GVSTTE ('?CHIB11')
         GOTO 998
      END IF
      IF (IANG.EQ.3.AND.WIFIR3(IAA)) THEN
         CALL GVSTTE ('?CHIB12')
         GOTO 998
      END IF
      IF (ABS(ANGL-GVFRTD(CHIANG(IANG,IAA))).LT.0.001) GOTO 998



      IF (IANG.EQ.1) THEN
         BASIS(1)=XCOORD(PNTAAS(IAA))
         BASIS(2)=YCOORD(PNTAAS(IAA))
         BASIS(3)=ZCOORD(PNTAAS(IAA))
         VECTOR(1)=XCOORD(PNTAAC(IAA))
         VECTOR(2)=YCOORD(PNTAAC(IAA))
         VECTOR(3)=ZCOORD(PNTAAC(IAA))
         CALL GVSSV3 (VECTOR,BASIS)
      ELSE IF (IANG.EQ.2) THEN
         BASIS(1)=XCOORD(PNTAAS(IAA)+1)
         BASIS(2)=YCOORD(PNTAAS(IAA)+1)
         BASIS(3)=ZCOORD(PNTAAS(IAA)+1)
         VECTOR(1)=XCOORD(PNTAAS(IAA)+2)
         VECTOR(2)=YCOORD(PNTAAS(IAA)+2)
         VECTOR(3)=ZCOORD(PNTAAS(IAA)+2)
         CALL GVSSV3 (VECTOR,BASIS)
      ELSE IF (IANG.EQ.3) THEN
         BASIS(1)=XCOORD(PNTAAS(IAA)+2)
         BASIS(2)=YCOORD(PNTAAS(IAA)+2)
         BASIS(3)=ZCOORD(PNTAAS(IAA)+2)
         VECTOR(1)=XCOORD(PNTAAS(IAA+1))
         VECTOR(2)=YCOORD(PNTAAS(IAA+1))
         VECTOR(3)=ZCOORD(PNTAAS(IAA+1))
         CALL GVSSV3 (VECTOR,BASIS)
      ELSE
         IAT=PNTAAS(IAA)-1+CHICON(2,IANG-3,RESTYP(IAA))
         IF (IAT.LT.1) GOTO 998
         BASIS(1)=XCOORD(PNTAAS(IAA)-1+CHICON(2,IANG-3,RESTYP(IAA)))
         BASIS(2)=YCOORD(PNTAAS(IAA)-1+CHICON(2,IANG-3,RESTYP(IAA)))
         BASIS(3)=ZCOORD(PNTAAS(IAA)-1+CHICON(2,IANG-3,RESTYP(IAA)))
         VECTOR(1)=XCOORD(PNTAAS(IAA)-1+CHICON(3,IANG-3,RESTYP(IAA)))
         VECTOR(2)=YCOORD(PNTAAS(IAA)-1+CHICON(3,IANG-3,RESTYP(IAA)))
         VECTOR(3)=ZCOORD(PNTAAS(IAA)-1+CHICON(3,IANG-3,RESTYP(IAA)))
         CALL GVSSV3 (VECTOR,BASIS)
      END IF



      ANGLE=GVF2PI(GVFDTR(ANGL)-CHIANG(IANG,IAA))
      CHIANG(IANG,IAA)=GVFDTR(ANGL)
      CALL GVSMGM (RMAT,VECTOR,ANGLE)



      IF (IANG.EQ.1) THEN



         DO 10 IAT=PNTAAS(IAA)+2,PNTAAE(IAA)
            IF (.NOT.ISATOK(IAT)) GOTO 10
            CV(1)=XCOORD(IAT)-BASIS(1)
            CV(2)=YCOORD(IAT)-BASIS(2)
            CV(3)=ZCOORD(IAT)-BASIS(3)
            CALL GVSMPV (CV,RMAT,BASIS)
            XCOORD(IAT)=CV(1)
            YCOORD(IAT)=CV(2)
            ZCOORD(IAT)=CV(3)
            IF (BOUND_TO(1,IAT).NE.0) CALL CHI015 (IAT,RMAT,BASIS)
   10    CONTINUE
      ELSE IF (IANG.EQ.2) THEN



         CV(1)=XCOORD(PNTAAS(IAA)+3)-BASIS(1)
         CV(2)=YCOORD(PNTAAS(IAA)+3)-BASIS(2)
         CV(3)=ZCOORD(PNTAAS(IAA)+3)-BASIS(3)
         CALL GVSMPV (CV,RMAT,BASIS)
         XCOORD(PNTAAS(IAA)+3)=CV(1)
         YCOORD(PNTAAS(IAA)+3)=CV(2)
         ZCOORD(PNTAAS(IAA)+3)=CV(3)
         IF (BOUND_TO(1,PNTAAS(IAA)+3).NE.0) CALL CHI015 
     +    (PNTAAS(IAA)+3,RMAT,BASIS)
      ELSE IF (IANG.GT.3) THEN



         DO 20 ITOR=3,MAXTAT
            LOCIAT=TORCON(ITOR,IANG-3,RESTYP(IAA))
            IF (LOCIAT.EQ.0) GOTO 20
            IAT=LOCIAT-1+PNTAAS(IAA)
            IF (.NOT.ISATOK(IAT)) GOTO 20
            CV(1)=XCOORD(IAT)-BASIS(1)
            CV(2)=YCOORD(IAT)-BASIS(2)
            CV(3)=ZCOORD(IAT)-BASIS(3)
            CALL GVSMPV (CV,RMAT,BASIS)
            XCOORD(IAT)=CV(1)
            YCOORD(IAT)=CV(2)
            ZCOORD(IAT)=CV(3)
            IF (BOUND_TO(1,IAT).NE.0) CALL CHI015 (IAT,RMAT,BASIS)
   20    CONTINUE
      END IF



      IF ((IANG.LE.3).AND.(.NOT.WIFIR3(IAA)).AND.
     +    (WIFPAR(1090).EQ.0)) THEN
         DO 40 IAAR=IAA+1,SOUADM(2,CHAINN(2,IAA))
            DO 30 IAT=PNTAAS(IAAR),PNTAAE(IAAR)
               IF (.NOT.ISATOK(IAT)) GOTO 30
               CV(1)=XCOORD(IAT)-BASIS(1)
               CV(2)=YCOORD(IAT)-BASIS(2)
               CV(3)=ZCOORD(IAT)-BASIS(3)
               CALL GVSMPV (CV,RMAT,BASIS)
               XCOORD(IAT)=CV(1)
               YCOORD(IAT)=CV(2)
               ZCOORD(IAT)=CV(3)
               IF (BOUND_TO(1,IAT).NE.0) CALL CHI015 (IAT,RMAT,BASIS)
   30       CONTINUE
   40    CONTINUE
      END IF



  998 CONTINUE


      RETURN
      END
      SUBROUTINE CHI010A (IAA,IANG,ANGL)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'CHIANG.INC'
      INTEGER       IAA, IANG, IAT, ITOR, IAT1, IAT2,
     +              IAT3, IAT4
      REAL          BASIS(3), VECTOR(3), RMAT(3,3), ANGL, ANGLE,
     +              GVFDTR, GVFRTD, OLDANG, CHI001, GVF360







      IF (RESTYP(IAA).LE.0) GOTO 998



      IAT=PNTAAS(IAA)-1+TORCON(1,IANG,RESTYP(IAA))
      IF (IAT.LT.1) GOTO 998
      BASIS(1)=XCOORD(IAT)
      BASIS(2)=YCOORD(IAT)
      BASIS(3)=ZCOORD(IAT)
      IAT=PNTAAS(IAA)-1+TORCON(2,IANG,RESTYP(IAA))
      IF (IAT.LT.1) GOTO 998
      VECTOR(1)=XCOORD(IAT)
      VECTOR(2)=YCOORD(IAT)
      VECTOR(3)=ZCOORD(IAT)
      CALL GVSSV3 (VECTOR,BASIS)



      IAT1=PNTAAS(IAA)+CHICON(1,IANG,RESTYP(IAA))-1
      IAT2=PNTAAS(IAA)+CHICON(2,IANG,RESTYP(IAA))-1
      IAT3=PNTAAS(IAA)+CHICON(3,IANG,RESTYP(IAA))-1
      IAT4=PNTAAS(IAA)+CHICON(4,IANG,RESTYP(IAA))-1
      OLDANG=GVFRTD(CHI001(IAT1,IAT2,IAT3,IAT4))
      IF (ABS(ANGL-OLDANG).LT.0.0001) GOTO 998



      ANGLE=GVFDTR(GVF360(ANGL-OLDANG))
      CALL GVSMGM (RMAT,VECTOR,ANGLE)



      DO 20 ITOR=3,MAXTAT
         IAT=TORCON(ITOR,IANG,RESTYP(IAA))
         IF (IAT.EQ.0) GOTO 20
         CV(1)=XCOORD(PNTAAS(IAA)-1+IAT)-BASIS(1)
         CV(2)=YCOORD(PNTAAS(IAA)-1+IAT)-BASIS(2)
         CV(3)=ZCOORD(PNTAAS(IAA)-1+IAT)-BASIS(3)
         CALL GVSMVV (CV,RMAT)
         XCOORD(PNTAAS(IAA)-1+IAT)=CV(1)+BASIS(1)
         YCOORD(PNTAAS(IAA)-1+IAT)=CV(2)+BASIS(2)
         ZCOORD(PNTAAS(IAA)-1+IAT)=CV(3)+BASIS(3)
   20 CONTINUE



  998 CONTINUE


      RETURN
      END
      SUBROUTINE CHI012 (IAA)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'CHIANG.INC'
      INTEGER       IAA, ICHI, ITOR, IAT1, IAT2, IAT3, IAT4
      REAL          CHI001, GVFDTR
      LOGICAL       WIFIRA, WIFIR1, WIFIR3







      IF (.NOT.WIFIRA(IAA)) THEN
         IF (WIFPAR(1012).NE.0) CALL GVSTTE ('?CHIB13')
         GOTO 998
      END IF
      IF (PNTAAS(IAA)+2.GT.NUMATF) THEN
         CALL GVSTTB ('?CHIB14')
         GOTO 998
      END IF



      IF (RESTYP(IAA).GT.0.AND.IAA.GT.NUMAAF) THEN
         DO 10 ITOR=1,CHIUSE(RESTYP(IAA))
            IAT1=PNTAAS(IAA)+CHICON(1,ITOR,RESTYP(IAA))-1
            IF (IAT1.EQ.0) GOTO 998
            IAT2=PNTAAS(IAA)+CHICON(2,ITOR,RESTYP(IAA))-1
            IAT3=PNTAAS(IAA)+CHICON(3,ITOR,RESTYP(IAA))-1
            IAT4=PNTAAS(IAA)+CHICON(4,ITOR,RESTYP(IAA))-1
            CHIANG(ITOR,IAA)=CHI001(IAT1,IAT2,IAT3,IAT4)
   10    CONTINUE
         GOTO 998
      END IF



      IF (WIFIR1(IAA).OR.PNTAAS(IAA)+2.GT.NUMATF) THEN
         CHIANG(1,IAA)=GVFDTR(999.9)
      ELSE
         CHIANG(1,IAA)=CHI001((PNTAAS(IAA-1)+2),PNTAAS(IAA),
     +    (PNTAAS(IAA)+1),(PNTAAS(IAA)+2))
      END IF



      IF (WIFIR3(IAA)) THEN
         CHIANG(2,IAA)=GVFDTR(999.9)
         CHIANG(3,IAA)=GVFDTR(999.9)
      ELSE
         CHIANG(2,IAA)=CHI001(PNTAAS(IAA),(PNTAAS(IAA)+1),
     +    (PNTAAS(IAA)+2),PNTAAS(IAA+1))
         CHIANG(3,IAA)=CHI001((PNTAAS(IAA)+1),(PNTAAS(IAA)+2),
     +    PNTAAS(IAA+1),(PNTAAS(IAA+1)+1))
      END IF



      DO 40 ICHI=1,5
         CHIANG(ICHI+3,IAA)=0.0
         IF (CHICON(1,ICHI,RESTYP(IAA)).EQ.0) GOTO 998
         CHIANG(ICHI+3,IAA)=CHI001(
     +    (PNTAAS(IAA)-1+CHICON(1,ICHI,RESTYP(IAA))),
     +    (PNTAAS(IAA)-1+CHICON(2,ICHI,RESTYP(IAA))),
     +    (PNTAAS(IAA)-1+CHICON(3,ICHI,RESTYP(IAA))),
     +    (PNTAAS(IAA)-1+CHICON(4,ICHI,RESTYP(IAA))))
   40 CONTINUE



  998 CONTINUE


      RETURN
      END

      SUBROUTINE CHI015 (IATIN,RMAT,BASIS)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      LOGICAL       GVFIBN, WIFIRR
      INTEGER       IAT, IAA, IATIN
      REAL          RMAT(3,3), BASIS(3)







      IAT=BOUND_TO(1,IATIN)
      IF (.NOT.GVFIBN(IAT,1,NUMATF)) GOTO 998
      IAA=ATIAA(IAT)
      IF (WIFIRR(IAA)) THEN
         CALL GVSTTB ('?CHIB27')
         GOTO 998
      END IF



      DO 10 IAT=PNTAAS(IAA),PNTAAE(IAA)
         XYZ(1)=XCOORD(IAT)-BASIS(1)
         XYZ(2)=YCOORD(IAT)-BASIS(2)
         XYZ(3)=ZCOORD(IAT)-BASIS(3)
         CALL GVSMPV (XYZ,RMAT,BASIS)
         XCOORD(IAT)=XYZ(1)
         YCOORD(IAT)=XYZ(2)
         ZCOORD(IAT)=XYZ(3)
   10 CONTINUE



  998 CONTINUE


      RETURN
      END
      SUBROUTINE CHI016 (IAA,NUMTOR,ARRAY)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'CHIANG.INC'
      INTEGER       IAA, ICHI, ITOR, IAT1, IAT2, IAT3, IAT4, NUMTOR
      REAL          CHI001, GVFDTR, ARRAY(MAXTOR)
      LOGICAL       WIFIRR, WIFIR1, WIFIR3







      IF (RESTYP(IAA).GT.0.AND.IAA.GT.NUMAAF) THEN
         DO 10 ITOR=1,CHIUSE(RESTYP(IAA))
            IAT1=PNTAAS(IAA)+CHICON(1,ITOR,RESTYP(IAA))-1
            IAT2=PNTAAS(IAA)+CHICON(2,ITOR,RESTYP(IAA))-1
            IAT3=PNTAAS(IAA)+CHICON(3,ITOR,RESTYP(IAA))-1
            IAT4=PNTAAS(IAA)+CHICON(4,ITOR,RESTYP(IAA))-1
            ARRAY(ITOR)=CHI001(IAT1,IAT2,IAT3,IAT4)
   10    CONTINUE
         NUMTOR=CHIUSE(RESTYP(IAA))
         GOTO 998
      END IF



      IF (.NOT.WIFIRR(IAA)) THEN
         CALL GVSTTE ('?CHIB13')
         GOTO 998
      END IF
      IF (PNTAAS(IAA)+2.GT.NUMATF) THEN
         CALL GVSTTB ('?CHIB14')
         GOTO 998
      END IF



      IF (WIFIR1(IAA).OR.PNTAAS(IAA)+2.GT.NUMATF)
     +    THEN
         ARRAY(1)=GVFDTR(999.9)
      ELSE
         ARRAY(1)=CHI001((PNTAAS(IAA-1)+2),PNTAAS(IAA),
     +    (PNTAAS(IAA)+1),(PNTAAS(IAA)+2))
      END IF



      IF (WIFIR3(IAA)) THEN
         ARRAY(2)=GVFDTR(999.9)
         ARRAY(3)=GVFDTR(999.9)
      ELSE
         ARRAY(2)=CHI001(PNTAAS(IAA),(PNTAAS(IAA)+1),
     +    (PNTAAS(IAA)+2),PNTAAS(IAA+1))
         ARRAY(3)=CHI001((PNTAAS(IAA)+1),(PNTAAS(IAA)+2),
     +    PNTAAS(IAA+1),(PNTAAS(IAA+1)+1))
      END IF



      DO 40 ICHI=1,5
         ARRAY(ICHI+3)=0.0
         IF (CHICON(1,ICHI,RESTYP(IAA)).EQ.0) GOTO 998
         ARRAY(ICHI+3)=CHI001(
     +    (PNTAAS(IAA)-1+CHICON(1,ICHI,RESTYP(IAA))),
     +    (PNTAAS(IAA)-1+CHICON(2,ICHI,RESTYP(IAA))),
     +    (PNTAAS(IAA)-1+CHICON(3,ICHI,RESTYP(IAA))),
     +    (PNTAAS(IAA)-1+CHICON(4,ICHI,RESTYP(IAA))))
   40 CONTINUE
      NUMTOR=CHIUSE(RESTYP(IAA))+3



  998 CONTINUE


      RETURN
      END
      SUBROUTINE CHI017 (JFT1,JFT2)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'CHIANG.INC'
      INCLUDE       'IMPROP.INC'
      INTEGER       IFT1, IFT2, JFT1, JFT2, IAA, IAT
      REAL          CHIPREF, CHIREAL, PDBC71, SIGPREF
      LOGICAL       INTERRUPTED, WIFIRA
      CHARACTER*4   T4, C1, C2, C3, C4








      CALL SETIFT (IFT1,IFT2,JFT1,JFT2)
      IF (IFT1.EQ.0) GOTO 998



      CALL SHOWTEXT ('?M2532')



      DO 20 IAA=IFT1,IFT2
         IF (INTERRUPTED()) GOTO 998



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



         DO 10 IAT=PNTAAS(IAA),PNTAAE(IAA)



            IF (.NOT.ISATOK(IAT)) GOTO 10



            SIGPREF=IMPSIG(PINIAA(IAT),RESTYP(IAA))
            IF (SIGPREF.GT.100.0) GOTO 10



            CHIPREF=IMPAVE(PINIAA(IAT),RESTYP(IAA))
            CHIREAL=PDBC71(IAT)
            C1=T4(ONESAT(IAT))
            C2=T4(ONESAT(WIFPAR(396)))
            C3=T4(ONESAT(WIFPAR(397)))
            C4=T4(ONESAT(WIFPAR(398)))
            CALL GVSFMT ('?FMT264')
            CALL GVSCTB (BIGLIN,132)
            WRITE (BIGLIN,FMT,ERR=999) 
     +       ATIAA(IAT),ONESA3(ATIAA(IAT)),C1,
     +       ATIAA(WIFPAR(396)),ONESA3(ATIAA(WIFPAR(396))),C2,
     +       ATIAA(WIFPAR(397)),ONESA3(ATIAA(WIFPAR(397))),C3,
     +       ATIAA(WIFPAR(398)),ONESA3(ATIAA(WIFPAR(398))),C4,
     +       CHIREAL,CHIPREF,SIGPREF,
     +       ABS(CHIREAL-CHIPREF)/(SIGPREF+0.001)
            CALL GVSTT6 (BIGLIN)
   10    CONTINUE
   20 CONTINUE
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('CHI017')



  998 CONTINUE



      RETURN
      END   
      SUBROUTINE CHI018

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'CHIANG.INC'
      INTEGER       IERR, IAA
      REAL          ANG1, ANG2, ANG3, ANG4, WIFBBA1, WIFBBA2, WIFBBA3,
     +              WIFBBA4
      LOGICAL       WIFIRA, WIFIR1, WIFIR3







      IERR=0



      CALL WIFWTF (' ',IERR)
      IF (IERR.NE.0) GOTO 998







      CALL SHOWTEXT ('?M2845')
      DO 100 IAA=1,NUMAAF
         IF (WRK1TF(IAA).AND.WIFIRA(IAA).AND.(.NOT.WIFIR1(IAA)).AND.
     +       (.NOT.WIFIR3(IAA))) THEN
            ANG1=WIFBBA1(IAA,IERR)
            IF (IERR.NE.0) GOTO 100
            ANG2=WIFBBA2(IAA,IERR)
            IF (IERR.NE.0) GOTO 100
            ANG3=WIFBBA3(IAA,IERR)
            IF (IERR.NE.0) GOTO 100
            ANG4=WIFBBA4(IAA,IERR)
            IF (IERR.NE.0) GOTO 100
            CALL DIF006A (6,IAA,ANG1,ANG2,ANG3,ANG4)
         END IF
 100  CONTINUE



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE CHI030 (IFT1,IFT2)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IERR, IAA, I, IFT1, IFT2, GVFPOS
      REAL          TAU, WIFANG, VAL
      LOGICAL       GVFIBN, WIFROK, FIRST, WIFBOK
      CHARACTER*2   WARN
      CHARACTER*6   TEXT







      FIRST=.TRUE.



      CALL GVSBTF (WRK1TF,MAXAA)
      IF (IFT1.NE.0) THEN
         DO 10 IAA=IFT1,IFT2
            WRK1TF(IAA)=.TRUE.
   10    CONTINUE
      ELSE
         CALL WIFWTF (' ',IERR)
         IF (IERR.NE.0) GOTO 998
      END IF



      DO 100 IAA=1,NUMAAF
         IF (.NOT.WRK1TF(IAA)) GOTO 100
         IF (GVFIBN(RESTYP(IAA),1,20)) THEN
            IF (ISATOK(PNTAAS(IAA)).AND.ISATOK(PNTAAC(IAA)).AND.
     +          ISATOK(PNTAAC(IAA)+1)) THEN
               TAU=WIFANG(PNTAAS(IAA),PNTAAC(IAA),PNTAAC(IAA)+1)
            ELSE
               TAU=-999.9
            END IF
            CALL GVSCTB (WARN,2)
            IF (WIFROK(IAA)) THEN
               WARN(2:2)='+'
            ELSE
               WARN(2:2)='-'
            END IF
            IF (WIFBOK(IAA)) THEN
               WARN(1:1)='+'
            ELSE
               WARN(1:1)='-'
            END IF
            CALL GVSCTB (TEXT,6)
            IF (GVFPOS(WARN,'-').EQ.0) THEN
               VAL=ABS(TAU-111.0)/3.0
               IF (VAL.GE.4.0) THEN
                  DO 20 I=1,MIN(6,NINT(VAL-3.5))
                     TEXT(I:I)='*'
 20               CONTINUE
               END IF
            END IF
            IF (FIRST) THEN
               FIRST=.FALSE.
               CALL SHOWTEXT ('?M5164')
            END IF
            CALL DIF008D (6,IAA,TAU,WARN//TEXT)
         END IF
 100  CONTINUE



      IF (FIRST) CALL SHOWTEXT ('?M5165')



  998 CONTINUE


      RETURN
      END   
