      Program water_sim
      Implicit NONE
c const:
      Real TIME_INIT,TIME_LAST
      Parameter (TIME_INIT=0.0, TIME_LAST=4.0)
      Real X_INIT
      Parameter (X_INIT=1.0)
      Real STEP
      Parameter (STEP = 0.025)
c local:
      Real time,x,x_next
      Real Prev_x,Prev_t, bucket
c begin:
      Write(*,*) '#Solve Diff. Equation'
      bucket=1
      x=X_INIT
      time = TIME_INIT
      Prev_x=x
      Prev_t=time
      Write(*,'(''#Bucket : '',F4.1,4X,''water: '',F7.5)') time,x
      Do While(time.lt.TIME_LAST)
         call calc_next_step(time,x,STEP,x_next)
         time=time+ STEP
         x=x_next
         if( Prev_x -x .gt. 0.1) then
           Write(*,'(F4.1,4X,F8.5)') bucket,(time-Prev_t)*x
           Prev_x=x
           Prev_t=time
           bucket=bucket+1.
         end if
c        Write(*,'(F4.1,4X,F7.5)') time,x
      End do

      end
      
      Real Function diff_eq(t,x)
      Implicit NONE
c input:
      Real t,x
c const:
      Real MAX_VOLTAGE
      Parameter (MAX_VOLTAGE=0.0)
c begin:
        diff_eq = MAX_VOLTAGE - x
      return
      End

      Subroutine calc_next_step(t,x,step,x_next)
      Implicit NONE
c input:
      Real t,x,step
c output:
      Real x_next
c function:
      Real diff_eq
        x_next = x + step*diff_eq(t,x)

      return
      end
