CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C     FUNCTION VBTIME
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
      FUNCTION VBTIME(i)
      REAL*8 vbtime
C     ------------------------------------------------------------------
C     vbtime -- returns cpu-time or elapse-time
C     input:
C       i=1 .. clear cpu-time counter, return 0
C       i=2 .. return cpu-time in seconds, keep counter
C       i=3 .. clear elapse-time counter, return 0
C       i=4 .. return elapse-time counter, keep counter
C     output: vbtime
C       i is not changed.
C     ------------------------------------------------------------------
      INTEGER i, time
      REAL s(2),etime
      REAL*8 tm0,tm1

      SAVE tm0,tm1
      DATA tm0/0.D0/, tm1/0.D0/

      vbtime = 0.D0
      IF( i.EQ.1 .OR. i.EQ.2 ) THEN
         vbtime = DBLE( etime(s) )
         IF( i.EQ.1 ) tm0 = vbtime
         vbtime = vbtime - tm0
      ELSE IF( i.EQ.3 .OR. i.EQ.4 ) THEN
         vbtime = DBLE( time() )
         IF( i.EQ.3 ) tm1 = vbtime
         vbtime = vbtime - tm1
      ENDIF

      RETURN
      END