



      LOGICAL FUNCTION WIF040(IAA,JAA,CUTOFF)



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IAA, JAA
      REAL          D, CUTOFF







      D=SQRT((SPHRAD(1,IAA)-SPHRAD(1,JAA))**2+
     +       (SPHRAD(2,IAA)-SPHRAD(2,JAA))**2+
     +       (SPHRAD(3,IAA)-SPHRAD(3,JAA))**2)



      WIF040=(D-SPHRAD(4,IAA)-SPHRAD(4,JAA)).LT.CUTOFF





      RETURN
      END
      LOGICAL FUNCTION WIF040A(IAA,JAA,CUTOFF)


















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IAA, JAA, IAT, JAT
      REAL          CUTOFF, WIFDST, D







      D=SQRT((SPHRAD(1,IAA)-SPHRAD(1,JAA))**2+
     +       (SPHRAD(2,IAA)-SPHRAD(2,JAA))**2+
     +       (SPHRAD(3,IAA)-SPHRAD(3,JAA))**2)
      WIF040A=(D-SPHRAD(4,IAA)-SPHRAD(4,JAA)).LT.CUTOFF
      IF (.NOT.WIF040A) GOTO 998



      WIF040A=.FALSE.
      DO 20 IAT=PNTAAS(IAA),PNTAAE(IAA)
         IF (.NOT.ISATOK(IAT)) GOTO 20
         DO 10 JAT=PNTAAS(JAA),PNTAAE(JAA)
            IF (.NOT.ISATOK(JAT)) GOTO 10
            IF (WIFDST(IAT,JAT)-VDWRAD(IAT)-VDWRAD(JAT).LT.CUTOFF) THEN
               WIF040A=.TRUE.
               GOTO 998
            END IF
   10    CONTINUE
   20 CONTINUE



  998 CONTINUE


      RETURN
      END
      LOGICAL FUNCTION WIF040B(IAA,JAA,CUTOFF)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IAA, JAA, IAT, JAT
      REAL          CUTOFF, WIFDST







      WIF040B=.FALSE.



      IF (RESTYP(IAA).EQ.6.OR.RESTYP(JAA).EQ.6) GOTO 998



      DO 20 IAT=PNTAAS(IAA)+4,PNTAAE(IAA)
         IF (.NOT.ISATOK(IAT)) GOTO 20
         DO 10 JAT=PNTAAS(JAA)+4,PNTAAE(JAA)
            IF (.NOT.ISATOK(JAT)) GOTO 10
            IF (WIFDST(IAT,JAT)-VDWRAD(IAT)-VDWRAD(JAT).LT.CUTOFF) THEN
               WIF040B=.TRUE.
               GOTO 998
            END IF
   10    CONTINUE
   20 CONTINUE



  998 CONTINUE


      RETURN
      END
      INTEGER FUNCTION WIF040C(IAA,JAA,CUTOFF)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IAA,JAA,IAT,JAT
      REAL          CUTOFF, WIFDST
      LOGICAL       WIF040







      WIF040C=0



      IF (.NOT.WIF040(IAA,JAA,CUTOFF)) GOTO 998
      IF (RESTYP(IAA).EQ.6.OR.RESTYP(JAA).EQ.6) GOTO 998
      IF (IAA.EQ.JAA) GOTO 998



      DO 20 IAT=PNTAAS(IAA)+4,PNTAAE(IAA)
         DO 10 JAT=PNTAAS(JAA)+4,PNTAAE(JAA)
            IF (WIFDST(IAT,JAT)-VDWRAD(IAT)-VDWRAD(JAT).LT.CUTOFF) THEN
               WIF040C=WIF040C+1
            END IF
   10    CONTINUE
   20 CONTINUE



  998 CONTINUE


      RETURN
      END
      SUBROUTINE WIF040D (IAA,JAA,CUTOFF,BBBB,BBSC,SCBB,SCSC)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IAA, JAA, IAT, JAT
      REAL          CUTOFF, WIFDST, BBBB, BBSC, SCBB, SCSC, DIST
      LOGICAL       WIF040, WIFIRA







      BBBB=99999.9
      BBSC=99999.9
      SCBB=99999.9
      SCSC=99999.9



      IF (.NOT.WIF040(IAA,JAA,CUTOFF)) GOTO 998
      IF ((.NOT.WIFIRA(IAA)).OR.(.NOT.WIFIRA(JAA))) GOTO 998



      DO 20 IAT=PNTAAS(IAA),PNTAAS(IAA)+3
         DO 10 JAT=PNTAAS(JAA),PNTAAS(JAA)+3
            DIST=WIFDST(IAT,JAT)-VDWRAD(IAT)-VDWRAD(JAT)
            IF (DIST.LT.CUTOFF) BBBB=MIN(BBBB,DIST)
   10    CONTINUE
   20 CONTINUE



      IF (RESTYP(JAA).NE.6) THEN
         DO 40 IAT=PNTAAS(IAA),PNTAAS(IAA)+3
            DO 30 JAT=PNTAAS(JAA)+4,PNTAAE(JAA)
               DIST=WIFDST(IAT,JAT)-VDWRAD(IAT)-VDWRAD(JAT)
               IF (DIST.LT.CUTOFF) BBSC=MIN(BBSC,DIST)
   30       CONTINUE
   40    CONTINUE
      END IF



      IF (RESTYP(IAA).NE.6) THEN
         DO 60 IAT=PNTAAS(IAA)+4,PNTAAE(IAA)
            DO 50 JAT=PNTAAS(JAA),PNTAAS(JAA)+3
               DIST=WIFDST(IAT,JAT)-VDWRAD(IAT)-VDWRAD(JAT)
               IF (DIST.LT.CUTOFF) SCBB=MIN(SCBB,DIST)
   50       CONTINUE
   60    CONTINUE
      END IF



      IF (RESTYP(IAA).NE.6.AND.RESTYP(JAA).NE.6) THEN
         DO 80 IAT=PNTAAS(IAA)+4,PNTAAE(IAA)
            DO 70 JAT=PNTAAS(JAA)+4,PNTAAE(JAA)
               DIST=WIFDST(IAT,JAT)-VDWRAD(IAT)-VDWRAD(JAT)
               IF (DIST.LT.CUTOFF) SCSC=MIN(SCSC,DIST)
   70       CONTINUE
   80    CONTINUE
      END IF



  998 CONTINUE


      RETURN
      END
      REAL FUNCTION WIF040E(IAA,JAA)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IAA, JAA, IAT, JAT
      REAL          DIJ, DIST, WIFDST







      IF (IAA.EQ.JAA) THEN
         WIF040E=0.0
         GOTO 998
      END IF



      DIST=99999.9



      DO 20 IAT=PNTAAS(IAA),PNTAAE(IAA)
         DO 10 JAT=PNTAAS(JAA),PNTAAE(JAA)
            DIJ=WIFDST(IAT,JAT)
            DIST=MIN(DIST,DIJ)
   10    CONTINUE
   20 CONTINUE  
      WIF040E=DIST   



  998 CONTINUE


      RETURN
      END   
      LOGICAL FUNCTION WIF050(IAA,JAA)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IAA, JAA
      LOGICAL       SYMCUT





      WIF050=SYMCUT(IAA,JAA,1,FLOAT(WIFPAR(56))/100.0)





      RETURN
      END

      SUBROUTINE WIF052 (IAA,IFT1,IFT2,IERR)


















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'GRPINC.INC'
      INCLUDE       'DGLOOP.INC'
      INTEGER       IAA, JAA, IFT1, IFT2, ITAG(MAXAA), IERR
      REAL          WIFDST, CBIAA(3), GVFDV3
      EQUIVALENCE   (ITAG(1),GRPNTR(1,1))







      CALL GVSITI (ITAG,MAXAA)
      CALL GVSRTC (PRPVAL,999999.9,IFT2)
      CALL GETCBETA (IAA,IERR)
      IF (IERR.NE.0) GOTO 998
      CALL GVSCPR (CBIAA,CBETA,3)



      DO 10 JAA=IFT1,IFT2
         PRPVAL(JAA)=WIFDST(PNTAAC(IAA),PNTAAC(JAA))
         ATTVAL(PNTAAC(JAA))=PRPVAL(JAA)
         CALL GETCBETA (JAA,IERR)
         IF (IERR.NE.0) GOTO 998
         ATTVAL(PNTAAS(JAA))=GVFDV3(CBIAA,CBETA)
   10 CONTINUE



      CALL GVSORT (PRPVAL,IFT2,ITAG)



      DO 20 JAA=IFT1,IFT2
         PRPVAL(JAA)=FLOAT(ITAG(JAA))
   20 CONTINUE



  998 CONTINUE


      RETURN
      END   

      SUBROUTINE WIF061

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IERR, IAA, IAT, JAT, JAA
      REAL          WIFDST
      CHARACTER*28  IATS, JATS, DIF000







      IERR=0



      CALL WIFGAT (' ',IAA,IAT,IERR)
      IF (IAT.LE.0.OR.IERR.NE.0) GOTO 998



      CALL WIFGAT (' ',JAA,JAT,IERR)
      IF (JAT.LE.0.OR.IERR.NE.0) GOTO 998



      CALL GVSCTB (LINE,80)
      IATS=DIF000(IAT)
      JATS=DIF000(JAT)
      CALL GVSFMT ('?FMT171')
      WRITE (LINE,FMT,ERR=999) IATS, JATS, WIFDST(IAT,JAT)
      CALL GVSTT6 (LINE)
      CALL GVSTT6 ('?M2368')
      CALL DIF013B (6,IAT,XCOORD(IAT),YCOORD(IAT),ZCOORD(IAT))
      CALL DIF013B (6,JAT,XCOORD(JAT),YCOORD(JAT),ZCOORD(JAT))



      CALL GVSFMT ('?FMT172')
      CALL GVSSTX (LINE,'?NEI-DST')
      WRITE (LINE(61:80),FMT,ERR=999) IAA,JAA
      CALL SETHIS (LINE)
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('WIF061')



  998 CONTINUE


      END
      SUBROUTINE WIF061A


















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IERR, IAA, JAA, IAT1, IAT2, JAT
      REAL          CUTOFF, WIFDST







      IERR=0
      CUTOFF=FLOAT(WIFPAR(56))/100.0



      CALL SCN110 (LOCNEI,'?M2633',IERR)
      IF (IERR.NE.0) GOTO 998
      CALL SCN111 (LOCNEI,LOCNET,' ',IERR)
      IF (IERR.NE.0) GOTO 998



      CALL SCN110 (LOCPAA,'?M2634',IERR)
      IF (IERR.NE.0) GOTO 998
      CALL SCN111 (LOCPAA,LOCPAT,' ',IERR)
      IF (IERR.NE.0) GOTO 998



      CALL SCN110 (LOCFAA,'?M2635',IERR)
      IF (IERR.NE.0) GOTO 998
      CALL SCN111 (LOCFAA,LOCFAT,' ',IERR)
      IF (IERR.NE.0) GOTO 998



      DO 100 IAA=1,NUMAAF-1
         IF (.NOT.LOCNEI(RESTYP(IAA))) GOTO 100
         IF (.NOT.LOCPAA(RESTYP(IAA+1))) GOTO 100



         DO 90 IAT1=PNTAAS(IAA),PNTAAE(IAA)
            IF (.NOT.LOCNET(PINIAA(IAT1))) GOTO 90



            DO 80 IAT2=PNTAAS(IAA+1),PNTAAE(IAA+1)
               IF (.NOT.LOCPAT(PINIAA(IAT2))) GOTO 80



               DO 70 JAA=1,NUMAAF
                  IF (.NOT.LOCFAA(RESTYP(JAA))) GOTO 70
                  IF (JAA.EQ.IAA.OR.JAA.EQ.IAA+1) GOTO 70



                  DO 60 JAT=PNTAAS(JAA),PNTAAE(JAA)
                     IF (.NOT.LOCFAT(PINIAA(JAT))) GOTO 60
                     IF (WIFDST(IAT1,JAT).GT.CUTOFF) GOTO 60
                     IF (WIFDST(IAT2,JAT).GT.CUTOFF) GOTO 60
                     CALL DIF014A (IAA,IAA+1,JAA)
 60               CONTINUE
 70            CONTINUE
 80         CONTINUE
 90      CONTINUE
 100  CONTINUE



 998  CONTINUE


      RETURN
      END
      SUBROUTINE WIF061B


















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IERR, IAA1, IAA2, IAA3, IAT1, IAT2, IAT3
      REAL          CUTOFF, WIFDST
      LOGICAL       LOC12(MAXTAT), LOC13(MAXTAT), WIF040B,
     +              LOC21(MAXTAT), LOC23(MAXTAT),
     +              LOC31(MAXTAT), LOC32(MAXTAT), OK12, OK23, OK13







      IERR=0
      CUTOFF=FLOAT(WIFPAR(56))/100.0



      CALL SCN110 (LOCNEI,'?M2633',IERR)
      IF (IERR.NE.0) GOTO 998
      CALL SCN111 (LOCNEI,LOC12,'?M2636',IERR)
      IF (IERR.NE.0) GOTO 998
      CALL SCN111 (LOCNEI,LOC13,'?M2637',IERR)
      IF (IERR.NE.0) GOTO 998



      CALL SCN110 (LOCPAA,'?M2634',IERR)
      IF (IERR.NE.0) GOTO 998
      CALL SCN111 (LOCPAA,LOC21,'?M2638',IERR)
      IF (IERR.NE.0) GOTO 998 
      CALL SCN111 (LOCPAA,LOC23,'?M2637',IERR)
      IF (IERR.NE.0) GOTO 998 



      CALL SCN110 (LOCFAA,'?M2635',IERR)
      IF (IERR.NE.0) GOTO 998
      CALL SCN111 (LOCFAA,LOC31,'?M2638',IERR)
      IF (IERR.NE.0) GOTO 998 
      CALL SCN111 (LOCFAA,LOC32,'?M2636',IERR)
      IF (IERR.NE.0) GOTO 998 



      DO 100 IAA1=1,NUMAAF
         IF (MOD(IAA1,100).EQ.0) PRINT*,IAA1
         IF (.NOT.LOCNEI(RESTYP(IAA1))) GOTO 100



         DO 90 IAA2=1,NUMAAF
            IF (.NOT.LOCPAA(RESTYP(IAA2))) GOTO 90
            IF (ABS(IAA2-IAA1).LE.1) GOTO 90
            IF (.NOT.WIF040B(IAA1,IAA2,CUTOFF-3.0)) GOTO 90



            DO 80 IAA3=1,NUMAAF
               IF (.NOT.LOCFAA(RESTYP(IAA3))) GOTO 80
               IF (ABS(IAA3-IAA1).LE.1.OR.ABS(IAA3-IAA2).LE.1) GOTO 80
               OK12=.FALSE.
               OK13=.FALSE.
               OK23=.FALSE.



               DO 70 IAT1=PNTAAS(IAA1),PNTAAE(IAA1)
                  IF (.NOT.LOC12(PINIAA(IAT1)).AND.
     +                .NOT.LOC13(PINIAA(IAT1))) GOTO 70



                  DO 60 IAT2=PNTAAS(IAA2),PNTAAE(IAA2)
                     IF (.NOT.LOC21(PINIAA(IAT2)).AND.
     +                   .NOT.LOC23(PINIAA(IAT2))) GOTO 60



                     DO 50 IAT3=PNTAAS(IAA3),PNTAAE(IAA3)
                        IF (.NOT.LOC31(PINIAA(IAT3)).AND.
     +                      .NOT.LOC32(PINIAA(IAT3))) GOTO 50



                        OK12=OK12.OR.(LOC12(PINIAA(IAT1)).AND.
     +                                LOC21(PINIAA(IAT2)).AND.
     +                                WIFDST(IAT1,IAT2).LE.CUTOFF)
                        OK13=OK13.OR.(LOC13(PINIAA(IAT1)).AND.
     +                                LOC31(PINIAA(IAT3)).AND.
     +                                WIFDST(IAT1,IAT3).LE.CUTOFF)
                        OK23=OK23.OR.(LOC23(PINIAA(IAT2)).AND.
     +                                LOC32(PINIAA(IAT3)).AND.
     +                                WIFDST(IAT2,IAT3).LE.CUTOFF)
                        IF (OK12.AND.OK13.AND.OK23) THEN
                           CALL DIF014A (IAA1,IAA2,IAA3)
                           GOTO 80
                        END IF
 50                  CONTINUE
 60               CONTINUE
 70            CONTINUE
 80         CONTINUE
 90      CONTINUE
 100  CONTINUE



  998 CONTINUE


      RETURN
      END
      SUBROUTINE WIF062

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IERR, IAA, IAT1, IAT2, IAT3, GVFFBT
      REAL          WIFANG
      CHARACTER*28  IATS, JATS, KATS, DIF000







      IERR=0



      CALL WIFGRS (IAA,'?RESIDM')
      IF (IAA.EQ.0) GOTO 998
      CALL GVSBTF (LOCPAA,NUMUA)
      LOCPAA(RESTYP(IAA))=.TRUE.
      CALL SCN111 (LOCPAA,LOCPAT,'?WIFGAT',IERR)
      IF (IERR.NE.0) GOTO 998
      IAT2=PNTAAS(IAA)+GVFFBT(LOCPAT,ATPRAA(RESTYP(IAA)))-1



      CALL WIFGRS (IAA,'?RESID1')
      IF (IAA.EQ.0) GOTO 998
      CALL GVSBTF (LOCPAA,NUMUA)
      LOCPAA(RESTYP(IAA))=.TRUE.
      CALL SCN111 (LOCPAA,LOCPAT,'?WIFGAT',IERR)
      IF (IERR.NE.0) GOTO 998
      IAT1=PNTAAS(IAA)+GVFFBT(LOCPAT,ATPRAA(RESTYP(IAA)))-1



      CALL WIFGRS (IAA,'?RESID2')
      IF (IAA.EQ.0) GOTO 998
      CALL GVSBTF (LOCPAA,NUMUA)
      LOCPAA(RESTYP(IAA))=.TRUE.
      CALL SCN111 (LOCPAA,LOCPAT,'?WIFGAT',IERR)
      IF (IERR.NE.0) GOTO 998
      IAT3=PNTAAS(IAA)+GVFFBT(LOCPAT,ATPRAA(RESTYP(IAA)))-1



      IATS=DIF000(IAT1)
      JATS=DIF000(IAT2)
      KATS=DIF000(IAT3)
      CALL GVSFMT ('?FMT171A')
      CALL GVSCTB (BIGLIN,132)
      WRITE (BIGLIN,FMT,ERR=999) IATS,JATS,KATS,WIFANG(IAT1,IAT2,IAT3)
      CALL GVSTT6 (BIGLIN)



      CALL SETHIS ('?NEI-ANG')
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('WIF062')



  998 CONTINUE


      RETURN
      END
