      integer function getlin(ieq)
      character*137 line
      common /rdwr/   iun1,iun2,iun3,iun4,iun5
      common /curlin/ line
      common /mflin/  linmf

      getlin = 1
      read(iun2,'(a)',err=100,end=100) line
      linmf = linmf + 1
      do i=1,137
         if (ichar(line(i:i)).eq.9) line(i:i) = ' '
      end do

      if (ieq.eq.1.or.ieq.eq.2) then
         do i=1,137
            if (ichar(line(i:i)).eq.61) line(i:i) = ' '
         end do
      endif

      if (ieq.eq.2) then
         do i=1,137
            ii = ichar(line(i:i))
            if (ii.eq.40.or.ii.eq.41.or.ii.eq.34) line(i:i) = ' '
         end do
      endif

      if (ieq.eq.3) then
         do while (.true.)
            i1 = index(line,'(')
            i2 = index(line,')')
            if (i1.gt.0.and.i2.gt.0) then
               line = line(1:i1-1)//line(i2+1:)
            else
               return
            endif
         end do
      endif

      return
100   getlin = 0
      return
      end

      subroutine setlin(str,ic)
      character*(*) str
      character*137 line
      common /curlin/ line

      line = str
      if (ic.ne.0) then
         do i=1,linlen(str)
            if (ichar(line(i:i)).eq.ic) line(i:i) = ' '
         end do
      endif

      return
      end

      integer function nxtwrd(string,strlen,itype,rtype)
c
c      string           nxtwrd = 1 
c      integer          nxtwrd = 2 
c      real             nxtwrd = 3 
c      no word          nxtwrd = 0
c
      character*(*) string
      integer itype,strlen
      double precision rtype
      double precision reada
      logical chkstr
      character*137 line
      common /curlin/ line

      nxtwrd = 0
      
      llen = linlen(line)
      if (llen.eq.0) return

      do while (line(1:1).eq.' ')
          line = line(2:)
      end do

      iend = index(line,' ')
      if (iend.eq.0) then
         iend = llen
      else
         iend = iend - 1
      endif
      if (chkstr(line,iend)) then
           nxtwrd = 1
           string = line(1:iend)
           strlen = iend
      elseif (index(line(1:iend),'.').ne.0) then
           nxtwrd = 3
           rtype = reada(line,1,iend)
      else
           nxtwrd = 2
           itype = reada(line,1,iend)
      endif

      line = line(iend+1:)

      return
      end

      logical function chkstr(line,iend)
      character*(*) line
      chkstr = .false.

      ie    = ichar('e')
      iee   = ichar('E')
      id    = ichar('d')
      idd   = ichar('D')
      nine  = ichar('9')
      izero = ichar('0')
      minus = ichar('-')
      iplus = ichar('+')
      idot  = ichar('.')
      icomma = ichar(',')
      islash  = ichar('/')

      ihase = 0
      idig = 0
      do i=1,iend
         n = ichar(line(i:i))
         if ((n.eq.ie.or.n.eq.iee.or.n.eq.id.or.n.eq.idd)
     &      .and.ihase.eq.0.and.idig.eq.1) then
             n = izero
             ihase = 1
         endif
         if (n.lt.iplus.or.n.gt.nine.or.n.eq.islash
     &       .or.n.eq.icomma) goto 100
         idig = 1
      end do

      n = ichar(line(1:1))
      n2 = ichar(line(2:2))
      if (iend.eq.1) then
         if (n.eq.minus) goto 100
         if (n.eq.iplus) goto 100
         if (n.eq.ie.or.n.eq.iee) goto 100
         if (n.eq.id.or.n.eq.idd) goto 100
      elseif (iend.gt.1) then
         if (n.eq.minus.and.n2.eq.minus) goto 100
      endif

      return
100   chkstr = .true.
      return
      end

      integer function linlen(line)
      character*(*) line

      linlen = 0

      do i=len(line),1,-1
         n = ichar(line(i:i))
         if (n.gt.32.and.n.le.126) goto 100
      end do

      return
100   linlen = i
      return
      end

      logical function datlin(line)
      character*(*) line

      datlin = .true.

      do i=1,linlen(line)
         n = ichar(line(i:i))
         if ((n.lt.43.or.n.gt.57).and.n.ne.32.and.n.ne.68.
     &       and.n.ne.100.and.n.ne.69.and.n.ne.101) goto 100
      end do

      return
100   datlin = .false.
      return
      end

      logical function gnreal(r,n,doget)
      implicit double precision (a-h,o-z)
      character*137 line,str
      common /curlin/ line
      integer getlin
      logical doget
      dimension r(*)

      gnreal = .true.

      if (doget) then
         if (getlin(0).ne.1) gnreal = .false.
      endif

      if (gnreal) then
          do i=1,n
             ktype = nxtwrd(str,nstr,itype,rtype)
             if (ktype.eq.3) then
                r(i) = rtype
             elseif (ktype.eq.2) then
                r(i) = dble(itype)
             else
                gnreal = .false.
             endif
          end do
      endif

      return
      end
    
      logical function gnint(iarr,n,doget)
      implicit double precision (a-h,o-z)
      character*137 line,str
      common /curlin/ line
      integer getlin
      logical doget
      dimension iarr(*)

      gnint = .true.

      if (doget) then
         if (getlin(0).ne.1) gnint = .false.
      endif


      if (gnint) then
          do i=1,n
             ktype = nxtwrd(str,nstr,itype,rtype)
             if (ktype.eq.2) then
                iarr(i) = itype
             else
                gnint = .false.
             endif
          end do
      endif

      return
      end
    
      subroutine lsparm(str,l)
      character*(*) str

      l = len(str)
      do i=1,l
         if (str(i:i).ne.' ') goto 10
      end do
10    str = str(i:)
      l = linlen(str)
      return
      end

      subroutine spatrm(str,l)
      character*(*) str

      j = 1
      l = len(str)
      do while (j.le.l) 
         if (str(j:j).eq.' ') then
           if (l.eq.1) then
              return
           else
              if (j.ne.l) then
                 if (j.eq.1) then
                    str(1:l-1) = str(2:l)
                    str(l:l) = ' '
                 else
c                    str(j:l-1) = str(j:j-1)//str(j+1:l)
                    str(j:l-1) = str(j+1:l)
                    str(l:l) = ' '
                 endif
              endif
              l = l - 1
           endif
         else
           j = j + 1
         endif
      end do

c      if (l.lt.len(str)) str(l+1:l+1) = char(0)

      return
      end

      integer function krnd(r)
      implicit double precision (a-h,p-z),integer (i-n),logical (o)

      krnd = int(r)
      if (r-dfloat(krnd).ge.0.5d0) krnd = krnd + 1

      return
      end

      subroutine rmnull(line)
      implicit double precision (a-h,p-z),integer (i-n),logical (o)
      character*137 line

      ii = 0
      do while (ii.le.137)
         ii = ii + 1
         jj = ichar(line(ii:ii))
         if (jj.eq.0) then
            do kk=ii,136
               line(kk:kk) = line(kk+1:kk+1)
            end do
            if (ii.eq.138) return
            ii = ii - 1
         endif
         if (jj.eq.10.or.jj.eq.13) return
      end do

      return
      end

