      Program rc_curcuit
      Implicit NONE
c const:
      Real TIME_INIT,TIME_LAST
      Parameter (TIME_INIT=0.0, TIME_LAST=50.0)
      Real X1_INIT,X2_INIT
      Parameter (X1_INIT=1.0,X2_INIT=0.)
      Real STEP
      Parameter (STEP = 1.0)
c local:
      Real time,x1,x2,x1_next,x2_next
c begin:
c     Write(*,*) 'Solve Diff. Equation'
      x1=X1_INIT
      x2=X2_INIT
      time = TIME_INIT

c     Write(*,'(''Time : '',F4.1,4X,''Vol.: '',F7.5)') time,x1
      Write(*,'(F4.1,4X,F7.5)') time,x1
      Do While(time.lt.TIME_LAST)
         call calc_next_step(time,x1,x2,STEP,x1_next,x2_next)
         time=time+ STEP
         x1=x1_next
         x2=x2_next
         Write(*,'(F4.1,4X,F7.5)') time,x1
      End do

      end
      
      Real Function diff_eq_1(t,x1,x2)
      Implicit NONE
c input:
      Real t,x1,x2
c begin:
        diff_eq_1 = x2
      return
      End
      
      Real Function diff_eq_2(t,x1,x2)
      Implicit NONE
c input:
      Real t,x1,x2
c const:
      Real R, C, L
      Parameter (R=1.0,C=0.3, L=10)
c begin:
        diff_eq_2 = -(R*C*x2 + x1)/(L*C)
      return
      End

      Subroutine calc_next_step(t,x1,x2,step,x1_next,x2_next)
      Implicit NONE
c input:
      Real t,x1,x2,step
c output:
      Real x1_next,x2_next
c function:
      Real diff_eq_1,diff_eq_2
      Real k1_1,k2_1,k3_1,k4_1
      Real k1_2,k2_2,k3_2,k4_2
        k1_1 = step * diff_eq_1(t,x1,x2)
        k1_2 = step * diff_eq_2(t,x1,x2)
        k2_1 = step * diff_eq_1(t+0.5*step,x1+0.5*k1_1,x2+0.5*k1_2 )
        k2_2 = step * diff_eq_2(t+0.5*step,x1+0.5*k1_1,x2+0.5*k1_2 )
        k3_1 = step * diff_eq_1(t+0.5*step,x1+0.5*k2_1,x2+0.5*k2_2 )
        k3_2 = step * diff_eq_2(t+0.5*step,x1+0.5*k2_1,x2+0.5*k2_2 )
        k4_1 = step * diff_eq_1(t + step, x1 + k3_1,x2+k3_2 )
        k4_2 = step * diff_eq_2(t + step, x1 + k3_1,x2+k3_2 )

        x1_next = x1 + (k1_1 + 2.*k2_1 + 2.*k3_1 + k4_1) /6.
        x2_next = x2 + (k1_2 + 2.*k2_2 + 2.*k3_2 + k4_2) /6.

      return
      end
