OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
rk78.f
Go to the documentation of this file.
1  SUBROUTINE rk78(DER,T,TOUT,N,X,H,RELERR,ABSERR,SP)
2 C VERSION OF 4/1/85
3 C PURPOSE
4 C RUNGE-KUTTA 7(8) METHOD AS GIVEN BY THE FEHLBERG COEFFICIENTS
5 C NASA TR R-287
6 C INPUT
7 C DER = NAME OF SUBROUTINE CONTAINING THE DERIVATIVES
8 C T = INITIAL INTEGRATION TIME
9 C TOUT = FINAL INTEGRATION TIME
10 C N = NUMBER OF EQUATIONS TO BE INTEGRATED
11 C X = THE STATE TO BE INTEGRATED, DIMENSION 6 HERE
12 C H = INITIAL GUESS OF STEP-SIZE
13 C RELERR = RELATIVE TOLERANCE
14 C ABSERR = ABSOLUTE TOLERANCE
15 C SP = APPROXIMATE TIME THAT USEROP WILL BE CALLED
16 C OUTPUT
17 C T = AT TOUT, T=TOUT
18 C X = STATE AT TOUT
19 C CALL SUBROUTINES
20 C DER, USEROP
21 C REFERENCES
22 C JPL EM 312/87-153, 20 APRIL 1987
23 C NASA TR R-287, OCTOBER 1968
24 C ANALYSIS
25 C J. H. KWOK - JPL
26 C PROGRAMMER
27 C J. H. KWOK - JPL
28 C PROGRAM MODIFICATIONS
29 C
30 C DECLARED DER AS EXTERNAL TO ELIMINATE COMPILER WARNING.
31 C F. S. PATT, JANUARY 13, 1995.
32 C
33 C NONE
34 C COMMENTS
35 C USER MUST CALL RK78CN BEFORE CALLING RK78.
36 C THE DIMENSIONS OF XDUM AND F CAN BE CHANGED FROM 6 TO ACCOMMODATE
37 C ANY SYSTEM OF DIFFERENTIAL EQUATIONS. USEROP IS A USER OPTION
38 C ROUTINE WHERE THE HEALTH OF THE INTEGRATION CAN BE MONITORED BY
39 C SETTING SP=ZERO. IT CAN ALSO BE USED TO CHECK CERTAIN CONDITIONS
40 C OF THE STATE, AND POSSIBLY RESTART WITH A NEW STATE OR STEP-SIZE
41 C BY SETTING ISTART=1 IN USEROP.
42 C
43  IMPLICIT DOUBLE PRECISION (a-h,o-z)
44  common/felcon/ch(13),alph(13),beta(13,12),ordrcp,norder,ntimes
45  dimension xdum(6),f(6,13),x(*)
46  EXTERNAL der
47  DATA zero,one/0.d0,1.d0/
48 C
49 C *** FACT IS A SCALING FACTOR TO REDUCE THE ESTIMATED STEPSIZE TO AVOID
50 C *** EXCEESIVE NUMBER OF REJECTION.
51 C *** SMALL IS A SMALL NUMBER COMPARED TO THE SIZE OF T
52 C
53  DATA fact,small/0.7d0,1.d-8/
54 C
55 C *** INITIALIZATION
56 C
57  nstp=0
58  nrej=0
59  sdt=dsign(one,tout-t)
60  dt=dabs(h)*sdt
61  spp=dabs(sp)*sdt
62  tpr=t
63  istart=0
64  iflag=0
65 C
66 C *** CALL USEROP AT INITIAL T
67 C
68 C CALL USEROP(T,X,N,DT,NREJ,NSTP,ISTART,IFLAG)
69 C
70 C *** START INTEGRATION AND SAVE INITIAL INFO
71 C
72  100 CONTINUE
73  istart=0
74  nstp=nstp+1
75  tdum=t
76  tpr=tpr+spp
77  DO 110 i=1,n
78  110 xdum(i)=x(i)
79 C
80 C *** CHECK FOR T+DT PASSING TOUT
81 C
82  IF (dabs(dt).GT.dabs(tout-t)) dt=tout-t
83 C
84 C *** CHECK FOR REACHING TOUT
85 C
86  IF (dabs(t-tout).LT.small) GO TO 900
87 C
88 C *** START FUNCTION EVALUATIONS
89 C
90  CALL der(t,x,f(1,1))
91  DO 300 k=2,ntimes
92  kk=k-1
93  DO 310 i=1,n
94  temp=zero
95  DO 320 j=1,kk
96  320 temp=temp+beta(k,j)*f(i,j)
97  310 x(i)=xdum(i)+dt*temp
98  t=tdum+alph(k)*dt
99  CALL der(t,x,f(1,k))
100  300 CONTINUE
101 C
102 C *** COMPUTE NEW STATE
103 C
104  DO 400 i=1,n
105  temp=zero
106  DO 410 l=1,ntimes
107  410 temp=temp+ch(l)*f(i,l)
108  400 x(i)=xdum(i)+dt*temp
109 C
110 C *** START LOCAL TRUNCATION ERROR COMPUTATION
111 C
112  err=relerr
113  DO 500 i=1,n
114  ter=dabs((f(i,1)+f(i,11)-f(i,12)-f(i,13))*ch(12)*dt)
115  tol=dabs(x(i))*relerr+abserr
116  const=ter/tol
117  IF (const.GT.err) err=const
118  500 CONTINUE
119 C
120 C *** ESTIMATE NEW STEP-SIZE
121 C
122  dt=fact*dt*(one/err)**ordrcp
123 C
124 C *** IF IFLAG.EQ.1, ACCEPT THIS STEP UNCONDITIONALLY
125 C
126  IF (iflag.EQ.1) THEN
127  iflag=0
128  GO TO 510
129  ENDIF
130 C
131 C *** REJECT LAST STEP IF ER.LT.ONE OR ISTART.EQ.1
132 C
133  220 CONTINUE
134  IF (err.GT.one.OR.istart.EQ.1) THEN
135  t=tdum
136  DO 610 i=1,n
137  610 x(i)=xdum(i)
138  nrej=nrej+1
139  nstp=nstp-1
140  GO TO 100
141  ENDIF
142 C
143 C *** CHECK FOR TIME TO CALL USEROP
144 C
145  510 CONTINUE
146  IF (sdt.GT.zero.AND.t.GE.tpr) GO TO 200
147  IF (sdt.LT.zero.AND.t.LE.tpr) GO TO 200
148  GO TO 100
149  200 CONTINUE
150 C CALL USEROP(T,X,N,DT,NREJ,NSTP,ISTART,IFLAG)
151  IF (istart.EQ.1) GO TO 220
152  GO TO 100
153  900 CONTINUE
154 C
155 C *** CALL USEROP THE LAST TIME
156 C
157 C CALL USEROP(T,X,N,DT,NREJ,NSTP,ISTART,IFLAG)
158  RETURN
159  END
subroutine const(NGAUSS, NMAX, MMAX, P, X, W, AN, ANN, S, SS, NP, EPS)
Definition: ampld.lp.f:924
subroutine fact
Definition: tmd.lp.f:1161
#define f
Definition: l1_czcs_hdf.c:702
subroutine rk78(DER, T, TOUT, N, X, H, RELERR, ABSERR, SP)
Definition: rk78.f:2
subroutine der(T, X, DX)
Definition: der.f:2