2 SUBROUTINE DRCHEK
(JOB
, G
, NEQ
, Y
, YH
,NYH
, G0
, G1
, GX
, JROOT
, IRT
)
4 INTEGER JOB
, NEQ
, NYH
, JROOT
, IRT
5 DOUBLE PRECISION Y
, YH
, G0
, G1
, GX
6 DIMENSION NEQ
(*), Y
(*), YH
(NYH
,*), G0
(*), G1
(*), GX
(*), JROOT
(*)
8 1 ICF
, IERPJ
, IERSL
, JCUR
, JSTART
, KFLAG
, L
,
9 2 LYH
, LEWT
, LACOR
, LSAVF
, LWM
, LIWM
, METH
, MITER
,
10 3 MAXORD
, MAXCOR
, MSBP
, MXNCF
, N
, NQ
, NST
, NFE
, NJE
, NQU
11 INTEGER IOWND3
, IOWNR3
, IRFND
, ITASKC
, NGC
, NGE
12 DOUBLE PRECISION ROWNS
,
13 1 CCMAX
, EL0
, H
, HMIN
, HMXI
, HU
, RC
, TN
, UROUND
14 DOUBLE PRECISION ROWNR3
, T0
, TLAST
, TOUTC
15 COMMON /DLS001
/ ROWNS
(209),
16 1 CCMAX
, EL0
, H
, HMIN
, HMXI
, HU
, RC
, TN
, UROUND
,
18 3 ICF
, IERPJ
, IERSL
, JCUR
, JSTART
, KFLAG
, L
,
19 4 LYH
, LEWT
, LACOR
, LSAVF
, LWM
, LIWM
, METH
, MITER
,
20 5 MAXORD
, MAXCOR
, MSBP
, MXNCF
, N
, NQ
, NST
, NFE
, NJE
, NQU
21 COMMON /DLSR01
/ ROWNR3
(2), T0
, TLAST
, TOUTC
,
22 1 IOWND3
(3), IOWNR3
(2), IRFND
, ITASKC
, NGC
, NGE
23 INTEGER I
, IFLAG
, JFLAG
24 DOUBLE PRECISION HMING
, T1
, TEMP1
, TEMP2
, X
26 C-----------------------------------------------------------------------
27 C This routine checks for the presence of a root in the
28 C vicinity of the current T, in a manner depending on the
29 C input flag JOB. It calls Subroutine DROOTS to locate the root
30 C as precisely as possible.
32 C In addition to variables described previously, DRCHEK
33 C uses the following for communication:
34 C JOB = integer flag indicating type of call:
35 C JOB = 1 means the problem is being initialized, and DRCHEK
36 C is to look for a root at or very near the initial T.
37 C JOB = 2 means a continuation call to the solver was just
38 C made, and DRCHEK is to check for a root in the
39 C relevant part of the step last taken.
40 C JOB = 3 means a successful step was just taken, and DRCHEK
41 C is to look for a root in the interval of the step.
42 C G0 = array of length NG, containing the value of g at T = T0.
43 C G0 is input for JOB .ge. 2, and output in all cases.
44 C G1,GX = arrays of length NG for work space.
45 C IRT = completion flag:
46 C IRT = 0 means no root was found.
47 C IRT = -1 means JOB = 1 and a root was found too near to T.
48 C IRT = 1 means a legitimate root was found (JOB = 2 or 3).
49 C On return, T0 is the root location, and Y is the
50 C corresponding solution vector.
51 C T0 = value of T at one endpoint of interval of interest. Only
52 C roots beyond T0 in the direction of integration are sought.
53 C T0 is input if JOB .ge. 2, and output in all cases.
54 C T0 is updated by DRCHEK, whether a root is found or not.
55 C TLAST = last value of T returned by the solver (input only).
56 C TOUTC = copy of TOUT (input only).
57 C IRFND = input flag showing whether the last step taken had a root.
58 C IRFND = 1 if it did, = 0 if not.
59 C ITASKC = copy of ITASK (input only).
60 C NGC = copy of NG (input only).
61 C-----------------------------------------------------------------------
65 HMING
= (ABS
(TN
) + ABS
(H
))*UROUND*100
.0D0
67 GO TO (100, 200, 300), JOB
69 C Evaluate g at initial T, and check for zero values. ------------------
72 CALL G
(NEQ
, T0
, Y
, NGC
, G0
)
76 110 IF (ABS
(G0
(I
)) .LE
. 0.0D0
) ZROOT
= .TRUE
.
77 IF (.NOT
. ZROOT
) GO TO 190
78 C g has a zero at T. Look at g at T + (small increment). --------------
83 120 Y
(I
) = Y
(I
) + TEMP2*YH
(I
,2)
84 CALL G
(NEQ
, T0
, Y
, NGC
, G0
)
88 130 IF (ABS
(G0
(I
)) .LE
. 0.0D0
) ZROOT
= .TRUE
.
89 IF (.NOT
. ZROOT
) GO TO 190
90 C g has a zero at T and also close to T. Take error return. -----------
99 IF (IRFND
.EQ
. 0) GO TO 260
100 C If a root was found on the previous step, evaluate G0 = g(T0). -------
101 CALL DINTDY
(T0
, 0, YH
, NYH
, Y
, IFLAG
)
102 CALL G
(NEQ
, T0
, Y
, NGC
, G0
)
106 210 IF (ABS
(G0
(I
)) .LE
. 0.0D0
) ZROOT
= .TRUE
.
107 IF (.NOT
. ZROOT
) GO TO 260
108 C g has a zero at T0. Look at g at T + (small increment). -------------
109 TEMP1
= SIGN
(HMING
,H
)
111 IF ((T0
- TN
)*H
.LT
. 0.0D0
) GO TO 230
114 220 Y
(I
) = Y
(I
) + TEMP2*YH
(I
,2)
116 230 CALL DINTDY
(T0
, 0, YH
, NYH
, Y
, IFLAG
)
117 240 CALL G
(NEQ
, T0
, Y
, NGC
, G0
)
121 IF (ABS
(G0
(I
)) .GT
. 0.0D0
) GO TO 250
125 IF (.NOT
. ZROOT
) GO TO 260
126 C g has a zero at T0 and also close to T0. Return root. ---------------
129 C G0 has no zero components. Proceed to check relevant interval. ------
130 260 IF (TN
.EQ
. TLAST
) GO TO 390
133 C Set T1 to TN or TOUTC, whichever comes first, and get g at T1. -------
134 IF (ITASKC
.EQ
.2 .OR
. ITASKC
.EQ
.3 .OR
. ITASKC
.EQ
.5) GO TO 310
135 IF ((TOUTC
- TN
)*H
.GE
. 0.0D0
) GO TO 310
137 IF ((T1
- T0
)*H
.LE
. 0.0D0
) GO TO 390
138 CALL DINTDY
(T1
, 0, YH
, NYH
, Y
, IFLAG
)
143 330 CALL G
(NEQ
, T1
, Y
, NGC
, G1
)
145 C Call DROOTS to search for root in interval from T0 to T1. ------------
148 CALL DROOTS
(NGC
, HMING
, JFLAG
, T0
, T1
, G0
, G1
, GX
, X
, JROOT
)
149 IF (JFLAG
.GT
. 1) GO TO 360
150 CALL DINTDY
(X
, 0, YH
, NYH
, Y
, IFLAG
)
151 CALL G
(NEQ
, X
, Y
, NGC
, GX
)
155 CALL DCOPY
(NGC
, GX
, 1, G0
, 1)
156 IF (JFLAG
.EQ
. 4) GO TO 390
157 C Found a root. Interpolate to X and return. --------------------------
158 CALL DINTDY
(X
, 0, YH
, NYH
, Y
, IFLAG
)
164 C----------------------- End of Subroutine DRCHEK ----------------------