











      SUBROUTINE MOL700 (TEXT,IERR)


















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IERR, GVFLEN, LENTXT
      LOGICAL       GVFISF
      CHARACTER*80  LOCLIN
      CHARACTER*(*) TEXT







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



      IERR=0
      CALL GVSCTB (LOCLIN,80)



   10 CONTINUE
      IF (LENTXT.LE.0) THEN
         CALL MOL701 (LOCLIN,IERR)
         IF (IERR.NE.0) GOTO 998
      ELSE
         CALL GVSSTX (LOCLIN,TEXT)
      END IF



      CALL GETFILE (11,' ',LOCLIN,IERR)
      IF (IERR.NE.0) THEN
         LENTXT=0
         GOTO 10
      END IF



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



      IF (WIFPAR(1264).EQ.0) CALL MOL711 (IERR)



  998 CONTINUE


      RETURN
      END
      SUBROUTINE MOL701 (FILENAME,IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IERR, GVFLEN, L
      LOGICAL       GVFYON, GVFISF
      CHARACTER*12  OUTFIL
      CHARACTER*80  LOCLIN
      CHARACTER*(*) FILENAME







      IERR=0
      CALL GVSCTB (LINE,80)
      CALL GVSCTB (LINE2,80)
      CALL GVSCTB (BIGLIN,132)



   10 CONTINUE
      CALL GVSCTB (LOCLIN,80)
      CALL IPROMPT ('?MOLGCF')
      CALL GETWORD (LOCLIN,IERR)
      IF (IERR.NE.0) GOTO 998
      CALL GVSSHL (LOCLIN)



      IF (WIFPAR(498).GE.1) CALL MOL020 (LOCLIN)



      CALL MOL702 (LOCLIN,LINE2,IERR)




      IF (IERR.EQ.0) THEN
         L=GVFLEN(LOCLIN)
         IF (LINE2(1:L).NE.LOCLIN(1:L)) THEN
            CALL GVSSTX (BIGLIN,'?M0065')
            CALL GVSSTX (BIGLIN(53:132),LINE2)
            CALL GVSRDB (BIGLIN)
            IF (.NOT.GVFYON(BIGLIN(1:GVFLEN(BIGLIN)),' ')) GOTO 10
         END IF
         CALL GVSSTX (LINE,LINE2)
      ELSE IF (GVFLEN(LOCLIN).EQ.4) THEN



         CALL MOL714 (LOCLIN(1:4),IERR)
         IF (IERR.NE.0) GOTO 998
         IF (GVFISF(OUTFIL)) THEN
            IERR=0
            CALL GVSSTX (LINE,OUTFIL)
         END IF
      END IF



      IF (IERR.NE.0) THEN
         CALL SHOWTEXT ('?MOLB02')
         GOTO 10
      END IF



      CALL GVSSTX (FILNMS(62),LINE)
      CALL GVSSTX (FILNMS(91),LINE)



      CALL GVSSTX (FILENAME,LINE)



  998 CONTINUE


      RETURN
      END
      SUBROUTINE MOL702 (IN,OUTSTR,IERR)



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       LDIR, LNAME, LEXT, NDIR, NEXT, IDIR, IEXT, IERR,
     +              GVFLEN, GVFPLS
      LOGICAL       GVFISF
      CHARACTER*80  PDIR(3), PEXT(9), NAME, EXT, BACKUP, INSTR
      CHARACTER*(*) IN, OUTSTR







      IF (LEN(OUTSTR).LT.80) THEN
         CALL GVSTTB ('?M0780')
         IERR=1
         GOTO 998
      END IF



      CALL GVSSTX (INSTR,IN)
      IF (GVFLEN(INSTR).EQ.5) INSTR(5:5)=' '
      CALL GVSSTX (BACKUP,OUTSTR)
      CALL GVSSTX (OUTSTR,INSTR)
      IERR=0



      CALL GVSCTB (FILNMS(90),80)
      CALL GVSSTX (FILNMS(90),INSTR)
      CALL MOL704 (FILNMS(90))
      CALL GVSCUC (FILNMS(90))



      IF (GVFISF(OUTSTR)) GOTO 998



      LDIR=GVFPLS(OUTSTR,'/')
      IF (LDIR.GE.1) THEN
         CALL GVSSTX (PDIR(1),OUTSTR(1:LDIR))
         CALL GVSCTB (OUTSTR(1:LDIR),LDIR)
         CALL GVSSHL (OUTSTR)
      ELSE
         CALL GVSSTX (PDIR(1),'./')
      END IF
      CALL GVSSTX (PDIR(2),FILNMS(61))
      NDIR=2



      LNAME=GVFPLS(OUTSTR,'.')
      IF (LNAME.GT.0) THEN
         CALL GVSSTX (NAME,OUTSTR(1:LNAME))
         CALL GVSCTB (OUTSTR(1:LNAME),LNAME)
         CALL GVSSHL (OUTSTR)
      ELSE
         LNAME=GVFLEN(OUTSTR)
         CALL GVSSTX (NAME,OUTSTR)
      END IF



      LEXT=GVFLEN(OUTSTR)
      IF (LEXT.GT.0) THEN
         CALL GVSSTX (EXT,OUTSTR(1:LEXT))
         CALL GVSCTB (OUTSTR(1:LEXT),LEXT)
      ELSE 
         CALL GVSCTB (EXT,80)
      END IF



      IF (LEXT.GT.0) THEN
         CALL GVSSTX (PEXT(1),EXT)
      ELSE
         CALL GVSSTX (PEXT(1),'.mcf')
      END IF
      CALL GVSSTX (PEXT(2),'.brk')
      CALL GVSSTX (PEXT(3),'.pdb')
      CALL GVSSTX (PEXT(4),'.mmol')
      CALL GVSSTX (PEXT(5),'.ent')
      CALL GVSSTX (PEXT(6),'.BRK')
      CALL GVSSTX (PEXT(7),'.MCF')
      CALL GVSSTX (PEXT(8),'.PDB')
      CALL GVSSTX (PEXT(9),'.PRE')
      NEXT=9



      DO 100 IDIR=1,NDIR
         DO 90 IEXT=1,NEXT
            CALL GVSCC3 (OUTSTR,PDIR(IDIR),NAME,PEXT(IEXT))
            IF (GVFISF(OUTSTR)) GOTO 200
            CALL GVSCUC (OUTSTR)
            IF (GVFISF(OUTSTR)) GOTO 200
            CALL GVSCLC (OUTSTR)
            IF (GVFISF(OUTSTR)) GOTO 200



            IF (PEXT(IEXT).EQ.'.ent') THEN
               CALL GVSCC4 (OUTSTR,PDIR(IDIR),'pdb',NAME,PEXT(IEXT))
               IF (GVFISF(OUTSTR)) GOTO 200
               CALL GVSCUC (OUTSTR)
               IF (GVFISF(OUTSTR)) GOTO 200
               CALL GVSCLC (OUTSTR)
               IF (GVFISF(OUTSTR)) GOTO 200
            END IF
   90    CONTINUE
  100 CONTINUE



      IERR=1
      CALL GVSSTX (OUTSTR,BACKUP(1:LEN(OUTSTR)))
      GOTO 998



  200 CONTINUE
      IERR=0
      IF (OUTSTR(1:2).EQ.'./') THEN
         OUTSTR(1:2)='  '
         CALL GVSSHL (OUTSTR)
      END IF



  998 CONTINUE


      RETURN
      END
      SUBROUTINE MOL703 (IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IERR







      IERR=0




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




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



      CALL KLONKUP
      CALL KLONKSET (WIFPAR(491),0,IERR)



      CALL MOL030 (IERR)



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE MOL704 (TEXT)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IPOS, GVFPOS, LENTXT, GVFLEN, IEXT
      CHARACTER*4   EXTS(10)
      CHARACTER*(*) TEXT








      IF (GVFLEN(TEXT).EQ.4) GOTO 998



      LENTXT=LEN(TEXT)
      EXTS(1)='.ent'
      EXTS(2)='.mcf'
      EXTS(3)='.brk'
      EXTS(4)='.pdb'
      EXTS(5)='.ENT'
      EXTS(6)='.MCF'
      EXTS(7)='.BRK'
      EXTS(8)='.PDB'
      EXTS(9)='.xyz'
      EXTS(10)='.XYZ'



      IF (TEXT(1:1).EQ.'.') THEN
         TEXT(1:1)=' '
         CALL GVSSHL (TEXT)
      END IF
      IF (TEXT(1:1).EQ.'.') THEN
         TEXT(1:1)=' '
         CALL GVSSHL (TEXT)
      END IF



 10   CONTINUE
      DO 15 IEXT=1,10
         IPOS=GVFPOS(TEXT,EXTS(IEXT))
         IF (IPOS.GE.3) THEN
            CALL GVSCTB (TEXT(IPOS:LENTXT),LENTXT-IPOS+1)
            GOTO 10
         END IF
 15   CONTINUE




 20   CONTINUE
      IPOS=GVFPOS(TEXT,'/')
      IF (IPOS.GE.1) THEN
         CALL GVSCTB (TEXT(1:IPOS),IPOS)
         CALL GVSSHL (TEXT)
         GOTO 20
      END IF




 30   CONTINUE
      IF (TEXT(1:3).EQ.'pdb'.OR.TEXT(1:3).EQ.'PDB') THEN
         CALL GVSCTB (TEXT(1:3),3)
         CALL GVSSHL (TEXT)
         GOTO 30
      END IF




  998 CONTINUE


      RETURN
      END   
      SUBROUTINE MOL711 (IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IERR, GVFLEN, IPOS, ISET, GVFPOS
      LOGICAL       GVFYON, GVFIBN, GVFISN
      CHARACTER*80  DEFSET







      IERR=0



      IF (WIFPAR(332).NE.0) THEN
         CALL MOL018
         IF (WIFPAR(491).LE.0) THEN
            CALL MOL100
            IERR=1
         ELSE
            IF (WIFPAR(491).GT.1) WIFPAR(491)=WIFPAR(491)-1
            GOTO 998
         END IF
         CALL GVSSTX (FILNMS(91),SOUNAM(WIFPAR(491)))
      END IF



      IF (GVFLEN(FILNMS(91)).EQ.0) THEN
         CALL GVSSTX (FILNMS(91),FILNMS(74))
         CALL GVSTT6 ('?M2226')
      END IF



      CALL MOL018
      IF (WIFPAR(491).LE.0) THEN
         CALL MOL100
         IERR=1
         GOTO 998
      END IF



      IF (.NOT.GVFIBN(WIFPAR(491),1,MAXMOL)) THEN
         CALL TOOMANY ('Sets.')
         IERR=1
         GOTO 998
      END IF



      IPOS=LEN(FILNMS(91))
 1    CONTINUE
      IPOS=IPOS-1
      IF (IPOS.GT.1.AND.FILNMS(91)(IPOS:IPOS).NE.'/') GOTO 1
      IF (FILNMS(91)(IPOS:IPOS).EQ.'/') IPOS=IPOS+1
      CALL GVSSTX (DEFSET,FILNMS(91)(IPOS:))

 2    CONTINUE
      IPOS=GVFPOS(DEFSET,'_')
      IF (IPOS.NE.0) THEN
         DEFSET(IPOS:IPOS)='.'
         GOTO 2
      END IF

 3    CONTINUE
      IPOS=GVFPOS(DEFSET,'\\')
      IF (IPOS.NE.0) THEN
         DEFSET(IPOS:IPOS)='.'
         GOTO 3
      END IF

 4    CONTINUE
      IPOS=GVFPOS(DEFSET,'$')
      IF (IPOS.NE.0) THEN
         DEFSET(IPOS:IPOS)='.'
         GOTO 4
      END IF

 5    CONTINUE
      IPOS=GVFPOS(DEFSET,'*')
      IF (IPOS.NE.0) THEN
         DEFSET(IPOS:IPOS)='.'
         GOTO 5
      END IF

 6    CONTINUE
      IPOS=GVFPOS(DEFSET,'%')
      IF (IPOS.NE.0) THEN
         DEFSET(IPOS:IPOS)='.'
         GOTO 6
      END IF




      IF (GVFISN(FILNMS(91)(1:1))) THEN
         CALL GVSCCC (LINE,'SET.',FILNMS(91))
         CALL GVSSTX (FILNMS(91),LINE)
      END IF





         CALL GVSSTX (SOUNAM(WIFPAR(491)),DEFSET)




  998 CONTINUE


      RETURN
      END
      SUBROUTINE MOL712 (FILE)


















      IMPLICIT      NONE
      CHARACTER*(*) FILE
      CHARACTER*1   CHAR1
      LOGICAL       GVFISF
      INTEGER       GVFPLS, GVFLEN, I, IPOS







      IF (GVFLEN(FILE).LE.0) THEN
         CALL GVSTTE ('?MOLC40')
         GOTO 998
      END IF



      IF (GVFISF(FILE)) GOTO 998





      IPOS=GVFPLS(FILE,'/')



      DO 10 I=IPOS+1,GVFLEN(FILE)
         CHAR1=FILE(I:I)
         CALL GVSCUC (CHAR1)
         FILE(I:I)=CHAR1
   10 CONTINUE



      IF (GVFISF(FILE)) THEN
         CALL GVST6C ('?MOLC41',FILE,.TRUE.)
         GOTO 998
      END IF



      DO 20 I=IPOS+1,GVFLEN(FILE)
         CHAR1=FILE(I:I)
         CALL GVSCLC (CHAR1)
         FILE(I:I)=CHAR1
   20 CONTINUE



      IF (GVFISF(FILE)) CALL GVST6C ('?MOLC41',FILE,.TRUE.)



  998 CONTINUE


      RETURN
      END
      SUBROUTINE MOL713 (INFILE,IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IERR, GVFPOS, IPOS
      LOGICAL       GVFIBN
      CHARACTER*80  INFILE, LOCLIN







      IERR=0
      CALL MOL702 (INFILE,LOCLIN,IERR)



      CALL GETFILE (11,' ',LOCLIN,IERR)
      IF (IERR.NE.0) GOTO 998



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



      CALL MOL018
      IF (WIFPAR(491).LE.0) THEN
         CALL MOL100
         IERR=1
         GOTO 998
      END IF



      IF (.NOT.GVFIBN(WIFPAR(491),1,MAXMOL)) THEN
         CALL TOOMANY ('Sets.')
         IERR=1
         GOTO 998
      END IF



      IPOS=GVFPOS(INFILE,'.')
      IF (IPOS.LE.1) THEN
         CALL GVSSTX (FILNMS(91),INFILE)
      ELSE
         CALL GVSSTX (FILNMS(91),INFILE(1:IPOS-1))
      END IF



  998 CONTINUE


      RETURN
      END
      SUBROUTINE MOL714 (FILENAME,IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IUNIT, IERR
      LOGICAL       GOTFILE
      CHARACTER*4   FILENAME







      IERR=0
      CALL GVSCLC (FILENAME)



      IF (.NOT.GOTFILE(IUNIT,'GETPDB')) THEN
         CALL GVST6C ('?M4040',FILENAME,.TRUE.)
         IERR=1
         GOTO 998
      END IF



      CALL SHOWTEXTU (IUNIT,'?M3273')
      CALL GVSFMT ('?M3274')
      CALL GVSCTB (LINE,80)
      WRITE (LINE,FMT,ERR=999) FILENAME
      CALL GVSTTU (IUNIT,LINE)
      CALL SHOWTEXTU (IUNIT,'?M3275')
      CALL GVSCLF (IUNIT)




      CALL GVSSPL ('chmod 777 GETPDB')



      CALL GVSSPL ('./GETPDB')
      CALL GVSCC3 (LINE,'pdb',FILENAME,'.ent')
      CALL GVSCLC (LINE)
      CALL GVST6C ('?M4041',LINE,.FALSE.)
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('MOL714')
      IERR=1



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE MOL715 (SEQNAM,IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IERR
      CHARACTER*4   SEQNAM







      CALL MOL702 (SEQNAM,LINE,IERR)
      IF (IERR.EQ.0) GOTO 998



      CALL MOL714 (SEQNAM,IERR)
      IF (IERR.EQ.0) GOTO 998



      CALL MOL702 (SEQNAM,LINE,IERR)
      IF (IERR.NE.0) GOTO 998
      CALL GVST6C (SEQNAM,'?M4025',.TRUE.)



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE MOL018

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       ISET, GVFLEN







      WIFPAR(491)=0
      CALL MOL018A



      DO 10 ISET=1,MAXSET
         IF (GVFLEN(SOUNAM(ISET)).LT.1) THEN
            WIFPAR(491)=ISET
            GOTO 998
         END IF
   10 CONTINUE



  998 CONTINUE


      RETURN
      END
      SUBROUTINE MOL018A




















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'ESPACE.INC'
      INTEGER       IAA, ISET
      LOGICAL       IKEEP(MAXSET)
      EQUIVALENCE   (IKEEP(1),ESPACE(1001))







      IF (WIFPAR(1176).NE.0) GOTO 998



      CALL ESPSET (1001,1000+MAXSET,69)



      CALL GVSBTF (IKEEP,MAXSET)



      DO 10 IAA=1,NUMAAT
         IF (SOUPNT(IAA).LE.0.OR.SOUPNT(IAA).GT.MAXSET) THEN
            CALL GVSTT6 ('?M3959')
            CALL DIF008 ('?M3960',IAA)
            CALL GVSTTI ('?M3961',SOUPNT(IAA))
            SOUPNT(IAA)=WIFPAR(491)
         END IF
         IKEEP(SOUPNT(IAA))=.TRUE.
   10 CONTINUE



      DO 20 ISET=2,MAXSET
         IF (.NOT.IKEEP(ISET)) CALL GVSCTB (SOUNAM(ISET),80)
   20 CONTINUE

      CALL ESPKIL (1001,1000+MAXSET,69,'MOL501')



  998 CONTINUE


      RETURN
      END
