~ubuntu-branches/ubuntu/saucy/python-scipy/saucy

« back to all changes in this revision

Viewing changes to scipy/integrate/odepack/lsodes.f

  • Committer: Bazaar Package Importer
  • Author(s): Ondrej Certik
  • Date: 2008-06-16 22:58:01 UTC
  • mfrom: (2.1.24 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080616225801-irdhrpcwiocfbcmt
Tags: 0.6.0-12
* The description updated to match the current SciPy (Closes: #489149).
* Standards-Version bumped to 3.8.0 (no action needed)
* Build-Depends: netcdf-dev changed to libnetcdf-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
      subroutine lsodes (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(1), y(1), rtol(1), atol(1), rwork(lrw), iwork(liw)
 
7
c-----------------------------------------------------------------------
 
8
c this is the march 30, 1987 version of
 
9
c lsodes.. livermore solver for ordinary differential equations
 
10
c          with general sparse jacobian matrices.
 
11
c this version is in double precision.
 
12
c
 
13
c lsodes solves the initial value problem for stiff or nonstiff
 
14
c systems of first order ode-s,
 
15
c     dy/dt = f(t,y) ,  or, in component form,
 
16
c     dy(i)/dt = f(i) = f(i,t,y(1),y(2),...,y(neq)) (i = 1,...,neq).
 
17
c lsodes is a variant of the lsode package, and is intended for
 
18
c problems in which the jacobian matrix df/dy has an arbitrary
 
19
c sparse structure (when the problem is stiff).
 
20
c
 
21
c authors..      alan c. hindmarsh,
 
22
c                computing and mathematics research division, l-316
 
23
c                lawrence livermore national laboratory
 
24
c                livermore, ca 94550.
 
25
c
 
26
c and            andrew h. sherman
 
27
c                j. s. nolen and associates
 
28
c                houston, tx 77084
 
29
c-----------------------------------------------------------------------
 
30
c references..
 
31
c 1.  alan c. hindmarsh,  odepack, a systematized collection of ode
 
32
c     solvers, in scientific computing, r. s. stepleman et al. (eds.),
 
33
c     north-holland, amsterdam, 1983, pp. 55-64.
 
34
c
 
35
c 2.  s. c. eisenstat, m. c. gursky, m. h. schultz, and a. h. sherman,
 
36
c     yale sparse matrix package.. i. the symmetric codes,
 
37
c     int. j. num. meth. eng., 18 (1982), pp. 1145-1151.
 
38
c
 
39
c 3.  s. c. eisenstat, m. c. gursky, m. h. schultz, and a. h. sherman,
 
40
c     yale sparse matrix package.. ii. the nonsymmetric codes,
 
41
c     research report no. 114, dept. of computer sciences, yale
 
42
c     university, 1977.
 
43
c-----------------------------------------------------------------------
 
44
c summary of usage.
 
45
c
 
46
c communication between the user and the lsodes package, for normal
 
47
c situations, is summarized here.  this summary describes only a subset
 
48
c of the full set of options available.  see the full description for
 
49
c details, including optional communication, nonstandard options,
 
50
c and instructions for special situations.  see also the example
 
51
c problem (with program and output) following this summary.
 
52
c
 
53
c a. first provide a subroutine of the form..
 
54
c               subroutine f (neq, t, y, ydot)
 
55
c               dimension y(neq), ydot(neq)
 
56
c which supplies the vector function f by loading ydot(i) with f(i).
 
57
c
 
58
c b. next determine (or guess) whether or not the problem is stiff.
 
59
c stiffness occurs when the jacobian matrix df/dy has an eigenvalue
 
60
c whose real part is negative and large in magnitude, compared to the
 
61
c reciprocal of the t span of interest.  if the problem is nonstiff,
 
62
c use a method flag mf = 10.  if it is stiff, there are two standard
 
63
c for the method flag, mf = 121 and mf = 222.  in both cases, lsodes
 
64
c requires the jacobian matrix in some form, and it treats this matrix
 
65
c in general sparse form, with sparsity structure determined internally.
 
66
c (for options where the user supplies the sparsity structure, see
 
67
c the full description of mf below.)
 
68
c
 
69
c c. if the problem is stiff, you are encouraged to supply the jacobian
 
70
c directly (mf = 121), but if this is not feasible, lsodes will
 
71
c compute it internally by difference quotients (mf = 222).
 
72
c if you are supplying the jacobian, provide a subroutine of the form..
 
73
c               subroutine jac (neq, t, y, j, ian, jan, pdj)
 
74
c               dimension y(1), ian(1), jan(1), pdj(1)
 
75
c here neq, t, y, and j are input arguments, and the jac routine is to
 
76
c load the array pdj (of length neq) with the j-th column of df/dy.
 
77
c i.e., load pdj(i) with df(i)/dy(j) for all relevant values of i.
 
78
c the arguments ian and jan should be ignored for normal situations.
 
79
c lsodes will call the jac routine with j = 1,2,...,neq.
 
80
c only nonzero elements need be loaded.  usually, a crude approximation
 
81
c to df/dy, possibly with fewer nonzero elements, will suffice.
 
82
c
 
83
c d. write a main program which calls subroutine lsodes once for
 
84
c each point at which answers are desired.  this should also provide
 
85
c for possible use of logical unit 6 for output of error messages
 
86
c by lsodes.  on the first call to lsodes, supply arguments as follows..
 
87
c f      = name of subroutine for right-hand side vector f.
 
88
c          this name must be declared external in calling program.
 
89
c neq    = number of first order ode-s.
 
90
c y      = array of initial values, of length neq.
 
91
c t      = the initial value of the independent variable.
 
92
c tout   = first point where output is desired (.ne. t).
 
93
c itol   = 1 or 2 according as atol (below) is a scalar or array.
 
94
c rtol   = relative tolerance parameter (scalar).
 
95
c atol   = absolute tolerance parameter (scalar or array).
 
96
c          the estimated local error in y(i) will be controlled so as
 
97
c          to be roughly less (in magnitude) than
 
98
c             ewt(i) = rtol*abs(y(i)) + atol     if itol = 1, or
 
99
c             ewt(i) = rtol*abs(y(i)) + atol(i)  if itol = 2.
 
100
c          thus the local error test passes if, in each component,
 
101
c          either the absolute error is less than atol (or atol(i)),
 
102
c          or the relative error is less than rtol.
 
103
c          use rtol = 0.0 for pure absolute error control, and
 
104
c          use atol = 0.0 (or atol(i) = 0.0) for pure relative error
 
105
c          control.  caution.. actual (global) errors may exceed these
 
106
c          local tolerances, so choose them conservatively.
 
107
c itask  = 1 for normal computation of output values of y at t = tout.
 
108
c istate = integer flag (input and output).  set istate = 1.
 
109
c iopt   = 0 to indicate no optional inputs used.
 
110
c rwork  = real work array of length at least..
 
111
c             20 + 16*neq            for mf = 10,
 
112
c             20 + (2 + 1./lenrat)*nnz + (11 + 9./lenrat)*neq
 
113
c                                    for mf = 121 or 222,
 
114
c          where..
 
115
c          nnz    = the number of nonzero elements in the sparse
 
116
c                   jacobian (if this is unknown, use an estimate), and
 
117
c          lenrat = the real to integer wordlength ratio (usually 1 in
 
118
c                   single precision and 2 in double precision).
 
119
c          in any case, the required size of rwork cannot generally
 
120
c          be predicted in advance if mf = 121 or 222, and the value
 
121
c          above is a rough estimate of a crude lower bound.  some
 
122
c          experimentation with this size may be necessary.
 
123
c          (when known, the correct required length is an optional
 
124
c          output, available in iwork(17).)
 
125
c lrw    = declared length of rwork (in user-s dimension).
 
126
c iwork  = integer work array of length at least 30.
 
127
c liw    = declared length of iwork (in user-s dimension).
 
128
c jac    = name of subroutine for jacobian matrix (mf = 121).
 
129
c          if used, this name must be declared external in calling
 
130
c          program.  if not used, pass a dummy name.
 
131
c mf     = method flag.  standard values are..
 
132
c          10  for nonstiff (adams) method, no jacobian used.
 
133
c          121 for stiff (bdf) method, user-supplied sparse jacobian.
 
134
c          222 for stiff method, internally generated sparse jacobian.
 
135
c note that the main program must declare arrays y, rwork, iwork,
 
136
c and possibly atol.
 
137
c
 
138
c e. the output from the first call (or any call) is..
 
139
c      y = array of computed values of y(t) vector.
 
140
c      t = corresponding value of independent variable (normally tout).
 
141
c istate = 2  if lsodes was successful, negative otherwise.
 
142
c          -1 means excess work done on this call (perhaps wrong mf).
 
143
c          -2 means excess accuracy requested (tolerances too small).
 
144
c          -3 means illegal input detected (see printed message).
 
145
c          -4 means repeated error test failures (check all inputs).
 
146
c          -5 means repeated convergence failures (perhaps bad jacobian
 
147
c             supplied or wrong choice of mf or tolerances).
 
148
c          -6 means error weight became zero during problem. (solution
 
149
c             component i vanished, and atol or atol(i) = 0.)
 
150
c          -7 means a fatal error return flag came from the sparse
 
151
c             solver cdrv by way of prjs or slss.  should never happen.
 
152
c          a return with istate = -1, -4, or -5 may result from using
 
153
c          an inappropriate sparsity structure, one that is quite
 
154
c          different from the initial structure.  consider calling
 
155
c          lsodes again with istate = 3 to force the structure to be
 
156
c          reevaluated.  see the full description of istate below.
 
157
c
 
158
c f. to continue the integration after a successful return, simply
 
159
c reset tout and call lsodes again.  no other parameters need be reset.
 
160
c
 
161
c-----------------------------------------------------------------------
 
162
c example problem.
 
163
c
 
164
c the following is a simple example problem, with the coding
 
165
c needed for its solution by lsodes.  the problem is from chemical
 
166
c kinetics, and consists of the following 12 rate equations..
 
167
c    dy1/dt  = -rk1*y1
 
168
c    dy2/dt  = rk1*y1 + rk11*rk14*y4 + rk19*rk14*y5
 
169
c                - rk3*y2*y3 - rk15*y2*y12 - rk2*y2
 
170
c    dy3/dt  = rk2*y2 - rk5*y3 - rk3*y2*y3 - rk7*y10*y3
 
171
c                + rk11*rk14*y4 + rk12*rk14*y6
 
172
c    dy4/dt  = rk3*y2*y3 - rk11*rk14*y4 - rk4*y4
 
173
c    dy5/dt  = rk15*y2*y12 - rk19*rk14*y5 - rk16*y5
 
174
c    dy6/dt  = rk7*y10*y3 - rk12*rk14*y6 - rk8*y6
 
175
c    dy7/dt  = rk17*y10*y12 - rk20*rk14*y7 - rk18*y7
 
176
c    dy8/dt  = rk9*y10 - rk13*rk14*y8 - rk10*y8
 
177
c    dy9/dt  = rk4*y4 + rk16*y5 + rk8*y6 + rk18*y7
 
178
c    dy10/dt = rk5*y3 + rk12*rk14*y6 + rk20*rk14*y7
 
179
c                + rk13*rk14*y8 - rk7*y10*y3 - rk17*y10*y12
 
180
c                - rk6*y10 - rk9*y10
 
181
c    dy11/dt = rk10*y8
 
182
c    dy12/dt = rk6*y10 + rk19*rk14*y5 + rk20*rk14*y7
 
183
c                - rk15*y2*y12 - rk17*y10*y12
 
184
c
 
185
c with rk1 = rk5 = 0.1,  rk4 = rk8 = rk16 = rk18 = 2.5,
 
186
c      rk10 = 5.0,  rk2 = rk6 = 10.0,  rk14 = 30.0,
 
187
c      rk3 = rk7 = rk9 = rk11 = rk12 = rk13 = rk19 = rk20 = 50.0,
 
188
c      rk15 = rk17 = 100.0.
 
189
c
 
190
c the t interval is from 0 to 1000, and the initial conditions
 
191
c are y1 = 1, y2 = y3 = ... = y12 = 0.  the problem is stiff.
 
192
c
 
193
c the following coding solves this problem with lsodes, using mf = 121
 
194
c and printing results at t = .1, 1., 10., 100., 1000.  it uses
 
195
c itol = 1 and mixed relative/absolute tolerance controls.
 
196
c during the run and at the end, statistical quantities of interest
 
197
c are printed (see optional outputs in the full description below).
 
198
c
 
199
c     external fex, jex
 
200
c     double precision atol, rtol, rwork, t, tout, y
 
201
c     dimension y(12), rwork(500), iwork(30)
 
202
c     data lrw/500/, liw/30/
 
203
c     neq = 12
 
204
c     do 10 i = 1,neq
 
205
c 10    y(i) = 0.0d0
 
206
c     y(1) = 1.0d0
 
207
c     t = 0.0d0
 
208
c     tout = 0.1d0
 
209
c     itol = 1
 
210
c     rtol = 1.0d-4
 
211
c     atol = 1.0d-6
 
212
c     itask = 1
 
213
c     istate = 1
 
214
c     iopt = 0
 
215
c     mf = 121
 
216
c     do 40 iout = 1,5
 
217
c       call lsodes (fex, neq, y, t, tout, itol, rtol, atol,
 
218
c    1     itask, istate, iopt, rwork, lrw, iwork, liw, jex, mf)
 
219
c       write(6,30)t,iwork(11),rwork(11),(y(i),i=1,neq)
 
220
c 30    format(//' at t =',e11.3,4x,
 
221
c    1    ' no. steps =',i5,4x,' last step =',e11.3/
 
222
c    2    '  y array =  ',4e14.5/13x,4e14.5/13x,4e14.5)
 
223
c       if (istate .lt. 0) go to 80
 
224
c       tout = tout*10.0d0
 
225
c 40    continue
 
226
c     lenrw = iwork(17)
 
227
c     leniw = iwork(18)
 
228
c     nst = iwork(11)
 
229
c     nfe = iwork(12)
 
230
c     nje = iwork(13)
 
231
c     nlu = iwork(21)
 
232
c     nnz = iwork(19)
 
233
c     nnzlu = iwork(25) + iwork(26) + neq
 
234
c     write (6,70) lenrw,leniw,nst,nfe,nje,nlu,nnz,nnzlu
 
235
c 70  format(//' required rwork size =',i4,'   iwork size =',i4/
 
236
c    1   ' no. steps =',i4,'   no. f-s =',i4,'   no. j-s =',i4,
 
237
c    2   '   no. lu-s =',i4/' no. of nonzeros in j =',i5,
 
238
c    3   '   no. of nonzeros in lu =',i5)
 
239
c     stop
 
240
c 80  write(6,90)istate
 
241
c 90  format(///' error halt.. istate =',i3)
 
242
c     stop
 
243
c     end
 
244
c
 
245
c     subroutine fex (neq, t, y, ydot)
 
246
c     double precision t, y, ydot
 
247
c     double precision rk1, rk2, rk3, rk4, rk5, rk6, rk7, rk8, rk9,
 
248
c    1   rk10, rk11, rk12, rk13, rk14, rk15, rk16, rk17
 
249
c     dimension y(12), ydot(12)
 
250
c     data rk1/0.1d0/, rk2/10.0d0/, rk3/50.0d0/, rk4/2.5d0/, rk5/0.1d0/,
 
251
c    1   rk6/10.0d0/, rk7/50.0d0/, rk8/2.5d0/, rk9/50.0d0/, rk10/5.0d0/,
 
252
c    2   rk11/50.0d0/, rk12/50.0d0/, rk13/50.0d0/, rk14/30.0d0/,
 
253
c    3   rk15/100.0d0/, rk16/2.5d0/, rk17/100.0d0/, rk18/2.5d0/,
 
254
c    4   rk19/50.0d0/, rk20/50.0d0/
 
255
c     ydot(1)  = -rk1*y(1)
 
256
c     ydot(2)  = rk1*y(1) + rk11*rk14*y(4) + rk19*rk14*y(5)
 
257
c    1           - rk3*y(2)*y(3) - rk15*y(2)*y(12) - rk2*y(2)
 
258
c     ydot(3)  = rk2*y(2) - rk5*y(3) - rk3*y(2)*y(3) - rk7*y(10)*y(3)
 
259
c    1           + rk11*rk14*y(4) + rk12*rk14*y(6)
 
260
c     ydot(4)  = rk3*y(2)*y(3) - rk11*rk14*y(4) - rk4*y(4)
 
261
c     ydot(5)  = rk15*y(2)*y(12) - rk19*rk14*y(5) - rk16*y(5)
 
262
c     ydot(6)  = rk7*y(10)*y(3) - rk12*rk14*y(6) - rk8*y(6)
 
263
c     ydot(7)  = rk17*y(10)*y(12) - rk20*rk14*y(7) - rk18*y(7)
 
264
c     ydot(8)  = rk9*y(10) - rk13*rk14*y(8) - rk10*y(8)
 
265
c     ydot(9)  = rk4*y(4) + rk16*y(5) + rk8*y(6) + rk18*y(7)
 
266
c     ydot(10) = rk5*y(3) + rk12*rk14*y(6) + rk20*rk14*y(7)
 
267
c    1           + rk13*rk14*y(8) - rk7*y(10)*y(3) - rk17*y(10)*y(12)
 
268
c    2           - rk6*y(10) - rk9*y(10)
 
269
c     ydot(11) = rk10*y(8)
 
270
c     ydot(12) = rk6*y(10) + rk19*rk14*y(5) + rk20*rk14*y(7)
 
271
c    1           - rk15*y(2)*y(12) - rk17*y(10)*y(12)
 
272
c     return
 
273
c     end
 
274
c
 
275
c     subroutine jex (neq, t, y, j, ia, ja, pdj)
 
276
c     double precision t, y, pdj
 
277
c     double precision rk1, rk2, rk3, rk4, rk5, rk6, rk7, rk8, rk9,
 
278
c    1   rk10, rk11, rk12, rk13, rk14, rk15, rk16, rk17
 
279
c     dimension y(1), ia(1), ja(1), pdj(1)
 
280
c     data rk1/0.1d0/, rk2/10.0d0/, rk3/50.0d0/, rk4/2.5d0/, rk5/0.1d0/,
 
281
c    1   rk6/10.0d0/, rk7/50.0d0/, rk8/2.5d0/, rk9/50.0d0/, rk10/5.0d0/,
 
282
c    2   rk11/50.0d0/, rk12/50.0d0/, rk13/50.0d0/, rk14/30.0d0/,
 
283
c    3   rk15/100.0d0/, rk16/2.5d0/, rk17/100.0d0/, rk18/2.5d0/,
 
284
c    4   rk19/50.0d0/, rk20/50.0d0/
 
285
c     go to (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), j
 
286
c 1   pdj(1) = -rk1
 
287
c     pdj(2) = rk1
 
288
c     return
 
289
c 2   pdj(2) = -rk3*y(3) - rk15*y(12) - rk2
 
290
c     pdj(3) = rk2 - rk3*y(3)
 
291
c     pdj(4) = rk3*y(3)
 
292
c     pdj(5) = rk15*y(12)
 
293
c     pdj(12) = -rk15*y(12)
 
294
c     return
 
295
c 3   pdj(2) = -rk3*y(2)
 
296
c     pdj(3) = -rk5 - rk3*y(2) - rk7*y(10)
 
297
c     pdj(4) = rk3*y(2)
 
298
c     pdj(6) = rk7*y(10)
 
299
c     pdj(10) = rk5 - rk7*y(10)
 
300
c     return
 
301
c 4   pdj(2) = rk11*rk14
 
302
c     pdj(3) = rk11*rk14
 
303
c     pdj(4) = -rk11*rk14 - rk4
 
304
c     pdj(9) = rk4
 
305
c     return
 
306
c 5   pdj(2) = rk19*rk14
 
307
c     pdj(5) = -rk19*rk14 - rk16
 
308
c     pdj(9) = rk16
 
309
c     pdj(12) = rk19*rk14
 
310
c     return
 
311
c 6   pdj(3) = rk12*rk14
 
312
c     pdj(6) = -rk12*rk14 - rk8
 
313
c     pdj(9) = rk8
 
314
c     pdj(10) = rk12*rk14
 
315
c     return
 
316
c 7   pdj(7) = -rk20*rk14 - rk18
 
317
c     pdj(9) = rk18
 
318
c     pdj(10) = rk20*rk14
 
319
c     pdj(12) = rk20*rk14
 
320
c     return
 
321
c 8   pdj(8) = -rk13*rk14 - rk10
 
322
c     pdj(10) = rk13*rk14
 
323
c     pdj(11) = rk10
 
324
c 9   return
 
325
c 10  pdj(3) = -rk7*y(3)
 
326
c     pdj(6) = rk7*y(3)
 
327
c     pdj(7) = rk17*y(12)
 
328
c     pdj(8) = rk9
 
329
c     pdj(10) = -rk7*y(3) - rk17*y(12) - rk6 - rk9
 
330
c     pdj(12) = rk6 - rk17*y(12)
 
331
c 11  return
 
332
c 12  pdj(2) = -rk15*y(2)
 
333
c     pdj(5) = rk15*y(2)
 
334
c     pdj(7) = rk17*y(10)
 
335
c     pdj(10) = -rk17*y(10)
 
336
c     pdj(12) = -rk15*y(2) - rk17*y(10)
 
337
c     return
 
338
c     end
 
339
c
 
340
c the output of this program (on a cray-1 in single precision)
 
341
c is as follows..
 
342
c
 
343
c
 
344
c at t =  1.000e-01     no. steps =   12     last step =  1.515e-02
 
345
c  y array =     9.90050e-01   6.28228e-03   3.65313e-03   7.51934e-07
 
346
c                1.12167e-09   1.18458e-09   1.77291e-12   3.26476e-07
 
347
c                5.46720e-08   9.99500e-06   4.48483e-08   2.76398e-06
 
348
c
 
349
c
 
350
c at t =  1.000e+00     no. steps =   33     last step =  7.880e-02
 
351
c  y array =     9.04837e-01   9.13105e-03   8.20622e-02   2.49177e-05
 
352
c                1.85055e-06   1.96797e-06   1.46157e-07   2.39557e-05
 
353
c                3.26306e-05   7.21621e-04   5.06433e-05   3.05010e-03
 
354
c
 
355
c
 
356
c at t =  1.000e+01     no. steps =   48     last step =  1.239e+00
 
357
c  y array =     3.67876e-01   3.68958e-03   3.65133e-01   4.48325e-05
 
358
c                6.10798e-05   4.33148e-05   5.90211e-05   1.18449e-04
 
359
c                3.15235e-03   3.56531e-03   4.15520e-03   2.48741e-01
 
360
c
 
361
c
 
362
c at t =  1.000e+02     no. steps =   91     last step =  3.764e+00
 
363
c  y array =     4.44981e-05   4.42666e-07   4.47273e-04  -3.53257e-11
 
364
c                2.81577e-08  -9.67741e-11   2.77615e-07   1.45322e-07
 
365
c                1.56230e-02   4.37394e-06   1.60104e-02   9.52246e-01
 
366
c
 
367
c
 
368
c at t =  1.000e+03     no. steps =  111     last step =  4.156e+02
 
369
c  y array =    -2.65492e-13   2.60539e-14  -8.59563e-12   6.29355e-14
 
370
c               -1.78066e-13   5.71471e-13  -1.47561e-12   4.58078e-15
 
371
c                1.56314e-02   1.37878e-13   1.60184e-02   9.52719e-01
 
372
c
 
373
c
 
374
c required rwork size = 442   iwork size =  30
 
375
c no. steps = 111   no. f-s = 142   no. j-s =   2   no. lu-s =  20
 
376
c no. of nonzeros in j =   44   no. of nonzeros in lu =   50
 
377
c-----------------------------------------------------------------------
 
378
c full description of user interface to lsodes.
 
379
c
 
380
c the user interface to lsodes consists of the following parts.
 
381
c
 
382
c i.   the call sequence to subroutine lsodes, which is a driver
 
383
c      routine for the solver.  this includes descriptions of both
 
384
c      the call sequence arguments and of user-supplied routines.
 
385
c      following these descriptions is a description of
 
386
c      optional inputs available through the call sequence, and then
 
387
c      a description of optional outputs (in the work arrays).
 
388
c
 
389
c ii.  descriptions of other routines in the lsodes package that may be
 
390
c      (optionally) called by the user.  these provide the ability to
 
391
c      alter error message handling, save and restore the internal
 
392
c      common, and obtain specified derivatives of the solution y(t).
 
393
c
 
394
c iii. descriptions of common blocks to be declared in overlay
 
395
c      or similar environments, or to be saved when doing an interrupt
 
396
c      of the problem and continued solution later.
 
397
c
 
398
c iv.  description of two routines in the lsodes package, either of
 
399
c      which the user may replace with his own version, if desired.
 
400
c      these relate to the measurement of errors.
 
401
c
 
402
c-----------------------------------------------------------------------
 
403
c part i.  call sequence.
 
404
c
 
405
c the call sequence parameters used for input only are
 
406
c     f, neq, tout, itol, rtol, atol, itask, iopt, lrw, liw, jac, mf,
 
407
c and those used for both input and output are
 
408
c     y, t, istate.
 
409
c the work arrays rwork and iwork are also used for conditional and
 
410
c optional inputs and optional outputs.  (the term output here refers
 
411
c to the return from subroutine lsodes to the user-s calling program.)
 
412
c
 
413
c the legality of input parameters will be thoroughly checked on the
 
414
c initial call for the problem, but not checked thereafter unless a
 
415
c change in input parameters is flagged by istate = 3 on input.
 
416
c
 
417
c the descriptions of the call arguments are as follows.
 
418
c
 
419
c f      = the name of the user-supplied subroutine defining the
 
420
c          ode system.  the system must be put in the first-order
 
421
c          form dy/dt = f(t,y), where f is a vector-valued function
 
422
c          of the scalar t and the vector y.  subroutine f is to
 
423
c          compute the function f.  it is to have the form
 
424
c               subroutine f (neq, t, y, ydot)
 
425
c               dimension y(1), ydot(1)
 
426
c          where neq, t, and y are input, and the array ydot = f(t,y)
 
427
c          is output.  y and ydot are arrays of length neq.
 
428
c          (in the dimension statement above, 1 is a dummy
 
429
c          dimension.. it can be replaced by any value.)
 
430
c          subroutine f should not alter y(1),...,y(neq).
 
431
c          f must be declared external in the calling program.
 
432
c
 
433
c          subroutine f may access user-defined quantities in
 
434
c          neq(2),... and/or in y(neq(1)+1),... if neq is an array
 
435
c          (dimensioned in f) and/or y has length exceeding neq(1).
 
436
c          see the descriptions of neq and y below.
 
437
c
 
438
c          if quantities computed in the f routine are needed
 
439
c          externally to lsodes, an extra call to f should be made
 
440
c          for this purpose, for consistent and accurate results.
 
441
c          if only the derivative dy/dt is needed, use intdy instead.
 
442
c
 
443
c neq    = the size of the ode system (number of first order
 
444
c          ordinary differential equations).  used only for input.
 
445
c          neq may be decreased, but not increased, during the problem.
 
446
c          if neq is decreased (with istate = 3 on input), the
 
447
c          remaining components of y should be left undisturbed, if
 
448
c          these are to be accessed in f and/or jac.
 
449
c
 
450
c          normally, neq is a scalar, and it is generally referred to
 
451
c          as a scalar in this user interface description.  however,
 
452
c          neq may be an array, with neq(1) set to the system size.
 
453
c          (the lsodes package accesses only neq(1).)  in either case,
 
454
c          this parameter is passed as the neq argument in all calls
 
455
c          to f and jac.  hence, if it is an array, locations
 
456
c          neq(2),... may be used to store other integer data and pass
 
457
c          it to f and/or jac.  subroutines f and/or jac must include
 
458
c          neq in a dimension statement in that case.
 
459
c
 
460
c y      = a real array for the vector of dependent variables, of
 
461
c          length neq or more.  used for both input and output on the
 
462
c          first call (istate = 1), and only for output on other calls.
 
463
c          on the first call, y must contain the vector of initial
 
464
c          values.  on output, y contains the computed solution vector,
 
465
c          evaluated at t.  if desired, the y array may be used
 
466
c          for other purposes between calls to the solver.
 
467
c
 
468
c          this array is passed as the y argument in all calls to
 
469
c          f and jac.  hence its length may exceed neq, and locations
 
470
c          y(neq+1),... may be used to store other real data and
 
471
c          pass it to f and/or jac.  (the lsodes package accesses only
 
472
c          y(1),...,y(neq).)
 
473
c
 
474
c t      = the independent variable.  on input, t is used only on the
 
475
c          first call, as the initial point of the integration.
 
476
c          on output, after each call, t is the value at which a
 
477
c          computed solution y is evaluated (usually the same as tout).
 
478
c          on an error return, t is the farthest point reached.
 
479
c
 
480
c tout   = the next value of t at which a computed solution is desired.
 
481
c          used only for input.
 
482
c
 
483
c          when starting the problem (istate = 1), tout may be equal
 
484
c          to t for one call, then should .ne. t for the next call.
 
485
c          for the initial t, an input value of tout .ne. t is used
 
486
c          in order to determine the direction of the integration
 
487
c          (i.e. the algebraic sign of the step sizes) and the rough
 
488
c          scale of the problem.  integration in either direction
 
489
c          (forward or backward in t) is permitted.
 
490
c
 
491
c          if itask = 2 or 5 (one-step modes), tout is ignored after
 
492
c          the first call (i.e. the first call with tout .ne. t).
 
493
c          otherwise, tout is required on every call.
 
494
c
 
495
c          if itask = 1, 3, or 4, the values of tout need not be
 
496
c          monotone, but a value of tout which backs up is limited
 
497
c          to the current internal t interval, whose endpoints are
 
498
c          tcur - hu and tcur (see optional outputs, below, for
 
499
c          tcur and hu).
 
500
c
 
501
c itol   = an indicator for the type of error control.  see
 
502
c          description below under atol.  used only for input.
 
503
c
 
504
c rtol   = a relative error tolerance parameter, either a scalar or
 
505
c          an array of length neq.  see description below under atol.
 
506
c          input only.
 
507
c
 
508
c atol   = an absolute error tolerance parameter, either a scalar or
 
509
c          an array of length neq.  input only.
 
510
c
 
511
c             the input parameters itol, rtol, and atol determine
 
512
c          the error control performed by the solver.  the solver will
 
513
c          control the vector e = (e(i)) of estimated local errors
 
514
c          in y, according to an inequality of the form
 
515
c                      rms-norm of ( e(i)/ewt(i) )   .le.   1,
 
516
c          where       ewt(i) = rtol(i)*abs(y(i)) + atol(i),
 
517
c          and the rms-norm (root-mean-square norm) here is
 
518
c          rms-norm(v) = sqrt(sum v(i)**2 / neq).  here ewt = (ewt(i))
 
519
c          is a vector of weights which must always be positive, and
 
520
c          the values of rtol and atol should all be non-negative.
 
521
c          the following table gives the types (scalar/array) of
 
522
c          rtol and atol, and the corresponding form of ewt(i).
 
523
c
 
524
c             itol    rtol       atol          ewt(i)
 
525
c              1     scalar     scalar     rtol*abs(y(i)) + atol
 
526
c              2     scalar     array      rtol*abs(y(i)) + atol(i)
 
527
c              3     array      scalar     rtol(i)*abs(y(i)) + atol
 
528
c              4     array      array      rtol(i)*abs(y(i)) + atol(i)
 
529
c
 
530
c          when either of these parameters is a scalar, it need not
 
531
c          be dimensioned in the user-s calling program.
 
532
c
 
533
c          if none of the above choices (with itol, rtol, and atol
 
534
c          fixed throughout the problem) is suitable, more general
 
535
c          error controls can be obtained by substituting
 
536
c          user-supplied routines for the setting of ewt and/or for
 
537
c          the norm calculation.  see part iv below.
 
538
c
 
539
c          if global errors are to be estimated by making a repeated
 
540
c          run on the same problem with smaller tolerances, then all
 
541
c          components of rtol and atol (i.e. of ewt) should be scaled
 
542
c          down uniformly.
 
543
c
 
544
c itask  = an index specifying the task to be performed.
 
545
c          input only.  itask has the following values and meanings.
 
546
c          1  means normal computation of output values of y(t) at
 
547
c             t = tout (by overshooting and interpolating).
 
548
c          2  means take one step only and return.
 
549
c          3  means stop at the first internal mesh point at or
 
550
c             beyond t = tout and return.
 
551
c          4  means normal computation of output values of y(t) at
 
552
c             t = tout but without overshooting t = tcrit.
 
553
c             tcrit must be input as rwork(1).  tcrit may be equal to
 
554
c             or beyond tout, but not behind it in the direction of
 
555
c             integration.  this option is useful if the problem
 
556
c             has a singularity at or beyond t = tcrit.
 
557
c          5  means take one step, without passing tcrit, and return.
 
558
c             tcrit must be input as rwork(1).
 
559
c
 
560
c          note..  if itask = 4 or 5 and the solver reaches tcrit
 
561
c          (within roundoff), it will return t = tcrit (exactly) to
 
562
c          indicate this (unless itask = 4 and tout comes before tcrit,
 
563
c          in which case answers at t = tout are returned first).
 
564
c
 
565
c istate = an index used for input and output to specify the
 
566
c          the state of the calculation.
 
567
c
 
568
c          on input, the values of istate are as follows.
 
569
c          1  means this is the first call for the problem
 
570
c             (initializations will be done).  see note below.
 
571
c          2  means this is not the first call, and the calculation
 
572
c             is to continue normally, with no change in any input
 
573
c             parameters except possibly tout and itask.
 
574
c             (if itol, rtol, and/or atol are changed between calls
 
575
c             with istate = 2, the new values will be used but not
 
576
c             tested for legality.)
 
577
c          3  means this is not the first call, and the
 
578
c             calculation is to continue normally, but with
 
579
c             a change in input parameters other than
 
580
c             tout and itask.  changes are allowed in
 
581
c             neq, itol, rtol, atol, iopt, lrw, liw, mf,
 
582
c             the conditional inputs ia and ja,
 
583
c             and any of the optional inputs except h0.
 
584
c             in particular, if miter = 1 or 2, a call with istate = 3
 
585
c             will cause the sparsity structure of the problem to be
 
586
c             recomputed (or reread from ia and ja if moss = 0).
 
587
c          note..  a preliminary call with tout = t is not counted
 
588
c          as a first call here, as no initialization or checking of
 
589
c          input is done.  (such a call is sometimes useful for the
 
590
c          purpose of outputting the initial conditions.)
 
591
c          thus the first call for which tout .ne. t requires
 
592
c          istate = 1 on input.
 
593
c
 
594
c          on output, istate has the following values and meanings.
 
595
c           1  means nothing was done, as tout was equal to t with
 
596
c              istate = 1 on input.  (however, an internal counter was
 
597
c              set to detect and prevent repeated calls of this type.)
 
598
c           2  means the integration was performed successfully.
 
599
c          -1  means an excessive amount of work (more than mxstep
 
600
c              steps) was done on this call, before completing the
 
601
c              requested task, but the integration was otherwise
 
602
c              successful as far as t.  (mxstep is an optional input
 
603
c              and is normally 500.)  to continue, the user may
 
604
c              simply reset istate to a value .gt. 1 and call again
 
605
c              (the excess work step counter will be reset to 0).
 
606
c              in addition, the user may increase mxstep to avoid
 
607
c              this error return (see below on optional inputs).
 
608
c          -2  means too much accuracy was requested for the precision
 
609
c              of the machine being used.  this was detected before
 
610
c              completing the requested task, but the integration
 
611
c              was successful as far as t.  to continue, the tolerance
 
612
c              parameters must be reset, and istate must be set
 
613
c              to 3.  the optional output tolsf may be used for this
 
614
c              purpose.  (note.. if this condition is detected before
 
615
c              taking any steps, then an illegal input return
 
616
c              (istate = -3) occurs instead.)
 
617
c          -3  means illegal input was detected, before taking any
 
618
c              integration steps.  see written message for details.
 
619
c              note..  if the solver detects an infinite loop of calls
 
620
c              to the solver with illegal input, it will cause
 
621
c              the run to stop.
 
622
c          -4  means there were repeated error test failures on
 
623
c              one attempted step, before completing the requested
 
624
c              task, but the integration was successful as far as t.
 
625
c              the problem may have a singularity, or the input
 
626
c              may be inappropriate.
 
627
c          -5  means there were repeated convergence test failures on
 
628
c              one attempted step, before completing the requested
 
629
c              task, but the integration was successful as far as t.
 
630
c              this may be caused by an inaccurate jacobian matrix,
 
631
c              if one is being used.
 
632
c          -6  means ewt(i) became zero for some i during the
 
633
c              integration.  pure relative error control (atol(i)=0.0)
 
634
c              was requested on a variable which has now vanished.
 
635
c              the integration was successful as far as t.
 
636
c          -7  means a fatal error return flag came from the sparse
 
637
c              solver cdrv by way of prjs or slss (numerical
 
638
c              factorization or backsolve).  this should never happen.
 
639
c              the integration was successful as far as t.
 
640
c
 
641
c          note.. an error return with istate = -1, -4, or -5 and with
 
642
c          miter = 1 or 2 may mean that the sparsity structure of the
 
643
c          problem has changed significantly since it was last
 
644
c          determined (or input).  in that case, one can attempt to
 
645
c          complete the integration by setting istate = 3 on the next
 
646
c          call, so that a new structure determination is done.
 
647
c
 
648
c          note..  since the normal output value of istate is 2,
 
649
c          it does not need to be reset for normal continuation.
 
650
c          also, since a negative input value of istate will be
 
651
c          regarded as illegal, a negative output value requires the
 
652
c          user to change it, and possibly other inputs, before
 
653
c          calling the solver again.
 
654
c
 
655
c iopt   = an integer flag to specify whether or not any optional
 
656
c          inputs are being used on this call.  input only.
 
657
c          the optional inputs are listed separately below.
 
658
c          iopt = 0 means no optional inputs are being used.
 
659
c                   default values will be used in all cases.
 
660
c          iopt = 1 means one or more optional inputs are being used.
 
661
c
 
662
c rwork  = a work array used for a mixture of real (double precision)
 
663
c          and integer work space.
 
664
c          the length of rwork (in real words) must be at least
 
665
c             20 + nyh*(maxord + 1) + 3*neq + lwm    where
 
666
c          nyh    = the initial value of neq,
 
667
c          maxord = 12 (if meth = 1) or 5 (if meth = 2) (unless a
 
668
c                   smaller value is given as an optional input),
 
669
c          lwm = 0                                    if miter = 0,
 
670
c          lwm = 2*nnz + 2*neq + (nnz+9*neq)/lenrat   if miter = 1,
 
671
c          lwm = 2*nnz + 2*neq + (nnz+10*neq)/lenrat  if miter = 2,
 
672
c          lwm = neq + 2                              if miter = 3.
 
673
c          in the above formulas,
 
674
c          nnz    = number of nonzero elements in the jacobian matrix.
 
675
c          lenrat = the real to integer wordlength ratio (usually 1 in
 
676
c                   single precision and 2 in double precision).
 
677
c          (see the mf description for meth and miter.)
 
678
c          thus if maxord has its default value and neq is constant,
 
679
c          the minimum length of rwork is..
 
680
c             20 + 16*neq        for mf = 10,
 
681
c             20 + 16*neq + lwm  for mf = 11, 111, 211, 12, 112, 212,
 
682
c             22 + 17*neq        for mf = 13,
 
683
c             20 +  9*neq        for mf = 20,
 
684
c             20 +  9*neq + lwm  for mf = 21, 121, 221, 22, 122, 222,
 
685
c             22 + 10*neq        for mf = 23.
 
686
c          if miter = 1 or 2, the above formula for lwm is only a
 
687
c          crude lower bound.  the required length of rwork cannot
 
688
c          be readily predicted in general, as it depends on the
 
689
c          sparsity structure of the problem.  some experimentation
 
690
c          may be necessary.
 
691
c
 
692
c          the first 20 words of rwork are reserved for conditional
 
693
c          and optional inputs and optional outputs.
 
694
c
 
695
c          the following word in rwork is a conditional input..
 
696
c            rwork(1) = tcrit = critical value of t which the solver
 
697
c                       is not to overshoot.  required if itask is
 
698
c                       4 or 5, and ignored otherwise.  (see itask.)
 
699
c
 
700
c lrw    = the length of the array rwork, as declared by the user.
 
701
c          (this will be checked by the solver.)
 
702
c
 
703
c iwork  = an integer work array.  the length of iwork must be at least
 
704
c             31 + neq + nnz   if moss = 0 and miter = 1 or 2, or
 
705
c             30               otherwise.
 
706
c          (nnz is the number of nonzero elements in df/dy.)
 
707
c
 
708
c          in lsodes, iwork is used only for conditional and
 
709
c          optional inputs and optional outputs.
 
710
c
 
711
c          the following two blocks of words in iwork are conditional
 
712
c          inputs, required if moss = 0 and miter = 1 or 2, but not
 
713
c          otherwise (see the description of mf for moss).
 
714
c            iwork(30+j) = ia(j)     (j=1,...,neq+1)
 
715
c            iwork(31+neq+k) = ja(k) (k=1,...,nnz)
 
716
c          the two arrays ia and ja describe the sparsity structure
 
717
c          to be assumed for the jacobian matrix.  ja contains the row
 
718
c          indices where nonzero elements occur, reading in columnwise
 
719
c          order, and ia contains the starting locations in ja of the
 
720
c          descriptions of columns 1,...,neq, in that order, with
 
721
c          ia(1) = 1.  thus, for each column index j = 1,...,neq, the
 
722
c          values of the row index i in column j where a nonzero
 
723
c          element may occur are given by
 
724
c            i = ja(k),  where   ia(j) .le. k .lt. ia(j+1).
 
725
c          if nnz is the total number of nonzero locations assumed,
 
726
c          then the length of the ja array is nnz, and ia(neq+1) must
 
727
c          be nnz + 1.  duplicate entries are not allowed.
 
728
c
 
729
c liw    = the length of the array iwork, as declared by the user.
 
730
c          (this will be checked by the solver.)
 
731
c
 
732
c note..  the work arrays must not be altered between calls to lsodes
 
733
c for the same problem, except possibly for the conditional and
 
734
c optional inputs, and except for the last 3*neq words of rwork.
 
735
c the latter space is used for internal scratch space, and so is
 
736
c available for use by the user outside lsodes between calls, if
 
737
c desired (but not for use by f or jac).
 
738
c
 
739
c jac    = name of user-supplied routine (miter = 1 or moss = 1) to
 
740
c          compute the jacobian matrix, df/dy, as a function of
 
741
c          the scalar t and the vector y.  it is to have the form
 
742
c               subroutine jac (neq, t, y, j, ian, jan, pdj)
 
743
c               dimension y(1), ian(1), jan(1), pdj(1)
 
744
c          where neq, t, y, j, ian, and jan are input, and the array
 
745
c          pdj, of length neq, is to be loaded with column j
 
746
c          of the jacobian on output.  thus df(i)/dy(j) is to be
 
747
c          loaded into pdj(i) for all relevant values of i.
 
748
c          here t and y have the same meaning as in subroutine f,
 
749
c          and j is a column index (1 to neq).  ian and jan are
 
750
c          undefined in calls to jac for structure determination
 
751
c          (moss = 1).  otherwise, ian and jan are structure
 
752
c          descriptors, as defined under optional outputs below, and
 
753
c          so can be used to determine the relevant row indices i, if
 
754
c          desired.  (in the dimension statement above, 1 is a
 
755
c          dummy dimension.. it can be replaced by any value.)
 
756
c               jac need not provide df/dy exactly.  a crude
 
757
c          approximation (possibly with greater sparsity) will do.
 
758
c               in any case, pdj is preset to zero by the solver,
 
759
c          so that only the nonzero elements need be loaded by jac.
 
760
c          calls to jac are made with j = 1,...,neq, in that order, and
 
761
c          each such set of calls is preceded by a call to f with the
 
762
c          same arguments neq, t, and y.  thus to gain some efficiency,
 
763
c          intermediate quantities shared by both calculations may be
 
764
c          saved in a user common block by f and not recomputed by jac,
 
765
c          if desired.  jac must not alter its input arguments.
 
766
c          jac must be declared external in the calling program.
 
767
c               subroutine jac may access user-defined quantities in
 
768
c          neq(2),... and y(neq(1)+1),... if neq is an array
 
769
c          (dimensioned in jac) and y has length exceeding neq(1).
 
770
c          see the descriptions of neq and y above.
 
771
c
 
772
c mf     = the method flag.  used only for input.
 
773
c          mf has three decimal digits-- moss, meth, miter--
 
774
c             mf = 100*moss + 10*meth + miter.
 
775
c          moss indicates the method to be used to obtain the sparsity
 
776
c          structure of the jacobian matrix if miter = 1 or 2..
 
777
c            moss = 0 means the user has supplied ia and ja
 
778
c                     (see descriptions under iwork above).
 
779
c            moss = 1 means the user has supplied jac (see below)
 
780
c                     and the structure will be obtained from neq
 
781
c                     initial calls to jac.
 
782
c            moss = 2 means the structure will be obtained from neq+1
 
783
c                     initial calls to f.
 
784
c          meth indicates the basic linear multistep method..
 
785
c            meth = 1 means the implicit adams method.
 
786
c            meth = 2 means the method based on backward
 
787
c                     differentiation formulas (bdf-s).
 
788
c          miter indicates the corrector iteration method..
 
789
c            miter = 0 means functional iteration (no jacobian matrix
 
790
c                      is involved).
 
791
c            miter = 1 means chord iteration with a user-supplied
 
792
c                      sparse jacobian, given by subroutine jac.
 
793
c            miter = 2 means chord iteration with an internally
 
794
c                      generated (difference quotient) sparse jacobian
 
795
c                      (using ngp extra calls to f per df/dy value,
 
796
c                      where ngp is an optional output described below.)
 
797
c            miter = 3 means chord iteration with an internally
 
798
c                      generated diagonal jacobian approximation.
 
799
c                      (using 1 extra call to f per df/dy evaluation).
 
800
c          if miter = 1 or moss = 1, the user must supply a subroutine
 
801
c          jac (the name is arbitrary) as described above under jac.
 
802
c          otherwise, a dummy argument can be used.
 
803
c
 
804
c          the standard choices for mf are..
 
805
c            mf = 10  for a nonstiff problem,
 
806
c            mf = 21 or 22 for a stiff problem with ia/ja supplied
 
807
c                     (21 if jac is supplied, 22 if not),
 
808
c            mf = 121 for a stiff problem with jac supplied,
 
809
c                     but not ia/ja,
 
810
c            mf = 222 for a stiff problem with neither ia/ja nor
 
811
c                     jac supplied.
 
812
c          the sparseness structure can be changed during the
 
813
c          problem by making a call to lsodes with istate = 3.
 
814
c-----------------------------------------------------------------------
 
815
c optional inputs.
 
816
c
 
817
c the following is a list of the optional inputs provided for in the
 
818
c call sequence.  (see also part ii.)  for each such input variable,
 
819
c this table lists its name as used in this documentation, its
 
820
c location in the call sequence, its meaning, and the default value.
 
821
c the use of any of these inputs requires iopt = 1, and in that
 
822
c case all of these inputs are examined.  a value of zero for any
 
823
c of these optional inputs will cause the default value to be used.
 
824
c thus to use a subset of the optional inputs, simply preload
 
825
c locations 5 to 10 in rwork and iwork to 0.0 and 0 respectively, and
 
826
c then set those of interest to nonzero values.
 
827
c
 
828
c name    location      meaning and default value
 
829
c
 
830
c h0      rwork(5)  the step size to be attempted on the first step.
 
831
c                   the default value is determined by the solver.
 
832
c
 
833
c hmax    rwork(6)  the maximum absolute step size allowed.
 
834
c                   the default value is infinite.
 
835
c
 
836
c hmin    rwork(7)  the minimum absolute step size allowed.
 
837
c                   the default value is 0.  (this lower bound is not
 
838
c                   enforced on the final step before reaching tcrit
 
839
c                   when itask = 4 or 5.)
 
840
c
 
841
c seth    rwork(8)  the element threshhold for sparsity determination
 
842
c                   when moss = 1 or 2.  if the absolute value of
 
843
c                   an estimated jacobian element is .le. seth, it
 
844
c                   will be assumed to be absent in the structure.
 
845
c                   the default value of seth is 0.
 
846
c
 
847
c maxord  iwork(5)  the maximum order to be allowed.  the default
 
848
c                   value is 12 if meth = 1, and 5 if meth = 2.
 
849
c                   if maxord exceeds the default value, it will
 
850
c                   be reduced to the default value.
 
851
c                   if maxord is changed during the problem, it may
 
852
c                   cause the current order to be reduced.
 
853
c
 
854
c mxstep  iwork(6)  maximum number of (internally defined) steps
 
855
c                   allowed during one call to the solver.
 
856
c                   the default value is 500.
 
857
c
 
858
c mxhnil  iwork(7)  maximum number of messages printed (per problem)
 
859
c                   warning that t + h = t on a step (h = step size).
 
860
c                   this must be positive to result in a non-default
 
861
c                   value.  the default value is 10.
 
862
c-----------------------------------------------------------------------
 
863
c optional outputs.
 
864
c
 
865
c as optional additional output from lsodes, the variables listed
 
866
c below are quantities related to the performance of lsodes
 
867
c which are available to the user.  these are communicated by way of
 
868
c the work arrays, but also have internal mnemonic names as shown.
 
869
c except where stated otherwise, all of these outputs are defined
 
870
c on any successful return from lsodes, and on any return with
 
871
c istate = -1, -2, -4, -5, or -6.  on an illegal input return
 
872
c (istate = -3), they will be unchanged from their existing values
 
873
c (if any), except possibly for tolsf, lenrw, and leniw.
 
874
c on any error return, outputs relevant to the error will be defined,
 
875
c as noted below.
 
876
c
 
877
c name    location      meaning
 
878
c
 
879
c hu      rwork(11) the step size in t last used (successfully).
 
880
c
 
881
c hcur    rwork(12) the step size to be attempted on the next step.
 
882
c
 
883
c tcur    rwork(13) the current value of the independent variable
 
884
c                   which the solver has actually reached, i.e. the
 
885
c                   current internal mesh point in t.  on output, tcur
 
886
c                   will always be at least as far as the argument
 
887
c                   t, but may be farther (if interpolation was done).
 
888
c
 
889
c tolsf   rwork(14) a tolerance scale factor, greater than 1.0,
 
890
c                   computed when a request for too much accuracy was
 
891
c                   detected (istate = -3 if detected at the start of
 
892
c                   the problem, istate = -2 otherwise).  if itol is
 
893
c                   left unaltered but rtol and atol are uniformly
 
894
c                   scaled up by a factor of tolsf for the next call,
 
895
c                   then the solver is deemed likely to succeed.
 
896
c                   (the user may also ignore tolsf and alter the
 
897
c                   tolerance parameters in any other way appropriate.)
 
898
c
 
899
c nst     iwork(11) the number of steps taken for the problem so far.
 
900
c
 
901
c nfe     iwork(12) the number of f evaluations for the problem so far,
 
902
c                   excluding those for structure determination
 
903
c                   (moss = 2).
 
904
c
 
905
c nje     iwork(13) the number of jacobian evaluations for the problem
 
906
c                   so far, excluding those for structure determination
 
907
c                   (moss = 1).
 
908
c
 
909
c nqu     iwork(14) the method order last used (successfully).
 
910
c
 
911
c nqcur   iwork(15) the order to be attempted on the next step.
 
912
c
 
913
c imxer   iwork(16) the index of the component of largest magnitude in
 
914
c                   the weighted local error vector ( e(i)/ewt(i) ),
 
915
c                   on an error return with istate = -4 or -5.
 
916
c
 
917
c lenrw   iwork(17) the length of rwork actually required.
 
918
c                   this is defined on normal returns and on an illegal
 
919
c                   input return for insufficient storage.
 
920
c
 
921
c leniw   iwork(18) the length of iwork actually required.
 
922
c                   this is defined on normal returns and on an illegal
 
923
c                   input return for insufficient storage.
 
924
c
 
925
c nnz     iwork(19) the number of nonzero elements in the jacobian
 
926
c                   matrix, including the diagonal (miter = 1 or 2).
 
927
c                   (this may differ from that given by ia(neq+1)-1
 
928
c                   if moss = 0, because of added diagonal entries.)
 
929
c
 
930
c ngp     iwork(20) the number of groups of column indices, used in
 
931
c                   difference quotient jacobian aproximations if
 
932
c                   miter = 2.  this is also the number of extra f
 
933
c                   evaluations needed for each jacobian evaluation.
 
934
c
 
935
c nlu     iwork(21) the number of sparse lu decompositions for the
 
936
c                   problem so far.
 
937
c
 
938
c lyh     iwork(22) the base address in rwork of the history array yh,
 
939
c                   described below in this list.
 
940
c
 
941
c ipian   iwork(23) the base address of the structure descriptor array
 
942
c                   ian, described below in this list.
 
943
c
 
944
c ipjan   iwork(24) the base address of the structure descriptor array
 
945
c                   jan, described below in this list.
 
946
c
 
947
c nzl     iwork(25) the number of nonzero elements in the strict lower
 
948
c                   triangle of the lu factorization used in the chord
 
949
c                   iteration (miter = 1 or 2).
 
950
c
 
951
c nzu     iwork(26) the number of nonzero elements in the strict upper
 
952
c                   triangle of the lu factorization used in the chord
 
953
c                   iteration (miter = 1 or 2).
 
954
c                   the total number of nonzeros in the factorization
 
955
c                   is therefore nzl + nzu + neq.
 
956
c
 
957
c the following four arrays are segments of the rwork array which
 
958
c may also be of interest to the user as optional outputs.
 
959
c for each array, the table below gives its internal name,
 
960
c its base address, and its description.
 
961
c for yh and acor, the base addresses are in rwork (a real array).
 
962
c the integer arrays ian and jan are to be obtained by declaring an
 
963
c integer array iwk and identifying iwk(1) with rwork(21), using either
 
964
c an equivalence statement or a subroutine call.  then the base
 
965
c addresses ipian (of ian) and ipjan (of jan) in iwk are to be obtained
 
966
c as optional outputs iwork(23) and iwork(24), respectively.
 
967
c thus ian(1) is iwk(ipian), etc.
 
968
c
 
969
c name    base address      description
 
970
c
 
971
c ian    ipian (in iwk)  structure descriptor array of size neq + 1.
 
972
c jan    ipjan (in iwk)  structure descriptor array of size nnz.
 
973
c         (see above)    ian and jan together describe the sparsity
 
974
c                        structure of the jacobian matrix, as used by
 
975
c                        lsodes when miter = 1 or 2.
 
976
c                        jan contains the row indices of the nonzero
 
977
c                        locations, reading in columnwise order, and
 
978
c                        ian contains the starting locations in jan of
 
979
c                        the descriptions of columns 1,...,neq, in
 
980
c                        that order, with ian(1) = 1.  thus for each
 
981
c                        j = 1,...,neq, the row indices i of the
 
982
c                        nonzero locations in column j are
 
983
c                        i = jan(k),  ian(j) .le. k .lt. ian(j+1).
 
984
c                        note that ian(neq+1) = nnz + 1.
 
985
c                        (if moss = 0, ian/jan may differ from the
 
986
c                        input ia/ja because of a different ordering
 
987
c                        in each column, and added diagonal entries.)
 
988
c
 
989
c yh      lyh            the nordsieck history array, of size nyh by
 
990
c          (optional     (nqcur + 1), where nyh is the initial value
 
991
c          output)       of neq.  for j = 0,1,...,nqcur, column j+1
 
992
c                        of yh contains hcur**j/factorial(j) times
 
993
c                        the j-th derivative of the interpolating
 
994
c                        polynomial currently representing the solution,
 
995
c                        evaluated at t = tcur.  the base address lyh
 
996
c                        is another optional output, listed above.
 
997
c
 
998
c acor     lenrw-neq+1   array of size neq used for the accumulated
 
999
c                        corrections on each step, scaled on output
 
1000
c                        to represent the estimated local error in y
 
1001
c                        on the last step.  this is the vector e in
 
1002
c                        the description of the error control.  it is
 
1003
c                        defined only on a successful return from
 
1004
c                        lsodes.
 
1005
c
 
1006
c-----------------------------------------------------------------------
 
1007
c part ii.  other routines callable.
 
1008
c
 
1009
c the following are optional calls which the user may make to
 
1010
c gain additional capabilities in conjunction with lsodes.
 
1011
c (the routines xsetun and xsetf are designed to conform to the
 
1012
c slatec error handling package.)
 
1013
c
 
1014
c     form of call                  function
 
1015
c   call xsetun(lun)          set the logical unit number, lun, for
 
1016
c                             output of messages from lsodes, if
 
1017
c                             the default is not desired.
 
1018
c                             the default value of lun is 6.
 
1019
c
 
1020
c   call xsetf(mflag)         set a flag to control the printing of
 
1021
c                             messages by lsodes.
 
1022
c                             mflag = 0 means do not print. (danger..
 
1023
c                             this risks losing valuable information.)
 
1024
c                             mflag = 1 means print (the default).
 
1025
c
 
1026
c                             either of the above calls may be made at
 
1027
c                             any time and will take effect immediately.
 
1028
c
 
1029
c   call srcms(rsav,isav,job) saves and restores the contents of
 
1030
c                             the internal common blocks used by
 
1031
c                             lsodes (see part iii below).
 
1032
c                             rsav must be a real array of length 224
 
1033
c                             or more, and isav must be an integer
 
1034
c                             array of length 75 or more.
 
1035
c                             job=1 means save common into rsav/isav.
 
1036
c                             job=2 means restore common from rsav/isav.
 
1037
c                                srcms is useful if one is
 
1038
c                             interrupting a run and restarting
 
1039
c                             later, or alternating between two or
 
1040
c                             more problems solved with lsodes.
 
1041
c
 
1042
c   call intdy(,,,,,)         provide derivatives of y, of various
 
1043
c        (see below)          orders, at a specified point t, if
 
1044
c                             desired.  it may be called only after
 
1045
c                             a successful return from lsodes.
 
1046
c
 
1047
c the detailed instructions for using intdy are as follows.
 
1048
c the form of the call is..
 
1049
c
 
1050
c   lyh = iwork(22)
 
1051
c   call intdy (t, k, rwork(lyh), nyh, dky, iflag)
 
1052
c
 
1053
c the input parameters are..
 
1054
c
 
1055
c t         = value of independent variable where answers are desired
 
1056
c             (normally the same as the t last returned by lsodes).
 
1057
c             for valid results, t must lie between tcur - hu and tcur.
 
1058
c             (see optional outputs for tcur and hu.)
 
1059
c k         = integer order of the derivative desired.  k must satisfy
 
1060
c             0 .le. k .le. nqcur, where nqcur is the current order
 
1061
c             (see optional outputs).  the capability corresponding
 
1062
c             to k = 0, i.e. computing y(t), is already provided
 
1063
c             by lsodes directly.  since nqcur .ge. 1, the first
 
1064
c             derivative dy/dt is always available with intdy.
 
1065
c lyh       = the base address of the history array yh, obtained
 
1066
c             as an optional output as shown above.
 
1067
c nyh       = column length of yh, equal to the initial value of neq.
 
1068
c
 
1069
c the output parameters are..
 
1070
c
 
1071
c dky       = a real array of length neq containing the computed value
 
1072
c             of the k-th derivative of y(t).
 
1073
c iflag     = integer flag, returned as 0 if k and t were legal,
 
1074
c             -1 if k was illegal, and -2 if t was illegal.
 
1075
c             on an error return, a message is also written.
 
1076
c-----------------------------------------------------------------------
 
1077
c part iii.  common blocks.
 
1078
c
 
1079
c if lsodes is to be used in an overlay situation, the user
 
1080
c must declare, in the primary overlay, the variables in..
 
1081
c   (1) the call sequence to lsodes,
 
1082
c   (2) the three internal common blocks
 
1083
c         /ls0001/  of length  257  (218 double precision words
 
1084
c                         followed by 39 integer words),
 
1085
c         /lss001/  of length  40    ( 6 double precision words
 
1086
c                         followed by 34 integer words),
 
1087
c         /eh0001/  of length  2 (integer words).
 
1088
c
 
1089
c if lsodes is used on a system in which the contents of internal
 
1090
c common blocks are not preserved between calls, the user should
 
1091
c declare the above three common blocks in his main program to insure
 
1092
c that their contents are preserved.
 
1093
c
 
1094
c if the solution of a given problem by lsodes is to be interrupted
 
1095
c and then later continued, such as when restarting an interrupted run
 
1096
c or alternating between two or more problems, the user should save,
 
1097
c following the return from the last lsodes call prior to the
 
1098
c interruption, the contents of the call sequence variables and the
 
1099
c internal common blocks, and later restore these values before the
 
1100
c next lsodes call for that problem.  to save and restore the common
 
1101
c blocks, use subroutine srcms (see part ii above).
 
1102
c
 
1103
c-----------------------------------------------------------------------
 
1104
c part iv.  optionally replaceable solver routines.
 
1105
c
 
1106
c below are descriptions of two routines in the lsodes package which
 
1107
c relate to the measurement of errors.  either routine can be
 
1108
c replaced by a user-supplied version, if desired.  however, since such
 
1109
c a replacement may have a major impact on performance, it should be
 
1110
c done only when absolutely necessary, and only with great caution.
 
1111
c (note.. the means by which the package version of a routine is
 
1112
c superseded by the user-s version may be system-dependent.)
 
1113
c
 
1114
c (a) ewset.
 
1115
c the following subroutine is called just before each internal
 
1116
c integration step, and sets the array of error weights, ewt, as
 
1117
c described under itol/rtol/atol above..
 
1118
c     subroutine ewset (neq, itol, rtol, atol, ycur, ewt)
 
1119
c where neq, itol, rtol, and atol are as in the lsodes call sequence,
 
1120
c ycur contains the current dependent variable vector, and
 
1121
c ewt is the array of weights set by ewset.
 
1122
c
 
1123
c if the user supplies this subroutine, it must return in ewt(i)
 
1124
c (i = 1,...,neq) a positive quantity suitable for comparing errors
 
1125
c in y(i) to.  the ewt array returned by ewset is passed to the
 
1126
c vnorm routine (see below), and also used by lsodes in the computation
 
1127
c of the optional output imxer, the diagonal jacobian approximation,
 
1128
c and the increments for difference quotient jacobians.
 
1129
c
 
1130
c in the user-supplied version of ewset, it may be desirable to use
 
1131
c the current values of derivatives of y.  derivatives up to order nq
 
1132
c are available from the history array yh, described above under
 
1133
c optional outputs.  in ewset, yh is identical to the ycur array,
 
1134
c extended to nq + 1 columns with a column length of nyh and scale
 
1135
c factors of h**j/factorial(j).  on the first call for the problem,
 
1136
c given by nst = 0, nq is 1 and h is temporarily set to 1.0.
 
1137
c the quantities nq, nyh, h, and nst can be obtained by including
 
1138
c in ewset the statements..
 
1139
c     double precision h, rls
 
1140
c     common /ls0001/ rls(218),ils(39)
 
1141
c     nq = ils(35)
 
1142
c     nyh = ils(14)
 
1143
c     nst = ils(36)
 
1144
c     h = rls(212)
 
1145
c thus, for example, the current value of dy/dt can be obtained as
 
1146
c ycur(nyh+i)/h  (i=1,...,neq)  (and the division by h is
 
1147
c unnecessary when nst = 0).
 
1148
c
 
1149
c (b) vnorm.
 
1150
c the following is a real function routine which computes the weighted
 
1151
c root-mean-square norm of a vector v..
 
1152
c     d = vnorm (n, v, w)
 
1153
c where..
 
1154
c   n = the length of the vector,
 
1155
c   v = real array of length n containing the vector,
 
1156
c   w = real array of length n containing weights,
 
1157
c   d = sqrt( (1/n) * sum(v(i)*w(i))**2 ).
 
1158
c vnorm is called with n = neq and with w(i) = 1.0/ewt(i), where
 
1159
c ewt is as set by subroutine ewset.
 
1160
c
 
1161
c if the user supplies this function, it should return a non-negative
 
1162
c value of vnorm suitable for use in the error control in lsodes.
 
1163
c none of the arguments should be altered by vnorm.
 
1164
c for example, a user-supplied vnorm routine might..
 
1165
c   -substitute a max-norm of (v(i)*w(i)) for the rms-norm, or
 
1166
c   -ignore some components of v in the norm, with the effect of
 
1167
c    suppressing the error control on those components of y.
 
1168
c-----------------------------------------------------------------------
 
1169
c-----------------------------------------------------------------------
 
1170
c other routines in the lsodes package.
 
1171
c
 
1172
c in addition to subroutine lsodes, the lsodes package includes the
 
1173
c following subroutines and function routines..
 
1174
c  iprep    acts as an iterface between lsodes and prep, and also does
 
1175
c           adjusting of work space pointers and work arrays.
 
1176
c  prep     is called by iprep to compute sparsity and do sparse matrix
 
1177
c           preprocessing if miter = 1 or 2.
 
1178
c  jgroup   is called by prep to compute groups of jacobian column
 
1179
c           indices for use when miter = 2.
 
1180
c  adjlr    adjusts the length of required sparse matrix work space.
 
1181
c           it is called by prep.
 
1182
c  cntnzu   is called by prep and counts the nonzero elements in the
 
1183
c           strict upper triangle of j + j-transpose, where j = df/dy.
 
1184
c  intdy    computes an interpolated value of the y vector at t = tout.
 
1185
c  stode    is the core integrator, which does one step of the
 
1186
c           integration and the associated error control.
 
1187
c  cfode    sets all method coefficients and test constants.
 
1188
c  prjs     computes and preprocesses the jacobian matrix j = df/dy
 
1189
c           and the newton iteration matrix p = i - h*l0*j.
 
1190
c  slss     manages solution of linear system in chord iteration.
 
1191
c  ewset    sets the error weight vector ewt before each step.
 
1192
c  vnorm    computes the weighted r.m.s. norm of a vector.
 
1193
c  srcms    is a user-callable routine to save and restore
 
1194
c           the contents of the internal common blocks.
 
1195
c  odrv     constructs a reordering of the rows and columns of
 
1196
c           a matrix by the minimum degree algorithm.  odrv is a
 
1197
c           driver routine which calls subroutines md, mdi, mdm,
 
1198
c           mdp, mdu, and sro.  see ref. 2 for details.  (the odrv
 
1199
c           module has been modified since ref. 2, however.)
 
1200
c  cdrv     performs reordering, symbolic factorization, numerical
 
1201
c           factorization, or linear system solution operations,
 
1202
c           depending on a path argument ipath.  cdrv is a
 
1203
c           driver routine which calls subroutines nroc, nsfc,
 
1204
c           nnfc, nnsc, and nntc.  see ref. 3 for details.
 
1205
c           lsodes uses cdrv to solve linear systems in which the
 
1206
c           coefficient matrix is  p = i - con*j, where i is the
 
1207
c           identity, con is a scalar, and j is an approximation to
 
1208
c           the jacobian df/dy.  because cdrv deals with rowwise
 
1209
c           sparsity descriptions, cdrv works with p-transpose, not p.
 
1210
c  d1mach   computes the unit roundoff in a machine-independent manner.
 
1211
c  xerrwv, xsetun, and xsetf   handle the printing of all error
 
1212
c           messages and warnings.  xerrwv is machine-dependent.
 
1213
c note..  vnorm and d1mach are function routines.
 
1214
c all the others are subroutines.
 
1215
c
 
1216
c the intrinsic and external routines used by lsodes are..
 
1217
c dabs, dmax1, dmin1, dfloat, max0, min0, mod, dsign, dsqrt, and write.
 
1218
c
 
1219
c a block data subprogram is also included with the package,
 
1220
c for loading some of the variables in internal common.
 
1221
c
 
1222
c-----------------------------------------------------------------------
 
1223
c the following card is for optimized compilation on lll compilers.
 
1224
clll. optimize
 
1225
c-----------------------------------------------------------------------
 
1226
      external prjs, slss
 
1227
      integer illin, init, lyh, lewt, lacor, lsavf, lwm, liwm,
 
1228
     1   mxstep, mxhnil, nhnil, ntrep, nslast, nyh, iowns
 
1229
      integer icf, ierpj, iersl, jcur, jstart, kflag, l, meth, miter,
 
1230
     1   maxord, maxcor, msbp, mxncf, n, nq, nst, nfe, nje, nqu
 
1231
      integer iplost, iesp, istatc, iys, iba, ibian, ibjan, ibjgp,
 
1232
     1   ipian, ipjan, ipjgp, ipigp, ipr, ipc, ipic, ipisp, iprsp, ipa,
 
1233
     2   lenyh, lenyhm, lenwk, lreq, lrat, lrest, lwmin, moss, msbj,
 
1234
     3   nslj, ngp, nlu, nnz, nsp, nzl, nzu
 
1235
      integer i, i1, i2, iflag, imax, imul, imxer, ipflag, ipgo, irem,
 
1236
     1   j, kgo, lenrat, lenyht, leniw, lenrw, lf0, lia, lja,
 
1237
     2   lrtem, lwtem, lyhd, lyhn, mf1, mord, mxhnl0, mxstp0, ncolm
 
1238
      double precision rowns,
 
1239
     1   ccmax, el0, h, hmin, hmxi, hu, rc, tn, uround
 
1240
      double precision con0, conmin, ccmxj, psmall, rbig, seth
 
1241
      double precision atoli, ayi, big, ewti, h0, hmax, hmx, rh, rtoli,
 
1242
     1   tcrit, tdist, tnext, tol, tolsf, tp, size, sum, w0,
 
1243
     2   d1mach, vnorm
 
1244
      dimension mord(2)
 
1245
      logical ihit
 
1246
c-----------------------------------------------------------------------
 
1247
c the following two internal common blocks contain
 
1248
c (a) variables which are local to any subroutine but whose values must
 
1249
c     be preserved between calls to the routine (own variables), and
 
1250
c (b) variables which are communicated between subroutines.
 
1251
c the structure of each block is as follows..  all real variables are
 
1252
c listed first, followed by all integers.  within each type, the
 
1253
c variables are grouped with those local to subroutine lsodes first,
 
1254
c then those local to subroutine stode or subroutine prjs
 
1255
c (no other routines have own variables), and finally those used
 
1256
c for communication.  the block ls0001 is declared in subroutines
 
1257
c lsodes, iprep, prep, intdy, stode, prjs, and slss.  the block lss001
 
1258
c is declared in subroutines lsodes, iprep, prep, prjs, and slss.
 
1259
c groups of variables are replaced by dummy arrays in the common
 
1260
c declarations in routines where those variables are not used.
 
1261
c-----------------------------------------------------------------------
 
1262
      common /ls0001/ rowns(209),
 
1263
     1   ccmax, el0, h, hmin, hmxi, hu, rc, tn, uround,
 
1264
     2   illin, init, lyh, lewt, lacor, lsavf, lwm, liwm,
 
1265
     3   mxstep, mxhnil, nhnil, ntrep, nslast, nyh, iowns(6),
 
1266
     4   icf, ierpj, iersl, jcur, jstart, kflag, l, meth, miter,
 
1267
     5   maxord, maxcor, msbp, mxncf, n, nq, nst, nfe, nje, nqu
 
1268
c
 
1269
      common /lss001/ con0, conmin, ccmxj, psmall, rbig, seth,
 
1270
     1   iplost, iesp, istatc, iys, iba, ibian, ibjan, ibjgp,
 
1271
     2   ipian, ipjan, ipjgp, ipigp, ipr, ipc, ipic, ipisp, iprsp, ipa,
 
1272
     3   lenyh, lenyhm, lenwk, lreq, lrat, lrest, lwmin, moss, msbj,
 
1273
     4   nslj, ngp, nlu, nnz, nsp, nzl, nzu
 
1274
c
 
1275
      data mord(1),mord(2)/12,5/, mxstp0/500/, mxhnl0/10/
 
1276
c-----------------------------------------------------------------------
 
1277
c in the data statement below, set lenrat equal to the ratio of
 
1278
c the wordlength for a real number to that for an integer.  usually,
 
1279
c lenrat = 1 for single precision and 2 for double precision.  if the
 
1280
c true ratio is not an integer, use the next smaller integer (.ge. 1).
 
1281
c-----------------------------------------------------------------------
 
1282
      data lenrat/2/
 
1283
c-----------------------------------------------------------------------
 
1284
c block a.
 
1285
c this code block is executed on every call.
 
1286
c it tests istate and itask for legality and branches appropriately.
 
1287
c if istate .gt. 1 but the flag init shows that initialization has
 
1288
c not yet been done, an error return occurs.
 
1289
c if istate = 1 and tout = t, jump to block g and return immediately.
 
1290
c-----------------------------------------------------------------------
 
1291
      if (istate .lt. 1 .or. istate .gt. 3) go to 601
 
1292
      if (itask .lt. 1 .or. itask .gt. 5) go to 602
 
1293
      if (istate .eq. 1) go to 10
 
1294
      if (init .eq. 0) go to 603
 
1295
      if (istate .eq. 2) go to 200
 
1296
      go to 20
 
1297
 10   init = 0
 
1298
      if (tout .eq. t) go to 430
 
1299
 20   ntrep = 0
 
1300
c-----------------------------------------------------------------------
 
1301
c block b.
 
1302
c the next code block is executed for the initial call (istate = 1),
 
1303
c or for a continuation call with parameter changes (istate = 3).
 
1304
c it contains checking of all inputs and various initializations.
 
1305
c if istate = 1, the final setting of work space pointers, the matrix
 
1306
c preprocessing, and other initializations are done in block c.
 
1307
c
 
1308
c first check legality of the non-optional inputs neq, itol, iopt,
 
1309
c mf, ml, and mu.
 
1310
c-----------------------------------------------------------------------
 
1311
      if (neq(1) .le. 0) go to 604
 
1312
      if (istate .eq. 1) go to 25
 
1313
      if (neq(1) .gt. n) go to 605
 
1314
 25   n = neq(1)
 
1315
      if (itol .lt. 1 .or. itol .gt. 4) go to 606
 
1316
      if (iopt .lt. 0 .or. iopt .gt. 1) go to 607
 
1317
      moss = mf/100
 
1318
      mf1 = mf - 100*moss
 
1319
      meth = mf1/10
 
1320
      miter = mf1 - 10*meth
 
1321
      if (moss .lt. 0 .or. moss .gt. 2) go to 608
 
1322
      if (meth .lt. 1 .or. meth .gt. 2) go to 608
 
1323
      if (miter .lt. 0 .or. miter .gt. 3) go to 608
 
1324
      if (miter .eq. 0 .or. miter .eq. 3) moss = 0
 
1325
c next process and check the optional inputs. --------------------------
 
1326
      if (iopt .eq. 1) go to 40
 
1327
      maxord = mord(meth)
 
1328
      mxstep = mxstp0
 
1329
      mxhnil = mxhnl0
 
1330
      if (istate .eq. 1) h0 = 0.0d0
 
1331
      hmxi = 0.0d0
 
1332
      hmin = 0.0d0
 
1333
      seth = 0.0d0
 
1334
      go to 60
 
1335
 40   maxord = iwork(5)
 
1336
      if (maxord .lt. 0) go to 611
 
1337
      if (maxord .eq. 0) maxord = 100
 
1338
      maxord = min0(maxord,mord(meth))
 
1339
      mxstep = iwork(6)
 
1340
      if (mxstep .lt. 0) go to 612
 
1341
      if (mxstep .eq. 0) mxstep = mxstp0
 
1342
      mxhnil = iwork(7)
 
1343
      if (mxhnil .lt. 0) go to 613
 
1344
      if (mxhnil .eq. 0) mxhnil = mxhnl0
 
1345
      if (istate .ne. 1) go to 50
 
1346
      h0 = rwork(5)
 
1347
      if ((tout - t)*h0 .lt. 0.0d0) go to 614
 
1348
 50   hmax = rwork(6)
 
1349
      if (hmax .lt. 0.0d0) go to 615
 
1350
      hmxi = 0.0d0
 
1351
      if (hmax .gt. 0.0d0) hmxi = 1.0d0/hmax
 
1352
      hmin = rwork(7)
 
1353
      if (hmin .lt. 0.0d0) go to 616
 
1354
      seth = rwork(8)
 
1355
      if (seth .lt. 0.0d0) go to 609
 
1356
c check rtol and atol for legality. ------------------------------------
 
1357
 60   rtoli = rtol(1)
 
1358
      atoli = atol(1)
 
1359
      do 65 i = 1,n
 
1360
        if (itol .ge. 3) rtoli = rtol(i)
 
1361
        if (itol .eq. 2 .or. itol .eq. 4) atoli = atol(i)
 
1362
        if (rtoli .lt. 0.0d0) go to 619
 
1363
        if (atoli .lt. 0.0d0) go to 620
 
1364
 65     continue
 
1365
c-----------------------------------------------------------------------
 
1366
c compute required work array lengths, as far as possible, and test
 
1367
c these against lrw and liw.  then set tentative pointers for work
 
1368
c arrays.  pointers to rwork/iwork segments are named by prefixing l to
 
1369
c the name of the segment.  e.g., the segment yh starts at rwork(lyh).
 
1370
c segments of rwork (in order) are denoted  wm, yh, savf, ewt, acor.
 
1371
c if miter = 1 or 2, the required length of the matrix work space wm
 
1372
c is not yet known, and so a crude minimum value is used for the
 
1373
c initial tests of lrw and liw, and yh is temporarily stored as far
 
1374
c to the right in rwork as possible, to leave the maximum amount
 
1375
c of space for wm for matrix preprocessing.  thus if miter = 1 or 2
 
1376
c and moss .ne. 2, some of the segments of rwork are temporarily
 
1377
c omitted, as they are not needed in the preprocessing.  these
 
1378
c omitted segments are.. acor if istate = 1, ewt and acor if istate = 3
 
1379
c and moss = 1, and savf, ewt, and acor if istate = 3 and moss = 0.
 
1380
c-----------------------------------------------------------------------
 
1381
      lrat = lenrat
 
1382
      if (istate .eq. 1) nyh = n
 
1383
      lwmin = 0
 
1384
      if (miter .eq. 1) lwmin = 4*n + 10*n/lrat
 
1385
      if (miter .eq. 2) lwmin = 4*n + 11*n/lrat
 
1386
      if (miter .eq. 3) lwmin = n + 2
 
1387
      lenyh = (maxord+1)*nyh
 
1388
      lrest = lenyh + 3*n
 
1389
      lenrw = 20 + lwmin + lrest
 
1390
      iwork(17) = lenrw
 
1391
      leniw = 30
 
1392
      if (moss .eq. 0 .and. miter .ne. 0 .and. miter .ne. 3)
 
1393
     1   leniw = leniw + n + 1
 
1394
      iwork(18) = leniw
 
1395
      if (lenrw .gt. lrw) go to 617
 
1396
      if (leniw .gt. liw) go to 618
 
1397
      lia = 31
 
1398
      if (moss .eq. 0 .and. miter .ne. 0 .and. miter .ne. 3)
 
1399
     1   leniw = leniw + iwork(lia+n) - 1
 
1400
      iwork(18) = leniw
 
1401
      if (leniw .gt. liw) go to 618
 
1402
      lja = lia + n + 1
 
1403
      lia = min0(lia,liw)
 
1404
      lja = min0(lja,liw)
 
1405
      lwm = 21
 
1406
      if (istate .eq. 1) nq = 1
 
1407
      ncolm = min0(nq+1,maxord+2)
 
1408
      lenyhm = ncolm*nyh
 
1409
      lenyht = lenyh
 
1410
      if (miter .eq. 1 .or. miter .eq. 2) lenyht = lenyhm
 
1411
      imul = 2
 
1412
      if (istate .eq. 3) imul = moss
 
1413
      if (moss .eq. 2) imul = 3
 
1414
      lrtem = lenyht + imul*n
 
1415
      lwtem = lwmin
 
1416
      if (miter .eq. 1 .or. miter .eq. 2) lwtem = lrw - 20 - lrtem
 
1417
      lenwk = lwtem
 
1418
      lyhn = lwm + lwtem
 
1419
      lsavf = lyhn + lenyht
 
1420
      lewt = lsavf + n
 
1421
      lacor = lewt + n
 
1422
      istatc = istate
 
1423
      if (istate .eq. 1) go to 100
 
1424
c-----------------------------------------------------------------------
 
1425
c istate = 3.  move yh to its new location.
 
1426
c note that only the part of yh needed for the next step, namely
 
1427
c min(nq+1,maxord+2) columns, is actually moved.
 
1428
c a temporary error weight array ewt is loaded if moss = 2.
 
1429
c sparse matrix processing is done in iprep/prep if miter = 1 or 2.
 
1430
c if maxord was reduced below nq, then the pointers are finally set
 
1431
c so that savf is identical to yh(*,maxord+2).
 
1432
c-----------------------------------------------------------------------
 
1433
      lyhd = lyh - lyhn
 
1434
      imax = lyhn - 1 + lenyhm
 
1435
c move yh.  branch for move right, no move, or move left. --------------
 
1436
      if (lyhd.lt.0) go to 70
 
1437
      if (lyhd.eq.0) go to 80
 
1438
      go to 74
 
1439
 70   do 72 i = lyhn,imax
 
1440
        j = imax + lyhn - i
 
1441
 72     rwork(j) = rwork(j+lyhd)
 
1442
      go to 80
 
1443
 74   do 76 i = lyhn,imax
 
1444
 76     rwork(i) = rwork(i+lyhd)
 
1445
 80   lyh = lyhn
 
1446
      iwork(22) = lyh
 
1447
      if (miter .eq. 0 .or. miter .eq. 3) go to 92
 
1448
      if (moss .ne. 2) go to 85
 
1449
c temporarily load ewt if miter = 1 or 2 and moss = 2. -----------------
 
1450
      call ewset (n, itol, rtol, atol, rwork(lyh), rwork(lewt))
 
1451
      do 82 i = 1,n
 
1452
        if (rwork(i+lewt-1) .le. 0.0d0) go to 621
 
1453
 82     rwork(i+lewt-1) = 1.0d0/rwork(i+lewt-1)
 
1454
 85   continue
 
1455
c iprep and prep do sparse matrix preprocessing if miter = 1 or 2. -----
 
1456
      lsavf = min0(lsavf,lrw)
 
1457
      lewt = min0(lewt,lrw)
 
1458
      lacor = min0(lacor,lrw)
 
1459
      call iprep (neq, y, rwork, iwork(lia), iwork(lja), ipflag, f, jac)
 
1460
      lenrw = lwm - 1 + lenwk + lrest
 
1461
      iwork(17) = lenrw
 
1462
      if (ipflag .ne. -1) iwork(23) = ipian
 
1463
      if (ipflag .ne. -1) iwork(24) = ipjan
 
1464
      ipgo = -ipflag + 1
 
1465
      go to (90, 628, 629, 630, 631, 632, 633), ipgo
 
1466
 90   iwork(22) = lyh
 
1467
      if (lenrw .gt. lrw) go to 617
 
1468
c set flag to signal parameter changes to stode. -----------------------
 
1469
 92   jstart = -1
 
1470
      if (n .eq. nyh) go to 200
 
1471
c neq was reduced.  zero part of yh to avoid undefined references. -----
 
1472
      i1 = lyh + l*nyh
 
1473
      i2 = lyh + (maxord + 1)*nyh - 1
 
1474
      if (i1 .gt. i2) go to 200
 
1475
      do 95 i = i1,i2
 
1476
 95     rwork(i) = 0.0d0
 
1477
      go to 200
 
1478
c-----------------------------------------------------------------------
 
1479
c block c.
 
1480
c the next block is for the initial call only (istate = 1).
 
1481
c it contains all remaining initializations, the initial call to f,
 
1482
c the sparse matrix preprocessing (miter = 1 or 2), and the
 
1483
c calculation of the initial step size.
 
1484
c the error weights in ewt are inverted after being loaded.
 
1485
c-----------------------------------------------------------------------
 
1486
 100  continue
 
1487
      lyh = lyhn
 
1488
      iwork(22) = lyh
 
1489
      tn = t
 
1490
      nst = 0
 
1491
      h = 1.0d0
 
1492
      nnz = 0
 
1493
      ngp = 0
 
1494
      nzl = 0
 
1495
      nzu = 0
 
1496
c load the initial value vector in yh. ---------------------------------
 
1497
      do 105 i = 1,n
 
1498
 105    rwork(i+lyh-1) = y(i)
 
1499
c initial call to f.  (lf0 points to yh(*,2).) -------------------------
 
1500
      lf0 = lyh + nyh
 
1501
      call f (neq, t, y, rwork(lf0))
 
1502
      nfe = 1
 
1503
c load and invert the ewt array.  (h is temporarily set to 1.0.) -------
 
1504
      call ewset (n, itol, rtol, atol, rwork(lyh), rwork(lewt))
 
1505
      do 110 i = 1,n
 
1506
        if (rwork(i+lewt-1) .le. 0.0d0) go to 621
 
1507
 110    rwork(i+lewt-1) = 1.0d0/rwork(i+lewt-1)
 
1508
      if (miter .eq. 0 .or. miter .eq. 3) go to 120
 
1509
c iprep and prep do sparse matrix preprocessing if miter = 1 or 2. -----
 
1510
      lacor = min0(lacor,lrw)
 
1511
      call iprep (neq, y, rwork, iwork(lia), iwork(lja), ipflag, f, jac)
 
1512
      lenrw = lwm - 1 + lenwk + lrest
 
1513
      iwork(17) = lenrw
 
1514
      if (ipflag .ne. -1) iwork(23) = ipian
 
1515
      if (ipflag .ne. -1) iwork(24) = ipjan
 
1516
      ipgo = -ipflag + 1
 
1517
      go to (115, 628, 629, 630, 631, 632, 633), ipgo
 
1518
 115  iwork(22) = lyh
 
1519
      if (lenrw .gt. lrw) go to 617
 
1520
c check tcrit for legality (itask = 4 or 5). ---------------------------
 
1521
 120  continue
 
1522
      if (itask .ne. 4 .and. itask .ne. 5) go to 125
 
1523
      tcrit = rwork(1)
 
1524
      if ((tcrit - tout)*(tout - t) .lt. 0.0d0) go to 625
 
1525
      if (h0 .ne. 0.0d0 .and. (t + h0 - tcrit)*h0 .gt. 0.0d0)
 
1526
     1   h0 = tcrit - t
 
1527
c initialize all remaining parameters. ---------------------------------
 
1528
 125  uround = d1mach(4)
 
1529
      jstart = 0
 
1530
      if (miter .ne. 0) rwork(lwm) = dsqrt(uround)
 
1531
      msbj = 50
 
1532
      nslj = 0
 
1533
      ccmxj = 0.2d0
 
1534
      psmall = 1000.0d0*uround
 
1535
      rbig = 0.01d0/psmall
 
1536
      nhnil = 0
 
1537
      nje = 0
 
1538
      nlu = 0
 
1539
      nslast = 0
 
1540
      hu = 0.0d0
 
1541
      nqu = 0
 
1542
      ccmax = 0.3d0
 
1543
      maxcor = 3
 
1544
      msbp = 20
 
1545
      mxncf = 10
 
1546
c-----------------------------------------------------------------------
 
1547
c the coding below computes the step size, h0, to be attempted on the
 
1548
c first step, unless the user has supplied a value for this.
 
1549
c first check that tout - t differs significantly from zero.
 
1550
c a scalar tolerance quantity tol is computed, as max(rtol(i))
 
1551
c if this is positive, or max(atol(i)/abs(y(i))) otherwise, adjusted
 
1552
c so as to be between 100*uround and 1.0e-3.
 
1553
c then the computed value h0 is given by..
 
1554
c                                      neq
 
1555
c   h0**2 = tol / ( w0**-2 + (1/neq) * sum ( f(i)/ywt(i) )**2  )
 
1556
c                                       1
 
1557
c where   w0     = max ( abs(t), abs(tout) ),
 
1558
c         f(i)   = i-th component of initial value of f,
 
1559
c         ywt(i) = ewt(i)/tol  (a weight for y(i)).
 
1560
c the sign of h0 is inferred from the initial values of tout and t.
 
1561
c-----------------------------------------------------------------------
 
1562
      lf0 = lyh + nyh
 
1563
      if (h0 .ne. 0.0d0) go to 180
 
1564
      tdist = dabs(tout - t)
 
1565
      w0 = dmax1(dabs(t),dabs(tout))
 
1566
      if (tdist .lt. 2.0d0*uround*w0) go to 622
 
1567
      tol = rtol(1)
 
1568
      if (itol .le. 2) go to 140
 
1569
      do 130 i = 1,n
 
1570
 130    tol = dmax1(tol,rtol(i))
 
1571
 140  if (tol .gt. 0.0d0) go to 160
 
1572
      atoli = atol(1)
 
1573
      do 150 i = 1,n
 
1574
        if (itol .eq. 2 .or. itol .eq. 4) atoli = atol(i)
 
1575
        ayi = dabs(y(i))
 
1576
        if (ayi .ne. 0.0d0) tol = dmax1(tol,atoli/ayi)
 
1577
 150    continue
 
1578
 160  tol = dmax1(tol,100.0d0*uround)
 
1579
      tol = dmin1(tol,0.001d0)
 
1580
      sum = vnorm (n, rwork(lf0), rwork(lewt))
 
1581
      sum = 1.0d0/(tol*w0*w0) + tol*sum**2
 
1582
      h0 = 1.0d0/dsqrt(sum)
 
1583
      h0 = dmin1(h0,tdist)
 
1584
      h0 = dsign(h0,tout-t)
 
1585
c adjust h0 if necessary to meet hmax bound. ---------------------------
 
1586
 180  rh = dabs(h0)*hmxi
 
1587
      if (rh .gt. 1.0d0) h0 = h0/rh
 
1588
c load h with h0 and scale yh(*,2) by h0. ------------------------------
 
1589
      h = h0
 
1590
      do 190 i = 1,n
 
1591
 190    rwork(i+lf0-1) = h0*rwork(i+lf0-1)
 
1592
      go to 270
 
1593
c-----------------------------------------------------------------------
 
1594
c block d.
 
1595
c the next code block is for continuation calls only (istate = 2 or 3)
 
1596
c and is to check stop conditions before taking a step.
 
1597
c-----------------------------------------------------------------------
 
1598
 200  nslast = nst
 
1599
      go to (210, 250, 220, 230, 240), itask
 
1600
 210  if ((tn - tout)*h .lt. 0.0d0) go to 250
 
1601
      call intdy (tout, 0, rwork(lyh), nyh, y, iflag)
 
1602
      if (iflag .ne. 0) go to 627
 
1603
      t = tout
 
1604
      go to 420
 
1605
 220  tp = tn - hu*(1.0d0 + 100.0d0*uround)
 
1606
      if ((tp - tout)*h .gt. 0.0d0) go to 623
 
1607
      if ((tn - tout)*h .lt. 0.0d0) go to 250
 
1608
      go to 400
 
1609
 230  tcrit = rwork(1)
 
1610
      if ((tn - tcrit)*h .gt. 0.0d0) go to 624
 
1611
      if ((tcrit - tout)*h .lt. 0.0d0) go to 625
 
1612
      if ((tn - tout)*h .lt. 0.0d0) go to 245
 
1613
      call intdy (tout, 0, rwork(lyh), nyh, y, iflag)
 
1614
      if (iflag .ne. 0) go to 627
 
1615
      t = tout
 
1616
      go to 420
 
1617
 240  tcrit = rwork(1)
 
1618
      if ((tn - tcrit)*h .gt. 0.0d0) go to 624
 
1619
 245  hmx = dabs(tn) + dabs(h)
 
1620
      ihit = dabs(tn - tcrit) .le. 100.0d0*uround*hmx
 
1621
      if (ihit) go to 400
 
1622
      tnext = tn + h*(1.0d0 + 4.0d0*uround)
 
1623
      if ((tnext - tcrit)*h .le. 0.0d0) go to 250
 
1624
      h = (tcrit - tn)*(1.0d0 - 4.0d0*uround)
 
1625
      if (istate .eq. 2) jstart = -2
 
1626
c-----------------------------------------------------------------------
 
1627
c block e.
 
1628
c the next block is normally executed for all calls and contains
 
1629
c the call to the one-step core integrator stode.
 
1630
c
 
1631
c this is a looping point for the integration steps.
 
1632
c
 
1633
c first check for too many steps being taken, update ewt (if not at
 
1634
c start of problem), check for too much accuracy being requested, and
 
1635
c check for h below the roundoff level in t.
 
1636
c-----------------------------------------------------------------------
 
1637
 250  continue
 
1638
      if ((nst-nslast) .ge. mxstep) go to 500
 
1639
      call ewset (n, itol, rtol, atol, rwork(lyh), rwork(lewt))
 
1640
      do 260 i = 1,n
 
1641
        if (rwork(i+lewt-1) .le. 0.0d0) go to 510
 
1642
 260    rwork(i+lewt-1) = 1.0d0/rwork(i+lewt-1)
 
1643
 270  tolsf = uround*vnorm (n, rwork(lyh), rwork(lewt))
 
1644
      if (tolsf .le. 1.0d0) go to 280
 
1645
      tolsf = tolsf*2.0d0
 
1646
      if (nst .eq. 0) go to 626
 
1647
      go to 520
 
1648
 280  if ((tn + h) .ne. tn) go to 290
 
1649
      nhnil = nhnil + 1
 
1650
      if (nhnil .gt. mxhnil) go to 290
 
1651
      call xerrwv('lsodes-- warning..internal t (=r1) and h (=r2) are',
 
1652
     1   50, 101, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1653
      call xerrwv(
 
1654
     1  '      such that in the machine, t + h = t on the next step  ',
 
1655
     1   60, 101, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1656
      call xerrwv('      (h = step size). solver will continue anyway',
 
1657
     1   50, 101, 0, 0, 0, 0, 2, tn, h)
 
1658
      if (nhnil .lt. mxhnil) go to 290
 
1659
      call xerrwv('lsodes-- above warning has been issued i1 times.  ',
 
1660
     1   50, 102, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1661
      call xerrwv('      it will not be issued again for this problem',
 
1662
     1   50, 102, 0, 1, mxhnil, 0, 0, 0.0d0, 0.0d0)
 
1663
 290  continue
 
1664
c-----------------------------------------------------------------------
 
1665
c    call stode(neq,y,yh,nyh,yh,ewt,savf,acor,wm,wm,f,jac,prjs,slss)
 
1666
c-----------------------------------------------------------------------
 
1667
      call stode (neq, y, rwork(lyh), nyh, rwork(lyh), rwork(lewt),
 
1668
     1   rwork(lsavf), rwork(lacor), rwork(lwm), rwork(lwm),
 
1669
     2   f, jac, prjs, slss)
 
1670
      kgo = 1 - kflag
 
1671
      go to (300, 530, 540, 550), kgo
 
1672
c-----------------------------------------------------------------------
 
1673
c block f.
 
1674
c the following block handles the case of a successful return from the
 
1675
c core integrator (kflag = 0).  test for stop conditions.
 
1676
c-----------------------------------------------------------------------
 
1677
 300  init = 1
 
1678
      go to (310, 400, 330, 340, 350), itask
 
1679
c itask = 1.  if tout has been reached, interpolate. -------------------
 
1680
 310  if ((tn - tout)*h .lt. 0.0d0) go to 250
 
1681
      call intdy (tout, 0, rwork(lyh), nyh, y, iflag)
 
1682
      t = tout
 
1683
      go to 420
 
1684
c itask = 3.  jump to exit if tout was reached. ------------------------
 
1685
 330  if ((tn - tout)*h .ge. 0.0d0) go to 400
 
1686
      go to 250
 
1687
c itask = 4.  see if tout or tcrit was reached.  adjust h if necessary.
 
1688
 340  if ((tn - tout)*h .lt. 0.0d0) go to 345
 
1689
      call intdy (tout, 0, rwork(lyh), nyh, y, iflag)
 
1690
      t = tout
 
1691
      go to 420
 
1692
 345  hmx = dabs(tn) + dabs(h)
 
1693
      ihit = dabs(tn - tcrit) .le. 100.0d0*uround*hmx
 
1694
      if (ihit) go to 400
 
1695
      tnext = tn + h*(1.0d0 + 4.0d0*uround)
 
1696
      if ((tnext - tcrit)*h .le. 0.0d0) go to 250
 
1697
      h = (tcrit - tn)*(1.0d0 - 4.0d0*uround)
 
1698
      jstart = -2
 
1699
      go to 250
 
1700
c itask = 5.  see if tcrit was reached and jump to exit. ---------------
 
1701
 350  hmx = dabs(tn) + dabs(h)
 
1702
      ihit = dabs(tn - tcrit) .le. 100.0d0*uround*hmx
 
1703
c-----------------------------------------------------------------------
 
1704
c block g.
 
1705
c the following block handles all successful returns from lsodes.
 
1706
c if itask .ne. 1, y is loaded from yh and t is set accordingly.
 
1707
c istate is set to 2, the illegal input counter is zeroed, and the
 
1708
c optional outputs are loaded into the work arrays before returning.
 
1709
c if istate = 1 and tout = t, there is a return with no action taken,
 
1710
c except that if this has happened repeatedly, the run is terminated.
 
1711
c-----------------------------------------------------------------------
 
1712
 400  do 410 i = 1,n
 
1713
 410    y(i) = rwork(i+lyh-1)
 
1714
      t = tn
 
1715
      if (itask .ne. 4 .and. itask .ne. 5) go to 420
 
1716
      if (ihit) t = tcrit
 
1717
 420  istate = 2
 
1718
      illin = 0
 
1719
      rwork(11) = hu
 
1720
      rwork(12) = h
 
1721
      rwork(13) = tn
 
1722
      iwork(11) = nst
 
1723
      iwork(12) = nfe
 
1724
      iwork(13) = nje
 
1725
      iwork(14) = nqu
 
1726
      iwork(15) = nq
 
1727
      iwork(19) = nnz
 
1728
      iwork(20) = ngp
 
1729
      iwork(21) = nlu
 
1730
      iwork(25) = nzl
 
1731
      iwork(26) = nzu
 
1732
      return
 
1733
c
 
1734
 430  ntrep = ntrep + 1
 
1735
      if (ntrep .lt. 5) return
 
1736
      call xerrwv(
 
1737
     1  'lsodes-- repeated calls with istate = 1 and tout = t (=r1)  ',
 
1738
     1   60, 301, 0, 0, 0, 0, 1, t, 0.0d0)
 
1739
      go to 800
 
1740
c-----------------------------------------------------------------------
 
1741
c block h.
 
1742
c the following block handles all unsuccessful returns other than
 
1743
c those for illegal input.  first the error message routine is called.
 
1744
c if there was an error test or convergence test failure, imxer is set.
 
1745
c then y is loaded from yh, t is set to tn, and the illegal input
 
1746
c counter illin is set to 0.  the optional outputs are loaded into
 
1747
c the work arrays before returning.
 
1748
c-----------------------------------------------------------------------
 
1749
c the maximum number of steps was taken before reaching tout. ----------
 
1750
 500  call xerrwv('lsodes-- at current t (=r1), mxstep (=i1) steps   ',
 
1751
     1   50, 201, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1752
      call xerrwv('      taken on this call before reaching tout     ',
 
1753
     1   50, 201, 0, 1, mxstep, 0, 1, tn, 0.0d0)
 
1754
      istate = -1
 
1755
      go to 580
 
1756
c ewt(i) .le. 0.0 for some i (not at start of problem). ----------------
 
1757
 510  ewti = rwork(lewt+i-1)
 
1758
      call xerrwv('lsodes-- at t (=r1), ewt(i1) has become r2 .le. 0.',
 
1759
     1   50, 202, 0, 1, i, 0, 2, tn, ewti)
 
1760
      istate = -6
 
1761
      go to 580
 
1762
c too much accuracy requested for machine precision. -------------------
 
1763
 520  call xerrwv('lsodes-- at t (=r1), too much accuracy requested  ',
 
1764
     1   50, 203, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1765
      call xerrwv('      for precision of machine..  see tolsf (=r2) ',
 
1766
     1   50, 203, 0, 0, 0, 0, 2, tn, tolsf)
 
1767
      rwork(14) = tolsf
 
1768
      istate = -2
 
1769
      go to 580
 
1770
c kflag = -1.  error test failed repeatedly or with abs(h) = hmin. -----
 
1771
 530  call xerrwv('lsodes-- at t(=r1) and step size h(=r2), the error',
 
1772
     1   50, 204, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1773
      call xerrwv('      test failed repeatedly or with abs(h) = hmin',
 
1774
     1   50, 204, 0, 0, 0, 0, 2, tn, h)
 
1775
      istate = -4
 
1776
      go to 560
 
1777
c kflag = -2.  convergence failed repeatedly or with abs(h) = hmin. ----
 
1778
 540  call xerrwv('lsodes-- at t (=r1) and step size h (=r2), the    ',
 
1779
     1   50, 205, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1780
      call xerrwv('      corrector convergence failed repeatedly     ',
 
1781
     1   50, 205, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1782
      call xerrwv('      or with abs(h) = hmin   ',
 
1783
     1   30, 205, 0, 0, 0, 0, 2, tn, h)
 
1784
      istate = -5
 
1785
      go to 560
 
1786
c kflag = -3.  fatal error flag returned by prjs or slss (cdrv). -------
 
1787
 550  call xerrwv('lsodes-- at t (=r1) and step size h (=r2), a fatal',
 
1788
     1   50, 207, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1789
      call xerrwv('      error flag was returned by cdrv (by way of  ',
 
1790
     1   50, 207, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1791
      call xerrwv('      subroutine prjs or slss)',
 
1792
     1   30, 207, 0, 0, 0, 0, 2, tn, h)
 
1793
      istate = -7
 
1794
      go to 580
 
1795
c compute imxer if relevant. -------------------------------------------
 
1796
 560  big = 0.0d0
 
1797
      imxer = 1
 
1798
      do 570 i = 1,n
 
1799
        size = dabs(rwork(i+lacor-1)*rwork(i+lewt-1))
 
1800
        if (big .ge. size) go to 570
 
1801
        big = size
 
1802
        imxer = i
 
1803
 570    continue
 
1804
      iwork(16) = imxer
 
1805
c set y vector, t, illin, and optional outputs. ------------------------
 
1806
 580  do 590 i = 1,n
 
1807
 590    y(i) = rwork(i+lyh-1)
 
1808
      t = tn
 
1809
      illin = 0
 
1810
      rwork(11) = hu
 
1811
      rwork(12) = h
 
1812
      rwork(13) = tn
 
1813
      iwork(11) = nst
 
1814
      iwork(12) = nfe
 
1815
      iwork(13) = nje
 
1816
      iwork(14) = nqu
 
1817
      iwork(15) = nq
 
1818
      iwork(19) = nnz
 
1819
      iwork(20) = ngp
 
1820
      iwork(21) = nlu
 
1821
      iwork(25) = nzl
 
1822
      iwork(26) = nzu
 
1823
      return
 
1824
c-----------------------------------------------------------------------
 
1825
c block i.
 
1826
c the following block handles all error returns due to illegal input
 
1827
c (istate = -3), as detected before calling the core integrator.
 
1828
c first the error message routine is called.  then if there have been
 
1829
c 5 consecutive such returns just before this call to the solver,
 
1830
c the run is halted.
 
1831
c-----------------------------------------------------------------------
 
1832
 601  call xerrwv('lsodes-- istate (=i1) illegal ',
 
1833
     1   30, 1, 0, 1, istate, 0, 0, 0.0d0, 0.0d0)
 
1834
      go to 700
 
1835
 602  call xerrwv('lsodes-- itask (=i1) illegal  ',
 
1836
     1   30, 2, 0, 1, itask, 0, 0, 0.0d0, 0.0d0)
 
1837
      go to 700
 
1838
 603  call xerrwv('lsodes-- istate .gt. 1 but lsodes not initialized ',
 
1839
     1   50, 3, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1840
      go to 700
 
1841
 604  call xerrwv('lsodes-- neq (=i1) .lt. 1     ',
 
1842
     1   30, 4, 0, 1, neq(1), 0, 0, 0.0d0, 0.0d0)
 
1843
      go to 700
 
1844
 605  call xerrwv('lsodes-- istate = 3 and neq increased (i1 to i2)  ',
 
1845
     1   50, 5, 0, 2, n, neq(1), 0, 0.0d0, 0.0d0)
 
1846
      go to 700
 
1847
 606  call xerrwv('lsodes-- itol (=i1) illegal   ',
 
1848
     1   30, 6, 0, 1, itol, 0, 0, 0.0d0, 0.0d0)
 
1849
      go to 700
 
1850
 607  call xerrwv('lsodes-- iopt (=i1) illegal   ',
 
1851
     1   30, 7, 0, 1, iopt, 0, 0, 0.0d0, 0.0d0)
 
1852
      go to 700
 
1853
 608  call xerrwv('lsodes-- mf (=i1) illegal     ',
 
1854
     1   30, 8, 0, 1, mf, 0, 0, 0.0d0, 0.0d0)
 
1855
      go to 700
 
1856
 609  call xerrwv('lsodes-- seth (=r1) .lt. 0.0  ',
 
1857
     1   30, 9, 0, 0, 0, 0, 1, seth, 0.0d0)
 
1858
      go to 700
 
1859
 611  call xerrwv('lsodes-- maxord (=i1) .lt. 0  ',
 
1860
     1   30, 11, 0, 1, maxord, 0, 0, 0.0d0, 0.0d0)
 
1861
      go to 700
 
1862
 612  call xerrwv('lsodes-- mxstep (=i1) .lt. 0  ',
 
1863
     1   30, 12, 0, 1, mxstep, 0, 0, 0.0d0, 0.0d0)
 
1864
      go to 700
 
1865
 613  call xerrwv('lsodes-- mxhnil (=i1) .lt. 0  ',
 
1866
     1   30, 13, 0, 1, mxhnil, 0, 0, 0.0d0, 0.0d0)
 
1867
      go to 700
 
1868
 614  call xerrwv('lsodes-- tout (=r1) behind t (=r2)      ',
 
1869
     1   40, 14, 0, 0, 0, 0, 2, tout, t)
 
1870
      call xerrwv('      integration direction is given by h0 (=r1)  ',
 
1871
     1   50, 14, 0, 0, 0, 0, 1, h0, 0.0d0)
 
1872
      go to 700
 
1873
 615  call xerrwv('lsodes-- hmax (=r1) .lt. 0.0  ',
 
1874
     1   30, 15, 0, 0, 0, 0, 1, hmax, 0.0d0)
 
1875
      go to 700
 
1876
 616  call xerrwv('lsodes-- hmin (=r1) .lt. 0.0  ',
 
1877
     1   30, 16, 0, 0, 0, 0, 1, hmin, 0.0d0)
 
1878
      go to 700
 
1879
 617  call xerrwv('lsodes-- rwork length is insufficient to proceed. ',
 
1880
     1   50, 17, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1881
      call xerrwv(
 
1882
     1  '        length needed is .ge. lenrw (=i1), exceeds lrw (=i2)',
 
1883
     1   60, 17, 0, 2, lenrw, lrw, 0, 0.0d0, 0.0d0)
 
1884
      go to 700
 
1885
 618  call xerrwv('lsodes-- iwork length is insufficient to proceed. ',
 
1886
     1   50, 18, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1887
      call xerrwv(
 
1888
     1  '        length needed is .ge. leniw (=i1), exceeds liw (=i2)',
 
1889
     1   60, 18, 0, 2, leniw, liw, 0, 0.0d0, 0.0d0)
 
1890
      go to 700
 
1891
 619  call xerrwv('lsodes-- rtol(i1) is r1 .lt. 0.0        ',
 
1892
     1   40, 19, 0, 1, i, 0, 1, rtoli, 0.0d0)
 
1893
      go to 700
 
1894
 620  call xerrwv('lsodes-- atol(i1) is r1 .lt. 0.0        ',
 
1895
     1   40, 20, 0, 1, i, 0, 1, atoli, 0.0d0)
 
1896
      go to 700
 
1897
 621  ewti = rwork(lewt+i-1)
 
1898
      call xerrwv('lsodes-- ewt(i1) is r1 .le. 0.0         ',
 
1899
     1   40, 21, 0, 1, i, 0, 1, ewti, 0.0d0)
 
1900
      go to 700
 
1901
 622  call xerrwv(
 
1902
     1  'lsodes-- tout (=r1) too close to t(=r2) to start integration',
 
1903
     1   60, 22, 0, 0, 0, 0, 2, tout, t)
 
1904
      go to 700
 
1905
 623  call xerrwv(
 
1906
     1  'lsodes-- itask = i1 and tout (=r1) behind tcur - hu (= r2)  ',
 
1907
     1   60, 23, 0, 1, itask, 0, 2, tout, tp)
 
1908
      go to 700
 
1909
 624  call xerrwv(
 
1910
     1  'lsodes-- itask = 4 or 5 and tcrit (=r1) behind tcur (=r2)   ',
 
1911
     1   60, 24, 0, 0, 0, 0, 2, tcrit, tn)
 
1912
      go to 700
 
1913
 625  call xerrwv(
 
1914
     1  'lsodes-- itask = 4 or 5 and tcrit (=r1) behind tout (=r2)   ',
 
1915
     1   60, 25, 0, 0, 0, 0, 2, tcrit, tout)
 
1916
      go to 700
 
1917
 626  call xerrwv('lsodes-- at start of problem, too much accuracy   ',
 
1918
     1   50, 26, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1919
      call xerrwv(
 
1920
     1  '      requested for precision of machine..  see tolsf (=r1) ',
 
1921
     1   60, 26, 0, 0, 0, 0, 1, tolsf, 0.0d0)
 
1922
      rwork(14) = tolsf
 
1923
      go to 700
 
1924
 627  call xerrwv('lsodes-- trouble from intdy. itask = i1, tout = r1',
 
1925
     1   50, 27, 0, 1, itask, 0, 1, tout, 0.0d0)
 
1926
      go to 700
 
1927
 628  call xerrwv(
 
1928
     1  'lsodes-- rwork length insufficient (for subroutine prep).   ',
 
1929
     1   60, 28, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1930
      call xerrwv(
 
1931
     1  '        length needed is .ge. lenrw (=i1), exceeds lrw (=i2)',
 
1932
     1   60, 28, 0, 2, lenrw, lrw, 0, 0.0d0, 0.0d0)
 
1933
      go to 700
 
1934
 629  call xerrwv(
 
1935
     1  'lsodes-- rwork length insufficient (for subroutine jgroup). ',
 
1936
     1   60, 29, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1937
      call xerrwv(
 
1938
     1  '        length needed is .ge. lenrw (=i1), exceeds lrw (=i2)',
 
1939
     1   60, 29, 0, 2, lenrw, lrw, 0, 0.0d0, 0.0d0)
 
1940
      go to 700
 
1941
 630  call xerrwv(
 
1942
     1  'lsodes-- rwork length insufficient (for subroutine odrv).   ',
 
1943
     1   60, 30, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1944
      call xerrwv(
 
1945
     1  '        length needed is .ge. lenrw (=i1), exceeds lrw (=i2)',
 
1946
     1   60, 30, 0, 2, lenrw, lrw, 0, 0.0d0, 0.0d0)
 
1947
      go to 700
 
1948
 631  call xerrwv(
 
1949
     1  'lsodes-- error from odrv in yale sparse matrix package      ',
 
1950
     1   60, 31, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1951
      imul = (iys - 1)/n
 
1952
      irem = iys - imul*n
 
1953
      call xerrwv(
 
1954
     1  '      at t (=r1), odrv returned error flag = i1*neq + i2.   ',
 
1955
     1   60, 31, 0, 2, imul, irem, 1, tn, 0.0d0)
 
1956
      go to 700
 
1957
 632  call xerrwv(
 
1958
     1  'lsodes-- rwork length insufficient (for subroutine cdrv).   ',
 
1959
     1   60, 32, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1960
      call xerrwv(
 
1961
     1  '        length needed is .ge. lenrw (=i1), exceeds lrw (=i2)',
 
1962
     1   60, 32, 0, 2, lenrw, lrw, 0, 0.0d0, 0.0d0)
 
1963
      go to 700
 
1964
 633  call xerrwv(
 
1965
     1  'lsodes-- error from cdrv in yale sparse matrix package      ',
 
1966
     1   60, 33, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1967
      imul = (iys - 1)/n
 
1968
      irem = iys - imul*n
 
1969
      call xerrwv(
 
1970
     1  '      at t (=r1), cdrv returned error flag = i1*neq + i2.   ',
 
1971
     1   60, 33, 0, 2, imul, irem, 1, tn, 0.0d0)
 
1972
      if (imul .eq. 2) call xerrwv(
 
1973
     1  '        duplicate entry in sparsity structure descriptors   ',
 
1974
     1   60, 33, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1975
      if (imul .eq. 3 .or. imul .eq. 6) call xerrwv(
 
1976
     1  '        insufficient storage for nsfc (called by cdrv)      ',
 
1977
     1   60, 33, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1978
c
 
1979
 700  if (illin .eq. 5) go to 710
 
1980
      illin = illin + 1
 
1981
      istate = -3
 
1982
      return
 
1983
 710  call xerrwv('lsodes-- repeated occurrences of illegal input    ',
 
1984
     1   50, 302, 0, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1985
c
 
1986
 800  call xerrwv('lsodes-- run aborted.. apparent infinite loop     ',
 
1987
     1   50, 303, 2, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1988
      return
 
1989
c----------------------- end of subroutine lsodes ----------------------
 
1990
      end