# NAG Library Routine Document

## 1Purpose

d02qwf is a setup routine which must be called prior to the first call of either of the integrators d02qff and d02qgf and may be called prior to any continuation call to these routines.

## 2Specification

Fortran Interface
 Subroutine d02qwf ( neqf, atol, rtol, crit, hmax, neqg,
 Integer, Intent (In) :: neqf, latol, lrtol, maxstp, neqg, lrwork, liwork Integer, Intent (Inout) :: iwork(liwork), ifail Real (Kind=nag_wp), Intent (In) :: atol(latol), rtol(lrtol), tcrit, hmax Real (Kind=nag_wp), Intent (Inout) :: rwork(lrwork) Logical, Intent (In) :: vectol, onestp, crit, sophst Logical, Intent (Inout) :: alterg Character (1), Intent (Inout) :: statef
#include nagmk26.h
 void d02qwf_ (char *statef, const Integer *neqf, const logical *vectol, const double atol[], const Integer *latol, const double rtol[], const Integer *lrtol, const logical *onestp, const logical *crit, const double *tcrit, const double *hmax, const Integer *maxstp, const Integer *neqg, logical *alterg, const logical *sophst, double rwork[], const Integer *lrwork, Integer iwork[], const Integer *liwork, Integer *ifail, const Charlen length_statef)

## 3Description

d02qwf permits initialization of the integration method and setting of optional inputs prior to any call of d02qff or d02qgf. It must be called before the first call of either of the routines d02qff or d02qgf and it may be called before any continuation call of either of the routines d02qff or d02qgf.

None.

## 5Arguments

1:     $\mathbf{statef}$ – Character(1)Input/Output
On entry: specifies whether the integration routine (d02qff or d02qgf) is to start a new system of ordinary differential equations, restart a system or continue with a system.
${\mathbf{statef}}=\text{'S'}$
Start integration with a new differential system.
${\mathbf{statef}}=\text{'R'}$
Restart integration with the current differential system.
${\mathbf{statef}}=\text{'C'}$
Continue integration with the current differential system.
Constraint: ${\mathbf{statef}}=\text{'S'}$, $\text{'R'}$ or $\text{'C'}$.
On exit: is set to 'C', except that if an error is detected, statef is unchanged.
2:     $\mathbf{neqf}$ – IntegerInput
On entry: the number of ordinary differential equations to be solved by the integration routine. neqf must remain unchanged on subsequent calls to d02qwf with ${\mathbf{statef}}=\text{'C'}$ or $\text{'R'}$.
Constraint: ${\mathbf{neqf}}\ge 1$.
3:     $\mathbf{vectol}$ – LogicalInput
On entry: specifies whether vector or scalar error control is to be employed for the local error test in the integration.
If ${\mathbf{vectol}}=\mathrm{.TRUE.}$, vector error control will be used and you must specify values of ${\mathbf{rtol}}\left(\mathit{i}\right)$ and ${\mathbf{atol}}\left(\mathit{i}\right)$, for $\mathit{i}=1,2,\dots ,{\mathbf{neqf}}$.
Otherwise scalar error control will be used and you must specify values of just ${\mathbf{rtol}}\left(1\right)$ and ${\mathbf{atol}}\left(1\right)$.
The error test to be satisfied is of the form
 $∑i=1neqf eiwi 2≤1.0.$
where ${w}_{i}$ is defined as follows:
 vectol ${w}_{i}$ .TRUE. ${\mathbf{rtol}}\left(i\right)×\left|{y}_{i}\right|+{\mathbf{atol}}\left(i\right)$ .FALSE. ${\mathbf{rtol}}\left(1\right)×\left|{y}_{i}\right|+{\mathbf{atol}}\left(1\right)$
and ${e}_{i}$ is an estimate of the local error in ${y}_{i}$, computed internally. vectol must remain unchanged on subsequent calls to d02qwf with ${\mathbf{statef}}=\text{'C'}$ or $\text{'R'}$.
4:     $\mathbf{atol}\left({\mathbf{latol}}\right)$ – Real (Kind=nag_wp) arrayInput
On entry: the absolute local error tolerance (see vectol).
Constraint: ${\mathbf{atol}}\left(i\right)\ge 0.0$.
5:     $\mathbf{latol}$ – IntegerInput
On entry: the dimension of the array atol as declared in the (sub)program from which d02qwf is called.
Constraints:
• if ${\mathbf{vectol}}=\mathrm{.TRUE.}$, ${\mathbf{latol}}\ge {\mathbf{neqf}}$;
• if ${\mathbf{vectol}}=\mathrm{.FALSE.}$, ${\mathbf{latol}}\ge 1$.
6:     $\mathbf{rtol}\left({\mathbf{lrtol}}\right)$ – Real (Kind=nag_wp) arrayInput
On entry: the relative local error tolerance (see vectol).
Constraints:
• ${\mathbf{rtol}}\left(i\right)\ge 0.0$;
• if ${\mathbf{atol}}\left(i\right)=0.0$, .
7:     $\mathbf{lrtol}$ – IntegerInput
On entry: the dimension of the array rtol as declared in the (sub)program from which d02qwf is called.
Constraints:
• if ${\mathbf{vectol}}=\mathrm{.TRUE.}$, ${\mathbf{lrtol}}\ge {\mathbf{neqf}}$;
• if ${\mathbf{vectol}}=\mathrm{.FALSE.}$, ${\mathbf{lrtol}}\ge 1$.
8:     $\mathbf{onestp}$ – LogicalInput
On entry: the mode of operation of the integration routine. If ${\mathbf{onestp}}=\mathrm{.TRUE.}$, the integration routine will operate in one-step mode, that is it will return after each successful step. Otherwise the integration routine will operate in interval mode, that is it will return at the end of the integration interval.
9:     $\mathbf{crit}$ – LogicalInput
On entry: specifies whether or not there is a value for the independent variable beyond which integration is not to be attempted. Setting ${\mathbf{crit}}=\mathrm{.TRUE.}$ indicates that there is such a point, whereas ${\mathbf{crit}}=\mathrm{.FALSE.}$ indicates that there is no such restriction.
10:   $\mathbf{tcrit}$ – Real (Kind=nag_wp)Input
On entry: with ${\mathbf{crit}}=\mathrm{.TRUE.}$, tcrit must be set to a value of the independent variable beyond which integration is not to be attempted. Otherwise tcrit is not referenced.
11:   $\mathbf{hmax}$ – Real (Kind=nag_wp)Input
On entry: if ${\mathbf{hmax}}\ne 0.0$, a bound on the absolute step size during the integration is taken to be $\left|{\mathbf{hmax}}\right|$.
If ${\mathbf{hmax}}=0.0$, no bound is assumed on the step size during the integration.
A bound may be required if there are features of the solution on very short ranges of integration which may be missed. You should try ${\mathbf{hmax}}=0.0$ first.
Note:  this argument only affects the step size if the option ${\mathbf{crit}}=\mathrm{.TRUE.}$ is being used.
12:   $\mathbf{maxstp}$ – IntegerInput
On entry: a bound on the number of attempted steps in any one call to the integration routine. If ${\mathbf{maxstp}}\le 0$ on entry, a value of $1000$ is used.
13:   $\mathbf{neqg}$ – IntegerInput
On entry: specifies whether or not root-finding is required in d02qff or d02qgf.
${\mathbf{neqg}}\le 0$
No root-finding is attempted.
${\mathbf{neqg}}>0$
Root-finding is required and neqg event functions will be specified for the integration routine.
14:   $\mathbf{alterg}$ – LogicalInput/Output
On entry: specifies whether or not the event functions have been redefined. alterg need not be set if ${\mathbf{statef}}=\text{'S'}$. On subsequent calls to d02qwf, if neqg has been set positive, ${\mathbf{alterg}}=\mathrm{.FALSE.}$ specifies that the event functions remain unchanged, whereas ${\mathbf{alterg}}=\mathrm{.TRUE.}$ specifies that the event functions have changed. Because of the expense in reinitializing the root searching procedure, alterg should be set to .TRUE. only if the event functions really have been altered. alterg need not be set if the root-finding option is not used.
On exit: is set to .FALSE..
15:   $\mathbf{sophst}$ – LogicalInput
On entry: the type of search technique to be used in the root-finding. If ${\mathbf{sophst}}=\mathrm{.TRUE.}$ then a sophisticated and reliable but expensive technique will be used, whereas for ${\mathbf{sophst}}=\mathrm{.FALSE.}$ a simple but less reliable technique will be used. If ${\mathbf{neqg}}\le 0$, sophst is not referenced.
16:   $\mathbf{rwork}\left({\mathbf{lrwork}}\right)$ – Real (Kind=nag_wp) arrayCommunication Array
This must be the same argument rwork supplied to the integration routine. It is used to pass information to the integration routine and therefore the contents of this array must not be changed before calling the integration routine.
17:   $\mathbf{lrwork}$ – IntegerInput
On entry: the dimension of the array rwork as declared in the (sub)program from which d02qwf is called.
Constraint: ${\mathbf{lrwork}}\ge 21×\left(1+{\mathbf{neqf}}\right)+2×\mathit{J}+\mathit{K}×{\mathbf{neqg}}+2$, where
 $J= neqf if ​vectol=.TRUE. 1 if ​vectol=.FALSE.$
and
 $K= 14 if ​ sophst=.TRUE. 5 if ​ sophst=.FALSE.$
.
18:   $\mathbf{iwork}\left({\mathbf{liwork}}\right)$ – Integer arrayCommunication Array
This must be the same argument iwork supplied to the integration routine. It is used to pass information to the integration routine and therefore the contents of this array must not be changed before calling the integration routine.
19:   $\mathbf{liwork}$ – IntegerInput
On entry: the dimension of the array iwork as declared in the (sub)program from which d02qwf is called.
Constraints:
• if ${\mathbf{sophst}}=\mathrm{.TRUE.}$, ${\mathbf{liwork}}\ge 21+4×{\mathbf{neqg}}$;
• if ${\mathbf{sophst}}=\mathrm{.FALSE.}$, ${\mathbf{liwork}}\ge 21+{\mathbf{neqg}}$.
20:   $\mathbf{ifail}$ – IntegerInput/Output
On entry: ifail must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this argument, the recommended value is $0$. When the value $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of ifail on exit.
On exit: ${\mathbf{ifail}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6Error Indicators and Warnings

If on entry ${\mathbf{ifail}}=0$ or $-1$, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
${\mathbf{ifail}}=1$
Illegal input detected.
${\mathbf{ifail}}=-99$
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

Not applicable.

## 8Parallelism and Performance

d02qwf is not thread safe and should not be called from a multithreaded user program. Please see Section 3.12.1 in How to Use the NAG Library and its Documentation for more information on thread safety.
d02qwf is not threaded in any implementation.

Prior to a continuation call of the integration routine, you may reset any of the optional parameters by calling d02qwf with ${\mathbf{statef}}=\text{'C'}$. You may reset:
If the behaviour of the system of differential equations has altered and you wish to restart the integration method from the value of t output from the integration routine (see d02qff and d02qgf), then statef should be set to ${\mathbf{statef}}=\text{'R'}$ and any of the optional parameters may be reset also. If you want to redefine the system of differential equations or start a new integration problem, then statef should be set to ${\mathbf{statef}}=\text{'S'}$. Resetting ${\mathbf{statef}}=\text{'R'}$ or $\text{'S'}$ on normal continuation calls causes a restart in the integration process, which is very inefficient when not needed.