      Subroutine rk4_1d(dx,ti,xi,tf,xf)
c=====================================================================
c rk4_1d:  Program to solve an initial value problem for 1st order ODE
c method:  4th-order Runge-Kutta method
c written by: Alex Godunov (October 2006)
c---------------------------------------------------------------------
c input ...
c dx(t,x)- function dx/dt (supplied by a user)
c ti - initial time
c xi  - initial position
c tf  - time for a solution
c
c output ...
c xf  - solution at point tf
c=================================================
      Real*8 dx,ti,xi,tf,xf
      Real*8 h,k1,k2,k3,k4

      h  = tf-ti

      k1 = h*dx(ti,xi)
      k2 = h*dx(ti+h/2.0,xi+k1/2.0)
      k3 = h*dx(ti+h/2.0,xi+k2/2.0)
      k4 = h*dx(ti+h,xi+k3)

      xf = xi + (k1 + 2.0*(k2+k3) + k4)/6.0
      Return
      End