# NAG Library Routine Document

## d01rbf (withdraw_1d_gen_vec_multi_diagnostic)

Note: please be advised that d01rbf has been deprecated. You are advised to follow the directions in Section 9.1 in d01raf to replicate its functionality. Furthermore, any future diagnostic enhancements for d01raf will only be available in this manner.

## 1Purpose

d01rbf is an expert diagnostic routine associated with d01raf to allow the arrays icom and com to be examined. These arrays contain details of the adaptive process. Facilities are provided, via the argument monit, to refine the final answer by adjusting the contribution made by specific segments.

## 2Specification

Fortran Interface
 Subroutine d01rbf ( ni, icom, com, lcom,
 Integer, Intent (In) :: ni, icom(licom), licom, lcom Integer, Intent (Inout) :: iuser(*), ifail Integer, Intent (Out) :: licusd, lcusd Real (Kind=nag_wp), Intent (In) :: com(lcom) Real (Kind=nag_wp), Intent (Inout) :: dinest(ni), errest(ni), ruser(*) External :: monit
#include nagmk26.h
 void d01rbf_ (void (NAG_CALL *monit)(const Integer *ni, const Integer *ns, double dinest[], double errest[], const Integer fcount[], const Integer sinfoi[], const Integer evals[], const Integer *ldi, const double sinfor[], const double fs[], const double es[], const Integer *ldr, Integer iuser[], double ruser[]),const Integer *ni, double dinest[], double errest[], const Integer icom[], const Integer *licom, Integer *licusd, const double com[], const Integer *lcom, Integer *lcusd, Integer iuser[], double ruser[], Integer *ifail)

## 3Description

The principal role of d01rbf is to take information about the adaptive process that is stored in com and icom and present it in more intelligible arguments. A monitor routine, monit, allows you to report the progress of the adaptive process back to the calling program between those calls of d01raf which have returned ${\mathbf{irevcm}}=11$ or $12$.
A secondary role, useful only if you are an expert, is to utilize monit in such a way that it can override aspects of that information. Specifically, you may choose to remove the contributions of one or more individual segments from the estimates for individual integrals contained in dinest and errest, and replace such information with a more accurate approximation you have calculated by some other means. Clearly this facility should only be used with care. We recommend that it be used only after d01raf has returned with ${\mathbf{irevcm}}=0$, i.e., it has completed the computation of the approximations of the integrals.

None.

## 5Arguments

1:     $\mathbf{monit}$ – Subroutine, supplied by the NAG Library or the user.External Procedure
monit allows you to examine details of the adaptive process after a call of d01raf returning ${\mathbf{irevcm}}=11$ or $12$. Additionally, after a call of d01raf returning ${\mathbf{irevcm}}=0$, monit may enhance the computed solution.
If no monitoring is required, monit may be the dummy monitoring routine d01rbm. (d01rbm is included in the NAG Library.)
The specification of monit is:
Fortran Interface
 Subroutine monit ( ni, ns, ldi, fs, es, ldr,
 Integer, Intent (In) :: ni, ns, fcount(ni), sinfoi(ldi,*), evals(ldi,*), ldi, ldr Integer, Intent (Inout) :: iuser(*) Real (Kind=nag_wp), Intent (In) :: sinfor(ldr,*), fs(ldr,*), es(ldr,*) Real (Kind=nag_wp), Intent (Inout) :: dinest(ni), errest(ni), ruser(*)
#include nagmk26.h
 void monit (const Integer *ni, const Integer *ns, double dinest[], double errest[], const Integer fcount[], const Integer sinfoi[], const Integer evals[], const Integer *ldi, const double sinfor[], const double fs[], const double es[], const Integer *ldr, Integer iuser[], double ruser[])
1:     $\mathbf{ni}$ – IntegerInput
On entry: ${n}_{i}$, the number of integrands specified in d01raf.
2:     $\mathbf{ns}$ – IntegerInput
On entry: ${n}_{s}$, the number of segments formed during the adaptive procedure that can currently be examined. ${n}_{s}=2{n}_{\mathit{sdiv}}+{s}_{\mathit{pri}}$, where ${n}_{\mathit{sdiv}}$ is the number of segments that have been subdivided (the number of subdivisions).
3:     $\mathbf{dinest}\left({\mathbf{ni}}\right)$ – Real (Kind=nag_wp) arrayInput/Output
On entry: ${\mathbf{dinest}}\left(\mathit{j}\right)$ contains the current estimate of the definite integral of integrand $\mathit{j}$, for $\mathit{j}=1,2,\dots ,{n}_{i}$.
On exit: you may refine the estimates in dinest. This should only be done after d01raf has returned ${\mathbf{irevcm}}=0$.
4:     $\mathbf{errest}\left({\mathbf{ni}}\right)$ – Real (Kind=nag_wp) arrayInput/Output
On entry: ${\mathbf{errest}}\left(\mathit{j}\right)$ contains the current error estimate associated with integral $\mathit{j}$, for $\mathit{j}=1,2,\dots ,{n}_{i}$.
On exit: you may refine the estimates in errest. This should only be done after d01raf has returned ${\mathbf{irevcm}}=0$.
5:     $\mathbf{fcount}\left({\mathbf{ni}}\right)$ – Integer arrayInput
On entry: ${\mathbf{fcount}}\left(\mathit{j}\right)$ contains the number of different approximations of integral $\mathit{j}$ calculated so far, for $\mathit{j}=1,2,\dots ,{n}_{i}$.
6:     $\mathbf{sinfoi}\left({\mathbf{ldi}},*\right)$ – Integer arrayInput
On entry: ${\mathbf{sinfoi}}\left(\mathit{l},\mathit{k}\right)$ contains information about the hierarchy of splitting, for $\mathit{l}=1,2,\dots ,5$ and $\mathit{k}=1,2,\dots ,{n}_{s}$.
${\mathbf{sinfoi}}\left(1,k\right)$
Contains a unique identifier, the sid, related to segment $k$.
${\mathbf{sinfoi}}\left(2,k\right)$
Contains the parent segment number of segment $k$, the reference to the segment that was split to create segment $k$.
${\mathbf{sinfoi}}\left(3,k\right)$ and ${\mathbf{sinfoi}}\left(4,k\right)$
Contain the segment numbers of the two child segments formed from segment $k$, if segment $k$ has been split. If segment $k$ has not been split, these will be negative.
${\mathbf{sinfoi}}\left(5,k\right)$
Contains the level at which the segment exists, corresponding to ${n}_{a}+1$, where ${n}_{a}$ is the number of ancestor segments of segment $k$.
If ${\mathbf{sinfoi}}\left(5,k\right)<0$, this segment is considered too small for further splitting, and its level is $\left|{\mathbf{sinfoi}}\left(5,k\right)\right|$.
7:     $\mathbf{evals}\left({\mathbf{ldi}},*\right)$ – Integer arrayInput
On entry: contains information to indicate whether an estimate of the integral $\mathit{j}$ has been obtained over segment $\mathit{k}$, and if so whether this evaluation still contributes to the approximation in ${\mathbf{dinest}}\left(\mathit{j}\right)$, for $\mathit{j}=1,2,\dots ,{n}_{i}$ and $\mathit{k}=1,2,\dots ,{n}_{s}$.
${\mathbf{evals}}\left(j,k\right)=0$
Indicates that integral $j$ has not been evaluated over segment $k$.
${\mathbf{evals}}\left(j,k\right)=1$
Indicates that integral $j$ has been evaluated over segment $k$, and that this evaluation contributes to the total approximation ${\mathbf{dinest}}\left(j\right)$.
${\mathbf{evals}}\left(j,k\right)=2$
Indicates that integral $j$ has been evaluated over segment $k$, that this evaluation contributes to the total approximation ${\mathbf{dinest}}\left(j\right)$, and that you have requested no further evaluation of this integral at this segment by setting ${\mathbf{needi}}\left(j\right)<0$.
${\mathbf{evals}}\left(j,k\right)=3$
Indicates that integral $j$ has been evaluated over segment $k$, and this evaluation no longer contributes to ${\mathbf{dinest}}\left(j\right)$.
${\mathbf{evals}}\left(j,k\right)=4$
Indicates that integral $j$ has been evaluated over segment $k$, that this evaluation contributes to the total approximation ${\mathbf{dinest}}\left(j\right)$, and that this segment is too small for any further splitting to be performed. Integral $j$ also has a local error estimate over this segment above the requested tolerance. Such segments cause d01raf to return ${\mathbf{ifail}}={\mathbf{2}}$ or ${\mathbf{3}}$, indicating extremely bad behaviour.
${\mathbf{evals}}\left(j,k\right)=5$
Indicates that integral $j$ has been evaluated over segment $k$, that this evaluation contributes to the total approximation of ${\mathbf{dinest}}\left(j\right)$, and that this segment is too small for any further splitting to be performed. The local error estimate is however below the requested tolerance.
8:     $\mathbf{ldi}$ – IntegerInput
On entry: the leading dimension of arrays sinfoi and evals.
9:     $\mathbf{sinfor}\left({\mathbf{ldr}},*\right)$ – Real (Kind=nag_wp) arrayInput
On entry: sinfor contains the bounds of each segment $\mathit{k}$, for $\mathit{k}=1,2,\dots ,{n}_{s}$.
${\mathbf{sinfor}}\left(1,k\right)$
Contains the lower bound of segment $k$.
${\mathbf{sinfor}}\left(2,k\right)$
Contains the upper bound of segment $k$.
10:   $\mathbf{fs}\left({\mathbf{ldr}},*\right)$ – Real (Kind=nag_wp) arrayInput
On entry: ${\mathbf{fs}}\left(\mathit{j},\mathit{k}\right)$ contains the definite integral estimate of the $\mathit{j}$th integral over the $\mathit{k}$th segment, for $\mathit{j}=1,2,\dots ,{n}_{i}$ and $\mathit{k}=1,2,\dots ,{n}_{s}$.
11:   $\mathbf{es}\left({\mathbf{ldr}},*\right)$ – Real (Kind=nag_wp) arrayInput
On entry: ${\mathbf{es}}\left(\mathit{j},\mathit{k}\right)$ contains the definite integral error estimate of the $\mathit{j}$th integral over the $\mathit{k}$th segment, for $\mathit{j}=1,2,\dots ,{n}_{i}$ and $\mathit{k}=1,2,\dots ,{n}_{s}$.
12:   $\mathbf{ldr}$ – IntegerInput
On entry: the leading dimension of arrays sinfor, fs and es.
13:   $\mathbf{iuser}\left(*\right)$ – Integer arrayUser Workspace
14:   $\mathbf{ruser}\left(*\right)$ – Real (Kind=nag_wp) arrayUser Workspace
monit is called with the arguments iuser and ruser as supplied to d01rbf. You should use the arrays iuser and ruser to supply information to monit.
monit must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which d01rbf is called. Arguments denoted as Input must not be changed by this procedure.
Note: monit should not return floating-point NaN (Not a Number) or infinity values, since these are not handled by d01rbf. If your code inadvertently does return any NaNs or infinities, d01rbf is likely to produce unexpected results.
2:     $\mathbf{ni}$ – IntegerInput
On entry: ${n}_{i}$, the number of integrals.
3:     $\mathbf{dinest}\left({\mathbf{ni}}\right)$ – Real (Kind=nag_wp) arrayInput/Output
On entry: ${\mathbf{dinest}}\left(\mathit{j}\right)$ contains the current estimate of the definite integral of integrand $\mathit{j}$, for $\mathit{j}=1,2,\dots ,{n}_{i}$.
On exit: dinest is not altered by d01rbf directly. It may be changed by monit.
4:     $\mathbf{errest}\left({\mathbf{ni}}\right)$ – Real (Kind=nag_wp) arrayInput/Output
On entry: ${\mathbf{errest}}\left(\mathit{j}\right)$ contains the current error estimate associated with integral $\mathit{j}$, for $\mathit{j}=1,2,\dots ,{n}_{i}$.
On exit: errest is not altered by d01rbf directly. It may be changed by monit.
5:     $\mathbf{icom}\left({\mathbf{licom}}\right)$ – Integer arrayCommunication Array
On entry: the elements of this array must not be changed since the call of d01raf.
6:     $\mathbf{licom}$ – IntegerInput
On entry: the dimension of the array icom as declared in the (sub)program from which d01rbf is called. Normally this will be the same value licom passed to d01raf.
Constraint: ${\mathbf{licom}}\ge 50$.
Note: if ${\mathbf{licom}}<{\mathbf{licusd}}$, (i.e., licom is less than the value passed to d01raf) not all segments may be investigated using monit (see argument ns) and d01rbf will return ${\mathbf{ifail}}={\mathbf{1}}$.
7:     $\mathbf{licusd}$ – IntegerOutput
On exit: the number of elements of the array icom, passed to d01raf, actually used.
8:     $\mathbf{com}\left({\mathbf{lcom}}\right)$ – Real (Kind=nag_wp) arrayCommunication Array
On entry: the elements of this array must not be changed since the call of d01raf.
9:     $\mathbf{lcom}$ – IntegerInput
On entry: the dimension of the array com as declared in the (sub)program from which d01rbf is called. Normally this will be the same value lcom passed to d01raf.
Constraint: ${\mathbf{lcom}}\ge 50$.
Note: if ${\mathbf{lcom}}<{\mathbf{lcusd}}$, (i.e., lcom is less than the value passed to d01raf) not all segments may be investigated using monit (see argument ns) and d01rbf will return ${\mathbf{ifail}}={\mathbf{1}}$.
10:   $\mathbf{lcusd}$ – IntegerOutput
On exit: the number of elements of com used by d01raf.
11:   $\mathbf{iuser}\left(*\right)$ – Integer arrayUser Workspace
12:   $\mathbf{ruser}\left(*\right)$ – Real (Kind=nag_wp) arrayUser Workspace
iuser and ruser are not used by d01rbf, but are passed directly to monit and may be used to pass information to this routine.
13:   $\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, because for this routine the values of the output arguments may be useful even if ${\mathbf{ifail}}\ne {\mathbf{0}}$ on exit, the recommended value is $-1$. When the value $-\mathbf{1}\text{​ or ​}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).
Note: d01rbf may return useful information for one or more of the following detected errors or warnings.
Errors or warnings detected by the routine:
${\mathbf{ifail}}=1$
On entry, ${\mathbf{licom}}=〈\mathit{\text{value}}〉$, ${\mathbf{lcom}}=〈\mathit{\text{value}}〉$.
licom or lcom is insufficient for a complete examination of the communication arrays. A maximum $〈\mathit{\text{value}}〉$ segments out of $〈\mathit{\text{value}}〉$ are examinable.
Constraint: ${\mathbf{licom}}\ge 〈\mathit{\text{value}}〉$ and ${\mathbf{lcom}}\ge 〈\mathit{\text{value}}〉$.
${\mathbf{ifail}}=21$
On entry, ni is not consistent with that used to construct the communication arrays.
On entry, ${\mathbf{ni}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ni}}=〈\mathit{\text{value}}〉$.
${\mathbf{ifail}}=61$
On entry, ${\mathbf{licom}}<50$.
${\mathbf{ifail}}=91$
On entry, ${\mathbf{lcom}}<50$.
${\mathbf{ifail}}=1101$
Either the communication arrays have not been created by d01raf, or they have become corrupted.
${\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

d01rbf is not threaded in any implementation.

When called after d01raf has returned ${\mathbf{irevcm}}=0$, d01rbf may be used to modify dinest and errest. For example if ${\mathbf{evals}}\left(\mathit{j},\stackrel{-}{\mathit{k}}\right)=4$ for some $j\in 1,\dots ,{n}_{i}$, $\stackrel{-}{k}\in 1,\dots ,{n}_{s}$, indicating integral $j$ was badly behaved over segment $\stackrel{-}{k}$, then one may potentially modify ${\mathbf{dinest}}\left(j\right)$ as follows:
• ${a}_{\stackrel{-}{k}}={\mathbf{sinfor}}\left(\mathit{l},\mathit{k}\right)$
• ${b}_{\stackrel{-}{k}}={\mathbf{sinfor}}\left(\mathit{l},\mathit{k}\right)$
• ${F}_{\stackrel{-}{k}}^{\mathrm{new}}={\int }_{{a}_{\stackrel{-}{k}}}^{{b}_{\stackrel{-}{k}}}{f}_{j}\left(x\right)dx$: performed using accurate technique for specific function.
• ${\mathbf{dinest}}\left(j\right)={\mathbf{dinest}}\left(j\right)-{\mathbf{fs}}\left(\mathit{j},\stackrel{-}{\mathit{k}}\right)+{F}_{\stackrel{-}{k}}^{\mathrm{new}}$
errest may be similarly updated if required.
Note: if integral $j$ has been approximated successfully due to extrapolation, indicated by ${\mathbf{needi}}\left(j\right)=1$ after d01raf has completed, ${\mathbf{dinest}}\left(j\right)$ will not be the direct sum of the contributing segments. You may however reconstruct the unextrapolated integral estimate as,
 $dinestj = ∑ K fsjk + ∑ K- fsjk- ,$
where $K=\left\{k\mid {\mathbf{evals}}\left({\mathbf{ldi}}×\left(\mathit{k}\right)+\mathit{j}\right)=1,2,5\right\}$ and $\stackrel{-}{K}=\left\{\stackrel{-}{\mathit{k}}\mid {\mathbf{evals}}\left({\mathbf{ldi}}×\left(\stackrel{-}{\mathit{k}}\right)+\mathit{j}\right)=4\right\}$, the sets of all contributing segements where integral $j$ has been evaluated accurately and inaccurately respectively. Some or all of the terms in the summation over $\stackrel{-}{K}$ may be replaced with more accurate approximations ${F}_{\stackrel{-}{k}}^{\mathrm{new}}$ if available.

## 10Example

See Section 10 in d01raf.
© The Numerical Algorithms Group Ltd, Oxford, UK. 2017