'*********************************************************************** '* Integrate a System of Ordinary Differential Equations By the * '* Runge-Kutta-Fehlberg method (double precision) * '* ------------------------------------------------------------------- * '* REFERENCE: H A Watts and L F Shampine, * '* Sandia Laboratories, * '* Albuquerque, New Mexico. * '* ------------------------------------------------------------------- * '* SAMPLE RUN: * '* * '* PROGRAM TRKF45 * '* Demonstrate the RKF45 ODE integrator. * '* * '* TEST01 * '* Solve a scalar equation: * '* * '* Y' = 0.25 * Y * ( 1 - Y / 20 ) * '* * '* T Y Y_Exact Error * '* * '* 0.00000 1.00000 1.00000 0.0000000 * '* 4.00000 2.50321 2.50322 -0.0000087 * '* 8.00000 5.60007 5.60009 -0.0000193 * '* 12.00000 10.27774 10.27773 -0.0000069 * '* 16.00000 14.83682 14.83683 -0.0000038 * '* 20.00000 17.73017 17.73017 -0.0000084 * '* * '* TEST02 * '* Solve a vector equation: * '* * '* Y'(1) = Y(2) * '* Y'(2) = - Y(1) * '* * '* T Y1 Y2 * '* * '* 0.00000 1.00000 0.00000 * '* 0.52360 0.86603 -0.50000 * '* 1.04720 0.50000 -0.86603 * '* 1.57080 0.00000 -1.00000 * '* 2.09440 -0.50000 -0.86603 * '* 2.61799 -0.86603 -0.50000 * '* 3.14159 -1.00000 -0.00000 * '* 3.66519 -0.86603 0.50000 * '* 4.18879 -0.50000 0.86603 * '* 4.71239 -0.00000 1.00001 * '* 5.23599 0.50000 0.86604 * '* 5.75959 0.86604 0.50001 * '* 6.28319 1.00002 0.00000 * '* * '* TEST03 * '* Solve a vector equation: * '* * '* Y'(1) = Y(2) * '* Y'(2) = Y(3) * '* Y'(3) = Y(4) * '* Y'(4) = Y(5) * '* Y'(5) = (45 * Y(3) * Y(4) * Y(5) - 40 * Y(4)^3) / (9 * Y(3)^2) * '* * '* T Y1 Y2 Y3 Y4 Y5 * '* * '* 0.00000 1.00000 1.00000 1.00000 1.00000 1.00000 * '* 0.13636 1.14610 1.14609 1.14587 1.14068 1.05604 * '* 0.27273 1.31354 1.31340 1.31128 1.28532 1.05248 * '* 0.40909 1.50538 1.50460 1.49612 1.42333 0.95209 * '* 0.54545 1.72508 1.72223 1.69844 1.53859 0.71111 * '* 0.68182 1.97638 1.96840 1.91370 1.60897 0.28809 * '* 0.81818 2.26328 2.24438 2.13400 1.60781 -0.33918 * '* 0.95455 2.58984 2.55011 2.34770 1.50801 -1.15027 * '* 1.09091 2.96003 2.88369 2.53985 1.28946 -2.06094 * '* 1.22727 3.37739 3.24105 2.69376 0.94820 -2.92046 * '* 1.36364 3.84475 3.61589 2.79372 0.50379 -3.54302 * '* 1.50000 4.36396 4.00000 2.82843 -0.00000 -3.77124 * '* ------------------------------------------------------------------- * '* * '* Basic Release 1.1 By J-P Moreau, Paris. * '* (www.jpmoreau.fr) * '* * '* Release 1.1: added test #3. * '*********************************************************************** ' LIST OF SUBROUTINES: ' 400: User defined calculation of derivatives (examples #1 and #2) ' 500: Calculate exact solution (example #1) ' 600: Define example #1 ' 700: Define example #2 ' 800: Define example #3 ' 1000: Fehlberg subroutine (one step) ' 1200: Emulation of Fortran routine Sign (with integers) ' 1210: Emulation of Fortran routine Sign (with real numbers) ' 1300: Emulation of Fortran routine Max (with real numbers) ' 1310: Emulation of Fortran routine Min (with real numbers) ' 2000: Runge-Kutta-Fehlberg method (double precision) '------------------------------------------------------------ DEFDBL A-H, O-Z DEFINT I-N NEQ = 5 'Maximum number of equations PI = 4# * ATN(1#) 'Constant PI EPSILON = 2.22D-16 'Small number DIM y(NEQ), yp(NEQ) 'auxiliary variables used by 400 DIM yy(NEQ), yyp(NEQ) 'work space used by successive calls to 1000 and 2000 DIM f1(NEQ), f2(NEQ), f3(NEQ), f4(NEQ), f5(NEQ) CLS PRINT PRINT " PROGRAM TRKF45" PRINT " Demonstrate the RKF45 ODE integrator." GOSUB 600 'call test01 PRINT INPUT "Any key to continue... ", R\$ GOSUB 700 'call test02 PRINT INPUT "Any key to continue... ", R\$ GOSUB 800 'call test03 PRINT INPUT "Any key to continue... ", R\$ END 'of main program 'User defined system of diff. equations 400 'Subroutine f(tt, yy, yyp) '-------------------------------------------------------------------- ' ' F evaluates the derivative for the ODE (TESTS #1 and #2). ' '-------------------------------------------------------------------} IF num = 1 THEN yyp(1) = .25 * yy(1) * (1# - yy(1) / 20#) ELSEIF num = 2 THEN yyp(1) = yy(2): yyp(2) = -yy(1) ELSE yyp(1) = yy(2) yyp(2) = yy(3) yyp(3) = yy(4) yyp(4) = yy(5) yyp(5) = (45# * yy(3) * yy(4) * yy(5) - 40# * yy(4) ^ 3) / (9# * yy(3) ^ 2) END IF RETURN 500 'function yexact(tt) '-------------------------------------------------------------------- ' ' YEXACT evaluates the exact solution of the ODE (For TEST #1). ' '-------------------------------------------------------------------- yexact = 20# / (1# + 19# * EXP(-.25 * tt)) RETURN 600 'Subroutine test01 '-------------------------------------------------------------------- ' ' TEST01 solves a scalar ODE in double precision. ' '-------------------------------------------------------------------- num = 1 'example #1 neqn = 1 'one equation F\$ = "####.#####" G\$ = "####.#######" PRINT PRINT " TEST01" PRINT " Solve a scalar equation:" PRINT PRINT " Y' = 0.25 * Y * ( 1 - Y / 20 )" PRINT abserr = .000001# relerr = .000001# iflag = 1 tstart = 0# tstop = 20# nstep = 5 tout = 0# y(1) = 1# PRINT " T Y Y_Exact Error" PRINT tt = tout: GOSUB 500'calculate yexact(tout) PRINT " "; : PRINT USING F\$; tout; PRINT " "; : PRINT USING F\$; y(1); PRINT " "; : PRINT USING F\$; yexact; PRINT " "; : PRINT USING G\$; y(1) - yexact FOR istep = 1 TO nstep t = ((nstep - istep + 1) * tstart + (istep - 1) * tstop) / nstep tout = ((nstep - istep) * tstart + (istep) * tstop) / nstep GOSUB 2000 'call rkfs (neqn,y,t,tout,relerr,abserr,iflag,yp,h,f1..f5,savr,save, 'nfe,kop,init,jflag,kflag) tt = tout: GOSUB 500'calculate yexact(tout) PRINT " "; : PRINT USING F\$; tout; PRINT " "; : PRINT USING F\$; y(1); PRINT " "; : PRINT USING F\$; yexact; PRINT " "; : PRINT USING G\$; y(1) - yexact NEXT istep RETURN 700 'Subroutine test02 '-------------------------------------------------------------------- ' ' TEST02 solves a vector ODE. ' '-------------------------------------------------------------------- num = 2 'Example #2 neqn = 2 '2 equations PRINT PRINT " TEST02" PRINT " Solve a vector equation:" PRINT PRINT " Y'(1) = Y(2)" PRINT " Y'(2) = - Y(1)" abserr = .000001# relerr = .000001# iflag = 1 tstart = 0# tstop = 2# * PI nstep = 12 tout = 0# y(1) = 1# y(2) = 0# PRINT PRINT " T Y1 Y2" PRINT PRINT " "; : PRINT USING F\$; tout; PRINT " "; : PRINT USING F\$; y(1); PRINT " "; : PRINT USING F\$; y(2) FOR istep = 1 TO nstep t = ((nstep - istep + 1) * tstart + (istep - 1) * tstop) / nstep tout = ((nstep - istep) * tstart + (istep * tstop) / nstep) GOSUB 2000 'call rkfs (neqn,y,t,tout,relerr,abserr,iflag,yp,h,f1..f5,savr,save, 'nfe,kop,init,jflag,kflag) PRINT " "; : PRINT USING F\$; tout; PRINT " "; : PRINT USING F\$; y(1); PRINT " "; : PRINT USING F\$; y(2) NEXT istep RETURN 800 'Subroutine test03 '-------------------------------------------------------------------- ' ' TEST02 solves a vector ODE. ' '-------------------------------------------------------------------- num = 3 'Example #3 neqn = 5 '5 equations PRINT PRINT " TEST03" PRINT " Solve a vector equation:" PRINT PRINT " Y'(1) = Y(2)" PRINT " Y'(2) = Y(3)" PRINT " Y'(3) = Y(4)" PRINT " Y'(4) = Y(5)" PRINT " Y'(5) = (45 * Y(3) * Y(4) * Y(5) - 40 * Y(4)^3) / (9 * Y(3)^2)" abserr = .000001# relerr = .000001# iflag = 1 tstart = 0# tstop = 1.5 nstep = 11 tout = 0# y(1) = 1# y(2) = 1# y(3) = 1# y(4) = 1# y(5) = 1# PRINT PRINT " T Y1 Y2 Y3 Y4 Y5" PRINT PRINT " "; : PRINT USING F\$; tout; PRINT " "; : PRINT USING F\$; y(1); PRINT " "; : PRINT USING F\$; y(2); PRINT " "; : PRINT USING F\$; y(3); PRINT " "; : PRINT USING F\$; y(4); PRINT " "; : PRINT USING F\$; y(5) FOR istep = 1 TO nstep t = ((nstep - istep + 1) * tstart + (istep - 1) * tstop) / nstep tout = ((nstep - istep) * tstart + (istep * tstop) / nstep) GOSUB 2000 'call rkfs (neqn,y,t,tout,relerr,abserr,iflag,yp,h,f1..f5,savr,save, 'nfe,kop,init,jflag,kflag) PRINT " "; : PRINT USING F\$; tout; PRINT " "; : PRINT USING F\$; y(1); PRINT " "; : PRINT USING F\$; y(2); PRINT " "; : PRINT USING F\$; y(3); PRINT " "; : PRINT USING F\$; y(4); PRINT " "; : PRINT USING F\$; y(5) NEXT istep RETURN '************************************************************************ '* Collection of Basic subroutines to Integrate a System of Ordinary * '* Differential Equations By the Runge-Kutta-Fehlberg method (in double * '* precision). * '************************************************************************ 1000 'Subroutine fehl(neqn, y, t, h, yp, f1, f2, f3, f4, f5, s) '************************************************************************ ' ' FEHL takes one Fehlberg fourth-fifth order step (double precision). ' ' Discussion: ' ' FEHL integrates a system of NEQN first order ordinary differential ' equations of the form ' dY(i)/dT = F(T,Y(1),---,Y(NEQN)) ' where the initial values Y and the initial derivatives ' YP are specified at the starting point T. ' ' FEHL advances the solution over the fixed step H and returns ' the fifth order (sixth order accurate locally) solution ' approximation at T+H in array S. ' ' The formulas have been grouped to control loss of significance. ' FEHL should be called with an H not smaller than 13 units of ' roundoff in T so that the various independent arguments can be ' distinguished. ' ' Author: ' ' H A Watts and L F Shampine, ' Sandia Laboratories, ' Albuquerque, New Mexico. ' ' RKF45 is primarily designed to solve non-stiff and mildly stiff ' differential equations when derivative evaluations are inexpensive. ' ' Parameters: ' ' Input, external F, a subroutine of the form ' Procedure f(t:double; y:VEC; var yp:VEC); ' to evaluate the derivatives. ' YP(I) = dY(I) / dT; ' ' Input, integer NEQN, the number of equations to be integrated. ' ' Input, double Y(NEQN), the current value of the dependent variable. ' ' Input, double T, the current value of the independent variable. ' ' Input, double H, the step size to take. ' ' Input, double YP(NEQN), the current value of the derivative of the ' dependent variable. ' ' Output, double F1(NEQN), double F2(NEQN), double F3(NEQN), double F4(NEQN), ' double F5(NEQN) are arrays of dimension NEQN which are needed for ' internal storage. ' ' Output, double S(NEQN), the computed estimate of the solution at T+H. '******************************************************************************} ch = h / 4# FOR i = 1 TO neqn f5(i) = y(i) + ch * yp(i) NEXT i tt = t + ch: FOR i = 1 TO neqn yy(i) = f5(i) NEXT i GOSUB 400 'call f(t+ch, f5, f1) FOR i = 1 TO neqn f1(i) = yyp(i) NEXT i ch = 3# * h / 32# FOR i = 1 TO neqn f5(i) = y(i) + ch * (yp(i) + 3# * f1(i)) NEXT i tt = t + 3# * h / 8# FOR i = 1 TO neqn yy(i) = f5(i) NEXT i GOSUB 400 'call f(t+3#*h/8#, f5, f2) FOR i = 1 TO neqn f2(i) = yyp(i) NEXT i ch = h / 2197# FOR i = 1 TO neqn f5(i) = y(i) + ch * (1932# * yp(i) + (7296# * f2(i) - 7200# * f1(i))) NEXT i tt = t + 12# * h / 13# FOR i = 1 TO neqn yy(i) = f5(i) NEXT i GOSUB 400 'call f(t+12#*h/13#, f5, f3) FOR i = 1 TO neqn f3(i) = yyp(i) NEXT i ch = h / 4104# FOR i = 1 TO neqn f5(i) = y(i) + ch * ((8341# * yp(i) - 845# * f3(i)) + (29440# * f2(i) - 32832# * f1(i))) NEXT i tt = t + h FOR i = 1 TO neqn yy(i) = f5(i) NEXT i GOSUB 400: 'call f(t+h, f5, f4) FOR i = 1 TO neqn f4(i) = yyp(i) NEXT i ch = h / 20520# FOR i = 1 TO neqn tmp = (41040# * f1(i) - 28352# * f2(i)) f1(i) = y(i) + ch * ((-6080# * yp(i) + (9295# * f3(i) - 5643# * f4(i))) + tmp) NEXT i tt = t + h / 2# FOR i = 1 TO neqn yy(i) = f1(i) NEXT i GOSUB 400 'call f(t+h/2#, f1, f5) FOR i = 1 TO neqn f5(i) = yyp(i) NEXT i ' Ready to compute the approximate solution at T+H. ch = h / 7618050# FOR i = 1 TO neqn tmp = (3953664# * f2(i) + 277020# * f5(i)) f1(i) = y(i) + ch * ((902880# * yp(i) + (3855735# * f3(i) - 1371249# * f4(i))) + tmp) NEXT i RETURN 'Emulation of Fortran Intrisic Functions 1200 'Function ISign(ia,ib) IF ib < 0 THEN ISign = -ABS(ia) ELSE ISign = ABS(ia) END IF RETURN 1210 'Function Sign(a,b) IF b < 0 THEN Sign = -ABS(a) ELSE Sign = ABS(a) END IF RETURN 1300 'Function XMax(a,b) IF a >= b THEN XMax = a ELSE XMax = b END IF RETURN 1310 'Function XMin(a,b) IF a <= b THEN XMIN = a ELSE XMIN = b END IF RETURN 2000 'Subroutine rkfs(neqn, y, t, tout, relerr, abserr, iflag, yp, h, f1, f2, f3, f4,f5, ' savr, save, nfe, kop, init, jflag, kflag) '*************************************************************************************** ' ' RKFS implements the Runge-Kutta-Fehlberg method (double precision). ' ' Discussion: ' ' RKFS integrates a system of first order ordinary differential ' equations as described in the comments for RKF45. ' ' The arrays yp, f1, f2, f3, f4, and f5 (of dimension neqn) and ' the variables h, savre, savae, nfe, kop, init, jflag and kflag are used ' internally by the code and appear in the call list to eliminate ' local retention of variables between calls. Accordingly, they ' should not be altered. Items of possible interest are ' ' YP - the derivative of the solution vector at T; ' H - an appropriate stepsize to be used for the next step; ' NFE - the number of derivative function evaluations. ' ' The expense is controlled by restricting the number ' of function evaluations to be approximately MAXNFE. ' As set, this corresponds to about 500 steps. ' ' REMIN is the minimum acceptable value of RELERR. Attempts ' to obtain higher accuracy with this subroutine are usually ' very expensive and often unsuccessful. '*************************************************************************************** 'Labels: 25,40,45,50,60,65,80,100,200,260 remin = .000000000001# maxnfe = 3000 ' ihfaild, ioutput: boolean (0 or 1) ' Check the input parameters eps = EPSILON IF neqn < 1 THEN iflag = 8 RETURN END IF IF relerr < 0# THEN iflag = 8 RETURN END IF IF abserr < 0# THEN iflag = 8 RETURN END IF mflag = ABS(iflag) IF ABS(iflag) < 1 OR ABS(iflag) > 8 THEN iflag = 8 RETURN END IF ' Is this the first call? IF mflag = 1 THEN GOTO 50 ' Check continuation possibilities IF t = tout AND kflag <> 3 THEN iflag = 8 RETURN END IF IF mflag <> 2 THEN GOTO 25 ' iflag = +2 or -2 IF kflag = 3 THEN GOTO 45 IF init = 0 THEN GOTO 45 IF kflag = 4 THEN GOTO 40 IF kflag = 5 AND abserr = 0# THEN END IF kflag = 6 AND relerr <= savr AND abserr <= save THEN END GOTO 50 ' iflag = 3,4,5,6,7 or 8 25 IF iflag = 3 THEN GOTO 45 IF iflag = 4 THEN GOTO 40 IF iflag = 5 AND abserr > 0# THEN GOTO 45 ' Integration cannot be continued since user did not respond to ' the instructions pertaining to iflag=5,6,7 or 8. END ' Reset function evaluation counter 40 nfe = 0 IF mflag = 2 THEN GOTO 50 ' Reset flag value from previous call 45 iflag = jflag IF kflag = 3 THEN mflag = ABS(iflag) ' Save input iflag and set continuation flag for subsequent input checking 50 jflag = iflag kflag = 0 ' Save relerr and abserr for checking input on subsequent calls savr = relerr save = abserr ' Restrict relative error tolerance to be at least as large as ' 2*eps+remin to avoid limiting precision difficulties arising ' from impossible accuracy requests. rer = 2# * EPSILON + remin ' The relative error tolerance is too small IF relerr < rer THEN relerr = rer iflag = 3 kflag = 3 RETURN END IF dt = tout - t IF mflag = 1 THEN GOTO 60 IF init = 0 THEN GOTO 65 GOTO 80 ' Initialization: ' set initialization completion indicator, init ' set indicator for too many output points, kop ' evaluate initial derivatives ' set counter for function evaluations, nfe ' evaluate initial derivatives ' set counter for function evaluations, nfe ' estimate starting stepsize. 60 init = 0 kop = 0 a = t FOR i = 1 TO neqn yy(i) = y(i) NEXT i GOSUB 400 'call f(a, y, yp) FOR i = 1 TO neqn yp(i) = yyp(i) NEXT i nfe = 1 IF t = tout THEN iflag = 2 RETURN END IF 65 init = 1 h = ABS(dt) toln = 0# FOR k = 1 TO neqn tol = relerr * ABS(y(k)) + abserr IF tol > 0# THEN toln = tol ypk = ABS(yp(k)) IF ypk * h ^ 5 > tol THEN h = (tol / ypk) ^ .2 END IF END IF NEXT k IF toln <= 0# THEN h = 0# 'h = XMax(h, 26# * eps * XMax(abs(t), abs(dt))) IF ABS(t) > ABS(dt) THEN tmp = ABS(t) ELSE tmp = ABS(dt) END IF IF h < 26# * eps * tmp THEN h = 26# * eps * tmp END IF ia = 2: ib = iflag: GOSUB 1200 jflag = ISign ' Set stepsize for integration in the direction from T to TOUT 80 a = h: b = dt: GOSUB 1210 h = Sign ' Test to see if RKF45 is being severely impacted by too many output points. IF ABS(h) >= 2# * ABS(dt) THEN kop = kop + 1 ' Unnecessary frequency of output IF kop = 100 THEN kop = 0 iflag = 7 RETURN END IF ' If too close to output point, extrapolate and return IF ABS(dt) <= 26# * eps * ABS(t) THEN FOR i = 1 TO neqn y(i) = y(i) + dt * yp(i) NEXT i a = tout FOR i = 1 TO neqn yy(i) = y(i) NEXT i GOSUB 400 'call f(a, y, yp) FOR i = 1 TO neqn yp(i) = yyp(i) NEXT i nfe = nfe + 1 t = tout iflag = 2 RETURN END IF ' Initialize output point indicator ioutput = 0 ' To avoid premature underflow in the error tolerance function, ' scale the error tolerances. scale = 2# / relerr ae = scale * abserr ' Step by step integration 100 : ihfaild = 0 ' Set smallest allowable stepsize hmin = 26# * eps * ABS(t) ' Adjust stepsize if necessary to hit the output point. ' Look ahead two steps to avoid drastic changes in the stepsize and ' thus lessen the impact of output points on the code. dt = tout - t IF ABS(dt) >= 2# * ABS(h) THEN GOTO 200 ' The next successful step will complete the integration to the output point. IF ABS(dt) <= ABS(h) THEN ioutput = 1 h = dt GOTO 200 END IF h = .5 * dt 'reduce step ' Core integrator for taking a single step ' ' The tolerances have been scaled to avoid premature underflow in ' computing the error tolerance function ET. ' To avoid problems with zero crossings, relative error is measured ' using the average of the magnitudes of the solution at the ' beginning and end of a step. ' The error estimate formula has been grouped to control loss of ' significance. ' ' To distinguish the various arguments, H is not permitted ' to become smaller than 26 units of roundoff in T. ' Practical limits on the change in the stepsize are enforced to ' smooth the stepsize selection process and to avoid excessive ' chattering on problems having discontinuities. ' To prevent unnecessary failures, the code uses 9/10 the stepsize ' it estimates will succeed. ' ' After a step failure, the stepsize is not allowed to increase for ' the next attempted step. This makes the code more efficient on ' problems having discontinuities and more effective in general ' since local extrapolation is being used and extra caution seems ' warranted. ' ' Test number of derivative function evaluations. ' If okay, try to advance the integration from T to T+H. ' Too many function calls. 200 IF nfe > maxnfe THEN iflag = 4 kflag = 4 RETURN END IF ' Advance an approximate solution over one step of length H. GOSUB 1000 'call fehl(neqn, y, t, h, yp, f1, f2, f3, f4, f5, f1) nfe = nfe + 5 ' Compute and test allowable tolerances versus local error estimates ' and remove scaling of tolerances. Note that relative error is ' measured with respect to the average of the magnitudes of the ' solution at the beginning and end of the step. eeoet = 0# FOR k = 1 TO neqn et = ABS(y(k)) + ABS(f1(k)) + ae IF et <= 0# THEN iflag = 5 RETURN END IF tmp = (22528# * f2(k) - 27360# * f5(k)) ee = ABS((-2090# * yp(k) + (21970# * f3(k) - 15048# * f4(k))) + tmp) 'eeoet = XMax(eeoet, ee/et) a = eecet: b = ee / et: GOSUB 1300: eecet = XMax NEXT k esttol = ABS(h) * eeoet * scale / 752400# IF esttol <= 1# THEN GOTO 260 ' Unsuccessful step. Reduce the stepsize, try again. ' The decrease is limited to a factor of 1/10. ihfaild = 1 ioutput = 0 IF esttol < 59049# THEN s = .9 / (esttol ^ .2) ELSE s = .1 END IF h = s * h IF ABS(h) < hmin THEN iflag = 6 kflag = 6 RETURN ELSE GOTO 200 END IF ' Successful step. Store solution at T+H and evaluate derivatives there. 260 t = t + h FOR i = 1 TO neqn y(i) = f1(i) NEXT i a = t FOR i = 1 TO neqn yy(i) = y(i) NEXT i GOSUB 400 'call f(a, y, yp) FOR i = 1 TO neqn yp(i) = yyp(i) NEXT i nfe = nfe + 1 ' Choose next stepsize. The increase is limited to a factor of 5. ' If step failure has just occurred, next stepsize is not allowed to increase. IF esttol > .0001889568# THEN s = .9 / esttol ^ .2 ELSE s = 5# END IF IF ihfaild <> 0 THEN 's = XMin(s, 1#) a = s: b = 1#: GOSUB 1310: s = XMIN END IF 'h = Sign(XMax(s * abs(h), hmin), h) a = s * ABS(h): b = hmin: GOSUB 1300 a = XMax: b = h: GOSUB 1210: h = Sign ' End of core integrator ' Should we take another step? IF ioutput <> 0 THEN t = tout iflag = 2 END IF IF iflag > 0 THEN GOTO 100 ' Integration successfully completed ' ne-step mode iflag = -2 RETURN 'end of file trkf45.bas