c
c
c     ###################################################
c     ##  COPYRIGHT (C)  1990  by  Jay William Ponder  ##
c     ##              All Rights Reserved              ##
c     ###################################################
c
c     #############################################################
c     ##                                                         ##
c     ##  subroutine getprm  --  get force field parameter file  ##
c     ##                                                         ##
c     #############################################################
c
c
c     "getprm" finds the potential energy parameter file
c     and then opens and reads the parameters
c
c
      subroutine getprm
      implicit none
      include 'sizes.i'
      include 'files.i'
      include 'iounit.i'
      include 'keys.i'
      integer i,iprm,next,freeunit
      character*20 keyword
      character*60 prmfile
      character*80 record
      logical exist
c
c
c     set the default name for the parameter file
c
      prmfile = filename(1:leng)//'.prm'
c
c     search the keyword list for the parameter filename
c
      do i = 1, nkey
         next = 1
         record = keyline(i)
         call gettext (record,keyword,next)
         call upcase (keyword)
         if (keyword(1:11) .eq. 'PARAMETERS ') then
            call gettext (record,prmfile,next)
         end if
      end do
      call suffix (prmfile,'prm')
      call version (prmfile,'old')
      inquire (file=prmfile,exist=exist)
c
c     try to get a parameter filename from the command line
c
      if (.not. exist) then
         call nextarg (prmfile,exist)
         if (exist) then
            call suffix (prmfile,'prm')
            call version (prmfile,'old')
            inquire (file=prmfile,exist=exist)
         end if
      end if
c
c     if necessary, ask for the parameter filename
c
      dowhile (.not. exist)
         write (iout,10)
   10    format (/,' Enter Potential Parameter File Name :  ',$)
         read (input,20)  prmfile
   20    format (a60)
         call suffix (prmfile,'prm')
         call version (prmfile,'old')
         inquire (file=prmfile,exist=exist)
      end do
c
c     open the parameter file, then read and close it
c
      iprm = freeunit ()
      open (unit=iprm,file=prmfile,status='old')
      rewind (unit=iprm)
      call readprm (iprm)
      close (unit=iprm)
      return
      end
