















      SUBROUTINE TOP001























      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IERR
      LOGICAL       GVFISF, GRTFILE







      CALL GVSCTB (LINE,80)
      IERR=0
      SPCNMB=2
      TOPUNT=0



      IF (GVFISF('TOPOLOGY.H')) THEN
         CALL GVSSTX (LINE,'TOPOLOGY.H')
      ELSE IF (GVFISF('TOPOLOGY.FIL')) THEN
         CALL GVSSTX (LINE,'TOPOLOGY.FIL')
      ELSE
         CALL SETFILNAM (LINE,'TOPOLOGY.FIL',IERR)
      END IF



      IF (IERR.NE.0) THEN
         CALL GVSCOD ('?EOF007')
         STOP
      END IF



      IF (.NOT.GRTFILE(TOPUNT,LINE)) THEN
         CALL GVSCOD ('?EOF007')
         STOP
      END IF



      CALL TOPINI



      CALL TOP002 (IERR)
      IF (IERR.NE.0) THEN
         CALL GVSCOD ('?ERF007')
         STOP
      END IF
      CALL GVSCLF (TOPUNT)



      IF (GVFISF('BADDRUG.FIL')) THEN



         IF (.NOT.GRTFILE(TOPUNT,'BADDRUG.FIL')) THEN
            CALL GVSCOD ('?EOF007')
            CALL GVSKIL
            GOTO 11
         END IF



         CALL TOP002 (IERR)
         IF (IERR.NE.0) THEN
            CALL GVSCOD ('?ERF007')
            GOTO 11
         END IF
         CALL GVSCLF (TOPUNT)
      END IF
 11   CONTINUE



      WIFPAR(294)=WIFPAR(276)
      CALL TOP006



      IF (TOPUNT.NE.0) CALL GVSCLF (TOPUNT)


      RETURN
      END
      SUBROUTINE TOPINI

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'CHIANG.INC'
      INCLUDE       'HGRINC.INC'
      INCLUDE       'REFINC.INC'







      CALL GVSIT0 (TORCON,MAXTAT*MAXTOR*NUMUA)
      CALL GVSIT0 (CHICON,4*MAXTOR*NUMUA)
      CALL GVSIT0 (MUTCON,2*MAXTAT*NUMUA)
      CALL GVSIT0 (ANGCON,3*MAXANG*NUMUA)
      CALL GVSIT0 (HGRAAS,NUMUA)
      CALL GVSIT0 (HGRAAE,NUMUA)
      CALL GVSIT0 (HGRAAN,NUMUA)
      CALL GVSIT0 (HGRATI,NUMUA*MAXTAT)
      CALL GVSIT0 (BOND13,12*MAXTAT*NUMUA)
      CALL GVSIT0 (FAMTYP,NUMUA)

      CALL GVSRT0 (DSTCON,MAXTAT*NUMUA)
      CALL GVSRT0 (DSTSIG,MAXTAT*NUMUA)
      CALL GVSRT0 (ANGDEF,MAXANG*NUMUA)
      CALL GVSRT0 (ANGSIG,MAXANG*NUMUA)
      CALL GVSRT0 (AAWGT,NUMUA)
      CALL GVSRT0 (STDCRD,3*MAXTAT*NUMUA)

      CALL GVSCTB (MUTROW4,5*MAXTAT*NUMUA)
      CALL GVSCTB (MUTSTO4,4*MAXTAT*NUMUA*MAXNNA)

      CALL GVSBTF (PLANAR,MAXTAT*MAXPGR*NUMUA)

      WIFPAR(276)=0
      NUMGRT=0





      RETURN
      END   
      SUBROUTINE TOP002 (IERR)
























      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'CHARGE.INC'
      INTEGER       IERR
      LOGICAL       GVFFOP







      IF (.NOT.GVFFOP(TOPUNT)) THEN
         CALL GVSTTB ('?TPFNIF')
         IERR=1
         GOTO 998
      END IF



      IERR=0



   10 CONTINUE



         CALL GETLINE (TOPUNT,LINE,IERR)
         IF (IERR.NE.0) GOTO 100
         IF (LINE(1:1).NE.'*') GOTO 10
         IF (LINE(1:4).EQ.'*END') GOTO 100



         CALL TOP003 (IERR)
         IF (IERR.NE.0) GOTO 100
      GOTO 10



  100 CONTINUE



      IF (ATPRAA(1).GT.5) THEN
         WIFPAR(84)=1
      ELSE
         WIFPAR(84)=0
      END IF



 998  CONTINUE


      RETURN
      END
      SUBROUTINE TOP003 (IERR)



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'CHIANG.INC'
      INCLUDE       'DATBAS.INC'
      INCLUDE       'HGRINC.INC'
      INCLUDE       'HBONDS.INC'
      INCLUDE       'CHARGE.INC'
      INCLUDE       'REFINC.INC'
      INCLUDE       'ESPACE.INC'
      INTEGER       MAXRRW, MAXIRW
      PARAMETER     (MAXRRW=5)
      PARAMETER     (MAXIRW=16)
      INTEGER       IROW(MAXIRW), ICEXP, ICON, ICNT, I, IAT, NPAR,
     +              IAT1, IAT2, ITOR, GVFLFI, IERR, GVFLFR, ILOOP, 
     +              IPEN, J, IRT, INNA
      REAL          RROW(MAXRRW), DEFDST
      LOGICAL       GVFFOP, GVFISN, DL
      CHARACTER*1   CHAR1, CHAR2
      CHARACTER*4   CHAR4, RT
      CHARACTER*256 LOCLIN







      IF (.NOT.GVFFOP(TOPUNT)) THEN
         CALL GVSTTB ('?TPFNIF')
         IERR=1
      END IF
      IF (WIFPAR(276).GT.NUMUA-1) THEN
         CALL GVSTTI2 ('?M0607',NUMUA,WIFPAR(276))
         WIFPAR(276)=NUMUA-1
      END IF




      IF (WIFPAR(810).NE.0) THEN
         CALL GVSBOX ('?M3629')
      END IF



      DL=DATOPE

      CALL PRP210 (IERR)



      ICEXP=MAXIRW
      IERR=0



      WIFPAR(276)=WIFPAR(276)+1
      IRT=WIFPAR(276)
      IF (WIFPAR(810).NE.0) THEN
         CALL GVSTTI ('WIFPAR(276)->',IRT)
         IF (DL) CALL GVSTUI (DATLOG,'WIFPAR(276)->',IRT)
      END IF



      CALL TOP003A (LOCLIN)
      IF (WIFPAR(810).NE.0.AND.WIFPAR(1208).EQ.0) CALL GVSCODA (' ')



      CALL GVSSTX (AANAME(IRT)(1:4),LOCLIN(1:4))
      CALL GVSSTX (A1NAME(IRT)(1:1),LOCLIN(5:5))
      RT=AANAME(IRT)

      IF (WIFPAR(810).NE.0) THEN
         CALL GVST6C ('?CHKM19',RT,.TRUE.)
         IF (DL) CALL GVSTUC (DATLOG,'?CHKM19',RT,.TRUE.)
      END IF
      CALL GVSFMT ('?FMT766')
      READ (LOCLIN,FMT,ERR=999) AAWGT(IRT)



      CALL GVSIT0 (IROW,MAXIRW)
      CALL TOP003A (LOCLIN)
      ICNT=GVFLFI(ICEXP,IROW,LOCLIN)
      IF (ICNT.LT.ICEXP-2) THEN
         CALL GVSTT6 (LOCLIN)
         CALL GVSTTI2 ('ICNT,ICEXP=',ICNT,ICEXP)
         CALL GVSTT6 ('?TPFBG1')
         CALL GVST6C ('?ERRTOR',RT,.TRUE.)
         CALL GVSKIL
         GOTO 997
      ELSE IF (ICNT.EQ.14) THEN
         IF (WIFPAR(810).NE.0) THEN
            CALL GVSTT6 ('?M3630')
            IF (DL) CALL GVSTTU (DATLOG,'?M3630')
         END IF
         IROW(15)=1
         IROW(16)=0
      END IF



      ATPRAA(IRT)=IROW(1)
      CHIUSE(IRT)=IROW(3)
      HATPRA(IRT)=IROW(8)
      IF (WIFPAR(810).NE.0) THEN
         CALL GVSTTI ('?M1907',IRT)
         CALL GVSTTI ('?M1908',IROW(1))
         CALL GVSTTI ('?M1909',IROW(2))
         CALL GVSTTI ('?M1910',IROW(3))
         CALL GVSTTI ('?M1911',IROW(4))
         CALL GVSTTI ('?M1912',IROW(5))
         CALL GVSTTI ('?M1913',IROW(6))
         CALL GVSTTI ('?M1914',IROW(7))
         CALL GVSTTI ('?M1915',IROW(8))
         CALL GVSTTI ('?M1916',IROW(9))
         IF (IROW(10).GT.0) THEN
            CALL GVSTT6 ('?M1917')
         ELSE
            CALL GVSTT6 ('?M1918')
         END IF
         IF (IROW(11).GT.0) THEN
            CALL GVSTT6 ('?M1919')
         ELSE
            CALL GVSTT6 ('?M1920')
         END IF
         CALL GVSTTI ('?M1922',IROW(13))
         CALL GVSTTI ('?M1923',IROW(14))
         CALL GVSTTI ('?M1923A',IROW(15))
      END IF
      IF (DL.AND.WIFPAR(810).NE.0) THEN
         CALL GVSTUI (DATLOG,'?M1907',IRT)
         CALL GVSTUI (DATLOG,'?M1908',IROW(1))
         CALL GVSTUI (DATLOG,'?M1909',IROW(2))
         CALL GVSTUI (DATLOG,'?M1910',IROW(3))
         CALL GVSTUI (DATLOG,'?M1911',IROW(4))
         CALL GVSTUI (DATLOG,'?M1912',IROW(5))
         CALL GVSTUI (DATLOG,'?M1913',IROW(6))
         CALL GVSTUI (DATLOG,'?M1914',IROW(7))
         CALL GVSTUI (DATLOG,'?M1915',IROW(8))
         CALL GVSTUI (DATLOG,'?M1916',IROW(9))
         IF (IROW(10).GT.0) THEN
            CALL GVSTTU (DATLOG,'?M1917')
         ELSE
            CALL GVSTTU (DATLOG,'?M1918')
         END IF
         IF (IROW(11).GT.0) THEN
            CALL GVSTTU (DATLOG,'?M1919')
         ELSE
            CALL GVSTTU (DATLOG,'?M1920')
         END IF
         CALL GVSTUI (DATLOG,'?M1922',IROW(13))
         CALL GVSTUI (DATLOG,'?M1923',IROW(14))
         CALL GVSTUI (DATLOG,'?M1923A',IROW(15))
      END IF
      CALL C1234567 ('In TOP003 at 1')



      IF (IROW(1).GT.MAXTAT) THEN
         CALL GVSTTE ('?M1906')
         CALL GVST6C ('?CHKM19',RT,.TRUE.)
         CALL GVSTTI2 ('?M1902',MAXTAT,IROW(1))
         GOTO 999
      END IF
      NUMNNA(IRT)=IROW(15)
      IF (IROW(15).EQ.1) THEN




         DO 13 ILOOP=1,(IROW(1)-1)/14+1
            CALL TOP003A (LOCLIN)

            CALL PRP206 (LOCLIN)
            DO 12 I=1,14
               CALL GVSSTX (MUTROW4(14*(ILOOP-1)+I,IRT),
     +          LOCLIN(5*I-4:5*I))
               CALL GVSSTX (MUTSTO4(14*(ILOOP-1)+I,IRT,1),
     +          LOCLIN(5*I-4:5*I-1))
 12         CONTINUE
 13      CONTINUE
      ELSE




         DO 16 INNA=1,IROW(15)

            CALL PRP208 ('?M4833',INNA)
            DO 15 ILOOP=1,(IROW(1)-1)/14+1
               CALL TOP003A (LOCLIN)

               CALL PRP206 (LOCLIN)
               DO 14 I=1,14
                  IF (INNA.EQ.1) THEN
                     CALL GVSSTX (MUTROW4(14*(ILOOP-1)+I,IRT),
     +                LOCLIN(5*I-4:5*I))
                     CALL GVSSTX (MUTSTO4(14*(ILOOP-1)+I,IRT,INNA),
     +                LOCLIN(5*I-4:5*I-1))
                  ELSE
                     CALL GVSSTX (MUTSTO4(14*(ILOOP-1)+I,IRT,INNA),
     +                LOCLIN(5*I-4:5*I-1))
                  END IF
 14            CONTINUE
 15         CONTINUE
            CALL C1234567 ('In TOP003 at 2')
 16      CONTINUE
      END IF
      CALL TOP_DEB_ATNAM (' ',IRT)



      IF (IROW(2).GT.MAXTAT) THEN
         CALL GVSTTE ('?M1905')
         CALL GVST6C ('?CHKM19',RT,.TRUE.)
         CALL GVSTTI2 ('?M1902',MAXTAT,IROW(2))
         GOTO 999
      END IF
      NCPRAA(WIFPAR(276))=IROW(2)
      DO 25 ILOOP=1,(IROW(2)-1)/10+1
         CALL TOP003A (LOCLIN)
         I=GVFLFI(20,MUTCON(1,10*(ILOOP-1)+1,IRT),LOCLIN)
         IF (WIFPAR(810).GT.0) THEN
            CALL GVSTTI (LOCLIN,I)
            IF (DL) CALL GVSTUI (DATLOG,LOCLIN,I)
         END IF
   25 CONTINUE
      CALL C1234567 ('In TOP003 at 3')
      IF (WIFPAR(810).GT.0) THEN
         DO 26 ILOOP=1,IROW(2)
            WRITE (6,3334,ERR=999) MUTCON(1,ILOOP,WIFPAR(276)),
     +       MUTCON(2,ILOOP,WIFPAR(276)),
     +       MUTROW4(MUTCON(1,ILOOP,WIFPAR(276)),WIFPAR(276)),
     +       MUTROW4(MUTCON(2,ILOOP,WIFPAR(276)),WIFPAR(276))
            IF (DL) WRITE (DATLOG,3334,ERR=999) MUTCON(1,ILOOP,
     +       WIFPAR(276)),MUTCON(2,ILOOP,WIFPAR(276)),
     +       MUTROW4(MUTCON(1,ILOOP,WIFPAR(276)),WIFPAR(276)),
     +       MUTROW4(MUTCON(2,ILOOP,WIFPAR(276)),WIFPAR(276))
 3334       FORMAT (2I5,2(1X,A5))
 26      CONTINUE
      END IF



      IF (IROW(3).GT.0) THEN
         IF (WIFPAR(810).NE.0) THEN
            CALL GVSTT6 ('?M1924')
            IF (DL) CALL GVSTTU (DATLOG,'?M1924')
         END IF
         IF (IROW(3).GT.MAXTOR) THEN
            CALL GVSTTE ('?M1925')
            CALL GVST6C ('?CHKM19',RT,.TRUE.)
            CALL GVSTTI2 ('?M1902',MAXTOR,IROW(3))
            GOTO 999
         END IF
         DO 40 ITOR=1,IROW(3)
            CALL TOP003A (LOCLIN)
            I=GVFLFI(MAXTAT,TORCON(1,ITOR,IRT),LOCLIN)
            IF (WIFPAR(810).NE.0) THEN
               WRITE (6,1040,ERR=40) IRT,ITOR,
     +          TORCON(1,ITOR,IRT),
     +          TORCON(2,ITOR,IRT),
     +          (TORCON(J,ITOR,IRT),J=3,I)
               IF (DL) WRITE (DATLOG,1040,ERR=40) IRT,ITOR,
     +          TORCON(1,ITOR,IRT),
     +          TORCON(2,ITOR,IRT),
     +          (TORCON(J,ITOR,IRT),J=3,I)
            END IF
   40    CONTINUE
      END IF
      CALL C1234567 ('In TOP003 at 4')



      IF (IROW(4).GT.0) THEN
         IF (IROW(4).GT.MAXTOR) THEN
            CALL GVSTTE ('?M1901')
            CALL GVST6C ('?CHKM19',RT,.TRUE.)
            CALL GVSTTI2 ('?M1902',MAXTOR,IROW(4))
            GOTO 999
         END IF
         IF (WIFPAR(810).NE.0) THEN
            CALL GVSTT6 ('?M1903')
            IF (DL) CALL GVSTTU (DATLOG,'?M1903')
         END IF
         DO 45 ILOOP=1,(IROW(4)-1)/5+1
            CALL TOP003A (LOCLIN)
            I=GVFLFI(20,CHICON(1,5*(ILOOP-1)+1,IRT),LOCLIN)
   45    CONTINUE
         DO 46 ILOOP=1,MAXTOR
            IF (WIFPAR(810).NE.0.AND.CHICON(1,ILOOP,IRT).GT.0)
     +          THEN
               WRITE (6,1030,ERR=46) IRT,ILOOP,
     +          (CHICON(I,ILOOP,IRT),I=1,4)
               IF (DL) WRITE (DATLOG,1030,ERR=46) IRT,ILOOP,
     +          (CHICON(I,ILOOP,IRT),I=1,4)
            END IF
   46    CONTINUE
      END IF
      CALL C1234567 ('In TOP003 at 5')



      IF (IROW(5).GT.0) THEN
         IF (IROW(5).GT.MAXTAT) THEN
            CALL GVSTTE ('?M1904')
            CALL GVST6C ('?CHKM19',RT,.TRUE.)
            CALL GVSTTI2 ('?M1902',MAXTAT,IROW(5))
            GOTO 999
         END IF
         DO 50 IAT=1,ATPRAA(IRT)
            CALL TOP003A (LOCLIN)



            CALL GVSFMT ('?FMT1283')
            READ (LOCLIN(1:27),FMT,ERR=501,END=999) 
     +       (STDCRD(I,IAT,IRT),I=1,3)
            GOTO 601
 501        CONTINUE
            CALL GVSRT0 (RROW,MAXRRW)
            I=GVFLFR(3,RROW,LOCLIN)
            STDCRD(1,IAT,IRT)=RROW(1)
            STDCRD(2,IAT,IRT)=RROW(2)
            STDCRD(3,IAT,IRT)=RROW(3)
 601        CONTINUE



            HBOPOS(IRT,IAT)=LOCLIN(30:30).EQ.'T'
            IF (LOCLIN(31:31).EQ.'+') THEN
               HBOPAR(IRT,IAT)=1
            ELSE IF (LOCLIN(31:31).EQ.'-') THEN
               HBOPAR(IRT,IAT)=-1
            END IF



            IF (LOCLIN(32:33).EQ.'  ') THEN
               HBOTYP(IRT,IAT)=0
            ELSE
               READ (LOCLIN(32:33),1010,ERR=999,END=998)
     +          HBOTYP(IRT,IAT)
            END IF



            IF (LOCLIN(34:35).EQ.'  ') THEN
               HGRATI(IRT,IAT)=0
            ELSE
               READ (LOCLIN(34:35),1010,ERR=999,END=998)
     +          HGRATI(IRT,IAT)
            END IF



            PLANAR(IAT,1,IRT)=LOCLIN(36:36).EQ.'1'.OR.
     +                        LOCLIN(37:37).EQ.'1'.OR.
     +                        LOCLIN(38:38).EQ.'1'.OR.
     +                        LOCLIN(39:39).EQ.'1'
            PLANAR(IAT,2,IRT)=LOCLIN(36:36).EQ.'2'.OR.
     +                        LOCLIN(37:37).EQ.'2'.OR.
     +                        LOCLIN(38:38).EQ.'2'.OR.
     +                        LOCLIN(39:39).EQ.'2'
            PLANAR(IAT,3,IRT)=LOCLIN(36:36).EQ.'3'.OR.
     +                        LOCLIN(37:37).EQ.'3'.OR.
     +                        LOCLIN(38:38).EQ.'3'.OR.
     +                        LOCLIN(39:39).EQ.'3'
            PLANAR(IAT,4,IRT)=LOCLIN(36:36).EQ.'4'.OR.
     +                        LOCLIN(37:37).EQ.'4'.OR.
     +                        LOCLIN(38:38).EQ.'4'.OR.
     +                        LOCLIN(39:39).EQ.'4'
            PLANAR(IAT,5,IRT)=LOCLIN(36:36).EQ.'5'.OR.
     +                        LOCLIN(37:37).EQ.'5'.OR.
     +                        LOCLIN(38:38).EQ.'5'.OR.
     +                        LOCLIN(39:39).EQ.'5'
            IF (WIFPAR(810).GT.0) THEN
               WRITE (6,3335,ERR=999) IAT,MUTROW4(IAT,WIFPAR(276)),
     +          STDCRD(1,IAT,IRT),STDCRD(2,IAT,IRT),STDCRD(3,IAT,IRT),
     +          HBOPAR(IRT,IAT),HBOTYP(IRT,IAT),HGRATI(IRT,IAT),
     +          HBOPOS(IRT,IAT)
               IF (DL) WRITE (DATLOG,3335,ERR=999) IAT,
     +          MUTROW4(IAT,WIFPAR(276)),
     +          STDCRD(1,IAT,IRT),STDCRD(2,IAT,IRT),STDCRD(3,IAT,IRT),
     +          HBOPAR(IRT,IAT),HBOTYP(IRT,IAT),HGRATI(IRT,IAT),
     +          HBOPOS(IRT,IAT)
 3335          FORMAT (I5,1X,A5,3F7.2,3I4,' ',L1)
            END IF
   50    CONTINUE
      END IF
      CALL C1234567 ('In TOP003 at 6')



      DO 60 ICON=1,IROW(2)
         IAT1=MUTCON(1,ICON,IRT)
         IAT2=MUTCON(2,ICON,IRT)
         CALL GVSSTX (CHAR4,MUTROW4(IAT1,IRT)(1:4))
         CALL GVSSHL (CHAR4)
         CHAR1=CHAR4(1:1)
         CALL GVSSTX (CHAR4,MUTROW4(IAT2,IRT)(1:4))
         CALL GVSSHL (CHAR4)
         CHAR2=CHAR4(1:1)
         DEFDST=0.0
         IF (CHAR1.EQ.'P') THEN
            DEFDST=DEFDST+1.06
         ELSE IF (CHAR1.EQ.'S') THEN
            DEFDST=DEFDST+1.02
         ELSE IF (CHAR1.EQ.'C') THEN
            DEFDST=DEFDST+0.75
         ELSE IF (CHAR1.EQ.'N') THEN
            DEFDST=DEFDST+0.70
         ELSE IF (CHAR1.EQ.'O') THEN
            DEFDST=DEFDST+0.61
         END IF
         IF (CHAR2.EQ.'P') THEN
            DEFDST=DEFDST+1.06
         ELSE IF (CHAR2.EQ.'S') THEN
            DEFDST=DEFDST+1.02
         ELSE IF (CHAR2.EQ.'C') THEN
            DEFDST=DEFDST+0.75
         ELSE IF (CHAR2.EQ.'N') THEN
            DEFDST=DEFDST+0.70
         ELSE IF (CHAR2.EQ.'O') THEN
            DEFDST=DEFDST+0.61
         END IF
         IF (GVFISN(CHAR1).OR.GVFISN(CHAR2)) DEFDST=1.0
         DSTCON(ICON,IRT)=DEFDST
         IF (DEFDST.GT.1.50) THEN
            DSTSIG(ICON,IRT)=0.07
         ELSE 
            DSTSIG(ICON,IRT)=0.05
         END IF
   60 CONTINUE
      CALL C1234567 ('In TOP003 at 7')



      IF (IROW(6).GT.0) THEN
         IF (IROW(6).GT.MAXTAT) THEN
            CALL GVSTTE ('?M1926')
            CALL GVST6C ('?CHKM19',RT,.TRUE.)
            CALL GVSTTI2 ('?M1902',MAXANG,IROW(9))
            GOTO 999
         END IF
         IF (WIFPAR(810).NE.0) THEN
            CALL GVSTT6 ('?M1927')
            IF (DL) CALL GVSTTU (DATLOG,'?M1927')
         END IF
         DO 70 ICON=1,IROW(6)
            CALL TOP003A (LOCLIN)
            IF (LOCLIN(1:1).EQ.'*') THEN
               CALL GVSTT6 ('?TPFBG2')
               CALL GVSKIL
               GOTO 999
            END IF
            CALL GVSFMT ('?FMT1284')
            READ (LOCLIN,FMT,ERR=502,END=999) DSTCON(ICON,IRT),
     +       DSTSIG(ICON,IRT)
            GOTO 602
 502        CONTINUE
               I=GVFLFR(2,RROW,LOCLIN)
               DSTCON(ICON,IRT)=RROW(1)
               DSTSIG(ICON,IRT)=RROW(2)
 602        CONTINUE
            IF (WIFPAR(810).NE.0) THEN
               CALL GVSCTB (LINE,80)
               CALL GVSFMT ('?FMT450')
               WRITE (LINE,FMT,ERR=996) MUTCON(1,ICON,IRT),
     +          MUTCON(2,ICON,IRT),DSTCON(ICON,IRT)
               CALL GVSTT6 (LINE)
               IF (DL) CALL GVSTTU (DATLOG,LINE)
            END IF
   70    CONTINUE
      END IF
      CALL C1234567 ('In TOP003 at 8')



      IF (IROW(9).GT.0) THEN
         IF (IROW(9).GT.MAXANG) THEN
            CALL GVSTTE ('?M1928')
            CALL GVST6C ('?CHKM19',RT,.TRUE.)
            CALL GVSTTI2 ('?M1902',MAXANG,IROW(9))
            GOTO 999
         END IF
         IF (WIFPAR(810).NE.0) THEN
            CALL GVSTT6 ('?M1929')
            CALL GVSTTU (DATLOG,'?M1929')
         END IF
         DO 75 I=1,IROW(9)
            CALL TOP003A (LOCLIN)
            IF (LOCLIN(1:1).EQ.'*') THEN
               CALL GVSTT6 ('?TPFBG2A')
               CALL GVSKIL
               GOTO 999
            END IF
            J=GVFLFR(5,RROW,LOCLIN)
            ANGCON(1,I,IRT)=NINT(RROW(1))
            ANGCON(2,I,IRT)=NINT(RROW(2))
            ANGCON(3,I,IRT)=NINT(RROW(3))
            ANGDEF(I,IRT)=RROW(4)
            ANGSIG(I,IRT)=RROW(5)
            IF (WIFPAR(810).NE.0) THEN
               CALL GVSCTB (LINE,80)
               CALL GVSFMT ('?FMT451') 
               WRITE (LINE,FMT,ERR=996) ANGCON(1,I,IRT),
     +          ANGCON(2,I,IRT),ANGCON(3,I,IRT),ANGDEF(I,IRT),
     +          ANGSIG(I,IRT)
               CALL GVSTT6 (LINE)
               IF (DL) CALL GVSTTU (DATLOG,LINE)
            END IF
   75   CONTINUE
      END IF
      CALL C1234567 ('In TOP003 at 9')



      IF (IROW(10).GT.0) THEN
         IF (IROW(10).GT.MAXTAT) THEN
            CALL GVSTTE ('?M1930')
            CALL GVST6C ('?CHKM19',RT,.TRUE.)
            CALL GVSTTI2 ('?M1902',MAXANG,IROW(10))
            GOTO 999
         END IF
         IF (WIFPAR(810).NE.0) THEN
            CALL GVSTT6 ('?M1931')
            IF (DL) CALL GVSTTU (DATLOG,'?M1931')
         END IF
         DO 80 IAT=1,ATPRAA(IRT)
            CALL TOP003A (LOCLIN)
            I=GVFLFI(12,BOND13(1,IAT,IRT),LOCLIN)
            IF (I.LE.0) GOTO 999
            IF (WIFPAR(810).NE.0) THEN
               CALL GVSCTB (LINE,80)
               CALL GVSFMT ('?FMT452')
               WRITE (LINE,FMT,ERR=996) (BOND13(J,IAT,IRT),J=1,I)
               CALL GVSTT6 (LINE)
               IF (DL) CALL GVSTTU (DATLOG,LINE)
            END IF
   80    CONTINUE
      END IF
      CALL C1234567 ('In TOP003 at 10')



      HGRAAN(IRT)=IROW(7)
      HGRAAS(IRT)=NUMGRT+1
      HGRAAE(IRT)=NUMGRT+IROW(7)
      IF (WIFPAR(810).NE.0) THEN
         CALL GVSTTI ('?M2839',IROW(7))
         IF (DL) CALL GVSTUI (DATLOG,'?M2839',IROW(7))
      END IF
      IF (IROW(7).GT.0) THEN
         DO 90 I=1,IROW(7)
            NUMGRT=NUMGRT+1
            IF (NUMGRT.GT.MAXGRT) THEN
               CALL GVSKIL
               GOTO 997
            END IF
            CALL TOP003A (LOCLIN)
            IF (WIFPAR(810).NE.0) THEN
               CALL GVST6C ('HGr',LOCLIN(1:60),.TRUE.)
               IF (DL) CALL GVSTUC (DATLOG,'HGr',LOCLIN(1:60),.TRUE.)
            END IF
            READ (LOCLIN,1020,ERR=999,END=998) HGRNUM(NUMGRT),
     +       (HGRPEN(IPEN,NUMGRT),IPEN=0,MAXGRS)
            IF (WIFPAR(810).NE.0) THEN
               CALL GVSCTB (LINE250,250)
               CALL GVSFMT ('?FMT453') 
               WRITE (LINE250,FMT,ERR=996) NUMGRT,HGRNUM(NUMGRT),
     +         (HGRPEN(IPEN,NUMGRT),IPEN=0,MAXGRS)
               CALL GVSTT6 (LINE250)
               IF (DL) CALL GVSTTU (DATLOG,LINE250)
            END IF
   90    CONTINUE
      END IF
      CALL C1234567 ('In TOP003 at 11')



      IF (IROW(11).GT.MAXCHG) THEN
         CALL GVSTTE ('?M1935')
         CALL GVST6C ('?CHKM19',RT,.TRUE.)
         CALL GVSTTI2 ('?M1902',MAXCHG,IROW(11))
         GOTO 999
      END IF



      IF (IROW(11).GT.0) THEN

         DO 100 NPAR=1,IROW(11)
            IPEN=0
 212        CONTINUE
               CALL TOP003A (LOCLIN)

               IF (LOCLIN(1:4).EQ.'*END') GOTO 900
               IPEN=IPEN+GVFLFR(ATPRAA(IRT),CHGGRT(IPEN+1,NPAR,IRT),
     +          LOCLIN)
            IF (IPEN.LT.HATPRA(IRT)) GOTO 212
 100     CONTINUE
      END IF






      SETROT(IRT)=IROW(16)
      IF (IROW(3).GT.0.AND.IROW(16).GT.0) THEN
         DO 130 J=1,IROW(16)
            CALL TOP003A (LOCLIN)
            IF (LOCLIN(1:4).EQ.'*END') THEN
               IF (WIFPAR(810).NE.0) THEN
                  CALL GVSTT6 ('?M1937')
                  IF (DL) CALL GVSTTU (DATLOG,'?M1937')
               END IF
               GOTO 900
            END IF
            I=GVFLFR(IROW(3),VALROT(1,J,IRT),LOCLIN)
            IF (WIFPAR(810).NE.0) CALL GVSTTR4 ('VALROT=',VALROT
     +       (1,J,IRT),VALROT(2,J,IRT),VALROT(3,J,IRT),VALROT(4,J,IRT))
            IF (DL.AND.WIFPAR(810).NE.0) CALL GVSTTR4U (DATLOG,
     +       'VALROT=',VALROT(1,J,IRT),VALROT(2,J,IRT),VALROT(3,J,IRT),
     +       VALROT(4,J,IRT))
 130     CONTINUE
      ELSE
         IF (WIFPAR(810).GT.0) THEN
            CALL GVSTT6 ('?M3669')
            IF (DL) CALL GVSTTU (DATLOG,'?M3669')
         END IF
      END IF



  900 CONTINUE
      CALL C1234567 ('In TOP003 at 12')
      IF (WIFPAR(810).NE.0) THEN
         CALL GVSTT6 ('?M1938')
         IF (DL) CALL GVSTTU (DATLOG,'?M1938')
         CALL GVSNL6 (2)
      END IF



      IF (IROW(14).EQ.0) THEN
         FAMTYP(IRT)=6
      ELSE
         FAMTYP(IRT)=IROW(14)
      END IF



      IF (WIFPAR(810).NE.0) THEN
         CALL GVSTT6 (AANAME(IRT)(1:4))
         IF (DL) CALL GVSTTU (DATLOG,AANAME(IRT)(1:4))
      END IF
      GOTO 995



  999 CONTINUE
      CALL GVSNL6 (2)
      CALL GVSTTB ('?M3670')
      IERR=1
      GOTO 995
  998 CONTINUE
      CALL GVSNL6 (2)
      CALL GVSKIL
      CALL GVSTTB ('?M4983')
      IERR=1
      GOTO 995
  997 CONTINUE
      CALL GVSNL6 (2)
      CALL GVSTTB ('?M4984')
      IERR=1
      GOTO 995
  996 CONTINUE
      CALL GVSNL6 (2)
      CALL GVSTTB ('?M4985')
      IERR=1



  995 CONTINUE


 1010 FORMAT (I2)
 1020 FORMAT (I5,30F5.2)
 1030 FORMAT ('CHICON',2I4,3X,20I3)
 1040 FORMAT (2I4,3X,2I4,3X,40I3)

      RETURN
      END
      SUBROUTINE TOP003A (TEXT)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       GVFLEN
      LOGICAL       GVFFOP
      CHARACTER*256 TEXT







      IF (.NOT.GVFFOP(TOPUNT)) THEN 
         CALL SHOWTEXT ('?M3562')
         STOP '          FATAL TOPOLOGY FILE READING ERROR            '
      END IF



 10   CONTINUE
         READ (TOPUNT,1000,ERR=999,END=999) TEXT

         CALL PRP206 (TEXT)



         IF (GVFLEN(TEXT).LE.0) GOTO 10



         IF (WIFPAR(810).GT.1) CALL GVST6C ('Read:',TEXT(1:60),.FALSE.)



         IF (TEXT(1:1).NE.'#') GOTO 998
      GOTO 10



  999 CONTINUE
      CALL SHOWTEXT ('?M3562')
      STOP '          FATAL TOPOLOGY FILE READING ERROR              '



  998 CONTINUE


 1000 FORMAT (A256)

      RETURN
      END   
      SUBROUTINE TOP004 (IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IERR







      IERR=0
      TOPUNT=0



      CALL GVSROF (TOPUNT,IERR)
      IF (TOPUNT.LE.0.OR.IERR.NE.0) THEN
         CALL GVSTTE ('?M3628')
         IERR=1
         GOTO 998
      END IF
      CALL GETFILE (TOPUNT,' ','DRGWIF.TOP',IERR)
      IF (IERR.NE.0) THEN
         CALL GVSTTE ('?M0474')
         IERR=1
         GOTO 998
      END IF



   10 CONTINUE
         CALL GETLINE (TOPUNT,LINE,IERR)
         IF (IERR.NE.0) GOTO 998
      IF (LINE(1:1).NE.'*') GOTO 10



      CALL TOP003 (IERR)



  998 CONTINUE
      CALL GVSCLF (TOPUNT)


      RETURN
      END   
      SUBROUTINE TOP005 (ISTART)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'CHIANG.INC'
      INTEGER       ISTART, IAT, IBND, I, IAATYP







      IF (ISTART.GT.NUMUA) THEN
         CALL GVSTTB ('?M3110')
         GOTO 998
      END IF



      DO 100 IAATYP=ISTART,NUMUA



         ATPRAA(IAATYP)=0
         HATPRA(IAATYP)=0
         NCPRAA(IAATYP)=0
         FAMTYP(IAATYP)=0



         DO 10 IAT=1,MAXTAT
            MUTCON(1,IAT,IAATYP)=0
            MUTCON(2,IAT,IAATYP)=0
 10      CONTINUE



         CALL GVSCTB (AANAME(IAATYP),4)
         A1NAME(IAATYP)=' '
         DO 30 IAT=1,MAXTAT
            CALL GVSCTB (MUTROW4(IAT,IAATYP),5)
            DO 20 I=1,MAXNNA
               CALL GVSCTB (MUTSTO4(IAT,IAATYP,I),4)
 20         CONTINUE
 30      CONTINUE



         AAWGT(IAATYP)=0.0
         DO 50 IAT=1,MAXTAT
            STDCRD(1,IAT,IAATYP)=0.0
            STDCRD(2,IAT,IAATYP)=0.0
            STDCRD(3,IAT,IAATYP)=0.0
            DSTCON(IAT,IAATYP)=0.0
            DSTSIG(IAT,IAATYP)=0.0
            DO 40 IBND=1,12
               BOND13(IBND,IAT,IAATYP)=0
 40         CONTINUE
 50      CONTINUE



         CHIUSE(IAATYP)=0
         DO 60 IAT=1,MAXANG
            ANGCON(1,IAT,IAATYP)=0
            ANGCON(2,IAT,IAATYP)=0
            ANGCON(3,IAT,IAATYP)=0
            ANGDEF(IAT,IAATYP)=0.0
            ANGSIG(IAT,IAATYP)=0.0
 60      CONTINUE
         DO 80 IBND=1,MAXTOR
            CHICON(1,IBND,IAATYP)=0
            CHICON(2,IBND,IAATYP)=0
            CHICON(3,IBND,IAATYP)=0
            CHICON(4,IBND,IAATYP)=0
            DO 70 IAT=1,MAXTAT
               TORCON(IAT,IBND,IAATYP)=0
 70         CONTINUE
 80      CONTINUE
 100  CONTINUE



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE TOP006

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IERR, IUNIT, NEXT
      LOGICAL       GRTFILE







      CALL GVSCTB (SPCATM,4*25)
      NEXT=0



      CALL GVSCCC (LINE,WHERIS,'SPCATM.DAT')
      IF (.NOT.GRTFILE(IUNIT,LINE)) STOP 'Topology SPCATM.DAT missing'



 10   CONTINUE
         CALL GVSCTB (LINE,80)
         CALL GETLINE (IUNIT,LINE,IERR)
         IF (IERR.NE.0) GOTO 998
         IF (LINE(1:1).EQ.'#') GOTO 10
         NEXT=NEXT+1
         IF (SPCNMB.EQ.1) THEN
            READ (LINE,1001,ERR=998,END=998) SPCATM(NEXT)
         ELSE IF (SPCNMB.EQ.2) THEN
            READ (LINE,1002,ERR=998,END=998) SPCATM(NEXT)
         ELSE IF (SPCNMB.EQ.3) THEN
            READ (LINE,1003,ERR=998,END=998) SPCATM(NEXT)
         END IF
      GOTO 10



  998 CONTINUE
      CALL GVSCLF (IUNIT)


 1001 FORMAT  (1X,A4)
 1002 FORMAT  (6X,A4)
 1003 FORMAT (11X,A4)

      RETURN
      END   
      LOGICAL FUNCTION TOP007(TEXT)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IAATYP, INDAA3, I
      LOGICAL       CH4EQCH4
      CHARACTER*(*) TEXT







      TOP007=.FALSE.



      IF (TEXT(1:4).NE.'ATOM'.AND.TEXT(1:6).NE.'HETATM') GOTO 998



      IF (CH4EQCH4(TEXT(13:16),' O2 ')) THEN
         IAATYP=INDAA3(TEXT(18:21))
         IF (IAATYP.GT.0) THEN
            DO 10 I=1,ATPRAA(IAATYP)
               IF (MUTROW4(I,IAATYP).EQ.' O2 ') THEN
                  TOP007=.TRUE.
                  GOTO 998
               END IF
 10         CONTINUE
         END IF
      END IF



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE TOP008 (TEXT)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IUNIT, JUNIT, KUNIT, IERR, GVFLEN
      LOGICAL       GVFISF, GOTFILE, GRTFILE
      CHARACTER*80  DRGWIF
      CHARACTER*(*) TEXT







      IUNIT=0
      JUNIT=0
      KUNIT=0
      IF (GVFISF('TOPOLOGY.H')) THEN
         IF (WIFPAR(84).EQ.0) THEN
            CALL GVSTT6 ('TOPOLOGY.H found while proton flag is off')
            GOTO 998
         END IF
      END IF
      IF (WIFPAR(276).GE.NUMUA-1) THEN
         STOP '          Too many drugs; increase NUMUA in BIGINC.INC'
      END IF
      CALL GVSSTX (DRGWIF,TEXT)
      IF (GVFLEN(DRGWIF).LE.0) CALL GVSSTX (DRGWIF,'DRGWIF.TOP')
      IF (.NOT.GVFISF(DRGWIF)) GOTO 998



      CALL GVSCLF (TOPUNT)
      CALL GVSDEL ('TOPOLOGY.NEW')



      IF (WIFPAR(84).EQ.0) THEN
         CALL SETFILNAM (LINE,'TOPOLOGY.FIL',IERR)
      ELSE
         CALL SETFILNAM (LINE,'TOPOLOGY.H',IERR)
      END IF
      IF (IERR.NE.0) GOTO 999
      IF (.NOT.GRTFILE(IUNIT,LINE)) GOTO 999
      IF (.NOT.GRTFILE(JUNIT,DRGWIF)) GOTO 999
      IF (.NOT.GOTFILE(KUNIT,'TOPOLOGY.NEW')) GOTO 999



      CALL PRP201 ('?M4968')
 10   CONTINUE
         CALL GVSCTB (LINE,80)
         CALL GETLINE (IUNIT,LINE,IERR)
         IF (IERR.NE.0) GOTO 999
         IF (LINE(1:4).EQ.'*END') GOTO 20
         CALL GVSTTU (KUNIT,LINE)
      GOTO 10



 20   CONTINUE
         CALL GVSCTB (LINE,80)
         CALL GETLINE (JUNIT,LINE,IERR)
         IF (IERR.NE.0) GOTO 999
         CALL GVSTTU (KUNIT,LINE)
         CALL PRP201 (LINE)
         IF (LINE(1:4).EQ.'*END') GOTO 30
      GOTO 20



 30   CONTINUE
      IF (IUNIT.NE.0) CALL GVSCLF (IUNIT)
      IF (JUNIT.NE.0) CALL GVSCLF (JUNIT)
      IF (KUNIT.NE.0) CALL GVSCLF (KUNIT)
      IF (GVFISF('TOPOLOGY.FIL').OR.WIFPAR(84).EQ.0) THEN
         IF (GVFISF('TOPOLOGY.FIL')) CALL GVSDEL ('TOPOLOGY.FIL')
         CALL GVSMV ('TOPOLOGY.FIL','TOPOLOGY.NEW',BIGLIN)
      ELSE
         CALL GVSDEL ('TOPOLOGY.H')
         CALL GVSMV ('TOPOLOGY.H','TOPOLOGY.NEW',BIGLIN)
      END IF
      IF (GVFISF('TOPOLOGY.NEW')) CALL GVSDEL ('TOPOLOGY.NEW')
      CALL TOP001
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('TOP008')



  998 CONTINUE
      IF (IUNIT.NE.0) CALL GVSCLF (IUNIT)
      IF (JUNIT.NE.0) CALL GVSCLF (JUNIT)
      IF (KUNIT.NE.0) CALL GVSCLF (KUNIT)


      RETURN
      END   
      SUBROUTINE TOP008D (TEXT)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IUNIT, JUNIT, KUNIT, IERR, GVFLEN
      LOGICAL       GVFISF, GOTFILE, GRTFILE
      CHARACTER*80  DRGWIF
      CHARACTER*(*) TEXT







      CALL GVSSTX (DRGWIF,TEXT)
      IF (GVFLEN(DRGWIF).LE.0) CALL GVSSTX (DRGWIF,'DRGWIF.TOP')
      IF (.NOT.GVFISF(DRGWIF)) GOTO 998



      IUNIT=0
      JUNIT=0
      KUNIT=0
      CALL GVSCLF (TOPUNT)
      CALL GVSDEL ('TOPOLOGY.NEW')
      IF (.NOT.GVFISF('BADDRUG.FIL')) THEN
         CALL GVSCPP ('BADDRUG.FIL',DRGWIF,BIGLIN)
         GOTO 998
      END IF



      IF (.NOT.GRTFILE(IUNIT,'BADDRUG.FIL')) GOTO 999
      IF (.NOT.GRTFILE(JUNIT,DRGWIF)) GOTO 999
      IF (.NOT.GOTFILE(KUNIT,'TOPOLOGY.NEW')) GOTO 999



      CALL PRP201 ('?M4968')
 10   CONTINUE
         CALL GVSCTB (LINE,80)
         CALL GETLINE (IUNIT,LINE,IERR)
         IF (IERR.NE.0) GOTO 999
         IF (LINE(1:4).EQ.'*END') GOTO 20
         CALL GVSTTU (KUNIT,LINE)
         CALL GVST6C ('BAD-OLD',LINE(1:60),.TRUE.)
      GOTO 10



 20   CONTINUE
         CALL GVSCTB (LINE,80)
         CALL GETLINE (JUNIT,LINE,IERR)
         IF (IERR.NE.0) GOTO 999
         CALL GVSTTU (KUNIT,LINE)
         CALL PRP201 (LINE)
         CALL GVST6C ('BAD-NEW',LINE(1:60),.TRUE.)
         IF (LINE(1:4).EQ.'*END') GOTO 30
      GOTO 20



 30   CONTINUE
      IF (IUNIT.NE.0) CALL GVSCLF (IUNIT)
      IF (JUNIT.NE.0) CALL GVSCLF (JUNIT)
      IF (KUNIT.NE.0) CALL GVSCLF (KUNIT)
      IF (GVFISF('BADDRUG.FIL')) CALL GVSDEL ('BADDRUG.FIL')
      CALL GVSMV ('BADDRUG.FIL','TOPOLOGY.NEW',BIGLIN)
      IF (GVFISF('TOPOLOGY.NEW')) CALL GVSDEL ('TOPOLOGY.NEW')
      CALL TOP001
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('TOP008D')



  998 CONTINUE
      IF (IUNIT.NE.0) CALL GVSCLF (IUNIT)
      IF (JUNIT.NE.0) CALL GVSCLF (JUNIT)
      IF (KUNIT.NE.0) CALL GVSCLF (KUNIT)


      RETURN
      END   
      SUBROUTINE TOP009

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      LOGICAL       GVFISF







      IF (GVFISF('TOPOLOGY.H')) GOTO 998



      CALL GVSDEL ('TOPOLOGY.FIL')
      CALL GVSDEL ('BADDRUG.*')



      CALL TOP001



 998  CONTINUE


      RETURN
      END   
      SUBROUTINE TOP010 (CHAR4)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      LOGICAL       GVFISF
      CHARACTER*4   CHAR4
      CHARACTER*8   LOCLIN







      IF (.NOT.GVFISF('DRGWIF.TOP')) THEN
         CALL GVST6C ('?FILNOF','DRGWIF.TOP',.TRUE.)
         GOTO 998
      END IF



      CALL GVSCCC (LOCLIN,CHAR4,'.TOP')



      IF (GVFISF(LOCLIN)) THEN
         CALL GVST6C ('File exists already:',LOCLIN,.TRUE.)
         GOTO 998
      END IF
      CALL GVSCP (LOCLIN,'DRGWIF.TOP',LINE250)



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE TOP011 (CHAR4,IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IERR
      LOGICAL       GVFISF
      CHARACTER*4   CHAR4
      CHARACTER*8   LOCLIN







      IERR=0



      CALL GVSCCC (LOCLIN,CHAR4,'.TOP')



      IF (.NOT.GVFISF(LOCLIN)) THEN
         CALL GVST6C ('?FILNOF',LOCLIN,.TRUE.)
         IERR=1
         GOTO 998
      END IF



      IF (GVFISF('DRGWIF.TOP')) CALL GVSDEL ('DRGWIF.TOP')
      CALL GVSCP ('DRGWIF.TOP',LOCLIN,LINE250)



      CALL TOP004 (IERR)



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE TOP050

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'DATBAS.INC'
      INTEGER       IERR
      LOGICAL       GVFIBN







      IF (GVFIBN(DRGUNT,1,100)) GOTO 998



      IERR=0
      CALL GVSROF (DRGUNT,IERR)
      IF (DRGUNT.EQ.0.OR.IERR.NE.0) GOTO 999



      CALL GVSODF (DRGUNT,.TRUE.,'DRGUNT.FIL','NEW',4,' ',IERR)
      IF (IERR.NE.0) GOTO 999
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('TOP050')



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE TOP051 (NAME)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'DATBAS.INC'
      INTEGER       ONE, IPNT, ICNT, INDAA3
      LOGICAL       CH4EQCH4, GVFIBN
      CHARACTER*4   NAME, CHAR4







      IF (GVFIBN(INDAA3(NAME),1,WIFPAR(294))) GOTO 998
      IF (DRGUNT.LE.0) CALL TOP050



      ONE=1



      IF (DRGPNT.LE.0) THEN
         WRITE (DRGUNT,REC=1,ERR=999) NAME
         WRITE (DRGUNT,REC=2,ERR=999) ONE
         DRGPNT=1
         GOTO 998
      END IF



      DO 10 IPNT=1,DRGPNT,2
         READ (DRGUNT,REC=IPNT,ERR=999) CHAR4
         READ (DRGUNT,REC=IPNT+1,ERR=999) ICNT



         IF (CH4EQCH4(NAME,CHAR4)) THEN
            ICNT=ICNT+1
            WRITE (DRGUNT,REC=IPNT+1,ERR=999) ICNT
            GOTO 998
         END IF
 10   CONTINUE



      DRGPNT=DRGPNT+2
      WRITE (DRGUNT,REC=DRGPNT,ERR=999) NAME
      WRITE (DRGUNT,REC=DRGPNT+1,ERR=999) ONE
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('TOP051')
      CALL TOP052



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE TOP052

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'DATBAS.INC'
      INTEGER       IPNT, ICNT
      CHARACTER*4   CHAR4







      IF (DRGUNT.LE.0) THEN
         CALL GVSTTE ('?M4990')
         GOTO 999
      END IF
      IF (DRGPNT.LE.0) THEN
         CALL GVSTT6 ('?M4991')
         IF (DATOPE) CALL GVSTTU (DATLOG,'?M4991')
         GOTO 998
      END IF



      CALL GVSTT6 ('?M4992')
      IF (DATOPE) THEN
         CALL GVSNLU (DATLOG,2)
         CALL GVSTTU (DATLOG,'?M4992')
      END IF
      CALL GVSFMT ('?FMT466')
      DO 10 IPNT=1,DRGPNT,2
         READ (DRGUNT,REC=IPNT,ERR=999) CHAR4
         READ (DRGUNT,REC=IPNT+1,ERR=999) ICNT
         WRITE (6,FMT,ERR=999) CHAR4,ICNT
         IF (DATOPE) WRITE (DATLOG,FMT,ERR=999) CHAR4,ICNT
 10   CONTINUE
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('TOP052')



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE TOP060

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'DATBAS.INC'
      INTEGER       IERR
      LOGICAL       GVFIBN







      IF (GVFIBN(DRGUN2,1,100)) GOTO 998



      IERR=0
      CALL GVSROF (DRGUN2,IERR)
      IF (DRGUN2.EQ.0.OR.IERR.NE.0) GOTO 999



      CALL GVSODF (DRGUN2,.TRUE.,'NONUNT.FIL','NEW',4,' ',IERR)
      IF (IERR.NE.0) GOTO 999
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('TOP060')



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE TOP061 (NAME)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'DATBAS.INC'
      INTEGER       ONE, IPNT, ICNT, INDAA3
      LOGICAL       CH4EQCH4, GVFIBN
      CHARACTER*4   NAME, CHAR4







      IF (DRGUN2.LE.0) CALL TOP060
      IF (GVFIBN(INDAA3(NAME),1,WIFPAR(294))) GOTO 998



      ONE=1



      IF (DRGPN2.LE.0) THEN
         WRITE (DRGUN2,REC=1,ERR=999) NAME
         WRITE (DRGUN2,REC=2,ERR=999) ONE
         DRGPN2=1
         GOTO 998
      END IF



      DO 10 IPNT=1,DRGPN2,2
         READ (DRGUN2,REC=IPNT,ERR=999) CHAR4
         READ (DRGUN2,REC=IPNT+1,ERR=999) ICNT



         IF (CH4EQCH4(NAME,CHAR4)) THEN
            ICNT=ICNT+1
            WRITE (DRGUN2,REC=IPNT+1,ERR=999) ICNT
            GOTO 998
         END IF
 10   CONTINUE



      DRGPN2=DRGPN2+2
      WRITE (DRGUN2,REC=DRGPN2,ERR=999) NAME
      WRITE (DRGUN2,REC=DRGPN2+1,ERR=999) ONE
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('TOP061')
      CALL TOP062



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE TOP062

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'DATBAS.INC'
      INTEGER       IPNT, ICNT
      CHARACTER*4   CHAR4







      IF (DRGUN2.LE.0) THEN
         CALL GVSTTE ('?M4994')
         GOTO 999
      END IF
      IF (DRGPN2.LE.0) THEN
         CALL GVSTT6 ('?M4993')
         IF (DATOPE) CALL GVSTTU (DATLOG,'?M4993')
         GOTO 998
      END IF



      CALL GVSTT6 ('?M4995')
      IF (DATOPE) THEN
         CALL GVSNLU (DATLOG,2)
         CALL GVSTTU (DATLOG,'?M4995')
      END IF
      CALL GVSFMT ('?FMT466')
      DO 10 IPNT=1,DRGPN2,2
         READ (DRGUN2,REC=IPNT,ERR=999) CHAR4
         READ (DRGUN2,REC=IPNT+1,ERR=999) ICNT
         WRITE (6,FMT,ERR=999) CHAR4,ICNT
         IF (DATOPE) WRITE (DATLOG,FMT,ERR=999) CHAR4,ICNT
 10   CONTINUE
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('TOP062')



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE TOP100

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'CHIANG.INC'
      INTEGER       IERR







      CALL GETFILE (TOPUNT,'?TPFNAM',' ',IERR)
      IF (IERR.NE.0) GOTO 998



      CALL TOPINI



      CALL C1234567 ('In TOP100 at 13')
      CALL TOP002 (IERR)
      WIFPAR(294)=WIFPAR(276)
      CALL C1234567 ('In TOP100 at the end')



  998 CONTINUE

      
      RETURN
      END
      SUBROUTINE TOP_DEB_ATNAM (TEXT,IAATYP)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       INNA, IAT, IAATYP, GVFLEN
      CHARACTER*(*) TEXT







      IF (WIFPAR(810).LE.0) GOTO 998



      IF (GVFLEN(TEXT).GE.1) CALL GVSTT6 (TEXT)



      CALL GVSTT6 ('-----.....-----.....-----.....-----.....')
      WRITE (6,1000,ERR=999) (MUTROW4(IAT,IAATYP),IAT=1,ATPRAA(IAATYP))



      CALL GVSTT6 ('-----.....-----.....-----.....-----.....')
      DO 10 INNA=1,NUMNNA(IAATYP)
         WRITE (6,1000,ERR=999) (MUTSTO4(IAT,IAATYP,INNA),IAT=1,
     +    ATPRAA(IAATYP))
 10   CONTINUE
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('TOP_DEB_ATNAM')



  998 CONTINUE


 1000 FORMAT (25(A4,1X))

      RETURN
      END   
