~ubuntu-branches/ubuntu/hoary/scilab/hoary

« back to all changes in this revision

Viewing changes to routines/integ/lsodar2.f

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2005-01-09 22:58:21 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050109225821-473xr8vhgugxxx5j
Tags: 3.0-12
changed configure.in to build scilab's own malloc.o, closes: #255869

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
      subroutine lsodar2(f, neq, y, t, tout, itol, rtol, atol, itask,
 
2
     1            istate, iopt, rwork, lrw, iwork, liw, jac, jt,
 
3
     2            g, ng, jroot)
 
4
      external f, jac, g
 
5
      integer neq, itol, itask, istate, iopt, lrw, iwork, liw, jt,
 
6
     1   ng, jroot
 
7
      double precision y, t, tout, rtol, atol, rwork
 
8
      dimension neq(*), y(*), rtol(*), atol(*), rwork(lrw), iwork(liw),
 
9
     1   jroot(ng)
 
10
c-----------------------------------------------------------------------
 
11
c this is the may 7, 1982 version of
 
12
c lsodar.. livermore solver for ordinary differential equations, with
 
13
c          automatic method switching for stiff and nonstiff problems,
 
14
c          and with root-finding.
 
15
c
 
16
c This version has been modified by scilab group on Feb 97 following Dr
 
17
c      Hindmarsh direction see Comments noted "cSCI"
 
18
c
 
19
c this version is in double precision.
 
20
c
 
21
c lsodar solves the initial value problem for stiff or nonstiff
 
22
c systems of first order ode-s,
 
23
c     dy/dt = f(t,y) ,  or, in component form,
 
24
c     dy(i)/dt = f(i) = f(i,t,y(1),y(2),...,y(neq)) (i = 1,...,neq).
 
25
c at the same time, it locates the roots of any of a set of functions
 
26
c     g(i) = g(i,t,y(1),...,y(neq))  (i = 1,...,ng).
 
27
c
 
28
c this a variant version of the lsode package.  it differs from lsode
 
29
c in two ways..
 
30
c (a) it switches automatically between stiff and nonstiff methods.
 
31
c this means that the user does not have to determine whether the
 
32
c problem is stiff or not, and the solver will automatically choose the
 
33
c appropriate method.  it always starts with the nonstiff method.
 
34
c (b) it finds the root of at least one of a set of constraint
 
35
c functions g(i) of the independent and dependent variables.
 
36
c it finds only those roots for which some g(i), as a function
 
37
c of t, changes sign in the interval of integration.
 
38
c it then returns the solution at the root, if that occurs
 
39
c sooner than the specified stop condition, and otherwise returns
 
40
c the solution according the specified stop condition.
 
41
c
 
42
c authors..
 
43
c                      linda r. petzold
 
44
c                      applied mathematics division 8331
 
45
c                      sandia national laboratories
 
46
c                      livermore, ca 94550
 
47
c and
 
48
c                      alan c. hindmarsh,
 
49
c                      mathematics and statistics division, l-316
 
50
c                      lawrence livermore national laboratory
 
51
c                      livermore, ca 94550.
 
52
c
 
53
c references..
 
54
c 1.  alan c. hindmarsh,  lsode and lsodi, two new initial value
 
55
c     ordinary differential equation solvers,
 
56
c     acm-signum newsletter, vol. 15, no. 4 (1980), pp. 10-11.
 
57
c 2.  linda r. petzold, automatic selection of methods for solving
 
58
c     stiff and nonstiff systems of ordinary differential equations,
 
59
c     siam j. sci. stat. comput. 4 (1983), pp. 136-148.
 
60
c 3.  kathie l. hiebert and lawrence f. shampine, implicitly defined
 
61
c     output points for solutions of ode-s, sandia report sand80-0180,
 
62
c     february, 1980.
 
63
c-----------------------------------------------------------------------
 
64
c summary of usage.
 
65
c
 
66
c communication between the user and the lsodar package, for normal
 
67
c situations, is summarized here.  this summary describes only a subset
 
68
c of the full set of options available.  see the full description for
 
69
c details, including alternative treatment of the jacobian matrix,
 
70
c optional inputs and outputs, nonstandard options, and
 
71
c instructions for special situations.  see also the example
 
72
c problem (with program and output) following this summary.
 
73
c
 
74
c a. first provide a subroutine of the form..
 
75
c               subroutine f (neq, t, y, ydot)
 
76
c               dimension y(neq), ydot(neq)
 
77
c which supplies the vector function f by loading ydot(i) with f(i).
 
78
c
 
79
c b. provide a subroutine of the form..
 
80
c               subroutine g (neq, t, y, ng, gout)
 
81
c               dimension y(neq), gout(ng)
 
82
c which supplies the vector function g by loading gout(i) with
 
83
c g(i), the i-th constraint function whose root is sought.
 
84
c
 
85
c c. write a main program which calls subroutine lsodar once for
 
86
c each point at which answers are desired.  this should also provide
 
87
c for possible use of logical unit 6 for output of error messages by
 
88
c lsodar.  on the first call to lsodar, supply arguments as follows..
 
89
c f      = name of subroutine for right-hand side vector f.
 
90
c          this name must be declared external in calling program.
 
91
c neq    = number of first order ode-s.
 
92
c y      = array of initial values, of length neq.
 
93
c t      = the initial value of the independent variable.
 
94
c tout   = first point where output is desired (.ne. t).
 
95
c itol   = 1 or 2 according as atol (below) is a scalar or array.
 
96
c rtol   = relative tolerance parameter (scalar).
 
97
c atol   = absolute tolerance parameter (scalar or array).
 
98
c          the estimated local error in y(i) will be controlled so as
 
99
c          to be less than
 
100
c             ewt(i) = rtol*abs(y(i)) + atol     if itol = 1, or
 
101
c             ewt(i) = rtol*abs(y(i)) + atol(i)  if itol = 2.
 
102
c          thus the local error test passes if, in each component,
 
103
c          either the absolute error is less than atol (or atol(i)),
 
104
c          or the relative error is less than rtol.
 
105
c          use rtol = 0.0 for pure absolute error control, and
 
106
c          use atol = 0.0 (or atol(i) = 0.0) for pure relative error
 
107
c          control.  caution.. actual (global) errors may exceed these
 
108
c          local tolerances, so choose them conservatively.
 
109
c itask  = 1 for normal computation of output values of y at t = tout.
 
110
c istate = integer flag (input and output).  set istate = 1.
 
111
c iopt   = 0 to indicate no optional inputs used.
 
112
c rwork  = real work array of length at least..
 
113
c             22 + neq * max(16, neq + 9) + 3*ng.
 
114
c          see also paragraph f below.
 
115
c lrw    = declared length of rwork (in user-s dimension).
 
116
c iwork  = integer work array of length at least  20 + neq.
 
117
c liw    = declared length of iwork (in user-s dimension).
 
118
c jac    = name of subroutine for jacobian matrix.
 
119
c          use a dummy name.  see also paragraph f below.
 
120
c jt     = jacobian type indicator.  set jt = 2.
 
121
c          see also paragraph f below.
 
122
c g      = name of subroutine for constraint functions, whose
 
123
c          roots are desired during the integration.
 
124
c          this name must be declared external in calling program.
 
125
c ng     = number of constraint functions g(i).  if there are none,
 
126
c          set ng = 0, and pass a dummy name for g.
 
127
c jroot  = integer array of length ng for output of root information.
 
128
c          see next paragraph.
 
129
c note that the main program must declare arrays y, rwork, iwork,
 
130
c jroot, and possibly atol.
 
131
c
 
132
c d. the output from the first call (or any call) is..
 
133
c      y = array of computed values of y(t) vector.
 
134
c      t = corresponding value of independent variable.  this is
 
135
c          tout if istate = 2, or the root location if istate = 3,
 
136
c          or the farthest point reached if lsodar was unsuccessful.
 
137
c istate = 2 or 3  if lsodar was successful, negative otherwise.
 
138
c           2 means no root was found, and tout was reached as desired.
 
139
c           3 means a root was found prior to reaching tout.
 
140
c          -1 means excess work done on this call (perhaps wrong jt).
 
141
c          -2 means excess accuracy requested (tolerances too small).
 
142
c          -3 means illegal input detected (see printed message).
 
143
c          -4 means repeated error test failures (check all inputs).
 
144
c          -5 means repeated convergence failures (perhaps bad jacobian
 
145
c             supplied or wrong choice of jt or tolerances).
 
146
c          -6 means error weight became zero during problem. (solution
 
147
c             component i vanished, and atol or atol(i) = 0.)
 
148
c          -7 means work space insufficient to finish (see messages).
 
149
c jroot  = array showing roots found if istate = 3 on return.
 
150
c          jroot(i) = 1 if g(i) has a root at t, or 0 otherwise.
 
151
c
 
152
c e. to continue the integration after a successful return, proceed
 
153
c as follows..
 
154
c  (a) if istate = 2 on return, reset tout and call lsodar again.
 
155
c  (b) if istate = 3 on return, reset istate to 2 and call lsodar again.
 
156
c in either case, no other parameters need be reset.
 
157
c
 
158
c f. note.. if and when lsodar regards the problem as stiff, and
 
159
c switches methods accordingly, it must make use of the neq by neq
 
160
c jacobian matrix, j = df/dy.  for the sake of simplicity, the
 
161
c inputs to lsodar recommended in paragraph c above cause lsodar to
 
162
c treat j as a full matrix, and to approximate it internally by
 
163
c difference quotients.  alternatively, j can be treated as a band
 
164
c matrix (with great potential reduction in the size of the rwork
 
165
c array).  also, in either the full or banded case, the user can supply
 
166
c j in closed form, with a routine whose name is passed as the jac
 
167
c argument.  these alternatives are described in the paragraphs on
 
168
c rwork, jac, and jt in the full description of the call sequence below.
 
169
c
 
170
c-----------------------------------------------------------------------
 
171
c example problem.
 
172
c
 
173
c the following is a simple example problem, with the coding
 
174
c needed for its solution by lsodar.  the problem is from chemical
 
175
c kinetics, and consists of the following three rate equations..
 
176
c     dy1/dt = -.04*y1 + 1.e4*y2*y3
 
177
c     dy2/dt = .04*y1 - 1.e4*y2*y3 - 3.e7*y2**2
 
178
c     dy3/dt = 3.e7*y2**2
 
179
c on the interval from t = 0.0 to t = 4.e10, with initial conditions
 
180
c y1 = 1.0, y2 = y3 = 0.  the problem is stiff.
 
181
c in addition, we want to find the values of t, y1, y2, and y3 at which
 
182
c   (1) y1 reaches the value 1.e-4, and
 
183
c   (2) y3 reaches the value 1.e-2.
 
184
c
 
185
c the following coding solves this problem with lsodar,
 
186
c printing results at t = .4, 4., ..., 4.e10, and at the computed
 
187
c roots.  it uses itol = 2 and atol much smaller for y2 than y1 or y3
 
188
c because y2 has much smaller values.
 
189
c at the end of the run, statistical quantities of interest are
 
190
c printed (see optional outputs in the full description below).
 
191
c
 
192
c     external fex, gex
 
193
c     double precision atol, rtol, rwork, t, tout, y
 
194
c     dimension y(3), atol(3), rwork(76), iwork(23), jroot(2)
 
195
c     neq = 3
 
196
c     y(1) = 1.0d0
 
197
c     y(2) = 0.0d0
 
198
c     y(3) = 0.0d0
 
199
c     t = 0.0d0
 
200
c     tout = 0.4d0
 
201
c     itol = 2
 
202
c     rtol = 1.0d-4
 
203
c     atol(1) = 1.0d-6
 
204
c     atol(2) = 1.0d-10
 
205
c     atol(3) = 1.0d-6
 
206
c     itask = 1
 
207
c     istate = 1
 
208
c     iopt = 0
 
209
c     lrw = 76
 
210
c     liw = 23
 
211
c     jt = 2
 
212
c     ng = 2
 
213
c     do 40 iout = 1,12
 
214
c 10    call lsodar(fex,neq,y,t,tout,itol,rtol,atol,itask,istate,
 
215
c    1     iopt,rwork,lrw,iwork,liw,jdum,jt,gex,ng,jroot)
 
216
c       write(6,20)t,y(1),y(2),y(3)
 
217
c 20    format(7h at t =,e12.4,6h   y =,3e14.6)
 
218
c       if (istate .lt. 0) go to 80
 
219
c       if (istate .eq. 2) go to 40
 
220
c       write(6,30)jroot(1),jroot(2)
 
221
c 30    format(5x,35h the above line is a root,  jroot =,2i5)
 
222
c       istate = 2
 
223
c       go to 10
 
224
c 40    tout = tout*10.0d0
 
225
c     write(6,60)iwork(11),iwork(12),iwork(13),iwork(10),
 
226
c    1   iwork(19),rwork(15)
 
227
c 60  format(/12h no. steps =,i4,11h  no. f-s =,i4,11h  no. j-s =,i4,
 
228
c    1   11h  no. g-s =,i4/
 
229
c    2   19h method last used =,i2,25h   last switch was at t =,e12.4)
 
230
c     stop
 
231
c 80  write(6,90)istate
 
232
c 90  format(///22h error halt.. istate =,i3)
 
233
c     stop
 
234
c     end
 
235
c
 
236
c     subroutine fex (neq, t, y, ydot)
 
237
c     double precision t, y, ydot
 
238
c     dimension y(3), ydot(3)
 
239
c     ydot(1) = -0.04d0*y(1) + 1.0d4*y(2)*y(3)
 
240
c     ydot(3) = 3.0d7*y(2)*y(2)
 
241
c     ydot(2) = -ydot(1) - ydot(3)
 
242
c     return
 
243
c     end
 
244
c
 
245
c     subroutine gex (neq, t, y, ng, gout)
 
246
c     double precision t, y, gout
 
247
c     dimension y(3), gout(2)
 
248
c     gout(1) = y(1) - 1.0d-4
 
249
c     gout(2) = y(3) - 1.0d-2
 
250
c     return
 
251
c     end
 
252
c
 
253
c the output of this program (on a cdc-7600 in single precision)
 
254
c is as follows..
 
255
c
 
256
c   at t =  2.6400e-01   y =  9.899653e-01  3.470563e-05  1.000000e-02
 
257
c        the above line is a root,  jroot =    0    1
 
258
c   at t =  4.0000e-01   y =  9.851712e-01  3.386380e-05  1.479493e-02
 
259
c   at t =  4.0000e+00   y =  9.055333e-01  2.240655e-05  9.444430e-02
 
260
c   at t =  4.0000e+01   y =  7.158403e-01  9.186334e-06  2.841505e-01
 
261
c   at t =  4.0000e+02   y =  4.505250e-01  3.222964e-06  5.494717e-01
 
262
c   at t =  4.0000e+03   y =  1.831975e-01  8.941774e-07  8.168016e-01
 
263
c   at t =  4.0000e+04   y =  3.898730e-02  1.621940e-07  9.610125e-01
 
264
c   at t =  4.0000e+05   y =  4.936363e-03  1.984221e-08  9.950636e-01
 
265
c   at t =  4.0000e+06   y =  5.161831e-04  2.065786e-09  9.994838e-01
 
266
c   at t =  2.0745e+07   y =  1.000000e-04  4.000395e-10  9.999000e-01
 
267
c        the above line is a root,  jroot =    1    0
 
268
c   at t =  4.0000e+07   y =  5.179817e-05  2.072032e-10  9.999482e-01
 
269
c   at t =  4.0000e+08   y =  5.283401e-06  2.113371e-11  9.999947e-01
 
270
c   at t =  4.0000e+09   y =  4.659031e-07  1.863613e-12  9.999995e-01
 
271
c   at t =  4.0000e+10   y =  1.404280e-08  5.617126e-14  1.000000e+00
 
272
c
 
273
c   no. steps = 361  no. f-s = 693  no. j-s =  64  no. g-s = 390
 
274
c   method last used = 2   last switch was at t =  6.0092e-03
 
275
c-----------------------------------------------------------------------
 
276
c full description of user interface to lsodar.
 
277
c
 
278
c the user interface to lsodar consists of the following parts.
 
279
c
 
280
c i.   the call sequence to subroutine lsodar, which is a driver
 
281
c      routine for the solver.  this includes descriptions of both
 
282
c      the call sequence arguments and of user-supplied routines.
 
283
c      following these descriptions is a description of
 
284
c      optional inputs available through the call sequence, and then
 
285
c      a description of optional outputs (in the work arrays).
 
286
c
 
287
c ii.  descriptions of other routines in the lsodar package that may be
 
288
c      (optionally) called by the user.  these provide the ability to
 
289
c      alter error message handling, save and restore the internal
 
290
c      common, and obtain specified derivatives of the solution y(t).
 
291
c
 
292
c iii. descriptions of common blocks to be declared in overlay
 
293
c      or similar environments, or to be saved when doing an interrupt
 
294
c      of the problem and continued solution later.
 
295
c
 
296
c iv.  description of a subroutine in the lsodar package,
 
297
c      which the user may replace with his own version, if desired.
 
298
c      this relates to the measurement of errors.
 
299
c
 
300
c-----------------------------------------------------------------------
 
301
c part i.  call sequence.
 
302
c
 
303
c the call sequence parameters used for input only are
 
304
c     f, neq, tout, itol, rtol, atol, itask, iopt, lrw, liw, jac,
 
305
c     jt, g, and ng,
 
306
c that used only for output is  jroot,
 
307
c and those used for both input and output are
 
308
c     y, t, istate.
 
309
c the work arrays rwork and iwork are also used for conditional and
 
310
c optional inputs and optional outputs.  (the term output here refers
 
311
c to the return from subroutine lsodar to the user-s calling program.)
 
312
c
 
313
c the legality of input parameters will be thoroughly checked on the
 
314
c initial call for the problem, but not checked thereafter unless a
 
315
c change in input parameters is flagged by istate = 3 on input.
 
316
c
 
317
c the descriptions of the call arguments are as follows.
 
318
c
 
319
c f      = the name of the user-supplied subroutine defining the
 
320
c          ode system.  the system must be put in the first-order
 
321
c          form dy/dt = f(t,y), where f is a vector-valued function
 
322
c          of the scalar t and the vector y.  subroutine f is to
 
323
c          compute the function f.  it is to have the form
 
324
c               subroutine f (neq, t, y, ydot)
 
325
c               dimension y(1), ydot(1)
 
326
c          where neq, t, and y are input, and the array ydot = f(t,y)
 
327
c          is output.  y and ydot are arrays of length neq.
 
328
c          (in the dimension statement above, 1 is a dummy
 
329
c          dimension.. it can be replaced by any value.)
 
330
c          subroutine f should not alter y(1),...,y(neq).
 
331
c          f must be declared external in the calling program.
 
332
c
 
333
c          subroutine f may access user-defined quantities in
 
334
c          neq(2),... and y(neq(1)+1),... if neq is an array
 
335
c          (dimensioned in f) and y has length exceeding neq(1).
 
336
c          see the descriptions of neq and y below.
 
337
c
 
338
c neq    = the size of the ode system (number of first order
 
339
c          ordinary differential equations).  used only for input.
 
340
c          neq may be decreased, but not increased, during the problem.
 
341
c          if neq is decreased (with istate = 3 on input), the
 
342
c          remaining components of y should be left undisturbed, if
 
343
c          these are to be accessed in f and/or jac.
 
344
c
 
345
c          normally, neq is a scalar, and it is generally referred to
 
346
c          as a scalar in this user interface description.  however,
 
347
c          neq may be an array, with neq(1) set to the system size.
 
348
c          (the lsodar package accesses only neq(1).)  in either case,
 
349
c          this parameter is passed as the neq argument in all calls
 
350
c          to f, jac, and g.  hence, if it is an array, locations
 
351
c          neq(2),... may be used to store other integer data and pass
 
352
c          it to f, jac, and g.  each such subroutine must include
 
353
c          neq in a dimension statement in that case.
 
354
c
 
355
c y      = a real array for the vector of dependent variables, of
 
356
c          length neq or more.  used for both input and output on the
 
357
c          first call (istate = 1), and only for output on other calls.
 
358
c          on the first call, y must contain the vector of initial
 
359
c          values.  on output, y contains the computed solution vector,
 
360
c          evaluated at t.  if desired, the y array may be used
 
361
c          for other purposes between calls to the solver.
 
362
c
 
363
c          this array is passed as the y argument in all calls to f,
 
364
c          jac, and g.  hence its length may exceed neq, and locations
 
365
c          y(neq+1),... may be used to store other real data and
 
366
c          pass it to f, jac, and g.  (the lsodar package accesses only
 
367
c          y(1),...,y(neq).)
 
368
c
 
369
c t      = the independent variable.  on input, t is used only on the
 
370
c          first call, as the initial point of the integration.
 
371
c          on output, after each call, t is the value at which a
 
372
c          computed solution y is evaluated (usually the same as tout).
 
373
c          if a root was found, t is the computed location of the
 
374
c          root reached first, on output.
 
375
c          on an error return, t is the farthest point reached.
 
376
c
 
377
c tout   = the next value of t at which a computed solution is desired.
 
378
c          used only for input.
 
379
c
 
380
c          when starting the problem (istate = 1), tout may be equal
 
381
c          to t for one call, then should .ne. t for the next call.
 
382
c          for the initial t, an input value of tout .ne. t is used
 
383
c          in order to determine the direction of the integration
 
384
c          (i.e. the algebraic sign of the step sizes) and the rough
 
385
c          scale of the problem.  integration in either direction
 
386
c          (forward or backward in t) is permitted.
 
387
c
 
388
c          if itask = 2 or 5 (one-step modes), tout is ignored after
 
389
c          the first call (i.e. the first call with tout .ne. t).
 
390
c          otherwise, tout is required on every call.
 
391
c
 
392
c          if itask = 1, 3, or 4, the values of tout need not be
 
393
c          monotone, but a value of tout which backs up is limited
 
394
c          to the current internal t interval, whose endpoints are
 
395
c          tcur - hu and tcur (see optional outputs, below, for
 
396
c          tcur and hu).
 
397
c
 
398
c itol   = an indicator for the type of error control.  see
 
399
c          description below under atol.  used only for input.
 
400
c
 
401
c rtol   = a relative error tolerance parameter, either a scalar or
 
402
c          an array of length neq.  see description below under atol.
 
403
c          input only.
 
404
c
 
405
c atol   = an absolute error tolerance parameter, either a scalar or
 
406
c          an array of length neq.  input only.
 
407
c
 
408
c             the input parameters itol, rtol, and atol determine
 
409
c          the error control performed by the solver.  the solver will
 
410
c          control the vector e = (e(i)) of estimated local errors
 
411
c          in y, according to an inequality of the form
 
412
c                      max-norm of ( e(i)/ewt(i) )   .le.   1,
 
413
c          where ewt = (ewt(i)) is a vector of positive error weights.
 
414
c          the values of rtol and atol should all be non-negative.
 
415
c          the following table gives the types (scalar/array) of
 
416
c          rtol and atol, and the corresponding form of ewt(i).
 
417
c
 
418
c             itol    rtol       atol          ewt(i)
 
419
c              1     scalar     scalar     rtol*abs(y(i)) + atol
 
420
c              2     scalar     array      rtol*abs(y(i)) + atol(i)
 
421
c              3     array      scalar     rtol(i)*abs(y(i)) + atol
 
422
c              4     array      array      rtol(i)*abs(y(i)) + atol(i)
 
423
c
 
424
c          when either of these parameters is a scalar, it need not
 
425
c          be dimensioned in the user-s calling program.
 
426
c
 
427
c          if none of the above choices (with itol, rtol, and atol
 
428
c          fixed throughout the problem) is suitable, more general
 
429
c          error controls can be obtained by substituting a
 
430
c          user-supplied routine for the setting of ewt.
 
431
c          see part iv below.
 
432
c
 
433
c          if global errors are to be estimated by making a repeated
 
434
c          run on the same problem with smaller tolerances, then all
 
435
c          components of rtol and atol (i.e. of ewt) should be scaled
 
436
c          down uniformly.
 
437
c
 
438
c itask  = an index specifying the task to be performed.
 
439
c          input only.  itask has the following values and meanings.
 
440
c          1  means normal computation of output values of y(t) at
 
441
c             t = tout (by overshooting and interpolating).
 
442
c          2  means take one step only and return.
 
443
c          3  means stop at the first internal mesh point at or
 
444
c             beyond t = tout and return.
 
445
c          4  means normal computation of output values of y(t) at
 
446
c             t = tout but without overshooting t = tcrit.
 
447
c             tcrit must be input as rwork(1).  tcrit may be equal to
 
448
c             or beyond tout, but not behind it in the direction of
 
449
c             integration.  this option is useful if the problem
 
450
c             has a singularity at or beyond t = tcrit.
 
451
c          5  means take one step, without passing tcrit, and return.
 
452
c             tcrit must be input as rwork(1).
 
453
c
 
454
c          note..  if itask = 4 or 5 and the solver reaches tcrit
 
455
c          (within roundoff), it will return t = tcrit (exactly) to
 
456
c          indicate this (unless itask = 4 and tout comes before tcrit,
 
457
c          in which case answers at t = tout are returned first).
 
458
c
 
459
c istate = an index used for input and output to specify the
 
460
c          the state of the calculation.
 
461
c
 
462
c          on input, the values of istate are as follows.
 
463
c          1  means this is the first call for the problem
 
464
c             (initializations will be done).  see note below.
 
465
c          2  means this is not the first call, and the calculation
 
466
c             is to continue normally, with no change in any input
 
467
c             parameters except possibly tout and itask.
 
468
c             (if itol, rtol, and/or atol are changed between calls
 
469
c             with istate = 2, the new values will be used but not
 
470
c             tested for legality.)
 
471
c          3  means this is not the first call, and the
 
472
c             calculation is to continue normally, but with
 
473
c             a change in input parameters other than
 
474
c             tout and itask.  changes are allowed in
 
475
c             neq, itol, rtol, atol, iopt, lrw, liw, jt, ml, mu,
 
476
c             and any optional inputs except h0, mxordn, and mxords.
 
477
c             (see iwork description for ml and mu.)
 
478
c             in addition, immediately following a return with
 
479
c             istate = 3 (root found), ng and g may be changed.
 
480
c             (but changing ng from 0 to .gt. 0 is not allowed.)
 
481
c          note..  a preliminary call with tout = t is not counted
 
482
c          as a first call here, as no initialization or checking of
 
483
c          input is done.  (such a call is sometimes useful for the
 
484
c          purpose of outputting the initial conditions.)
 
485
c          thus the first call for which tout .ne. t requires
 
486
c          istate = 1 on input.
 
487
c
 
488
c          on output, istate has the following values and meanings.
 
489
c           1  means nothing was done, as tout was equal to t with
 
490
c              istate = 1 on input.  (however, an internal counter was
 
491
c              set to detect and prevent repeated calls of this type.)
 
492
c           2  means the integration was performed successfully, and
 
493
c              no roots were found.
 
494
c           3  means the integration was successful, and one or more
 
495
c              roots were found before satisfying the stop condition
 
496
c              specified by itask.  see jroot.
 
497
c           4  zero lifting
 
498
 
 
499
c          -1  means an excessive amount of work (more than mxstep
 
500
c              steps) was done on this call, before completing the
 
501
c              requested task, but the integration was otherwise
 
502
c              successful as far as t.  (mxstep is an optional input
 
503
c              and is normally 500.)  to continue, the user may
 
504
c              simply reset istate to a value .gt. 1 and call again
 
505
c              (the excess work step counter will be reset to 0).
 
506
c              in addition, the user may increase mxstep to avoid
 
507
c              this error return (see below on optional inputs).
 
508
c          -2  means too much accuracy was requested for the precision
 
509
c              of the machine being used.  this was detected before
 
510
c              completing the requested task, but the integration
 
511
c              was successful as far as t.  to continue, the tolerance
 
512
c              parameters must be reset, and istate must be set
 
513
c              to 3.  the optional output tolsf may be used for this
 
514
c              purpose.  (note.. if this condition is detected before
 
515
c              taking any steps, then an illegal input return
 
516
c              (istate = -3) occurs instead.)
 
517
c          -3  means illegal input was detected, before taking any
 
518
c              integration steps.  see written message for details.
 
519
c              note..  if the solver detects an infinite loop of calls
 
520
c              to the solver with illegal input, it will cause
 
521
c              the run to stop.
 
522
c          -4  means there were repeated error test failures on
 
523
c              one attempted step, before completing the requested
 
524
c              task, but the integration was successful as far as t.
 
525
c              the problem may have a singularity, or the input
 
526
c              may be inappropriate.
 
527
c          -5  means there were repeated convergence test failures on
 
528
c              one attempted step, before completing the requested
 
529
c              task, but the integration was successful as far as t.
 
530
c              this may be caused by an inaccurate jacobian matrix,
 
531
c              if one is being used.
 
532
c          -6  means ewt(i) became zero for some i during the
 
533
c              integration.  pure relative error control (atol(i)=0.0)
 
534
c              was requested on a variable which has now vanished.
 
535
c              the integration was successful as far as t.
 
536
c          -7  means the length of rwork and/or iwork was too small to
 
537
c              proceed, but the integration was successful as far as t.
 
538
c              this happens when lsodar chooses to switch methods
 
539
c              but lrw and/or liw is too small for the new method.
 
540
c
 
541
c          note..  since the normal output value of istate is 2,
 
542
c          it does not need to be reset for normal continuation.
 
543
c          also, since a negative input value of istate will be
 
544
c          regarded as illegal, a negative output value requires the
 
545
c          user to change it, and possibly other inputs, before
 
546
c          calling the solver again.
 
547
c
 
548
c iopt   = an integer flag to specify whether or not any optional
 
549
c          inputs are being used on this call.  input only.
 
550
c          the optional inputs are listed separately below.
 
551
c          iopt = 0 means no optional inputs are being used.
 
552
c                   default values will be used in all cases.
 
553
c          iopt = 1 means one or more optional inputs are being used.
 
554
c
 
555
c rwork  = a real array (double precision) for work space, and (in the
 
556
c          first 20 words) for conditional and optional inputs and
 
557
c          optional outputs.
 
558
c          as lsodar switches automatically between stiff and nonstiff
 
559
c          methods, the required length of rwork can change during the
 
560
c          problem.  thus the rwork array passed to lsodar can either
 
561
c          have a static (fixed) length large enough for both methods,
 
562
c          or have a dynamic (changing) length altered by the calling
 
563
c          program in response to output from lsodar.
 
564
c
 
565
c                       --- fixed length case ---
 
566
c          if the rwork length is to be fixed, it should be at least
 
567
c               max (lrn, lrs),
 
568
c          where lrn and lrs are the rwork lengths required when the
 
569
c          current method is nonstiff or stiff, respectively.
 
570
c
 
571
c          the separate rwork length requirements lrn and lrs are
 
572
c          as follows..
 
573
c          if neq is constant and the maximum method orders have
 
574
c          their default values, then
 
575
c             lrn = 20 + 16*neq + 3*ng,
 
576
c             lrs = 22 + 9*neq + neq**2 + 3*ng           (jt = 1 or 2),
 
577
c             lrs = 22 + 10*neq + (2*ml+mu)*neq + 3*ng   (jt = 4 or 5).
 
578
c          under any other conditions, lrn and lrs are given by..
 
579
c             lrn = 20 + nyh*(mxordn+1) + 3*neq + 3*ng,
 
580
c             lrs = 20 + nyh*(mxords+1) + 3*neq + lmat + 3*ng,
 
581
c          where
 
582
c             nyh    = the initial value of neq,
 
583
c             mxordn = 12, unless a smaller value is given as an
 
584
c                      optional input,
 
585
c             mxords = 5, unless a smaller value is given as an
 
586
c                      optional input,
 
587
c             lmat   = length of matrix work space..
 
588
c             lmat   = neq**2 + 2              if jt = 1 or 2,
 
589
c             lmat   = (2*ml + mu + 1)*neq + 2 if jt = 4 or 5.
 
590
c
 
591
c                       --- dynamic length case ---
 
592
c          if the length of rwork is to be dynamic, then it should
 
593
c          be at least lrn or lrs, as defined above, depending on the
 
594
c          current method.  initially, it must be at least lrn (since
 
595
c          lsodar starts with the nonstiff method).  on any return
 
596
c          from lsodar, the optional output mcur indicates the current
 
597
c          method.  if mcur differs from the value it had on the
 
598
c          previous return, or if there has only been one call to
 
599
c          lsodar and mcur is now 2, then lsodar has switched
 
600
c          methods during the last call, and the length of rwork
 
601
c          should be reset (to lrn if mcur = 1, or to lrs if
 
602
c          mcur = 2).  (an increase in the rwork length is required
 
603
c          if lsodar returned istate = -7, but not otherwise.)
 
604
c          after resetting the length, call lsodar with istate = 3
 
605
c          to signal that change.
 
606
c
 
607
c lrw    = the length of the array rwork, as declared by the user.
 
608
c          (this will be checked by the solver.)
 
609
c
 
610
c iwork  = an integer array for work space.
 
611
c          as lsodar switches automatically between stiff and nonstiff
 
612
c          methods, the required length of iwork can change during
 
613
c          problem, between
 
614
c             lis = 20 + neq   and   lin = 20,
 
615
c          respectively.  thus the iwork array passed to lsodar can
 
616
c          either have a fixed length of at least 20 + neq, or have a
 
617
c          dynamic length of at least lin or lis, depending on the
 
618
c          current method.  the comments on dynamic length under
 
619
c          rwork above apply here.  initially, this length need
 
620
c          only be at least lin = 20.
 
621
c
 
622
c          the first few words of iwork are used for conditional and
 
623
c          optional inputs and optional outputs.
 
624
c
 
625
c          the following 2 words in iwork are conditional inputs..
 
626
c            iwork(1) = ml     these are the lower and upper
 
627
c            iwork(2) = mu     half-bandwidths, respectively, of the
 
628
c                       banded jacobian, excluding the main diagonal.
 
629
c                       the band is defined by the matrix locations
 
630
c                       (i,j) with i-ml .le. j .le. i+mu.  ml and mu
 
631
c                       must satisfy  0 .le.  ml,mu  .le. neq-1.
 
632
c                       these are required if jt is 4 or 5, and
 
633
c                       ignored otherwise.  ml and mu may in fact be
 
634
c                       the band parameters for a matrix to which
 
635
c                       df/dy is only approximately equal.
 
636
c
 
637
c liw    = the length of the array iwork, as declared by the user.
 
638
c          (this will be checked by the solver.)
 
639
c
 
640
c note.. the base addresses of the work arrays must not be
 
641
c altered between calls to lsodar for the same problem.
 
642
c the contents of the work arrays must not be altered
 
643
c between calls, except possibly for the conditional and
 
644
c optional inputs, and except for the last 3*neq words of rwork.
 
645
c the latter space is used for internal scratch space, and so is
 
646
c available for use by the user outside lsodar between calls, if
 
647
c desired (but not for use by f, jac, or g).
 
648
c
 
649
c jac    = the name of the user-supplied routine to compute the
 
650
c          jacobian matrix, df/dy, if jt = 1 or 4.  the jac routine
 
651
c          is optional, but if the problem is expected to be stiff much
 
652
c          of the time, you are encouraged to supply jac, for the sake
 
653
c          of efficiency.  (alternatively, set jt = 2 or 5 to have
 
654
c          lsodar compute df/dy internally by difference quotients.)
 
655
c          if and when lsodar uses df/dy, if treats this neq by neq
 
656
c          matrix either as full (jt = 1 or 2), or as banded (jt =
 
657
c          4 or 5) with half-bandwidths ml and mu (discussed under
 
658
c          iwork above).  in either case, if jt = 1 or 4, the jac
 
659
c          routine must compute df/dy as a function of the scalar t
 
660
c          and the vector y.  it is to have the form
 
661
c               subroutine jac (neq, t, y, ml, mu, pd, nrowpd)
 
662
c               dimension y(1), pd(nrowpd,1)
 
663
c          where neq, t, y, ml, mu, and nrowpd are input and the array
 
664
c          pd is to be loaded with partial derivatives (elements of
 
665
c          the jacobian matrix) on output.  pd must be given a first
 
666
c          dimension of nrowpd.  t and y have the same meaning as in
 
667
c          subroutine f.  (in the dimension statement above, 1 is a
 
668
c          dummy dimension.. it can be replaced by any value.)
 
669
c               in the full matrix case (jt = 1), ml and mu are
 
670
c          ignored, and the jacobian is to be loaded into pd in
 
671
c          columnwise manner, with df(i)/dy(j) loaded into pd(i,j).
 
672
c               in the band matrix case (jt = 4), the elements
 
673
c          within the band are to be loaded into pd in columnwise
 
674
c          manner, with diagonal lines of df/dy loaded into the rows
 
675
c          of pd.  thus df(i)/dy(j) is to be loaded into pd(i-j+mu+1,j).
 
676
c          ml and mu are the half-bandwidth parameters (see iwork).
 
677
c          the locations in pd in the two triangular areas which
 
678
c          correspond to nonexistent matrix elements can be ignored
 
679
c          or loaded arbitrarily, as they are overwritten by lsodar.
 
680
c               jac need not provide df/dy exactly.  a crude
 
681
c          approximation (possibly with a smaller bandwidth) will do.
 
682
c               in either case, pd is preset to zero by the solver,
 
683
c          so that only the nonzero elements need be loaded by jac.
 
684
c          each call to jac is preceded by a call to f with the same
 
685
c          arguments neq, t, and y.  thus to gain some efficiency,
 
686
c          intermediate quantities shared by both calculations may be
 
687
c          saved in a user common block by f and not recomputed by jac,
 
688
c          if desired.  also, jac may alter the y array, if desired.
 
689
c          jac must be declared external in the calling program.
 
690
c               subroutine jac may access user-defined quantities in
 
691
c          neq(2),... and y(neq(1)+1),... if neq is an array
 
692
c          (dimensioned in jac) and y has length exceeding neq(1).
 
693
c          see the descriptions of neq and y above.
 
694
c
 
695
c jt     = jacobian type indicator.  used only for input.
 
696
c          jt specifies how the jacobian matrix df/dy will be
 
697
c          treated, if and when lsodar requires this matrix.
 
698
c          jt has the following values and meanings..
 
699
c           1 means a user-supplied full (neq by neq) jacobian.
 
700
c           2 means an internally generated (difference quotient) full
 
701
c             jacobian (using neq extra calls to f per df/dy value).
 
702
c           4 means a user-supplied banded jacobian.
 
703
c           5 means an internally generated banded jacobian (using
 
704
c             ml+mu+1 extra calls to f per df/dy evaluation).
 
705
c          if jt = 1 or 4, the user must supply a subroutine jac
 
706
c          (the name is arbitrary) as described above under jac.
 
707
c          if jt = 2 or 5, a dummy argument can be used.
 
708
c
 
709
c g      = the name of subroutine for constraint functions, whose
 
710
c          roots are desired during the integration.  it is to have
 
711
c          the form
 
712
c               subroutine g (neq, t, y, ng, gout)
 
713
c               dimension y(neq), gout(ng)
 
714
c          where neq, t, y, and ng are input, and the array gout
 
715
c          is output.  neq, t, and y have the same meaning as in
 
716
c          the f routine, and gout is an array of length ng.
 
717
c          for i = 1,...,ng, this routine is to load into gout(i)
 
718
c          the value at (t,y) of the i-th constraint function g(i).
 
719
c          lsodar will find roots of the g(i) of odd multiplicity
 
720
c          (i.e. sign changes) as they occur during the integration.
 
721
c          g must be declared external in the calling program.
 
722
c
 
723
c          caution.. because of numerical errors in the functions
 
724
c          g(i) due to roundoff and integration error, lsodar may
 
725
c          return false roots, or return the same root at two or more
 
726
c          nearly equal values of t.  if such false roots are
 
727
c          suspected, the user should consider smaller error tolerances
 
728
c          and/or higher precision in the evaluation of the g(i).
 
729
c
 
730
c          if a root of some g(i) defines the end of the problem,
 
731
c          the input to lsodar should nevertheless allow integration
 
732
c          to a point slightly past that root, so that lsodar can
 
733
c          locate the root by interpolation.
 
734
c
 
735
c          subroutine g may access user-defined quantities in
 
736
c          neq(2),... and y(neq(1)+1),... if neq is an array
 
737
c          (dimensioned in g) and y has length exceeding neq(1).
 
738
c          see the descriptions of neq and y above.
 
739
c
 
740
c ng     = number of constraint functions g(i).  if there are none,
 
741
c          set ng = 0, and pass a dummy name for g.
 
742
c
 
743
c jroot  = integer array of length ng.  used only for output.
 
744
c          on a return with istate = 3 (one or more roots found),
 
745
c          jroot(i) = 1 if g(i) has a root at t, or jroot(i) = 0 if not.
 
746
c-----------------------------------------------------------------------
 
747
c optional inputs.
 
748
c
 
749
c the following is a list of the optional inputs provided for in the
 
750
c call sequence.  (see also part ii.)  for each such input variable,
 
751
c this table lists its name as used in this documentation, its
 
752
c location in the call sequence, its meaning, and the default value.
 
753
c the use of any of these inputs requires iopt = 1, and in that
 
754
c case all of these inputs are examined.  a value of zero for any
 
755
c of these optional inputs will cause the default value to be used.
 
756
c thus to use a subset of the optional inputs, simply preload
 
757
c locations 5 to 10 in rwork and iwork to 0.0 and 0 respectively, and
 
758
c then set those of interest to nonzero values.
 
759
c
 
760
c name    location      meaning and default value
 
761
c
 
762
c h0      rwork(5)  the step size to be attempted on the first step.
 
763
c                   the default value is determined by the solver.
 
764
c
 
765
c hmax    rwork(6)  the maximum absolute step size allowed.
 
766
c                   the default value is infinite.
 
767
c
 
768
c hmin    rwork(7)  the minimum absolute step size allowed.
 
769
c                   the default value is 0.  (this lower bound is not
 
770
c                   enforced on the final step before reaching tcrit
 
771
c                   when itask = 4 or 5.)
 
772
c
 
773
c ixpr    iwork(5)  flag to generate extra printing at method switches.
 
774
c                   ixpr = 0 means no extra printing (the default).
 
775
c                   ixpr = 1 means print data on each switch.
 
776
c                   t, h, and nst will be printed on the same logical
 
777
c                   unit as used for error messages.
 
778
c
 
779
c mxstep  iwork(6)  maximum number of (internally defined) steps
 
780
c                   allowed during one call to the solver.
 
781
c                   the default value is 500.
 
782
c
 
783
c mxhnil  iwork(7)  maximum number of messages printed (per problem)
 
784
c                   warning that t + h = t on a step (h = step size).
 
785
c                   this must be positive to result in a non-default
 
786
c                   value.  the default value is 10.
 
787
c
 
788
c mxordn  iwork(8)  the maximum order to be allowed for the nonstiff
 
789
c                   (adams) method.  the default value is 12.
 
790
c                   if mxordn exceeds the default value, it will
 
791
c                   be reduced to the default value.
 
792
c                   mxordn is held constant during the problem.
 
793
c
 
794
c mxords  iwork(9)  the maximum order to be allowed for the stiff
 
795
c                   (bdf) method.  the default value is 5.
 
796
c                   if mxords exceeds the default value, it will
 
797
c                   be reduced to the default value.
 
798
c                   mxords is held constant during the problem.
 
799
c-----------------------------------------------------------------------
 
800
c optional outputs.
 
801
c
 
802
c as optional additional output from lsodar, the variables listed
 
803
c below are quantities related to the performance of lsodar
 
804
c which are available to the user.  these are communicated by way of
 
805
c the work arrays, but also have internal mnemonic names as shown.
 
806
c except where stated otherwise, all of these outputs are defined
 
807
c on any successful return from lsodar, and on any return with
 
808
c istate = -1, -2, -4, -5, or -6.  on an illegal input return
 
809
c (istate = -3), they will be unchanged from their existing values
 
810
c (if any), except possibly for tolsf, lenrw, and leniw.
 
811
c on any error return, outputs relevant to the error will be defined,
 
812
c as noted below.
 
813
c
 
814
c name    location      meaning
 
815
c
 
816
c hu      rwork(11) the step size in t last used (successfully).
 
817
c
 
818
c hcur    rwork(12) the step size to be attempted on the next step.
 
819
c
 
820
c tcur    rwork(13) the current value of the independent variable
 
821
c                   which the solver has actually reached, i.e. the
 
822
c                   current internal mesh point in t.  on output, tcur
 
823
c                   will always be at least as far as the argument
 
824
c                   t, but may be farther (if interpolation was done).
 
825
c
 
826
c tolsf   rwork(14) a tolerance scale factor, greater than 1.0,
 
827
c                   computed when a request for too much accuracy was
 
828
c                   detected (istate = -3 if detected at the start of
 
829
c                   the problem, istate = -2 otherwise).  if itol is
 
830
c                   left unaltered but rtol and atol are uniformly
 
831
c                   scaled up by a factor of tolsf for the next call,
 
832
c                   then the solver is deemed likely to succeed.
 
833
c                   (the user may also ignore tolsf and alter the
 
834
c                   tolerance parameters in any other way appropriate.)
 
835
c
 
836
c tsw     rwork(15) the value of t at the time of the last method
 
837
c                   switch, if any.
 
838
c
 
839
c nge     iwork(10) the number of g evaluations for the problem so far.
 
840
c
 
841
c nst     iwork(11) the number of steps taken for the problem so far.
 
842
c
 
843
c nfe     iwork(12) the number of f evaluations for the problem so far.
 
844
c
 
845
c nje     iwork(13) the number of jacobian evaluations (and of matrix
 
846
c                   lu decompositions) for the problem so far.
 
847
c
 
848
c nqu     iwork(14) the method order last used (successfully).
 
849
c
 
850
c nqcur   iwork(15) the order to be attempted on the next step.
 
851
c
 
852
c imxer   iwork(16) the index of the component of largest magnitude in
 
853
c                   the weighted local error vector ( e(i)/ewt(i) ),
 
854
c                   on an error return with istate = -4 or -5.
 
855
c
 
856
c lenrw   iwork(17) the length of rwork actually required, assuming
 
857
c                   that the length of rwork is to be fixed for the
 
858
c                   rest of the problem, and that switching may occur.
 
859
c                   this is defined on normal returns and on an illegal
 
860
c                   input return for insufficient storage.
 
861
c
 
862
c leniw   iwork(18) the length of iwork actually required, assuming
 
863
c                   that the length of iwork is to be fixed for the
 
864
c                   rest of the problem, and that switching may occur.
 
865
c                   this is defined on normal returns and on an illegal
 
866
c                   input return for insufficient storage.
 
867
c
 
868
c mused   iwork(19) the method indicator for the last successful step..
 
869
c                   1 means adams (nonstiff), 2 means bdf (stiff).
 
870
c
 
871
c mcur    iwork(20) the current method indicator..
 
872
c                   1 means adams (nonstiff), 2 means bdf (stiff).
 
873
c                   this is the method to be attempted
 
874
c                   on the next step.  thus it differs from mused
 
875
c                   only if a method switch has just been made.
 
876
c
 
877
c the following two arrays are segments of the rwork array which
 
878
c may also be of interest to the user as optional outputs.
 
879
c for each array, the table below gives its internal name,
 
880
c its base address in rwork, and its description.
 
881
c
 
882
c name    base address      description
 
883
c
 
884
c yh      21 + 3*ng      the nordsieck history array, of size nyh by
 
885
c                        (nqcur + 1), where nyh is the initial value
 
886
c                        of neq.  for j = 0,1,...,nqcur, column j+1
 
887
c                        of yh contains hcur**j/factorial(j) times
 
888
c                        the j-th derivative of the interpolating
 
889
c                        polynomial currently representing the solution,
 
890
c                        evaluated at t = tcur.
 
891
c
 
892
c acor     lacor         array of size neq used for the accumulated
 
893
c         (from common   corrections on each step, scaled on output
 
894
c           as noted)    to represent the estimated local error in y
 
895
c                        on the last step.  this is the vector e in
 
896
c                        the description of the error control.  it is
 
897
c                        defined only on a successful return from
 
898
c                        lsodar.  the base address lacor is obtained by
 
899
c                        including in the user-s program the
 
900
c                        following 3 lines..
 
901
c                           double precision rls
 
902
c                           common /ls0001/ rls(219), ils(39)
 
903
c                           lacor = ils(5)
 
904
c
 
905
c-----------------------------------------------------------------------
 
906
c part ii.  other routines callable.
 
907
c
 
908
c the following are optional calls which the user may make to
 
909
c gain additional capabilities in conjunction with lsodar.
 
910
c (the routines xsetun and xsetf are designed to conform to the
 
911
c slatec error handling package.)
 
912
c
 
913
c     form of call                  function
 
914
c   call xsetun(lun)          set the logical unit number, lun, for
 
915
c                             output of messages from lsodar, if
 
916
c                             the default is not desired.
 
917
c                             the default value of lun is 6.
 
918
c
 
919
c   call xsetf(mflag)         set a flag to control the printing of
 
920
c                             messages by lsodar.
 
921
c                             mflag = 0 means do not print. (danger..
 
922
c                             this risks losing valuable information.)
 
923
c                             mflag = 1 means print (the default).
 
924
c
 
925
c                             either of the above calls may be made at
 
926
c                             any time and will take effect immediately.
 
927
c
 
928
c   call svcar (rsav, isav)   store in rsav and isav the contents
 
929
c                             of the internal common blocks used by
 
930
c                             lsodar (see part iii below).
 
931
c                             rsav must be a real array of length 246
 
932
c                             or more, and isav must be an integer
 
933
c                             array of length 59 or more.
 
934
c
 
935
c   call rscar (rsav, isav)   restore, from rsav and isav, the contents
 
936
c                             of the internal common blocks used by
 
937
c                             lsodar.  presumes a prior call to svcar
 
938
c                             with the same arguments.
 
939
c
 
940
c                             svcar and rscar are useful if
 
941
c                             interrupting a run and restarting
 
942
c                             later, or alternating between two or
 
943
c                             more problems solved with lsodar.
 
944
c
 
945
c   call intdy(,,,,,)         provide derivatives of y, of various
 
946
c        (see below)          orders, at a specified point t, if
 
947
c                             desired.  it may be called only after
 
948
c                             a successful return from lsodar.
 
949
c
 
950
c the detailed instructions for using intdy are as follows.
 
951
c the form of the call is..
 
952
c
 
953
c   call intdy (t, k, rwork(lyh), nyh, dky, iflag)
 
954
c
 
955
c the input parameters are..
 
956
c
 
957
c t         = value of independent variable where answers are desired
 
958
c             (normally the same as the t last returned by lsodar).
 
959
c             for valid results, t must lie between tcur - hu and tcur.
 
960
c             (see optional outputs for tcur and hu.)
 
961
c k         = integer order of the derivative desired.  k must satisfy
 
962
c             0 .le. k .le. nqcur, where nqcur is the current order
 
963
c             (see optional outputs).  the capability corresponding
 
964
c             to k = 0, i.e. computing y(t), is already provided
 
965
c             by lsodar directly.  since nqcur .ge. 1, the first
 
966
c             derivative dy/dt is always available with intdy.
 
967
c lyh       = 21 + 3*ng = base address in rwork of the history array yh.
 
968
c nyh       = column length of yh, equal to the initial value of neq.
 
969
c
 
970
c the output parameters are..
 
971
c
 
972
c dky       = a real array of length neq containing the computed value
 
973
c             of the k-th derivative of y(t).
 
974
c iflag     = integer flag, returned as 0 if k and t were legal,
 
975
c             -1 if k was illegal, and -2 if t was illegal.
 
976
c             on an error return, a message is also written.
 
977
c-----------------------------------------------------------------------
 
978
c part iii.  common blocks.
 
979
c
 
980
c if lsodar is to be used in an overlay situation, the user
 
981
c must declare, in the primary overlay, the variables in..
 
982
c   (1) the call sequence to lsodar,
 
983
c   (2) the four internal common blocks
 
984
c         /ls0001/  of length  258  (219 double precision words
 
985
c                         followed by 39 integer words),
 
986
c         /lsa001/  of length  31    (22 double precision words
 
987
c                         followed by  9 integer words),
 
988
c         /lsr001/  of length  14     (5 double precision words
 
989
c                         followed by  9 integer words),
 
990
c         /eh0001/  of length  2 (integer words).
 
991
c
 
992
c if lsodar is used on a system in which the contents of internal
 
993
c common blocks are not preserved between calls, the user should
 
994
c declare the above common blocks in his main program to insure
 
995
c that their contents are preserved.
 
996
c
 
997
c if the solution of a given problem by lsodar is to be interrupted
 
998
c and then later continued, such as when restarting an interrupted run
 
999
c or alternating between two or more problems, the user should save,
 
1000
c following the return from the last lsodar call prior to the
 
1001
c interruption, the contents of the call sequence variables and the
 
1002
c internal common blocks, and later restore these values before the
 
1003
c next lsodar call for that problem.  to save and restore the common
 
1004
c blocks, use subroutines svcar and rscar (see part ii above).
 
1005
c
 
1006
c-----------------------------------------------------------------------
 
1007
c part iv.  optionally replaceable solver routines.
 
1008
c
 
1009
c below is a description of a routine in the lsodar package which
 
1010
c relates to the measurement of errors, and can be
 
1011
c replaced by a user-supplied version, if desired.  however, since such
 
1012
c a replacement may have a major impact on performance, it should be
 
1013
c done only when absolutely necessary, and only with great caution.
 
1014
c (note.. the means by which the package version of a routine is
 
1015
c superseded by the user-s version may be system-dependent.)
 
1016
c
 
1017
c (a) ewset.
 
1018
c the following subroutine is called just before each internal
 
1019
c integration step, and sets the array of error weights, ewt, as
 
1020
c described under itol/rtol/atol above..
 
1021
c     subroutine ewset (neq, itol, rtol, atol, ycur, ewt)
 
1022
c where neq, itol, rtol, and atol are as in the lsodar call sequence,
 
1023
c ycur contains the current dependent variable vector, and
 
1024
c ewt is the array of weights set by ewset.
 
1025
c
 
1026
c if the user supplies this subroutine, it must return in ewt(i)
 
1027
c (i = 1,...,neq) a positive quantity suitable for comparing errors
 
1028
c in y(i) to.  the ewt array returned by ewset is passed to the
 
1029
c vmnorm routine, and also used by lsodar in the computation
 
1030
c of the optional output imxer, and the increments for difference
 
1031
c quotient jacobians.
 
1032
c
 
1033
c in the user-supplied version of ewset, it may be desirable to use
 
1034
c the current values of derivatives of y.  derivatives up to order nq
 
1035
c are available from the history array yh, described above under
 
1036
c optional outputs.  in ewset, yh is identical to the ycur array,
 
1037
c extended to nq + 1 columns with a column length of nyh and scale
 
1038
c factors of h**j/factorial(j).  on the first call for the problem,
 
1039
c given by nst = 0, nq is 1 and h is temporarily set to 1.0.
 
1040
c the quantities nq, nyh, h, and nst can be obtained by including
 
1041
c in ewset the statements..
 
1042
c     double precision h, rls
 
1043
c     common /ls0001/ rls(219),ils(39)
 
1044
c     nq = ils(35)
 
1045
c     nyh = ils(14)
 
1046
c     nst = ils(36)
 
1047
c     h = rls(213)
 
1048
c thus, for example, the current value of dy/dt can be obtained as
 
1049
c ycur(nyh+i)/h  (i=1,...,neq)  (and the division by h is
 
1050
c unnecessary when nst = 0).
 
1051
c-----------------------------------------------------------------------
 
1052
c-----------------------------------------------------------------------
 
1053
c other routines in the lsodar package.
 
1054
c
 
1055
c in addition to subroutine lsodar, the lsodar package includes the
 
1056
c following subroutines and function routines..
 
1057
c  rchek    does preliminary checking for roots, and serves as an
 
1058
c           interface between subroutine lsodar and subroutine roots.
 
1059
c  roots    finds the leftmost root of a set of functions.
 
1060
c  intdy    computes an interpolated value of the y vector at t = tout.
 
1061
c  stoda    is the core integrator, which does one step of the
 
1062
c           integration and the associated error control.
 
1063
c  cfode    sets all method coefficients and test constants.
 
1064
c  prja     computes and preprocesses the jacobian matrix j = df/dy
 
1065
c           and the newton iteration matrix p = i - h*l0*j.
 
1066
c  solsy    manages solution of linear system in chord iteration.
 
1067
c  ewset    sets the error weight vector ewt before each step.
 
1068
c  vmnorm   computes the weighted max-norm of a vector.
 
1069
c  fnorm    computes the norm of a full matrix consistent with the
 
1070
c           weighted max-norm on vectors.
 
1071
c  bnorm    computes the norm of a band matrix consistent with the
 
1072
c           weighted max-norm on vectors.
 
1073
c  svcar and rscar   are user-callable routines to save and restore,
 
1074
c           respectively, the contents of the internal common blocks.
 
1075
c  dgefa and dgesl   are routines from linpack for solving full
 
1076
c           systems of linear algebraic equations.
 
1077
c  dgbfa and dgbsl   are routines from linpack for solving banded
 
1078
c           linear systems.
 
1079
c  daxpy, dscal, idamax, ddot, and dcopy   are basic linear algebra
 
1080
c           modules (blas) used by the above linpack routines.
 
1081
c  dlamch   computes the unit roundoff in a machine-independent manner.
 
1082
c  xerrwv, xsetun, and xsetf   handle the printing of all error
 
1083
c           messages and warnings.  xerrwv is machine-dependent.
 
1084
c note..  vmnorm, fnorm, bnorm, idamax, ddot, and dlamch are function
 
1085
c routines.  all the others are subroutines.
 
1086
c
 
1087
c the intrinsic and external routines used by lsodar are..
 
1088
c dabs, dmax1, dmin1, dfloat, max0, min0, mod, dsign, dsqrt, and write.
 
1089
c
 
1090
c a block data subprogram is also included with the package,
 
1091
c for loading some of the variables in internal common.
 
1092
c
 
1093
c-----------------------------------------------------------------------
 
1094
c the following card is for optimized compilation on lll compilers.
 
1095
clll. optimize
 
1096
c-----------------------------------------------------------------------
 
1097
      external prja, solsy
 
1098
      integer illin, init, lyh, lewt, lacor, lsavf, lwm, liwm,
 
1099
     1   mxstep, mxhnil, nhnil, ntrep, nslast, nyh, iowns
 
1100
      integer icf, ierpj, iersl, jcur, jstart, kflag, l, meth, miter,
 
1101
     1   maxord, maxcor, msbp, mxncf, n, nq, nst, nfe, nje, nqu
 
1102
      integer insufr, insufi, ixpr, iowns2, jtyp, mused, mxordn, mxords
 
1103
      integer lg0, lg1, lgx, iownr3, irfnd, itaskc, ngc, nge
 
1104
      integer i, i1, i2, iflag, imxer, kgo, lf0,
 
1105
     1   leniw, lenrw, lenwm, ml, mord, mu, mxhnl0, mxstp0
 
1106
      integer len1, len1c, len1n, len1s, len2, leniwc,
 
1107
     1   lenrwc, lenrwn, lenrws
 
1108
      integer irfp, irt, lenyh, lyhnew
 
1109
      double precision tret, rowns,
 
1110
     1   ccmax, el0, h, hmin, hmxi, hu, rc, tn, uround
 
1111
      double precision tsw, rowns2, pdnorm
 
1112
      double precision rownr3, t0, tlast, toutc
 
1113
      double precision atoli, ayi, big, ewti, h0, hmax, hmx, rh, rtoli,
 
1114
     1   tcrit, tdist, tnext, tol, tolsf, tp, size, sum, w0,
 
1115
     2   dlamch, vmnorm
 
1116
      dimension mord(2)
 
1117
      logical ihit
 
1118
c-----------------------------------------------------------------------
 
1119
c the following three internal common blocks contain
 
1120
c (a) variables which are local to any subroutine but whose values must
 
1121
c     be preserved between calls to the routine (own variables), and
 
1122
c (b) variables which are communicated between subroutines.
 
1123
c the structure of each block is as follows..  all real variables are
 
1124
c listed first, followed by all integers.  within each type, the
 
1125
c variables are grouped with those local to subroutine lsodar first,
 
1126
c then those local to subroutine roots or subroutine stoda
 
1127
c (no other routines have own variables), and finally those used
 
1128
c for communication.  the block ls0001 is declared in subroutines
 
1129
c lsodar, intdy, stoda, prja, and solsy.  the block lsa001 is declared
 
1130
c in subroutines lsodar, stoda, and prja.  the block lsr001 is declared
 
1131
c in subroutines lsodar, rchek, and roots.  groups of variables are
 
1132
c replaced by dummy arrays in the common declarations in routines
 
1133
c where those variables are not used.
 
1134
c-----------------------------------------------------------------------
 
1135
      integer         iero
 
1136
      common /ierode/ iero
 
1137
      common /ls0001/ tret, rowns(209),
 
1138
     1   ccmax, el0, h, hmin, hmxi, hu, rc, tn, uround,
 
1139
     2   illin, init, lyh, lewt, lacor, lsavf, lwm, liwm,
 
1140
     3   mxstep, mxhnil, nhnil, ntrep, nslast, nyh, iowns(6),
 
1141
     4   icf, ierpj, iersl, jcur, jstart, kflag, l, meth, miter,
 
1142
     5   maxord, maxcor, msbp, mxncf, n, nq, nst, nfe, nje, nqu
 
1143
      common /lsa001/ tsw, rowns2(20), pdnorm,
 
1144
     1   insufr, insufi, ixpr, iowns2(2), jtyp, mused, mxordn, mxords
 
1145
      common /lsr001/ rownr3(2), t0, tlast, toutc,
 
1146
     1   lg0, lg1, lgx, iownr3(2), irfnd, itaskc, ngc, nge
 
1147
c
 
1148
      data mord(1),mord(2)/12,5/, mxstp0/500/, mxhnl0/10/
 
1149
c-----------------------------------------------------------------------
 
1150
c block a.
 
1151
c this code block is executed on every call.
 
1152
c it tests istate and itask for legality and branches appropriately.
 
1153
c if istate .gt. 1 but the flag init shows that initialization has
 
1154
c not yet been done, an error return occurs.
 
1155
c if istate = 1 and tout = t, jump to block g and return immediately.
 
1156
c-----------------------------------------------------------------------
 
1157
      if (istate .lt. 1 .or. istate .gt. 3) go to 601
 
1158
      if (itask .lt. 1 .or. itask .gt. 5) go to 602
 
1159
      itaskc = itask
 
1160
      if (istate .eq. 1) go to 10
 
1161
      if (init .eq. 0) go to 603
 
1162
      if (istate .eq. 2) go to 200
 
1163
      go to 20
 
1164
 10   init = 0
 
1165
      if (tout .eq. t) go to 430
 
1166
 20   ntrep = 0
 
1167
c-----------------------------------------------------------------------
 
1168
c block b.
 
1169
c the next code block is executed for the initial call (istate = 1),
 
1170
c or for a continuation call with parameter changes (istate = 3).
 
1171
c it contains checking of all inputs and various initializations.
 
1172
c
 
1173
c first check legality of the non-optional inputs neq, itol, iopt,
 
1174
c jt, ml, mu, and ng.
 
1175
c-----------------------------------------------------------------------
 
1176
      if (neq(1) .le. 0) go to 604
 
1177
      if (istate .eq. 1) go to 25
 
1178
      if (neq(1) .gt. n) go to 605
 
1179
 25   n = neq(1)
 
1180
      if (itol .lt. 1 .or. itol .gt. 4) go to 606
 
1181
      if (iopt .lt. 0 .or. iopt .gt. 1) go to 607
 
1182
      if (jt .eq. 3 .or. jt .lt. 1 .or. jt .gt. 5) go to 608
 
1183
      jtyp = jt
 
1184
      if (jt .le. 2) go to 30
 
1185
      ml = iwork(1)
 
1186
      mu = iwork(2)
 
1187
      if (ml .lt. 0 .or. ml .ge. n) go to 609
 
1188
      if (mu .lt. 0 .or. mu .ge. n) go to 610
 
1189
 30   continue
 
1190
      if (ng .lt. 0) go to 630
 
1191
      if (istate .eq. 1) go to 35
 
1192
      if (irfnd .eq. 0 .and. ng .ne. ngc) go to 631
 
1193
 35   ngc = ng
 
1194
c next process and check the optional inputs. --------------------------
 
1195
      if (iopt .eq. 1) go to 40
 
1196
      ixpr = 0
 
1197
      mxstep = mxstp0
 
1198
      mxhnil = mxhnl0
 
1199
      hmxi = 0.0d0
 
1200
      hmin = 0.0d0
 
1201
      if (istate .ne. 1) go to 60
 
1202
      h0 = 0.0d0
 
1203
      mxordn = mord(1)
 
1204
      mxords = mord(2)
 
1205
      go to 60
 
1206
 40   ixpr = iwork(5)
 
1207
      if (ixpr .lt. 0 .or. ixpr .gt. 1) go to 611
 
1208
      mxstep = iwork(6)
 
1209
      if (mxstep .lt. 0) go to 612
 
1210
      if (mxstep .eq. 0) mxstep = mxstp0
 
1211
      mxhnil = iwork(7)
 
1212
      if (mxhnil .lt. 0) go to 613
 
1213
      if (mxhnil .eq. 0) mxhnil = mxhnl0
 
1214
      if (istate .ne. 1) go to 50
 
1215
      h0 = rwork(5)
 
1216
      mxordn = iwork(8)
 
1217
      if (mxordn .lt. 0) go to 628
 
1218
      if (mxordn .eq. 0) mxordn = 100
 
1219
      mxordn = min0(mxordn,mord(1))
 
1220
      mxords = iwork(9)
 
1221
      if (mxords .lt. 0) go to 629
 
1222
      if (mxords .eq. 0) mxords = 100
 
1223
      mxords = min0(mxords,mord(2))
 
1224
      if ((tout - t)*h0 .lt. 0.0d0) go to 614
 
1225
 50   hmax = rwork(6)
 
1226
      if (hmax .lt. 0.0d0) go to 615
 
1227
      hmxi = 0.0d0
 
1228
      if (hmax .gt. 0.0d0) hmxi = 1.0d0/hmax
 
1229
      hmin = rwork(7)
 
1230
      if (hmin .lt. 0.0d0) go to 616
 
1231
c-----------------------------------------------------------------------
 
1232
c set work array pointers and check lengths lrw and liw.
 
1233
c if istate = 1, meth is initialized to 1 here to facilitate the
 
1234
c checking of work space lengths.
 
1235
c pointers to segments of rwork and iwork are named by prefixing l to
 
1236
c the name of the segment.  e.g., the segment yh starts at rwork(lyh).
 
1237
c segments of rwork (in order) are denoted  g0, g1, gx, yh, wm,
 
1238
c ewt, savf, acor.
 
1239
c if the lengths provided are insufficient for the current method,
 
1240
c an error return occurs.  this is treated as illegal input on the
 
1241
c first call, but as a problem interruption with istate = -7 on a
 
1242
c continuation call.  if the lengths are sufficient for the current
 
1243
c method but not for both methods, a warning message is sent.
 
1244
c-----------------------------------------------------------------------
 
1245
 60   if (istate .eq. 1) meth = 1
 
1246
      if (istate .eq. 1) nyh = n
 
1247
      lg0 = 21
 
1248
      lg1 = lg0 + ng
 
1249
      lgx = lg1 + ng
 
1250
      lyhnew = lgx + ng
 
1251
      if (istate .eq. 1) lyh = lyhnew
 
1252
      if (lyhnew .eq. lyh) go to 62
 
1253
c if istate = 3 and ng was changed, shift yh to its new location. ------
 
1254
      lenyh = l*nyh
 
1255
      if (lrw .lt. lyhnew-1+lenyh) go to 62
 
1256
      i1 = 1
 
1257
      if (lyhnew .gt. lyh) i1 = -1
 
1258
      call dcopy (lenyh, rwork(lyh), i1, rwork(lyhnew), i1)
 
1259
      lyh = lyhnew
 
1260
 62   continue
 
1261
      len1n = lyhnew - 1 + (mxordn + 1)*nyh
 
1262
      len1s = lyhnew - 1 + (mxords + 1)*nyh
 
1263
      lwm = len1s + 1
 
1264
      if (jt .le. 2) lenwm = n*n + 2
 
1265
      if (jt .ge. 4) lenwm = (2*ml + mu + 1)*n + 2
 
1266
      len1s = len1s + lenwm
 
1267
      len1c = len1n
 
1268
      if (meth .eq. 2) len1c = len1s
 
1269
      len1 = max0(len1n,len1s)
 
1270
      len2 = 3*n
 
1271
      lenrw = len1 + len2
 
1272
      lenrwn = len1n + len2
 
1273
      lenrws = len1s + len2
 
1274
      lenrwc = len1c + len2
 
1275
      iwork(17) = lenrw
 
1276
      liwm = 1
 
1277
      leniw = 20 + n
 
1278
c     ----------------------------- masking ----------------
 
1279
      leniw = leniw+ng
 
1280
c     ----------------------------- masking ----------------
 
1281
      leniwc = 20
 
1282
      if (meth .eq. 2) leniwc = leniw
 
1283
      iwork(18) = leniw
 
1284
      if (istate .eq. 1 .and. lrw .lt. lenrwc) go to 617
 
1285
      if (istate .eq. 1 .and. liw .lt. leniwc) go to 618
 
1286
      if (istate .eq. 3 .and. lrw .lt. lenrwc) go to 550
 
1287
      if (istate .eq. 3 .and. liw .lt. leniwc) go to 555
 
1288
      lewt = len1 + 1
 
1289
      insufr = 0
 
1290
      if (lrw .ge. lenrw) go to 65
 
1291
      insufr = 2
 
1292
      lewt = len1c + 1
 
1293
      call xerrwv(
 
1294
     1  'lsodar-  warning.. rwork length is sufficient for now, but  ',
 
1295
     1   60, 103, 1, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1296
      call xerrwv(
 
1297
     1  '      may not be later.  integration will proceed anyway.   ',
 
1298
     1   60, 103, 1, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1299
      call xerrwv(
 
1300
     1  '      length needed is lenrw = i1, while lrw = i2.',
 
1301
     1   50, 103, 1, 2, lenrw, lrw, 0, 0.0d0, 0.0d0)
 
1302
 65   lsavf = lewt + n
 
1303
      lacor = lsavf + n
 
1304
      insufi = 0
 
1305
      if (liw .ge. leniw) go to 70
 
1306
      insufi = 2
 
1307
      call xerrwv(
 
1308
     1  'lsodar-  warning.. iwork length is sufficient for now, but  ',
 
1309
     1   60, 104, 1, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1310
      call xerrwv(
 
1311
     1  '      may not be later.  integration will proceed anyway.   ',
 
1312
     1   60, 104, 1, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1313
      call xerrwv(
 
1314
     1  '      length needed is leniw = i1, while liw = i2.',
 
1315
     1   50, 104, 1, 2, leniw, liw, 0, 0.0d0, 0.0d0)
 
1316
 70   continue
 
1317
c check rtol and atol for legality. ------------------------------------
 
1318
      rtoli = rtol(1)
 
1319
      atoli = atol(1)
 
1320
      do 75 i = 1,n
 
1321
        if (itol .ge. 3) rtoli = rtol(i)
 
1322
        if (itol .eq. 2 .or. itol .eq. 4) atoli = atol(i)
 
1323
        if (rtoli .lt. 0.0d0) go to 619
 
1324
        if (atoli .lt. 0.0d0) go to 620
 
1325
 75     continue
 
1326
      if (istate .eq. 1) go to 100
 
1327
c if istate = 3, set flag to signal parameter changes to stoda. --------
 
1328
      jstart = -1
 
1329
      if (n .eq. nyh) go to 200
 
1330
c neq was reduced.  zero part of yh to avoid undefined references. -----
 
1331
      i1 = lyh + l*nyh
 
1332
      i2 = lyh + (maxord + 1)*nyh - 1
 
1333
      if (i1 .gt. i2) go to 200
 
1334
      do 95 i = i1,i2
 
1335
 95     rwork(i) = 0.0d0
 
1336
      go to 200
 
1337
c-----------------------------------------------------------------------
 
1338
c block c.
 
1339
c the next block is for the initial call only (istate = 1).
 
1340
c it contains all remaining initializations, the initial call to f,
 
1341
c and the calculation of the initial step size.
 
1342
c the error weights in ewt are inverted after being loaded.
 
1343
c-----------------------------------------------------------------------
 
1344
 100  uround = dlamch('p')
 
1345
      tn = t
 
1346
      tsw = t
 
1347
      maxord = mxordn
 
1348
      if (itask .ne. 4 .and. itask .ne. 5) go to 110
 
1349
      tcrit = rwork(1)
 
1350
      if ((tcrit - tout)*(tout - t) .lt. 0.0d0) go to 625
 
1351
      if (h0 .ne. 0.0d0 .and. (t + h0 - tcrit)*h0 .gt. 0.0d0)
 
1352
     1   h0 = tcrit - t
 
1353
 110  jstart = 0
 
1354
      nhnil = 0
 
1355
      nst = 0
 
1356
      nje = 0
 
1357
      nslast = 0
 
1358
      hu = 0.0d0
 
1359
      nqu = 0
 
1360
      mused = 0
 
1361
      miter = 0
 
1362
      ccmax = 0.3d0
 
1363
      maxcor = 3
 
1364
      msbp = 20
 
1365
      mxncf = 10
 
1366
c initial call to f.  (lf0 points to yh(*,2).) -------------------------
 
1367
      lf0 = lyh + nyh
 
1368
      call f (neq, t, y, rwork(lf0))
 
1369
      if(iero.gt.0) return
 
1370
      nfe = 1
 
1371
c load the initial value vector in yh. ---------------------------------
 
1372
      do 115 i = 1,n
 
1373
 115    rwork(i+lyh-1) = y(i)
 
1374
c load and invert the ewt array.  (h is temporarily set to 1.0.) -------
 
1375
      nq = 1
 
1376
      h = 1.0d0
 
1377
      call ewset (n, itol, rtol, atol, rwork(lyh), rwork(lewt))
 
1378
      do 120 i = 1,n
 
1379
        if (rwork(i+lewt-1) .le. 0.0d0) go to 621
 
1380
 120    rwork(i+lewt-1) = 1.0d0/rwork(i+lewt-1)
 
1381
c-----------------------------------------------------------------------
 
1382
c the coding below computes the step size, h0, to be attempted on the
 
1383
c first step, unless the user has supplied a value for this.
 
1384
c first check that tout - t differs significantly from zero.
 
1385
c a scalar tolerance quantity tol is computed, as max(rtol(i))
 
1386
c if this is positive, or max(atol(i)/abs(y(i))) otherwise, adjusted
 
1387
c so as to be between 100*uround and 1.0e-3.
 
1388
c then the computed value h0 is given by..
 
1389
c
 
1390
c   h0**(-2)  =  1./(tol * w0**2)  +  tol * (norm(f))**2
 
1391
c
 
1392
c where   w0     = max ( abs(t), abs(tout) ),
 
1393
c         f      = the initial value of the vector f(t,y), and
 
1394
c         norm() = the weighted vector norm used throughout, given by
 
1395
c                  the vmnorm function routine, and weighted by the
 
1396
c                  tolerances initially loaded into the ewt array.
 
1397
c the sign of h0 is inferred from the initial values of tout and t.
 
1398
c abs(h0) is made .le. abs(tout-t) in any case.
 
1399
c-----------------------------------------------------------------------
 
1400
      if (h0 .ne. 0.0d0) go to 180
 
1401
      tdist = dabs(tout - t)
 
1402
      w0 = dmax1(dabs(t),dabs(tout))
 
1403
      if (tdist .lt. 2.0d0*uround*w0) go to 622
 
1404
      tol = rtol(1)
 
1405
      if (itol .le. 2) go to 140
 
1406
      do 130 i = 1,n
 
1407
 130    tol = dmax1(tol,rtol(i))
 
1408
 140  if (tol .gt. 0.0d0) go to 160
 
1409
      atoli = atol(1)
 
1410
      do 150 i = 1,n
 
1411
        if (itol .eq. 2 .or. itol .eq. 4) atoli = atol(i)
 
1412
        ayi = dabs(y(i))
 
1413
        if (ayi .ne. 0.0d0) tol = dmax1(tol,atoli/ayi)
 
1414
 150    continue
 
1415
 160  tol = dmax1(tol,100.0d0*uround)
 
1416
      tol = dmin1(tol,0.001d0)
 
1417
      sum = vmnorm (n, rwork(lf0), rwork(lewt))
 
1418
      sum = 1.0d0/(tol*w0*w0) + tol*sum**2
 
1419
      h0 = 1.0d0/dsqrt(sum)
 
1420
      h0 = dmin1(h0,tdist)
 
1421
      h0 = dsign(h0,tout-t)
 
1422
c adjust h0 if necessary to meet hmax bound. ---------------------------
 
1423
 180  rh = dabs(h0)*hmxi
 
1424
      if (rh .gt. 1.0d0) h0 = h0/rh
 
1425
c load h with h0 and scale yh(*,2) by h0. ------------------------------
 
1426
      h = h0
 
1427
      do 190 i = 1,n
 
1428
 190    rwork(i+lf0-1) = h0*rwork(i+lf0-1)
 
1429
c
 
1430
c check for a zero of g at t. ------------------------------------------
 
1431
      irfnd = 0
 
1432
      toutc = tout
 
1433
      if (ngc .eq. 0) go to 270
 
1434
c     --------------------- masking -----------------------
 
1435
      call rchek2 (1, g, neq, y, rwork(lyh), nyh,
 
1436
     1   rwork(lg0), rwork(lg1), rwork(lgx), jroot, irt,iwork)
 
1437
      if (iero.gt.0) return
 
1438
      if (irt .eq. 2)  then
 
1439
         irfnd = 2
 
1440
         go to 270
 
1441
      endif
 
1442
      if (irt .eq. 0) go to 270
 
1443
      go to 632
 
1444
c-----------------------------------------------------------------------
 
1445
c block d.
 
1446
c the next code block is for continuation calls only (istate = 2 or 3)
 
1447
c and is to check stop conditions before taking a step.
 
1448
c first, rchek is called to check for a root within the last step
 
1449
c taken, other than the last root found there, if any.
 
1450
c if itask = 2 or 5, and y(tn) has not yet been returned to the user
 
1451
c because of an intervening root, return through block g.
 
1452
c-----------------------------------------------------------------------
 
1453
 200  nslast = nst
 
1454
c
 
1455
      irfp = irfnd
 
1456
      if (ngc .eq. 0) go to 205
 
1457
      if (itask .eq. 1 .or. itask .eq. 4) toutc = tout
 
1458
c     --------------------- masking -----------------------
 
1459
      call rchek2 (2, g, neq, y, rwork(lyh), nyh,
 
1460
     1   rwork(lg0), rwork(lg1), rwork(lgx), jroot, irt,iwork)
 
1461
c     --------------------- masking -----------------------
 
1462
      if(iero.gt.0) return
 
1463
      if (irt .lt. 0) go to 632
 
1464
      if (irt .ne. 1) go to 205
 
1465
      irfnd = 1
 
1466
      istate = 3
 
1467
      t = t0
 
1468
      go to 425
 
1469
 205  continue
 
1470
      irfnd = 0
 
1471
      if (irfp .eq. 1 .and. tlast .ne. tn .and. itask .eq. 2) go to 400
 
1472
c
 
1473
      go to (210, 250, 220, 230, 240), itask
 
1474
 210  if ((tn - tout)*h .lt. 0.0d0) go to 250
 
1475
      call intdy (tout, 0, rwork(lyh), nyh, y, iflag)
 
1476
      if (iflag .ne. 0) go to 627
 
1477
      t = tout
 
1478
      go to 420
 
1479
 220  tp = tn - hu*(1.0d0 + 100.0d0*uround)
 
1480
      if ((tp - tout)*h .gt. 0.0d0) go to 623
 
1481
      if ((tn - tout)*h .lt. 0.0d0) go to 250
 
1482
      t = tn
 
1483
      go to 400
 
1484
 230  tcrit = rwork(1)
 
1485
      if ((tn - tcrit)*h .gt. 0.0d0) go to 624
 
1486
      if ((tcrit - tout)*h .lt. 0.0d0) go to 625
 
1487
      if ((tn - tout)*h .lt. 0.0d0) go to 245
 
1488
      call intdy (tout, 0, rwork(lyh), nyh, y, iflag)
 
1489
      if (iflag .ne. 0) go to 627
 
1490
      t = tout
 
1491
      go to 420
 
1492
 240  tcrit = rwork(1)
 
1493
      if ((tn - tcrit)*h .gt. 0.0d0) go to 624
 
1494
 245  hmx = dabs(tn) + dabs(h)
 
1495
      ihit = dabs(tn - tcrit) .le. 100.0d0*uround*hmx
 
1496
      if (ihit) t = tcrit
 
1497
      if (irfp .eq. 1 .and. tlast .ne. tn .and. itask .eq. 5) go to 400
 
1498
      if (ihit) go to 400
 
1499
      tnext = tn + h*(1.0d0 + 4.0d0*uround)
 
1500
      if ((tnext - tcrit)*h .le. 0.0d0) go to 250
 
1501
      h = (tcrit - tn)*(1.0d0 - 4.0d0*uround)
 
1502
cSCI
 
1503
cSCI  if (istate .eq. 2) jstart = -2
 
1504
cSCI  replaced by:
 
1505
      if (istate .eq. 2 .and. jstart .ge. 0) jstart = -2
 
1506
c-----------------------------------------------------------------------
 
1507
c block e.
 
1508
c the next block is normally executed for all calls and contains
 
1509
c the call to the one-step core integrator stoda.
 
1510
c
 
1511
c this is a looping point for the integration steps.
 
1512
c
 
1513
c first check for too many steps being taken, update ewt (if not at
 
1514
c start of problem), check for too much accuracy being requested, and
 
1515
c check for h below the roundoff level in t.
 
1516
c-----------------------------------------------------------------------
 
1517
 250  continue
 
1518
      if (meth .eq. mused) go to 255
 
1519
      if (insufr .eq. 1) go to 550
 
1520
      if (insufi .eq. 1) go to 555
 
1521
 255  if ((nst-nslast) .ge. mxstep) go to 500
 
1522
      call ewset (n, itol, rtol, atol, rwork(lyh), rwork(lewt))
 
1523
      do 260 i = 1,n
 
1524
        if (rwork(i+lewt-1) .le. 0.0d0) go to 510
 
1525
 260    rwork(i+lewt-1) = 1.0d0/rwork(i+lewt-1)
 
1526
 270  tolsf = uround*vmnorm (n, rwork(lyh), rwork(lewt))
 
1527
      if (tolsf .le. 0.01d0) go to 280
 
1528
      tolsf = tolsf*200.0d0
 
1529
      if (nst .eq. 0) go to 626
 
1530
      go to 520
 
1531
 280  if ((tn + h) .ne. tn) go to 290
 
1532
      nhnil = nhnil + 1
 
1533
      if (nhnil .gt. mxhnil) go to 290
 
1534
      call xerrwv('lsodar-  warning..internal t (=r1) and h (=r2) are',
 
1535
     1   50, 101, 1, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1536
      call xerrwv(
 
1537
     1  '      such that in the machine, t + h = t on the next step ',
 
1538
     1   60, 101, 1, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1539
      call xerrwv('      (h = step size). solver will continue anyway',
 
1540
     1   50, 101, 1, 0, 0, 0, 2, tn, h)
 
1541
      if (nhnil .lt. mxhnil) go to 290
 
1542
      call xerrwv('sodar-  above warning has been issued i1 times.  ',
 
1543
     1   50, 102, 1, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1544
      call xerrwv('     it will not be issued again for this problem',
 
1545
     1   50, 102, 1, 1, mxhnil, 0, 0, 0.0d0, 0.0d0)
 
1546
 290  continue
 
1547
c-----------------------------------------------------------------------
 
1548
c     call stoda(neq,y,yh,nyh,yh,ewt,savf,acor,wm,iwm,f,jac,prja,solsy)
 
1549
c-----------------------------------------------------------------------
 
1550
      call stoda (neq, y, rwork(lyh), nyh, rwork(lyh), rwork(lewt),
 
1551
     1   rwork(lsavf), rwork(lacor), rwork(lwm), iwork(liwm),
 
1552
     2   f, jac, prja, solsy)
 
1553
      if(iero.gt.0) return
 
1554
      kgo = 1 - kflag
 
1555
      go to (300, 530, 540), kgo
 
1556
c-----------------------------------------------------------------------
 
1557
c block f.
 
1558
c the following block handles the case of a successful return from the
 
1559
c core integrator (kflag = 0).
 
1560
c if a method switch was just made, record tsw, reset maxord,
 
1561
c set jstart to -1 to signal stoda to complete the switch,
 
1562
c and do extra printing of data if ixpr = 1.
 
1563
c then call rchek to check for a root within the last step.
 
1564
c then, if no root was found, check for stop conditions.
 
1565
c-----------------------------------------------------------------------
 
1566
 300  init = 1
 
1567
      if (meth .eq. mused) go to 310
 
1568
      tsw = tn
 
1569
      maxord = mxordn
 
1570
      if (meth .eq. 2) maxord = mxords
 
1571
      if (meth .eq. 2) rwork(lwm) = dsqrt(uround)
 
1572
      insufr = min0(insufr,1)
 
1573
      insufi = min0(insufi,1)
 
1574
      jstart = -1
 
1575
      if (ixpr .eq. 0) go to 310
 
1576
      if (meth .eq. 2) call xerrwv(
 
1577
     1  'lsodar- a switch to the bdf (stiff) method has occurred     ',
 
1578
     1   60, 105, 1, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1579
      if (meth .eq. 1) call xerrwv(
 
1580
     1  'lsodar- a switch to the adams (nonstiff) method has occurred',
 
1581
     1   60, 106, 1, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1582
      call xerrwv(
 
1583
     1  '     at t = r1,  tentative step size h = r2,  step nst = i1 ',
 
1584
     1   60, 107, 1, 1, nst, 0, 2, tn, h)
 
1585
 310  continue
 
1586
c
 
1587
      if (ngc .eq. 0) go to 315
 
1588
c     --------------------- masking -----------------------
 
1589
      call rchek2 (3, g, neq, y, rwork(lyh), nyh,
 
1590
     1   rwork(lg0), rwork(lg1), rwork(lgx), jroot, irt,iwork)
 
1591
c     --------------------- masking -----------------------
 
1592
 
 
1593
      if(iero.gt.0) return
 
1594
 
 
1595
      if(irt .eq. 2) then
 
1596
         lirfnd = 2
 
1597
         istate = 4
 
1598
         t = t0
 
1599
         go to 425
 
1600
      endif
 
1601
 
 
1602
      if (irt .ne. 1) go to 315
 
1603
      irfnd = 1
 
1604
      istate = 3
 
1605
      t = t0
 
1606
      go to 425
 
1607
 315  continue
 
1608
c
 
1609
      go to (320, 400, 330, 340, 350), itask
 
1610
c itask = 1.  if tout has been reached, interpolate. -------------------
 
1611
 320  if ((tn - tout)*h .lt. 0.0d0) go to 250
 
1612
      call intdy (tout, 0, rwork(lyh), nyh, y, iflag)
 
1613
      t = tout
 
1614
      go to 420
 
1615
c itask = 3.  jump to exit if tout was reached. ------------------------
 
1616
 330  if ((tn - tout)*h .ge. 0.0d0) go to 400
 
1617
      go to 250
 
1618
c itask = 4.  see if tout or tcrit was reached.  adjust h if necessary.
 
1619
 340  if ((tn - tout)*h .lt. 0.0d0) go to 345
 
1620
      call intdy (tout, 0, rwork(lyh), nyh, y, iflag)
 
1621
      t = tout
 
1622
      go to 420
 
1623
 345  hmx = dabs(tn) + dabs(h)
 
1624
      ihit = dabs(tn - tcrit) .le. 100.0d0*uround*hmx
 
1625
      if (ihit) go to 400
 
1626
      tnext = tn + h*(1.0d0 + 4.0d0*uround)
 
1627
      if ((tnext - tcrit)*h .le. 0.0d0) go to 250
 
1628
      h = (tcrit - tn)*(1.0d0 - 4.0d0*uround)
 
1629
cSCI
 
1630
cSCI  jstart = -2
 
1631
cSCI  replaced by:
 
1632
      if (jstart .ge. 0) jstart = -2
 
1633
      go to 250
 
1634
c itask = 5.  see if tcrit was reached and jump to exit. ---------------
 
1635
 350  hmx = dabs(tn) + dabs(h)
 
1636
      ihit = dabs(tn - tcrit) .le. 100.0d0*uround*hmx
 
1637
c-----------------------------------------------------------------------
 
1638
c block g.
 
1639
c the following block handles all successful returns from lsodar.
 
1640
c if itask .ne. 1, y is loaded from yh and t is set accordingly.
 
1641
c istate is set to 2, the illegal input counter is zeroed, and the
 
1642
c optional outputs are loaded into the work arrays before returning.
 
1643
c if istate = 1 and tout = t, there is a return with no action taken,
 
1644
c except that if this has happened repeatedly, the run is terminated.
 
1645
c-----------------------------------------------------------------------
 
1646
 400  do 410 i = 1,n
 
1647
 410    y(i) = rwork(i+lyh-1)
 
1648
      t = tn
 
1649
      if (itask .ne. 4 .and. itask .ne. 5) go to 420
 
1650
      if (ihit) t = tcrit
 
1651
 420  istate = 2
 
1652
 425  continue
 
1653
      illin = 0
 
1654
      rwork(11) = hu
 
1655
      rwork(12) = h
 
1656
      rwork(13) = tn
 
1657
      rwork(15) = tsw
 
1658
      iwork(11) = nst
 
1659
      iwork(12) = nfe
 
1660
      iwork(13) = nje
 
1661
      iwork(14) = nqu
 
1662
      iwork(15) = nq
 
1663
      iwork(19) = mused
 
1664
      iwork(20) = meth
 
1665
      iwork(10) = nge
 
1666
      tlast = t
 
1667
      return
 
1668
c
 
1669
 430  ntrep = ntrep + 1
 
1670
      if (ntrep .lt. 5) return
 
1671
      call xerrwv(
 
1672
     1  'lsodar-  repeated calls with istate = 1 and tout = t (=r1)  ',
 
1673
     1   60, 301, 1, 0, 0, 0, 1, t, 0.0d0)
 
1674
      go to 800
 
1675
c-----------------------------------------------------------------------
 
1676
c block h.
 
1677
c the following block handles all unsuccessful returns other than
 
1678
c those for illegal input.  first the error message routine is called.
 
1679
c if there was an error test or convergence test failure, imxer is set.
 
1680
c then y is loaded from yh, t is set to tn, and the illegal input
 
1681
c counter illin is set to 0.  the optional outputs are loaded into
 
1682
c the work arrays before returning.
 
1683
c-----------------------------------------------------------------------
 
1684
c the maximum number of steps was taken before reaching tout. ----------
 
1685
 500  call xerrwv('lsodar-  at current t (=r1), mxstep (=i1) steps'   ,
 
1686
     1   50, 201, 1, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1687
      call xerrwv('      taken on this call before reaching tout     ',
 
1688
     1   50, 201, 1, 1, mxstep, 0, 1, tn, 0.0d0)
 
1689
      istate = -1
 
1690
      go to 580
 
1691
c ewt(i) .le. 0.0 for some i (not at start of problem). ----------------
 
1692
 510  ewti = rwork(lewt+i-1)
 
1693
      call xerrwv('lsodar-  at t (=r1), ewt(i1) has become r2 .le. 0.',
 
1694
     1   50, 202, 1, 1, i, 0, 2, tn, ewti)
 
1695
      istate = -6
 
1696
      go to 580
 
1697
c too much accuracy requested for machine precision. -------------------
 
1698
 520  call xerrwv('lsodar-  at t (=r1), too much accuracy requested ',
 
1699
     1   50, 203, 1, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1700
      call xerrwv('      for precision of machine..  see tolsf (=r2)',
 
1701
     1   50, 203, 1, 0, 0, 0, 2, tn, tolsf)
 
1702
      rwork(14) = tolsf
 
1703
      istate = -2
 
1704
      go to 580
 
1705
c kflag = -1.  error test failed repeatedly or with abs(h) = hmin. -----
 
1706
 530  call xerrwv('lsodar-  at t(=r1) and step size h(=r2), the error',
 
1707
     1   50, 204, 1, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1708
      call xerrwv('      test failed repeatedly or with abs(h) = hmin',
 
1709
     1   50, 204, 1, 0, 0, 0, 2, tn, h)
 
1710
      istate = -4
 
1711
      go to 560
 
1712
c kflag = -2.  convergence failed repeatedly or with abs(h) = hmin. ----
 
1713
 540  call xerrwv('lsodar-  at t (=r1) and step size h (=r2), the   ',
 
1714
     1   50, 205, 1, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1715
      call xerrwv('      corrector convergence failed repeatedly    ',
 
1716
     1   50, 205, 1, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1717
      call xerrwv('      or with abs(h) = hmin   ',
 
1718
     1   30, 205, 1, 0, 0, 0, 2, tn, h)
 
1719
      istate = -5
 
1720
      go to 560
 
1721
c rwork length too small to proceed. -----------------------------------
 
1722
 550  call xerrwv('lsodar-  at current t(=r1), rwork length too small',
 
1723
     1   50, 206, 1, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1724
      call xerrwv(
 
1725
     1  '      to proceed.  the integration was otherwise successful.',
 
1726
     1   60, 206, 1, 0, 0, 0, 1, tn, 0.0d0)
 
1727
      istate = -7
 
1728
      go to 580
 
1729
c iwork length too small to proceed. -----------------------------------
 
1730
 555  call xerrwv('lsodar-  at current t(=r1), iwork length too small',
 
1731
     1   50, 207, 1, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1732
      call xerrwv(
 
1733
     1  '      to proceed.  the integration was otherwise successful.',
 
1734
     1   60, 207, 1, 0, 0, 0, 1, tn, 0.0d0)
 
1735
      istate = -7
 
1736
      go to 580
 
1737
c compute imxer if relevant. -------------------------------------------
 
1738
 560  big = 0.0d0
 
1739
      imxer = 1
 
1740
      do 570 i = 1,n
 
1741
        size = dabs(rwork(i+lacor-1)*rwork(i+lewt-1))
 
1742
        if (big .ge. size) go to 570
 
1743
        big = size
 
1744
        imxer = i
 
1745
 570    continue
 
1746
      iwork(16) = imxer
 
1747
c set y vector, t, illin, and optional outputs. ------------------------
 
1748
 580  do 590 i = 1,n
 
1749
 590    y(i) = rwork(i+lyh-1)
 
1750
      t = tn
 
1751
      illin = 0
 
1752
      rwork(11) = hu
 
1753
      rwork(12) = h
 
1754
      rwork(13) = tn
 
1755
      rwork(15) = tsw
 
1756
      iwork(11) = nst
 
1757
      iwork(12) = nfe
 
1758
      iwork(13) = nje
 
1759
      iwork(14) = nqu
 
1760
      iwork(15) = nq
 
1761
      iwork(19) = mused
 
1762
      iwork(20) = meth
 
1763
      iwork(10) = nge
 
1764
      tlast = t
 
1765
      return
 
1766
c-----------------------------------------------------------------------
 
1767
c block i.
 
1768
c the following block handles all error returns due to illegal input
 
1769
c (istate = -3), as detected before calling the core integrator.
 
1770
c first the error message routine is called.  then if there have been
 
1771
c 5 consecutive such returns just before this call to the solver,
 
1772
c the run is halted.
 
1773
c-----------------------------------------------------------------------
 
1774
 601  call xerrwv('lsodar-  istate (=i1) illegal ',
 
1775
     1   30, 1, 1, 1, istate, 0, 0, 0.0d0, 0.0d0)
 
1776
      go to 700
 
1777
 602  call xerrwv('lsodar-  itask (=i1) illegal  ',
 
1778
     1   30, 2, 1, 1, itask, 0, 0, 0.0d0, 0.0d0)
 
1779
      go to 700
 
1780
 603  call xerrwv('lsodar-  istate .gt. 1 but lsodar not initialized ',
 
1781
     1   50, 3, 1, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1782
      go to 700
 
1783
 604  call xerrwv('lsodar-  neq (=i1) .lt. 1     ',
 
1784
     1   30, 4, 1, 1, neq(1), 0, 0, 0.0d0, 0.0d0)
 
1785
      go to 700
 
1786
 605  call xerrwv('lsodar-  istate = 3 and neq increased (i1 to i2)  ',
 
1787
     1   50, 5, 1, 2, n, neq(1), 0, 0.0d0, 0.0d0)
 
1788
      go to 700
 
1789
 606  call xerrwv('lsodar-  itol (=i1) illegal   ',
 
1790
     1   30, 6, 1, 1, itol, 0, 0, 0.0d0, 0.0d0)
 
1791
      go to 700
 
1792
 607  call xerrwv('lsodar-  iopt (=i1) illegal   ',
 
1793
     1   30, 7, 1, 1, iopt, 0, 0, 0.0d0, 0.0d0)
 
1794
      go to 700
 
1795
 608  call xerrwv('lsodar-  jt (=i1) illegal     ',
 
1796
     1   30, 8, 1, 1, jt, 0, 0, 0.0d0, 0.0d0)
 
1797
      go to 700
 
1798
 609  call xerrwv('lsodar-  ml (=i1) illegal.. .lt.0 or .ge.neq (=i2)',
 
1799
     1   50, 9, 1, 2, ml, neq(1), 0, 0.0d0, 0.0d0)
 
1800
      go to 700
 
1801
 610  call xerrwv('lsodar-  mu (=i1) illegal.. .lt.0 or .ge.neq (=i2)',
 
1802
     1   50, 10, 1, 2, mu, neq(1), 0, 0.0d0, 0.0d0)
 
1803
      go to 700
 
1804
 611  call xerrwv('lsodar-  ixpr (=i1) illegal   ',
 
1805
     1   30, 11, 1, 1, ixpr, 0, 0, 0.0d0, 0.0d0)
 
1806
      go to 700
 
1807
 612  call xerrwv('lsodar-  mxstep (=i1) .lt. 0  ',
 
1808
     1   30, 12, 1, 1, mxstep, 0, 0, 0.0d0, 0.0d0)
 
1809
      go to 700
 
1810
 613  call xerrwv('lsodar-  mxhnil (=i1) .lt. 0  ',
 
1811
     1   30, 13, 1, 1, mxhnil, 0, 0, 0.0d0, 0.0d0)
 
1812
      go to 700
 
1813
 614  call xerrwv('lsodar-  tout (=r1) behind t (=r2)      ',
 
1814
     1   40, 14, 1, 0, 0, 0, 2, tout, t)
 
1815
      call xerrwv('      integration direction is given by h0 (=r1)  ',
 
1816
     1   50, 14, 1, 0, 0, 0, 1, h0, 0.0d0)
 
1817
      go to 700
 
1818
 615  call xerrwv('lsodar-  hmax (=r1) .lt. 0.0  ',
 
1819
     1   30, 15, 1, 0, 0, 0, 1, hmax, 0.0d0)
 
1820
      go to 700
 
1821
 616  call xerrwv('lsodar-  hmin (=r1) .lt. 0.0  ',
 
1822
     1   30, 16, 1, 0, 0, 0, 1, hmin, 0.0d0)
 
1823
      go to 700
 
1824
 617  call xerrwv(
 
1825
     1  'lsodar-  rwork length needed, lenrw (=i1), exceeds lrw (=i2)',
 
1826
     1   60, 17, 1, 2, lenrw, lrw, 0, 0.0d0, 0.0d0)
 
1827
      go to 700
 
1828
 618  call xerrwv(
 
1829
     1  'lsodar-  iwork length needed, leniw (=i1), exceeds liw (=i2)',
 
1830
     1   60, 18, 1, 2, leniw, liw, 0, 0.0d0, 0.0d0)
 
1831
      go to 700
 
1832
 619  call xerrwv('lsodar-  rtol(i1) is r1 .lt. 0.0        ',
 
1833
     1   40, 19, 1, 1, i, 0, 1, rtoli, 0.0d0)
 
1834
      go to 700
 
1835
 620  call xerrwv('lsodar-  atol(i1) is r1 .lt. 0.0        ',
 
1836
     1   40, 20, 1, 1, i, 0, 1, atoli, 0.0d0)
 
1837
      go to 700
 
1838
 621  ewti = rwork(lewt+i-1)
 
1839
      call xerrwv('lsodar-  ewt(i1) is r1 .le. 0.0         ',
 
1840
     1   40, 21, 1, 1, i, 0, 1, ewti, 0.0d0)
 
1841
      go to 700
 
1842
 622  call xerrwv(
 
1843
     1   'lsodar-  tout (=r1) too close to t(=r2) to start integration',
 
1844
     1   60, 22, 1, 0, 0, 0, 2, tout, t)
 
1845
      go to 700
 
1846
 623  call xerrwv(
 
1847
     1  'lsodar-  itask = i1 and tout (=r1) behind tcur - hu (= r2)  ',
 
1848
     1   60, 23, 1, 1, itask, 0, 2, tout, tp)
 
1849
      go to 700
 
1850
 624  call xerrwv(
 
1851
     1  'lsodar-  itask = 4 or 5 and tcrit (=r1) behind tcur (=r2)   ',
 
1852
     1   60, 24, 1, 0, 0, 0, 2, tcrit, tn)
 
1853
      go to 700
 
1854
 625  call xerrwv(
 
1855
     1  'lsodar-  itask = 4 or 5 and tcrit (=r1) behind tout (=r2)   ',
 
1856
     1   60, 25, 1, 0, 0, 0, 2, tcrit, tout)
 
1857
      go to 700
 
1858
 626  call xerrwv('lsodar-  at start of problem, too much accuracy   ',
 
1859
     1   50, 26, 1, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1860
      call xerrwv(
 
1861
     1  '      requested for precision of machine..  see tolsf (=r1) ',
 
1862
     1   60, 26, 1, 0, 0, 0, 1, tolsf, 0.0d0)
 
1863
      rwork(14) = tolsf
 
1864
      go to 700
 
1865
 627  call xerrwv('lsodar-  trouble from intdy. itask = i1, tout = r1',
 
1866
     1   50, 27, 1, 1, itask, 0, 1, tout, 0.0d0)
 
1867
      go to 700
 
1868
 628  call xerrwv('lsodar-  mxordn (=i1) .lt. 0  ',
 
1869
     1   30, 28, 1, 1, mxordn, 0, 0, 0.0d0, 0.0d0)
 
1870
      go to 700
 
1871
 629  call xerrwv('lsodar-  mxords (=i1) .lt. 0  ',
 
1872
     1   30, 29, 1, 1, mxords, 0, 0, 0.0d0, 0.0d0)
 
1873
      go to 700
 
1874
 630  call xerrwv('lsodar-  ng (=i1) .lt. 0      ',
 
1875
     1   30, 30, 1, 1, ng, 0, 0, 0.0d0, 0.0d0)
 
1876
      go to 700
 
1877
 631  call xerrwv('lsodar-  ng changed (from i1 to i2) illegally,    ',
 
1878
     1   50, 31, 1, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1879
      call xerrwv('      i.e. not immediately after a root was found ',
 
1880
     1   50, 31, 1, 2, ngc, ng, 0, 0.0d0, 0.0d0)
 
1881
      go to 700
 
1882
 632  call xerrwv('lsodar-  one or more components of g has a root   ',
 
1883
     1   50, 32, 1, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1884
      call xerrwv('      too near to the initial point     ',
 
1885
     1   40, 32, 1, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1886
c
 
1887
 700  if (illin .eq. 5) go to 710
 
1888
      illin = illin + 1
 
1889
      tlast = t
 
1890
      istate = -3
 
1891
      return
 
1892
 710  call xerrwv('lsodar-  repeated occurrences of illegal input    ',
 
1893
     1   50, 302, 1, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1894
c
 
1895
 800  call xerrwv('lsodar-  run aborted.. apparent infinite loop     ',
 
1896
     1   50, 303, 2, 0, 0, 0, 0, 0.0d0, 0.0d0)
 
1897
      return
 
1898
c----------------------- end of subroutine lsodar ----------------------
 
1899
      end