c
c
c     ###################################################
c     ##  COPYRIGHT (C)  1992  by  Jay William Ponder  ##
c     ##              All Rights Reserved              ##
c     ###################################################
c
c     ################################################################
c     ##                                                            ##
c     ##  subroutine cutoffs  --  set distance and Hessian cutoffs  ##
c     ##                                                            ##
c     ################################################################
c
c
c     "cutoffs" initializes and stores the cutoff distance windows,
c     the Hessian matrix cutoff, and the neighbor generation method
c     for pairwise potential functions
c
c
      subroutine cutoffs
      implicit none
      include 'sizes.i'
      include 'cutoff.i'
      include 'hescut.i'
      include 'keys.i'
      integer i,next
      character*20 keyword
      character*80 record,string
      logical truncate
c
c
c     set default values for cutoffs and the switching function
c
      vdwcut = 100000000.0d0
      chgcut = 100000000.0d0
      dplcut = 100000000.0d0
      vdwtaper = 0.90d0
      chgtaper = 0.65d0
      dpltaper = 0.75d0
      truncate = .false.
      hesscut = 0.0d0
c
c     neighbor default is double loop, not method of lights
c
      use_lights = .false.
c
c     search the keywords for various cutoff parameters
c
      do i = 1, nkey
         next = 1
         record = keyline(i)
         call gettext (record,keyword,next)
         call upcase (keyword)
c
c     get the cutoff radii for potential energy functions
c
         if (keyword(1:7) .eq. 'CUTOFF ') then
            string = record(next:80)
            read (string,*,err=10)  vdwcut
            chgcut = vdwcut
            dplcut = vdwcut
         else if (keyword(1:11) .eq. 'VDW-CUTOFF ') then
            string = record(next:80)
            read (string,*,err=10)  vdwcut
         else if (keyword(1:11) .eq. 'CHG-CUTOFF ') then
            string = record(next:80)
            read (string,*,err=10)  chgcut
         else if (keyword(1:11) .eq. 'DPL-CUTOFF ') then
            string= record(next:80)
            read (string,*,err=10)  dplcut
c
c     get distance for initialization of energy switching
c
         else if (keyword(1:6) .eq. 'TAPER ') then
            string = record(next:80)
            read (string,*,err=10)  vdwtaper
            chgtaper = vdwtaper
            dpltaper = vdwtaper
         else if (keyword(1:10) .eq. 'VDW-TAPER ') then
            string = record(next:80)
            read (string,*,err=10)  vdwtaper
         else if (keyword(1:10) .eq. 'CHG-TAPER ') then
            string = record(next:80)
            read (string,*,err=10)  chgtaper
         else if (keyword(1:10) .eq. 'DPL-TAPER ') then
            string= record(next:80)
            read (string,*,err=10)  dpltaper
c
c     get truncation, Hessian minimum and neighbor method
c
         else if (keyword(1:9) .eq. 'TRUNCATE ') then
            truncate = .true.
         else if (keyword(1:12) .eq. 'HESS-CUTOFF ') then
            string = record(next:80)
            read (string,*,err=10)  hesscut
         else if (keyword(1:7) .eq. 'LIGHTS ') then
            use_lights = .true.
         end if
   10    continue
      end do
c
c     convert any distance percentages to absolute distances
c
      if (vdwtaper .lt. 1.0d0) then
         vdwtaper = vdwtaper * vdwcut
      end if
      if (chgtaper .lt. 1.0d0) then
         chgtaper = chgtaper * chgcut
      end if
      if (dpltaper .lt. 1.0d0) then
         dpltaper = dpltaper * dplcut
      end if
c
c     apply truncation cutoffs if they were requested
c
      if (truncate) then
         vdwtaper = vdwcut
         chgtaper = chgcut
         dpltaper = dplcut
      end if
      return
      end
