c
c
c     ###################################################
c     ##  COPYRIGHT (C)  1990  by  Jay William Ponder  ##
c     ###################################################
c
c     #############################################################
c     ##                                                         ##
c     ##  subroutine readseq  --  read biopolymer sequence file  ##
c     ##                                                         ##
c     #############################################################
c
c
c     "readseq" gets a biopolymer sequence from an external
c     file; all lines in the file are part of the sequence, an
c     initial integer on a line is ignored and all remaining
c     nonblank characters are part of the sequence
c
c
      subroutine readseq (iseq)
      implicit none
      include 'sizes.i'
      include 'aminos.i'
      include 'files.i'
      include 'iounit.i'
      include 'sequen.i'
      integer i,j,iseq,number
      integer next,length,trimtext
      character*1 letter
      character*60 seqfile
      character*80 record
      logical opened
c
c
c     zero out the number and type of residues
c
      nseq = 0
      do i = 1, maxres
         seq(i) = ' '
      end do
c
c     open input unit if not already done
c
      inquire (unit=iseq,opened=opened)
      if (.not. opened) then
         seqfile = filename(1:leng)//'.seq'
         open (unit=iseq,file=seqfile,status='old')
         rewind (unit=iseq)
      end if
c
c     read in the biopolymer sequence file
c
      dowhile (.true.)
         read (iseq,10,err=20,end=20)  record
   10    format (a80)
         length = trimtext (record)
         next = 1
         call getnumb (record,number,next)
         do j = next, length
            letter = record(j:j)
            if (letter .ne. ' ') then
               nseq = nseq + 1
               seq(nseq) = letter
            end if
         end do
      end do
c
c     find the residue type for each sequence element
c
   20 continue
      do i = 1, nseq
         seqtyp(i) = 0
         do j = 1, maxamino
            if (seq(i) .eq. amino1(j))  seqtyp(i) = j
         end do
      end do
      if (.not. opened)  close (unit=iseq)
      return
      end
