



      SUBROUTINE WIF430 (DONE)


















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'OPTION.INC'
      INTEGER       IERR
      LOGICAL       DONE
      EXTERNAL      LPDTST

      RETURN
      END

      SUBROUTINE WIF407 (IAA,ERROR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'ESPACE.INC'
      INCLUDE       'GRPINC.INC'
      INCLUDE       'DGLOOP.INC'
      INCLUDE       'DATBAS.INC'
      INTEGER       IERR, IAA, IHIT, IATO, WIF51HALF, WIF51H
      LOGICAL       BOOLS(NUMUA), WIFIRA, GVFIBN
      REAL          SUMDIF, ERROR







      ERROR=9.99
      IF (.NOT.GVFIBN(RESTYP(IAA),1,20)) GOTO 998
      IF (.NOT.WIFIRA(IAA)) GOTO 998



      CALL WIF415
      IF (WIFPAR(51).NE.5) CALL WIF019 (5)
      CALL WIFPUSHPPP (564,0)
      CALL WIFPUSHPPP (524,1)
      IATO=PNTAAS(IAA)+3
      WIF51H=WIF51HALF()



      CALL WIF432A (IAA,IERR)
      IF (IERR.NE.0) GOTO 100



      CALL GVSBTF (BOOLS,NUMUA)
      BOOLS(RESTYP(IAA))=.TRUE.
      CALL WIF425 (IAA,BOOLS)



      IF (WIFPAR(54).LE.4) THEN
         IF (WIFPAR(279).LE.0) CALL GVSTTI ('?M0252',IAA)
         GOTO 100
      END IF
      SUMDIF=0.0
      DO 10 IHIT=1,WIFPAR(54)



         CALL REC003 (INDPNT(GRPNTR(1,IHIT))+GRPNTR(2,IHIT)+WIF51H,IERR)
         IF (IERR.NE.0) GOTO 998
         IF (.NOT.LASTOK) GOTO 998



         CALL REC004 (CV(1),CV(2),CV(3),4,IERR)



         CALL GVSMPV (CV,DGMAT(1,1,IHIT,1),DGVEC(1,IHIT,1))
         SUMDIF=SUMDIF+(XCOORD(IATO)-CV(1))**2+
     +                 (YCOORD(IATO)-CV(2))**2+
     +                 (ZCOORD(IATO)-CV(3))**2
   10 CONTINUE



      ERROR=SQRT(SUMDIF/FLOAT(MAX(1,WIFPAR(54))))



  100 CONTINUE
      CALL WIFPOPPPP (524)
      CALL WIFPOPPPP (564)



  998 CONTINUE


      RETURN
      END

      LOGICAL FUNCTION WIF408(IAA)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'DGLOOP.INC'
      INTEGER       IAA, IERR, WIF51HALF, WIF51H
      LOGICAL       WIFIRA, WIFIRC







      WIF408=.TRUE.
      IERR=0
      WIF51H=WIF51HALF()



      IF (.NOT.WIFIRA(IAA)) THEN
         CALL GVSTTE ('?M1596')
         WIF408=.FALSE.
         GOTO 998
      END IF
      IF (IAA-WIF51H.LT.1) THEN
         CALL GVSTTE ('?M1594')
         WIF408=.FALSE.
         GOTO 998
      END IF
      IF (IAA+WIF51H.GT.NUMAAF) THEN
         CALL GVSTTE ('?M1595')
         WIF408=.FALSE.
         GOTO 998
      END IF



      IF (WIFIRC(IAA)) THEN
         WIFPAR(532)=1
      ELSE
         IF (HATPRA(RESTYP(IAA)).GT.4) THEN
            CALL GETCBETA (IAA,IERR)
         ELSE
            CBETA(1)=0.0
            CBETA(2)=0.0
            CBETA(3)=0.0
         END IF
         WIFPAR(532)=0
      END IF
      WIF408=(IERR.EQ.0)



  998 CONTINUE


      RETURN
      END   
      LOGICAL FUNCTION WIF409()


















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      LOGICAL       GVFODD





      WIF409=GVFODD(WIFPAR(51))
      IF (.NOT.WIF409) CALL SHOWTEXT ('?NEWE24')





      RETURN
      END
      SUBROUTINE WIF410 (IAA)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'CHIANG.INC'
      INCLUDE       'DGLOOP.INC'
      INTEGER       IAA, ILOWER, IHIGHR, ICA1, ICA, I, WIF51H,
     +              IERR, WIF51HALF
      REAL          GVFDV3, GVFRTD
      LOGICAL       WIF084, WIFIRC, WIFIRA








      WIFPAR(54)=0
      WIF51H=WIF51HALF()
      ILOWER=IAA-WIF51H
      IHIGHR=IAA+WIF51H



      IF (ILOWER.LT.1.OR.IHIGHR.GT.NUMAAF) THEN
         CALL GVSTTB ('?DGB01')
         GOTO 998
      END IF



      IF (.NOT.WIF084(ILOWER,IHIGHR)) THEN
         CALL GVSTT6 ('?DGB02')
      END IF



      IF (.NOT.WIFIRA(ILOWER)) THEN
         CALL GVSTTE ('?DGB03')
         GOTO 998
      END IF



      CALL CHI004
      WIFPAR(581)=NINT(GVFRTD(CHIANG(2,IAA-1)))
      WIFPAR(582)=NINT(GVFRTD(CHIANG(1,IAA)))
      WIFPAR(583)=NINT(GVFRTD(CHIANG(2,IAA)))
      WIFPAR(584)=NINT(GVFRTD(CHIANG(1,IAA+1)))
      WIFPAR(585)=IAA
      WIFPAR(604)=IAA
      IF (WIFIRC(IAA)) WIFPAR(585)=0
      IF (HATPRA(RESTYP(IAA)).LE.4) WIFPAR(585)=0



      CALL GETCBETA (IAA,IERR)





      IF (WIFPAR(638).LE.0) THEN
         CALL GVSTTB ('?DGB04')
         WIFPAR(638)=4*MAXIG
         CALL GVSNL6 (2)
      END IF

      ICA1=0
      DO 5 ICA=ILOWER,IHIGHR
         ICA1=ICA1+1
         FTCRDS(1,ICA1)=XCOORD(PNTAAC(ICA))
         FTCRDS(2,ICA1)=YCOORD(PNTAAC(ICA))
         FTCRDS(3,ICA1)=ZCOORD(PNTAAC(ICA))
    5 CONTINUE





      DO 10 I=2,WIFPAR(51)
         FTCRDS(4,I)=GVFDV3(FTCRDS(1,1),FTCRDS(1,I))
   10 CONTINUE



      IF (ISATOK(PNTAAS(IAA)).AND.ISATOK(PNTAAS(IAA)+2).AND.
     +    ISATOK(PNTAAS(IAA)+3)) THEN
          FTCRDS(1,WIFPAR(51)+1)=XCOORD(PNTAAS(IAA))
          FTCRDS(2,WIFPAR(51)+1)=YCOORD(PNTAAS(IAA))
          FTCRDS(3,WIFPAR(51)+1)=ZCOORD(PNTAAS(IAA))
          FTCRDS(4,WIFPAR(51)+1)=1.0
          FTCRDS(1,WIFPAR(51)+2)=XCOORD(PNTAAS(IAA)+2)
          FTCRDS(2,WIFPAR(51)+2)=YCOORD(PNTAAS(IAA)+2)
          FTCRDS(3,WIFPAR(51)+2)=ZCOORD(PNTAAS(IAA)+2)
          FTCRDS(4,WIFPAR(51)+2)=1.0
          FTCRDS(1,WIFPAR(51)+3)=XCOORD(PNTAAS(IAA)+3)
          FTCRDS(2,WIFPAR(51)+3)=YCOORD(PNTAAS(IAA)+3)
          FTCRDS(3,WIFPAR(51)+3)=ZCOORD(PNTAAS(IAA)+3)
          FTCRDS(4,WIFPAR(51)+3)=1.0
      END IF



  998 CONTINUE


      RETURN
      END
      SUBROUTINE WIF411 (IGRP)


















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'GRPINC.INC'
      INTEGER       GVFFFI, I, IGRP
      LOGICAL       GVFYON, GVFIBN







      IGRP=0





      CALL GRPFREENB
   10 CONTINUE
      CALL I1PROMPT ('?ASKGRP1',NXTGRP)
      I=GVFFFI(1,IGRP)



      IF (I.EQ.1.AND.IGRP.EQ.0) GOTO 998
      IF (I.EQ.0) IGRP=NXTGRP
      IF (.NOT.GVFIBN(IGRP,1,10)) THEN
         CALL GVSTTI ('?GRPB09',IGRP)
         GOTO 10
      END IF
      IF (GRPACT(IGRP)) THEN
         CALL GVSTT6 ('?GRPB12')
         IF (.NOT.GVFYON('?WALB14',' ')) GOTO 10
      END IF



  998 CONTINUE


      RETURN
      END
      SUBROUTINE WIF412

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'







      WIFPAR(52)=NINT(FLOAT(WIFPAR(52))*1.5)
      WIFPAR(53)=NINT(FLOAT(WIFPAR(53))*1.5)
      WIFPAR(65)=NINT(FLOAT(WIFPAR(65))*1.5)



      CALL SETHIS ('?M1141')





      RETURN
      END
      SUBROUTINE WIF413

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'







      WIFPAR(52)=MAX(50,NINT(FLOAT(WIFPAR(52))/1.5))
      WIFPAR(53)=NINT(FLOAT(WIFPAR(53))/1.5)
      WIFPAR(65)=NINT(FLOAT(WIFPAR(65))/1.5)



      CALL SETHIS ('?M1142')





      RETURN
      END
      SUBROUTINE WIF415

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'DGLOOP.INC'
      INCLUDE       'DATBAS.INC'
      LOGICAL       GVFFOP







      IF (ALLSEQ(1,1).EQ.0) CALL SHOWTEXT ('?DGB20')
      IF (.NOT.GVFFOP(40)) THEN
         CALL SHOWTEXT ('?DGB21')
         CALL WIF109
         CALL SYMINI
         CALL WIFRDF
         CALL WIF103
         CALL WIF021
         CALL WIF112
      END IF



      CALL GVSRTC (DGWVAL,1.0,WIFPAR(51))





      RETURN
      END

      SUBROUTINE WIF422 (IAA)



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'ESPACE.INC'
      INCLUDE       'DGLOOP.INC'
      INCLUDE       'GRPINC.INC'
      INTEGER       IERR, IMID, IAA
      LOGICAL       WIF409







      IF (.NOT.WIF409()) GOTO 998



      IF (IAA.LE.0) THEN
         CALL WIFGRS (IMID,' ')
      ELSE
         IMID=IAA
      END IF



      IF (IMID.EQ.0) GOTO 998
      CALL WIF432 (IMID,IERR)
      IF (IERR.NE.0) GOTO 998




      CALL GVSRTC (DGWVAL,1.0,WIFPAR(51))



      IF (IAA.LE.0) THEN
         CALL GVSFMT ('?FMT051')
         CALL GVSCTB (GRPTITLE,80)
         WRITE (GRPTITLE,FMT,ERR=999) ONESA3(IMID),IMID,NUMNAM(IMID),
     +    WIFPAR(51)
      END IF



      CALL GVSBTF (LOCPAA,NUMUA)
      LOCPAA(RESTYP(IMID))=.TRUE.
      CALL WIF425 (IMID,LOCPAA)
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('WIF422')



  998 CONTINUE


      RETURN
      END

      SUBROUTINE WIF424B (IGRP,IHITIN,IAA,IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'ESPACE.INC'
      INCLUDE       'CHIANG.INC'
      INCLUDE       'GRPINC.INC'
      INCLUDE       'DGLOOP.INC'
      INCLUDE       'DATBAS.INC'
      INTEGER       IERR, IGRP, IHIT, IHITT, IAA, ISEQ, IAAS, 
     +              IAT, IHITIN, WIF51HALF, WIF51H, IR
      REAL          XYZAA(3,15)
      LOGICAL       GVFIBN







      IERR=0




      IF (NBINDB.LE.0) THEN
         CALL GVSTTE ('?NODBOP')
         IERR=1
         GOTO 998
      END IF
      IF (WIFPAR(54).LE.0) THEN
         CALL GVSTT6 ('?M4191')
         IERR=1
         GOTO 998
      END IF
      IF (AANAME(RESTYP(IAA)).EQ.'GLY ') GOTO 998
      WIF51H=WIF51HALF()



      IHITT=ABS(IHITIN)
      IHIT=IHITT
      IF (.NOT.GVFIBN(IHIT,1,1000)) THEN
         CALL GVSNL6 (2)
         CALL GVSKIL
         IERR=1
         GOTO 998
      END IF 
      ISEQ=GRPNTR(1,IHIT)
      IAAS=GRPNTR(2,IHIT)
      IERR=0
      IF (IAAS.LE.10000) THEN







         IF (RESTYP(IAA).NE.ALLSEQ(IAAS+INT(DGWHER(2,IGRP)/2),ISEQ))THEN
            CALL GVSTTE ('?DGB26')
            CALL WIF429 (IAA)
            IERR=1
            GOTO 998
         END IF






         CALL REC003 (INDPNT(ISEQ)+IAAS+WIF51H,IERR)
         IF (IERR.NE.0) THEN
            PRINT*,'REC003 IN WIF424B: IERR=1',ihit,wifpar(54)
            GOTO 999
         END IF
         IF (.NOT.LASTOK) THEN
            PRINT*,'REC003 IN WIF424B LASTOK=FALSE',ihit,wifpar(54)
            CALL GVSKIL
            GOTO 999
         END IF




         DO 30 IAT=1,HATPRA(RESTYP(IAA))
            CALL REC004 (XYZ(1),XYZ(2),XYZ(3),IAT,IERR)

            IF (ABS(XYZ(1)).LT.0.1.AND.ABS(XYZ(2)).LT.0.1.AND.
     +          ABS(XYZ(3)).LT.0.1) THEN

               GOTO 999
            END IF
            IF (IERR.NE.0)  THEN
               PRINT*,'READING WITH REC004 FAILED IN WIF424B'
               GOTO 999
            END IF



            CALL GVSMV3 (XYZAA(1,IAT),DGMAT(1,1,IHIT,IGRP),XYZ)
            CALL GVSAV3 (XYZAA(1,IAT),DGVEC(1,IHIT,IGRP))

 30      CONTINUE



         XYZ(1)=XCOORD(PNTAAC(IAA))-XYZAA(1,2)
         XYZ(2)=YCOORD(PNTAAC(IAA))-XYZAA(2,2)
         XYZ(3)=ZCOORD(PNTAAC(IAA))-XYZAA(3,2)



         DO 40 IAT=5,HATPRA(RESTYP(IAA))
            XCOORD(IAT+PNTAAS(IAA)-1)=XYZAA(1,IAT)+XYZ(1)
            YCOORD(IAT+PNTAAS(IAA)-1)=XYZAA(2,IAT)+XYZ(2)
            ZCOORD(IAT+PNTAAS(IAA)-1)=XYZAA(3,IAT)+XYZ(3)
 40      CONTINUE

      ELSE



         IF (CHIUSE(RESTYP(IAA)).GE.1) THEN
            DO 50 IR=1,CHIUSE(RESTYP(IAA))
               CALL CHI010 (IAA,IR+3,VALROT(IR,IAAS-10000,RESTYP(IAA)))
 50         CONTINUE
         END IF
      END IF




      IF (.NOT.ISATOK(PNTAAS(IAA))) THEN
         CALL MOL200
      ELSE
         CALL MOL201 (IAA)
      END IF
      IF (WIFPAR(84).EQ.1.AND.WIFPAR(384).EQ.0) THEN
         CALL GVSBTF (WRK1TF,NUMAAF)
         CALL HAS016 (IAA,IAA)
      END IF

      GOTO 998



  999 CONTINUE
      CALL GVSTTE ('?M1889')



  998 CONTINUE


      RETURN
      END
      SUBROUTINE WIF425 (IAA,BOOLS)


















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'ESPACE.INC'
      INCLUDE       'GRPINC.INC'
      INCLUDE       'HSTINC.INC'
      INCLUDE       'DGLOOP.INC'
      INTEGER       GVFCBT, IRELAX, IAA, IGRP, ITEST, IBACK, IERR, 
     +              GVFLEN, WIF51HALF, WIF51H
      LOGICAL       GVFIBN, BOOLS(NUMUA), WIF408







      IF (.NOT.GVFIBN(GVFCBT(BOOLS,20),1,20)) THEN
         CALL GVSTTB ('?DGB27')
         GOTO 998
      END IF
      IF (.NOT.WIF408(IAA)) GOTO 998



      IRELAX=0
      WIFPAR(54)=0
      IERR=0
      WIF51H=WIF51HALF()



      IF (WIFPAR(524).NE.0) THEN
         IGRP=WIFPAR(524)
      ELSE
         CALL WIF411 (IGRP)
         IF (IGRP.EQ.0) GOTO 998
      END IF
      IF (.NOT.GVFIBN(IGRP,1,10)) THEN
         CALL GVSTTI ('?GRPB01',IGRP)
         GOTO 998
      END IF
      IF (WIFPAR(51).LT.4) THEN
         CALL GVSTTI ('?DGB30',WIFPAR(51))
         CALL WIF019 (5)
      END IF




      CALL WIF410 (IAA)




      IF (WIFPAR(556).NE.0) THEN
         IF (.NOT.ACCDON(IAA)) THEN
            CALL ACC001
            CALL WIF039
            IF (.NOT.ACCDON(IAA)) GOTO 998
         END IF
         CALL GVSCCC (LINE,FILDIR(27),'ALLACC.ACC')
         CALL SCN203B (LINE,'REAL',IERR)
         IF (IERR.NE.0) GOTO 998
      END IF



      CALL INI426 (IERR)
      IF (IERR.NE.0) GOTO 998




   10 CONTINUE
      CALL GVSIT0 (WIFPAR(950),20)
      ACCDON(IAA)=.FALSE.
      SUMACC(IAA)=0.0

      DO 30 ITEST=1,WIFPAR(708)
         CALL WIF426 (ITEST,BOOLS,IGRP)
         IF (WIFPAR(54).GE.WIFPAR(55)) GOTO 31
   30 CONTINUE
   31 CONTINUE










      IF (WIFPAR(524).EQ.0.OR.IRELAX.GE.WIFPAR(564)) THEN
         IF (WIFPAR(54).LT.1) GOTO 35
      ELSE
         IF (WIFPAR(54).LT.5) THEN
            IF (IRELAX.GE.1) GOTO 35
            WIFPAR(54)=0
            IRELAX=IRELAX+1
            CALL WIF412
            GOTO 10
         END IF
      END IF
   35 IF (IRELAX.NE.0) THEN
         DO 40 IBACK=1,IRELAX
            CALL WIF413
   40    CONTINUE
      END IF



      DGWHER(1,IGRP)=IAA-WIF51H
      DGWHER(2,IGRP)=WIFPAR(51)
      IF (GVFLEN(GRPTITLE).LE.0) THEN
         CALL GVSFMT ('?FMT050')
         CALL GVSCTB (GRPTITLE,80)
         WRITE (GRPTITLE,FMT,ERR=999) ONESA3(IAA),IAA,NUMNAM(IAA),
     +    WIFPAR(51)
      END IF
      CALL GVSSTX (GRPHOW(IGRP),GRPTITLE)
      CALL SETHIS (GRPTITLE)
      CALL GRPSAVE (IGRP,GRPNTR,WIFPAR(54))
      CALL GVSCTB (GRPTITLE,80)
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('WIF425')



  998 CONTINUE


      RETURN
      END
      SUBROUTINE INI426 (IERR)


















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'DATBAS.INC'
      INCLUDE       'ESPACE.INC'
      INTEGER       I, K, ISEQDB(MAXSP), IAADB(MAXSP), OLDLEN, IERR, 
     +              IAATYP, IAT, LUN
      LOGICAL       FIRST, GVFFOP
      REAL          SCRTCH(1000), ALPHI(MAXSP), ALPSI(MAXSP),
     +              ROWLOC(6,MAXSP), ALCAS(3,MAXSP), ALCBS(3,MAXSP)
      common /ppp/  rowloc,iseqdb,iaadb,alcas,alcbs,alphi,alpsi
      SAVE          OLDLEN, FIRST, LUN
      DATA FIRST    /.TRUE./
      DATA OLDLEN   /-99/







      IERR=0



      IF (.NOT.FIRST) THEN
         IF (OLDLEN.NE.WIFPAR(51)) THEN
            CALL GVSTT6 ('?M0437')
            FIRST=.TRUE.
         END IF
      END IF



      IF (FIRST) THEN
         FIRST=.FALSE.
         OLDLEN=WIFPAR(51)



         CALL GVSCCC (LINE,FILDIR(28),'CACA.NEW')
         CALL GVSROF (LUN,IERR)
         IF (IERR.NE.0) GOTO 998
         CALL GVSOUF (LINE,LUN,'OLD')
         IF (.NOT.GVFFOP(LUN)) GOTO 998



         DO 30 I=1,1000000
            READ (LUN,ERR=31,END=31) (SCRTCH(K),K=1,WIFPAR(638)+1),
     +       ALCAS(1,I),ALCAS(2,I),ALCAS(3,I),
     +       ALCBS(1,I),ALCBS(2,I),ALCBS(3,I),
     +       ALPHI(I),ALPSI(I)
            ISEQDB(I)=NINT(SCRTCH(1))
            IAADB(I)=NINT(SCRTCH(2))



            CALL REC003 (INDPNT(ISEQDB(I))+IAADB(I),IERR)
            IF (IERR.NE.0) GOTO 999
            IF (.NOT.LASTOK) THEN
               IAADB(I)=-999999
               GOTO 30
            END IF
            IAATYP=ALLSEQ(IAADB(I),ISEQDB(I))
            IF (IAATYP.LE.0) THEN
               IAADB(I)=-999999
               GOTO 30
            ELSE IF (IAATYP.GT.20) THEN
               IAADB(I)=-999999
               GOTO 30
            ELSE
               DO 10 IAT=7,-3+20*HATPRA(IAATYP),20
                  IF (ABS(RECRD(IAT)-1.0).GT.0.1) THEN
                     IAADB(I)=-999999
                     GOTO 30
                  END IF
 10            CONTINUE
            END IF
            DO 20 K=WIFPAR(51),MAX(3,WIFPAR(51)-5),-1
               ROWLOC(6-WIFPAR(51)+K,I)=SCRTCH(K)
 20         CONTINUE
            WIFPAR(708)=I
 30      CONTINUE
 31      CONTINUE
      END IF
      GOTO 998



  999 CONTINUE
      CALL GVSTTE ('?M1890')



  998 CONTINUE
      IF (GVFFOP(LUN)) CALL GVSCLF (LUN)


      RETURN
      END
      SUBROUTINE WIF426 (ITEST,BOOLS,IGRP)






















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'CHIANG.INC'
      INCLUDE       'GRPINC.INC'
      INCLUDE       'DGLOOP.INC'
      INCLUDE       'DATBAS.INC'
      INCLUDE       'ESPACE.INC'
      INTEGER       ITEST, IGRP, IAA, ISEQ, IAATYP, I, NEXT, ICA, IAAM,
     +              ICAST, IAT, IHIT, ISEQDB(MAXSP), IAADB(MAXSP), K,
     +              WIF51H, IERR
      LOGICAL       BOOLS(NUMUA), GVFIBN, ISBUMP
      REAL          XYZCON(3,50), XYZFIT(3,50), GVFANG, GVFRTD, 
     +              CBETALOC(3), CALPHALOC(3), TMP, RMSE, RMSM, QFACT,
     +              ALPHI(MAXSP), ALPSI(MAXSP), ROWLOC(6,MAXSP),
     +              ALCAS(3,MAXSP), ALCBS(3,MAXSP), DIFF, GVFRSM
      common /ppp/  rowloc,iseqdb,iaadb,alcas,alcbs,alphi,alpsi









      WIF51H=INT(FLOAT(WIFPAR(51))/2.0)
      IF (IAADB(ITEST+WIF51H).LT.-1000.OR.IAADB(ITEST).LT.-1000) THEN
         GOTO 997
      END IF



      IAA=IAADB(ITEST)+WIF51H
      ISEQ=ISEQDB(ITEST)
      WIFPAR(950)=WIFPAR(950)+1



      IF (.NOT.GVFIBN(ISEQ,1,NBINDB)) THEN
         CALL GVSKIL
         GOTO 997
      END IF
      IF (IAA.GT.NAAFIL(ISEQ)-WIF51H.OR.IAA.LT.WIF51H.OR.ISEQ.LE.0.OR.
     +    (IAA.LE.0.AND.IAA.GT.-1000).OR.ISEQ.GT.NBINDB) THEN
         WIFPAR(951)=WIFPAR(951)+1
         GOTO 997
      END IF



      IAATYP=ALLSEQ(IAA,ISEQ)
      IF (IAATYP.LT.1.OR.IAATYP.GT.20) THEN
         GOTO 997
      END IF
      IF (.NOT.BOOLS(IAATYP)) THEN
         WIFPAR(952)=WIFPAR(952)+1
         GOTO 997
      END IF



      IF (WIFPAR(19).NE.0) THEN
         I=ALLSEQ(IAA+1,ISEQ)
         IF (.NOT.LOCNEI(I)) THEN
            WIFPAR(953)=WIFPAR(953)+1
            GOTO 997
         END IF
      END IF



      IF (WIFFAC(ISEQ).NE.2) THEN
         WIFPAR(954)=WIFPAR(954)+1
         GOTO 997
      END IF



      QFACT=ABS(FTCRDS(4,WIFPAR(51))-ROWLOC(6,ITEST))
      IF (QFACT.GT.WIFPAR(52)/50.0) THEN
         WIFPAR(955)=WIFPAR(955)+1
         GOTO 997
      END IF




      K=0
      DO 10 I=WIFPAR(51), MAX(WIFPAR(51)-5,3), -1
         IF (DGWVAL(I).GT.0.0001) THEN
            DIFF=FTCRDS(4,I)-ROWLOC(6-WIFPAR(51)+I,ITEST)
            IF (DGWVAL(I)*ABS(DIFF).GT.WIFPAR(52)/50.0) THEN
               WIFPAR(956)=WIFPAR(956)+1
               GOTO 997
            END IF
            QFACT=QFACT+DGWVAL(I)*DIFF*DIFF
            K=K+1
         END IF
   10 CONTINUE



      IF (K.GT.0) THEN
         QFACT=QFACT/GVFRSM(DGWVAL,WIFPAR(51))
         IF (QFACT.GT.(WIFPAR(53)/100.0)**2) THEN
            WIFPAR(957)=WIFPAR(957)+1
            GOTO 997
         END IF
      END IF



      IF (WIFPAR(556).EQ.1) THEN
         IF (GENVR4(IAA,ISEQ).LT.FLOAT(WIFPAR(557))/100.0.OR.
     +       GENVR4(IAA,ISEQ).GT.FLOAT(WIFPAR(558))/100.0) THEN
            WIFPAR(958)=WIFPAR(958)+1
            GOTO 997
         END IF
      END IF



      CALPHALOC(1)=0.0
      CALPHALOC(2)=0.0
      CALPHALOC(3)=0.0
      CBETALOC(1)=0.0
      CBETALOC(2)=0.0
      CBETALOC(3)=0.0




      NEXT=0
      ICAST=INDPNT(ISEQDB(ITEST))+IAADB(ITEST)
      DO 30 I=1,WIFPAR(51)
         IF (DGWVAL(I).GT.0.0001) THEN
            NEXT=NEXT+1
            ICA=ICAST+I-1



            IF (WIFPAR(585).NE.0.AND.I.EQ.WIF51H+1) THEN



               CBETALOC(1)=ALCBS(1,ICA)
               CBETALOC(2)=ALCBS(2,ICA)
               CBETALOC(3)=ALCBS(3,ICA)
               CALPHALOC(1)=ALCAS(1,ICA)
               CALPHALOC(2)=ALCAS(2,ICA)
               CALPHALOC(3)=ALCAS(3,ICA)
            END IF



            XYZFIT(1,NEXT)=ALCAS(1,ICA)
            XYZFIT(2,NEXT)=ALCAS(2,ICA)
            XYZFIT(3,NEXT)=ALCAS(3,ICA)
            XYZCON(1,NEXT)=FTCRDS(1,I)
            XYZCON(2,NEXT)=FTCRDS(2,I)
            XYZCON(3,NEXT)=FTCRDS(3,I)
         END IF
   30 CONTINUE



      IF (NEXT.LT.3) THEN
         CALL GVSTTB ('?DGB32')
         CALL GVSKIL
         WIFPAR(959)=WIFPAR(959)+1
         GOTO 997
      END IF



      IHIT=WIFPAR(54)+1
      CALL GVSSPN (NEXT,XYZCON,XYZFIT,DGMAT(1,1,IHIT,IGRP),
     + DGVEC(1,IHIT,IGRP),RMSE,RMSM)
      QFCSTR(IHIT,IGRP)=RMSE



      IF (QFCSTR(IHIT,IGRP).GT.WIFPAR(65)/100.0) THEN
         WIFPAR(960)=WIFPAR(960)+1
         GOTO 997
      END IF
      IF (RMSM.GT.WIFPAR(1521)/100.0) THEN
         WIFPAR(960)=WIFPAR(960)+1
         GOTO 997
      END IF



      IF (QFCSTR(IHIT,IGRP).LT.0.0001) THEN
         WIFPAR(961)=WIFPAR(961)+1
         GOTO 997
      END IF



      IF (HATPRA(IAATYP).GT.4.AND.WIFPAR(532).EQ.0.AND.
     +    DGWVAL(WIF51H+1).GT.0.001) THEN
         CV(1)=CBETALOC(1)-CALPHALOC(1)
         CV(2)=CBETALOC(2)-CALPHALOC(2)
         CV(3)=CBETALOC(3)-CALPHALOC(3)
         CALL GVSMV3 (XYZ,DGMAT(1,1,IHIT,IGRP),CV)
         CV(1)=CBETA(1)-XCOORD(PNTAAC(WIFPAR(604)))
         CV(2)=CBETA(2)-YCOORD(PNTAAC(WIFPAR(604)))
         CV(3)=CBETA(3)-ZCOORD(PNTAAC(WIFPAR(604)))
         IF (GVFRTD(GVFANG(CV,XYZ)).GT.20.0) THEN
            WIFPAR(962)=WIFPAR(962)+1
            GOTO 997
         END IF
      END IF



      IAAM=INDPNT(ISEQ)+IAA
      IF (WIFPAR(585).NE.0) THEN
         TMP=ABS(ALPSI(IAAM-1)-FLOAT(WIFPAR(581)))
         IF (TMP.GT.180.0) TMP=360.0-TMP
         IF (TMP.GT.60.0) THEN
            WIFPAR(963)=WIFPAR(963)+1
            GOTO 997
         END IF
         TMP=ABS(ALPHI(IAAM)-FLOAT(WIFPAR(582)))
         IF (TMP.GT.180.0) TMP=360.0-TMP
         IF (TMP.GT.60.0) THEN
            WIFPAR(964)=WIFPAR(964)+1
            GOTO 997
         END IF
         TMP=ABS(ALPSI(IAAM)-FLOAT(WIFPAR(583)))
         IF (TMP.GT.180.0) TMP=360.0-TMP
         IF (TMP.GT.60.0) THEN
            WIFPAR(965)=WIFPAR(965)+1
            GOTO 997
         END IF
         TMP=ABS(ALPHI(IAAM+1)-FLOAT(WIFPAR(584)))
         IF (TMP.GT.180.0) TMP=360.0-TMP
         IF (TMP.GT.60.0) THEN
            WIFPAR(966)=WIFPAR(966)+1
            GOTO 997
         END IF
      END IF



      CALL REC003 (ICAST+WIF51H,IERR)
      IF (IERR.NE.0) GOTO 998
      IF (.NOT.LASTOK) GOTO 997
      IF (WIFPAR(603).NE.0.AND.HATPRA(IAATYP).GE.5) THEN
         DO 40 IAT=5,HATPRA(IAATYP)
            WIFPAR(640)=PNTAAS(WIFPAR(604))+IAT-1
            CALL REC004 (CV(1),CV(2),CV(3),IAT,IERR)
            IF (IERR.NE.0) GOTO 998
            CALL GVSMV3 (XYZ,DGMAT(1,1,IHIT,IGRP),CV)
            CALL GVSAV3 (XYZ,DGVEC(1,IHIT,IGRP))
            CALL WIF426A (XYZ,ISBUMP)
            IF (ISBUMP) THEN
               WIFPAR(967)=WIFPAR(967)+1
               GOTO 997
            END IF
   40    CONTINUE
      END IF



      WIFPAR(968)=WIFPAR(968)+1
      WIFPAR(54)=IHIT
      GRPNTR(1,IHIT)=ISEQDB(ITEST)
      GRPNTR(2,IHIT)=IAADB(ITEST)
      QFACTS(IHIT)=QFCSTR(IHIT,IGRP)
      GOTO 997



  998 CONTINUE
      CALL GVSTTB ('?DGB33')



  997 CONTINUE


      RETURN
      END
      SUBROUTINE WIF426A (XYZPOS,BUMP)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IAA, IAT
      REAL          XYZPOS(3), D12, WIFDST
      LOGICAL       BUMP, T54EQUAL







      BUMP=.FALSE.



      DO 20 IAA=1,NUMAAT
         IF (IAA.EQ.WIFPAR(604)) GOTO 20
         IF (SOUPNT(IAA).NE.SOUPNT(WIFPAR(604))) GOTO 20
         IF (MODNMB(IAA).NE.MODNMB(WIFPAR(604))) GOTO 20



         D12=SQRT((SPHRAD(1,IAA)-XYZPOS(1))**2+
     +            (SPHRAD(2,IAA)-XYZPOS(2))**2+
     +            (SPHRAD(3,IAA)-XYZPOS(3))**2)-SPHRAD(4,IAA)
         IF (D12.GT.FLOAT(-WIFPAR(1191))/1000.0) GOTO 20



         DO 10 IAT=PNTAAS(IAA),PNTAAE(IAA)
            IF (.NOT.ISATOK(IAT).OR.PROTON(IAT)) GOTO 10



            IF (ABS(IAA-WIFPAR(604)).LE.1.AND.
     +       IAT.LE.PNTAAS(IAA)+3) GOTO 10



            IF (T54EQUAL(ONESAT(IAT),' SG ').AND.
     +          T54EQUAL(ONESAT(WIFPAR(640)),' SG ')) THEN
               D12=WIFDST(IAT,WIFPAR(640))-2.0



            ELSE
               D12=SQRT((XCOORD(IAT)-XYZPOS(1))**2+
     +                  (YCOORD(IAT)-XYZPOS(2))**2+
     +                  (ZCOORD(IAT)-XYZPOS(3))**2)-VDWRAD(IAT)-1.8
            END IF
            IF (D12.LT.FLOAT(-WIFPAR(1191))/1000.0) THEN
               BUMP=.TRUE.
               GOTO 998
            END IF
   10    CONTINUE
   20 CONTINUE



  998 CONTINUE


      RETURN
      END   

      SUBROUTINE WIF429 (IAA)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'GRPINC.INC'
      INCLUDE       'DATBAS.INC'
      INTEGER       IAA, IHIT, IAAS, ISEQ
      LOGICAL       GVFIBN







      IF (WIFPAR(54).LE.0) GOTO 998
      IF (WIFPAR(1012).LE.0) GOTO 998



      CALL WIFSGP (1)



      DO 10 IHIT=1,WIFPAR(54)
         ISEQ=GRPNTR(1,IHIT)
         IAAS=GRPNTR(2,IHIT)
         IF (.NOT.GVFIBN(ISEQ,1,NBINDB)) GOTO 20
         IF (.NOT.GVFIBN(IAAS,1,MAXADB)) GOTO 20
 10   CONTINUE
      GOTO 998
 20   CONTINUE
      DO 30 IHIT=1,WIFPAR(54)
         ISEQ=GRPNTR(1,IHIT)
         IAAS=GRPNTR(2,IHIT)
         PRINT*,IHIT,IAA,IAAS,ISEQ,RESTYP(IAA),ALLSEQ(IAAS,ISEQ)
 30   CONTINUE
      CALL GVSKIL



  998 CONTINUE


      RETURN
      END   

      SUBROUTINE WIF432 (IAA,IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      LOGICAL       GVFYON, GVFIBN
      INTEGER       IAA, ISTART, IEND, IERR, WIF51HALF, WIF51H







      IF (.NOT.GVFIBN(IAA,1,NUMAAF)) THEN
         IERR=1
         CALL GVSTTE ('?NEWE2')
         GOTO 998
      END IF



      IERR=0
      WIF51H=WIF51HALF()
      ISTART=IAA-WIF51H
      IEND=IAA+WIF51H



      IF (ISTART.LT.1.OR.IEND.GT.NUMAAF) THEN
         IERR=1
         CALL GVSTTE ('?NEWE3')
         CALL GVSKIL
         GOTO 998
      END IF



      IF (CHAINN(2,ISTART).NE.CHAINN(2,IEND)) THEN
         CALL GVSTT6 ('?NEWT104')
         IF (GVFYON('?NEWY2',' ')) GOTO 998
         IERR=1
      END IF



  998 CONTINUE


      RETURN
      END
      SUBROUTINE WIF432A (IAA,IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      LOGICAL       GVFIBN
      INTEGER       IAA, ISTART, IEND, IERR, WIF51HALF, WIF51H







      IF (.NOT.GVFIBN(IAA,1,NUMAAF)) THEN
         IERR=1
         CALL GVSTTB ('?NEWB1')
         GOTO 998
      END IF



      IERR=0
      WIF51H=WIF51HALF()
      ISTART=IAA-WIF51H
      IEND=IAA+WIF51H



      IF (ISTART.LT.1.OR.IEND.GT.NUMAAF) THEN
         IERR=1
         GOTO 998
      END IF



      IF (CHAINN(2,ISTART).NE.CHAINN(2,IEND)) IERR=1



  998 CONTINUE


      RETURN
      END

      SUBROUTINE WIF444 (IFT1,IFT2,IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IERR, IFT1, IFT2, ISOUP1, ISOUP2
      LOGICAL       CHANGE, WIFISA







      IERR=0
      CHANGE=.FALSE.
      ISOUP1=CHAINN(2,IFT1)
      ISOUP2=CHAINN(2,IFT2)



      IF (ISOUP1.NE.ISOUP2) THEN
         CALL GVSTTE ('?NEWE10')
         IERR=1
      END IF



      IF (.NOT.WIFISA(ISOUP2)) THEN
         CALL GVSTTE ('?NEWE11')
         IERR=1
      END IF



      IF (IFT1-SOUADM(1,ISOUP1).LT.2) THEN
         CHANGE=.TRUE.
         IFT1=SOUADM(1,ISOUP1)+2
      END IF



      IF (SOUADM(2,ISOUP1)-IFT2.LT.2) THEN
         CHANGE=.TRUE.
         IFT2=SOUADM(2,ISOUP1)-2
      END IF



      IF (IFT2.LT.IFT1) THEN
         IERR=1
         GOTO 998
      END IF
      IF (CHANGE) CALL GVSTTI2 ('?NEWZ2',IFT1,IFT2)



  998 CONTINUE


      RETURN
      END

      SUBROUTINE WIF456

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'IRIGRA.INC'
      INCLUDE       'DATBAS.INC'
      INCLUDE       'DGLOOP.INC'
      INCLUDE       'HSTINC.INC'
      INCLUDE       'GRPINC.INC'
      INCLUDE       'ESPACE.INC'
      INTEGER       IGRP, IHIT, NHIT, ISEQ, IAAS, IAAE, IAA, I, J, IERR
      REAL          ALPHAS(3,35)
      LOGICAL       GVFIBN







      IF (WIFPAR(55).LE.0) THEN
         GOTO 998
      END IF



      CALL WIF115 (IGRP)
      IF (IGRP.EQ.0) GOTO 998
      IF (GRPHOW(IGRP)(1:2).NE.'DG') THEN
         CALL GVSTTE ('?DGB16')
         GOTO 998
      END IF



      NHIT=MIN(100,GRPLEN(IGRP))
      IF (NHIT.LE.0) THEN
         CALL GVSTTE ('?DGB15')
         GOTO 998
      END IF
      CALL GRTVIN



      DO 100 IHIT=1,NHIT
         IF (.NOT.GVFIBN(IHIT,1,WIFPAR(54))) THEN
            CALL GVSTT6 ('?M2661')
            CALL GVSTTI2 ('?M2662',WIFPAR(54),WIFPAR(55))
            CALL GVSTTI2 ('?M2663',J,IHIT)
            CALL GVSKIL
            GOTO 100
         END IF
         ISEQ=GRPNTR(1,IHIT)
         IAAS=GRPNTR(2,IHIT)
         IAAE=IAAS+WIFPAR(51)-1
         IAAE=MIN(IAAE,IAAS+34)



         CALL GVSNL6 (1)
         CALL GVSFMT ('?FMT661')
         CALL GVSCTB (LINE,80)
         WRITE (LINE,FMT,ERR=998) IHIT,NAMFIL(ISEQ),QFCSTR(IHIT,IGRP)
         CALL GVSTT6 (LINE)



         CALL GVSFMT ('?FMT667')
         CALL GVSCTB (LINE250,250)
         WRITE (LINE250,FMT,ERR=998) IAAS,IAAE,
     +    (AANAME(ALLSEQ(I,ISEQ)),I=IAAS,IAAE)
         CALL GVSTT6 (LINE250)



         CALL GVSFMT ('?FMT668')
         CALL GVSCTB (LINE250,250)
         WRITE (LINE250,FMT,ERR=998) (ALLHST(I,ISEQ),I=IAAS,IAAE)
         CALL GVSTT6 (LINE250)



         DO 10 IAA=IAAS,IAAE
            CALL REC003 (INDPNT(ISEQ)+IAA,IERR)
            IF (IERR.NE.0) GOTO 998
            IF (.NOT.LASTOK) GOTO 998



            CALL REC004 (ALPHAS(1,IAA-IAAS+1),ALPHAS(2,IAA-IAAS+1),
     +       ALPHAS(3,IAA-IAAS+1),2,IERR)
            IF (IERR.NE.0) GOTO 998
            CALL GVSMPV (ALPHAS(1,IAA-IAAS+1),DGMAT(1,1,IHIT,IGRP),
     +       DGVEC(1,IHIT,IGRP))
            CALL GVSTTR3 ('?M3128',ALPHAS(1,IAA-IAAS+1),
     +       ALPHAS(2,IAA-IAAS+1),ALPHAS(3,IAA-IAAS+1))
            CALL GRTCRS (ALPHAS(1,IAA-IAAS+1),ALPHAS(2,IAA-IAAS+1),
     +       ALPHAS(3,IAA-IAAS+1),0.1,180,IERR)
 10      CONTINUE
 100  CONTINUE
      IF (USE300) CALL GRAMOL (' ')



  998 CONTINUE


      RETURN
      END   
