c
c
c     ###################################################
c     ##  COPYRIGHT (C)  1993  by  Jay William Ponder  ##
c     ##              All Rights Reserved              ##
c     ###################################################
c
c     ###############################################################
c     ##                                                           ##
c     ##  subroutine clock  --  find elapsed time for current job  ##
c     ##                                                           ##
c     ###############################################################
c
c
c     "clock" determines elapsed CPU time in seconds since the
c     start of the job; only one of the implementations should
c     be activated by removing comment characters from the code
c
c
      subroutine clock (seconds)
      implicit none
      real*8 seconds
c
c
c     Unix machines have access to the "etime" intrinsic,
c     this code works for Sun, DEC, SGI, Convex and others
c
      real etime,times(2)
      seconds = dble(etime(times))
c
c     IBM RS/6000 under AIX appends an underscore to "etime"
c
c     real etime_,times(2)
c     seconds = dble(etime_(times))
c
c     Hewlett-Packard machines under HP-UX and Apple Macintosh
c     under Language Systems Fortran can only give the wall clock
c     difference; HP's also require use of the +E1 compiler option
c
c     real secnds,start
c     logical initial
c     save initial,start
c     data initial  / .true. /
c     if (initial) then
c        initial = .false.
c        start = secnds (0.0)
c     end if
c     seconds = secnds (start)
c
c     Digital OpenVMS machines use a special system call
c
c     include '($jpidef)'
c     structure /itmlst3_1item/
c        structure item
c           integer*2 buffer_length
c           integer*2 code
c           integer*4 buffer_address
c           integer*4 retlen_address
c        end structure
c     end structure
c     record /itmlst3_1item/ jpi_list
c     integer*4 cputime
c     jpi_list.item.code = jpi$_cputim
c     jpi_list.item.buffer_length = 4
c     jpi_list.item.buffer_address = %loc(cputime)
c     jpi_list.item.retlen_address = 0
c     call sys$getjpiw (,,,jpi_list,,,)
c     seconds = 0.01d0 * dble(cputime)
c
c     Intel PC's under the Digital Visual Fortran 5.0 compiler
c
c     real time
c     call cpu_time (time)
c     seconds = dble(time)
c
c     Intel-based PC's under the Microsoft and Watcom compilers;
c     note that this returns the wall clock time only, and will
c     fail for timing intervals spaning midnight
c
c     integer*2 hrs,mins,secs,hsecs
c     real*8 start
c     logical initial
c     save initial,start
c     data initial  / .true. /
c     if (initial) then
c        initial = .false.
c        call gettim (hrs,mins,secs,hsecs)
c        start = 3600.0d0*dble(hrs) + 60.0d0*dble(mins)
c    &              + dble(secs) + 0.01d0*dble(hsecs)
c     end if
c     call gettim (hrs,mins,secs,hsecs)
c     seconds = 3600.0d0*dble(hrs) + 60.0d0*dble(mins)
c    &             + dble(secs) + 0.01d0*dble(hsecs) - start
      return
      end
