GNU Octave  4.0.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
dlsode.f
Go to the documentation of this file.
1  SUBROUTINE dlsode (F, NEQ, Y, T, TOUT, ITOL, RTOL, ATOL, ITASK,
2  1 istate, iopt, rwork, lrw, iwork, liw, jac, mf)
3  EXTERNAL f, jac
4  INTEGER NEQ, ITOL, ITASK, ISTATE, IOPT, LRW, IWORK, LIW, MF
5  DOUBLE PRECISION Y, T, TOUT, RTOL, ATOL, RWORK
6  dimension neq(*), y(*), rtol(*), atol(*), rwork(lrw), iwork(liw)
7 C-----------------------------------------------------------------------
8 C THIS IS THE MARCH 30, 1987 VERSION OF
9 C LSODE.. LIVERMORE SOLVER FOR ORDINARY DIFFERENTIAL EQUATIONS.
10 C THIS VERSION IS IN DOUBLE PRECISION.
11 C
12 C LSODE SOLVES THE INITIAL VALUE PROBLEM FOR STIFF OR NONSTIFF
13 C SYSTEMS OF FIRST ORDER ODE-S,
14 C DY/DT = F(T,Y) , OR, IN COMPONENT FORM,
15 C DY(I)/DT = F(I) = F(I,T,Y(1),Y(2),...,Y(NEQ)) (I = 1,...,NEQ).
16 C LSODE IS A PACKAGE BASED ON THE GEAR AND GEARB PACKAGES, AND ON THE
17 C OCTOBER 23, 1978 VERSION OF THE TENTATIVE ODEPACK USER INTERFACE
18 C STANDARD, WITH MINOR MODIFICATIONS.
19 C-----------------------------------------------------------------------
20 C REFERENCE..
21 C ALAN C. HINDMARSH, ODEPACK, A SYSTEMATIZED COLLECTION OF ODE
22 C SOLVERS, IN SCIENTIFIC COMPUTING, R. S. STEPLEMAN ET AL. (EDS.),
23 C NORTH-HOLLAND, AMSTERDAM, 1983, PP. 55-64.
24 C-----------------------------------------------------------------------
25 C AUTHOR AND CONTACT.. ALAN C. HINDMARSH,
26 C COMPUTING AND MATHEMATICS RESEARCH DIV., L-316
27 C LAWRENCE LIVERMORE NATIONAL LABORATORY
28 C LIVERMORE, CA 94550.
29 C-----------------------------------------------------------------------
30 C SUMMARY OF USAGE.
31 C
32 C COMMUNICATION BETWEEN THE USER AND THE LSODE PACKAGE, FOR NORMAL
33 C SITUATIONS, IS SUMMARIZED HERE. THIS SUMMARY DESCRIBES ONLY A SUBSET
34 C OF THE FULL SET OF OPTIONS AVAILABLE. SEE THE FULL DESCRIPTION FOR
35 C DETAILS, INCLUDING OPTIONAL COMMUNICATION, NONSTANDARD OPTIONS,
36 C AND INSTRUCTIONS FOR SPECIAL SITUATIONS. SEE ALSO THE EXAMPLE
37 C PROBLEM (WITH PROGRAM AND OUTPUT) FOLLOWING THIS SUMMARY.
38 C
39 C A. FIRST PROVIDE A SUBROUTINE OF THE FORM..
40 C SUBROUTINE F (NEQ, T, Y, YDOT, IERR)
41 C DIMENSION Y(NEQ), YDOT(NEQ)
42 C WHICH SUPPLIES THE VECTOR FUNCTION F BY LOADING YDOT(I) WITH F(I).
43 C
44 C B. NEXT DETERMINE (OR GUESS) WHETHER OR NOT THE PROBLEM IS STIFF.
45 C STIFFNESS OCCURS WHEN THE JACOBIAN MATRIX DF/DY HAS AN EIGENVALUE
46 C WHOSE REAL PART IS NEGATIVE AND LARGE IN MAGNITUDE, COMPARED TO THE
47 C RECIPROCAL OF THE T SPAN OF INTEREST. IF THE PROBLEM IS NONSTIFF,
48 C USE A METHOD FLAG MF = 10. IF IT IS STIFF, THERE ARE FOUR STANDARD
49 C CHOICES FOR MF, AND LSODE REQUIRES THE JACOBIAN MATRIX IN SOME FORM.
50 C THIS MATRIX IS REGARDED EITHER AS FULL (MF = 21 OR 22),
51 C OR BANDED (MF = 24 OR 25). IN THE BANDED CASE, LSODE REQUIRES TWO
52 C HALF-BANDWIDTH PARAMETERS ML AND MU. THESE ARE, RESPECTIVELY, THE
53 C WIDTHS OF THE LOWER AND UPPER PARTS OF THE BAND, EXCLUDING THE MAIN
54 C DIAGONAL. THUS THE BAND CONSISTS OF THE LOCATIONS (I,J) WITH
55 C I-ML .LE. J .LE. I+MU, AND THE FULL BANDWIDTH IS ML+MU+1.
56 C
57 C C. IF THE PROBLEM IS STIFF, YOU ARE ENCOURAGED TO SUPPLY THE JACOBIAN
58 C DIRECTLY (MF = 21 OR 24), BUT IF THIS IS NOT FEASIBLE, LSODE WILL
59 C COMPUTE IT INTERNALLY BY DIFFERENCE QUOTIENTS (MF = 22 OR 25).
60 C IF YOU ARE SUPPLYING THE JACOBIAN, PROVIDE A SUBROUTINE OF THE FORM..
61 C SUBROUTINE JAC (NEQ, T, Y, ML, MU, PD, NROWPD)
62 C DIMENSION Y(NEQ), PD(NROWPD,NEQ)
63 C WHICH SUPPLIES DF/DY BY LOADING PD AS FOLLOWS..
64 C FOR A FULL JACOBIAN (MF = 21), LOAD PD(I,J) WITH DF(I)/DY(J),
65 C THE PARTIAL DERIVATIVE OF F(I) WITH RESPECT TO Y(J). (IGNORE THE
66 C ML AND MU ARGUMENTS IN THIS CASE.)
67 C FOR A BANDED JACOBIAN (MF = 24), LOAD PD(I-J+MU+1,J) WITH
68 C DF(I)/DY(J), I.E. LOAD THE DIAGONAL LINES OF DF/DY INTO THE ROWS OF
69 C PD FROM THE TOP DOWN.
70 C IN EITHER CASE, ONLY NONZERO ELEMENTS NEED BE LOADED.
71 C
72 C D. WRITE A MAIN PROGRAM WHICH CALLS SUBROUTINE LSODE ONCE FOR
73 C EACH POINT AT WHICH ANSWERS ARE DESIRED. THIS SHOULD ALSO PROVIDE
74 C FOR POSSIBLE USE OF LOGICAL UNIT 6 FOR OUTPUT OF ERROR MESSAGES
75 C BY LSODE. ON THE FIRST CALL TO LSODE, SUPPLY ARGUMENTS AS FOLLOWS..
76 C F = NAME OF SUBROUTINE FOR RIGHT-HAND SIDE VECTOR F.
77 C THIS NAME MUST BE DECLARED EXTERNAL IN CALLING PROGRAM.
78 C NEQ = NUMBER OF FIRST ORDER ODE-S.
79 C Y = ARRAY OF INITIAL VALUES, OF LENGTH NEQ.
80 C T = THE INITIAL VALUE OF THE INDEPENDENT VARIABLE.
81 C TOUT = FIRST POINT WHERE OUTPUT IS DESIRED (.NE. T).
82 C ITOL = 1 OR 2 ACCORDING AS ATOL (BELOW) IS A SCALAR OR ARRAY.
83 C RTOL = RELATIVE TOLERANCE PARAMETER (SCALAR).
84 C ATOL = ABSOLUTE TOLERANCE PARAMETER (SCALAR OR ARRAY).
85 C THE ESTIMATED LOCAL ERROR IN Y(I) WILL BE CONTROLLED SO AS
86 C TO BE ROUGHLY LESS (IN MAGNITUDE) THAN
87 C EWT(I) = RTOL*ABS(Y(I)) + ATOL IF ITOL = 1, OR
88 C EWT(I) = RTOL*ABS(Y(I)) + ATOL(I) IF ITOL = 2.
89 C THUS THE LOCAL ERROR TEST PASSES IF, IN EACH COMPONENT,
90 C EITHER THE ABSOLUTE ERROR IS LESS THAN ATOL (OR ATOL(I)),
91 C OR THE RELATIVE ERROR IS LESS THAN RTOL.
92 C USE RTOL = 0.0 FOR PURE ABSOLUTE ERROR CONTROL, AND
93 C USE ATOL = 0.0 (OR ATOL(I) = 0.0) FOR PURE RELATIVE ERROR
94 C CONTROL. CAUTION.. ACTUAL (GLOBAL) ERRORS MAY EXCEED THESE
95 C LOCAL TOLERANCES, SO CHOOSE THEM CONSERVATIVELY.
96 C ITASK = 1 FOR NORMAL COMPUTATION OF OUTPUT VALUES OF Y AT T = TOUT.
97 C ISTATE = INTEGER FLAG (INPUT AND OUTPUT). SET ISTATE = 1.
98 C IOPT = 0 TO INDICATE NO OPTIONAL INPUTS USED.
99 C RWORK = REAL WORK ARRAY OF LENGTH AT LEAST..
100 C 20 + 16*NEQ FOR MF = 10,
101 C 22 + 9*NEQ + NEQ**2 FOR MF = 21 OR 22,
102 C 22 + 10*NEQ + (2*ML + MU)*NEQ FOR MF = 24 OR 25.
103 C LRW = DECLARED LENGTH OF RWORK (IN USER-S DIMENSION).
104 C IWORK = INTEGER WORK ARRAY OF LENGTH AT LEAST..
105 C 20 FOR MF = 10,
106 C 20 + NEQ FOR MF = 21, 22, 24, OR 25.
107 C IF MF = 24 OR 25, INPUT IN IWORK(1),IWORK(2) THE LOWER
108 C AND UPPER HALF-BANDWIDTHS ML,MU.
109 C LIW = DECLARED LENGTH OF IWORK (IN USER-S DIMENSION).
110 C JAC = NAME OF SUBROUTINE FOR JACOBIAN MATRIX (MF = 21 OR 24).
111 C IF USED, THIS NAME MUST BE DECLARED EXTERNAL IN CALLING
112 C PROGRAM. IF NOT USED, PASS A DUMMY NAME.
113 C MF = METHOD FLAG. STANDARD VALUES ARE..
114 C 10 FOR NONSTIFF (ADAMS) METHOD, NO JACOBIAN USED.
115 C 21 FOR STIFF (BDF) METHOD, USER-SUPPLIED FULL JACOBIAN.
116 C 22 FOR STIFF METHOD, INTERNALLY GENERATED FULL JACOBIAN.
117 C 24 FOR STIFF METHOD, USER-SUPPLIED BANDED JACOBIAN.
118 C 25 FOR STIFF METHOD, INTERNALLY GENERATED BANDED JACOBIAN.
119 C NOTE THAT THE MAIN PROGRAM MUST DECLARE ARRAYS Y, RWORK, IWORK,
120 C AND POSSIBLY ATOL.
121 C
122 C E. THE OUTPUT FROM THE FIRST CALL (OR ANY CALL) IS..
123 C Y = ARRAY OF COMPUTED VALUES OF Y(T) VECTOR.
124 C T = CORRESPONDING VALUE OF INDEPENDENT VARIABLE (NORMALLY TOUT).
125 C ISTATE = 2 IF LSODE WAS SUCCESSFUL, NEGATIVE OTHERWISE.
126 C -1 MEANS EXCESS WORK DONE ON THIS CALL (PERHAPS WRONG MF).
127 C -2 MEANS EXCESS ACCURACY REQUESTED (TOLERANCES TOO SMALL).
128 C -3 MEANS ILLEGAL INPUT DETECTED (SEE PRINTED MESSAGE).
129 C -4 MEANS REPEATED ERROR TEST FAILURES (CHECK ALL INPUTS).
130 C -5 MEANS REPEATED CONVERGENCE FAILURES (PERHAPS BAD JACOBIAN
131 C SUPPLIED OR WRONG CHOICE OF MF OR TOLERANCES).
132 C -6 MEANS ERROR WEIGHT BECAME ZERO DURING PROBLEM. (SOLUTION
133 C COMPONENT I VANISHED, AND ATOL OR ATOL(I) = 0.)
134 C -13 MEANS EXIT REQUESTED IN USER-SUPPLIED FUNCTION.
135 C
136 C F. TO CONTINUE THE INTEGRATION AFTER A SUCCESSFUL RETURN, SIMPLY
137 C RESET TOUT AND CALL LSODE AGAIN. NO OTHER PARAMETERS NEED BE RESET.
138 C
139 C-----------------------------------------------------------------------
140 C EXAMPLE PROBLEM.
141 C
142 C THE FOLLOWING IS A SIMPLE EXAMPLE PROBLEM, WITH THE CODING
143 C NEEDED FOR ITS SOLUTION BY LSODE. THE PROBLEM IS FROM CHEMICAL
144 C KINETICS, AND CONSISTS OF THE FOLLOWING THREE RATE EQUATIONS..
145 C DY1/DT = -.04*Y1 + 1.E4*Y2*Y3
146 C DY2/DT = .04*Y1 - 1.E4*Y2*Y3 - 3.E7*Y2**2
147 C DY3/DT = 3.E7*Y2**2
148 C ON THE INTERVAL FROM T = 0.0 TO T = 4.E10, WITH INITIAL CONDITIONS
149 C Y1 = 1.0, Y2 = Y3 = 0. THE PROBLEM IS STIFF.
150 C
151 C THE FOLLOWING CODING SOLVES THIS PROBLEM WITH LSODE, USING MF = 21
152 C AND PRINTING RESULTS AT T = .4, 4., ..., 4.E10. IT USES
153 C ITOL = 2 AND ATOL MUCH SMALLER FOR Y2 THAN Y1 OR Y3 BECAUSE
154 C Y2 HAS MUCH SMALLER VALUES.
155 C AT THE END OF THE RUN, STATISTICAL QUANTITIES OF INTEREST ARE
156 C PRINTED (SEE OPTIONAL OUTPUTS IN THE FULL DESCRIPTION BELOW).
157 C
158 C EXTERNAL FEX, JEX
159 C DOUBLE PRECISION ATOL, RTOL, RWORK, T, TOUT, Y
160 C DIMENSION Y(3), ATOL(3), RWORK(58), IWORK(23)
161 C NEQ = 3
162 C Y(1) = 1.D0
163 C Y(2) = 0.D0
164 C Y(3) = 0.D0
165 C T = 0.D0
166 C TOUT = .4D0
167 C ITOL = 2
168 C RTOL = 1.D-4
169 C ATOL(1) = 1.D-6
170 C ATOL(2) = 1.D-10
171 C ATOL(3) = 1.D-6
172 C ITASK = 1
173 C ISTATE = 1
174 C IOPT = 0
175 C LRW = 58
176 C LIW = 23
177 C MF = 21
178 C DO 40 IOUT = 1,12
179 C CALL LSODE(FEX,NEQ,Y,T,TOUT,ITOL,RTOL,ATOL,ITASK,ISTATE,
180 C 1 IOPT,RWORK,LRW,IWORK,LIW,JEX,MF)
181 C WRITE(6,20)T,Y(1),Y(2),Y(3)
182 C 20 FORMAT(7H AT T =,E12.4,6H Y =,3E14.6)
183 C IF (ISTATE .LT. 0) GO TO 80
184 C 40 TOUT = TOUT*10.D0
185 C WRITE(6,60)IWORK(11),IWORK(12),IWORK(13)
186 C 60 FORMAT(/12H NO. STEPS =,I4,11H NO. F-S =,I4,11H NO. J-S =,I4)
187 C STOP
188 C 80 WRITE(6,90)ISTATE
189 C 90 FORMAT(///22H ERROR HALT.. ISTATE =,I3)
190 C STOP
191 C END
192 C
193 C SUBROUTINE FEX (NEQ, T, Y, YDOT)
194 C DOUBLE PRECISION T, Y, YDOT
195 C DIMENSION Y(3), YDOT(3)
196 C YDOT(1) = -.04D0*Y(1) + 1.D4*Y(2)*Y(3)
197 C YDOT(3) = 3.D7*Y(2)*Y(2)
198 C YDOT(2) = -YDOT(1) - YDOT(3)
199 C RETURN
200 C END
201 C
202 C SUBROUTINE JEX (NEQ, T, Y, ML, MU, PD, NRPD)
203 C DOUBLE PRECISION PD, T, Y
204 C DIMENSION Y(3), PD(NRPD,3)
205 C PD(1,1) = -.04D0
206 C PD(1,2) = 1.D4*Y(3)
207 C PD(1,3) = 1.D4*Y(2)
208 C PD(2,1) = .04D0
209 C PD(2,3) = -PD(1,3)
210 C PD(3,2) = 6.D7*Y(2)
211 C PD(2,2) = -PD(1,2) - PD(3,2)
212 C RETURN
213 C END
214 C
215 C THE OUTPUT OF THIS PROGRAM (ON A CDC-7600 IN SINGLE PRECISION)
216 C IS AS FOLLOWS..
217 C
218 C AT T = 4.0000E-01 Y = 9.851726E-01 3.386406E-05 1.479357E-02
219 C AT T = 4.0000E+00 Y = 9.055142E-01 2.240418E-05 9.446344E-02
220 C AT T = 4.0000E+01 Y = 7.158050E-01 9.184616E-06 2.841858E-01
221 C AT T = 4.0000E+02 Y = 4.504846E-01 3.222434E-06 5.495122E-01
222 C AT T = 4.0000E+03 Y = 1.831701E-01 8.940379E-07 8.168290E-01
223 C AT T = 4.0000E+04 Y = 3.897016E-02 1.621193E-07 9.610297E-01
224 C AT T = 4.0000E+05 Y = 4.935213E-03 1.983756E-08 9.950648E-01
225 C AT T = 4.0000E+06 Y = 5.159269E-04 2.064759E-09 9.994841E-01
226 C AT T = 4.0000E+07 Y = 5.306413E-05 2.122677E-10 9.999469E-01
227 C AT T = 4.0000E+08 Y = 5.494529E-06 2.197824E-11 9.999945E-01
228 C AT T = 4.0000E+09 Y = 5.129458E-07 2.051784E-12 9.999995E-01
229 C AT T = 4.0000E+10 Y = -7.170586E-08 -2.868234E-13 1.000000E+00
230 C
231 C NO. STEPS = 330 NO. F-S = 405 NO. J-S = 69
232 C-----------------------------------------------------------------------
233 C FULL DESCRIPTION OF USER INTERFACE TO LSODE.
234 C
235 C THE USER INTERFACE TO LSODE CONSISTS OF THE FOLLOWING PARTS.
236 C
237 C I. THE CALL SEQUENCE TO SUBROUTINE LSODE, WHICH IS A DRIVER
238 C ROUTINE FOR THE SOLVER. THIS INCLUDES DESCRIPTIONS OF BOTH
239 C THE CALL SEQUENCE ARGUMENTS AND OF USER-SUPPLIED ROUTINES.
240 C FOLLOWING THESE DESCRIPTIONS IS A DESCRIPTION OF
241 C OPTIONAL INPUTS AVAILABLE THROUGH THE CALL SEQUENCE, AND THEN
242 C A DESCRIPTION OF OPTIONAL OUTPUTS (IN THE WORK ARRAYS).
243 C
244 C II. DESCRIPTIONS OF OTHER ROUTINES IN THE LSODE PACKAGE THAT MAY BE
245 C (OPTIONALLY) CALLED BY THE USER. THESE PROVIDE THE ABILITY TO
246 C ALTER ERROR MESSAGE HANDLING, SAVE AND RESTORE THE INTERNAL
247 C COMMON, AND OBTAIN SPECIFIED DERIVATIVES OF THE SOLUTION Y(T).
248 C
249 C III. DESCRIPTIONS OF COMMON BLOCKS TO BE DECLARED IN OVERLAY
250 C OR SIMILAR ENVIRONMENTS, OR TO BE SAVED WHEN DOING AN INTERRUPT
251 C OF THE PROBLEM AND CONTINUED SOLUTION LATER.
252 C
253 C IV. DESCRIPTION OF TWO ROUTINES IN THE LSODE PACKAGE, EITHER OF
254 C WHICH THE USER MAY REPLACE WITH HIS OWN VERSION, IF DESIRED.
255 C THESE RELATE TO THE MEASUREMENT OF ERRORS.
256 C
257 C-----------------------------------------------------------------------
258 C PART I. CALL SEQUENCE.
259 C
260 C THE CALL SEQUENCE PARAMETERS USED FOR INPUT ONLY ARE
261 C F, NEQ, TOUT, ITOL, RTOL, ATOL, ITASK, IOPT, LRW, LIW, JAC, MF,
262 C AND THOSE USED FOR BOTH INPUT AND OUTPUT ARE
263 C Y, T, ISTATE.
264 C THE WORK ARRAYS RWORK AND IWORK ARE ALSO USED FOR CONDITIONAL AND
265 C OPTIONAL INPUTS AND OPTIONAL OUTPUTS. (THE TERM OUTPUT HERE REFERS
266 C TO THE RETURN FROM SUBROUTINE LSODE TO THE USER-S CALLING PROGRAM.)
267 C
268 C THE LEGALITY OF INPUT PARAMETERS WILL BE THOROUGHLY CHECKED ON THE
269 C INITIAL CALL FOR THE PROBLEM, BUT NOT CHECKED THEREAFTER UNLESS A
270 C CHANGE IN INPUT PARAMETERS IS FLAGGED BY ISTATE = 3 ON INPUT.
271 C
272 C THE DESCRIPTIONS OF THE CALL ARGUMENTS ARE AS FOLLOWS.
273 C
274 C F = THE NAME OF THE USER-SUPPLIED SUBROUTINE DEFINING THE
275 C ODE SYSTEM. THE SYSTEM MUST BE PUT IN THE FIRST-ORDER
276 C FORM DY/DT = F(T,Y), WHERE F IS A VECTOR-VALUED FUNCTION
277 C OF THE SCALAR T AND THE VECTOR Y. SUBROUTINE F IS TO
278 C COMPUTE THE FUNCTION F. IT IS TO HAVE THE FORM
279 C SUBROUTINE F (NEQ, T, Y, YDOT)
280 C DIMENSION Y(1), YDOT(1)
281 C WHERE NEQ, T, AND Y ARE INPUT, AND THE ARRAY YDOT = F(T,Y)
282 C IS OUTPUT. Y AND YDOT ARE ARRAYS OF LENGTH NEQ.
283 C (IN THE DIMENSION STATEMENT ABOVE, 1 IS A DUMMY
284 C DIMENSION.. IT CAN BE REPLACED BY ANY VALUE.)
285 C SUBROUTINE F SHOULD NOT ALTER Y(1),...,Y(NEQ).
286 C F MUST BE DECLARED EXTERNAL IN THE CALLING PROGRAM.
287 C
288 C SUBROUTINE F MAY ACCESS USER-DEFINED QUANTITIES IN
289 C NEQ(2),... AND/OR IN Y(NEQ(1)+1),... IF NEQ IS AN ARRAY
290 C (DIMENSIONED IN F) AND/OR Y HAS LENGTH EXCEEDING NEQ(1).
291 C SEE THE DESCRIPTIONS OF NEQ AND Y BELOW.
292 C
293 C IF QUANTITIES COMPUTED IN THE F ROUTINE ARE NEEDED
294 C EXTERNALLY TO LSODE, AN EXTRA CALL TO F SHOULD BE MADE
295 C FOR THIS PURPOSE, FOR CONSISTENT AND ACCURATE RESULTS.
296 C IF ONLY THE DERIVATIVE DY/DT IS NEEDED, USE INTDY INSTEAD.
297 C
298 C NEQ = THE SIZE OF THE ODE SYSTEM (NUMBER OF FIRST ORDER
299 C ORDINARY DIFFERENTIAL EQUATIONS). USED ONLY FOR INPUT.
300 C NEQ MAY BE DECREASED, BUT NOT INCREASED, DURING THE PROBLEM.
301 C IF NEQ IS DECREASED (WITH ISTATE = 3 ON INPUT), THE
302 C REMAINING COMPONENTS OF Y SHOULD BE LEFT UNDISTURBED, IF
303 C THESE ARE TO BE ACCESSED IN F AND/OR JAC.
304 C
305 C NORMALLY, NEQ IS A SCALAR, AND IT IS GENERALLY REFERRED TO
306 C AS A SCALAR IN THIS USER INTERFACE DESCRIPTION. HOWEVER,
307 C NEQ MAY BE AN ARRAY, WITH NEQ(1) SET TO THE SYSTEM SIZE.
308 C (THE LSODE PACKAGE ACCESSES ONLY NEQ(1).) IN EITHER CASE,
309 C THIS PARAMETER IS PASSED AS THE NEQ ARGUMENT IN ALL CALLS
310 C TO F AND JAC. HENCE, IF IT IS AN ARRAY, LOCATIONS
311 C NEQ(2),... MAY BE USED TO STORE OTHER INTEGER DATA AND PASS
312 C IT TO F AND/OR JAC. SUBROUTINES F AND/OR JAC MUST INCLUDE
313 C NEQ IN A DIMENSION STATEMENT IN THAT CASE.
314 C
315 C Y = A REAL ARRAY FOR THE VECTOR OF DEPENDENT VARIABLES, OF
316 C LENGTH NEQ OR MORE. USED FOR BOTH INPUT AND OUTPUT ON THE
317 C FIRST CALL (ISTATE = 1), AND ONLY FOR OUTPUT ON OTHER CALLS.
318 C ON THE FIRST CALL, Y MUST CONTAIN THE VECTOR OF INITIAL
319 C VALUES. ON OUTPUT, Y CONTAINS THE COMPUTED SOLUTION VECTOR,
320 C EVALUATED AT T. IF DESIRED, THE Y ARRAY MAY BE USED
321 C FOR OTHER PURPOSES BETWEEN CALLS TO THE SOLVER.
322 C
323 C THIS ARRAY IS PASSED AS THE Y ARGUMENT IN ALL CALLS TO
324 C F AND JAC. HENCE ITS LENGTH MAY EXCEED NEQ, AND LOCATIONS
325 C Y(NEQ+1),... MAY BE USED TO STORE OTHER REAL DATA AND
326 C PASS IT TO F AND/OR JAC. (THE LSODE PACKAGE ACCESSES ONLY
327 C Y(1),...,Y(NEQ).)
328 C
329 C T = THE INDEPENDENT VARIABLE. ON INPUT, T IS USED ONLY ON THE
330 C FIRST CALL, AS THE INITIAL POINT OF THE INTEGRATION.
331 C ON OUTPUT, AFTER EACH CALL, T IS THE VALUE AT WHICH A
332 C COMPUTED SOLUTION Y IS EVALUATED (USUALLY THE SAME AS TOUT).
333 C ON AN ERROR RETURN, T IS THE FARTHEST POINT REACHED.
334 C
335 C TOUT = THE NEXT VALUE OF T AT WHICH A COMPUTED SOLUTION IS DESIRED.
336 C USED ONLY FOR INPUT.
337 C
338 C WHEN STARTING THE PROBLEM (ISTATE = 1), TOUT MAY BE EQUAL
339 C TO T FOR ONE CALL, THEN SHOULD .NE. T FOR THE NEXT CALL.
340 C FOR THE INITIAL T, AN INPUT VALUE OF TOUT .NE. T IS USED
341 C IN ORDER TO DETERMINE THE DIRECTION OF THE INTEGRATION
342 C (I.E. THE ALGEBRAIC SIGN OF THE STEP SIZES) AND THE ROUGH
343 C SCALE OF THE PROBLEM. INTEGRATION IN EITHER DIRECTION
344 C (FORWARD OR BACKWARD IN T) IS PERMITTED.
345 C
346 C IF ITASK = 2 OR 5 (ONE-STEP MODES), TOUT IS IGNORED AFTER
347 C THE FIRST CALL (I.E. THE FIRST CALL WITH TOUT .NE. T).
348 C OTHERWISE, TOUT IS REQUIRED ON EVERY CALL.
349 C
350 C IF ITASK = 1, 3, OR 4, THE VALUES OF TOUT NEED NOT BE
351 C MONOTONE, BUT A VALUE OF TOUT WHICH BACKS UP IS LIMITED
352 C TO THE CURRENT INTERNAL T INTERVAL, WHOSE ENDPOINTS ARE
353 C TCUR - HU AND TCUR (SEE OPTIONAL OUTPUTS, BELOW, FOR
354 C TCUR AND HU).
355 C
356 C ITOL = AN INDICATOR FOR THE TYPE OF ERROR CONTROL. SEE
357 C DESCRIPTION BELOW UNDER ATOL. USED ONLY FOR INPUT.
358 C
359 C RTOL = A RELATIVE ERROR TOLERANCE PARAMETER, EITHER A SCALAR OR
360 C AN ARRAY OF LENGTH NEQ. SEE DESCRIPTION BELOW UNDER ATOL.
361 C INPUT ONLY.
362 C
363 C ATOL = AN ABSOLUTE ERROR TOLERANCE PARAMETER, EITHER A SCALAR OR
364 C AN ARRAY OF LENGTH NEQ. INPUT ONLY.
365 C
366 C THE INPUT PARAMETERS ITOL, RTOL, AND ATOL DETERMINE
367 C THE ERROR CONTROL PERFORMED BY THE SOLVER. THE SOLVER WILL
368 C CONTROL THE VECTOR E = (E(I)) OF ESTIMATED LOCAL ERRORS
369 C IN Y, ACCORDING TO AN INEQUALITY OF THE FORM
370 C RMS-NORM OF ( E(I)/EWT(I) ) .LE. 1,
371 C WHERE EWT(I) = RTOL(I)*ABS(Y(I)) + ATOL(I),
372 C AND THE RMS-NORM (ROOT-MEAN-SQUARE NORM) HERE IS
373 C RMS-NORM(V) = SQRT(SUM V(I)**2 / NEQ). HERE EWT = (EWT(I))
374 C IS A VECTOR OF WEIGHTS WHICH MUST ALWAYS BE POSITIVE, AND
375 C THE VALUES OF RTOL AND ATOL SHOULD ALL BE NON-NEGATIVE.
376 C THE FOLLOWING TABLE GIVES THE TYPES (SCALAR/ARRAY) OF
377 C RTOL AND ATOL, AND THE CORRESPONDING FORM OF EWT(I).
378 C
379 C ITOL RTOL ATOL EWT(I)
380 C 1 SCALAR SCALAR RTOL*ABS(Y(I)) + ATOL
381 C 2 SCALAR ARRAY RTOL*ABS(Y(I)) + ATOL(I)
382 C 3 ARRAY SCALAR RTOL(I)*ABS(Y(I)) + ATOL
383 C 4 ARRAY ARRAY RTOL(I)*ABS(Y(I)) + ATOL(I)
384 C
385 C WHEN EITHER OF THESE PARAMETERS IS A SCALAR, IT NEED NOT
386 C BE DIMENSIONED IN THE USER-S CALLING PROGRAM.
387 C
388 C IF NONE OF THE ABOVE CHOICES (WITH ITOL, RTOL, AND ATOL
389 C FIXED THROUGHOUT THE PROBLEM) IS SUITABLE, MORE GENERAL
390 C ERROR CONTROLS CAN BE OBTAINED BY SUBSTITUTING
391 C USER-SUPPLIED ROUTINES FOR THE SETTING OF EWT AND/OR FOR
392 C THE NORM CALCULATION. SEE PART IV BELOW.
393 C
394 C IF GLOBAL ERRORS ARE TO BE ESTIMATED BY MAKING A REPEATED
395 C RUN ON THE SAME PROBLEM WITH SMALLER TOLERANCES, THEN ALL
396 C COMPONENTS OF RTOL AND ATOL (I.E. OF EWT) SHOULD BE SCALED
397 C DOWN UNIFORMLY.
398 C
399 C ITASK = AN INDEX SPECIFYING THE TASK TO BE PERFORMED.
400 C INPUT ONLY. ITASK HAS THE FOLLOWING VALUES AND MEANINGS.
401 C 1 MEANS NORMAL COMPUTATION OF OUTPUT VALUES OF Y(T) AT
402 C T = TOUT (BY OVERSHOOTING AND INTERPOLATING).
403 C 2 MEANS TAKE ONE STEP ONLY AND RETURN.
404 C 3 MEANS STOP AT THE FIRST INTERNAL MESH POINT AT OR
405 C BEYOND T = TOUT AND RETURN.
406 C 4 MEANS NORMAL COMPUTATION OF OUTPUT VALUES OF Y(T) AT
407 C T = TOUT BUT WITHOUT OVERSHOOTING T = TCRIT.
408 C TCRIT MUST BE INPUT AS RWORK(1). TCRIT MAY BE EQUAL TO
409 C OR BEYOND TOUT, BUT NOT BEHIND IT IN THE DIRECTION OF
410 C INTEGRATION. THIS OPTION IS USEFUL IF THE PROBLEM
411 C HAS A SINGULARITY AT OR BEYOND T = TCRIT.
412 C 5 MEANS TAKE ONE STEP, WITHOUT PASSING TCRIT, AND RETURN.
413 C TCRIT MUST BE INPUT AS RWORK(1).
414 C
415 C NOTE.. IF ITASK = 4 OR 5 AND THE SOLVER REACHES TCRIT
416 C (WITHIN ROUNDOFF), IT WILL RETURN T = TCRIT (EXACTLY) TO
417 C INDICATE THIS (UNLESS ITASK = 4 AND TOUT COMES BEFORE TCRIT,
418 C IN WHICH CASE ANSWERS AT T = TOUT ARE RETURNED FIRST).
419 C
420 C ISTATE = AN INDEX USED FOR INPUT AND OUTPUT TO SPECIFY THE
421 C THE STATE OF THE CALCULATION.
422 C
423 C ON INPUT, THE VALUES OF ISTATE ARE AS FOLLOWS.
424 C 1 MEANS THIS IS THE FIRST CALL FOR THE PROBLEM
425 C (INITIALIZATIONS WILL BE DONE). SEE NOTE BELOW.
426 C 2 MEANS THIS IS NOT THE FIRST CALL, AND THE CALCULATION
427 C IS TO CONTINUE NORMALLY, WITH NO CHANGE IN ANY INPUT
428 C PARAMETERS EXCEPT POSSIBLY TOUT AND ITASK.
429 C (IF ITOL, RTOL, AND/OR ATOL ARE CHANGED BETWEEN CALLS
430 C WITH ISTATE = 2, THE NEW VALUES WILL BE USED BUT NOT
431 C TESTED FOR LEGALITY.)
432 C 3 MEANS THIS IS NOT THE FIRST CALL, AND THE
433 C CALCULATION IS TO CONTINUE NORMALLY, BUT WITH
434 C A CHANGE IN INPUT PARAMETERS OTHER THAN
435 C TOUT AND ITASK. CHANGES ARE ALLOWED IN
436 C NEQ, ITOL, RTOL, ATOL, IOPT, LRW, LIW, MF, ML, MU,
437 C AND ANY OF THE OPTIONAL INPUTS EXCEPT H0.
438 C (SEE IWORK DESCRIPTION FOR ML AND MU.)
439 C NOTE.. A PRELIMINARY CALL WITH TOUT = T IS NOT COUNTED
440 C AS A FIRST CALL HERE, AS NO INITIALIZATION OR CHECKING OF
441 C INPUT IS DONE. (SUCH A CALL IS SOMETIMES USEFUL FOR THE
442 C PURPOSE OF OUTPUTTING THE INITIAL CONDITIONS.)
443 C THUS THE FIRST CALL FOR WHICH TOUT .NE. T REQUIRES
444 C ISTATE = 1 ON INPUT.
445 C
446 C ON OUTPUT, ISTATE HAS THE FOLLOWING VALUES AND MEANINGS.
447 C 1 MEANS NOTHING WAS DONE, AS TOUT WAS EQUAL TO T WITH
448 C ISTATE = 1 ON INPUT. (HOWEVER, AN INTERNAL COUNTER WAS
449 C SET TO DETECT AND PREVENT REPEATED CALLS OF THIS TYPE.)
450 C 2 MEANS THE INTEGRATION WAS PERFORMED SUCCESSFULLY.
451 C -1 MEANS AN EXCESSIVE AMOUNT OF WORK (MORE THAN MXSTEP
452 C STEPS) WAS DONE ON THIS CALL, BEFORE COMPLETING THE
453 C REQUESTED TASK, BUT THE INTEGRATION WAS OTHERWISE
454 C SUCCESSFUL AS FAR AS T. (MXSTEP IS AN OPTIONAL INPUT
455 C AND IS NORMALLY 500.) TO CONTINUE, THE USER MAY
456 C SIMPLY RESET ISTATE TO A VALUE .GT. 1 AND CALL AGAIN
457 C (THE EXCESS WORK STEP COUNTER WILL BE RESET TO 0).
458 C IN ADDITION, THE USER MAY INCREASE MXSTEP TO AVOID
459 C THIS ERROR RETURN (SEE BELOW ON OPTIONAL INPUTS).
460 C -2 MEANS TOO MUCH ACCURACY WAS REQUESTED FOR THE PRECISION
461 C OF THE MACHINE BEING USED. THIS WAS DETECTED BEFORE
462 C COMPLETING THE REQUESTED TASK, BUT THE INTEGRATION
463 C WAS SUCCESSFUL AS FAR AS T. TO CONTINUE, THE TOLERANCE
464 C PARAMETERS MUST BE RESET, AND ISTATE MUST BE SET
465 C TO 3. THE OPTIONAL OUTPUT TOLSF MAY BE USED FOR THIS
466 C PURPOSE. (NOTE.. IF THIS CONDITION IS DETECTED BEFORE
467 C TAKING ANY STEPS, THEN AN ILLEGAL INPUT RETURN
468 C (ISTATE = -3) OCCURS INSTEAD.)
469 C -3 MEANS ILLEGAL INPUT WAS DETECTED, BEFORE TAKING ANY
470 C INTEGRATION STEPS. SEE WRITTEN MESSAGE FOR DETAILS.
471 C NOTE.. IF THE SOLVER DETECTS AN INFINITE LOOP OF CALLS
472 C TO THE SOLVER WITH ILLEGAL INPUT, IT WILL CAUSE
473 C THE RUN TO STOP.
474 C -4 MEANS THERE WERE REPEATED ERROR TEST FAILURES ON
475 C ONE ATTEMPTED STEP, BEFORE COMPLETING THE REQUESTED
476 C TASK, BUT THE INTEGRATION WAS SUCCESSFUL AS FAR AS T.
477 C THE PROBLEM MAY HAVE A SINGULARITY, OR THE INPUT
478 C MAY BE INAPPROPRIATE.
479 C -5 MEANS THERE WERE REPEATED CONVERGENCE TEST FAILURES ON
480 C ONE ATTEMPTED STEP, BEFORE COMPLETING THE REQUESTED
481 C TASK, BUT THE INTEGRATION WAS SUCCESSFUL AS FAR AS T.
482 C THIS MAY BE CAUSED BY AN INACCURATE JACOBIAN MATRIX,
483 C IF ONE IS BEING USED.
484 C -6 MEANS EWT(I) BECAME ZERO FOR SOME I DURING THE
485 C INTEGRATION. PURE RELATIVE ERROR CONTROL (ATOL(I)=0.0)
486 C WAS REQUESTED ON A VARIABLE WHICH HAS NOW VANISHED.
487 C THE INTEGRATION WAS SUCCESSFUL AS FAR AS T.
488 C
489 C NOTE.. SINCE THE NORMAL OUTPUT VALUE OF ISTATE IS 2,
490 C IT DOES NOT NEED TO BE RESET FOR NORMAL CONTINUATION.
491 C ALSO, SINCE A NEGATIVE INPUT VALUE OF ISTATE WILL BE
492 C REGARDED AS ILLEGAL, A NEGATIVE OUTPUT VALUE REQUIRES THE
493 C USER TO CHANGE IT, AND POSSIBLY OTHER INPUTS, BEFORE
494 C CALLING THE SOLVER AGAIN.
495 C
496 C IOPT = AN INTEGER FLAG TO SPECIFY WHETHER OR NOT ANY OPTIONAL
497 C INPUTS ARE BEING USED ON THIS CALL. INPUT ONLY.
498 C THE OPTIONAL INPUTS ARE LISTED SEPARATELY BELOW.
499 C IOPT = 0 MEANS NO OPTIONAL INPUTS ARE BEING USED.
500 C DEFAULT VALUES WILL BE USED IN ALL CASES.
501 C IOPT = 1 MEANS ONE OR MORE OPTIONAL INPUTS ARE BEING USED.
502 C
503 C RWORK = A REAL WORKING ARRAY (DOUBLE PRECISION).
504 C THE LENGTH OF RWORK MUST BE AT LEAST
505 C 20 + NYH*(MAXORD + 1) + 3*NEQ + LWM WHERE
506 C NYH = THE INITIAL VALUE OF NEQ,
507 C MAXORD = 12 (IF METH = 1) OR 5 (IF METH = 2) (UNLESS A
508 C SMALLER VALUE IS GIVEN AS AN OPTIONAL INPUT),
509 C LWM = 0 IF MITER = 0,
510 C LWM = NEQ**2 + 2 IF MITER IS 1 OR 2,
511 C LWM = NEQ + 2 IF MITER = 3, AND
512 C LWM = (2*ML+MU+1)*NEQ + 2 IF MITER IS 4 OR 5.
513 C (SEE THE MF DESCRIPTION FOR METH AND MITER.)
514 C THUS IF MAXORD HAS ITS DEFAULT VALUE AND NEQ IS CONSTANT,
515 C THIS LENGTH IS..
516 C 20 + 16*NEQ FOR MF = 10,
517 C 22 + 16*NEQ + NEQ**2 FOR MF = 11 OR 12,
518 C 22 + 17*NEQ FOR MF = 13,
519 C 22 + 17*NEQ + (2*ML+MU)*NEQ FOR MF = 14 OR 15,
520 C 20 + 9*NEQ FOR MF = 20,
521 C 22 + 9*NEQ + NEQ**2 FOR MF = 21 OR 22,
522 C 22 + 10*NEQ FOR MF = 23,
523 C 22 + 10*NEQ + (2*ML+MU)*NEQ FOR MF = 24 OR 25.
524 C THE FIRST 20 WORDS OF RWORK ARE RESERVED FOR CONDITIONAL
525 C AND OPTIONAL INPUTS AND OPTIONAL OUTPUTS.
526 C
527 C THE FOLLOWING WORD IN RWORK IS A CONDITIONAL INPUT..
528 C RWORK(1) = TCRIT = CRITICAL VALUE OF T WHICH THE SOLVER
529 C IS NOT TO OVERSHOOT. REQUIRED IF ITASK IS
530 C 4 OR 5, AND IGNORED OTHERWISE. (SEE ITASK.)
531 C
532 C LRW = THE LENGTH OF THE ARRAY RWORK, AS DECLARED BY THE USER.
533 C (THIS WILL BE CHECKED BY THE SOLVER.)
534 C
535 C IWORK = AN INTEGER WORK ARRAY. THE LENGTH OF IWORK MUST BE AT LEAST
536 C 20 IF MITER = 0 OR 3 (MF = 10, 13, 20, 23), OR
537 C 20 + NEQ OTHERWISE (MF = 11, 12, 14, 15, 21, 22, 24, 25).
538 C THE FIRST FEW WORDS OF IWORK ARE USED FOR CONDITIONAL AND
539 C OPTIONAL INPUTS AND OPTIONAL OUTPUTS.
540 C
541 C THE FOLLOWING 2 WORDS IN IWORK ARE CONDITIONAL INPUTS..
542 C IWORK(1) = ML THESE ARE THE LOWER AND UPPER
543 C IWORK(2) = MU HALF-BANDWIDTHS, RESPECTIVELY, OF THE
544 C BANDED JACOBIAN, EXCLUDING THE MAIN DIAGONAL.
545 C THE BAND IS DEFINED BY THE MATRIX LOCATIONS
546 C (I,J) WITH I-ML .LE. J .LE. I+MU. ML AND MU
547 C MUST SATISFY 0 .LE. ML,MU .LE. NEQ-1.
548 C THESE ARE REQUIRED IF MITER IS 4 OR 5, AND
549 C IGNORED OTHERWISE. ML AND MU MAY IN FACT BE
550 C THE BAND PARAMETERS FOR A MATRIX TO WHICH
551 C DF/DY IS ONLY APPROXIMATELY EQUAL.
552 C
553 C LIW = THE LENGTH OF THE ARRAY IWORK, AS DECLARED BY THE USER.
554 C (THIS WILL BE CHECKED BY THE SOLVER.)
555 C
556 C NOTE.. THE WORK ARRAYS MUST NOT BE ALTERED BETWEEN CALLS TO LSODE
557 C FOR THE SAME PROBLEM, EXCEPT POSSIBLY FOR THE CONDITIONAL AND
558 C OPTIONAL INPUTS, AND EXCEPT FOR THE LAST 3*NEQ WORDS OF RWORK.
559 C THE LATTER SPACE IS USED FOR INTERNAL SCRATCH SPACE, AND SO IS
560 C AVAILABLE FOR USE BY THE USER OUTSIDE LSODE BETWEEN CALLS, IF
561 C DESIRED (BUT NOT FOR USE BY F OR JAC).
562 C
563 C JAC = THE NAME OF THE USER-SUPPLIED ROUTINE (MITER = 1 OR 4) TO
564 C COMPUTE THE JACOBIAN MATRIX, DF/DY, AS A FUNCTION OF
565 C THE SCALAR T AND THE VECTOR Y. IT IS TO HAVE THE FORM
566 C SUBROUTINE JAC (NEQ, T, Y, ML, MU, PD, NROWPD)
567 C DIMENSION Y(1), PD(NROWPD,1)
568 C WHERE NEQ, T, Y, ML, MU, AND NROWPD ARE INPUT AND THE ARRAY
569 C PD IS TO BE LOADED WITH PARTIAL DERIVATIVES (ELEMENTS OF
570 C THE JACOBIAN MATRIX) ON OUTPUT. PD MUST BE GIVEN A FIRST
571 C DIMENSION OF NROWPD. T AND Y HAVE THE SAME MEANING AS IN
572 C SUBROUTINE F. (IN THE DIMENSION STATEMENT ABOVE, 1 IS A
573 C DUMMY DIMENSION.. IT CAN BE REPLACED BY ANY VALUE.)
574 C IN THE FULL MATRIX CASE (MITER = 1), ML AND MU ARE
575 C IGNORED, AND THE JACOBIAN IS TO BE LOADED INTO PD IN
576 C COLUMNWISE MANNER, WITH DF(I)/DY(J) LOADED INTO PD(I,J).
577 C IN THE BAND MATRIX CASE (MITER = 4), THE ELEMENTS
578 C WITHIN THE BAND ARE TO BE LOADED INTO PD IN COLUMNWISE
579 C MANNER, WITH DIAGONAL LINES OF DF/DY LOADED INTO THE ROWS
580 C OF PD. THUS DF(I)/DY(J) IS TO BE LOADED INTO PD(I-J+MU+1,J).
581 C ML AND MU ARE THE HALF-BANDWIDTH PARAMETERS (SEE IWORK).
582 C THE LOCATIONS IN PD IN THE TWO TRIANGULAR AREAS WHICH
583 C CORRESPOND TO NONEXISTENT MATRIX ELEMENTS CAN BE IGNORED
584 C OR LOADED ARBITRARILY, AS THEY ARE OVERWRITTEN BY LSODE.
585 C JAC NEED NOT PROVIDE DF/DY EXACTLY. A CRUDE
586 C APPROXIMATION (POSSIBLY WITH A SMALLER BANDWIDTH) WILL DO.
587 C IN EITHER CASE, PD IS PRESET TO ZERO BY THE SOLVER,
588 C SO THAT ONLY THE NONZERO ELEMENTS NEED BE LOADED BY JAC.
589 C EACH CALL TO JAC IS PRECEDED BY A CALL TO F WITH THE SAME
590 C ARGUMENTS NEQ, T, AND Y. THUS TO GAIN SOME EFFICIENCY,
591 C INTERMEDIATE QUANTITIES SHARED BY BOTH CALCULATIONS MAY BE
592 C SAVED IN A USER COMMON BLOCK BY F AND NOT RECOMPUTED BY JAC,
593 C IF DESIRED. ALSO, JAC MAY ALTER THE Y ARRAY, IF DESIRED.
594 C JAC MUST BE DECLARED EXTERNAL IN THE CALLING PROGRAM.
595 C SUBROUTINE JAC MAY ACCESS USER-DEFINED QUANTITIES IN
596 C NEQ(2),... AND/OR IN Y(NEQ(1)+1),... IF NEQ IS AN ARRAY
597 C (DIMENSIONED IN JAC) AND/OR Y HAS LENGTH EXCEEDING NEQ(1).
598 C SEE THE DESCRIPTIONS OF NEQ AND Y ABOVE.
599 C
600 C MF = THE METHOD FLAG. USED ONLY FOR INPUT. THE LEGAL VALUES OF
601 C MF ARE 10, 11, 12, 13, 14, 15, 20, 21, 22, 23, 24, AND 25.
602 C MF HAS DECIMAL DIGITS METH AND MITER.. MF = 10*METH + MITER.
603 C METH INDICATES THE BASIC LINEAR MULTISTEP METHOD..
604 C METH = 1 MEANS THE IMPLICIT ADAMS METHOD.
605 C METH = 2 MEANS THE METHOD BASED ON BACKWARD
606 C DIFFERENTIATION FORMULAS (BDF-S).
607 C MITER INDICATES THE CORRECTOR ITERATION METHOD..
608 C MITER = 0 MEANS FUNCTIONAL ITERATION (NO JACOBIAN MATRIX
609 C IS INVOLVED).
610 C MITER = 1 MEANS CHORD ITERATION WITH A USER-SUPPLIED
611 C FULL (NEQ BY NEQ) JACOBIAN.
612 C MITER = 2 MEANS CHORD ITERATION WITH AN INTERNALLY
613 C GENERATED (DIFFERENCE QUOTIENT) FULL JACOBIAN
614 C (USING NEQ EXTRA CALLS TO F PER DF/DY VALUE).
615 C MITER = 3 MEANS CHORD ITERATION WITH AN INTERNALLY
616 C GENERATED DIAGONAL JACOBIAN APPROXIMATION.
617 C (USING 1 EXTRA CALL TO F PER DF/DY EVALUATION).
618 C MITER = 4 MEANS CHORD ITERATION WITH A USER-SUPPLIED
619 C BANDED JACOBIAN.
620 C MITER = 5 MEANS CHORD ITERATION WITH AN INTERNALLY
621 C GENERATED BANDED JACOBIAN (USING ML+MU+1 EXTRA
622 C CALLS TO F PER DF/DY EVALUATION).
623 C IF MITER = 1 OR 4, THE USER MUST SUPPLY A SUBROUTINE JAC
624 C (THE NAME IS ARBITRARY) AS DESCRIBED ABOVE UNDER JAC.
625 C FOR OTHER VALUES OF MITER, A DUMMY ARGUMENT CAN BE USED.
626 C-----------------------------------------------------------------------
627 C OPTIONAL INPUTS.
628 C
629 C THE FOLLOWING IS A LIST OF THE OPTIONAL INPUTS PROVIDED FOR IN THE
630 C CALL SEQUENCE. (SEE ALSO PART II.) FOR EACH SUCH INPUT VARIABLE,
631 C THIS TABLE LISTS ITS NAME AS USED IN THIS DOCUMENTATION, ITS
632 C LOCATION IN THE CALL SEQUENCE, ITS MEANING, AND THE DEFAULT VALUE.
633 C THE USE OF ANY OF THESE INPUTS REQUIRES IOPT = 1, AND IN THAT
634 C CASE ALL OF THESE INPUTS ARE EXAMINED. A VALUE OF ZERO FOR ANY
635 C OF THESE OPTIONAL INPUTS WILL CAUSE THE DEFAULT VALUE TO BE USED.
636 C THUS TO USE A SUBSET OF THE OPTIONAL INPUTS, SIMPLY PRELOAD
637 C LOCATIONS 5 TO 10 IN RWORK AND IWORK TO 0.0 AND 0 RESPECTIVELY, AND
638 C THEN SET THOSE OF INTEREST TO NONZERO VALUES.
639 C
640 C NAME LOCATION MEANING AND DEFAULT VALUE
641 C
642 C H0 RWORK(5) THE STEP SIZE TO BE ATTEMPTED ON THE FIRST STEP.
643 C THE DEFAULT VALUE IS DETERMINED BY THE SOLVER.
644 C
645 C HMAX RWORK(6) THE MAXIMUM ABSOLUTE STEP SIZE ALLOWED.
646 C THE DEFAULT VALUE IS INFINITE.
647 C
648 C HMIN RWORK(7) THE MINIMUM ABSOLUTE STEP SIZE ALLOWED.
649 C THE DEFAULT VALUE IS 0. (THIS LOWER BOUND IS NOT
650 C ENFORCED ON THE FINAL STEP BEFORE REACHING TCRIT
651 C WHEN ITASK = 4 OR 5.)
652 C
653 C MAXORD IWORK(5) THE MAXIMUM ORDER TO BE ALLOWED. THE DEFAULT
654 C VALUE IS 12 IF METH = 1, AND 5 IF METH = 2.
655 C IF MAXORD EXCEEDS THE DEFAULT VALUE, IT WILL
656 C BE REDUCED TO THE DEFAULT VALUE.
657 C IF MAXORD IS CHANGED DURING THE PROBLEM, IT MAY
658 C CAUSE THE CURRENT ORDER TO BE REDUCED.
659 C
660 C MXSTEP IWORK(6) MAXIMUM NUMBER OF (INTERNALLY DEFINED) STEPS
661 C ALLOWED DURING ONE CALL TO THE SOLVER.
662 C THE DEFAULT VALUE IS 500.
663 C
664 C MXHNIL IWORK(7) MAXIMUM NUMBER OF MESSAGES PRINTED (PER PROBLEM)
665 C WARNING THAT T + H = T ON A STEP (H = STEP SIZE).
666 C THIS MUST BE POSITIVE TO RESULT IN A NON-DEFAULT
667 C VALUE. THE DEFAULT VALUE IS 10.
668 C-----------------------------------------------------------------------
669 C OPTIONAL OUTPUTS.
670 C
671 C AS OPTIONAL ADDITIONAL OUTPUT FROM LSODE, THE VARIABLES LISTED
672 C BELOW ARE QUANTITIES RELATED TO THE PERFORMANCE OF LSODE
673 C WHICH ARE AVAILABLE TO THE USER. THESE ARE COMMUNICATED BY WAY OF
674 C THE WORK ARRAYS, BUT ALSO HAVE INTERNAL MNEMONIC NAMES AS SHOWN.
675 C EXCEPT WHERE STATED OTHERWISE, ALL OF THESE OUTPUTS ARE DEFINED
676 C ON ANY SUCCESSFUL RETURN FROM LSODE, AND ON ANY RETURN WITH
677 C ISTATE = -1, -2, -4, -5, OR -6. ON AN ILLEGAL INPUT RETURN
678 C (ISTATE = -3), THEY WILL BE UNCHANGED FROM THEIR EXISTING VALUES
679 C (IF ANY), EXCEPT POSSIBLY FOR TOLSF, LENRW, AND LENIW.
680 C ON ANY ERROR RETURN, OUTPUTS RELEVANT TO THE ERROR WILL BE DEFINED,
681 C AS NOTED BELOW.
682 C
683 C NAME LOCATION MEANING
684 C
685 C HU RWORK(11) THE STEP SIZE IN T LAST USED (SUCCESSFULLY).
686 C
687 C HCUR RWORK(12) THE STEP SIZE TO BE ATTEMPTED ON THE NEXT STEP.
688 C
689 C TCUR RWORK(13) THE CURRENT VALUE OF THE INDEPENDENT VARIABLE
690 C WHICH THE SOLVER HAS ACTUALLY REACHED, I.E. THE
691 C CURRENT INTERNAL MESH POINT IN T. ON OUTPUT, TCUR
692 C WILL ALWAYS BE AT LEAST AS FAR AS THE ARGUMENT
693 C T, BUT MAY BE FARTHER (IF INTERPOLATION WAS DONE).
694 C
695 C TOLSF RWORK(14) A TOLERANCE SCALE FACTOR, GREATER THAN 1.0,
696 C COMPUTED WHEN A REQUEST FOR TOO MUCH ACCURACY WAS
697 C DETECTED (ISTATE = -3 IF DETECTED AT THE START OF
698 C THE PROBLEM, ISTATE = -2 OTHERWISE). IF ITOL IS
699 C LEFT UNALTERED BUT RTOL AND ATOL ARE UNIFORMLY
700 C SCALED UP BY A FACTOR OF TOLSF FOR THE NEXT CALL,
701 C THEN THE SOLVER IS DEEMED LIKELY TO SUCCEED.
702 C (THE USER MAY ALSO IGNORE TOLSF AND ALTER THE
703 C TOLERANCE PARAMETERS IN ANY OTHER WAY APPROPRIATE.)
704 C
705 C NST IWORK(11) THE NUMBER OF STEPS TAKEN FOR THE PROBLEM SO FAR.
706 C
707 C NFE IWORK(12) THE NUMBER OF F EVALUATIONS FOR THE PROBLEM SO FAR.
708 C
709 C NJE IWORK(13) THE NUMBER OF JACOBIAN EVALUATIONS (AND OF MATRIX
710 C LU DECOMPOSITIONS) FOR THE PROBLEM SO FAR.
711 C
712 C NQU IWORK(14) THE METHOD ORDER LAST USED (SUCCESSFULLY).
713 C
714 C NQCUR IWORK(15) THE ORDER TO BE ATTEMPTED ON THE NEXT STEP.
715 C
716 C IMXER IWORK(16) THE INDEX OF THE COMPONENT OF LARGEST MAGNITUDE IN
717 C THE WEIGHTED LOCAL ERROR VECTOR ( E(I)/EWT(I) ),
718 C ON AN ERROR RETURN WITH ISTATE = -4 OR -5.
719 C
720 C LENRW IWORK(17) THE LENGTH OF RWORK ACTUALLY REQUIRED.
721 C THIS IS DEFINED ON NORMAL RETURNS AND ON AN ILLEGAL
722 C INPUT RETURN FOR INSUFFICIENT STORAGE.
723 C
724 C LENIW IWORK(18) THE LENGTH OF IWORK ACTUALLY REQUIRED.
725 C THIS IS DEFINED ON NORMAL RETURNS AND ON AN ILLEGAL
726 C INPUT RETURN FOR INSUFFICIENT STORAGE.
727 C
728 C THE FOLLOWING TWO ARRAYS ARE SEGMENTS OF THE RWORK ARRAY WHICH
729 C MAY ALSO BE OF INTEREST TO THE USER AS OPTIONAL OUTPUTS.
730 C FOR EACH ARRAY, THE TABLE BELOW GIVES ITS INTERNAL NAME,
731 C ITS BASE ADDRESS IN RWORK, AND ITS DESCRIPTION.
732 C
733 C NAME BASE ADDRESS DESCRIPTION
734 C
735 C YH 21 THE NORDSIECK HISTORY ARRAY, OF SIZE NYH BY
736 C (NQCUR + 1), WHERE NYH IS THE INITIAL VALUE
737 C OF NEQ. FOR J = 0,1,...,NQCUR, COLUMN J+1
738 C OF YH CONTAINS HCUR**J/FACTORIAL(J) TIMES
739 C THE J-TH DERIVATIVE OF THE INTERPOLATING
740 C POLYNOMIAL CURRENTLY REPRESENTING THE SOLUTION,
741 C EVALUATED AT T = TCUR.
742 C
743 C ACOR LENRW-NEQ+1 ARRAY OF SIZE NEQ USED FOR THE ACCUMULATED
744 C CORRECTIONS ON EACH STEP, SCALED ON OUTPUT
745 C TO REPRESENT THE ESTIMATED LOCAL ERROR IN Y
746 C ON THE LAST STEP. THIS IS THE VECTOR E IN
747 C THE DESCRIPTION OF THE ERROR CONTROL. IT IS
748 C DEFINED ONLY ON A SUCCESSFUL RETURN FROM LSODE.
749 C
750 C-----------------------------------------------------------------------
751 C PART II. OTHER ROUTINES CALLABLE.
752 C
753 C THE FOLLOWING ARE OPTIONAL CALLS WHICH THE USER MAY MAKE TO
754 C GAIN ADDITIONAL CAPABILITIES IN CONJUNCTION WITH LSODE.
755 C (THE ROUTINES XSETUN AND XSETF ARE DESIGNED TO CONFORM TO THE
756 C SLATEC ERROR HANDLING PACKAGE.)
757 C
758 C FORM OF CALL FUNCTION
759 C CALL XSETUN(LUN) SET THE LOGICAL UNIT NUMBER, LUN, FOR
760 C OUTPUT OF MESSAGES FROM LSODE, IF
761 C THE DEFAULT IS NOT DESIRED.
762 C THE DEFAULT VALUE OF LUN IS 6.
763 C
764 C CALL XSETF(MFLAG) SET A FLAG TO CONTROL THE PRINTING OF
765 C MESSAGES BY LSODE.
766 C MFLAG = 0 MEANS DO NOT PRINT. (DANGER..
767 C THIS RISKS LOSING VALUABLE INFORMATION.)
768 C MFLAG = 1 MEANS PRINT (THE DEFAULT).
769 C
770 C EITHER OF THE ABOVE CALLS MAY BE MADE AT
771 C ANY TIME AND WILL TAKE EFFECT IMMEDIATELY.
772 C
773 C CALL SRCOM(RSAV,ISAV,JOB) SAVES AND RESTORES THE CONTENTS OF
774 C THE INTERNAL COMMON BLOCKS USED BY
775 C LSODE (SEE PART III BELOW).
776 C RSAV MUST BE A REAL ARRAY OF LENGTH 218
777 C OR MORE, AND ISAV MUST BE AN INTEGER
778 C ARRAY OF LENGTH 41 OR MORE.
779 C JOB=1 MEANS SAVE COMMON INTO RSAV/ISAV.
780 C JOB=2 MEANS RESTORE COMMON FROM RSAV/ISAV.
781 C SRCOM IS USEFUL IF ONE IS
782 C INTERRUPTING A RUN AND RESTARTING
783 C LATER, OR ALTERNATING BETWEEN TWO OR
784 C MORE PROBLEMS SOLVED WITH LSODE.
785 C
786 C CALL INTDY(,,,,,) PROVIDE DERIVATIVES OF Y, OF VARIOUS
787 C (SEE BELOW) ORDERS, AT A SPECIFIED POINT T, IF
788 C DESIRED. IT MAY BE CALLED ONLY AFTER
789 C A SUCCESSFUL RETURN FROM LSODE.
790 C
791 C THE DETAILED INSTRUCTIONS FOR USING INTDY ARE AS FOLLOWS.
792 C THE FORM OF THE CALL IS..
793 C
794 C CALL INTDY (T, K, RWORK(21), NYH, DKY, IFLAG)
795 C
796 C THE INPUT PARAMETERS ARE..
797 C
798 C T = VALUE OF INDEPENDENT VARIABLE WHERE ANSWERS ARE DESIRED
799 C (NORMALLY THE SAME AS THE T LAST RETURNED BY LSODE).
800 C FOR VALID RESULTS, T MUST LIE BETWEEN TCUR - HU AND TCUR.
801 C (SEE OPTIONAL OUTPUTS FOR TCUR AND HU.)
802 C K = INTEGER ORDER OF THE DERIVATIVE DESIRED. K MUST SATISFY
803 C 0 .LE. K .LE. NQCUR, WHERE NQCUR IS THE CURRENT ORDER
804 C (SEE OPTIONAL OUTPUTS). THE CAPABILITY CORRESPONDING
805 C TO K = 0, I.E. COMPUTING Y(T), IS ALREADY PROVIDED
806 C BY LSODE DIRECTLY. SINCE NQCUR .GE. 1, THE FIRST
807 C DERIVATIVE DY/DT IS ALWAYS AVAILABLE WITH INTDY.
808 C RWORK(21) = THE BASE ADDRESS OF THE HISTORY ARRAY YH.
809 C NYH = COLUMN LENGTH OF YH, EQUAL TO THE INITIAL VALUE OF NEQ.
810 C
811 C THE OUTPUT PARAMETERS ARE..
812 C
813 C DKY = A REAL ARRAY OF LENGTH NEQ CONTAINING THE COMPUTED VALUE
814 C OF THE K-TH DERIVATIVE OF Y(T).
815 C IFLAG = INTEGER FLAG, RETURNED AS 0 IF K AND T WERE LEGAL,
816 C -1 IF K WAS ILLEGAL, AND -2 IF T WAS ILLEGAL.
817 C ON AN ERROR RETURN, A MESSAGE IS ALSO WRITTEN.
818 C-----------------------------------------------------------------------
819 C PART III. COMMON BLOCKS.
820 C
821 C IF LSODE IS TO BE USED IN AN OVERLAY SITUATION, THE USER
822 C MUST DECLARE, IN THE PRIMARY OVERLAY, THE VARIABLES IN..
823 C (1) THE CALL SEQUENCE TO LSODE,
824 C (2) THE INTERNAL COMMON BLOCK
825 C /LS0001/ OF LENGTH 257 (218 DOUBLE PRECISION WORDS
826 C FOLLOWED BY 39 INTEGER WORDS),
827 C
828 C IF LSODE IS USED ON A SYSTEM IN WHICH THE CONTENTS OF INTERNAL
829 C COMMON BLOCKS ARE NOT PRESERVED BETWEEN CALLS, THE USER SHOULD
830 C DECLARE THE ABOVE TWO COMMON BLOCKS IN HIS MAIN PROGRAM TO INSURE
831 C THAT THEIR CONTENTS ARE PRESERVED.
832 C
833 C IF THE SOLUTION OF A GIVEN PROBLEM BY LSODE IS TO BE INTERRUPTED
834 C AND THEN LATER CONTINUED, SUCH AS WHEN RESTARTING AN INTERRUPTED RUN
835 C OR ALTERNATING BETWEEN TWO OR MORE PROBLEMS, THE USER SHOULD SAVE,
836 C FOLLOWING THE RETURN FROM THE LAST LSODE CALL PRIOR TO THE
837 C INTERRUPTION, THE CONTENTS OF THE CALL SEQUENCE VARIABLES AND THE
838 C INTERNAL COMMON BLOCKS, AND LATER RESTORE THESE VALUES BEFORE THE
839 C NEXT LSODE CALL FOR THAT PROBLEM. TO SAVE AND RESTORE THE COMMON
840 C BLOCKS, USE SUBROUTINE SRCOM (SEE PART II ABOVE).
841 C
842 C-----------------------------------------------------------------------
843 C PART IV. OPTIONALLY REPLACEABLE SOLVER ROUTINES.
844 C
845 C BELOW ARE DESCRIPTIONS OF TWO ROUTINES IN THE LSODE PACKAGE WHICH
846 C RELATE TO THE MEASUREMENT OF ERRORS. EITHER ROUTINE CAN BE
847 C REPLACED BY A USER-SUPPLIED VERSION, IF DESIRED. HOWEVER, SINCE SUCH
848 C A REPLACEMENT MAY HAVE A MAJOR IMPACT ON PERFORMANCE, IT SHOULD BE
849 C DONE ONLY WHEN ABSOLUTELY NECESSARY, AND ONLY WITH GREAT CAUTION.
850 C (NOTE.. THE MEANS BY WHICH THE PACKAGE VERSION OF A ROUTINE IS
851 C SUPERSEDED BY THE USER-S VERSION MAY BE SYSTEM-DEPENDENT.)
852 C
853 C (A) EWSET.
854 C THE FOLLOWING SUBROUTINE IS CALLED JUST BEFORE EACH INTERNAL
855 C INTEGRATION STEP, AND SETS THE ARRAY OF ERROR WEIGHTS, EWT, AS
856 C DESCRIBED UNDER ITOL/RTOL/ATOL ABOVE..
857 C SUBROUTINE EWSET (NEQ, ITOL, RTOL, ATOL, YCUR, EWT)
858 C WHERE NEQ, ITOL, RTOL, AND ATOL ARE AS IN THE LSODE CALL SEQUENCE,
859 C YCUR CONTAINS THE CURRENT DEPENDENT VARIABLE VECTOR, AND
860 C EWT IS THE ARRAY OF WEIGHTS SET BY EWSET.
861 C
862 C IF THE USER SUPPLIES THIS SUBROUTINE, IT MUST RETURN IN EWT(I)
863 C (I = 1,...,NEQ) A POSITIVE QUANTITY SUITABLE FOR COMPARING ERRORS
864 C IN Y(I) TO. THE EWT ARRAY RETURNED BY EWSET IS PASSED TO THE
865 C VNORM ROUTINE (SEE BELOW), AND ALSO USED BY LSODE IN THE COMPUTATION
866 C OF THE OPTIONAL OUTPUT IMXER, THE DIAGONAL JACOBIAN APPROXIMATION,
867 C AND THE INCREMENTS FOR DIFFERENCE QUOTIENT JACOBIANS.
868 C
869 C IN THE USER-SUPPLIED VERSION OF EWSET, IT MAY BE DESIRABLE TO USE
870 C THE CURRENT VALUES OF DERIVATIVES OF Y. DERIVATIVES UP TO ORDER NQ
871 C ARE AVAILABLE FROM THE HISTORY ARRAY YH, DESCRIBED ABOVE UNDER
872 C OPTIONAL OUTPUTS. IN EWSET, YH IS IDENTICAL TO THE YCUR ARRAY,
873 C EXTENDED TO NQ + 1 COLUMNS WITH A COLUMN LENGTH OF NYH AND SCALE
874 C FACTORS OF H**J/FACTORIAL(J). ON THE FIRST CALL FOR THE PROBLEM,
875 C GIVEN BY NST = 0, NQ IS 1 AND H IS TEMPORARILY SET TO 1.0.
876 C THE QUANTITIES NQ, NYH, H, AND NST CAN BE OBTAINED BY INCLUDING
877 C IN EWSET THE STATEMENTS..
878 C DOUBLE PRECISION H, RLS
879 C COMMON /LS0001/ RLS(218),ILS(39)
880 C NQ = ILS(35)
881 C NYH = ILS(14)
882 C NST = ILS(36)
883 C H = RLS(212)
884 C THUS, FOR EXAMPLE, THE CURRENT VALUE OF DY/DT CAN BE OBTAINED AS
885 C YCUR(NYH+I)/H (I=1,...,NEQ) (AND THE DIVISION BY H IS
886 C UNNECESSARY WHEN NST = 0).
887 C
888 C (B) VNORM.
889 C THE FOLLOWING IS A REAL FUNCTION ROUTINE WHICH COMPUTES THE WEIGHTED
890 C ROOT-MEAN-SQUARE NORM OF A VECTOR V..
891 C D = VNORM (N, V, W)
892 C WHERE..
893 C N = THE LENGTH OF THE VECTOR,
894 C V = REAL ARRAY OF LENGTH N CONTAINING THE VECTOR,
895 C W = REAL ARRAY OF LENGTH N CONTAINING WEIGHTS,
896 C D = SQRT( (1/N) * SUM(V(I)*W(I))**2 ).
897 C VNORM IS CALLED WITH N = NEQ AND WITH W(I) = 1.0/EWT(I), WHERE
898 C EWT IS AS SET BY SUBROUTINE EWSET.
899 C
900 C IF THE USER SUPPLIES THIS FUNCTION, IT SHOULD RETURN A NON-NEGATIVE
901 C VALUE OF VNORM SUITABLE FOR USE IN THE ERROR CONTROL IN LSODE.
902 C NONE OF THE ARGUMENTS SHOULD BE ALTERED BY VNORM.
903 C FOR EXAMPLE, A USER-SUPPLIED VNORM ROUTINE MIGHT..
904 C -SUBSTITUTE A MAX-NORM OF (V(I)*W(I)) FOR THE RMS-NORM, OR
905 C -IGNORE SOME COMPONENTS OF V IN THE NORM, WITH THE EFFECT OF
906 C SUPPRESSING THE ERROR CONTROL ON THOSE COMPONENTS OF Y.
907 C-----------------------------------------------------------------------
908 C-----------------------------------------------------------------------
909 C OTHER ROUTINES IN THE LSODE PACKAGE.
910 C
911 C IN ADDITION TO SUBROUTINE LSODE, THE LSODE PACKAGE INCLUDES THE
912 C FOLLOWING SUBROUTINES AND FUNCTION ROUTINES..
913 C INTDY COMPUTES AN INTERPOLATED VALUE OF THE Y VECTOR AT T = TOUT.
914 C STODE IS THE CORE INTEGRATOR, WHICH DOES ONE STEP OF THE
915 C INTEGRATION AND THE ASSOCIATED ERROR CONTROL.
916 C CFODE SETS ALL METHOD COEFFICIENTS AND TEST CONSTANTS.
917 C PREPJ COMPUTES AND PREPROCESSES THE JACOBIAN MATRIX J = DF/DY
918 C AND THE NEWTON ITERATION MATRIX P = I - H*L0*J.
919 C SOLSY MANAGES SOLUTION OF LINEAR SYSTEM IN CHORD ITERATION.
920 C EWSET SETS THE ERROR WEIGHT VECTOR EWT BEFORE EACH STEP.
921 C VNORM COMPUTES THE WEIGHTED R.M.S. NORM OF A VECTOR.
922 C SRCOM IS A USER-CALLABLE ROUTINE TO SAVE AND RESTORE
923 C THE CONTENTS OF THE INTERNAL COMMON BLOCKS.
924 C DGETRF AND DGETRS ARE ROUTINES FROM LAPACK FOR SOLVING FULL
925 C SYSTEMS OF LINEAR ALGEBRAIC EQUATIONS.
926 C DGBTRF AND DGBTRS ARE ROUTINES FROM LAPACK FOR SOLVING BANDED
927 C LINEAR SYSTEMS.
928 C DAXPY, DSCAL, IDAMAX, AND DDOT ARE BASIC LINEAR ALGEBRA MODULES
929 C (BLAS) USED BY THE ABOVE LINPACK ROUTINES.
930 C D1MACH COMPUTES THE UNIT ROUNDOFF IN A MACHINE-INDEPENDENT MANNER.
931 C XERRWD, XSETUN, AND XSETF HANDLE THE PRINTING OF ALL ERROR
932 C MESSAGES AND WARNINGS. XERRWD IS MACHINE-DEPENDENT.
933 C NOTE.. VNORM, IDAMAX, DDOT, AND D1MACH ARE FUNCTION ROUTINES.
934 C ALL THE OTHERS ARE SUBROUTINES.
935 C
936 C THE INTRINSIC AND EXTERNAL ROUTINES USED BY LSODE ARE..
937 C DABS, DMAX1, DMIN1, DBLE, MAX0, MIN0, MOD, DSIGN, DSQRT, AND WRITE.
938 C
939 C A BLOCK DATA SUBPROGRAM IS ALSO INCLUDED WITH THE PACKAGE,
940 C FOR LOADING SOME OF THE VARIABLES IN INTERNAL COMMON.
941 C
942 C-----------------------------------------------------------------------
943 C THE FOLLOWING CARD IS FOR OPTIMIZED COMPILATION ON LLNL COMPILERS.
944 CLLL. OPTIMIZE
945 C-----------------------------------------------------------------------
946  EXTERNAL prepj, solsy
947  INTEGER ILLIN, INIT, LYH, LEWT, LACOR, LSAVF, LWM, LIWM,
948  1 mxstep, mxhnil, nhnil, ntrep, nslast, nyh, iowns
949  INTEGER ICF, IERPJ, IERSL, JCUR, JSTART, KFLAG, L, METH, MITER,
950  1 maxord, maxcor, msbp, mxncf, n, nq, nst, nfe, nje, nqu
951  INTEGER I, I1, I2, IFLAG, IMXER, KGO, LF0,
952  1 leniw, lenrw, lenwm, ml, mord, mu, mxhnl0, mxstp0
953  DOUBLE PRECISION ROWNS,
954  1 ccmax, el0, h, hmin, hmxi, hu, rc, tn, uround
955  DOUBLE PRECISION ATOLI, AYI, BIG, EWTI, H0, HMAX, HMX, RH, RTOLI,
956  1 tcrit, tdist, tnext, tol, tolsf, tp, SIZE, sum, w0,
957  2 d1mach, vnorm
958  dimension mord(2)
959  LOGICAL IHIT
960 C-----------------------------------------------------------------------
961 C THE FOLLOWING INTERNAL COMMON BLOCK CONTAINS
962 C (A) VARIABLES WHICH ARE LOCAL TO ANY SUBROUTINE BUT WHOSE VALUES MUST
963 C BE PRESERVED BETWEEN CALLS TO THE ROUTINE (OWN VARIABLES), AND
964 C (B) VARIABLES WHICH ARE COMMUNICATED BETWEEN SUBROUTINES.
965 C THE STRUCTURE OF THE BLOCK IS AS FOLLOWS.. ALL REAL VARIABLES ARE
966 C LISTED FIRST, FOLLOWED BY ALL INTEGERS. WITHIN EACH TYPE, THE
967 C VARIABLES ARE GROUPED WITH THOSE LOCAL TO SUBROUTINE LSODE FIRST,
968 C THEN THOSE LOCAL TO SUBROUTINE STODE, AND FINALLY THOSE USED
969 C FOR COMMUNICATION. THE BLOCK IS DECLARED IN SUBROUTINES
970 C LSODE, INTDY, STODE, PREPJ, AND SOLSY. GROUPS OF VARIABLES ARE
971 C REPLACED BY DUMMY ARRAYS IN THE COMMON DECLARATIONS IN ROUTINES
972 C WHERE THOSE VARIABLES ARE NOT USED.
973 C-----------------------------------------------------------------------
974  COMMON /ls0001/ rowns(209),
975  1 ccmax, el0, h, hmin, hmxi, hu, rc, tn, uround,
976  2 illin, init, lyh, lewt, lacor, lsavf, lwm, liwm,
977  3 mxstep, mxhnil, nhnil, ntrep, nslast, nyh, iowns(6),
978  4 icf, ierpj, iersl, jcur, jstart, kflag, l, meth, miter,
979  5 maxord, maxcor, msbp, mxncf, n, nq, nst, nfe, nje, nqu
980 C
981  DATA mord(1),mord(2)/12,5/, mxstp0/500/, mxhnl0/10/
982 C-----------------------------------------------------------------------
983 C BLOCK A.
984 C THIS CODE BLOCK IS EXECUTED ON EVERY CALL.
985 C IT TESTS ISTATE AND ITASK FOR LEGALITY AND BRANCHES APPROPRIATELY.
986 C IF ISTATE .GT. 1 BUT THE FLAG INIT SHOWS THAT INITIALIZATION HAS
987 C NOT YET BEEN DONE, AN ERROR RETURN OCCURS.
988 C IF ISTATE = 1 AND TOUT = T, JUMP TO BLOCK G AND RETURN IMMEDIATELY.
989 C-----------------------------------------------------------------------
990  IF (istate .LT. 1 .OR. istate .GT. 3) go to 601
991  IF (itask .LT. 1 .OR. itask .GT. 5) go to 602
992  IF (istate .EQ. 1) go to 10
993  IF (init .EQ. 0) go to 603
994  IF (istate .EQ. 2) go to 200
995  go to 20
996  10 init = 0
997  IF (tout .EQ. t) go to 430
998  20 ntrep = 0
999 C-----------------------------------------------------------------------
1000 C BLOCK B.
1001 C THE NEXT CODE BLOCK IS EXECUTED FOR THE INITIAL CALL (ISTATE = 1),
1002 C OR FOR A CONTINUATION CALL WITH PARAMETER CHANGES (ISTATE = 3).
1003 C IT CONTAINS CHECKING OF ALL INPUTS AND VARIOUS INITIALIZATIONS.
1004 C
1005 C FIRST CHECK LEGALITY OF THE NON-OPTIONAL INPUTS NEQ, ITOL, IOPT,
1006 C MF, ML, AND MU.
1007 C-----------------------------------------------------------------------
1008  IF (neq(1) .LE. 0) go to 604
1009  IF (istate .EQ. 1) go to 25
1010  IF (neq(1) .GT. n) go to 605
1011  25 n = neq(1)
1012  IF (itol .LT. 1 .OR. itol .GT. 4) go to 606
1013  IF (iopt .LT. 0 .OR. iopt .GT. 1) go to 607
1014  meth = mf/10
1015  miter = mf - 10*meth
1016  IF (meth .LT. 1 .OR. meth .GT. 2) go to 608
1017  IF (miter .LT. 0 .OR. miter .GT. 5) go to 608
1018  IF (miter .LE. 3) go to 30
1019  ml = iwork(1)
1020  mu = iwork(2)
1021  IF (ml .LT. 0 .OR. ml .GE. n) go to 609
1022  IF (mu .LT. 0 .OR. mu .GE. n) go to 610
1023  30 CONTINUE
1024 C NEXT PROCESS AND CHECK THE OPTIONAL INPUTS. --------------------------
1025  IF (iopt .EQ. 1) go to 40
1026  maxord = mord(meth)
1027  mxstep = mxstp0
1028  mxhnil = mxhnl0
1029  IF (istate .EQ. 1) h0 = 0.0d0
1030  hmxi = 0.0d0
1031  hmin = 0.0d0
1032  go to 60
1033  40 maxord = iwork(5)
1034  IF (maxord .LT. 0) go to 611
1035  IF (maxord .EQ. 0) maxord = 100
1036  maxord = min0(maxord,mord(meth))
1037  mxstep = iwork(6)
1038  IF (mxstep .LT. 0) go to 612
1039  IF (mxstep .EQ. 0) mxstep = mxstp0
1040  mxhnil = iwork(7)
1041  IF (mxhnil .LT. 0) go to 613
1042  IF (mxhnil .EQ. 0) mxhnil = mxhnl0
1043  IF (istate .NE. 1) go to 50
1044  h0 = rwork(5)
1045  IF ((tout - t)*h0 .LT. 0.0d0) go to 614
1046  50 hmax = rwork(6)
1047  IF (hmax .LT. 0.0d0) go to 615
1048  hmxi = 0.0d0
1049  IF (hmax .GT. 0.0d0) hmxi = 1.0d0/hmax
1050  hmin = rwork(7)
1051  IF (hmin .LT. 0.0d0) go to 616
1052 C-----------------------------------------------------------------------
1053 C SET WORK ARRAY POINTERS AND CHECK LENGTHS LRW AND LIW.
1054 C POINTERS TO SEGMENTS OF RWORK AND IWORK ARE NAMED BY PREFIXING L TO
1055 C THE NAME OF THE SEGMENT. E.G., THE SEGMENT YH STARTS AT RWORK(LYH).
1056 C SEGMENTS OF RWORK (IN ORDER) ARE DENOTED YH, WM, EWT, SAVF, ACOR.
1057 C-----------------------------------------------------------------------
1058  60 lyh = 21
1059  IF (istate .EQ. 1) nyh = n
1060  lwm = lyh + (maxord + 1)*nyh
1061  IF (miter .EQ. 0) lenwm = 0
1062  IF (miter .EQ. 1 .OR. miter .EQ. 2) lenwm = n*n + 2
1063  IF (miter .EQ. 3) lenwm = n + 2
1064  IF (miter .GE. 4) lenwm = (2*ml + mu + 1)*n + 2
1065  lewt = lwm + lenwm
1066  lsavf = lewt + n
1067  lacor = lsavf + n
1068  lenrw = lacor + n - 1
1069  iwork(17) = lenrw
1070  liwm = 1
1071  leniw = 20 + n
1072  IF (miter .EQ. 0 .OR. miter .EQ. 3) leniw = 20
1073  iwork(18) = leniw
1074  IF (lenrw .GT. lrw) go to 617
1075  IF (leniw .GT. liw) go to 618
1076 C CHECK RTOL AND ATOL FOR LEGALITY. ------------------------------------
1077  rtoli = rtol(1)
1078  atoli = atol(1)
1079  DO 70 i = 1,n
1080  IF (itol .GE. 3) rtoli = rtol(i)
1081  IF (itol .EQ. 2 .OR. itol .EQ. 4) atoli = atol(i)
1082  IF (rtoli .LT. 0.0d0) go to 619
1083  IF (atoli .LT. 0.0d0) go to 620
1084  70 CONTINUE
1085  IF (istate .EQ. 1) go to 100
1086 C IF ISTATE = 3, SET FLAG TO SIGNAL PARAMETER CHANGES TO STODE. --------
1087  jstart = -1
1088  IF (nq .LE. maxord) go to 90
1089 C MAXORD WAS REDUCED BELOW NQ. COPY YH(*,MAXORD+2) INTO SAVF. ---------
1090  DO 80 i = 1,n
1091  80 rwork(i+lsavf-1) = rwork(i+lwm-1)
1092 C RELOAD WM(1) = RWORK(LWM), SINCE LWM MAY HAVE CHANGED. ---------------
1093  90 IF (miter .GT. 0) rwork(lwm) = dsqrt(uround)
1094  IF (n .EQ. nyh) go to 200
1095 C NEQ WAS REDUCED. ZERO PART OF YH TO AVOID UNDEFINED REFERENCES. -----
1096  i1 = lyh + l*nyh
1097  i2 = lyh + (maxord + 1)*nyh - 1
1098  IF (i1 .GT. i2) go to 200
1099  DO 95 i = i1,i2
1100  95 rwork(i) = 0.0d0
1101  go to 200
1102 C-----------------------------------------------------------------------
1103 C BLOCK C.
1104 C THE NEXT BLOCK IS FOR THE INITIAL CALL ONLY (ISTATE = 1).
1105 C IT CONTAINS ALL REMAINING INITIALIZATIONS, THE INITIAL CALL TO F,
1106 C AND THE CALCULATION OF THE INITIAL STEP SIZE.
1107 C THE ERROR WEIGHTS IN EWT ARE INVERTED AFTER BEING LOADED.
1108 C-----------------------------------------------------------------------
1109  100 uround = d1mach(4)
1110  tn = t
1111  IF (itask .NE. 4 .AND. itask .NE. 5) go to 110
1112  tcrit = rwork(1)
1113  IF ((tcrit - tout)*(tout - t) .LT. 0.0d0) go to 625
1114  IF (h0 .NE. 0.0d0 .AND. (t + h0 - tcrit)*h0 .GT. 0.0d0)
1115  1 h0 = tcrit - t
1116  110 jstart = 0
1117  IF (miter .GT. 0) rwork(lwm) = dsqrt(uround)
1118  nhnil = 0
1119  nst = 0
1120  nje = 0
1121  nslast = 0
1122  hu = 0.0d0
1123  nqu = 0
1124  ccmax = 0.3d0
1125  maxcor = 3
1126  msbp = 20
1127  mxncf = 10
1128 C INITIAL CALL TO F. (LF0 POINTS TO YH(*,2).) -------------------------
1129  lf0 = lyh + nyh
1130  ierr = 0
1131  CALL f(neq, t, y, rwork(lf0), ierr)
1132  IF (ierr .LT. 0) THEN
1133  istate = -13
1134  RETURN
1135  ENDIF
1136  nfe = 1
1137 C LOAD THE INITIAL VALUE VECTOR IN YH. ---------------------------------
1138  DO 115 i = 1,n
1139  115 rwork(i+lyh-1) = y(i)
1140 C LOAD AND INVERT THE EWT ARRAY. (H IS TEMPORARILY SET TO 1.0.) -------
1141  nq = 1
1142  h = 1.0d0
1143  CALL ewset(n, itol, rtol, atol, rwork(lyh), rwork(lewt))
1144  DO 120 i = 1,n
1145  IF (rwork(i+lewt-1) .LE. 0.0d0) go to 621
1146  120 rwork(i+lewt-1) = 1.0d0/rwork(i+lewt-1)
1147 C-----------------------------------------------------------------------
1148 C THE CODING BELOW COMPUTES THE STEP SIZE, H0, TO BE ATTEMPTED ON THE
1149 C FIRST STEP, UNLESS THE USER HAS SUPPLIED A VALUE FOR THIS.
1150 C FIRST CHECK THAT TOUT - T DIFFERS SIGNIFICANTLY FROM ZERO.
1151 C A SCALAR TOLERANCE QUANTITY TOL IS COMPUTED, AS MAX(RTOL(I))
1152 C IF THIS IS POSITIVE, OR MAX(ATOL(I)/ABS(Y(I))) OTHERWISE, ADJUSTED
1153 C SO AS TO BE BETWEEN 100*UROUND AND 1.0E-3.
1154 C THEN THE COMPUTED VALUE H0 IS GIVEN BY..
1155 C NEQ
1156 C H0**2 = TOL / ( W0**-2 + (1/NEQ) * SUM ( F(I)/YWT(I) )**2 )
1157 C 1
1158 C WHERE W0 = MAX ( ABS(T), ABS(TOUT) ),
1159 C F(I) = I-TH COMPONENT OF INITIAL VALUE OF F,
1160 C YWT(I) = EWT(I)/TOL (A WEIGHT FOR Y(I)).
1161 C THE SIGN OF H0 IS INFERRED FROM THE INITIAL VALUES OF TOUT AND T.
1162 C-----------------------------------------------------------------------
1163  IF (h0 .NE. 0.0d0) go to 180
1164  tdist = dabs(tout - t)
1165  w0 = dmax1(dabs(t),dabs(tout))
1166  IF (tdist .LT. 2.0d0*uround*w0) go to 622
1167  tol = rtol(1)
1168  IF (itol .LE. 2) go to 140
1169  DO 130 i = 1,n
1170  130 tol = dmax1(tol,rtol(i))
1171  140 IF (tol .GT. 0.0d0) go to 160
1172  atoli = atol(1)
1173  DO 150 i = 1,n
1174  IF (itol .EQ. 2 .OR. itol .EQ. 4) atoli = atol(i)
1175  ayi = dabs(y(i))
1176  IF (ayi .NE. 0.0d0) tol = dmax1(tol,atoli/ayi)
1177  150 CONTINUE
1178  160 tol = dmax1(tol,100.0d0*uround)
1179  tol = dmin1(tol,0.001d0)
1180  sum = vnorm(n, rwork(lf0), rwork(lewt))
1181  sum = 1.0d0/(tol*w0*w0) + tol*sum**2
1182  h0 = 1.0d0/dsqrt(sum)
1183  h0 = dmin1(h0,tdist)
1184  h0 = dsign(h0,tout-t)
1185 C ADJUST H0 IF NECESSARY TO MEET HMAX BOUND. ---------------------------
1186  180 rh = dabs(h0)*hmxi
1187  IF (rh .GT. 1.0d0) h0 = h0/rh
1188 C LOAD H WITH H0 AND SCALE YH(*,2) BY H0. ------------------------------
1189  h = h0
1190  DO 190 i = 1,n
1191  190 rwork(i+lf0-1) = h0*rwork(i+lf0-1)
1192  go to 270
1193 C-----------------------------------------------------------------------
1194 C BLOCK D.
1195 C THE NEXT CODE BLOCK IS FOR CONTINUATION CALLS ONLY (ISTATE = 2 OR 3)
1196 C AND IS TO CHECK STOP CONDITIONS BEFORE TAKING A STEP.
1197 C-----------------------------------------------------------------------
1198  200 nslast = nst
1199  go to(210, 250, 220, 230, 240), itask
1200  210 IF ((tn - tout)*h .LT. 0.0d0) go to 250
1201  CALL intdy(tout, 0, rwork(lyh), nyh, y, iflag)
1202  IF (iflag .NE. 0) go to 627
1203  t = tout
1204  go to 420
1205  220 tp = tn - hu*(1.0d0 + 100.0d0*uround)
1206  IF ((tp - tout)*h .GT. 0.0d0) go to 623
1207  IF ((tn - tout)*h .LT. 0.0d0) go to 250
1208  go to 400
1209  230 tcrit = rwork(1)
1210  IF ((tn - tcrit)*h .GT. 0.0d0) go to 624
1211  IF ((tcrit - tout)*h .LT. 0.0d0) go to 625
1212  IF ((tn - tout)*h .LT. 0.0d0) go to 245
1213  CALL intdy(tout, 0, rwork(lyh), nyh, y, iflag)
1214  IF (iflag .NE. 0) go to 627
1215  t = tout
1216  go to 420
1217  240 tcrit = rwork(1)
1218  IF ((tn - tcrit)*h .GT. 0.0d0) go to 624
1219  245 hmx = dabs(tn) + dabs(h)
1220  ihit = dabs(tn - tcrit) .LE. 100.0d0*uround*hmx
1221  IF (ihit) go to 400
1222  tnext = tn + h*(1.0d0 + 4.0d0*uround)
1223  IF ((tnext - tcrit)*h .LE. 0.0d0) go to 250
1224  h = (tcrit - tn)*(1.0d0 - 4.0d0*uround)
1225  IF (istate .EQ. 2) jstart = -2
1226 C-----------------------------------------------------------------------
1227 C BLOCK E.
1228 C THE NEXT BLOCK IS NORMALLY EXECUTED FOR ALL CALLS AND CONTAINS
1229 C THE CALL TO THE ONE-STEP CORE INTEGRATOR STODE.
1230 C
1231 C THIS IS A LOOPING POINT FOR THE INTEGRATION STEPS.
1232 C
1233 C FIRST CHECK FOR TOO MANY STEPS BEING TAKEN, UPDATE EWT (IF NOT AT
1234 C START OF PROBLEM), CHECK FOR TOO MUCH ACCURACY BEING REQUESTED, AND
1235 C CHECK FOR H BELOW THE ROUNDOFF LEVEL IN T.
1236 C-----------------------------------------------------------------------
1237  250 CONTINUE
1238  IF ((nst-nslast) .GE. mxstep) go to 500
1239  CALL ewset(n, itol, rtol, atol, rwork(lyh), rwork(lewt))
1240  DO 260 i = 1,n
1241  IF (rwork(i+lewt-1) .LE. 0.0d0) go to 510
1242  260 rwork(i+lewt-1) = 1.0d0/rwork(i+lewt-1)
1243  270 tolsf = uround*vnorm(n, rwork(lyh), rwork(lewt))
1244  IF (tolsf .LE. 1.0d0) go to 280
1245  tolsf = tolsf*2.0d0
1246  IF (nst .EQ. 0) go to 626
1247  go to 520
1248  280 IF ((tn + h) .NE. tn) go to 290
1249  nhnil = nhnil + 1
1250  IF (nhnil .GT. mxhnil) go to 290
1251  CALL xerrwd('LSODE-- WARNING..INTERNAL T (=R1) AND H (=R2) ARE',
1252  1 50, 101, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
1253  CALL xerrwd(
1254  1 ' SUCH THAT IN THE MACHINE, T + H = T ON THE NEXT STEP ',
1255  1 60, 101, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
1256  CALL xerrwd(' (H = STEP SIZE). SOLVER WILL CONTINUE ANYWAY',
1257  1 50, 101, 0, 0, 0, 0, 2, tn, h)
1258  IF (nhnil .LT. mxhnil) go to 290
1259  CALL xerrwd('LSODE-- ABOVE WARNING HAS BEEN ISSUED I1 TIMES. ',
1260  1 50, 102, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
1261  CALL xerrwd(' IT WILL NOT BE ISSUED AGAIN FOR THIS PROBLEM',
1262  1 50, 102, 0, 1, mxhnil, 0, 0, 0.0d0, 0.0d0)
1263  290 CONTINUE
1264 C-----------------------------------------------------------------------
1265 C CALL STODE(NEQ,Y,YH,NYH,YH,EWT,SAVF,ACOR,WM,IWM,F,JAC,PREPJ,SOLSY)
1266 C-----------------------------------------------------------------------
1267  ierr = 0
1268  CALL stode(neq, y, rwork(lyh), nyh, rwork(lyh), rwork(lewt),
1269  1 rwork(lsavf), rwork(lacor), rwork(lwm), iwork(liwm),
1270  2 f, jac, prepj, solsy, ierr)
1271  IF (ierr .LT. 0) THEN
1272  istate = -13
1273  RETURN
1274  ENDIF
1275  kgo = 1 - kflag
1276  go to(300, 530, 540), kgo
1277 C-----------------------------------------------------------------------
1278 C BLOCK F.
1279 C THE FOLLOWING BLOCK HANDLES THE CASE OF A SUCCESSFUL RETURN FROM THE
1280 C CORE INTEGRATOR (KFLAG = 0). TEST FOR STOP CONDITIONS.
1281 C-----------------------------------------------------------------------
1282  300 init = 1
1283  go to(310, 400, 330, 340, 350), itask
1284 C ITASK = 1. IF TOUT HAS BEEN REACHED, INTERPOLATE. -------------------
1285  310 IF ((tn - tout)*h .LT. 0.0d0) go to 250
1286  CALL intdy(tout, 0, rwork(lyh), nyh, y, iflag)
1287  t = tout
1288  go to 420
1289 C ITASK = 3. JUMP TO EXIT IF TOUT WAS REACHED. ------------------------
1290  330 IF ((tn - tout)*h .GE. 0.0d0) go to 400
1291  go to 250
1292 C ITASK = 4. SEE IF TOUT OR TCRIT WAS REACHED. ADJUST H IF NECESSARY.
1293  340 IF ((tn - tout)*h .LT. 0.0d0) go to 345
1294  CALL intdy(tout, 0, rwork(lyh), nyh, y, iflag)
1295  t = tout
1296  go to 420
1297  345 hmx = dabs(tn) + dabs(h)
1298  ihit = dabs(tn - tcrit) .LE. 100.0d0*uround*hmx
1299  IF (ihit) go to 400
1300  tnext = tn + h*(1.0d0 + 4.0d0*uround)
1301  IF ((tnext - tcrit)*h .LE. 0.0d0) go to 250
1302  h = (tcrit - tn)*(1.0d0 - 4.0d0*uround)
1303  jstart = -2
1304  go to 250
1305 C ITASK = 5. SEE IF TCRIT WAS REACHED AND JUMP TO EXIT. ---------------
1306  350 hmx = dabs(tn) + dabs(h)
1307  ihit = dabs(tn - tcrit) .LE. 100.0d0*uround*hmx
1308 C-----------------------------------------------------------------------
1309 C BLOCK G.
1310 C THE FOLLOWING BLOCK HANDLES ALL SUCCESSFUL RETURNS FROM LSODE.
1311 C IF ITASK .NE. 1, Y IS LOADED FROM YH AND T IS SET ACCORDINGLY.
1312 C ISTATE IS SET TO 2, THE ILLEGAL INPUT COUNTER IS ZEROED, AND THE
1313 C OPTIONAL OUTPUTS ARE LOADED INTO THE WORK ARRAYS BEFORE RETURNING.
1314 C IF ISTATE = 1 AND TOUT = T, THERE IS A RETURN WITH NO ACTION TAKEN,
1315 C EXCEPT THAT IF THIS HAS HAPPENED REPEATEDLY, THE RUN IS TERMINATED.
1316 C-----------------------------------------------------------------------
1317  400 DO 410 i = 1,n
1318  410 y(i) = rwork(i+lyh-1)
1319  t = tn
1320  IF (itask .NE. 4 .AND. itask .NE. 5) go to 420
1321  IF (ihit) t = tcrit
1322  420 istate = 2
1323  illin = 0
1324  rwork(11) = hu
1325  rwork(12) = h
1326  rwork(13) = tn
1327  iwork(11) = nst
1328  iwork(12) = nfe
1329  iwork(13) = nje
1330  iwork(14) = nqu
1331  iwork(15) = nq
1332  RETURN
1333 C
1334  430 ntrep = ntrep + 1
1335  IF (ntrep .LT. 5) RETURN
1336  CALL xerrwd(
1337  1 'LSODE-- REPEATED CALLS WITH ISTATE = 1 AND TOUT = T (=R1) ',
1338  1 60, 301, 0, 0, 0, 0, 1, t, 0.0d0)
1339  go to 800
1340 C-----------------------------------------------------------------------
1341 C BLOCK H.
1342 C THE FOLLOWING BLOCK HANDLES ALL UNSUCCESSFUL RETURNS OTHER THAN
1343 C THOSE FOR ILLEGAL INPUT. FIRST THE ERROR MESSAGE ROUTINE IS CALLED.
1344 C IF THERE WAS AN ERROR TEST OR CONVERGENCE TEST FAILURE, IMXER IS SET.
1345 C THEN Y IS LOADED FROM YH, T IS SET TO TN, AND THE ILLEGAL INPUT
1346 C COUNTER ILLIN IS SET TO 0. THE OPTIONAL OUTPUTS ARE LOADED INTO
1347 C THE WORK ARRAYS BEFORE RETURNING.
1348 C-----------------------------------------------------------------------
1349 C THE MAXIMUM NUMBER OF STEPS WAS TAKEN BEFORE REACHING TOUT. ----------
1350  500 CALL xerrwd('LSODE-- AT CURRENT T (=R1), MXSTEP (=I1) STEPS ',
1351  1 50, 201, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
1352  CALL xerrwd(' TAKEN ON THIS CALL BEFORE REACHING TOUT ',
1353  1 50, 201, 0, 1, mxstep, 0, 1, tn, 0.0d0)
1354  istate = -1
1355  go to 580
1356 C EWT(I) .LE. 0.0 FOR SOME I (NOT AT START OF PROBLEM). ----------------
1357  510 ewti = rwork(lewt+i-1)
1358  CALL xerrwd(.LE.'LSODE-- AT T (=R1), EWT(I1) HAS BECOME R2 0.',
1359  1 50, 202, 0, 1, i, 0, 2, tn, ewti)
1360  istate = -6
1361  go to 580
1362 C TOO MUCH ACCURACY REQUESTED FOR MACHINE PRECISION. -------------------
1363  520 CALL xerrwd('LSODE-- AT T (=R1), TOO MUCH ACCURACY REQUESTED ',
1364  1 50, 203, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
1365  CALL xerrwd(' FOR PRECISION OF MACHINE.. SEE TOLSF (=R2) ',
1366  1 50, 203, 0, 0, 0, 0, 2, tn, tolsf)
1367  rwork(14) = tolsf
1368  istate = -2
1369  go to 580
1370 C KFLAG = -1. ERROR TEST FAILED REPEATEDLY OR WITH ABS(H) = HMIN. -----
1371  530 CALL xerrwd('LSODE-- AT T(=R1) AND STEP SIZE H(=R2), THE ERROR',
1372  1 50, 204, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
1373  CALL xerrwd(' TEST FAILED REPEATEDLY OR WITH ABS(H) = HMIN',
1374  1 50, 204, 0, 0, 0, 0, 2, tn, h)
1375  istate = -4
1376  go to 560
1377 C KFLAG = -2. CONVERGENCE FAILED REPEATEDLY OR WITH ABS(H) = HMIN. ----
1378  540 CALL xerrwd('LSODE-- AT T (=R1) AND STEP SIZE H (=R2), THE ',
1379  1 50, 205, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
1380  CALL xerrwd(' CORRECTOR CONVERGENCE FAILED REPEATEDLY ',
1381  1 50, 205, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
1382  CALL xerrwd(' OR WITH ABS(H) = HMIN ',
1383  1 30, 205, 0, 0, 0, 0, 2, tn, h)
1384  istate = -5
1385 C COMPUTE IMXER IF RELEVANT. -------------------------------------------
1386  560 big = 0.0d0
1387  imxer = 1
1388  DO 570 i = 1,n
1389  SIZE = dabs(rwork(i+lacor-1)*rwork(i+lewt-1))
1390  IF (big .GE. size) go to 570
1391  big = SIZE
1392  imxer = i
1393  570 CONTINUE
1394  iwork(16) = imxer
1395 C SET Y VECTOR, T, ILLIN, AND OPTIONAL OUTPUTS. ------------------------
1396  580 DO 590 i = 1,n
1397  590 y(i) = rwork(i+lyh-1)
1398  t = tn
1399  illin = 0
1400  rwork(11) = hu
1401  rwork(12) = h
1402  rwork(13) = tn
1403  iwork(11) = nst
1404  iwork(12) = nfe
1405  iwork(13) = nje
1406  iwork(14) = nqu
1407  iwork(15) = nq
1408  RETURN
1409 C-----------------------------------------------------------------------
1410 C BLOCK I.
1411 C THE FOLLOWING BLOCK HANDLES ALL ERROR RETURNS DUE TO ILLEGAL INPUT
1412 C (ISTATE = -3), AS DETECTED BEFORE CALLING THE CORE INTEGRATOR.
1413 C FIRST THE ERROR MESSAGE ROUTINE IS CALLED. THEN IF THERE HAVE BEEN
1414 C 5 CONSECUTIVE SUCH RETURNS JUST BEFORE THIS CALL TO THE SOLVER,
1415 C THE RUN IS HALTED.
1416 C-----------------------------------------------------------------------
1417  601 CALL xerrwd('LSODE-- ISTATE (=I1) ILLEGAL ',
1418  1 30, 1, 0, 1, istate, 0, 0, 0.0d0, 0.0d0)
1419  go to 700
1420  602 CALL xerrwd('LSODE-- ITASK (=I1) ILLEGAL ',
1421  1 30, 2, 0, 1, itask, 0, 0, 0.0d0, 0.0d0)
1422  go to 700
1423  603 CALL xerrwd(.GT.'LSODE-- ISTATE 1 BUT LSODE NOT INITIALIZED ',
1424  1 50, 3, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
1425  go to 700
1426  604 CALL xerrwd(.LT.'LSODE-- NEQ (=I1) 1 ',
1427  1 30, 4, 0, 1, neq(1), 0, 0, 0.0d0, 0.0d0)
1428  go to 700
1429  605 CALL xerrwd('LSODE-- ISTATE = 3 AND NEQ INCREASED (I1 TO I2) ',
1430  1 50, 5, 0, 2, n, neq(1), 0, 0.0d0, 0.0d0)
1431  go to 700
1432  606 CALL xerrwd('LSODE-- ITOL (=I1) ILLEGAL ',
1433  1 30, 6, 0, 1, itol, 0, 0, 0.0d0, 0.0d0)
1434  go to 700
1435  607 CALL xerrwd('LSODE-- IOPT (=I1) ILLEGAL ',
1436  1 30, 7, 0, 1, iopt, 0, 0, 0.0d0, 0.0d0)
1437  go to 700
1438  608 CALL xerrwd('LSODE-- MF (=I1) ILLEGAL ',
1439  1 30, 8, 0, 1, mf, 0, 0, 0.0d0, 0.0d0)
1440  go to 700
1441  609 CALL xerrwd(.LT..GE.'LSODE-- ML (=I1) ILLEGAL.. 0 OR NEQ (=I2)',
1442  1 50, 9, 0, 2, ml, neq(1), 0, 0.0d0, 0.0d0)
1443  go to 700
1444  610 CALL xerrwd(.LT..GE.'LSODE-- MU (=I1) ILLEGAL.. 0 OR NEQ (=I2)',
1445  1 50, 10, 0, 2, mu, neq(1), 0, 0.0d0, 0.0d0)
1446  go to 700
1447  611 CALL xerrwd(.LT.'LSODE-- MAXORD (=I1) 0 ',
1448  1 30, 11, 0, 1, maxord, 0, 0, 0.0d0, 0.0d0)
1449  go to 700
1450  612 CALL xerrwd(.LT.'LSODE-- MXSTEP (=I1) 0 ',
1451  1 30, 12, 0, 1, mxstep, 0, 0, 0.0d0, 0.0d0)
1452  go to 700
1453  613 CALL xerrwd(.LT.'LSODE-- MXHNIL (=I1) 0 ',
1454  1 30, 13, 0, 1, mxhnil, 0, 0, 0.0d0, 0.0d0)
1455  go to 700
1456  614 CALL xerrwd('LSODE-- TOUT (=R1) BEHIND T (=R2) ',
1457  1 40, 14, 0, 0, 0, 0, 2, tout, t)
1458  CALL xerrwd(' INTEGRATION DIRECTION IS GIVEN BY H0 (=R1) ',
1459  1 50, 14, 0, 0, 0, 0, 1, h0, 0.0d0)
1460  go to 700
1461  615 CALL xerrwd(.LT.'LSODE-- HMAX (=R1) 0.0 ',
1462  1 30, 15, 0, 0, 0, 0, 1, hmax, 0.0d0)
1463  go to 700
1464  616 CALL xerrwd(.LT.'LSODE-- HMIN (=R1) 0.0 ',
1465  1 30, 16, 0, 0, 0, 0, 1, hmin, 0.0d0)
1466  go to 700
1467  617 CALL xerrwd(
1468  1 'LSODE-- RWORK LENGTH NEEDED, LENRW (=I1), EXCEEDS LRW (=I2)',
1469  1 60, 17, 0, 2, lenrw, lrw, 0, 0.0d0, 0.0d0)
1470  go to 700
1471  618 CALL xerrwd(
1472  1 'LSODE-- IWORK LENGTH NEEDED, LENIW (=I1), EXCEEDS LIW (=I2)',
1473  1 60, 18, 0, 2, leniw, liw, 0, 0.0d0, 0.0d0)
1474  go to 700
1475  619 CALL xerrwd(.LT.'LSODE-- RTOL(I1) IS R1 0.0 ',
1476  1 40, 19, 0, 1, i, 0, 1, rtoli, 0.0d0)
1477  go to 700
1478  620 CALL xerrwd(.LT.'LSODE-- ATOL(I1) IS R1 0.0 ',
1479  1 40, 20, 0, 1, i, 0, 1, atoli, 0.0d0)
1480  go to 700
1481  621 ewti = rwork(lewt+i-1)
1482  CALL xerrwd(.LE.'LSODE-- EWT(I1) IS R1 0.0 ',
1483  1 40, 21, 0, 1, i, 0, 1, ewti, 0.0d0)
1484  go to 700
1485  622 CALL xerrwd(
1486  1 'LSODE-- TOUT (=R1) TOO CLOSE TO T(=R2) TO START INTEGRATION',
1487  1 60, 22, 0, 0, 0, 0, 2, tout, t)
1488  go to 700
1489  623 CALL xerrwd(
1490  1 'LSODE-- ITASK = I1 AND TOUT (=R1) BEHIND TCUR - HU (= R2) ',
1491  1 60, 23, 0, 1, itask, 0, 2, tout, tp)
1492  go to 700
1493  624 CALL xerrwd(
1494  1 'LSODE-- ITASK = 4 OR 5 AND TCRIT (=R1) BEHIND TCUR (=R2) ',
1495  1 60, 24, 0, 0, 0, 0, 2, tcrit, tn)
1496  go to 700
1497  625 CALL xerrwd(
1498  1 'LSODE-- ITASK = 4 OR 5 AND TCRIT (=R1) BEHIND TOUT (=R2) ',
1499  1 60, 25, 0, 0, 0, 0, 2, tcrit, tout)
1500  go to 700
1501  626 CALL xerrwd('LSODE-- AT START OF PROBLEM, TOO MUCH ACCURACY ',
1502  1 50, 26, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
1503  CALL xerrwd(
1504  1 ' REQUESTED FOR PRECISION OF MACHINE.. SEE TOLSF (=R1) ',
1505  1 60, 26, 0, 0, 0, 0, 1, tolsf, 0.0d0)
1506  rwork(14) = tolsf
1507  go to 700
1508  627 CALL xerrwd('LSODE-- TROUBLE FROM INTDY. ITASK = I1, TOUT = R1',
1509  1 50, 27, 0, 1, itask, 0, 1, tout, 0.0d0)
1510 C
1511  700 IF (illin .EQ. 5) go to 710
1512  illin = illin + 1
1513  istate = -3
1514  RETURN
1515  710 CALL xerrwd('LSODE-- REPEATED OCCURRENCES OF ILLEGAL INPUT ',
1516  1 50, 302, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
1517 C
1518  800 CALL xerrwd('LSODE-- RUN ABORTED.. APPARENT INFINITE LOOP ',
1519  1 50, 303, 2, 0, 0, 0, 0, 0.0d0, 0.0d0)
1520  RETURN
1521 C----------------------- END OF SUBROUTINE LSODE -----------------------
1522  END
subroutine prepj(NEQ, Y, YH, NYH, EWT, FTEM, SAVF, WM, IWM, F, JAC, IERR)
Definition: prepj.f:1
subroutine dlsode(F, NEQ, Y, T, TOUT, ITOL, RTOL, ATOL, ITASK, ISTATE, IOPT, RWORK, LRW, IWORK, LIW, JAC, MF)
Definition: dlsode.f:1
std::string dimension(void) const
subroutine xerrwd(MSG, NMES, NERR, LEVEL, NI, I1, I2, NR, R1, R2)
Definition: xerrwd.f:3
subroutine stode(NEQ, Y, YH, NYH, YH1, EWT, SAVF, ACOR, WM, IWM, F, JAC, PJAC, SLVS, IERR)
Definition: stode.f:1
F77_RET_T const double const double * f
size_t size(T const (&)[z])
Definition: help.cc:103
subroutine ewset(N, ITOL, RTOL, ATOL, YCUR, EWT)
Definition: ewset.f:1
subroutine intdy(T, K, YH, NYH, DKY, IFLAG)
Definition: intdy.f:1
subroutine solsy(WM, IWM, X, TEM)
Definition: solsy.f:1
double precision function vnorm(N, V, W)
Definition: vnorm.f:1