c
c
c     ###################################################
c     ##  COPYRIGHT (C)  1993  by  Jay William Ponder  ##
c     ##              All Rights Reserved              ##
c     ###################################################
c
c     ##############################################################
c     ##                                                          ##
c     ##  subroutine unitcell  --  read periodic cell parameters  ##
c     ##                                                          ##
c     ##############################################################
c
c
c     "unitcell" gets the periodic unitcell sizes and related
c     values from an external keyword file
c
c
      subroutine unitcell
      implicit none
      include 'sizes.i'
      include 'boxes.i'
      include 'keys.i'
      integer i,next
      character*20 keyword
      character*80 record,string
c
c
c     set the default values for the unitcell variables
c
      xbox = 0.0d0
      ybox = 0.0d0
      zbox = 0.0d0
      alpha = 0.0d0
      beta = 0.0d0
      gamma = 0.0d0
      octahedron = .false.
      spacegrp = '          '
c
c     get keywords containing crystal lattice dimensions
c
      do i = 1, nkey
         next = 1
         record = keyline(i)
         call gettext (record,keyword,next)
         call upcase (keyword)
         string = record(next:80)
         if (keyword(1:7) .eq. 'A-AXIS ') then
            read (string,*,err=20)  xbox
         else if (keyword(1:7) .eq. 'B-AXIS ') then
            read (string,*,err=20)  ybox
         else if (keyword(1:7) .eq. 'C-AXIS ') then
            read (string,*,err=20)  zbox
         else if (keyword(1:6) .eq. 'ALPHA ') then
            read (string,*,err=20)  alpha
         else if (keyword(1:5) .eq. 'BETA ') then
            read (string,*,err=20)  beta
         else if (keyword(1:6) .eq. 'GAMMA ') then
            read (string,*,err=20)  gamma
         else if (keyword(1:11) .eq. 'OCTAHEDRON ') then
            octahedron = .true.
         else if (keyword(1:11) .eq. 'SPACEGROUP ') then
            call getword (record,spacegrp,next)
         end if
   20    continue
      end do
c
c     assume standard defaults for unspecified cell parameters
c
      if (xbox .ne. 0.0d0) then
         if (ybox .eq. 0.0d0)  ybox = xbox
         if (zbox .eq. 0.0d0)  zbox = xbox
      end if
      if (max(alpha,beta,gamma) .ne. 0.0d0) then
         if (alpha .eq. 0.0d0)  alpha = 90.0d0
         if (beta .eq. 0.0d0)  beta = 90.0d0
         if (gamma .eq. 0.0d0)  gamma = 90.0d0
      end if
      return
      end
