| 1 | afe | 1.1 | c***  4th order runge-kutta, more or less straight out of | 
| 2 |  |  | c***  numerical recipes | 
| 3 |  |  |  | 
| 4 |  |  | subroutine rk4(y,dydx,par,n,x,h,yout,derivs) | 
| 5 |  |  |  | 
| 6 |  |  | implicit none | 
| 7 |  |  |  | 
| 8 |  |  | integer i, n | 
| 9 |  |  | real y(n),dydx(n),yout(n) | 
| 10 |  |  | real yt(n), par(n), dyt(n) | 
| 11 |  |  | real dym(n) | 
| 12 |  |  | real h, hh, x, xh, h6 | 
| 13 |  |  | external derivs | 
| 14 |  |  |  | 
| 15 |  |  | hh=h*0.5 | 
| 16 |  |  | h6=h/6. | 
| 17 |  |  | xh=x+hh | 
| 18 |  |  |  | 
| 19 |  |  | do i=1,n | 
| 20 |  |  | yt(i)=y(i)+hh*dydx(i) | 
| 21 |  |  | enddo | 
| 22 |  |  | call derivs(xh,yt,dyt,par,n) | 
| 23 |  |  | do i=1,n | 
| 24 |  |  | yt(i)=y(i)+hh*dyt(i) | 
| 25 |  |  | enddo | 
| 26 |  |  | call derivs(xh,yt,dym,par,n) | 
| 27 |  |  | do i=1,n | 
| 28 |  |  | yt(i)=y(i)+h*dym(i) | 
| 29 |  |  | dym(i)=dyt(i)+dym(i) | 
| 30 |  |  | enddo | 
| 31 |  |  | call derivs(x+h,yt,dyt,par,n) | 
| 32 |  |  | do i=1,n | 
| 33 |  |  | yout(i)=y(i)+h6*(dydx(i)+dyt(i)+2.*dym(i)) | 
| 34 |  |  | enddo | 
| 35 |  |  |  | 
| 36 |  |  | return | 
| 37 |  |  | end | 
| 38 |  |  |  |