NAG FORTRAN MARK 16 LIBRARY CONCISE SUMMARY

N.B. This summary does not include routines which have been superseded and are scheduled for withdrawal at a future mark.

A00AAF
Library identification, details of implementation and mark
A02AAF
Square root of a complex number
A02ABF
Modulus of a complex number
A02ACF
Quotient of two complex numbers
C02AFF
All zeros of complex polynomial, modified Laguerre method
C02AGF
All zeros of real polynomial, modified Laguerre method
C02AHF
All zeros of complex quadratic
C02AJF
All zeros of real quadratic
C05ADF
Zero of continuous function in given interval, Bus and Dekker algorithm
C05AGF
Zero of continuous function, Bus and Dekker algorithm, from given starting value, binary search for interval
C05AJF
Zero of continuous function, continuation method, from a given starting value
C05AVF
Binary search for interval containing zero of continuous function (reverse communication)
C05AXF
Zero of continuous function by continuation method, from given starting value (reverse communication)
C05AZF
Zero in given interval of continuous function by Bus and Dekker algorithm (reverse communication)
C05NBF
Solution of system of nonlinear equations using function values only (easy-to-use)
C05NCF
Solution of system of nonlinear equations using function values only (comprehensive)
C05NDF
Solution of systems of nonlinear equations using function values only (reverse communication)
C05PBF
Solution of system of nonlinear equations using 1st derivatives (easy-to-use)
C05PCF
Solution of system of nonlinear equations using 1st derivatives (comprehensive)
C05PDF
Solution of systems of nonlinear equations using 1st derivatives (reverse communication)
C05ZAF
Check user's routine for calculating 1st derivatives
C06BAF
Acceleration of convergence of sequence, Shanks' transformation and epsilon algorithm
C06DBF
Sum of a Chebyshev series
C06EAF
Single 1-D real discrete Fourier transform, no extra workspace
C06EBF
Single 1-D Hermitian discrete Fourier transform, no extra workspace
C06ECF
Single 1-D complex discrete Fourier transform, no extra workspace
C06EKF
Circular convolution or correlation of two real vectors, no extra workspace
C06FAF
Single 1-D real discrete Fourier transform, extra workspace for greater speed
C06FBF
Single 1-D Hermitian discrete Fourier transform, extra workspace for greater speed
C06FCF
Single 1-D complex discrete Fourier transform, extra workspace for greater speed
C06FFF
1-D complex discrete Fourier transform of multi-dimensional data
C06FJF
Multi-dimensional complex discrete Fourier transform of multi-dimensional data
C06FKF
Circular convolution or correlation of two real vectors, extra workspace for greater speed
C06FPF
Multiple 1-D real discrete Fourier transforms
C06FQF
Multiple 1-D Hermitian discrete Fourier transforms
C06FRF
Multiple 1-D complex discrete Fourier transforms
C06FUF
2-D complex discrete Fourier transform
C06GBF
Complex conjugate of Hermitian sequence
C06GCF
Complex conjugate of complex sequence
C06GQF
Complex conjugate of multiple Hermitian sequences
C06GSF
Convert Hermitian sequences to general complex sequences
C06HAF
Discrete sine transform
C06HBF
Discrete cosine transform
C06HCF
Discrete quarter-wave sine transform
C06HDF
Discrete quarter-wave cosine transform
C06LAF
Inverse Laplace transform, Crump's method
C06LBF
Inverse Laplace transform, modified Weeks' method
C06LCF
Evaluate inverse Laplace transform as computed by C06LBF
D01AHF
1-D quadrature, adaptive, finite interval, strategy due to Patterson, suitable for well-behaved integrands
D01AJF
1-D quadrature, adaptive, finite interval, strategy due to Piessens and de Doncker, allowing for badly-behaved integrands
D01AKF
1-D quadrature, adaptive, finite interval, method suitable for oscillating functions
D01ALF
1-D quadrature, adaptive, finite interval, allowing for singularities at user-specified break-points
D01AMF
1-D quadrature, adaptive, infinite or semi-infinite interval
D01ANF
1-D quadrature, adaptive, finite interval, weight function cos(wx) or sin(wx)
D01APF
1-D quadrature, adaptive, finite interval, weight function with end-point singularities of algebraico-logarithmic type
D01AQF
1-D quadrature, adaptive, finite interval, weight function 1/(x-c), Cauchy principal value (Hilbert transform)
D01ARF
1-D quadrature, non-adaptive, finite interval with provision for indefinite integrals
D01ASF
1-D quadrature, adaptive, semi-infinite interval, weight function cos(wx) or sin(wx)
D01ATF
1-D quadrature, adaptive, finite interval, variant of D01AJF efficient on vector machines
D01AUF
1-D quadrature, adaptive, finite interval, variant of D01AKF efficient on vector machines
D01BAF
1-D Gaussian quadrature
D01BBF
Pre-computed weights and abscissae for Gaussian quadrature rules, restricted choice of rule
D01BCF
Calculation of weights and abscissae for Gaussian quadrature rules, general choice of rule
D01BDF
1-D quadrature, non-adaptive, finite interval
D01DAF
2-D quadrature, finite region
D01EAF
Multi-dimensional adaptive quadrature over hyper-rectangle, multiple integrands
D01FBF
Multi-dimensional Gaussian quadrature over hyper-rectangle
D01FCF
Multi-dimensional adaptive quadrature over hyper-rectangle
D01FDF
Multi-dimensional quadrature, Sag-Szekeres method, general product region or n-sphere
D01GAF
1-D quadrature, integration of function defined by data values, Gill-Miller method
D01GBF
Multi-dimensional quadrature over hyper-rectangle, Monte Carlo method
D01GCF
Multi-dimensional quadrature, general product region, number-theoretic method
D01GDF
Multi-dimensional quadrature, general product region, number-theoretic method, variant of D01GCF efficient on vector machines
D01GYF
Korobov optimal coefficients for use in D01GCF or D01GDF, when number of points is prime
D01GZF
Korobov optimal coefficients for use in D01GCF or D01GDF, when number of points is product of two primes
D01JAF
Multi-dimensional quadrature over an n-sphere, allowing for badly-behaved integrands
D01PAF
Multi-dimensional quadrature over an n-simplex
D02AGF
ODEs, boundary value problem, shooting and matching technique, allowing interior matching point, general parameters to be determined
D02BGF
ODEs, IVP, Runge-Kutta-Merson method, until a component attains given value (simple driver)
D02BHF
ODEs, IVP, Runge-Kutta-Merson method, until function of solution is zero (simple driver)
D02CJF
ODEs, IVP, Adams method, until function of solution is zero, intermediate output (simple driver)
D02EJF
ODEs, stiff IVP, BDF method, until function of solution is zero, intermediate output (simple driver)
D02GAF
ODEs, boundary value problem, finite difference technique with deferred correction, simple nonlinear problem
D02GBF
ODEs, boundary value problem, finite difference technique with deferred correction, general linear problem
D02HAF
ODEs, boundary value problem, shooting and matching, boundary values to be determined
D02HBF
ODEs, boundary value problem, shooting and matching, general parameters to be determined
D02JAF
ODEs, boundary value problem, collocation and least-squares, single N-th order linear equation
D02JBF
ODEs, boundary value problem, collocation and least-squares, system of 1st order linear equations
D02KAF
2nd order Sturm-Liouville problem, regular system, finite range, eigenvalue only
D02KDF
2nd order Sturm-Liouville problem, regular/singular system, finite/infinite range, eigenvalue only, user-specified break-points
D02KEF
2nd order Sturm-Liouville problem, regular/singular system, finite/infinite range, eigenvalue and eigenfunction, user-specified break-points
D02LAF
2nd order ODEs, IVP, Runge-Kutta-Nystrom method
D02LXF
2nd order ODEs, IVP, set-up for D02LAF
D02LYF
2nd order ODEs, IVP, diagnostics for D02LAF
D02LZF
2nd order ODEs, IVP, interpolation for D02LAF
D02MVF
ODEs, IVP, DASSL method, set-up for D02M-N routines
D02MZF
ODEs, IVP, interpolation for D02M-N routines, natural interpolant
D02NBF
Explicit ODEs, stiff IVP, full Jacobian (comprehensive)
D02NCF
Explicit ODEs, stiff IVP, banded Jacobian (comprehensive)
D02NDF
Explicit ODEs, stiff IVP, sparse Jacobian (comprehensive)
D02NGF
Implicit/algebraic ODEs, stiff IVP, full Jacobian (comprehensive)
D02NHF
Implicit/algebraic ODEs, stiff IVP, banded Jacobian (comprehensive)
D02NJF
Implicit/algebraic ODEs, stiff IVP, sparse Jacobian (comprehensive)
D02NMF
Explicit ODEs, stiff IVP (reverse communication, comprehensive)
D02NNF
Implicit/algebraic ODEs, stiff IVP (reverse communication, comprehensive)
D02NRF
ODEs, IVP, for use with D02M-N routines, sparse Jacobian, enquiry routine
D02NSF
ODEs, IVP, for use with D02M-N routines, full Jacobian, linear algebra set-up
D02NTF
ODEs, IVP, for use with D02M-N routines, banded Jacobian, linear algebra set-up
D02NUF
ODEs, IVP, for use with D02M-N routines, sparse Jacobian, linear algebra set-up
D02NVF
ODEs, IVP, BDF method, set-up for D02M-N routines
D02NWF
ODEs, IVP, Blend method, set-up for D02M-N routines
D02NXF
ODEs, IVP, sparse Jacobian, linear algebra diagnostics, for use with D02M-N routines
D02NYF
ODEs, IVP, integrator diagnostics, for use with D02M-N routines
D02NZF
ODEs, IVP, set-up for continuation calls to integrator, for use with D02M-N routines,
D02PCF
ODEs, IVP, Runge-Kutta method, integration over range with output
D02PDF
ODEs, IVP, Runge-Kutta method, integration over one step
D02PVF
ODEs, IVP, set-up for D02PCF and D02PDF
D02PWF
ODEs, IVP, resets end of range for D02PDF
D02PXF
ODEs, IVP, interpolation for D02PDF
D02PYF
ODEs, IVP, integration diagnostics for D02PCF and D02PDF
D02PZF
ODEs, IVP, error assessment diagnostics for D02PCF and D02PDF
D02QFF
ODEs, IVP, Adams method with root-finding (forward communication, comprehensive)
D02QGF
ODEs, IVP, Adams method with root-finding (reverse communication, comprehensive)
D02QWF
ODEs, IVP, set-up for D02QFF and D02QGF
D02QXF
ODEs, IVP, diagnostics for D02QFF and D02QGF
D02QYF
ODEs, IVP, root-finding diagnostics for D02QFF and D02QGF
D02QZF
ODEs, IVP, interpolation for D02QFF or D02QGF
D02RAF
ODEs, general nonlinear boundary value problem, finite difference technique with deferred correction, continuation facility
D02SAF
ODEs, boundary value problem, shooting and matching technique, subject to extra algebraic equations, general parameters to be determined
D02TGF
N-th order linear ODEs, boundary value problem, collocation and least-squares
D02XJF
ODEs, IVP, interpolation for D02M-N routines, natural interpolant
D02XKF
ODEs, IVP, interpolation for D02M-N routines, C1 interpolant
D02ZAF
ODEs, IVP, weighted norm of local error estimate for D02M-N routines
D03EAF
Elliptic PDE, Laplace's equation, 2-D arbitrary domain
D03EBF
Elliptic PDE, solution of finite difference equations by SIP, five-point 2-D molecule, iterate to convergence
D03ECF
Elliptic PDE, solution of finite difference equations by SIP for seven-point 3-D molecule, iterate to convergence
D03EDF
Elliptic PDE, solution of finite difference equations by a multigrid technique
D03EEF
Discretize a 2nd order elliptic PDE on a rectangle
D03FAF
Elliptic PDE, Helmholtz equation, 3-D Cartesian co-ordinates
D03MAF
Triangulation of a plane region
D03PCF
General system of parabolic PDEs, method of lines, finite differences, one space variable
D03PDF
General system of parabolic PDEs, method of lines, Chebyshev C0 collocation, one space variable
D03PEF
General system of first order PDEs, method of lines, Keller box discretisation, one space variable
D03PHF
General system of parabolic PDEs, coupled DAEs, method of lines, finite differences, one space variable
D03PJF
General system of parabolic PDEs, coupled DAEs, method of lines, Chebyshev C0 collocation, one space variable
D03PKF
General system of first order PDEs, coupled DAEs, method of lines, Keller box discretisation, one space variable
D03PPF
General system of parabolic PDEs, coupled DAEs, method of lines, finite differences, remeshing, one space variable
D03PRF
General system of first order PDEs, coupled DAEs, method of lines, Keller box discretisation, remeshing, one space variable
D03PYF
PDEs, spatial interpolation with D03PDF or D03PJF
D03PZF
PDEs, spatial interpolation with D03PCF or D03PHF
D03UAF
Elliptic PDE, solution of finite difference equations by SIP, five-point 2-D molecule, one iteration
D03UBF
Elliptic PDE, solution of finite difference equations by SIP, seven-point 3-D molecule, one iteration
D04AAF
Numerical differentiation, derivatives up to order 14, function of one real variable
D05AAF
Linear non-singular Fredholm integral equation, 2nd kind, split kernel
D05ABF
Linear non-singular Fredholm integral equation, 2nd kind, smooth kernel
D05BAF
Nonlinear Volterra convolution equation, 2nd kind
D05BDF
Nonlinear convolution Volterra-Abel equation, 2nd kind, weakly singular
D05BEF
Nonlinear convolution Volterra-Abel equation, 1st kind, weakly singular
D05BWF
Generate weights for use in solving Volterra equations
D05BYF
Generate weights for use in solving weakly singular Abel type equations
E01AAF
Interpolated values, Aitken's technique, unequally spaced data, one variable
E01ABF
Interpolated values, Everett's formula, equally spaced data, one variable
E01AEF
Interpolating functions, polynomial interpolant, data may include derivative values, one variable
E01BAF
Interpolating functions, cubic spline interpolant, one variable
E01BEF
Interpolating functions, monotonicity-preserving, piecewise cubic Hermite, one variable
E01BFF
Interpolated values, interpolant computed by E01BEF, function only, one variable,
E01BGF
Interpolated values, interpolant computed by E01BEF, function and 1st derivative, one variable
E01BHF
Interpolated values, interpolant computed by E01BEF, definite integral, one variable
E01DAF
Interpolating functions, fitting bicubic spline, data on rectangular grid
E01RAF
Interpolating functions, rational interpolant, one variable
E01RBF
Interpolated values, evaluate rational interpolant computed by E01RAF, one variable
E01SAF
Interpolating functions, method of Renka and Cline, two variables
E01SBF
Interpolated values, evaluate interpolant computed by E01SAF, two variables
E01SEF
Interpolating functions, modified Shepard's method, two variables
E01SFF
Interpolated values, evaluate interpolant computed by E01SEF, two variables
E02ACF
Minimax curve fit by polynomials
E02ADF
Least-squares curve fit, by polynomials, arbitrary data points
E02AEF
Evaluation of fitted polynomial in one variable from Chebyshev series form (simplified parameter list)
E02AFF
Least-squares polynomial fit, special data points (including interpolation)
E02AGF
Least-squares polynomial fit, values and derivatives may be constrained, arbitrary data points,
E02AHF
Derivative of fitted polynomial in Chebyshev series form
E02AJF
Integral of fitted polynomial in Chebyshev series form
E02AKF
Evaluation of fitted polynomial in one variable, from Chebyshev series form
E02BAF
Least-squares curve cubic spline fit (including interpolation)
E02BBF
Evaluation of fitted cubic spline, function only
E02BCF
Evaluation of fitted cubic spline, function and derivatives
E02BDF
Evaluation of fitted cubic spline, definite integral
E02BEF
Least-squares cubic spline curve fit, automatic knot placement
E02CAF
Least-squares surface fit by polynomials, data on lines
E02CBF
Evaluation of fitted polynomial in two variables
E02DAF
Least-squares surface fit, bicubic splines
E02DCF
Least-squares surface fit by bicubic splines with automatic knot placement, data on rectangular grid
E02DDF
Least-squares surface fit by bicubic splines with automatic knot placement, scattered data
E02DEF
Evaluation of a fitted bicubic spline at a vector of points
E02DFF
Evaluation of a fitted bicubic spline at a mesh of points
E02GAF
L(1)-approximation by general linear function
E02GBF
L(1)-approximation by general linear function subject to linear inequality constraints
E02GCF
L(infinity)-approximation by general linear function
E02RAF
Pade-approximants
E02RBF
Evaluation of fitted rational function as computed by E02RAF
E02ZAF
Sort 2-D data into panels for fitting bicubic splines
E04ABF
Minimum, function of one variable using function values only
E04BBF
Minimum, function of one variable, using 1st derivative
E04CCF
Unconstrained minimum, simplex algorithm, function of several variables using function values only (comprehensive)
E04DGF
Unconstrained minimum, pre-conditioned conjugate gradient algorithm, function of several variables using 1st derivatives (comprehensive)
E04DJF
Read optional parameter values for E04DGF from external file
E04DKF
Supply optional parameter values to E04DGF
E04FCF
Unconstrained minimum of a sum of squares, combined Gauss-Newton and modified Newton algorithm using function values only (comprehensive)
E04FDF
Unconstrained minimum of a sum of squares, combined Gauss-Newton and modified Newton algorithm using function values only (easy-to-use)
E04GBF
Unconstrained minimum of a sum of squares, combined Gauss-Newton and quasi-Newton algorithm using 1st derivatives (comprehensive)
E04GCF
Unconstrained minimum of a sum of squares, combined Gauss-Newton and quasi-Newton algorithm, using 1st derivatives (easy-to-use)
E04GDF
Unconstrained minimum of a sum of squares, combined Gauss-Newton and modified Newton algorithm using 1st derivatives (comprehensive)
E04GEF
Unconstrained minimum of a sum of squares, combined Gauss-Newton and modified Newton algorithm using 1st derivatives (easy-to-use)
E04HCF
Check user's routine for calculating 1st derivatives of function
E04HDF
Check user's routine for calculating 2nd derivatives of function
E04HEF
Unconstrained minimum of a sum of squares, combined Gauss-Newton and modified Newton algorithm, using 2nd derivatives (comprehensive)
E04HFF
Unconstrained minimum of a sum of squares, combined Gauss-Newton and modified Newton algorithm, using 2nd derivatives (easy-to-use)
E04JAF
Minimum, function of several variables, quasi-Newton algorithm, simple bounds, using function values only (easy-to-use)
E04KAF
Minimum, function of several variables, quasi-Newton algorithm, simple bounds, using 1st derivatives (easy-to-use)
E04KCF
Minimum, function of several variables, modified Newton algorithm, simple bounds, using 1st derivatives (easy-to-use)
E04KDF
Minimum, function of several variables, modified Newton algorithm, simple bounds, using 1st derivatives (comprehensive)
E04LAF
Minimum, function of several variables, modified Newton algorithm, simple bounds, using 1st and 2nd derivatives (easy-to-use)
E04LBF
Minimum, function of several variables, modified Newton algorithm, simple bounds, using 1st and 2nd derivatives (comprehensive)
E04MFF
LP problem
E04MGF
Read optional parameter values for E04MFF from external file
E04MHF
Supply optional parameter values to E04MFF
E04NCF
Convex QP problem or linearly-constrained linear least-squares problem
E04NDF
Read optional parameter values for E04NCF from external file
E04NEF
Supply optional parameter values to E04NCF
E04NFF
QP problem
E04NGF
Read optional parameter values for E04NFF from external file
E04NHF
Supply optional parameter values to E04NFF
E04UCF
Minimum, function of several variables, sequential QP method, nonlinear constraints, using function values and optionally 1st derivatives (comprehensive)
E04UDF
Read optional parameter values for E04UCF from external file
E04UEF
Supply optional parameter values to E04UCF
E04UPF
Minimum of a sum of squares, nonlinear constraints, sequential QP method, using function values and optionally 1st derivatives
E04UQF
Read optional parameter values for E04UPF from external file
E04URF
Supply optional parameter values to E04UPF
E04XAF
Estimate (using numerical differentiation) gradient and/or Hessian of a function
E04YAF
Check user's routine for calculating Jacobian of 1st derivatives
E04YBF
Check user's routine for calculating Hessian of a sum of squares
E04YCF
Covariance matrix for nonlinear least-squares problem
E04ZCF
Check user's routines for calculating 1st derivatives of function and constraints
F01ABF
Inverse of real symmetric positive-definite matrix using iterative refinement (simplified parameter list)
F01ADF
Inverse of real symmetric positive-definite matrix
F01BLF
Pseudo-inverse and rank of a real mxn matrix (m>=n)
F01BRF
LU factorization of real sparse matrix
F01BSF
LU factorization of real sparse matrix with known sparsity pattern
F01BUF
ULDL*U* factorization of real symmetric positive-definite band matrix
F01BVF
Reduction to standard form, generalized real symmetric-definite banded eigenproblem
F01CKF
Matrix multiplication
F01CRF
Matrix transposition
F01CTF
Sum or difference of two real matrices, optional scaling and transposition
F01CWF
Sum or difference of two complex matrices, optional scaling and transposition
F01LEF
LU factorization of real tridiagonal matrix
F01LHF
LU factorization of real almost block diagonal matrix
F01MAF
LL* factorization of real sparse symmetric positive-definite matrix
F01MCF
LDL* factorization of real symmetric positive-definite variable-bandwidth matrix
F01QGF
RQ factorization of real m by n upper trapezoidal matrix (m<=n)
F01QJF
RQ factorization of real m by n matrix (m<=n)
F01QKF
Operations with orthogonal matrices, form rows of Q, after RQ factorization by F01QJF
F01RGF
RQ factorization of complex m by n upper trapezoidal matrix (m<=n)
F01RJF
RQ factorization of complex m by n matrix (m<=n)
F01RKF
Operations with unitary matrices, form rows of Q, after RQ factorization by F01RJF
F01ZAF
Convert real matrix between packed triangular and square storage schemes
F01ZBF
Convert complex matrix between packed triangular and square storage schemes
F01ZCF
Convert real matrix between packed banded and rectangular storage schemes
F01ZDF
Convert complex matrix between packed banded and rectangular storage schemes
F02BBF
Selected eigenvalues and eigenvectors of real symmetric matrix (Black box)
F02BCF
Selected eigenvalues and eigenvectors of real matrix (Black box)
F02BDF
Selected eigenvalues and eigenvectors of complex matrix (Black box)
F02BJF
All eigenvalues and optionally eigenvectors of generalized eigenproblem by QZ algorithm, real matrices (Black box)
F02EAF
All eigenvalues and Schur factorization of real general matrix (Black Box)
F02EBF
All eigenvalues and eigenvectors of real general matrix (Black Box)
F02FAF
All eigenvalues and eigenvectors of real symmetric matrix (Black Box)
F02FDF
All eigenvalues and eigenvectors of real symmetric-definite generalized problem (Black Box)
F02FHF
All eigenvalues of generalized banded real symmetric-definite eigenproblem (Black box)
F02FJF
Selected eigenvalues and eigenvectors of sparse symmetric eigenproblem (Black box)
F02GAF
All eigenvalues and Schur factorization of complex general matrix (Black Box)
F02GBF
All eigenvalues and eigenvectors of complex general matrix (Black Box)
F02GJF
All eigenvalues and optionally eigenvectors of generalized complex eigenproblem by QZ algorithm (Black box)
F02HAF
All eigenvalues and eigenvectors of complex Hermitian matrix (Black Box)
F02HDF
All eigenvalues and eigenvectors of complex Hermitian-definite generalized problem (Black Box)
F02SDF
Eigenvector of generalized real banded eigenproblem by inverse iteration
F02WDF
QR factorization, possibly followed by SVD
F02WEF
SVD of real matrix (Black Box)
F02WUF
SVD of a real upper triangular matrix (Black Box)
F02XEF
SVD of complex matrix (Black Box)
F02XUF
SVD of complex upper triangular matrix (Black Box)
F03AAF
Determinant of real matrix (Black Box)
F03ABF
Determinant of real symmetric positive-definite matrix (Black Box)
F03ACF
Determinant of real symmetric positive-definite band matrix (Black Box)
F03ADF
Determinant of complex matrix (Black Box)
F03AEF
LL* factorization and determinant of real symmetric positive-definite matrix
F03AFF
LU factorization and determinant of real matrix
F04AAF
Solution of real simultaneous linear equations with multiple right-hand sides (Black Box)
F04ABF
Solution of real symmetric positive-definite simultaneous linear equations with multiple right-hand sides using iterative refinement (Black Box)
F04ACF
Solution of real symmetric positive-definite banded simultaneous linear equations with multiple right-hand sides (Black Box)
F04ADF
Solution of complex simultaneous linear equations with multiple right-hand sides (Black Box)
F04AEF
Solution of real simultaneous linear equations with multiple right-hand sides using iterative refinement (Black Box)
F04AFF
Solution of real symmetric positive-definite simultaneous linear equations using iterative refinement (coefficient matrix already factorized by F03AEF)
F04AGF
Solution of real symmetric positive-definite simultaneous linear equations (coefficient matrix already factorized by F03AEF)
F04AHF
Solution of real simultaneous linear equations using iterative refinement (coefficient matrix already factorized by F03AFF)
F04AJF
Solution of real simultaneous linear equations (coefficient matrix already factorized by F03AFF)
F04AMF
Least-squares solution of m real equations in n unknowns, rank= n, m>=n using iterative refinement (Black Box)
F04ARF
Solution of real simultaneous linear equations, one right-hand side (Black Box)
F04ASF
Solution of real symmetric positive-definite simultaneous linear equations, one right-hand side using iterative refinement (Black Box)
F04ATF
Solution of real simultaneous linear equations, one right-hand side using iterative refinement (Black Box)
F04AXF
Solution of real sparse simultaneous linear equations (coefficient matrix already factorized)
F04EAF
Solution of real tridiagonal simultaneous linear equations, one right-hand side (Black Box)
F04FAF
Solution of real symmetric positive-definite tridiagonal simultaneous linear equations, one right-hand side (Black Box)
F04FEF
Solution of the Yule-Walker equations for a real symmetric positive-definite Toeplitz matrix, one right-hand side
F04FFF
Solution of real symmetric positive-definite Toeplitz system, one right-hand side
F04JAF
Minimal least-squares solution of m real equations in n unknowns, rank<= n, m>=n
F04JDF
Minimal least-squares solution of m real equations in n unknowns, rank<= n, m<=n
F04JGF
Least-squares (if rank=n) or minimal least-squares (if rank=n
F04LEF
Solution of real tridiagonal simultaneous linear equations (coefficient matrix already factorized by F01LEF)
F04LHF
Solution of real almost block diagonal simultaneous linear equations (coefficient matrix already factorized by F01LHF)
F04MAF
Real sparse symmetric positive-definite simultaneous linear equations (coefficient matrix already factorized by F01MAF)
F04MBF
Real sparse symmetric simultaneous linear equations
F04MCF
Solution of real symmetric positive-definite variable-bandwidth simultaneous linear equations (coefficient matrix already factorized by F01MCF)
F04MEF
Update solution of the Yule-Walker equations for a real symmetric positive-definite Toeplitz matrix
F04MFF
Update solution of real symmetric positive-definite Toeplitz system
F04QAF
Sparse linear least-squares problem, m real equations in n unknowns
F04YAF
Covariance matrix for linear least-squares problems, m real equations in n unknowns
F04YCF
Norm estimation (for use in condition estimation), real matrix
F04ZCF
Norm estimation (for use in condition estimation), complex matrix
F05AAF
Gram-Schmidt orthogonalisation of n vectors of order m
F06AAF
Generate real plane rotation (SROTG/DROTG)
F06BAF
Generate real plane rotation, storing tangent
F06BCF
Recover cosine and sine from given real tangent
F06BEF
Generate real Jacobi plane rotation
F06BHF
Apply real similarity rotation to 2 by 2 symmetric matrix
F06BLF
Compute quotient of two real scalars, with overflow flag
F06BMF
Compute Euclidean norm from scaled form
F06BNF
Compute square root of (a*a + b*b), real a and b
F06BPF
Compute eigenvalue of 2 by 2 real symmetric matrix
F06CAF
Generate complex plane rotation, storing tangent, real cosine
F06CBF
Generate complex plane rotation, storing tangent, real sine
F06CCF
Recover cosine and sine from given complex tangent, real cosine
F06CDF
Recover cosine and sine from given complex tangent, real sine
F06CHF
Apply complex similarity rotation to 2 by 2 Hermitian matrix
F06CLF
Compute quotient of two complex scalars, with overflow flag
F06DBF
Broadcast scalar into integer vector
F06DFF
Copy integer vector
F06EAF
Dot product of two real vectors (SDOT/DDOT)
F06ECF
Add scalar times real vector to real vector (SAXPY/DAXPY)
F06EDF
Multiply real vector by scalar (SSCAL/DSCAL)
F06EFF
Copy real vector (SCOPY/DCOPY)
F06EGF
Swap two real vectors (SSWAP/DSWAP)
F06EJF
Compute Euclidean norm of real vector (SNRM2/DNRM2)
F06EKF
Sum the absolute values of real vector elements (SASUM/DASUM)
F06EPF
Apply real plane rotation (SROT/DROT)
F06ERF
Dot product of two real sparse vectors (SDOTI/DDOTI)
F06ETF
Add a scalar times a real sparse vector to another real sparse vector (SAXPYI/DAXPYI)
F06EUF
Gather a real sparse vector (SGTHR/DGTHR)
F06EVF
Gather and set to zero a real sparse vector (SGTHRZ/DGTHRZ)
F06EWF
Scatter a real sparse vector (SSCTR/DSCTR)
F06EXF
Apply plane rotation to two real sparse vectors (SROTI/DROTI)
F06FAF
Compute cosine of angle between two real vectors
F06FBF
Broadcast scalar into real vector
F06FCF
Multiply real vector by diagonal matrix
F06FDF
Multiply real vector by scalar, preserving input vector
F06FGF
Negate real vector
F06FJF
Update Euclidean norm of real vector in scaled form
F06FKF
Compute weighted Euclidean norm of real vector
F06FLF
Elements of real vector with largest and smallest absolute value
F06FPF
Apply real symmetric plane rotation to two vectors
F06FQF
Generate sequence of real plane rotations
F06FRF
Generate real elementary reflection, NAG style
F06FSF
Generate real elementary reflection, LINPACK style
F06FTF
Apply real elementary reflection, NAG style
F06FUF
Apply real elementary reflection, LINPACK style
F06GAF
Dot product of two complex vectors, unconjugated (CDOTU/ZDOTU)
F06GBF
Dot product of two complex vectors, conjugated (CDOTC/ZDOTC)
F06GCF
Add scalar times complex vector to complex vector (CAXPY/ZAXPY)
F06GDF
Multiply complex vector by complex scalar (CSCAL/ZSCAL)
F06GFF
Copy complex vector (CCOPY/ZCOPY)
F06GGF
Swap two complex vectors (CSWAP/ZSWAP)
F06GRF
Dot product of two complex sparse vector, unconjugated (CDOTUI/ZDOTUI)
F06GSF
Dot product of two complex sparse vector, conjugated (CDOTCI/ZDOTCI)
F06GTF
Add a scalar times a complex sparse vector to another complex sparse vector (CAXPYI/ZAXPYI)
F06GUF
Gather a complex sparse vector (CGTHR/ZGTHR)
F06GVF
Gather and set to zero a complex sparse vector (CGTHRZ/ZGTHRZ)
F06GWF
Scatter a complex sparse vector (CSCTR/ZSCTR)
F06HBF
Broadcast scalar into complex vector
F06HCF
Multiply complex vector by complex diagonal matrix
F06HDF
Multiply complex vector by complex scalar, preserving input vector
F06HGF
Negate complex vector
F06HPF
Apply complex plane rotation
F06HQF
Generate sequence of complex plane rotations
F06HRF
Generate complex elementary reflection
F06HTF
Apply complex elementary reflection
F06JDF
Multiply complex vector by real scalar (CSSCAL/ZDSCAL)
F06JJF
Compute Euclidean norm of complex vector (SCNRM2/DZNRM2)
F06JKF
Sum the absolute values of complex vector elements (SCASUM/DZASUM)
F06JLF
Index, real vector element with largest absolute value (ISAMAX/IDAMAX)
F06JMF
Index, complex vector element with largest absolute value (ICAMAX/IZAMAX)
F06KCF
Multiply complex vector by real diagonal matrix
F06KDF
Multiply complex vector by real scalar, preserving input vector
F06KFF
Copy real vector to complex vector
F06KJF
Update Euclidean norm of complex vector in scaled form
F06KLF
Last non-negligible element of real vector
F06KPF
Apply real plane rotation to two complex vectors
F06PAF
Matrix-vector product, real rectangular matrix (SGEMV/DGEMV)
F06PBF
Matrix-vector product, real rectangular band matrix (SGBMV/DGBMV)
F06PCF
Matrix-vector product, real symmetric matrix (SSYMV/DSYMV)
F06PDF
Matrix-vector product, real symmetric band matrix (SSBMV/DSBMV)
F06PEF
Matrix-vector product, real symmetric packed matrix (SSPMV/DSPMV)
F06PFF
Matrix-vector product, real triangular matrix (STRMV/DTRMV)
F06PGF
Matrix-vector product, real triangular band matrix (STBMV/DTBMV)
F06PHF
Matrix-vector product, real triangular packed matrix (STPMV/DTPMV)
F06PJF
System of equations, real triangular matrix (STRSV/DTRSV)
F06PKF
System of equations, real triangular band matrix (STBSV/DTBSV)
F06PLF
System of equations, real triangular packed matrix (STPSV/DTPSV)
F06PMF
Rank-1 update, real rectangular matrix (SGER/DGER)
F06PPF
Rank-1 update, real symmetric matrix (SSYR/DSYR)
F06PQF
Rank-1 update, real symmetric packed matrix (SSPR/DSPR)
F06PRF
Rank-2 update, real symmetric matrix (SSYR2/DSYR2)
F06PSF
Rank-2 update, real symmetric packed matrix (SSPR2/DSPR2)
F06QFF
Matrix copy, real rectangular or trapezoidal matrix
F06QHF
Matrix initialisation, real rectangular matrix
F06QJF
Permute rows or columns, real rectangular matrix, permutations represented by an integer array
F06QKF
Permute rows or columns, real rectangular matrix, permutations represented by a real array
F06QMF
Orthogonal similarity transformation of a real symmetric matrix as a sequence of plane rotations
F06QPF
QR factorization by sequence of plane rotations, rank-1 update of real upper triangular matrix
F06QQF
QR factorization by sequence of plane rotations, real upper triangular matrix augmented by a full row
F06QRF
QR or RQ factorization by sequence of plane rotations, real upper Hessenberg matrix
F06QSF
QR or RQ factorization by sequence of plane rotations, real upper spiked matrix
F06QTF
QR factorization of UZ or RQ factorization of ZU, U real upper triangular, Z a sequence of plane rotations
F06QVF
Compute upper Hessenberg matrix by sequence of plane rotations, real upper triangular matrix
F06QWF
Compute upper spiked matrix by sequence of plane rotations, real upper triangular matrix
F06QXF
Apply sequence of plane rotations, real rectangular matrix
F06RAF
1-norm, infinity-norm, Frobenius norm, largest absolute element, real general matrix
F06RBF
1-norm, infinity-norm, Frobenius norm, largest absolute element, real band matrix
F06RCF
1-norm, infinity-norm, Frobenius norm, largest absolute element, real symmetric matrix
F06RDF
1-norm, infinity-norm, Frobenius norm, largest absolute element, real symmetric matrix, packed storage
F06REF
1-norm, infinity-norm, Frobenius norm, largest absolute element, real symmetric band matrix
F06RJF
1-norm, infinity-norm, Frobenius norm, largest absolute element, real trapezoidal/triangular matrix
F06RKF
1-norm, infinity-norm, Frobenius norm, largest absolute element, real triangular matrix, packed storage
F06RLF
1-norm, infinity-norm, Frobenius norm, largest absolute element, real triangular band matrix
F06RMF
1-norm, infinity-norm, Frobenius norm, largest absolute element, real Hessenberg matrix
F06SAF
Matrix-vector product, complex rectangular matrix (CGEMV/ZGEMV)
F06SBF
Matrix-vector product, complex rectangular band matrix (CGBMV/ZGBMV)
F06SCF
Matrix-vector product, complex Hermitian matrix (CHEMV/ZHEMV)
F06SDF
Matrix-vector product, complex Hermitian band matrix (CHBMV/ZHBMV)
F06SEF
Matrix-vector product, complex Hermitian packed matrix (CHPMV/ZHPMV)
F06SFF
Matrix-vector product, complex triangular matrix (CTRMV/ZTRMV)
F06SGF
Matrix-vector product, complex triangular band matrix (CTBMV/ZTBMV)
F06SHF
Matrix-vector product, complex triangular packed matrix (CTPMV/ZTPMV)
F06SJF
System of equations, complex triangular matrix (CTRSV/ZTRSV)
F06SKF
System of equations, complex triangular band matrix (CTBSV/ZTBSV)
F06SLF
System of equations, complex triangular packed matrix (CTPSV/ZTPSV)
F06SMF
Rank-1 update, complex rectangular matrix, unconjugated vector (CGERU/ZGERU)
F06SNF
Rank-1 update, complex rectangular matrix, conjugated vector (CGERC/ZGERC)
F06SPF
Rank-1 update, complex Hermitian matrix (CHER/ZHER)
F06SQF
Rank-1 update, complex Hermitian packed matrix (CHPR/ZHPR)
F06SRF
Rank-2 update, complex Hermitian matrix (CHER2/ZHER2)
F06SSF
Rank-2 update, complex Hermitian packed matrix (CHPR2/ZHPR2)
F06TFF
Matrix copy, complex rectangular or trapezoidal matrix
F06THF
Matrix initialisation, complex rectangular matrix
F06TMF
Unitary similarity transformation of a Hermitian matrix as a sequence of plane rotations
F06TPF
QR factorization by sequence of plane rotations, rank-1 update of complex upper triangular matrix
F06TQF
QR factorization by sequence of plane rotations, complex upper triangular matrix augmented by a full row
F06TRF
QR or RQ factorization by sequence of plane rotations, complex upper Hessenberg matrix
F06TSF
QR or RQ factorization by sequence of plane rotations, complex upper spiked matrix
F06TTF
QR factorization of UZ or RQ factorization of ZU, U complex upper triangular, Z a sequence of plane rotations
F06TVF
Compute upper Hessenberg matrix by sequence of plane rotations, complex upper triangular matrix
F06TWF
Compute upper spiked matrix by sequence of plane rotations, complex upper triangular matrix
F06TXF
Apply sequence of plane rotations, complex rectangular matrix, real cosine and complex sine
F06TYF
Apply sequence of plane rotations, complex rectangular matrix, complex cosine and real sine
F06UAF
1-norm, infinity-norm, Frobenius norm, largest absolute element, complex general matrix
F06UBF
1-norm, infinity-norm, Frobenius norm, largest absolute element, complex band matrix
F06UCF
1-norm, infinity-norm, Frobenius norm, largest absolute element, complex Hermitian matrix
F06UDF
1-norm, infinity-norm, Frobenius norm, largest absolute element, complex Hermitian matrix, packed storage
F06UEF
1-norm, infinity-norm, Frobenius norm, largest absolute element, complex Hermitian band matrix
F06UFF
1-norm, infinity-norm, Frobenius norm, largest absolute element, complex symmetric matrix
F06UGF
1-norm, infinity-norm, Frobenius norm, largest absolute element, complex symmetric matrix, packed storage
F06UHF
1-norm, infinity-norm, Frobenius norm, largest absolute element, complex symmetric band matrix
F06UJF
1-norm, infinity-norm, Frobenius norm, largest absolute element, complex trapezoidal/triangular matrix
F06UKF
1-norm, infinity-norm, Frobenius norm, largest absolute element, complex triangular matrix, packed storage
F06ULF
1-norm, infinity-norm, Frobenius norm, largest absolute element, complex triangular band matrix
F06UMF
1-norm, infinity-norm, Frobenius norm, largest absolute element, complex Hessenberg matrix
F06VJF
Permute rows or columns, complex rectangular matrix, permutations represented by an integer array
F06VKF
Permute rows or columns, complex rectangular matrix, permutations represented by a real array
F06VXF
Apply sequence of plane rotations, complex rectangular matrix, real cosine and sine
F06YAF
Matrix-matrix product, two real rectangular matrices (SGEMM/DGEMM)
F06YCF
Matrix-matrix product, one real symmetric matrix, one real rectangular matrix (SSYMM/DSYMM)
F06YFF
Matrix-matrix product, one real triangular matrix, one real rectangular matrix (STRMM/DTRMM)
F06YJF
Solves a system of equations with multiple right-hand sides, real triangular coefficient matrix (STRSM/DTRSM)
F06YPF
Rank-k update of a real symmetric matrix (SSYRK/DSYRK)
F06YRF
Rank-2k update of a real symmetric matrix (SSYR2K/DSYR2K)
F06ZAF
Matrix-matrix product, two complex rectangular matrices (CGEMM/ZGEMM)
F06ZCF
Matrix-matrix product, one complex Hermitian matrix, one complex rectangular matrix (CHEMM/ZHEMM)
F06ZFF
Matrix-matrix product, one complex triangular matrix, one complex rectangular matrix (CTRMM/ZTRMM)
F06ZJF
Solves system of equations with multiple right-hand sides, complex triangular coefficient matrix (CTRSM/ZTRSM)
F06ZPF
Rank-k update of a complex Hermitian matrix (CHERK/ZHERK)
F06ZRF
Rank-2k update of a complex Hermitian matrix (CHER2K/ZHER2K)
F06ZTF
Matrix-matrix product, one complex symmetric matrix, one complex rectangular matrix (CSYMM/ZSYMM)
F06ZUF
Rank-k update of a complex symmetric matrix (CSYRK/ZSYRK)
F06ZWF
Rank-2k update of a complex symmetric matrix (CSYR2K/ZHER2K)
F07ADF
LU factorization of real m by n matrix (SGETRF/DGETRF)
F07AEF
Solution of real system of linear equations, multiple right-hand sides, matrix already factorized by F07ADF (SGETRS/DGETRS)
F07AGF
Estimate condition number of real matrix, matrix already factorized by F07ADF (SGECON/DGECON)
F07AHF
Refined solution with error bounds of real system of linear equations, multiple right-hand sides (SGERFS/DGERFS)
F07AJF
Inverse of a real matrix, matrix already factorized by F07ADF (SGETRI/DGETRI)
F07ARF
LU factorization of complex m by n matrix (CGETRF/ZGETRF)
F07ASF
Solution of complex system of linear equations, multiple right-hand sides, matrix already factorized by F07ARF (CGETRS/ZGETRS)
F07AUF
Estimate condition number of complex matrix, matrix already factorized by F07ARF (CGECON/ZGECON)
F07AVF
Refined solution with error bounds of complex system of linear equations, multiple right-hand sides (CGERFS/ZGERFS)
F07AWF
Inverse of a complex matrix, matrix already factorized by F07ARF (CGETRI/ZGETRI)
F07BDF
LU factorization of real m by n band matrix (SGBTRF/DGBTRF)
F07BEF
Solution of real band system of linear equations, multiple right-hand sides, matrix already factorized by F07BDF (SGBTRS/DGBTRS)
F07BGF
Estimate condition number of real band matrix, matrix already factorized by F07BDF (SGBCON/DGBCON)
F07BHF
Refined solution with error bounds of real band system of linear equations, multiple right-hand sides (SGBRFS/DGBRFS)
F07BRF
LU factorization of complex m by n band matrix (CGBTRF/ZGBTRF)
F07BSF
Solution of complex band system of linear equations, multiple right-hand sides, matrix already factorized by F07BRF (CGBTRS/ZGBTRS)
F07BUF
Estimate condition number of complex band matrix, matrix already factorized by F07BRF (CGBCON/ZGBCON)
F07BVF
Refined solution with error bounds of complex band system of linear equations, multiple right-hand sides (CGBRFS/ZGBRFS)
F07FDF
Cholesky factorization of real symmetric positive-definite matrix (SPOTRF/DPOTRF)
F07FEF
Solution of real symmetric positive-definite system of linear equations, multiple right-hand sides, matrix already factorized by F07FDF (SPOTRS/DPOTRS)
F07FGF
Estimate condition number of real symmetric positive-definite matrix, matrix already factorized by F07FDF (SPOCON/DPOCON)
F07FHF
Refined solution with error bounds of real symmetric positive-definite system of linear equations, multiple right-hand sides (SPORFS/DPORFS)
F07FJF
Inverse of a real symmetric positive-definite matrix, matrix already factorized by F07FDF (SPOTRI/DPOTRI)
F07FRF
Cholesky factorization of complex Hermitian positive-definite matrix (CPOTRF/ZPOTRF)
F07FSF
Solution of complex Hermitian positive-definite system of linear equations, multiple right-hand sides, matrix already factorized by F07FRF (CPOTRS/ZPOTRS)
F07FUF
Estimate condition number of complex Hermitian positive-definite matrix, matrix already factorized by F07FRF (CPOCON/ZPOCON)
F07FVF
Refined solution with error bounds of complex Hermitian positive-definite system of linear equations, multiple right-hand sides (CPORFS/ZPORFS)
F07FWF
Inverse of a complex Hermitian positive-definite matrix, matrix already factorized by F07FRF (CPOTRI/ZPOTRI)
F07GDF
Cholesky factorization of a real symmetric positive-definite matrix, packed storage (SPPTRF/DPPTRF)
F07GEF
Solution of real symmetric positive-definite system of linear equations, multiple right-hand sides, matrix already factorized by F07GDF, packed storage (SPPTRS/DPPTRS)
F07GGF
Estimate condition number of real symmetric positive-definite matrix, matrix already factorized by F07GDF, packed storage (SPPCON/DPPCON)
F07GHF
Refined solution with error bounds of real symmetric positive-definite system of linear equations, multiple right-hand sides, packed storage (SPPRFS/DPPRFS)
F07GJF
Inverse of a real symmetric positive-definite matrix, matrix already factorized by F07GDF, packed storage (SPPTRI/DPPTRI)
F07GRF
Cholesky factorization of complex Hermitian positive-definite matrix, packed storage (CPPTRF/ZPPTRF)
F07GSF
Solution of complex Hermitian positive-definite system of linear equations, multiple right-hand sides, matrix already factorized by F07GRF, packed storage (CPPTRS/ZPPTRS)
F07GUF
Estimate condition number of complex Hermitian positive-definite matrix, matrix already factorized by F07GRF, packed storage (CPPCON/ZPPCON)
F07GVF
Refined solution with error bounds of complex Hermitian positive-definite system of linear equations, multiple right-hand sides, packed storage (CPPRFS/ZPPRFS)
F07GWF
Inverse of a complex Hermitian positive-definite matrix, matrix already factorized by F07GRF, packed storage (CPPTRI/ZPPTRI)
F07HDF
Cholesky factorization of real symmetric positive-definite band matrix (SPBTRF/DPBTRF)
F07HEF
Solution of real symmetric positive-definite band system of linear equations, multiple right-hand sides, matrix already factorized by F07HDF (SPBTRS/DPBTRS)
F07HGF
Estimate condition number of real symmetric positive-definite band matrix, matrix already factorized by F07HDF (SPBCON/DPBCON)
F07HHF
Refined solution with error bounds of real symmetric positive-definite band system of linear equations, multiple right-hand sides (SPBRFS/DPBRFS)
F07HRF
Cholesky factorization of complex Hermitian positive-definite band matrix (CPBTRF/ZPBTRF)
F07HSF
Solution of complex Hermitian positive-definite band system of linear equations, multiple right-hand sides, matrix already factorized by F07HRF (CPBTRS/ZPBTRS)
F07HUF
Estimate condition number of complex Hermitian positive-definite band matrix, matrix already factorized by F07HRF (CPBCON/ZPBCON)
F07HVF
Refined solution with error bounds of complex Hermitian positive-definite band system of linear equations, multiple right-hand sides (CPBRFS/ZPBRFS)
F07MDF
Bunch-Kaufman factorization of real symmetric indefinite matrix (SSYTRF/DSYTRF)
F07MEF
Solution of real symmetric indefinite system of linear equations, multiple right-hand sides, matrix already factorized by F07MDF (SSYTRS/DSYTRS)
F07MGF
Estimate condition number of real symmetric indefinite matrix, matrix already factorized by F07MDF (SSYCON/DSYCON)
F07MHF
Refined solution with error bounds of real symmetric indefinite system of linear equations, multiple right-hand sides (SSYRFS/DSYRFS)
F07MJF
Inverse of a real symmetric indefinite matrix, matrix already factorized by F07MDF (SSYTRI/DSYTRI)
F07MRF
Bunch-Kaufman factorization of complex Hermitian indefinite matrix (CHETRF/ZHETRF)
F07MSF
Solution of complex Hermitian indefinite system of linear equations, multiple right-hand sides, matrix already factorized by F07MRF (CHETRS/ZHETRS)
F07MUF
Estimate condition number of complex Hermitian indefinite matrix, matrix already factorized by F07MRF (CHECON/ZHECON)
F07MVF
Refined solution with error bounds of complex Hermitian indefinite system of linear equations, multiple right-hand sides (CHERFS/ZHERFS)
F07MWF
Inverse of a complex Hermitian indefinite matrix, matrix already factorized by F07MRF (CHETRI/ZHETRI)
F07NRF
Bunch-Kaufman factorization of complex symmetric matrix (CSYTRF/ZSYTRF)
F07NSF
Solution of complex symmetric system of linear equations, multiple right-hand sides, matrix already factorized by F07NRF (CSYTRS/ZSYTRS)
F07NUF
Estimate condition number of complex symmetric matrix, matrix already factorized by F07NRF (CSYCON/ZSYCON)
F07NVF
Refined solution with error bounds of complex symmetric system of linear equations, multiple right-hand sides (CSYRFS/ZSYRFS)
F07NWF
Inverse of a complex symmetric matrix, matrix already factorized by F07NRF (CSYTRI/ZSYTRI)
F07PDF
Bunch-Kaufman factorization of real symmetric indefinite matrix, packed storage (SSPTRF/DSPTRF)
F07PEF
Solution of real symmetric indefinite system of linear equations, multiple right-hand sides, matrix already factorized by F07PDF, packed storage (SSPTRS/DSPTRS)
F07PGF
Estimate condition number of real symmetric indefinite matrix, matrix already factorized by F07PDF, packed storage (SSPCON/DSPCON)
F07PHF
Refined solution with error bounds of real symmetric indefinite system of linear equations, multiple right-hand sides, packed storage (SSPRFS/DSPRFS)
F07PJF
Inverse of a real symmetric indefinite matrix, matrix already factorized by F07PDF, packed storage (SSPTRI/DSPTRI)
F07PRF
Bunch-Kaufman factorization of complex Hermitian indefinite matrix, packed storage (CHPTRF/ZHPTRF)
F07PSF
Solution of complex Hermitian indefinite system of linear equations, multiple right-hand sides, matrix already factorized by F07PRF, packed storage (CHPTRS/ZHPTRS)
F07PUF
Estimate condition number of complex Hermitian indefinite matrix, matrix already factorized by F07PRF, packed storage (CHPCON/ZHPCON)
F07PVF
Refined solution with error bounds of complex Hermitian indefinite system of linear equations, multiple right-hand sides, packed storage (CHPRFS/ZHPRFS)
F07PWF
Inverse of a complex Hermitian indefinite matrix, matrix already factorized by F07PRF, packed storage (CHPTRI/ZHPTRI)
F07QRF
Bunch-Kaufman factorization of complex symmetric matrix, packed storage (CSPTRF/ZSPTRF)
F07QSF
Solution of complex symmetric system of linear equations, multiple right-hand sides, matrix already factorized by F07QRF, packed storage (CSPTRS/ZSPTRS)
F07QUF
Estimate condition number of complex symmetric matrix, matrix already factorized by F07QRF, packed storage (CSPCON/ZSPCON)
F07QVF
Refined solution with error bounds of complex symmetric system of linear equations, multiple right-hand sides, packed storage (CSPRFS/ZSPRFS)
F07QWF
Inverse of a complex symmetric matrix, matrix already factorized by F07QRF, packed storage (CSPTRI/ZSPTRI)
F07TEF
Solution of real triangular system of linear equations, multiple right-hand sides (STRTRS/DTRTRS)
F07TGF
Estimate condition number of real triangular matrix (STRCON/DTRCON)
F07THF
Error bounds for solution of real triangular system of linear equations, multiple right-hand sides (STRRFS/DTRRFS)
F07TJF
Inverse of a real triangular matrix (STRTRI/DTRTRI)
F07TSF
Solution of complex triangular system of linear equations, multiple right-hand sides (CTRTRS/ZTRTRS)
F07TUF
Estimate condition number of complex triangular matrix (CTRCON/ZTRCON)
F07TVF
Error bounds for solution of complex triangular system of linear equations, multiple right-hand sides (CTRRFS/ZTRRFS)
F07TWF
Inverse of a complex triangular matrix (CTRTRI/ZTRTRI)
F07UEF
Solution of real triangular system of linear equations, multiple right-hand sides, packed storage (STPTRS/DTPTRS)
F07UGF
Estimate condition number of real triangular matrix, packed storage (STPCON/DTPCON)
F07UHF
Error bounds for solution of real triangular system of linear equations, multiple right-hand sides, packed storage (STPRFS/DTPRFS)
F07UJF
Inverse of a real triangular matrix, packed storage (STPTRI/DTPTRI)
F07USF
Solution of complex triangular system of linear equations, multiple right-hand sides, packed storage (CTPTRS/ZTPTRS)
F07UUF
Estimate condition number of complex triangular matrix, packed storage (CTPCON/ZTPCON)
F07UVF
Error bounds for solution of complex triangular system of linear equations, multiple right-hand sides, packed storage (CTPRFS/ZTPRFS)
F07UWF
Inverse of a complex triangular matrix, packed storage (CTPTRI/ZTPTRI)
F07VEF
Solution of real band triangular system of linear equations, multiple right-hand sides (STBTRS/DTBTRS)
F07VGF
Estimate condition number of real band triangular matrix (STBCON/DTBCON)
F07VHF
Error bounds for solution of real band triangular system of linear equations, multiple right-hand sides (STBRFS/DTBRFS)
F07VSF
Solution of complex band triangular system of linear equations, multiple right-hand sides (CTBTRS/ZTBTRS)
F07VUF
Estimate condition number of complex band triangular matrix (CTBCON/ZTBCON)
F07VVF
Error bounds for solution of complex band triangular system of linear equations, multiple right-hand sides (CTBRFS/ZTBRFS)
F08AEF
QR factorization of real general rectangular matrix (SGEQRF/DGEQRF)
F08AFF
Form all or part of orthogonal Q from QR factorization determined by F08AEF or F08BEF (SORGQR/DORGQR)
F08AGF
Apply orthogonal transformation determined by F08AEF or F08BEF (SORMQR/DORMQR)
F08AHF
LQ factorization of real general rectangular matrix (SGELQF/DGELQF)
F08AJF
Form all or part of orthogonal Q from LQ factorization determined by F08AHF (SORGLQ/DORGLQ)
F08AKF
Apply orthogonal transformation determined by F08AHF (SORMLQ/DORMLQ)
F08ASF
QR factorization of complex general rectangular matrix (CGEQRF/ZGEQRF)
F08ATF
Form all or part of unitary Q from QR factorization determined by F08ASF or F08BSF (CUNGQR/ZUNGQR)
F08AUF
Apply unitary transformation determined by F08ASF or F08BSF (CUNMQR/ZUNMQR)
F08AVF
LQ factorization of complex general rectangular matrix (CGELQF/ZGELQF)
F08AWF
Form all or part of unitary Q from LQ factorization determined by F08AVF (CUNGLQ/ZUNGLQ)
F08AXF
Apply unitary transformation determined by F08AVF (CUNMLQ/ZUNMLQ)
F08BEF
QR factorization with column pivoting of real general rectangular matrix (SGEQPF/DGEQPF)
F08BSF
QR factorization with column pivoting of complex general rectangular matrix (CGEQPF/ZGEQPF)
F08FEF
Orthogonal reduction of real symmetric matrix to symmetric tridiagonal form (SSYTRD/DSYTRD)
F08FFF
Generate orthogonal transformation matrix from reduction to tridiagonal form determined by F08FEF (SORGTR/DORGTR)
F08FGF
Apply orthogonal transformation determined by F08FEF (SORMTR/DORMTR)
F08FSF
Unitary reduction of complex Hermitian matrix to real symmetric tridiagonal form (CHETRD/ZHETRD)
F08FTF
Generate unitary transformation matrix from reduction to tridiagonal form determined by F08FSF (CUNGTR/ZUNGTR)
F08FUF
Apply unitary transformation matrix determined by F08FSF (CUNMTR/ZUNMTR)
F08GEF
Orthogonal reduction of real symmetric matrix to symmetric tridiagonal form, packed storage (SSPTRD/DSPTRD)
F08GFF
Generate orthogonal transformation matrix from reduction to tridiagonal form determined by F08GEF (SOPGTR/DOPGTR)
F08GGF
Apply orthogonal transformation determined by F08GEF (SOPMTR/DOPMTR)
F08GSF
Unitary reduction of complex Hermitian matrix to real symmetric tridiagonal form, packed storage (CHPTRD/ZHPTRD)
F08GTF
Generate unitary transformation matrix from reduction to tridiagonal form determined by F08GSF (CUPGTR/ZUPGTR)
F08GUF
Apply unitary transformation matrix determined by F08GSF (CUPMTR/ZUPMTR)
F08HEF
Orthogonal reduction of real symmetric band matrix to symmetric tridiagonal form (SSBTRD/DBSTRD)
F08HSF
Unitary reduction of complex Hermitian band matrix to real symmetric tridiagonal form (CHBTRD/ZHBTRD)
F08JEF
All eigenvalues and eigenvectors of real symmetric tridiagonal matrix, reduced from real symmetric matrix using implicit QL or QR (SSTEQR/DSTEQR)
F08JFF
All eigenvalues of real symmetric tridiagonal matrix, root-free variant of QL or QR (SSTERF/DSTERF)
F08JGF
All eigenvalues and eigenvectors of real symmetric positive definite tridiagonal matrix, reduced from real symmetric positive definite matrix (SPTEQR/DPTEQR)
F08JJF
Selected eigenvalues of real symmetric tridiagonal matrix by bisection (SSTEBZ/DSTEBZ)
F08JKF
Selected eigenvectors of real symmetric tridiagonal matrix by inverse iteration, storing eigenvectors in real array (SSTEIN/DSTEIN)
F08JSF
All eigenvalues and eigenvectors of real symmetric tridiagonal matrix, reduced from complex Hermitian matrix, using implicit QL or QR (CSTEQR/ZSTEQR)
F08JUF
All eigenvalues and eigenvectors of real symmetric positive definite tridiagonal matrix, reduced from complex Hermitian positive definite matrix (CPTEQR/ZPTEQR)
F08JXF
Selected eigenvectors of real symmetric tridiagonal matrix by inverse iteration, storing eigenvectors in complex array (CSTEIN/ZSTEIN)
F08KEF
Orthogonal reduction of real general rectangular matrix to bidiagonal form (SGEBRD/DGEBRD)
F08KFF
Generate orthogonal transformation matrices from reduction to bidiagonal form determined by F08KEF (SORGBR/DORGBR)
F08KGF
Apply orthogonal transformations from reduction to bidiagonal form determined by F08KEF (SORMBR/DORMBR)
F08KSF
Unitary reduction of complex general rectangular matrix to bidiagonal form (CGEBRD/ZGEBRD)
F08KTF
Generate unitary transformation matrices from reduction to bidiagonal form determined by F08KSF (CUNGBR/ZUNGBR)
F08KUF
Apply unitary transformations from reduction to bidiagonal form determined by F08KSF (CUNMBR/ZUNMBR)
F08MEF
SVD of real bidiagonal matrix reduced from real general matrix (SBDSQR/DBDSQR)
F08MSF
SVD of real bidiagonal matrix reduced from complex general matrix (CBDSQR/ZBDSQR)
F08NEF
Orthogonal reduction of real general matrix to upper Hessenberg form (SGEHRD/DGEHRD)
F08NFF
Generate orthogonal transformation matrix from reduction to Hessenberg form determined by F08NEF (SORGHR/DORGHR)
F08NGF
Apply orthogonal transformation matrix from reduction to Hessenberg form determined by F08NEF (SORMHR/DORMHR)
F08NHF
Balance real general matrix (SGEBAL/DGEBAL)
F08NJF
Transform eigenvectors of real balanced matrix to those of original matrix supplied to F08NHF (SGEBAK/DGEBAK)
F08NSF
Unitary reduction of complex general matrix to upper Hessenberg form (CGEHRD/ZGEHRD)
F08NTF
Generate unitary transformation matrix from reduction to Hessenberg form determined by F08NSF (CUNGHR/ZUNGHR)
F08NUF
Apply unitary transformation matrix from reduction to Hessenberg form determined by F08NSF (CUNMHR/ZUNMHR)
F08NVF
Balance complex general matrix (CGEBAL/ZGEBAL)
F08NWF
Transform eigenvectors of complex balanced matrix to those of original matrix supplied to F08NVF (CGEBAK/ZGEBAK)
F08PEF
Eigenvalues and Schur factorization of real upper Hessenberg matrix reduced from real general matrix (SHSEQR/DHSEQR)
F08PKF
Selected right and/or left eigenvectors of real upper Hessenberg matrix by inverse iteration (SHSEIN/DHSEIN)
F08PSF
Eigenvalues and Schur factorization of complex upper Hessenberg matrix reduced from complex general matrix (CHSEQR/ZHSEQR)
F08PXF
Selected right and/or left eigenvectors of complex upper Hessenberg matrix by inverse iteration (CHSEIN/ZHSEIN)
F08QFF
Reorder Schur factorization of real matrix using orthogonal similarity transformation (STREXC/DTREXC)
F08QGF
Reorder Schur factorization of real matrix, form orthonormal basis of right invariant subspace for selected eigenvalues, with estimates of sensitivities (STRSEN/DTRSEN)
F08QHF
Solve real Sylvester matrix equation AX + XB = C, A and B are upper quasi-triangular or transposes (STRSYL/DTRSYL)
F08QKF
Left and/or right eigenvectors of a real upper quasi-triangular matrix (STREVC/DTREVC)
F08QLF
Estimates of sensitivities of selected eigenvalues and eigenvectors of real upper quasi-triangular matrix (STRSNA/DTRSNA)
F08QTF
Reorder Schur factorization of complex matrix using unitary similarity transformation (CTREXC/ZTREXC)
F08QUF
Reorder Schur factorization of complex matrix, form orthonormal basis of right invariant subspace for selected eigenvalues, with estimates of sensitivities (CTRSEN/ZTRSEN)
F08QVF
Solve complex Sylvester matrix equation AX + XB = C, A and B are upper triangular or conjugate-transposes (CTRSYL/ZTRSYL)
F08QXF
Left and/or right eigenvectors of a complex upper triangular matrix (CTREVC/ZTREVC)
F08QYF
Estimates of sensitivities of selected eigenvalues and eigenvectors of complex upper triangular matrix (CTRSNA/ZTRSNA)
F08SEF
Reduction to standard form of real symmetric-definite generalized eigenproblem Ax=kBx, ABx=kx or BAx=kx, B factorized by F07FDF (SSYGST/DSYGST)
F08SSF
Reduction to standard form of complex Hermitian-definite generalized eigenproblem Ax=kBx, ABx=kx or BAx=kx, B factorized by F07FRF (CHEGST/ZHEGST)
F08TEF
Reduction to standard form of real symmetric-definite generalized eigenproblem Ax=kBx, ABx=kx or BAx=kx, packed storage, B factorized by F07GDF (SSPGST/DSPGST)
F08TSF
Reduction to standard form of complex Hermitian-definite generalized eigenproblem Ax=kBx, ABx=kx or BAx=kx, packed storage, B factorized by F07GRF (CHPGST/ZHPGST)
G01AAF
Mean, variance, skewness, kurtosis etc, one variable, from raw data
G01ABF
Mean, variance, skewness, kurtosis etc, two variables, from raw data
G01ADF
Mean, variance, skewness, kurtosis etc, one variable, from frequency table
G01AEF
Frequency table from raw data
G01AFF
Two-way contingency table analysis, with chi-square/Fisher's exact test
G01AGF
Lineprinter scatterplot of two variables
G01AHF
Lineprinter scatterplot of one variable against Normal scores
G01AJF
Lineprinter histogram of one variable
G01ALF
Computes a five-point summary (median, hinges and extremes)
G01ARF
Constructs a stem and leaf plot
G01ASF
Constructs a box and whisker plot
G01BJF
Binomial distribution function
G01BKF
Poisson distribution function
G01BLF
Hypergeometric distribution function
G01DAF
Normal scores, accurate values
G01DBF
Normal scores, approximate values
G01DCF
Normal scores, approximate variance-covariance matrix
G01DDF
Shapiro and Wilk's W test for Normality
G01DHF
Ranks, Normal scores, approximate Normal scores or exponential (Savage) scores
G01EAF
Computes probabilities for the standard Normal distribution
G01EBF
Computes probabilities for Student's t-distribution
G01ECF
Computes probabilities for chi-square distribution
G01EDF
Computes probabilities for F-distribution
G01EEF
Computes upper and lower tail probabilities and probability density function for the beta distribution
G01EFF
Computes probabilities for the gamma distribution
G01EMF
Computes probability for the Studentized range statistic
G01EPF
Computes bounds for the significance of a Durbin-Watson statistic
G01ERF
Computes probability for Von Mises distribution
G01EYF
Computes probabilities for the one-sample Kolmogorov-Smirnov distribution
G01EZF
Computes probabilities for the two-sample Kolmogorov-Smirnov distribution
G01FAF
Computes deviates for the standard Normal distribution
G01FBF
Computes deviates for Student's t-distribution
G01FCF
Computes deviates for the chi-square distribution
G01FDF
Computes deviates for the F-distribution
G01FEF
Computes deviates for the beta distribution
G01FFF
Computes deviates for the gamma distribution
G01FMF
Computes deviates for the Studentized range statistic
G01GBF
Computes probabilities for the non-central Student's t-distribution
G01GCF
Computes probabilities for the non-central chi-square distribution
G01GDF
Computes probabilities for the non-central F-distribution
G01GEF
Computes probabilities for the non-central beta distribution
G01HAF
Computes probability for the bivariate Normal distribution
G01HBF
Computes probabilities for the multivariate Normal distribution
G01JCF
Computes probability for a positive linear combination of chi-square variables
G01JDF
Computes lower tail probability for a linear combination of (central) chi-squared variables
G01MBF
Computes reciprocal of Mills' Ratio
G01NAF
Cumulants and moments of quadratic forms in Normal variables
G01NBF
Moments of ratios of quadratic forms in Normal variables, and related statistics
G02BAF
Pearson product-moment correlation coefficients, all variables, no missing values
G02BBF
Pearson product-moment correlation coefficients, all variables, casewise treatment of missing values
G02BCF
Pearson product-moment correlation coefficients, all variables, pairwise treatment of missing values
G02BDF
Correlation-like coefficients (about zero), all variables, no missing values
G02BEF
Correlation-like coefficients (about zero), all variables, casewise treatment of missing values
G02BFF
Correlation-like coefficients (about zero), all variables, pairwise treatment of missing values
G02BGF
Pearson product-moment correlation coefficients, subset of variables, no missing values
G02BHF
Pearson product-moment correlation coefficients, subset of variables, casewise treatment of missing values
G02BJF
Pearson product-moment correlation coefficients, subset of variables, pairwise treatment of missing values
G02BKF
Correlation-like coefficients (about zero), subset of variables, no missing values
G02BLF
Correlation-like coefficients (about zero), subset of variables, casewise treatment of missing values
G02BMF
Correlation-like coefficients (about zero), subset of variables, pairwise treatment of missing values
G02BNF
Kendall/Spearman non-parametric rank correlation coefficients, no missing values, overwriting input data
G02BPF
Kendall/Spearman non-parametric rank correlation coefficients, casewise treatment of missing values, overwriting input data
G02BQF
Kendall/Spearman non-parametric rank correlation coefficients, no missing values, preserving input data
G02BRF
Kendall/Spearman non-parametric rank correlation coefficients, casewise treatment of missing values, preserving input data
G02BSF
Kendall/Spearman non-parametric rank correlation coefficients, pairwise treatment of missing values
G02BTF
Update a weighted sum of squares matrix with a new observation
G02BUF
Computes a weighted sum of squares matrix
G02BWF
Computes a correlation matrix from a sum of squares matrix
G02BXF
Computes (optionally weighted) correlation and covariance matrices
G02CAF
Simple linear regression with constant term, no missing values
G02CBF
Simple linear regression without constant term, no missing values
G02CCF
Simple linear regression with constant term, missing values
G02CDF
Simple linear regression without constant term, missing values
G02CEF
Service routines for multiple linear regression, select elements from vectors and matrices
G02CFF
Service routines for multiple linear regression, re-order elements of vectors and matrices
G02CGF
Multiple linear regression, from correlation coefficients, with constant term
G02CHF
Multiple linear regression, from correlation-like coefficients, without constant term
G02DAF
Fits a general (multiple) linear regression model
G02DCF
Add/delete an observation to/from a general linear regression model
G02DDF
Estimates of linear parameters and general linear regression model from updated model
G02DEF
Add a new variable to a general linear regression model
G02DFF
Delete a variable from a general linear regression model
G02DGF
Fits a general linear regression model for new dependent variable
G02DKF
Estimates and standard errors of parameters of a general linear regression model for given constraints
G02DNF
Computes estimable function of a general linear regression model and its standard error
G02EAF
Computes residual sums of squares for all possible linear regressions for a set of independent variables
G02ECF
Calculates R-square and Cp values from residual sums of squares
G02EEF
Fits a linear regression model by forward selection
G02FAF
Calculates standardized residuals and influence statistics
G02FCF
Computes Durbin-Watson test statistic
G02GAF
Fits a generalized linear model with Normal errors
G02GBF
Fits a generalized linear model with binomial errors
G02GCF
Fits a generalized linear model with Poisson errors
G02GDF
Fits a generalized linear model with gamma errors
G02GKF
Estimates and standard errors of parameters of a general linear model for given constraints
G02GNF
Computes estimable function of a generalized linear model and its standard error
G02HAF
Robust regression, standard M-estimates
G02HBF
Robust regression, compute weights for use with G02HDF
G02HDF
Robust regression, compute regression with user-specified functions
G02HFF
Robust regression, variance-covariance matrix following G02HDF
G02HKF
Calculates a robust estimation of a correlation matrix, Huber's weight function
G02HLF
Calculates a robust estimation of a correlation matrix, user-supplied weight function plus derivatives
G02HMF
Calculates a robust estimation of a correlation matrix, user-supplied weight function
G03AAF
Performs principal component analysis
G03ACF
Performs canonical variate analysis
G03ADF
Performs canonical correlation analysis
G03BAF
Computes orthogonal rotations for loading matrix, generalized orthomax criterion
G03BCF
Computes Procrustes rotations
G03CAF
Computes the maximum likelihood estimates of the parameters of a factor analysis model, factor loadings, communalities and residual correlations
G03CCF
Computes factor score coefficients (for use after G03CAF)
G03DAF
Computes test statistic for equality of within-group covariance matrices and matrices for discriminant analysis
G03DBF
Computes Mahalanobis squared distances for group or pooled variance-covariance matrices (for use after G03DAF)
G03DCF
Allocates observations to groups according to selected rules (for use after G03DAF)
G03EAF
Computes distance matrix
G03ECF
Hierarchical cluster analysis
G03EFF
K-means cluster analysis
G03EHF
Constructs dendrogram (for use after G03ECF)
G03EJF
Computes cluster indicator variable (for use after G03ECF)
G03ZAF
Produces standardized values (z-scores) for a data matrix
G04AGF
Two-way analysis of variance, hierarchical classification, subgroups of unequal size
G04BBF
Analysis of variance, randomized block or completely randomized design, treatment means and standard errors
G04CAF
Analysis of variance, complete factorial design, treatment means and standard errors
G05CAF
Pseudo-random real numbers, uniform distribution over (0,1)
G05CBF
Initialise random number generating routines to give repeatable sequence
G05CCF
Initialise random number generating routines to give non-repeatable sequence
G05CFF
Save state of random number generating routines
G05CGF
Restore state of random number generating routines
G05DAF
Pseudo-random real numbers, uniform distribution over (a,b)
G05DBF
Pseudo-random real numbers, (negative) exponential distribution
G05DCF
Pseudo-random real numbers, logistic distribution
G05DDF
Pseudo-random real numbers, Normal distribution
G05DEF
Pseudo-random real numbers, lognormal distribution
G05DFF
Pseudo-random real numbers, Cauchy distribution
G05DHF
Pseudo-random real numbers, chi-square distribution
G05DJF
Pseudo-random real numbers, Student's t-distribution
G05DKF
Pseudo-random real numbers, F-distribution
G05DPF
Pseudo-random real numbers, Weibull distribution
G05DRF
Pseudo-random integer, Poisson distribution
G05DYF
Pseudo-random integer from uniform distribution
G05DZF
Pseudo-random logical (boolean) value
G05EAF
Set up reference vector for multivariate Normal distribution
G05EBF
Set up reference vector for generating pseudo-random integers, uniform distribution
G05ECF
Set up reference vector for generating pseudo-random integers, Poisson distribution
G05EDF
Set up reference vector for generating pseudo-random integers, binomial distribution
G05EEF
Set up reference vector for generating pseudo-random integers, negative binomial distribution
G05EFF
Set up reference vector for generating pseudo-random integers, hypergeometric distribution
G05EGF
Set up reference vector for univariate ARMA time series model
G05EHF
Pseudo-random permutation of an integer vector
G05EJF
Pseudo-random sample from an integer vector
G05EWF
Generate next term from reference vector for ARMA time series model
G05EXF
Set up reference vector from supplied cumulative distribution function or probability distribution function
G05EYF
Pseudo-random integer from reference vector
G05EZF
Pseudo-random multivariate Normal vector from reference vector
G05FAF
Generates a vector of random numbers from a uniform distribution
G05FBF
Generates a vector of random numbers from an (negative) exponential distribution
G05FDF
Generates a vector of random numbers from a Normal distribution
G05FEF
Generates a vector of pseudo-random numbers from a beta distribution
G05FFF
Generates a vector of pseudo-random numbers from a gamma distribution
G05FSF
Generates vector of pseudo-random variates from Von Mises distribution
G05GAF
Computes random orthogonal matrix
G05GBF
Computes random correlation matrix
G05HDF
Generates a realisation of a multivariate time series from a VARMA model
G07AAF
Computes confidence interval for the parameter of a binomial distribution
G07ABF
Computes confidence interval for the parameter of a Poisson distribution
G07BBF
Computes maximum likelihood estimates for parameters of the Normal distribution from grouped and/or censored data
G07BEF
Computes maximum likelihood estimates for parameters of the Weibull distribution
G07CAF
Computes t-test statistic for a difference in means between two Normal populations, confidence interval
G07DAF
Robust estimation, median, median absolute deviation, robust standard deviation
G07DBF
Robust estimation, M-estimates for location and scale parameters, standard weight functions
G07DCF
Robust estimation, M-estimates for location and scale parameters, user-defined weight functions
G07DDF
Computes a trimmed and winsorized mean of a single sample with estimates of their variance
G07EAF
Robust confidence intervals, 1 sample
G07EBF
Robust confidence intervals, 2 sample
G08AAF
Sign test on two paired samples
G08ACF
Median test on two samples of unequal size
G08AEF
Friedman two-way analysis of variance on k matched samples
G08AFF
Kruskal-Wallis one-way analysis of variance on k samples of unequal size
G08AGF
Performs the Wilcoxon one-sample (matched pairs) signed rank test
G08AHF
Performs the Mann-Whitney U test on two independent samples
G08AJF
Computes the exact probabilities for the Mann-Whitney U statistic, no ties in pooled sample
G08AKF
Computes the exact probabilities for the Mann-Whitney U statistic, ties in pooled sample
G08ALF
Performs the Cochran Q test on cross-classified binary data
G08BAF
Mood's and David's tests on two samples of unequal size
G08CBF
Performs the one-sample Kolmogorov-Smirnov test for standard distributions
G08CCF
Performs the one-sample Kolmogorov-Smirnov test for a user-supplied distribution
G08CDF
Performs the two-sample Kolmogorov-Smirnov test
G08CGF
Performs the chi-square goodness of fit test, for standard continuous distributions
G08DAF
Kendall's coefficient of concordance
G08EAF
Performs the runs up or runs down test for randomness
G08EBF
Performs the pairs (serial) test for randomness
G08ECF
Performs the triplets test for randomness
G08EDF
Performs the gaps test for randomness
G08RAF
Regression using ranks, uncensored data
G08RBF
Regression using ranks, right-censored data
G10ABF
Fit cubic smoothing spline, smoothing parameter given
G10ACF
Fit cubic smoothing spline, smoothing parameter estimated
G10BAF
Kernel density estimate using Gaussian kernel
G10CAF
Compute smoothed data sequence using running median smoothers
G10ZAF
Reorder data to give ordered distinct observations
G11AAF
Chi-square statistics for two-way contingency table
G11SAF
Contingency table, latent variable model for binary data
G11SBF
Frequency count for G11SAF
G12AAF
Computes Kaplan-Meier (product-limit) estimates of survival probabilities
G13AAF
Univariate time series, seasonal and non-seasonal differencing
G13ABF
Univariate time series, sample autocorrelation function
G13ACF
Univariate time series, partial autocorrelations from autocorrelations
G13ADF
Univariate time series, preliminary estimation, seasonal ARIMA model
G13AEF
Univariate time series, estimation, seasonal ARIMA model (comprehensive)
G13AFF
Univariate time series, estimation, seasonal ARIMA model (easy-to-use)
G13AGF
Univariate time series, update state set for forecasting
G13AHF
Univariate time series, forecasting from state set
G13AJF
Univariate time series, state set and forecasts, from fully specified seasonal ARIMA model
G13ASF
Univariate time series, diagnostic checking of residuals, following G13AEF or G13AFF
G13AUF
Computes quantities needed for range-mean or standard deviation-mean plot
G13BAF
Multivariate time series, filtering (pre-whitening) by an ARIMA model
G13BBF
Multivariate time series, filtering by a transfer function model
G13BCF
Multivariate time series, cross-correlations
G13BDF
Multivariate time series, preliminary estimation of transfer function model
G13BEF
Multivariate time series, estimation of multi-input model
G13BGF
Multivariate time series, update state set for forecasting from multi-input model
G13BHF
Multivariate time series, forecasting from state set of multi-input model
G13BJF
Multivariate time series, state set and forecasts from fully specified multi-input model
G13CAF
Univariate time series, smoothed sample spectrum using rectangular, Bartlett, Tukey or Parzen lag window
G13CBF
Univariate time series, smoothed sample spectrum using spectral smoothing by the trapezium frequency (Daniell) window
G13CCF
Multivariate time series, smoothed sample cross spectrum using rectangular, Bartlett, Tukey or Parzen lag window
G13CDF
Multivariate time series, smoothed sample cross spectrum using spectral smoothing by the trapezium frequency (Daniell) window
G13CEF
Multivariate time series, cross amplitude spectrum, squared coherency, bounds, univariate and bivariate (cross) spectra
G13CFF
Multivariate time series, gain, phase, bounds, univariate and bivariate (cross) spectra
G13CGF
Multivariate time series, noise spectrum, bounds, impulse response function and its standard error
G13DBF
Multivariate time series, multiple squared partial autocorrelation matrices
G13DCF
Multivariate time series, estimation of VARMA model
G13DJF
Multivariate time series, forecasts and their standard errors
G13DKF
Multivariate time series, updates forecasts and their standard errors
G13DLF
Multivariate time series, differences and/or transforms (for use before G13DCF)
G13DMF
Multivariate time series, sample cross-correlation or cross-covariance matrices
G13DNF
Multivariate time series, sample partial lag correlation matrices, chi-squared statistics and significance levels
G13DPF
Multivariate time series, partial autoregression matrices
G13DSF
Multivariate time series, diagnostic checking of residuals, following G13DCF
G13DXF
Calculates the zeros of a vector autoregressive (or moving average) operator
H02BBF
Integer programming problem, branch and bound method
H02BFF
Interpret MPSX data file defining IP or LP problem, optimize and print solution
H02BUF
Converts MPSX data file defining IP or LP problem to format required by H02BBF or E04MFF
H02BVF
Prints IP or LP solutions with user specified names for rows and columns
H02BZF
Integer programming solution, supplies further information on solution obtained by H02BBF
H03ABF
Transportation problem
M01CAF
Sort a vector, real numbers
M01CBF
Sort a vector, integer numbers
M01CCF
Sort a vector, character data
M01DAF
Rank a vector, real numbers
M01DBF
Rank a vector, integer numbers
M01DCF
Rank a vector, character data
M01DEF
Rank rows of a matrix, real numbers
M01DFF
Rank rows of a matrix, integer numbers
M01DJF
Rank columns of a matrix, real numbers
M01DKF
Rank columns of a matrix, integer numbers
M01DZF
Rank arbitrary data
M01EAF
Rearrange a vector according to given ranks, real numbers
M01EBF
Rearrange a vector according to given ranks, integer numbers
M01ECF
Rearrange a vector according to given ranks, character data
M01ZAF
Invert a permutation
M01ZBF
Check validity of a permutation
M01ZCF
Decompose a permutation into cycles
P01ABF
Return value of error indicator/terminate with error message
S01BAF
ln (1+x)
S01EAF
Complex exponential, exp(z)
S07AAF
tan x
S09AAF
arcsin x
S09ABF
arccos x
S10AAF
tanh x
S10ABF
sinh x
S10ACF
cosh x
S11AAF
arctanh x
S11ABF
arcsinh x
S11ACF
arccosh x
S13AAF
Exponential integral E1(x)
S13ACF
Cosine integral Ci(x)
S13ADF
Sine integral Si(x)
S14AAF
Gamma function
S14ABF
Log Gamma function
S14ACF
psi (x) - ln x
S14ADF
Scaled derivatives of psi (x)
S14BAF
Incomplete gamma functions P(a,x) and Q(a,x)
S15ABF
Cumulative normal distribution function P(x)
S15ACF
Complement of cumulative normal distribution function Q(x)
S15ADF
Complement of error function erfc(x)
S15AEF
Error function erf(x)
S15AFF
Dawson's integral
S15DDF
Scaled complex complement of error function, exp(-z**2)erfc(-iz)
S17ACF
Bessel function Y0(x)
S17ADF
Bessel function Y1(x)
S17AEF
Bessel function J0(x)
S17AFF
Bessel function J1(x)
S17AGF
Airy function Ai(x)
S17AHF
Airy function Bi(x)
S17AJF
Airy function Ai'(x)
S17AKF
Airy function Bi'(x)
S17DCF
Bessel functions Y(a+n)(z), real a>=0, complex z, n=0,1,2,..,
S17DEF
Bessel functions J(a+n)(z), real a>=0, complex z, n=0,1,2,...
S17DGF
Airy functions Ai(z) and Ai'(z), complex z
S17DHF
Airy functions Bi(z) and Bi'(z), complex z
S17DLF
Hankel functions H(j)(a+n)(z), j=1,2, real a>=0, complex z, n=0,1,2,...
S18ACF
Modified Bessel function K0(x)
S18ADF
Modified Bessel function K1(x)
S18AEF
Modified Bessel function I0(x)
S18AFF
Modified Bessel function I1(x)
S18CCF
Modified Bessel function exp(x)*K0(x)
S18CDF
Modified Bessel function exp(x)*K1(x)
S18CEF
Modified Bessel function exp(-abs(x))*I0(x)
S18CFF
Modified Bessel function exp(-abs(x))*I1(x)
S18DCF
Modified Bessel functions K(a+n)(z), real a>=0, complex z, n=0,1,2,...
S18DEF
Modified Bessel functions I(a+n)(z), real a>=0, complex z, n=0,1,2,...
S19AAF
Kelvin function ber x
S19ABF
Kelvin function bei x
S19ACF
Kelvin function ker x
S19ADF
Kelvin function kei x
S20ACF
Fresnel integral S(x)
S20ADF
Fresnel integral C(x)
S21BAF
Degenerate symmetrised elliptic integral of 1st kind Rc(x,y)
S21BBF
Symmetrised elliptic integral of 1st kind Rf(x,y,z)
S21BCF
Symmetrised elliptic integral of 2nd kind Rd(x,y,z)
S21BDF
Symmetrised elliptic integral of 3rd kind Rj(x,y,z,r)
S21CAF
Jacobian elliptic functions sn, cn and dn
X01AAF
Pi
X01ABF
Euler's constant, Gamma
X02AHF
Largest permissible argument for SIN and COS
X02AJF
Machine precision
X02AKF
Smallest positive model number
X02ALF
Largest positive model number
X02AMF
Safe range of floating-point arithmetic
X02ANF
Safe range of complex floating-point arithmetic
X02BBF
Largest representable integer
X02BEF
Maximum number of decimal digits that can be represented
X02BHF
Parameter of floating-point arithmetic model, b
X02BJF
Parameter of floating-point arithmetic model, p
X02BKF
Parameter of floating-point arithmetic model, emin
X02BLF
Parameter of floating-point arithmetic model, emax
X02DAF
Switch for taking precautions to avoid underflow
X02DJF
Parameter of floating-point arithmetic model, ROUNDS
X03AAF
Real inner product added to initial value, basic/additional precision
X03ABF
Complex inner product added to initial value, basic/additional precision
X04AAF
Return or set unit number for error messages
X04ABF
Return or set unit number for advisory messages
X04BAF
Write formatted record to external file
X04BBF
Read formatted record from external file
X04CAF
Print a real general matrix (easy-to-use)
X04CBF
Print a real general matrix (comprehensive)
X04CCF
Print a real packed triangular matrix (easy-to-use)
X04CDF
Print a real packed triangular matrix (comprehensive)
X04CEF
Print a real packed banded matrix (easy-to-use)
X04CFF
Print a real packed banded matrix (comprehensive)
X04DAF
Print a complex general matrix (easy-to-use)
X04DBF
Print a complex general matrix (comprehensive)
X04DCF
Print a complex packed triangular matrix (easy-to-use)
X04DDF
Print a complex packed triangular matrix (comprehensive)
X04DEF
Print a complex packed banded matrix (easy-to-use)
X04DFF
Print a complex packed banded matrix (comprehensive)
X04EAF
Print an integer matrix (easy-to-use)
X04EBF
Print an integer matrix (comprehensive)
X05AAF
Return date and time as an array of integers
X05ABF
Convert array of integers representing date and time to character string
X05ACF
Compare two character strings representing date and time
X05BAF
Return the CPU time


A00AAF
      SUBROUTINE A00AAF
C     MARK 15 RE-ISSUE. NAG COPYRIGHT 1991.
C
C     Writes information about the particular implementation of the
C     NAG Library in use.
C
C     The output channel is given by a call to X04ABF.
C

A02AAF
      SUBROUTINE A02AAF(XXR,XXI,YR,YI)
C     MARK 2A RELEASE.  NAG COPYRIGHT 1973
C     MARK 4.5 REVISED
C     MARK 5C REVISED
C     MARK 11C REVISED. IER-467 (MAR 1985)
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     COMPUTES THE SQUARE ROOT OF A COMPLEX NUMBER
C

A02ABF
      DOUBLE PRECISION FUNCTION A02ABF(XXR,XXI)
C     NAG COPYRIGHT 1975
C     MARK 4.5 REVISED
C     MARK 5C REVISED
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     RETURNS THE ABSOLUTE VALUE OF A COMPLEX NUMBER VIA ROUTINE
C     NAME
C

A02ACF
      SUBROUTINE A02ACF(XXR,XXI,YYR,YYI,ZR,ZI)
C     MARK 2A RELEASE.  NAG COPYRIGHT 1973
C     MARK 4.5 REVISED
C     MARK 5C REVISED
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     DIVIDES ONE COMPLEX NUMBER BY A SECOND
C

C02AFF
      SUBROUTINE C02AFF(A,N,SCALE,Z,WORK,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C     MARK 15B REVISED. IER-944 (NOV 1991).
C
C     C02AFF ATTEMPTS TO FIND ALL THE ROOTS OF THE NTH ORDER COMPLEX
C     POLYNOMIAL EQUATION
C
C         N
C        SUM [A(1,k)+A(2,k)*I] * Z**(N-k) = 0.
C        k=0
C
C     THE ZEROS OF POLYNOMIALS OF DEGREE 1 AND 2 ARE CALCULATED BY
C     CAREFULLY EVALUATING THE "STANDARD" CLOSED FORMULAS
C           Z = -B/A AND
C           Z = (-B +/- SQRT(B*B-4*A*C))/(2*A) RESPECTIVELY, WHERE
C        A = CMPLX(A(1,0),A(2,0))
C        B = CMPLX(A(1,1),A(2,1)) AND
C        C = CMPLX(A(1,2),A(2,2)).
C     FOR N >= 3, THE ROOTS ARE LOCATED ITERATIVELY USING A VARIANT OF
C     LAGUERRE'S METHOD, WHICH IS CUBICALLY CONVERGENT FOR ISOLATED
C     ZEROS AND LINEARLY CONVERGENT FOR MULTIPLE ZEROS.
C
C     C02AFF ITSELF IS ESSENTIALLY A DUMMY ROUTINE WHOSE FUNCTION IS TO
C     PARTITION THE WORK ARRAY WORK FOR USE BY C02AFZ.
C     WORK IS PARTITIONED INTO 2 ARRAYS EACH OF SIZE 2*(N + 1).
C

C02AGF
      SUBROUTINE C02AGF(A,N,SCALE,Z,WORK,IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.
C     MARK 15B REVISED. IER-945 (NOV 1991).
C
C     C02AGF ATTEMPTS TO FIND ALL THE ROOTS OF THE NTH ORDER REAL
C     POLYNOMIAL EQUATION
C
C        A(0)*Z**N + A(1)*Z**(N-1) + ... + A(N-1)*Z + A(N) = 0.
C
C     THE ZEROS OF POLYNOMIALS OF DEGREE 1 AND 2 ARE CALCULATED USING
C     THE "STANDARD" CLOSED FORMULAS
C           Z = -A(1)/A(0) AND
C           Z = (-A(1) +/- SQRT(DISC))/(2*A(0)) RESPECTIVELY, WHERE
C        DISC = A(1)**2 - 4*A(0)*A(2).
C     FOR N >= 3, THE ROOTS ARE LOCATED ITERATIVELY USING A VARIANT OF
C     LAGUERRE'S METHOD, WHICH IS CUBICALLY CONVERGENT FOR ISOLATED
C     ZEROS (REAL OR COMPLEX) AND LINEARLY CONVERGENT FOR MULTIPLE
C     ZEROS.
C
C     C02AGF ITSELF IS ESSENTIALLY A DUMMY ROUTINE WHOSE FUNCTION IS TO
C     PARTITION THE WORK ARRAY WORK FOR USE BY C02AGZ.
C     WORK IS PARTITIONED INTO 2 ARRAYS EACH OF SIZE (N + 1).
C

C02AHF
      SUBROUTINE C02AHF(AR,AI,BR,BI,CR,CI,ZSM,ZLG,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     C02AHF DETERMINES THE ROOTS OF THE QUADRATIC EQUATION
C        A*Z**2 + B*Z + C = 0
C     WHERE A = CMPLX(AR,AI), B = CMPLX(BR,BI) AND C = CMPLX(CR,CI)
C     ARE COMPLEX COEFFICIENTS, AND ZSM AND ZLG ARE THE SMALLEST AND
C     LARGEST ROOT IN MAGNITUDE RESPECTIVELY.
C

C02AJF
      SUBROUTINE C02AJF(A,B,C,ZSM,ZLG,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     C02AJF DETERMINES THE ROOTS OF THE QUADRATIC EQUATION
C        A*Z**2 + B*Z + C = 0
C     WHERE A, B AND C ARE REAL COEFFICIENTS, AND ZSM AND ZLG
C     ARE THE SMALLEST AND LARGEST ROOT IN MAGNITUDE RESPECTIVELY.
C

C05ADF
      SUBROUTINE C05ADF(A,B,EPS,ETA,F,X,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 10C REVISED. IER-422 (JUL 1983).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     DRIVER FOR C05AZF

C05AGF
      SUBROUTINE C05AGF(X,HH,EPS,ETA,F,A,B,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 9 REVISED. IER-300 (SEP 1981).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     DRIVER FOR C05AVF AND C05AZF

C05AJF
      SUBROUTINE C05AJF(X,EPS,ETA,F,NFMAX,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C     DRIVER FOR C05AXF

C05AVF
      SUBROUTINE C05AVF(X,FX,H,BOUNDL,BOUNDU,A,C,IND,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 10B REVISED. IER-398 (JAN 1983).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     FINDS INTERVAL [A,X] IN WHICH LIES ROOT OF F.
C     [BOUNDL,BOUNDU] CONTAINS [A,X],X IS INITIAL GUESS
C     AND H IS STARTING STEP.

C05AXF
      SUBROUTINE C05AXF(X,FX,TOL,IR,SCALE,C,IND,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 9 REVISED. IER-301 (SEP 1981).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C     USES METHOD OF OF SWIFT AND LINDFIELD,
C     C.J.VOL 21. MINK=C(1),MAXK=C(2).

C05AZF
      SUBROUTINE C05AZF(X,Y,FX,TOLX,IR,C,IND,IFAIL)
C     MARK 8 RE-ISSUE. NAG COPYRIGHT 1979.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 12A REVISED. IER-496 (AUG 1986).
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).

C05NBF
      SUBROUTINE C05NBF(FCN,N,X,FVEC,TOL,WA,LWA,IFAIL)
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.
C     **********
C
C     SUBROUTINE C05NBF (based on MINPACK routine HYBRD1)
C
C     The purpose of C05NBF is to find a zero of a system of
C     N nonlinear functions in N variables by a modification
C     of the Powell Hybrid method. This is done by using the
C     more general nonlinear equation solver C05NCF. The user
C     must provide a subroutine which calculates the functions.
C     The Jacobian is then calculated by a forward-difference
C     approximation.
C
C     Argonne National Laboratory. MINPACK Project. March 1980.
C     Burton S. Garbow, Kenneth E. Hillstrom, Jorge J. More
C     **********
C
C     Revised to output explanatory messages.
C     P.J.D. Mayes, NAG Central Office, December 1987
C

C05NCF
      SUBROUTINE C05NCF(FCN,N,X,FVEC,XTOL,MAXFEV,ML,MU,EPSFCN,DIAG,MODE,
     *                  FACTOR,NPRINT,NFEV,FJAC,LDFJAC,R,LR,QTF,W,IFAIL)
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.
C     **********
C
C     SUBROUTINE C05NCF
C
C     The purpose of C05NCF is to interface to C05NCS.
C     The latter is based on MINPACK routine HYBRD.
C
C     **********
C
C     Revised to output explanatory messages.
C     P.J.D. Mayes, NAG Central Office, December 1987.
C

C05NDF
      SUBROUTINE C05NDF(IREVCM,N,X,FVEC,XTOL,ML,MU,EPSFCN,DIAG,MODE,
     *                  FACTOR,FJAC,LDFJAC,R,LR,QTF,W,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C     **********
C
C     SUBROUTINE C05NDF
C
C     The purpose of C05NDF is to interface to C05NDS.
C     The latter is based on MINPACK routine HYBRD.
C
C     **********
C
C     Revised to output explanatory messages.
C     P.J.D. Mayes, NAG Central Office, December 1987.
C     Revised to reverse communication.
C     M.S. Derakhshan, NAG Central Office, September 1988.
C

C05PBF
      SUBROUTINE C05PBF(FCN,N,X,FVEC,FJAC,LDFJAC,TOL,WA,LWA,IFAIL)
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.
C     **********
C
C     SUBROUTINE C05PBF (based on MINPACK routine HYBRJ1)
C
C     The purpose of C05PBF is to find a zero of a system of
C     N nonlinear functions in N variables by a modification
C     of the Powell Hybrid method. This is done by using the
C     more general nonlinear equation solver C05PCF. The user
C     must provide a subroutine which calculates the functions
C     and the Jacobian.
C
C     **********
C
C     Revised to output explanatory messages.
C     P.J.D. Mayes, NAG Central Office, December 1987.
C

C05PCF
      SUBROUTINE C05PCF(FCN,N,X,FVEC,FJAC,LDFJAC,XTOL,MAXFEV,DIAG,MODE,
     *                  FACTOR,NPRINT,NFEV,NJEV,R,LR,QTF,W,IFAIL)
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.
C     **********
C
C     SUBROUTINE C05PCF
C
C     The purpose of C05PCF is to interface to C05PCZ.
C     The latter is based upon MINPACK routine HYBRJ.
C
C     **********
C
C     Revised to output explanatory messages.
C     P.J.D. Mayes, NAG Central Office, December 1987.
C

C05PDF
      SUBROUTINE C05PDF(IREVCM,N,X,FVEC,FJAC,LDFJAC,XTOL,DIAG,MODE,
     *                  FACTOR,R,LR,QTF,W,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C     **********
C
C     SUBROUTINE C05PDF
C
C     The purpose of C05PDF is to interface to C05PDZ.
C     The latter is based upon MINPACK routine HYBRJ.
C
C     **********
C
C     Revised to output explanatory messages.
C     P.J.D. Mayes, NAG Central Office, December 1987.
C     Revised to reverse communication.
C     M.S. Derakhshan, NAG Central Office, September 1988.
C
C     ..Subroutine Arguments ..
C

C05ZAF
      SUBROUTINE C05ZAF(M,N,X,FVEC,FJAC,LDFJAC,XP,FVECP,MODE,ERR)
C     MARK 9 RELEASE.  NAG COPYRIGHT 1981
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C     **********
C
C     SUBROUTINE C05ZAF(BASED ON MINPACK ROUTINE CHKDER)
C
C     THIS SUBROUTINE CHECKS THE GRADIENTS OF M NONLINEAR FUNCTIONS
C     IN N VARIABLES, EVALUATED AT A POINT X, FOR CONSISTENCY WITH
C     THE FUNCTIONS THEMSELVES. THE USER MUST CALL C05ZAF TWICE,
C     FIRST WITH MODE = 1 AND THEN WITH MODE = 2.
C
C     MODE = 1. ON INPUT, X MUST CONTAIN THE POINT OF EVALUATION.
C     ON OUTPUT, XP IS SET TO A NEIGHBORING POINT.
C
C     MODE = 2. ON INPUT, FVEC MUST CONTAIN THE FUNCTIONS AND THE
C     ROWS OF FJAC MUST CONTAIN THE GRADIENTS
C     OF THE RESPECTIVE FUNCTIONS EACH EVALUATED
C     AT X, AND FVECP MUST CONTAIN THE FUNCTIONS
C     EVALUATED AT XP.
C     ON OUTPUT, ERR CONTAINS MEASURES OF CORRECTNESS OF
C     THE RESPECTIVE GRADIENTS.
C
C     THE SUBROUTINE DOES NOT PERFORM RELIABLY IF CANCELLATION OR
C     ROUNDING ERRORS CAUSE A SEVERE LOSS OF SIGNIFICANCE IN THE
C     EVALUATION OF A FUNCTION. THEREFORE, NONE OF THE COMPONENTS
C     OF X SHOULD BE UNUSUALLY SMALL (IN PARTICULAR, ZERO) OR ANY
C     OTHER VALUE WHICH MAY CAUSE LOSS OF SIGNIFICANCE.
C
C     **********
C
C     EPSMCH IS THE MACHINE PRECISION.
C

C06BAF
      SUBROUTINE C06BAF(SEQN,NCALL,RESULT,ABSERR,WORK,IWORK,IFAIL)
C     MARK 10 RELEASE. NAG COPYRIGHT 1982.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C     MARK 14C REVISED. IER-870 (NOV 1990).
C     CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C
C     MODIFIED VERSION OF ROUTINE D01AJY (EPSILON ALGORITHM)
C     BASED ON QUADPACK ROUTINE EPSALG
C
C     CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C
C     PURPOSE
C        THE ROUTINE TRANSFORMS A GIVEN SEQUENCE OF
C        APPROXIMATIONS, BY MEANS OF THE EPSILON
C        ALGORITHM OF P. WYNN, AND PREDICTS A LIMIT
C        FOR THE SEQUENCE.
C        AN ESTIMATE OF THE ABSOLUTE ERROR IS ALSO GIVEN.
C        THE CONDENSED EPSILON TABLE IS COMPUTED. ONLY THOSE
C        ELEMENTS NEEDED FOR THE COMPUTATION OF THE
C        NEXT DIAGONAL ARE PRESERVED.
C
C     PARAMETERS
C        SEQN   - THE NEW ELEMENT IN THE FIRST COLUMN
C                 OF THE EPSILON TABLE.
C
C        NCALL  - NUMBER OF CALLS MADE TO THE ROUTINE.
C                 MUST BE SET TO ZERO BEFORE FIRST ENTRY
C                 AND UNCHANGED BETWEEN CALLS.
C
C        RESULT - RESULTING APPROXIMATION TO THE LIMIT
C                 OF THE SEQUENCE.
C
C        ABSERR - ESTIMATE OF THE ABSOLUTE ERROR COMPUTED FROM
C                 RESULT AND THE 3 PREVIOUS /RESULTS/
C
C        WORK   - ONE DIMENSION ARRAY OF SIZE IWORK
C
C        IWORK  - DIMENSION OF WORK. MUST BE .GT. 8
C                 PREFERABLY IWORK.GE.(MAX NUMBER OF SEQN)+6
C
C        IFAIL  - ON EXIT =1 IF NCALL .LT. ZERO
C                         =2 IF IWORK .LT. 9
C
C     CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C
C     MODIFICATIONS
C     THE TWO ARRAYS EPSTAB AND RES3LA HAVE BEEN COMBINED
C     TO ONE WORK ARRAY - RES3LA(1),(2),(3) IS NOW
C                          WORK (2),(3),(4)
C                    AND  EPSTAB(1),(2),...,(N) IS NOW
C                          WORK (5),(6),...,(N+4).
C     SEQN HAD TO BE ASSIGNED TO SOME ELEMENT OF EPSTAB
C     BEFORE CALLING THIS ROUTINE IN ORIGINAL FORM, IS NOW
C     ASSIGNED TO WORK(I) INSIDE THIS ROUTINE WHERE INFO
C     NECESSARY TO DETERMINE I IS PASSED VIA WORK(1).
C
C     CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C
C     CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C
C     /LIMEXP/ IS THE MAXIMUM NUMBER OF ELEMENTS THE EPSILON
C     TABLE CAN CONTAIN. IF THIS NUMBER IS REACHED, THE UPPER
C     DIAGONAL OF THE EPSILON TABLE IS DELETED.
C

C06DBF
      DOUBLE PRECISION FUNCTION C06DBF(X,C,N,S)
C     MARK 6 RELEASE. NAG COPYRIGHT 1977.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     THIS FUNCTION EVALUATES A CHEBYSHEV SERIES OF ONE OF THREE
C     FORMS ACCORDING TO THE VALUE OF S
C     S=1- 0.5*C(1)+SUM FROM J=2 TO N OF C(J)*T(J-1)(X),
C     S=2- 0.5*C(1)+SUM FROM J=2 TO N OF C(J)*T(2J-2)(X),
C     S=3- SUM FROM J=1 TO N OF C(J)*T(2J-1)(X),
C     WHERE X LIES IN THE RANGE -1.0 .LE. X .LE. 1.0
C

C06EAF
      SUBROUTINE C06EAF(X,PTS,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     REAL FOURIER TRANSFORM

C06EBF
      SUBROUTINE C06EBF(X,PTS,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     HERMITE FOURIER TRANSFORM

C06ECF
      SUBROUTINE C06ECF(X,Y,PTS,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     COMPLEX FOURIER TRANSFORM

C06EKF
      SUBROUTINE C06EKF(JOB,X,Y,N,IFAIL)
C     MARK 11 RELEASE. NAG COPYRIGHT 1984.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     IF JOB = 1, CONVOLUTION OF 2 REAL VECTORS.
C     IF JOB = 2, CORRELATION OF 2 REAL VECTORS.
C
C     (NO WORK ARRAY REQUIRED)
C

C06FAF
      SUBROUTINE C06FAF(X,PTS,WORK,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     REAL FOURIER TRANSFORM

C06FBF
      SUBROUTINE C06FBF(X,PTS,WORK,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     HERMITE FOURIER TRANSFORM

C06FCF
      SUBROUTINE C06FCF(X,Y,PTS,WORK,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     COMPLEX FOURIER TRANSFORM

C06FFF
      SUBROUTINE C06FFF(NDIM,L,ND,N,X,Y,WORK,LWORK,IFAIL)
C     MARK 11 RELEASE. NAG COPYRIGHT 1984.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     DISCRETE FOURIER TRANSFORM OF ONE VARIABLE IN A
C     MULTI-VARIABLE SEQUENCE OF COMPLEX DATA VALUES
C

C06FJF
      SUBROUTINE C06FJF(NDIM,ND,N,X,Y,WORK,LWORK,IFAIL)
C     MARK 11 RELEASE. NAG COPYRIGHT 1984.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     MULTI-DIMENSIONAL DISCRETE FOURIER TRANSFORM OF A
C     MULTI-DIMENSIONAL SEQUENCE OF COMPLEX DATA VALUES
C

C06FKF
      SUBROUTINE C06FKF(JOB,X,Y,N,WORK,IFAIL)
C     MARK 11 RELEASE. NAG COPYRIGHT 1984.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     IF JOB = 1, CONVOLUTION OF 2 REAL VECTORS.
C     IF JOB = 2, CORRELATION OF 2 REAL VECTORS.
C
C     (USING WORK ARRAY FOR EXTRA SPEED)
C

C06FPF
      SUBROUTINE C06FPF(M,N,X,INIT,TRIG,WORK,IFAIL)
CVD$R NOVECTOR
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

C06FQF
      SUBROUTINE C06FQF(M,N,X,INIT,TRIG,WORK,IFAIL)
CVD$R NOVECTOR
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

C06FRF
      SUBROUTINE C06FRF(M,N,X,Y,INIT,TRIG,WORK,IFAIL)
CVD$R NOVECTOR
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

C06FUF
      SUBROUTINE C06FUF(M,N,X,Y,INIT,TRIGM,TRIGN,WORK,IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.
C
C     C06FUF computes a two-dimensional Fast Fourier Transform of
C     a complex array, by calling the vectorized multiple
C     one-dimensional routine C06FRF together with an explicit
C     transposition of the data using the auxiliary routine C06FUZ.
C

C06GBF
      SUBROUTINE C06GBF(X,PTS,IFAIL)
CVD$R VECTOR
CVD$R NOLSTVAL
CVD$R STRIP
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     HERMITIAN CONJUGATE

C06GCF
      SUBROUTINE C06GCF(Y,PTS,IFAIL)
CVD$R VECTOR
CVD$R NOLSTVAL
CVD$R STRIP
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     COMPLEX CONJUGATE

C06GQF
      SUBROUTINE C06GQF(M,N,X,IFAIL)
CVD$R VECTOR
CVD$R NOLSTVAL
CVD$R STRIP
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

C06GSF
      SUBROUTINE C06GSF(M,N,X,U,V,IFAIL)
CVD$R VECTOR
CVD$R NOLSTVAL
CVD$R STRIP
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C

C06HAF
      SUBROUTINE C06HAF(M,N,X,INIT,TRIG,WORK,IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.
C     MARK 14C REVISED. IER-871 (NOV 1990).
C     MARK 15 REVISED. IER-894 (APR 1991).
C
C     C06HAF computes multiple Fourier sine transforms of sequences
C     of real data using the multiple real transform kernel C06FPX,
C     and pre- and post-processing steps described by Swarztrauber.
C

C06HBF
      SUBROUTINE C06HBF(M,N,X,INIT,TRIG,WORK,IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.
C     MARK 14C REVISED. IER-872 (NOV 1990).
C     MARK 15 REVISED. IER-895 (APR 1991).
C
C     C06HBF computes multiple Fourier cosine transforms of sequences
C     of real data using the multiple real transform kernel C06FPX,
C     and pre- and post-processing steps described by Swarztrauber.
C

C06HCF
      SUBROUTINE C06HCF(DIRECT,M,N,X,INIT,TRIG,WORK,IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.
C     MARK 13B REVISED. IER-650 (AUG 1988).
C     MARK 14C REVISED. IER-873 (NOV 1990).
C     MARK 15 REVISED. IER-896 (APR 1991).
C
C     C06HCF computes multiple quarter-wave Fourier sine transforms
C     of sequences of real data using the multiple real and
C     Hermitian transform kernels C06FPX and C06FQX, and pre- and
C     post-processing steps described by Swarztrauber.
C

C06HDF
      SUBROUTINE C06HDF(DIRECT,M,N,X,INIT,TRIG,WORK,IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.
C     MARK 13B REVISED. IER-651 (AUG 1988).
C     MARK 15 REVISED. IER-897 (APR 1991).
C
C     C06HDF computes multiple quarter-wave Fourier cosine transforms
C     of sequences of real data using the multiple real and
C     Hermitian transform kernels C06FPX and C06FQX, and pre- and
C     post-processing steps described by Swarztrauber.
C

C06LAF
      SUBROUTINE C06LAF(FUN,N,T,VALINV,ERREST,RELERR,ALPHAB,TFAC,MXTERM,
     *                  NTERMS,NA,ALOW,AHIGH,NFEVAL,WORK,IFAIL)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C
C     Estimates values of the inverse Laplace transform of a given
C     function using a Fourier series approximation.
C     Real and imaginary parts of the function, and a bound on the
C     exponential order of the inverse, are required.
C

C06LBF
      SUBROUTINE C06LBF(F,SIGMA0,SIGMA,B,EPSTOL,MMAX,M,ACOEF,ERRVEC,
     *                  IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C     MARK 15B REVISED. IER-946 (NOV 1991).
C
C     C06LBF computes a set of Laguerre expansion coefficients for the
C     inverse Laplace transform of a user-specified analytic function.
C     The value of the inverse Laplace transform at a specified argument
C     can be obtained by a subsequent call to C06LCF.
C
C     C06LBF is derived from the subroutine MODUL1 in the package WEEKS
C     by B.S. Garbow, G. Giunta, J.N. Lyness and A. Murli, Algorithm
C     662: A Fortran software package for the numerical inversion of the
C     Laplace Transform based on Weeks' method, ACM Trans. Math.
C     Software, 14, pp 171-176 (1988).
C
C     INPUT arguments
C
C     F      - procedure - name of function subprogram for the complex
C                     valued Laplace transform to be inverted.  F must
C                     be declared EXTERNAL in the calling program.
C     sigma0 - real - the abscissa of convergence of the Laplace
C                     transform.
C     sigma  - real - the first parameter of the Laguerre expansion.
C                     If sigma is not greater than sigma0, it defaults
C                     and is reset to (sigma0 + 0.7).
C     b      - real - the second parameter of the Laguerre expansion.
C                     If b is less than 2.0*(sigma - sigma0), it
C                     defaults and is reset to 2.5*(sigma - sigma0).
C     epstol - real - the required absolute uniform pseudo accuracy for
C                     the coefficients and inverse Laplace transform
C                     values.
C     mmax   - integer -  an upper limit on the number of coefficients
C                     to be computed.  Note that the maximum number of
C                     Laplace transform evaluations is (mmax/2 + 2).
C
C     OUTPUT arguments
C
C     m      - integer - the number of coefficients actually computed.
C     acoef  - real(mmax) - the array of Laguerre coefficients.
C     errvec - real(8) - an 8-component vector of diagnostic
C                     information.
C          All components are functions of Laguerre coefficients acoef.
C          (1) = Overall estimate of the pseudo-error = (2) + (3) + (4).
C                  Pseudo-error = absolute error / exp(sigma*t) .
C          (2) = Estimate of the discretisation pseudo-error.
C          (3) = Estimate of the truncation pseudo-error.
C          (4) = Estimate of the conditioning pseudo-error, on the basis
C                  of minimal noise levels in function values.
C          (5) = K - Coefficient of the decay function for acoef.
C          (6) = R - Base of the decay function for acoef.
C                  abs(acoef(j+1)) .le. K/R**j for j .ge. m/2 .
C          (7) = ALPHA - Logarithm of the largest acoef.
C          (8) = BETA - Logarithm of the smallest nonzero acoef.
C     ifail  - integer - the output state parameter, takes one of 6
C                        values:
C           0 => Normal termination, estimated error less than epstol.
C           1 => MMAX < 8.
C           2 => Normal termination, but with estimated error bounds
C                slightly larger than epstol.  Note, however, that the
C                actual errors on the final results may be smaller than
C                epstol as bounds independent of t are pessimistic.
C           3 => The round-off level makes it impossible to achieve the
C                required accuracy.
C           4 => The decay rate of the coefficients is too small.
C                It may improve results to increase mmax.
C           5 => The decay rate of the coefficients is too small and the
C                truncation error too large because of round-off error.
C           6 => No error bounds are returned as the behavior of the
C                coefficients does not enable reasonable prediction.
C                Check the value of sigma0.
C                In this case, (errvec(j),j=1,5) are each set to -1.0.
C         NOTE - When ifail is 3, 4, 5 or 6, changing b and sigma
C                may help.  If not, the method should be abandoned.
C

C06LCF
      SUBROUTINE C06LCF(T,SIGMA,B,M,ACOEF,ERRVEC,FINV,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     C06LCF evaluates, for a specified nonnegative t, the inverse
C     finv of the prescribed Laplace transform using the series below,
C     denoted as SUM, whose coefficients are provided by C06LBF.  The
C     values of sigma and b are those returned by C06LBF.
C
C        finv = exp(sigma*t)*SUM
C
C     where
C
C        SUM = summation of (acoef(j)*exp(-b*t/2)*L(j,b*t),j=1,m),
C        L(j,b*t) denotes the Laguerre polynomial of degree j-1,
C        exp(-b*t/2)*L(j,b*t) is the associated Laguerre function.
C
C     When t is nonpositive, the evaluation approximates
C     the analytic continuation of the inverse Laplace transform,
C     becoming progressively poorer as t becomes more negative.
C
C     Note that this routine is overflow/underflow(destructive) free
C     and can be used even when the value exp(sigma*t) overflows
C     or exp(-bt/2) underflows.
C
C     C06LCF is derived from the subroutine MODUL2 in the package WEEKS
C     by B.S. Garbow, G. Giunta, J.N. Lyness and A. Murli, Algorithm
C     662: A Fortran software package for the numerical inversion of the
C     Laplace Transform based on Weeks' method, ACM Trans. Math.
C     Software, 14, pp 171-176 (1988).
C
C     INPUT arguments
C
C     t      - real - the point where the inverse Laplace transform
C                     is to be computed.
C     m      - integer - the number of terms of the Laguerre expansion.
C     acoef  - real(m) - the coefficients of the Laguerre expansion.
C     sigma  - real - the first parameter of the Laguerre expansion.
C                     It must have the same value as returned by C06LBF.
C     b      - real - the second parameter of the Laguerre expansion.
C                     It must have the same value as returned by C06LBF.
C     errvec - real(8) - the vector of diagnostic information from
C                     C06LBF. Only components 1,7 and 8 are used in
C                     C06LCF. (If C06LCF is used independently of
C                     C06LBF, store ALPHA,BETA into (7),(8) and set
C                     errvec(1) = 0.0 .)
C
C     OUTPUT arguments
C
C     finv   - real - the value of the inverse Laplace transform at t.
C     ifail  - integer - the error indicator.
C           0 => Normal termination.
C           1 => The value of the inverse Laplace transform is found to
C                be too large to be representable - finv is set to 0.0.
C           2 => The value of the inverse Laplace transform is found to
C                be too small to be representable - finv is set to 0.0.
C

D01AHF
      DOUBLE PRECISION FUNCTION D01AHF(A,B,EPR,NPTS,RELERR,F,NL,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 8A REVISED. IER-254 (AUG 1980).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 12B REVISED. IER-525 (FEB 1987).
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C     MARK 14 REVISED. IER-819 (DEC 1989).
C
C     THIS FUNCTION ROUTINE PERFORMS AUTOMATIC INTEGRATION OVER A
C     FINITE INTERVAL USING THE BASIC INTEGRATION ALGORITHMS D01AHY
C     AND D01AHX, TOGETHER WITH, IF NECESSARY, AN ADAPTIVE
C     SUBDIVISION PROCESS.
C
C     INPUT ARGUMENTS
C     ----- ----------
C     A,B     -  LOWER AND UPPER INTEGRATION LIMITS.
C     EPR     -  REQUIRED RELATIVE ACCURACY.
C     NL      -  APPROXIMATE LIMIT ON NUMBER OF INTEGRAND
C                EVALUATIONS. IF SET NEGATIVE OR ZERO THE
C                DEFAULT IS 10000.
C     F       -  THE USER NAMED AND PREPARED FUNCTION  F(X)
C                GIVES THE VALUE OF THE INTEGRAND AT X.
C     IFAIL      INTEGER VARIABLE
C             - 0  FOR HARD FAIL REPORT
C             - 1  FOR SOFT FAIL REPORT
C
C     OUTPUT ARGUMENTS
C     ------ ----------
C     NPTS    -  NUMBER OF INTEGRAND EVALUATIONS USED IN OBTAINING
C                THE RESULT.
C     RELERR  -  ROUGH ESTIMATE OF RELATIVE ACCURACY ACHIEVED.
C     IFAIL   -  VALUE INDICATES THE OUTCOME OF THE INTEGRATION -
C                IFAIL  = 0  CONVERGED
C                IFAIL  = 1  INTEGRAND EVALUATIONS EXCEEDED  NL.
C                            THE RESULT WAS OBTAINED BY CONTINUING
C                            BUT IGNORING ANY NEED TO SUBDIVIDE.
C                            RESULT LIKELY TO BE INACCURATE.
C                IFAIL  = 2  DURING THE SUBDIVISION PROCESS
C                            THE STACK BECAME FULL
C                            (PRESENTLY SET TO HOLD 20
C                            LEVELS OF INFORMATION.  MAY BE
C                            INCREASED BY  ALTERING  ISMAX
C                            AND THE DIMENSIONS OF STACK
C                            AND ISTACK). RESULT IS
C                            OBTAINED BY CONTINUING BUT
C                            IGNORING CONVERGENCE FAILURES
C                            ON INTERVALS  WHICH CANNOT BE
C                            ACCOMMODATED ON THE STACKS.
C                            RESULT LIKELY TO BE
C                            INACCURATE.
C                IFAIL  = 3  INVALID ACCURACY REQUEST.
C
C     THE SUBDIVISION STRATEGY IS AS FOLLOWS -
C     AT EACH STAGE AN INTERVAL IS PRESENTED FOR SUBDIVISION
C     (INITIALLY THE WHOLE INTERVAL). THE POINT OF SUBDIVISION IS
C     DETERMINED BY THE RELATIVE GRADIENT OF THE INTEGRAND
C     AT THE END POINTS (SEE D01AHZ) AND MAY BE IN THE
C     RATIO 1/2, 1/1 OR 2/1.D01AHY IS THEN APPLIED TO EACH
C     SUBINTERVAL.  SHOULD IT FAIL TO CONVERGE ON THE LEFT
C     SUBINTERVAL THE SUBINTERVAL IS STACKED FOR FUTURE
C     EXAMINATION AND THE RIGHT SUBINTERVAL IMMEDIATELY
C     EXAMINED. SHOULD  IT FAIL ON THE RIGHT SUBINTERVAL
C     SUBDIVISION IS IMMEDIATELY PERFORMED AND THE WHOLE
C     PROCESS REPEATED. EACH CONVERGED RESULT IS
C     ACCUMULATED AS THE PARTIAL VALUE OF THE INTEGRAL.
C     WHEN THE LEFT  AND RIGHT SUBINTERVALS BOTH CONVERGE
C     THE INTERVAL LAST STACKED IS SUBDIVIDED AND THE
C     PROCESS REPEATED.
C     A NUMBER OF REFINEMENTS ARE INCLUDED.  ATTEMPTS ARE MADE TO
C     DETECT LARGE VARIATIONS IN THE INTEGRAND AND
C     TRANSFORMATIONS ARE MADE IF ENDPOINT VARIATION IS
C     EXTREME. THIS DEPENDS ON THE RATE OF CONVERGENCE OF
C     D01AHX AND ON THE END POINT RELATIVE GRADIENTS OF THE
C     INTEGRAND FOR THE NON-SUBDIVIDED INTERVAL.  RANDOM
C     TRANSFORMATIONS ARE ALSO APPLIED TO IMPROVE THE
C     RELIABILITY.  THE  RELATIVE ACCURACY REQUESTED ON
C     EACH SUBINTERVAL IS ADJUSTED IN ACCORDANCE WITH ITS
C     LIKELY CONTRIBUTION TO THE TOTAL INTEGRAL.
C

D01AJF
      SUBROUTINE D01AJF(F,A,B,EPSABS,EPSREL,RESULT,ABSERR,WORK,LWORK,
     *                  IWORK,LIWORK,IFAIL)
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.
C
C     D01AJF IS A GENERAL PURPOSE INTEGRATOR WHICH CALCULATES
C     AN APPROXIMATION TO THE INTEGRAL OF A FUNCTION OVER A FINITE
C     INTERVAL (A,B)
C
C     D01AJF ITSELF IS ESSENTIALLY A DUMMY ROUTINE WHOSE FUNCTION IS TO
C     PARTITION THE WORK ARRAYS WORK AND IWORK FOR USE BY D01AJV.
C     WORK IS PARTITIONED INTO 4 ARRAYS EACH OF SIZE LIMIT, WHERE
C     LIMIT = MIN(LWORK/4, LIWORK).
C     IWORK IS A SINGLE ARRAY IN D01AJV OF SIZE LIMIT.
C

D01AKF
      SUBROUTINE D01AKF(F,A,B,EPSABS,EPSREL,RESULT,ABSERR,WORK,LWORK,
     *                  IWORK,LIWORK,IFAIL)
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.
C
C     D01AKF IS AN ADAPTIVE INTEGRATOR, ESPECIALLY SUITED TO
C     STRONGLY OSCILLATORY NON-SINGULAR INTEGRANDS, WHICH CALCULATES
C     AN APPROXIMATION TO THE INTEGRAL OF A FUNCTION OVER A FINITE
C     INTERVAL (A,B)
C
C     D01AKF ITSELF IS ESSENTIALLY A DUMMY ROUTINE WHOSE FUNCTION IS TO
C     PARTITION THE WORK ARRAYS WORK AND IWORK FOR USE BY D01AKV.
C     WORK IS PARTITIONED INTO 4 ARRAYS EACH OF SIZE LIMIT, WHERE
C     LIMIT = MIN(LWORK/4, LIWORK).
C     IWORK IS A SINGLE ARRAY IN D01AKV OF SIZE LIMIT.
C

D01ALF
      SUBROUTINE D01ALF(F,A,B,NPTS,POINTS,EPSABS,EPSREL,RESULT,ABSERR,
     *                  WORK,LWORK,IWORK,LIWORK,IFAIL)
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.
C
C     D01ALF IS A GENERAL PURPOSE INTEGRATOR WHICH CALCULATES AN
C     APPROXIMATION TO THE INTEGRAL OVER THE INTERVAL (A,B) OF A
C     FUNCTION WHICH MAY HAVE A LOCAL SINGULAR BEHAVIOUR AT A
C     FINITE NUMBER OF POINTS WITHIN THE INTEGRATION INTERVAL.
C
C     D01ALF ITSELF IS ESSENTIALLY A DUMMY ROUTINE WHOSE FUNCTION
C     IS TO PARTITION THE WORK ARRAYS WORK AND LWORK FOR USE BY D01ALV.
C     WORK IS PARTITIONED INTO 4 ARRAYS OF SIZE LIMIT, WHERE
C     LIMIT = MIN((LWORK-2*NPTS-4)/4, (LIWORK-NPTS-2)/2) AND
C     2 ARRAYS OF SIZE NPTS + 2. IWORK IS PARTITIONED INTO 2 ARRAYS OF
C     SIZE LIMIT AND 1 ARRAY OF SIZE NPTS + 2.
C

D01AMF
      SUBROUTINE D01AMF(F,BOUND,INF,EPSABS,EPSREL,RESULT,ABSERR,WORK,
     *                  LWORK,IWORK,LIWORK,IFAIL)
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.
C     BASED ON THE QUADPACK ROUTINE  QAGI.
C
C     D01AMF CALCULATES AN APPROXIMATION TO THE INTEGRAL OF A FUNCTION
C     OVER THE INTERVAL (A,B) , WHERE A AND/OR B IS INFINITE.
C
C     D01AMF ITSELF IS ESSENTIALLY A DUMMY ROUTINE WHOSE FUNCTION IS TO
C     PARTITION THE WORK ARRAYS WORK AND IWORK FOR USE BY D01AMV.
C     WORK IS PARTITIONED INTO 4 ARRAYS EACH OF SIZE LIMIT, WHERE
C     LIMIT = MIN(LWORK/4, LIMIT).
C     IWORK IS A SINGLE ARRAY IN D01AMV OF SIZE LIMIT.
C

D01ANF
      SUBROUTINE D01ANF(F,A,B,OMEGA,KEY,EPSABS,EPSREL,RESULT,ABSERR,
     *                  WORK,LWORK,IWORK,LIWORK,IFAIL)
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.
C
C     D01ANF CALCULATES AN APPROXIMATION TO THE COSINE OR SINE
C     TRANSFORM OF A FUNCTION OVER AN INTERVAL (A,B)
C
C     D01ANF ITSELF IS ESSENTIALLY A DUMMY ROUTINE WHOSE FUNCTION
C     IS TO PARTITION THE WORK ARRAYS WORK AND LWORK FOR USE BY
C     D01ANV. WORK IS PARTITIONED INTO 4 ARRAYS EACH OF SIZE LIMIT,
C     WHERE LIMIT = MIN(LWORK/4, LIWORK/2) .
C     IWORK IS PARTITIONED INTO 2 ARRAYS EACH OF SIZE LIMIT.
C
C     MAXP1 - AN UPPER BOUND ON THE NUMBER OF CHEBYSHEV MOMENTS
C             WHICH CAN BE STORED (SEE D01ANV).
C     ICALL - ENABLES THE CHEBYSHEV MOMENTS ALREADY COMPUTED
C             (WITH ICALL = 1) TO BE RE-USED ON SUBSEQUENT CALLS
C             (ICALL > 1) (SEE D01ANV).

D01APF
      SUBROUTINE D01APF(F,A,B,ALFA,BETA,KEY,EPSABS,EPSREL,RESULT,ABSERR,
     *                  WORK,LWORK,IWORK,LIWORK,IFAIL)
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.
C
C     D01APF IS AN ADAPTIVE INTEGRATOR WHICH CALCULATES AN
C     APPROXIMATION TO THE INTEGRAL OF A FUNCTION G(X)W(X) OVER
C     (A,B) WHERE THE WEIGHT FUNCTION W HAS END-POINT
C     SINGULARITIES OF ALGEBRAICO-LOGARITHMIC TYPE.
C
C     D01APF ITSELF IS ESSENTIALLY A DUMMY ROUTINE WHOSE FUNCTION IS TO
C     PARTITION THE WORK ARRAYS WORK AND IWORK FOR USE BY D01APV.
C     WORK IS PARTITIONED INTO 4 ARRAYS EACH OF SIZE LIMIT, WHERE
C     LIMIT = MIN(LWORK/4, LIWORK).
C     IWORK IS A SINGLE ARRAY IN D01APV OF SIZE LIMIT.
C

D01AQF
      SUBROUTINE D01AQF(F,A,B,C,EPSABS,EPSREL,RESULT,ABSERR,WORK,LWORK,
     *                  IWORK,LIWORK,IFAIL)
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.
C
C     D01AQF CALCULATES AN APPROXIMATION TO THE HILBERT TRANSFORM
C     OF A FUNCTION G(X) OVER (A,B)
C
C     D01AQF ITSELF IS ESSENTIALLY A DUMMY ROUTINE WHOSE FUNCTION IS TO
C     PARTITION THE WORK ARRAYS WORK AND IWORK FOR USE BY D01AQV.
C     WORK IS PARTITIONED INTO 4 ARRAYS EACH OF SIZE LIMIT, WHERE
C     LIMIT = MIN(LWORK/4, LIWORK).
C     IWORK IS A SINGLE ARRAY IN D01AQV OF SIZE LIMIT.
C

D01ARF
      SUBROUTINE D01ARF(A,B,F,RELACC,ABSACC,MAXRUL,IPARM,ACC,ANS,N,
     *                  ALPHA,IFAIL)
C     MARK 10 RELEASE. NAG COPYRIGHT 1982.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 13 X02 FUNCTIONS (APR 1988).
C     MARK 13 REVISED. IER-576 (MAR 1988).
C
C     DEFINITE AND INDEFINITE INTEGRATION OVER A FINITE INTERVAL
C
C     THE NUMERICAL INTEGRATION IS PERFORMED USING A SEQUENCE OF
C     RULES BASED ON THE REPEATED OPTIMAL EXTENSIONS OF THE 3-POINT
C     GAUSS RULE (SEE PATTERSON,T.N.L.,MATHS.COMP.,22,847-857,1968).
C     UP TO 9 RULES MAY BE APPLIED USING 1,3,7,15,31,63,127,255 AND
C     511 POINTS OF RESPECTIVE POLYNOMIAL INTEGRATING DEGREE 1,5,11
C     23,47,95,191,383 AND 767. EACH RULE HAS THE INTERLACING
C     PROPERTY THAT THE NEXT IN SEQUENCE INCLUDES ALL THE POINTS OF
C     ITS PREDECESSOR. IN CARRYING OUT THE INTEGRATION THE RESULTS
C     OF SUCCESSIVE RULES ARE COMPARED. WHEN THE LATEST TWO RESULTS
C     DIFFER ABSOLUTELY BY NOT MORE THAN A SPECIFIED TOLERANCE THE
C     RESULT OF THE LAST RULE USED IS TAKEN AS THE VALUE OF THE
C     INTEGRAL. THE PROCEDURE IS NON-ADAPTIVE IN THAT IF THE REQUIRED
C     TOLERANCE IS NOT ACHIEVED AFTER APPLYING ALL RULES NO ATTEMPT
C     IS MADE TO CONTINUE, THE BEST AVAILABLE RESULT IS RETURNED
C     WITH A WARNING.
C
C     THE CALL TO THE SUBROUTINE TAKES THE FORM-
C
C      CALL D01ARF(A,B,F,RELACC,ABSACC,MAXRUL,IPARM,
C                  ACC,ANS,N,ALPHA,IFAIL)
C
C     THE ACTION PERFORMED IS CONTROLLED BY THE PARAMETER IPARM
C     AS FOLLOWS-
C
C     IPARM=0  -THE INTEGRAND F(X) IS INTEGRATED TO A PRESCRIBED
C               ACCURACY OVER THE FINITE INTERVAL A.LE.X.LE.B.
C
C     IPARM=1  -AS FOR IPARM=0 BUT ADDITIONALLY THE EXPANSION OF
C               INTEGRAND OVER THE INTERVAL (A,B) IN LEGENDRE
C               POLYNOMIALS IS CALCULATED USING THE SAME VALUES
C               OF THE INTEGRAND AS USED TO CALCULATE THE INTEGRAL.
C               THE EXPANSION COEFFICIENTS MAY BE USED LATER IN
C               COMPUTING INDEFINITE INTEGRALS.
C
C     IPARM=2  -INDEFINITE INTEGRATION -THE INTEGRAND F(X) IS
C               INTEGRATED ANALYTICALLY OVER THE INTERVAL
C               A.LE.X.LE.B USING THE LEGENDRE EXPANSION OF THE
C               INTEGRAND. NO FURTHER EVALUATIONS OF THE INTEGRAND
C               ARE REQUIRED. THE SUBROUTINE MUST PREVIOUSLY
C               HAVE BEEN CALLED WITH IPARM=1 AND THE INTERVAL
C               (A,B) MUST LIE WITHIN THE INTERVAL PRESCRIBED FOR
C               THAT PREVIOUS CALL.
C
C                    -FORMAL ARGUMENT SPECIFICATIONS-
C
C     INPUT ARGUMENTS-
C
C     A,B        -RESPECTIVE LOWER AND UPPER LIMITS TO THE INTERVAL
C                 OF INTEGRATION. REAL VARIABLES OR CONSTANTS.
C
C     F          -USER SUPPLIED AND DEFINED REAL FUNCTION F(X) TO
C                 CALCULATE THE VALUE OF THE INTEGRAND AT X (REAL
C                 VARIABLE). (IPARM=0 OR 1 ONLY).
C
C     RELACC,    -RESPECTIVE RELATIVE AND ABSOLUTE ACCURACIES
C     ABSACC      REQUIRED. THE REQUIRED ACCURACY IS ASSUMED TO HAVE
C                 BEEN ACHIEVED WHEN THE RESULTS OF TWO SUCCESSIVE
C                 RULES DIFFER ABSOLUTELY BY NOT MORE THAN
C                         AMAX1(ABS(ABSACC),ABS(RELACC*ANS))
C                 WHERE ANS IS THE RESULT OBTAINED BY THE LAST RULE
C                 USED. IF BOTH RELACC AND ABSACC ARE ZERO THEN
C                 RELACC IS ASSUMED TO HAVE VALUE 10.0*EPMACH, WHERE
C                 EPMACH IS THE SMALLEST POSITIVE REAL NUMBER SUCH
C                 THAT
C                            1.0+EPMACH .GT. 1.0
C                 TO MACHINE ACCURACY. IF ALL RULES ARE EXHAUSTED
C                 WITHOUT ACHIEVING THE REQUIRED ACCURACY, ERROR
C                 IFAIL=1 IS RAISED AND ANS IS SET TO THE VALUE
C                 OBTAINED BY THE LAST RULE AS THE BEST
C                 APPROXIMATION POSSIBLE. REAL VARIABLES OR
C                 CONSTANTS.
C                 (IPARM=0 OR 1 ONLY).
C
C     MAXRUL     -MAXIMUM NUMBER OF SUCCESSIVE RULES TO BE USED.
C                 1.LE.MAXRUL.LE.9. IF OUTSIDE THESE LIMITS MAXRUL
C                 DEFAULTS TO THE VALUE 9. INTEGER VARIABLE OR
C                 CONSTANT. (IPARM=0 OR 1 ONLY).
C
C     IPARM      -THIS CONTROLS THE ACTION OF THE SUBROUTINE AND IS
C                 SET TO ONE OF THE THREE POSSIBLE VALUES 0,1 OR 2.
C                 IPARM=0  EVALUATES THE INTEGRAL ONLY.
C                      =1  EVALUATES THE INTEGRAL AND THE EXPANSION
C                          OF THE INTEGRAND IN LEGENDRE POLYNOMIALS.
C                      =2  CARRIES OUT INDEFINITE INTEGRATION.
C                          IN THIS CASE ONLY THE ARGUMENTS A,B,
C                          IPARM, ANS, ALPHA AND IFAIL ARE RELEVANT
C                          WITH THE OTHERS SUPPLIED SIMPLY AS DUMMY
C                          ARGUMENTS.
C                          INTEGER VARIABLE OR CONSTANT.
C                 FULLER DETAILS ON IPARM HAVE BEEN GIVEN EARLIER.
C
C     ALPHA      -REAL ARRAY
C                 THIS ARRAY SHOULD HAVE BEEN GENERATED BY A
C                 PREVIOUS CALL WITH IPARM=1.  CONTENTS AS DESCRIBED
C                 UNDER OUTPUT ARGUMENTS BELOW.
C                 (IPARM=2 ONLY)
C
C     IFAIL      -NAG ERROR CONTROL. INTEGER VARIABLE.
C                 IFAIL=0  HARD FAIL.
C                      =1  SOFT FAIL.
C
C
C     OUTPUT ARGUMENTS-
C
C     ACC        -ESTIMATED ABSOLUTE ERROR IN RESULT. THIS IS TAKEN
C                 AS THE VALUE OF THE ABSOLUTE DIFFERENCE BETWEEN
C                 THE RESULTS OF THE LAST TWO RULES USED.
C                 REAL VARIABLE. (IPARM=0 OR 1 ONLY).
C
C     ANS        -APPROXIMATE VALUE OF THE INTEGRAL. REAL VARIABLE.
C
C     N          -NUMBER OF EVALUATIONS OF THE INTEGRAND USED.
C                 INTEGER VARIABLE. (IPARM=0 OR 1 ONLY).
C
C     ALPHA      -REAL ARRAY
C                 THIS ARRAY CONTAINS
C                 ALPHA(1) TO ALPHA(NPTS) = THE NPTS COEFFICIENTS OF
C                 THE APPROXIMATION TO F(X) OVER (A,B) GIVEN BY-
C
C                 F(X) = SUM( I=1 TO NPTS ) ALPHA(I)*P(I-1,T)
C
C                 WHERE X = (B+A+(B-A)*T)/2 AND P(I,T) IS THE
C                 LEGENDRE POLYNOMIAL OF DEGREE I OVER (-1,1). THIS
C                 APPROXIMATION IS INTEGRATED TO OBTAIN THE VALUE OF
C                 THE INDEFINITE INTEGRAL.
C                 NPTS=3*(N+1)/4 FOR N=1,3 OR 7
C                 NPTS=3*N/4 OTHERWISE.
C
C                 ALPHA ALSO HOLDS THE FOLLOWING INFORMATION
C                 REQUIRED FOR CALLS FOR INDEFINITE INTEGRATION
C                 ALPHA(390)=NPTS
C                 ALPHA(389)=1 IF ALPHA USABLE FOR INDEF INTEGRATION
C                               (IE. IPARM=1 AND RANGE NON-TRIVIAL)
C                           =0 OTHERWISE
C                 ALPHA(388)=IFAIL (IF ALPHA(389)=1)
C                            UNDEFINED OTHERWISE
C                 ALPHA(387)=B
C                 ALPHA(386)=A
C                 ALPHA SHOULD BE DECLARED IN THE CALLING
C                 PROGRAM TO HAVE AT LEAST 390 ELEMENTS.
C                 (IPARM=1 ONLY)
C                 ALPHA IS UNCHANGED WHEN IPARM=2
C
C     IFAIL      -REPORTS ERRORS AS FOLLOWS- (INTEGER VARIABLE)
C                 IFAIL=0  NO ERRORS DETECTED.
C                      =1  ALL MAXRUL RULES HAVE BEEN APPLIED
C                          WITHOUT ACHIEVING THE REQUIRED ACCURACY.
C                          ANS IS SET TO THE VALUE OBTAINED BY THE
C                          LAST RULE USED.
C                      =2  IPARM FAILS TO SATISFY 0.LE.IPARM.LE.2.
C                      =3  SUBROUTINE HAS BEEN CALLED WITH IPARM=2
C                          BUT A PREVIOUS CALL WITH IPARM=1 HAS BEEN
C                          OMITTED OR WAS INVOKED WITH AN
C                          INTEGRATION INTERVAL OF LENGTH ZERO.
C                          (IPARM=2 ONLY).
C                      =4  THE INTERVAL FOR INDEFINITE INTEGRATION
C                          IS NOT CONTAINED WITHIN THE INTERVAL
C                          SPECIFIED WHEN THE SUBROUTINE WAS
C                          PREVIOUSLY CALLED WITH IPARM=1.
C                          (IPARM=2 ONLY).
C

D01ASF
      SUBROUTINE D01ASF(F,A,OMEGA,KEY,EPSABS,RESULT,ABSERR,LIMLST,LST,
     *                  ERLST,RSLST,IERLST,WORK,LWORK,IWORK,LIWORK,
     *                  IFAIL)
C     MARK 13 RELEASE.  NAG COPYRIGHT 1988.
C
C     D01ASF CALCULATES AN APPROXIMATION TO THE COSINE OR SINE
C     TRANSFORM OF A FUNCTION OVER AN INTERVAL (A,INFINITY)
C
C     D01ASF ITSELF IS ESSENTIALLY A DUMMY ROUTINE WHOSE FUNCTION
C     IS TO PARTITION THE WORK ARRAYS WORK AND LWORK FOR USE BY
C     D01ASV. WORK IS PARTITIONED INTO 4 ARRAYS EACH OF SIZE LIMIT,
C     WHERE LIMIT = MIN(LWORK/4, LIWORK/2).
C     IWORK IS PARTITIONED INTO 2 ARRAYS EACH OF SIZE LIMIT.
C
C     MAXP1 - AN UPPER BOUND ON THE NUMBER OF CHEBYSHEV MOMENTS
C             WHICH CAN BE STORED, WHERE MAXP1.GE.1 (SEE D01ASV).

D01ATF
      SUBROUTINE D01ATF(F,A,B,EPSABS,EPSREL,RESULT,ABSERR,WORK,LWORK,
     *                  IWORK,LIWORK,IFAIL)
C     MARK 13 RELEASE.  NAG COPYRIGHT 1988.
C     MARK 13B REVISED. IER-653 (AUG 1988).
C
C     D01ATF IS A GENERAL PURPOSE INTEGRATOR WHICH CALCULATES
C     AN APPROXIMATION TO THE INTEGRAL OF A FUNCTION OVER A FINITE
C     INTERVAL (A,B)
C
C     D01ATF ITSELF IS ESSENTIALLY A DUMMY ROUTINE WHOSE FUNCTION IS TO
C     PARTITION THE WORK ARRAYS WORK AND IWORK FOR USE BY D01ATV.
C     WORK IS PARTITIONED INTO 4 ARRAYS EACH OF SIZE LIMIT, WHERE
C     LIMIT = MIN(LWORK/4, LIWORK).
C     IWORK IS A SINGLE ARRAY IN D01ATV OF SIZE LIMIT.
C

D01AUF
      SUBROUTINE D01AUF(F,A,B,KEY,EPSABS,EPSREL,RESULT,ABSERR,WORK,
     *                  LWORK,IWORK,LIWORK,IFAIL)
C     MARK 13 RELEASE.  NAG COPYRIGHT 1988.
C
C     D01AUF IS AN ADAPTIVE INTEGRATOR, ESPECIALLY SUITED TO
C     STRONGLY OSCILLATORY NON-SINGULAR INTEGRANDS, WHICH CALCULATES
C     AN APPROXIMATION TO THE INTEGRAL OF A FUNCTION OVER A FINITE
C     INTERVAL (A,B)
C
C     D01AUF ITSELF IS ESSENTIALLY A DUMMY ROUTINE WHOSE FUNCTION IS TO
C     PARTITION THE WORK ARRAYS WORK AND IWORK FOR USE BY D01AUV.
C     WORK IS PARTITIONED INTO 4 ARRAYS EACH OF SIZE LIMIT, WHERE
C     LIMIT = MIN(LWORK/4, LIWORK).
C     IWORK IS A SINGLE ARRAY IN D01AUV OF SIZE LIMIT.
C

D01BAF
      DOUBLE PRECISION FUNCTION D01BAF(WTFUN,A,B,NPTS,FUN,IFAIL)
C     MARK 7 RELEASE. NAG COPYRIGHT 1978.
C     MARK 8A REVISED. IER-250 (JULY 1980).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     EVALUATES INTEGRAL OF FUNCTION FUN BY NPTS GAUSS FORMULA OF
C     TYPE WTFUN
C     IFAIL = 1 - THE NPTS RULE IS NOT AMONG THOSE STORED
C     ( ANSWER EVALUATED FOR LARGEST VALID NPTS LESS THAN REQUESTED
C     VALUE)
C     IFAIL = 2 - VALUES OF A OR B INVALID
C     ( ANSWER RETURNED AS ZERO)
C
C     WTFUN

D01BBF
      SUBROUTINE D01BBF(WTFUN,A,B,ITYPE,NPTS,WEIGHT,ABSCIS,IFAIL)
C     MARK 7 RELEASE. NAG COPYRIGHT 1978.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     RETURNS WEIGHTS AND PIVOTS FOR ONE GAUSS-WTFUN FORMULA IF
C     STORED
C     IFAIL = 1 - THE NPTS RULE IS NOT AMONG THOSE STORED
C     ( WEIGHT,ABSCIS EVALUATED FOR LARGEST VALID NPTS LESS THAN
C     REQUESTED VALUE)
C     IFAIL = 2 - VALUES OF A OR B INVALID
C     ( ALL WEIGHTS AND ABSCISSAE RETURNED AS ZERO)
C     IFAIL = 3 - UNDERFLOW IN EVALUATING LAGUERRE OR HERMITE
C     NORMAL WEIGHTS
C     ( THE UNDERFLOWING WEIGHTS ARE RETURNED AS ZERO)
C
C     THE WEIGHTS AND ABSCISSAE RETURNED DEPEND ON A AND B.
C
C     WTFUN

D01BCF
      SUBROUTINE D01BCF(ITYPE,AA,BB,CC,DD,NPNTS,WEIGHT,ABSCIS,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 9C REVISED. IER-370 (JUN 1982).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C     MARK 14A REVISED. IER-677 (DEC 1989).
C     MARK 14B REVISED. IER-840 (MAR 1990).
C     SUBROUTINE FOR THE DETERMINATION OF GAUSSIAN QUADRATURE RULES
C     **************************************************************
C
C     INPUT PARAMETERS
C
C     ITYPE  INTEGER WHICH SPECIFIES THE RULE TYPE CHOSEN
C               WEIGHT W(X)          INTERVAL     RESTRICTIONS
C     0            1                    A,B          B.GT.A
C     1    (B-X)**C*(X-A)**D            A,B     B.GT.A,C,D.GT.-1
C     2   ABS(X-0.5*(A+B))**C           A,B     C.GT.-1,B.GT.A
C     3  ABS(X-A)**C*EXP(-B*X)          A,INF   C.GT.-1,B.GT.0
C     3  ABS(X-A)**C*EXP(-B*X)       -INF,A     C.GT.-1,B.LT.0
C     4 ABS(X-A)**C*EXP(-B*(X-A)**2) -INF,INF   C.GT.-1,B.GT.0
C     5  ABS(X-A)**C/ABS(X+B)**D      A,INF A.GT.-B,C.GT.-1,D.GT.C+1
C     5  ABS(X-A)**C/ABS(X+B)**D     -INF,A A.LT.-B,C.GT.-1,D.GT.C+1
C     ABS(ITYPE) MUST BE LESS THAN 6. IF ITYPE IS GIVEN LESS THAN
C     ZERO THEN THE ADJUSTED WEIGHTS ARE CALCULATED. IF NPNTS IS
C     ODD AND ITYPE EQUALS -2 OR -4 AND C IS NOT ZERO, THERE MAY BE
C     PROBLEMS.
C
C     AA     REAL PARAMETER USED TO SPECIFY RULE TYPE.  SEE ITYPE.
C
C     BB     REAL PARAMETER USED TO SPECIFY RULE TYPE.  SEE ITYPE.
C
C     CC     REAL PARAMETER USED TO SPECIFY RULE TYPE.  SEE ITYPE.
C
C     DD     REAL PARAMETER USED TO SPECIFY RULE TYPE.  SEE ITYPE.
C
C     IFAIL  NAG FAILURE PARAMETER.  SEE NAG DOCUMENTATION.
C
C     NPNTS  INTEGER THAT DETERMINES DIMENSION OF WEIGHT AND ABSCIS
C
C     OUTPUT PARAMETERS
C
C     WEIGHT  REAL ARRAY OF DIMENSION NPNTS WHICH CONTAINS
C     RULE WEIGHTS
C
C     ABSCIS  REAL ARRAY OF DIMENSION NPNTS WHICH CONTAINS
C     RULE ABSCISSAE
C
C     IFAIL INTEGER NAG FAILURE PARAMETER
C       IFAIL=0 FOR NORMAL EXIT
C       IFAIL=1 FOR FAILURE IN NAG ROUTINE F02AVF
C       IFAIL=2 FOR PARAMETER NPNTS OR ITYPE OUT OF RANGE
C       IFAIL=3 FOR PARAMETER AA OR BB OR CC OR DD OUT OF
C               ALLOWED RANGE
C       IFAIL=4 FOR OVERFLOW IN CALCULATION OF WEIGHTS
C       IFAIL=5 FOR UNDERFLOW IN CALCULATION OF WEIGHTS
C       IFAIL=6 FOR ITYPE=-2 OR -4, NPNTS ODD, C NOT ZERO
C
C     **************************************************************

D01BDF
      SUBROUTINE D01BDF(F,A,B,EPSABS,EPSREL,RESULT,ABSERR)
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.
C     BASED ON QUADPACK ROUTINE  QNG.

D01DAF
      SUBROUTINE D01DAF(YA,YB,PHI1,PHI2,F,ABSACC,ANS,NPTS,IFAIL)
C
C     EVALUATES A DOUBLE INTEGRAL BY REPEATED APPLICATIONS
C     OF PATTERSON'S METHOD.
C     NAG COPYRIGHT 1975
C     MARK 5 RELEASE
C     MARK 7 REVISED IER-138 (DEC 1978)
C     MARK 11.5(F77) REVISED. (SEPT 1985.)

D01EAF
      SUBROUTINE D01EAF(NDIM,A,B,MINCLS,MAXCLS,NFUN,FUNSUB,ABSREQ,
     *                  RELREQ,LENWRK,WORK,FINEST,ABSEST,IFAIL)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C
C     ADAPTIVE MULTIDIMENSIONAL INTEGRATION SUBROUTINE
C
C      AUTHOR - ALAN GENZ, COMPUTER SCIENCE DEPARTMENT,
C               WASHINGTON STATE UNIVERSITY,
C               PULLMAN, WASHINGTON  99164
C
C     THIS SUBROUTINE COMPUTES AN APPROXIMATION TO THE INTEGRAL
C
C      B(1) B(2)     B(NDIM)
C     I    I    ... I       (F ,F ,...,F    ) DX(NDIM)...DX(2)DX(1),
C      A(1) A(2)     A(NDIM)  1  2      NFUN
C
C       WHERE F = F (X ,X ,...,X    ), I = 1,2,...,NFUN.
C              I   I  1  2      NDIM
C
C     *********  PARAMETERS FOR D01EAF  *******************************
C     INPUT PARAMETERS
C     NDIM    NUMBER OF VARIABLES
C     A       REAL ARRAY OF LOWER LIMITS, WITH DIMENSION(NDIM)
C     B       REAL ARRAY OF UPPER LIMITS, WITH DIMENSION(NDIM)
C     MINCLS  MINIMUM NUMBER OF FUNSUB CALLS TO BE ALLOWED,
C             MINCLS MUST NOT EXCEED MAXCLS.  IF MINCLS.LT.0 THEN THE
C             ROUTINE ASSUMES A PREVIOUS CALL HAS BEEN MADE WITH THE
C             SAME INTEGRANDS AND CONTINUES THAT CALCULATION.
C     MAXCLS  MAXIMUM NUMBER OF FUNSUB CALLS TO BE ALLOWED,
C             WHICH MUST BE AT LEAST IRCLS, WHERE
C             IRCLS =  2**NDIM+2*NDIM**2+2*NDIM+1, IF NDIM .LT. 11 OR
C             IRCLS = 1+NDIM*(12+(NDIM-1)*(6+(NDIM-2)*4))/3, OTHERWISE.
C     NFUN    NUMBER OF INTEGRANDS
C     FUNSUB  EXTERNALLY DECLARED USER DEFINED INTEGRAND SUBROUTINE
C             IT MUST HAVE PARAMETERS (NDIM,Z,NFUN,F), WHERE Z IS A REAL
C             ARRAY OF DIMENSION(NDIM) AND F IS A REAL ARRAY OF
C             DIMENSION (NFUN). F(I) MUST GIVE THE VALUE OF INTEGRAND
C             I AT Z.
C     ABSREQ  REQUIRED ABSOLUTE ACCURACY
C     RELREQ  REQUIRED RELATIVE ACCURACY
C     LENWRK  LENGTH OF ARRAY WORK OF WORKING STORAGE, THE ROUTINE
C             NEEDS LENWRK AT LEAST AS LARGE AS 8*NDIM + 11*NFUN + 3.
C             FOR MAXIMUM EFFICIENCY LENWRK SHOULD BE APPROXIMATELY
C             6*NDIM+9*NFUN+(NDIM+NFUN+2)*(1+MAXCLS/IRCLS) IF
C             MAXCLS FUNCTION CALLS ARE USED. IF LENWRK IS SIGNIFICANTLY
C             LESS THAN THIS D01EAF WILL WORK LESS EFFICIENTLY.
C
C     OUTPUT PARAMETERS
C     MINCLS  ACTUAL NUMBER OF FUNSUB CALLS USED BY D01EAF
C     WORK    REAL ARRAY OF WORKING STORAGE OF DIMENSION (LENWRK).
C     FINEST  REAL ARRAY OF DIMENSION(NFUN) OF ESTIMATED VALUES OF
C             INTEGRALS.
C     ABSEST  REAL ARRAY DIMENSION(NFUN) ESTIMATED ABSOLUTE ACCURACIES.
C             ABSEST(I) GIVES THE ESTIMATED ACCURACY FOR FINEST(I).
C     IFAIL   FAILURE INDICATOR
C             IFAIL=0 FOR NORMAL EXIT, WHEN MAX(ABSEST) .LE. ABSREQ OR
C                     MAX(ABSEST) .LE. MAX(ABS(FINEST))*RELREQ WITH
C                     MAXCLS OR LESS FUNSUB CALLS MADE.
C             IFAIL=1 IF MAXCLS WAS TOO SMALL FOR D01EAF TO OBTAIN THE
C                     REQUIRED RELATIVE ACCURACY EPS.  IN THIS CASE
C                     D01EAF RETURNS VALUES OF FINEST WITH ESTIMATED
C                     ABSOLUTE ACCURACIES ABSEST.
C             IFAIL=2 IF LENWRK TOO SMALL FOR MAXCLS FUNCTION CALLS.
C                     IN THIS CASE D01EAF RETURNS VALUES OF FINEST WITH
C                     ESTIMATED ACCURACIES ABSEST USING THE WORKING
C                     STORAGE AVAILABLE.
C             IFAIL=3 RE-ENTRY WITH MAXCLS TOO SMALL TO MAKE ANY
C                     PROGRESS
C             IFAIL=4 IF MINCLS .GT. MAXCLS OR MAXCLS .LT. IRCLS
C                     OR LENWRK .LT. 8*NDIM + 11*NFUN + 3.
C     ******************************************************************
C

D01FBF
      DOUBLE PRECISION FUNCTION D01FBF(NDIM,NPTVEC,LWA,WEIGHT,ABSCIS,
     *                                 FUN,IFAIL)
C     ***   MULTIDIMENSIONAL INTEGRATION RULE EVALUATION
C     **************************************************************
C
C       INPUT PARAMETERS
C     NDIM  INTEGER WHICH SPECIFIES THE NUMBER OF VARIABLES
C           NDIM MUST BE GREATER THAN ONE AND LESS THAN 21.
C     NPTVEC INTEGER ARRAY OF DIMENSION NDIM. NPTVEC(J) SPECIFIES
C           THE NUMBER OF FUNCTION EVALUATION POINTS IN THE
C           INTEGRATION RULE FOR VARIABLE J.
C     LWA   INTEGER WHICH SPECIFIES THE DIMENSION OF THE ARRAYS
C           WEIGHT AND ABSCIS. LWA .GE. THE SUM OF THE COMPONENTS
C           OF NPTVEC.
C     WEIGHT  REAL ARRAY OF DIMENSION LWA.  THIS ARRAY MUST
C           CONTAIN ALL THE INTEGRATION RULE WEIGHTS IN
C           THE CORRECT ORDER.
C     ABSCIS REAL ARRAY OF DIMENSION LWA. THIS ARRAY MUST
C           CONTAIN ALL THE INTEGRATION RULE ABSCISSAE IN
C           THE CORRECT ORDER.
C     FUN    EXTERNALLY DECLARED USER DEFINED INTEGRAND
C           WHICH MUST HAVE PARAMETERS NDIM AND A REAL
C           ARRAY OF DIMENSION NDIM.
C     IFAIL INTEGER NAG FAILURE PARAMETER.  SEE NAG DOCUMENTATION.
C           ON ENTRY IFAIL SHOULD ALWAYS BE SET TO ZERO
C
C       OUTPUT PARAMETERS
C     D01FBF REAL VALUE WHICH GIVES THE VALUE OF THE
C           INTEGRATION RULE WHEN APPLIED TO THE INTEGRAND
C           FUN.
C     IFAIL  INTEGER NAG FAILURE PARAMETER
C           IFAIL=0 FOR NORMAL EXIT
C           IFAIL=1 IF NDIM.LT.1 OR NDIM.GT.20 OR LWA TOO SMALL
C     **************************************************************

D01FCF
      SUBROUTINE D01FCF(NDIM,A,B,MINPTS,MAXPTS,FUNCTN,EPS,ACC,LENWRK,
     *                  WRKSTR,FINVAL,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 10B REVISED. IER-399 (JAN 1983).
C     MARK 11C REVISED. IER-464 (MAR 1985).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 12A REVISED. IER-498 (AUG 1986).
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C
C     ADAPTIVE MULTIDIMENSIONAL INTEGRATION SUBROUTINE
C
C     *********  PARAMETERS FOR D01FCF  ****************************
C
C      INPUT PARAMETERS
C
C     NDIM    INTEGER NUMBER OF VARIABLES, MUST EXCEED 1 BUT
C             NOT EXCEED 15.
C
C     A       REAL ARRAY OF LOWER LIMITS, WITH DIMENSION NDIM
C
C     B       REAL ARRAY OF UPPER LIMITS, WITH DIMENSION NDIM
C
C     MINPTS  INTEGER MINIMUM NUMBER OF INTEGRAND VALUES TO BE
C             ALLOWED, WHICH MUST NOT EXCEED MAXPTS.
C
C     MAXPTS  INTEGER MAXIMUM NUMBER OF INTEGRAND VALUES TO BE
C             ALLOWED, WHICH MUST BE AT LEAST
C             2**NDIM+2*NDIM**2+2*NDIM+1.
C
C     FUNCTN  EXTERNALLY DECLARED USER DEFINED REAL FUNCTION
C             INTEGRAND. IT MUST HAVE PARAMETERS (NDIM,Z),
C             WHERE Z IS A REAL ARRAY OF DIMENSION NDIM.
C
C     EPS     REAL REQUIRED RELATIVE ACCURACY, MUST BE GREATER
C             THAN ZERO
C
C     LENWRK  INTEGER LENGTH OF ARRAY WRKSTR, MUST BE AT LEAST
C             2*NDIM+4.
C
C     IFAIL   INTEGER NAG FAILURE PARAMETER
C             IFAIL=0 FOR HARD FAIL
C             IFAIL=1 FOR SOFT FAIL
C
C      OUTPUT PARAMETERS
C
C     MINPTS  INTEGER NUMBER OF INTEGRAND VALUES USED BY THE
C             ROUTINE
C
C     WRKSTR  REAL ARRAY OF WORKING STORAGE OF DIMENSION (LENWRK).
C
C     ACC     REAL ESTIMATED RELATIVE ACCURACY OF FINVAL
C
C     FINVAL  REAL ESTIMATED VALUE OF INTEGRAL
C
C     IFAIL   IFAIL=0 FOR NORMAL EXIT, WHEN ESTIMATED RELATIVE
C                  LESS INTEGACCURACY RAND VALUES USED.
C
C          IFAIL=1 IF NDIM.LT.2, NDIM.GT.15, MINPTS.GT.MAXPTS,
C                  MAXPTS.LT.2**NDIM+2*NDIM*(NDIM+1)+1, EPS.LE.0
C                  OR LENWRK.LT.2*NDIM+4.
C
C          IFAIL=2 IF MAXPTS WAS TOO SMALL FOR D01FCF TO OBTAIN THE
C                  REQUIRED RELATIVE ACCURACY EPS.  IN THIS
C                  CASE D01FCF RETURNS A VALUE OF FINVAL
C                  WITH ESTIMATED RELATIVE ACCURACY ACC.
C
C          IFAIL=3 IF LENWRK TOO SMALL FOR MAXPTS INTEGRAND
C                  VALUES.  IN THIS CASE D01FCF RETURNS A
C                  VALUE OF FINVAL WITH ESTIMATED ACCURACY
C                  ACC USING THE WORKING STORAGE
C                  AVAILABLE, BUT ACC WILL BE GREATER
C                  THAN EPS.
C
C     **************************************************************
C

D01FDF
      SUBROUTINE D01FDF(N,F,SIGMA,REGION,LIMIT,R0,U,RESULT,NPTS,IFAIL)
C     MARK 10 RELEASE. NAG COPYRIGHT 1982.
C     MARK 10C REVISED. IER-425 (JUL 1983).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C
C     MULTIPLE INTEGRATION
C
C     THIS SUBROUTINE CALCULATES AN APPROXIMATION TO-
C        D1      DN
C        I ......I F(X1,...,XN) DX1 .. DXN        (SIGMA .LT. 0)
C        C1      CN
C
C      OR
C
C        I ......I F(X1,...,XN) DX1 .. DXN        (SIGMA .GE. 0)
C     N-SPHERE RADIUS SIGMA
C
C     MULTIPLE INTEGRATION BASED ON THE METHOD OF SAG AND SZEKERES,
C     NUMERICAL EVALUATION OF HIGH DIMENSIONAL INTEGRALS -
C     MATHS.COMP. V18,245-253,1964.
C
C     INPUT ARGUMENTS
C     ----- ----------
C
C      N     - INTEGER NUMBER OF DIMENSIONS (1 .LE. N .LE. 30)
C      F     - EXTERNALLY DECLARED REAL USER FUNCTION INTEGRAND
C              HAVING ARGUMENTS (N,X) WHERE X IS A REAL ARRAY
C              OF DIMENSION N WHOSE ELEMENTS ARE THE VARIABLE
C              VALUES.
C      SIGMA - THIS DETERMINES THE DOMAIN OF INTEGRATION AS FOLLOWS
C              (A) SIGMA .LT. 0.
C              THE INTEGRATION IS CARRIED OUT OVER THE PRODUCT
C              REGION DETERMINED BY THE USER SUPPLIED SUBROUTINE
C              REGION.
C              (B) SIGMA .GE. 0.
C              THE INTEGRATION IS CARRIED OUT OVER THE N-SPHERE
C              OF RADIUS SIGMA. IN THIS CASE SUBROUTINE REGION IS
C              NOT CALLED AND IS SIMPLY SUPPLIED AS A DUMMY ROUTINE.
C      REGION- EXTERNALLY DECLARED USER SUBROUTINE WITH ARGUMENTS
C              (N,X,J,C,D) WHICH CALCULATES THE LOWER LIMIT C
C              AND THE UPPER LIMIT D CORRESPONDING TO THE ARRAY
C              VARIABLE X(J). C AND D MAY DEPEND ON X(1)..X(J-1).
C      LIMIT - APPROXIMATE NO. OF INTEGRAND EVALUATIONS TO BE USED.
C              IT MUST BE GREATER THAN 100. IN VERY LOW DIMENSIONS
C              IT MAY NOT BE POSSIBLE TO ATTAIN THIS AS AN UPPER
C              LIMIT DUE TO INTERNAL STORAGE LIMITATIONS (YY(30)).
C      R0    - ADJUSTABLE PARAMETER, TYPICAL VALUE 0.8,
C              (0 .LT. R0 .LE. 1)
C      U     - ADJUSTABLE PARAMETER, TYPICAL VALUE 1.5,(U .GT. 0)
C      IFAIL - INTEGER, NAG FAILURE PARAMETER
C              IFAIL=0, HARD FAIL
C              IFAIL=1, SOFT FAIL
C
C     OUTPUT ARGUMENTS
C     ------ ----------
C
C      RESULT- APPROXIMATE VALUE OF INTEGRAL
C      NPTS  - ACTUAL NUMBER OF INTEGRAND EVALUATIONS.
C      IFAIL - IFAIL=0, NORMAL EXIT
C              IFAIL=1, INVALID N VALUE (N .GT. 30)
C              IFAIL=2, INVALID LIMIT VALUE
C              IFAIL=3, INVALID R0 VALUE
C              IFAIL=4, INVALID U VALUE
C
C     REGION

D01GAF
      SUBROUTINE D01GAF(X,Y,N,ANS,ER,IFAIL)
C
C     THIS SUBROUTINE INTEGRATES A FUNCTION (Y) SPECIFIED
C     NUMERICALLY AT N POINTS (X), WHERE N IS AT LEAST 4,
C     OVER THE RANGE X(1) TO X(N).  THE POINTS NEED NOT BE
C     EQUALLY SPACED, BUT SHOULD BE DISTINCT AND IN ASCENDING
C     OR DESCENDING ORDER.  AN ERROR ESTIMATE IS RETURNED.
C     THE METHOD IS DUE TO GILL AND MILLER.
C
C     NAG COPYRIGHT 1975
C     MARK 5 RELEASE
C     MARK 7 REVISED IER-154 (DEC 1978)
C     MARK 11.5(F77) REVISED. (SEPT 1985.)

D01GBF
      SUBROUTINE D01GBF(NUMVAR,A,B,MINPTS,MAXPTS,FUNCTN,RELEPS,RELERR,
     *                  LENWRK,WRKSTR,FINVAL,IFAIL)
C     MARK 10 RELEASE. NAG COPYRIGHT 1982.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     ADAPTIVE MONTE-CARLO MULTIDIMENSIONAL INTEGRATION SUBROUTINE
C     THIS SUBROUTINE COMPUTES AN APPROXIMATION TO THE INTEGRAL
C
C      B(1) B(2)     B(NUMVAR)
C     I    I    ... I   FUNCTN(NUMVAR,X) DX(NUMVAR)...DX(2)DX(1)
C      A(1) A(2)     A(NUMVAR)
C
C     ***** INPUT PARAMETERS
C
C     NUMVAR  INTEGER NUMBER OF VARIABLES, MUST EXCEED 0
C     A       REAL ARRAY OF LOWER LIMITS, WITH DIMENSION NUMVAR
C     B       REAL ARRAY OF UPPER LIMITS, WITH DIMENSION NUMVAR
C     MINPTS  INTEGER MINIMUM NUMBER OF FUNCTION EVALUATIONS TO BE
C             ALLOWED. MINPTS MUST BE LESS THAN MAXPTS.
C             IF MINPTS IS NEGATIVE, THIS SPECIFIES
C              A)A CONTINUATION OF THE PREVIOUS CALCULATION USING
C                THE SAME INTEGRAND, OR
C              B)THE BEGINNING OF A NEW CALCULATION WITH A SIMILAR
C                INTEGRAND BUT USING THE SUBDIVISION THAT WAS USED
C                AT THE END OF THE PREVIOUS CALL OF D01GBF
C     MAXPTS  INTEGER MAXIMUM NUMBER OF FUNCTION EVALUATIONS TO BE
C             ALLOWED, WHICH MUST EXCEED MINPTS AND MUST BE AT LEAST
C             4*NUMVAR+4. IN THE CONTINUATION CASE THIS IS THE
C             NUMBER OF NEW FUNCTION EVALUATIONS TO BE ALLOWED.
C     FUNCTN  REAL EXTERNALLY DECLARED USER DEFINED FUNCTION
C             INTEGRAND. IT MUST HAVE PARAMETERS (NUMVAR,X), WHERE X
C             IS A REAL ARRAY OF DIMENSION NUMVAR.
C     RELEPS  REAL REQUIRED RELATIVE ACCURACY
C     LENWRK  INTEGER LENGTH OF ARRAY WRKSTR OF WORKING STORAGE,
C             WHICH MUST BE AT LEAST 10*NUMVAR WITH RECOMMENDED
C             VALUE 3*NUMVAR*((MAXPTS/4)**(1/NUMVAR))+7*NUMVAR
C     WRKSTR  REAL ARRAY OF WORKING STORAGE OF DIMENSION(LENWRK).
C             WHEN MINPTS IS SET NEGATIVE FOR CASE B), THEN
C             WRKSTR(LENWRK) MUST BE SET TO ZERO.  IN CASES A) AND
C             B) OTHER VALUES OF WRKSTR MUST NOT BE CHANGED BETWEEN
C             SUCCESSIVE CALLS.
C     IFAIL   INTEGER NAG FAILURE PARAMETER
C
C     ***** OUTPUT PARAMETERS
C
C     WRKSTR  REAL ARRAY OF WORKING STORAGE OF DIMENSION (LENWRK),
C             ON EXIT THIS CONTAINS INFORMATION WHICH COULD BE USED
C             IN LATER CALLS OF D01GBF WITH THE SAME OR A SIMILAR
C             INTEGRAND.
C     RELERR  REAL ESTIMATED RELATIVE ACCURACY OF FINVAL
C     FINVAL  REAL ESTIMATED VALUE OF INTEGRAL.  IN THE CONTINUATION
C             CASE A FINVAL MUST NOT BE CHANGED BETWEEN SUCCESSIVE
C             CALLS.
C     IFAIL   IFAIL=0 FOR NORMAL EXIT, WHEN ESTIMATED RELATIVE
C                     ACCURACY IS LESS THAN RELEPS WITH FEWER THAN
C                     MAXPTS FUNCTION CALLS MADE.
C             IFAIL=1 IF NUMVAR.LT.1, MINPTS.GE.MAXPTS,
C                     LENWRK.LT.10*NUMVAR OR MAXPTS.LT.4*(NUMVAR+1)
C                     OR RELEPS.LT.0.0.
C             IFAIL=2 IF MAXPTS WAS TOO SMALL FOR D01GBF TO OBTAIN
C                     THE REQUIRED ACCURACY.  IN THIS CASE D01GBF
C                     RETURNS A VALUE OF FINVAL WITH ESTIMATED
C                     RELATIVE ACCURACY RELERR.
C
C     FAIL FOR TOO MANY OR TOO FEW VARIABLES OR LENWRK TOO SMALL OR
C     MINPTS.GE.MAXPTS OR MAXPTS.LT.4*NUMVAR+4
C

D01GCF
      SUBROUTINE D01GCF(N,F,REGION,NPTS,VK,NRAND,ITRANS,RES,ERR,IFAIL)
C     MARK 10 RELEASE. NAG COPYRIGHT 1982.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     MULTIPLE INTEGRATION
C
C     THIS SUBROUTINE CALCULATES AN APPROXIMATION TO
C            D1      DN
C            I ......I F(X1,...,XN) DX1 .. DXN
C            C1      CN
C
C     USING THE KOROBOV-CONROY NUMBER-THEORETIC METHOD.
C     (N.M.KOROBOV,NUMBER THEORETIC METHODS IN APPROXIMATE ANALYSIS,
C     FIZMATGIZ,MOSCOW,1963, H.CONROY,J.CHEM.PHYS.47,(1967),
C     5307-5813)
C
C     INPUT ARGUMENTS
C
C     N        -INTEGER SPECIFYING THE NUMBER OF DIMENSIONS.
C               1 .LE. N .LE. 20.
C
C     F        -EXTERNALLY DECLARED REAL USER FUNCTION INTEGRAND
C               HAVING ARGUMENTS (N,X) WHERE X IS A REAL ARRAY
C               OF DIMENSION N WHOSE ELEMENTS ARE THE VARIABLE
C               VALUES.
C
C     REGION   -EXTERNALLY DECLARED USER SUBROUTINE WITH ARGUMENTS
C               (N,X,J,C,D) WHICH CALCULATES THE LOWER LIMIT C
C               AND THE UPPER LIMIT D CORRESPONDING TO THE ARRAY
C               VARIABLE X(J). C AND D MAY DEPEND ON X(1)..X(J-1).
C
C     NPTS     -INTEGER VARIABLE WHICH SPECIFIES THE KOROBOV RULE
C               TO BE USED. THERE ARE TWO ALTERNATIVES DEPENDING
C               ON THE VALUE OF NPTS
C               (A) 1 .LE. NPTS .LE. 6
C                   IN THIS CASE ONE OF THE SIX PRESET RULES IS
C                   CHOSEN USING 2129, 5003, 10007, 20011, 40009 OR
C                   80021 POINTS ACCORDING TO THE RESPECTIVE VALUE
C                   OF NPTS.
C               (B) NPTS .GT. 6
C                   NPTS IS THE NUMBER OF ACTUAL POINTS TO BE USED
C                   WITH CORRESPONDING OPTIMAL COEFFICIENTS SUPPLIED
C                   BY THE USER IN ARRAY VK.
C
C     VK       -REAL ARRAY CONTAINING N OPTIMAL COEFFICIENTS
C               FOR THE CASE NPTS .GT. 6.
C
C     NRAND    -INTEGER NUMBER SPECIFYING THE NUMBER OF RANDOM
C               SAMPLES TO BE GENERATED IN THE ERROR ESTIMATION.
C               (GENERALLY A SMALL VALUE ,SAY 3 TO 5, IS SUFFICIENT)
C               THE TOTAL NUMBER OF INTEGRAND EVALUATIONS WILL BE
C               NRAND*NPTS.
C
C     ITRANS   -THIS SHOULD BE SET TO 0 OR 1. THE NORMAL SETTING
C               IS 0. WHEN SET TO 1 THE PERIODIZING TRANSFORMATION
C               IS SUPPRESSED (TO COVER CASES WHERE THE INTEGRAND IS
C               ALREADY PERIODIC OR WHERE THE USER DESIRES TO
C               SPECIFY A PARTICULAR TRANSFORMATION IN THE
C               DEFINITION OF F).
C
C     IFAIL    -INTEGER VARIABLE SPECIFYING THE ERROR REPORTING
C               OPTION. IFAIL IS SET TO 0 FOR HARD FAIL AND TO 1 FOR
C               SOFT FAIL REPORT.
C
C
C     OUTPUT ARGUMENTS
C
C     VK       -WHEN THE SUBROUTINE IS CALLED WITH 1 .LE. NPTS
C               .LE. 6 THEN N ELEMENTS OF ARRAY VK WILL BE SET
C               TO THE OPTIMAL COEFFICIENTS USED BY THE PRESET RULE.
C
C     RES      -APPROXIMATION TO THE VALUE OF THE INTEGRAL.
C
C     ERR      -STANDARD ERROR AS COMPUTED FROM NRAND SAMPLE VALUES.
C               IF NRAND IS SET TO 1 THEN ERR WILL BE RETURNED WITH
C               VALUE 0.
C
C     IFAIL    -THIS REPORTS THE ERROR CONDITIONS AS FOLLOWS
C               IFAIL=0  NO ERROR DETECTED.
C                    =1  N FAILS TO SATISFY 1 .LE. N .LE. 20
C                    =2  NPTS .LT. 1.
C                    =3  NRAND .LT. 1.
C
C     ************* IMPLEMENTATION-DEPENDENT CODING ****************
C     THIS ROUTINE REQUIRES AT ONE POINT TO PERFORM EXACT INTEGER
C     ARITHMETIC WITH AT LEAST 32 BITS AVAILABLE FOR INTERMEDIATE
C     RESULTS. THE INTEGERS ARE STORED AS FLOATING-POINT VARIABLES
C     (IN ORDER TO AVOID INTEGER OVERFLOW ON SOME MACHINES). IF THE
C     MACHINE DOES NOT PROVIDE AT LEAST 32 BITS OF BASIC FLOATING-
C     POINT PRECISION, THEN ONE STATEMENT IN THE CODE MUST BE
C     CONVERTED TO ADDITIONAL PRECISION (SEE COMMENTS IN CODE).
C     **************************************************************
C
C     REGION

D01GDF
      SUBROUTINE D01GDF(N,VECFUN,VECREG,NPTS,VK,NRAND,ITRANS,RES,ERR,
     *                  IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.

D01GYF
      SUBROUTINE D01GYF(N,NPTS,VK,IFAIL)
C     MARK 10 RELEASE. NAG COPYRIGHT 1982.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C
C     CALCULATION OF THE KOROBOV OPTIMAL COEFFICIENTS
C     FOR A PRIME NUMBER OF POINTS.
C
C     SEE KOROBOV,NUMBER THEORETIC METHODS IN APPROXIMATE ANALYSIS,
C     FIZMATGIZ,MOSCOW,1963.
C
C     INPUT ARGUMENTS
C
C     N        -INTEGER NUMBER OF DIMENSIONS.
C
C     NPTS     -PRIME INTEGER SPECIFYING THE NUMBER OF POINTS
C               TO BE USED.
C
C     IFAIL    -INTEGER VARIABLE SPECIFYING THE ERROR
C               REPORTING OPTION. IFAIL IS SET TO 0 FOR HARD
C               FAIL AND TO 1 FOR SOFT FAIL REPORT
C
C     OUTPUT ARGUMENTS
C
C     VK       -REAL ARRAY WHOSE FIRST N ELEMENTS CONTAIN
C               THE OPTIMAL COEFFICIENTS.
C
C     IFAIL    -THIS REPORTS THE ERROR CONDITIONS AS FOLLOWS
C               IFAIL=0   NO ERROR REPORTED
C               IFAIL=1   N .LT. 1
C               IFAIL=2   NPTS .LT. 5
C               IFAIL=3   NPTS IS NOT PRIME
C               IFAIL=4   INSUFFICIENT PRECISION
C
C     VALIDITY CHECK

D01GZF
      SUBROUTINE D01GZF(N,NP1,NP2,VK,IFAIL)
C     MARK 10 RELEASE. NAG COPYRIGHT 1982.
C     MARK 10C REVISED. IER-426 (JUL 1983).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C
C     CALCULATION OF THE KOROBOV OPTIMAL COEFFICIENTS
C     FOR NUMBERS OF POINTS WHICH ARE PRODUCTS OF PRIMES
C
C     SEE KOROBOV,NUMBER THEORETIC METHODS IN APPROXIMATE ANALYSIS,
C     FIZMATGIZ,MOSCOW,1963.
C
C     INPUT ARGUMENTS
C
C     N       -INTEGER NUMBER OF DIMENSIONS.
C
C     NP1,NP2 -PRIME INTEGERS SPECIFYING THE NUMBER OF POINTS
C              TO BE USED AS NP1*NP2.
C
C     IFAIL   -INTEGER VARIABLE SPECIFYING THE ERROR
C              REPORTING OPTION. IFAIL IS SET TO 0 FOR HARD
C              FAIL AND TO 1 FOR SOFT FAIL REPORT.
C
C     OUTPUT ARGUMENTS
C
C     VK      -REAL ARRAY WHOSE FIRST N ELEMENTS CONTAIN
C              THE OPTIMAL COEFFICIENTS.
C
C     IFAIL   -THIS REPORTS THE ERROR CONDITIONS AS FOLLOWS
C              IFAIL=0   NO ERROR DETECTED
C              IFAIL=1   N .LT. 1
C              IFAIL=2   NP1.LT.5 OR NP2.LT.2 OR NP2.GE.NP1
C              IFAIL=3   NP1*NP2 OVERFLOWS
C              IFAIL=4   NP1 IS NOT PRIME
C              IFAIL=5   NP2 IS NOT PRIME
C              IFAIL=6   INSUFFICIENT PRECISION
C
C     VALIDITY CHECK

D01JAF
      SUBROUTINE D01JAF(F,N,RADIUS,EPSA,EPSR,METHOD,ICOORD,RESULT,
     *                  ESTERR,EVALS,IFAIL)
C     MARK 10 RELEASE. NAG COPYRIGHT 1982.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C
C     **************************************************************
C
C     AUTOMATIC INTEGRATION OVER A SPHERE
C     -----------------------------------
C
C     STANDARD FORTRAN SUBROUTINE
C
C     PURPOSE
C     -------
C
C     THE ROUTINE CALCULATES AN APPROXIMATION RESULT TO THE
C     INTEGRAL
C
C     J = I ... I F(X1, ..., XN) DX1 ... DXN
C            S
C
C     WHERE S IS THE HYPERSPHERE (X1**2 + ...XN**2)**0.5.LE.RADIUS.
C     THE INTEGRAND FUNCTION MAY ALSO BE DEFINED IN SPHERICAL
C     COORDINATES (SEE PARAMETER ICOORD).
C
C     IF EVERYTHING GOES WELL,
C       ABS(RESULT-J).LE.MAX(EPSA,EPSR*ABS(J)).
C
C     PARAMETERS
C     ----------
C
C     ON ENTRY
C     --------
C     F      - REAL FUNCTION, SUPPLIED BY THE USER, IT
C              EVALUATES THE INTEGRAND AT THE POINT (X(1),...,X(N))
C              (IN CARTESIAN COORDINATES) OR (RO,THETA(1),...,
C              THETA(N-1)) (IN SPHERICAL COORDINATES) (SEE
C              PARAMETER ICOORD). F MUST BE DECLARED EXTERNAL
C              IN THE CALLING (SUB)PROGRAM.
C              CARE SHOULD BE TAKEN TO AVOID UNDERFLOW AND/OR
C              OVERFLOW PROBLEMS IN THE INTEGRAND FUNCTION
C              SUBPROGRAM, BECAUSE SOME OF THE INTEGRATION NODES
C              USED BY D01JAF ARE VERY CLOSE TO THE SURFACE
C              OR TO THE CENTRE OF THE SPHERE.
C              F IS SPECIFIED AS
C
C                    REAL FUNCTION F(N,X)
C              C     INTEGER N
C              C     REAL X(N)
C
C     N      - DIMENSION OF THE SPHERE (N.LE.4, FOR N.GT.4 SEE
C              DIMENSION INFORMATION BELOW)
C
C     RADIUS - RADIUS OF THE SPHERE
C
C     EPSA   - REQUESTED ABSOLUTE ACCURACY
C
C     EPSR   - REQUESTED RELATIVE ACCURACY
C
C              THE ROUTINE ATTEMPTS TO CALCULATE AN APPROXIMATION
C              RESULT TO THE INTEGRAL J, HOPEFULLY SATISFYING
C              ABS(RESULT-J).LE.MAX(EPSA,EPSR*ABS(J)).
C
C     METHOD - KEY FOR CHOOSING THE TRANSFORMATION TO BE
C              USED BY THE ROUTINE, DEPENDING ON THE BEHAVIOUR OF
C              THE INTEGRAND FUNCTION AND THE REQUESTED ACCURACY
C              - DEFAULT VALUE METHOD = 0
C              - WELL-BEHAVED FUNCTION OR FUNCTION WITH SINGULARITY
C                ONLY ON THE SURFACE OF THE SPHERE-
C                         - LOW  ACCURACY REQUESTED, METHOD = 1
C                         - HIGH ACCURACY REQUESTED, METHOD = 2
C              - FUNCTION WITH STRONG SINGULARITY ON THE SURFACE-
C                         - LOW  ACCURACY REQUESTED, METHOD = 3
C                         - HIGH ACCURACY REQUESTED, METHOD = 4
C                IN THIS CASE THE INTEGRAND MUST BE DEFINED IN THE
C                SPECIAL SPHERICAL COORDINATES (SEE ICOORD).
C              - FUNCTION WITH SINGULARITY IN THE CENTRE OF THE
C                SPHERE (SINGULARITY ON THE SURFACE IS ALLOWED
C                AS WELL)-
C                         - LOW  ACCURACY REQUESTED, METHOD = 5
C                         - HIGH ACCURACY REQUESTED, METHOD = 6
C              WHEN METHOD = 0, EPSR.LE.1.E-6 IS CONSIDERED AS A
C              HIGH, EPSR.GT.1.E-6 AS A LOW ACCURACY. HOWEVER, THE
C              VALUE OF EPSR WHICH DISTINGUISHES HIGH FROM LOW
C              TOLERANCES DEPENDS ALSO ON THE INTEGRAND. WHEN USING
C              METHOD.GT.0, THIS VALUE MAY IN GENERAL BE DECREASED
C              WHEN THE INTEGRAND IS SMOOTH, INCREASED WHEN IT
C              IS BADLY BEHAVED.
C
C     ICOORD - INDICATES WHICH KIND OF COORDINATES
C              ARE USED IN THE FUNCTION SUBPROGRAM F(N,X)-
C              ICOORD = 0- X(I) I = 1...N- CARTESIAN COORDINATES
C              ICOORD = 1- X- SPHERICAL COORDINATES-
C                          X(1) = RO
C                          X(I) = THETA(I-1)   I = 2...N
C              ICOORD = 2- IF METHOD IS SET TO 3 OR 4, THE USER HAS
C                          TO DEFINE THE FUNCTION IN SPHERICAL
C                          COORDINATES, WITH THE ADDITIONAL
C                          TRANSFORMATION RO = RADIUS - LAMBDA.
C                          IN THIS CASE THE ROUTINE DOES ITS
C                          COMPUTATIONS WITH LAMBDA INSTEAD OF WITH
C                          RO, AND THUS
C                          X(1) = LAMBDA
C                          X(I) = THETA(I-1)   I = 2...N.
C                          THE USER HAS TO TAKE CARE THAT THE
C                          FUNCTION SUBPROGRAM DOES NOT CONTAIN
C                          EXPRESSIONS OF THE FORM
C                          RADIUS - LAMBDA.
C              REMARKS   - THE CARTESIAN COORDINATES ARE RELATED
C                          TO THE SPHERICAL COORDINATES BY
C                          X(1) = RO*SIN(THETA(1))*...
C                                   *SIN(THETA(N-2))*SIN(THETA(N-1))
C                          X(2) = RO*SIN(THETA(1))*...
C                                   *SIN(THETA(N-2))*COS(THETA(N-1))
C                          X(3) = RO*SIN(THETA(1))*...
C                                                   *COS(THETA(N-2))
C                          X(N) = RO*COS(THETA(1))
C                          WHERE  0.LT.THETA(I).LE.PI   I = 1...N-2
C                                 0.LT.THETA(N-1).LE.2.E0*PI
C
C     ON EXIT
C     -------
C     RESULT - APPROXIMATION TO THE INTEGRAL
C
C     ESTERR - ESTIMATE OF THE (MODULUS OF THE) ABSOLUTE ERROR
C
C     EVALS  - NUMBER OF FUNCTION EVALUATIONS NEEDED TO OBTAIN
C              THE RESULT
C
C     IFAIL  - ERROR FLAG
C              IFAIL= 0- NORMAL AND RELIABLE TERMINATION OF THE
C                        ROUTINE, IT IS ASSUMED THAT THE TOLERANCE
C                        CRITERIA HAVE BEEN SATISFIED.
C              IFAIL= 1- THE REQUESTED ACCURACY CANNOT BE ACHIEVED
C                        WITHIN A LIMITING NUMBER OF FUNCTION
C                        EVALUATIONS (WHICH IS SET BY THE ROUTINE).
C              IFAIL= 2- THE PRESENCE OF ROUNDOFF ERROR PREVENTS
C                        THE REQUESTED ACCURACY FROM BEING OBTAINED.
C              IFAIL= 3- THE MAXIMUM ACCURACY WITH RESPECT TO THE
C                        MACHINE DEPENDENT CONSTANTS EPMACH AND
C                        UFLOW HAS BEEN ACHIEVED. IF THIS MAXIMUM
C                        ACCURACY IS RATHER LOW, IFAIL=3 MEANS THAT
C                        A SEVERE SINGULARITY ON THE BOUNDARY OR
C                        AT THE CENTRE OF THE SPHERE PREVENTS THE
C                        REQUESTED ACCURACY FROM BEING ACHIEVED.
C                        IF METHOD.LT.3, SETTING  METHOD=3 OR 4 MAY
C                        HELP.
C              IFAIL= 4- THE INPUT IS INVALID. NO CALCULATIONS HAVE
C                        BEEN PERFORMED (RESULT AND ESTERR ARE SET
C                        TO 0). THIS OCCURS WHEN
C                            N.LT.2 OR.GT.4,
C                         OR METHOD.LT.0 OR.GT.6,
C                         OR ICOORD.LT.0 OR.GT.2,
C                         OR METHOD.NE.3 OR 4  AND ICOORD = 2,
C                         OR METHOD = 3 OR 4 AND ICOORD.NE.2,
C                         OR RADIUS .LT. 0.0.
C
C     SUBPROGRAMS CALLED
C     ------------------
C
C         - D01JAY
C         - D01JAZ - D01JAX
C                  - D01JAW
C
C     DIMENSION INFORMATION
C     ---------------------
C
C     TO USE THE ROUTINE FOR INTEGRATION OVER A SPHERE
C     OF DIMENSION NDIM.GT.4, SET THE SIZE OF ALL THE
C     ARRAYS IN THE ROUTINES D01JAF, D01JAZ, D01JAX AND D01JAW
C     TO NDIM. FURTHERMORE DELETE THE TEST ON THE VALIDITY OF INPUT
C     PARAMETER N.
C
C     MACHINE DEPENDENT CONSTANTS
C     ---------------------------
C
C     EPMACH IS THE RELATIVE MACHINE ACCURACY.
C     UFLOW  IS ABOUT EQUAL TO, BUT MUST NOT BE LESS THAN
C              THE SMALLEST POSITIVE REAL NUMBER REPRESENTABLE
C              BY THE MACHINE.
C
C     RMAX, RMIN AND RMID WILL BE CALCULATED AS FUNCTIONS OF THE
C     ABOVE CONSTANTS. THEIR VALUES CAN INFLUENCE THE PERFORMANCE
C     OF THE ROUTINE CONSIDERABLY.
C
C     LABELLED COMMON AREAS
C     ---------------------
C
C         - AD01JA
C         - BD01JA
C         - CD01JA
C
C     LIST OF MAJOR VARIABLES
C     -----------------------
C
C     X      - THE CARTESIAN COORDINATES OF A GRID POINT
C
C     ABSCIS - THE CARTESIAN OR SPHERICAL COORDINATES
C              OF THE INTEGRATION NODE IN THE ORIGINAL REGION,
C              CORRESPONDING TO X
C
C     R      - DISTANCE FROM THE CENTRE
C
C     RO     - DISTANCE FROM THE CENTRE IN THE ORIGINAL REGION,
C              CORRESPONDING TO R
C
C     IRAD2  - INPUT PARAMETER OF THE ROUTINE D01JAZ, IRAD2*H = R**2
C
C     ITRANS - CODE FOR THE TRANSFORMATION TO BE USED, THE
C              VALUE OF ITRANS IS DETERMINED BY THE INPUT PARAMETERS
C              METHOD AND EPSR.
C
C     EPSLIM - CRITICAL VALUE OF EPSR FOR CHOICE OF THE
C              TRANSFORMATION WHEN METHOD = 0
C
C     WEIGHT - THE JACOBIAN OF THE TRANSFORMATION IN THE GRID POINTS
C              AT DISTANCE R EQUALS WEIGHT * RADIUS**N.
C
C     RMAX   - IF R.GT.RMAX- RADIUS*(1-EPMACH).LE.R0.LE.RADIUS, AND
C              /OR TO PREVENT UNDERFLOW DURING THE CALCULATION OF
C              THE WEIGHT.
C
C     RMIN   - IF METHOD = 5 OR 6 AND R.LT.RMIN, UNDERFLOW OCCURS
C              DURING THE CALCULATION OF THE WEIGHT.
C
C     RMID   - IF R = RMID, THEN RO = RMAX / 2.
C
C     BREAK1,- THE TRANSFORMED INTEGRAND IS NEGLIGIBLE WHEN
C     BREAK2   R.GT.BREAK1 OR R.LT.BREAK2.
C
C     TMIN   - USED TO DETERMINE BREAK1 AND BREAK2
C
C     SAVE   - SAVEGUARD WITH RESPECT TO TRUNCATION ERROR
C
C     H      - STEPLENGTH USED IN EACH DIRECTION IN THE TRAPEZOIDAL
C              RULE
C
C     HFAK   - THE INITIAL STEPLENGTH IS HFAK * RMAX / 2.
C
C     ITRMAX - DETERMINES THE MAXIMUM NUMBER OF FUNCTION
C              EVALUATIONS, THE STEPLENGTH H CANNOT BE HALVED
C              MORE THAN ITRMAX TIMES.
C
C     ERREXT - EXTRAPOLATED ERROR ESTIMATE
C
C     RESFOR - APPROXIMATION TO THE INTEGRAL IN THE PREVIOUS
C              STEP
C
C     ERRDIF - SIMPLE ERROR ESTIMATE (=ABS(RESULT-RESFOR))
C
C     ERREXT - EXTRAPOLATED ERROR ESTIMATE
C
C     ERTRUN - TRUNCATION ERROR ESTIMATE
C
C     RTRUN1 - GREATEST R (LESS THAN RMAX) USED IN THE PREVIOUS
C              STEP
C
C     RTRUN2 - IF METHOD=5 OR 6, THE SMALLEST R (GREATER THAN RMIN)
C              USED IN THE PREVIOUS STEP
C
C     STRUN1 - USED TO DETERMINE THE TRUNCATION ERROR ESTIMATE
C
C     STRUN2 - USED TO DETERMINE THE TRUNCATION ERROR ESTIMATE
C
C     SRAHN  - USED TO COMPUTE TMIN- IN EACH STEP,
C              SRAHN = SAVE / (RADIUS * H)**N.
C
C     **************************************************************
C

D01PAF
      SUBROUTINE D01PAF(NUMVAR,VERTEX,IV1,IV2,INTGND,MINORD,MAXORD,
     *                  INTVLS,ESTERR,IFAIL)
C     MARK 10 RELEASE. NAG COPYRIGHT 1982.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MULTIDIMENSIONAL SIMPLEX ROMBERG INTEGRATION SUBROUTINE
C       SUBROUTINE FOR COMPUTING INTEGRALS OF THE TYPE
C
C            I F(X) DX(1)DX(2)...DX(NUMVAR)
C             S
C
C       WHERE S IS A NUMVAR DIMENSIONAL SIMPLEX
C
C     **************  PARAMETERS FOR D01PAF  ***********************
C     NUMVAR  INTEGER NUMBER OF VARIABLES, MUST EXCEED 1.
C     VERTEX  REAL ARRAY OF SIMPLEX VERTICES WITH DIMENSION
C             (IV1,IV2). VERTEX(I,J) IS THE JTH COORDINATE OF THE
C             ITH VERTEX
C     IV1     INTEGER FIRST DIMENSION OF VERTEX, MUST BE
C             .GE. NUMVAR+1.
C     IV2     INTEGER SECOND DIMENSION OF VERTEX, MUST BE
C             .GE. 2*NUMVAR+2.
C     INTGND  EXTERNALLY DECLARED USER DEFINED REAL FUNCTION
C             INTEGRAND.
C             IT MUST HAVE PARAMETERS (NUMVAR,X), WHERE X IS A REAL
C             ARRAY WITH DIMENSION NUMVAR.
C     MINORD  INTEGER MINIMUM ORDER PARAMETER, MUST BE AT LEAST 0
C             AND LESS THAN MAXORD.  WHEN MINORD IS NOT 0 THE
C             SUBROUTINE ASSUMES A PREVIOUS CALL OR CALLS OF THE
C             SUBROUTINE HAVE BEEN USED TO COMPUTE
C             INTVLS(1), INTVLS(2),..., INTVLS(MINORD).
C             ON EXIT, MINORD IS SET EQUAL TO MAXORD.
C     MAXORD  INTEGER MAXIMUM ORDER PARAMETER, MUST BE GREATER THAN
C             MINORD THE SUBROUTINE COMPUTES INTVLS(MINORD+1),
C             INTVLS(MINORD+2), ..., INTVLS(MAXORD).
C     INTVLS  REAL ARRAY OF DIMENSION(MAXORD).  UPON SUCCESSFUL EXIT
C             INTVLS(1), INTVLS(2),..., INTVLS(MAXORD) ARE
C             APPROXIMATIONS TO THE INTEGRAL.  INTVLS(J) WILL BE AN
C             APPROXIMATION OF POLYNOMIAL DEGREE 2*J-1.
C     ESTERR  REAL ABSOLUTE ERROR ESTIMATE
C     IFAIL   INTEGER FAILURE OUTPUT PARAMETER
C             IFAIL=0 FOR SUCCESSFUL TERMINATION OF THE SUBROUTINE
C             IFAIL=1 WHEN PARAMETERS NUMVAR,MINORD,MAXORD,
C                     IV1 OR IV2 ARE OUT OF RANGE
C             IFAIL=2 WHEN F03AAF FAILS FROM UNDERFLOW OR OVERFLOW
C                     IN THE COMPUTATION OF THE SIMPLEX VOLUME
C     **************************************************************

D02AGF
      SUBROUTINE D02AGF(H,ERROR,PARERR,PARAM,C,N,N1,M1,AUX,BCAUX,RAAUX,
     *                  PRSOL,MAT,COPY,WSPACE,WSPAC1,WSPAC2,IFAIL)
C     NAG COPYRIGHT 1975
C     MARK 4.5 REVISED
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C     MARK 15 REVISED. IER-898 (APR 1991). (LAPACK)
C
C     SOLVES A GENERAL BOUNDARY VALUE
C     PROBLEM FOR N DIFFERENTIAL EQUATIONS
C     IN N1 PARAMETERS USING A SHOOTING
C     AND MATCHING TECHNIQUE.  EPS IS THE
C     LARGEST REAL VARIABLE SUCH THAT 1+EPS=1
C     ALL IMPLICITLY DECLARED REALS MAY BE USED DOUBLE-LENGTH
C     THE ARRAY COPY IS REDUNDANT

D02BGF
      SUBROUTINE D02BGF(X,XEND,N,Y,TOL,HMAX,M,VAL,FCN,W,IFAIL)
C     MARK 7 RELEASE. NAG COPYRIGHT 1978.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     TO FIND POSITION AT WHICH A COMPONENT OF THE SOLUTION ATTAINS
C     A GIVEN VALUE
C     FCN

D02BHF
      SUBROUTINE D02BHF(X,XEND,N,Y,TOL,IRELAB,HMAX,FCN,G,W,IFAIL)
C     MARK 7 RELEASE. NAG COPYRIGHT 1978.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     CALCULATES THE POINT X,WHERE G(X,Y)=0
C     FCN

D02CJF
      SUBROUTINE D02CJF(T,TEND,NEQ,Y,FCN,TOL,RELABS,OUTPUT,G,RWORK,
     *                  IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.
C     MARK 14A REVISED.  IER-680 (DEC 1989).

D02EJF
      SUBROUTINE D02EJF(X,XEND,N,Y,FCN,PEDERV,TOL,RELABS,OUTPUT,G,W,IW,
     *                  IFAIL)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C     MARK 12B REVISED. IER-551 (FEB 1987).
C     MARK 13 REVISED. IER-586 (MAR 1988).
C     MARK 13 REVISED. IER-611 (APR 1988).
C     MARK 13 REVISED. IER-612 (APR 1988).
C     MARK 13B REVISED. IER-654 (AUG 1988).
C     MARK 16 REVISED. IER-971 (JUN 1993).

D02GAF
      SUBROUTINE D02GAF(U,V,N,A,B,TOL,FCN,MNP,X,Y,NP,W,LW,IW,LIW,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 9 REVISED. IER-305 (SEP 1981).
C     MARK 9C REVISED. IER-373 (JUN 1982)
C     MARK 10 REVISED. IER-377 (JUN 1982).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     FCN

D02GBF
      SUBROUTINE D02GBF(A,B,N,TOL,FCNF,FCNG,C,D,GAM,MNP,X,Y,NP,W,LW,IW,
     *                  LIW,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 9 REVISED. IER-305 (SEP 1981).
C     MARK 9C REVISED. IER-373 (JUN 1982)
C     MARK 10 REVISED. IER-377 (JUN 1982).
C     MARK 10A REVISED. IER-389 (OCT 1982).
C     MARK 10B REVISED. IER-400 (JAN 1983).
C     MARK 11 REVISED. IER-434 (FEB 1984).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. IER-606 (APR 1988).
C     FCNF, FCNG

D02HAF
      SUBROUTINE D02HAF(A,B,N,X,X1,TOL,FCN,SOLN,M1,W,IW,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     FCN

D02HBF
      SUBROUTINE D02HBF(P,N1,PE,E,N,SOLN,M1,FCN,BC,RANGE,W,IW,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 9 REVISED. IER-306 (SEP 1981).
C     MARK 9C REVISED. IER-366 (MAY 1982).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. IER-619 (APR 1988).
C     BC, FCN, RANGE

D02JAF
      SUBROUTINE D02JAF(N,CF,BC,X0,X1,K1,KP,C,W,LW,IW,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     BC

D02JBF
      SUBROUTINE D02JBF(N,CF,BC,X0,X1,K1,KP,C,IC,W,LW,IW,LIW,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     BC

D02KAF
      SUBROUTINE D02KAF(XL,XR,COEFFN,BCOND,K,TOL,ELAM,DELAM,MONIT,IFAIL)
C     MARK 7 RELEASE. NAG COPYRIGHT 1978.
C     MARK 8A REVISED. IER-257 (AUG 1980).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C

D02KDF
      SUBROUTINE D02KDF(XPOINT,NXP,COEFFN,BDYVAL,K,TOL,ELAM,DELAM,HMAX,
     *                  MAXIT,MAXFUN,MONIT,IFAIL)
C     MARK 7 RELEASE. NAG COPYRIGHT 1978.
C     MARK 8A REVISED. IER-258 (AUG 1980).
C     MARK 9 REVISED. IER-307 (SEP 1981).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C
C     MEANING OF COMMON VARIABLES:
C     ZER,ONE,TWO,PI - CONSTANTS WITH INDICATED VALUES
C     LAMDA - CURRENT VALUE OF EIGENVALUE ESTIMATE. SET AND USED IN
C     EIGODE. USED IN AUX,OPTSC.
C     PSIGN   - SAMPLE P(X) VALUE. SET IN PRUFER, USED IN AUX.
C     MINSC - MINIMUM ALLOWED SCALEFACTOR. SET IN EIGODE, USED IN
C     OPTSC.
C     BP    - USED BY THE POLYGONAL SCALING METHOD. THE CURRENT
C     VALUE OF THE DERIVATIVE OF B(X). SET IN PRUFER, USED I
C
C     BDYVAL, MONIT

D02KEF
      SUBROUTINE D02KEF(XPOINT,NXP,IC1,COEFFN,BDYVAL,K,TOL,ELAM,DELAM,
     *                  HMAX,MAXIT,MAXFUN,MONIT,REPORT,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C
C     MEANING OF COMMON VARIABLES:
C     ZER,ONE,TWO,PI - CONSTANTS WITH INDICATED VALUES
C     LAMDA - CURRENT VALUE OF EIGENVALUE ESTIMATE. SET AND USED IN
C     EIGODE. USED IN AUX,OPTSC.
C     PSIGN   - SAMPLE P(X) VALUE. SET IN PRUFER, USED IN AUX.
C     MINSC - MINIMUM ALLOWED SCALEFACTOR. SET IN EIGODE, USED IN
C     OPTSC.
C     BP    - USED BY THE POLYGONAL SCALING METHOD. THE CURRENT
C     VALUE OF THE DERIVATIVE OF B(X). SET IN PRUFER, USED I
C
C     BDYVAL, COEFFN, MONIT, REPORT

D02LAF
      SUBROUTINE D02LAF(F,NEQ,T,TEND,Y,YP,YDP,RWORK,LRWORK,IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.
C     MARK 16A REVISED. IER-972 (JUN 1993).
C
C     NOTE -
C     THE ARRAYS IN COMMON ARE LARGE ENOUGH TO ACCOMODATE THE
C     COEFFICIENTS OF THE 12(10) FORMULA PAIR.  THIS ADDS CLARITY
C     TO THE PROGRAM BUT SOME STORAGE COULD BE SAVED IF NECESSARY
C     (BY ADDITIONAL PROGRAMMING EFFORT).  TWO POSSIBLE WAYS OF
C     SAVING STORAGE ARE:
C     1) STORE THE MATRIX OF COEFFICIENTS  A  IN STRICTLY LOWER
C        TRIANGULAR FORM.  THIS WOULD SAVE  153  LOCATIONS.
C     2) INCLUDE THE STORAGE REQUIREMENT FOR THE COEFFICIENTS
C        IN THE WORKSPACE ARRAY  RWORK.
C
C
C     IF THE USE OF COMMON STATEMENTS IS TO BE AVOIDED, /AD02LA/ CAN
C     BE REPLACED BY CALLING THE APPROPRIATE COEFFICIENT ROUTINE
C     (D02LAY OR D02LAZ) ON EACH ENTRY TO D02LAF.  SIMILARLY, THE
C     VALUES IN /CD02LA/ COULD BE RECOMPUTED ON EACH ENTRY.
C     OTHER MEANS WILL HAVE TO BE FOUND TO REPLACE /BD02LA/.
C

D02LXF
      SUBROUTINE D02LXF(NEQ,H,TOL,THRES,THRESP,MAXSTP,START,ONESTP,HIGH,
     *                  RWORK,LRWORK,IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.
C
C     THIS IS THE SET-UP ROUTINE FOR THE NYSTROM CODE D02LAF.  IT
C     MUST BE CALLED BEFORE THE FIRST CALL TO D02LAF AND CAN BE
C     USED BETWEEN CONTINUATION CALLS TO CHANGE OPTIONAL INPUTS.
C
C     THE ROUTINE USES THE MACHINE-DEPENDENT CONSTANTS UROUND
C     AND THRDEF, WHICH IS CURRENTLY SET TO 50*UROUND.
C
C     IF STORAGE IS AT A PREMIUM, THEN IN THE CALLING (SUB)PROGRAM THE
C     ACTUAL ARGUMENT 'THRES' MAY BE THE ACTUAL ARGUMENT
C     'RWORK(17+4*NEQ)' AND SIMILARLY 'THRESP' MAY BE 'RWORK(17+5*NEQ)'
C

D02LYF
      SUBROUTINE D02LYF(NEQ,HNEXT,HUSED,HSTART,NSUCC,NFAIL,NATT,THRES,
     *                  THRESP,RWORK,LRWORK,IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.
C
C     THIS IS THE DIAGNOSTIC ROUTINE ASSOCIATED WITH THE NYSTROM
C     SOLVER D02LAF.  THE VALUES OF THE PARAMETERS IN THE SUBROUTINE
C     CALL ARE TAKEN OUT OF RWORK.
C
C     SEE COMMENT IN D02LXF ABOUT STORAGE REDUCTION FOR THRES AND
C     THRESP.
C

D02LZF
      SUBROUTINE D02LZF(NEQ,T,Y,YP,NWANT,TWANT,YWANT,YPWANT,RWORK,
     *                  LRWORK,IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.
C
C     THIS ROUTINE USES THE THIRD FORMULA OF THE RKN6(4)6 TRIPLE
C     TO RETURN THE VALUES OF Y AND YP AT THE POINT TWANT, WHICH
C     SHOULD BE BETWEEN T-H AND T.
C

D02MVF
      SUBROUTINE D02MVF(NEQMAX,NY2DIM,MAXORD,CONST,TCRIT,HMIN,HMAX,H0,
     *                  MAXSTP,MXHNIL,NORM,RWORK,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C***********************************************************************
C   THIS ROUTINE INITIALISES THE DASSL IMPLENTATION OF B.D.F
C   METHODS AS USED IN THE D02N SUB CHAPTER
C INPUT PARAMETERS
C
C  NEQMAX - INTEGER
C   THE MAXIMUM NUMBER OF EQUATIONS
C   NY2DIM     THE SECOND DIMENSION OF THE YSAVE ARRAY , IT SHOULD BE
C              SET TO MAXORD + 3, UNLESS MAXORD IS ZERO ,SEE BELOW.
C   MAXORD     THE MAXIMUM ORDER TO BE USED. THIS SHOULD BE POSITIVE AND
C              THIS SHOULD BE LESS THAN 6 . WHEN MAXORD IS SET
C              TO ZERO THE DEFAULT VALUES OF  5
C              WILL BE USED BY THE CODE (NY2DIM MUST BE LARGE ENOUGH
C              FOR THESE DEFAULT VALUES).
C
C
C          N.B. THE SIZE OF THE YSAVE ARRAY PASSED INTO NITE3  MUST BE
C              YSAVE(NYH, MAXORD + 3). WHERE NYH IS THE NUMBER OF
C              DIFFERENTIAL ALGEBRAIC EQUATIONS OR AN UPPER BOUND ON
C              THIS NUMBER .
C----------------------------------------------------------------------

D02MZF
      SUBROUTINE D02MZF(TSOL,SOL,M,NEQMAX,NEQ,YSAVE,NY2DIM,RWORK,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.

D02NBF
      SUBROUTINE D02NBF(NEQ,NEQMAX,T,TOUT,Y,YDOTI,RWORK,RTOL,ATOL,ITOL,
     *                  INFORM,FCN,YSAVE,NY2DIM,JAC,WKJAC,NWKJAC,MONITR,
     *                  ITASK,ITRACE,IFAIL)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

D02NCF
      SUBROUTINE D02NCF(NEQ,NEQMAX,T,TOUT,Y,YDOTI,RWORK,RTOL,ATOL,ITOL,
     *                  INFORM,FCN,YSAVE,NY2DIM,JAC,WKJAC,NWKJAC,JACPVT,
     *                  NJCPVT,MONITR,ITASK,ITRACE,IFAIL)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

D02NDF
      SUBROUTINE D02NDF(NEQ,NEQMAX,T,TOUT,Y,YDOTI,RWORK,RTOL,ATOL,ITOL,
     *                  INFORM,FCN,YSAVE,NY2DIM,JAC,WKJAC,NWKJAC,JACPVT,
     *                  NJCPVT,MONITR,ITASK,ITRACE,IFAIL)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

D02NGF
      SUBROUTINE D02NGF(NEQ,NEQMAX,T,TOUT,Y,YDOTI,RWORK,RTOL,ATOL,ITOL,
     *                  INFORM,RESID,YSAVE,NY2DIM,JAC,WKJAC,NWKJAC,
     *                  MONITR,LDERIV,ITASK,ITRACE,IFAIL)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

D02NHF
      SUBROUTINE D02NHF(NEQ,NEQMAX,T,TOUT,Y,YDOTI,RWORK,RTOL,ATOL,ITOL,
     *                  INFORM,RESID,YSAVE,NY2DIM,JAC,WKJAC,NWKJAC,
     *                  JACPVT,NJCPVT,MONITR,LDERIV,ITASK,ITRACE,IFAIL)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

D02NJF
      SUBROUTINE D02NJF(NEQ,NEQMAX,T,TOUT,Y,YDOTI,RWORK,RTOL,ATOL,ITOL,
     *                  INFORM,RESID,YSAVE,NY2DIM,JAC,WKJAC,NWKJAC,
     *                  JACPVT,NJCPVT,MONITR,LDERIV,ITASK,ITRACE,IFAIL)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

D02NMF
      SUBROUTINE D02NMF(NEQ,NEQMAX,T,TOUT,Y,YDOTI,RWORK,RTOL,ATOL,ITOL,
     *                  INFORM,YSAVE,NY2DIM,WKJAC,NWKJAC,JACPVT,NJCPVT,
     *                  IMON,INLN,IRES,IREVCM,ITASK,JTRACE,IFAIL)
C     MARK 14 RE-ISSUE. NAG COPYRIGHT 1989.
C     MARK 14C REVISED. IER-874 (NOV 1990).
C     MARK 16A REVISED. IER-974 (JUN 1993).
C-----------------------------------------------------------------------
C THE FOLLOWING INTERNAL COMMON BLOCKS ARE DEFINED AS FOLLOWS;
C     AD02NM CONTAINS TRACE LEVEL AND CHANNEL FOR DEBUGGING
C     BD02NM CONTAINS THE INTEGRATION STATISTICS PARAMETERS SUCH
C            NUMBER OF JACOBIAN EVALUATIONS AND STEPS. THE PARAMETER
C            NINTER CONTAINS THE EFFECTIVE SIZE OF THE MEMORY ARRAY
C            YH(NEQMAX,NINTER) IF INTERPOLATION IS TO BE USED ON IT.
C     DD02NM CONTAINS THE VARIABLES USED IN THE TIME MANAGEMENT
C            SCHEME AND THE WORKSPACE POINTERS.
C     ED02NM CONTAINS THE COMMUNICATION POINTERS USED IN REVERSE
C            COMMUNICATION BETWEEN THE TIME MANAGEMENT SCHEME AND
C            THE MODULES CALLED BY IT.
C     FD02NM CONTAINS THE IFIP TRANSPORTABLE NUMERICAL SOFTWARE
C            PARAMETERS WHICH ARE INITIALISED IN THE BLOCK DATA .
C     GD02NM CONTAINS INFORMATION USED BY THE NONLINEAR EQUATIONS
C            SOLVER CAN BE USED BY THE STEP MODULE TO IMPLEMENT
C            A DAMPED NEWTON METHOD  OR TO GOVERN THE NUMBER OF
C            ITERATIONS PERFORMED.
C     HD02NM PASSES THE TYPE OF NORM TO BE USED TO THE FUNCTION D02ZAF.
C   IMPORTANT
C   ---------
C      THE RESIDUAL, STEP, NONLINEAR EQUATIONS AND LINEAR ALGEBRA
C   MODULES ALL COMMUNICATE BY USING REVERSE COMMUNICATION THROUGH
C   THE TIME MANAGEMENT SCHEME IN D02NMF. ACCESS TO THESE MODULES IS
C   ONLY THROUGH THE PARAMETER LIST USED IN D02NMF. INTERNAL
C   COMMUNICATION BETWEEN THE GROUPS OF ROUTINES WHICH MAKE UP A
C   MODULE IS BY COMMON BLOCKS. FOR EXAMPLE THERE ARE THREE ROUTINES
C   IN THE B.D.F./ ADAMS METHOD TIME INTEGRATION MODULE :BDFSET, D02NMX
C   AND D02XJY. INTERCOMMUNICATION BETWEEN THESE ROUTINES IS VIA COMMON
C   BLOCKS.
C-----------------------------------------------------------------------

D02NNF
      SUBROUTINE D02NNF(NEQ,NEQMAX,T,TOUT,Y,YDOTI,RWORK,RTOL,ATOL,ITOL,
     *                  INFORM,YSAVE,NY2DIM,WKJAC,NWKJAC,JACPVT,NJCPVT,
     *                  IMON,INLN,IRES,IREVCM,LDERIV,ITASK,JTRACE,IFAIL)
C     MARK 14 RE-ISSUE. NAG COPYRIGHT 1989.
C     MARK 15A REVISED. IER-938 (APR 1991).
C     MARK 15 REVISED. IER-939 (APR 1991).
C     MARK 16A REVISED. IER-977 (JUN 1993).
C-----------------------------------------------------------------------
C THE FOLLOWING INTERNAL COMMON BLOCKS ARE DEFINED AS FOLLOWS;
C     AD02NM CONTAINS TRACE LEVEL AND CHANNEL FOR DEBUGGING
C     BD02NM CONTAINS THE INTEGRATION STATISTICS PARAMETERS SUCH
C            NUMBER OF JACOBIAN EVALUATIONS AND STEPS. THE PARAMETER
C            NINTER CONTAINS THE EFFECTIVE SIZE OF THE MEMORY ARRAY
C            YH(NEQMAX,NINTER) IF INTERPOLATION IS TO BE USED ON IT.
C     DD02NM CONTAINS THE VARIABLES USED IN THE TIME MANAGEMENT
C            SCHEME AND THE WORKSPACE POINTERS.
C     ED02NM CONTAINS THE COMMUNICATION POINTERS USED IN REVERSE
C            COMMUNICATION BETWEEN THE TIME MANAGEMENT SCHEME AND
C            THE MODULES CALLED BY IT.
C     FD02NM CONTAINS THE IFIP TRANSPORTABLE NUMERICAL SOFTWARE
C            PARAMETERS WHICH ARE INITIALISED IN THE BLOCK DATA .
C     GD02NM CONTAINS INFORMATION USED BY THE NONLINEAR EQUATIONS
C            SOLVER CAN BE USED BY THE STEP MODULE TO IMPLEMENT
C            A DAMPED NEWTON METHOD  OR TO GOVERN THE NUMBER OF
C            ITERATIONS PERFORMED.
C     HD02NM PASSES THE TYPE OF NORM TO BE USED TO THE FUNCTION D02ZAF.
C   IMPORTANT
C   ---------
C      THE RESIDUAL, STEP, NONLINEAR EQUATIONS AND LINEAR ALGEBRA
C   MODULES ALL COMMUNICATE BY USING REVERSE COMMUNICATION THROUGH
C   THE TIME MANAGEMENT SCHEME IN D02NNF. ACCESS TO THESE MODULES IS
C   ONLY THROUGH THE PARAMETER LIST USED IN D02NNF. INTERNAL
C   COMMUNICATION BETWEEN THE GROUPS OF ROUTINES WHICH MAKE UP A
C   MODULE IS BY COMMON BLOCKS. FOR EXAMPLE THERE ARE THREE ROUTINES
C   IN THE B.D.F./ ADAMS METHOD TIME INTEGRATION MODULE :BDFSET, D02NMX
C   AND D02XJZ. INTERCOMMUNICATION BETWEEN THESE ROUTINES IS VIA COMMON
C   BLOCKS.
C-----------------------------------------------------------------------

D02NRF
      SUBROUTINE D02NRF(J,IPLACE,INFORM)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

D02NSF
      SUBROUTINE D02NSF(NEQ,NEQMAX,JCEVAL,NWKJAC,RWORK,IFAIL)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C
C     SETUP ROUTINE FOR FULL LINEAR ALGEBRA OPTION
C

D02NTF
      SUBROUTINE D02NTF(NEQ,NEQMAX,JCEVAL,ML,MU,NWKJAC,NJCPVT,RWORK,
     *                  IFAIL)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C
C     SETUP ROUTINE FOR BANDED LINEAR ALGEBRA OPTION
C

D02NUF
      SUBROUTINE D02NUF(NEQ,NEQMAX,JCEVAL,NWKJAC,IA,NIA,JA,NJA,JACPVT,
     *                  NJCPVT,SENS,U,ETA,LBLOCK,ISPLIT,RWORK,IFAIL)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C     MARK 12B REVISED. IER-528 (FEB 1987).

D02NVF
      SUBROUTINE D02NVF(NEQMAX,NY2DIM,MAXORD,METHOD,PETZLD,CONST,TCRIT,
     *                  HMIN,HMAX,H0,MAXSTP,MXHNIL,NORM,RWORK,IFAIL)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C
C     SETUP ROUTINE FOR INTEGRATOR EMPLOYING B.D.F. METHOD
C

D02NWF
      SUBROUTINE D02NWF(NEQMAX,NY2DIM,MAXORD,CONST,TCRIT,HMIN,HMAX,H0,
     *                  MAXSTP,MXHNIL,NORM,RWORK,IFAIL)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C     MARK 12B REVISED. IER-530 (FEB 1987).
C
C     SETUP ROUTINE FOR INTEGRATOR EMPLOYING A BLEND METHOD
C

D02NXF
      SUBROUTINE D02NXF(ICALL,LIWREQ,LIWUSD,LRWREQ,LRWUSD,NLU,NNZ,NGP,
     *                  ISPLIT,IGROW,LBLOCK,NBLOCK,INFORM)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C     MARK 14 REVISED. IER-712 (DEC 1989).

D02NYF
      SUBROUTINE D02NYF(NEQ,NEQMAX,HU,H,TCUR,TOLSF,RWORK,NST,NRE,NJE,
     *                  NQU,NQ,NITER,IMXER,ALGEQU,INFORM,IFAIL)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C     MARK 12B REVISED. IER-531 (FEB 1987).

D02NZF
      SUBROUTINE D02NZF(NEQMAX,TCRIT,H,HMIN,HMAX,MAXSTP,MAXHNL,RWORK,
     *                  IFAIL)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C     MARK 12B REVISED. IER-532 (FEB 1987).

D02PCF
      SUBROUTINE D02PCF(F,TWANT,TGOT,YGOT,YPGOT,YMAX,WORK,IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1993.
C$$$$ SUBROUTINE UT $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
C
C  If you are not familiar with the code D02PCF and how it is used in
C  conjunction with D02PVF to solve initial value problems, you should
C  study the document file RKSUITE.DOC carefully before proceeding
C  further. The following "Brief Reminder" is intended only to remind
C  you of the meaning, type, and size requirements of the arguments.
C
C  NAME DECLARED IN AN EXTERNAL STATEMENT IN THE CALLING PROGRAM:
C
C     F         - name of the subroutine for evaluating the differential
C                 equations.
C
C  The subroutine F must have the form
C
C  SUBROUTINE F(T,Y,YP)
C  DOUBLE PRECISION T,Y(*),YP(*)
C    Given input values of the independent variable T and the solution
C    components Y(*), for each L = 1,2,...,NEQ evaluate the differential
C    equation for the derivative of the Ith solution component and place
C    the value in YP(L).  Do not alter the input values of T and Y(*).
C  RETURN
C  END
C
C  INPUT VARIABLE
C
C     TWANT     - DOUBLE PRECISION
C                 The next value of the independent variable where a
C                 solution is desired.
C
C                 Constraints: TWANT must lie between the previous value
C                 of TGOT (TSTART on the first call) and TEND. TWANT can
C                 be equal to TEND, but it must be clearly
C                 distinguishable from the previous value of TGOT
C                 (TSTART on the first call) in the precision available.
C
C  OUTPUT VARIABLES
C
C     TGOT      - DOUBLE PRECISION
C                 A solution has been computed at this value of the
C                 independent variable.
C     YGOT(*)   - DOUBLE PRECISION array of length NEQ
C                 Approximation to the true solution at TGOT. Do not
C                 alter the contents of this array
C     YPGOT(*)  - DOUBLE PRECISION array of length NEQ
C                 Approximation to the first derivative of the true
C                 solution at TGOT.
C     YMAX(*)   - DOUBLE PRECISION array of length NEQ
C                 YMAX(L) is the largest magnitude of YGOT(L) computed
C                 at any time in the integration from TSTART to TGOT.
C                 Do not alter the contents of this array.
C
C  WORKSPACE
C
C     WORK(*)   - DOUBLE PRECISION array as used in D02PVF
C                 Do not alter the contents of this array.
C
C  OUTPUT VARIABLE
C
C     IFAIL     - INTEGER
C
C                       SUCCESS.  TGOT = TWANT.
C                 = 0 - Complete success.
C
C                       "SOFT" FAILURES
C                 = 2 - Warning:  You are using METHOD = 3 inefficiently
C                       by computing answers at many values of TWANT. If
C                       you really need answers at so many specific
C                       points, it would be more efficient to compute
C                       them with METHOD = 2.  To do this you would need
C                       to restart from TGOT, YGOT(*) by a call to
C                       D02PVF.  If you wish to continue as you are, you
C                       may.
C                 = 3 - Warning:  A considerable amount of work has been
C                       expended.  If you wish to continue on to TWANT,
C                       just call D02PCF again.
C                 = 4 - Warning:  It appears that this problem is
C                       "stiff". You really should change to another
C                       code that is intended for such problems, but if
C                       you insist, you can continue with D02PCF by
C                       calling it again.
C
C                       "HARD" FAILURES
C                 = 5 - You are asking for too much accuracy. You cannot
C                       continue integrating this problem.
C                 = 6 - The global error assessment may not be reliable
C                       beyond the current point in the integration. You
C                       cannot continue integrating this problem.
C
C                       "CATASTROPHIC" FAILURES
C                 = 1 - The nature of the catastrophe is reported on
C                       the standard output channel. Unless special
C                       provision was made in advance (see RKSUITE.DOC),
C                       the computation then comes to a STOP.
C
C$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

D02PDF
      SUBROUTINE D02PDF(F,TNOW,YNOW,YPNOW,WORK,IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1993.
C$$$$ SUBROUTINE CT $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
C
C  If you are not familiar with the code D02PDF and how it is used in
C  conjunction with D02PVF to solve initial value problems, you should
C  study the document file RKSUITE.DOC carefully before attempting to
C  use the code. The following "Brief Reminder" is intended only to
C  remind you of the meaning, type, and size requirements of the
C  arguments.
C
C  NAME DECLARED IN AN EXTERNAL STATEMENT IN THE CALLING PROGRAM:
C
C     F         - name of the subroutine for evaluating the differential
C                 equations.
C
C  The subroutine F must have the form
C
C  SUBROUTINE F(T,Y,YP)
C  DOUBLE PRECISION T,Y(*),YP(*)
C     Using the input values of the independent variable T and the
C     solution components Y(*), for each L = 1,2,...,NEQ evaluate the
C     differential equation for the derivative of the Lth solution
C     component and place the value in YP(L).  Do not alter the input
C     values of T and Y(*).
C  RETURN
C  END
C
C  OUTPUT VARIABLES
C
C     TNOW      - DOUBLE PRECISION
C                 Current value of the independent variable.
C     YNOW(*)   - DOUBLE PRECISION array of length NEQ
C                 Approximation to the true solution at TNOW.
C     YPNOW(*)  - DOUBLE PRECISION array of length NEQ
C                 Approximation to the first derivative of the
C                 true solution at TNOW.
C
C  WORKSPACE
C
C     WORK(*)   - DOUBLE PRECISION array as used in D02PVF
C                 Do not alter the contents of this array.
C
C  OUTPUT VARIABLE
C
C     IFAIL     - INTEGER
C
C                       SUCCESS.  A STEP WAS TAKEN TO TNOW.
C                 = 0 - Complete success.
C
C                       "SOFT" FAILURES
C                 = 2 - Warning:  You have obtained an answer by
C                       integrating to TEND (TNOW = TEND).  You have
C                       done this at least 100 times, and monitoring of
C                       the computation reveals that this way of getting
C                       output has degraded the efficiency of the code.
C                       If you really need answers at so many specific
C                       points, it would be more efficient to get them
C                       with D02PXF.  (If METHOD = 3, you would need to
C                       change METHOD and restart from TNOW, YNOW(*) by
C                       a call to D02PVF.)  If you wish to continue as
C                       you are, you may.
C                 = 3 - Warning:  A considerable amount of work has been
C                       expended. To continue the integration, just call
C                       D02PDF again.
C                 = 4 - Warning:  It appears that this problem is
C                       "stiff". You really should change to another
C                       code that is intended for such problems, but if
C                       you insist, you can continue with D02PDF by
C                       calling it again.
C
C                       "HARD" FAILURES
C                 = 5 - You are asking for too much accuracy. You cannot
C                       continue integrating this problem.
C                 = 6 - The global error assessment may not be reliable
C                       beyond the current point in the integration.
C                       You cannot continue integrating this problem.
C
C                       "CATASTROPHIC" FAILURES
C                 = 1 - The nature of the catastrophe is reported on
C                       the standard output channel. Unless special
C                       provision was made in advance (see RKSUITE.DOC),
C                       the computation then comes to a STOP.
C
C$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

D02PVF
      SUBROUTINE D02PVF(NEQ,TSTART,YSTART,TEND,TOL,THRES,METHOD,TASK,
     *                  ERRASS,HSTART,WORK,LENWRK,IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1993.
C$$$$ SUBROUTINE SETUP $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
C
C  If you are not familiar with the code D02PVF and how it is used in
C  conjunction with D02PCF or D02PDF to solve initial value problems,
C  you should study the document file RKSUITE.DOC carefully before
C  attempting to use the code.
C  The following "Brief Reminder" is intended only to remind you of the
C  meaning, type, and size requirements of the arguments.
C
C  The environmental parameters OUTCH, MCHEPS, and DWARF are used in the
C  following description.  To find out their values
C
C       CALL D02PVX(OUTCH,MCHEPS,DWARF)
C
C  INPUT VARIABLES
C
C     NEQ       - INTEGER
C                 The number of differential equations in the system.
C                 Constraint: NEQ >= 1
C     TSTART    - DOUBLE PRECISION
C                 The initial value of the independent variable.
C     YSTART(*) - DOUBLE PRECISION array of length NEQ
C                 The vector of initial values of the solution
C                 components.
C     TEND      - DOUBLE PRECISION
C                 The integration proceeds from TSTART in the direction
C                 of TEND. You cannot go past TEND.
C                 Constraint: TEND must be clearly distinguishable from
C                 TSTART in the precision available.
C     TOL       - DOUBLE PRECISION
C                 The relative error tolerance.
C                 Constraint: 0.01D0 >= TOL >= 10*MCHEPS
C     THRES(*)  - DOUBLE PRECISION array of length NEQ
C                 THRES(L) is the threshold for the Ith solution
C                 component.
C                 Constraint: THRES(L) >= SQRT(DWARF)
C     METHOD    - INTEGER
C                 Specifies which Runge-Kutta pair is to be used.
C                  = 1 - use the (2,3) pair
C                  = 2 - use the (4,5) pair
C                  = 3 - use the (7,8) pair
C     TASK      - CHARACTER*(*)
C                 Only the first character of TASK is significant.
C                 TASK(1:1) = `U' or `u' - D02PCF is to be used
C                           = `C' or `c' - D02PDF is to be used
C                 Constraint: TASK(1:1) = `U'or `u' or`C' or `c'
C     ERRASS    - LOGICAL
C                 = .FALSE. - do not attempt to assess the true error.
C                 = .TRUE.  - assess the true error. Costs roughly twice
C                             as much as the integration with METHODs 2
C                             and 3, and three times with METHOD = 1.
C     HSTART    - DOUBLE PRECISION
C                 0.0D0     - select automatically the first step size.
C                 non-zero  - try HSTART for the first step.
C
C  WORKSPACE
C
C     WORK(*) - DOUBLE PRECISION array of length LENWRK
C               Do not alter the contents of this array after calling
C               D02PVF.
C
C  INPUT VARIABLES
C
C     LENWRK  - INTEGER
C               Length of WORK(*): How big LENWRK must be depends
C               on the task and how it is to be solved.
C
C               LENWRK = 32*NEQ is sufficient for all cases.
C
C               If storage is a problem, the least storage possible
C               in the various cases is:
C
C                 If TASK = `U' or `u', then
C                   if ERRASS = .FALSE. and
C                     METHOD = 1, LENWRK must be at least 10*NEQ
C                            = 2                          20*NEQ
C                            = 3                          16*NEQ
C                   if ERRASS = .TRUE. and
C                     METHOD = 1, LENWRK must be at least 15*NEQ
C                            = 2                          32*NEQ
C                            = 3                          21*NEQ
C
C                 If TASK = `C' or `c', then
C                   if ERRASS = .FALSE. and
C                     METHOD = 1, LENWRK must be at least 10*NEQ
C                            = 2                          14*NEQ
C                            = 3                          16*NEQ
C                   if ERRASS = .TRUE. and
C                     METHOD = 1, LENWRK must be at least 15*NEQ
C                            = 2                          26*NEQ
C                            = 3                          21*NEQ
C
C                 Warning:  To exploit the interpolation capability
C                 of METHODs 1 and 2, you have to call D02PXF.  This
C                 subroutine requires working storage in addition to
C                 that specified here.
C
C  In the event of a "catastrophic" failure to call D02PVF correctly,
C  the nature of the catastrophe is reported on the standard output
C  channel, regardless of the value of MESAGE.  Unless special provision
C  was made in advance (see RKSUITE.DOC), the computation then comes to
C  STOP.
C
C$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

D02PWF
      SUBROUTINE D02PWF(TENDNU,IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1993.
C$$$$ SUBROUTINE RESET $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
C
C  If you are not familiar with the code D02PWF and how it is used in
C  conjunction with D02PDF to solve initial value problems, you should
C  study the document file RKSUITE.DOC carefully before attempting to
C  use the code. The following "Brief Reminder" is intended only to
C  remind you of the meaning, type, and size requirements of the
C  arguments.
C
C  The integration using D02PDF proceeds from TSTART in the direction of
C  TEND, and is now at TNOW.  To reset TEND to a new value TENDNU, just
C  call D02PWF with TENDNU as the argument.  You must continue
C  integrating in the same direction, so the sign of (TENDNU - TNOW)
C  must be the same as the sign of (TEND - TSTART). To change direction
C  you must restart by a call to D02PVF.
C
C  INPUT VARIABLE
C
C     TENDNU    - DOUBLE PRECISION
C                 The new value of TEND.
C                 Constraint: TENDNU and TNOW must be clearly
C                 distinguishable in the precision used.  The
C                 sign of (TENDNU - TNOW) must be the same as
C                 the sign of (TEND - TSTART).
C
C$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

D02PXF
      SUBROUTINE D02PXF(TWANT,REQEST,NWANT,YWANT,YPWANT,F,WORK,WRKINT,
     *                  LENINT,IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1993.
C$$$$ SUBROUTINE INTRP $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
C
C  If you are not familiar with the code D02PXF and how it is used in
C  conjunction with D02PDF to solve initial value problems, you should
C  study the document file RKSUITE.DOC carefully before attempting to
C  use the code. The following "Brief Reminder" is intended only to
C  remind you of the meaning, type, and size requirements of the
C  arguments.
C
C  When integrating with METHOD = 1 or 2, answers may be obtained
C  inexpensively between steps by interpolation. D02PXF is called after
C  a step by D02PDF from a previous value of T, called TOLD below, to
C  the current value of T to get an answer at TWANT. You can specify any
C  value of TWANT you wish, but specifying a value outside the interval
C  [TOLD,T] is likely to yield answers with unsatisfactory accuracy.
C
C  INPUT VARIABLE
C
C     TWANT     - DOUBLE PRECISION
C                 The value of the independent variable where a solution
C                 is desired.
C
C  The interpolant is to be evaluated at TWANT to approximate the
C  solution and/or its first derivative there.  There are three
C  cases:
C
C  INPUT VARIABLE
C
C     REQEST    - CHARACTER*(*)
C                 Only the first character of REQEST is significant.
C                 REQEST(1:1) = `S' or `s'- compute approximate
C                             = `D' or `d'- compute approximate first
C                                           `D'erivative of the solution
C                                           only.
C                             = `B' or `b'- compute `B'oth approximate
C                                           solution and first
C                                           derivative.
C                 Constraint: REQEST(1:1) must be `S',`s',`D',`d',`B' or
C                             `b'.
C
C  If you intend to interpolate at many points, you should arrange for
C  the the interesting components to be the first ones because the code
C  approximates only the first NWANT components.
C
C  INPUT VARIABLE
C
C     NWANT     - INTEGER
C                 Only the first NWANT components of the answer are to
C                 be computed.
C                 Constraint:  NEQ >= NWANT >= 1
C
C  OUTPUT VARIABLES
C
C     YWANT(*)  - DOUBLE PRECISION array of length NWANT
C                 Approximation to the first NWANT components of the
C                 true solution at TWANT when REQESTed.
C     YPWANT(*) - DOUBLE PRECISION array of length NWANT
C                 Approximation to the first NWANT components of the
C                 first derivative of the true solution at TWANT when
C                 REQESTed.
C
C  NAME DECLARED IN AN EXTERNAL STATEMENT IN THE PROGRAM CALLING D02PXF:
C
C     F         - name of the subroutine for evaluating the differential
C                 equations as provided to D02PDF.
C
C  WORKSPACE
C
C     WORK(*)   - DOUBLE PRECISION array as used in D02PVF and D02PDF
C                 Do not alter the contents of this array.
C
C     WRKINT(*) - DOUBLE PRECISION array of length LENINT
C                 Do not alter the contents of this array.
C
C     LENINT    - INTEGER
C                 Length of WRKINT. If
C                 METHOD = 1, LENINT must be at least 1
C                        = 2, LENINT must be at least
C                          NEQ+MAX(NEQ,5*NWANT)
C                        = 3--CANNOT BE USED WITH THIS SUBROUTINE
C
C$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

D02PYF
      SUBROUTINE D02PYF(TOTFCN,STPCST,WASTE,STPSOK,HNEXT,IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1993.
C$$$$ SUBROUTINE STAT $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
C
C  If you are not familiar with the code D02PYF and how it is used in
C  conjunction with the integrators D02PDF and D02PCF, you should study
C  the document file RKSUITE.DOC carefully before attempting to use the
C  code. The following "Brief Reminder" is intended only to remind you
C  of the meaning, type, and size requirements of the arguments.
C
C  D02PYF is called to obtain some details about the integration.
C
C  OUTPUT VARIABLES
C
C     TOTFCN    - INTEGER
C                 Total number of calls to F in the integration so far
C                 -- a measure of the cost of the integration.
C     STPCST    - INTEGER
C                 Cost of a typical step with this METHOD measured in
C                 calls to F.
C     WASTE     - DOUBLE PRECISION
C                 The number of attempted steps that failed to meet the
C                 local error requirement divided by the total number of
C                 steps attempted so far in the integration.
C     STPSOK    - INTEGER
C                 The number of accepted steps.
C     HNEXT     - DOUBLE PRECISION
C                 The step size the integrator plans to use for the next
C                 step.
C
C$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

D02PZF
      SUBROUTINE D02PZF(RMSERR,ERRMAX,TERRMX,WORK,IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1993.
C$$$$ SUBROUTINE GLBERR $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
C
C  If you are not familiar with the code D02PZF and how it is used in
C  conjunction with D02PCF and D02PDF to solve initial value problems,
C  you should study the document file RKSUITE.DOC carefully before
C  attempting to use the code.  The following "Brief Reminder" is
C  intended only to remind you of the meaning, type, and size
C  requirements of the arguments.
C
C  If ERRASS was set .TRUE. in the call to D02PVF, then after any call
C  to D02PCF or D02PDF to advance the integration to TNOW or TWANT, the
C  subroutine D02PZF may be called to obtain an assessment of the true
C  error of the integration. At each step and for each solution
C  component Y(L), a more accurate "true" solution YT(L), an average
C  magnitude "size(L)" of its size, and its error
C  abs(Y(L) - YT(L))/max("size(L)",THRES(L)) are computed. The
C  assessment returned in RMSERR(L) is the RMS (root-mean-square)
C  average of the error in the Lth solution component over all steps of
C  the integration from TSTART through TNOW.
C
C  OUTPUT VARIABLES
C
C     RMSERR(*) - DOUBLE PRECISION array of length NEQ
C                 RMSERR(L) approximates the RMS average of the true
C                 error of the numerical solution for the Ith solution
C                 component, L = 1,2,...,NEQ.  The average is taken over
C                 all steps from TSTART to TNOW.
C     ERRMAX    - DOUBLE PRECISION
C                 The maximum (approximate) true error taken over all
C                 solution components and all steps from TSTART to TNOW.
C     TERRMX    - DOUBLE PRECISION
C                 First value of the independent variable where the
C                 (approximate) true error attains the maximum value
C                 ERRMAX.
C
C  WORKSPACE
C
C     WORK(*)   - DOUBLE PRECISION array as used in D02PVF and D02PCF or
C                 D02PDF
C
C$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

D02QFF
      SUBROUTINE D02QFF(F,NEQF,T,Y,TOUT,G,NEQG,ROOT,RWORK,LRWORK,IWORK,
     *                  LIWORK,IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.

D02QGF
      SUBROUTINE D02QGF(NEQF,T,Y,TOUT,NEQG,ROOT,IREVCM,TRVCM,YRVCM,
     *                  YPRVCM,GRVCM,KGRVCM,RWORK,LRWORK,IWORK,LIWORK,
     *                  IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.

D02QWF
      SUBROUTINE D02QWF(STATEF,NEQF,VECTOL,ATOL,LATOL,RTOL,LRTOL,ONESTP,
     *                  CRIT,TCRIT,HMAX,MAXSTP,NEQG,ALTERG,SOPHST,RWORK,
     *                  LRWORK,IWORK,LIWORK,IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.

D02QXF
      SUBROUTINE D02QXF(NEQF,YP,TCURR,HLAST,HNEXT,ODLAST,ODNEXT,NSUCC,
     *                  NFAIL,TOLFAC,BADCMP,RWORK,LRWORK,IWORK,LIWORK,
     *                  IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.

D02QYF
      SUBROUTINE D02QYF(NEQG,INDEX,TYPE,EVENTS,RESIDS,RWORK,LRWORK,
     *                  IWORK,LIWORK,IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.

D02QZF
      SUBROUTINE D02QZF(NEQF,TWANT,NWANT,YWANT,YPWANT,RWORK,LRWORK,
     *                  IWORK,LIWORK,IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.

D02RAF
      SUBROUTINE D02RAF(M,NMAX,N,NUMBEG,NUMMIX,TOL,INIT,X,Y,IY,ABT,FCN,
     *                  G,IJAC,JACOBF,JACOBG,DELEPS,JACEPS,JACGEP,WORK,
     *                  LWORK,IWORK,LIWORK,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C     MARK 14 REVISED. IER-821 (DEC 1989).
C     FCN, G, JACEPS, JACGEP, JACOBF, JACOBG

D02SAF
      SUBROUTINE D02SAF(P,M,N,N1,PE,PF,E,DP,NPOINT,WP,IWP,ICOUNT,RANGE,
     *                  BC,FCN,EQN,CONSTR,YMAX,MONIT,PRSOL,W,IW1,IW2,
     *                  IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     SOLVES A TWO POINT BVP
C     BC, EQN, FCN, MONIT, PRSOL, RANGE

D02TGF
      SUBROUTINE D02TGF(N,M,L,X0,X1,K1,KP,C,IC,COEFF,BDYC,W,LW,IW,LIW,
     *                  IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     BDYC,COEFF

D02XJF
      SUBROUTINE D02XJF(XSOL,SOL,M,W,NEQMAX,IW,NEQ,X,NQ,HU,H,IFAIL)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C     MARK 12B REVISED. IER-545 (FEB 1987).

D02XKF
      SUBROUTINE D02XKF(XSOL,SOL,M,W,NEQMAX,IW,W2,NEQ,X,NQ,HU,H,IFAIL)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C     MARK 12B REVISED. IER-533 (FEB 1987).

D02ZAF
      DOUBLE PRECISION FUNCTION D02ZAF(N,V,W,IFAIL)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C
C     OLD NAME VNORM
C
C-----------------------------------------------------------------------
C INORM = 1         MAXIMUM NORM
C       = 2         AVERAGE L2 NORM
C  THE CHOICE OF NORM IS DEFINED BY THE USER ON ENTRY TO SPRINT AND
C  PASSED TO THIS FUNCTION BY THE COMMON BLOCK /HD02NM/.
C
C  BOTH NORMS ARE WEIGHTED VECTOR NORMS OF
C  THE VECTOR OF LENGTH N CONTAINED IN THE ARRAY V, WITH WEIGHTS
C  CONTAINED IN THE ARRAY W OF LENGTH N.
C  E.G. FOR THE AVERAGED L2 NORM
C       D02ZAF = SQRT( (1/N) * SUM( V(I)*W(I) )**2 )
C      THE L2 NORM CAN BE OBTAINED BY APPROPRIATE SCALING OF THE WEIGHTS
C  FOR THE MAX NORM
C       D02ZAF = MAX '' V(I)*W(I) ''
C                I
C      THE MODIFIED MAX NORM CAN BE OBTAINED , AS FOR THE L2 NORM, BY
C      APPROPRIATE SCALING OF THE WEIGHTS.
C-----------------------------------------------------------------------

D03EAF
      SUBROUTINE D03EAF(STAGE1,EXT,DORM,N,P,Q,X,Y,N1P1,PHI,PHID,ALPHA,C,
     *                  IC,NP4,ICINT,NP1,IFAIL)
C     MARK 7 RELEASE. NAG COPYRIGHT 1978.
C     MARK 7G REVISED. IER-218 (FEB 1980)
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C
C     THIS SUBROUTINE SOLVES DIRICHLET, NEUMANN AND MIXED BOUNDARY
C     VALUE PROBLEMS FOR LAPLACES EQUATION IN TWO DIMENSIONS, BY AN
C     INTEGRAL EQUATION METHOD BASED UPON GREENS FORMULA. IT IS
C     APPLICABLE TO ANY DOMAIN BOUNDED, INTERNALLY AND/OR
C     EXTERNALLY, BY CLOSED CONTOURS.
C
C
C     THE NEXT TWO VARIABLES ARE MACHINE-DEPENDENT CONSTANTS. THE
C     FIRST CONTAINS THE VALUE OF PI AND THE SECOND THE VALUE OF EPS
C     WHICH IS THE SMALLEST NUMBER FOR WHICH 1.0 + EPS .GT. 1.0
C     WITHIN THE MACHINE.
C

D03EBF
      SUBROUTINE D03EBF(N1,N2,N1M,A,B,C,D,E,Q,T,APARAM,ITMAX,ITCOUN,
     *                  ITUSED,NDIR,IXN,IYN,CONRES,CONCHN,RESIDS,CHNGS,
     *                  WRKSP1,WRKSP2,WRKSP3,IFAIL)
C     MARK 7 RELEASE. NAG COPYRIGHT 1978.
C     MARK 8C REVISED. IER-267 (OCT. 1980).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     *************************************************************
C     D03EBF OBTAINS THE SOLUTION TO A SYSTEM OF SIMULTANEOUS
C     ALGEBRAIC EQUATIONS OF FIVE POINT MOLECULE FORM ON A
C     TOPOLOGICALLY RECTANGULAR MESH.
C     IT IS THE DRIVING ROUTINE FOR D03UAF FOR STANDARD
C     APPLICATIONS.
C
C
C     INPUTS
C
C     N1      NUMBER OF NODES IN THE FIRST COORDINATE DIRECTION.
C     N2      NUMBER OF NODES IN THE SECOND COORDINATE DIRECTION.
C     N1M     FIRST DIMENSION OF ALL THE TWO-DIMENSIONAL ARRAYS.
C     A       ARRAY OF DIMENSION (N1M,N2) STORES THE COEFFICIENT
C             OF THE ITERATIVE UPDATE EQUATIONS AS SHOWN BELOW -
C     B       DITTO ... DIMENSION (N1M,N2) ...
C     C       DITTO ... DIMENSION (N1M,N2) ...
C     D       DITTO ... DIMENSION (N1M,N2) ...
C     E       DITTO ... DIMENSION (N1M,N2) ...
C
C        A(I,J)*T(I,J-1)+B(I,J)*T(I-1,J)+C(I,J)*T(I,J)+D(I,J)*
C        T(I+1,J)+E(I,J)*T(I,J+1) = Q(I,J)
C
C             WITH I=1,2,...,N1 AND J=1,2,...,N2 AND WHERE T(I,J)
C             IS THE ARRAY WHOSE VALUES ARE SOUGHT AND WHERE
C             Q(I,J) IS THE ARRAY OF SOURCE TERMS. ANY VALUES OF
C             T OUTSIDE THE PROBLEM AREA (1-N1,1-N2) ARE TAKEN
C             AS ZERO.
C     Q       IS THE ARRAY OF SOURCE TERMS DIMENSION (N1M,N2)
C     T       ARRAY STORING THE APPROXIMATE SOLUTION OF T IN THE
C             ABOVE EQUATION WHICH IS PASSED TO THE ROUTINE.
C             IF NO BETTER APPROXIMATION IS KNOWN, AN ARRAY OF
C             ZEROS CAN BE USED DIMENSIONED (N1M,N2).
C     APARAM  IS AN ITERATION ACCELERATION PARAMETER FACTOR
C             TYPICALLY SET TO 1.0. IF CONVERGENCE IS SLOW, IT
C             CAN BE DECREASED. IF DIVERGENCE IS OBTAINED, IT
C             SHOULD BE INCREASED. IN EITHER CASE IT MUST NOT
C             GO OUTSIDE THE BOUNDS PRESCRIBED (SEE IFAIL
C             PARAMETER FOR D03UAF).
C     ITMAX   IS THE MAXIMUM NUMBER OF ITERATIONS TO BE USED.
C     ITCOUN  IS AN INDICATOR SET EQUAL TO 0 ON THE FIRST CALL
C             TO D03EBF. FOR SUBSEQUENT CALLS FOR THE SAME
C             PROBLEM, I.E. SAME N1 N2,BUT POSSIBLY DIFFERENT
C             COEFFICIENTS AND/OR SOURCE TERMS, AS OCCUR WITH NON
C             LINEAR SYSTEMS OR TIME DEPENDENT SYSTEMS, ITCOUN
C             SHOULD BE SET TO THE NUMBER OF ITERATIONS USED SO
C             FAR ON SUBSEQUENT CALLS TO ENSURE SUITABLE CYCLING
C             OF THE ITERATION ACCELERATION PARAMETERS IN D03UAF.
C             CHANGED ON OUTPUT TO THE NUMBER OF ITERATIONS USED
C             SO FAR I.E. ITCOUN ON RETURN = ITCOUN ON INPUT +
C             ITUSED ON RETURN
C     NDIR    IS AN INTEGER SET TO A NON-ZERO VALUE FOR SYSTEMS
C             OF EQUATIONS WHICH HAVE A UNIQUE SOLUTION. FOR
C             SYSTEMS DERIVED FROM, E.G. LAPLACES EQUATION WITH
C             ALL NEUMANN BOUNDARY CONDITIONS, PROBLEMS WITH AN
C             ARBITRARY CONSTANT CAN BE ADDED TO THE SOLUTION,
C             NDIR SHOULD BE SET TO ZERO AND THE VALUES OF THE
C             NEXT 2 PARAMETERS MUST BE SPECIFIED. FOR SUCH
C             PROBLEMS THE ROUTINE SUBTRACTS THE VALUE OF THE
C             FUNCTION DERIVED AT THE NODE (IXN,IYN) FROM THE
C             WHOLE SOLUTION AFTER EACH ITERATION TO REDUCE THE
C             POSSIBLITY OF LARGE ROUNDING ERRORS. THE USER MU
C             ALSO ENSURE THAT FOR SUCH PROBLEMS THE APPROPRIATE
C             CONSISTENCY CONDITION ON THE SOURCE TERMS IS
C             SATISFIED.
C     IXN,IYN NODAL INDECIES OF THE NODE AT WHICH THE SOLUTION IS
C             TO BE REDUCED TO ZERO FOR PROBLEMS FOR WHICH NDIR IS
C             SET TO ZERO THE NODE SHOULD NOT CORRESPOND TO A
C             CORNER NODE OF THE REGION OF INTEREST.
C
C     CONVERGENCE CRITERIA
C
C     CONRES  CONVERGENCE CRITERION ON THE MAXIMUM ABSOLUTE VALUE
C             OF THE NORMALIZED RESIDUAL, THE LATTER BEING
C             DEFINED AS THE RESIDUAL OF THE EQUATION DIVIDED BY
C             THE CENTRAL COEFFICIENT WHEN THE LATTER IS NOT
C             EQUAL TO O.O, AND DEFINED AS THE RESIDUAL WHEN THE
C             CENTRAL COEFFICIENT IS 0.0.
C     CONCHN  CONVERGENCE CRITERION ON THE MAXIMUM ABSOLUTE VALUE
C             OF THE CHANGE MADE AT EACH ITERATION OF THE ARRAY T
C
C     CONVERGENCE IS ACHIEVED WHEN BOTH THE CRITERIA ARE SATISFIED
C
C     RESIDS  ARRAY OF DIMENSION ITMAX ... SEE OUTPUT
C     CHNGS   ARRAY OF DIMENSION ITMAX ... SEE OUTPUT
C
C     WRKSP1  WORKSPACE ARRAY OF DIMENSION (N1M,N2) USED BY D03UAF
C     WRKSP2   ... DITTO ...
C     WRKSP3  WORKSPACE ARRAY OF DIMENSION (N1M,N2) USED TO PASS
C             THE RESIDUALS TO D03UAF, AND IN WHICH THE UPDATE
C             VALUES ARE RETURNED FROM D03UAF TO THIS ROUTINE.
C
C     IFAIL   IS AN ERROR PARAMETER INDICATOR SET BY THE USER TO
C             INDICATE THE TYPE OF FAILURE IF AN ERROR IS
C             ENCOUNTERED.
C
C     PROCESS
C
C     SET ERROR PARAMETER
C     CHECK INPUT INTEGERS
C     COMMENCEMENT OF CALCULATIONAL PROCEDURE
C     START OF ITERATIVE SOLUTION PROCEDURE
C     SET CONVERGENCE PARAMETER ACCUMULATORS TO ZERO
C     CALCULATE THE RESIDUALS AND STORE IN ARRAY WRKSP3
C     CALL SUBROUTINE D03UAF TO PERFORM 1 ITERATION OF S.I.P
C     AND WHICH RETURNS THE ARRAY OF UPDATES IN THE ARRAY WRKSP3
C     COMBINE THE UPDATES WITH THE OLD SOLUTION
C     CHECK FOR CONVERGENCE
C     REPEAT TO CONVERGENCE OR UNTIL MAXIMUM NUMBER OF ITERATIONS
C     HAVE BEEN USED
C     SET ERROR INDICATOR ACCORDINGLY
C     RETURN
C
C     OUTPUTS
C
C     T       ARRAY STORING THE SOLUTION OF THE SYSTEM OF EQUATIONS
C             PROVIDED.
C     ITUSED  NUMBER OF ITERATIONS ACTUALLY USED THIS CALL.
C     ITCOUN  ACCUMULATED NUMBER OF ITERATIONS USED
C             ITCOUN ON OUTPUT = ITCOUN ON INPUT + ITUSED ON OUTPUT
C     RESIDS  VECTOR STORING THE MAXIMUM ABSOLUTE RESIDUALS OF EACH
C             ITERATION, DIMENSION ITMAX. ONLY THE FIRST ITUSED
C             VALUES ARE SET ON RETURN.
C     CHNGS   ARRAY STORING THE MAXIMUM ABSOLUTE CHANGES OF EACH
C             ITERATION, DIMENSION ITMAX. ONLY THE FIRST ITUSED
C             VALUES ARE SET ON RETURN.
C     IFAIL   ERROR INDICATOR
C             =0 CORRECT RETURN
C             =1 EITHER N1.LE.1 OR N2.LE.1
C             =2 CONVERGENCE NOT ACHIEVED. REFER TO VALUES IN
C                RESIDS AND CHNGS TO DETERMINE IF THE ITERATION
C                WAS CONVERGING. REFER TO GUIDE ON SETTING APARAM
C                IF CONVERGENCE IS VERY SLOW.
C             =3 APARAM.LE.0.0
C             =4 APARAM.GE.((N1-1)**2+(N2-1)**2)/2.0
C
C     ROUTINES USED
C
C     D03UAF  SINGLE ITERATION OF S.I.P. FOR A FIVE POINT MOLECULE
C             SYSTEM.
C     P01AAF  ERROR HANDLING ROUTINE.
C
C     **************************************************************
C
C
C     SET ERROR PARAMETER
C

D03ECF
      SUBROUTINE D03ECF(N1,N2,N3,N1M,N2M,A,B,C,D,E,F,G,Q,T,APARAM,ITMAX,
     *                  ITCOUN,ITUSED,NDIR,IXN,IYN,IZN,CONRES,CONCHN,
     *                  RESIDS,CHNGS,WRKSP1,WRKSP2,WRKSP3,WRKSP4,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     **************************************************************
C
C             DAVID A. H.  JACOBS              22/5/79
C     D03ECF OBTAINS THE SOLUTION OF A SYSTEM OF SIMULTANEOUS
C     ALGEBRAIC EQUATIONS OF SEVEN POINT MOLECULE FORM ON A
C     THREE-DIMENSIONAL TOPOLOGICALLY RECTANGULAR MESH.
C
C     IT IS THE DRIVING ROUTINE FOR ROUTINE D03UBF FOR
C     STANDARD APPLICATIONS
C
C     INPUTS
C     ------
C
C     N1       NUMBER OF NODES IN THE FIRST COORDINATE DIRECTION.
C
C     N2       NUMBER OF NODES IN THE SECOND COORDINATE DIRECTION.
C
C     N3       NUMBER OF NODES IN THE THIRD COORDINATE DIRECTION.
C
C     N1M      FIRST DIMENSION OF ALL THREE DIMENSIONAL ARRAYS.
C
C     N2M      SECOND DIMENSION OF ALL THREE DIMENSIONAL ARRAYS.
C
C     A,B,C,   ARRAYS ALL OF DIMENSION (N1M,N2M,N3) STORING
C     D,E,F,G  THE COEFFICIENTS OF THE ITERATIVE UPDATE
C              EQUATIONS -
C
C       A(I,J,K)*T(I,J,K-1)+B(I,J,K)*T(I,J-1,K)+C(I,J,K)*T(I-1,J,K)+
C       D(I,J,K)*T(I,J,K)+E(I,J,K)*T(I+1,J,K)+F(I,J,K)*T(I,J+1,K)+
C       G(I,J,K)*T(I,J,K+1)=Q(I,J,K)
C
C              WITH I=1,2,...,N1 , J=1,2,...,N2 AND K=1,2,...,N3
C              AND WHERE T(I,J,K) IS THE ARRAY WHOSE VALUES
C              ARE SOUGHT (AND WHICH OVERWRITES THE INITIAL
C              APPROXIMATION STORED ON INPUT IN THE ARRAY
C              T). ANY VALUES OF T OUTSIDE THE
C              (1-N1,1-N2,1-N3) ARRAY ARE TAKEN AS ZERO.
C     Q        IS THE ARRAY OF SOURCE TERMS DIMENSIONED
C              Q(N1M,N2M,N3).
C
C     T        ARRAY STORING THE APPROXIMATE SOLUTION OF T
C              IN THE ABOVE EQUATION WHICH IS PASSED TO THE
C              ROUTINE. IF NO BETTER APPROXIMATION IS
C              KNOWN, AN ARRAY OF ZEROS CAN BE USED.
C              DIMENSIONED T(N1M,N2M,N3) CHANGED ON RETURN
C              TO THE SOLUTION OBTAINED.
C
C     APARAM   IS AN ITERATION ACCELERATION PARAMETER FACTOR
C              TYPICALLY SET TO 1.0. IF CONVERGENCE IS
C              SLOW, IT CAN BE DECREASED. IF DIVERGENCE IS
C              OBTAINED, IT SHOULD BE INCREASED. IN EITHER
C              CASE IT MUST NOT GO OUTSIDE THE BOUNDS
C              PRESCRIBED.
C
C     ITMAX    IS THE MAXIMUM NUMBER OF ITERATIONS TO BE USED
C
C     ITCOUN   IS AN INDICATOR SET EQUAL TO 1 ON THE FIRST
C              CALL TO D03ECF FOR SUBSEQUENT CALLS FOR THE
C              SAME PROBLEM, I.E. SAME N1 N2 N3, BUT
C              POSSIBLY DIFFERENT COEFFICIENTS AND/OR
C              SOURCE TERMS,  AS OCCUR WITH NON-LINEAR
C              SYSTEMS OR TIME-DEPENDENT SYSTEMS, ITCOUN
C              SHOULD BE SET TO THE NUMBER OF ITERATIONS
C              USED SO FAR.  ON SUBSEQUENT CALLS TO ENSURE
C              SUITABLE CYCLING OF THE ITERATION
C              ACCELERATION PARAMETERS IN D03UBF. CHANGED ON
C              EXIT TO THE NUMBER OF ITERATIONS USED SO FAR
C              I.E. ITCOUN  ON RETURN  =  ITCOUN  ON INPUT
C              +  ITUSED  ON RETURN
C     NDIR     IS AN INTEGER SET TO A NON-ZERO VALUE FOR
C              SYSTEMS OF EQUATIONS WHICH HAVE A UNIQUE
C              SOLUTION. FOR SYSTEMS DERIVED FROM, FOR
C              EXAMPLE LAPACES EQUATION WITH ALL NEUMANN
C              BOUNDARY CONDITIONS,  PROBLEMS TO WHICH AN
C              ARBITRARY CONSTANT CAN BE ADDED TO THE
C              SOLUTION, NDIR SHOULD BE SET TO 0 (ZERO) AND
C              THE VALUES OF THE  NEXT THREE PARAMETERS
C              MUST BE SPECIFIED. FOR SUCH PROBLEMS THE
C              ROUTINE SUBTRACTS THE VALUE OF THE FUNCTION
C              DERIVED AT THE  NODE (IXN,IYN,IZN) FROM THE
C              WHOLE SOLUTION AFTER EACH ITERATION TO
C              REDUCE THE POSSIBILITY OF LARGE ROUNDING
C              ERRORS. THE  USER MUST ALSO ENSURE THAT FOR
C              SUCH PROBLEMS THE APPROPRIATE CONSISTENCY
C              CONDITION ON THE SOURCE TERMS IS SATISFIED.
C
C     IXN,IYN,IZN  NODAL INDECIES OF THE NODE AT WHICH THE
C              SOLUTION IS TO BE REDUCED TO ZERO FOR
C              PROBLEMS FOR WHICH NDIR IS SET TO 0 THE NODE
C              SHOULD NOT CORRESPOND TO A CORNER NODE OF
C              THE  REGION OF INTEREST.
C
C     CONVERGENCE CRITERIA
C
C     CONRES   CONVERGENCE CRITERION ON THE MAXIMUM ABSOLUTE
C              VALUE OF THE NORMALIZED RESIDUAL, THE LATTER
C              BEING DEFINED AS THE RESIDUAL OF THE
C              EQUATION DIVIDED BY THE CENTRAL COEFFICIENT
C              WHEN THE LATER IS NOT EQUAL TO 0.0, AND
C              DEFINED AS THE  RESIDUAL WHEN THE CENTRAL
C              COEFFICIENT IS 0.0.
C
C     CONCHN   CONVERGENCE CRITERION ON THE MAXIMUM ABSOLUTE
C              VALUE OF THE CHANGE MADE AT EACH ITERATION
C              TO THE ARRAY T.
C
C       CONVERGENCE IS ACHIEVED WHEN BOTH THE CRITERIA ARE
C       SATISFIED.
C
C     RESIDS   ARRAY OF DIMENSION  ITMAX ... SEE OUTPUT
C
C     CHNGS    ARRAY OF DIMENSION  ITMAX ... SEE OUTPUT
C
C     WRKSP1   IS A WORKSPACE ARRAY OF DIMENSION
C              (N1M,N2M,N3) USED BY D03UBF
C
C     WRKSP2    ... DITTO ...
C
C     WRKSP3    ... DITTO ...
C
C     WRKSP4   IS A WORKSPACE ARRAY OF DIMENSION
C              (N1M,N2M,N3) USED TO PASS THE RESIDUALS TO
C              D03UBF, AND IN WHICH THE UPDATE VALUES ARE
C              RETURNED FROM D03UBF TO THIS ROUTINE.
C     IFAIL    IS AN ERROR PARAMETER INDICATOR SET BY THE USER TO
C              INDICATE THE TYPE OF FAILURE IF AN ERROR IS
C              ENCOUNTERED.
C
C     ALL ABOVE PASSED AS ARGUMENTS
C
C     PROCESS
C     -------
C
C     SET ERROR PARAMETER
C     CHECK INPUT INTEGERS
C     COMMENCEMENT OF CALCULATIONAL PROCEDURE
C     START OF ITERATIVE SOLUTION PROCEDURE
C        SET CONVERGENCE PARAMETER ACCUMULATORS TO ZERO
C        CALCULATE THE RESIDUALS AND STORE IN ARRAY WRKSP4
C        CALL SUBROUTINE  D03UBF TO PERFORM ONE ITERATION OF S.I.P.
C         AND WHICH RETURNS THE ARRAY OF UPDATES IN THE ARRAY WRKSP4
C        COMBINE THE UPDATES WITH THE OLD SOLUTION
C        CHECK FOR CONVERGENCE
C     REPEAT TO CONVERGENCE OR UNTIL MAXIMUM NUMBER OF
C      ITERATIONS HAVE BEEN USED.
C     SET ERROR INDICATOR ACCORDINGLY.
C     RETURN
C
C     OUTPUTS
C     -------
C
C     T          ARRAY STORING THE SOLUTION TO THE SYSTEM OF
C                EQUATIONS PROVIDED.
C
C     ITUSED     NUMBER OF ITERATIONS ACTUALLY USED THIS CALL.
C
C     ITCOUN     ACCUMULATED NUMBER OF ITERATIONS USED
C                ITCOUN  ON OUTPUT  =  ITCOUN  ON INPUT  +
C                 ITUSED  ON OUTPUT
C
C     RESIDS     VECTOR STORING THE MAXIMUM ABSOLUTE RESIDUALS
C                OF EACH ITERATION,  DIMENSION  ITMAX.  ONLY
C                THE FIRST  ITUSED VALUES ARE SET ON RETURN.
C
C     CHNGS      ARRAY STORING THE MAXIMUM ABSOLUTE CHANGES OF
C                EACH ITERATION, DIMENSION   ITMAX.  ONLY THE
C                FIRST  ITUSED VALUES ARE SET ON RETURN.
C
C     IFAIL      ERROR INDICATOR
C          = 0  CORRECT RETURN
C          = 1  EITHER N1.LE.1 OR N2.LE.1 OR N3.LE.1
C          = 2  N1M IS LESS THAN N1 OR N2M IS LESS THAN N2
C          = 3  APARAM.LE.0.0
C          = 4  APARAM.GT.((N1-1)**2+(N2-1)**2+(N3-1)**2)/3.
C          = 5  CONVERGENCE NOT ACHIEVED. REFER TO VALUES
C               IN RESIDS AND CHNGS TO DETERMINE IF THE
C               ITERATION WAS CONVERGING. REFER TO GUIDE
C               ON SETTING APARAM IF CONVERGENCE IS VERY
C               SLOW.
C
C     ALL PASSED AS ARGUMENTS
C
C     ROUTINES USED
C     -------------
C
C     D03UBF    SINGLE ITERATION OF S.I.P. FOR A SEVEN POINT
C               MOLECULE SYSTEM.
C     P01AAF     ERROR HANDLING ROUTINE
C
C     **************************************************************
C
C
C     SET ERROR PARAMETER AND ITERATION COUNTER
C

D03EDF
      SUBROUTINE D03EDF(NGX,NGY,LDA,A,RHS,UB,MAXIT,ACC,US,U,IOUT,NUMIT,
     *                  IFAIL)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C     MARK 12B REVISED. IER-534 (FEB 1987).
C     MARK 13 REVISED. IER-624 (APR 1988).
C     MARK 14 REVISED. IER-811 (DEC 1989).
C
C     MGD1 author -- P Wesseling, Delft University, Holland
C     Modified by -- C P Thompson and G J McCarthy, CSSD, AERE Harwell
C     Modified for NAG usage -- NAG Central Office
C

D03EEF
      SUBROUTINE D03EEF(XMIN,XMAX,YMIN,YMAX,PDEF,BNDY,NGX,NGY,LDA,A,RHS,
     *                  SCHEME,IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.

D03FAF
      SUBROUTINE D03FAF(XS,XF,L,LBDCND,BDXS,BDXF,YS,YF,M,MBDCND,BDYS,
     *                  BDYF,ZS,ZF,N,NBDCND,BDZS,BDZF,LAMBDA,LDIMF,
     *                  MDIMF,F,PERTRB,W,LWRK,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.

D03MAF
      SUBROUTINE D03MAF(H,M,N,NB,NPTS,PLACES,INDEX,IDIM,IN,DIST,LD,
     *                  IFAIL)
C     MARK 7 RELEASE. NAG COPYRIGHT 1978.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     **************************************************************
C
C     H IS THE LENGTH OF THE SIDES OF THE TRIANGLES IN THE ORIGINAL
C     GRID.
C     ON THE LINE Y=-H/2 THERE ARE M GRID POINTS AT X=0,H*SQRT(3.0),
C     . . .,(M-1)*H*SQRT(3.0) IN THE ORIGINAL GRID.
C     ON THE LINE X=0 THERE ARE N GRID POINTS AT Y=-H/2,H/2,...,
C     (N-3/2)*H IN THE ORIGINAL GRID.
C     WE WILL REFER TO A LINE OF POINTS OF THE ORIGINAL GRID WITH
C     THE SAME COORDINATES AS A GRID COLUMN.
C     THE REGION OVER WHICH THE EQUATION IS TO BE SOLVED MUST LIE
C     WITHIN THE RECTANGLE WITH CORNERS AT (0,0),(0,(N-1)*H),
C     ((M-1)*H*SQRT(3.0),0).
C     NB      IS THE NUMBER OF TIMES A TRIANGLE SIDE IS BISECTED
C             TO FIND ITS POINT OF INTERSECTION WITH THE BOUNDARY.
C             THE ACCURACY IS THEREFORE H/2**NB.
C     NPTS    IS THE NUMBER OF POINTS AT WHICH THE SOLUTION IS
C             FOUND. THIS IS CALCULATED BY D03MAF. IN THE EVENT
C             OF FAILURE BECAUSE NDIM IS TOO SMALL (IFAIL=1) OR
C             BECAUSE AN INTERNAL POINT IS FOUND ON OR OUTSIDE THE
C             BOUNDING RECTANGLE (IFAIL=2) OR BECAUSE LD IS TOO
C             SMALL (IFAIL=3) THEN NPTS IS SET TO ZERO.
C     PLACES  IS AN ARRAY IN WHICH THE X AND Y COORDINATES OF THE
C             GRID POINTS ARE STORED. ITS SECOND DIMENSION SHOULD
C             BE AT LEAST IDIM WHICH MUST BE LESS THAN NPTS.
C             D03MAF CHECKS THAT IDIM.GE.NPTS.
C     FOR THE JTH POINT AND ITS THREE NEIGHBOURS AHEAD OF IT IN
C     THE ORDERING, INDEX(I,J),I=1,4 HOLDS
C             (THE POINT NUMBER) FOR INTERNAL POINTS
C             - (THE POINT NUMBER) FOR BOUNDARY POINTS AND
C             ZERO FOR EXTERNAL POINTS.
C     IN      IS THE NAME OF AN INTEGER VALUED FUNCTION TO BE
C             SUPPLIED BY THE USER. IT HAS REAL ARGUMENTS X,Y AND
C             SHOULD RETURN THE VALUE 1 IF (X,Y) LIES INSIDE THE
C             REGION AND 0 IF OUTSIDE.
C     DIST    IS AN ARRAY USED FOR WORKSPACE. ITS SECOND DIMENSION
C             SHOULD BE AT LEAST LD WHICH MUST BE AT LEAST 4*N.
C
C     **************************************************************
C

D03PCF
      SUBROUTINE D03PCF(NPDE,M,TS,TOUT,PDEDEF,BNDARY,U,NPTS,X,ACC,W,NW,
     *                  IW,NIW,ITASK,ITRACE,IND,IFAIL)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C---------------------------------------------------------------------
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C  This code is the setup routine for PDE problems only.
C  The remeshing option is not available and the linear algebra
C  is restricted to using a banded matrices, with BDF method
C  integrator.
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C-------------------------------------------------------------------

D03PDF
      SUBROUTINE D03PDF(NPDE,M,TS,TOUT,PDEDEF,BNDARY,U,NBKPTS,XBKPTS,
     *                  NPOLY,NPTS,X,UINIT,ACC,W,NW,IW,NIW,ITASK,ITRACE,
     *                  IND,IFAIL)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C     MARK 16 REVISED. IER-1131 (JUL 1993).
C
C     Modified to meet NAG standard  by  M.S. Derakhshan
C ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C ----------------------------------------------------------------------

D03PEF
      SUBROUTINE D03PEF(NPDE,TS,TOUT,PDEDEF,BNDARY,U,NPTS,X,NLEFT,ACC,W,
     *                  NW,IW,NIW,ITASK,ITRACE,IND,IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1993.
C
C-----------------------------------------------------------------------
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C     This code is the setup routine for PDE problems only.
C     The remeshing option is not available and the linear algebra
C     is restricted to banded matrices, with BDF method integrator.
C+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C-----------------------------------------------------------------------

D03PHF
      SUBROUTINE D03PHF(NPDE,M,TS,TOUT,PDEDEF,BNDARY,U,NPTS,X,NCODE,
     *                  ODEDEF,NXI,XI,NEQN,RTOL,ATOL,ITOL,NORM,LAOPT,
     *                  ALGOPT,W,NW,IW,NIW,ITASK,ITRACE,IND,IFAIL)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C----------------------------------------------------------------------
C++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

D03PJF
      SUBROUTINE D03PJF(NPDE,M,TS,TOUT,PDEDEF,BNDARY,U,NBKPTS,XBKPTS,
     *                  NPOLY,NPTS,X,NCODE,ODEDEF,NXI,XI,NEQN,UVINIT,
     *                  RTOL,ATOL,ITOL,NORM,LAOPT,ALGOPT,W,NW,IW,NIW,
     *                  ITASK,ITRACE,IND,IFAIL)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C
C     Modified to meet NAG standard  by  M.S. Derakhshan
C ----------------------------------------------------------------------
C ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

D03PKF
      SUBROUTINE D03PKF(NPDE,TS,TOUT,PDEDEF,BNDARY,U,NPTS,X,NLEFT,NCODE,
     *                  ODEDEF,NXI,XI,NEQN,RTOL,ATOL,ITOL,NORM,LAOPT,
     *                  ALGOPT,W,NW,IW,NIW,ITASK,ITRACE,IND,IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1993.
C ----------------------------------------------------------------------
C ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

D03PPF
      SUBROUTINE D03PPF(NPDE,M,TS,TOUT,PDEDEF,BNDARY,UVINIT,U,NPTS,X,
     *                  NCODE,ODEDEF,NXI,XI,NEQN,RTOL,ATOL,ITOL,NORM,
     *                  LAOPT,ALGOPT,REMESH,NXFIX,XFIX,NRMESH,DXMESH,
     *                  TRMESH,IPMINF,XRATIO,CONST,MONFFD,W,NW,IW,NIW,
     *                  ITASK,ITRACE,IND,IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1993.
C
C ----------------------------------------------------------------------
C     N.B. Integer workspace is NXFIX+1 greater than in non-remeshing
C         routines to allow allocation of memory for the array IXFIX
C         with adjustable dimensions NXFIX+1 (the additional 1 being
C         necessary since NXFIX can be zero). i.e. IW(NIW-NXFIX) is
C         passed to D03PHZ as the start of the array(IXFIX(NXFIX+1).
C         Local scalar NIWO is the size of the original integer
C         workspace (passed to D03PHZ).
C ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

D03PRF
      SUBROUTINE D03PRF(NPDE,TS,TOUT,PDEDEF,BNDARY,UVINIT,U,NPTS,X,
     *                  NLEFT,NCODE,ODEDEF,NXI,XI,NEQN,RTOL,ATOL,ITOL,
     *                  NORM,LAOPT,ALGOPT,REMESH,NXFIX,XFIX,NRMESH,
     *                  DXMESH,TRMESH,IPMINF,XRATIO,CONST,MONFKB,W,NW,
     *                  IW,NIW,ITASK,ITRACE,IND,IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1993.
C ----------------------------------------------------------------------
C     SEE COMMENTS IN D03PPF ABOUT SIZE OF INTEGER WORKSPACE
C ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

D03PYF
      SUBROUTINE D03PYF(NPDE,U,NBKPTS,XBKPTS,NPOLY,NPTS,XP,INTPTS,ITYPE,
     *                  UOUT,W,NW,IFAIL)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C    -------------------------------------------------------------------
C    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C
C     Routine to provide values of the solution and possibly the
C     first derivative in space and the flux on the mesh
C     XP(INTPTS).
C
C   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C   --------------------------------------------------------------------

D03PZF
      SUBROUTINE D03PZF(NPDE,M,U,NPTS,X,XP,INTPTS,ITYPE,UOUT,IFAIL)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C     -----------------------------------------------------
C     +++++++++++++++++++++++++++++++++++++++++++++++++++++
C     Routine to compute solution and possibly its first deriv
C     at the interpolation points stored in the array XP.
C     Linear interpolation is used.
C
C     Parameter list :
C
C     XP(INTPTS) ;  the spatial interpolation points,
C                 XP(I) < XP(I+1) , I = 1, IPTS-1
C
C     UOUT(NPDE,IPTS,ITYPE) ;  array to hold the values found by
C                         linear interpolation
C
C           UOUT(J,K,1)  ;  holds U(XP(K),T) for PDE J
C           UOUT(J,K,2)  ;  holds DU/DX of UOUT(J,K,1)
C
C     X(NPTS)    ;  is an array that contains the original mesh
C
C     U(NEQN)    ;  holds the original solution; the first NPDE*NPTS
C                   components of this contains the PDE solution at the
C                   mesh points X(NPTS) and the last NV components are
C                   the additional coupled ode variables
C
C     ITYPE      ;  has value 1 or 2 depending on how many components
C                   of the array UP are required
C
C     IFAIL    ;  error flag ; set to I if XP(I) lies outside the range
C                   (X(1) , X(NPTS)) .
C     ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C     ------------------------------------------------------------------
C

D03UAF
      SUBROUTINE D03UAF(N1,N2,N1M,A,B,C,D,E,APARAM,IT,R,WRKSP1,WRKSP2,
     *                  IFAIL)
C     MARK 7 RELEASE. NAG COPYRIGHT 1978.
C     MARK 10A REVISED. IER-386 (OCT 1982).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     **************************************************************
C     D03UAF PERFORMS 1 ITERATION OF THE STRONGLY IMPLICIT PROCEDURE
C     AT EACH CALL TO CALCULATE THE SUCCESSIVE APPROXIMATE
C     CORRECTIONS TO THE SOLUTION OF A SYSTEM OF SIMULTANEOUS
C     ALGEBRAIC EQUATIONS FOR WHICH THE ITERATIVE UPDATE MATRIX IS
C     OF THE FIVE POINT MOLECULE FORM ON A TOPOLOGICALLY TWO-
C     DIMENSIONAL RECTANGULAR MESH.
C
C     STRONGLY IMPLICIT PROCEDURE ROUTINE FOR 2 DIMENSIONAL 05
C     POINT MOLECULES.
C
C     INPUTS
C
C     N1      NUMBER OF NODES IN THE FIRST COORDINATE DIRECTION.
C     N2      NUMBER OF NODES IN THE SECOND COORDINATE DIRECTION.
C     N1M     FIRST DIMENSION OF ALL THE TWO-DIMENSIONAL ARRAYS.
C     A       ARRAY OF DIMENSION (N1M,N2) STORING THE COEFFICIENT
C             OF THE ITERATIVE UPDATE EQUATIONS AS SHOWN BELOW -
C     B       ... DIMENSION (N1M,N2) ...
C     C       ... DIMENSION (N1M,N2) ...
C     D       ... DIMENSION (N1M,N2) ...
C     E       ... DIMENSION (N1M,N2) ...
C
C     A(I,J)*S(I,J-1)+B(I,J)*S(I-1,J)+C(I,J)*S(I,J)+D(I,J)*
C      S(I+1,J)+E(I,J)*S(I,J+1)=R(I,J)
C
C             WITH I=1,2,...,N1 AND J=1,2,...,N2 AND WHERE S(I,J)
C             IS THE ARRAY WHOSE APPROXIMATE VALUES ARE SOUGHT
C             (AND WHICH OVERWRITE THE RESIDUALS R(I,J) STORED ON
C             INPUT IN THE ARRAY R). ANY VALUES OF S OUTSIDE THE
C             (1-N1,1-N2) ARRAY WHICH DEFINES THE PROBLEM REGION
C             ARE TAKEN AS ZERO.
C     R       IS INPUT AS THE ARRAY OF RESIDUALS, CORRESPONDING
C             TO R ABOVE, CHANGED ON OUTPUT TO THE VALUES OF THE
C             UPDATE ARRAY CORRESPONDING TO S ABOVE, DIMENSIONED
C             (N1M,N2).
C     APARAM  IS AN ITERATION ACCELERATION PARAMETER FACTOR
C             TYPICALLY SET TO 1.0. IF CONVERGENCE IS SLOW, IT
C             CAN BE DECREASED. IF DIVERGENCE IS OBTAINED, IT
C             SHOULD BE INCREASED. IN EITHER CASE IT MUST NOT GO
C             OUTSIDE THE BOUNDS PRESCRIBED (SEE IFAIL PARAMETER
C             FOR D03UAF).
C     IT      IS THE ITERATION COUNTER SET AND INCREMENTED BY
C             THE CALLING ROUTINE, IT IS USED TO DETERMINE THE
C             APPROPRIATE ITERATION PARAMETERS.
C     WRKSP1  IS A WORKSPACE ARRAY OF DIMENSION (N1M,N2).
C     WRKSP2  ... DITTO ...
C     IFAIL   IS AN ERROR PARAMETER INDICATOR SET BY THE USER TO
C             INDICATE THE TYPE OF FAILURE IF AN ERROR IS
C             ENCOUNTERED.
C
C     PROCESS
C
C     SET ERROR PARAMETER
C     CHECK INPUT INTEGERS
C     SET FREQUENTLY REQUIRED INTEGER VARIABLES
C     COMMENCEMENT OF CALCULATIONAL PROCEDURE
C     SET ODD/EVEN COUNTERS  KS=1 FOR ODD ITERATIONS
C                            KS=2 FOR EVEN ITERATIONS
C     DETERMINE THE NUMBER OF THE ACCELERATION PARAMETER TO BE USED
C     (THE SAME PARAMETER IS USED FOR 2 ITERATIONS, THERE ARE 9
C     PARAMETERS IN ALL).
C     FIRST CALCULATE THE TERM, ALM, IN THE LARGEST PARAMETER
C     CHECK THE VALUES OF ALM
C     DETERMINE THE ITERATION PARAMETER
C     START THE APPROXIMATE LU FACTORIZATION DETERMINING THE VALUES
C     OF THE ELEMENTS SB,SC IN THE LOWER TRIANGULAR MATRIX L AND
C     WRKSP1 AND WRKSP2 IN THE UPPER TRIANGULAR MATRIX U. PROGRESS
C     FORWARDS FIRST AND INVERT THE LOWER TRIANGULAR MATRIX L AS
C     ONE PROCEEDS SO THAT THE ELEMENTS SB,SC DO NOT HAVE TO BE
C     STORED IN ARRAYS. THE ELEMENTS WRKSP1 AND WRKSP2 HAVE TO BE
C     STORED FOR THE SUBSEQUENT INVERSION OF THE MATRIX U BY BACK
C     SUBSTITUTION.
C     DO JL = 1,N2
C        (JL IS ONLY A COUNTER IN THE SECOND COORDINATE DIRECTION
C         J IS THE INDEX OF THE SECOND COORDINATE AND ON
C         ALTERNATE ITERATIONS SCANS FIRST INCREASING AND THEN
C         DECREASING).
C         DO I = 1,N1
C            (I IS THE INDEX IN THE FIRST COORDINATE DIRECTION)
C             STORE TH VALUE OF THE CENTRAL COEFFICIENT
C             DETERMINE THE TYPE OF THE DIFFERENCE EQUATION
C               FOR A FIVE POINT MOLECULE EQUATION -
C                  SET VALUES OF ADJACENT ARRAY ELEMENTS DEPENDENT
C                  ON NODAL POSITION
C                  CALCULATE THE OFF-DIAGONAL ELEMENTS OF L,
C                  NAMELY SB AND SC
C                  CALCULATE THE OFTEN USED EXPRESSIONS
C                  CALCULATE THE VALUE OF THE DIAGONAL ELEMENT OF L
C                  CALCULATE AND STORE THE ELEMENTS OF U, NAMELY
C                  WRKSP1 AND WRKSP2
C                  CALCULATE THE ELEMENTS OF L**(-1) * RESIDUAL
C                  ARRAY
C               FOR THE EXPLICIT EQUATION DO THE SAME
C     END OF SCAN FOR FORWARD ELIMINATION
C     BACK SUBSTITUTION TO MULTIPLY BY U**(-1)
C     DO JL = 1,N2
C        J RUNS BACKWARDS AND FORWARDS ALTERNATELY
C        DO I = N1,N1-1,....,2,1
C           R IS INITIALLY L**(-1) * RESIDUAL, IT BECOMES
C           (U**(-1) * (L**(-1) *RESIDUAL) = CHANGE
C     END OF SCAN FOR BACK SUBSTITUTION
C     RETURN
C
C     OUTPUTS
C
C     R       ARRAY STORING THE APPROXIMATE SOLUTION TO THE SYSTEM
C             OF EQUATIONS PROVIDED, AFTER ONE ITERATION. NOTE
C             THAT IT HAS OVERWRITTEN THE INPUT RESIDUAL.
C     IFAIL   ERROR INDICATOR
C             =0 CORRECT RETURN
C             =1 EITHER N1.LE.1 OR N2.LE.1
C             =2 N1M IS LESS THAN N1
C             =3 APARAM.LE.0.0
C             =4 APARAM.GT.((N1-1)**2+N2-1)**2)/2.
C
C     ROUTINES USED
C
C     P01AAF  ERROR HANDLING ROUTINE
C
C     **************************************************************
C

D03UBF
      SUBROUTINE D03UBF(N1,N2,N3,N1M,N2M,A,B,C,D,E,F,G,APARAM,IT,R,
     *                  WRKSP1,WRKSP2,WRKSP3,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 10A REVISED. IER-387 (OCT 1982).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     **************************************************************
C
C            DAVID A. H.  JACOBS         22/5/79
C     D03UBF PERFORMS ONE ITERATION OF THE STRONGLY IMPLICIT
C     PROCEDURE AT EACH CALL TO CALCULATE THE SUCCESSIVE
C     APPROXIMATE CORRECTIONS TO THE SOLUTION OF A SYSTEM
C     OF SIMULTANEOUS ALGEBRAIC EQUATIONS FOR WHICH THE
C     ITERATIVE UPDATE MATRIX IS OF THE SEVEN POINT
C     MOLECULE FORM ON A TOPOLOGICALLY THREE-DIMENSIONAL
C     RECTANGULAR MESH.
C
C     INPUTS
C     ------
C
C     N1       NUMBER OF NODES IN THE FIRST COORDINATE DIRECTION.
C
C     N2       NUMBER OF NODES IN THE SECOND COORDINATE DIRECTION.
C
C     N3       NUMBER OF NODES IN THE THIRD COORDINATE DIRECTION.
C
C     N1M      FIRST DIMENSION OF ALL THREE DIMENSIONAL ARRAYS.
C
C     N2M      SECOND DIMENSION OF ALL THREE DIMENSIONAL ARRAYS.
C
C     A,B,C,   ARRAYS ALL OF DIMENSION (N1M,N2M,N3) STORING
C     D,E,F,G  THE COEFFICIENTS OF THE ITERATIVE UPDATE
C              EQUATIONS  -
C
C       A(I,J,K)*S(I,J,K-1)+B(I,J,K)*S(I,J-1,K)+C(I,J,K)*S(I-1,J,K)+
C       D(I,J,K)*S(I,J,K)+E(I,J,K)*S(I+1,J,K)+F(I,J,K)*S(I,J+1,K)+
C       G(I,J,K)*S(I,J,K+1)=R(I,J,K)
C
C              WITH I=1,2,...,N1 , J=1,2,...,N2 AND K=1,2,...,N3
C              AND WHERE S(I,J,K) IS THE ARRAY WHOSE
C              APPROXIMATE VALUES ARE SOUGHT (AND WHICH
C              OVERWRITE THE RESIDUALS R(I,J,K) STORED ON
C              INPUT IN THE ARRAY R). ANY VALUES OF S
C              OUTSIDE THE  (1-N1,1-N2,1-N3) ARRAY ARE
C              TAKEN AS ZERO.
C
C     R        IS INPUT AS THE ARRAY OF RESIDUALS,
C              CORRESPONDING TO R ABOVE, CHANGED ON OUTPUT
C              TO THE VALUES  OF THE UPDATE ARRAY
C              CORRESPONDING TO S ABOVE, DIMENSIONED
C              R(N1M,N2M,N3)
C
C     APARAM   IS AN ITERATION ACCELERATION PARAMETER FACTOR
C              TYPICALLY SET TO 1.0. IF CONVERGENCE IS
C              SLOW, IT CAN BE DECREASED. IF DIVERGENCE IS
C              OBTAINED, IT SHOULD BE INCREASED. IN EITHER
C              CASE IT MUST NOT GO OUTSIDE THE BOUNDS
C              PRESCRIBED. (SEE IFAIL PARAMETER DETAILS.)
C
C     IT        IS THE ITERATION COUNTER SET AND
C              INCREMENTED BY THE CALLING ROUTINE, IT IS
C              USED TO DETERMINE THE APPROPRIATE ITERATION
C              PARAMETERS.
C
C     WRKSP1   IS A WORKSPACE ARRAY OF DIMENSION (N1M,N2M,N3)
C
C     WRKSP2    ... DITTO ...
C
C     WRKSP3    ... DITTO ...
C
C     IFAIL    IS AN ERROR PARAMETER INDICATOR SET BY THE USER TO
C              INDICATE THE TYPE OF FAILURE IF AN ERROR IS
C              ENCOUNTERED.
C
C     ALL ABOVE PASSED AS ARGUMENTS
C
C     PROCESS
C     -------
C
C     SET ERROR PARAMETER
C     CHECK INPUT INTEGERS
C     SET FREQUENTLY REQUIRED INTEGER VARIABLES
C     COMMENCEMENT OF CALCULATIONAL PROCEDURE
C     SET ODD/EVEN COUNTERS   KS=1  FOR ODD ITERATIONS
C                            KS=2  FOR EVEN ITERATIONS
C     DETERMINE THE NUMBER OF THE ACCELERATION PARAMETER TO
C     BE USED (THE SAME PARAMETER IS USED FOR 2 ITERATIONS,
C     THERE ARE 9 PARAMETERS IN ALL).
C     FIRST CALCULATE THE TERM, ALM, IN THE LARGEST PARAMETER
C     CHECK THE VALUES OF ALM
C     DETERMINE THE ITERATION PARAMETER
C     START OF APPROXIMATE LU FACTORIZATION DETERMINING THE
C     VALUES OF THE ELEMENTS SA,SB,SC IN THE LOWER
C     TRIANGULAR MATRIX L AND WRKSP1, WRKSP2 AND WRKSP3 IN
C     THE UPPER TRIANGULAR MATRIX U. PROGRESS FORWARDS
C     FIRST  AND INVERT THE LOWER TRIANGULAR MATRIX L AS
C     ONE PROCEEDS SO THAT THE ELEMENTS SA,SB,SC DO NOT
C     HAVE TO BE STORED IN ARRAYS.THE ELEMENTS WRKSP1,
C     WRKSP2 AND WRKSP3 HAVVE TO BE STORED FOR THE
C     SUBSEQUENT  INVERSION OF THE MATRIX U BY BACK
C     SUBSTITUTION.
C     DO KL=1,N3
C       (KL IS ONLY A COUNTER IN THE THIRD COORDINATE DIRECTION
C        K IS THE INDEX OF THE THIRD COORDINATE AND ON ALTERNATE
C        ITERATIONS SCANS FIRST INCREASING AND THEN DECREASING).
C       DO JL=1,N2
C          (JL IS ONLY A COUNTER IN THE SECOND COORDINATE DIRECTION
C           J IS THE INDEX OF THE SECOND COORDINATE AND ON ALTERNATE
C           ITERATIONS SCANS FIRST INCREASING AND THEN DECREASING).
C          DO I=1,N1
C             (I IS THE INDEX IN THE FIRST COORDINATE DIRECTION)
C             STORE THE VALUE OF THE CENTRAL COEFFICIENT
C             DETERMINE THE TYPE OF THE DIFFERENCE EQUATION
C                FOR A SEVEN POINT MOLECULE EQUATION -
C                   SET VALUES OF ADJACENT ARRAY ELEMENTS
C                    DEPENDENT ON NODAL POSITION
C
C                   CALCULATE THE OFF-DIAGONAL ELEMENTS OF
C                   L, NAMELY SA,SB,SC
C                   CALCULATE OFTEN USED EXPRESIONS
C                   CALCULATE THE VALUE OF THE DIAGONAL ELEMENT OF L
C                   CALCULATE AND STORE THE ELEMENTS OF U,
C                    NAMELY WRKSP1, WRKSP2 AND WRKSP3
C
C                   CALCULATE THE ELEMENTS OF L**(-1) *
C                   RESIDUAL ARRAY
C                FOR THE EXPLICIT EQUATION DO THE SAME
C     END OF SCAN FOR THE FORWARD ELIMINATION
C     BACK SUBSTITUTION TO MULTIPLY BY  U**(-1)
C     DO KL=1,N3
C       K RUNS BACKWARDS AND FORWARDS ALTERNATELY
C       DO JL=1,N2
C          J RUNS BACKWARDS AND FORWARDS ALTERNATELY
C          DO I=N1,N1-1,...,2,1
C             R IS INITIALLY L**(-1) * RESIDUAL, IT BECOMES
C              (U**(-1) * (L**(-1) * RESIDUAL) = CHANGE
C     END OF SCAN FOR THE BACK SUBSTITUTION
C     RETURN
C
C     OUTPUTS
C     -------
C
C     R         ARRAY STORING THE APPROXIMATE SOLUTION TO
C               THE SYSTEM OF EQUATIONS PROVIDED, AFTER
C               THE ONE ITERATION. NOTE THAT IT HAS
C               OVERWRITTEN THE INPUT RESIDUAL.
C
C     IFAIL     ERROR INDICATOR
C          = 0  CORRECT RETURN
C          = 1  EITHER N1.LE.1 OR N2.LE.1 OR N3.LE.1
C          = 2  N1M IS LESS THAN N1 OR N2M IS LESS THAN N2
C          = 3  APARAM.LE.0.0
C          = 4  APARAM.GT.((N1-1)**2+(N2-1)**2+(N3-1)**2)/3.
C
C     BOTH PASSED AS ARGUMENTS
C
C     ROUTINES USED
C     -------------
C
C     P01AAF     ERROR HANDLING ROUTINE
C
C     **************************************************************
C

D04AAF
      SUBROUTINE D04AAF(XVAL,NDER,HBASE,DER,EREST,FUN,IFAIL)
C
C     ***   PURPOSE   ***
C
C     A SUBROUTINE FOR NUMERICAL DIFFERENTIATION AT A POINT.  IT
C     RETURNS A SET OF APPROXIMATIONS TO THE J-TH ORDER DERIVATIVE
C     (J=1,2,...14) OF FUN(X) EVALUATED AT X = XVAL  AND, FOR EACH
C     DERIVATIVE, AN ERROR ESTIMATE ( WHICH INCLUDES THE EFFECT OF
C     AMPLIFICATION OF ROUND- OFF ERRORS).
C
C
C     ***   INPUT  PARAMETERS   ***
C
C     (1) XVAL   REAL.  THE ABSCISSA AT WHICH THE SET OF
C     DERIVATIVES IS REQUIRED.
C     (2) NDER   INTEGER. THE HIGHEST ORDER DERIVATIVE REQUIRED.
C     IF(NDER.GT.0)  ALL DERIVATIVES UP TO MIN(NDER,14) ARE
C     CALCULATED.
C     IF(NDER.LT.0 AND NDER EVEN)  EVEN ORDER DERIVATIVES
C     UP TO MIN(-NDER,14) ARE CALCULATED.
C     IF(NDER.LT.0 AND NDER ODD )  ODD  ORDER DERIVATIVES
C     UP TO MIN(-NDER,13) ARE CALCULATED.
C     (3) HBASE  REAL.  A STEP LENGTH.
C     (6) FUN    THE NAME OF A REAL FUNCTION SUBPROGRAMME,
C     WHICH IS REQUIRED BY THE ROUTINE AS A SUBPROGRAMME
C     AND WHICH REPRESENTS THE FUNCTION BEING DIFFERENTIATED
C     THE ROUTINE REQUIRES 21 FUNCTION EVALUATIONS FUN(X)
C     LOCATED AT    X = XVAL    AND AT
C     X = XVAL + (2*J-1)*HBASE,  J=-9,-8, .... +9,+10.
C     THE FUNCTION VALUE AT  X = XVAL IS DISREGARDED WHEN
C     ONLY ODD ORDER DERIVATIVES ARE REQUIRED.
C
C     ***   OUTPUT PARAMETERS   ***
C
C     (4) DER(J)   J=1,2,...14.  REAL. A VECTOR OF
C     APPROXIMATIONS TO THE J-TH DERIVATIVE OF FUN(X)
C     EVALUATED AT X = XVAL.
C     (5) EREST(J) J=1,2,...14.  REAL. A VECTOR OF
C     ESTIMATES OF THE DABSOLUTE ACCURACY OF DER(J).  THESE
C     ARE NEGATIVE WHEN EREST(J).GT.ABS(DER(J)), OR WHEN,
C     FOR SOME OTHER REASON THE ROUTINE IS DOUBTFUL ABOUT
C     THE VALIDITY OF THE RESULT.
C
C     ***   IMPORTANT WARNING   ***
C
C     EREST IS AN ESTIMATE OF THE OVERALL ERROR.  IT IS ESSENTIAL
C     FOR
C     PROPER USE THAT THE USER CHECKS EACH VALUE OF DER
C     SUBSEQUENTLY
C     USED TO SEE THAT IT IS ACCURATE ENOUGH FOR HIS PURPOSES.
C     FAILURE TO DO THIS MAY RESULT IN THE CONTAMINATION OF ALL
C     SUBSEQUENT RESULTS.
C     IT IS TO BE EXPECTED THAT IN NEARLY ALL CASES  DER(14) WILL
C     BE
C     UNUSABLE.( 14 REPRESENTS A LIMIT IN WHICH FOR THE EASIEST
C     FUNCTION LIKELY TO BE ENCOUNTERED THIS ROUTINE MIGHT JUST
C     OBTAIN
C     AN APPROXIMATION OF THE CORRECT SIGN.)
C
C     ***   NOTE ON CALCULATION   ***
C
C     THE CALCULATION IS BASED ON THE EXTENDED T-TABLE (T SUB
C     K,P,S)
C     DESCRIBED IN LYNESS AND MOLER, NUM. MATH., 8, 458-464,(1966).
C     REFERENCES IN COMMENT CARDS TO TTAB(NK,NP,NS) REFER TO
C     T-TABLE
C     WITH NK=K+1,  NP=P+1,  NS=S+1.   SINCE ONLY PART OF THE
C     EXTENDED
C     T-TABLE IS NEEDED AT ONE TIME, THAT PART IS STORED IN
C     RTAB(10,7)
C     AND IS SUBSEQUENTLY OVERWRITTEN.  HERE
C     RTAB(NK,NP-NS+1)  =  TTAB(NK,NP,NS).
C
C     NAG COPYRIGHT 1976
C     MARK 5 RELEASE
C     MARK 6B REVISED  IER-116 (MAR 1978)
C     MARK 7 REVISED IER-139 (DEC 1978)
C     MARK 8 REVISED. IER-219 (MAR 1980)
C     MARK 8D REVISED. IER-271 (DEC 1980).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).

D05AAF
      SUBROUTINE D05AAF(LAMBDA,A,B,K1,K2,G,F,C,N,IND,W1,W2,WD,NMAX,MN,
     *                  IFAIL)
C     MARK 5 RELEASE  NAG COPYRIGHT 1976
C     MARK 6 REVISED
C     MARK 9 REVISED. IER-304 (SEP 1981).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     BASED UPON NPL DNAC LIBRARY SUBROUTINE F2926
C     THIS SUBROUTINE SOLVES THE FREDHOLM INTEGRAL EQUATION OF THE
C     SECOND KIND
C     F(X) - LAMBDA * (INTEGRAL FROM A TO B OF K(X,S) * F(S) DS) =
C     G(X)
C     FOR A.LE.X.LE.B, WHEN THE KERNEL IS DEFINED IN TWO PARTS
C     K = K1 FOR A.LE.S.LE.X AND K = K2 FOR X.LT.S.LE.B.
C     THE METHOD USED IS THAT OF EL-GENDI, WHICH REQUIRES
C     THAT EACH OF THE FUNCTIONS K1 AND K2 SHOULD BE SMOOTH
C     AND NON SINGULAR FOR ALL X AND S IN THE CLOSED INTERVAL
C     (A,B).
C     THE SUBROUTINE USES AUXILIARY SUBROUTINE F04AAF
C     AND FUNCTIONS P01AAF AND C06DBF.
C     NAG COPYRIGHT 1976
C     MARK 5 RELEASE

D05ABF
      SUBROUTINE D05ABF(K,G,LAMBDA,A,B,ODOREV,EV,N,CM,F1,WK,NMAX,NT2P1,
     *                  F,C,IFAIL)
C     MARK 6 RELEASE. NAG COPYRIGHT 1977.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     NPL DNAC LIBRARY SUBROUTINE F2925.
C
C     THIS SUBROUTINE SOLVES THE NON-SINGULAR FREDHOLM INTEGRAL
C     EQUATION OF THE SECOND KIND-
C     F(X) - LAMBDA*(INTEGRAL FROM A TO B OF K(X,S)*F(S) DS) = G(X)
C     FOR A .LE. X .LE. B, BY THE METHOD OF S.E. EL-GENDI
C     (COMPUTER J., 1969, VOL.12, PP.282-287).
C
C     THE SUBROUTINE USES AUXILIARY SUBROUTINES F04AAF
C     AND FUNCTIONS X01AAF,P01AAF AND C06DBF.
C

D05BAF
      SUBROUTINE D05BAF(CK,CG,CF,METHOD,IORDER,ALIM,TLIM,YN,ERREST,NOUT,
     *                  TOL,THRESH,WORK,IWK,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C     MARK 14B REVISED. IER-845 (MAR 1990).
C
C     <<<<<<<<<<<<<<<<<<<<<<<<<<<     >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
C
C          A code for the solution of convolution Volterra
C                 equation of the second kind
C
C                             by
C
C                   M.S Derakhshan,   January 1989.
C     ---------------------------------------------------------------
C     +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C     This subroutine computes the numerical solution of the
C     convolution Volterra integeral equation of the second kind
C
C                           t
C     (1)    y(t) = f(t) +  I k(t - s) g(s,y(s))ds,  (t >= a).
C                           a
C
C     The underlying methods for the numerical solution of (1)
C     are the reducible linear multistep formulae of the Adam's
C     and Backward Differentiation (BD) type.
C     +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C     ---------------------------------------------------------------

D05BDF
      SUBROUTINE D05BDF(CK,CF,CG,INITWT,IORDER,TLIM,TOLNL,NMESH,YN,WORK,
     *                  LWK,NCT,IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.
C
C     <<<<<<<<<<<<<<<<<<<<<<<<<<<<     >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
C
C          A code for the solution of nonlinear convolution
C             weakly singular Abel-Volterra equation
C                      of the second kind
C
C     M.S Derakhshan,
C     Mark 16. Nag Copyright, 1991.
C     --------------------------------------------------------------
C     ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C     This routine computes the numerical solution of a weakly
C     singular Volterra-Abel integral equation of the 2nd kind of
C     the form :
C                                 t     -1/2
C     y(t) = f(t) + (1/sqrt(pi))  I (t-s)    k(t-s) g(s, y(s)) ds,
C                                 0
C                                                      (t >= 0).
C     The solution  YN(i)  approximates  y(t) at  t = (i-1)*H,
C     i = 1, ..., NMESH. The code is based on
C     the BDF fractional linear multistep method of orders
C     4, 5 and 6 and FFT techniques can be used for the
C     computation of the lag term.
C     For a complete description of the parameters, see the
C     routine specification.
C     ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C     --------------------------------------------------------------

D05BEF
      SUBROUTINE D05BEF(CK,CF,CG,INITWT,IORDER,TLIM,TOLNL,NMESH,YN,WORK,
     *                  LWK,NCT,IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.
C
C     <<<<<<<<<<<<<<<<<<<<<<<<<<<<     >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
C
C          A code for the solution of nonlinear convolution
C             weakly singular Abel-Volterra equation
C                      of the first kind
C
C     M.S Derakhshan,
C     Mark 16. Nag Copyright, 1991.
C     ---------------------------------------------------------------
C     +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C     This routine computes the numerical solution of a weakly
C     singular Volterra-Abel integral equation of the 1st kind of
C     the form :
C                                 t     -1/2
C        0 = f(t) + (1/sqrt(pi))  I (t-s)    k(t-s) g(s, y(s)) ds,
C                                 0
C                                                      (t >= 0).
C     The solution  YN(i)  approximates  y(t) at  t = (i-1)*H,
C     i = 1, ..., NMESH. The code is based on
C     the BDF fractional linear multistep method of orders
C     4, 5 and 6 and FFT techniques can be used for the
C     computation of the lag term. The solution at zero should be
C     available.
C     For a complete description of the parameters, see the
C     routine specification.
C     +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C     -------------------------------------------------------------

D05BWF
      SUBROUTINE D05BWF(METHOD,IORDER,OMEGA,NOMG,LENSW,SW,LDSW,NWT,
     *                  IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.
C
C     <<<<<<<<<<<<<<<<<<<<<<<<<<<     >>>>>>>>>>>>>>>>>>>>>>>>>>>
C
C          A code for generating the quadrature weights
C          associated with a reducible linear multistep
C                  method for solving Volterra
C                         equations
C
C     Mark 16 Release. NAG Copyright 1991.
C     M.S Derakhshan,  May 1991.
C     ------------------------------------------------------
C     ++++++++++++++++++++++++++++++++++++++++++++++++++++++
C      This subroutine generates the weights associated with
C      the Adams formulae of the orders 3 to 6, and the
C      Backward Differentiation Formulae of the orders
C      2 to 5.
C     ++++++++++++++++++++++++++++++++++++++++++++++++++++++
C     ------------------------------------------------------
C
C
C

D05BYF
      SUBROUTINE D05BYF(IORDER,IQ,LENFW,WT,SW,LDSW,WORK,LWK,IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.
C
C     <<<<<<<<<<<<<<<<<<<<<<<<<     >>>>>>>>>>>>>>>>>>>>>>>>>>
C
C              A routine for computing Fractional weights
C                 of BDF formulae of orders 4, 5 and 6.
C
C     M.S. Derakhshan.
C     --------------------------------------------------------------
C     ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C     This routine computes the square root convolution weights
C     of BDF reducible rules of orders 4 to 6. It also computes
C     the values of the starting fractional weights associated with
C     these BDF formulae.
C     ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
C     --------------------------------------------------------------

E01AAF
      SUBROUTINE E01AAF(A,B,C,N1,N2,N,X)
C     MARK 1 RELEASE.  NAG COPYRIGHT 1971
C     MARK 4.5 REVISED
C     MARK 11.5(F77) REVISED. (SEPT 1985.)

E01ABF
      SUBROUTINE E01ABF(N,P,A,G,N1,N2,IFAIL)
C     MARK 2 RELEASE.  NAG COPYRIGHT 1972
C     MARK 3 REVISED.
C     MARK 4.5 REVISED
C     MARK 7A REVISED  IER-158 (MAR 1979)
C     MARK 9 REVISED. IER-351 (SEP 1981)
C     MARK 11.5(F77) REVISED. (SEPT 1985.)

E01AEF
      SUBROUTINE E01AEF(M,XMIN,XMAX,X,Y,IP,N,ITMIN,ITMAX,A,WRK,LWRK,
     *                  IWRK,LIWRK,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     *******************************************************
C
C     NPL ALGORITHMS LIBRARY ROUTINE PINTRP
C
C     CREATED 17 07 79.  UPDATED 14 05 80.  RELEASE 00/42
C
C     AUTHORS ... GERALD T. ANTHONY, MAURICE G. COX,
C                 J. GEOFFREY HAYES AND MICHAEL A. SINGER.
C     NATIONAL PHYSICAL LABORATORY, TEDDINGTON,
C     MIDDLESEX TW11 OLW, ENGLAND
C
C     *******************************************************
C
C     E01AEF. A ROUTINE, WITH CHECKS, WHICH DETERMINES AND
C     REFINES A POLYNOMIAL INTERPOLANT  Q(X)  TO DATA WHICH
C     MAY CONTAIN DERIVATIVES.
C
C     INPUT PARAMETERS
C        M        NUMBER OF DISTINCT X-VALUES
C        XMIN,
C        XMAX     LOWER AND UPPER ENDPOINTS OF INTERVAL
C        X        INDEPENDENT VARIABLE VALUES (DISTINCT)
C        Y        VALUES AND DERIVATIVES OF
C                    DEPENDENT VARIABLE.
C        IP       HIGHEST ORDER OF DERIVATIVE AT EACH X-VALUE.
C        N        NUMBER OF INTERPOLATING CONDITIONS.
C                    N = M + IP(1) + IP(2) + ... + IP(M).
C        ITMIN,
C        ITMAX    MINIMUM AND MAXIMUM NUMBER OF ITERATIONS TO BE
C                    PERFORMED.
C
C     OUTPUT PARAMETERS
C        A        CHEBYSHEV COEFFICIENTS OF  Q(X)
C
C     WORKSPACE (AND ASSOCIATED DIMENSION) PARAMETERS
C        WRK      REAL WORKSPACE ARRAY.  THE FIRST IMAX ELEMENTS
C                    CONTAIN, ON EXIT, PERFORMANCE INDICES FOR
C                    THE INTERPOLATING POLYNOMIAL, AND THE NEXT
C                    N  ELEMENTS THE COMPUTED RESIDUALS
C        LWRK     DIMENSION OF WRK. LWRK MUST BE AT LEAST
C                    7*N + 5*IMAX + M + 2, WHERE
C                    IMAX IS ONE MORE THAN THE LARGEST ELEMENT
C                    OF THE ARRAY IP.
C        IWRK     INTEGER WORKSPACE ARRAY.  ON EXIT,  IWRK(1)
C                    CONTAINS THE NUMBER OF ITERATIONS TAKEN
C        LIWRK    DIMENSION OF IWRK.  AT LEAST 2*M + 2.
C
C     FAILURE INDICATOR PARAMETER
C        IFAIL    FAILURE INDICATOR.
C                    0 - SUCCESSFUL TERMINATION.
C                    1 - AT LEAST ONE OF THE FOLLOWING CONDITIONS
C                        HAS BEEN VIOLATED -
C                           M AT LEAST 1,
C                           N = M + IP(1) + IP(2) + ... + IP(M),
C                           LWRK AT LEAST 7*N + 5*IMAX + M + 2,
C                           LIWRK AT LEAST 2*M + 2.
C                    2 - FOR SOME I, IP(I) IS LESS THAN 0.
C                    3 - AT LEAST ONE OF THE FOLLOWING CONDITIONS
C                        HAS BEEN VIOLATED -
C                           XMIN STRICTLY LESS THAN XMAX,
C                           FOR EACH I, X(I) MUST LIE IN THE
C                              INTERVAL XMIN TO XMAX,
C                           THE X-VALUES MUST ALL BE DISTINCT
C                    4 - NOT ALL PERFORMANCE INDICES LESS THAN
C                        ONE, BUT ITMAX ITERATIONS PERFORMED,
C                    5 - COMPUTATION TERMINATED BECAUSE
C                        ITERATIONS DIVERGING.
C
C
C     CHECK AND SET ITERATION LIMITS
C

E01BAF
      SUBROUTINE E01BAF(M,X,Y,K,C,LCK,WRK,LWRK,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     ******************************************************
C
C     NPL ALGORITHMS LIBRARY ROUTINE SP3INT
C
C     CREATED 16/5/79.                        RELEASE 00/00
C
C     AUTHORS ... GERALD T. ANTHONY, MAURICE G.COX
C                 J.GEOFFREY HAYES AND MICHAEL A. SINGER.
C     NATIONAL PHYSICAL LABORATORY, TEDDINGTON,
C     MIDDLESEX TW11 OLW, ENGLAND
C
C     ******************************************************
C
C     E01BAF.  AN ALGORITHM, WITH CHECKS, TO DETERMINE THE
C     COEFFICIENTS IN THE B-SPLINE REPRESENTATION OF A CUBIC
C     SPLINE WHICH INTERPOLATES (PASSES EXACTLY THROUGH) A
C     GIVEN SET OF POINTS.
C
C     INPUT PARAMETERS
C        M        THE NUMBER OF DISTINCT POINTS WHICH THE
C                    SPLINE IS TO INTERPOLATE.
C                    (M MUST BE AT LEAST 4.)
C        X        ARRAY CONTAINING THE DISTINCT VALUES OF THE
C                    INDEPENDENT VARIABLE. NB X(I) MUST BE
C                    STRICTLY GREATER THAN X(J) WHENEVER I IS
C                    STRICTLY GREATER THAN J.
C        Y        ARRAY CONTAINING THE VALUES OF THE DEPENDENT
C                    VARIABLE.
C        LCK      THE SMALLER OF THE ACTUALLY DECLARED DIMENSIONS
C                    OF K AND C. MUST BE AT LEAST M + 4.
C
C     OUTPUT PARAMETERS
C        K        ON SUCCESSFUL EXIT, K CONTAINS THE KNOTS
C                    SET UP BY THE ROUTINE. IF THE SPLINE IS
C                    TO BE EVALUATED (BY NPL ROUTINE E02BEF,
C                    FOR EXAMPLE) THE ARRAY K MUST NOT BE
C                    ALTERED BEFORE CALLING THAT ROUTINE.
C        C        ON SUCCESSFUL EXIT, C CONTAINS THE B-SPLINE
C                    COEFFICIENTS OF THE INTERPOLATING SPLINE.
C                    THESE ARE ALSO REQUIRED BY THE EVALUATING
C                    ROUTINE E02BEF.
C        IFAIL    FAILURE INDICATOR
C                    0 - SUCCESSFUL TERMINATION.
C                    1 - ONE OF THE FOLLOWING CONDITIONS HAS
C                        BEEN VIOLATED -
C                        M AT LEAST 4
C                        LK AT LEAST M + 4
C                        LWORK AT LEAST 6 * M + 16
C                    2 - THE VALUES OF THE INDEPENDENT VARIABLE
C                        ARE DISORDERED. IN OTHER WORDS, THE
C                        CONDITION MENTIONED UNDER X IS NOT
C                        SATISFIED.
C
C     WORKSPACE (AND ASSOCIATED DIMENSION) PARAMETERS
C        WRK     WORKSPACE ARRAY, OF LENGTH LWRK.
C        LWRK    ACTUAL DECLARED DIMENSION OF WRK.
C                    MUST BE AT LEAST 6 * M + 16.
C

E01BEF
      SUBROUTINE E01BEF(N,X,F,D,IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.
C
C     Computes a monotonicity-preserving piecewise cubic Hermite
C     interpolant to a set of data points.
C
C     E01BEF is a driver for E01BEZ (derived from PCHIP routine PCHIM),
C     specialiSed for the case INCFD = 1.
C

E01BFF
      SUBROUTINE E01BFF(N,X,F,D,M,PX,PF,IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.
C
C     Evaluates a piecewise cubic Hermite interpolant at a set of
C     points.
C
C     E01BFF is a driver for E01BFZ (derived from PCHIP routine PCHFE),
C     specialised for the case INCFD = 1.
C

E01BGF
      SUBROUTINE E01BGF(N,X,F,D,M,PX,PF,PD,IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.
C
C     Evaluates a piecewise cubic Hermite interpolant and its first
C     derivative at a set of data points.
C
C     E01BGF is a driver for E01BGZ (derived from PCHIP routine PCHFD),
C     specialised for the case INCFD = 1.
C

E01BHF
      SUBROUTINE E01BHF(N,X,F,D,A,B,PINT,IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.
C
C     Evaluates the definite integral of a piecewise cubic Hermite
C     interpolant over the interval (a,b).
C
C     E01BHF is a driver for E01BHZ (derived from PCHIP routine PCHIA),
C     specialised for the case INCFD = 1.
C

E01DAF
      SUBROUTINE E01DAF(MX,MY,X,Y,F,PX,PY,LAMDA,MU,C,WRK,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C     Derived from DASL routine B2IRE.

E01RAF
      SUBROUTINE E01RAF(N,X,F,M,A,U,IW,IFAIL)
C     MARK 9 RELEASE. NAG COPYRIGHT 1981
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C
C     E01RAF PRODUCES, FROM A SET OF FUNCTION VALUES
C     AND CORRESPONDING ABSCISSAE, THE COEFFICIENTS OF
C     AN INTERPOLATING RATIONAL FUNCTION EXPRESSED IN
C     CONTINUED FRACTION FORM
C
C     ON ENTRY
C     N  -INTEGER-  NUMBER OF INTERPOLATION POINTS
C     X  -REAL ARRAY-  ABSCISSA POINTS
C     F  -REAL ARRAY-  FUNCTION VALUES
C     ON EXIT
C     M  -INTEGER-  NUMBER OF THIELE COEFFICIENTS
C     U  -REAL ARRAY-  REORDERED ABSCISSA POINTS
C     A  -REAL ARRAY-  THIELE COEFFICIENTS
C     IW  -INTEGER ARRAY-  WORKSPACE
C     IFAIL  -INTEGER-  ERROR INDICATOR
C
C     VERSION U.K.C.  21/11/79
C     BY P.R. GRAVES-MORRIS, T.R. HOPKINS AND D.J. WINSTANLEY
C     BASED ON A PROCEDURE BY A.R. CURTIS.
C
C     EPS IS A MACHINE DEPENDENT VARIABLE.

E01RBF
      SUBROUTINE E01RBF(M,A,U,X,F,IFAIL)
C     MARK 9 RELEASE. NAG COPYRIGHT 1981
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C
C     E01RBF EVALUATES CONTINUED FRACTIONS OF THE FORM
C     PRODUCED BY E01RAF
C
C     ON ENTRY
C     X  -REAL-  POINT AT WHICH THIELE INTERPOLANT IS TO BE
C     EVALUATED
C     U  -REAL ARRAY-  ABSCISSA POINTS (REARRANGED)
C     A  -REAL ARRAY-  THIELE COEFFICIENTS
C     M  -INTEGER-  NUMBER OF COEFFICIENTS
C     ON EXIT
C     F  -REAL-  CALCULATED VALUE OF THE THIELE INTERPOLANT
C     IFAIL  -INTEGER-  ERROR INDICATOR
C
C     EPS IS A MACHINE DEPENDENT VARIABLE.

E01SAF
      SUBROUTINE E01SAF(M,X,Y,F,TRIANG,GRADS,IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.
C
C     Creates a Thiessen triangulation of (M,X,Y) and computes
C     derivatives required for interpolation.
C
C     Input arguments:
C     M is the number of data points (nodes).
C     X, Y, F are the scattered data to be interpolated, F = F(X,Y).
C
C     Output arguments:
C     TRIANG contains the data structure defining the triangulation;
C      used as parameters IADJ and IEND to subroutine E01SAZ.
C     GRADS contains the estimated partial derivatives at the nodes;
C      first row contains derivatives with respect to X, second row
C      with respect to Y. Used as parameter ZXZY to subroutine E01SAZ.
C
C     Parameters:
C     TOL is a convergence criterion for estimating gradients at nodes;
C      TOL .ge. 0.0; TOL = 0.01 is sufficient.
C     MAXIT is the maximum number of iterations allowed for computation
C      of estimated gradients; MAXIT .ge. 0.
C
C     M, X, Y, F, TRIANG and GRADS should be used as input to NAG
C     library routine E01SBF to compute interpolated values of F(X,Y).
C

E01SBF
      SUBROUTINE E01SBF(M,X,Y,F,TRIANG,GRADS,PX,PY,PF,IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.
C
C     Takes a Thiessen triangulation of a set of points in the plane,
C     and estimated partial derivatives with respect to X and Y, as
C     returned by NAG Fortran Library routine E01SAF. Returns the
C     value of a C1 function F(X,Y) interpolating the points and their
C     partial derivatives, evaluated at the point (PX,PY).
C     If (PX,PY) lies outside the triangulation boundary, extrapolation
C     is performed. Interpolation is exact for quadratic data.
C

E01SEF
      SUBROUTINE E01SEF(M,X,Y,F,RNW,RNQ,NW,NQ,FNODES,MINNQ,WRK,IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.
C     MARK 14C REVISED. IER-876 (NOV 1990).
C
C     This subroutine serves to construct a Shepard's method type of
C     surface through a set of scattered data points, using a least
C     squares quadratic nodal function through each point.
C
C     Routine created - December 1986
C     Author          - Richard Franke
C                       Naval Postgraduate School Monterey,
C                       California  93940
C                       Adapted for Nag by H.Scullion (Leic Univ.)
C                       and I. Gladwell (Nag Ltd.)
C
C     Input Parameters:
C
C            M  -  The number of data points.
C
C        X,Y,F  -  The data points, (X(I),Y(I),F(I),I=1,M)
C
C          RNW  -  The radius for the weight functions.
C
C          RNQ  -  The radius for the nodal functions. If either of
C                  RNW or RNQ is .le. zero on entry, then their values
C                  will be computed, using the values of NW and NQ,
C                  and will be returned on exit.
C
C           NW  -  The approximate number of neighbouring nodes to
C                  affect each weight function.
C
C           NQ  -  The approximate number of neighbouring nodes to
C                  affect each nodal function. If either of
C                  NW or NQ is .le. zero on entry, then a default
C                  value will be used.
C
C     Output Parameters:
C
C       FNODES  -  Real array of dimension at least (5*M).
C                  This array is used to store the coefficients for the
C                  nodal functions.
C
C          WRK  -  Real work array of dimension at least (6*M),
C                  used in E01SEZ.
C
C     On exit, if IFAIL = 0, normal return.
C                   = 1, input error. M.lt.3
C                   = 2, input error. RNQ.lt.RNW
C                   = 3, input error. NQ.lt.NW
C                   = 4, input error. The (X(I),Y(I)) points are
C                        not unique for I = 1,2,...,M.
C

E01SFF
      SUBROUTINE E01SFF(M,X,Y,F,RNW,FNODES,PX,PY,PF,IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.
C
C     This function serves as the evaluation module in a quadratic
C     Shepard interpolation process. This module should be called
C     after a call to subroutine E01SEF.
C
C     Routine created - December 1986
C     Author          - Richard Franke
C                       Naval Postgraduate School Monterey,
C                       California  93940
C                       Adapted for Nag by H.Scullion (Leic Univ.)
C                       and I. Gladwell (Nag Ltd.)
C
C     Input Parameters:
C
C            M  -  The number of data points.
C                  Unchanged on exit.
C
C        X,Y,F  -  The data points, (X(I),Y(I),F(I),I=1,M).
C                  Unchanged on exit.
C
C          RNW  -  The radius for the weight functions. As
C                  defined in E01SEF.
C                  Unchanged on exit.
C
C       FNODES  -  Real array of dimension at least (5*M).
C                  This array is used to store the coefficients for
C                  the nodal functions.
C                  Unchanged on exit.
C
C        PX,PY  -  The point (PX,PY) where the function is to be
C                  evaluated.
C                  Unchanged on exit.
C
C     Output Parameter:
C
C           PF  -  The value of the interpolant at point (PX,PY).
C
C     On exit, if IFAIL = 0, normal return.
C                    = 1, M is .lt. 3.
C                    = 2, evaluation point is outside support region.
C

E02ACF
      SUBROUTINE E02ACF(X,Y,N,AA,M1,REF)
C     MARK 1 RELEASE.  NAG COPYRIGHT 1971
C     MARK 4.5 REVISED
C     MARK 5C REVISED
C     MARK 9B REVISED. IER-361 (JAN 1982)
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 14C REVISED. IER-877 (NOV 1990).
C     CALCULATES A MINIMAX POLYNOMIAL FIT TO A SET OF DATA POINTS
C     AS A
C     SERIES OF CHEBYSHEV POLYNOMIALS.

E02ADF
      SUBROUTINE E02ADF(M,KPLUS1,NROWS,X,Y,W,WORK1,WORK2,A,S,IFAIL)
C
C     NAG LIBRARY SUBROUTINE  E02ADF
C
C     E02ADF  COMPUTES WEIGHTED LEAST-SQUARES POLYNOMIAL
C     APPROXIMATIONS TO AN ARBITRARY SET OF DATA POINTS.
C
C     FORSYTHE-CLENSHAW METHOD WITH MODIFICATIONS DUE TO
C     REINSCH AND GENTLEMAN.
C
C     USES NAG LIBRARY ROUTINE  P01AAF.
C     USES BASIC EXTERNAL FUNCTION  SQRT.
C
C     STARTED - 1973.
C     COMPLETED - 1976.
C     AUTHOR - MGC AND JGH.
C
C     WORK1  AND  WORK2  ARE WORKSPACE AREAS.
C     WORK1(1, R)  CONTAINS THE VALUE OF THE  R TH  WEIGHTED
C     RESIDUAL FOR THE CURRENT DEGREE  I.
C     WORK1(2, R)  CONTAINS THE VALUE OF  X(R)  TRANSFORMED
C     TO THE RANGE  -1  TO  +1.
C     WORK1(3, R)  CONTAINS THE WEIGHTED VALUE OF THE CURRENT
C     ORTHOGONAL POLYNOMIAL (OF DEGREE  I)  AT THE  R TH
C     DATA POINT.
C     WORK2(1, J)  CONTAINS THE COEFFICIENT OF THE CHEBYSHEV
C     POLYNOMIAL OF DEGREE  J - 1  IN THE CHEBYSHEV-SERIES
C     REPRESENTATION OF THE CURRENT ORTHOGONAL POLYNOMIAL
C     (OF DEGREE  I).
C     WORK2(2, J)  CONTAINS THE COEFFICIENT OF THE CHEBYSHEV
C     POLYNOMIAL OF DEGREE  J - 1  IN THE CHEBYSHEV-SERIES
C     REPRESENTATION OF THE PREVIOUS ORTHOGONAL POLYNOMIAL
C     (OF DEGREE  I - 1).
C
C     NAG COPYRIGHT 1975
C     MARK 5 RELEASE
C     MARK 6 REVISED  IER-84
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     CHECK THAT THE VALUES OF  M  AND  KPLUS1  ARE REASONABLE
C

E02AEF
      SUBROUTINE E02AEF(NPLUS1,A,XCAP,P,IFAIL)
C     NAG LIBRARY SUBROUTINE  E02AEF
C
C     E02AEF  EVALUATES A POLYNOMIAL FROM ITS CHEBYSHEV-
C     SERIES REPRESENTATION.
C
C     CLENSHAW METHOD WITH MODIFICATIONS DUE TO REINSCH
C     AND GENTLEMAN.
C
C     USES NAG LIBRARY ROUTINES  P01ABF  AND  X02AJF.
C     USES INTRINSIC FUNCTION  ABS.
C
C     STARTED - 1973.
C     COMPLETED - 1976.
C     AUTHOR - MGC AND JGH.
C
C     NAG COPYRIGHT 1975
C     MARK 5 RELEASE
C     MARK 7 REVISED IER-140 (DEC 1978)
C     MARK 9 REVISED. IER-352 (SEP 1981)
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C

E02AFF
      SUBROUTINE E02AFF(NPLUS1,F,A,IFAIL)
C     NAG LIBRARY SUBROUTINE  E02AFF
C
C     E02AFF  COMPUTES THE COEFFICIENTS OF A POLYNOMIAL,
C     IN ITS CHEBYSHEV-SERIES FORM, WHICH INTERPOLATES
C     (PASSES EXACTLY THROUGH) DATA AT A SPECIAL SET OF
C     POINTS.  LEAST-SQUARES POLYNOMIAL APPROXIMATIONS
C     CAN ALSO BE OBTAINED.
C
C     CLENSHAW METHOD WITH MODIFICATIONS DUE TO REINSCH
C     AND GENTLEMAN.
C
C     USES NAG LIBRARY ROUTINES  P01AAF  AND  X01AAF.
C     USES BASIC EXTERNAL FUNCTION  SIN.
C
C     STARTED - 1973.
C     COMPLETED - 1976.
C     AUTHOR - MGC AND JGH.
C
C     NAG COPYRIGHT 1975
C     MARK 5 RELEASE
C     MARK 5B REVISED  IER-73
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C

E02AGF
      SUBROUTINE E02AGF(M,KPLUS1,NROWS,XMIN,XMAX,X,Y,W,MF,XF,YF,LYF,IP,
     *                  A,S,NP1,WRK,LWRK,IWRK,LIWRK,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 9 REVISED. IER-314 (SEP 1981).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 14C REVISED. IER-878 (NOV 1990).
C
C     **************************************************************
C
C     NPL ALGORITHMS LIBRARY ROUTINE CONFIT
C
C     CREATED  20/8/1979      UPDATED  16/5/80     RELEASE NO. 00/05
C
C     AUTHOR... GERALD T ANTHONY.
C     NATIONAL PHYSICAL LABORATORY,
C     TEDDINGTON, MIDDLESEX TW11 0LW,
C     ENGLAND.
C
C     **************************************************************
C
C     E02AGF CALLS E01AEW TO DETERMINE A POLYNOMIAL MU(X) WHICH
C     INTERPOLATES THE GIVEN CONSTRAINTS AND A POLYNOMIAL NU(X)
C     WHICH HAS VALUE ZERO WHERE A CONSTRAINED VALUE IS SPECIFIED.
C     IT THEN CALLS E02ADZ TO FIT Y-MU(X) AS A POLYNOMIAL IN X
C     WITH FACTOR NU(X). FINALLY THE COEFFICIENTS OF MU ARE ADDED
C     TO THESE FITS TO GIVE THE COEFFICIENTS OF THE CONSTRAINED
C     FITS TO Y. ALL POLYNOMIALS ARE EXPRESSED IN CHEBYSHEV
C     SERIES FORM
C
C     INPUT PARAMETERS
C        M        THE NUMBER OF DATA POINTS TO BE FITTED
C        KPLUS1   FITS WITH UP TO KPLUS1 COEFFICIENTS ARE REQUIRED
C        NROWS    FIRST DIMENSION OF ARRAY A WHERE COEFFICIENTS ARE
C                 TO BE STORED
C        XMIN,    END POINTS OF THE RANGE OF THE
C        XMAX     INDEPENDENT VARIABLE
C        X, Y, W  ARRAYS OF DATA VALUES OF THE INDEPENDENT VARIABLE,
C                 DEPENDENT VARIABLE AND WEIGHT, RESPECTIVELY
C        MF       NUMBER OF X VALUES AT WHICH A CONSTRAINT
C                 IS SPECIFIED
C        XF       ARRAY OF VALUES OF THE INDEPENDENT
C                 VARIABLE AT WHICH CONSTRAINTS ARE
C                 SPECIFIED
C        YF       ARRAY OF SPECIFIED VALUES AND DERIVATIVES OF THE
C                 DEPENDENT VARIABLE IN THE ORDER
C                    Y1, Y1 DERIV, Y1 2ND DERIV,...., Y2,....
C        LYF      DIMENSION OF ARRAY YF
C        IP       INTEGER ARRAY OF DEGREES OF DERIVATIVES
C                 SPECIFIED AT EACH POINT XF
C
C     OUTPUT PARAMETERS
C        A        ON EXIT, 2 PARAMETER ARRAY CONTAINING THE
C                 COEFFICIENTS OF THE CHEBYSHEV SERIES
C                 REPRESENTATION OF THE FITS, A(I+1, J+1)
C                 CONTAINS THE COEFFICIENT OF TJ IN THE FIT
C                 OF DEGREE I, I = N,N+1,...,K,  J =
C                 0,1,...,I  WHERE N = NP1 - 1
C        S        ON EXIT, ARRAY CONTAINING THE R.M.S. RESIDUAL FOR
C                 EACH DEGREE OF FIT FROM N TO K
C        NP1      ON EXIT, CONTAINS N + 1, WHERE N IS THE
C                 TOTAL NUMBER OF INTERPOLATION CONDITIONS
C
C        IFAIL    FAILURE INDICATOR
C                  0 - SUCCESSFUL TERMINATION
C                  1 - AT LEAST ONE OF THE FOLLOWING CONDITIONS
C                      HAS BEEN VIOLATED
C                      LYF    AT LEAST N
C                      LWRK   AT LEAST 2*N + 2 + THE LARGER OF
C                             4*M + 3*KPLUS1 AND 8*NP1 +
C                             5*IMAX + MF - 3 WHERE IMAX =
C                             1 + MAX(IP(I))
C                      LIWRK  AT LEAST 2*MF + 2
C                      KPLUS1 AT LEAST NP1
C                      M      AT LEAST 1
C                      NROWS  AT LEAST KPLUS1
C                      MF     AT LEAST 1
C                  2 - FOR SOME I, IP(I) IS LESS THAN 0
C                  3 - XMIN IS NOT STRICTLY LESS THAN XMAX
C                      OR FOR SOME I, XF(I) IS NOT IN RANGE
C                      XMIN TO XMAX OR THE XF(I) ARE NOT
C                      DISTINCT
C                  4 - FOR SOME I, X(I) IS NOT IN RANGE XMIN TO XMAX
C                  5 - THE X(I) ARE NOT NON-DECREASING
C                  6 - THE NUMBER OF DISTINCT VALUES OF X(I) WITH
C                      NON-ZERO WEIGHT IS LESS THAN KPLUS1 - NP1
C                  7 - E01AEW HAS FAILED TO CONVERGE, IE
C                      THE CONSTRAINT CANNOT BE SATISFIED
C                      WITH SUFFICIENT ACCURACY
C
C     WORKSPACE PARAMETERS
C        WRK      REAL WORKSPACE ARRAY
C        LWRK     DIMENSION OF WRK.   LWRK MUST BE AT LEAST
C                 2*N + 2 + THE LARGER OF
C                 4*M + 3*KPLUS1 AND 8*NP1 + 5*IMAX + MF - 3
C                 WHERE IMAX = 1 + MAX(IP(I))
C        IWRK     INTEGER WORKSPACE ARRAY
C        LIWRK    DIMENSION OF IWRK.   LIWRK MUST BE AT LEAST
C                 2*MF + 2
C

E02AHF
      SUBROUTINE E02AHF(NP1,XMIN,XMAX,A,IA1,LA,PATM1,ADIF,IADIF1,LADIF,
     *                  IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     * * * * * * * * * * * * * * * * * * * * * * * * * * * *
C
C     NPL DATA FITTING LIBRARY ROUTINE CHBDIF
C
C     CREATED 1/5/79    UPDATED 23/1/80     RELEASE NO. 00/03
C
C     AUTHORS.. GERALD T ANTHONY, MAURICE G COX, J GEOFFREY HAYES.
C     NATIONAL PHYSICAL LABORATORY
C     TEDDINGTON, MIDDLESEX, ENGLAND.
C
C     * * * * * * * * * * * * * * * * * * * * * * * * * * * *
C
C     INPUT PARAMETERS
C        NP1    = N+1 WHERE N IS DEGREE OF GIVEN POLYNOMIAL
C        XMIN   LOWER LIMIT OF RANGE OF X
C        XMAX   UPPER LIMIT OF RANGE OF X
C        A      COEFFICIENTS A0, A1,...AN OF THE GIVEN POLYNOMIAL
C        IA1       ARE STORED IN ARRAY A IN POSITIONS 1, 1+IA1,...
C                  1+N*IA1, RESPECTIVELY
C        LA     THE DECLARED DIMENSION OF ARRAY A
C
C     OUTPUT PARAMETERS
C        PATM1  THE VALUE OF THE GIVEN POLYNOMIAL AT XMIN
C        ADIF   THE COEFFICIENTS OF THE DERIVATIVE POLYNOMIAL
C        IADIF1    ARE RETURNED IN ARRAY ADIF IN POSITIONS
C                  1, 1+IADIF1,...1+(N-1)*IADIF1
C        LADIF  THE DECLARED DIMENSION OF ARRAY ADIF
C        IFAIL  ERROR INDICATOR
C
C     DIFFERENTIATE THE SERIES WITH COEFFICIENTS A OF DEGREE N
C     (I.E. NP1 COEFFICIENTS) TO OBTAIN THE SERIES WITH COEFFICIENTS
C     ADIF OF DEGREE N-1. ALSO SET NEXT HIGHER COEFFICIENT TO ZERO.
C

E02AJF
      SUBROUTINE E02AJF(NP1,XMIN,XMAX,A,IA1,LA,QATM1,AIN,IAINT1,LAINT,
     *                  IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 9 REVISED. IER-315 (SEP 1981).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     * * * * * * * * * * * * * * * * * * * * * * * * * * * *
C
C     NPL DATA FITTING LIBRARY ROUTINE CHBINT
C
C     CREATED 1/5/79    UPDATED 23/1/80     RELEASE NO. 00/03
C
C     AUTHORS.. GERALD T ANTHONY, MAURICE G COX, J GEOFFREY HAYES.
C     NATIONAL PHYSICAL LABORATORY
C     TEDDINGTON, MIDDLESEX, ENGLAND.
C
C     * * * * * * * * * * * * * * * * * * * * * * * * * * * *
C
C     INPUT PARAMETERS
C        NP1    = N+1 WHERE N IS DEGREE OF GIVEN POLYNOMIAL
C        XMIN   LOWER LIMIT OF RANGE OF X
C        XMAX   UPPER LIMIT OF RANGE OF X
C        A      COEFFICIENTS A0, A1,...AN OF THE GIVEN POLYNOMIAL
C        IA1       ARE STORED IN ARRAY A IN POSITIONS 1, 1+IA1,...
C                  1+N*IA1, RESPECTIVELY
C        LA     THE DECLARED DIMENSION OF ARRAY A
C        QATM1  THE VALUE OF THE INTEGRATED POLYNOMIAL AT XMIN
C
C     OUTPUT PARAMETERS
C        AIN   THE COEFFICIENTS OF THE INTEGRATED POLYNOMIAL
C        IAINT1    ARE RETURNED IN ARRAY AIN IN POSITIONS
C                  1, 1+IAINT1,...1+NP1*IAINT1
C        LAINT  THE DECLARED DIMENSION OF ARRAY AIN
C        IFAIL  ERROR INDICATOR
C
C     INTEGRATE THE SERIES WITH COEFFICIENTS A OF DEGREE N
C     (I.E. NP1 COEFFICIENTS) TO OBTAIN THE SERIES WITH COEFFICIENTS
C     AIN OF DEGREE N + 1.  THE SUM OF THE INTEGRATED SERIES IS
C     QATM1 AT THE LEFT HAND END OF THE INTERVAL OF DEFINITION, XMIN
C

E02AKF
      SUBROUTINE E02AKF(NP1,XMIN,XMAX,A,IA1,LA,X,RESULT,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     * * * * * * * * * * * * * * * * * * * * * * * * * * *
C
C     NPL DATA FITTING LIBRARY ROUTINE TVAL1C
C
C     CREATED 19/3/79    UPDATED 6/7/79    RELEASE NO. 00/04.
C
C     AUTHORS.. GERALD T ANTHONY, MAURICE G COX, BETTY CURTIS
C     AND J GEOFFREY HAYES.
C     NATIONAL PHYSICAL LABORATORY
C     TEDDINGTON, MIDDLESEX, ENGLAND.
C
C     * * * * * * * * * * * * * * * * * * * * * * * * * * *
C
C     INPUT PARAMETERS
C        NP1      NP1 = N + 1. N IS THE DEGREE OF THE
C                 CHEBYSHEV SERIES
C        XMIN     MINIMUM VALUE OF X
C        XMAX     MAXIMUM VALUE OF X
C        A        THE ARRAY WHERE THE COEFFICIENTS ARE STORED
C        IA1      THE ADDRESS INCREMENT OF A
C        LA       DIMENSION OF A
C        X        UNNORMALIZED ARGUMENT IN THE RANGE (XMIN, XMAX)
C
C     OUTPUT PARAMETERS
C        RESULT   VALUE OF THE SUMMATION
C        IFAIL    ERROR INDICATOR
C
C     NP1 CHEBYSHEV COEFFICIENTS A0, A1, ..., AN, ARE
C     STORED IN THE ARRAY A IN POSITIONS 1, 1+IA1, 1+2*IA1, ...,
C     1+N*IA1, WHERE N = NP1 - 1.
C     IA1 MUST NOT BE NEGATIVE.
C     LA MUST BE AT LEAST EQUAL TO 1 + N*IA1.
C     THE VALUE OF THE POLYNOMIAL OF DEGREE N
C     A0T0(XCAP)/2 + A1T1(XCAP) + A2T2(XCAP) + + ... + ANTN(XCAP),
C     IS CALCULATED FOR THE ARGUMENT XCAP, WHERE XCAP IS
C     THE NORMALIZED VALUE OF X IN THE RANGE (XMIN, XMAX),
C     STORING IT IN RESULT.
C     UNLESS THE ROUTINE DETECTS AN ERROR, IFAIL CONTAINS
C     ZERO ON EXIT.
C     IFAIL = 1 INDICATES AT LEAST ONE OF THE RESTRICTIONS ON
C        INPUT PARAMETERS IS VIOLATED - IE
C     NP1 .GT. 0
C     IA1 .GE. 0
C     LA .GE. 1 + N * IA1
C     XMIN .LT. XMAX
C     IFAIL = 2 INDICATES THAT
C     X DOES NOT SATISFY THE RESTRICTION XMIN .LE. X .LE. XMAX.
C     THE RECURRENCE RELATION BY CLENSHAW, MODIFIED BY REINSCH
C     AND GENTLEMAN, IS USED.
C

E02BAF
      SUBROUTINE E02BAF(M,NCAP7,X,Y,W,K,WORK1,WORK2,C,SS,IFAIL)
C     NAG COPYRIGHT 1975
C     MARK 5 RELEASE
C     MARK 6 REVISED  IER-84
C     MARK 8 RE-ISSUE. IER-224 (APR 1980).
C     MARK 9A REVISED. IER-356 (NOV 1981)
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     NAG LIBRARY SUBROUTINE  E02BAF
C
C     E02BAF  COMPUTES A WEIGHTED LEAST-SQUARES APPROXIMATION
C     TO AN ARBITRARY SET OF DATA POINTS BY A CUBIC SPLINE
C     WITH KNOTS PRESCRIBED BY THE USER.  CUBIC SPLINE
C     INTERPOLATION CAN ALSO BE CARRIED OUT.
C
C     COX-DE BOOR METHOD FOR EVALUATING B-SPLINES WITH
C     ADAPTATION OF GENTLEMAN*S PLANE ROTATION SCHEME FOR
C     SOLVING OVER-DETERMINED LINEAR SYSTEMS.
C
C     USES NAG LIBRARY ROUTINE  P01AAF.
C
C     STARTED - 1973.
C     COMPLETED - 1976.
C     AUTHOR - MGC AND JGH.
C
C     REDESIGNED TO USE CLASSICAL GIVENS ROTATIONS IN
C     ORDER TO AVOID THE OCCASIONAL UNDERFLOW (AND HENCE
C     OVERFLOW) PROBLEMS EXPERIENCED BY GENTLEMAN*S 3-
C     MULTIPLICATION PLANE ROTATION SCHEME
C
C     WORK1  AND  WORK2  ARE WORKSPACE AREAS.
C     WORK1(R)  CONTAINS THE VALUE OF THE  R TH  DISTINCT DATA
C     ABSCISSA AND, SUBSEQUENTLY, FOR  R = 1, 2, 3, 4,  THE
C     VALUES OF THE NON-ZERO B-SPLINES FOR EACH SUCCESSIVE
C     ABSCISSA VALUE.
C     WORK2(L, J)  CONTAINS, FOR  L = 1, 2, 3, 4,  THE VALUE OF
C     THE  J TH  ELEMENT IN THE  L TH  DIAGONAL OF THE
C     UPPER TRIANGULAR MATRIX OF BANDWIDTH  4  IN THE
C     TRIANGULAR SYSTEM DEFINING THE B-SPLINE COEFFICIENTS.
C

E02BBF
      SUBROUTINE E02BBF(NCAP7,K,C,X,S,IFAIL)
C     NAG LIBRARY SUBROUTINE  E02BBF
C
C     E02BBF  EVALUATES A CUBIC SPLINE FROM ITS
C     B-SPLINE REPRESENTATION.
C
C     DE BOOR*S METHOD OF CONVEX COMBINATIONS.
C
C     USES NAG LIBRARY ROUTINE  P01AAF.
C
C     STARTED - 1973.
C     COMPLETED - 1976.
C     AUTHOR - MGC AND JGH.
C
C     NAG COPYRIGHT 1975
C     MARK 5 RELEASE
C     MARK 7 REVISED IER-141 (DEC 1978)
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C

E02BCF
      SUBROUTINE E02BCF(NCAP7,K,C,X,LEFT,S,IFAIL)
C     MARK 7 RELEASE. NAG COPYRIGHT 1978.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     **************************************************
C     *                                                *
C     *         NAG LIBRARY SUBROUTINE  E02BCF         *
C     *                                                *
C     *  EVALUATION OF CUBIC SPLINE AND ITS            *
C     *  DERIVATIVES FROM ITS B-SPLINE REPRESENTATION  *
C     *                                                *
C     *  ROUTINE CREATED ... 17 NOV 1977               *
C     *  LATEST UPDATE ....  24 APR 1978               *
C     *  RELEASE NUMBER ...  01                        *
C     *  AUTHORS ... MAURICE G. COX AND                *
C     *              J. GEOFFREY HAYES, N.P.L.         *
C     *                                                *
C     **************************************************
C

E02BDF
      SUBROUTINE E02BDF(NCAP7,K,C,DEFINT,IFAIL)
C     MARK 7 RELEASE. NAG COPYRIGHT 1978.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     **************************************************
C     *                                                *
C     *         NAG LIBRARY SUBROUTINE  E02BDF         *
C     *                                                *
C     *  DEFINITE INTEGRAL OF CUBIC SPLINE FROM ITS    *
C     *  B-SPLINE REPRESENTATION                       *
C     *                                                *
C     *  ROUTINE CREATED ... 17 NOV 1977               *
C     *  LATEST UPDATE ....  24 APR 1978               *
C     *  RELEASE NUMBER ...  01                        *
C     *  AUTHORS ... MAURICE G. COX AND                *
C     *              J. GEOFFREY HAYES, N.P.L.         *
C     *                                                *
C     **************************************************
C

E02BEF
      SUBROUTINE E02BEF(START,M,X,Y,W,S,NEST,N,K,C,FP,WRK,LWRK,IWRK,
     *                  IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.

E02CAF
      SUBROUTINE E02CAF(M,N,K,L,X,Y,F,W,NX,A,NA,XMIN,XMAX,NUX,INUXP1,
     *                  NUY,INUYP1,WORK,NWORK,IFAIL)
C     MARK 7 RELEASE. NAG COPYRIGHT 1978.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     E02CAF IS A CALLING ROUTINE WHICH SETS UP WORK SPACE ARRAYS
C     FOR THE SUBROUTINE E02CAZ AND THEN CALLS IT TO OBTAIN AN
C     APPROXIMATION TO THE LEAST SQUARES POLYNOMIAL SURFACE FIT
C     TO DATA ARBITRARILY DISTRIBUTED ON LINES PARALLEL TO ONE
C     INDEPENDENT COORDINATE AXIS.
C
C     STARTED - 1978.
C     COMPLETED - 1978.
C     AUTHOR - GTA.
C
C
C     FIND MAXIMUM OF N AND THE ELEMENTS OF M, AND LARGER OF K AND
C     L, AND THE SUM OF THE ELEMENTS OF M
C

E02CBF
      SUBROUTINE E02CBF(MFIRST,MLAST,K,L,X,XMIN,XMAX,Y,YMIN,YMAX,FF,A,
     *                  NA,WORK,NWORK,IFAIL)
C     MARK 7 RELEASE. NAG COPYRIGHT 1978.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     THIS SUBROUTINE EVALUATES A POLYNOMIAL OF DEGREE K AND L
C     RESPECTIVELY IN THE INDEPENDENT VARIABLES X AND Y.  THE
C     POLYNOMIAL IS GIVEN IN DOUBLE CHEBYSHEV SERIES FORM
C     A(I,J) * TI(XCAP) * TJ(YCAP),
C     SUMMED OVER I = 0,1,...K AND J = 0,1,...L WITH THE CONVENTION
C     THAT TERMS WITH EITHER I OR J ZERO ARE HALVED AND THE TERM
C     WITH BOTH I AND J ZERO IS MULTIPLIED BY 0.25. HERE TI(XCAP)
C     IS THE CHEBYSHEV POLYNOMIAL OF THE FIRST KIND OF DEGREE I
C     WITH ARGUMENT XCAP=((X - XMIN) - (XMAX - X))/(XMAX - XMIN).
C     TJ(YCAP) IS DEFINED SIMILARLY. THE COEFFICIENT A(I,J)
C     SHOULD BE STORED IN ELEMENT (L + 1)*I + J + 1 OF THE SINGLE
C     DIMENSION ARRAY A. THE EVALUATION IS PERFORMED FOR A SINGLE
C     GIVEN VALUE OF Y WITH EACH X VALUE GIVEN IN X(R), FOR R =
C     MFIRST, MFIRST+1,....,MLAST.
C
C     STARTED - 1978.
C     COMPLETED - 1978.
C     AUTHOR - GTA.
C

E02DAF
      SUBROUTINE E02DAF(M,PX,PY,X,Y,F,W,LAMDA,MU,POINT,NPOINT,DL,C,NC,
     *                  WS,NWS,EPS,SIGMA,RANK,IFAIL)
C     MARK 6 RELEASE. NAG COPYRIGHT 1977
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     THIS IS A CALLING ROUTINE WHICH SETS UP WORK SPACE ARRAYS
C     FOR THE SUBROUTINE E02DAZ, AND THEN CALLS IT.
C

E02DCF
      SUBROUTINE E02DCF(START,MX,X,MY,Y,F,S,NXEST,NYEST,NX,LAMDA,NY,MU,
     *                  C,FP,WRK,LWRK,IWRK,LIWRK,IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.

E02DDF
      SUBROUTINE E02DDF(START,M,X,Y,F,W,S,NXEST,NYEST,NX,LAMDA,NY,MU,C,
     *                  FP,RANK,WRK,LWRK,IWRK,LIWRK,IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.

E02DEF
      SUBROUTINE E02DEF(M,PX,PY,X,Y,LAMDA,MU,C,FF,WRK,IWRK,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     Derived from DASL routine B2VRE.
C
C     E02DEF. An algorithm for evaluating a bicubic polynomial
C     spline S(X,Y) from its B-spline representation at the M
C     points (X(I),Y(I)), I = 1, 2, ..., M.
C
C     Input Parameters:
C        M        The number of evaluation points.
C        PX       NXKNTS + 8,  where  NXKNTS  is number
C                    of interior  X-knots.
C        PY       NYKNTS + 8,  where  NYKNTS  is number
C                    of interior  Y-knots.
C        X        X-values.
C        Y        Y-values.
C        LAMDA    The X-knots.
C        MU       The Y-knots.
C        C        B-spline coefficients of  S.  First
C                    subscript relates to  X.
C
C     Output parameter:
C        FF       Values of spline.
C                 On exit, FF(I) contains the value of
C                 the spline evaluated at point (X(I),Y(I)),
C                 for I = 1,..,M.
C
C     Workspace parameters:
C        WRK      Real workspace of dimension at least (PY-4).
C        IWRK     Integer workspace of dimension at least (PY-4).
C
C     Failure indicator parameter:
C        IFAIL    Failure indicator:
C                 1 -  PX     .LT. 8,    or
C                      PY     .LT. 8,    or
C                      M      .LT. 1.
C                 2 -  E02DFW  failure for  X  or  Y.
C                 3 -  At least one point (X(K),Y(K)) lies
C                      outside the rectangle defined by
C                      LAMDA(4), LAMDA(PX-3), MU(4) and MU(PY-3).
C

E02DFF
      SUBROUTINE E02DFF(MX,MY,PX,PY,X,Y,LAMDA,MU,C,FF,WRK,LWRK,IWRK,
     *                  LIWRK,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     Derived from DASL routine B2VRE.
C
C     E02DFF.  An algorithm for evaluating a bivariate
C     polynomial spline  S(X,Y)  from its B-spline
C     representation at all vertices of a rectangular mesh.
C
C     The routine is designed to be fast, but this is at the
C     expense of some workspace.  If speed is less important
C     than space,  E02DFF  may be called several times with
C     one meshline of values, for example, at each call.
C
C     Input Parameters:
C        PX       NXKNTS + 8,  where  NXKNTS  is number
C                    of interior  X-knots.
C        LAMDA    The X-knots.
C        PY       NYKNTS + 8,  where  NYKNTS  is number
C                    of interior  Y-knots.
C        MU       The Y-knots.
C        C        B-spline coefficients of  S.  First
C                    subscript relates to  X.
C        MX       The number of  X-meshlines.
C        X        X-meshline values.
C        MY       The number of  Y-meshlines.
C        Y        The Y-meshline values.
C
C     Output parameters:
C        FF       Values of spline.
C                 On exit, FF((I-1)*MY+J) contains the value of
C                 the spline evaluated at point (X(I),Y(J)),
C                 for I = 1,..,MX, J = 1,..,MY.
C
C     Workspace (and associated dimension) parameters:
C        WRK      Real workspace.
C        LWRK     Dimension of  WRK.  .ge. NWRK =
C                    min(NWRK1, NWRK2),  where
C                    NWRK1 = MX*4 + PX,
C                    NWRK2 = MY*4 + PY.
C        IWRK     Integer workspace.
C        LIWRK    Dimension of  IWRK.  .ge. NIWRK =
C                    MX + PX - 4  (if NWRK1 .le. NWRK2),
C                    MY + PY - 4  (otherwise).
C
C     Failure indicator parameter:
C        IFAIL    Failure indicator:
C                 1 -  PX     .LT. 8,    or
C                      PY     .LT. 8,    or
C                      MX     .LT. 0,    or
C                      MY     .LT. 0,    or
C                      LWRK   .LT. NWRK  or
C                      LIWRK  .LT. NIWRK
C                 2 -  E02DFW  failure for  X  or  Y.
C                 3 -  LAMDA(4) .le. X(1) .lt. X(2) .lt. ...
C                               .lt. X(MX) .le. LAMDA(PX-3)    or
C                      MU(4) .le. Y(1) .lt. Y(2) .lt. ...
C                            .lt. Y(MY) .le. MU(PY-3)
C                      violated.
C

E02GAF
      SUBROUTINE E02GAF(M,A,LA,B,NPLUS2,TOL,X,RESID,IRANK,ITER,IWORK,
     *                  IFAIL)
C     MARK 7 RELEASE. NAG COPYRIGHT 1978.
C     MARK 10A REVISED. IER-396 (OCT 1982).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C
C     THIS SUBROUTINE USES A MODIFICATION OF THE SIMPLEX METHOD
C     OF LINEAR PROGRAMMING TO CALCULATE AN L1 SOLUTION TO AN
C     OVER-DETERMINED SYSTEM OF LINEAR EQUATIONS.
C

E02GBF
      SUBROUTINE E02GBF(M,N,MPL1,E,IER,F,X,MXS1,MONIT,IPRINT,K,EL1N,
     *                  INDX,W,IW,IFAIL)
C     MARK 7 RELEASE. NAG COPYRIGHT 1978.
C     MARK 8A REVISED. IER-256 (AUG 1980).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C     MARK 14 REVISED. IER-812 (DEC 1989).
C     MONIT

E02GCF
      SUBROUTINE E02GCF(M,N,MDIM,NDIM,A,B,TOL1,RELER,X,RESMAX,IRANK,
     *                  ITER,IFAIL)
C     MARK 8 RELEASE.  NAG COPYRIGHT 1980.
C     MARK 9 REVISED. IER-316 (SEP 1981).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C
C     THIS SUBROUTINE USES A MODIFICATION OF THE SIMPLEX METHOD
C     OF LINEAR PROGRAMMING TO CALCULATE A CHEBYSHEV SOLUTION TO
C     AN OVER-DETERMINED SYSTEM OF LINEAR EQUATIONS.
C
C     DERIVED FROM ACM ALGORITHM 495 BY I. BARRODALE AND C. PHILLIPS
C

E02RAF
      SUBROUTINE E02RAF(IA,IB,C,IC,A,B,W,JW,IFAIL)
C     MARK 7 RELEASE. NAG COPYRIGHT 1978.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     GIVEN A POWER SERIES E02RAF CALCULATES THE COEFFICIENTS OF
C     THE (L/M) PADE APPROXIMANT.
C
C     ARGUMENT LIST.
C     --------------
C
C     IA    (INTEGER)  ON ENTRY IA=L+1. THIS PARAMETER IMPLICITLY
C                      SPECIFIES THE ORDER OF THE NUMERATOR OF THE
C                      APPROXIMANT.
C                      UNCHANGED ON EXIT.
C     IB    (INTEGER)  ON ENTRY IB=M+1. THIS PARAMETER IMPLICITLY
C                      SPECIFIES THE ORDER OF THE DENOMINATOR OF
C                      THE APPROXIMANT. UNCHANGED ON EXIT.
C     C   (REAL ARRAY) ON ENTRY CONTAINS THE POWER SERIES
C                      COEFFICIENTS. UNCHANGED ON EXIT.
C     IC    (INTEGER)  LENGTH OF ARRAY C. AT LEAST L+M+1
C     A   (REAL ARRAY) ON EXIT CONTAINS THE NUMERATOR COEFFICIENTS
C                      A(1)= COEFF OF X**0 ETC.
C     B   (REAL ARRAY) ON EXIT CONTAINS THE DENOMINATOR
C                      COEFFICIENTS. B(1)=COEFF OF X**0 ETC.
C     W   (REAL ARRAY) ARRAY USED AS WORKSPACE.
C     JW    (INTEGER)  DIMENSION OF W AT LEAST IB*(2*IB+3).
C     IFAIL (INTEGER)  USED FOR ERROR EXITS.
C

E02RBF
      SUBROUTINE E02RBF(A,IA,B,IB,X,ANS,IFAIL)
C     MARK 7 RELEASE. NAG COPYRIGHT 1978.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C
C     E02RBF EVALUATES AN (L/M) PADE APPROXIMANT, WHOSE
C     NUMERATOR AND DENOMINATOR COEFFICIENTS ARE STORED IN
C     ARRAYS A AND B RESPECTIVELY, AT A GIVEN POINT X.
C
C     ARGUMENT LIST
C     -------------
C
C     A,B  (REAL ARRAYS) ON ENTRY CONTAINS THE NUMERATOR
C                        (DENOMINATOR) COEFFICIENTS OF THE PADE
C                        APPROXIMANT. UNCHANGED ON EXIT.
C     IA,IB  (INTEGERS)  ON ENTRY DEFINE IMPLICITLY THE ORDERS
C                        OF THE NUMERATOR IA=L+1, AND DENOMINATOR
C                        IB=M+1. UNCHANGED ON EXIT.
C     X        (REAL)    ON ENTRY DEFINES THE POINT OF EVALUATION
C                        OF THE PADE APPROXIMANT. UNCHANGED ON
C                        EXIT.
C     ANS      (REAL)    ON EXIT CONTAINS THE VALUE OF THE PADE
C                        APPROXIMANT AT X.
C     IFAIL   (INTEGER)  USED FOR ERROR EXITS.
C

E02ZAF
      SUBROUTINE E02ZAF(PX,PY,LAMDA,MU,M,X,Y,POINT,NPOINT,ADRES,NADRES,
     *                  IFAIL)
C     MARK 6 RELEASE. NAG COPYRIGHT 1977
C     MARK 10 REVISED. IER-385 (JUN 1982).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     THE REAL ARRAYS LAMDA AND MU OF DIMENSION AT LEAST
C     PX-4 AND PY-4 RESPECTIVELY EACH CONTAIN A SEQUENCE
C     OF NON-DECREASING VALUES.  THE POINTS WITH COORDINATES
C     GIVEN IN X(1) TO X(M) AND Y(1) TO Y(M) ARE SORTED INTO
C     THE RECTANGULAR PANELS DETERMINED BY THE LAMDA AND MU
C     VALUES.  ARRAYS X AND Y ARE UNCHANGED, THE ORDERING
C     BEING INDICATED BY NADRES LINKED LISTS STORED IN ARRAY
C     POINT(1) TO POINT(NPOINT), WHERE
C     NADRES = (PX-7)*(PY-7) IS THE NUMBER OF PANELS, AND
C     NPOINT .GE. NADRES + M
C

E04ABF
      SUBROUTINE E04ABF(FUN,EPS,T,A,B,MAXCAL,X,F,IFAIL)
C
C     MARK 6 RELEASE NAG COPYRIGHT 1977
C     MARK 8 REVISED. IER-231 (MAR 1980).
C     MARK 8D REVISED. IER-272 (DEC 1980).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C
C     **************************************************************
C
C     E04ABF ATTEMPTS TO FIND A MINIMUM IN AN INTERVAL A .LE. X .LE.
C     B OF A FUNCTION F(X) OF THE SCALAR X, USING FUNCTION VALUES
C     ONLY.
C
C     IT IS BASED ON THE SUBROUTINE UNIFUN IN THE NPL ALGORITHMS
C     LIBRARY (REF. NO. E4/13/F). THE FUNCTION F(X) IS DEFINED BY
C     THE USER-SUPPLIED SUBROUTINE FUN. T AND EPS DEFINE A TOLERANCE
C     TOL = EPS * ABS(X) + T, AND FUN IS NEVER EVALUATED AT TWO
C     POINTS CLOSER THAN TOL. IF FUN IS DELTA-UNIMODAL, FOR SOME
C     DELTA LESS THAN TOL, THEN X APPROXIMATES THE GLOBAL MINIMUM OF
C     FUN WITH AN ERROR LESS THAN 3*TOL. IF FUN IS NOT DELTA-
C     UNIMODAL ON (A, B), THEN X MAY APPROXIMATE A LOCAL, BUT NON
C     GLOBAL, MINIMUM. EPS SHOULD BE NO SMALLER THAN 2*EPSMCH, AND
C     PREFERABLY NOT MUCH LESS THAN SQRT(EPSMCH), WHERE EPSMCH IS
C     THE RELATIVE MACHINE PRECISION. T SHOULD BE POSITIVE. NOTE
C     THAT, FOR CONSISTENCY WITH OTHER E04 DOCUMENTATION, THE NAME
C     FUNCT IS USED INSTEAD OF FUN IN THE WRITE-UP.
C
C     PHILIP E. GILL, WALTER MURRAY, SUSAN M. PICKEN, HAZEL M.
C     BARBER AND MARGARET H. WRIGHT, D.N.A.C., NATIONAL PHYSICAL
C     LABORATORY, ENGLAND
C
C     **************************************************************
C
C     FUN

E04BBF
      SUBROUTINE E04BBF(FUN,EPS,T,A,B,MAXCAL,X,F,G,IFAIL)
C
C     MARK 6 RELEASE NAG COPYRIGHT 1977
C     MARK 8D REVISED. IER-272 (DEC 1980).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C
C     **************************************************************
C
C     E04BBF ATTEMPTS TO FIND A MINIMUM IN AN INTERVAL A .LE. X .LE.
C     B OF A FUNCTION F(X) OF THE SCALAR X, USING FUNCTION AND
C     GRADIENT VALUES.
C
C     IT IS BASED ON THE SUBROUTINE UNIGRD IN THE NPL ALGORITHMS
C     LIBRARY (REF. NO. E4/14/F). THE FUNCTION F(X) IS DEFINED BY
C     THE USER-SUPPLIED SUBROUTINE FUN. T AND EPS DEFINE A TOLERANCE
C     TOL = EPS * ABS(X) + T, AND FUN IS NEVER EVALUATED AT TWO
C     POINTS CLOSER THAN TOL. IF FUN IS DELTA-UNIMODAL, FOR SOME
C     DELTA LESS THAN TOL, THEN X APPROXIMATES THE GLOBAL MINIMUM OF
C     FUN WITH AN ERROR LESS THAN 3*TOL. IF FUN IS NOT DELTA-
C     UNIMODAL ON (A, B), THEN X MAY APPROXIMATE A LOCAL, BUT NON
C     GLOBAL, MINIMUM. EPS SHOULD BE NO SMALLER THAN 2*EPSMCH, AND
C     PREFERABLY NOT MUCH LESS THAN SQRT(EPSMCH), WHERE EPSMCH IS
C     THE RELATIVE MACHINE PRECISION. T SHOULD BE POSITIVE. NOTE
C     THAT, FOR CONSISTENCY WITH OTHER E04 DOCUMENTATION, THE NAME
C     FUNCT IS USED INSTEAD OF FUN IN THE WRITE-UP.
C
C     PHILIP E. GILL, WALTER MURRAY, SUSAN M. PICKEN, HAZEL M.
C     BARBER AND MARGARET H. WRIGHT, D.N.A.C., NATIONAL PHYSICAL
C     LABORATORY, ENGLAND
C
C     **************************************************************
C
C     FUN

E04CCF
      SUBROUTINE E04CCF(N,X,FMIN,EPS,N1,PDSTAR,PSTAR,PBAR,STEP,Y,P,
     *                  FUNCT,MONIT,MAXIT,IFAIL)
C     MARK 1 RELEASE.  NAG COPYRIGHT 1971
C     MARK 3 REVISED.
C     MARK 4.5 REISSUE. LER-F7
C     MARK 8 REVISED. IER-220 (MAR 1980)
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C     MARK 14 REVISED. IER-716 (DEC 1989).
C     MARK 16A REVISED. IER-984 (JUN 1993).

E04DGF
      SUBROUTINE E04DGF(N,FUNGRD,ITER,OBJF,OBJGRD,X,IWORK,WORK,IUSER,
     *                  USER,IFAIL)
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.
C     MARK 16 REVISED. IER-1053 (JUL 1993).
C
C     ==================================================================
C     E04DGF is a pre-conditioned, limited memory quasi-Newton method,
C     based on method PLMA of "Conjugate gradient methods for
C     large-scale nonlinear optimization", Technical Report SOL 79-15.
C     ==================================================================
C
C     -----------
C     Parameters
C     -----------
C
C     N      - INTEGER.
C           On entry, N must contain the number of variables in the
C           problem.
C
C     FUNGRD - SUBROUTINE, supplied by the user.
C           FUNGRD must be declared as EXTERNAL in the routine that
C           calls E04DGF.
C           If MODE = 0 then FUNGRD must calculate the objective
C           function, if MODE = 2 it must also calculate the gradient
C           vector.
C
C          It's specification is:
C          SUBROUTINE FUNGRD( MODE, N, X, OBJF, G, NSTATE, IUSER, USER )
C          INTEGER    MODE, N, NSTATE, IUSER(*)
C          REAL       X(N), OBJF, G(N), USER(*)
C
C          MODE   - INTEGER.
C          MODE indicates which parameter values within FUNGRD need to
C          be set.
C          If MODE = 0, FUNGRD must only return the value of the
C          objective function (OBJF) at X.
C          If MODE = 2, FUNGRD must also return the gradient ( G(1)...
C          ...G(N) ).
C          If MODE is negative on exit from FUNGRD, the execution of
C          E04DGF is terminated with IFAIL set to MODE.
C
C          N      - INTEGER.
C          On entry, N specifies the number of variables as input to
C          E04DGF.
C          N must not be altered by FUNGRD.
C
C          X      - REAL array of dimension (N).
C          On entry, X contains the point at which the objective
C          function is to be evaluated.
C          X must not be altered by FUNGRD.
C
C          OBJF   - REAL.
C          On exit, OBJF must contain the value of the objective
C          function.
C
C          G      - REAL array of dimension (N).
C          On exit, if MODE = 2 G(1) ... G(N) must contain the gradient
C          vector of the objective function. The j-th component of G
C          must contain the partial derivative of the function with
C          respect to the j-th variable.
C
C          NSTATE - INTEGER.
C          On entry, NSTATE will be set to 1 on the first call of FUNGRD
C          by E04DGF, and is set to 0 for all subsequent calls. Thus, if
C          the user wishes, NSTATE may be tested within FUNGRD in order
C          to perform cerain calculations once only. For example, the
C          user may read data or initialise COMMON blocks when NSTATE
C          = 1.
C
C          IUSER  - INTEGER array of dimension as least (1).
C          USER   - REAL    array of dimension at least (1).
C          FUNGRD is called from E04DGF with the parameters IUSER and
C          USER as supplied to E04DGF. The user is free to use arrays
C          IUSER and USER to supply information to FUNGRD as an
C          alternative to using COMMON.
C
C     ITER   - INTEGER.
C           On exit, ITER is set to the number of iterations performed
C           by E04DGF.
C
C     OBJF   - REAL.
C           On exit, contains the value of the objective function at the
C           final iterate.
C
C     OBJGRD - REAL array of length at least (N).
C           On exit, OBJGRD contains the gradient vector at the final
C           iterate.
C
C     X      - REAL array of length at least (N).
C           On entry, X must contain the initial estimate of the
C           solution.
C           On exit, X contains the final estimate of the solution.
C
C     IWORK  - INTEGER array of dimension at least (N+1).
C           Work array.
C
C     WORK   - REAL array of dimension at least (13*N).
C           Work array.
C
C     IFAIL  - INTEGER.
C           On entry, IFAIL must be set to 0,-1 or 1. The recommended
C           value for IFAIL is -1.
C           On exit, IFAIL represents a diagnostic indicator. The values
C           of IFAIL on exit are as follows:-
C
C           IFAIL < 0  the user requested termination by setting MODE
C                      negative within routine FUNGRD.
C
C           IFAIL = 0  indicates successful termination.
C
C           IFAIL = 3  maximum number of function evaluations have
C                      been performed.
C
C           IFAIL = 4  the computed upper bound on the step length
C                      taken during the linesearch was too small.
C                      A re-run with a larger value assigned to the
C                      maximum step length ( i.e. BIGDX ) may be
C                      successful. If BIGDX is already large ( .ge.
C                      the default value ) then current point cannot
C                      be improved upon.
C
C           IFAIL = 6  the current point cannot be improved upon.
C                      A sufficient decrease in the function value
C                      could not be attained during the final
C                      linesearch. If the subroutine OBJFUN computes
C                      the function and gradients correctly, then
C                      this may occur because an overly stringent
C                      accuracy has been requested i.e. Optimality
C                      tolerance (FTOL) is too small or if the
C                      minimum lies close to a step length of zero.
C
C           IFAIL = 7  large errors were found in the derivatives of
C                      the objective function. This value of IFAIL
C                      will occur if the verification process
C                      indicated that at least one gradient component
C                      had no correct figures. The user should refer
C                      to the printed output to determine which
C                      elements are suspect to be in error.
C
C           IFAIL = 8  indicates that the gradient (g) at the starting
C                      point is too small. The value g(trans)*g is
C                      less than machine precision. The problem
C                      should be rerun at a different starting point.
C
C           IFAIL = 9  an input parameter is invalid.
C
C
C     -------------------
C     Optional Parameters
C     -------------------
C
C     ITMAX   an INTEGER, the maximum number of iterations to be
C          performed. If ITMAX .lt. 0, then a default value of
C          max(50,5*N) is taken.
C
C     BIGDX   a REAL variable, the maximum allowable step length. The
C          default value is 1.0E+20.
C
C     FGUESS  a REAL variable, user supplied guess of optimum objective
C          function value. FGUESS is F(est) of CG paper (p.10 ).
C
C     EPSRF   a REAL variable which specifies the relative precision
C          of the objective function at the starting point.
C
C     ETA     is a REAL variable used to specify the accuracy of the
C          linesearch.
C
C     FTOL    is a REAL variable which indicates the correct number of
C          figures the user desires in the optimum function value.
C          For this purpose, leading zeros after the decimal are
C          considered as candidates for correct figures.
C
C     MSGCG   is an INTEGER variable which indicates the amount of
C          output required by the user.
C          The values of MSGCG are as follows:-
C          MSGCG = 0   No printout.
C          MSGCG = 1   Final solution only.
C          MSGCG = 5   One line of output for each iteration.
C          MSGCG = 10  Final solution and brief line of output for each
C                      iteration.
C
C     LDBGCG  is an INTEGER variable controlling debug output. If LDBGCG
C          > 0, then debug printout will be produced.
C
C     IDBGCG  is an INTEGER variable which indicates the number of the
C          iteration from which debug print should start.
C
C     ******************************************************************
C
C     -- Written on 4th June 1986.
C     Sven Hammarling and Janet Welding, NAG Central Office.
C

E04DJF
      SUBROUTINE E04DJF(IOPTNS,INFORM)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C
C     E04DJF  reads the options file from unit  IOPTNS  and loads the
C     options into the relevant elements of  IPRMCG  and  RPRMCG.
C
C     If  IOPTNS .lt. 0  or  IOPTNS .gt. 99  then no file is read,
C     otherwise the file associated with unit  IOPTNS  is read.
C
C     Output:
C
C         INFORM = 0  if a complete  OPTIONS  file was found
C                     (starting with  BEGIN  and ending with  END);
C                  1  if  IOPTNS .lt. 0  or  IOPTNS .gt. 99;
C                  2  if  BEGIN  was found, but end-of-file
C                     occurred before  END  was found;
C                  3  if end-of-file occurred before  BEGIN  or
C                     ENDRUN  were found;
C                  4  if  ENDRUN  was found before  BEGIN.
C
C     -- Written on 5-June-1986.
C        Sven Hammarling and Janet Welding, NAG Central Office.
C

E04DKF
      SUBROUTINE E04DKF(STRING)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C
C     E04DKF  loads the option supplied in  STRING  into the relevant
C     element of  IPRMLS  or  RPRMLS.
C
C     -- Written on 5-June-1986.
C        Janet Welding and Sven Hammarling, NAG Central Office.
C

E04FCF
      SUBROUTINE E04FCF(M,N,LSFN1,LSMON,IPRINT,MAXCAL,ETA,XTOL,STEPMX,X,
     *                  FSUMSQ,FVEC,FJAC,LJ,S,VT,LVT,NITER,NFTOTL,IW,
     *                  LIW,W,LW,IFAIL)
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.
C
C     **************************************************************
C
C     E04FCF IS A COMPREHENSIVE QUASI-NEWTON ALGORITHM FOR FINDING
C     AN UNCONSTRAINED MINIMUM OF A SUM OF SQUARES OF M NONLINEAR
C     FUNCTIONS IN N VARIABLES (M .GE. N).  NO DERIVATIVES ARE
C     REQUIRED.
C
C     THE ROUTINE IS ESSENTIALLY IDENTICAL TO THE SUBROUTINE LSNDN
C     IN THE NPL ALGORITHMS LIBRARY (REF. NO. E4/22/F).
C
C     PHILIP E. GILL, ENID M. R. LONG, WALTER MURRAY,
C     SUSAN M. PICKEN AND BRIAN T. HINDE
C     D.N.A.C., NATIONAL PHYSICAL LABORATORY, ENGLAND
C
C     **************************************************************
C
C     Modified to output explanatory messages.
C     Peter Mayes, NAG Central Office, December 1987.
C

E04FDF
      SUBROUTINE E04FDF(M,N,X,FSUMSQ,IW,LIW,W,LW,IFAIL)
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.
C
C     **************************************************************
C
C     E04FDF IS AN EASY-TO-USE ALGORITHM FOR FINDING
C     AN UNCONSTRAINED MINIMUM OF A SUM OF SQUARES OF M NONLINEAR
C     FUNCTIONS IN N VARIABLES (M .GE. N).  NO DERIVATIVES ARE
C     REQUIRED.
C
C     THE ROUTINE IS ESSENTIALLY IDENTICAL TO THE SUBROUTINE LSNDN1
C     IN THE NPL ALGORITHMS LIBRARY (REF. NO. E4/26/F) AND CALLS
C     E04FCZ WITH SUITABLE DEFAULT SETTINGS FOR PARAMETERS. IT CALLS
C     THE USER-SUPPLIED ROUTINE LSFUN1.
C
C     N.B. LSFUN1 IS A DESIGNATED NAME.
C     --------------------------------
C
C     GIVEN AN INITIAL APPROXIMATION TO THE MINIMUM, E04FDF COMPUTES
C     THE POSITION OF THE MINIMUM AND THE CORRESPONDING FUNCTION
C     VALUE.  THE REAL ARRAY W AND THE INTEGER ARRAY IW ARE USED
C     AS WORKSPACE.  W MUST BE DIMENSIONED AT LEAST
C     7*N + N*N + 2*M*N + 3*M + N*(N - 1)/2 OR 9 + 5*M IF N = 1
C     AND IW MUST HAVE AT LEAST ONE ELEMENT.
C
C     PHILIP E. GILL, WALTER MURRAY, SUSAN M. PICKEN,
C     NICHOLAS I. M. GOULD AND ENID M. R. LONG
C     D.N.A.C., NATIONAL PHYSICAL LABORATORY, ENGLAND
C
C     **************************************************************
C
C     Modified to call BLAS.
C     Peter Mayes, NAG Central Office, October 1987.
C
C     Modified to output explanatory messages.
C     Peter Mayes, NAG Central Office, December 1987.
C

E04GBF
      SUBROUTINE E04GBF(M,N,LSQLIN,LSFJC,LSMON,IPRINT,MAXCAL,ETA,XTOL,
     *                  STEPMX,X,FSUMSQ,FVEC,FJAC,LJ,S,VT,LVT,NITER,
     *                  NFTOTL,IW,LIW,W,LW,IFAIL)
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.
C     MARK 16 REVISED. IER-989 (JUN 1993).
C
C     **************************************************************
C
C     E04GBF IS A COMPREHENSIVE QUASI-NEWTON ALGORITHM FOR FINDING
C     AN UNCONSTRAINED MINIMUM OF A SUM OF SQUARES OF M NONLINEAR
C     FUNCTIONS IN N VARIABLES (M .GE. N).  FIRST DERIVATIVES ARE
C     REQUIRED.
C
C     THE ROUTINE IS ESSENTIALLY IDENTICAL TO THE SUBROUTINE LSFDQ
C     IN THE NPL ALGORITHMS LIBRARY (REF. NO. E4/21/F). E04GBF
C     WILL NORMALLY BE CALLED WITH E04FCV (WHICH CALLS E04ABZ)
C     OR E04HEV (WHICH CALLS E04BBZ) AS THE PARAMETER LSQLIN.
C
C     PHILIP E. GILL, SUSAN M. PICKEN, WALTER MURRAY
C     BRIAN T. HINDE AND NICHOLAS I. M. GOULD
C     D.N.A.C., NATIONAL PHYSICAL LABORATORY, ENGLAND.
C
C     **************************************************************
C
C     Modified to output explanatory messages.
C     Peter Mayes, NAG Central Office, December 1987.
C

E04GCF
      SUBROUTINE E04GCF(M,N,X,FSUMSQ,IW,LIW,W,LW,IFAIL)
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.
C
C     **************************************************************
C
C     E04GCF IS AN EASY-TO-USE QUASI-NEWTON ALGORITHM FOR FINDING
C     AN UNCONSTRAINED MINIMUM OF A SUM OF SQUARES OF M NONLINEAR
C     FUNCTIONS IN N VARIABLES (M .GE. N).  FIRST DERIVATIVES ARE
C     REQUIRED.
C
C     THE ROUTINE IS ESSENTIALLY IDENTICAL TO THE SUBROUTINE LSFDQ2
C     IN THE NPL ALGORITHMS LIBRARY (REF. NO. E4/21/F) AND CALLS
C     E04GBF WITH SUITABLE DEFAULT SETTINGS FOR PARAMETERS.  IT
C     CALLS THE USER-SUPPLIED ROUTINE LSFUN2.
C
C     N.B. LSFUN2 IS A DESIGNATED NAME.
C     --------------------------------
C
C     GIVEN AN INITIAL APPROXIMATION TO THE MINIMUM, E04GCF COMPUTES
C     THE POSITION OF THE MINIMUM AND THE CORRESPONDING FUNCTION
C     VALUE.  THE REAL ARRAY W AND THE INTEGER ARRAY IW ARE USED
C     AS WORKSPACE.  W MUST BE DIMENSIONED AT LEAST
C     8*N + N*N + 2*M*N + 3*M + N*(N - 1)/2 + N*(N + 1)/2 OR
C     11 + 5*M IF N = 1 AND IW MUST BE HAVE AT LEAST ONE ELEMENT.
C
C     PHILIP E. GILL, WALTER MURRAY, SUSAN M. PICKEN
C     AND NICHOLAS I. M. GOULD.
C     D.N.A.C., NATIONAL PHYSICAL LABORATORY, ENGLAND.
C
C     **************************************************************
C
C     Modified to call BLAS.
C     Peter Mayes, NAG Central Office, October 1987.
C
C     Modified to output explanatory messages.
C     Peter Mayes, NAG Central Office, December 1987.
C

E04GDF
      SUBROUTINE E04GDF(M,N,LSFJC,LSMON,IPRINT,MAXFUN,ETA,XTOL,STEPMX,X,
     *                  FSUMSQ,FVEC,FJAC,LJ,S,VT,LVT,NITER,NFTOTL,IW,
     *                  LIW,W,LW,IFAIL)
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.
C
C     **************************************************************
C
C     E04GDF IS A COMPREHENSIVE MODIFIED GAUSS-NEWTON ALGORITHM
C     FOR FINDING AN UNCONSTRAINED MINIMUM OF A SUM OF SQUARES OF
C     M NONLINEAR FUNCTIONS IN N VARIABLES (M .GE. N).  FIRST
C     DERIVATIVES ARE REQUIRED.
C
C     THE ROUTINE IS ESSENTIALLY IDENTICAL TO THE SUBROUTINE LSFDN
C     IN THE NPL ALGORITHMS LIBRARY (REF. NO. E4/18/F).
C
C     PHILIP E. GILL, SUSAN M. PICKEN, WALTER MURRAY,
C     BRIAN T. HINDE AND ENID M. R. LONG
C     D.N.A.C., NATIONAL PHYSICAL LABORATORY, ENGLAND.
C
C     **************************************************************
C
C     Modified to output explanatory messages.
C     Peter Mayes, NAG Central Office, December 1987.
C

E04GEF
      SUBROUTINE E04GEF(M,N,X,FSUMSQ,IW,LIW,W,LW,IFAIL)
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.
C
C     **************************************************************
C
C     E04GEF IS AN EASY-TO-USE MODIFIED GAUSS-NEWTON ALGORITHM
C     FOR FINDING AN UNCONSTRAINED MINIMUM OF A SUM OF SQUARES OF
C     M NONLINEAR FUNCTIONS IN N VARIABLES (M .GE. N).  FIRST
C     DERIVATIVES ARE REQUIRED.
C
C     THE ROUTINE IS ESSENTIALLY IDENTICAL TO THE SUBROUTINE LSFDN2
C     IN THE NPL ALGORITHMS LIBRARY (REF. NO. E4/24/F) AND CALLS
C     E04HEX WITH SUITABLE DEFAULT SETTINGS FOR PARAMETERS.  IT
C     CALLS THE USER-SUPPLIED ROUTINE LSFUN2.
C
C     N.B. LSFUN2 IS A DESIGNATED NAME.
C     --------------------------------
C
C     GIVEN AN INITIAL APPROXIMATION TO THE MINIMUM, E04GEF COMPUTES
C     THE POSITION OF THE MINIMUM AND THE CORRESPONDING FUNCTION
C     VALUE.  THE REAL ARRAY W AND THE INTEGER ARRAY IW ARE USED
C     AS WORKSPACE.  W MUST BE DIMENSIONED AT LEAST
C     8*N + N*N + 2*M*N + 3*M + N*(N - 1)/2 + N*(N + 1)/2 OR
C     11 + 5*M IF N = 1 AND IW MUST HAVE AT LEAST ONE ELEMENT.
C
C     PHILIP E. GILL, WALTER MURRAY, SUSAN M. PICKEN
C     AND NICHOLAS I. M. GOULD.
C     D.N.A.C., NATIONAL PHYSICAL LABORATORY, ENGLAND.
C
C     **************************************************************
C
C     Modified to call BLAS.
C     Peter Mayes, NAG Central Office, October 1987.
C
C     Modified to output explanatory messages
C     Peter Mayes, NAG Central Office, December 1987.
C

E04HCF
      SUBROUTINE E04HCF(N,SFUN,X,F,G,IW,LIW,W,LW,IFAIL)
C
C     MARK 6 RELEASE NAG COPYRIGHT 1977
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C     MARK 14 REVISED. IER-799 (DEC 1989).
C
C     **************************************************************
C
C     E04HCF CHECKS THAT A USER-SUPPLIED ROUTINE FOR EVALUATING AN
C     OBJECTIVE FUNCTION AND ITS FIRST DERIVATIVES PRODUCES
C     DERIVATIVE VALUES WHICH ARE CONSISTENT WITH THE FUNCTION
C     VALUES CALCULATED.
C
C     THE ROUTINE IS ESSENTIALLY IDENTICAL TO THE SUBROUTINE CHKGRD
C     IN THE NPL ALGORITHMS LIBRARY (REF. NO. E4/05/F). W(I), I = 1,
C     2, . . . , 3*N ARE USED AS WORKSPACE. (NOTE THAT, FOR
C     CONSISTENCY WITH OTHER E04 DOCUMENTATION, THE NAME FUNCT IS
C     USED INSTEAD OF SFUN IN THE WRITE-UP.)
C
C     PHILIP E. GILL, ENID M. R. LONG, WALTER MURRAY, SUSAN M.
C     PICKEN, D.N.A.C., NATIONAL PHYSICAL LABORATORY, ENGLAND.
C
C     **************************************************************
C
C     SFUN
C
C     A MACHINE DEPENDENT CONSTANT IS SET HERE. EPSMCH IS THE
C     SMALLEST POSITIVE REAL NUMBER SUCH THAT 1 + EPSMCH .GT. 1.
C

E04HDF
      SUBROUTINE E04HDF(N,SFUN,SHESS,X,G,HESL,LH,HESD,IW,LIW,W,LW,IFAIL)
C
C     MARK 6 RELEASE NAG COPYRIGHT 1977
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C     MARK 13 REVISED. IER-645 (APR 1988).
C     MARK 14 REVISED. IER-800 (DEC 1989).
C
C     **************************************************************
C
C     E04HDF CHECKS THAT A USER-SUPPLIED ROUTINE FOR CALCULATING
C     SECOND DERIVATIVES OF AN OBJECTIVE FUNCTION IS CONSISTENT WITH
C     A USER-SUPPLIED ROUTINE FOR CALCULATING THE CORRESPONDING
C     FIRST DERIVATIVES.
C
C     THE ROUTINE IS ESSENTIALLY IDENTICAL TO THE SUBROUTINE CHKHES
C     IN THE NPL ALGORITHMS LIBRARY (REF. NO. E4/04/F). W(I), I = 1,
C     2, . . . , 5*N ARE USED AS WORKSPACE. (NOTE THAT, FOR
C     CONSISTENCY WITH OTHER E04 DOCUMENTATION, THE NAMES FUNCT AND
C     HESS ARE USED INSTEAD OF SFUN AND SHESS IN THE WRITE-UP.)
C
C     PHILIP E. GILL, ENID M. R. LONG, WALTER MURRAY, SUSAN M.
C     PICKEN, D.N.A.C., NATIONAL PHYSICAL LABORATORY, ENGLAND.
C
C     **************************************************************
C
C     SFUN, SHESS
C
C     A MACHINE DEPENDENT CONSTANT IS SET HERE. EPSMCH IS THE
C     SMALLEST POSITIVE REAL NUMBER SUCH THAT 1.0 + EPSMCH .GT. 1.0.
C

E04HEF
      SUBROUTINE E04HEF(M,N,LSFJC,LSHES,LSMON,IPRINT,MAXCAL,ETA,XTOL,
     *                  STEPMX,X,FSUMSQ,FVEC,FJAC,LJ,S,VT,LVT,NITER,
     *                  NFTOTL,IW,LIW,W,LW,IFAIL)
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.
C
C     **************************************************************
C
C     E04HEF IS A COMPREHENSIVE MODIFIED GAUSS-NEWTON ALGORITHM
C     FOR FINDING AN UNCONSTRAINED MINIMUM OF A SUM OF SQUARES OF
C     M NONLINEAR FUNCTIONS IN N VARIABLES (M .GE. N). FIRST AND
C     SECOND DERIVATIVES ARE REQUIRED.
C
C     THE ROUTINE IS ESSENTIALLY IDENTICAL TO THE SUBROUTINE LSSDN
C     IN THE NPL ALGORITHMS LIBRARY (REF. NO. E4/17/F).
C
C     PHILIP E. GILL, SUSAN M. PICKEN, WALTER MURRAY AND
C     NICHOLAS I. M. GOULD.
C     D.N.A.C., NATIONAL PHYSICAL LABORATORY, ENGLAND.
C
C     **************************************************************
C
C     Modified to output explanatory messages.
C     Peter Mayes, NAG Central Office, December 1987.
C

E04HFF
      SUBROUTINE E04HFF(M,N,X,FSUMSQ,IW,LIW,W,LW,IFAIL)
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.
C
C     **************************************************************
C
C     E04HFF IS AN EASY-TO-USE MODIFIED GAUSS-NEWTON ALGORITHM
C     FOR FINDING AN UNCONSTRAINED MINIMUM OF A SUM OF SQUARES OF
C     M NONLINEAR FUNCTIONS IN N VARIABLES (M .GE. N).  FIRST AND
C     SECOND DERIVATIVES ARE REQUIRED.
C
C     THE ROUTINE IS ESSENTIALLY IDENTICAL TO THE SUBROUTINE LSSDN2
C     IN THE NPL ALGORITHMS LIBRARY (REF. NO. E4/23/F) AND CALLS
C     E04HEX WITH SUITABLE DEFAULT SETTINGS FOR PARAMETERS.  IT
C     CALLS THE USER-SUPPLIED ROUTINES LSFUN2 AND LSHES2.
C
C     N.B. LSFUN2 AND LSHES2 ARE DESIGNATED NAMES.
C     -------------------------------------------
C
C     GIVEN AN INITIAL APPROXIMATION TO THE MINIMUM, E04HFF COMPUTES
C     THE POSITION OF THE MINIMUM AND THE CORRESPONDING FUNCTION
C     VALUE.  THE REAL ARRAY W AND THE INTEGER ARRAY IW ARE USED
C     AS WORKSPACE.  W MUST BE DIMENSIONED AT LEAST
C     8*N + N*N + 2*M*N + 3*M + N*(N - 1)/2 + N*(N + 1)/2 OR
C     11 + 5*M IF N = 1 AND IW MUST HAVE AT LEAST ONE ELEMENT.
C
C     PHILIP E. GILL, WALTER MURRAY, SUSAN M. PICKEN
C     AND NICHOLAS I. M. GOULD.
C     D.N.A.C., NATIONAL PHYSICAL LABORATORY, ENGLAND.
C
C     **************************************************************
C
C     Modified to call BLAS.
C     Peter Mayes, NAG Central Office, October 1987.
C
C     Modified to output explanatory messages.
C     Peter Mayes, NAG Central Office, December 1987.
C

E04JAF
      SUBROUTINE E04JAF(N,IBOUND,BL,BU,X,F,IW,LIW,W,LW,IFAIL)
C
C     MARK 6 RELEASE NAG COPYRIGHT 1977
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C     MARK 13A REVISED. IER-632 (APR 1988).
C     MARK 14 REVISED. IER-815 (DEC 1989).
C     MARK 16 REVISED. IER-1109 (JUL 1993).
C
C     **************************************************************
C
C     E04JAF IS AN EASY-TO-USE QUASI-NEWTON ALGORITHM FOR FINDING A
C     MINIMUM OF A FUNCTION F(X1, X2, . . . XN), SUBJECT TO FIXED
C     UPPER AND LOWER BOUNDS ON THE INDEPENDENT VARIABLES X1, X2, .
C     . . , XN , USING FUNCTION VALUES ONLY.
C
C     GIVEN AN INITIAL ESTIMATE OF THE POSITION OF A CONSTRAINED
C     MINIMUM, THE ROUTINE ATTEMPTS TO COMPUTE THE POSITION OF THE
C     MINIMUM AND THE CORRESPONDING FUNCTION VALUE. IT IS ASSUMED
C     THAT F IS TWICE CONTINUOUSLY-DIFFERENTIABLE.
C
C     THE ROUTINE IS ESSENTIALLY IDENTICAL TO THE SUBROUTINE BCNDQ1
C     IN THE NPL ALGORITHMS LIBRARY (REF. NO. E4/49/F) AND CALLS
C     E04JBL WITH SUITABLE DEFAULT SETTINGS FOR PARAMETERS.
C
C     N.B. FUNCT1 IS A DESIGNATED NAME.
C     --------------------------------
C
C     THE REAL ARRAY W, USED AS WORKSPACE BY E04JAF, MUST BE
C     DIMENSIONED AT LEAST 12*N + N*(N - 1)/2, OR 13 IF N = 1. THE
C     INTEGER ARRAY IW, ALSO USED AS WORKSPACE BY E04JAF, MUST BE
C     DIMENSIONED AT LEAST (N + 2).
C
C     PHILIP E. GILL, WALTER MURRAY, SUSAN M. PICKEN, MARGARET H.
C     WRIGHT AND ENID M. R. LONG, D.N.A.C., NATIONAL PHYSICAL
C     LABORATORY, ENGLAND
C
C     **************************************************************
C
C
C     A MACHINE-DEPENDENT CONSTANT IS SET HERE. EPSMCH IS THE
C     SMALLEST POSITIVE REAL NUMBER SUCH THAT 1 + EPSMCH .GT. 1.
C

E04KAF
      SUBROUTINE E04KAF(N,IBOUND,BL,BU,X,F,G,IW,LIW,W,LW,IFAIL)
C
C     MARK 6 RELEASE NAG COPYRIGHT 1977
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C     MARK 13A REVISED. IER-632 (APR 1988).
C     MARK 14 REVISED. IER-816 (DEC 1989).
C     MARK 16 REVISED. IER-1110 (JUL 1993).
C
C     **************************************************************
C
C     E04KAF IS AN EASY-TO-USE QUASI-NEWTON ALGORITHM FOR FINDING A
C     MINIMUM OF A FUNCTION F(X1, X2, . . . , XN), SUBJECT TO FIXED
C     UPPER AND LOWER BOUNDS ON THE INDEPENDENT VARIABLES X1, X2, .
C     . . , XN , WHEN FIRST DERIVATIVES OF F ARE AVAILABLE.
C
C     GIVEN AN INITIAL ESTIMATE OF THE POSITION OF A CONSTRAINED
C     MINIMUM, THE ROUTINE ATTEMPTS TO COMPUTE THE POSITION OF THE
C     MINIMUM AND THE CORRESPONDING FUNCTION AND GRADIENT VALUES. IT
C     IS ASSUMED THAT F IS TWICE CONTINUOUSLY-DIFFERENTIABLE.
C
C     THE ROUTINE IS ESSENTIALLY IDENTICAL TO THE SUBROUTINE BCFDQ2
C     IN THE NPL ALGORITHMS LIBRARY (REF. NO. E4/48/F) AND CALLS
C     E04KBN WITH SUITABLE DEFAULT SETTINGS FOR PARAMETERS. (IN
C     PARTICULAR, E04LBS IS USED AS MINLIN.)
C
C     N.B. FUNCT2 IS A DESIGNATED NAME.
C     --------------------------------
C
C     THE REAL ARRAY W, USED AS WORKSPACE BY E04KAF, MUST BE
C     DIMENSIONED AT LEAST 10*N + N*(N - 1)/2, OR 11 IF N = 1. THE
C     INTEGER ARRAY IW, ALSO USED AS WORKSPACE BY E04KAF, MUST BE
C     DIMENSIONED AT LEAST (N + 2).
C
C     PHILIP E. GILL, WALTER MURRAY, SUSAN M. PICKEN, MARGARET H.
C     WRIGHT AND ENID M. R. LONG, D.N.A.C., NATIONAL PHYSICAL
C     LABORATORY, ENGLAND
C
C     **************************************************************
C
C
C     A MACHINE-DEPENDENT CONSTANT IS SET HERE. EPSMCH IS THE
C     SMALLEST POSITIVE REAL NUMBER SUCH THAT 1 + EPSMCH .GT.
C     EPSMCH.
C

E04KCF
      SUBROUTINE E04KCF(N,IBOUND,BL,BU,X,F,G,IW,LIW,W,LW,IFAIL)
C
C     MARK 6 RELEASE NAG COPYRIGHT 1977
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C     MARK 13A REVISED. IER-632 (APR 1988).
C     MARK 14 REVISED. IER-817 (DEC 1989).
C
C     **************************************************************
C
C     E04KCF IS AN EASY-TO-USE MODIFIED NEWTON ALGORITHM FOR FINDING
C     A MINIMUM OF A FUNCTION F(X1, X2, . . . , XN), SUBJECT TO
C     FIXED UPPER AND LOWER BOUNDS ON THE INDEPENDENT VARIABLES X1,
C     X2, . . . , XN , WHEN FIRST DERIVATIVES OF F ARE AVAILABLE.
C
C     GIVEN AN INITIAL ESTIMATE OF THE POSITION OF A CONSTRAINED
C     MINIMUM, THE ROUTINE ATTEMPTS TO COMPUTE THE POSITION OF THE
C     MINIMUM AND THE CORRESPONDING FUNCTION AND GRADIENT VALUES. IT
C     IS ASSUMED THAT F IS TWICE CONTINUOUSLY-DIFFERENTIABLE.
C
C     THE ROUTINE IS ESSENTIALLY IDENTICAL TO THE SUBROUTINE BCFDN2
C     IN THE NPL ALGORITHMS LIBRARY (REF. E4/47/F) AND CALLS E04LBR
C     WITH SUITABLE DEFAULT SETTINGS FOR PARAMETERS.
C
C     N.B. FUNCT2 IS A DESIGNATED NAME.
C     --------------------------------
C
C     THE REAL ARRAY W, USED AS WORKSPACE BY E04KCF, MUST BE
C     DIMENSIONED AT LEAST N*(N + 7), OR 10 IF N = 1. THE INTEGER
C     ARRAY IW, ALSO USED AS WORKSPACE BY E04KCF, MUST BE
C     DIMENSIONED AT LEAST (N + 2).
C
C     PHILIP E. GILL, WALTER MURRAY, SUSAN M. PICKEN, MARGARET H.
C     WRIGHT AND ENID M. R. LONG, D.N.A.C., NATIONAL PHYSICAL
C     LABORATORY, ENGLAND
C
C     **************************************************************
C
C
C     A MACHINE-DEPENDENT CONSTANT IS SET HERE. EPSMCH IS THE
C     SMALLEST POSITIVE REAL NUMBER SUCH THAT 1 + EPSMCH .GT. 1.
C

E04KDF
      SUBROUTINE E04KDF(N,SFUN,MONIT,IPRINT,MAXFUN,ETA,XTOL,DELTA,
     *                  STEPMX,IBOUND,BL,BU,X,HESL,LH,HESD,ISTATE,F,G,
     *                  IW,LIW,W,LW,IFAIL)
C
C     MARK 6 RELEASE NAG COPYRIGHT 1977
C     MARK 6A REVISED  IER-100
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     **************************************************************
C
C     E04KDF IS A COMPREHENSIVE MODIFIED NEWTON ALGORITHM FOR
C     FINDING
C     - AN UNCONSTRAINED MINIMUM OF A FUNCTION OF SEVERAL VARIABLES
C     - A MINIMUM OF A FUNCTION OF SEVERAL VARIABLES SUBJECT TO
C     FIXED UPPER AND/OR LOWER BOUNDS ON THE VARIABLES.
C     FIRST DERIVATIVES ARE REQUIRED.
C
C     THE ROUTINE IS ESSENTIALLY IDENTICAL TO THE SUBROUTINE BCMNAF
C     IN THE NPL ALGORITHMS LIBRARY (REF. NO. E4/32/F). IT CALLS
C     E04LBR WITH E04KDZ AS THE PARAMETER SHESS AND E04LBS (WHICH
C     CALLS E04BBZ) AS THE PARAMETER MINLIN.
C
C     THE USER MUST SUPPLY AN INITIAL APPROXIMATION TO THE MINIMUM
C     AND A SUBROUTINE SFUN TO COMPUTE THE FUNCTION VALUE AND/OR
C     GRADIENT VECTOR. (NOTE THAT FOR CONSISTENCY WITH OTHER E04
C     DOCUMENTATION, THE NAME FUNCT IS USED INSTEAD OF SFUN IN THE
C     WRITE-UP.) THE ARRAYS W AND IW ARE USED AS WORK-SPACE BY
C     E04LBR AND MUST BE DIMENSIONED AT LEAST MAX(8, 7*N + N(N-1)/2
C     ) AND 2, RESPECTIVELY. ON EXIT, E04KDF GIVES THE ESTIMATED
C     POSITION OF THE CONSTRAINED MINIMUM IN X AND THE LOWEST
C     FUNCTION VALUE IN F.
C
C     THE MAJORITY OF THE ARITHMETIC IS PERFORMED BY F01BQZ, F01DEF
C     AND F04AQZ, WHICH ARE CALLED MANY TIMES DURING THE SOLUTION OF
C     A PROBLEM. IMPLEMENTORS CAN REDUCE THE TIME TAKEN BY E04KDF
C     (PARTICULARLY WHEN N IS LARGE) BY PUTTING THE BODIES OF THESE
C     ROUTINES INTO MACHINE CODE.
C
C     PHILIP E. GILL, WALTER MURRAY, SUSAN M. PICKEN, MARGARET H.
C     WRIGHT AND ENID M. R. LONG, D.N.A.C., NATIONAL PHYSICAL
C     LABORATORY, ENGLAND
C
C     **************************************************************
C

E04LAF
      SUBROUTINE E04LAF(N,IBOUND,BL,BU,X,F,G,IW,LIW,W,LW,IFAIL)
C
C     MARK 6 RELEASE NAG COPYRIGHT 1977
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C     MARK 13A REVISED. IER-632 (APR 1988).
C     MARK 14 REVISED. IER-818 (DEC 1989).
C
C     **************************************************************
C
C     E04LAF IS AN EASY-TO-USE MODIFIED NEWTON ALGORITHM FOR FINDING
C     A MINIMUM OF A FUNCTION F(X1, X2, . . . , XN), SUBJECT TO
C     FIXED UPPER AND LOWER BOUNDS ON THE INDEPENDENT VARIABLES X1,
C     X2, . . . , XN , WHEN FIRST AND SECOND DERIVATIVES ARE
C     AVAILABLE.
C
C     GIVEN AN INITIAL ESTIMATE OF THE POSITION OF A CONSTRAINED
C     MINIMUM, THE ROUTINE ATTEMPTS TO COMPUTE THE POSITION OF THE
C     MINIMUM AND THE CORRESPONDING FUNCTION AND GRADIENT VALUES. IT
C     IS ASSUMED THAT F IS TWICE CONTINUOUSLY-DIFFERENTIABLE.
C
C     THE ROUTINE IS ESSENTIALLY IDENTICAL TO THE SUBROUTINE BCSDN2
C     IN THE NPL ALGORITHMS LIBRARY (REF. E4/46/F) AND CALLS E04LBR
C     WITH SUITABLE DEFAULT SETTINGS FOR PARAMETERS.
C
C     N.B. FUNCT2 AND HESS2 ARE DESIGNATED NAMES.
C     ------------------------------------------
C
C     THE REAL ARRAY W, USED AS WORKSPACE BY E04LAF, MUST BE
C     DIMENSIONED AT LEAST N*(N + 7), OR 10 IF N = 1. THE INTEGER
C     ARRAY IW, ALSO USED AS WORKSPACE BY E04LAF, MUST BE
C     DIMENSIONED AT LEAST (N + 2).
C
C     PHILIP E. GILL, WALTER MURRAY, SUSAN M. PICKEN, MARGARET H.
C     WRIGHT AND ENID M. R. LONG, D.N.A.C., NATIONAL PHYSICAL
C     LABORATORY, ENGLAND
C
C     **************************************************************
C
C
C     A MACHINE-DEPENDENT CONSTANT IS SET HERE. EPSMCH IS THE
C     SMALLEST POSITIVE REAL NUMBER SUCH THAT 1 + EPSMCH .GT. 1.
C

E04LBF
      SUBROUTINE E04LBF(N,SFUN,SHESS,MONIT,IPRINT,MAXFUN,ETA,XTOL,
     *                  STEPMX,IBOUND,BL,BU,X,HESL,LH,HESD,ISTATE,F,G,
     *                  IW,LIW,W,LW,IFAIL)
C
C     MARK 6 RELEASE NAG COPYRIGHT 1977
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     **************************************************************
C
C     E04LBF IS A COMPREHENSIVE MODIFIED NEWTON ALGORITHM FOR
C     FINDING
C     - AN UNCONSTRAINED MINIMUM OF A FUNCTION OF SEVERAL VARIABLES
C     - A MINIMUM OF A FUNCTION OF SEVERAL VARIABLES SUBJECT TO
C     FIXED UPPER AND/OR LOWER BOUNDS ON THE VARIABLES.
C     FIRST AND SECOND DERIVATIVES ARE REQUIRED.
C
C     THE ROUTINE IS ESSENTIALLY IDENTICAL TO THE SUBROUTINE BCMNA
C     IN THE NPL ALGORITHMS LIBRARY (REF. NO. E4/31/F). IT CALLS
C     E04LBR WITH E04LBS (WHICH CALLS E04BBZ) AS THE PARAMETER
C     MINLIN.
C
C     THE USER MUST SUPPLY AN INITIAL APPROXIMATION TO THE MINIMUM,
C     A SUBROUTINE SFUN TO COMPUTE THE FUNCTION VALUE AND/OR
C     GRADIENT VECTOR, AND A SUBROUTINE SHESS TO CALCULATE THE
C     HESSIAN MATRIX. (NOTE THAT, FOR CONSISTENCY WITH OTHER E04
C     DOCUMENTATION, THE NAMES FUNCT AND HESS ARE USED INSTEAD OF
C     SFUN AND SHESS IN THE WRITE-UP.) THE ARRAYS W AND IW ARE USED
C     AS WORK-SPACE BY E04LBR AND MUST BE DIMENSIONED AT LEAST
C     MAX(8, 7*N + N(N-1)/2 ) AND 2, RESPECTIVELY. ON EXIT, E04LBF
C     GIVES THE ESTIMATED POSITION OF THE CONSTRAINED MINIMUM IN X
C     AND THE LOWEST FUNCTION VALUE IN F.
C
C     THE MAJORITY OF THE ARITHMETIC IS PERFORMED BY F01BQZ, F01DEF
C     AND F04AQZ, WHICH ARE CALLED MANY TIMES DURING THE SOLUTION OF
C     A PROBLEM. IMPLEMENTORS CAN REDUCE THE TIME TAKEN BY E04LBF
C     (PARTICULARLY WHEN N IS LARGE) BY PUTTING THE BODIES OF THESE
C     ROUTINES INTO MACHINE CODE.
C
C     PHILIP E. GILL, WALTER MURRAY, SUSAN M. PICKEN, MARGARET H.
C     WRIGHT AND ENID M. R. LONG, D.N.A.C., NATIONAL PHYSICAL
C     LABORATORY, ENGLAND
C
C     **************************************************************
C

E04MFF
      SUBROUTINE E04MFF(N,NCLIN,A,LDA,BL,BU,CVEC,ISTATE,X,ITER,OBJ,AX,
     *                  CLAMDA,IW,LENIW,W,LENW,IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.
C
C     ******************************************************************
C     E04MFF  solves the linear programming problem
C
C           minimize               c' x
C              x
C                                 (  x )
C           subject to    bl  .le.(    ).ge.  bu,
C                                 ( Ax )
C
C     where  A  is a constant  nclin by n  matrix.
C     The feasible region is defined by a mixture of linear equality or
C     inequality constraints on  x.
C
C     n  is the number of variables (dimension of x).
C        (n must be positive.)
C
C     nclin  is the number of general linear constraints (rows of  A).
C        (nclin may be zero.)
C
C     The first  n  elements of  bl  and   bu  are lower and upper
C     bounds on the variables.  The next  nclin  elements are
C     lower and upper bounds on the general linear constraints.
C
C     The matrix  A  of coefficients in the general linear constraints
C     is entered as the two-dimensional array  A  (of dimension
C     LDA by n).  If nclin = 0, A is not referenced.
C
C     The vector  x  must contain an initial estimate of the solution,
C     and will contain the computed solution on output.
C
C     Documentation for  E04MFF  is coming real soon now.
C     Wait for the release of  users guide for LPOPT (Version 1.00-6),
C     by P. E. Gill, W. Murray and M. A. Saunders,
C
C     Version 1.0-6    Jun  30, 1991.  (Nag Mk 16 version.)
C
C     Copyright  1989  Optimates.
C     ******************************************************************
C

E04MGF
      SUBROUTINE E04MGF(IOPTNS,INFORM)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.
C
C     ******************************************************************
C     E04MGF  reads the options file from unit  IOPTNS  and loads the
C     options into the relevant elements of  IPRMLC  and  RPRMLC.
C
C     If  IOPTNS .lt. 0  or  IOPTNS .gt. 99  then no file is read,
C     otherwise the file associated with unit  IOPTNS  is read.
C
C     Output:
C
C         INFORM = 0  if a complete  OPTIONS  file was found
C                     (starting with  BEGIN  and ending with  END);
C                  1  if  IOPTNS .lt. 0  or  IOPTNS .gt. 99;
C                  2  if  BEGIN  was found, but end-of-file
C                     occurred before  END  was found;
C                  3  if end-of-file occurred before  BEGIN  or
C                     ENDRUN  were found;
C                  4  if  ENDRUN  was found before  BEGIN.
C     ******************************************************************
C

E04MHF
      SUBROUTINE E04MHF(STRING)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.
C
C     ******************************************************************
C     E04MHF  loads the option supplied in  STRING  into the relevant
C     element of  IPRMLC  or  RPRMLC.
C     ******************************************************************
C

E04NCF
      SUBROUTINE E04NCF(MM,N,NCLIN,LDA,LDR,A,BL,BU,CVEC,ISTATE,KX,X,R,B,
     *                  ITER,OBJ,CLAMDA,IW,LENIW,W,LENW,IFAIL)
C     MARK 14 RE-ISSUE.  NAG COPYRIGHT 1989.
C     MARK 16 REVISED. IER-1060 (JUL 1993).
C
C     ******************************************************************
C     E04NCF  solves problems of the form
C
C           Minimize               F(x)
C              x
C                                 (  x )
C           subject to    bl  .le.(    ).ge.  bu,
C                                 ( Ax )
C
C     where  '  denotes the transpose of a column vector,  x  denotes
C     the n-vector of parameters and  F(x) is one of the following
C     functions..
C
C     FP =  None                    (find a feasible point).
C     LP =  c'x
C     QP1=        1/2 x'Rx           R  n times n, symmetric pos. def.
C     QP2=  c'x + 1/2 x'Rx           .  .   ..        ..       ..  ..
C     QP3=        1/2 x'R'Rx         R  m times n, upper triangular.
C     QP4=  c'x + 1/2 x'R'Rx         .  .   ..  .   ..      ...
C     LS1=        1/2 (b - Rx)'(b - Rx)   R  m times n, rectangular.
C     LS2=  c'x + 1/2 (b - Rx)'(b - Rx)   .  .   ..  .     ...
C     LS3=        1/2 (b - Rx)'(b - Rx)  R  m times n, upper triangular.
C     LS4=  c'x + 1/2 (b - Rx)'(b - Rx)  .  .   ..  .   ..      ...
C
C     The matrix  R  is entered as the two-dimensional array  R  (of row
C     dimension  LDR).  If  LDR = 0,  R  is not accessed.
C
C     The vector  c  is entered in the one-dimensional array  CVEC.
C
C     NCLIN  is the number of general linear constraints (rows of  A).
C     (NCLIN may be zero.)
C
C     The first  N  elements of  BL  and   BU  are lower and upper
C     bounds on the variables.  The next  NCLIN  elements are
C     lower and upper bounds on the general linear constraints.
C
C     The matrix  A  of coefficients in the general linear constraints
C     is entered as the two-dimensional array  A  (of dimension
C     LDA  by  N).  If  NCLIN = 0,  A  is not accessed.
C
C     The vector  x  must contain an initial estimate of the solution,
C     and will contain the computed solution on output.
C
C
C     Complete documentation for  E04NCF  is contained in
C     Report SOL 86-1,
C     Users Guide for LSSOL (Version 1.0), by P.E. Gill,
C     S. J. Hammarling, W. Murray, M.A. Saunders and M.H. Wright,
C     Department of Operations Research, Stanford University, Stanford,
C     California 94305.
C
C     Systems Optimization Laboratory, Stanford University.
C     Version 1.0  Dated 24-January-1986.
C     Version 1.01 Dated 30-June-1986.  Level-2 BLAS added.
C     Version 1.02 Dated 13-May-1988.   Level-2 matrix routines added.
C     Version 1.05 Dated 20-Sep-1992.   Output modified.
C                        20-Oct-1992.   Summary file included.
C
C     Copyright  1984  Stanford University.
C
C     This material may be reproduced by or for the U.S. Government
C     pursuant to the copyright license under DAR clause 7-104.9(a)
C     (1979 Mar).
C
C     This material is based upon work partially supported by the
C     National Science Foundation under Grants MCS-7926009 and
C     ECS-8312142; the Department of Energy Contract AM03-76SF00326,
C     PA No. DE-AT03-76ER72018; the Army Research Office Contract DAA29-
C     84-K-0156; and the Office of Naval Research Grant N00014-75-C-0267
C     ******************************************************************
C

E04NDF
      SUBROUTINE E04NDF(IOPTNS,INFORM)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C
C***********************************************************************
C     E04NDF  reads the options file from unit  IOPTNS  and loads the
C     options into the relevant elements of  IPRMLS  and  RPRMLS.
C
C     If  IOPTNS .lt. 0  or  IOPTNS .gt. 99  then no file is read,
C     otherwise the file associated with unit  IOPTNS  is read.
C
C     Output:
C
C         INFORM = 0  if a complete  OPTIONS  file was found
C                     (starting with  BEGIN  and ending with  END);
C                  1  if  IOPTNS .lt. 0  or  IOPTNS .gt. 99;
C                  2  if  BEGIN  was found, but end-of-file
C                     occurred before  END  was found;
C                  3  if end-of-file occurred before  BEGIN  or
C                     ENDRUN  were found;
C                  4  if  ENDRUN  was found before  BEGIN.
C***********************************************************************
C

E04NEF
      SUBROUTINE E04NEF(STRING)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C
C***********************************************************************
C     E04NEF  loads the option supplied in  STRING  into the relevant
C     element of  IPRMLS  or  RPRMLS.
C***********************************************************************
C

E04NFF
      SUBROUTINE E04NFF(N,NCLIN,A,LDA,BL,BU,CVEC,H,LDH,QPHESS,ISTATE,X,
     *                  ITER,OBJ,AX,CLAMDA,IW,LENIW,W,LENW,IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.
C
C     ******************************************************************
C     E04NFF  solves problems of the form
C
C              minimize               f(x)
C                 x
C                                    (  x )
C              subject to    bl  .le.(    ).ge.  bu,
C                                    ( Ax )
C
C     where  '  denotes the transpose of a column vector,  x  denotes
C     the n-vector of parameters and  f(x) is one of the following...
C
C     FP            =              none    (find a feasible point)
C     LP            =    c'x
C     QP1           =          1/2 x'Hx     H n x n symmetric
C     QP2 (default) =    c'x + 1/2 x'Hx     H n x n symmetric
C     QP3           =          1/2 x'H'Hx   H m x n upper trapezoidal
C     QP4           =    c'x + 1/2 x'H'Hx   H m x n upper trapezoidal
C
C     The matrix  H  is stored in the two-dimensional array  H  of
C     row dimension  LDH.  H  can be entered explicitly as the matrix
C     H,  or implicitly via a user-supplied version of the
C     subroutine QPHESS.  If  LDH = 0,  H is not touched.
C
C     The vector  c  is entered in the one-dimensional array  CVEC.
C
C     nclin  is the number of general linear constraints (rows of  A).
C     (nclin may be zero.)
C
C     The first  n  elements of  bl  and   bu  are lower and upper
C     bounds on the variables.  The next  nclin  elements are
C     lower and upper bounds on the general linear constraints.
C
C     The matrix  A  of coefficients in the general linear constraints
C     is entered as the two-dimensional array  A  (of dimension
C     LDA by n).  If nclin = 0, A is not referenced.
C
C     The vector  x  must contain an initial estimate of the solution,
C     and will contain the computed solution on output.
C
C     Documentation for QPOPT is coming real soon now.
C     Wait for the release of users guide for QPOPT (Version 1.0), by
C     P. E. Gill, W. Murray and M. A. Saunders.
C
C     Version 1.0-6  Jun      30, 1991. (Nag Mk 16 version).
C
C     This version of  E04NFF  dated 11-Nov-92.
C     Copyright  1988  Optimates.
C     ******************************************************************
C

E04NGF
      SUBROUTINE E04NGF(IOPTNS,INFORM)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.
C
C     ******************************************************************
C     E04NGF  reads the options file from unit  IOPTNS  and loads the
C     options into the relevant elements of  IPRMLC  and  RPRMLC.
C
C     If  IOPTNS .lt. 0  or  IOPTNS .gt. 99  then no file is read,
C     otherwise the file associated with unit  IOPTNS  is read.
C
C     Output:
C
C         INFORM = 0  if a complete  OPTIONS  file was found
C                     (starting with  BEGIN  and ending with  END);
C                  1  if  IOPTNS .lt. 0  or  IOPTNS .gt. 99;
C                  2  if  BEGIN  was found, but end-of-file
C                     occurred before  END  was found;
C                  3  if end-of-file occurred before  BEGIN  or
C                     ENDRUN  were found;
C                  4  if  ENDRUN  was found before  BEGIN.
C     ******************************************************************
C

E04NHF
      SUBROUTINE E04NHF(STRING)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.
C
C     ******************************************************************
C     E04NHF  loads the option supplied in  STRING  into the relevant
C     element of  IPRMLC  or  RPRMLC.
C     ******************************************************************
C

E04UCF
      SUBROUTINE E04UCF(N,NCLIN,NCNLN,LDA,LDCJU,LDR,A,BL,BU,CONFUN,
     *                  OBJFUN,ITER,ISTATE,C,CJACU,CLAMDA,OBJF,GRADU,R,
     *                  X,IW,LENIW,W,LENW,IUSER,USER,IFAIL)
C     MARK 14 RE-ISSUE.  NAG COPYRIGHT 1989.
C     MARK 15B REVISED. IER-951 (NOV 1991).
C     MARK 16 REVISED. IER-1077 (JUL 1993).
C
C     ==================================================================
C     E04UCF   solves the nonlinear program
C
C            minimize                   F(x)
C
C                                    (    x  )
C            subject to    bl  .le.  (  A*x  )  .le.  bu
C                                    (  c(x) )
C
C     where  F(x)  is a smooth scalar function,  A  is a constant matrix
C     and  c(x)  is a vector of smooth nonlinear functions.  The
C     feasible region is defined by a mixture of linear and nonlinear
C     equality or inequality constraints on  x.
C
C     The dimensions of the problem are...
C
C     N        the number of variables (dimension of  x),
C
C     NCLIN    the number of linear constraints (rows of the matrix  A),
C
C     NCNLN    the number of nonlinear constraints (dimension of  c(x)),
C
C
C     E04UCF   uses a sequential quadratic programming algorithm, with a
C     positive-definite quasi-Newton approximation to the transformed
C     Hessian  Q'HQ  of the Lagrangian function (which will be stored in
C     the array  R).
C
C
C     Complete documentation for  E04UCF  is contained in Report
C     SOL 86-2, Users guide for E04UCF (Version 4.0), by P.E. Gill,
C     W. Murray, M.A. Saunders and M.H. Wright, Department of Operations
C     Research,  Stanford University, Stanford, California 94305.
C
C     Systems Optimization Laboratory, Stanford University.
C     Version 1.1,  April     12, 1983. The less said about this one...
C     Version 2.0,  April     30, 1984.
C     Version 3.0,  March     20, 1985. First Fortran 77 version
C     Version 3.2,  August    20, 1985.
C     Version 4.0,  April     16, 1986. First version with differences
C     Version 4.01, June      30, 1986. Level 2 BLAS + F77 linesearch
C     Version 4.02, August     5, 1986. Reset SSBFGS. One call to E04XAY
C     Version 4.03, June      14, 1987. Step limit
C     Version 4.04, June      28, 1989. Vectorizable BLAS
C     Version 4.05, November  28, 1989. Load and save files added
C                                       (but not to NAG version!)
C     Version 4.06, November   5, 1991. E04UCJ and E04UCK updated
C                   October   17, 1992. Summary/print file option.
C
C     Copyright  1983  Stanford University.
C
C     This material may be reproduced by or for the U.S. Government
C     pursuant to the copyright license under DAR Clause 7-104.9(a)
C     (1979 Mar).
C
C     This material is based upon work partially supported by the
C     National Science Foundation under Grants MCS-7926009 and
C     ECS-8312142; the Department of Energy Contract AM03-76SF00326,
C     PA No. DE-AT03-76ER72018; the Army Research Office Contract
C     DAA29-84-K-0156; and the Office of Naval Research Grant
C     N00014-75-C-0267.
C     ==================================================================
C

E04UDF
      SUBROUTINE E04UDF(IOPTNS,INFORM)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C
C***********************************************************************
C     E04UDF  reads the options file from unit  IOPTNS  and loads the
C     options into the relevant elements of  IPRMNP  and  RPRMNP.
C
C     If  IOPTNS .lt. 0  or  IOPTNS .gt. 99  then no file is read,
C     otherwise the file associated with unit  IOPTNS  is read.
C
C     Output:
C
C         INFORM = 0  if a complete  OPTIONS  file was found
C                     (starting with  BEGIN  and ending with  END);
C                  1  if  IOPTNS .lt. 0  or  IOPTNS .gt. 99;
C                  2  if  BEGIN  was found, but end-of-file
C                     occurred before  END  was found;
C                  3  if end-of-file occurred before  BEGIN  or
C                     ENDRUN  were found;
C                  4  if  ENDRUN  was found before  BEGIN.
C***********************************************************************
C

E04UEF
      SUBROUTINE E04UEF(STRING)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C
C***********************************************************************
C     E04UEF  loads the option supplied in STRING into the relevant
C     element of IPRMLS, RPRMLS, IPRMNP or RPRMNP.
C***********************************************************************
C

E04UPF
      SUBROUTINE E04UPF(M,N,NCLIN,NCNLN,LDA,LDCJU,LDFJU,LDR,A,BL,BU,
     *                  CONFUN,OBJFUN,ITER,ISTATE,C,CJACU,F,FJACU,
     *                  CLAMDA,OBJF,R,X,IW,LENIW,W,LENW,IUSER,USER,
     *                  IFAIL)
C     MARK 14 RELEASE.  NAG COPYRIGHT 1989.
C     MARK 16 REVISED. IER-1097 (JUL 1993).
C
C     ------------------------------------------------------------------
C
C     E04UPF  solves the constrained least-squares problem
C
C            minimize           F(x) = 0.5 * f(x)'f(x)
C
C
C                                    (    x  )
C            subject to    bl  .le.  (  A*x  )  .le.  bu
C                                    (  c(x) )
C
C     where  f(x)  is a vector of smooth functions,  A  is a constant
C     matrix and  c(x)  is a vector of smooth nonlinear functions.
C     The feasible region is defined by a mixture of linear and
C     nonlinear equality or inequality constraints on  x.
C
C     The dimensions of the problem are...
C
C     M        the number of elements of the vector f(x),
C
C     N        the number of variables (dimension of  x),
C
C     NCLIN    the number of linear constraints (rows of the matrix  A),
C
C     NCNLN    the number of nonlinear constraints (dimension of  c(x)).
C
C
C     E04UPF  uses a sequential quadratic programming algorithm, with a
C     positive-definite quasi-Newton approximation to the transformed
C     Hessian  Q'HQ  of the Lagrangian function (which will be stored in
C     the array  R).
C
C     Version 4.04, June        9, 1989.
C     Version 4.06, November    5, 1991. (Matches E04UCF).
C
C     Copyright  1989  Optimates.
C     ------------------------------------------------------------------
C

E04UQF
      SUBROUTINE E04UQF(IOPTNS,INFORM)
C     MARK 14 RELEASE.  NAG COPYRIGHT 1989.
C
C     ******************************************************************
C     E04UQF  reads the options file from unit  IOPTNS  and loads the
C     options into the relevant elements of  IPRMNP, RPRMNP, IPRMNL
C     and  RPRMNL.
C
C     If  IOPTNS .lt. 0  or  IOPTNS .gt. 99  then no file is read,
C     otherwise the file associated with unit  IOPTNS  is read.
C
C     Output:
C
C         INFORM = 0  if a complete  OPTIONS  file was found
C                     (starting with  BEGIN  and ending with  END);
C                  1  if  IOPTNS .lt. 0  or  IOPTNS .gt. 99;
C                  2  if  BEGIN  was found, but end-of-file
C                     occurred before  END  was found;
C                  3  if end-of-file occurred before  BEGIN  or
C                     ENDRUN  were found;
C                  4  if  ENDRUN  was found before  BEGIN.
C     ******************************************************************
C

E04URF
      SUBROUTINE E04URF(STRING)
C     MARK 14 RELEASE.  NAG COPYRIGHT 1989.
C
C     ******************************************************************
C     E04URF  loads the option supplied in STRING into the relevant
C     element of IPRMLS, RPRMLS, IPRMNP, RPRMNP, IPRMNL or RPRMNL.
C     ******************************************************************
C

E04XAF
      SUBROUTINE E04XAF(MSGLVL,N,EPSRF,X,MODE,OBJFUN,LHES,HFORW,FX,GRAD,
     *                  HCNTRL,HESIAN,IWARN,WORK,IUSER,USER,INFO,IFAIL)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C     MARK 13B REVISED. IER-659 (AUG 1988).
C     MARK 14 REVISED. IER-725 (DEC 1989).
C     MARK 16 REVISED. IER-1106 (JUL 1993).
C***********************************************************************
C     E04XAF (FDCALC)  computes a set of forward-difference intervals
C     for the n-variable function objfun at the point x by repeatedly
C     calling subroutine  E04XAZ (CHCORE).
C
C     Full documentation of  fdcalc  is contained in report SOL 83-6,
C     Documentation of FDCORE and FDCALC, by P.E. Gill, W. Murray,
C     M.A. Saunders and M.H. Wright, Department of Operations Research,
C     Stanford University, Stanford, California 94305, June 1983.
C
C     The input parameters of E04XAF are ...
C
C     msglvl   integer
C              -Controls the level of printout.
C               msglvl = 0  No printout.
C               msglvl = 1  Summary printout for each variable and
C                           warning messages.
C               msglvl = 2  Full debug printout from E04XAF and CHCORE.
C
C     n        integer
C              -The number of variables.
C
C     epsrf    real
C              -A good bound on the relative error in computing fx at x.
C               If epsrf is negative on entry or if the users value of
C               epsrf is too small or too large then the default value
C               of e**0.9 is used, where e is the machine precision.
C
C     x        real array of dimension at least (n).
C              -The point at which the intervals are to be computed.
C
C     mode     integer
C              -If mode = 0 E04XAF returns the gradient vector and
C                           hessian diagonal given function only.
C               If mode = 1 E04XAF returns the hessian matrix given
C                           function and gradients.
C               If mode = 2 E04XAF returns the gradient vector and
C                           hessian matrix given function only.
C
C     objfun   subroutine provided by the user.
C              -Objfun must calculate the objective function ( and
C               gradients if mode = 1 ). Objfun must be declared as
C               external in the routine that calls E04XAF.
C               Its specification is:
C               subroutine objfun( mode, n, x, fx grad, nstate)
C
C     lhes     integer
C              -The first dimension of array hesian as declared in the
C               calling program.
C               lhes .ge. n
C
C     the input/output parameters of E04XAF are ...
C
C     hforw    real array of dimension at least (n).
C              -Before entry, hforw should contain the initial trial
C               intervals for:-
C                  variable x(i)    if mode = 0 or mode = 2
C                  gradient grad(i) if mode = 1
C               If hforw(i) .le. 0.0 then the initial trial interval is
C               computed by E04XAF.
C               On exit hforw contains the forward-difference intervals.
C
C     the output parameters of E04XAF are ...
C
C     fx       real
C              -The value of the function at x.
C
C     grad     real array of dimension at least (n).
C              -The approximate gradient vector at x (computed by
C               forward-differences with  hforw if mode = 0 or 2).
C
C     hcntrl   real array of dimension at least (n).
C              -The central-difference intervals.
C
C     hesian   real array of dimension (lhes,n) if mode = 1 or mode = 2.
C                ''  ''   ''  ''       (lhes,1) if mode = 0.
C              -If mode = 1 or mode = 2 then the leading n by n part of
C               this array will contain the full hessian matrix.
C               If mode = 0 then the first n elements of this array will
C               contain the hessian diagonals.
C
C     iwarn    integer
C              -On successful exit iwarn = 0.
C               If the value of epsrf on entry is too small or too large
C               then iwarn is set to 1 or 2 respectively on exit.
C
C     the workspace parameters of E04XAF are ...
C
C     work     real array of dimension at least (n**2 + n) if mode = 1
C              mode = 2.
C              real array of dimension at least (n) if mode = 0.
C              -Used as workspace.
C
C     iuser    integer array of length at least (1)
C              -This array is not used by E04XAF, but is passed directly
C               to user supplied routine objfun and may be used to
C               supply information to objfun.
C
C     user     real array of length at least (1)
C              -This array is not used by E04XAF, but is passed directly
C               to user supplied routine objfun and may be used to
C               supply information to objfun.
C
C     the diagnostic parameters of E04XAF are ...
C
C     info     integer array of dimension at least (n)
C              -The i-th component indicates the status of the interval
C               for variable i (if mode = 0 or 2) or gradient i (if
C               mode = 1). info(i) = 0  means that the interval was
C               satisfactory.
C
C     ifail    integer
C              -Before entry ifail must be set to 0, -1 or 1 (see
C               Chapter p01). The recommended value is -1.
C               On successful exit ifail = 0.
C
C     Original Fortran 66 Version 2.1 of June 1983.  (SOL)
C     Fortran 77 version dated 17-May-1985.          (SOL)
C     Edited to output full hessian matrix. Mark 12. (NAG)
C
C***********************************************************************

E04YAF
      SUBROUTINE E04YAF(M,N,LSQFUN,X,FVEC,FJAC,LJ,IW,LIW,W,LW,IFAIL)
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.
C
C     **************************************************************
C
C     E04YAF CHECKS THAT A USER-SUPPLIED ROUTINE FOR EVALUATING A
C     VECTOR OF FUNCTIONS AND THE MATRIX OF THEIR FIRST DERIVATIVES
C     PRODUCES DERIVATIVE VALUES WHICH ARE CONSISTENT WITH THE
C     FUNCTION VALUES CALCULATED.
C
C     THIS SUBROUTINE MAY BE USED WHEN THE PARAMETER LIST OF LSQFUN
C     IS  (IFLAG, M, N, X, FVEC, FJAC, LJ, IW, LIW, W, LW)
C
C     PHILIP E. GILL, ENID M. R. LONG, WALTER MURRAY,
C     SUSAN M. PICKEN
C     D.N.A.C., NATIONAL PHYSICAL LABORATORY, ENGLAND.
C
C     **************************************************************
C
C     Revised to output explanatory messages.
C     Peter Mayes, NAG Central Office, December 1987.
C

E04YBF
      SUBROUTINE E04YBF(M,N,LSQFUN,LSQHES,X,FVEC,FJAC,LJ,B,LB,IW,LIW,W,
     *                  LW,IFAIL)
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.
C     MARK 14A REVISED.  IER-683 (DEC 1989).
C
C     **************************************************************
C
C     E04YBF CHECKS THAT A USER-SUPPLIED ROUTINE FOR EVALUATING
C     THE SECOND DERIVATIVE TERM OF THE HESSIAN MATRIX OF A SUM OF
C     SQUARES IS CONSISTENT WITH A USER-SUPPLIED ROUTINE FOR
C     CALCULATING THE CORRESPONDING FIRST DERIVATIVES.
C
C     THIS SUBROUTINE MAY BE USED WHEN THE PARAMETER LIST OF LSQHES
C     IS  (IFLAG, M, N, LB, FVEC, X, B, IW, LIW, W, LW)
C     AND THE PARAMETER LIST OF LSQFUN IS
C     (IFLAG, M, N, X, FVEC, FJAC, LJ, IW, LIW, W, LW)
C
C     PHILIP E. GILL, ENID M. R. LONG, WALTER MURRAY,
C     SUSAN M. PICKEN
C     D.N.A.C., NATIONAL PHYSICAL LABORATORY, ENGLAND.
C
C     **************************************************************
C
C     Revised to output explanatory messages.
C     Peter Mayes, NAG Central Office, December 1987.
C

E04YCF
      SUBROUTINE E04YCF(JOB,M,N,FSUMSQ,S,V,LV,CJ,WORK,IFAIL)
C     MARK 11 RELEASE. NAG COPYRIGHT 1983.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     E04YCF RETURNS ESTIMATES OF ELEMENTS OF THE VARIANCE-COVARIANCE
C     MATRIX FOR THE ESTIMATED REGRESSION COEFFICIENTS OF A NONLINEAR
C     LEAST SQUARES PROBLEMS.
C
C     FOR A DESCRIPTION OF THE PARAMETERS AND USE OF THIS ROUTINE SEE
C     THE NAG LIBRARY MANUAL.
C
C     -- WRITTEN ON 10-JANUARY-1984.  S.J. HAMMARLING.
C
C     NAG FORTRAN 66 ROUTINE.
C

E04ZCF
      SUBROUTINE E04ZCF(N,M,LA,CON,FUN,C,A,F,G,X,W,LW,IFAIL)
C     MARK 11 RELEASE. NAG COPYRIGHT 1983.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C     MARK 14 REVISED. IER-810 (DEC 1989).
C     MARK 15B REVISED. IER-952 (NOV 1991).
C
C     THIS VERSION MODIFIED (FROM E04ZAF) FOR USE WITH ROUTINES
C     E04VCF AND E04VDF.  S.J.HAMMARLING - 25 JULY 1983.
C
C     **************************************************************
C
C     E04ZCF CHECKS THAT USER-SUPPLIED ROUTINES FOR EVALUATING AN
C     OBJECTIVE FUNCTION, CONSTRAINT FUNCTIONS AND THEIR FIRST
C     DERIVATIVES PRODUCE DERIVATIVE VALUES WHICH ARE CONSISTENT
C     WITH THE FUNCTION AND CONSTRAINT VALUES CALCULATED.
C
C     THE ROUTINE IS ESSENTIALLY IDENTICAL TO THE SUBROUTINE CHKNCD
C     IN THE NPL ALGORITHMS LIBRARY (REF. NO. E4/66/F). W(I), I = 1,
C     2, . . . , 4*N + M + N*M ARE USED AS WORKSPACE. (NOTE THAT,
C     FOR CONSISTENCY WITH OTHER E04 DOCUMENTATION, THE NAME FUNCT
C     IS USED INSTEAD OF SFUN IN THE WRITE-UP.)
C
C     PHILIP E. GILL, ENID M. R. LONG, WALTER MURRAY AND SUSAN M.
C     PICKEN, D.N.A.C., NATIONAL PHYSICAL LABORATORY, ENGLAND.
C
C     **************************************************************
C
C     CON, FUN
C
C     A MACHINE DEPENDENT CONSTANT IS SET HERE. EPSMCH IS THE
C     SMALLEST POSITIVE REAL NUMBER SUCH THAT 1.0 + EPSMCH .GT. 1.0.
C

F01ABF
      SUBROUTINE F01ABF(A,IA,N,B,IB,Z,IFAIL)
C     MARK 2 RELEASE. NAG COPYRIGHT 1972
C     MARK 4 REVISED.
C     MARK 4.5 REVISED
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C     MARK 16 REVISED. IER-1001 (JUN 1993).
C
C     ACCURATE INVERSE OF A REAL SYMMETRIC POSITIVE DEFINITE
C     MATRIX USING CHOLESKYS METHOD, SIMPLIFIED PARAMETERS.
C     1ST AUGUST 1971
C

F01ADF
      SUBROUTINE F01ADF(N,A,IA,IFAIL)
C     MARK 15 RE-ISSUE. NAG COPYRIGHT 1991.
C
C     CHOLINVERSION1
C     The upper triangle of a positive definite symmetric matrix,
C     A, is stored in the upper triangle of an (N+1)*N array
C     A(I,J), I=1,N+1, J=1,N. The Cholesky decomposition A=LU,
C     where U is the transpose of L , is performed and L is stored
C     in the remainder of the array A. The reciprocals of the
C     diagonal elements are stored instead of the elements them-
C     selves. L is then replaced by its inverse and this in turn
C     is replaced by the lower triangle of the inverse of A. A is
C     retained so that the inverse can be subsequently improved.
C     The subroutine will fail if A, modified by the rounding
C     errors, is not positive definite.
C     1st December 1971
C
C     Rewritten to call LAPACK routines SPOTRF/F07FDF and
C     SPOTRI/F07FJF; new IFAIL exit for illegal input
C     parameters inserted; error messages inserted (February 1991).
C

F01BLF
      SUBROUTINE F01BLF(M,N,T,A,IA,AIJMAX,IRANK,INC,D,U,IU,DU,IFAIL)
C     NAG COPYRIGHT 1976. MARK  5 RELEASE.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     PDK, DNAC, NPL, TEDDINGTON. NOVEMBER 1975.
C     NPL DNAC LIBRARY SUBROUTINE QUINV.
C
C     DETERMINE THE RANK AND THE PSEUDO-INVERSE OF AN M*N
C     MATRIX A, WHERE M.GE.N. HOUSEHOLDERS FACTORISATION
C     INVOLVING ORTHOGONAL MATRICES IS USED IN THE
C     DECOMPOSITION A=QU. A CRITERION T IS USED TO
C     DECIDE WHEN ELEMENTS CAN BE REGARDED AS ZERO IN
C     THE DETERMINATION OF RANK. THE ELEMENT OF LARGEST
C     MODULUS IN THE CURRENT MATRIX AT EACH STAGE OF THE
C     REDUCTION IS RECORDED IN THE VECTOR AIJMAX. THE
C     TRANSPOSE OF THE PSEUDO-INVERSE IS OVERWRITTEN ON
C     A. A FAILURE EXIT WILL BE DUE TO AN INCORRECT
C     CHOICE OF T OR M LESS THAN N. USES AUXILIARY SUBROUTINES
C     F01BLZ AND F01BLY.
C

F01BRF
      SUBROUTINE F01BRF(N,NZ,A,LICN,IRN,LIRN,ICN,U,IKEEP,IW,W,LBLOCK,
     *                  GROW,ABORT,IDISP,IFAIL)
C     MARK 7 RELEASE. NAG COPYRIGHT 1978
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     DERIVED FROM HARWELL LIBRARY ROUTINE MA28A
C
C     THE PARAMETERS ARE AS FOLLOWS.....
C     N     INTEGER  ORDER OF MATRIX  NOT ALTERED BY SUBROUTINE.
C     NZ    INTEGER  NUMBER OF NON-ZEROS IN INPUT MATRIX  NOT
C     .     ALTERED BY SUBROUTINE.
C     A     REAL ARRAY  LENGTH LICN.  HOLDS NON-ZEROS OF
C     .     MATRIX ON ENTRY AND NON-ZEROS OF FACTORS ON EXIT.
C     .     REORDERED BY F01BRZ AND F01BRY AND ALTERED BY F01BRT.
C     LICN  INTEGER  LENGTH OF ARRAYS A AND ICN.  NOT ALTERED BY
C     .     SUBROUTINE.
C     IRN   INTEGER ARRAY  LENGTH LIRN.  HOLDS ROW INDICES ON INPUT
C     .     AND USED AS WORKSPACE BY F01BRT TO HOLD COLUMN
C     .     ORIENTATION OF MATRIX.
C     LIRN  INTEGER  LENGTH OF ARRAY IRN.
C     ICN   INTEGER ARRAY  LENGTH LICN.  HOLDS COLUMN INDICES ON
C     .     ENTRY AND COLUMN INDICES OF DECOMPOSED MATRIX ON EXIT.
C     .     REORDERED BY F01BRZ AND F01BRY AND ALTERED BY F01BRT.
C     U     REAL VARIABLE  SET BY USER TO CONTROL BIAS TOWARDS
C     .     NUMERIC OR SPARSITY PIVOTING.  U=1.0 GIVES PARTIAL
C     .     PIVOTING WHILE U=0. DOES NOT CHECK MULTIPLIERS AT ALL.
C     .     VALUES OF U GREATER THAN ONE ARE TREATED AS ONE WHILE
C     .     NEGATIVE VALUES ARE TREATED AS ZERO.  NOT ALTERED BY
C     .     SUBROUTINE.
C     IKEEP  INTEGER ARRAY  LENGTH 5*N  USED AS WORKSPACE BY F01BRF
C     .     (SEE LATER COMMENTS).  IT IS NOT REQUIRED TO BE SET ON
C     .     ENTRY AND, ON EXIT, IT CONTAINS INFORMATION ABOUT THE
C     .     DECOMPOSITION.  IT SHOULD BE PRESERVED BETWEEN THIS CALL
C     .     AND SUBSEQUENT CALLS TO F01BSF OR F04AXF.
C     IKEEP(I,1),I=1,N  HOLDS THE TOTAL LENGTH OF THE PART OF ROW I
C     .     IN THE DIAGONAL BLOCK.
C     ROW IKEEP(I,2),I=1,N  OF THE INPUT MATRIX IS THE ITH ROW IN
C     .     PIVOT ORDER.
C     COLUMN IKEEP(I,3),I=1,N  OF THE INPUT MATRIX IS THE ITH
C     .     COLUMN IN PIVOT ORDER.
C     IKEEP(I,4),I=1,N  HOLDS THE LENGTH OF THE PART OF ROW I IN
C     .     THE L PART OF THE L/U DECOMPOSITION.
C     IKEEP(I,5),I=1,N  HOLDS THE LENGTH OF THE PART OF ROW I IN
C     .     THE OFF-DIAGONAL BLOCKS.  IF THERE IS ONLY ONE DIAGONAL
C     .     BLOCK, IKEEP(1,5) WILL BE SET TO -1.
C     IW    INTEGER ARRAY LENGTH 8*N.
C     .     USED AS WORKSPACE.
C     W     REAL ARRAY  LENGTH N.  USED BY F01BRQ BOTH AS WORKSPACE
C     .     AND TO RETURN GROWTH ESTIMATE IN W(1).  THE USE OF THIS
C     .     ARRAY BY F01BRF IS THUS OPTIONAL DEPENDING ON THE VALUE
C     .     OF PARAMETER GROW.
C     LBLOCK  LOGICAL IF TRUE, F01BRY IS USED TO FIRST PERMUTE
C     .     THE MATRIX TO BLOCK LOWER TRIANGULAR FORM.
C     GROW  LOGICAL IF TRUE, THEN AN ESTIMATE OF THE INCREASE
C     .     IN SIZE OF MATRIX ELEMENTS DURING L/U DECOMPOSITION IS
C     .     GIVEN BY F01BRQ IN W(1).
C     ABORT  LOGICAL ARRAY LENGTH 4.
C     IF ABORT(1)=TRUE, THE ROUTINE WILL EXIT IMMEDIATELY
C     .     ON DETECTING STRUCTURAL SINGULARITY.
C     IF ABORT(2)=TRUE, THE ROUTINE WILL EXIT IMMEDIATELY
C     .     ON DETECTING NUMERICAL SINGULARITY.
C     IF ABORT(3)=TRUE, THE ROUTINE WILL EXIT IMMEDIATELY WHEN THE
C     .     AVAILABLE SPACE IN A/ICN IS FILLED UP BY THE PREVIOUSLY
C     .     DECOMPOSED ACTIVE, AND UNDECOMPOSED PARTS OF THE MATRIX.
C     IF ABORT(4)=TRUE, THE ROUTINE WILL EXIT IMMEDIATELY
C     .     ON DETECTING DUPLICATE ELEMENTS IN THE INPUT MATRIX.
C     IDISP  INTEGER ARRAY LENGTH 10. USED TO COMMUNICATE
C     .     INFORMATION ABOUT THE DECOMPOSITION TO THE USER AND
C     .     ALSO BETWEEN THIS CALL TO F01BRF AND SUBSEQUENT CALLS
C     .     TO F01BSF AND F04AXF.
C     ON EXIT -
C     IDISP(1) AND IDISP(2) INDICATE THE POSITION IN ARRAYS A AND
C     .     ICN OF THE FIRST AND LAST ELEMENTS IN THE L/U
C     .     DECOMPOSITION OF THE DIAGONAL BLOCKS RESPECTIVELY.
C     IDISP(3)= IRNCP  THE NUMBER OF COMPRESSES ON ARRAY IRN.
C     IDISP(4)= ICNCP  THE NUMBER OF COMPRESSES ON ARRAYS ICN/A.
C     IDISP(5)= IRANK  ESTIMATED RANK OF THE MATRIX.
C     IDISP(6)= MINIRN MINIMUM LENGTH OF ARRAY IRN FOR SUCCESS ON
C     .     FUTURE RUNS.
C     IDISP(7)= MINICN MINIMUM LENGTH OF ARRAYS ICN/A FOR SUCCESS
C     .     ON FUTURE RUNS.
C     IDISP(8)= NUMNZ  STRUCTURAL RANK OF MATRIX.
C     IDISP(9)= NUM    NUMBER OF DIAGONAL BLOCKS.
C     IDISP(10)=LARGE  SIZE OF LARGEST DIAGONAL BLOCK.
C     IFAIL  INTEGER VARIABLE  USED AS ERROR FLAG BY ROUTINE.
C
C     INTERNAL VARIABLES AND WORKSPACE USED IN  F01BRF ARE DEFINED
C     WITHIN THE SUBROUTINE IMMEDIATELY PRIOR TO THEIR FIRST USE.

F01BSF
      SUBROUTINE F01BSF(N,NZ,A,LICN,IVECT,JVECT,ICN,IKEEP,IW,W,GROW,EPS,
     *                  RMIN,ABORT,IDISP,IFAIL)
C     MARK 7 RELEASE. NAG COPYRIGHT 1978
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     DERIVED FROM HARWELL LIBRARY ROUTINE MA28B
C
C     DECOMPOSES A REAL SPARSE MATRIX USING THE PIVOTAL SEQUENCE
C     PREVIOUSLY OBTAINED BY F01BRF WHEN A MATRIX OF THE SAME
C     SPARSITY PATTERN WAS DECOMPOSED.
C
C     THE PARAMETERS ARE AS FOLLOWS ...
C     N      INTEGER  ORDER OF MATRIX  NOT ALTERED BY SUBROUTINE.
C     NZ     INTEGER  NUMBER OF NON-ZEROS IN INPUT MATRIX  NOT
C     .      ALTERED BY SUBROUTINE.
C     A      REAL ARRAY  LENGTH LICN.  HOLDS NON-ZEROS OF MATRIX ON
C     .      ENTRY AND NON-ZEROS OF FACTORS ON EXIT.  REORDERED
C     .      BY F01BSZ AND ALTERED BY SUBROUTINE F01BSY.
C     LICN   INTEGER  LENGTH OF ARRAYS A AND ICN.  NOT ALTERED BY
C     .      SUBROUTINE.
C     IVECT,JVECT  INTEGER ARRAYS  LENGTH NZ.  HOLD ROW AND COLUMN
C     .      INDICES OF NON-ZEROS RESPECTIVELY.  NOT ALTERED BY
C     .      SUBROUTINE.
C     ICN    INTEGER ARRAY  LENGTH LICN.  SAME ARRAY AS OUTPUT FROM
C     .      F01BRF.  UNCHANGED BY F01BSF.
C     IKEEP  INTEGER ARRAY  LENGTH 5*N.  SAME ARRAY AS OUTPUT FROM
C     .      F01BRF.  UNCHANGED BY F01BSF.
C     IW     INTEGER ARRAY  LENGTH 5*N.
C     .      USED AS WORKSPACE BY F01BSZ AND F01BSY.
C     W      REAL ARRAY  LENGTH N.  USED AS WORKSPACE
C     .      BY F01BSZ, F01BSY AND (OPTIONALLY) F01BRQ.
C     GROW   LOGICAL.  IF TRUE, AN ESTIMATE OF THE INCREASE
C     .      IN SIZE OF ARRAY ELEMENTS DURING L/U DECOMPOSITION
C     .      IS GIVEN BY F01BRQ IN W(1).
C     EPS    REAL.  USED TO TEST FOR SMALL PIVOTS. IF THE USER SETS
C     .      EPS.GT.1.0, NO CHECK IS MADE ON THE SIZE OF THE PIVOTS.
C     RMIN   REAL.  GIVES THE USER SOME INFORMATION ABOUT THE
C     .      STABILITY OF THE DECOMPOSITION.
C     ABORT  LOGICAL.  IF ABORT=TRUE, THE ROUTINE WILL EXIT
C     .      IMMEDIATELY ON DETECTING DUPLICATE ELEMENTS IN THE
C     .      INPUT MATRIX.
C     IDISP  INTEGER ARRAY LENGTH 2.  IDISP(1) AND (2) MUST HAVE THE
C     .      SAME VALUES AS OUTPUT FROM F01BRF. UNCHANGED BY THE
C     .      ROUTINE.
C     IFAIL  INTEGER.  USED AS ERROR FLAG BY THE ROUTINE.
C

F01BUF
      SUBROUTINE F01BUF(N,M1,K,A,IA,W,IFAIL)
C     MARK 7 RELEASE. NAG COPYRIGHT 1978.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     U*L*D*L**T*U**T DECOMPOSITION OF AN N*N POSITIVE DEFINITE
C     MATRIX A OF BAND WIDTH 2*M+1 WITH M1=M+1. K DETERMINES
C     THE SWITCHOVER POINT FROM U TO L AND MUST BE SUCH THAT
C     K.LE.N, K.GE.M. IF K=N THEN AN L*D*L**T DECOMPOSITION IS
C     OBTAINED. THE UPPER TRIANGULAR PART OF A IS
C     PRESENTED AS AN M1*N ARRAY A WITH THE DIAGONAL
C     ELEMENTS OF A IN THE M1-TH ROW. THE SPARE
C     LOCATIONS IN THE TOP LEFT ARE NOT USED. U, L AND D
C     ARE OVERWRITTEN ON A.
C     D(I) OVERWRITES A(I,I), L(I,J) OVERWRITES A(J,I) AND U(I,J)
C     OVERWRITES A(I,J), THE ELEMENT OF A(J,I) BEING STORED IN
C     POSITION (J+M+1-I,I) OF ARRAY A.
C     THE ALGORITHM WILL FAIL IF ANY COMPUTED ELEMENT OF D IS SUCH
C     THAT D(I).LE.0.0.
C     AN ADDITIONAL WORK SPACE OF M1 ELEMENTS IS USED.
C
C     PDK, DNAC, NPL, TEDDINGTON. DEC 1977.
C     NPL DNAC LIBRARY SUBROUTINE ULBAND.
C

F01BVF
      SUBROUTINE F01BVF(N,MA1,MB1,M3,K,A,IA,B,IB,C,IC,W,IFAIL)
C     MARK 7 RELEASE. NAG COPYRIGHT 1978.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     REDUCTION OF THE GENERAL SYMMETRIC EIGENPROBLEM
C     A*X=LAMBDA*B*X WITH B POSITIVE DEFINITE, WHERE A AND B
C     ARE BAND MATRICES OF ORDER N AND OF BANDWIDTHS 2*MA+1
C     AND 2*MB+1 RESPECTIVELY WITH MA1=MA+1 AND
C     MB1=MB+1, MA.GE.MB, TO THE EQUIVALENT
C     STANDARD SYMMETRIC PROBLEM C*Z=LAMBDA*Z, WHERE C IS A
C     BAND MATRIX OF WIDTH 2*MA+1. THE UPPER TRIANGLES OF
C     A AND B ARE GIVEN IN THE ARRAYS A(MA1,N) AND
C     B(MB1,N) WITH THEIR DIAGONAL ELEMENTS IN THE FINAL
C     ROWS. THE MATRIX B MUST HAVE BEEN FIRSTLY
C     DECOMPOSED USING THE SUBROUTINE F01BUF WITH K AS
C     THE SWITCHOVER POINT FROM U TO L. THE UPPER TRIANGLE
C     OF C OVERWRITES THE ELEMENTS OF ARRAY A, SO THE
C     ORIGINAL A IS LOST. AN ADDITIONAL WORK SPACE OF
C     (MA+MB+1)*(3*MA+MB) ELEMENTS IS USED.
C
C     PDK, DNAC, NPL, TEDDINGTON. DEC 1977.
C     NPL DNAC LIBRARY SUBROUTINE ULTRAN.
C

F01CKF
      SUBROUTINE F01CKF(A,B,C,N,P,M,Z,IZ,OPT,IFAIL)
C     MARK 14 RE-ISSUE.  NAG COPYRIGHT 1989.
C
C     RETURNS WITH THE RESULT OF THE MATRIX MULTIPLICATION OF B AND
C     C
C     IN THE MATRIX A, WITH THE OPTION TO OVERWRITE B OR C.
C     **************************************************************
C     ****
C     MATRIX MULTIPLICATION
C     A=B*C          IF OPT= 1 A,B,C ASSUMED DISTINCT
C     IF OPT=2 B IS OVERWRITTEN
C     IF OPT=3 C IS OVERWRITTEN
C     **************************************************************
C     ****

F01CRF
      SUBROUTINE F01CRF(A,M,N,MN,MOVE,IWRK,IFAIL)
C     MARK 7 RELEASE. NAG COPYRIGHT 1978.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 14A REVISED. IER-684 (DEC 1989).
C     *****
C     ALGORITHM 380 - REVISED
C     *****
C     A IS A ONE-DIMENSIONAL ARRAY OF LENGTH MN = M*N, WHICH
C     CONTAINS THE M X N MATRIX TO BE F01CRFPOSED
C     (STORED COLUMNWISE).
C     MOVE IS A ONE-DIMENSIONAL ARRAY OF LENGTH IWRK USED
C     TO STORE INFORMATION TO SPEED UP THE PROCESS. THE
C     VALUE IWRK = (M+N)/2 IS RECOMMENDED.
C     IFAIL INDICATES THE SUCCESS OR FAILURE OF THE ROUTINE.
C     NORMAL RETURN  IFAIL = 0
C     ERRORS         IFAIL = 1, MN NOT EQUAL TO M*N
C                    IFAIL = 2, IWRK NEGATIVE OR ZERO
C                    IFAIL.LT.ZERO, (SHOULD NEVER OCCUR),
C     IN THIS CASE WE SET IFAIL EQUAL TO THE FINAL VALUE OF I
C     WHEN THE SEARCH IS COMPLETED BUT SOME LOOPS HAVE NOT BEEN
C     MOVED NOTE * MOVE(I) WILL STAY ZERO FOR FIXED POINTS.
C     CHECK ARGUMENTS AND INITIALIZE.

F01CTF
      SUBROUTINE F01CTF(TRANSA,TRANSB,M,N,ALPHA,A,LDA,BETA,B,LDB,C,LDC,
     *                  IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C     MARK 14C REVISED. IER-883 (NOV 1990).
C
C  Purpose
C  =======
C
C  F01CTF performs one of the matrix-matrix operations
C
C     C := alpha*op( A ) + beta*op( B ),
C
C  where  op( X ) is one of
C
C     op( X ) = X   or   op( X ) = X',
C
C  alpha and beta are scalars, and A, B and C are matrices, with op( A )
C  an m by n matrix,  op( B )  an m by n matrix, and C an m by n matrix.
C
C  Parameters
C  ==========
C
C  TRANSA - CHARACTER*1.
C           On entry, TRANSA specifies the form of op( A ) to be used in
C           the matrix addition as follows:
C
C              TRANSA = 'N' or 'n',  op( A ) = A.
C
C              TRANSA = 'T' or 't',  op( A ) = A'.
C
C              TRANSA = 'C' or 'c',  op( A ) = A'.
C
C           Unchanged on exit.
C
C  TRANSB - CHARACTER*1.
C           On entry, TRANSB specifies the form of op( B ) to be used in
C           the matrix addition as follows:
C
C              TRANSB = 'N' or 'n',  op( B ) = B.
C
C              TRANSB = 'T' or 't',  op( B ) = B'.
C
C              TRANSB = 'C' or 'c',  op( B ) = B'.
C
C           Unchanged on exit.
C
C  M      - INTEGER.
C           On entry,  M  specifies  the number  of rows of the matrices
C           op( A ) and op( B ). M must be at least zero.
C           Unchanged on exit.
C
C  N      - INTEGER.
C           On entry, N  specifies the number of columns of the matrices
C           op( A ) and op( B ). N must be at least zero.
C           Unchanged on exit.
C
C  ALPHA  - REAL            .
C           On entry, ALPHA specifies the scalar alpha.  When  ALPHA  is
C           supplied as zero then A need not be set on entry.
C           Unchanged on exit.
C
C  A      - REAL             array of DIMENSION ( LDA, ma ), where ma is
C           m when TRANSA = 'N' or 'n', and is n otherwise.
C           If alpha is zero, then A need not be set on entry.
C           If alpha is not zero, then before entry with TRANSA = 'N' or
C           'n', the leading m by n part of the array A must contain the
C           matrix  A, otherwise the leading n by m part of the array  A
C           must contain the matrix A.
C           Unchanged on exit.
C
C  LDA    - INTEGER.
C           On entry, LDA specifies the first dimension of A as declared
C           in the calling (sub) program. When  TRANSA = 'N' or 'n' then
C           LDA must be at least  max( 1, m ), otherwise  LDA must be at
C           least  max( 1, n ).
C           Unchanged on exit.
C
C  BETA   - REAL            .
C           On entry,  BETA  specifies the scalar  beta.  When  BETA  is
C           supplied as zero then B need not be set on entry.
C           Unchanged on exit.
C
C  B      - REAL             array of DIMENSION ( LDB, mb ), where mb is
C           m when TRANSB = 'N' or 'n', and is n otherwise.
C           If beta is zero, then B need not be set on entry.
C           If beta is not zero, then before entry with  TRANSB = 'N' or
C           'n', the leading m by n part of the array B must contain the
C           matrix  B, otherwise the leading n by m part of the array  B
C           must contain the matrix B.
C           Unchanged on exit.
C
C  LDB    - INTEGER.
C           On entry, LDB specifies the first dimension of B as declared
C           in the calling (sub) program. When  TRANSB = 'N' or 'n' then
C           LDB must be at least  max( 1, m ), otherwise  LDB must be at
C           least  max( 1, n ).
C           Unchanged on exit.
C
C  C      - REAL             array of DIMENSION ( LDC, N ).
C           On exit, the array  C  is overwritten by the  m by n  matrix
C           alpha*op( A ) + beta*op( B ).
C
C  LDC    - INTEGER.
C           On entry, LDC specifies the first dimension of C as declared
C           in  the  calling  (sub)  program.   LDC  must  be  at  least
C           max( 1, m ).
C           Unchanged on exit.
C
C

F01CWF
      SUBROUTINE F01CWF(TRANSA,TRANSB,M,N,ALPHA,A,LDA,BETA,B,LDB,C,LDC,
     *                  IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C     MARK 15A REVISED. IER-909 (APR 1991).
C
C  Purpose
C  =======
C
C  F01CWF performs one of the matrix-matrix operations
C
C     C := alpha*op( A ) + beta*op( B ),
C
C  where  op( X ) is one of
C
C     op( X ) = X   or   op( X ) = X',
C
C  alpha and beta are scalars, and A, B and C are matrices, with op( A )
C  an m by n matrix,  op( B )  an m by n matrix, and C an m by n matrix.
C
C  Parameters
C  ==========
C
C  TRANSA - CHARACTER*1.
C           On entry, TRANSA specifies the form of op( A ) to be used in
C           the matrix addition as follows:
C
C              TRANSA = 'N' or 'n',  op( A ) = A.
C
C              TRANSA = 'T' or 't',  op( A ) = A'.
C
C              TRANSA = 'C' or 'c',  op( A ) = conjg(A').
C
C           Unchanged on exit.
C
C  TRANSB - CHARACTER*1.
C           On entry, TRANSB specifies the form of op( B ) to be used in
C           the matrix addition as follows:
C
C              TRANSB = 'N' or 'n',  op( B ) = B.
C
C              TRANSB = 'T' or 't',  op( B ) = B'.
C
C              TRANSB = 'C' or 'c',  op( B ) = conjg(B').
C
C           Unchanged on exit.
C
C  M      - INTEGER.
C           On entry,  M  specifies  the number  of rows of the matrices
C           op( A ) and op( B ). M must be at least zero.
C           Unchanged on exit.
C
C  N      - INTEGER.
C           On entry, N  specifies the number of columns of the matrices
C           op( A ) and op( B ). N must be at least zero.
C           Unchanged on exit.
C
C  ALPHA  - COMPLEX         .
C           On entry, ALPHA specifies the scalar alpha.  When  ALPHA  is
C           supplied as zero then A need not be set on entry.
C           Unchanged on exit.
C
C  A      - COMPLEX          array of DIMENSION ( LDA, ma ), where ma is
C           m when TRANSA = 'N' or 'n', and is n otherwise.
C           If alpha is zero, then A need not be set on entry.
C           If alpha is not zero, then before entry with TRANSA = 'N' or
C           'n', the leading m by n part of the array A must contain the
C           matrix  A, otherwise the leading n by m part of the array  A
C           must contain the matrix A.
C           Unchanged on exit.
C
C  LDA    - INTEGER.
C           On entry, LDA specifies the first dimension of A as declared
C           in the calling (sub) program. When  TRANSA = 'N' or 'n' then
C           LDA must be at least  max( 1, m ), otherwise  LDA must be at
C           least  max( 1, n ).
C           Unchanged on exit.
C
C  BETA   - COMPLEX         .
C           On entry,  BETA  specifies the scalar  beta.  When  BETA  is
C           supplied as zero then B need not be set on entry.
C           Unchanged on exit.
C
C  B      - COMPLEX          array of DIMENSION ( LDB, mb ), where mb is
C           m when TRANSB = 'N' or 'n', and is n otherwise.
C           If beta is zero, then B need not be set on entry.
C           If beta is not zero, then before entry with  TRANSB = 'N' or
C           'n', the leading m by n part of the array B must contain the
C           matrix  B, otherwise the leading n by m part of the array  B
C           must contain the matrix B.
C           Unchanged on exit.
C
C  LDB    - INTEGER.
C           On entry, LDB specifies the first dimension of B as declared
C           in the calling (sub) program. When  TRANSB = 'N' or 'n' then
C           LDB must be at least  max( 1, m ), otherwise  LDB must be at
C           least  max( 1, n ).
C           Unchanged on exit.
C
C  C      - COMPLEX          array of DIMENSION ( LDC, N ).
C           On exit, the array  C  is overwritten by the  m by n  matrix
C           alpha*op( A ) + beta*op( B ).
C
C  LDC    - INTEGER.
C           On entry, LDC specifies the first dimension of C as declared
C           in  the  calling  (sub)  program.   LDC  must  be  at  least
C           max( 1, m ).
C           Unchanged on exit.
C
C

F01LEF
      SUBROUTINE F01LEF(N,A,LAMBDA,B,C,TOL,D,IN,IFAIL)
C     MARK 11 RELEASE. NAG COPYRIGHT 1983.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 14 REVISED. IER-728 (DEC 1989).
C
C     F01LEF FACTORIZES THE MATRIX ( T - LAMBDA*I ), WHERE T IS AN
C     N BY N TRIDIAGONAL MATRIX AND LAMBDA IS A SCALAR, AS
C
C     T - LAMBDA*I = P*L*U ,
C
C     WHERE P IS A PERMUTATION MATRIX, L IS A UNIT LOWER TRIANGULAR
C     MATRIX WITH AT MOST ONE NON-ZERO SUB-DIAGONAL ELEMENT PER
C     COLUMN AND U IS AN UPPER TRIANGULAR MATRIX WITH TWO NON-ZERO
C     SUPER-DIAGONALS.
C
C     FOR A DESCRIPTION OF THE PARAMETERS AND USE OF THIS ROUTINE SEE
C     THE NAG LIBRARY MANUAL.
C
C     -- WRITTEN ON 11-JANUARY-1983.  S.J.HAMMARLING.
C
C     NAG FORTRAN 66 GENERAL PURPOSE ROUTINE.
C

F01LHF
      SUBROUTINE F01LHF(N,NBLOKS,BLKSTR,A,LENA,PIVOT,TOL,INDEX,IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.
C     MARK 13B REVISED. IER-661 (AUG 1988).
C     MARK 14C REVISED. IER-884 (NOV 1990).
C
C     Purpose:
C
C     F01LHF decomposes a real almost block diagonal matrix.
C
C
C     Specification:
C
C        SUBROUTINE F01LHF(N,NBLOKS,BLKSTR,A,LENA,PIVOT,
C       *                  TOL,INDEX,IFAIL)
C     C     INTEGER    N,NBLOKS,BLKSTR(3,NBLOKS),LENA,PIVOT(N),
C     C    *           INDEX,IFAIL
C     C     real       A(LENA),TOL
C
C
C     Description:
C
C     The routine factorizes a real almost block diagonal matrix, A, by
C     column elimination with alternate row and column pivoting such
C     that no 'fill-in' is produced. The code, which is derived from
C     ARCECO desribed in [1], uses Level 2 BLAS [2].
C     No three successive diagonal blocks may have columns in
C     common and therefore the almost block diagonal matrix must have
C     the form shown in the following diagram.
C
C         .------|
C         | .    |
C     1   |___.__|
C           |   .-----------|
C           |     .         |
C           |       .       |
C           |         .     |
C     2     |___________.___|
C                   |     .-------|
C                   |       .     |
C     3             |_________.___|
C                               .
C                                 .
C                                   .
C                                     .
C                                       .
C                                   |-----.-----------|
C                                   |       .         |
C                                   |         .       |
C                                   |           .     |
C     NBLOKS-1                      |_____________.___|
C                                         |         .---|
C                                         |           . |
C     NBLOKS                              |_____________|
C
C
C     References:
C
C     [1] FORTRAN Packages for Solving Certain Almost Block Diagonal
C      Linear Systems by Modified Alternate Row and Column Elimination,
C      J.C.Diaz, G.Fairweather, P.Keast,
C      ACM Transactions on Mathematical Software (1983) 9, 358-375
C
C     [2] An Extended Set of Fortran Basic Linear Algebra Subprograms
C      J.J.Dongarra, J.DuCroz, S.Hammarling, R.J.Hanson
C      NAG Technical Report (1987) TR3/87
C
C
C     Parameters:
C
C       N - INTEGER
C           On entry, N must specify the number of rows of the
C           matrix A.
C           N .gt. 0.
C           Unchanged on exit.
C
C     NBLOKS - INTEGER
C           On entry, NBLOKS must specify the total number of blocks
C           of the matrix A.
C           0 .lt. NBLOKS .le. N.
C           Unchanged on exit.
C
C     BLKSTR - INTEGER array of DIMENSION (3,NBLOKS)
C           Before entry, BLKSTR must contain information which
C           describes the block structure of A as follows:
C           BLKSTR(1,k) must contain the number of rows in the kth
C                       block, k=1,2,..,NBLOKS;
C           BLKSTR(2,k) must contain the number of columns in the kth
C                       block, k=1,2,..,NBLOKS;
C           BLKSTR(3,k) must contain the number of columns of overlap
C                       between the kth and (k+1)th blocks,
C                       k=1,2,..,NBLOKS-1.
C           BLKSTR(3,NBLOKS) need not be set.
C
C           The following conditions delimit the structure of A.
C           BLKSTR(1,k),BLKSTR(2,k) .gt. 0  k=1,2,..,NBLOKS
C           BLKSTR(3,k) .ge. 0 k=1,2,..,NBLOKS
C           (there must be at least one column and one row in each block
C           and a non-negative number of columns of overlap)
C
C           BLKSTR(3,k-1)+BLKSTR(3,k) .le.
C                                   BLKSTR(2,k)  k=2,3,..,NBLOKS-1
C           (the total number of columns in overlaps in each block must
C           not exceed the number of columns in that block)
C
C           BLKSTR(2,1) .ge. BLKSTR(1,1)
C           BLKSTR(2,1)+sum(BLKSTR(2,k)-BLKSTR(3,k-1);k=2,j) .ge.
C                          sum(BLKSTR(1,k);k=1,j)  j=2,3,..,NBLOKS-1
C           sum(BLKSTR(2,k)-BLKSTR(3,k);k=1,j) .le.
C                          sum(BLKSTR(1,k);k=1,j)  j=1,2,..,NBLOKS-1
C           (the index of the first column of the overlap between the
C           jth and (j+1)th blocks must be .le. the index of the last
C           row of the jth block, and the index of the last column of
C           overlap must be .ge. the index of the last row of the jth
C           block)
C
C           sum(BLKSTR(1,k);k=1,NBLOKS) .eq. N
C           BLKSTR(2,1)+sum(BLKSTR(2,k)-BLKSTR(3,k-1);k=2,NBLOKS) .eq. N
C           (both the number of rows and of columns of A must equal N)
C
C           Unchanged on exit.
C
C       A - real array of DIMENSION (LENA)
C           Before entry, A must contain the elements of the real almost
C           block diagonal matrix stored block by block and each block
C           stored column by column. The sizes of the blocks and the
C           overlaps are defined by the parameter BLKSTR.
C           If the first element of the kth block is in position (m,n)
C           of the matrix A, then the (i,j)th element of the matrix A,
C           if it is in the kth block, should be stored in location
C               A(nbasek + (j+1-n)*nrowsk + (i+1-m))
C           where
C               nbasek = sum(BLKSTR(1,l)*BLKSTR(2,l);l=1,k-1)
C           is the base address of the kth block, and
C               nrowsk = BLKSTR(1,k)
C           which is the number of rows of the kth block.
C           On succesful exit, A contains the decomposed form of the
C           matrix.
C
C     LENA - INTEGER
C           On entry, LENA must specify the dimension of array A as
C           declared in the (sub)program from which F01LHF is called.
C           LENA .ge. sum(BLKSTR(1,k)*BLKSTR(2,k);k=1,NBLOKS).
C           Unchanged on exit.
C
C     TOL - real
C           Before entry, TOL must specify a relative tolerance to be
C           used to indicate whether or not the matrix is singular. See
C           'Further Comments' on how TOL is used. If TOL is non-
C           positive then TOL is reset to 10*eps, where eps is the
C           relative machine precision (see NAG Library routine X02AJF).
C
C     INDEX - INTEGER
C           On succesful exit with IFAIL = 0, or on exit with
C           IFAIL = -1, INDEX contains the value 0. On exit with
C           IFAIL = 1 INDEX contains the value k, where k is the
C           first position on the diagonal of the matrix A where too
C           small a pivot or a zero pivot was detected.
C
C     PIVOT - INTEGER array of DIMENSION (N)
C           On exit, PIVOT details the interchanges.
C
C     IFAIL - INTEGER
C
C           Before entry, IFAIL must be set to 0, -1 or 1. For users
C           not familiar with this parameter (described in chapter P01),
C           the recommended value is 0.
C           Unless the routine detects an error (see Section 6), IFAIL
C           contains 0 on exit.
C
C
C     Error Indicators:
C
C     Errors detected by the routine:
C
C     If on entry IFAIL = 0 or -1, explanatory error messages are
C     output on the current error message unit (as defined by NAG
C     Library routine X04AAF).
C
C     IFAIL = -1  N .lt. 1 or
C                 NBLOKS .lt. 1 or
C                 N .lt. NBLOKS or
C                 LENA too small or
C                 illegal values detected in BLKSTR.
C
C     IFAIL = 1   Decomposition complete but a small or zero pivot has
C                 been detected.
C
C
C     Further Comments:
C
C     Singularity or near singularity in A is determined by the
C     parameter TOL. If the absolute value of any pivot is less than
C     TOL * the maximum absolute element of A then A is said to be
C     singular. The position on the diagonal of A of the first of any
C     such pivots is indicated by the parameter INDEX.
C     This routine may be followed by  the routine F04LHF, which is
C     designed to solve sets of linear equations AX = B. In general,
C     more accurate solutions can be obtained by routine SUBSTB, but
C     are more expensive in terms of arithmetic operations and require
C     more storage.
C
C     CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C
C       AUXILIARY ROUTINES
C       ------------------
C       F01LHY: TO PERFORM THE COLUMN ELIMINATIONS WITH ROW PIVOTING
C       F01LHX: TO PERFORM THE COLUMN ELIMINATIONS WITH COLUMN PIVOTING
C       F01LHZ: TO PERFORM CHECKS ON THE PARAMETER BLKSTR
C       IDAMAX: TO FIND INDEX OF LARGEST ABSOLUTE ELEMEMT OF A VECTOR
C
C     CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C

F01MAF
      SUBROUTINE F01MAF(N,NZ,A,LA,INI,LINI,INJ,DROPTL,DENSW,W,IK,IW,
     *                  ABORT,INFORM,IFLAG)
C     MARK 11 RELEASE. NAG COPYRIGHT 1983.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     F01MAF PERFORMS AN INCOMPLETE CHOLESKY FACTORIZATION OF
C     A SPARSE SYMMETRIC POSITIVE DEFINITE MATRIX A.
C
C     THE ROUTINE IS BASED UPON THE HARWELL ROUTINE MA31A BY
C     N MUNKSGAARD.
C
C     THE DEVELOPMENT OF MA31A WAS SUPPORTED BY THE DANISH
C     NATURAL RESEARCH COUNCIL, GRANT NUMBER 511-10069
C
C     FOR A DESCRIPTION OF THE PARAMETERS AND USE OF THIS ROUTINE
C     SEE THE NAG LIBRARY MANUAL. PARAMETER ASSOCIATION IS AS BELOW.
C
C     ROUTINE    DOCUMENT
C     N           N
C     NZ         NZ
C     A           A
C     LA         LICN
C     INI        IRN
C     LINI       LIRN
C     INJ        ICN
C     DROPTL     DROPTL
C     DENSW      DENSW
C     INFORM     INFORM
C     W         WKEEP
C     IK        IKEEP
C     IW       IWORK
C     ABORT       ABORT
C     IFLAG       IFAIL
C
C     ARRAYS MA31I, MA31J AND MA31K CORRESPOND TO COMMON BLOCKS
C     OF THE SAME NAMES IN MA31A.
C

F01MCF
      SUBROUTINE F01MCF(N,A,LAL,NROW,L,D,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 14 REVISED. IER-729 (DEC 1989).
C
C     ******************************************************
C
C     NPL ALGORITHMS LIBRARY ROUTINE VBCHFC
C
C     CREATED 04 05 79.  UPDATED 07 09 79.  RELEASE 00/22
C
C     AUTHOR ... MAURICE G. COX.
C     NATIONAL PHYSICAL LABORATORY, TEDDINGTON,
C     MIDDLESEX TW11 OLW, ENGLAND.
C
C     ******************************************************
C
C     F01MCF.  AN ALGORITHM TO DETERMINE THE CHOLESKY
C     FACTORIZATION  A = LDU  (WHERE  L  IS UNIT TRIANGULAR,
C     D  IS DIAGONAL AND  U = L TRANSPOSED) OF A SYMMETRIC
C     POSITIVE DEFINITE MATRIX  A  HAVING A VARIABLE BANDWIDTH.
C
C     INPUT PARAMETERS
C        N        ORDER OF  A
C        A        ELEMENTS WITHIN ENVELOPE OF  A,
C                    IN ROW BY ROW ORDER
C        LAL      SMALLER OF THE DIMENSIONS OF A AND L. AT LEAST
C                    NROW(1) + NROW(2) + ... + NROW(N).
C        NROW     WIDTHS OF ROWS OF  A
C
C     OUTPUT (AND ASSOCIATED) PARAMETERS
C        L        ELEMENTS WITHIN ENVELOPE OF UNIT LOWER
C                    TRIANGULAR FACTOR  L  (INCLUDING UNIT
C                    DIAGONAL ELEMENTS), IN ROW BY ROW ORDER
C        D        DIAGONAL ELEMENTS OF D
C
C     INPUT-OUTPUT PARAMETER
C        IFAIL    FAILURE INDICATOR
C
C                 ENTRY VALUES
C                    0 - TERMINATE IMMEDIATELY IF MATRIX FOUND TO BE
C                        NON-DEFINITE
C                    NON-ZERO - CONTINUE UNLESS ZERO PIVOT FOUND
C
C                  EXIT VALUES
C                    0 - SUCCESSFUL TERMINATION
C                    1 - AT LEAST ONE OF THE FOLLOWING
C                        RESTRICTIONS RELATING TO  N,  LAL
C                        AND THE ARRAY  NROW  IS VIOLATED.
C                           N  .GE. 1,
C                           NROW(1) .GE. 1  AND  .LE. I,
C                              FOR  I = 1, 2, ..., N,
C                           NROW(1) + NROW(2) + ...
C                    2 - A, AS MODIFIED BY ROUNDING ERRORS,
C                        IS NOT POSITIVE DEFINITE. FACTORIZATION
C                        NOT COMPLETED.
C                    3 - A, AS MODIFIED BY ROUNDING ERRORS,
C                        IS NOT POSITIVE DEFINITE. FACTORIZATION
C                        COMPLETED BUT MAY BE INACCURATE.
C

F01QGF
      SUBROUTINE F01QGF(M,N,A,LDA,ZETA,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C  1. Purpose
C     =======
C
C  F01QGF  reduces  the  m by n ( m.le.n )  upper trapezoidal  matrix  A
C  to  upper triangular  form by  means  of  orthogonal transformations.
C
C  2. Description
C     ===========
C
C  The  m  by  n  ( m .le. n )  upper  trapezoidal  matrix  A  given  by
C
C     A = ( U  X ),
C
C  where  U  is an  m by m  upper triangular  matrix, is  factorized  as
C
C     A = ( R  0 )*P',
C
C  where  P  is an  n by n  orthogonal matrix and  R  is an m by m upper
C  triangular matrix.
C
C  The  factorization  is  obtained  by  Householder's  method. The  kth
C  transformation  matrix, P( k ), which is used to introduce zeros into
C  the ( m - k + 1 )th row of A is given in the form
C
C     P( k ) = ( I     0   ),
C              ( 0  T( k ) )
C
C  where
C
C     T( k ) = I - u( k )*u( k )',   u( k ) = ( zeta   ),
C                                             (   0    )
C                                             ( z( k ) )
C
C  zeta  is  a  scalar  and  z( k )  is  an  ( n - m )  element  vector.
C  zeta  and  z( k ) are chosen to annhilate the elements of the kth row
C  of X.
C
C  The vector  u( k ) is returned in the kth element of  ZETA and in the
C  kth row of  A, such that  zeta  is in  ZETA( k )  and the elements of
C  z( k )  are in  a( k, m + 1 ), ..., a( k, n ). The elements of  R are
C  returned in the upper triangular part of A.
C
C  P is given by
C
C     P = ( P( 1 )*P( 2 )*...*P( m ) )'.
C
C  3. Parameters
C     ==========
C
C  M      - INTEGER.
C
C           On entry, M  specifies the number of rows of A. M must be at
C           least 0. When  M = 0  then an immediate return is  effected.
C
C           Unchanged on exit.
C
C  N      - INTEGER.
C
C           On entry, N  specifies the number of columns of A. N must be
C           at  least  M.
C
C           Unchanged on exit.
C
C  A      - REAL array of DIMENSION ( LDA, n ).
C
C           Before entry, the leading  M by N  upper trapezoidal part of
C           the  array  A  must  contain  the  matrix  to be factorized.
C
C           On exit, the  M by M upper triangular part of A will contain
C           the  upper  triangular  matrix  R  and  the  remaining  M by
C           ( N - M )  upper trapezoidal part of  A will contain details
C           of the factorization as described above.
C
C  LDA    - INTEGER.
C
C           On  entry, LDA  must  specify  the  leading dimension of the
C           array  A  as declared in the calling (sub) program. LDA must
C           be at least M.
C
C           Unchanged on exit.
C
C  ZETA   - REAL array of DIMENSION at least ( m ).
C
C           On exit,  ZETA( k )  contains the scalar  zeta( k )  for the
C           ( m - k + 1 )th  transformation.    If    P( k ) = I    then
C           ZETA( k ) = 0.0,  otherwise  ZETA( k ) contains zeta( k ) as
C           described  above  and  zeta( k )  is  always  in  the  range
C           ( 1.0, sqrt( 2.0 ) ).
C
C  IFAIL  - INTEGER.
C
C           Before entry,  IFAIL  must contain one of the values -1 or 0
C           or 1 to specify noisy soft failure or noisy hard failure  or
C           silent soft failure. ( See Chapter P01 for further details.)
C
C           On  successful exit  IFAIL  will be  zero,  otherwise  IFAIL
C           will  be set to   -1  indicating that an input parameter has
C           been  incorrectly  set. See  the  next  section  for further
C           details.
C
C  4. Diagnostic Information
C     ======================
C
C  IFAIL = -1
C
C     One or more of the following conditions holds:
C
C        M   .lt. 0
C        N   .lt. M
C        LDA .lt. M
C
C  If  on  entry,  IFAIL  was either  -1 or 0  then  further  diagnostic
C  information  will  be  output  on  the  error message  channel. ( See
C  routine  X04AAF. )
C
C
C  Nag Fortran 77 Auxiliary linear algebra routine.
C
C  -- Written on 19-November-1987.
C     Sven Hammarling, Nag Central Office.
C

F01QJF
      SUBROUTINE F01QJF(M,N,A,LDA,ZETA,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C  1. Purpose
C     =======
C
C  F01QJF  finds the  RQ factorization  of the  real  m by n,  m .le. n,
C  matrix  A, so that  A is reduced to upper triangular form by means of
C  orthogonal transformations from the right.
C
C  2. Description
C     ===========
C
C  The m by n matrix A is factorized as
C
C     A = ( R  0 )*P'   when   m.lt.n,
C
C     A = R*P'          when   m = n,
C
C  where  P  is an  n by n orthogonal matrix and  R  is an  m by m upper
C  triangular matrix.
C
C  P  is  given  as a  sequence  of  Householder transformation matrices
C
C     P = P( m )*...*P( 2 )*P( 1 ),
C
C  the  ( m - k + 1 )th  transformation matrix,  P( k ),  being used  to
C  introduce zeros into the  kth row of A.  P( k ) has the form
C
C     P( k ) = I - u( k )*u( k )',
C
C  where
C
C     u( k ) = (    w( k ) ),
C              ( zeta( k ) )
C              (    0      )
C              (    z( k ) )
C
C  zeta( k )  is a scalar,  w( k ) is an  ( k - 1 )  element  vector and
C  z( k ) is an ( n - m ) element vector.  u( k ) is chosen to annhilate
C  the elements in the kth row of A.
C
C  The vector  u( k ) is returned in the kth element of  ZETA and in the
C  kth row of  A, such that  zeta( k ) is in  ZETA( k ), the elements of
C  w( k )  are in  a( k, 1 ), ..., a( k, k - 1 )  and  the  elements  of
C  z( k ) are in  a( k, m + 1 ), ..., a( k, n ).  The elements of  R are
C  returned in the  upper triangular part of  A.
C
C  3. Parameters
C     ==========
C
C  M      - INTEGER.
C
C           On entry, M must specify the number of rows of  A. M must be
C           at  least  zero. When  M = 0  then  an  immediate return  is
C           effected.
C
C           Unchanged on exit.
C
C  N      - INTEGER.
C
C           On entry, N must specify the number of columns of  A. N must
C           be at least m.
C
C           Unchanged on exit.
C
C  A      - REAL             array of DIMENSION ( LDA, n ).
C
C           Before entry, the leading  M by N  part of the array  A must
C           contain the matrix to be factorized.
C
C           On exit, the  M by M upper triangular part of A will contain
C           the  upper triangular  matrix  R,  and the  M by M  strictly
C           lower  triangular  part  of   A  and  the   M  by  ( N - M )
C           rectangular part of  A  to the right of the upper triangular
C           part will contain details of the  factorization as described
C           above.
C
C  LDA    - INTEGER.
C
C           On entry, LDA  must  specify  the  leading dimension of  the
C           array  A  as declared in the calling (sub) program. LDA must
C           be at least  m.
C
C           Unchanged on exit.
C
C  ZETA   - REAL             array of DIMENSION at least ( m ).
C
C           On exit,  ZETA( k )  contains the scalar  zeta( k )  for the
C           ( m - k + 1 )th   transformation.     If   P( k ) = I   then
C           ZETA( k ) = 0.0,   otherwise  ZETA( k )  contains  zeta( k )
C           as  described above  and  zeta( k )  is always in the  range
C           ( 1.0, sqrt( 2.0 ) ).
C
C  IFAIL  - INTEGER.
C
C           Before entry,  IFAIL  must contain one of the values -1 or 0
C           or 1 to specify noisy soft failure or noisy hard failure  or
C           silent soft failure. ( See Chapter P01 for further details.)
C
C           On successful  exit  IFAIL  will be  zero,  otherwise  IFAIL
C           will  be set to  -1  indicating that an  input parameter has
C           been  incorrectly  set. See  the  next section  for  further
C           details.
C
C  4. Diagnostic Information
C     ======================
C
C  IFAIL = -1
C
C     One or more of the following conditions holds:
C
C        M   .lt. 0
C        N   .lt. M
C        LDA .lt. M
C
C  If  on  entry,  IFAIL  was  either  -1 or 0  then  further diagnostic
C  information  will  be  output  on  the  error message  channel. ( See
C  routine  X04AAF. )
C
C  5. Further information
C     ===================
C
C  The first  k rows  of the  orthogonal matrix  P'  can be  obtained by
C  by calling NAG Library routine F01QKF, which overwrites the k rows of
C  P'  on the first  k rows of the array A.  P' is obtained by the call:
C
C     IFAIL = 0
C     CALL F01QKF( 'Separate', M, N, K, A, LDA, ZETA, WORK, IFAIL )
C
C  WORK must be a  max( m - 1, k - m, 1 ) element array.  If K is larger
C  than  M,  then  A  must have been declared to have at least  K  rows.
C
C  Operations involving the matrix  R  can readily  be performed by  the
C  Level 2 BLAS  routines  DTRSV and DTRMV , (see Chapter F06), but note
C  that no test for  near singularity of  R  is incorporated in  DTRSV .
C  If  R  is singular,  or nearly singular then the  NAG Library routine
C  F02WUF  can be  used to  determine  the  singular value decomposition
C  of  R.
C
C
C  Nag Fortran 77 Auxiliary linear algebra routine.
C
C  -- Written on 17-November-1987.
C     Sven Hammarling, Nag Central Office.
C

F01QKF
      SUBROUTINE F01QKF(WHERET,M,N,NROWP,A,LDA,ZETA,WORK,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C  1. Purpose
C     =======
C
C  F01QKF  returns the first  nrowp rows of the n by n orthogonal matrix
C  P',  where  P  is given as the product of  Householder transformation
C  matrices.
C
C  This  routine  is  intended  for  use  following  NAG Fortran Library
C  routine  F01QJF.
C
C  2. Description
C     ===========
C
C  P is assumed to be given by
C
C     P = P( m )*P( m - 1 )*...*P( 1 ),
C
C  where
C
C     P( k ) = I - u( k )*u( k )',
C
C     u( k ) = (    w( k ) ),
C              ( zeta( k ) )
C              (    0      )
C              (    z( k ) )
C
C  zeta( k )  is a scalar,  w( k )  is a  ( k - 1 )  element vector  and
C  z( k )  is an  ( n - m ) element vector.
C
C  w( k )  must be supplied in the kth row of A in  elements  a( k, 1 ),
C  ..., a( k, k - 1 ).   z( k ) must be  supplied  in  the  kth  row  of
C  A  in elements  a( k, m + 1 ), ..., a( k, n )  and  zeta( k ) must be
C  supplied  either in  a( k, k )  or in  ZETA( k ),  depending upon the
C  parameter WHERET.
C
C  3. Parameters
C     ==========
C
C  WHERET - CHARACTER*1.
C
C           On entry,  WHERET  specifies where the elements of  zeta are
C           to be found as follows.
C
C           WHERET = 'I' or 'i'   ( In A )
C
C              The elements of zeta are in A.
C
C           WHERET = 'S' or 's'   ( Separate )
C
C              The  elements of  zeta  are  separate  from  A, in  ZETA.
C
C           Unchanged on exit.
C
C  M      - INTEGER.
C
C           On entry, M  must specify the number of rows of A. M must be
C           at least zero.
C
C           Unchanged on exit.
C
C  N      - INTEGER.
C
C           On entry, N  must specify the number of columns of A. N must
C           be at least m.
C
C           Unchanged on exit.
C
C  NROWP  - INTEGER.
C
C           On entry,  NROWP  must  specify  the required number of rows
C           of P.  NROWP must be at least zero and not be larger than n.
C           When   NROWP = 0  then  an  immediate  return  is  effected.
C
C           Unchanged on exit.
C
C  A      - REAL             array of DIMENSION ( LDA, n ).
C
C           Before entry, the leading  M by M  strictly lower triangular
C           part of the array A, and the M by ( N - M ) rectangular part
C           of A with top left hand corner at element A( 1, M + 1 ) must
C           contain  details  of  the  matrix   P.   In  addition,  when
C           WHERET = 'I' or 'i'  then  the  diagonal elements of  A must
C           contain the elements of zeta.
C
C           On exit, the first NROWP rows of the array A are overwritten
C           by the first  NROWP  rows  of the  n by n  orthogonal matrix
C           P'.
C
C           Unchanged on exit.
C
C  LDA    - INTEGER.
C
C           On  entry, LDA  must specify  the leading dimension  of  the
C           array  A  as declared in the calling (sub) program. LDA must
C           be at least max(m,nrowp).
C
C           Unchanged on exit.
C
C  ZETA   - REAL             array of  DIMENSION  at least  ( m ),  when
C           WHERET = 'S' or 's'.
C
C           Before entry with  WHERET = 'S' or 's', the array  ZETA must
C           contain  the  elements  of  zeta.  If  ZETA( k ) = 0.0  then
C           P( k )  is assumed to be I, otherwise  ZETA( k )  is assumed
C           to contain zeta( k ).
C
C           When  WHERET = 'I' or 'i', the array ZETA is not referenced.
C
C           Unchanged on exit.
C
C  WORK   - REAL             array  of  DIMENSION  at  least  ( lwork ),
C           where  lwork = max( m - 1, nrowp - m, 1 ).
C
C           Used as internal workspace.
C
C  IFAIL  - INTEGER.
C
C           Before entry,  IFAIL  must contain one of the values -1 or 0
C           or 1 to specify noisy soft failure or noisy hard failure  or
C           silent soft failure. ( See Chapter P01 for further details.)
C
C           On  successful exit  IFAIL  will be  zero,  otherwise  IFAIL
C           will  be set to   -1  indicating that an input parameter has
C           been  incorrectly  set. See  the  next  section  for further
C           details.
C
C  4. Diagnostic Information
C     ======================
C
C  IFAIL = -1
C
C     One or more of the following conditions holds:
C
C        WHERET .ne. 'I' or 'i' or 'S' or 's'
C        M      .lt. 0
C        N      .lt. M
C        NROWP  .lt. 0  .or.  NROWP .gt. N
C        LDA    .lt. M
C
C  If  on  entry,  IFAIL  was either  -1 or 0  then  further  diagnostic
C  information  will  be  output  on  the  error message  channel. ( See
C  routine  X04AAF. )
C
C
C  Nag Fortran 77 Auxiliary linear algebra routine.
C
C  -- Written on 3-December-1987.
C     Sven Hammarling and Mick Pont, Nag Central Office.
C

F01RGF
      SUBROUTINE F01RGF(M,N,A,LDA,THETA,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C  1. Purpose
C     =======
C
C  F01RGF  reduces  the  m by n ( m.le.n )  upper trapezoidal  matrix  A
C  to  upper  triangular  form  by  means  of  unitary  transformations.
C
C  2. Description
C     ===========
C
C  The  m  by  n  ( m .le. n )  upper  trapezoidal  matrix  A  given  by
C
C     A = ( U  X ),
C
C  where  U  is an  m by m  upper triangular  matrix, is  factorized  as
C
C     A = ( R  0 )*conjg( P' ),
C
C  where  P  is an  n by n  unitary  matrix and  R  is an  m by m  upper
C  triangular matrix with real diagonal elements.
C
C  P  is  given  as a  sequence  of  Householder transformation matrices
C
C     P = P( m )*...*P( 2 )*P( 1 ),
C
C  the  ( m - k + 1 )th  transformation matrix,  P( k ),  being  used to
C  introduce zeros into the kth row of A.  P( k ) has the form
C
C     P( k ) = ( I     0   ),
C              ( 0  T( k ) )
C
C  where
C
C     T( k ) = I - gamma( k )*u( k )*conjg( u( k )' ),
C
C     u( k ) = ( zeta( k ) ),
C              (    0      )
C              (    z( k ) )
C
C  gamma( k ) is a scalar for which  real( gamma( k ) ) = 1.0, zeta( k )
C  is  a  real  scalar  and  z( k )  is  an  ( n - m )  element  vector.
C  gamma( k ), zeta( k ) and z( k ) are chosen to annhilate the elements
C  of the kth row  of  X  and to make the diagonal elements of  R  real.
C
C  The scalar  gamma( k )  and the  vector  u( k )  are returned  in the
C  kth element of THETA  and in the  kth row of A, such that theta( k ),
C  given by
C
C     theta( k ) = ( zeta( k ), aimag( gamma( k ) ) ),
C
C  is in  THETA( k )  and the elements of  z( k ) are in  a( k, m + 1 ),
C  ..., a( k, n ).   The  elements  of  R  are  returned  in  the  upper
C  triangular part of  A.
C
C  3. Parameters
C     ==========
C
C  M      - INTEGER.
C
C           On entry, M  specifies the number of rows of A. M must be at
C           least 0. When  M = 0  then an immediate return is  effected.
C
C           Unchanged on exit.
C
C  N      - INTEGER.
C
C           On entry, N  specifies the number of columns of A. N must be
C           at least M.
C
C           Unchanged on exit.
C
C  A      - REAL array of DIMENSION ( LDA, n ).
C
C           Before entry, the leading  M by N  upper trapezoidal part of
C           the  array  A  must  contain  the  matrix  to be factorized.
C
C           On exit, the  M by M upper triangular part of A will contain
C           the upper triangular matrix  R, with the  imaginary parts of
C           the  diagonal elements set to  zero, and the  M by ( N - M )
C           upper trapezoidal  part of  A  will  contain details  of the
C           factorization as described above.
C
C  LDA    - INTEGER.
C
C           On  entry, LDA  must  specify  the  leading dimension of the
C           array  A  as declared in the calling (sub) program. LDA must
C           be at least M.
C
C           Unchanged on exit.
C
C  THETA  - COMPLEX array of DIMENSION at least ( m ).
C
C           On exit,  THETA( k ) contains the scalar  theta( k ) for the
C           ( m - k + 1 )th   transformation.   If    T( k ) = I    then
C           THETA( k ) = 0.0,  if
C
C              T( k ) = ( alpha  0 ),   real( alpha ) .lt. 0.0,
C                       (   0    I )
C
C           then   THETA( k ) = alpha,   otherwise  THETA( k )  contains
C           theta( k )  as  described above  and  real( theta( k ) )  is
C           always in the range  ( 1.0, sqrt( 2.0 ) ).
C
C  IFAIL - INTEGER.
C
C           Before entry,  IFAIL  must contain one of the values -1 or 0
C           or 1 to specify noisy soft failure or noisy hard failure  or
C           silent soft failure. ( See Chapter P01 for further details.)
C
C           On  successful exit  IFAIL  will be  zero,  otherwise  IFAIL
C           will  be set to   -1  indicating that an input parameter has
C           been  incorrectly  set. See  the  next  section  for further
C           details.
C
C  4. Diagnostic Information
C     ======================
C
C  IFAIL = -1
C
C     One or more of the following conditions holds:
C
C        M   .lt. 0
C        N   .lt. M
C        LDA .lt. M
C
C  If  on  entry,  IFAIL  was either  -1 or 0  then  further  diagnostic
C  information  will  be  output  on  the  error message  channel. ( See
C  routine  X04AAF. )
C
C
C  Nag Fortran 77 Auxiliary linear algebra routine.
C
C  -- Written on 19-November-1987.
C     Sven Hammarling, Nag Central Office.
C

F01RJF
      SUBROUTINE F01RJF(M,N,A,LDA,THETA,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C  1. Purpose
C     =======
C
C  F01RJF  finds the  RQ factorization of the complex m by n,  m .le. n,
C  matrix  A, so that  A is reduced to upper triangular form by means of
C  unitary transformations from the right.
C
C  2. Description
C     ===========
C
C  The m by n matrix A is factorized as
C
C     A = ( R  0 )*conjg( P' )   when   m.lt.n,
C
C     A = R*conjg( P' )          when   m = n,
C
C  where  P  is an  n by n  unitary matrix  and  R  is an  m by m  upper
C  triangular matrix with real diagonal elements.
C
C  P  is  given  as a  sequence  of  Householder transformation matrices
C
C     P = P( m )*...*P( 2 )*P( 1 ),
C
C  the  ( m - k + 1 )th  transformation matrix,  P( k ),  being used  to
C  introduce zeros into the  kth row of A.  P( k ) has the form
C
C     P( k ) = I - gamma( k )*u( k )*conjg( u( k )' ),
C
C  where
C
C     u( k ) = (    w( k ) ),
C              ( zeta( k ) )
C              (    0      )
C              (    z( k ) )
C
C  gamma( k ) is a scalar for which  real( gamma( k ) ) = 1.0, zeta( k )
C  is a real scalar,  w( k ) is an ( k - 1 ) element vector  and  z( k )
C  is an ( n - m ) element vector.  gamma( k ) and u( k )  are chosen to
C  annhilate the elements in the  kth row of A  and to make the diagonal
C  elements real.
C
C  The scalar  gamma( k ) and the vector  u( k ) are returned in the kth
C  element of  THETA  and in the  kth row  of  A, such that  theta( k ),
C  given by
C
C     theta( k ) = ( zeta( k ), aimag( gamma( k ) ) ),
C
C  is in  THETA( k ),  the elements  of  w( k )  are in  a( k, 1 ), ...,
C  a( k, k - 1 )  and the elements of z( k ) are in  a( k, m + 1 ), ...,
C  a( k, n ).  The elements of  R  are returned in the  upper triangular
C  part of  A.
C
C  3. Parameters
C     ==========
C
C  M      - INTEGER.
C
C           On entry, M must specify the number of rows of  A. M must be
C           at  least  zero. When  M = 0  then  an  immediate return  is
C           effected.
C
C           Unchanged on exit.
C
C  N      - INTEGER.
C
C           On entry, N must specify the number of columns of  A. N must
C           be at least m.
C
C           Unchanged on exit.
C
C  A      - COMPLEX array of DIMENSION ( LDA, n ).
C
C           Before entry, the leading  M by N  part of the array  A must
C           contain the matrix to be factorized.
C
C           On exit, the  M by M upper triangular part of A will contain
C           the upper triangular matrix  R, with the  imaginary parts of
C           the diagonal elements set to zero, and the  M by M  strictly
C           lower  triangular  part  of   A  and  the   M  by  ( N - M )
C           rectangular part of  A  to the right of the upper triangular
C           part will contain details of the  factorization as described
C           above.
C
C  LDA    - INTEGER.
C
C           On entry, LDA  must  specify  the  leading dimension of  the
C           array  A  as declared in the calling (sub) program. LDA must
C           be at least  m.
C
C           Unchanged on exit.
C
C  THETA  - COMPLEX array of DIMENSION at least ( m ).
C
C           On exit, THETA( k )  contains the scalar  theta( k ) for the
C           ( m - k + 1 )th   transformation.     If   P( k ) = I   then
C           THETA( k ) = 0.0,  if
C
C              P( k ) = ( I    0    0 ),   real( alpha ) .lt. 0.0,
C                       ( 0  alpha  0 )
C                       ( 0    0    I )
C
C           then   THETA( k ) = alpha,   otherwise  THETA( k )  contains
C           theta( k )  as  described above  and  real( theta( k ) )  is
C           always in the range ( 1.0, sqrt( 2.0 ) ).
C
C  IFAIL  - INTEGER.
C
C           Before entry,  IFAIL  must contain one of the values -1 or 0
C           or 1 to specify noisy soft failure or noisy hard failure  or
C           silent soft failure. ( See Chapter P01 for further details.)
C
C           On successful  exit  IFAIL  will be  zero,  otherwise  IFAIL
C           will  be set to  -1  indicating that an  input parameter has
C           been  incorrectly  set. See  the  next section  for  further
C           details.
C
C  4. Diagnostic Information
C     ======================
C
C  IFAIL = -1
C
C     One or more of the following conditions holds:
C
C        M   .lt. 0
C        N   .lt. M
C        LDA .lt. M
C
C  If  on  entry,  IFAIL  was  either  -1 or 0  then  further diagnostic
C  information  will  be  output  on  the  error message  channel. ( See
C  routine  X04AAF. )
C
C  5. Further information
C     ===================
C
C  The first  k rows of the unitary matrix  conjg( P' )  can be obtained
C  by calling NAG Library routine  F01RKF,  which overwrites the  k rows
C  of conjg( P' )  on the first  k rows of the array  A.  conjg( P' ) is
C  obtained by the call:
C
C     IFAIL = 0
C     CALL F01RKF( 'Separate', M, N, K, A, LDA, THETA, WORK, IFAIL )
C
C  WORK must be a  max( m - 1, k - m, 1 ) element array.  If K is larger
C  than  M,  then  A  must have been declared to have at least  K  rows.
C
C  Operations involving the matrix  R  can readily  be performed by  the
C  Level 2 BLAS  routines  ZTRSV and ZTRMV , (see Chapter F06), but note
C  that no test for  near singularity of  R  is incorporated in  ZTRSV .
C  If  R  is singular,  or nearly singular then the  NAG Library routine
C  F02XUF  can be  used to  determine  the  singular value decomposition
C  of  R.
C
C
C  Nag Fortran 77 Auxiliary linear algebra routine.
C
C  -- Written on 17-November-1987.
C     Sven Hammarling, Nag Central Office.
C

F01RKF
      SUBROUTINE F01RKF(WHERET,M,N,NROWP,A,LDA,THETA,WORK,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C  1. Purpose
C     =======
C
C  F01RKF  returns the first  nrowp  rows of the  n by n  unitary matrix
C  conjg( P' ),   where  P  is  given  as  the  product  of  Householder
C  transformation  matrices.
C
C  This  routine  is  intended  for  use  following  NAG Fortran Library
C  routine  F01RJF.
C
C  2. Description
C     ===========
C
C  P is assumed to be given by
C
C     P = P( m )*P( m - 1 )*...*P( 1 ),
C
C  where
C
C     P( k ) = I - gamma( k )*u( k )*conjg( u( k )' ),
C
C     u( k ) = (    w( k ) ),
C              ( zeta( k ) )
C              (    0      )
C              (    z( k ) )
C
C  gamma( k ) is a scalar for which  real( gamma( k ) ) = 1.0, zeta( k )
C  is a real scalar,  w( k )  is a ( k - 1 ) element  vector  and z( k )
C  is an ( n - m ) element vector.
C
C  w( k )  must be supplied in the kth row of A in  elements  a( k, 1 ),
C  ..., a( k, k - 1 ).   z( k ) must be  supplied  in  the  kth  row  of
C  A in  elements a( k, m + 1 ), ..., a( k, n ) and theta( k ), given by
C
C     theta( k ) = ( zeta( k ), aimag( gamma( k ) ) ),
C
C  must be supplied either in a( k, k ) or in THETA( k ), depending upon
C  the parameter WHERET.
C
C  3. Parameters
C     ==========
C
C  WHERET - CHARACTER*1.
C
C           On entry, WHERET  specifies where the elements of  theta are
C           to be found as follows.
C
C           WHERET = 'I' or 'i'   ( In A )
C
C              The elements of theta are in A.
C
C           WHERET = 'S' or 's'   ( Separate )
C
C              The elements of theta are separate from A, in THETA.
C
C           Unchanged on exit.
C
C  M      - INTEGER.
C
C           On entry, M  must specify the number of rows of A. M must be
C           at least zero.
C
C           Unchanged on exit.
C
C  N      - INTEGER.
C
C           On entry, N  must specify the number of columns of A. N must
C           be at least m.
C
C           Unchanged on exit.
C
C  NROWP  - INTEGER.
C
C           On entry,  NROWP  must  specify  the required number of rows
C           of P.  NROWP must be at least zero and not be larger than n.
C           When   NROWP = 0  then  an  immediate  return  is  effected.
C
C           Unchanged on exit.
C
C  A      - COMPLEX array of DIMENSION ( LDA, n ).
C
C           Before entry, the leading  M by M  strictly lower triangular
C           part of the array A, and the M by ( N - M ) rectangular part
C           of A with top left hand corner at element A( 1, M + 1 ) must
C           contain  details  of  the  matrix   P.   In  addition,  when
C           WHERET = 'I' or 'i'  then  the  diagonal elements of  A must
C           contain the elements of theta.
C
C           On exit, the first NROWP rows of the array A are overwritten
C           by  the  first  NROWP  rows  of the  n by n  unitary  matrix
C           conjg( P' ).
C
C           Unchanged on exit.
C
C  LDA    - INTEGER.
C
C           On  entry, LDA  must specify  the leading dimension  of  the
C           array  A  as declared in the calling (sub) program. LDA must
C           be at least max(m,nrowp).
C
C           Unchanged on exit.
C
C  THETA  - COMPLEX array of DIMENSION at least ( m ), when WHERET = 'S'
C           or 's'.
C
C           Before entry with  WHERET = 'S' or 's', the array THETA must
C           contain  the elements of  theta.  If  THETA( k ) = 0.0  then
C           P( k )  is assumed  to be  I,  if  THETA( k ) = alpha,  with
C           real( alpha ) .lt. 0.0  then  P( k )  is assumed  to  be  of
C           the form
C
C              P( k ) = ( I    0    0 ),
C                       ( 0  alpha  0 )
C                       ( 0    0    I )
C
C           otherwise  THETA( k ) is assumed to contain theta( k ) given
C           by  theta( k ) = ( zeta( k ), aimag( gamma( k ) ) ).
C
C           When WHERET = 'I' or 'i', the array THETA is not referenced.
C
C           Unchanged on exit.
C
C  WORK   - COMPLEX  array  of  DIMENSION  at  least  ( lwork ),   where
C           lwork = max( m - 1, nrowp - m, 1 ).
C
C           Used as internal workspace.
C
C  IFAIL  - INTEGER.
C
C           Before entry,  IFAIL  must contain one of the values -1 or 0
C           or 1 to specify noisy soft failure or noisy hard failure  or
C           silent soft failure. ( See Chapter P01 for further details.)
C
C           On  successful exit  IFAIL  will be  zero,  otherwise  IFAIL
C           will  be set to   -1  indicating that an input parameter has
C           been  incorrectly  set. See  the  next  section  for further
C           details.
C
C  4. Diagnostic Information
C     ======================
C
C  IFAIL = -1
C
C     One or more of the following conditions holds:
C
C        WHERET .ne. 'I' or 'i' or 'S' or 's'
C        M      .lt. 0
C        N      .lt. M
C        NROWP  .lt. 0  .or.  NROWP .gt. N
C        LDA    .lt. M
C
C  If  on  entry,  IFAIL  was either  -1 or 0  then  further  diagnostic
C  information  will  be  output  on  the  error message  channel. ( See
C  routine  X04AAF. )
C
C
C  Nag Fortran 77 Auxiliary linear algebra routine.
C
C  -- Written on 3-December-1987.
C     Sven Hammarling and Mick Pont, Nag Central Office.
C

F01ZAF
      SUBROUTINE F01ZAF(JOB,UPLO,DIAG,N,A,LDA,B,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     Copies a real triangular matrix from packed vector storage to
C     a two-dimensional array, or vice-versa.
C
C     Parameters:
C
C     JOB - CHARACTER*1.
C       JOB = 'P' or 'p' : 'Pack' - the contents of matrix A are to be
C       packed into vector B.
C       JOB = 'U' or 'u' : 'Unpack' - the contents of vector B are to
C       be unpacked into matrix A.
C
C     UPLO - CHARACTER*1.
C       UPLO = 'U' or 'u' : 'Upper' - the matrix is upper triangular,
C       and stored by column in the packed vector.
C       UPLO = 'L' or 'l' : 'Upper' - the matrix is lower triangular,
C       and stored by column in the packed vector.
C
C     DIAG - CHARACTER*1.
C       DIAG = 'N' or 'n' : 'Non-unit' - the triangular matrix has
C       non-unit diagonal elements, which are packed or unpacked with
C       the rest of the matrix.
C       DIAG = 'U' or 'u' : 'Unit' - the triangular matrix is assumed
C       to have unit diagonal elements which are not stored, in the
C       format being copied from, but are inserted into the format
C       being copied to.
C       DIAG = ' ' : 'Blank' - the matrix is assumed to be strictly
C       upper or strictly lower triangular. No reference is made
C       either to the diagonal elements of matrix A or to the
C       corresponding elements of vector B, although space must be
C       allocated for them in the packed vector.
C
C     N - INTEGER.
C       The order of the matrix. N > 0.
C
C     A(LDA, N) - real array.
C       If JOB = 'P' or 'p', then on entry A must contain the matrix
C       stored in the upper triangle if UPLO = 'U' or 'u', and stored
C       in the lower triangle if UPLO = 'L' or 'l'. The opposite
C       triangle of A may be undefined.
C       If JOB = 'U' or 'u', then on exit A will contain the matrix
C       stored in the upper triangle if UPLO = 'U' or 'u', and stored
C       in the lower triangle if UPLO = 'L' or 'l'. The opposite
C       triangle is left untouched.
C
C     LDA - INTEGER.
C       The leading dimension of array A as declared in the calling
C       (sub)program.
C
C     B((N*(N+1))/2) - real array.
C       If JOB = 'U' or 'u', then on entry B must contain the triangular
C       matrix packed by column.
C       If JOB = 'P' or 'p', then on exit B will contain the triangular
C       matrix packed by column.
C
C     IFAIL - INTEGER.
C       Error flag. On exit,
C         IFAIL = 1 if JOB <> 'P', 'p', 'U' or 'u'.
C         IFAIL = 2 if UPLO <> 'U', 'u', 'L' or 'l'.
C         IFAIL = 3 if DIAG <> 'N', 'n', 'U', 'u', 'B' or 'b'.
C         IFAIL = 4 if N < 1.
C         IFAIL = 5 if LDA < N.
C

F01ZBF
      SUBROUTINE F01ZBF(JOB,UPLO,DIAG,N,A,LDA,B,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     Copies a complex triangular matrix from packed vector storage to
C     a two-dimensional array, or vice-versa.
C
C     Parameters:
C
C     JOB - CHARACTER*1.
C       JOB = 'P' or 'p' : 'Pack' - the contents of matrix A are to be
C       packed into vector B.
C       JOB = 'U' or 'u' : 'Unpack' - the contents of vector B are to
C       be unpacked into matrix A.
C
C     UPLO - CHARACTER*1.
C       UPLO = 'U' or 'u' : 'Upper' - the matrix is upper triangular,
C       and stored by column in the packed vector.
C       UPLO = 'L' or 'l' : 'Upper' - the matrix is lower triangular,
C       and stored by column in the packed vector.
C
C     DIAG - CHARACTER*1.
C       DIAG = 'N' or 'n' : 'Non-unit' - the triangular matrix has
C       non-unit diagonal elements, which are packed or unpacked with
C       the rest of the matrix.
C       DIAG = 'U' or 'u' : 'Unit' - the triangular matrix is assumed
C       to have unit diagonal elements which are not stored, in the
C       format being copied from, but are inserted into the format
C       being copied to.
C       DIAG = ' ' : 'Blank' - the matrix is assumed to be strictly
C       upper or strictly lower triangular. No reference is made
C       either to the diagonal elements of matrix A or to the
C       corresponding elements of vector B, although space must be
C       allocated for them in the packed vector.
C
C     N - INTEGER.
C       The order of the matrix. N > 0.
C
C     A(LDA, N) - complex array.
C       If JOB = 'P' or 'p', then on entry A must contain the matrix
C       stored in the upper triangle if UPLO = 'U' or 'u', and stored
C       in the lower triangle if UPLO = 'L' or 'l'. The opposite
C       triangle of A may be undefined.
C       If JOB = 'U' or 'u', then on exit A will contain the matrix
C       stored in the upper triangle if UPLO = 'U' or 'u', and stored
C       in the lower triangle if UPLO = 'L' or 'l'. The opposite
C       triangle is left untouched.
C
C     LDA - INTEGER.
C       The leading dimension of array A as declared in the calling
C       (sub)program.
C
C     B((N*(N+1))/2) - complex array.
C       If JOB = 'U' or 'u', then on entry B must contain the triangular
C       matrix packed by column.
C       If JOB = 'P' or 'p', then on exit B will contain the triangular
C       matrix packed by column.
C
C     IFAIL - INTEGER.
C       Error flag. On exit,
C         IFAIL = 1 if JOB <> 'P', 'p', 'U' or 'u'.
C         IFAIL = 2 if UPLO <> 'U', 'u', 'L' or 'l'.
C         IFAIL = 3 if DIAG <> 'N', 'n', 'U', 'u', 'B' or 'b'.
C         IFAIL = 4 if N < 1.
C         IFAIL = 5 if LDA < N.
C

F01ZCF
      SUBROUTINE F01ZCF(JOB,M,N,KL,KU,A,LDA,B,LDB,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     Converts a real banded matrix from packed storage to unpacked,
C     or vice-versa.
C
C     Parameters:
C
C     JOB - CHARACTER*1.
C       JOB = 'P' or 'p' : 'Pack' - the contents of matrix A are to be
C       packed into matrix B.
C       JOB = 'U' or 'u' : 'Unpack' - the contents of matrix B are to
C       be unpacked into matrix A.
C
C     M - INTEGER.
C       On entry, M specifies the number of rows of the matrix A.
C
C     N - INTEGER.
C       On entry, N specifies the number of columns of the matrix A.
C
C     KL - INTEGER.
C       On entry, KL specifies the number of sub-diagonals of the
C       matrix A. KL >= 0.
C
C     KU - INTEGER.
C       On entry, KU specifies the number of super-diagonals of the
C       matrix A. KU >= 0.
C
C     A(LDA, N) - real array.
C       If JOB = 'P' or 'p', then on entry the leading M by N part
C       of array A must contain the band matrix stored in unpacked
C       form. Elements of A that lie above the KUth super-diagonal
C       and below the KLth sub-diagonal are not referenced and need
C       not be defined.
C       If JOB = 'U' or 'u', then on entry the array A may be
C       undefined. On exit, A contains the band matrix stored in
C       unpacked form. Elements of the leading M by N part of A that
C       lie above the KUth super-diagonal or below the KLth
C       sub-diagonal are assigned the value zero.
C
C     LDA - INTEGER.
C       On entry, LDA specifies the first dimension of A as declared
C       in the calling (sub)program. LDA >= M.
C
C     B(LDA, MIN(M+KU,N)) - real array.
C       If JOB = 'U' or 'u', then on entry the leading (KL + KU + 1)
C       by min(M+KU,N) part of array B must contain the band matrix,
C       packed column by column, with the leading diagonal of the
C       matrix in row (KU + 1) of the array, the first super-diagonal
C       starting at position 2 in row KU, the first sub-diagonal
C       starting at position 1 in row (KU + 2), and so on.
C       Elements in the array B that do not correspond to elements
C       in the band matrix (such as the top left KU by KU triangle)
C       are not referenced.
C       If JOB = 'P', then on entry B may be undefined, and on exit
C       B contains the band matrix, packed as described above.
C       Elements in the array B that do not correspond to elements
C       in the band matrix (such as the top left KU by KU triangle)
C       are not referenced.
C
C     LDB - INTEGER.
C       On entry, LDB specifies the first dimension of B as declared
C       in the calling (sub)program. LDB >= (KL + KU + 1).
C
C     IFAIL - INTEGER.
C       Error flag. On exit,
C         IFAIL = 1 if JOB <> 'P', 'p', 'U' or 'u'.
C         IFAIL = 2 if KL < 0.
C         IFAIL = 3 if KU < 0.
C         IFAIL = 4 if LDA < M.
C         IFAIL = 5 if LDB < KL + KU + 1.
C

F01ZDF
      SUBROUTINE F01ZDF(JOB,M,N,KL,KU,A,LDA,B,LDB,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     Converts a complex banded matrix from packed storage to unpacked,
C     or vice-versa.
C
C     Parameters:
C
C     JOB - CHARACTER*1.
C       JOB = 'P' or 'p' : 'Pack' - the contents of matrix A are to be
C       packed into matrix B.
C       JOB = 'U' or 'u' : 'Unpack' - the contents of matrix B are to
C       be unpacked into matrix A.
C
C     M - INTEGER.
C       On entry, M specifies the number of rows of the matrix A.
C
C     N - INTEGER.
C       On entry, N specifies the number of columns of the matrix A.
C
C     KL - INTEGER.
C       On entry, KL specifies the number of sub-diagonals of the
C       matrix A. KL >= 0.
C
C     KU - INTEGER.
C       On entry, KU specifies the number of super-diagonals of the
C       matrix A. KU >= 0.
C
C     A(LDA, N) - complex array.
C       If JOB = 'P' or 'p', then on entry the leading M by N part
C       of array A must contain the band matrix stored in unpacked
C       form. Elements of A that lie above the KUth super-diagonal
C       and below the KLth sub-diagonal are not referenced and need
C       not be defined.
C       If JOB = 'U' or 'u', then on entry the array A may be
C       undefined. On exit, A contains the band matrix stored in
C       unpacked form. Elements of the leading M by N part of A that
C       lie above the KUth super-diagonal or below the KLth
C       sub-diagonal are assigned the value zero.
C
C     LDA - INTEGER.
C       On entry, LDA specifies the first dimension of A as declared
C       in the calling (sub)program. LDA >= M.
C
C     B(LDA, MIN(M+KU,N)) - complex array.
C       If JOB = 'U' or 'u', then on entry the leading (KL + KU + 1)
C       by min(M+KU,N) part of array B must contain the band matrix,
C       packed column by column, with the leading diagonal of the
C       matrix in row (KU + 1) of the array, the first super-diagonal
C       starting at position 2 in row KU, the first sub-diagonal
C       starting at position 1 in row (KU + 2), and so on.
C       Elements in the array B that do not correspond to elements
C       in the band matrix (such as the top left KU by KU triangle)
C       are not referenced.
C       If JOB = 'P', then on entry B may be undefined, and on exit
C       B contains the band matrix, packed as described above.
C       Elements in the array B that do not correspond to elements
C       in the band matrix (such as the top left KU by KU triangle)
C       are unreferenced.
C
C     LDB - INTEGER.
C       On entry, LDB specifies the first dimension of B as declared
C       in the calling (sub)program. LDB >= (KL + KU + 1).
C
C     IFAIL - INTEGER.
C       Error flag. On exit,
C         IFAIL = 1 if JOB <> 'P', 'p', 'U' or 'u'.
C         IFAIL = 2 if KL < 0.
C         IFAIL = 3 if KU < 0.
C         IFAIL = 4 if LDA < M.
C         IFAIL = 5 if LDB < KL + KU + 1.
C

F02BBF
      SUBROUTINE F02BBF(A,IA,N,ALB,UB,M,MM,R,V,IV,D,E,E2,X,G,C,ICOUNT,
     *                  IFAIL)
C     NAG COPYRIGHT 1976. MARK  5 RELEASE.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C     MARK 14 REVISED. IER-740 (DEC 1989).
C     WRITTEN BY W.PHILLIPS     1ST OCTOBER 1975
C     OXFORD UNIVERSITY COMPUTING LABORATORY.
C     THIS ROUTINE REPLACES F02ACF.
C
C     SELECTED EIGENVALUES AND EIGENVECTORS OF A REAL SYMMETRIC
C     MATRIX
C

F02BCF
      SUBROUTINE F02BCF(A,IA,N,RLB,RUB,M,MM,RR,RI,VR,IVR,VI,IVI,INTGER,
     *                  ICNT,C,B,IB,U,V,LFAIL)
C     MARK 7 RELEASE. NAG COPYRIGHT 1978.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C     W.PHILLIPS. OXFORD UNIVERSITY COMPUTING SERVICE. 1 JUN 1977
C
C     SELECTED EIGENVALUES AND EIGENVECTORS  OF A REAL UNSYMMETRIC
C     MATRIX
C
C     THIS ROUTINE REPLACES F02AHF.
C

F02BDF
      SUBROUTINE F02BDF(AR,IAR,AI,IAI,N,RLB,RUB,M,MM,RR,RI,VR,IVR,VI,
     *                  IVI,INTGER,C,BR,IBR,BI,IBI,U,V,LFAIL)
C     MARK 7 RELEASE. NAG COPYRIGHT 1978.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C     W.PHILLIPS. OXFORD UNIVERSITY COMPUTING SERVICE. 1 JUN 1977
C
C     SELECTED EIGENVALUES AND EIGENVECTORS OF A COMPLEX
C     UNSYMMETRIC MATRIX
C
C     THIS ROUTINE REPLACES F02ALF.
C

F02BJF
      SUBROUTINE F02BJF(N,A,IA,B,IB,EPS1,ALFR,ALFI,BETA,MATZ,Z,IZ,ITER,
     *                  IFAIL)
C     MARK 6 RELEASE. NAG COPYRIGHT 1977
C     MARK 6A REVISED  IER-99
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     THIS SUBROUTINE PERFORMS THE QZ ALGORITHM FOR SOLVING THE
C     GENERALIZED MATRIX EIGENVALUE PROBLEM, A*Z = LAMBDA*B*Z
C     WHERE A AND B ARE REAL SQUARE MATRICES.
C     REFERENCE
C     SIAM J.NUMER.ANAL., 10, PP241-256, 1973.
C     C. B. MOLER AND G. W. STEWART.
C
C     THIS SUBROUTINE WAS WRITTEN BY
C     W. PHILLIPS OXFORD UNIVERSITY COMPUTING SERVICE.
C     IT CALLS F02BJW, F02BJX, F02BJY AND F02BJZ WHICH
C     WERE OBTAINED FROM EISPACK.
C

F02EAF
      SUBROUTINE F02EAF(JOB,N,A,LDA,WR,WI,Z,LDZ,WORK,LWORK,IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.
C
C     F02EAF computes all the eigenvalues, the Schur form, or the
C     complete Schur factorization, of a real general matrix A.
C
C     F02EAF is a driver routine which calls computational routines
C     from LAPACK in Chapter F08.
C

F02EBF
      SUBROUTINE F02EBF(JOB,N,A,LDA,WR,WI,VR,LDVR,VI,LDVI,WORK,LWORK,
     *                  IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.
C
C     F02EBF computes all the eigenvalues, and optionally all the
C     eigenvectors, of a real general matrix A.
C
C     F02EBF is a driver routine which calls computational routines
C     from LAPACK in Chapter F08.
C

F02FAF
      SUBROUTINE F02FAF(JOB,UPLO,N,A,LDA,W,WORK,LWORK,IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.
C
C     F02FAF computes all the eigenvalues, and optionally all the
C     eigenvectors, of a real symmetric matrix A.
C
C     F02FAF is a driver routine which calls computational routines from
C     LAPACK in Chapter F08.
C

F02FDF
      SUBROUTINE F02FDF(ITYPE,JOB,UPLO,N,A,LDA,B,LDB,W,WORK,LWORK,IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.
C
C     F02FDF computes all the eigenvalues, and optionally all the
C     eigenvectors, of a real symmetric-definite generalized
C     eigenproblem, of one of the types:
C
C       1. A*z = lambda*B*z
C       2. A*B*z = lambda*z
C       3. B*A*z = lambda*z.
C
C     Here A and B are symmetric and B is also positive-definite.
C
C     F02FDF is a driver routine which calls computational routines from
C     LAPACK in Chapter F08.
C

F02FHF
      SUBROUTINE F02FHF(N,MA,A,NRA,MB,B,NRB,D,WORK,LWORK,IFAIL)
C     MARK 11 RELEASE. NAG COPYRIGHT 1983.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C
C     F02FHF FINDS THE EIGENVALUES FOR THE GENERALIZED BAND SYMMETRIC
C     EIGENVALUE PROBLEM
C
C     A*X = LAMBDA*B*X ,
C
C     WHERE A AND B ARE N BY N BAND SYMMETRIC MATRICES OF HALF-BAND
C     WIDTHS MA AND MB RESPECTIVELY AND B IS POSITIVE DEFINITE, BY
C     A VARIANT OF THE METHOD OF CRAWFORD.
C
C     FOR A DESCRIPTION OF THE PARAMETERS AND USE OF THIS ROUTINE SEE
C     THE NAG LIBRARY MANUAL.
C
C     -- WRITTEN ON 20-DECEMBER-1982.  S.J.HAMMARLING.
C
C     NAG FORTRAN 66 BLACK BOX ROUTINE.
C
C

F02FJF
      SUBROUTINE F02FJF(N,EM,P,KM,EPS,IP,OP,INF,NOVECS,X,MN,D,WORK,
     *                  LWORK,RWORK,LRWORK,IWORK,LIWORK,IFAIL)
C     MARK 11 RELEASE. NAG COPYRIGHT 1983.
C     MARK 11B REVISED. IER-458 (SEP 1984).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 12A REVISED. IER-509 (AUG 1986).
C
C     **************************************************************
C     *********
C
C     F02FJF - ITERATIVE COMPUTATION OF EIGENVALUES LARGEST IN
C     MAGNI-
C     TUDE AND CORRESPONDING EIGENVECTORS OF A REAL GENERAL-
C     IZED SYMMETRIC MATRIX
C
C     PURPOSE
C
C     A REAL N-SQUARE MATRIX C IS B-SYMMETRIC RELATIVE TO AN
C     N-SQUARE
C     SYMMETRIC POSITIVE DEFINITE MATRIX B WHEN
C     BC = ( C - TRANSPOSED )B.
C     GIVEN AS OPTIONAL INPUT A SET OF P INITIAL APPROXIMATE
C     EIGENVECTORS OF A REAL N-SQUARE B-SYMMETRIC MATRIX C CORRES-
C     PONDING TO P EIGENVALUES OF C LARGEST IN MAGNITUDE, F02FJF
C     COM-
C     PUTES EM EIGENVALUES AND EM CORRESPONDING EIGENVECTORS TO A
C     PRECISION DEPENDENT ON THE STRUCTURE OF B AND C AND ON A GIVEN
C     TOLERANCE EPS.  THE MATRIX B IS PRESENTED TO F02FJF AS AN
C     ALGO-
C     RITHM FOR CALCULATING THE STANDARD INNER PRODUCT ( W, BZ ) =
C     ( W - TRANSPOSED )BZ GIVEN COLUMN N-VECTORS W AND Z
C     IMPLEMENTED
C     AS A FORTRAN COMPATIBLE REAL FUNCTION SUBPROGRAM. THE MATRIX C
C     IS PRESENTED AS A SUBROUTINE SUBPROGRAM WHICH GIVEN A COLUMN
C     N-VECTOR Z CALCULATES ITS IMAGE W = CZ UNDER THE MATRIX C.
C     DEPENDING ON THE CHOICE OF B AND C, F02FJF APPLIES TO A WIDE
C     VARIETY OF SYMMETRIC EIGENPROBLEMS.
C
C     METHOD
C
C     F02FJF REPRESENTS RESULTS OF EXTENSIVE MODIFICATIONS AND TESTS
C     OF SUBROUTINE RITZIT, AN ANSI FORTRAN TRANSLATION OF THE
C     ALGOL 60 PROCEDURE OF THE SAME NAME.  THE BASIC RUTISHAUSER
C     -REINSCH ALGORITHM IS PRESERVED.
C
C     PAUL J. NIKOLAI
C     US AIR FORCE FLIGHT DYNAMICS LABORATORY
C     AFFDL/FBR
C     WRIGHT - PATTERSON AFB, OHIO 45433
C     (513) - 255 - 5350
C
C     FURTHER MODIFIED AT NAG CENTRAL OFFICE BY SVEN.
C     CALLS TO SVD ROUTINES REPLACE CALLS AT EACH ITERATION TO
C     TRED2 AND IMTQL2. THIS AVOIDS FORMING R( R**T ).
C     WORKSPACE ASSIGNED TO A VECTOR AND REDUCED SLIGHTLY.
C     SOME MINOR MODIFICATIONS TO IMPROVE PERFORMANCE ON PAGED
C     MACHINES
C
C     FOR A DESCRIPTION OF THE PARAMETERS AND USE OF THIS ROUTINE
C     SEE THE
C     NAG LIBRARY MANUAL. PARAMETER ASSOCIATION IS AS BELOW.
C
C     ROUTINE     DOCUMENT
C     N            N
C     EM            M
C     P            K
C     KM          NOITS
C     EPS          TOL
C     IP           DOT
C     OP          IMAGE
C     INF         MONIT
C     NOVECS       NOVECS
C     X            X
C     MN           NRX
C     D            D
C     WORK         WORK
C     LWORK        LWORK
C     RWORK        RWORK
C     LRWORK       LRWORK
C     IWORK        IWORK
C     LIWORK       LIWORK
C     IFAIL        IFAIL
C
C     **************************************************************
C     *********
C
C     INF, OP
C
C     THE LOCAL VARIABLE ARRAYS FROM RITZIT ARE ASSIGNED TO THE
C     VARIABLE ARRAY WORK AS FOLLOWS
C
C     B  - WORK( I ), I = 1, ..., P**2.
C     U  - WORK( I ), I = 1, ..., N.
C     W  - WORK( I ), I = N + 1, ..., 2*N.
C     CX - WORK( I ), I = CX1, ..., CX1 + P - 1
C     WHERE  CX1 = MAX( P**2, 2*N ) + 1
C     F  - WORK( I ), I = CX1 + P, ..., CX1 + 2*P - 1
C     RQ - WORK( I ), I = CX1 + 2*P, ..., CX1 + 3*P - 1
C
C     V, R AND Q ARE NOT NEEDED.
C
C     TEST THE INPUT PARAMETERS.
C

F02GAF
      SUBROUTINE F02GAF(JOB,N,A,LDA,W,Z,LDZ,RWORK,WORK,LWORK,IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.
C
C     F02GAF computes all the eigenvalues, the Schur form, or the
C     complete Schur factorization, of a complex general matrix A.
C
C     F02GAF is a driver routine which calls computational routines
C     from LAPACK in Chapter F08.
C

F02GBF
      SUBROUTINE F02GBF(JOB,N,A,LDA,W,V,LDV,RWORK,WORK,LWORK,IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.
C
C     F02GBF computes all the eigenvalues, and optionally all the
C     eigenvectors, of a complex general matrix A.
C
C     F02GBF is a driver routine which calls computational routines
C     from LAPACK in Chapter F08.
C

F02GJF
      SUBROUTINE F02GJF(N,AR,IAR,AI,IAI,BR,IBR,BI,IBI,EPS1,ALFR,ALFI,
     *                  BETA,MATZ,ZR,IZR,ZI,IZI,ITER,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     THIS ROUTINE IS THE COMPLEX ANALOGUE OF THE QZ ALGORITHM FOR
C     SOLVING THE GENERALIZED MATRIX EIGENVALUE PROBLEM,
C     A*Z = LAMBDA*B*Z
C     WHERE A AND B ARE REAL SQUARE MATRICES.
C     REFERENCE
C     SIAM J. NUMER. ANAL., 10, PP241-256, 1973.
C     C.B. MOLER AND G.W. STEWART.
C
C     THIS BLACK BOX ROUTINE WAS WRITTEN BY
C     W. PHILLIPS OXFORD UNIVERSITY COMPUTING SERVICE
C
C     IT CALLS F02GJX, F02GJY AND F02GJZ WHICH
C     WERE OBTAINED FROM EISPACK.
C

F02HAF
      SUBROUTINE F02HAF(JOB,UPLO,N,A,LDA,W,RWORK,WORK,LWORK,IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.
C
C     F02HAF computes all the eigenvalues, and optionally all the
C     eigenvectors, of a complex Hermitian matrix A.
C
C     F02HAF is a driver routine which calls computational routines from
C     LAPACK in Chapter F08.
C

F02HDF
      SUBROUTINE F02HDF(ITYPE,JOB,UPLO,N,A,LDA,B,LDB,W,RWORK,WORK,LWORK,
     *                  IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.
C
C     F02HDF computes all the eigenvalues, and optionally all the
C     eigenvectors, of a complex Hermitian-definite generalized
C     eigenproblem, of one of the types:
C
C       1. A*z = lambda*B*z
C       2. A*B*z = lambda*z
C       3. B*A*z = lambda*z.
C
C     Here A and B are Hermitian and B is also positive-definite.
C
C     F02HDF is a driver routine which calls computational routines from
C     LAPACK in Chapter F08.
C

F02SDF
      SUBROUTINE F02SDF(N,MA1,MB1,A,IA,B,IB,SYM,RELEP,RMU,VEC,D,INT,
     *                  WORK,LWORK,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C
C     PDK, DNACS, NPL, TEDDINGTON, JAN 1979
C     NPL DNACS LIBRARY SUBROUTINE BABIT
C
C     FINDS AN EIGENVECTOR CORRESPONDING TO A GIVEN EIGENVALUE
C     BY INVERSE ITERATION FOR THE GENERAL EIGENPROBLEM
C     A * X = RMU * B * X
C     WHERE BOTH A AND B ARE BAND MATRICES OF ORDER N
C     WITH BANDWIDTHS 2*MA1-1 AND 2*MB1-1 RESPECTIVELY.
C
C     THE ROUTINE PROVIDES SPECIAL OPTIONS FOR THE CASES WHERE
C     - BOTH A AND B ARE SYMMETRIC (SPECIFIED BY SYM = .TRUE.)
C     - B IS A UNIT MATRIX (SPECIFIED BY MB1.LE.0).
C     IN THE LATTER CASE THE ARRAY B IS NOT REFERENCED.
C
C     FOR AN UNSYMMETRIC PROBLEM (SYM = .FALSE.) THE DIAGONAL
C     LINES OF THE MATRICES A AND B MUST BE STORED IN THE ROWS
C     OF THE ARRAYS A AND B, WITH THE LOWEST SUBDIAGONAL IN
C     ROW 1 AND THE MAIN DIAGONAL IN ROW MA1 OR MB1.  EACH ROW
C     OF THE MATRICES IS STORED IN THE CORRESPONDING COLUMN
C     OF THE ARRAYS.  THE ELEMENTS IN THE UPPER LEFT AND LOWER
C     RIGHT CORNERS NEED NOT BE SET, BUT THEY ARE SET TO ZERO
C     AT THE START OF THE ROUTINE.
C
C     FOR A SYMMETRIC PROBLEM (SYM = .TRUE.) ONLY THE LOWER
C     TRIANGLES OF THE MATRICES NEED BE STORED, IN THE FIRST
C     MA1 OR MB1 ROWS OF THE ARRAYS.  NOTE THAT THE ARRAY A
C     MUST ALWAYS HAVE AT LEAST 2*MA1-1 ROWS, BUT THE ARRAY B
C     NEED ONLY HAVE MB1 ROWS IF SYM IS .TRUE..
C
C     THE COMPUTED EIGENVECTOR IS STORED IN THE ARRAY VEC(N),
C     NORMALISED SO THAT THE LARGEST ELEMENT IS 1.0.
C     RELEP IS THE RELATIVE ERROR OF THE GIVEN DATA. IF IT IS LESS
C     THAN THE VALUE RETURNED BY X02AJF, THEN THE LATTER VALUE
C     IS USED INSTEAD.
C
C     ON ENTRY D(1) PROVIDES INFORMATION ON THE NATURE OF THE
C     PROBLEM WHICH IS USED TO DETERMINE THE COURSE OF THE
C     ALGORITHM.  ON EXIT THE ARRAY D CONTAINS THE SUCCESSIVE
C     CORRECTIONS TO RMU IF D(1).NE.0.0 ON ENTRY AND
C     THE FINAL CORRECTION TO RMU IS ALSO ALWAYS STORED IN
C     D(30).
C

F02WDF
      SUBROUTINE F02WDF(M,N,A,NRA,WANTB,B,TOL,SVD,IRANK,Z,SV,WANTR,R,
     *                  NRR,WANTPT,PT,NRPT,WORK,LWORK,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C     WRITTEN BY S. HAMMARLING, MIDDLESEX POLYTECHNIC (SVDGN4)
C
C     F02WDF RETURNS THE HOUSEHOLDER QU FACTORIZATION OF A
C     AND, IF EITHER A IS NOT OF FULL RANK OR IF SVD IS TRUE,
C     PART OR ALL OF THE SINGULAR VALUE DECOMPOSITION (SVD) OF
C     A, WHERE A IS AN M*N (M.GE.N) MATRIX.
C
C     A IS FIRST FACTORIZED AS
C
C     A = Q*(U) ,
C           (0)
C
C     WHERE Q IS ORTHOGONAL AND U IS UPPER TRIANGULAR.
C
C     IF EITHER U IS SINGULAR OR SVD IS TRUE THEN PART OR ALL
C     OF THE SVD OF U GIVEN BY
C
C     U = R*D*(P**T) ,
C
C     WHERE R AND P ARE ORTHOGONAL AND D IS DIAGONAL WITH
C     NON-NEGATIVE DIAGONAL ELEMENTS, IS OBTAINED.
C
C     THE SVD OF A IS THEN GIVEN BY
C
C     A = Q*(R 0)*(D)*(P**T) ,
C           (0 I) (0)
C
C     THE DIAGONAL ELEMENTS OF D BEING THE SINGULAR VALUES OF A.
C
C     IF WANTB IS TRUE THEN (Q**T)*B IS FORMED FOLLOWED, IF
C     APPROPRIATE, BY (R**T 0)*(Q**T)*B.
C                     ( 0   I)
C
C     INPUT PARAMETERS.
C
C     M      - NUMBER OF ROWS OF A. M MUST BE AT LEAST N.
C
C     N      - NUMBER OF COLUMNS OF A. N MUST BE AT LEAST UNITY.
C
C     A      - M*N MATRIX TO BE FACTORIZED.
C
C     NRA    - ROW DIMENSION OF A AS DECLARED IN THE
C              CALLING PROGRAM. NRA MUST BE AT LEAST M.
C
C     WANTB  - MUST BE .TRUE. IF (Q**T)*B OR, IF APPROPRIATE,
C              (R**T 0)*(Q**T)*B IS REQUIRED.
C              ( 0   I)
C              IF WANTB IS .FALSE. THEN B IS NOT REFERENCED.
C
C     B      - AN M ELEMENT VECTOR.
C
C     TOL    - A RELATIVE TOLERANCE USED TO DETERMINE THE RANK OF A.
C              TOL SHOULD BE CHOSEN AS APPROXIMATELY THE LARGEST
C              RELATIVE ERROR IN THE ELEMENTS OF A.
C              LETTING EPS DENOTE THE SMALLEST REAL FOR WHICH
C              1.0+EPS.GT.1.0 ON THE MACHINE, IF TOL IS OUTSIDE THE
C              RANGE (EPS,1) THEN THE VALUE EPS IS USED IN
C              PLACE OF TOL. U IS REGARDED AS SINGULAR IF
C              L(U)*L(U**(-1))*TOL.GT.1, WHERE L(U) DENOTES
C              THE EUCLIDEAN LENGTH OF U.
C              IF THE SINGULAR VALUES OF A ARE COMPUTED
C              THEN THE RANK OF A IS DETERMINED BY
C              NEGLECTING SINGULAR VALUES FOR WHICH
C              SV(1)*TOL.GE.SV(I), WHERE SV(1) IS THE
C              LARGEST SINGULAR  VALUE.
C
C     SVD    - MUST BE .TRUE. IF PART OR ALL OF THE SVD IS
C              REQUIRED EVEN IF A IS OF FULL RANK.
C
C     WANTR  - MUST BE .TRUE. IF THE ORTHOGONAL MATRIX R IS REQUIRED
C              IF WANTR IS .FALSE. THEN R IS NOT REFERENCED.
C
C     NRR    - ROW DIMENSION OF R AS DECLARED IN THE CALLING PROGRAM
C              NRR MUST BE AT LEAST N.
C
C     WANTPT - MUST BE .TRUE. IF THE ORTHOGONAL MATRIX P**T
C              IS REQUIRED. NOTE THAT PT IS REFERENCED EVEN
C              WHEN WANTPT IS .FALSE., BUT SEE OUTPUT
C              PARAMETER PT BELOW.
C
C     NRPT   - ROW DIMENSION OF PT AS DECLARED IN THE
C              CALLING PROGRAM. NRPT MUST BE AT LEAST N.
C
C     IFAIL  - THE USUAL FAILURE PARAMETER. IF IN DOUBT SET IFAIL TO
C              ZERO BEFORE CALLING F02WDF.
C
C     OUTPUT PARAMETERS.
C
C     A      - A, TOGETHER WITH THE VECTOR Z, WILL CONTAIN
C              DETAILS OF THE QU FACTORIZATION AS RETURNED
C              FROM ROUTINE F01QAF, UNLESS F02WDF IS CALLED
C              WITH PT=A AND SVD IS RETURNED AS .TRUE..
C
C     B      - IF WANTB IS .TRUE. THEN IF A IS OF FULL RANK AND SVD
C              IS RETURNED AS .FALSE. B IS OVERWRITTEN BY (Q**T)*B,
C              OTHERWISE B IS OVERWRITTEN BY (R**T 0)*(Q**T)*B.
C                                            ( 0   I)
C              IF WANTB IS .FALSE. THEN B IS NOT REFERENCED.
C
C     SVD    - SVD IS RETURNED AS .TRUE. IF THE SINGULAR VALUES OF A
C              HAVE BEEN OBTAINED AND IS RETURNED AS
C              .FALSE. IF ONLY THE QU FACTORIZATION OF A
C              HAS BEEN OBTAINED.
C
C     IRANK  - THE RANK OF THE MATRIX A.
C
C     Z      - N ELEMENT VECTOR. SEE OUTPUT PARAMETER A ABOVE.
C              IF Z IS NOT REQUIRED THEN THE ROUTINE MAY BE
C              CALLED WITH Z=SV.
C
C     SV     - N ELEMENT VECTOR. IF A IS NOT OF FULL RANK OR IF SVD
C              IS RETURNED AS .TRUE. THEN SV WILL CONTAIN
C              THE SINGULAR VALUES OF A ARRANGED IN
C              DESCENDING ORDER.
C
C     R      - N*N MATRIX. IF WANTR IS .TRUE. AND SVD IS RETURNED AS
C              .TRUE. THEN R RETURNS THE LEFT HAND
C              ORTHOGONAL MATRIX OF THE SVD OF U.
C              IF WANTR IS .FALSE. THEN R IS NOT REFERENCED.
C
C     PT     - N*N MATRIX. IF WANTPT IS .TRUE. AND SVD IS
C              RETURNED AS .TRUE. THEN PT RETURNS THE
C              MATRIX P**T.
C              THE ROUTINE MAY BE CALLED WITH PT=A.
C              IF WANTPT IS .FALSE. BUT WANTR IS .TRUE.
C              THEN THE ROUTINE MAY BE CALLED WITH PT=R.
C
C     IFAIL  - ON NORMAL RETURN IFAIL WILL BE ZERO.
C              IN THE UNLIKELY EVENT THAT THE QR-ALGORITHM
C              FAILS TO FIND THE SINGULAR VALUES IN 50*N
C              ITERATIONS THEN IFAIL WILL BE 2 OR MORE AND
C              SUCH THAT SV(1),SV(2),..., SV(IFAIL-1) MAY
C              NOT HAVE BEEN FOUND.
C              IF AN INPUT PARAMETER IS INCORRECTLY
C              SUPPLIED THEN IFAIL IS SET TO UNITY.
C
C     WORKSPACE PARAMETERS.
C
C     WORK   - A 3*N ELEMENT VECTOR.
C              IF SVD IS RETURNED AS .FALSE. THEN WORK(1) WILL
C              CONTAIN THE CONDITION NUMBER, L(U)*L(U**(-1)), OF THE
C              UPPER TRIANGULAR MATRIX U.
C              IF SVD IS RETURNED AS .TRUE. THEN WORK(1)
C              WILL CONTAIN THE TOTAL NUMBER OF ITERATIONS
C              TAKEN BY THE QR-ALGORITHM.
C
C     LWORK  - LENGTH OF THE VECTOR WORK. LWORK MUST BE AT
C               LEAST 3*N.
C

F02WEF
      SUBROUTINE F02WEF(M,N,A,LDA,NCOLB,B,LDB,WANTQ,Q,LDQ,SV,WANTP,PT,
     *                  LDPT,WORK,IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.
C     MARK 14 REVISED. IER-789 (DEC 1989).
C     MARK 14B REVISED. IER-834 (MAR 1990).
C
C  1. Purpose
C     =======
C
C  F02WEF  returns all, or part, of the  singular value decomposition of
C  a general real matrix.
C
C  2. Description
C     ===========
C
C  The m by n matrix A is factorized as
C
C     A = Q*D*P',
C
C  where
C
C     D = ( S ),      m .gt. n,
C         ( 0 )
C
C     D =   S,        m .eq. n,
C
C     D = ( S  0 ),   m .lt. n,
C
C  Q is an  m by m orthogonal matrix,  P is an  n by n orthogonal matrix
C  and  S  is a  min( m, n ) by min( m, n )  diagonal matrix  with  non-
C  negative diagonal elements, sv( 1 ), sv( 2 ), ..., sv( min( m, n ) ),
C  ordered such that
C
C     sv( 1 ) .ge. sv( 2 ) .ge. ... .ge. sv( min( m, n ) ) .ge. 0.
C
C  The first min( m, n ) columns of Q are the left-hand singular vectors
C  of A, the diagonal elements of S are the singular values of A and the
C  first min( m, n ) columns of P are the right-hand singular vectors of
C  A.
C
C  Either or both of the left-hand and right-hand singular vectors of  A
C  may be requested and the matrix
C  C given by
C
C     C = Q'*B,
C
C  where B is an m by ncolb given matrix, may also be requested.
C
C  The  routine  obtains  the  singular  value  decomposition  by  first
C  reducing  A  to  upper  triangular  form  by  means  of   Householder
C  transformations, from the left when  m .ge. n and from the right when
C  m .lt. n.  The  upper triangular form  is then reduced to  bidiagonal
C  form by  Givens plane rotations and finally the  QR algorithm is used
C  to obtain the  singular value decomposition  of the  bidiagonal form.
C
C  3. Parameters
C     ==========
C
C  M      - INTEGER.
C
C           On entry, M must specify the number of rows of the matrix A.
C           M  must be  at least  zero.  When  M = 0  then an  immediate
C           return is effected.
C
C           Unchanged on exit.
C
C  N      - INTEGER.
C
C           On entry, N must specify the number of columns of the matrix
C           A.  N must be at least zero.  When  N = 0  then an immediate
C           return is effected.
C
C           Unchanged on exit.
C
C  A      - REAL             array of DIMENSION ( LDA, n ).
C
C           Before entry, the leading  M by N  part of the array  A must
C           contain the matrix  A  whose singular value decomposition is
C           required.
C
C           If  m .ge. n  and  WANTQ is .TRUE.  then on exit, the M by N
C           part of A will contain the first n columns of the orthogonal
C           matrix  Q.
C
C           If  m .lt. n  and  WANTP is .TRUE.  then on exit, the M by N
C           part of  A  will contain the first  m rows of the orthogonal
C           matrix  P'.
C
C           If   m .ge. n  and   WANTQ is .FALSE.  and   WANTP is .TRUE.
C           then on exit, the  min( M, N ) by N  part of  A will contain
C           the first  min( m, n )  rows  of the  orthogonal matrix  P'.
C
C           Otherwise  the   M by N  part  of  A  is  used  as  internal
C           workspace.
C
C  LDA    - INTEGER.
C
C           On entry, LDA  must  specify  the  leading dimension of  the
C           array  A  as declared in the calling (sub) program. LDA must
C           be at least  m.
C
C           Unchanged on exit.
C
C  NCOLB  - On entry,  NCOLB  must specify the  number of columns of the
C           matrix  B  and must be at least  zero.  When  NCOLB = 0  the
C           array  B  is not referenced.
C
C  B      - REAL             array of DIMENSION ( LDB, ncolb ).
C
C           Before entry with  NCOLB .gt. 0, the leading M by NCOLB part
C           of the array  B  must contain the  matrix to be  transformed
C           and  on exit,  B  is overwritten  by the  m by ncolb  matrix
C           Q'*B.
C
C  LDB    - INTEGER.
C
C           On entry, LDB  must  specify  the  leading dimension of  the
C           array  B  as declared  in the  calling  (sub) program.  When
C           NCOLB .gt. 0  then LDB must be at least  m.
C
C           Unchanged on exit.
C
C  WANTQ  - LOGICAL.
C
C           On entry,  WANTQ  must be .TRUE.  if the  left-hand singular
C           vectors are required. If  WANTQ is .FALSE.  then  the  array
C           Q  is not referenced.
C
C           Unchanged on exit.
C
C  Q      - REAL             array of DIMENSION ( LDQ, m ).
C
C           On exit  with  M .lt. N  and  WANTQ as .TRUE.,  the  leading
C           M by M  part  of the  array  Q  will contain  the orthogonal
C           matrix Q. Otherwise the array  Q is not referenced.
C
C  LDQ    - INTEGER.
C
C           On entry, LDQ  must  specify  the  leading dimension of  the
C           array  Q  as declared  in the  calling  (sub) program.  When
C           M .lt. N  and  WANTQ is .TRUE.,  LDQ  must  be at  least  m.
C
C           Unchanged on exit.
C
C  SV     - REAL array of DIMENSION at least ( min( m, n ) ).
C
C           On exit, the array  SV will contain the min( m, n ) diagonal
C           elements of the matrix  S.
C
C  WANTP  - LOGICAL.
C
C           On entry,  WANTP must be .TRUE.  if the  right-hand singular
C           vectors are  required.  If  WANTP is .FALSE.  then the array
C           PT  is not referenced.
C
C           Unchanged on exit.
C
C  PT     - REAL             array of DIMENSION ( LDPT, n ).
C
C           On exit  with  M .ge. N  and  WANTQ and WANTP as .TRUE., the
C           leading  N by N  part  of the  array  PT  will  contain  the
C           orthogonal  matrix  P'.   Otherwise  the  array  PT  is  not
C           referenced.
C
C  LDPT   - INTEGER.
C
C           On entry,  LDPT  must specify the  leading dimension  of the
C           array  PT  as declared  in the  calling (sub) program.  When
C           M .ge. N  and  WANTQ and WANTP are .TRUE.,  LDPT  must be at
C           least  n.
C
C           Unchanged on exit.
C
C  WORK   - REAL array of DIMENSION at least ( lwork ), where lwork must
C           be as given in the following table:
C
C              M .ge. N
C
C                 WANTQ is .TRUE.  and   WANTP is .TRUE.
C
C                    lwork = max(n**2 + 5*( n - 1 ), n + ncolb, 4)
C
C                 WANTQ is .TRUE.  and  WANTP is .FALSE.
C
C                    lwork = max(n**2 + 4*( n - 1 ) + 1, n + ncolb, 4)
C
C                 WANTQ is .FALSE.  and  WANTP is .TRUE.
C
C                    lwork = max( 3*( n - 1 ), 2 )   when   NCOLB   =  0
C                    lwork = max( 5*( n - 1 ), 2 )   when   NCOLB .gt. 0
C
C                 WANTQ is .FALSE.  and  WANTP is .FALSE.
C
C                    lwork = max( 2*( n - 1 ), 2 )   when  NCOLB   =  0
C                    lwork = max( 3*( n - 1 ), 2 )   when  NCOLB .gt. 0
C
C              M .lt. N
C
C                 WANTQ is .TRUE.  and   WANTP is .TRUE.
C
C                    lwork = max( m**2 + 5*( m - 1 ), 2 )
C
C                 WANTQ is .TRUE.  and  WANTP is .FALSE.
C
C                    lwork = max( 3*( m - 1 ), 1 )
C
C                 WANTQ is .FALSE.  and  WANTP is .TRUE.
C
C                    lwork = max( m**2 + 3*( m - 1 ), 2 )
C                                                  when  NCOLB   =  0
C                    lwork = max( m**2 + 5*( m - 1 ), 2 )
C                                                  when  NCOLB .gt. 0
C
C                 WANTQ is .FALSE.  and  WANTP is .FALSE.
C
C                    lwork = max( 2*( m - 1 ), 1 )    when  NCOLB   =  0
C                    lwork = max( 3*( m - 1 ), 1 )    when  NCOLB .gt. 0
C
C           The array  WORK  is used as  internal  workspace by  F02WEF.
C           On exit,  WORK( min( m, n ) )  contains the  total number of
C           iterations taken by the QR algorithm.
C
C  IFAIL  - INTEGER.
C
C           Before entry,  IFAIL  must contain one of the values -1 or 0
C           or 1 to specify noisy soft failure or noisy hard failure  or
C           silent soft failure. ( See Chapter P01 for further details.)
C
C           On successful  exit  IFAIL  will be  zero,  otherwise  IFAIL
C           will be set to a  non-zero value  indicating either  that an
C           input parameter  has been  incorrectly set,  or that the  QR
C           algorithm  is not  converging.  See  the  next  section  for
C           further details.
C
C  4. Diagnostic Information
C     ======================
C
C  IFAIL = -1
C
C     One or more of the following conditions holds:
C
C        M     .lt. 0
C        N     .lt. 0
C        LDA   .lt. M
C        NCOLB .lt. 0
C        LDB   .lt. M  and  NCOLB .gt. 0
C        LDQ   .lt. M  and  M     .lt. N  and  WANTQ is true
C        LDPT  .lt. N  and  M     .ge. N  and  WANTQ is true
C                                         and  WANTP is true
C
C  IFAIL .gt. 0
C
C     The  QR  algorithm  has  failed  to  converge  in   50*min( M, N )
C     iterations.  In this case  sv( 1 ), sv( 2 ), ..., sv( IFAIL )  may
C     not  have been found correctly  and the remaining  singular values
C     may not be the smallest. The matrix  A will nevertheless have been
C     factorized  as   A = Q*E*P',  where  the  leading   min( m, n ) by
C     min( m, n )  part  of  E  is  a  bidiagonal matrix  with  sv( 1 ),
C     sv( 2 ), ..., sv( min( m, n ) )   as  the  diagonal  elements  and
C     work( 1 ), work( 2 ), ..., work( min( m, n ) - 1 )  as the  super-
C     diagonal elements.
C
C     This failure is not likely to occur.
C
C  If  on  entry,  IFAIL  was  either  -1 or 0  then  further diagnostic
C  information  will  be  output  on  the  error message  channel. ( See
C  routine  X04AAF. )
C
C  5. Further information
C     ===================
C
C  Following the use of this routine the rank of A may be estimated by
C  a call to the INTEGER function F06KLF.  The statement:
C
C     IRANK = F06KLF( MIN( M, N ), SV, 1, TOL )
C
C  returns  the value  ( k - 1 ), in  IRANK,  where  k  is the  smallest
C  integer  for  which   sv( k ) .lt. tol*sv( 1 ),   where  tol  is  the
C  tolerance supplied in  TOL, so that  IRANK is an estimate of the rank
C  of  S  and thus also of  A.  If  TOL is supplied as negative then the
C  relative machine precision ( see routine X02AJF ) is used in place of
C  TOL.
C
C
C  Nag Fortran 77 Auxiliary linear algebra routine.
C
C  -- Written on 12-January-1988.
C     Sven Hammarling, Nag Central Office.
C

F02WUF
      SUBROUTINE F02WUF(N,A,LDA,NCOLB,B,LDB,WANTQ,Q,LDQ,SV,WANTP,WORK,
     *                  IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C  1. Purpose
C     =======
C
C  F02WUF  returns all, or part, of the  singular value decomposition of
C  a real upper triangular matrix.
C
C  2. Description
C     ===========
C
C  The n by n upper triangular matrix R is factorized as
C
C     R = Q*S*P',
C
C  where  Q and P  are  n by n orthogonal matrices and  S  is an  n by n
C  diagonal  matrix   with  non-negative  diagonal  elements,   sv( 1 ),
C  sv( 2 ), ..., sv( n ), ordered such that
C
C     sv( 1 ) .ge. sv( 2 ) .ge. ... .ge. sv( n ) .ge. 0.
C
C  The  columns of  Q  are the  left-hand  singular vectors  of  R,  the
C  diagonal elements of  S are the singular values of  R and the columns
C  of  P are the right-hand singular vectors of  R.
C
C  Either or both of Q and P' may be requested and the matrix C given by
C
C     C = Q'*B,
C
C  where B is an n by ncolb given matrix, may also be requested.
C
C  The  routine  obtains  the  singular  value  decomposition  by  first
C  reducing  R  to  bidiagonal form  by means of  Givens plane rotations
C  and  then  using  the  QR algorithm  to  obtain  the  singular  value
C  decomposition  of the  bidiagonal form.
C
C  3. Parameters
C     ==========
C
C  N      - INTEGER.
C
C           On entry,  N must specify the order of the matrix R.  N must
C           be  at  least zero. When  N = 0  then an immediate return is
C           effected.
C
C           Unchanged on exit.
C
C  A      - REAL             array of DIMENSION ( LDA, n ).
C
C           Before entry,  the leading  N by N  upper triangular part of
C           the array  A  must contain the  upper triangular  matrix  R.
C
C           If  WANTP is .TRUE.  then on exit, the N by N part of A will
C           contain  the  n by n  orthogonal matrix  P',  otherwise  the
C           N by N  upper triangular  part  of  A  is  used as  internal
C           workspace,  but  the  strictly lower triangular  part  of  A
C           is not referenced.
C
C  LDA    - INTEGER.
C
C           On entry, LDA  must  specify  the  leading dimension of  the
C           array  A  as declared in the calling (sub) program. LDA must
C           be at least  n.
C
C           Unchanged on exit.
C
C  NCOLB  - On entry,  NCOLB  must specify the  number of columns of the
C           matrix  B  and must be at least  zero.  When  NCOLB = 0  the
C           array  B  is not referenced.
C
C  B      - REAL             array of DIMENSION ( LDB, ncolb ).
C
C           Before entry with  NCOLB .gt. 0, the leading N by NCOLB part
C           of the array  B  must contain the  matrix to be  transformed
C           and  on exit,  B  is overwritten  by the  n by ncolb  matrix
C           Q'*B.
C
C  LDB    - INTEGER.
C
C           On entry, LDB  must  specify  the  leading dimension of  the
C           array  B  as declared  in the  calling  (sub) program.  When
C           NCOLB .gt. 0  then LDB must be at least  n.
C
C           Unchanged on exit.
C
C  WANTQ  - LOGICAL.
C
C           On entry,  WANTQ must be .TRUE. if the matrix Q is required.
C           If  WANTQ is .FALSE.  then  the array  Q  is not referenced.
C
C           Unchanged on exit.
C
C  Q      - REAL             array of DIMENSION ( LDQ, n ).
C
C           On exit with  WANTQ as .TRUE.,  the leading  N by N  part of
C           the array Q will contain the orthogonal matrix Q.  Otherwise
C           the array  Q  is not referenced.
C
C  LDQ    - INTEGER.
C
C           On entry, LDQ  must  specify  the  leading dimension of  the
C           array  Q  as declared  in the  calling  (sub) program.  When
C           WANTQ is .TRUE.,  LDQ  must be at least n.
C
C           Unchanged on exit.
C
C  SV     - REAL array of DIMENSION at least ( n ).
C
C           On exit, the array  SV will contain the  n diagonal elements
C           of the matrix S.
C
C  WANTP  - LOGICAL.
C
C           On entry, WANTP must be .TRUE. if the matrix P' is required,
C           in which case  P'  is overwritten on the array A,  otherwise
C           WANTP must be .FALSE..
C
C           Unchanged on exit.
C
C  WORK   - REAL array of DIMENSION at least  ( max( 1, lwork ) ), where
C           lwork must satisfy:
C
C              lwork = 2*( n - 1 ) when
C                 ncolb = 0  and  WANTQ and WANTP are .FALSE.,
C
C              lwork = 3*( n - 1 ) when
C                 either  ncolb = 0  and  WANTQ is .FALSE.  and
C                 WANTP is .TRUE.,  or  WANTP is .FALSE.  and  one or
C                 both of  ncolb .gt. 0  and  WANTQ is .TRUE.
C
C              lwork = 5*( n - 1 ) otherwise.
C
C           The array   WORK  is used as  internal workspace by  F06XUF.
C           On exit,  WORK( n )  contains the total number of iterations
C           taken by the QR algorithm.
C
C  IFAIL  - INTEGER.
C
C           Before entry,  IFAIL  must contain one of the values -1 or 0
C           or 1 to specify noisy soft failure or noisy hard failure  or
C           silent soft failure. ( See Chapter P01 for further details.)
C
C           On successful  exit  IFAIL  will be  zero,  otherwise  IFAIL
C           will be set to a  non-zero value  indicating either  that an
C           input parameter  has been  incorrectly set,  or that the  QR
C           algorithm  is not  converging.  See  the  next  section  for
C           further details.
C
C  4. Diagnostic Information
C     ======================
C
C  IFAIL = -1
C
C     One or more of the following conditions holds:
C
C        N     .lt. 0
C        LDA   .lt. N
C        NCOLB .lt. 0
C        LDB   .lt. N  and  NCOLB .gt. 0
C        LDQ   .lt. N  and  WANTQ  is  true
C
C  IFAIL .gt. 0
C
C     The  QR algorithm  has failed to converge in  50*N iterations.  In
C     this  case  sv( 1 ), sv( 2 ), ..., sv( IFAIL )  may not  have been
C     found correctly  and the remaining singular values  may not be the
C     smallest.  The matrix  R will nevertheless have been factorized as
C     R = Q*E*P', where E is a bidiagonal matrix with  sv( 1 ), sv( 2 ),
C     ..., sv( n )  as the  diagonal elements and  work( 1 ), work( 2 ),
C     ..., work( n - 1 )  as the super-diagonal elements.
C
C     This failure is not likely to occur.
C
C  If  on  entry,  IFAIL  was  either  -1 or 0  then  further diagnostic
C  information  will  be  output  on  the  error message  channel. ( See
C  routine  X04AAF. )
C
C  5. Further information
C     ===================
C
C  Following the use of this routine the rank of R may be estimated by
C  a call to the INTEGER function F06KLF.  The statement:
C
C     IRANK = F06KLF( N, SV, 1, TOL )
C
C  returns  the value  ( k - 1 ), in  IRANK,  where  k  is the  smallest
C  integer  for  which   sv( k ) .lt. tol*sv( 1 ),   where  tol  is  the
C  tolerance supplied in  TOL, so that  IRANK is an estimate of the rank
C  of  S  and thus also of  R.  If  TOL is supplied as negative then the
C  relative machine precision ( see routine X02AJF ) is used in place of
C  TOL.
C
C
C  Nag Fortran 77 Auxiliary linear algebra routine.
C
C  -- Written on 10-January-1988.
C     Sven Hammarling, Nag Central Office.
C

F02XEF
      SUBROUTINE F02XEF(M,N,A,LDA,NCOLB,B,LDB,WANTQ,Q,LDQ,SV,WANTP,PH,
     *                  LDPH,RWORK,CWORK,IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.
C     MARK 14 REVISED. IER-791 (DEC 1989).
C     MARK 14B REVISED. IER-835 (MAR 1990).
C
C  1. Purpose
C     =======
C
C  F02XEF  returns all, or part, of the  singular value decomposition of
C  a general complex matrix.
C
C  2. Description
C     ===========
C
C  The m by n matrix A is factorized as
C
C     A = Q*D*conjg( P' ),
C
C  where
C
C     D = ( S ),      m .gt. n,
C         ( 0 )
C
C     D =   S,        m .eq. n,
C
C     D = ( S  0 ),   m .lt. n,
C
C  Q is an m by m unitary matrix, P is an n by n unitary matrix and S is
C  a  min( m, n ) by min( m, n )  diagonal matrix with real non-negative
C  diagonal elements,  sv( 1 ), sv( 2 ), ..., sv( min( m, n ) ), ordered
C  such that
C
C     sv( 1 ) .ge. sv( 2 ) .ge. ... .ge. sv( min( m, n ) ) .ge. 0.
C
C  The first min( m, n ) columns of Q are the left-hand singular vectors
C  of A, the diagonal elements of S are the singular values of A and the
C  first min( m, n ) columns of P are the right-hand singular vectors of
C  A.
C
C  Either or both of the left-hand and right-hand singular vectors of  A
C  may be requested and the matrix
C  C given by
C
C     C = conjg( Q' )*B,
C
C  where B is an m by ncolb given matrix, may also be requested.
C
C  The  routine  obtains  the  singular  value  decomposition  by  first
C  reducing  A  to  upper  triangular  form  by  means  of   Householder
C  transformations, from the left when  m .ge. n and from the right when
C  m .lt. n.  The  upper triangular form  is then reduced to  bidiagonal
C  form by  Givens plane rotations and finally the  QR algorithm is used
C  to obtain the  singular value decomposition  of the  bidiagonal form.
C
C  3. Parameters
C     ==========
C
C  M      - INTEGER.
C
C           On entry, M must specify the number of rows of the matrix A.
C           M  must be  at least  zero.  When  M = 0  then an  immediate
C           return is effected.
C
C           Unchanged on exit.
C
C  N      - INTEGER.
C
C           On entry, N must specify the number of columns of the matrix
C           A.  N must be at least zero.  When  N = 0  then an immediate
C           return is effected.
C
C           Unchanged on exit.
C
C  A      - COMPLEX array of DIMENSION ( LDA, n ).
C
C           Before entry, the leading  M by N  part of the array  A must
C           contain the matrix  A  whose singular value decomposition is
C           required.
C
C           If  m .ge. n  and  WANTQ is .TRUE.  then on exit, the M by N
C           part of  A  will contain the first  n columns of the unitary
C           matrix  Q.
C
C           If  m .lt. n  and  WANTP is .TRUE.  then on exit, the M by N
C           part of  A  will contain  the first  m rows  of the  unitary
C           matrix  conjg( P' ).
C
C           If   m .ge. n  and   WANTQ is .FALSE.  and   WANTP is .TRUE.
C           then on exit, the  min( M, N ) by N  part of  A will contain
C           the  first   min( m, n )  rows   of   the   unitary   matrix
C           conjg( P' ).
C
C           Otherwise  the   M by N  part  of  A  is  used  as  internal
C           workspace.
C
C  LDA    - INTEGER.
C
C           On entry, LDA  must  specify  the  leading dimension of  the
C           array  A  as declared in the calling (sub) program. LDA must
C           be at least  m.
C
C           Unchanged on exit.
C
C  NCOLB  - On entry,  NCOLB  must specify the  number of columns of the
C           matrix  B  and must be at least  zero.  When  NCOLB = 0  the
C           array  B  is not referenced.
C
C  B      - COMPLEX array of DIMENSION ( LDB, ncolb ).
C
C           Before entry with  NCOLB .gt. 0, the leading M by NCOLB part
C           of the array  B  must contain the  matrix to be  transformed
C           and  on exit,  B  is overwritten  by the  m by ncolb  matrix
C           conjg( Q' )*B.
C
C  LDB    - INTEGER.
C
C           On entry, LDB  must  specify  the  leading dimension of  the
C           array  B  as declared  in the  calling  (sub) program.  When
C           NCOLB .gt. 0  then LDB must be at least  m.
C
C           Unchanged on exit.
C
C  WANTQ  - LOGICAL.
C
C           On entry,  WANTQ  must be .TRUE.  if the  left-hand singular
C           vectors are required. If  WANTQ is .FALSE.  then  the  array
C           Q  is not referenced.
C
C           Unchanged on exit.
C
C  Q      - COMPLEX array of DIMENSION ( LDQ, m ).
C
C           On exit  with  M .lt. N  and  WANTQ as .TRUE.,  the  leading
C           M by M part of the array  Q  will contain the unitary matrix
C           Q.  Otherwise the array  Q  is not referenced.
C
C  LDQ    - INTEGER.
C
C           On entry, LDQ  must  specify  the  leading dimension of  the
C           array  Q  as declared  in the  calling  (sub) program.  When
C           M .lt. N  and  WANTQ is .TRUE.,  LDQ  must  be at  least  m.
C
C           Unchanged on exit.
C
C  SV     - REAL array of DIMENSION at least ( min( m, n ) ).
C
C           On exit, the array  SV will contain the min( m, n ) diagonal
C           elements of the matrix  S.
C
C  WANTP  - LOGICAL.
C
C           On entry,  WANTP must be .TRUE.  if the  right-hand singular
C           vectors are  required.  If  WANTP is .FALSE.  then the array
C           PH  is not referenced.
C
C           Unchanged on exit.
C
C  PH     - COMPLEX array of DIMENSION ( LDPH, n ).
C
C           On exit  with  M .ge. N  and  WANTQ and WANTP as .TRUE., the
C           leading N by N part of the array PH will contain the unitary
C           matrix   conjg( P' ).   Otherwise  the  array   PH   is  not
C           referenced.
C
C  LDPH   - INTEGER.
C
C           On entry,  LDPH  must specify the  leading dimension  of the
C           array  PH  as declared  in the  calling (sub) program.  When
C           M .ge. N  and  WANTQ and WANTP are .TRUE.,  LDPH  must be at
C           least  n.
C
C           Unchanged on exit.
C
C  RWORK  - REAL array of DIMENSION at least ( max( 1, lrwork ) ), where
C           lrwork must satisfy:
C
C              lrwork = 2*( min( m, n ) - 1 ) when
C                 ncolb = 0  and  WANTQ and WANTP are .FALSE.,
C
C              lrwork = 3*( min( m, n ) - 1 ) when
C                 either  ncolb = 0  and  WANTQ is .FALSE.  and
C                 WANTP is .TRUE.,  or  WANTP is .FALSE.  and  one or
C                 both of  ncolb .gt. 0  and  WANTQ is .TRUE.
C
C              lrwork = 5*( min( m, n ) - 1 ) otherwise.
C
C           The array  RWORK  is used as  internal workspace by  F06XUF.
C           On exit,  RWORK( min( m, n )  ) contains the total number of
C           iterations taken by the QR algorithm.
C
C  CWORK  - COMPLEX array of DIMENSION at least ( lcwork ), where lcwork
C           must satisfy:
C
C              lcwork = n + max( n**2, ncolb )      when
C                 m .ge. n  and  WANTQ and WANTP are both .TRUE.
C
C              lcwork = n + max( n**2 + n, ncolb )  when
C                 m .ge. n  and  WANTQ is .TRUE., but WANTP is .FALSE.
C
C              lcwork = n + max( n, ncolb )         when
C                 m .ge. n  and  WANTQ is .FALSE.
C
C              lcwork = m**2 + m    when
C                 m .lt. n  and WANTP is .TRUE.
C
C              lcwork = m           when
C                 m .lt. n  and WANTP is .FALSE.
C
C           The array  CWORK  is used as  internal workspace by  F06XEF.
C
C  IFAIL  - INTEGER.
C
C           Before entry,  IFAIL  must contain one of the values -1 or 0
C           or 1 to specify noisy soft failure or noisy hard failure  or
C           silent soft failure. ( See Chapter P01 for further details.)
C
C           On successful  exit  IFAIL  will be  zero,  otherwise  IFAIL
C           will be set to a  non-zero value  indicating either  that an
C           input parameter  has been  incorrectly set,  or that the  QR
C           algorithm  is not  converging.  See  the  next  section  for
C           further details.
C
C  4. Diagnostic Information
C     ======================
C
C  IFAIL = -1
C
C     One or more of the following conditions holds:
C
C        M     .lt. 0
C        N     .lt. 0
C        LDA   .lt. M
C        NCOLB .lt. 0
C        LDB   .lt. M  and  NCOLB .gt. 0
C        LDQ   .lt. M  and  M     .lt. N  and  WANTQ is true
C        LDPH  .lt. N  and  M     .ge. N  and  WANTQ is true
C                                         and  WANTP is true
C
C  IFAIL .gt. 0
C
C     The  QR  algorithm  has  failed  to  converge  in   50*min( M, N )
C     iterations.  In this case  sv( 1 ), sv( 2 ), ..., sv( IFAIL )  may
C     not  have been found correctly  and the remaining  singular values
C     may not be the smallest. The matrix  A will nevertheless have been
C     factorized as  A = Q*E*conjg( P' ),  where the leading min( m, n )
C     by  min( m, n )  part of  E  is a bidiagonal matrix with  sv( 1 ),
C     sv( 2 ), ..., sv( min( m, n ) )   as  the  diagonal  elements  and
C     rwork( 1 ),  rwork( 2 ),  ...,  rwork( min( m, n ) - 1 )   as  the
C     super-diagonal elements.
C
C     This failure is not likely to occur.
C
C  If  on  entry,  IFAIL  was  either  -1 or 0  then  further diagnostic
C  information  will  be  output  on  the  error message  channel. ( See
C  routine  X04AAF. )
C
C  5. Further information
C     ===================
C
C  Following the use of this routine the rank of A may be estimated by
C  a call to the INTEGER function F06KLF.  The statement:
C
C     IRANK = F06KLF( MIN( M, N ), SV, 1, TOL )
C
C  returns  the value  ( k - 1 ), in  IRANK,  where  k  is the  smallest
C  integer  for  which   sv( k ) .lt. tol*sv( 1 ),   where  tol  is  the
C  tolerance supplied in  TOL, so that  IRANK is an estimate of the rank
C  of  S  and thus also of  A.  If  TOL is supplied as negative then the
C  relative machine precision ( see routine X02AJF ) is used in place of
C  TOL.
C
C
C  Nag Fortran 77 Auxiliary linear algebra routine.
C
C  -- Written on 26-November-1987.
C     Sven Hammarling, Nag Central Office.
C

F02XUF
      SUBROUTINE F02XUF(N,A,LDA,NCOLB,B,LDB,WANTQ,Q,LDQ,SV,WANTP,RWORK,
     *                  CWORK,IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.
C     MARK 14 REVISED. IER-792 (DEC 1989).
C
C  1. Purpose
C     =======
C
C  F02XUF  returns all, or part, of the  singular value decomposition of
C  a complex upper triangular matrix.
C
C  2. Description
C     ===========
C
C  The n by n upper triangular matrix R is factorized as
C
C     R = Q*S*conjg( P' ),
C
C  where Q and P are n by n unitary matrices and S is an n by n diagonal
C  matrix with  real non-negative  diagonal elements,  sv( 1 ), sv( 2 ),
C  ..., sv( n ), ordered such that
C
C     sv( 1 ) .ge. sv( 2 ) .ge. ... .ge. sv( n ) .ge. 0.
C
C  The  columns of  Q  are the  left-hand  singular vectors  of  R,  the
C  diagonal elements of  S are the singular values of  R and the columns
C  of  P are the right-hand singular vectors of  R.
C
C  Either or both of  Q and conjg( P' )  may be requested and the matrix
C  C given by
C
C     C = conjg( Q' )*B,
C
C  where B is an n by ncolb given matrix, may also be requested.
C
C  The  routine  obtains  the  singular  value  decomposition  by  first
C  reducing  R  to  bidiagonal form  by means of  Givens plane rotations
C  and  then  using  the  QR algorithm  to  obtain  the  singular  value
C  decomposition  of the  bidiagonal form.
C
C  3. Parameters
C     ==========
C
C  N      - INTEGER.
C
C           On entry,  N must specify the order of the matrix R.  N must
C           be  at  least zero. When  N = 0  then an immediate return is
C           effected.
C
C           Unchanged on exit.
C
C  A      - COMPLEX array of DIMENSION ( LDA, n ).
C
C           Before entry,  the leading  N by N  upper triangular part of
C           the array  A  must contain the  upper triangular  matrix  R.
C
C           If  WANTP is .TRUE.  then on exit, the N by N part of A will
C           contain the  n by n  unitary matrix  conjg( P' ),  otherwise
C           the  N by N  upper triangular part of  A is used as internal
C           workspace,  but  the  strictly lower triangular  part  of  A
C           is not referenced.
C
C  LDA    - INTEGER.
C
C           On entry, LDA  must  specify  the  leading dimension of  the
C           array  A  as declared in the calling (sub) program. LDA must
C           be at least  n.
C
C           Unchanged on exit.
C
C  NCOLB  - On entry,  NCOLB  must specify the  number of columns of the
C           matrix  B  and must be at least  zero.  When  NCOLB = 0  the
C           array  B  is not referenced.
C
C  B      - COMPLEX array of DIMENSION ( LDB, ncolb ).
C
C           Before entry with  NCOLB .gt. 0, the leading N by NCOLB part
C           of the array  B  must contain the  matrix to be  transformed
C           and  on exit,  B  is overwritten  by the  n by ncolb  matrix
C           conjg( Q' )*B.
C
C  LDB    - INTEGER.
C
C           On entry, LDB  must  specify  the  leading dimension of  the
C           array  B  as declared  in the  calling  (sub) program.  When
C           NCOLB .gt. 0  then LDB must be at least  n.
C
C           Unchanged on exit.
C
C  WANTQ  - LOGICAL.
C
C           On entry,  WANTQ must be .TRUE. if the matrix Q is required.
C           If  WANTQ is .FALSE.  then  the array  Q  is not referenced.
C
C           Unchanged on exit.
C
C  Q      - COMPLEX array of DIMENSION ( LDQ, n ).
C
C           On exit with  WANTQ as .TRUE.,  the leading  N by N  part of
C           the array  Q  will contain the unitary matrix  Q.  Otherwise
C           the array  Q  is not referenced.
C
C  LDQ    - INTEGER.
C
C           On entry, LDQ  must  specify  the  leading dimension of  the
C           array  Q  as declared  in the  calling  (sub) program.  When
C           WANTQ is .TRUE.,  LDQ  must be at least n.
C
C           Unchanged on exit.
C
C  SV     - REAL array of DIMENSION at least ( n ).
C
C           On exit, the array  SV will contain the  n diagonal elements
C           of the matrix S.
C
C  WANTP  - LOGICAL.
C
C           On entry,  WANTP must be .TRUE. if the matrix conjg( P' ) is
C           required,  in which case  conjg( P' )  is overwritten on the
C           array A, otherwise WANTP must be .FALSE..
C
C           Unchanged on exit.
C
C  RWORK  - REAL array of DIMENSION at least ( max( 1, lrwork ) ), where
C           lrwork must satisfy:
C
C              lrwork = 2*( n - 1 ) when
C                 ncolb = 0  and  WANTQ and WANTP are .FALSE.,
C
C              lrwork = 3*( n - 1 ) when
C                 either  ncolb = 0  and  WANTQ is .FALSE.  and
C                 WANTP is .TRUE.,  or  WANTP is .FALSE.  and  one or
C                 both of  ncolb .gt. 0  and  WANTQ is .TRUE.
C
C              lrwork = 5*( n - 1 ) otherwise.
C
C           The array  RWORK  is used as  internal workspace by  F06XUF.
C           On exit,  RWORK( n ) contains the total number of iterations
C           taken by the QR algorithm.
C
C  CWORK  - COMPLEX  array of  DIMENSION  at least  ( max( 1, n - 1 ) ).
C
C           The array  CWORK  is used as  internal workspace by  F06XUF.
C
C  IFAIL  - INTEGER.
C
C           Before entry,  IFAIL  must contain one of the values -1 or 0
C           or 1 to specify noisy soft failure or noisy hard failure  or
C           silent soft failure. ( See Chapter P01 for further details.)
C
C           On successful  exit  IFAIL  will be  zero,  otherwise  IFAIL
C           will be set to a  non-zero value  indicating either  that an
C           input parameter  has been  incorrectly set,  or that the  QR
C           algorithm  is not  converging.  See  the  next  section  for
C           further details.
C
C  4. Diagnostic Information
C     ======================
C
C  IFAIL = -1
C
C     One or more of the following conditions holds:
C
C        N     .lt. 0
C        LDA   .lt. N
C        NCOLB .lt. 0
C        LDB   .lt. N  and  NCOLB .gt. 0
C        LDQ   .lt. N  and  WANTQ  is  true
C
C  IFAIL .gt. 0
C
C     The  QR algorithm  has failed to converge in  50*N iterations.  In
C     this  case  sv( 1 ), sv( 2 ), ..., sv( IFAIL )  may not  have been
C     found correctly  and the remaining singular values  may not be the
C     smallest.  The matrix  R will nevertheless have been factorized as
C     R = Q*E*conjg( P' ),   where   E   is  a  bidiagonal  matrix  with
C     sv( 1 ), sv( 2 ), ..., sv( n )   as  the  diagonal  elements   and
C     rwork( 1 ), rwork( 2 ), ..., rwork( n - 1 )  as the super-diagonal
C     elements.
C
C     This failure is not likely to occur.
C
C  If  on  entry,  IFAIL  was  either  -1 or 0  then  further diagnostic
C  information  will  be  output  on  the  error message  channel. ( See
C  routine  X04AAF. )
C
C  5. Further information
C     ===================
C
C  Following the use of this routine the rank of R may be estimated by
C  a call to the INTEGER function F06KLF.  The statement:
C
C     IRANK = F06KLF( N, SV, 1, TOL )
C
C  returns  the value  ( k - 1 ), in  IRANK,  where  k  is the  smallest
C  integer  for  which   sv( k ) .lt. tol*sv( 1 ),   where  tol  is  the
C  tolerance supplied in  TOL, so that  IRANK is an estimate of the rank
C  of  S  and thus also of  R.  If  TOL is supplied as negative then the
C  relative machine precision ( see routine X02AJF ) is used in place of
C  TOL.
C
C
C  Nag Fortran 77 Auxiliary linear algebra routine.
C
C  -- Written on 25-November-1987.
C     Sven Hammarling, Nag Central Office.
C

F03AAF
      SUBROUTINE F03AAF(A,IA,N,DET,WKSPCE,IFAIL)
C     MARK 15 RE-ISSUE. NAG COPYRIGHT 1991.
C
C     Determinant of real matrix.
C     1st August 1971
C
C     Rewritten to call F07ADG, a modified version of LAPACK routine
C     SGETRF/F07ADF; new IFAIL exit inserted for illegal input
C     parameters; error messages inserted. February 1991.
C

F03ABF
      SUBROUTINE F03ABF(A,IA,N,DET,WKSPCE,IFAIL)
C     MARK 15 RE-ISSUE. NAG COPYRIGHT 1991.
C
C     Determinant of real symmetric positive definite matrix
C     1st August 1971
C
C     Rewritten to call LAPACK routine SPOTRF/F07FDF;
C     new IFAIL exit inserted for illegal input parameters;
C     error messages inserted. February 1991.
C

F03ACF
      SUBROUTINE F03ACF(A,IA,N,M,DET,RL,IL,M1,LFAIL)
C     MARK 2 RELEASE. NAG COPYRIGHT 1972
C     MARK 3 REVISED.
C     MARK 4.5 REVISED
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C
C     DETERMINANT OF REAL POSITIVE DEFINITE SYMMETRIC BAND MATRIX
C     1ST AUGUST 1971
C

F03ADF
      SUBROUTINE F03ADF(A,IA,N,DETR,DETI,WKSPCE,IFAIL)
C     MARK 15 RE-ISSUE. NAG COPYRIGHT 1991.
C
C     Determinant of complex matrix
C     1st August 1971
C
C     Rewritten to call F07ARG, a modified version of LAPACK routine
C     CGETRF/F07ARF; new IFAIL exit inserted for illegal input
C     parameters; error messages inserted. February 1991.
C

F03AEF
      SUBROUTINE F03AEF(N,A,IA,P,D1,ID,IFAIL)
C     MARK 15 RE-ISSUE. NAG COPYRIGHT 1991.
C
C     CHOLDET1
C     The upper triangle of a positive definite symmetric matrix,
C     A, is stored in the upper triangle of an N*N array A(I,J),
C     I=1,N, J=1,N. The Cholesky decomposition A = LU, where
C     U is the transpose of L, is performed and stored in the
C     remainder of the array A except for the reciprocals of the
C     diagonal elements which are stored in P(I), I = 1,N,
C     instead of the elements themselves. A is retained so that
C     the solution obtained can be subsequently improved. The
C     determinant, D1 * 2.0**ID, of A is also computed. The
C     subroutine will fail if A, modified by the rounding errors,
C     is not positive definite.
C     1st December 1971
C
C     Rewritten to call LAPACK routine SPOTRF/F07ADF; new IFAIL
C     exit inserted for illegal input parameters; error messages
C     inserted. February 1991.
C

F03AFF
      SUBROUTINE F03AFF(N,EPS,A,IA,D1,ID,P,IFAIL)
C     MARK 15 RE-ISSUE. NAG COPYRIGHT 1991.
C
C     UNSYMDET
C     The unsymmetric matrix, A, is stored in the N*N array A(I,J),
C     I=1,N, J=1,N. The decomposition A=LU, where L is a
C     lower triangular matrix and U is a unit upper triangular
C     matrix, is performed and overwritten on A, omitting the unit
C     diagonal of U. A record of any interchanges made to the rows
C     of A is kept in P(I), I=1,N, such that the I-th row and
C     the P(I)-th row were interchanged at the I-th step. The
C     determinant, D1 * 2.0**ID, of A is also computed. The
C     subroutine will fail if A, modified by the rounding errors, is
C     singular or almost singular.
C     1st December 1971
C
C     Rewritten to call F07ADG, a modified version of LAPACK routine
C     SGETRF/F07ADF; new IFAIL exit inserted for illegal input
C     parameters; error messages inserted. February 1991.
C

F04AAF
      SUBROUTINE F04AAF(A,IA,B,IB,N,M,C,IC,WKSPCE,IFAIL)
C     MARK 15 RE-ISSUE. NAG COPYRIGHT 1991.
C
C     Approximate solution of a set of real linear equations
C     with multiple right hand sides.
C     1st August 1971
C
C     Rewritten to call F07ADG and F07AEG, modified versions of LAPACK
C     routines SGETRF/F07ADF and SGETRS/F07AEF; new IFAIL exit inserted
C     for illegal input parameters; error messages inserted.
C     February 1991.
C

F04ABF
      SUBROUTINE F04ABF(A,IA,B,IB,N,M,C,IC,WKSPCE,BB,IBB,IFAIL)
C     MARK 15 RE-ISSUE. NAG COPYRIGHT 1991.
C
C     Accurate solution of a set of real symmetric positive
C     definite linear equations with multiple right hand sides.
C     1st August 1971
C
C     Rewritten to call LAPACK routine SPOTRF/F07FDF;
C     new IFAIL exit inserted for illegal input parameters;
C     error messages inserted. February 1991.
C

F04ACF
      SUBROUTINE F04ACF(A,IA,B,IB,N,M,LR,C,IC,RL,IL,M1,LFAIL)
C     MARK 2 RELEASE. NAG COPYRIGHT 1972
C     MARK 3 REVISED.
C     MARK 4.5 REVISED
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     APPROXIMATE SOLUTION OF A SET OF REAL SYMMETRIC POSITIVE
C     DEFINITE BAND LINEAR EQUATIONS WITH MULTIPLE RIGHT
C     HAND SIDES.
C     1ST AUGUST 1971
C

F04ADF
      SUBROUTINE F04ADF(A,IA,B,IB,N,M,C,IC,WKSPCE,IFAIL)
C     MARK 15 RE-ISSUE. NAG COPYRIGHT 1991.
C
C     Approximate solution of a set of complex linear
C     equations with multiple right hand sides.
C     1st August 1971
C
C     Rewritten to call F07ARG and F07ASG, modified versions of LAPACK
C     routines CGETRF/F07ARF and CGETRS/F07ASF; new IFAIL exit inserted
C     for illegal input parameters; error messages inserted.
C     February 1991.
C

F04AEF
      SUBROUTINE F04AEF(A,IA,B,IB,N,M,C,IC,WKSPCE,AA,IAA,BB,IBB,IFAIL)
C     MARK 15 RE-ISSUE. NAG COPYRIGHT 1991.
C
C     Accurate solution of a set of real linear equations
C     with multiple right hand sides.
C     1st August 1971
C
C     Rewritten to call F07ADG, a modified version of LAPACK routine
C     SGETRF/F07ADF; new IFAIL exit inserted for illegal input
C     parameters; error messages inserted. February 1991.
C

F04AFF
      SUBROUTINE F04AFF(N,IR,A,IA,P,B,IB,EPS,X,IX,BB,IBB,L,IFAIL)
C     MARK 2 RELEASE. NAG COPYRIGHT 1972
C     MARK 3 REVISED.
C     MARK 4.5 REVISED
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. IER-637 (APR 1988).
C     ACCSOLVE
C     SOLVES AX=B WHERE A IS AN N*N POSITIVE DEFINITE SYMMETRIC
C     MATRIX AND B IS AN N*IR MATRIX OF RIGHT HAND SIDES, USING THE
C     SUBROUTINE F04AGF . THE SUBROUTINE MUST BY PRECEDED BY
C     F03AEF IN WHICH L IS PRODUCED IN A(I,J) AND P(I). THE
C     RESIDUALS BB=B-AX ARE CALCULATED AND AD=BB IS SOLVED,
C     OVERWRITING D ON BB. THE REFINEMENT IS REPEATED, AS LONG AS
C     THE MAXIMUM CORRECTION AT ANY STAGE IS LESS THAN HALF THAT AT
C     THE PREVIOUS STAGE, UNTIL THE MAXIMUM CORRECTION IS LESS
C     THAN 2 EPS TIMES THE MAXIMUM X. EXITS WITH IFAIL = 1 IF
C     THE SOLUTION FAILS TO IMPROVE. L IS THE NUMBER OF
C     ITERATIONS.
C     ADDITIONAL PRECISION INNERPRODUCTS ARE ABSOLUTELY NECESSARY.
C     1ST DECEMBER 1971
C

F04AGF
      SUBROUTINE F04AGF(N,IR,A,IA,P,B,IB,X,IX)
C     MARK 2 RELEASE. NAG COPYRIGHT 1972
C     MARK 4.5 REVISED
C     MARK 11 REVISED. VECTORISATION (JAN 1984).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 12 REVISED. EXTENDED BLAS (JUNE 1986)
C
C     CHOLSOL1
C     SOLVES AX=B, WHERE A IS A POSITIVE DEFINITE SYMMETRIC MATRIX
C     AND B IS AN N*IR MATRIX OF IR RIGHT-HAND SIDES. THE
C     SUBROUTINE
C     F04AGF MUST BY PRECEDED BY F03AEF IN WHICH L IS
C     PRODUCED IN A(I,J) AND P(I), FROM A. AX=B IS SOLVED IN TWO
C     STEPS, LY=B AND UX=Y, AND X IS OVERWRITTEN ON Y.
C     1ST AUGUST 1971
C

F04AHF
      SUBROUTINE F04AHF(N,IR,A,IA,AA,IAA,P,B,IB,EPS,X,IX,BB,IBB,L,IFAIL)
C     MARK 2 RELEASE. NAG COPYRIGHT 1972
C     MARK 3 REVISED.
C     MARK 4 REVISED.
C     MARK 4.5 REVISED
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     UNSYMACCSOLVE
C     SOLVES AX=B WHERE A IS AN N*N UNSYMMETRIC MATRIX AND B IS AN
C     N*IR MATRIX OF RIGHT HAND SIDES, USING THE SUBROUTINE F04AJF.
C     THE SUBROUTINE MUST BY PRECEDED BY F03AFF IN WHICH L AND U
C     ARE PRODUCED IN AA(I,J) AND THE INTERCHANGES IN P(I). THE
C     RESIDUALS BB=B-AX ARE CALCULATED AND AD=BB IS SOLVED, OVER-
C     WRITING D ON BB. THE REFINEMENT IS REPEATED, AS LONG AS THE
C     MAXIMUM CORRECTION AT ANY STAGE IS LESS THAN HALF THAT AT THE
C     PREVIOUS STAGE, UNTIL THE MAXIMUM CORRECTION IS LESS THAN 2
C     EPS TIMES THE MAXIMUM X. SETS IFAIL = 1 IF THE SOLUTION FAILS
C     TO IMPROVE, ELSE IFAIL = 0. L IS THE NUMBER OF ITERATIONS.
C     ADDITIONAL PRECISION INNERPRODUCTS ARE ABSOLUTELY NECESSARY.
C     1ST DECEMBER 1971
C

F04AJF
      SUBROUTINE F04AJF(N,IR,A,IA,P,B,IB)
C     MARK 2 RELEASE. NAG COPYRIGHT 1972
C     MARK 4 REVISED.
C     MARK 4.5 REVISED
C     MARK 11 REVISED. VECTORISATION (JAN 1984).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 12 REVISED. EXTENDED BLAS (JUNE 1986)
C
C     UNSYMSOL
C     SOLVES AX=B, WHERE A IS AN UNSYMMETRIC MATRIX AND B IS AN
C     N*IR
C     MATRIX OF IR RIGHT-HAND SIDES. THE SUBROUTINE F04AJF MUST BY
C     PRECEDED BY F03AFF IN WHICH L AND U ARE PRODUCED IN A(I,J),
C     FROM A, AND THE RECORD OF THE INTERCHANGES IS PRODUCED IN
C     P(I). AX=B IS SOLVED IN THREE STEPS, INTERCHANGE THE
C     ELEMENTS OF B, LY=B AND UX=Y. THE MATRICES Y AND THEN X ARE
C     OVERWRITTEN ON B.
C     1ST AUGUST 1971
C

F04AMF
      SUBROUTINE F04AMF(A,IA,X,IX,B,IB,M,N,IP,ETA,QR,IQR,ALPHA,E,Y,Z,R,
     *                  IPIVOT,IFAIL)
C     MARK 2 RELEASE. NAG COPYRIGHT 1972
C     MARK 3 REVISED.
C     MARK 4.5 REVISED
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 16A REVISED. IER-1003 (JUN 1993).
C     LEAST SQUARES SOLUTION
C     THE ARRAY A(M,N) CONTAINS THE GIVEN MATRIX OF AN
C     OVERDETERMINED SYSTEM OF M LINEAR EQUATIONS IN N UNKNOWNS
C     (M.GE.N). FOR THE IP RIGHT HAND SIDES GIVEN AS THE COLUMNS
C     OF THE ARRAY B(M,IP), THE LEAST SQUARES SOLUTIONS ARE
C     COMPUTED AND STORED AS THE COLUMNS OF THE ARRAY X(N,IP).
C     IF RANK(A).LT.N THEN THE PROBLEM IS LEFT UNSOLVED AND IFAIL
C     IS SET EQUAL TO 1. IN EITHER CASE A AND B ARE
C     LEFT INTACT. ETA IS THE RELATIVE MACHINE PRECISION.
C     ADDITIONAL PRECISION INNERPRODUCTS ARE ABSOLUTELY NECESSARY.
C     1ST. MARCH  1972
C

F04ARF
      SUBROUTINE F04ARF(A,IA,B,N,C,WKS,IFAIL)
C     MARK 15 RE-ISSUE. NAG COPYRIGHT 1991.
C
C     Approximate solution of a set of real linear
C     equations with one right hand side.
C     1st. April 1973
C
C     Rewritten to call F07ADG and F07AEG, modified versions of LAPACK
C     routines SGETRF/F07ADF and SGETRS/F07AEF; new IFAIL exit inserted
C     for illegal input parameters; error messages inserted.
C     February 1991.
C

F04ASF
      SUBROUTINE F04ASF(A,IA,B,N,C,WK1,WK2,IFAIL)
C     MARK 15 RE-ISSUE. NAG COPYRIGHT 1991.
C     MARK 16 REVISED. IER-1004 (JUN 1993).
C
C     Accurate solution of a set of real symmetric positive
C     definite linear equations with one right hand side.
C     1st April 1973
C
C     Rewritten to call LAPACK routine SPOTRF/F07FDF;
C     new IFAIL exit inserted for illegal input parameters;
C     error messages inserted. February 1991.
C

F04ATF
      SUBROUTINE F04ATF(A,IA,B,N,C,AA,IAA,WKS1,WKS2,IFAIL)
C     MARK 15 RE-ISSUE. NAG COPYRIGHT 1991.
C
C     Accurate solution of a set of real linear equations
C     with one right side.
C     1st. April 1973
C
C     Rewritten to call F07ADG, a modified version of LAPACK routine
C     SGETRF/F07ADF; new IFAIL exit inserted for illegal input
C     parameters; error messages inserted. February 1991.
C

F04AXF
      SUBROUTINE F04AXF(N,A,LICN,ICN,IKEEP,RHS,W,MTYPE,IDISP,RESID)
C     MARK 7 RELEASE. NAG COPYRIGHT 1978
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     DERIVED FROM HARWELL LIBRARY ROUTINE MA28C
C
C     THE PARAMETERS ARE AS FOLLOWS ....
C     N     INTEGER  ORDER OF MATRIX  NOT ALTERED BY SUBROUTINE.
C     A     REAL ARRAY  LENGTH LICN.  THE SAME ARRAY AS WAS USED
C     .     IN THE MOST RECENT CALL TO F01BRF OR F01BSF.
C     LICN  INTEGER  LENGTH OF ARRAYS A AND ICN.  NOT ALTERED BY
C     .     SUBROUTINE.
C     ICN   INTEGER ARRAY  LENGTH LICN.  SAME ARRAY AS OUTPUT FROM
C     .     F01BRF.  UNCHANGED BY F04AXF.
C     IKEEP INTEGER ARRAY  LENGTH 5*N.  SAME ARRAY AS OUTPUT FROM
C     .     F01BRF.  UNCHANGED BY F04AXF.
C     RHS   REAL ARRAY  LENGTH N.  ON ENTRY, IT HOLDS THE
C     .     RIGHT HAND SIDE.  ON EXIT, THE SOLUTION VECTOR.
C     W     REAL ARRAY  LENGTH N. USED AS WORKSPACE BY
C     .     F04AXZ.
C     MTYPE INTEGER  USED TO TELL F04AXZ TO SOLVE THE DIRECT
C     .     EQUATION (MTYPE=1) OR ITS TRANSPOSE (MTYPE.NE.1).
C     IDISP INTEGER ARRAY LENGTH 2.  SAME ARRAY AS OUTPUT BY
C     .     F01BRF.  IT IS UNCHANGED BY F04AXF.
C     RESID REAL VARIBLE. RETURNS MAXIMUM RESIDUAL OF EQUATIONS
C     .     WHERE PIVOT WAS ZERO.
C
C
C     F04AXZ PREFORMS THE SOLUTION OF THE SET OF EQUATIONS

F04EAF
      SUBROUTINE F04EAF(N,D,DU,DL,B,IFAIL)
C     MARK 11 RELEASE. NAG COPYRIGHT 1983.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 14A REVISED. IER-688 (DEC 1989).
C
C     F04EAF SOLVES THE EQUATIONS
C
C     T*X = B ,
C
C     WHERE T IS AN N BY N TRIDIAGONAL MATRIX, BY GAUSSIAN ELIMINATION
C     WITH PARTIAL PIVOTING.
C
C     FOR A DESCRIPTION OF THE PARAMETERS AND USE OF THIS ROUTINE SEE
C     THE NAG LIBRARY MANUAL.
C
C     -- WRITTEN ON 14-JANUARY-1983.  S.J.HAMMARLING.
C
C     NAG FORTRAN 66 BLACK BOX ROUTINE.
C

F04FAF
      SUBROUTINE F04FAF(JOB,N,D,E,B,IFAIL)
C     MARK 11 RELEASE. NAG COPYRIGHT 1983.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 14 REVISED. IER-741 (DEC 1989).
C
C     F04FAF SOLVES THE EQUATIONS
C
C     T*X = B ,
C
C     WHERE T IS AN N BY N SYMMETRIC POSITIVE DEFINITE TRIDIAGONAL
C     MATRIX, BY A MODIFIED CHOLESKY ALGORITHM.
C
C     FOR A DESCRIPTION OF THE PARAMETERS AND USE OF THIS ROUTINE SEE
C     THE NAG LIBRARY MANUAL.
C
C     -- WRITTEN ON 17-JANUARY-1983.  S.J.HAMMARLING.
C

F04FEF
      SUBROUTINE F04FEF(N,T,X,WANTP,P,WANTV,V,VLAST,WORK,IFAIL)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C     -- Written on 9-February-1990.
C     This version dated 29-December-1990.
C     Sven Hammarling, Nag Ltd.
C

F04FFF
      SUBROUTINE F04FFF(N,T,B,X,WANTP,P,WORK,IFAIL)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C     -- Written on 1-December-1990.
C     This version dated 29-December-1990.
C     Sven Hammarling, Nag Ltd.
C

F04JAF
      SUBROUTINE F04JAF(M,N,A,NRA,B,TOL,SIGMA,IRANK,WORK,LWORK,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 16 REVISED. IER-1005 (JUN 1993).
C     WRITTEN BY S. HAMMARLING, MIDDLESEX POLYTECHNIC (SVDLS1)
C
C     F04JAF RETURNS THE N ELEMENT VECTOR X, OF MINIMAL
C     LENGTH, THAT MINIMIZES THE EUCLIDEAN LENGTH OF THE M
C     ELEMENT VECTOR R GIVEN BY
C
C     R = B-A*X ,
C
C     WHERE A IS AN M*N (M.GE.N) MATRIX AND B IS AN M ELEMENT
C     VECTOR. X IS OVERWRITTEN ON B.
C
C     THE SOLUTION IS OBTAINED VIA A SINGULAR VALUE
C     DECOMPOSITION (SVD) OF THE MATRIX A GIVEN BY
C
C     A = Q*(D)*(P**T) ,
C           (0)
C
C     WHERE Q AND P ARE ORTHOGONAL AND D IS A DIAGONAL MATRIX WITH
C     NON-NEGATIVE DIAGONAL ELEMENTS, THESE BEING THE SINGULAR
C     VALUES OF A.
C
C     INPUT PARAMETERS.
C
C     M     - NUMBER OF ROWS OF A. M MUST BE AT LEAST N.
C
C     N     - NUMBER OF COLUMNS OF A. N MUST BE AT LEAST UNITY.
C
C     A     - AN M*N REAL MATRIX.
C
C     NRA   - ROW DIMENSION OF A AS DECLARED IN THE CALLING PROGRAM.
C             NRA MUST BE AT LEAST M.
C
C     B     - AN M ELEMENT REAL VECTOR.
C
C     TOL   - A RELATIVE TOLERANCE USED TO DETERMINE THE RANK OF A.
C             TOL SHOULD BE CHOSEN AS APPROXIMATELY THE
C             LARGEST RELATIVE ERROR IN THE ELEMENTS OF A.
C             FOR EXAMPLE IF THE ELEMENTS OF A ARE CORRECT
C             TO ABOUT 4 SIGNIFICANT FIGURES THEN TOL
C             SHOULD BE CHOSEN AS ABOUT 5.0*10.0**(-4).
C
C     IFAIL - THE USUAL FAILURE PARAMETER. IF IN DOUBT SET
C             IFAIL TO ZERO BEFORE CALLING THIS ROUTINE.
C
C     OUTPUT PARAMETERS.
C
C     A     - THE TOP N*N PART OF A WILL CONTAIN THE
C             ORTHOGONAL MATRIX P**T OF THE SVD.
C             THE REMAINDER OF A IS USED FOR INTERNAL WORKSPACE.
C
C     B     - THE FIRST N ELEMENTS OF B WILL CONTAIN THE
C             MINIMAL LEAST SQUARES SOLUTION VECTOR X.
C
C     SIGMA - IF M IS GREATER THAN IRANK THEN SIGMA WILL CONTAIN THE
C             STANDARD ERROR GIVEN BY
C             SIGMA=L(R)/SQRT(M-IRANK), WHERE L(R) DENOTES
C             THE EUCLIDEAN LENGTH OF THE RESIDUAL VECTOR
C             R. IF M=IRANK THEN SIGMA IS RETURNED AS ZERO.
C
C     IRANK - THE RANK OF THE MATRIX A.
C
C     IFAIL - ON NORMAL RETURN IFAIL WILL BE ZERO.
C             IN THE UNLIKELY EVENT THAT THE QR-ALGORITHM
C             FAILS TO FIND THE SINGULAR VALUES IN 50*N
C             ITERATIONS THEN IFAIL IS SET TO 2.
C             IF AN INPUT PARAMETER IS INCORRECTLY SUPPLIED
C             THEN IFAIL IS SET TO UNITY.
C
C     WORKSPACE PARAMETERS.
C
C     WORK  - A 4*N ELEMENT VECTOR.
C             ON RETURN THE FIRST N ELEMENTS OF WORK WILL
C             CONTAIN THE SINGULAR VALUES OF A ARRANGED IN
C             DESCENDING ORDER.
C             WORK(N+1) WILL CONTAIN THE TOTAL NUMBER OF ITERATIONS
C             TAKEN BY THE QR-ALGORITHM.
C
C     LWORK - THE LENGTH OF THE VECTOR WORK. LWORK MUST BE
C             AT LEAST 4*N.
C

F04JDF
      SUBROUTINE F04JDF(M,N,A,NRA,B,TOL,SIGMA,IRANK,WORK,LWORK,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     WRITTEN BY S. HAMMARLING, MIDDLESEX POLYTECHNIC (SVDLS2)
C
C     F04JDF RETURNS THE N ELEMENT VECTOR X, OF MINIMAL
C     LENGTH, THAT MINIMIZES THE EUCLIDEAN LENGTH OF THE M
C     ELEMENT VECTOR R GIVEN BY
C
C     R = B-A*X ,
C
C     WHERE A IS AN M*N (M.LE.N) MATRIX AND B IS AN M ELEMENT
C     VECTOR. X IS OVERWRITTEN ON B.
C
C     THE SOLUTION IS OBTAINED VIA A SINGULAR VALUE
C     DECOMPOSITION (SVD) OF THE MATRIX A GIVEN BY
C
C     A = Q*(D 0)*(P**T) ,
C
C     WHERE Q AND P ARE ORTHOGONAL AND D IS A DIAGONAL MATRIX WITH
C     NON-NEGATIVE DIAGONAL ELEMENTS, THESE BEING THE SINGULAR
C     VALUES OF A.
C
C     INPUT PARAMETERS.
C
C     M     - NUMBER OF ROWS OF A. M MUST BE AT LEAST UNITY.
C
C     N     - NUMBER OF COLUMNS OF A. N MUST BE AT LEAST M.
C
C     A     - AN M*N REAL MATRIX.
C
C     NRA   - ROW DIMENSION OF A AS DECLARED IN THE CALLING PROGRAM.
C             NRA MUST BE AT LEAST M.
C
C     B     - AN N ELEMENT REAL VECTOR.
C             THE FIRST M ELEMENTS OF B MUST CONTAIN THE
C             VECTOR B OF THE LEAST SQUARES PROBLEM.
C
C
C     TOL   - A RELATIVE TOLERANCE USED TO DETERMINE THE RANK OF A.
C             TOL SHOULD BE CHOSEN AS APPROXIMATELY THE
C             LARGEST RELATIVE ERROR IN THE ELEMENTS OF A.
C             FOR EXAMPLE IF THE ELEMENTS OF A ARE CORRECT
C             TO ABOUT 4 SIGNIFICANT FIGURES THEN TOL
C             SHOULD BE CHOSEN AS ABOUT 5.0*10.0**(-4).
C
C     IFAIL - THE USUAL FAILURE PARAMETER. IF IN DOUBT SET
C             IFAIL TO ZERO BEFORE CALLING THIS ROUTINE.
C
C     OUTPUT PARAMETERS.
C
C     A     - A WILL CONTAIN THE FIRST M ROWS OF THE
C             ORTHOGONAL MATRIX P**T OF THE SVD.
C
C     B     - B WILL CONTAIN THE MINIMAL LEAST SQUARES
C             SOLUTION VECTOR X.
C
C     SIGMA - IF M IS GREATER THAN IRANK THEN SIGMA WILL CONTAIN THE
C             STANDARD ERROR GIVEN BY
C             SIGMA=L(R)/SQRT(M-IRANK), WHERE L(R) DENOTES
C             THE EUCLIDEAN LENGTH OF THE RESIDUAL VECTOR
C             R. IF M=IRANK THEN SIGMA IS RETURNED AS ZERO.
C
C     IRANK - THE RANK OF THE MATRIX A.
C
C     IFAIL - ON NORMAL RETURN IFAIL WILL BE ZERO.
C             IN THE UNLIKELY EVENT THAT THE QR-ALGORITHM
C             FAILS TO FIND THE SINGULAR VALUES IN 50*M
C             ITERATIONS THEN IFAIL IS SET TO 2.
C             IF AN INPUT PARAMETER IS INCORRECTLY SUPPLIED
C             THEN IFAIL IS SET TO UNITY.
C
C     WORKSPACE PARAMETERS.
C
C     WORK  - AN (M*M+4*M) ELEMENT VECTOR.
C             ON RETURN THE FIRST M ELEMENTS OF WORK WILL
C             CONTAIN THE SINGULAR VALUES OF A ARRANGED IN
C             DESCENDING ORDER. WORK(M+1) WILL CONTAIN THE
C             TOTAL NUMBER OF ITERATIONS TAKEN BY THE
C             QR-ALGORITHM.
C
C     LWORK - THE LENGTH OF THE VECTOR WORK.
C             LWORK MUST BE AT LEAST M*M+4*M.
C

F04JGF
      SUBROUTINE F04JGF(M,N,A,NRA,B,TOL,SVD,SIGMA,IRANK,WORK,LWORK,
     *                  IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     WRITTEN BY S. HAMMARLING, MIDDLESEX POLYTECHNIC (SVDLS4)
C
C     F04JGF RETURNS THE N ELEMENT VECTOR X, OF MINIMAL
C     LENGTH, THAT MINIMIZES THE EUCLIDEAN LENGTH OF THE M
C     ELEMENT VECTOR R GIVEN BY
C
C     R = B-A*X ,
C
C     WHERE A IS AN M*N (M.GE.N) MATRIX AND B IS AN M ELEMENT
C     VECTOR. X IS OVERWRITTEN ON B.
C
C     THE HOUSEHOLDER QU FACTORIZATION OF A GIVEN BY
C
C     A = Q*(U) ,
C           (0)
C
C     WHERE Q IS ORTHOGONAL AND U IS UPPER TRIANGULAR, IS
C     COMPUTED FIRST.
C
C     IF U IS NON-SINGULAR THEN THE LEAST SQUARES SOLUTION, X,
C     IS OBTAINED VIA THE QU FACTORIZATION.
C
C     ON THE OTHER HAND IF U IS SINGULAR THEN THE SINGULAR VALUE
C     DECOMPOSITION (SVD) OF U IS COMPUTED. THIS, TOGETHER
C     WITH THE QU FACTORIZATION, GIVES THE SVD OF A GIVEN BY
C
C     A = Q1*(D)*(P**T) ,
C            (0)
C
C     WHERE Q1 AND P ARE ORTHOGONAL AND D IS A DIAGONAL MATRIX WITH
C     NON-NEGATIVE DIAGONAL ELEMENTS, THESE BEING THE SINGULAR
C     VALUES OF A.
C
C     IN THIS CASE THE MINIMAL LEAST SQUARES SOLUTION, X, IS
C     OBTAINED VIA THE SVD OF A.
C
C     DECISIONS ON SINGULARITY AND RANK ARE BASED UPON THE
C     USER SUPPLIED PARAMETER TOL.
C
C     INPUT PARAMETERS.
C
C     M     - NUMBER OF ROWS OF A. M MUST BE AT LEAST N.
C
C     N     - NUMBER OF COLUMNS OF A. N MUST BE AT LEAST UNITY.
C
C     A     - AN M*N REAL MATRIX.
C
C     NRA   - ROW DIMENSION OF A AS DECLARED IN THE CALLING PROGRAM.
C             NRA MUST BE AT LEAST M.
C
C     B     - AN M ELEMENT REAL VECTOR.
C
C     TOL   - A RELATIVE TOLERANCE USED TO DETERMINE THE RANK OF A.
C             TOL SHOULD BE CHOSEN AS APPROXIMATELY THE
C             LARGEST RELATIVE ERROR IN THE ELEMENTS OF A.
C             FOR EXAMPLE IF THE ELEMENTS OF A ARE CORRECT
C             TO ABOUT 4 SIGNIFICANT FIGURES THEN TOL
C             SHOULD BE CHOSEN AS ABOUT 5.0*10.0**(-4).
C
C     IFAIL - THE USUAL FAILURE PARAMETER. IF IN DOUBT SET
C             IFAIL TO ZERO BEFORE CALLING THIS ROUTINE.
C
C
C     OUTPUT PARAMETERS.
C
C     A     - IF SVD IS RETURNED AS .TRUE. THEN THE TOP N*N
C             PART OF A CONTAINS THE ORTHOGONAL MATRIX P**T
C             OF THE SVD OF A. IN THIS CASE THE REMAINDER
C             OF A IS USED FOR INTERNAL WORKSPACE.
C             IF SVD IS RETURNED AS .FALSE. THEN A,
C             TOGETHER WITH THE FIRST N ELEMENTS OF THE
C             VECTOR WORK, CONTAINS DETAILS OF THE
C             HOUSEHOLDER QU FACTORIZATION OF A AS RETURNED
C             FROM  ROUTINE F01QAF.
C
C     B     - THE FIRST N ELEMENTS OF B WILL CONTAIN THE
C             SOLUTION VECTOR X.
C
C     SVD   - WILL BE .TRUE. IF THE SVD OF A HAS BEEN
C             COMPUTED AND WILL BE .FALSE. IF ONLY THE QU
C             FACTORIZATION OF A HAS BEEN COMPUTED.
C             IT SHOULD BE NOTED THAT IT IS POSSIBLE FOR SVD TO BE
C             .TRUE. AND FOR IRANK TO BE N. SUCH AN
C             OCCURANCE MEANS THAT THE MATRIX U ONLY JUST
C             FAILED THE TEST FOR NON-SINGULARITY.
C
C     SIGMA - IF M IS GREATER THAN IRANK THEN SIGMA WILL CONTAIN THE
C             STANDARD ERROR GIVEN BY
C             SIGMA=L(R)/SQRT(M-IRANK), WHERE L(R) DENOTES
C             THE EUCLIDEAN LENGTH OF THE RESIDUAL VECTOR
C             R. IF M=IRANK THEN SIGMA IS RETURNED AS ZERO.
C
C     IRANK - THE RANK OF THE MATRIX A.
C
C     IFAIL - ON NORMAL RETURN IFAIL WILL BE ZERO.
C             IN THE UNLIKELY EVENT THAT THE QR ALGORITHM
C             FAILS TO FIND THE SINGULAR VALUES IN 50*N
C             ITERATIONS THEN IFAIL IS SET TO 2. THIS
C             FAILURE CANNOT OCCUR IF THE SVD OF A IS NOT
C             COMPUTED.
C             IF AN INPUT PARAMETER IS INCORRECTLY SUPPLIED
C             THEN IFAIL IS SET TO UNITY.
C
C     WORKSPACE PARAMETERS.
C
C     WORK  - A 4*N ELEMENT VECTOR.
C             IF SVD IS RETURNED AS .TRUE. THEN THE FIRST N
C             ELEMENTS OF WORK WILL CONTAIN THE SINGULAR
C             VALUES OF A ARRANGED IN DESCENDING ORDER.
C             IF SVD IS RETURNED AS .FALSE. THEN THE FIRST
C             N ELEMENTS OF WORK WILL CONTAIN INFORMATION
C             ON THE QU FACTORIZATION OF A. SEE OUTPUT
C             PARAMETER A ABOVE.
C             IF SVD IS RETURNED AS .FALSE. THEN WORK(N+1)
C             WILL CONTAIN THE CONDITION NUMBER
C             L(U)*L(U**(-1)) OF THE UPPER TRIANGULAR
C             MATRIX U.
C             IF SVD IS RETURNED AS .TRUE. THEN WORK(N+1) WILL
C             CONTAIN THE TOTAL NUMBER OF ITERATIONS TAKEN BY THE
C             QR-ALGORITHM.
C
C     LWORK - THE LENGTH OF THE VECTOR WORK. LWORK MUST BE
C             AT LEAST 4*N.
C

F04LEF
      SUBROUTINE F04LEF(JOB,N,A,B,C,D,IN,Y,TOL,IFAIL)
C     MARK 11 RELEASE. NAG COPYRIGHT 1983.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 14 REVISED. IER-743 (DEC 1989).
C     MARK 16A REVISED. IER-1006 (JUN 1993).
C
C     F04LEF SOLVES ONE OF THE SYSTEMS OF EQUATIONS
C
C     T*X = Y ,   ( T**T )*X = Y ,   U*X = Y ,
C
C     WHERE T IS AN N BY N TRIDIAGONAL MATRIX THAT HAS BEEN
C     FACTORIZED AS
C
C     T = P*L*U ,
C
C     BY ROUTINE F01LEF.
C
C     FOR A DESCRIPTION OF THE PARAMETERS AND USE OF THIS ROUTINE SEE
C     THE NAG LIBRARY MANUAL.
C
C     -- WRITTEN ON 19-JANUARY-1983.  S.J.HAMMARLING.
C
C     NAG FORTRAN 66 GENERAL PURPOSE ROUTINE.
C

F04LHF
      SUBROUTINE F04LHF(TRANS,N,NBLOKS,BLKSTR,A,LENA,PIVOT,B,LDB,IR,
     *                  IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.
C     MARK 13B REVISED. IER-665 (AUG 1988).
C     MARK 5 REVISED. IER-930 (APR 1991).
C
C     Purpose:
C
C     F04LHF calculates the approximate solution of a set of real linear
C     equations with multiple right hand sides, AX = B or A(trans)X = B,
C     where A is an almost block diagonal matrix which has been
C     decomposed using F01LHF.
C
C
C     Specification:
C
C        SUBROUTINE F04LHF(TRANS,N,NBLOKS,BLKSTR,A,LENA,PIVOT,
C       *                  B,LDB,IR,IFAIL)
C     C     INTEGER    N,NBLOKS,BLKSTR(3,NBLOKS),LENA,PIVOT(N),
C     C    *           LDB,IR,IFAIL
C     C     real       A(LENA),B(LDB,IR)
C     C     CHARACTER*1 TRANS
C
C
C     Description:
C
C     The routine solves a set of real linear equations AX = B or
C     A(trans)X = B, where
C     A is almost block diagonal. A must first be decomposed by
C     F01LHF. F04LHFthen computes X by forward and backward
C     substitution over the blocks. The code utilizes Level 3 BLAS [2].
C
C
C     References:
C
C     [1] FORTRAN Packages for Solving Certain Almost Block Diagonal
C      Linear Systems by Modified Alternate Row and Column Elimination,
C      J.C.Diaz, G.Fairweather, P.Keast,
C      ACM Transactions on Mathematical Software (1983) 9, 358-375
C
C     [2] A Proposal for a Set of Level 3 Basic Linear Algebra
C      Subprograms
C      J.J.Dongarra, J.DuCroz, I.Duff, S.Hammarling
C      NAG Technical Report (1987) In preparation
C
C
C     Parameters:
C
C     TRANS - CHARACTER*1.
C           On entry, TRANS must specify what solutions are required as
C           follows:
C                TRANS = 'N' or 'n'    AX = B
C                TRANS = 'T' or 't'    A(trans)X=B
C           Unchanged on exit.
C
C       N - INTEGER
C           On entry, N must specify the number of linear equations
C           defined by the matrix A. This must be the same parameter
C           N supplied to F01LHF when decomposing A.
C           N .gt. 0.
C           Unchanged on exit.
C
C     NBLOKS - INTEGER
C           On entry, NBLOKS must specify the total number of blocks
C           of the matrix A. This must be the same parameter NBLOKS
C           supplied to F01LHF.
C           0 .lt. NBLOKS .le. N.
C           Unchanged on exit.
C
C     BLKSTR - INTEGER array of DIMENSION (3,NBLOKS)
C           Before entry, BLKSTR must contain information which
C           describes the block structure of A. It must be unchanged
C           since the last call to F01LHF.
C           Unchanged on exit.
C
C       A - real array of DIMENSION (LENA)
C           Before entry, A must contain the elements in the
C           decomposition of A as output by F01LHF. It must be
C           unchanged since the last call to F01LHF.
C           Unchanged on exit.
C
C     LENA - INTEGER
C           On entry, LENA specifies the dimension of array A as
C           declared in the (sub)program from which F04LHF is called.
C           This must be the same parameter LENA supplied to F01LHF.
C           LENA .ge. sum(BLKSTR(1,k)*BLKSTR(2,k);k=1,NBLOKS)
C           Unchanged on exit.
C
C     PIVOT - INTEGER array of DIMENSION (N)
C           Before entry, PIVOT must contain the pivot information
C           about the decomposition as output from F01LHF. It must be
C           unchanged since the last call to F01LHF.
C           Unchanged on exit.
C
C       B - real array of DIMENSION (LDB,s) where s.ge.IR .
C           Before entry, B must contain the elements of the IR right
C           hand sides stored as columns.
C           On succesful exit, B will contain the IR solution vectors.
C
C     LDB - INTEGER
C           On entry, LDB must specify the first dimension of array B
C           as declared in the (sub)program from which F04LHF is called.
C           LDB .ge. N.
C           Unchanged on exit.
C
C      IR - INTEGER
C           On entry, IR must specify the number of right hand sides.
C           IR .gt. 0.
C           Unchanged on exit.
C
C     IFAIL - INTEGER
C           Before entry, IFAIL must be set to 0, -1 or 1. For users
C           not familiar with this parameter (described in chapter P01),
C           the recommended value is 0.
C           Unless the routine detects an error (see section 6), IFAIL
C           contains 0 on exit.
C
C
C     Error Indicators:
C
C     If on entry IFAIL = 0 or -1, explanatory error messages are output
C     on the current error message unit (as defined by the NAG Library
C     routine X04AAF).
C
C     IFAIL = 1  N .lt. 1 or
C                NBLOKS .lt. 1 or
C                IR .lt. 1 or
C                LDB .lt. N or
C                N .lt. NBLOKS or
C                LENA too small or
C                illegal values detected in BLKSTR or
C                illegal value for TRANS.
C
C
C     Further Comments:
C
C     None.
C
C     CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C
C       AUXILIARY ROUTINES
C       ------------------
C       SSWAP : TO INTERCHANGE TWO VECTORS
C       SGEMM : TO PERFORM MATRIX X MATRIX TYPE OPERATIONS
C       STRSM : TO PERFORM TRIANGULAR SOLVES
C       F04LHX: TO PERFORM TRAPEZOIDAL SOLVES
C       F01LHZ: TO PERFORM CHECKS ON THE PARAMETER BLKSTR
C
C     SGEMM AND STRSM ARE EXISTING LEVEL 3 BLAS
C     (THEY CALL SGEMV AND STRSV RESPECTIVELY)
C     F04LHX/STXSM IS A PROPOSED LEVEL 3 BLAS
C     (IT CALLS F04LHW/STXSV, A PROPOSED LEVEL 2 BLAS)
C
C     CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C
C     NOTE THAT THERE IS SPECIAL CODE TO HANDLE THE CASE WHEN IR = 1 .
C
C     CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
C

F04MAF
      SUBROUTINE F04MAF(N,NZ,A,LA,INI,LINI,INJ,B,EPS,KMAX,W,W1,IK,
     *                  INFORM,IFLAG)
C     MARK 11 RELEASE. NAG COPYRIGHT 1983.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 16A REVISED. IER-1007 (JUN 1993).
C
C     F04MAF SOLVES THE EQUATIONS A*X = B, WHERE A IS A SPARSE
C     SYMMETRIC POSITIVE DEFINITE MATRIX, USING A PRECONDITIONED
C     CONJUGATE GRADIENT METHOD. A MUST HAVE BEEN FACTORIZED BY
C     THE NAG LIBRARY ROUTINE F01MAF.
C
C     THE ROUTINE IS BASED UPON THE HARWELL ROUTINE MA31B BY
C     N MUNKSGAARD.
C
C     THE DEVELOPMENT OF MA31B WAS SUPPORTED BY THE DANISH
C     NATURAL RESEARCH COUNCIL, GRANT NUMBER 511-10069
C
C     FOR A DESCRIPTION OF THE PARAMETERS AND USE OF THIS ROUTINE
C     SEE THE NAG LIBRARY MANUAL. PARAMETER ASSOCIATION IS AS
C     BELOW.
C
C     ROUTINE     DOCUMENT
C     N            N
C     NZ          NZ
C     A            A
C     LA          LA
C     INI         INDI
C     LINI        LINDI
C     INJ         INDJ
C     B            B
C     EPS          ACC
C     KMAX        NOITS
C     W          WORK
C     W1         WORK1
C     IK         IWORK
C     INFORM       INFORM
C     IFLAG        IFAIL
C
C     **************************************************
C
C

F04MBF
      SUBROUTINE F04MBF(N,B,X,APROD,MSOLVE,PRECON,SHIFT,RTOL,ITNLIM,
     *                  MSGLVL,ITN,ANORM,ACOND,RNORM,XNORM,WORK,RWORK,
     *                  LRWORK,IWORK,LIWORK,INFORM,IFAIL)
C     MARK 11 RELEASE. NAG COPYRIGHT 1983.
C     MARK 11B REVISED. IER-459 (SEP 1984).
C     MARK 11D REVISED. IER-472 (NOV 1985).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13A REVISED. IER-622 (APR 1988).
C
C     DESCRIPTION
C     -----------
C
C     F04MBF  IS DESIGNED TO SOLVE THE SYSTEM OF LINEAR EQUATIONS
C
C                A*X = B
C
C     WHERE  A  IS AN  N*N  SYMMETRIC MATRIX AND  B  IS A GIVEN VECTOR.
C     THE MATRIX  A  IS NOT REQUIRED TO BE POSITIVE DEFINITE.
C     ( IF  A  IS KNOWN TO BE DEFINITE, THE METHOD OF CONJUGATE
C     GRADIENTS WILL USUALLY BE SOMEWHAT MORE EFFICIENT. )
C
C
C     THE MATRIX  A  IS INTENDED TO BE LARGE AND SPARSE.  IT IS ACCESSED
C     BY MEANS OF A SUBROUTINE CALL OF THE FORM
C
C                CALL APROD ( IFLAG, N, X, Y,
C                             RWORK, LRWORK, IWORK, LIWORK )
C
C     WHICH MUST RETURN THE PRODUCT  Y = A*X  FOR ANY GIVEN VECTOR  X.
C
C
C     MORE GENERALLY,  F04MBF  IS DESIGNED TO SOLVE THE SYSTEM
C
C                ( A - SHIFT*I )*X = B
C
C     WHERE   SHIFT  IS A SPECIFIED SCALAR VALUE.  IF  SHIFT  AND  B
C     ARE SUITABLY CHOSEN, THE COMPUTED VECTOR  X  MAY APPROXIMATE AN
C     EIGENVECTOR OF  A,  AS IN THE METHODS OF INVERSE ITERATION
C     AND/OR RAYLEIGH-QUOTIENT ITERATION.
C
C
C     AGAIN, THE MATRIX  ( A - SHIFT*I ) NEED NOT BE POSITIVE DEFINITE.
C     THE WORK PER ITERATION IS VERY SLIGHTLY LESS IF SHIFT = 0.
C
C     A FURTHER OPTION IS THAT OF PRECONDITIONING , WHICH MAY REDUCE
C     THE NUMBER OF ITERATIONS REQUIRED.  IF  M  IS A POSITIVE
C     DEFINITE MATRIX WHICH IS KNOWN TO APPROXIMATE  ( A - SHIFT*I )
C     IN SOME SENSE, AND IF SYSTEMS OF THE FORM  M*Y = X  CAN BE
C     SOLVED EFFICIENTLY, THE PARAMETERS  PRECON  AND  MSOLVE  MAY BE
C     USEFUL ( SEE BELOW ).  WHEN  PRECON = .TRUE. ,  F04MBF  WILL
C     IMPLICITLY SOLVE THE SYSTEM OF EQUATIONS
C
C        M**( -1/2 )*( A - SHIFT*I )*M**( -1/2 )*Y  =  M**( -1/2 )*B,
C
C     AND RETURN THE SOLUTION  X = M**( -1/2 )*Y.
C
C     PARAMETERS
C     ----------
C
C     N       INPUT      THE DIMENSION OF THE MATRIX  A.
C
C     B( N )  INPUT     THE RHS VECTOR  B.
C
C     X( N )  OUTPUT    RETURNS THE COMPUTED SOLUTION  X.
C
C     APROD   EXTERNAL   A SUBROUTINE DEFINING THE MATRIX  A.
C                        FOR A GIVEN VECTOR  X,  THE STATEMENT
C
C                           CALL APROD ( IFLAG, N, X, Y,
C                                        RWORK, LRWORK, IWORK, LIWORK )
C
C                        SHOULD RETURN THE PRODUCT  Y = A*X.
C                        APROD   MUST NOT ALTER THE VECTOR  X.
C
C     MSOLVE  EXTERNAL   AN OPTIONAL SUBROUTINE DEFINING A
C                        PRECONDITIONING MATRIX  M,  WHICH WILL USUALLY
C                        APPROXIMATE  ( A - SHIFT*I ) IN SOME SENSE.
C                        M  MUST BE POSITIVE DEFINITE.
C                        FOR A GIVEN VECTOR  X,  THE STATEMENT
C
C                           CALL MSOLVE( IFLAG, N, X, Y,
C                                        RWORK, LRWORK, IWORK, LIWORK )
C
C                        SHOULD SOLVE THE LINEAR SYSTEM  M*Y = X.
C                        MSOLVE  MUST NOT ALTER THE VECTOR  X.
C
C                        NOTE. THE PROGRAM CALLING  F04MBF  MUST
C                        DECLARE  APROD   AND  MSOLVE  TO BE EXTERNAL.
C
C     PRECON  INPUT      IF  PRECON = .TRUE. ,  PRECONDITIONING WILL
C                        BE INVOKED.  OTHERWISE, SUBROUTINE  MSOLVE
C                        WILL NOT BE REFERENCED.  IN THIS CASE THE
C                        ACTUAL PARAMETER CORRESPONDING TO  MSOLVE  MAY
C                        BE THE SAME AS THAT CORRESPONDING TO  APROD .
C
C     SHIFT   INPUT      SHOULD BE ZERO IF THE SYSTEM  A*X = B  IS TO
C                        BE SOLVED.  OTHERWISE  SHIFT  COULD BE AN
C                        APPROXIMATION TO AN EIGENVALUE OF  A,
C                        E.G. THE RAYLEIGH QUOTIENT
C                        B( T )*A*B/( B( T )*B )
C                        CORRESPONDING TO THE VECTOR  B.
C
C     RTOL    INPUT      A USER-SPECIFIED TOLERANCE.  F04MBF TERMINATES
C                        IF IT APPEARS THAT  NORM( RBAR ) IS SMALLER
C                        THAN RTOL*NORM( ABAR )*NORM( Y ),  WHERE
C                        ABAR  IS THE TRANSFORMED MATRIX OPERATOR
C
C                        ABAR = M**( -1/2 )*( A - SHIFT*I )*M**( -1/2 )
C
C                        AND  RBAR  IS THE TRANSFORMED RESIDUAL VECTOR
C
C                        RBAR = M**( -1/2 )*( B - ( A - SHIFT*I )*X )
C
C                        ( AND  M = I  IF  PRECON = .FALSE. ).
C
C     ITNLIM  INPUT      AN UPPER LIMIT ON THE NUMBER OF ITERATIONS.
C
C     MSGLVL  INPUT      DETERMINES THE LEVEL OF PRINTING.
C                        IF MSGLVL .GT. 1 THEN PROGRESS IS MONITERED
C                        BY PRINTING OUT A SUMMARY LINE PERIODICALLY.
C                        IF MSGLVL .GT. 0 THEN A SUMMARY IS PRINTED
C                        AT THE END OF THE ROUTINE.
C                        OUTPUT IS ON THE UNIT GIVEN BY X04ABF.
C
C     INFORM  OUTPUT     AN INTEGER GIVING THE REASON FOR TERMINATION...
C
C             0          B = 0,  SO THE EXACT SOLUTION IS  X = 0.
C                        NO ITERATIONS WERE PERFORMED.
C
C             1          NORM( RBAR ) APPEARS TO BE LESS THAN
C                        THE VALUE  RTOL*NORM( ABAR )*NORM( Y ).
C
C             2          NORM( RBAR ) APPEARS TO BE LESS THAN
C                        THE VALUE   EPS*NORM( ABAR )*NORM( Y ).
C                        THIS MEANS THAT THE RESIDUAL IS AS SMALL AS
C                        SEEMS REASONABLE ON THIS MACHINE.
C
C             3          NORM( ABAR )*NORM( Y ) EXCEEDS  NORM( B )/EPS,
C                        WHICH SHOULD INDICATE THAT  X  HAS ESSENTIALLY
C                        CONVERGED TO AN EIGENVECTOR OF  A
C                        CORRESPONDING TO THE EIGENVALUE  SHIFT.
C
C             4          THE ITERATION LIMIT WAS REACHED BEFORE ANY OF
C                        THE PREVIOUS CRITERIA WERE SATISFIED.
C
C             5          THE PRECONDITIONING MATRIX  M  DOES NOT APPEAR
C                        TO BE POSITIVE DEFINITE.  X  WILL NOT BE AN
C                        ACCEPTABLE SOLUTION.
C
C     ITN     OUTPUT     THE NUMBER OF ITERATIONS PERFORMED.
C
C     ANORM   OUTPUT     AN ESTIMATE OF THE NORM OF THE MATRIX OPERATOR
C                        ABAR = M**( -1/2 )*( A - SHIFT*I )*M**( -1/2 ).
C
C     ACOND   OUTPUT     AN ESTIMATE OF THE CONDITION OF  ABAR  ABOVE.
C                        THIS WILL USUALLY BE A SUBSTANTIAL
C                        UNDER-ESTIMATE OF THE TRUE CONDITION.
C
C     RNORM   OUTPUT     THE NORM OF THE FINAL RESIDUAL VECTOR,
C                        R = B - ( A - SHIFT*I )*X.
C
C     XNORM   OUTPUT     THE NORM OF THE FINAL SOLUTION VECTOR  X.
C
C     WORK    WORKSPACE  OF LENGTH AL LEAST 5*N.
C
C     REFERENCES
C     ----------
C
C     THIS ROUTINE IS DERIVED FROM THE SUBROUTINE  SYMMLQ  DESCRIBED IN
C     THE FOLLOWING REFERENCES...
C
C         C.C. PAIGE AND M.A. SAUNDERS,  SOLUTION OF SPARSE INDEFINITE
C         SYSTEMS OF EQUATIONS AND LEAST SQUARES PROBLEMS,
C         TECHNICAL REPORT STAN-CS-73-399, COMPUTER SCIENCE DEPARTMENT,
C         STANFORD UNIVERSITY, STANFORD, CALIFORNIA, NOVEMBER 1973.
C
C         C.C. PAIGE AND M.A. SAUNDERS,  SOLUTION OF SPARSE INDEFINITE
C         SYSTEMS OF LINEAR EQUATIONS,
C         SIAM J. NUMER. ANAL. 12, 4, SEPTEMBER 1975, PP. 617-629.
C
C         J.G. LEWIS,  ALGORITHMS FOR SPARSE MATRIX EIGENVALUE PROBLEMS,
C         TECHNICAL REPORT STAN-CS-77-595, COMPUTER SCIENCE DEPARTMENT,
C         STANFORD UNIVERSITY, STANFORD, CALIFORNIA, MARCH 1977.
C
C     FURTHER COMMENTS
C     ----------------
C
C     SYMMLQ.         VERSION DATED 13 OCT 1981.  MAS.
C     F04MBF.    THIS VERSION DATED 11 OCT 1983.  S.J.HAMMARLING
C     F04MBFT.   THIS VERSION DATED  3 JAN 1984.  S.J.HAMMARLING
C                SETS W(1)BAR = V(1).
C
C     THE VECTORS Y, V, R1, R2 AND W OF SYMMLQ HAVE BEEN COMBINED INTO
C     THE ARRAY WORK IN F04MBF AS FOLLOWS.
C
C      Y( I ) = WORK( I, 1 ),  I = 1, 2, ..., N
C      V( I ) = WORK( I, 2 ),  I = 1, 2, ..., N
C     R1( I ) = WORK( I, 3 ),  I = 1, 2, ..., N
C     R2( I ) = WORK( I, 4 ),  I = 1, 2, ..., N
C      W( I ) = WORK( I, 5 ),  I = 1, 2, ..., N.
C
C     IN ALL THE EMBEDDED COMMENTS IN THE CODE TAKE M = I IF
C     PRECON = .FALSE..
C
C     SUBROUTINES AND FUNCTIONS
C
C     USER               APROD , MSOLVE
C     BLAS               AXPY  , COPY  , DOT   , NRM2
C     NAG BLAS           CNSV  , NROT  , NROTG , SCMV
C     NAG                X02ZAZ
C     FORTRAN            ABS   , AMAX1 , AMIN1 , MOD   , SQRT
C
C     APROD, MSOLVE

F04MCF
      SUBROUTINE F04MCF(N,L,LL,D,NROW,P,B,NRB,ISELCT,X,NRX,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 14 REVISED. IER-746 (DEC 1989).
C
C     ******************************************************
C
C     NPL ALGORITHMS LIBRARY ROUTINE VBSOLC
C
C     CREATED 16 05 79.  UPDATED 07 09 79.  RELEASE 00/12
C
C     AUTHOR ... MAURICE G. COX.
C     NATIONAL PHYSICAL LABORATORY, TEDDINGTON,
C     MIDDLESEX TW11 OLW, ENGLAND.
C
C     ******************************************************
C
C     F04MCF.  AN ALGORITHM TO DETERMINE THE SOLUTION OF THE
C     SYSTEM  AX = B  (AND RELATED SYSTEMS),  WHERE  A  IS A
C     SYMMETRIC POSITIVE DEFINITE VARIABLE BANDWIDTH MATRIX,
C     FOLLOWING AN  LDU  FACTORIZATION OF  A  (WHERE
C     U = L TRANSPOSED).
C
C     INPUT PARAMETERS
C        N        ORDER OF  L
C        L        ELEMENTS WITHIN ENVELOPE OF UNIT LOWER
C                    TRIANGULAR MATRIX  L  (INCLUDING UNIT
C                    DIAGONAL ELEMENTS), IN ROW BY ROW ORDER
C        LL       DIMENSION OF  L.  AT LEAST
C                    NROW(1) + NROW(2) + ... + NROW(N).
C        D        DIAGONAL ELEMENTS OF DIAGONAL MATRIX  D
C        NROW     WIDTHS OF ROWS OF  L
C        P        NUMBER OF COLUMNS OF  B.
C                    GREATER THAN OR EQUAL TO  1.
C        B        RIGHT HAND SIDE VECTORS, STORED BY COLUMNS
C        NRB      ROW DIMENSION OF  B,  AS DECLARED IN CALLING
C                    PROGRAM UNIT
C        ISELCT   SELECTION INDICATOR
C                    1 - SOLVE  LDUX = B  (NORMAL APPLICATION)
C                    2 - SOLVE  LDX  = B  (LOWER TRIANGULAR
C                                            SOLVER)
C                    3 - SOLVE  DUX  = B  (UPPER TRIANGULAR
C                                            SOLVER)
C                    4 - SOLVE  LUX  = B
C                    5 - SOLVE  LX   = B  (UNIT LOWER
C                                            TRIANGULAR SOLVER)
C                    6 - SOLVE  UX   = B  (UNIT UPPER
C                                            TRIANGULAR SOLVER),
C                              WHERE  U = L TRANSPOSED.
C
C     OUTPUT (AND ASSOCIATED) PARAMETERS
C        X        SOLUTION VECTORS, STORED BY COLUMNS
C        NRX      ROW DIMENSION OF  X,  AS DECLARED IN CALLING
C                    PROGRAM UNIT
C
C     FAILURE INDICATORS
C        IFAIL    FAILURE INDICATOR
C                    0 - SUCCESSFUL TERMINATION
C                    1 - AT LEAST ONE OF THE FOLLOWING
C                        RESTRICTIONS RELATING TO  N,  LL
C                        AND THE ARRAY  NROW  IS VIOLATED.
C                           N  .GE. 1,
C                           NROW(1) .GE. 1  AND  .LE. I,
C                              FOR  I = 1, 2, ..., N,
C                           NROW(1) + NROW(2) + ...
C                           ... + NROW(N)  .LE.  LL.
C                    2 - AT LEAST ONE OF THE FOLLOWING
C                        RESTRICTIONS RELATING TO  P,
C                        NRB  AND  NRX  IS VIOLATED.
C                           P .GE. 1,
C                           NRB .GE. N,
C                           NRX .GE. N
C                    3 - ISELCT IS LESS THAN 1 OR GREATER THAN 6
C                    4 - D  SINGULAR
C                           (APPLIES ONLY IF  ISELCT .LE. 3)
C                    5 - L  NOT  U N I T  TRIANGULAR, AS EXPECTED
C

F04MEF
      SUBROUTINE F04MEF(N,T,X,V,WORK,IFAIL)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C     -- Written on 9-February-1990.
C     This version dated 8-January-1991.
C     Sven Hammarling, Nag Ltd.
C

F04MFF
      SUBROUTINE F04MFF(N,T,B,X,P,WORK,IFAIL)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C     -- Written on 9-February-1990.
C     This version dated 8-January-1991.
C     Sven Hammarling, Nag Ltd.
C

F04QAF
      SUBROUTINE F04QAF(M,N,B,X,SE,APROD,DAMP,ATOL,BTOL,CONLIM,ITNLIM,
     *                  MSGLVL,ITN,ANORM,ACOND,RNORM,ARNORM,XNORM,WORK,
     *                  RWORK,LRWORK,IWORK,LIWORK,INFORM,IFAIL)
C     MARK 11 RELEASE. NAG COPYRIGHT 1983.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     DESCRIPTION
C     -----------
C
C     F04QAF  FINDS A SOLUTION  X  TO THE FOLLOWING PROBLEMS...
C
C     1. UNSYMMETRIC EQUATIONS --    SOLVE  A*X = B
C
C     2. LINEAR LEAST SQUARES  --    SOLVE  A*X = B
C                                    IN THE LEAST-SQUARES SENSE
C
C     3. DAMPED LEAST SQUARES  --    SOLVE  (   A    )*X = ( B )
C                                           ( DAMP*I )     ( 0 )
C                                    IN THE LEAST-SQUARES SENSE
C
C     WHERE  A  IS A MATRIX WITH  M  ROWS AND  N  COLUMNS, B  IS AN
C     M-VECTOR, AND  DAMP  IS A SCALAR ( ALL QUANTITIES REAL ).
C     THE MATRIX  A  IS INTENDED TO BE LARGE AND SPARSE.  IT IS ACCESSED
C     BY MEANS OF SUBROUTINE CALLS OF THE FORM
C
C          CALL APROD ( MODE, M, N, X, Y, RWORK, LRWORK, IWORK, LIWORK )
C
C     WHICH MUST PERFORM THE FOLLOWING FUNCTIONS...
C
C                IF MODE = 1, COMPUTE  Y = Y + A*X.
C                IF MODE = 2, COMPUTE  X = X + A( TRANSPOSE )*Y.
C
C     THE VECTORS X AND Y ARE INPUT PARAMETERS IN BOTH CASES.
C     IF MODE = 1, Y SHOULD BE ALTERED WITHOUT CHANGING X.
C     IF MODE = 2, X SHOULD BE ALTERED WITHOUT CHANGING Y.
C     THE PARAMETERS RWORK, LRWORK, IWORK, LIWORK MAY BE USED FOR
C     WORKSPACE AS DESCRIBED BELOW.
C
C     THE RHS VECTOR  B  IS OVERWRITTEN.
C
C     NOTE.  F04QAF USES AN ITERATIVE METHOD TO APPROXIMATE THE
C            SOLUTION.
C     THE NUMBER OF ITERATIONS REQUIRED TO REACH A CERTAIN ACCURACY
C     DEPENDS STRONGLY ON THE SCALING OF THE PROBLEM.  POOR SCALING OF
C     THE ROWS OR COLUMNS OF  A  SHOULD THEREFORE BE AVOIDED WHERE
C     POSSIBLE.
C
C     FOR EXAMPLE, IN PROBLEM 1 THE SOLUTION IS UNALTERED BY
C     ROW-SCALING.  IF A ROW OF  A  IS VERY SMALL OR LARGE COMPARED TO
C     THE OTHER ROWS OF  A,  THE CORRESPONDING ROW OF  ( A  B )  SHOULD
C     BE SCALED UP OR DOWN.
C
C     IN PROBLEMS 1 AND 2, THE SOLUTION  X  IS EASILY RECOVERED
C     FOLLOWING COLUMN-SCALING.  IN THE ABSENCE OF BETTER INFORMATION,
C     THE NONZERO COLUMNS OF  A  SHOULD BE SCALED SO THAT THEY ALL HAVE
C     THE SAME EUCLIDEAN NORM ( E.G.  1.0 ).
C
C     IN PROBLEM 3, THERE IS NO FREEDOM TO RE-SCALE IF  DAMP  IS
C     NONZERO.  HOWEVER, THE VALUE OF  DAMP  SHOULD BE ASSIGNED ONLY
C     AFTER ATTENTION HAS BEEN PAID TO THE SCALING OF  A.
C
C     THE PARAMETER  DAMP  IS INTENDED TO HELP REGULARIZE
C     ILL-CONDITIONED SYSTEMS, BY PREVENTING THE TRUE SOLUTION FROM
C     BEING VERY LARGE.  ANOTHER AID TO REGULARIZATION IS PROVIDED BY
C     THE PARAMETER  ACOND,  WHICH MAY BE USED TO TERMINATE ITERATIONS
C     BEFORE THE COMPUTED SOLUTION BECOMES VERY LARGE.
C
C     THE FOLLOWING QUANTITIES ARE USED IN DISCUSSING THE SUBROUTINE
C     PARAMETERS...
C
C     ABAR   =  (   A    ),          BBAR  =  ( B )
C               ( DAMP*I )                    ( 0 )
C
C     R      =  B  -  A*X,           RBAR  =  BBAR  -  ABAR*X
C
C     RNORM  =  SQRT( NORM( R )**2  + ( DAMP**2 )*( NORM( X )**2 ) )
C            =  NORM( RBAR )
C
C     RELPR  =  THE RELATIVE PRECISION OF FLOATING-POINT ARITHMETIC
C               ON THE MACHINE BEING USED.
C
C     F04QAF  MINIMIZES THE FUNCTION  RNORM  WITH RESPECT TO  X.
C
C     PARAMETERS
C     ----------
C
C     M       INPUT      THE NUMBER OF ROWS IN  A.
C
C     N       INPUT      THE NUMBER OF COLUMNS IN  A.
C
C     APROD   EXTERNAL   SEE ABOVE.
C
C     DAMP    INPUT      THE DAMPING PARAMETER FOR PROBLEM 3 ABOVE.
C                        ( DAMP  SHOULD BE 0.0 FOR PROBLEMS 1 AND 2. )
C                        IF THE SYSTEM  A*X = B  IS INCOMPATIBLE, VALUES
C                        OF  DAMP  IN THE RANGE 0 TO
C                        SQRT( RELPR )*NORM( A )
C                        WILL PROBABLY HAVE A NEGLIGIBLE EFFECT.
C                        LARGER VALUES OF  DAMP  WILL TEND TO DECREASE
C                        THE NORM OF  X  AND TO REDUCE THE NUMBER OF
C                        ITERATIONS REQUIRED BY F04QAF.
C
C                        THE WORK PER ITERATION AND THE STORAGE NEEDED
C                        BY F04QAF ARE THE SAME FOR ALL VALUES OF  DAMP.
C
C     LIWORK  INPUT      THE LENGTH OF THE WORKSPACE ARRAY  IWORK.
C     LRWORK  INPUT      THE LENGTH OF THE WORKSPACE ARRAY  RWORK.
C     IWORK   WORKSPACE  AN INTEGER ARRAY OF LENGTH  LIWORK.
C     RWORK   WORKSPACE  A REAL ARRAY OF LENGTH  LRWORK.
C
C             NOTE.  F04QAF DOES NOT EXPLICITLY USE THE PREVIOUS FOUR
C             PARAMETERS, BUT PASSES THEM TO SUBROUTINE APROD FOR
C             POSSIBLE USE AS WORKSPACE.  IF APROD DOES NOT NEED
C             IW  OR  RW,  THE VALUES  LENIW = 1  OR  LENRW = 1  SHOULD
C             BE USED, AND THE ACTUAL PARAMETERS CORRESPONDING TO
C             IW  OR  RW  MAY BE ANY CONVENIENT ARRAY OF SUITABLE TYPE.
C
C     B( M )  INPUT      THE RHS VECTOR.  BEWARE THAT  B  IS
C                        OVER-WRITTEN BY F04QAF.
C
C     X( N )  OUTPUT     RETURNS THE COMPUTED SOLUTION  X.
C
C     SE( N ) OUTPUT     RETURNS STANDARD ERROR ESTIMATES FOR THE
C                        COMPONENTS OF  X.  FOR EACH I,  SE( I )  IS SET
C                        TO THE VALUE  RNORM*SQRT( SIGMA( I, I )/T ),
C                        WHERE  SIGMA( I, I )  IS AN ESTIMATE OF THE ITH
C                        DIAGONAL OF THE INVERSE OF
C                        ABAR( TRANSPOSE )*ABAR
C                        AND  T = 1      IF  M .LE. N,
C                             T = M - N  IF  M .GT. N  AND  DAMP = 0,
C                             T = M      IF  DAMP .NE. 0.
C
C     ATOL    INPUT      AN ESTIMATE OF THE RELATIVE ERROR IN THE DATA
C                        DEFINING THE MATRIX  A.  FOR EXAMPLE,
C                        IF  A  IS ACCURATE TO ABOUT 6 DIGITS, SET
C                        ATOL = 1.0E-6 .
C
C     BTOL    INPUT      AN ESTIMATE OF THE RELATIVE ERROR IN THE DATA
C                        DEFINING THE RHS VECTOR  B.  FOR EXAMPLE,
C                        IF  B  IS ACCURATE TO ABOUT 6 DIGITS, SET
C                        BTOL = 1.0E-6 .
C
C     CONLIM  INPUT      AN UPPER LIMIT ON  COND( ABAR ),  THE APPARENT
C                        CONDITION NUMBER OF THE MATRIX  ABAR.
C                        ITERATIONS WILL BE TERMINATED IF A COMPUTED
C                        ESTIMATE OF  COND( ABAR )  EXCEEDS  CONLIM.
C                        THIS IS INTENDED TO PREVENT CERTAIN SMALL OR
C                        ZERO SINGULAR VALUES OF  A  OR  ABAR  FROM
C                        COMING INTO EFFECT AND CAUSING UNWANTED GROWTH
C                        IN THE COMPUTED SOLUTION.
C
C                        CONLIM  AND  DAMP  MAY BE USED SEPARATELY OR
C                        TOGETHER TO REGULARIZE ILL-CONDITIONED SYSTEMS.
C
C                        NORMALLY,  CONLIM  SHOULD BE IN THE RANGE
C                        1000  TO  1/RELPR.
C                        SUGGESTED VALUE --
C                        CONLIM = 1/( 100*RELPR )  FOR COMPATIBLE
C                        SYSTEMS,
C                        CONLIM = 1/( 10*SQRT( RELPR ) )  FOR LEAST
C                        SQUARES.
C
C             NOTE.  IF THE USER IS NOT CONCERNED ABOUT THE PARAMETERS
C             ATOL, BTOL  AND  CONLIM,  ANY OR ALL OF THEM MAY BE SET
C             TO ZERO.  THE EFFECT WILL BE THE SAME AS THE VALUES
C             RELPR, RELPR  AND  1/RELPR  RESPECTIVELY.
C
C     ITNLIM  INPUT      AN UPPER LIMIT ON THE NUMBER OF ITERATIONS.
C                        SUGGESTED VALUE --
C                        ITNLIM = N/2     FOR WELL CONDITIONED SYSTEMS,
C                        ITNLIM = 4*N     OTHERWISE.
C
C     ITN     OUTPUT     THE NUMBER OF ITERATIONS TAKEN.
C
C     MSGLVL  INPUT      DETERMINES THE LEVEL OF PRINTING.
C                        IF MSGLVL .GT. 1 THEN PROGRESS IS MONITERED
C                        BY PRINTING OUT A SUMMARY LINE PERIODICALLY.
C                        IF MSGLVL .GT. 0 THEN A SUMMARY IS PRINTED
C                        AT THE END OF THE ROUTINE.
C                        OUTPUT IS ON THE UNIT GIVEN BY X04ABF.
C
C     INFORM  OUTPUT     AN INTEGER GIVING THE REASON FOR TERMINATION...
C
C                0       X = 0  IS THE EXACT SOLUTION.
C                        NO ITERATIONS WERE PERFORMED.
C
C                1       THE EQUATIONS  A*X = B  ARE PROBABLY
C                        COMPATIBLE.  NORM( A*X - B )  IS SUFFICIENTLY
C                        SMALL, GIVEN THE VALUES OF  ATOL  AND  BTOL.
C
C                2       THE SYSTEM  A*X = B  IS PROBABLY NOT
C                        COMPATIBLE.  A LEAST-SQUARES SOLUTION HAS
C                        BEEN OBTAINED WHICH IS SUFFICIENTLY ACCURATE,
C                        GIVEN THE VALUE OF  ATOL.
C
C                3       THE EQUATIONS  A*X = B  ARE PROBABLY
C                        COMPATIBLE.  NORM( A*X - B )  IS AS SMALL AS
C                        SEEMS REASONABLE ON THIS MACHINE.
C
C                4       THE SYSTEM  A*X = B  IS PROBABLY NOT
C                        COMPATIBLE.  A LEAST-SQUARES SOLUTION HAS
C                        BEEN OBTAINED WHICH IS AS ACCURATE AS SEEMS
C                        REASONABLE ON THIS MACHINE.
C
C                5       AN ESTIMATE OF  COND( ABAR )  HAS EXCEEDED
C                        CONLIM.   THE SYSTEM  A*X = B  APPEARS TO BE
C                        ILL-CONDITIONED.  OTHERWISE, THERE COULD BE AN
C                        AN ERROR IN SUBROUTINE APROD .
C
C                6       COND( ABAR )  SEEMS TO BE SO LARGE THAT THERE
C                        IS NOT MUCH POINT IN DOING FURTHER ITERATIONS,
C                        GIVEN THE PRECISION OF THIS MACHINE.
C                        THERE COULD BE AN ERROR IN SUBROUTINE APROD.
C
C                7       THE ITERATION LIMIT  ITNLIM  WAS REACHED.
C
C     ANORM   OUTPUT     AN ESTIMATE OF THE FROBENIUS NORM OF  ABAR.
C                        THIS IS THE SQUARE-ROOT OF THE SUM OF SQUARES
C                        OF THE ELEMENTS OF  ABAR.
C                        IF  DAMP  IS SMALL AND IF THE COLUMNS OF  A
C                        HAVE ALL BEEN SCALED TO HAVE LENGTH  1.0,
C                        ANORM  SHOULD INCREASE TO ROUGHLY  SQRT( N ).
C                        A RADICALLY DIFFERENT VALUE FOR  ANORM  MAY
C                        INDICATE AN ERROR IN SUBROUTINE APROD ( THERE
C                        MAY BE AN INCONSISTENCY BETWEEN MODES 1 AND
C                        2 ).
C
C     ACOND   OUTPUT     AN ESTIMATE OF  COND( ABAR ),  THE CONDITION
C                        NUMBER OF  ABAR.  A VERY HIGH VALUE OF  ACOND
C                        MAY AGAIN INDICATE AN ERROR IN APROD.
C
C     RNORM   OUTPUT     AN ESTIMATE OF THE FINAL VALUE OF NORM( RBAR ),
C                        THE FUNCTION BEING MINIMIZED ( SEE NOTATION
C                        ABOVE ).  THIS WILL BE SMALL IF  A*X = B  HAS
C                        A SOLUTION.
C
C     ARNORM  OUTPUT     AN ESTIMATE OF THE FINAL VALUE OF
C                        NORM( ABAR( TRANSPOSE )*RBAR ), THE NORM OF
C                        THE RESIDUAL FOR THE USUAL NORMAL EQUATIONS.
C                        THIS SHOULD BE SMALL IN ALL CASES.  ( ARNORM
C                        WILL OFTEN BE SMALLER THAN THE TRUE VALUE
C                        COMPUTED FROM THE OUTPUT VECTOR  X. )
C
C     XNORM   OUTPUT     AN ESTIMATE OF THE NORM OF THE FINAL
C                        SOLUTION VECTOR  X.
C
C     WORK    WORKSPACE  ARRAY OF LENGTH AT LEAST 2*N.
C
C
C     SUBROUTINES AND FUNCTIONS USED
C     ------------------------------
C
C     USER       APROD
C     BLAS       COPY  , NRM2  , SCAL
C     NAG BLAS   CNSV  , ROTG
C     NAG        X02ZAZ
C     FORTRAN    ABS   , MOD   , SQRT
C
C     REFERENCES
C     ----------
C
C     PAIGE, C.C. AND SAUNDERS, M.A.  LSQR: AN ALGORITHM FOR SPARSE
C        LINEAR EQUATIONS AND SPARSE LEAST SQUARES.
C        ACM TRANSACTIONS ON MATHEMATICAL SOFTWARE 8, 1 ( MARCH 1982 ).
C
C     LAWSON, C.L., HANSON, R.J., KINCAID, D.R. AND KROGH, F.T.
C        BASIC LINEAR ALGEBRA SUBPROGRAMS FOR FORTRAN USAGE.
C        ACM TRANSACTIONS ON MATHEMATICAL SOFTWARE 5, 3 ( SEPT 1979 ),
C        308-323 AND 324-325.
C
C     FURTHER COMMENTS
C     ----------------
C
C     LSQR.           VERSION DATED 22 FEBRUARY 1982.  MAS.
C     F04QAF.    THIS VERSION DATED 11 OCT  1983.  S.J.HAMMARLING
C
C     IN THIS VERSION THE VECTORS V AND W ARE STORED IN THE ARRAY
C     WORK AS FOLLOWS.
C
C        V( I ) = WORK( I, 1 ),  I = 1, 2, ..., N
C        W( I ) = WORK( I, 2 ),  I = 1, 2, ..., N.
C
C     APROD

F04YAF
      SUBROUTINE F04YAF(JOB,P,SIGMA,A,NRA,SVD,IRANK,SV,CJ,WORK,IFAIL)
C     MARK 11 RELEASE.  NAG COPYRIGHT 1983.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     F04YAF RETURNS ELEMENTS OF THE ESTIMATED VARIANCE-COVARIANCE
C     MATRIX OF THE SAMPLE REGRESSION COEFFICIENTS FOR THE SOLUTION
C     OF A LINEAR REGRESSION PROBLEM.
C
C     THE ROUTINE CAN BE USED TO FIND THE ESTIMATED VARIANCES OF THE
C     SAMPLE REGRESSION COEFFICIENTS.
C
C     FOR A DESCRIPTION OF THE PARAMETERS AND USE OF THIS ROUTINE SEE
C     THE NAG LIBRARY MANUAL.
C
C     -- WRITTEN ON 29-NOVEMBER-1982.  S.J. HAMMARLING.
C
C     NAG FORTRAN 66 ROUTINE.
C

F04YCF
      SUBROUTINE F04YCF(ICASE,N,X,ESTNRM,WORK,IWORK,IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.
C     MARK 15 REVISED. IER-913 (APR 1991).
C
C     F04YCF estimates the 1-norm of a square, real matrix A.
C     Reverse communication is used for evaluating matrix-vector
C     products.
C
C     On entry,
C
C        N       integer.  The order of the matrix.  N .ge. 1.
C
C        IWORK   integer(N). Used as workspace.
C
C        ICASE   integer. ICASE must be set to zero on initial entry.
C
C     On intermediate returns:
C
C        ICASE   = 1 or 2.
C
C        X       real(N), must be overwritten by
C
C                     A*X,             if ICASE=1,
C                     transpose(A)*X,  if ICASE=2,
C
C                and F04YCF must be re-called, with all the other
C                parameters unchanged.
C
C     On final return,
C
C        ICASE   = 0.
C
C        ESTNRM  real. Contains an estimate (a lower bound) for norm(A).
C
C        WORK    real(N). Contains vector V such that V = A*W, where
C                ESTNRM = norm(V)/norm(W) (W  is not returned).
C
C     Nick Higham, University of Manchester.
C
C     Reference:
C     N.J. Higham (1987) Fortran Codes for Estimating
C     the One-norm of a Real or Complex Matrix, with Applications
C     to Condition  Estimation, Numerical Analysis Report No. 135,
C     University of Manchester, Manchester M13 9PL, England.
C

F04ZCF
      SUBROUTINE F04ZCF(ICASE,N,X,ESTNRM,WORK,IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.
C     MARK 15 REVISED. IER-914 (APR 1991).
C
C     F04ZCF estimates the 1-norm of a square, complex matrix  A.
C     Reverse communication is used for evaluating matrix-vector
C     products.
C
C     On entry,
C
C        N       integer. The order of the matrix.  N .ge. 1.
C
C       ICASE    integer. ICASE must be set to zero on initial entry.
C
C     On intermediate returns
C
C       ICASE    = 1 or 2.
C
C        X       complex(N). X must be overwritten by
C
C                     A*X,          if ICASE=1,
C                     conjg(A')*X,  if ICASE=2,
C
C                and F04ZCF must be re-called, with all the other
C                parameters unchanged.
C
C     On final return,
C
C        ICASE    = 0.
C
C        ESTNRM  real. Contains an estimate (a lower bound) for norm(A).
C
C        WORK    complex(N). Contains vector V such that V = A*W, where
C                ESTNRM = norm(V)/norm(W) (W is not returned).
C
C     Nick Higham, University of Manchester.
C
C     Reference:
C     N.J. Higham (1987) Fortran Codes for Estimating
C     the One-norm of a Real or Complex Matrix, with Applications
C     to Condition  Estimation, Numerical Analysis Report No. 135,
C     University of Manchester, Manchester M13 9PL, England.
C

F05AAF
      SUBROUTINE F05AAF(A,IA,M,N1,N2,S,CC,ICOL,IFAIL)
C     MARK 4 RELEASE NAG COPYRIGHT 1974.
C     MARK 4.5 REVISED
C     MARK 10A REVISED. IER-390 (OCT 1982).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     PERFORMS SCHMIDT ORTHONORMALISATION ON VECTORS N1
C     TO N2 OF ARRAY A.

F06AAF
      SUBROUTINE F06AAF( A, B, C, S )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06BAF
      SUBROUTINE F06BAF( A, B, C, S )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06BCF
      SUBROUTINE F06BCF( T, C, S )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C     MARK 13 REVISED. IER-602 (MAR 1988).

F06BEF
      SUBROUTINE F06BEF( JOB, X, Y, Z, C, S )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06BHF
      SUBROUTINE F06BHF( X, Y, Z, C, S )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06BLF
      DOUBLE PRECISION FUNCTION F06BLF( A, B, FAIL )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06BMF
      DOUBLE PRECISION FUNCTION F06BMF( SCALE, SSQ )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06BNF
      DOUBLE PRECISION FUNCTION F06BNF( A, B )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06BPF
      DOUBLE PRECISION FUNCTION F06BPF( A, B, C )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06CAF
      SUBROUTINE F06CAF( A, B, C, S )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C     MARK 14A REVISED. IER-689 (DEC 1989).
C     MARK 15A REVISED. IER-916 (APR 1991).

F06CBF
      SUBROUTINE F06CBF( A, B, C, S )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06CCF
      SUBROUTINE F06CCF( T, C, S )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C     MARK 13 REVISED. IER-603 (MAR 1988).
C     MARK 15 REVISED. IER-943 (APR 1991).

F06CDF
      SUBROUTINE F06CDF( T, C, S )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C     MARK 13 REVISED. IER-604 (MAR 1988).

F06CHF
      SUBROUTINE F06CHF( X, Y, Z, C, S )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06CLF
      COMPLEX*16       FUNCTION F06CLF( A, B, FAIL )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C     MARK 13 REVISED. IER-605 (MAR 1988).

F06DBF
      SUBROUTINE F06DBF( N, CONST, X, INCX )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06DFF
      SUBROUTINE F06DFF( N, X, INCX, Y, INCY )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06EAF
      DOUBLE PRECISION FUNCTION F06EAF( N, X, INCX, Y, INCY )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06ECF
      SUBROUTINE F06ECF( N, ALPHA, X, INCX, Y, INCY )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06EDF
      SUBROUTINE F06EDF( N, ALPHA, X, INCX )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06EFF
      SUBROUTINE F06EFF( N, X, INCX, Y, INCY )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06EGF
      SUBROUTINE F06EGF( N, X, INCX, Y, INCY )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06EJF
      DOUBLE PRECISION FUNCTION F06EJF( N, X, INCX )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06EKF
      DOUBLE PRECISION FUNCTION F06EKF( N, X, INCX )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06EPF
      SUBROUTINE F06EPF( N, X, INCX, Y, INCY, C, S )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06ERF
      DOUBLE PRECISION FUNCTION F06ERF(NZ,X,INDX,Y)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     PURPOSE
C
C         DDOTI COMPUTES THE VECTOR INNER PRODUCT OF
C             A REAL SPARSE VECTOR  X
C             STORED IN COMPRESSED FORM  (X,INDX)
C         WITH
C             A REAL VECTOR  Y  IN FULL STORAGE FORM.
C
C         ONLY THE ELEMENTS OF Y WHOSE INDICES ARE LISTED IN INDX
C         ARE REFERENCED.
C
C     ARGUMENTS
C
C     INPUT ...
C
C         NZ      INTEGER     NUMBER OF ELEMENTS IN THE COMPRESSED FORM.
C         X       REAL        ARRAY CONTAINING THE VALUES OF THE
C                             COMPRESSED FORM.
C         INDX    INTEGER     ARRAY CONTAINING THE INDICES OF THE
C                             COMPRESSED FORM.
C         Y       REAL        ARRAY, ON INPUT, WHICH CONTAINS THE
C                             VECTOR  Y  IN FULL STORAGE FORM.  ONLY
C                             THE ELEMENTS  CORRESPONDING TO THE
C                             INDICES IN  INDX  WILL BE ACCESSED.
C
C     OUTPUT ...
C
C         DDOTI   REAL        REAL FUNCTION VALUE EQUAL TO THE
C                             VECTOR INNER PRODUCT.
C                             IF  NZ .LE. 0  DDOTI IS SET TO ZERO.
C
C     SPARSE BASIC LINEAR ALGEBRA SUBPROGRAM
C
C     FORTRAN VERSION WRITTEN OCTOBER 1984
C     ROGER G GRIMES, BOEING COMPUTER SERVICES
C

F06ETF
      SUBROUTINE F06ETF(NZ,A,X,INDX,Y)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     PURPOSE
C
C         DAXPYI ADDS A REAL SCALAR MULTIPLE OF
C             A REAL SPARSE VECTOR  X
C             STORED IN COMPRESSED FORM  (X,INDX)
C         TO
C             A REAL VECTOR  Y  IN FULL STORAGE FORM.
C
C         ONLY THE ELEMENTS OF  Y  WHOSE INDICES ARE LISTED IN  INDX
C         ARE REFERENCED OR MODIFIED.  THE VALUES IN  INDX  MUST BE
C         DISTINCT TO ALLOW CONSISTENT VECTOR OR PARALLEL EXECUTION.
C
C         ALTHOUGH DISTINCT INDICES WILL ALLOW VECTOR OR PARALLEL
C         EXECUTION, MOST COMPILERS FOR HIGH-PERFORMANCE MACHINES WILL
C         BE UNABLE TO GENERATE BEST POSSIBLE CODE WITHOUT SOME
C         MODIFICATION, SUCH AS COMPILER DIRECTIVES, TO THIS CODE.
C
C     ARGUMENTS
C
C     INPUT ...
C
C         NZ      INTEGER     NUMBER OF ELEMENTS IN THE COMPRESSED FORM.
C         A       REAL        SCALAR MULTIPLIER OF  X.
C         X       REAL        ARRAY CONTAINING THE VALUES OF THE
C                             COMPRESSED FORM.
C         INDX    INTEGER     ARRAY CONTAINING THE INDICES OF THE
C                             COMPRESSED FORM.  IT IS ASSUMED THAT
C                             THE ELEMENTS IN  INDX  ARE DISTINCT.
C
C     UPDATED ...
C
C         Y       REAL        ARRAY, ON INPUT, WHICH CONTAINS THE
C                             VECTOR  Y  IN FULL STORAGE FORM.  ON
C                             OUTPUT ONLY THE ELEMENTS CORRESPONDING TO
C                             THE INDICES IN  INDX  HAVE BEEN MODIFIED.
C
C     SPARSE BASIC LINEAR ALGEBRA SUBPROGRAM
C
C     FORTRAN VERSION WRITTEN OCTOBER 1984
C     ROGER G GRIMES, BOEING COMPUTER SERVICES
C

F06EUF
      SUBROUTINE F06EUF(NZ,Y,X,INDX)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     PURPOSE
C
C         DGTHR GATHERS THE SPECIFIED ELEMENTS FROM
C             A REAL VECTOR  Y  IN FULL STORAGE FORM
C         INTO
C             A REAL VECTOR  X  IN COMPRESSED FORM (X,INDX).
C
C         ONLY THE ELEMENTS OF  Y  WHOSE INDICES ARE LISTED IN INDX
C         ARE REFERENCED.
C
C     ARGUMENTS
C
C     INPUT ...
C
C         NZ      INTEGER     NUMBER OF ELEMENTS TO BE GATHERED INTO
C                             COMPRESSED FORM.
C         Y       REAL        ARRAY, ON INPUT, WHICH CONTAINS THE
C                             VECTOR  Y  IN FULL STORAGE FORM.  ONLY
C                             THE ELEMENTS CORRESPONDING TO THE INDICES
C                             IN  INDX  WILL BE ACCESSED.
C         INDX    INTEGER     ARRAY CONTAINING THE INDICES OF THE
C                             VALUES TO BE GATHERED INTO COMPRESSED
C                             FORM.
C
C     OUTPUT ...
C
C         X       REAL        ARRAY CONTAINING THE VALUES GATHERED INTO
C                             THE COMPRESSED FORM.
C
C     SPARSE BASIC LINEAR ALGEBRA SUBPROGRAM
C
C     FORTRAN VERSION WRITTEN OCTOBER 1984
C     ROGER G GRIMES, BOEING COMPUTER SERVICES
C

F06EVF
      SUBROUTINE F06EVF(NZ,Y,X,INDX)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     PURPOSE
C
C         DGTHRZ GATHERS THE SPECIFIED ELEMENTS FROM
C             A REAL VECTOR  Y  IN FULL STORAGE FORM
C         INTO
C             A REAL VECTOR  X  IN COMPRESSED FORM  (X,INDX).
C         FURTHERMORE THE GATHERED ELEMENTS OF  Y  ARE SET TO ZERO.
C
C         ONLY THE ELEMENTS OF  Y  WHOSE INDICES ARE LISTED IN  INDX
C         ARE REFERENCED OR MODIFIED.
C
C     ARGUMENTS
C
C     INPUT ...
C
C         NZ      INTEGER     NUMBER OF ELEMENTS TO BE GATHERED INTO
C                             COMPRESSED FORM.
C         INDX    INTEGER     ARRAY CONTAINING THE INDICES OF THE
C                             VALUES TO BE GATHERED INTO COMPRESSED
C                             FORM.
C
C     UPDATED ...
C
C         Y       REAL        ARRAY, ON INPUT, WHICH CONTAINS THE
C                             VECTOR  Y  IN FULL STORAGE FORM.  THE
C                             GATHERED COMPONENTS IN  Y  ARE SET TO
C                             ZERO. ONLY THE ELEMENTS CORRESPONDING TO
C                             THE INDICES IN  INDX  HAVE BEEN ACCESSED.
C
C     OUTPUT ...
C
C         X       REAL        ARRAY CONTAINING THE VALUES GATHERED INTO
C                             THE COMPRESSED FORM.
C
C     SPARSE BASIC LINEAR ALGEBRA SUBPROGRAM
C
C     FORTRAN VERSION WRITTEN OCTOBER 1984
C     ROGER G GRIMES, BOEING COMPUTER SERVICES
C

F06EWF
      SUBROUTINE F06EWF(NZ,X,INDX,Y)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     PURPOSE
C
C         DSCTR SCATTERS THE COMPONENTS OF
C             A SPARSE VECTOR  X  STORED IN COMPRESSED FORM  (X,INDX)
C         INTO
C             SPECIFIED COMPONENTS OF A REAL VECTOR  Y
C             IN FULL STORAGE FORM.
C
C         ONLY THE ELEMENTS OF  Y  WHOSE INDICES ARE LISTED IN  INDX
C         ARE MODIFIED.  THE VALUES IN  INDX  MUST BE DISTINCT TO
C         ALLOW CONSISTENT VECTOR OR PARALLEL EXECUTION.
C
C         ALTHOUGH DISTINCT INDICES WILL ALLOW VECTOR OR PARALLEL
C         EXECUTION, MOST COMPILERS FOR HIGH-PERFORMANCE MACHINES WILL
C         BE UNABLE TO GENERATE BEST POSSIBLE CODE WITHOUT SOME
C         MODIFICATION, SUCH AS COMPILER DIRECTIVES, TO THIS CODE.
C
C     ARGUMENTS
C
C     INPUT ...
C
C         NZ      INTEGER     NUMBER OF ELEMENTS TO BE SCATTERED FROM
C                             COMPRESSED FORM.
C         X       REAL        ARRAY CONTAINING THE VALUES TO BE
C                             SCATTERED FROM COMPRESSED FORM INTO FULL
C                             STORAGE FORM.
C         INDX    INTEGER     ARRAY CONTAINING THE INDICES OF THE VALUES
C                             TO BE SCATTERED FROM COMPRESSED FORM.
C                             IT IS ASSUMED THAT THE ELEMENTS IN  INDX
C                             ARE DISTINCT.
C
C     OUTPUT ...
C
C         Y       REAL        ARRAY WHOSE ELEMENTS SPECIFIED BY  INDX
C                             HAVE BEEN SET TO THE CORRESPONDING
C                             ENTRIES OF  X.  ONLY THE ELEMENTS
C                             CORRESPONDING TO THE INDICES IN  INDX
C                             HAVE BEEN MODIFIED.
C
C     SPARSE BASIC LINEAR ALGEBRA SUBPROGRAM
C
C     FORTRAN VERSION WRITTEN OCTOBER 1984
C     ROGER G GRIMES, BOEING COMPUTER SERVICES
C

F06EXF
      SUBROUTINE F06EXF(NZ,X,INDX,Y,C,S)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     PURPOSE
C
C         DROTI APPLIES A GIVENS ROTATION TO
C             A SPARSE VECTOR   X  STORED IN COMPRESSED FORM  (X,INDX)
C         AND
C             ANOTHER VECTOR  Y  IN FULL STORAGE FORM.
C
C         DROTI DOES NOT HANDLE FILL-IN IN  X  AND THEREFORE, IT IS
C         ASSUMED THAT ALL NONZERO COMPONENTS OF  Y  ARE LISTED IN
C         INDX.  ONLY THE ELEMENTS OF  Y  WHOSE INDICES ARE LISTED IN
C         INDX  ARE REFERENCED OR MODIFIED.  THE VALUES IN  INDX  MUST
C         BE DISTINCT TO ALLOW CONSISTENT VECTOR OR PARALLEL EXECUTION.
C
C         ALTHOUGH DISTINCT INDICES WILL ALLOW VECTOR OR PARALLEL
C         EXECUTION, MOST COMPILERS FOR HIGH-PERFORMANCE MACHINES WILL
C         BE UNABLE TO GENERATE BEST POSSIBLE CODE WITHOUT SOME
C         MODIFICATION, SUCH AS COMPILER DIRECTIVES, TO THIS CODE.
C
C     ARGUMENTS
C
C     INPUT ...
C
C         NZ      INTEGER     NUMBER OF ELEMENTS IN THE COMPRESSED FORM.
C         INDX    INTEGER     ARRAY CONTAINING THE INDICIES OF THE
C                             COMPRESSED FORM.  IT IS ASSUMED THAT
C                             THE ELEMENTS IN  INDX  ARE DISTINCT.
C         C,S     REAL        THE TWO SCALARS DEFINING THE GIVENS
C                             ROTATION.
C
C     UPDATED ...
C
C         X       REAL        ARRAY CONTAINING THE VALUES OF THE
C                             SPARSE VECTOR IN COMPRESSED FORM.
C         Y       REAL        ARRAY WHICH CONTAINS THE VECTOR  Y
C                             IN FULL STORAGE FORM.  ONLY THE
C                             ELEMENTS WHOSE INDICIES ARE LISTED IN
C                             INDX  HAVE BEEN REFERENCED OR MODIFIED.
C
C     SPARSE BASIC LINEAR ALGEBRA SUBPROGRAM
C
C     FORTRAN VERSION WRITTEN OCTOBER 1984
C     ROGER G GRIMES, BOEING COMPUTER SERVICES
C

F06FAF
      DOUBLE PRECISION FUNCTION F06FAF( N, J, TOLX, X, INCX,
     $                                  TOLY, Y, INCY )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06FBF
      SUBROUTINE F06FBF( N, CONST, X, INCX )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06FCF
      SUBROUTINE F06FCF( N, D, INCD, X, INCX )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06FDF
      SUBROUTINE F06FDF( N, ALPHA, X, INCX, Y, INCY )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06FGF
      SUBROUTINE F06FGF( N, X, INCX )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06FJF
      SUBROUTINE F06FJF( N, X, INCX, SCALE, SUMSQ )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06FKF
      DOUBLE PRECISION FUNCTION F06FKF( N, W, INCW, X, INCX )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06FLF
      SUBROUTINE F06FLF( N, X, INCX, XMAX, XMIN )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06FPF
      SUBROUTINE F06FPF( N, X, INCX, Y, INCY, C, S )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06FQF
      SUBROUTINE F06FQF( PIVOT, DIRECT, N, ALPHA, X, INCX, C, S )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06FRF
      SUBROUTINE F06FRF( N, ALPHA, X, INCX, TOL, ZETA )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06FSF
      SUBROUTINE F06FSF( N, ALPHA, X, INCX, TOL, Z1 )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06FTF
      SUBROUTINE F06FTF( N, DELTA, Y, INCY, ZETA, Z, INCZ )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06FUF
      SUBROUTINE F06FUF( N, Z, INCZ, Z1, ALPHA, X, INCX )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06GAF
      COMPLEX*16       FUNCTION F06GAF( N, X, INCX, Y, INCY )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06GBF
      COMPLEX*16       FUNCTION F06GBF( N, X, INCX, Y, INCY )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06GCF
      SUBROUTINE F06GCF( N, ALPHA, X, INCX, Y, INCY )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06GDF
      SUBROUTINE F06GDF( N, ALPHA, X, INCX )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06GFF
      SUBROUTINE F06GFF( N, X, INCX, Y, INCY )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06GGF
      SUBROUTINE F06GGF( N, X, INCX, Y, INCY )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06GRF
      COMPLEX*16  FUNCTION F06GRF(NZ,X,INDX,Y)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     PURPOSE
C
C         ZDOTUI COMPUTES THE UNCONJUGATED VECTOR INNER PRODUCT OF
C             A COMPLEX SPARSE VECTOR  X
C             STORED IN COMPRESSED FORM  (X,INDX)
C         WITH
C             A COMPLEX VECTOR  Y  IN FULL STORAGE FORM.
C
C         ONLY THE ELEMENTS OF  Y  WHOSE INDICES ARE LISTED IN  INDX
C         ARE REFERENCED.
C
C     ARGUMENTS
C
C     INPUT ...
C
C         NZ      INTEGER     NUMBER OF ELEMENTS IN THE COMPRESSED FORM.
C         X       COMPLEX     ARRAY CONTAINING THE VALUES OF THE
C                             COMPRESSED FORM.
C         INDX    INTEGER     ARRAY CONTAINING THE INDICES OF THE
C                             COMPRESSED FORM.
C         Y       COMPLEX     ARRAY, ON INPUT, WHICH CONTAINS THE
C                             VECTOR  Y  IN FULL STORAGE FORM.  ONLY
C                             THE ELEMENTS  CORRESPONDING TO THE
C                             INDICES IN  INDX  WILL BE ACCESSED.
C
C     OUTPUT ...
C
C         ZDOTUI   COMPLEX    COMPLEX FUNCTION VALUE EQUAL TO THE
C                             UNCONJUGATED VECTOR INNER PRODUCT.
C                             IF  NZ .LE. 0  ZDOTCI IS SET TO ZERO.
C
C     SPARSE BASIC LINEAR ALGEBRA SUBPROGRAM
C
C     FORTRAN VERSION WRITTEN OCTOBER 1984
C     ROGER G GRIMES, BOEING COMPUTER SERVICES
C

F06GSF
      COMPLEX*16  FUNCTION F06GSF(NZ,X,INDX,Y)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     PURPOSE
C
C         ZDOTCI COMPUTES THE CONJUGATED VECTOR INNER PRODUCT OF
C             A COMPLEX SPARSE VECTOR  X
C             STORED IN COMPRESSED FORM  (X,INDX)
C         WITH
C             A COMPLEX VECTOR  Y  IN FULL STORAGE FORM.
C
C         ONLY THE ELEMENTS OF Y WHOSE INDICES ARE LISTED IN INDX
C         ARE REFERENCED.
C
C     ARGUMENTS
C
C     INPUT ...
C
C         NZ      INTEGER     NUMBER OF ELEMENTS IN THE COMPRESSED FORM.
C         X       COMPLEX     ARRAY CONTAINING THE VALUES OF THE
C                             COMPRESSED FORM.
C         INDX    INTEGER     ARRAY CONTAINING THE INDICES OF THE
C                             COMPRESSED FORM.
C         Y       COMPLEX     ARRAY, ON INPUT, WHICH CONTAINS THE
C                             VECTOR  Y  IN FULL STORAGE FORM.  ONLY
C                             THE ELEMENTS  CORRESPONDING TO THE
C                             INDICES IN  INDX  WILL BE ACCESSED.
C
C     OUTPUT ...
C
C         ZDOTCI   COMPLEX    COMPLEX FUNCTION VALUE EQUAL TO THE
C                             CONJUGATED VECTOR INNER PRODUCT.
C                             IF  NZ .LE. 0  ZDOTCI IS SET TO ZERO.
C
C     SPARSE BASIC LINEAR ALGEBRA SUBPROGRAM
C
C     FORTRAN VERSION WRITTEN OCTOBER 1984
C     ROGER G GRIMES, BOEING COMPUTER SERVICES
C

F06GTF
      SUBROUTINE F06GTF(NZ,A,X,INDX,Y)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     PURPOSE
C
C         ZAXPYI ADDS A COMPLEX SCALAR MULTIPLE OF
C             A COMPLEX SPARSE VECTOR  X
C             STORED IN COMPRESSED FORM  (X,INDX)
C         TO
C             A COMPLEX VECTOR  Y  IN FULL STORAGE FORM.
C
C         ONLY THE ELEMENTS OF  Y  WHOSE INDICES ARE LISTED IN  INDX
C         ARE REFERENCED OR MODIFIED.  THE VALUES IN  INDX  MUST BE
C         DISTINCT TO ALLOW CONSISTENT VECTOR OR PARALLEL EXECUTION.
C
C         ALTHOUGH DISTINCT INDICES WILL ALLOW VECTOR OR PARALLEL
C         EXECUTION, MOST COMPILERS FOR HIGH-PERFORMANCE MACHINES WILL
C         BE UNABLE TO GENERATE BEST POSSIBLE CODE WITHOUT SOME
C         MODIFICATION, SUCH AS COMPILER DIRECTIVES, TO THIS CODE.
C
C     ARGUMENTS
C
C     INPUT ...
C
C         NZ      INTEGER     NUMBER OF ELEMENTS IN THE COMPRESSED FORM.
C         A       COMPLEX     SCALAR MULTIPLIER OF  X.
C         X       COMPLEX     ARRAY CONTAINING THE VALUES OF THE
C                             COMPRESSED FORM.
C         INDX    INTEGER     ARRAY CONTAINING THE INDICES OF THE
C                             COMPRESSED FORM.  IT IS ASSUMED THAT
C                             THE ELEMENTS IN  INDX  ARE DISTINCT.
C
C     UPDATED ...
C
C         Y       COMPLEX     ARRAY, ON INPUT, WHICH CONTAINS THE
C                             VECTOR  Y  IN FULL STORAGE FORM.  ON
C                             OUTPUT ONLY THE ELEMENTS CORRESPONDING TO
C                             THE INDICES IN  INDX  HAVE BEEN MODIFIED.
C
C     SPARSE BASIC LINEAR ALGEBRA SUBPROGRAM
C
C     FORTRAN VERSION WRITTEN OCTOBER 1984
C     ROGER G GRIMES, BOEING COMPUTER SERVICES
C

F06GUF
      SUBROUTINE F06GUF(NZ,Y,X,INDX)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     PURPOSE
C
C         ZGTHR GATHERS THE SPECIFIED ELEMENTS FROM
C             A COMPLEX VECTOR  Y  IN FULL STORAGE FORM
C         INTO
C             A COMPLEX VECTOR  X  IN COMPRESSED FORM (X,INDX).
C
C         ONLY THE ELEMENTS OF  Y  WHOSE INDICES ARE LISTED IN INDX
C         ARE REFERENCED.
C
C     ARGUMENTS
C
C     INPUT ...
C
C         NZ      INTEGER     NUMBER OF ELEMENTS TO BE GATHERED INTO
C                             COMPRESSED FORM.
C         Y       COMPLEX     ARRAY, ON INPUT, WHICH CONTAINS THE
C                             VECTOR  Y  IN FULL STORAGE FORM.  ONLY
C                             THE ELEMENTS CORRESPONDING TO THE INDICES
C                             IN  INDX  WILL BE ACCESSED.
C         INDX    INTEGER     ARRAY CONTAINING THE INDICES OF THE
C                             VALUES TO BE GATHERED INTO COMPRESSED
C                             FORM.
C
C     OUTPUT ...
C
C         X       COMPLEX     ARRAY CONTAINING THE VALUES GATHERED INTO
C                             THE COMPRESSED FORM.
C
C     SPARSE BASIC LINEAR ALGEBRA SUBPROGRAM
C
C     FORTRAN VERSION WRITTEN OCTOBER 1984
C     ROGER G GRIMES, BOEING COMPUTER SERVICES
C

F06GVF
      SUBROUTINE F06GVF(NZ,Y,X,INDX)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     PURPOSE
C
C         ZGTHRZ GATHERS THE SPECIFIED ELEMENTS FROM
C             A COMPLEX VECTOR  Y  IN FULL STORAGE FORM
C         INTO
C             A COMPLEX VECTOR  X  IN COMPRESSED FORM  (X,INDX).
C         FURTHERMORE THE GATHERED ELEMENTS OF  Y  ARE SET TO ZERO.
C
C         ONLY THE ELEMENTS OF  Y  WHOSE INDICES ARE LISTED IN  INDX
C         ARE REFERENCED OR MODIFIED.
C
C     ARGUMENTS
C
C     INPUT ...
C
C         NZ      INTEGER     NUMBER OF ELEMENTS TO BE GATHERED INTO
C                             COMPRESSED FORM.
C         INDX    INTEGER     ARRAY CONTAINING THE INDICES OF THE
C                             VALUES TO BE GATHERED INTO COMPRESSED
C                             FORM.
C
C     UPDATED ...
C
C         Y       COMPLEX     ARRAY, ON INPUT, WHICH CONTAINS THE
C                             VECTOR  Y  IN FULL STORAGE FORM.  THE
C                             GATHERED COMPONENTS IN  Y  ARE SET TO
C                             ZERO. ONLY THE ELEMENTS CORRESPONDING TO
C                             THE INDICES IN  INDX  HAVE BEEN ACCESSED.
C
C     OUTPUT ...
C
C         X       COMPLEX     ARRAY CONTAINING THE VALUES GATHERED INTO
C                             THE COMPRESSED FORM.
C
C     SPARSE BASIC LINEAR ALGEBRA SUBPROGRAM
C
C     FORTRAN VERSION WRITTEN OCTOBER 1984
C     ROGER G GRIMES, BOEING COMPUTER SERVICES
C

F06GWF
      SUBROUTINE F06GWF(NZ,X,INDX,Y)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     PURPOSE
C
C         ZSCTR SCATTERS THE COMPONENTS OF
C             A SPARSE VECTOR  X  STORED IN COMPRESSED FORM  (X,INDX)
C         INTO
C             SPECIFIED COMPONENTS OF A COMPLEX VECTOR  Y
C             IN FULL STORAGE FORM.
C
C         ONLY THE ELEMENTS OF  Y  WHOSE INDICES ARE LISTED IN  INDX
C         ARE MODIFIED.  THE VALUES IN  INDX  MUST BE DISTINCT TO
C         ALLOW CONSISTENT VECTOR OR PARALLEL EXECUTION.
C
C         ALTHOUGH DISTINCT INDICES WILL ALLOW VECTOR OR PARALLEL
C         EXECUTION, MOST COMPILERS FOR HIGH-PERFORMANCE MACHINES WILL
C         BE UNABLE TO GENERATE BEST POSSIBLE CODE WITHOUT SOME
C         MODIFICATION, SUCH AS COMPILER DIRECTIVES, TO THIS CODE.
C
C     ARGUMENTS
C
C     INPUT ...
C
C         NZ      INTEGER     NUMBER OF ELEMENTS TO BE SCATTERED FROM
C                             COMPRESSED FORM.
C         X       COMPLEX     ARRAY CONTAINING THE VALUES TO BE
C                             SCATTERED FROM COMPRESSED FORM INTO FULL
C                             STORAGE FORM.
C         INDX    INTEGER     ARRAY CONTAINING THE INDICES OF THE VALUES
C                             TO BE SCATTERED FROM COMPRESSED FORM.
C                             IT IS ASSUMED THAT THE ELEMENTS IN  INDX
C                             ARE DISTINCT.
C
C     OUTPUT ...
C
C         Y       COMPLEX     ARRAY WHOSE ELEMENTS SPECIFIED BY  INDX
C                             HAVE BEEN SET TO THE CORRESPONDING
C                             ENTRIES OF  X.  ONLY THE ELEMENTS
C                             CORRESPONDING TO THE INDICES IN  INDX
C                             HAVE BEEN MODIFIED.
C
C     SPARSE BASIC LINEAR ALGEBRA SUBPROGRAM
C
C     FORTRAN VERSION WRITTEN OCTOBER 1984
C     ROGER G GRIMES, BOEING COMPUTER SERVICES
C

F06HBF
      SUBROUTINE F06HBF( N, CONST, X, INCX )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06HCF
      SUBROUTINE F06HCF( N, D, INCD, X, INCX )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06HDF
      SUBROUTINE F06HDF( N, ALPHA, X, INCX, Y, INCY )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06HGF
      SUBROUTINE F06HGF( N, X, INCX )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06HPF
      SUBROUTINE F06HPF( N, X, INCX, Y, INCY, C, S )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06HQF
      SUBROUTINE F06HQF( PIVOT, DIRECT, N, ALPHA, X, INCX, C, S )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06HRF
      SUBROUTINE F06HRF( N, ALPHA, X, INCX, TOL, THETA )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06HTF
      SUBROUTINE F06HTF( N, DELTA, Y, INCY, THETA, Z, INCZ )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06JDF
      SUBROUTINE F06JDF( N, ALPHA, X, INCX )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06JJF
      DOUBLE PRECISION FUNCTION F06JJF( N, X, INCX )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06JKF
      DOUBLE PRECISION FUNCTION F06JKF( N, X, INCX )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06JLF
      INTEGER FUNCTION F06JLF( N, X, INCX )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06JMF
      INTEGER FUNCTION F06JMF( N, X, INCX )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06KCF
      SUBROUTINE F06KCF( N, D, INCD, X, INCX )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06KDF
      SUBROUTINE F06KDF( N, ALPHA, X, INCX, Y, INCY )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06KFF
      SUBROUTINE F06KFF( N, X, INCX, Y, INCY )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06KJF
      SUBROUTINE F06KJF( N, X, INCX, SCALE, SUMSQ )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06KLF
      INTEGER FUNCTION F06KLF( N, X, INCX, TOL )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06KPF
      SUBROUTINE F06KPF( N, X, INCX, Y, INCY, C, S )
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

F06PAF
      SUBROUTINE F06PAF( TRANS, M, N, ALPHA, A, LDA, X, INCX,
     $                   BETA, Y, INCY )
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.

F06PBF
      SUBROUTINE F06PBF( TRANS, M, N, KL, KU, ALPHA, A, LDA, X, INCX,
     $                   BETA, Y, INCY )
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.

F06PCF
      SUBROUTINE F06PCF( UPLO, N, ALPHA, A, LDA, X, INCX,
     $                   BETA, Y, INCY )
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.

F06PDF
      SUBROUTINE F06PDF( UPLO, N, K, ALPHA, A, LDA, X, INCX,
     $                   BETA, Y, INCY )
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.

F06PEF
      SUBROUTINE F06PEF( UPLO, N, ALPHA, AP, X, INCX, BETA, Y, INCY )
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.

F06PFF
      SUBROUTINE F06PFF( UPLO, TRANS, DIAG, N, A, LDA, X, INCX )
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.

F06PGF
      SUBROUTINE F06PGF( UPLO, TRANS, DIAG, N, K, A, LDA, X, INCX )
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.

F06PHF
      SUBROUTINE F06PHF( UPLO, TRANS, DIAG, N, AP, X, INCX )
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.

F06PJF
      SUBROUTINE F06PJF( UPLO, TRANS, DIAG, N, A, LDA, X, INCX )
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.

F06PKF
      SUBROUTINE F06PKF( UPLO, TRANS, DIAG, N, K, A, LDA, X, INCX )
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.

F06PLF
      SUBROUTINE F06PLF( UPLO, TRANS, DIAG, N, AP, X, INCX )
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.

F06PMF
      SUBROUTINE F06PMF( M, N, ALPHA, X, INCX, Y, INCY, A, LDA )
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.

F06PPF
      SUBROUTINE F06PPF( UPLO, N, ALPHA, X, INCX, A, LDA )
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.

F06PQF
      SUBROUTINE F06PQF( UPLO, N, ALPHA, X, INCX, AP )
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.

F06PRF
      SUBROUTINE F06PRF( UPLO, N, ALPHA, X, INCX, Y, INCY, A, LDA )
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.

F06PSF
      SUBROUTINE F06PSF( UPLO, N, ALPHA, X, INCX, Y, INCY, AP )
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.

F06QFF
      SUBROUTINE F06QFF( MATRIX, M, N, A, LDA, B, LDB )
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.

F06QHF
      SUBROUTINE F06QHF( MATRIX, M, N, CONST, DIAG, A, LDA )
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.

F06QJF
      SUBROUTINE F06QJF( SIDE, TRANS, N, PERM, K, B, LDB )
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.

F06QKF
      SUBROUTINE F06QKF( SIDE, TRANS, N, PERM, K, B, LDB )
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.

F06QMF
      SUBROUTINE F06QMF( UPLO, PIVOT, DIRECT, N, K1, K2, C, S, A, LDA )
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.

F06QPF
      SUBROUTINE F06QPF( N, ALPHA, X, INCX, Y, INCY, A, LDA, C, S )
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.

F06QQF
      SUBROUTINE F06QQF( N, ALPHA, X, INCX, A, LDA, C, S )
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.

F06QRF
      SUBROUTINE F06QRF( SIDE, N, K1, K2, C, S, A, LDA )
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.

F06QSF
      SUBROUTINE F06QSF( SIDE, N, K1, K2, C, S, A, LDA )
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.

F06QTF
      SUBROUTINE F06QTF( SIDE, N, K1, K2, C, S, A, LDA )
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.

F06QVF
      SUBROUTINE F06QVF( SIDE, N, K1, K2, C, S, A, LDA )
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.

F06QWF
      SUBROUTINE F06QWF( SIDE, N, K1, K2, C, S, A, LDA )
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.

F06QXF
      SUBROUTINE F06QXF( SIDE, PIVOT, DIRECT, M, N, K1, K2, C, S, A,
     $                   LDA )
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.

F06RAF
      DOUBLE PRECISION FUNCTION F06RAF(NORM,M,N,A,LDA,WORK)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C     REAL                 DLANGE
C     ENTRY                DLANGE(NORM,M,N,A,LDA,WORK)
C
C  Purpose
C  =======
C
C  DLANGE  returns the value of the one norm,  or the Frobenius norm, or
C  the  infinity norm,  or the  element of  largest absolute value  of a
C  real matrix A.
C
C  Description
C  ===========
C
C  DLANGE returns the value
C
C     DLANGE = ( max(abs(A(i,j))), NORM = 'M' or 'm'
C              (
C              ( norm1(A),         NORM = '1', 'O' or 'o'
C              (
C              ( normI(A),         NORM = 'I' or 'i'
C              (
C              ( normF(A),         NORM = 'F', 'f', 'E' or 'e'
C
C  where  norm1  denotes the  one norm of a matrix (maximum column sum),
C  normI  denotes the  infinity norm  of a matrix  (maximum row sum) and
C  normF  denotes the  Frobenius norm of a matrix (square root of sum of
C  squares).  Note that  max(abs(A(i,j)))  is not a  matrix norm.
C
C  Arguments
C  =========
C
C  NORM    (input) CHARACTER*1
C          Specifies the value to be returned in DLANGE as described
C          above.
C
C  M       (input) INTEGER
C          The number of rows of the matrix A.  M >= 0.  When M = 0,
C          DLANGE is set to zero.
C
C  N       (input) INTEGER
C          The number of columns of the matrix A.  N >= 0.  When N = 0,
C          DLANGE is set to zero.
C
C  A       (input) REAL array, dimension (LDA,N)
C          The m by n matrix A.
C
C  LDA     (input) INTEGER
C          The leading dimension of the array A.  LDA >= max(M,1).
C
C  WORK    (workspace) REAL array, dimension (LWORK),
C          where LWORK >= M when NORM = 'I'; otherwise, WORK is not
C          referenced.
C
C
C  -- LAPACK auxiliary routine (adapted for NAG Library)
C     Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
C     Courant Institute, Argonne National Lab, and Rice University
C

F06RBF
      DOUBLE PRECISION FUNCTION F06RBF(NORM,N,KL,KU,AB,LDAB,WORK)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C     REAL                 DLANGB
C     ENTRY                DLANGB(NORM,N,KL,KU,AB,LDAB,WORK)
C
C  Purpose
C  =======
C
C  DLANGB  returns the value of the one norm,  or the Frobenius norm, or
C  the  infinity norm,  or the element of  largest absolute value  of an
C  n by n band matrix  A,  with kl sub-diagonals and ku super-diagonals.
C
C  Description
C  ===========
C
C  DLANGB returns the value
C
C     DLANGB = ( max(abs(A(i,j))), NORM = 'M' or 'm'
C              (
C              ( norm1(A),         NORM = '1', 'O' or 'o'
C              (
C              ( normI(A),         NORM = 'I' or 'i'
C              (
C              ( normF(A),         NORM = 'F', 'f', 'E' or 'e'
C
C  where  norm1  denotes the  one norm of a matrix (maximum column sum),
C  normI  denotes the  infinity norm  of a matrix  (maximum row sum) and
C  normF  denotes the  Frobenius norm of a matrix (square root of sum of
C  squares).  Note that  max(abs(A(i,j)))  is not a  matrix norm.
C
C  Arguments
C  =========
C
C  NORM    (input) CHARACTER*1
C          Specifies the value to be returned in DLANGB as described
C          above.
C
C  N       (input) INTEGER
C          The order of the matrix A.  N >= 0.  When N = 0, DLANGB is
C          set to zero.
C
C  KL      (input) INTEGER
C          The number of sub-diagonals of the matrix A.  KL >= 0.
C
C  KU      (input) INTEGER
C          The number of super-diagonals of the matrix A.  KU >= 0.
C
C  AB      (input) REAL array, dimension (LDAB,N)
C          The band matrix A, stored in rows 1 to KL+KU+1.  The j-th
C          column of A is stored in the j-th column of the array AB as
C          follows:
C          AB(ku+1+i-j,j) = A(i,j) for max(1,j-ku)<=i<=min(n,j+kl).
C
C  LDAB    (input) INTEGER
C          The leading dimension of the array AB.  LDAB >= KL+KU+1.
C
C  WORK    (workspace) REAL array, dimension (LWORK),
C          where LWORK >= N when NORM = 'I'; otherwise, WORK is not
C          referenced.
C
C
C  -- LAPACK auxiliary routine (adapted for NAG Library)
C     Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
C     Courant Institute, Argonne National Lab, and Rice University
C

F06RCF
      DOUBLE PRECISION FUNCTION F06RCF(NORM,UPLO,N,A,LDA,WORK)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C     REAL                 DLANSY
C     ENTRY                DLANSY(NORM,UPLO,N,A,LDA,WORK)
C
C  Purpose
C  =======
C
C  DLANSY  returns the value of the one norm,  or the Frobenius norm, or
C  the  infinity norm,  or the  element of  largest absolute value  of a
C  real symmetric matrix A.
C
C  Description
C  ===========
C
C  DLANSY returns the value
C
C     DLANSY = ( max(abs(A(i,j))), NORM = 'M' or 'm'
C              (
C              ( norm1(A),         NORM = '1', 'O' or 'o'
C              (
C              ( normI(A),         NORM = 'I' or 'i'
C              (
C              ( normF(A),         NORM = 'F', 'f', 'E' or 'e'
C
C  where  norm1  denotes the  one norm of a matrix (maximum column sum),
C  normI  denotes the  infinity norm  of a matrix  (maximum row sum) and
C  normF  denotes the  Frobenius norm of a matrix (square root of sum of
C  squares).  Note that  max(abs(A(i,j)))  is not a  matrix norm.
C
C  Arguments
C  =========
C
C  NORM    (input) CHARACTER*1
C          Specifies the value to be returned in DLANSY as described
C          above.
C
C  UPLO    (input) CHARACTER*1
C          Specifies whether the upper or lower triangular part of the
C          symmetric matrix A is to be referenced.
C          = 'U':  Upper triangular part of A is referenced
C          = 'L':  Lower triangular part of A is referenced
C
C  N       (input) INTEGER
C          The order of the matrix A.  N >= 0.  When N = 0, DLANSY is
C          set to zero.
C
C  A       (input) REAL array, dimension (LDA,N)
C          The symmetric matrix A.  If UPLO = 'U', the leading n by n
C          upper triangular part of A contains the upper triangular part
C          of the matrix A, and the strictly lower triangular part of A
C          is not referenced.  If UPLO = 'L', the leading n by n lower
C          triangular part of A contains the lower triangular part of
C          the matrix A, and the strictly upper triangular part of A is
C          not referenced.
C
C  LDA     (input) INTEGER
C          The leading dimension of the array A.  LDA >= max(N,1).
C
C  WORK    (workspace) REAL array, dimension (LWORK),
C          where LWORK >= N when NORM = 'I' or '1' or 'O'; otherwise,
C          WORK is not referenced.
C
C
C  -- LAPACK auxiliary routine (adapted for NAG Library)
C     Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
C     Courant Institute, Argonne National Lab, and Rice University
C

F06RDF
      DOUBLE PRECISION FUNCTION F06RDF(NORM,UPLO,N,AP,WORK)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C     REAL                 DLANSP
C     ENTRY                DLANSP(NORM,UPLO,N,AP,WORK)
C
C  Purpose
C  =======
C
C  DLANSP  returns the value of the one norm,  or the Frobenius norm, or
C  the  infinity norm,  or the  element of  largest absolute value  of a
C  real symmetric matrix A,  supplied in packed form.
C
C  Description
C  ===========
C
C  DLANSP returns the value
C
C     DLANSP = ( max(abs(A(i,j))), NORM = 'M' or 'm'
C              (
C              ( norm1(A),         NORM = '1', 'O' or 'o'
C              (
C              ( normI(A),         NORM = 'I' or 'i'
C              (
C              ( normF(A),         NORM = 'F', 'f', 'E' or 'e'
C
C  where  norm1  denotes the  one norm of a matrix (maximum column sum),
C  normI  denotes the  infinity norm  of a matrix  (maximum row sum) and
C  normF  denotes the  Frobenius norm of a matrix (square root of sum of
C  squares).  Note that  max(abs(A(i,j)))  is not a  matrix norm.
C
C  Arguments
C  =========
C
C  NORM    (input) CHARACTER*1
C          Specifies the value to be returned in DLANSP as described
C          above.
C
C  UPLO    (input) CHARACTER*1
C          Specifies whether the upper or lower triangular part of the
C          symmetric matrix A is supplied.
C          = 'U':  Upper triangular part of A is supplied
C          = 'L':  Lower triangular part of A is supplied
C
C  N       (input) INTEGER
C          The order of the matrix A.  N >= 0.  When N = 0, DLANSP is
C          set to zero.
C
C  AP      (input) REAL array, dimension (N*(N+1)/2)
C          The upper or lower triangle of the symmetric matrix A, packed
C          columnwise in a linear array.  The j-th column of A is stored
C          in the array AP as follows:
C          if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j;
C          if UPLO = 'L', AP(i + (j-1)*(2n-j+2)/2) = A(i,j) for j<=i<=n.
C
C  WORK    (workspace) REAL array, dimension (LWORK),
C          where LWORK >= N when NORM = 'I' or '1' or 'O'; otherwise,
C          WORK is not referenced.
C
C
C  -- LAPACK auxiliary routine (adapted for NAG Library)
C     Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
C     Courant Institute, Argonne National Lab, and Rice University
C

F06REF
      DOUBLE PRECISION FUNCTION F06REF(NORM,UPLO,N,K,AB,LDAB,WORK)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C     REAL                 DLANSB
C     ENTRY                DLANSB(NORM,UPLO,N,K,AB,LDAB,WORK)
C
C  Purpose
C  =======
C
C  DLANSB  returns the value of the one norm,  or the Frobenius norm, or
C  the  infinity norm,  or the element of  largest absolute value  of an
C  n by n symmetric band matrix A,  with k super-diagonals.
C
C  Description
C  ===========
C
C  DLANSB returns the value
C
C     DLANSB = ( max(abs(A(i,j))), NORM = 'M' or 'm'
C              (
C              ( norm1(A),         NORM = '1', 'O' or 'o'
C              (
C              ( normI(A),         NORM = 'I' or 'i'
C              (
C              ( normF(A),         NORM = 'F', 'f', 'E' or 'e'
C
C  where  norm1  denotes the  one norm of a matrix (maximum column sum),
C  normI  denotes the  infinity norm  of a matrix  (maximum row sum) and
C  normF  denotes the  Frobenius norm of a matrix (square root of sum of
C  squares).  Note that  max(abs(A(i,j)))  is not a  matrix norm.
C
C  Arguments
C  =========
C
C  NORM    (input) CHARACTER*1
C          Specifies the value to be returned in DLANSB as described
C          above.
C
C  UPLO    (input) CHARACTER*1
C          Specifies whether the upper or lower triangular part of the
C          band matrix A is supplied.
C          = 'U':  Upper triangular part is supplied
C          = 'L':  Lower triangular part is supplied
C
C  N       (input) INTEGER
C          The order of the matrix A.  N >= 0.  When N = 0, DLANSB is
C          set to zero.
C
C  K       (input) INTEGER
C          The number of super-diagonals or sub-diagonals of the
C          band matrix A.  K >= 0.
C
C  AB      (input) REAL array, dimension (LDAB,N)
C          The upper or lower triangle of the symmetric band matrix A,
C          stored in the first K+1 rows of AB.  The j-th column of A is
C          stored in the j-th column of the array AB as follows:
C          if UPLO = 'U', AB(k+1+i-j,j) = A(i,j) for max(1,j-k)<=i<=j;
C          if UPLO = 'L', AB(1+i-j,j)   = A(i,j) for j<=i<=min(n,j+k).
C
C  LDAB    (input) INTEGER
C          The leading dimension of the array AB.  LDAB >= K+1.
C
C  WORK    (workspace) REAL array, dimension (LWORK),
C          where LWORK >= N when NORM = 'I' or '1' or 'O'; otherwise,
C          WORK is not referenced.
C
C
C  -- LAPACK auxiliary routine (adapted for NAG Library)
C     Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
C     Courant Institute, Argonne National Lab, and Rice University
C

F06RJF
      DOUBLE PRECISION FUNCTION F06RJF(NORM,UPLO,DIAG,M,N,A,LDA,WORK)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C     REAL                 DLANTR
C     ENTRY                DLANTR(NORM,UPLO,DIAG,M,N,A,LDA,WORK)
C
C  Purpose
C  =======
C
C  DLANTR  returns the value of the one norm,  or the Frobenius norm, or
C  the  infinity norm,  or the  element of  largest absolute value  of a
C  trapezoidal or triangular matrix A.
C
C  Description
C  ===========
C
C  DLANTR returns the value
C
C     DLANTR = ( max(abs(A(i,j))), NORM = 'M' or 'm'
C              (
C              ( norm1(A),         NORM = '1', 'O' or 'o'
C              (
C              ( normI(A),         NORM = 'I' or 'i'
C              (
C              ( normF(A),         NORM = 'F', 'f', 'E' or 'e'
C
C  where  norm1  denotes the  one norm of a matrix (maximum column sum),
C  normI  denotes the  infinity norm  of a matrix  (maximum row sum) and
C  normF  denotes the  Frobenius norm of a matrix (square root of sum of
C  squares).  Note that  max(abs(A(i,j)))  is not a  matrix norm.
C
C  Arguments
C  =========
C
C  NORM    (input) CHARACTER*1
C          Specifies the value to be returned in DLANTR as described
C          above.
C
C  UPLO    (input) CHARACTER*1
C          Specifies whether the matrix A is upper or lower trapezoidal.
C          = 'U':  Upper trapezoidal
C          = 'L':  Lower trapezoidal
C          Note that A is triangular instead of trapezoidal if M = N.
C
C  DIAG    (input) CHARACTER*1
C          Specifies whether or not the matrix A has unit diagonal.
C          = 'N':  Non-unit diagonal
C          = 'U':  Unit diagonal
C
C  M       (input) INTEGER
C          The number of rows of the matrix A.  M >= 0, and if
C          UPLO = 'U', M <= N.  When M = 0, DLANTR is set to zero.
C
C  N       (input) INTEGER
C          The number of columns of the matrix A.  N >= 0, and if
C          UPLO = 'L', N <= M.  When N = 0, DLANTR is set to zero.
C
C  A       (input) REAL array, dimension (LDA,N)
C          The trapezoidal matrix A (A is triangular if M = N).
C          If UPLO = 'U', the leading m by n upper trapezoidal part of
C          the array A contains the upper trapezoidal matrix, and the
C          strictly lower triangular part of A is not referenced.
C          If UPLO = 'L', the leading m by n lower trapezoidal part of
C          the array A contains the lower trapezoidal matrix, and the
C          strictly upper triangular part of A is not referenced.  Note
C          that when DIAG = 'U', the diagonal elements of A are not
C          referenced and are assumed to be one.
C
C  LDA     (input) INTEGER
C          The leading dimension of the array A.  LDA >= max(M,1).
C
C  WORK    (workspace) REAL array, dimension (LWORK),
C          where LWORK >= M when NORM = 'I'; otherwise, WORK is not
C          referenced.
C
C
C  -- LAPACK auxiliary routine (adapted for NAG Library)
C     Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
C     Courant Institute, Argonne National Lab, and Rice University
C

F06RKF
      DOUBLE PRECISION FUNCTION F06RKF(NORM,UPLO,DIAG,N,AP,WORK)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C     REAL                 DLANTP
C     ENTRY                DLANTP(NORM,UPLO,DIAG,N,AP,WORK)
C
C  Purpose
C  =======
C
C  DLANTP  returns the value of the one norm,  or the Frobenius norm, or
C  the  infinity norm,  or the  element of  largest absolute value  of a
C  triangular matrix A, supplied in packed form.
C
C  Description
C  ===========
C
C  DLANTP returns the value
C
C     DLANTP = ( max(abs(A(i,j))), NORM = 'M' or 'm'
C              (
C              ( norm1(A),         NORM = '1', 'O' or 'o'
C              (
C              ( normI(A),         NORM = 'I' or 'i'
C              (
C              ( normF(A),         NORM = 'F', 'f', 'E' or 'e'
C
C  where  norm1  denotes the  one norm of a matrix (maximum column sum),
C  normI  denotes the  infinity norm  of a matrix  (maximum row sum) and
C  normF  denotes the  Frobenius norm of a matrix (square root of sum of
C  squares).  Note that  max(abs(A(i,j)))  is not a  matrix norm.
C
C  Arguments
C  =========
C
C  NORM    (input) CHARACTER*1
C          Specifies the value to be returned in DLANTP as described
C          above.
C
C  UPLO    (input) CHARACTER*1
C          Specifies whether the matrix A is upper or lower triangular.
C          = 'U':  Upper triangular
C          = 'L':  Lower triangular
C
C  DIAG    (input) CHARACTER*1
C          Specifies whether or not the matrix A is unit triangular.
C          = 'N':  Non-unit triangular
C          = 'U':  Unit triangular
C
C  N       (input) INTEGER
C          The order of the matrix A.  N >= 0.  When N = 0, DLANTP is
C          set to zero.
C
C  AP      (input) REAL array, dimension (N*(N+1)/2)
C          The upper or lower triangular matrix A, packed columnwise in
C          a linear array.  The j-th column of A is stored in the array
C          AP as follows:
C          if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j;
C          if UPLO = 'L', AP(i + (j-1)*(2n-j+2)/2) = A(i,j) for j<=i<=n.
C          Note that when DIAG = 'U', the elements of the array AP
C          corresponding to the diagonal elements of the matrix A are
C          not referenced, but are assumed to be one.
C
C  WORK    (workspace) REAL array, dimension (LWORK),
C          where LWORK >= N when NORM = 'I'; otherwise, WORK is not
C          referenced.
C
C
C  -- LAPACK auxiliary routine (adapted for NAG Library)
C     Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
C     Courant Institute, Argonne National Lab, and Rice University
C

F06RLF
      DOUBLE PRECISION FUNCTION F06RLF(NORM,UPLO,DIAG,N,K,AB,LDAB,WORK)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C     REAL                 DLANTB
C     ENTRY                DLANTB(NORM,UPLO,DIAG,N,K,AB,LDAB,WORK)
C
C  Purpose
C  =======
C
C  DLANTB  returns the value of the one norm,  or the Frobenius norm, or
C  the  infinity norm,  or the element of  largest absolute value  of an
C  n by n triangular band matrix A,  with ( k + 1 ) diagonals.
C
C  Description
C  ===========
C
C  DLANTB returns the value
C
C     DLANTB = ( max(abs(A(i,j))), NORM = 'M' or 'm'
C              (
C              ( norm1(A),         NORM = '1', 'O' or 'o'
C              (
C              ( normI(A),         NORM = 'I' or 'i'
C              (
C              ( normF(A),         NORM = 'F', 'f', 'E' or 'e'
C
C  where  norm1  denotes the  one norm of a matrix (maximum column sum),
C  normI  denotes the  infinity norm  of a matrix  (maximum row sum) and
C  normF  denotes the  Frobenius norm of a matrix (square root of sum of
C  squares).  Note that  max(abs(A(i,j)))  is not a  matrix norm.
C
C  Arguments
C  =========
C
C  NORM    (input) CHARACTER*1
C          Specifies the value to be returned in DLANTB as described
C          above.
C
C  UPLO    (input) CHARACTER*1
C          Specifies whether the matrix A is upper or lower triangular.
C          = 'U':  Upper triangular
C          = 'L':  Lower triangular
C
C  DIAG    (input) CHARACTER*1
C          Specifies whether or not the matrix A is unit triangular.
C          = 'N':  Non-unit triangular
C          = 'U':  Unit triangular
C
C  N       (input) INTEGER
C          The order of the matrix A.  N >= 0.  When N = 0, DLANTB is
C          set to zero.
C
C  K       (input) INTEGER
C          The number of super-diagonals of the matrix A if UPLO = 'U',
C          or the number of sub-diagonals of the matrix A if UPLO = 'L'.
C          K >= 0.
C
C  AB      (input) REAL array, dimension (LDAB,N)
C          The upper or lower triangular band matrix A, stored in the
C          first k+1 rows of AB.  The j-th column of A is stored
C          in the j-th column of the array AB as follows:
C          if UPLO = 'U', AB(k+1+i-j,j) = A(i,j) for max(1,j-k)<=i<=j;
C          if UPLO = 'L', AB(1+i-j,j)   = A(i,j) for j<=i<=min(n,j+k).
C          Note that when DIAG = 'U', the elements of the array AB
C          corresponding to the diagonal elements of the matrix A are
C          not referenced, but are assumed to be one.
C
C  LDAB    (input) INTEGER
C          The leading dimension of the array AB.  LDAB >= K+1.
C
C  WORK    (workspace) REAL array, dimension (LWORK),
C          where LWORK >= N when NORM = 'I'; otherwise, WORK is not
C          referenced.
C
C
C  -- LAPACK auxiliary routine (adapted for NAG Library)
C     Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
C     Courant Institute, Argonne National Lab, and Rice University
C

F06RMF
      DOUBLE PRECISION FUNCTION F06RMF(NORM,N,A,LDA,WORK)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C     REAL                 DLANHS
C     ENTRY                DLANHS(NORM,N,A,LDA,WORK)
C
C  Purpose
C  =======
C
C  DLANHS  returns the value of the one norm,  or the Frobenius norm, or
C  the  infinity norm,  or the  element of  largest absolute value  of a
C  Hessenberg matrix A.
C
C  Description
C  ===========
C
C  DLANHS returns the value
C
C     DLANHS = ( max(abs(A(i,j))), NORM = 'M' or 'm'
C              (
C              ( norm1(A),         NORM = '1', 'O' or 'o'
C              (
C              ( normI(A),         NORM = 'I' or 'i'
C              (
C              ( normF(A),         NORM = 'F', 'f', 'E' or 'e'
C
C  where  norm1  denotes the  one norm of a matrix (maximum column sum),
C  normI  denotes the  infinity norm  of a matrix  (maximum row sum) and
C  normF  denotes the  Frobenius norm of a matrix (square root of sum of
C  squares).  Note that  max(abs(A(i,j)))  is not a  matrix norm.
C
C  Arguments
C  =========
C
C  NORM    (input) CHARACTER*1
C          Specifies the value to be returned in DLANHS as described
C          above.
C
C  N       (input) INTEGER
C          The order of the matrix A.  N >= 0.  When N = 0, DLANHS is
C          set to zero.
C
C  A       (input) REAL array, dimension (LDA,N)
C          The n by n upper Hessenberg matrix A; the part of A below the
C          first sub-diagonal is not referenced.
C
C  LDA     (input) INTEGER
C          The leading dimension of the array A.  LDA >= max(N,1).
C
C  WORK    (workspace) REAL array, dimension (LWORK),
C          where LWORK >= N when NORM = 'I'; otherwise, WORK is not
C          referenced.
C
C
C  -- LAPACK auxiliary routine (adapted for NAG Library)
C     Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
C     Courant Institute, Argonne National Lab, and Rice University
C

F06SAF
      SUBROUTINE F06SAF( TRANS, M, N, ALPHA, A, LDA, X, INCX,
     $                   BETA, Y, INCY )
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.

F06SBF
      SUBROUTINE F06SBF( TRANS, M, N, KL, KU, ALPHA, A, LDA, X, INCX,
     $                   BETA, Y, INCY )
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.

F06SCF
      SUBROUTINE F06SCF( UPLO, N, ALPHA, A, LDA, X, INCX,
     $                   BETA, Y, INCY )
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.

F06SDF
      SUBROUTINE F06SDF( UPLO, N, K, ALPHA, A, LDA, X, INCX,
     $                   BETA, Y, INCY )
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.

F06SEF
      SUBROUTINE F06SEF( UPLO, N, ALPHA, AP, X, INCX, BETA, Y, INCY )
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.

F06SFF
      SUBROUTINE F06SFF( UPLO, TRANS, DIAG, N, A, LDA, X, INCX )
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.

F06SGF
      SUBROUTINE F06SGF( UPLO, TRANS, DIAG, N, K, A, LDA, X, INCX )
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.

F06SHF
      SUBROUTINE F06SHF( UPLO, TRANS, DIAG, N, AP, X, INCX )
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.

F06SJF
      SUBROUTINE F06SJF( UPLO, TRANS, DIAG, N, A, LDA, X, INCX )
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.

F06SKF
      SUBROUTINE F06SKF( UPLO, TRANS, DIAG, N, K, A, LDA, X, INCX )
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.

F06SLF
      SUBROUTINE F06SLF( UPLO, TRANS, DIAG, N, AP, X, INCX )
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.

F06SMF
      SUBROUTINE F06SMF( M, N, ALPHA, X, INCX, Y, INCY, A, LDA )
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.

F06SNF
      SUBROUTINE F06SNF( M, N, ALPHA, X, INCX, Y, INCY, A, LDA )
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.

F06SPF
      SUBROUTINE F06SPF( UPLO, N, ALPHA, X, INCX, A, LDA )
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.

F06SQF
      SUBROUTINE F06SQF( UPLO, N, ALPHA, X, INCX, AP )
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.

F06SRF
      SUBROUTINE F06SRF( UPLO, N, ALPHA, X, INCX, Y, INCY, A, LDA )
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.

F06SSF
      SUBROUTINE F06SSF( UPLO, N, ALPHA, X, INCX, Y, INCY, AP )
C     MARK 13 RE-ISSUE. NAG COPYRIGHT 1988.

F06TFF
      SUBROUTINE F06TFF( MATRIX, M, N, A, LDA, B, LDB )
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.

F06THF
      SUBROUTINE F06THF( MATRIX, M, N, CONST, DIAG, A, LDA )
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.

F06TMF
      SUBROUTINE F06TMF( UPLO, PIVOT, DIRECT, N, K1, K2, C, S, A, LDA )
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.

F06TPF
      SUBROUTINE F06TPF( N, ALPHA, X, INCX, Y, INCY, A, LDA, C, S )
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.

F06TQF
      SUBROUTINE F06TQF( N, ALPHA, X, INCX, A, LDA, C, S )
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.

F06TRF
      SUBROUTINE F06TRF( SIDE, N, K1, K2, C, S, A, LDA )
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.

F06TSF
      SUBROUTINE F06TSF( SIDE, N, K1, K2, C, S, A, LDA )
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.

F06TTF
      SUBROUTINE F06TTF( SIDE, N, K1, K2, C, S, A, LDA )
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.

F06TVF
      SUBROUTINE F06TVF( SIDE, N, K1, K2, C, S, A, LDA )
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.

F06TWF
      SUBROUTINE F06TWF( SIDE, N, K1, K2, C, S, A, LDA )
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.

F06TXF
      SUBROUTINE F06TXF( SIDE, PIVOT, DIRECT, M, N, K1, K2, C, S, A,
     $                   LDA )
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.

F06TYF
      SUBROUTINE F06TYF( SIDE, PIVOT, DIRECT, M, N, K1, K2, C, S, A,
     $                   LDA )
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.

F06UAF
      DOUBLE PRECISION FUNCTION F06UAF(NORM,M,N,A,LDA,WORK)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C     REAL                 ZLANGE
C     ENTRY                ZLANGE(NORM,M,N,A,LDA,WORK)
C
C  Purpose
C  =======
C
C  ZLANGE  returns the value of the one norm,  or the Frobenius norm, or
C  the  infinity norm,  or the  element of  largest absolute value  of a
C  complex matrix A.
C
C  Description
C  ===========
C
C  ZLANGE returns the value
C
C     ZLANGE = ( max(abs(A(i,j))), NORM = 'M' or 'm'
C              (
C              ( norm1(A),         NORM = '1', 'O' or 'o'
C              (
C              ( normI(A),         NORM = 'I' or 'i'
C              (
C              ( normF(A),         NORM = 'F', 'f', 'E' or 'e'
C
C  where  norm1  denotes the  one norm of a matrix (maximum column sum),
C  normI  denotes the  infinity norm  of a matrix  (maximum row sum) and
C  normF  denotes the  Frobenius norm of a matrix (square root of sum of
C  squares).  Note that  max(abs(A(i,j)))  is not a  matrix norm.
C
C  Arguments
C  =========
C
C  NORM    (input) CHARACTER*1
C          Specifies the value to be returned in ZLANGE as described
C          above.
C
C  M       (input) INTEGER
C          The number of rows of the matrix A.  M >= 0.  When M = 0,
C          ZLANGE is set to zero.
C
C  N       (input) INTEGER
C          The number of columns of the matrix A.  N >= 0.  When N = 0,
C          ZLANGE is set to zero.
C
C  A       (input) COMPLEX array, dimension (LDA,N)
C          The m by n matrix A.
C
C  LDA     (input) INTEGER
C          The leading dimension of the array A.  LDA >= max(M,1).
C
C  WORK    (workspace) REAL array, dimension (LWORK),
C          where LWORK >= M when NORM = 'I'; otherwise, WORK is not
C          referenced.
C
C
C  -- LAPACK auxiliary routine (adapted for NAG Library)
C     Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
C     Courant Institute, Argonne National Lab, and Rice University
C

F06UBF
      DOUBLE PRECISION FUNCTION F06UBF(NORM,N,KL,KU,AB,LDAB,WORK)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C     REAL                 ZLANGB
C     ENTRY                ZLANGB(NORM,N,KL,KU,AB,LDAB,WORK)
C
C  Purpose
C  =======
C
C  ZLANGB  returns the value of the one norm,  or the Frobenius norm, or
C  the  infinity norm,  or the element of  largest absolute value  of an
C  n by n band matrix  A,  with kl sub-diagonals and ku super-diagonals.
C
C  Description
C  ===========
C
C  ZLANGB returns the value
C
C     ZLANGB = ( max(abs(A(i,j))), NORM = 'M' or 'm'
C              (
C              ( norm1(A),         NORM = '1', 'O' or 'o'
C              (
C              ( normI(A),         NORM = 'I' or 'i'
C              (
C              ( normF(A),         NORM = 'F', 'f', 'E' or 'e'
C
C  where  norm1  denotes the  one norm of a matrix (maximum column sum),
C  normI  denotes the  infinity norm  of a matrix  (maximum row sum) and
C  normF  denotes the  Frobenius norm of a matrix (square root of sum of
C  squares).  Note that  max(abs(A(i,j)))  is not a  matrix norm.
C
C  Arguments
C  =========
C
C  NORM    (input) CHARACTER*1
C          Specifies the value to be returned in ZLANGB as described
C          above.
C
C  N       (input) INTEGER
C          The order of the matrix A.  N >= 0.  When N = 0, ZLANGB is
C          set to zero.
C
C  KL      (input) INTEGER
C          The number of sub-diagonals of the matrix A.  KL >= 0.
C
C  KU      (input) INTEGER
C          The number of super-diagonals of the matrix A.  KU >= 0.
C
C  AB      (input) COMPLEX array, dimension (LDAB,N)
C          The band matrix A, stored in rows 1 to KL+KU+1.  The j-th
C          column of A is stored in the j-th column of the array AB as
C          follows:
C          AB(ku+1+i-j,j) = A(i,j) for max(1,j-ku)<=i<=min(n,j+kl).
C
C  LDAB    (input) INTEGER
C          The leading dimension of the array AB.  LDAB >= KL+KU+1.
C
C  WORK    (workspace) REAL array, dimension (LWORK),
C          where LWORK >= N when NORM = 'I'; otherwise, WORK is not
C          referenced.
C
C
C  -- LAPACK auxiliary routine (adapted for NAG Library)
C     Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
C     Courant Institute, Argonne National Lab, and Rice University
C

F06UCF
      DOUBLE PRECISION FUNCTION F06UCF(NORM,UPLO,N,A,LDA,WORK)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C     REAL                 ZLANHE
C     ENTRY                ZLANHE(NORM,UPLO,N,A,LDA,WORK)
C
C  Purpose
C  =======
C
C  ZLANHE  returns the value of the one norm,  or the Frobenius norm, or
C  the  infinity norm,  or the  element of  largest absolute value  of a
C  complex hermitian matrix A.
C
C  Description
C  ===========
C
C  ZLANHE returns the value
C
C     ZLANHE = ( max(abs(A(i,j))), NORM = 'M' or 'm'
C              (
C              ( norm1(A),         NORM = '1', 'O' or 'o'
C              (
C              ( normI(A),         NORM = 'I' or 'i'
C              (
C              ( normF(A),         NORM = 'F', 'f', 'E' or 'e'
C
C  where  norm1  denotes the  one norm of a matrix (maximum column sum),
C  normI  denotes the  infinity norm  of a matrix  (maximum row sum) and
C  normF  denotes the  Frobenius norm of a matrix (square root of sum of
C  squares).  Note that  max(abs(A(i,j)))  is not a  matrix norm.
C
C  Arguments
C  =========
C
C  NORM    (input) CHARACTER*1
C          Specifies the value to be returned in ZLANHE as described
C          above.
C
C  UPLO    (input) CHARACTER*1
C          Specifies whether the upper or lower triangular part of the
C          hermitian matrix A is to be referenced.
C          = 'U':  Upper triangular part of A is referenced
C          = 'L':  Lower triangular part of A is referenced
C
C  N       (input) INTEGER
C          The order of the matrix A.  N >= 0.  When N = 0, ZLANHE is
C          set to zero.
C
C  A       (input) COMPLEX array, dimension (LDA,N)
C          The hermitian matrix A.  If UPLO = 'U', the leading n by n
C          upper triangular part of A contains the upper triangular part
C          of the matrix A, and the strictly lower triangular part of A
C          is not referenced.  If UPLO = 'L', the leading n by n lower
C          triangular part of A contains the lower triangular part of
C          the matrix A, and the strictly upper triangular part of A is
C          not referenced. Note that the imaginary parts of the diagonal
C          elements need not be set and are assumed to be zero.
C
C  LDA     (input) INTEGER
C          The leading dimension of the array A.  LDA >= max(N,1).
C
C  WORK    (workspace) REAL array, dimension (LWORK),
C          where LWORK >= N when NORM = 'I' or '1' or 'O'; otherwise,
C          WORK is not referenced.
C
C
C  -- LAPACK auxiliary routine (adapted for NAG Library)
C     Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
C     Courant Institute, Argonne National Lab, and Rice University
C

F06UDF
      DOUBLE PRECISION FUNCTION F06UDF(NORM,UPLO,N,AP,WORK)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C     REAL                 ZLANHP
C     ENTRY                ZLANHP(NORM,UPLO,N,AP,WORK)
C
C  Purpose
C  =======
C
C  ZLANHP  returns the value of the one norm,  or the Frobenius norm, or
C  the  infinity norm,  or the  element of  largest absolute value  of a
C  complex hermitian matrix A,  supplied in packed form.
C
C  Description
C  ===========
C
C  ZLANHP returns the value
C
C     ZLANHP = ( max(abs(A(i,j))), NORM = 'M' or 'm'
C              (
C              ( norm1(A),         NORM = '1', 'O' or 'o'
C              (
C              ( normI(A),         NORM = 'I' or 'i'
C              (
C              ( normF(A),         NORM = 'F', 'f', 'E' or 'e'
C
C  where  norm1  denotes the  one norm of a matrix (maximum column sum),
C  normI  denotes the  infinity norm  of a matrix  (maximum row sum) and
C  normF  denotes the  Frobenius norm of a matrix (square root of sum of
C  squares).  Note that  max(abs(A(i,j)))  is not a  matrix norm.
C
C  Arguments
C  =========
C
C  NORM    (input) CHARACTER*1
C          Specifies the value to be returned in ZLANHP as described
C          above.
C
C  UPLO    (input) CHARACTER*1
C          Specifies whether the upper or lower triangular part of the
C          hermitian matrix A is supplied.
C          = 'U':  Upper triangular part of A is supplied
C          = 'L':  Lower triangular part of A is supplied
C
C  N       (input) INTEGER
C          The order of the matrix A.  N >= 0.  When N = 0, ZLANHP is
C          set to zero.
C
C  AP      (input) COMPLEX array, dimension (N*(N+1)/2)
C          The upper or lower triangle of the hermitian matrix A, packed
C          columnwise in a linear array.  The j-th column of A is stored
C          in the array AP as follows:
C          if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j;
C          if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n.
C          Note that the  imaginary parts of the diagonal elements need
C          not be set and are assumed to be zero.
C
C  WORK    (workspace) REAL array, dimension (LWORK),
C          where LWORK >= N when NORM = 'I' or '1' or 'O'; otherwise,
C          WORK is not referenced.
C
C
C  -- LAPACK auxiliary routine (adapted for NAG Library)
C     Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
C     Courant Institute, Argonne National Lab, and Rice University
C

F06UEF
      DOUBLE PRECISION FUNCTION F06UEF(NORM,UPLO,N,K,AB,LDAB,WORK)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C     REAL                 ZLANHB
C     ENTRY                ZLANHB(NORM,UPLO,N,K,AB,LDAB,WORK)
C
C  Purpose
C  =======
C
C  ZLANHB  returns the value of the one norm,  or the Frobenius norm, or
C  the  infinity norm,  or the element of  largest absolute value  of an
C  n by n hermitian band matrix A,  with k super-diagonals.
C
C  Description
C  ===========
C
C  ZLANHB returns the value
C
C     ZLANHB = ( max(abs(A(i,j))), NORM = 'M' or 'm'
C              (
C              ( norm1(A),         NORM = '1', 'O' or 'o'
C              (
C              ( normI(A),         NORM = 'I' or 'i'
C              (
C              ( normF(A),         NORM = 'F', 'f', 'E' or 'e'
C
C  where  norm1  denotes the  one norm of a matrix (maximum column sum),
C  normI  denotes the  infinity norm  of a matrix  (maximum row sum) and
C  normF  denotes the  Frobenius norm of a matrix (square root of sum of
C  squares).  Note that  max(abs(A(i,j)))  is not a  matrix norm.
C
C  Arguments
C  =========
C
C  NORM    (input) CHARACTER*1
C          Specifies the value to be returned in ZLANHB as described
C          above.
C
C  UPLO    (input) CHARACTER*1
C          Specifies whether the upper or lower triangular part of the
C          band matrix A is supplied.
C          = 'U':  Upper triangular
C          = 'L':  Lower triangular
C
C  N       (input) INTEGER
C          The order of the matrix A.  N >= 0.  When N = 0, ZLANHB is
C          set to zero.
C
C  K       (input) INTEGER
C          The number of super-diagonals or sub-diagonals of the
C          band matrix A.  K >= 0.
C
C  AB      (input) COMPLEX array, dimension (LDAB,N)
C          The upper or lower triangle of the hermitian band matrix A,
C          stored in the first K+1 rows of AB.  The j-th column of A is
C          stored in the j-th column of the array AB as follows:
C          if UPLO = 'U', AB(k+1+i-j,j) = A(i,j) for max(1,j-k)<=i<=j;
C          if UPLO = 'L', AB(1+i-j,j)   = A(i,j) for j<=i<=min(n,j+k).
C          Note that the imaginary parts of the diagonal elements need
C          not be set and are assumed to be zero.
C
C  LDAB    (input) INTEGER
C          The leading dimension of the array AB.  LDAB >= K+1.
C
C  WORK    (workspace) REAL array, dimension (LWORK),
C          where LWORK >= N when NORM = 'I' or '1' or 'O'; otherwise,
C          WORK is not referenced.
C
C
C  -- LAPACK auxiliary routine (adapted for NAG Library)
C     Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
C     Courant Institute, Argonne National Lab, and Rice University
C

F06UFF
      DOUBLE PRECISION FUNCTION F06UFF(NORM,UPLO,N,A,LDA,WORK)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C     REAL                 ZLANSY
C     ENTRY                ZLANSY(NORM,UPLO,N,A,LDA,WORK)
C
C  Purpose
C  =======
C
C  ZLANSY  returns the value of the one norm,  or the Frobenius norm, or
C  the  infinity norm,  or the  element of  largest absolute value  of a
C  complex symmetric matrix A.
C
C  Description
C  ===========
C
C  ZLANSY returns the value
C
C     ZLANSY = ( max(abs(A(i,j))), NORM = 'M' or 'm'
C              (
C              ( norm1(A),         NORM = '1', 'O' or 'o'
C              (
C              ( normI(A),         NORM = 'I' or 'i'
C              (
C              ( normF(A),         NORM = 'F', 'f', 'E' or 'e'
C
C  where  norm1  denotes the  one norm of a matrix (maximum column sum),
C  normI  denotes the  infinity norm  of a matrix  (maximum row sum) and
C  normF  denotes the  Frobenius norm of a matrix (square root of sum of
C  squares).  Note that  max(abs(A(i,j)))  is not a  matrix norm.
C
C  Arguments
C  =========
C
C  NORM    (input) CHARACTER*1
C          Specifies the value to be returned in ZLANSY as described
C          above.
C
C  UPLO    (input) CHARACTER*1
C          Specifies whether the upper or lower triangular part of the
C          symmetric matrix A is to be referenced.
C          = 'U':  Upper triangular part of A is referenced
C          = 'L':  Lower triangular part of A is referenced
C
C  N       (input) INTEGER
C          The order of the matrix A.  N >= 0.  When N = 0, ZLANSY is
C          set to zero.
C
C  A       (input) COMPLEX array, dimension (LDA,N)
C          The symmetric matrix A.  If UPLO = 'U', the leading n by n
C          upper triangular part of A contains the upper triangular part
C          of the matrix A, and the strictly lower triangular part of A
C          is not referenced.  If UPLO = 'L', the leading n by n lower
C          triangular part of A contains the lower triangular part of
C          the matrix A, and the strictly upper triangular part of A is
C          not referenced.
C
C  LDA     (input) INTEGER
C          The leading dimension of the array A.  LDA >= max(N,1).
C
C  WORK    (workspace) REAL array, dimension (LWORK),
C          where LWORK >= N when NORM = 'I' or '1' or 'O'; otherwise,
C          WORK is not referenced.
C
C
C  -- LAPACK auxiliary routine (adapted for NAG Library)
C     Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
C     Courant Institute, Argonne National Lab, and Rice University
C

F06UGF
      DOUBLE PRECISION FUNCTION F06UGF(NORM,UPLO,N,AP,WORK)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C     REAL                 ZLANSP
C     ENTRY                ZLANSP(NORM,UPLO,N,AP,WORK)
C
C  Purpose
C  =======
C
C  ZLANSP  returns the value of the one norm,  or the Frobenius norm, or
C  the  infinity norm,  or the  element of  largest absolute value  of a
C  complex symmetric matrix A,  supplied in packed form.
C
C  Description
C  ===========
C
C  ZLANSP returns the value
C
C     ZLANSP = ( max(abs(A(i,j))), NORM = 'M' or 'm'
C              (
C              ( norm1(A),         NORM = '1', 'O' or 'o'
C              (
C              ( normI(A),         NORM = 'I' or 'i'
C              (
C              ( normF(A),         NORM = 'F', 'f', 'E' or 'e'
C
C  where  norm1  denotes the  one norm of a matrix (maximum column sum),
C  normI  denotes the  infinity norm  of a matrix  (maximum row sum) and
C  normF  denotes the  Frobenius norm of a matrix (square root of sum of
C  squares).  Note that  max(abs(A(i,j)))  is not a  matrix norm.
C
C  Arguments
C  =========
C
C  NORM    (input) CHARACTER*1
C          Specifies the value to be returned in ZLANSP as described
C          above.
C
C  UPLO    (input) CHARACTER*1
C          Specifies whether the upper or lower triangular part of the
C          symmetric matrix A is supplied.
C          = 'U':  Upper triangular part of A is supplied
C          = 'L':  Lower triangular part of A is supplied
C
C  N       (input) INTEGER
C          The order of the matrix A.  N >= 0.  When N = 0, ZLANSP is
C          set to zero.
C
C  AP      (input) COMPLEX array, dimension (N*(N+1)/2)
C          The upper or lower triangle of the symmetric matrix A, packed
C          columnwise in a linear array.  The j-th column of A is stored
C          in the array AP as follows:
C          if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j;
C          if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n.
C
C  WORK    (workspace) REAL array, dimension (LWORK),
C          where LWORK >= N when NORM = 'I' or '1' or 'O'; otherwise,
C          WORK is not referenced.
C
C
C  -- LAPACK auxiliary routine (adapted for NAG Library)
C     Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
C     Courant Institute, Argonne National Lab, and Rice University
C

F06UHF
      DOUBLE PRECISION FUNCTION F06UHF(NORM,UPLO,N,K,AB,LDAB,WORK)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C     REAL                 ZLANSB
C     ENTRY                ZLANSB(NORM,UPLO,N,K,AB,LDAB,WORK)
C
C  Purpose
C  =======
C
C  ZLANSB  returns the value of the one norm,  or the Frobenius norm, or
C  the  infinity norm,  or the element of  largest absolute value  of an
C  n by n symmetric band matrix A,  with k super-diagonals.
C
C  Description
C  ===========
C
C  ZLANSB returns the value
C
C     ZLANSB = ( max(abs(A(i,j))), NORM = 'M' or 'm'
C              (
C              ( norm1(A),         NORM = '1', 'O' or 'o'
C              (
C              ( normI(A),         NORM = 'I' or 'i'
C              (
C              ( normF(A),         NORM = 'F', 'f', 'E' or 'e'
C
C  where  norm1  denotes the  one norm of a matrix (maximum column sum),
C  normI  denotes the  infinity norm  of a matrix  (maximum row sum) and
C  normF  denotes the  Frobenius norm of a matrix (square root of sum of
C  squares).  Note that  max(abs(A(i,j)))  is not a  matrix norm.
C
C  Arguments
C  =========
C
C  NORM    (input) CHARACTER*1
C          Specifies the value to be returned in ZLANSB as described
C          above.
C
C  UPLO    (input) CHARACTER*1
C          Specifies whether the upper or lower triangular part of the
C          band matrix A is supplied.
C          = 'U':  Upper triangular part is supplied
C          = 'L':  Lower triangular part is supplied
C
C  N       (input) INTEGER
C          The order of the matrix A.  N >= 0.  When N = 0, ZLANSB is
C          set to zero.
C
C  K       (input) INTEGER
C          The number of super-diagonals or sub-diagonals of the
C          band matrix A.  K >= 0.
C
C  AB      (input) COMPLEX array, dimension (LDAB,N)
C          The upper or lower triangle of the symmetric band matrix A,
C          stored in the first K+1 rows of AB.  The j-th column of A is
C          stored in the j-th column of the array AB as follows:
C          if UPLO = 'U', AB(k+1+i-j,j) = A(i,j) for max(1,j-k)<=i<=j;
C          if UPLO = 'L', AB(1+i-j,j)   = A(i,j) for j<=i<=min(n,j+k).
C
C  LDAB    (input) INTEGER
C          The leading dimension of the array AB.  LDAB >= K+1.
C
C  WORK    (workspace) REAL array, dimension (LWORK),
C          where LWORK >= N when NORM = 'I' or '1' or 'O'; otherwise,
C          WORK is not referenced.
C
C
C  -- LAPACK auxiliary routine (adapted for NAG Library)
C     Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
C     Courant Institute, Argonne National Lab, and Rice University
C

F06UJF
      DOUBLE PRECISION FUNCTION F06UJF(NORM,UPLO,DIAG,M,N,A,LDA,WORK)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C     REAL                 ZLANTR
C     ENTRY                ZLANTR(NORM,UPLO,DIAG,M,N,A,LDA,WORK)
C
C  Purpose
C  =======
C
C  ZLANTR  returns the value of the one norm,  or the Frobenius norm, or
C  the  infinity norm,  or the  element of  largest absolute value  of a
C  trapezoidal or triangular matrix A.
C
C  Description
C  ===========
C
C  ZLANTR returns the value
C
C     ZLANTR = ( max(abs(A(i,j))), NORM = 'M' or 'm'
C              (
C              ( norm1(A),         NORM = '1', 'O' or 'o'
C              (
C              ( normI(A),         NORM = 'I' or 'i'
C              (
C              ( normF(A),         NORM = 'F', 'f', 'E' or 'e'
C
C  where  norm1  denotes the  one norm of a matrix (maximum column sum),
C  normI  denotes the  infinity norm  of a matrix  (maximum row sum) and
C  normF  denotes the  Frobenius norm of a matrix (square root of sum of
C  squares).  Note that  max(abs(A(i,j)))  is not a  matrix norm.
C
C  Arguments
C  =========
C
C  NORM    (input) CHARACTER*1
C          Specifies the value to be returned in ZLANTR as described
C          above.
C
C  UPLO    (input) CHARACTER*1
C          Specifies whether the matrix A is upper or lower trapezoidal.
C          = 'U':  Upper trapezoidal
C          = 'L':  Lower trapezoidal
C          Note that A is triangular instead of trapezoidal if M = N.
C
C  DIAG    (input) CHARACTER*1
C          Specifies whether or not the matrix A has unit diagonal.
C          = 'N':  Non-unit diagonal
C          = 'U':  Unit diagonal
C
C  M       (input) INTEGER
C          The number of rows of the matrix A.  M >= 0, and if
C          UPLO = 'U', M <= N.  When M = 0, ZLANTR is set to zero.
C
C  N       (input) INTEGER
C          The number of columns of the matrix A.  N >= 0, and if
C          UPLO = 'L', N <= M.  When N = 0, ZLANTR is set to zero.
C
C  A       (input) COMPLEX array, dimension (LDA,N)
C          The trapezoidal matrix A (A is triangular if M = N).
C          If UPLO = 'U', the leading m by n upper trapezoidal part of
C          the array A contains the upper trapezoidal matrix, and the
C          strictly lower triangular part of A is not referenced.
C          If UPLO = 'L', the leading m by n lower trapezoidal part of
C          the array A contains the lower trapezoidal matrix, and the
C          strictly upper triangular part of A is not referenced.  Note
C          that when DIAG = 'U', the diagonal elements of A are not
C          referenced and are assumed to be one.
C
C  LDA     (input) INTEGER
C          The leading dimension of the array A.  LDA >= max(M,1).
C
C  WORK    (workspace) REAL array, dimension (LWORK),
C          where LWORK >= M when NORM = 'I'; otherwise, WORK is not
C          referenced.
C
C
C  -- LAPACK auxiliary routine (adapted for NAG Library)
C     Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
C     Courant Institute, Argonne National Lab, and Rice University
C

F06UKF
      DOUBLE PRECISION FUNCTION F06UKF(NORM,UPLO,DIAG,N,AP,WORK)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C     REAL                 ZLANTP
C     ENTRY                ZLANTP(NORM,UPLO,DIAG,N,AP,WORK)
C
C  Purpose
C  =======
C
C  ZLANTP  returns the value of the one norm,  or the Frobenius norm, or
C  the  infinity norm,  or the  element of  largest absolute value  of a
C  triangular matrix A, supplied in packed form.
C
C  Description
C  ===========
C
C  ZLANTP returns the value
C
C     ZLANTP = ( max(abs(A(i,j))), NORM = 'M' or 'm'
C              (
C              ( norm1(A),         NORM = '1', 'O' or 'o'
C              (
C              ( normI(A),         NORM = 'I' or 'i'
C              (
C              ( normF(A),         NORM = 'F', 'f', 'E' or 'e'
C
C  where  norm1  denotes the  one norm of a matrix (maximum column sum),
C  normI  denotes the  infinity norm  of a matrix  (maximum row sum) and
C  normF  denotes the  Frobenius norm of a matrix (square root of sum of
C  squares).  Note that  max(abs(A(i,j)))  is not a  matrix norm.
C
C  Arguments
C  =========
C
C  NORM    (input) CHARACTER*1
C          Specifies the value to be returned in ZLANTP as described
C          above.
C
C  UPLO    (input) CHARACTER*1
C          Specifies whether the matrix A is upper or lower triangular.
C          = 'U':  Upper triangular
C          = 'L':  Lower triangular
C
C  DIAG    (input) CHARACTER*1
C          Specifies whether or not the matrix A is unit triangular.
C          = 'N':  Non-unit triangular
C          = 'U':  Unit triangular
C
C  N       (input) INTEGER
C          The order of the matrix A.  N >= 0.  When N = 0, ZLANTP is
C          set to zero.
C
C  AP      (input) COMPLEX array, dimension (N*(N+1)/2)
C          The upper or lower triangular matrix A, packed columnwise in
C          a linear array.  The j-th column of A is stored in the array
C          AP as follows:
C          if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j;
C          if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n.
C          Note that when DIAG = 'U', the elements of the array AP
C          corresponding to the diagonal elements of the matrix A are
C          not referenced, but are assumed to be one.
C
C  WORK    (workspace) REAL array, dimension (LWORK),
C          where LWORK >= N when NORM = 'I'; otherwise, WORK is not
C          referenced.
C
C
C  -- LAPACK auxiliary routine (adapted for NAG Library)
C     Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
C     Courant Institute, Argonne National Lab, and Rice University
C

F06ULF
      DOUBLE PRECISION FUNCTION F06ULF(NORM,UPLO,DIAG,N,K,AB,LDAB,WORK)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C     REAL                 ZLANTB
C     ENTRY                ZLANTB(NORM,UPLO,DIAG,N,K,AB,LDAB,WORK)
C
C  Purpose
C  =======
C
C  ZLANTB  returns the value of the one norm,  or the Frobenius norm, or
C  the  infinity norm,  or the element of  largest absolute value  of an
C  n by n triangular band matrix A,  with ( k + 1 ) diagonals.
C
C  Description
C  ===========
C
C  ZLANTB returns the value
C
C     ZLANTB = ( max(abs(A(i,j))), NORM = 'M' or 'm'
C              (
C              ( norm1(A),         NORM = '1', 'O' or 'o'
C              (
C              ( normI(A),         NORM = 'I' or 'i'
C              (
C              ( normF(A),         NORM = 'F', 'f', 'E' or 'e'
C
C  where  norm1  denotes the  one norm of a matrix (maximum column sum),
C  normI  denotes the  infinity norm  of a matrix  (maximum row sum) and
C  normF  denotes the  Frobenius norm of a matrix (square root of sum of
C  squares).  Note that  max(abs(A(i,j)))  is not a  matrix norm.
C
C  Arguments
C  =========
C
C  NORM    (input) CHARACTER*1
C          Specifies the value to be returned in ZLANTB as described
C          above.
C
C  UPLO    (input) CHARACTER*1
C          Specifies whether the matrix A is upper or lower triangular.
C          = 'U':  Upper triangular
C          = 'L':  Lower triangular
C
C  DIAG    (input) CHARACTER*1
C          Specifies whether or not the matrix A is unit triangular.
C          = 'N':  Non-unit triangular
C          = 'U':  Unit triangular
C
C  N       (input) INTEGER
C          The order of the matrix A.  N >= 0.  When N = 0, ZLANTB is
C          set to zero.
C
C  K       (input) INTEGER
C          The number of super-diagonals of the matrix A if UPLO = 'U',
C          or the number of sub-diagonals of the matrix A if UPLO = 'L'.
C          K >= 0.
C
C  AB      (input) COMPLEX array, dimension (LDAB,N)
C          The upper or lower triangular band matrix A, stored in the
C          first k+1 rows of AB.  The j-th column of A is stored
C          in the j-th column of the array AB as follows:
C          if UPLO = 'U', AB(k+1+i-j,j) = A(i,j) for max(1,j-k)<=i<=j;
C          if UPLO = 'L', AB(1+i-j,j)   = A(i,j) for j<=i<=min(n,j+k).
C          Note that when DIAG = 'U', the elements of the array AB
C          corresponding to the diagonal elements of the matrix A are
C          not referenced, but are assumed to be one.
C
C  LDAB    (input) INTEGER
C          The leading dimension of the array AB.  LDAB >= K+1.
C
C  WORK    (workspace) REAL array, dimension (LWORK),
C          where LWORK >= N when NORM = 'I'; otherwise, WORK is not
C          referenced.
C
C
C  -- LAPACK auxiliary routine (adapted for NAG Library)
C     Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
C     Courant Institute, Argonne National Lab, and Rice University
C

F06UMF
      DOUBLE PRECISION FUNCTION F06UMF(NORM,N,A,LDA,WORK)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C     REAL                 ZLANHS
C     ENTRY                ZLANHS(NORM,N,A,LDA,WORK)
C
C  Purpose
C  =======
C
C  ZLANHS  returns the value of the one norm,  or the Frobenius norm, or
C  the  infinity norm,  or the  element of  largest absolute value  of a
C  Hessenberg matrix A.
C
C  Description
C  ===========
C
C  ZLANHS returns the value
C
C     ZLANHS = ( max(abs(A(i,j))), NORM = 'M' or 'm'
C              (
C              ( norm1(A),         NORM = '1', 'O' or 'o'
C              (
C              ( normI(A),         NORM = 'I' or 'i'
C              (
C              ( normF(A),         NORM = 'F', 'f', 'E' or 'e'
C
C  where  norm1  denotes the  one norm of a matrix (maximum column sum),
C  normI  denotes the  infinity norm  of a matrix  (maximum row sum) and
C  normF  denotes the  Frobenius norm of a matrix (square root of sum of
C  squares).  Note that  max(abs(A(i,j)))  is not a  matrix norm.
C
C  Arguments
C  =========
C
C  NORM    (input) CHARACTER*1
C          Specifies the value to be returned in ZLANHS as described
C          above.
C
C  N       (input) INTEGER
C          The order of the matrix A.  N >= 0.  When N = 0, ZLANHS is
C          set to zero.
C
C  A       (input) COMPLEX array, dimension (LDA,N)
C          The n by n upper Hessenberg matrix A; the part of A below the
C          first sub-diagonal is not referenced.
C
C  LDA     (input) INTEGER
C          The leading dimension of the array A.  LDA >= max(N,1).
C
C  WORK    (workspace) REAL array, dimension (LWORK),
C          where LWORK >= N when NORM = 'I'; otherwise, WORK is not
C          referenced.
C
C
C  -- LAPACK auxiliary routine (adapted for NAG Library)
C     Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
C     Courant Institute, Argonne National Lab, and Rice University
C

F06VJF
      SUBROUTINE F06VJF( SIDE, TRANS, N, PERM, K, B, LDB )
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.

F06VKF
      SUBROUTINE F06VKF( SIDE, TRANS, N, PERM, K, B, LDB )
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.

F06VXF
      SUBROUTINE F06VXF( SIDE, PIVOT, DIRECT, M, N, K1, K2, C, S, A,
     $                   LDA )
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.

F06YAF
      SUBROUTINE F06YAF(TRANSA,TRANSB,M,N,K,ALPHA,A,LDA,B,LDB,BETA,C,
     *                  LDC)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C  Purpose
C  =======
C
C  DGEMM  performs one of the matrix-matrix operations
C
C     C := alpha*op( A )*op( B ) + beta*C,
C
C  where  op( X ) is one of
C
C     op( X ) = X   or   op( X ) = X',
C
C  alpha and beta are scalars, and A, B and C are matrices, with op( A )
C  an m by k matrix,  op( B )  a  k by n matrix and  C an m by n matrix.
C
C  Parameters
C  ==========
C
C  TRANSA - CHARACTER*1.
C           On entry, TRANSA specifies the form of op( A ) to be used in
C           the matrix multiplication as follows:
C
C              TRANSA = 'N' or 'n',  op( A ) = A.
C
C              TRANSA = 'T' or 't',  op( A ) = A'.
C
C              TRANSA = 'C' or 'c',  op( A ) = A'.
C
C           Unchanged on exit.
C
C  TRANSB - CHARACTER*1.
C           On entry, TRANSB specifies the form of op( B ) to be used in
C           the matrix multiplication as follows:
C
C              TRANSB = 'N' or 'n',  op( B ) = B.
C
C              TRANSB = 'T' or 't',  op( B ) = B'.
C
C              TRANSB = 'C' or 'c',  op( B ) = B'.
C
C           Unchanged on exit.
C
C  M      - INTEGER.
C           On entry,  M  specifies  the number  of rows  of the  matrix
C           op( A )  and of the  matrix  C.  M  must  be at least  zero.
C           Unchanged on exit.
C
C  N      - INTEGER.
C           On entry,  N  specifies the number  of columns of the matrix
C           op( B ) and the number of columns of the matrix C. N must be
C           at least zero.
C           Unchanged on exit.
C
C  K      - INTEGER.
C           On entry,  K  specifies  the number of columns of the matrix
C           op( A ) and the number of rows of the matrix op( B ). K must
C           be at least  zero.
C           Unchanged on exit.
C
C  ALPHA  - REAL            .
C           On entry, ALPHA specifies the scalar alpha.
C           Unchanged on exit.
C
C  A      - REAL             array of DIMENSION ( LDA, ka ), where ka is
C           k  when  TRANSA = 'N' or 'n',  and is  m  otherwise.
C           Before entry with  TRANSA = 'N' or 'n',  the leading  m by k
C           part of the array  A  must contain the matrix  A,  otherwise
C           the leading  k by m  part of the array  A  must contain  the
C           matrix A.
C           Unchanged on exit.
C
C  LDA    - INTEGER.
C           On entry, LDA specifies the first dimension of A as declared
C           in the calling (sub) program. When  TRANSA = 'N' or 'n' then
C           LDA must be at least  max( 1, m ), otherwise  LDA must be at
C           least  max( 1, k ).
C           Unchanged on exit.
C
C  B      - REAL             array of DIMENSION ( LDB, kb ), where kb is
C           n  when  TRANSB = 'N' or 'n',  and is  k  otherwise.
C           Before entry with  TRANSB = 'N' or 'n',  the leading  k by n
C           part of the array  B  must contain the matrix  B,  otherwise
C           the leading  n by k  part of the array  B  must contain  the
C           matrix B.
C           Unchanged on exit.
C
C  LDB    - INTEGER.
C           On entry, LDB specifies the first dimension of B as declared
C           in the calling (sub) program. When  TRANSB = 'N' or 'n' then
C           LDB must be at least  max( 1, k ), otherwise  LDB must be at
C           least  max( 1, n ).
C           Unchanged on exit.
C
C  BETA   - REAL            .
C           On entry,  BETA  specifies the scalar  beta.  When  BETA  is
C           supplied as zero then C need not be set on input.
C           Unchanged on exit.
C
C  C      - REAL             array of DIMENSION ( LDC, n ).
C           Before entry, the leading  m by n  part of the array  C must
C           contain the matrix  C,  except when  beta  is zero, in which
C           case C need not be set on entry.
C           On exit, the array  C  is overwritten by the  m by n  matrix
C           ( alpha*op( A )*op( B ) + beta*C ).
C
C  LDC    - INTEGER.
C           On entry, LDC specifies the first dimension of C as declared
C           in  the  calling  (sub)  program.   LDC  must  be  at  least
C           max( 1, m ).
C           Unchanged on exit.
C
C
C  Level 3 Blas routine.
C
C  -- Written on 8-February-1989.
C     Jack Dongarra, Argonne National Laboratory.
C     Iain Duff, AERE Harwell.
C     Jeremy Du Croz, Numerical Algorithms Group Ltd.
C     Sven Hammarling, Numerical Algorithms Group Ltd.
C
C

F06YCF
      SUBROUTINE F06YCF(SIDE,UPLO,M,N,ALPHA,A,LDA,B,LDB,BETA,C,LDC)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C  Purpose
C  =======
C
C  DSYMM  performs one of the matrix-matrix operations
C
C     C := alpha*A*B + beta*C,
C
C  or
C
C     C := alpha*B*A + beta*C,
C
C  where alpha and beta are scalars,  A is a symmetric matrix and  B and
C  C are  m by n matrices.
C
C  Parameters
C  ==========
C
C  SIDE   - CHARACTER*1.
C           On entry,  SIDE  specifies whether  the  symmetric matrix  A
C           appears on the  left or right  in the  operation as follows:
C
C              SIDE = 'L' or 'l'   C := alpha*A*B + beta*C,
C
C              SIDE = 'R' or 'r'   C := alpha*B*A + beta*C,
C
C           Unchanged on exit.
C
C  UPLO   - CHARACTER*1.
C           On  entry,   UPLO  specifies  whether  the  upper  or  lower
C           triangular  part  of  the  symmetric  matrix   A  is  to  be
C           referenced as follows:
C
C              UPLO = 'U' or 'u'   Only the upper triangular part of the
C                                  symmetric matrix is to be referenced.
C
C              UPLO = 'L' or 'l'   Only the lower triangular part of the
C                                  symmetric matrix is to be referenced.
C
C           Unchanged on exit.
C
C  M      - INTEGER.
C           On entry,  M  specifies the number of rows of the matrix  C.
C           M  must be at least zero.
C           Unchanged on exit.
C
C  N      - INTEGER.
C           On entry, N specifies the number of columns of the matrix C.
C           N  must be at least zero.
C           Unchanged on exit.
C
C  ALPHA  - REAL            .
C           On entry, ALPHA specifies the scalar alpha.
C           Unchanged on exit.
C
C  A      - REAL             array of DIMENSION ( LDA, ka ), where ka is
C           m  when  SIDE = 'L' or 'l'  and is  n otherwise.
C           Before entry  with  SIDE = 'L' or 'l',  the  m by m  part of
C           the array  A  must contain the  symmetric matrix,  such that
C           when  UPLO = 'U' or 'u', the leading m by m upper triangular
C           part of the array  A  must contain the upper triangular part
C           of the  symmetric matrix and the  strictly  lower triangular
C           part of  A  is not referenced,  and when  UPLO = 'L' or 'l',
C           the leading  m by m  lower triangular part  of the  array  A
C           must  contain  the  lower triangular part  of the  symmetric
C           matrix and the  strictly upper triangular part of  A  is not
C           referenced.
C           Before entry  with  SIDE = 'R' or 'r',  the  n by n  part of
C           the array  A  must contain the  symmetric matrix,  such that
C           when  UPLO = 'U' or 'u', the leading n by n upper triangular
C           part of the array  A  must contain the upper triangular part
C           of the  symmetric matrix and the  strictly  lower triangular
C           part of  A  is not referenced,  and when  UPLO = 'L' or 'l',
C           the leading  n by n  lower triangular part  of the  array  A
C           must  contain  the  lower triangular part  of the  symmetric
C           matrix and the  strictly upper triangular part of  A  is not
C           referenced.
C           Unchanged on exit.
C
C  LDA    - INTEGER.
C           On entry, LDA specifies the first dimension of A as declared
C           in the calling (sub) program.  When  SIDE = 'L' or 'l'  then
C           LDA must be at least  max( 1, m ), otherwise  LDA must be at
C           least  max( 1, n ).
C           Unchanged on exit.
C
C  B      - REAL             array of DIMENSION ( LDB, n ).
C           Before entry, the leading  m by n part of the array  B  must
C           contain the matrix B.
C           Unchanged on exit.
C
C  LDB    - INTEGER.
C           On entry, LDB specifies the first dimension of B as declared
C           in  the  calling  (sub)  program.   LDB  must  be  at  least
C           max( 1, m ).
C           Unchanged on exit.
C
C  BETA   - REAL            .
C           On entry,  BETA  specifies the scalar  beta.  When  BETA  is
C           supplied as zero then C need not be set on input.
C           Unchanged on exit.
C
C  C      - REAL             array of DIMENSION ( LDC, n ).
C           Before entry, the leading  m by n  part of the array  C must
C           contain the matrix  C,  except when  beta  is zero, in which
C           case C need not be set on entry.
C           On exit, the array  C  is overwritten by the  m by n updated
C           matrix.
C
C  LDC    - INTEGER.
C           On entry, LDC specifies the first dimension of C as declared
C           in  the  calling  (sub)  program.   LDC  must  be  at  least
C           max( 1, m ).
C           Unchanged on exit.
C
C
C  Level 3 Blas routine.
C
C  -- Written on 8-February-1989.
C     Jack Dongarra, Argonne National Laboratory.
C     Iain Duff, AERE Harwell.
C     Jeremy Du Croz, Numerical Algorithms Group Ltd.
C     Sven Hammarling, Numerical Algorithms Group Ltd.
C
C

F06YFF
      SUBROUTINE F06YFF(SIDE,UPLO,TRANSA,DIAG,M,N,ALPHA,A,LDA,B,LDB)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C  Purpose
C  =======
C
C  DTRMM  performs one of the matrix-matrix operations
C
C     B := alpha*op( A )*B,   or   B := alpha*B*op( A ),
C
C  where  alpha  is a scalar,  B  is an m by n matrix,  A  is a unit, or
C  non-unit,  upper or lower triangular matrix  and  op( A )  is one  of
C
C     op( A ) = A   or   op( A ) = A'.
C
C  Parameters
C  ==========
C
C  SIDE   - CHARACTER*1.
C           On entry,  SIDE specifies whether  op( A ) multiplies B from
C           the left or right as follows:
C
C              SIDE = 'L' or 'l'   B := alpha*op( A )*B.
C
C              SIDE = 'R' or 'r'   B := alpha*B*op( A ).
C
C           Unchanged on exit.
C
C  UPLO   - CHARACTER*1.
C           On entry, UPLO specifies whether the matrix A is an upper or
C           lower triangular matrix as follows:
C
C              UPLO = 'U' or 'u'   A is an upper triangular matrix.
C
C              UPLO = 'L' or 'l'   A is a lower triangular matrix.
C
C           Unchanged on exit.
C
C  TRANSA - CHARACTER*1.
C           On entry, TRANSA specifies the form of op( A ) to be used in
C           the matrix multiplication as follows:
C
C              TRANSA = 'N' or 'n'   op( A ) = A.
C
C              TRANSA = 'T' or 't'   op( A ) = A'.
C
C              TRANSA = 'C' or 'c'   op( A ) = A'.
C
C           Unchanged on exit.
C
C  DIAG   - CHARACTER*1.
C           On entry, DIAG specifies whether or not A is unit triangular
C           as follows:
C
C              DIAG = 'U' or 'u'   A is assumed to be unit triangular.
C
C              DIAG = 'N' or 'n'   A is not assumed to be unit
C                                  triangular.
C
C           Unchanged on exit.
C
C  M      - INTEGER.
C           On entry, M specifies the number of rows of B. M must be at
C           least zero.
C           Unchanged on exit.
C
C  N      - INTEGER.
C           On entry, N specifies the number of columns of B.  N must be
C           at least zero.
C           Unchanged on exit.
C
C  ALPHA  - REAL            .
C           On entry,  ALPHA specifies the scalar  alpha. When  alpha is
C           zero then  A is not referenced and  B need not be set before
C           entry.
C           Unchanged on exit.
C
C  A      - REAL             array of DIMENSION ( LDA, k ), where k is m
C           when  SIDE = 'L' or 'l'  and is  n  when  SIDE = 'R' or 'r'.
C           Before entry  with  UPLO = 'U' or 'u',  the  leading  k by k
C           upper triangular part of the array  A must contain the upper
C           triangular matrix  and the strictly lower triangular part of
C           A is not referenced.
C           Before entry  with  UPLO = 'L' or 'l',  the  leading  k by k
C           lower triangular part of the array  A must contain the lower
C           triangular matrix  and the strictly upper triangular part of
C           A is not referenced.
C           Note that when  DIAG = 'U' or 'u',  the diagonal elements of
C           A  are not referenced either,  but are assumed to be  unity.
C           Unchanged on exit.
C
C  LDA    - INTEGER.
C           On entry, LDA specifies the first dimension of A as declared
C           in the calling (sub) program.  When  SIDE = 'L' or 'l'  then
C           LDA  must be at least  max( 1, m ),  when  SIDE = 'R' or 'r'
C           then LDA must be at least max( 1, n ).
C           Unchanged on exit.
C
C  B      - REAL             array of DIMENSION ( LDB, n ).
C           Before entry,  the leading  m by n part of the array  B must
C           contain the matrix  B,  and  on exit  is overwritten  by the
C           transformed matrix.
C
C  LDB    - INTEGER.
C           On entry, LDB specifies the first dimension of B as declared
C           in  the  calling  (sub)  program.   LDB  must  be  at  least
C           max( 1, m ).
C           Unchanged on exit.
C
C
C  Level 3 Blas routine.
C
C  -- Written on 8-February-1989.
C     Jack Dongarra, Argonne National Laboratory.
C     Iain Duff, AERE Harwell.
C     Jeremy Du Croz, Numerical Algorithms Group Ltd.
C     Sven Hammarling, Numerical Algorithms Group Ltd.
C
C

F06YJF
      SUBROUTINE F06YJF(SIDE,UPLO,TRANSA,DIAG,M,N,ALPHA,A,LDA,B,LDB)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C  Purpose
C  =======
C
C  DTRSM  solves one of the matrix equations
C
C     op( A )*X = alpha*B,   or   X*op( A ) = alpha*B,
C
C  where alpha is a scalar, X and B are m by n matrices, A is a unit, or
C  non-unit,  upper or lower triangular matrix  and  op( A )  is one  of
C
C     op( A ) = A   or   op( A ) = A'.
C
C  The matrix X is overwritten on B.
C
C  Parameters
C  ==========
C
C  SIDE   - CHARACTER*1.
C           On entry, SIDE specifies whether op( A ) appears on the left
C           or right of X as follows:
C
C              SIDE = 'L' or 'l'   op( A )*X = alpha*B.
C
C              SIDE = 'R' or 'r'   X*op( A ) = alpha*B.
C
C           Unchanged on exit.
C
C  UPLO   - CHARACTER*1.
C           On entry, UPLO specifies whether the matrix A is an upper or
C           lower triangular matrix as follows:
C
C              UPLO = 'U' or 'u'   A is an upper triangular matrix.
C
C              UPLO = 'L' or 'l'   A is a lower triangular matrix.
C
C           Unchanged on exit.
C
C  TRANSA - CHARACTER*1.
C           On entry, TRANSA specifies the form of op( A ) to be used in
C           the matrix multiplication as follows:
C
C              TRANSA = 'N' or 'n'   op( A ) = A.
C
C              TRANSA = 'T' or 't'   op( A ) = A'.
C
C              TRANSA = 'C' or 'c'   op( A ) = A'.
C
C           Unchanged on exit.
C
C  DIAG   - CHARACTER*1.
C           On entry, DIAG specifies whether or not A is unit triangular
C           as follows:
C
C              DIAG = 'U' or 'u'   A is assumed to be unit triangular.
C
C              DIAG = 'N' or 'n'   A is not assumed to be unit
C                                  triangular.
C
C           Unchanged on exit.
C
C  M      - INTEGER.
C           On entry, M specifies the number of rows of B. M must be at
C           least zero.
C           Unchanged on exit.
C
C  N      - INTEGER.
C           On entry, N specifies the number of columns of B.  N must be
C           at least zero.
C           Unchanged on exit.
C
C  ALPHA  - REAL            .
C           On entry,  ALPHA specifies the scalar  alpha. When  alpha is
C           zero then  A is not referenced and  B need not be set before
C           entry.
C           Unchanged on exit.
C
C  A      - REAL             array of DIMENSION ( LDA, k ), where k is m
C           when  SIDE = 'L' or 'l'  and is  n  when  SIDE = 'R' or 'r'.
C           Before entry  with  UPLO = 'U' or 'u',  the  leading  k by k
C           upper triangular part of the array  A must contain the upper
C           triangular matrix  and the strictly lower triangular part of
C           A is not referenced.
C           Before entry  with  UPLO = 'L' or 'l',  the  leading  k by k
C           lower triangular part of the array  A must contain the lower
C           triangular matrix  and the strictly upper triangular part of
C           A is not referenced.
C           Note that when  DIAG = 'U' or 'u',  the diagonal elements of
C           A  are not referenced either,  but are assumed to be  unity.
C           Unchanged on exit.
C
C  LDA    - INTEGER.
C           On entry, LDA specifies the first dimension of A as declared
C           in the calling (sub) program.  When  SIDE = 'L' or 'l'  then
C           LDA  must be at least  max( 1, m ),  when  SIDE = 'R' or 'r'
C           then LDA must be at least max( 1, n ).
C           Unchanged on exit.
C
C  B      - REAL             array of DIMENSION ( LDB, n ).
C           Before entry,  the leading  m by n part of the array  B must
C           contain  the  right-hand  side  matrix  B,  and  on exit  is
C           overwritten by the solution matrix  X.
C
C  LDB    - INTEGER.
C           On entry, LDB specifies the first dimension of B as declared
C           in  the  calling  (sub)  program.   LDB  must  be  at  least
C           max( 1, m ).
C           Unchanged on exit.
C
C
C  Level 3 Blas routine.
C
C
C  -- Written on 8-February-1989.
C     Jack Dongarra, Argonne National Laboratory.
C     Iain Duff, AERE Harwell.
C     Jeremy Du Croz, Numerical Algorithms Group Ltd.
C     Sven Hammarling, Numerical Algorithms Group Ltd.
C
C

F06YPF
      SUBROUTINE F06YPF(UPLO,TRANS,N,K,ALPHA,A,LDA,BETA,C,LDC)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C  Purpose
C  =======
C
C  DSYRK  performs one of the symmetric rank k operations
C
C     C := alpha*A*A' + beta*C,
C
C  or
C
C     C := alpha*A'*A + beta*C,
C
C  where  alpha and beta  are scalars, C is an  n by n  symmetric matrix
C  and  A  is an  n by k  matrix in the first case and a  k by n  matrix
C  in the second case.
C
C  Parameters
C  ==========
C
C  UPLO   - CHARACTER*1.
C           On  entry,   UPLO  specifies  whether  the  upper  or  lower
C           triangular  part  of the  array  C  is to be  referenced  as
C           follows:
C
C              UPLO = 'U' or 'u'   Only the  upper triangular part of  C
C                                  is to be referenced.
C
C              UPLO = 'L' or 'l'   Only the  lower triangular part of  C
C                                  is to be referenced.
C
C           Unchanged on exit.
C
C  TRANS  - CHARACTER*1.
C           On entry,  TRANS  specifies the operation to be performed as
C           follows:
C
C              TRANS = 'N' or 'n'   C := alpha*A*A' + beta*C.
C
C              TRANS = 'T' or 't'   C := alpha*A'*A + beta*C.
C
C              TRANS = 'C' or 'c'   C := alpha*A'*A + beta*C.
C
C           Unchanged on exit.
C
C  N      - INTEGER.
C           On entry,  N specifies the order of the matrix C.  N must be
C           at least zero.
C           Unchanged on exit.
C
C  K      - INTEGER.
C           On entry with  TRANS = 'N' or 'n',  K  specifies  the number
C           of  columns   of  the   matrix   A,   and  on   entry   with
C           TRANS = 'T' or 't' or 'C' or 'c',  K  specifies  the  number
C           of rows of the matrix  A.  K must be at least zero.
C           Unchanged on exit.
C
C  ALPHA  - REAL            .
C           On entry, ALPHA specifies the scalar alpha.
C           Unchanged on exit.
C
C  A      - REAL             array of DIMENSION ( LDA, ka ), where ka is
C           k  when  TRANS = 'N' or 'n',  and is  n  otherwise.
C           Before entry with  TRANS = 'N' or 'n',  the  leading  n by k
C           part of the array  A  must contain the matrix  A,  otherwise
C           the leading  k by n  part of the array  A  must contain  the
C           matrix A.
C           Unchanged on exit.
C
C  LDA    - INTEGER.
C           On entry, LDA specifies the first dimension of A as declared
C           in  the  calling  (sub)  program.   When  TRANS = 'N' or 'n'
C           then  LDA must be at least  max( 1, n ), otherwise  LDA must
C           be at least  max( 1, k ).
C           Unchanged on exit.
C
C  BETA   - REAL            .
C           On entry, BETA specifies the scalar beta.
C           Unchanged on exit.
C
C  C      - REAL             array of DIMENSION ( LDC, n ).
C           Before entry  with  UPLO = 'U' or 'u',  the leading  n by n
C           upper triangular part of the array C must contain the upper
C           triangular part  of the  symmetric matrix  and the strictly
C           lower triangular part of C is not referenced.  On exit, the
C           upper triangular part of the array  C is overwritten by the
C           upper triangular part of the updated matrix.
C           Before entry  with  UPLO = 'L' or 'l',  the leading  n by n
C           lower triangular part of the array C must contain the lower
C           triangular part  of the  symmetric matrix  and the strictly
C           upper triangular part of C is not referenced.  On exit, the
C           lower triangular part of the array  C is overwritten by the
C           lower triangular part of the updated matrix.
C
C  LDC    - INTEGER.
C           On entry, LDC specifies the first dimension of C as declared
C           in  the  calling  (sub)  program.   LDC  must  be  at  least
C           max( 1, n ).
C           Unchanged on exit.
C
C
C  Level 3 Blas routine.
C
C  -- Written on 8-February-1989.
C     Jack Dongarra, Argonne National Laboratory.
C     Iain Duff, AERE Harwell.
C     Jeremy Du Croz, Numerical Algorithms Group Ltd.
C     Sven Hammarling, Numerical Algorithms Group Ltd.
C
C

F06YRF
      SUBROUTINE F06YRF(UPLO,TRANS,N,K,ALPHA,A,LDA,B,LDB,BETA,C,LDC)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C  Purpose
C  =======
C
C  DSYR2K  performs one of the symmetric rank 2k operations
C
C     C := alpha*A*B' + alpha*B*A' + beta*C,
C
C  or
C
C     C := alpha*A'*B + alpha*B'*A + beta*C,
C
C  where  alpha and beta  are scalars, C is an  n by n  symmetric matrix
C  and  A and B  are  n by k  matrices  in the  first  case  and  k by n
C  matrices in the second case.
C
C  Parameters
C  ==========
C
C  UPLO   - CHARACTER*1.
C           On  entry,   UPLO  specifies  whether  the  upper  or  lower
C           triangular  part  of the  array  C  is to be  referenced  as
C           follows:
C
C              UPLO = 'U' or 'u'   Only the  upper triangular part of  C
C                                  is to be referenced.
C
C              UPLO = 'L' or 'l'   Only the  lower triangular part of  C
C                                  is to be referenced.
C
C           Unchanged on exit.
C
C  TRANS  - CHARACTER*1.
C           On entry,  TRANS  specifies the operation to be performed as
C           follows:
C
C              TRANS = 'N' or 'n'   C := alpha*A*B' + alpha*B*A' +
C                                        beta*C.
C
C              TRANS = 'T' or 't'   C := alpha*A'*B + alpha*B'*A +
C                                        beta*C.
C
C              TRANS = 'C' or 'c'   C := alpha*A'*B + alpha*B'*A +
C                                        beta*C.
C
C           Unchanged on exit.
C
C  N      - INTEGER.
C           On entry,  N specifies the order of the matrix C.  N must be
C           at least zero.
C           Unchanged on exit.
C
C  K      - INTEGER.
C           On entry with  TRANS = 'N' or 'n',  K  specifies  the number
C           of  columns  of the  matrices  A and B,  and on  entry  with
C           TRANS = 'T' or 't' or 'C' or 'c',  K  specifies  the  number
C           of rows of the matrices  A and B.  K must be at least  zero.
C           Unchanged on exit.
C
C  ALPHA  - REAL            .
C           On entry, ALPHA specifies the scalar alpha.
C           Unchanged on exit.
C
C  A      - REAL             array of DIMENSION ( LDA, ka ), where ka is
C           k  when  TRANS = 'N' or 'n',  and is  n  otherwise.
C           Before entry with  TRANS = 'N' or 'n',  the  leading  n by k
C           part of the array  A  must contain the matrix  A,  otherwise
C           the leading  k by n  part of the array  A  must contain  the
C           matrix A.
C           Unchanged on exit.
C
C  LDA    - INTEGER.
C           On entry, LDA specifies the first dimension of A as declared
C           in  the  calling  (sub)  program.   When  TRANS = 'N' or 'n'
C           then  LDA must be at least  max( 1, n ), otherwise  LDA must
C           be at least  max( 1, k ).
C           Unchanged on exit.
C
C  B      - REAL             array of DIMENSION ( LDB, kb ), where kb is
C           k  when  TRANS = 'N' or 'n',  and is  n  otherwise.
C           Before entry with  TRANS = 'N' or 'n',  the  leading  n by k
C           part of the array  B  must contain the matrix  B,  otherwise
C           the leading  k by n  part of the array  B  must contain  the
C           matrix B.
C           Unchanged on exit.
C
C  LDB    - INTEGER.
C           On entry, LDB specifies the first dimension of B as declared
C           in  the  calling  (sub)  program.   When  TRANS = 'N' or 'n'
C           then  LDB must be at least  max( 1, n ), otherwise  LDB must
C           be at least  max( 1, k ).
C           Unchanged on exit.
C
C  BETA   - REAL            .
C           On entry, BETA specifies the scalar beta.
C           Unchanged on exit.
C
C  C      - REAL             array of DIMENSION ( LDC, n ).
C           Before entry  with  UPLO = 'U' or 'u',  the leading  n by n
C           upper triangular part of the array C must contain the upper
C           triangular part  of the  symmetric matrix  and the strictly
C           lower triangular part of C is not referenced.  On exit, the
C           upper triangular part of the array  C is overwritten by the
C           upper triangular part of the updated matrix.
C           Before entry  with  UPLO = 'L' or 'l',  the leading  n by n
C           lower triangular part of the array C must contain the lower
C           triangular part  of the  symmetric matrix  and the strictly
C           upper triangular part of C is not referenced.  On exit, the
C           lower triangular part of the array  C is overwritten by the
C           lower triangular part of the updated matrix.
C
C  LDC    - INTEGER.
C           On entry, LDC specifies the first dimension of C as declared
C           in  the  calling  (sub)  program.   LDC  must  be  at  least
C           max( 1, n ).
C           Unchanged on exit.
C
C
C  Level 3 Blas routine.
C
C
C  -- Written on 8-February-1989.
C     Jack Dongarra, Argonne National Laboratory.
C     Iain Duff, AERE Harwell.
C     Jeremy Du Croz, Numerical Algorithms Group Ltd.
C     Sven Hammarling, Numerical Algorithms Group Ltd.
C
C

F06ZAF
      SUBROUTINE F06ZAF(TRANSA,TRANSB,M,N,K,ALPHA,A,LDA,B,LDB,BETA,C,
     *                  LDC)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C  Purpose
C  =======
C
C  ZGEMM  performs one of the matrix-matrix operations
C
C     C := alpha*op( A )*op( B ) + beta*C,
C
C  where  op( X ) is one of
C
C     op( X ) = X   or   op( X ) = X'   or   op( X ) = conjg( X' ),
C
C  alpha and beta are scalars, and A, B and C are matrices, with op( A )
C  an m by k matrix,  op( B )  a  k by n matrix and  C an m by n matrix.
C
C  Parameters
C  ==========
C
C  TRANSA - CHARACTER*1.
C           On entry, TRANSA specifies the form of op( A ) to be used in
C           the matrix multiplication as follows:
C
C              TRANSA = 'N' or 'n',  op( A ) = A.
C
C              TRANSA = 'T' or 't',  op( A ) = A'.
C
C              TRANSA = 'C' or 'c',  op( A ) = conjg( A' ).
C
C           Unchanged on exit.
C
C  TRANSB - CHARACTER*1.
C           On entry, TRANSB specifies the form of op( B ) to be used in
C           the matrix multiplication as follows:
C
C              TRANSB = 'N' or 'n',  op( B ) = B.
C
C              TRANSB = 'T' or 't',  op( B ) = B'.
C
C              TRANSB = 'C' or 'c',  op( B ) = conjg( B' ).
C
C           Unchanged on exit.
C
C  M      - INTEGER.
C           On entry,  M  specifies  the number  of rows  of the  matrix
C           op( A )  and of the  matrix  C.  M  must  be at least  zero.
C           Unchanged on exit.
C
C  N      - INTEGER.
C           On entry,  N  specifies the number  of columns of the matrix
C           op( B ) and the number of columns of the matrix C. N must be
C           at least zero.
C           Unchanged on exit.
C
C  K      - INTEGER.
C           On entry,  K  specifies  the number of columns of the matrix
C           op( A ) and the number of rows of the matrix op( B ). K must
C           be at least  zero.
C           Unchanged on exit.
C
C  ALPHA  - COMPLEX         .
C           On entry, ALPHA specifies the scalar alpha.
C           Unchanged on exit.
C
C  A      - COMPLEX          array of DIMENSION ( LDA, ka ), where ka is
C           k  when  TRANSA = 'N' or 'n',  and is  m  otherwise.
C           Before entry with  TRANSA = 'N' or 'n',  the leading  m by k
C           part of the array  A  must contain the matrix  A,  otherwise
C           the leading  k by m  part of the array  A  must contain  the
C           matrix A.
C           Unchanged on exit.
C
C  LDA    - INTEGER.
C           On entry, LDA specifies the first dimension of A as declared
C           in the calling (sub) program. When  TRANSA = 'N' or 'n' then
C           LDA must be at least  max( 1, m ), otherwise  LDA must be at
C           least  max( 1, k ).
C           Unchanged on exit.
C
C  B      - COMPLEX          array of DIMENSION ( LDB, kb ), where kb is
C           n  when  TRANSB = 'N' or 'n',  and is  k  otherwise.
C           Before entry with  TRANSB = 'N' or 'n',  the leading  k by n
C           part of the array  B  must contain the matrix  B,  otherwise
C           the leading  n by k  part of the array  B  must contain  the
C           matrix B.
C           Unchanged on exit.
C
C  LDB    - INTEGER.
C           On entry, LDB specifies the first dimension of B as declared
C           in the calling (sub) program. When  TRANSB = 'N' or 'n' then
C           LDB must be at least  max( 1, k ), otherwise  LDB must be at
C           least  max( 1, n ).
C           Unchanged on exit.
C
C  BETA   - COMPLEX         .
C           On entry,  BETA  specifies the scalar  beta.  When  BETA  is
C           supplied as zero then C need not be set on input.
C           Unchanged on exit.
C
C  C      - COMPLEX          array of DIMENSION ( LDC, n ).
C           Before entry, the leading  m by n  part of the array  C must
C           contain the matrix  C,  except when  beta  is zero, in which
C           case C need not be set on entry.
C           On exit, the array  C  is overwritten by the  m by n  matrix
C           ( alpha*op( A )*op( B ) + beta*C ).
C
C  LDC    - INTEGER.
C           On entry, LDC specifies the first dimension of C as declared
C           in  the  calling  (sub)  program.   LDC  must  be  at  least
C           max( 1, m ).
C           Unchanged on exit.
C
C
C  Level 3 Blas routine.
C
C  -- Written on 8-February-1989.
C     Jack Dongarra, Argonne National Laboratory.
C     Iain Duff, AERE Harwell.
C     Jeremy Du Croz, Numerical Algorithms Group Ltd.
C     Sven Hammarling, Numerical Algorithms Group Ltd.
C
C

F06ZCF
      SUBROUTINE F06ZCF(SIDE,UPLO,M,N,ALPHA,A,LDA,B,LDB,BETA,C,LDC)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C  Purpose
C  =======
C
C  ZHEMM  performs one of the matrix-matrix operations
C
C     C := alpha*A*B + beta*C,
C
C  or
C
C     C := alpha*B*A + beta*C,
C
C  where alpha and beta are scalars, A is an hermitian matrix and  B and
C  C are m by n matrices.
C
C  Parameters
C  ==========
C
C  SIDE   - CHARACTER*1.
C           On entry,  SIDE  specifies whether  the  hermitian matrix  A
C           appears on the  left or right  in the  operation as follows:
C
C              SIDE = 'L' or 'l'   C := alpha*A*B + beta*C,
C
C              SIDE = 'R' or 'r'   C := alpha*B*A + beta*C,
C
C           Unchanged on exit.
C
C  UPLO   - CHARACTER*1.
C           On  entry,   UPLO  specifies  whether  the  upper  or  lower
C           triangular  part  of  the  hermitian  matrix   A  is  to  be
C           referenced as follows:
C
C              UPLO = 'U' or 'u'   Only the upper triangular part of the
C                                  hermitian matrix is to be referenced.
C
C              UPLO = 'L' or 'l'   Only the lower triangular part of the
C                                  hermitian matrix is to be referenced.
C
C           Unchanged on exit.
C
C  M      - INTEGER.
C           On entry,  M  specifies the number of rows of the matrix  C.
C           M  must be at least zero.
C           Unchanged on exit.
C
C  N      - INTEGER.
C           On entry, N specifies the number of columns of the matrix C.
C           N  must be at least zero.
C           Unchanged on exit.
C
C  ALPHA  - COMPLEX         .
C           On entry, ALPHA specifies the scalar alpha.
C           Unchanged on exit.
C
C  A      - COMPLEX          array of DIMENSION ( LDA, ka ), where ka is
C           m  when  SIDE = 'L' or 'l'  and is n  otherwise.
C           Before entry  with  SIDE = 'L' or 'l',  the  m by m  part of
C           the array  A  must contain the  hermitian matrix,  such that
C           when  UPLO = 'U' or 'u', the leading m by m upper triangular
C           part of the array  A  must contain the upper triangular part
C           of the  hermitian matrix and the  strictly  lower triangular
C           part of  A  is not referenced,  and when  UPLO = 'L' or 'l',
C           the leading  m by m  lower triangular part  of the  array  A
C           must  contain  the  lower triangular part  of the  hermitian
C           matrix and the  strictly upper triangular part of  A  is not
C           referenced.
C           Before entry  with  SIDE = 'R' or 'r',  the  n by n  part of
C           the array  A  must contain the  hermitian matrix,  such that
C           when  UPLO = 'U' or 'u', the leading n by n upper triangular
C           part of the array  A  must contain the upper triangular part
C           of the  hermitian matrix and the  strictly  lower triangular
C           part of  A  is not referenced,  and when  UPLO = 'L' or 'l',
C           the leading  n by n  lower triangular part  of the  array  A
C           must  contain  the  lower triangular part  of the  hermitian
C           matrix and the  strictly upper triangular part of  A  is not
C           referenced.
C           Note that the imaginary parts  of the diagonal elements need
C           not be set, they are assumed to be zero.
C           Unchanged on exit.
C
C  LDA    - INTEGER.
C           On entry, LDA specifies the first dimension of A as declared
C           in the  calling (sub) program. When  SIDE = 'L' or 'l'  then
C           LDA must be at least  max( 1, m ), otherwise  LDA must be at
C           least max( 1, n ).
C           Unchanged on exit.
C
C  B      - COMPLEX          array of DIMENSION ( LDB, n ).
C           Before entry, the leading  m by n part of the array  B  must
C           contain the matrix B.
C           Unchanged on exit.
C
C  LDB    - INTEGER.
C           On entry, LDB specifies the first dimension of B as declared
C           in  the  calling  (sub)  program.   LDB  must  be  at  least
C           max( 1, m ).
C           Unchanged on exit.
C
C  BETA   - COMPLEX         .
C           On entry,  BETA  specifies the scalar  beta.  When  BETA  is
C           supplied as zero then C need not be set on input.
C           Unchanged on exit.
C
C  C      - COMPLEX          array of DIMENSION ( LDC, n ).
C           Before entry, the leading  m by n  part of the array  C must
C           contain the matrix  C,  except when  beta  is zero, in which
C           case C need not be set on entry.
C           On exit, the array  C  is overwritten by the  m by n updated
C           matrix.
C
C  LDC    - INTEGER.
C           On entry, LDC specifies the first dimension of C as declared
C           in  the  calling  (sub)  program.   LDC  must  be  at  least
C           max( 1, m ).
C           Unchanged on exit.
C
C
C  Level 3 Blas routine.
C
C  -- Written on 8-February-1989.
C     Jack Dongarra, Argonne National Laboratory.
C     Iain Duff, AERE Harwell.
C     Jeremy Du Croz, Numerical Algorithms Group Ltd.
C     Sven Hammarling, Numerical Algorithms Group Ltd.
C
C

F06ZFF
      SUBROUTINE F06ZFF(SIDE,UPLO,TRANSA,DIAG,M,N,ALPHA,A,LDA,B,LDB)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C  Purpose
C  =======
C
C  ZTRMM  performs one of the matrix-matrix operations
C
C     B := alpha*op( A )*B,   or   B := alpha*B*op( A )
C
C  where  alpha  is a scalar,  B  is an m by n matrix,  A  is a unit, or
C  non-unit,  upper or lower triangular matrix  and  op( A )  is one  of
C
C     op( A ) = A   or   op( A ) = A'   or   op( A ) = conjg( A' ).
C
C  Parameters
C  ==========
C
C  SIDE   - CHARACTER*1.
C           On entry,  SIDE specifies whether  op( A ) multiplies B from
C           the left or right as follows:
C
C              SIDE = 'L' or 'l'   B := alpha*op( A )*B.
C
C              SIDE = 'R' or 'r'   B := alpha*B*op( A ).
C
C           Unchanged on exit.
C
C  UPLO   - CHARACTER*1.
C           On entry, UPLO specifies whether the matrix A is an upper or
C           lower triangular matrix as follows:
C
C              UPLO = 'U' or 'u'   A is an upper triangular matrix.
C
C              UPLO = 'L' or 'l'   A is a lower triangular matrix.
C
C           Unchanged on exit.
C
C  TRANSA - CHARACTER*1.
C           On entry, TRANSA specifies the form of op( A ) to be used in
C           the matrix multiplication as follows:
C
C              TRANSA = 'N' or 'n'   op( A ) = A.
C
C              TRANSA = 'T' or 't'   op( A ) = A'.
C
C              TRANSA = 'C' or 'c'   op( A ) = conjg( A' ).
C
C           Unchanged on exit.
C
C  DIAG   - CHARACTER*1.
C           On entry, DIAG specifies whether or not A is unit triangular
C           as follows:
C
C              DIAG = 'U' or 'u'   A is assumed to be unit triangular.
C
C              DIAG = 'N' or 'n'   A is not assumed to be unit
C                                  triangular.
C
C           Unchanged on exit.
C
C  M      - INTEGER.
C           On entry, M specifies the number of rows of B. M must be at
C           least zero.
C           Unchanged on exit.
C
C  N      - INTEGER.
C           On entry, N specifies the number of columns of B.  N must be
C           at least zero.
C           Unchanged on exit.
C
C  ALPHA  - COMPLEX         .
C           On entry,  ALPHA specifies the scalar  alpha. When  alpha is
C           zero then  A is not referenced and  B need not be set before
C           entry.
C           Unchanged on exit.
C
C  A      - COMPLEX          array of DIMENSION ( LDA, k ), where k is m
C           when  SIDE = 'L' or 'l'  and is  n  when  SIDE = 'R' or 'r'.
C           Before entry  with  UPLO = 'U' or 'u',  the  leading  k by k
C           upper triangular part of the array  A must contain the upper
C           triangular matrix  and the strictly lower triangular part of
C           A is not referenced.
C           Before entry  with  UPLO = 'L' or 'l',  the  leading  k by k
C           lower triangular part of the array  A must contain the lower
C           triangular matrix  and the strictly upper triangular part of
C           A is not referenced.
C           Note that when  DIAG = 'U' or 'u',  the diagonal elements of
C           A  are not referenced either,  but are assumed to be  unity.
C           Unchanged on exit.
C
C  LDA    - INTEGER.
C           On entry, LDA specifies the first dimension of A as declared
C           in the calling (sub) program.  When  SIDE = 'L' or 'l'  then
C           LDA  must be at least  max( 1, m ),  when  SIDE = 'R' or 'r'
C           then LDA must be at least max( 1, n ).
C           Unchanged on exit.
C
C  B      - COMPLEX          array of DIMENSION ( LDB, n ).
C           Before entry,  the leading  m by n part of the array  B must
C           contain the matrix  B,  and  on exit  is overwritten  by the
C           transformed matrix.
C
C  LDB    - INTEGER.
C           On entry, LDB specifies the first dimension of B as declared
C           in  the  calling  (sub)  program.   LDB  must  be  at  least
C           max( 1, m ).
C           Unchanged on exit.
C
C
C  Level 3 Blas routine.
C
C  -- Written on 8-February-1989.
C     Jack Dongarra, Argonne National Laboratory.
C     Iain Duff, AERE Harwell.
C     Jeremy Du Croz, Numerical Algorithms Group Ltd.
C     Sven Hammarling, Numerical Algorithms Group Ltd.
C
C

F06ZJF
      SUBROUTINE F06ZJF(SIDE,UPLO,TRANSA,DIAG,M,N,ALPHA,A,LDA,B,LDB)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C  Purpose
C  =======
C
C  ZTRSM  solves one of the matrix equations
C
C     op( A )*X = alpha*B,   or   X*op( A ) = alpha*B,
C
C  where alpha is a scalar, X and B are m by n matrices, A is a unit, or
C  non-unit,  upper or lower triangular matrix  and  op( A )  is one  of
C
C     op( A ) = A   or   op( A ) = A'   or   op( A ) = conjg( A' ).
C
C  The matrix X is overwritten on B.
C
C  Parameters
C  ==========
C
C  SIDE   - CHARACTER*1.
C           On entry, SIDE specifies whether op( A ) appears on the left
C           or right of X as follows:
C
C              SIDE = 'L' or 'l'   op( A )*X = alpha*B.
C
C              SIDE = 'R' or 'r'   X*op( A ) = alpha*B.
C
C           Unchanged on exit.
C
C  UPLO   - CHARACTER*1.
C           On entry, UPLO specifies whether the matrix A is an upper or
C           lower triangular matrix as follows:
C
C              UPLO = 'U' or 'u'   A is an upper triangular matrix.
C
C              UPLO = 'L' or 'l'   A is a lower triangular matrix.
C
C           Unchanged on exit.
C
C  TRANSA - CHARACTER*1.
C           On entry, TRANSA specifies the form of op( A ) to be used in
C           the matrix multiplication as follows:
C
C              TRANSA = 'N' or 'n'   op( A ) = A.
C
C              TRANSA = 'T' or 't'   op( A ) = A'.
C
C              TRANSA = 'C' or 'c'   op( A ) = conjg( A' ).
C
C           Unchanged on exit.
C
C  DIAG   - CHARACTER*1.
C           On entry, DIAG specifies whether or not A is unit triangular
C           as follows:
C
C              DIAG = 'U' or 'u'   A is assumed to be unit triangular.
C
C              DIAG = 'N' or 'n'   A is not assumed to be unit
C                                  triangular.
C
C           Unchanged on exit.
C
C  M      - INTEGER.
C           On entry, M specifies the number of rows of B. M must be at
C           least zero.
C           Unchanged on exit.
C
C  N      - INTEGER.
C           On entry, N specifies the number of columns of B.  N must be
C           at least zero.
C           Unchanged on exit.
C
C  ALPHA  - COMPLEX         .
C           On entry,  ALPHA specifies the scalar  alpha. When  alpha is
C           zero then  A is not referenced and  B need not be set before
C           entry.
C           Unchanged on exit.
C
C  A      - COMPLEX          array of DIMENSION ( LDA, k ), where k is m
C           when  SIDE = 'L' or 'l'  and is  n  when  SIDE = 'R' or 'r'.
C           Before entry  with  UPLO = 'U' or 'u',  the  leading  k by k
C           upper triangular part of the array  A must contain the upper
C           triangular matrix  and the strictly lower triangular part of
C           A is not referenced.
C           Before entry  with  UPLO = 'L' or 'l',  the  leading  k by k
C           lower triangular part of the array  A must contain the lower
C           triangular matrix  and the strictly upper triangular part of
C           A is not referenced.
C           Note that when  DIAG = 'U' or 'u',  the diagonal elements of
C           A  are not referenced either,  but are assumed to be  unity.
C           Unchanged on exit.
C
C  LDA    - INTEGER.
C           On entry, LDA specifies the first dimension of A as declared
C           in the calling (sub) program.  When  SIDE = 'L' or 'l'  then
C           LDA  must be at least  max( 1, m ),  when  SIDE = 'R' or 'r'
C           then LDA must be at least max( 1, n ).
C           Unchanged on exit.
C
C  B      - COMPLEX          array of DIMENSION ( LDB, n ).
C           Before entry,  the leading  m by n part of the array  B must
C           contain  the  right-hand  side  matrix  B,  and  on exit  is
C           overwritten by the solution matrix  X.
C
C  LDB    - INTEGER.
C           On entry, LDB specifies the first dimension of B as declared
C           in  the  calling  (sub)  program.   LDB  must  be  at  least
C           max( 1, m ).
C           Unchanged on exit.
C
C
C  Level 3 Blas routine.
C
C  -- Written on 8-February-1989.
C     Jack Dongarra, Argonne National Laboratory.
C     Iain Duff, AERE Harwell.
C     Jeremy Du Croz, Numerical Algorithms Group Ltd.
C     Sven Hammarling, Numerical Algorithms Group Ltd.
C
C

F06ZPF
      SUBROUTINE F06ZPF(UPLO,TRANS,N,K,ALPHA,A,LDA,BETA,C,LDC)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C  Purpose
C  =======
C
C  ZHERK  performs one of the hermitian rank k operations
C
C     C := alpha*A*conjg( A' ) + beta*C,
C
C  or
C
C     C := alpha*conjg( A' )*A + beta*C,
C
C  where  alpha and beta  are  real scalars,  C is an  n by n  hermitian
C  matrix and  A  is an  n by k  matrix in the  first case and a  k by n
C  matrix in the second case.
C
C  Parameters
C  ==========
C
C  UPLO   - CHARACTER*1.
C           On  entry,   UPLO  specifies  whether  the  upper  or  lower
C           triangular  part  of the  array  C  is to be  referenced  as
C           follows:
C
C              UPLO = 'U' or 'u'   Only the  upper triangular part of  C
C                                  is to be referenced.
C
C              UPLO = 'L' or 'l'   Only the  lower triangular part of  C
C                                  is to be referenced.
C
C           Unchanged on exit.
C
C  TRANS  - CHARACTER*1.
C           On entry,  TRANS  specifies the operation to be performed as
C           follows:
C
C              TRANS = 'N' or 'n'   C := alpha*A*conjg( A' ) + beta*C.
C
C              TRANS = 'C' or 'c'   C := alpha*conjg( A' )*A + beta*C.
C
C           Unchanged on exit.
C
C  N      - INTEGER.
C           On entry,  N specifies the order of the matrix C.  N must be
C           at least zero.
C           Unchanged on exit.
C
C  K      - INTEGER.
C           On entry with  TRANS = 'N' or 'n',  K  specifies  the number
C           of  columns   of  the   matrix   A,   and  on   entry   with
C           TRANS = 'C' or 'c',  K  specifies  the number of rows of the
C           matrix A.  K must be at least zero.
C           Unchanged on exit.
C
C  ALPHA  - REAL            .
C           On entry, ALPHA specifies the scalar alpha.
C           Unchanged on exit.
C
C  A      - COMPLEX          array of DIMENSION ( LDA, ka ), where ka is
C           k  when  TRANS = 'N' or 'n',  and is  n  otherwise.
C           Before entry with  TRANS = 'N' or 'n',  the  leading  n by k
C           part of the array  A  must contain the matrix  A,  otherwise
C           the leading  k by n  part of the array  A  must contain  the
C           matrix A.
C           Unchanged on exit.
C
C  LDA    - INTEGER.
C           On entry, LDA specifies the first dimension of A as declared
C           in  the  calling  (sub)  program.   When  TRANS = 'N' or 'n'
C           then  LDA must be at least  max( 1, n ), otherwise  LDA must
C           be at least  max( 1, k ).
C           Unchanged on exit.
C
C  BETA   - REAL            .
C           On entry, BETA specifies the scalar beta.
C           Unchanged on exit.
C
C  C      - COMPLEX          array of DIMENSION ( LDC, n ).
C           Before entry  with  UPLO = 'U' or 'u',  the leading  n by n
C           upper triangular part of the array C must contain the upper
C           triangular part  of the  hermitian matrix  and the strictly
C           lower triangular part of C is not referenced.  On exit, the
C           upper triangular part of the array  C is overwritten by the
C           upper triangular part of the updated matrix.
C           Before entry  with  UPLO = 'L' or 'l',  the leading  n by n
C           lower triangular part of the array C must contain the lower
C           triangular part  of the  hermitian matrix  and the strictly
C           upper triangular part of C is not referenced.  On exit, the
C           lower triangular part of the array  C is overwritten by the
C           lower triangular part of the updated matrix.
C           Note that the imaginary parts of the diagonal elements need
C           not be set,  they are assumed to be zero,  and on exit they
C           are set to zero.
C
C  LDC    - INTEGER.
C           On entry, LDC specifies the first dimension of C as declared
C           in  the  calling  (sub)  program.   LDC  must  be  at  least
C           max( 1, n ).
C           Unchanged on exit.
C
C
C  Level 3 Blas routine.
C
C  -- Written on 8-February-1989.
C     Jack Dongarra, Argonne National Laboratory.
C     Iain Duff, AERE Harwell.
C     Jeremy Du Croz, Numerical Algorithms Group Ltd.
C     Sven Hammarling, Numerical Algorithms Group Ltd.
C
C

F06ZRF
      SUBROUTINE F06ZRF(UPLO,TRANS,N,K,ALPHA,A,LDA,B,LDB,BETA,C,LDC)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C  Purpose
C  =======
C
C  ZHER2K  performs one of the hermitian rank 2k operations
C
C     C := alpha*A*conjg( B' ) + conjg( alpha )*B*conjg( A' ) + beta*C,
C
C  or
C
C     C := alpha*conjg( A' )*B + conjg( alpha )*conjg( B' )*A + beta*C,
C
C  where  alpha and beta  are scalars with  beta  real,  C is an  n by n
C  hermitian matrix and  A and B  are  n by k matrices in the first case
C  and  k by n  matrices in the second case.
C
C  Parameters
C  ==========
C
C  UPLO   - CHARACTER*1.
C           On  entry,   UPLO  specifies  whether  the  upper  or  lower
C           triangular  part  of the  array  C  is to be  referenced  as
C           follows:
C
C              UPLO = 'U' or 'u'   Only the  upper triangular part of  C
C                                  is to be referenced.
C
C              UPLO = 'L' or 'l'   Only the  lower triangular part of  C
C                                  is to be referenced.
C
C           Unchanged on exit.
C
C  TRANS  - CHARACTER*1.
C           On entry,  TRANS  specifies the operation to be performed as
C           follows:
C
C              TRANS = 'N' or 'n'    C := alpha*A*conjg( B' )          +
C                                         conjg( alpha )*B*conjg( A' ) +
C                                         beta*C.
C
C              TRANS = 'C' or 'c'    C := alpha*conjg( A' )*B          +
C                                         conjg( alpha )*conjg( B' )*A +
C                                         beta*C.
C
C           Unchanged on exit.
C
C  N      - INTEGER.
C           On entry,  N specifies the order of the matrix C.  N must be
C           at least zero.
C           Unchanged on exit.
C
C  K      - INTEGER.
C           On entry with  TRANS = 'N' or 'n',  K  specifies  the number
C           of  columns  of the  matrices  A and B,  and on  entry  with
C           TRANS = 'C' or 'c',  K  specifies  the number of rows of the
C           matrices  A and B.  K must be at least zero.
C           Unchanged on exit.
C
C  ALPHA  - COMPLEX         .
C           On entry, ALPHA specifies the scalar alpha.
C           Unchanged on exit.
C
C  A      - COMPLEX          array of DIMENSION ( LDA, ka ), where ka is
C           k  when  TRANS = 'N' or 'n',  and is  n  otherwise.
C           Before entry with  TRANS = 'N' or 'n',  the  leading  n by k
C           part of the array  A  must contain the matrix  A,  otherwise
C           the leading  k by n  part of the array  A  must contain  the
C           matrix A.
C           Unchanged on exit.
C
C  LDA    - INTEGER.
C           On entry, LDA specifies the first dimension of A as declared
C           in  the  calling  (sub)  program.   When  TRANS = 'N' or 'n'
C           then  LDA must be at least  max( 1, n ), otherwise  LDA must
C           be at least  max( 1, k ).
C           Unchanged on exit.
C
C  B      - COMPLEX          array of DIMENSION ( LDB, kb ), where kb is
C           k  when  TRANS = 'N' or 'n',  and is  n  otherwise.
C           Before entry with  TRANS = 'N' or 'n',  the  leading  n by k
C           part of the array  B  must contain the matrix  B,  otherwise
C           the leading  k by n  part of the array  B  must contain  the
C           matrix B.
C           Unchanged on exit.
C
C  LDB    - INTEGER.
C           On entry, LDB specifies the first dimension of B as declared
C           in  the  calling  (sub)  program.   When  TRANS = 'N' or 'n'
C           then  LDB must be at least  max( 1, n ), otherwise  LDB must
C           be at least  max( 1, k ).
C           Unchanged on exit.
C
C  BETA   - REAL            .
C           On entry, BETA specifies the scalar beta.
C           Unchanged on exit.
C
C  C      - COMPLEX          array of DIMENSION ( LDC, n ).
C           Before entry  with  UPLO = 'U' or 'u',  the leading  n by n
C           upper triangular part of the array C must contain the upper
C           triangular part  of the  hermitian matrix  and the strictly
C           lower triangular part of C is not referenced.  On exit, the
C           upper triangular part of the array  C is overwritten by the
C           upper triangular part of the updated matrix.
C           Before entry  with  UPLO = 'L' or 'l',  the leading  n by n
C           lower triangular part of the array C must contain the lower
C           triangular part  of the  hermitian matrix  and the strictly
C           upper triangular part of C is not referenced.  On exit, the
C           lower triangular part of the array  C is overwritten by the
C           lower triangular part of the updated matrix.
C           Note that the imaginary parts of the diagonal elements need
C           not be set,  they are assumed to be zero,  and on exit they
C           are set to zero.
C
C  LDC    - INTEGER.
C           On entry, LDC specifies the first dimension of C as declared
C           in  the  calling  (sub)  program.   LDC  must  be  at  least
C           max( 1, n ).
C           Unchanged on exit.
C
C
C  Level 3 Blas routine.
C
C  -- Written on 8-February-1989.
C     Jack Dongarra, Argonne National Laboratory.
C     Iain Duff, AERE Harwell.
C     Jeremy Du Croz, Numerical Algorithms Group Ltd.
C     Sven Hammarling, Numerical Algorithms Group Ltd.
C
C

F06ZTF
      SUBROUTINE F06ZTF(SIDE,UPLO,M,N,ALPHA,A,LDA,B,LDB,BETA,C,LDC)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C  Purpose
C  =======
C
C  ZSYMM  performs one of the matrix-matrix operations
C
C     C := alpha*A*B + beta*C,
C
C  or
C
C     C := alpha*B*A + beta*C,
C
C  where  alpha and beta are scalars, A is a symmetric matrix and  B and
C  C are m by n matrices.
C
C  Parameters
C  ==========
C
C  SIDE   - CHARACTER*1.
C           On entry,  SIDE  specifies whether  the  symmetric matrix  A
C           appears on the  left or right  in the  operation as follows:
C
C              SIDE = 'L' or 'l'   C := alpha*A*B + beta*C,
C
C              SIDE = 'R' or 'r'   C := alpha*B*A + beta*C,
C
C           Unchanged on exit.
C
C  UPLO   - CHARACTER*1.
C           On  entry,   UPLO  specifies  whether  the  upper  or  lower
C           triangular  part  of  the  symmetric  matrix   A  is  to  be
C           referenced as follows:
C
C              UPLO = 'U' or 'u'   Only the upper triangular part of the
C                                  symmetric matrix is to be referenced.
C
C              UPLO = 'L' or 'l'   Only the lower triangular part of the
C                                  symmetric matrix is to be referenced.
C
C           Unchanged on exit.
C
C  M      - INTEGER.
C           On entry,  M  specifies the number of rows of the matrix  C.
C           M  must be at least zero.
C           Unchanged on exit.
C
C  N      - INTEGER.
C           On entry, N specifies the number of columns of the matrix C.
C           N  must be at least zero.
C           Unchanged on exit.
C
C  ALPHA  - COMPLEX         .
C           On entry, ALPHA specifies the scalar alpha.
C           Unchanged on exit.
C
C  A      - COMPLEX          array of DIMENSION ( LDA, ka ), where ka is
C           m  when  SIDE = 'L' or 'l'  and is n  otherwise.
C           Before entry  with  SIDE = 'L' or 'l',  the  m by m  part of
C           the array  A  must contain the  symmetric matrix,  such that
C           when  UPLO = 'U' or 'u', the leading m by m upper triangular
C           part of the array  A  must contain the upper triangular part
C           of the  symmetric matrix and the  strictly  lower triangular
C           part of  A  is not referenced,  and when  UPLO = 'L' or 'l',
C           the leading  m by m  lower triangular part  of the  array  A
C           must  contain  the  lower triangular part  of the  symmetric
C           matrix and the  strictly upper triangular part of  A  is not
C           referenced.
C           Before entry  with  SIDE = 'R' or 'r',  the  n by n  part of
C           the array  A  must contain the  symmetric matrix,  such that
C           when  UPLO = 'U' or 'u', the leading n by n upper triangular
C           part of the array  A  must contain the upper triangular part
C           of the  symmetric matrix and the  strictly  lower triangular
C           part of  A  is not referenced,  and when  UPLO = 'L' or 'l',
C           the leading  n by n  lower triangular part  of the  array  A
C           must  contain  the  lower triangular part  of the  symmetric
C           matrix and the  strictly upper triangular part of  A  is not
C           referenced.
C           Unchanged on exit.
C
C  LDA    - INTEGER.
C           On entry, LDA specifies the first dimension of A as declared
C           in the  calling (sub) program. When  SIDE = 'L' or 'l'  then
C           LDA must be at least  max( 1, m ), otherwise  LDA must be at
C           least max( 1, n ).
C           Unchanged on exit.
C
C  B      - COMPLEX          array of DIMENSION ( LDB, n ).
C           Before entry, the leading  m by n part of the array  B  must
C           contain the matrix B.
C           Unchanged on exit.
C
C  LDB    - INTEGER.
C           On entry, LDB specifies the first dimension of B as declared
C           in  the  calling  (sub)  program.   LDB  must  be  at  least
C           max( 1, m ).
C           Unchanged on exit.
C
C  BETA   - COMPLEX         .
C           On entry,  BETA  specifies the scalar  beta.  When  BETA  is
C           supplied as zero then C need not be set on input.
C           Unchanged on exit.
C
C  C      - COMPLEX          array of DIMENSION ( LDC, n ).
C           Before entry, the leading  m by n  part of the array  C must
C           contain the matrix  C,  except when  beta  is zero, in which
C           case C need not be set on entry.
C           On exit, the array  C  is overwritten by the  m by n updated
C           matrix.
C
C  LDC    - INTEGER.
C           On entry, LDC specifies the first dimension of C as declared
C           in  the  calling  (sub)  program.   LDC  must  be  at  least
C           max( 1, m ).
C           Unchanged on exit.
C
C
C  Level 3 Blas routine.
C
C  -- Written on 8-February-1989.
C     Jack Dongarra, Argonne National Laboratory.
C     Iain Duff, AERE Harwell.
C     Jeremy Du Croz, Numerical Algorithms Group Ltd.
C     Sven Hammarling, Numerical Algorithms Group Ltd.
C
C

F06ZUF
      SUBROUTINE F06ZUF(UPLO,TRANS,N,K,ALPHA,A,LDA,BETA,C,LDC)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C  Purpose
C  =======
C
C  ZSYRK  performs one of the symmetric rank k operations
C
C     C := alpha*A*A' + beta*C,
C
C  or
C
C     C := alpha*A'*A + beta*C,
C
C  where  alpha and beta  are scalars,  C is an  n by n symmetric matrix
C  and  A  is an  n by k  matrix in the first case and a  k by n  matrix
C  in the second case.
C
C  Parameters
C  ==========
C
C  UPLO   - CHARACTER*1.
C           On  entry,   UPLO  specifies  whether  the  upper  or  lower
C           triangular  part  of the  array  C  is to be  referenced  as
C           follows:
C
C              UPLO = 'U' or 'u'   Only the  upper triangular part of  C
C                                  is to be referenced.
C
C              UPLO = 'L' or 'l'   Only the  lower triangular part of  C
C                                  is to be referenced.
C
C           Unchanged on exit.
C
C  TRANS  - CHARACTER*1.
C           On entry,  TRANS  specifies the operation to be performed as
C           follows:
C
C              TRANS = 'N' or 'n'   C := alpha*A*A' + beta*C.
C
C              TRANS = 'T' or 't'   C := alpha*A'*A + beta*C.
C
C           Unchanged on exit.
C
C  N      - INTEGER.
C           On entry,  N specifies the order of the matrix C.  N must be
C           at least zero.
C           Unchanged on exit.
C
C  K      - INTEGER.
C           On entry with  TRANS = 'N' or 'n',  K  specifies  the number
C           of  columns   of  the   matrix   A,   and  on   entry   with
C           TRANS = 'T' or 't',  K  specifies  the number of rows of the
C           matrix A.  K must be at least zero.
C           Unchanged on exit.
C
C  ALPHA  - COMPLEX         .
C           On entry, ALPHA specifies the scalar alpha.
C           Unchanged on exit.
C
C  A      - COMPLEX          array of DIMENSION ( LDA, ka ), where ka is
C           k  when  TRANS = 'N' or 'n',  and is  n  otherwise.
C           Before entry with  TRANS = 'N' or 'n',  the  leading  n by k
C           part of the array  A  must contain the matrix  A,  otherwise
C           the leading  k by n  part of the array  A  must contain  the
C           matrix A.
C           Unchanged on exit.
C
C  LDA    - INTEGER.
C           On entry, LDA specifies the first dimension of A as declared
C           in  the  calling  (sub)  program.   When  TRANS = 'N' or 'n'
C           then  LDA must be at least  max( 1, n ), otherwise  LDA must
C           be at least  max( 1, k ).
C           Unchanged on exit.
C
C  BETA   - COMPLEX         .
C           On entry, BETA specifies the scalar beta.
C           Unchanged on exit.
C
C  C      - COMPLEX          array of DIMENSION ( LDC, n ).
C           Before entry  with  UPLO = 'U' or 'u',  the leading  n by n
C           upper triangular part of the array C must contain the upper
C           triangular part  of the  symmetric matrix  and the strictly
C           lower triangular part of C is not referenced.  On exit, the
C           upper triangular part of the array  C is overwritten by the
C           upper triangular part of the updated matrix.
C           Before entry  with  UPLO = 'L' or 'l',  the leading  n by n
C           lower triangular part of the array C must contain the lower
C           triangular part  of the  symmetric matrix  and the strictly
C           upper triangular part of C is not referenced.  On exit, the
C           lower triangular part of the array  C is overwritten by the
C           lower triangular part of the updated matrix.
C
C  LDC    - INTEGER.
C           On entry, LDC specifies the first dimension of C as declared
C           in  the  calling  (sub)  program.   LDC  must  be  at  least
C           max( 1, n ).
C           Unchanged on exit.
C
C
C  Level 3 Blas routine.
C
C  -- Written on 8-February-1989.
C     Jack Dongarra, Argonne National Laboratory.
C     Iain Duff, AERE Harwell.
C     Jeremy Du Croz, Numerical Algorithms Group Ltd.
C     Sven Hammarling, Numerical Algorithms Group Ltd.
C
C

F06ZWF
      SUBROUTINE F06ZWF(UPLO,TRANS,N,K,ALPHA,A,LDA,B,LDB,BETA,C,LDC)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C  Purpose
C  =======
C
C  ZSYR2K  performs one of the symmetric rank 2k operations
C
C     C := alpha*A*B' + alpha*B*A' + beta*C,
C
C  or
C
C     C := alpha*A'*B + alpha*B'*A + beta*C,
C
C  where  alpha and beta  are scalars,  C is an  n by n symmetric matrix
C  and  A and B  are  n by k  matrices  in the  first  case  and  k by n
C  matrices in the second case.
C
C  Parameters
C  ==========
C
C  UPLO   - CHARACTER*1.
C           On  entry,   UPLO  specifies  whether  the  upper  or  lower
C           triangular  part  of the  array  C  is to be  referenced  as
C           follows:
C
C              UPLO = 'U' or 'u'   Only the  upper triangular part of  C
C                                  is to be referenced.
C
C              UPLO = 'L' or 'l'   Only the  lower triangular part of  C
C                                  is to be referenced.
C
C           Unchanged on exit.
C
C  TRANS  - CHARACTER*1.
C           On entry,  TRANS  specifies the operation to be performed as
C           follows:
C
C              TRANS = 'N' or 'n'    C := alpha*A*B' + alpha*B*A' +
C                                         beta*C.
C
C              TRANS = 'T' or 't'    C := alpha*A'*B + alpha*B'*A +
C                                         beta*C.
C
C           Unchanged on exit.
C
C  N      - INTEGER.
C           On entry,  N specifies the order of the matrix C.  N must be
C           at least zero.
C           Unchanged on exit.
C
C  K      - INTEGER.
C           On entry with  TRANS = 'N' or 'n',  K  specifies  the number
C           of  columns  of the  matrices  A and B,  and on  entry  with
C           TRANS = 'T' or 't',  K  specifies  the number of rows of the
C           matrices  A and B.  K must be at least zero.
C           Unchanged on exit.
C
C  ALPHA  - COMPLEX         .
C           On entry, ALPHA specifies the scalar alpha.
C           Unchanged on exit.
C
C  A      - COMPLEX          array of DIMENSION ( LDA, ka ), where ka is
C           k  when  TRANS = 'N' or 'n',  and is  n  otherwise.
C           Before entry with  TRANS = 'N' or 'n',  the  leading  n by k
C           part of the array  A  must contain the matrix  A,  otherwise
C           the leading  k by n  part of the array  A  must contain  the
C           matrix A.
C           Unchanged on exit.
C
C  LDA    - INTEGER.
C           On entry, LDA specifies the first dimension of A as declared
C           in  the  calling  (sub)  program.   When  TRANS = 'N' or 'n'
C           then  LDA must be at least  max( 1, n ), otherwise  LDA must
C           be at least  max( 1, k ).
C           Unchanged on exit.
C
C  B      - COMPLEX          array of DIMENSION ( LDB, kb ), where kb is
C           k  when  TRANS = 'N' or 'n',  and is  n  otherwise.
C           Before entry with  TRANS = 'N' or 'n',  the  leading  n by k
C           part of the array  B  must contain the matrix  B,  otherwise
C           the leading  k by n  part of the array  B  must contain  the
C           matrix B.
C           Unchanged on exit.
C
C  LDB    - INTEGER.
C           On entry, LDB specifies the first dimension of B as declared
C           in  the  calling  (sub)  program.   When  TRANS = 'N' or 'n'
C           then  LDB must be at least  max( 1, n ), otherwise  LDB must
C           be at least  max( 1, k ).
C           Unchanged on exit.
C
C  BETA   - COMPLEX         .
C           On entry, BETA specifies the scalar beta.
C           Unchanged on exit.
C
C  C      - COMPLEX          array of DIMENSION ( LDC, n ).
C           Before entry  with  UPLO = 'U' or 'u',  the leading  n by n
C           upper triangular part of the array C must contain the upper
C           triangular part  of the  symmetric matrix  and the strictly
C           lower triangular part of C is not referenced.  On exit, the
C           upper triangular part of the array  C is overwritten by the
C           upper triangular part of the updated matrix.
C           Before entry  with  UPLO = 'L' or 'l',  the leading  n by n
C           lower triangular part of the array C must contain the lower
C           triangular part  of the  symmetric matrix  and the strictly
C           upper triangular part of C is not referenced.  On exit, the
C           lower triangular part of the array  C is overwritten by the
C           lower triangular part of the updated matrix.
C
C  LDC    - INTEGER.
C           On entry, LDC specifies the first dimension of C as declared
C           in  the  calling  (sub)  program.   LDC  must  be  at  least
C           max( 1, n ).
C           Unchanged on exit.
C
C
C  Level 3 Blas routine.
C
C  -- Written on 8-February-1989.
C     Jack Dongarra, Argonne National Laboratory.
C     Iain Duff, AERE Harwell.
C     Jeremy Du Croz, Numerical Algorithms Group Ltd.
C     Sven Hammarling, Numerical Algorithms Group Ltd.
C
C

F07ADF
      SUBROUTINE F07ADF(M,N,A,LDA,IPIV,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C     MARK 16 REVISED. IER-1009 (JUN 1993).

F07AEF
      SUBROUTINE F07AEF(TRANS,N,NRHS,A,LDA,IPIV,B,LDB,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C     MARK 16 REVISED. IER-1013 (JUN 1993).

F07AGF
      SUBROUTINE F07AGF(NORM,N,A,LDA,ANORM,RCOND,WORK,IWORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07AHF
      SUBROUTINE F07AHF(TRANS,N,NRHS,A,LDA,AF,LDAF,IPIV,B,LDB,X,LDX,
     *                  FERR,BERR,WORK,IWORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07AJF
      SUBROUTINE F07AJF(N,A,LDA,IPIV,WORK,LWORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07ARF
      SUBROUTINE F07ARF(M,N,A,LDA,IPIV,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C     MARK 16 REVISED. IER-1015 (JUN 1993).
C

F07ASF
      SUBROUTINE F07ASF(TRANS,N,NRHS,A,LDA,IPIV,B,LDB,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C     MARK 16 REVISED. IER-1019 (JUN 1993).

F07AUF
      SUBROUTINE F07AUF(NORM,N,A,LDA,ANORM,RCOND,WORK,RWORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07AVF
      SUBROUTINE F07AVF(TRANS,N,NRHS,A,LDA,AF,LDAF,IPIV,B,LDB,X,LDX,
     *                  FERR,BERR,WORK,RWORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07AWF
      SUBROUTINE F07AWF(N,A,LDA,IPIV,WORK,LWORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07BDF
      SUBROUTINE F07BDF(M,N,KL,KU,AB,LDAB,IPIV,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07BEF
      SUBROUTINE F07BEF(TRANS,N,KL,KU,NRHS,AB,LDAB,IPIV,B,LDB,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07BGF
      SUBROUTINE F07BGF(NORM,N,KL,KU,AB,LDAB,IPIV,ANORM,RCOND,WORK,
     *                  IWORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07BHF
      SUBROUTINE F07BHF(TRANS,N,KL,KU,NRHS,AB,LDAB,AFB,LDAFB,IPIV,B,LDB,
     *                  X,LDX,FERR,BERR,WORK,IWORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07BRF
      SUBROUTINE F07BRF(M,N,KL,KU,AB,LDAB,IPIV,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07BSF
      SUBROUTINE F07BSF(TRANS,N,KL,KU,NRHS,AB,LDAB,IPIV,B,LDB,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07BUF
      SUBROUTINE F07BUF(NORM,N,KL,KU,AB,LDAB,IPIV,ANORM,RCOND,WORK,
     *                  RWORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07BVF
      SUBROUTINE F07BVF(TRANS,N,KL,KU,NRHS,AB,LDAB,AFB,LDAFB,IPIV,B,LDB,
     *                  X,LDX,FERR,BERR,WORK,RWORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07FDF
      SUBROUTINE F07FDF(UPLO,N,A,LDA,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07FEF
      SUBROUTINE F07FEF(UPLO,N,NRHS,A,LDA,B,LDB,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C     MARK 16 REVISED. IER-1021 (JUN 1993).

F07FGF
      SUBROUTINE F07FGF(UPLO,N,A,LDA,ANORM,RCOND,WORK,IWORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07FHF
      SUBROUTINE F07FHF(UPLO,N,NRHS,A,LDA,AF,LDAF,B,LDB,X,LDX,FERR,BERR,
     *                  WORK,IWORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07FJF
      SUBROUTINE F07FJF(UPLO,N,A,LDA,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07FRF
      SUBROUTINE F07FRF(UPLO,N,A,LDA,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07FSF
      SUBROUTINE F07FSF(UPLO,N,NRHS,A,LDA,B,LDB,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C     MARK 16 REVISED. IER-1022 (JUN 1993).

F07FUF
      SUBROUTINE F07FUF(UPLO,N,A,LDA,ANORM,RCOND,WORK,RWORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07FVF
      SUBROUTINE F07FVF(UPLO,N,NRHS,A,LDA,AF,LDAF,B,LDB,X,LDX,FERR,BERR,
     *                  WORK,RWORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07FWF
      SUBROUTINE F07FWF(UPLO,N,A,LDA,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07GDF
      SUBROUTINE F07GDF(UPLO,N,AP,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07GEF
      SUBROUTINE F07GEF(UPLO,N,NRHS,AP,B,LDB,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07GGF
      SUBROUTINE F07GGF(UPLO,N,AP,ANORM,RCOND,WORK,IWORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07GHF
      SUBROUTINE F07GHF(UPLO,N,NRHS,AP,AFP,B,LDB,X,LDX,FERR,BERR,WORK,
     *                  IWORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07GJF
      SUBROUTINE F07GJF(UPLO,N,AP,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07GRF
      SUBROUTINE F07GRF(UPLO,N,AP,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07GSF
      SUBROUTINE F07GSF(UPLO,N,NRHS,AP,B,LDB,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07GUF
      SUBROUTINE F07GUF(UPLO,N,AP,ANORM,RCOND,WORK,RWORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07GVF
      SUBROUTINE F07GVF(UPLO,N,NRHS,AP,AFP,B,LDB,X,LDX,FERR,BERR,WORK,
     *                  RWORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07GWF
      SUBROUTINE F07GWF(UPLO,N,AP,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07HDF
      SUBROUTINE F07HDF(UPLO,N,KD,AB,LDAB,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07HEF
      SUBROUTINE F07HEF(UPLO,N,KD,NRHS,AB,LDAB,B,LDB,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07HGF
      SUBROUTINE F07HGF(UPLO,N,KD,AB,LDAB,ANORM,RCOND,WORK,IWORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07HHF
      SUBROUTINE F07HHF(UPLO,N,KD,NRHS,AB,LDAB,AFB,LDAFB,B,LDB,X,LDX,
     *                  FERR,BERR,WORK,IWORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07HRF
      SUBROUTINE F07HRF(UPLO,N,KD,AB,LDAB,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07HSF
      SUBROUTINE F07HSF(UPLO,N,KD,NRHS,AB,LDAB,B,LDB,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07HUF
      SUBROUTINE F07HUF(UPLO,N,KD,AB,LDAB,ANORM,RCOND,WORK,RWORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07HVF
      SUBROUTINE F07HVF(UPLO,N,KD,NRHS,AB,LDAB,AFB,LDAFB,B,LDB,X,LDX,
     *                  FERR,BERR,WORK,RWORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07MDF
      SUBROUTINE F07MDF(UPLO,N,A,LDA,IPIV,WORK,LWORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07MEF
      SUBROUTINE F07MEF(UPLO,N,NRHS,A,LDA,IPIV,B,LDB,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07MGF
      SUBROUTINE F07MGF(UPLO,N,A,LDA,IPIV,ANORM,RCOND,WORK,IWORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07MHF
      SUBROUTINE F07MHF(UPLO,N,NRHS,A,LDA,AF,LDAF,IPIV,B,LDB,X,LDX,FERR,
     *                  BERR,WORK,IWORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07MJF
      SUBROUTINE F07MJF(UPLO,N,A,LDA,IPIV,WORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07MRF
      SUBROUTINE F07MRF(UPLO,N,A,LDA,IPIV,WORK,LWORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07MSF
      SUBROUTINE F07MSF(UPLO,N,NRHS,A,LDA,IPIV,B,LDB,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07MUF
      SUBROUTINE F07MUF(UPLO,N,A,LDA,IPIV,ANORM,RCOND,WORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07MVF
      SUBROUTINE F07MVF(UPLO,N,NRHS,A,LDA,AF,LDAF,IPIV,B,LDB,X,LDX,FERR,
     *                  BERR,WORK,RWORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07MWF
      SUBROUTINE F07MWF(UPLO,N,A,LDA,IPIV,WORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07NRF
      SUBROUTINE F07NRF(UPLO,N,A,LDA,IPIV,WORK,LWORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07NSF
      SUBROUTINE F07NSF(UPLO,N,NRHS,A,LDA,IPIV,B,LDB,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07NUF
      SUBROUTINE F07NUF(UPLO,N,A,LDA,IPIV,ANORM,RCOND,WORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07NVF
      SUBROUTINE F07NVF(UPLO,N,NRHS,A,LDA,AF,LDAF,IPIV,B,LDB,X,LDX,FERR,
     *                  BERR,WORK,RWORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07NWF
      SUBROUTINE F07NWF(UPLO,N,A,LDA,IPIV,WORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07PDF
      SUBROUTINE F07PDF(UPLO,N,AP,IPIV,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07PEF
      SUBROUTINE F07PEF(UPLO,N,NRHS,AP,IPIV,B,LDB,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07PGF
      SUBROUTINE F07PGF(UPLO,N,AP,IPIV,ANORM,RCOND,WORK,IWORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07PHF
      SUBROUTINE F07PHF(UPLO,N,NRHS,AP,AFP,IPIV,B,LDB,X,LDX,FERR,BERR,
     *                  WORK,IWORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07PJF
      SUBROUTINE F07PJF(UPLO,N,AP,IPIV,WORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07PRF
      SUBROUTINE F07PRF(UPLO,N,AP,IPIV,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07PSF
      SUBROUTINE F07PSF(UPLO,N,NRHS,AP,IPIV,B,LDB,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07PUF
      SUBROUTINE F07PUF(UPLO,N,AP,IPIV,ANORM,RCOND,WORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07PVF
      SUBROUTINE F07PVF(UPLO,N,NRHS,AP,AFP,IPIV,B,LDB,X,LDX,FERR,BERR,
     *                  WORK,RWORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07PWF
      SUBROUTINE F07PWF(UPLO,N,AP,IPIV,WORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07QRF
      SUBROUTINE F07QRF(UPLO,N,AP,IPIV,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07QSF
      SUBROUTINE F07QSF(UPLO,N,NRHS,AP,IPIV,B,LDB,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07QUF
      SUBROUTINE F07QUF(UPLO,N,AP,IPIV,ANORM,RCOND,WORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07QVF
      SUBROUTINE F07QVF(UPLO,N,NRHS,AP,AFP,IPIV,B,LDB,X,LDX,FERR,BERR,
     *                  WORK,RWORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07QWF
      SUBROUTINE F07QWF(UPLO,N,AP,IPIV,WORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07TEF
      SUBROUTINE F07TEF(UPLO,TRANS,DIAG,N,NRHS,A,LDA,B,LDB,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C     MARK 16 REVISED. IER-1023 (JUN 1993).

F07TGF
      SUBROUTINE F07TGF(NORM,UPLO,DIAG,N,A,LDA,RCOND,WORK,IWORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07THF
      SUBROUTINE F07THF(UPLO,TRANS,DIAG,N,NRHS,A,LDA,B,LDB,X,LDX,FERR,
     *                  BERR,WORK,IWORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07TJF
      SUBROUTINE F07TJF(UPLO,DIAG,N,A,LDA,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07TSF
      SUBROUTINE F07TSF(UPLO,TRANS,DIAG,N,NRHS,A,LDA,B,LDB,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C     MARK 16 REVISED. IER-1025 (JUN 1993).

F07TUF
      SUBROUTINE F07TUF(NORM,UPLO,DIAG,N,A,LDA,RCOND,WORK,RWORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07TVF
      SUBROUTINE F07TVF(UPLO,TRANS,DIAG,N,NRHS,A,LDA,B,LDB,X,LDX,FERR,
     *                  BERR,WORK,RWORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07TWF
      SUBROUTINE F07TWF(UPLO,DIAG,N,A,LDA,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07UEF
      SUBROUTINE F07UEF(UPLO,TRANS,DIAG,N,NRHS,AP,B,LDB,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07UGF
      SUBROUTINE F07UGF(NORM,UPLO,DIAG,N,AP,RCOND,WORK,IWORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07UHF
      SUBROUTINE F07UHF(UPLO,TRANS,DIAG,N,NRHS,AP,B,LDB,X,LDX,FERR,BERR,
     *                  WORK,IWORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07UJF
      SUBROUTINE F07UJF(UPLO,DIAG,N,AP,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07USF
      SUBROUTINE F07USF(UPLO,TRANS,DIAG,N,NRHS,AP,B,LDB,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07UUF
      SUBROUTINE F07UUF(NORM,UPLO,DIAG,N,AP,RCOND,WORK,RWORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07UVF
      SUBROUTINE F07UVF(UPLO,TRANS,DIAG,N,NRHS,AP,B,LDB,X,LDX,FERR,BERR,
     *                  WORK,RWORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07UWF
      SUBROUTINE F07UWF(UPLO,DIAG,N,AP,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07VEF
      SUBROUTINE F07VEF(UPLO,TRANS,DIAG,N,KD,NRHS,AB,LDAB,B,LDB,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07VGF
      SUBROUTINE F07VGF(NORM,UPLO,DIAG,N,KD,AB,LDAB,RCOND,WORK,IWORK,
     *                  INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07VHF
      SUBROUTINE F07VHF(UPLO,TRANS,DIAG,N,KD,NRHS,AB,LDAB,B,LDB,X,LDX,
     *                  FERR,BERR,WORK,IWORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07VSF
      SUBROUTINE F07VSF(UPLO,TRANS,DIAG,N,KD,NRHS,AB,LDAB,B,LDB,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07VUF
      SUBROUTINE F07VUF(NORM,UPLO,DIAG,N,KD,AB,LDAB,RCOND,WORK,RWORK,
     *                  INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F07VVF
      SUBROUTINE F07VVF(UPLO,TRANS,DIAG,N,KD,NRHS,AB,LDAB,B,LDB,X,LDX,
     *                  FERR,BERR,WORK,RWORK,INFO)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

F08AEF
      SUBROUTINE F08AEF(M,N,A,LDA,TAU,WORK,LWORK,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08AFF
      SUBROUTINE F08AFF(M,N,K,A,LDA,TAU,WORK,LWORK,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08AGF
      SUBROUTINE F08AGF(SIDE,TRANS,M,N,K,A,LDA,TAU,C,LDC,WORK,LWORK,
     *                  INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08AHF
      SUBROUTINE F08AHF(M,N,A,LDA,TAU,WORK,LWORK,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08AJF
      SUBROUTINE F08AJF(M,N,K,A,LDA,TAU,WORK,LWORK,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08AKF
      SUBROUTINE F08AKF(SIDE,TRANS,M,N,K,A,LDA,TAU,C,LDC,WORK,LWORK,
     *                  INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08ASF
      SUBROUTINE F08ASF(M,N,A,LDA,TAU,WORK,LWORK,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08ATF
      SUBROUTINE F08ATF(M,N,K,A,LDA,TAU,WORK,LWORK,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08AUF
      SUBROUTINE F08AUF(SIDE,TRANS,M,N,K,A,LDA,TAU,C,LDC,WORK,LWORK,
     *                  INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08AVF
      SUBROUTINE F08AVF(M,N,A,LDA,TAU,WORK,LWORK,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08AWF
      SUBROUTINE F08AWF(M,N,K,A,LDA,TAU,WORK,LWORK,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08AXF
      SUBROUTINE F08AXF(SIDE,TRANS,M,N,K,A,LDA,TAU,C,LDC,WORK,LWORK,
     *                  INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08BEF
      SUBROUTINE F08BEF(M,N,A,LDA,JPVT,TAU,WORK,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08BSF
      SUBROUTINE F08BSF(M,N,A,LDA,JPVT,TAU,WORK,RWORK,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08FEF
      SUBROUTINE F08FEF(UPLO,N,A,LDA,D,E,TAU,WORK,LWORK,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08FFF
      SUBROUTINE F08FFF(UPLO,N,A,LDA,TAU,WORK,LWORK,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08FGF
      SUBROUTINE F08FGF(SIDE,UPLO,TRANS,M,N,A,LDA,TAU,C,LDC,WORK,LWORK,
     *                  INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08FSF
      SUBROUTINE F08FSF(UPLO,N,A,LDA,D,E,TAU,WORK,LWORK,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08FTF
      SUBROUTINE F08FTF(UPLO,N,A,LDA,TAU,WORK,LWORK,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08FUF
      SUBROUTINE F08FUF(SIDE,UPLO,TRANS,M,N,A,LDA,TAU,C,LDC,WORK,LWORK,
     *                  INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08GEF
      SUBROUTINE F08GEF(UPLO,N,AP,D,E,TAU,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08GFF
      SUBROUTINE F08GFF(UPLO,N,AP,TAU,Q,LDQ,WORK,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08GGF
      SUBROUTINE F08GGF(SIDE,UPLO,TRANS,M,N,AP,TAU,C,LDC,WORK,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08GSF
      SUBROUTINE F08GSF(UPLO,N,AP,D,E,TAU,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08GTF
      SUBROUTINE F08GTF(UPLO,N,AP,TAU,Q,LDQ,WORK,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08GUF
      SUBROUTINE F08GUF(SIDE,UPLO,TRANS,M,N,AP,TAU,C,LDC,WORK,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08HEF
      SUBROUTINE F08HEF(VECT,UPLO,N,KD,AB,LDAB,D,E,Q,LDQ,WORK,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08HSF
      SUBROUTINE F08HSF(VECT,UPLO,N,KD,AB,LDAB,D,E,Q,LDQ,WORK,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08JEF
      SUBROUTINE F08JEF(COMPZ,N,D,E,Z,LDZ,WORK,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08JFF
      SUBROUTINE F08JFF(N,D,E,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08JGF
      SUBROUTINE F08JGF(COMPZ,N,D,E,Z,LDZ,WORK,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08JJF
      SUBROUTINE F08JJF(RANGE,ORDER,N,VL,VU,IL,IU,ABSTOL,D,E,M,NSPLIT,W,
     *                  IBLOCK,ISPLIT,WORK,IWORK,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08JKF
      SUBROUTINE F08JKF(N,D,E,M,W,IBLOCK,ISPLIT,Z,LDZ,WORK,IWORK,IFAIL,
     *                  INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08JSF
      SUBROUTINE F08JSF(COMPZ,N,D,E,Z,LDZ,WORK,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08JUF
      SUBROUTINE F08JUF(COMPZ,N,D,E,Z,LDZ,WORK,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08JXF
      SUBROUTINE F08JXF(N,D,E,M,W,IBLOCK,ISPLIT,Z,LDZ,WORK,IWORK,IFAIL,
     *                  INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08KEF
      SUBROUTINE F08KEF(M,N,A,LDA,D,E,TAUQ,TAUP,WORK,LWORK,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08KFF
      SUBROUTINE F08KFF(VECT,M,N,K,A,LDA,TAU,WORK,LWORK,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08KGF
      SUBROUTINE F08KGF(VECT,SIDE,TRANS,M,N,K,A,LDA,TAU,C,LDC,WORK,
     *                  LWORK,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08KSF
      SUBROUTINE F08KSF(M,N,A,LDA,D,E,TAUQ,TAUP,WORK,LWORK,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08KTF
      SUBROUTINE F08KTF(VECT,M,N,K,A,LDA,TAU,WORK,LWORK,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08KUF
      SUBROUTINE F08KUF(VECT,SIDE,TRANS,M,N,K,A,LDA,TAU,C,LDC,WORK,
     *                  LWORK,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08MEF
      SUBROUTINE F08MEF(UPLO,N,NCVT,NRU,NCC,D,E,VT,LDVT,U,LDU,C,LDC,
     *                  WORK,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08MSF
      SUBROUTINE F08MSF(UPLO,N,NCVT,NRU,NCC,D,E,VT,LDVT,U,LDU,C,LDC,
     *                  WORK,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08NEF
      SUBROUTINE F08NEF(N,ILO,IHI,A,LDA,TAU,WORK,LWORK,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08NFF
      SUBROUTINE F08NFF(N,ILO,IHI,A,LDA,TAU,WORK,LWORK,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08NGF
      SUBROUTINE F08NGF(SIDE,TRANS,M,N,ILO,IHI,A,LDA,TAU,C,LDC,WORK,
     *                  LWORK,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08NHF
      SUBROUTINE F08NHF(JOB,N,A,LDA,ILO,IHI,SCALE,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08NJF
      SUBROUTINE F08NJF(JOB,SIDE,N,ILO,IHI,SCALE,M,V,LDV,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08NSF
      SUBROUTINE F08NSF(N,ILO,IHI,A,LDA,TAU,WORK,LWORK,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08NTF
      SUBROUTINE F08NTF(N,ILO,IHI,A,LDA,TAU,WORK,LWORK,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08NUF
      SUBROUTINE F08NUF(SIDE,TRANS,M,N,ILO,IHI,A,LDA,TAU,C,LDC,WORK,
     *                  LWORK,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08NVF
      SUBROUTINE F08NVF(JOB,N,A,LDA,ILO,IHI,SCALE,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08NWF
      SUBROUTINE F08NWF(JOB,SIDE,N,ILO,IHI,SCALE,M,V,LDV,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08PEF
      SUBROUTINE F08PEF(JOB,COMPZ,N,ILO,IHI,H,LDH,WR,WI,Z,LDZ,WORK,
     *                  LWORK,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08PKF
      SUBROUTINE F08PKF(JOB,EIGSRC,INITV,SELECT,N,H,LDH,WR,WI,VL,LDVL,
     *                  VR,LDVR,MM,M,WORK,IFAILL,IFAILR,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08PSF
      SUBROUTINE F08PSF(JOB,COMPZ,N,ILO,IHI,H,LDH,W,Z,LDZ,WORK,LWORK,
     *                  INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08PXF
      SUBROUTINE F08PXF(JOB,EIGSRC,INITV,SELECT,N,H,LDH,W,VL,LDVL,VR,
     *                  LDVR,MM,M,WORK,RWORK,IFAILL,IFAILR,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08QFF
      SUBROUTINE F08QFF(COMPQ,N,T,LDT,Q,LDQ,IFST,ILST,WORK,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08QGF
      SUBROUTINE F08QGF(JOB,COMPQ,SELECT,N,T,LDT,Q,LDQ,WR,WI,M,S,SEP,
     *                  WORK,LWORK,IWORK,LIWORK,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08QHF
      SUBROUTINE F08QHF(TRANA,TRANB,ISGN,M,N,A,LDA,B,LDB,C,LDC,SCALE,
     *                  INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08QKF
      SUBROUTINE F08QKF(JOB,HOWMNY,SELECT,N,T,LDT,VL,LDVL,VR,LDVR,MM,M,
     *                  WORK,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08QLF
      SUBROUTINE F08QLF(JOB,HOWMNY,SELECT,N,T,LDT,VL,LDVL,VR,LDVR,S,SEP,
     *                  MM,M,WORK,LDWORK,IWORK,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08QTF
      SUBROUTINE F08QTF(COMPQ,N,T,LDT,Q,LDQ,IFST,ILST,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08QUF
      SUBROUTINE F08QUF(JOB,COMPQ,SELECT,N,T,LDT,Q,LDQ,W,M,S,SEP,WORK,
     *                  LWORK,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08QVF
      SUBROUTINE F08QVF(TRANA,TRANB,ISGN,M,N,A,LDA,B,LDB,C,LDC,SCALE,
     *                  INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08QXF
      SUBROUTINE F08QXF(JOB,HOWMNY,SELECT,N,T,LDT,VL,LDVL,VR,LDVR,MM,M,
     *                  WORK,RWORK,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08QYF
      SUBROUTINE F08QYF(JOB,HOWMNY,SELECT,N,T,LDT,VL,LDVL,VR,LDVR,S,SEP,
     *                  MM,M,WORK,LDWORK,RWORK,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08SEF
      SUBROUTINE F08SEF(ITYPE,UPLO,N,A,LDA,B,LDB,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08SSF
      SUBROUTINE F08SSF(ITYPE,UPLO,N,A,LDA,B,LDB,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08TEF
      SUBROUTINE F08TEF(ITYPE,UPLO,N,AP,BP,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

F08TSF
      SUBROUTINE F08TSF(ITYPE,UPLO,N,AP,BP,INFO)
C     MARK 16 RELEASE. NAG COPYRIGHT 1992.

G01AAF
      SUBROUTINE G01AAF(N,X,IWT,WT,XMEAN,S2,S3,S4,XMIN,XMAX,WSUM,IFAIL)
C     MARK 4 RELEASE NAG COPYRIGHT 1974.
C     MARK 4.5 REVISED
C     MARK 10D REVISED. IER-430 (FEB 1984)
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C
C     G01AAF - THE ROUTINE RETURNS THE MEAN, THE STANDARD
C     DEVIATION, THE COEFFICIENTS OF SKEWNESS AND
C     KURTOSIS, AND THE LARGEST AND SMALLEST VALUES
C     FROM THE VALUES IN THE ARRAY X - OPTIONALLY
C     USING WEIGHTS IN THE ARRAY WT
C
C     USES NAG LIBRARY ROUTINE P01AAF
C

G01ABF
      SUBROUTINE G01ABF(N,X1,X2,IWT,WT,RES,IFAIL)
C     MARK 4 RELEASE NAG COPYRIGHT 1974.
C     MARK 4.5 REVISED
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     G01ABF - THE ROUTINE COMPUTES MEANS, STD DEVNS, MINIMA,
C     MAXIMA, CORRECTED SUMS OF SQUARES AND PRODUCTS,
C     AND THE PRODUCT MOMENT CORRELATION COEFFICIENT
C     FOR TWO VARIABLES IN THE ARRAYS X1 AND X2 -
C     OPTIONALLY USING WEIGHTS IN THE ARRAY WT
C
C     USES NAG LIBRARY ROUTINE P01AAF
C

G01ADF
      SUBROUTINE G01ADF(K,X,IFREQ,XMEAN,S2,S3,S4,N,IFAIL)
C     MARK 4 RELEASE NAG COPYRIGHT 1974.
C     MARK 4.5 REVISED
C     MARK 5C REVISED IER-82
C     MARK 9 REVISED. IER-331 (SEP 1981).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. IER-619 (APR 1988).
C
C     G01ADF - THE ROUTINE COMPUTES MEAN, STD DEVN, AND COEFFTS
C     OF SKEWNESS AND KURTOSIS FOR GROUPED DATA
C
C     USES NAG LIBRARY ROUTINE P01AAF
C

G01AEF
      SUBROUTINE G01AEF(N,K2,X,ICLASS,CINT,IFREQ,XMIN,XMAX,IFAIL)
C     MARK 4 RELEASE NAG COPYRIGHT 1974.
C     MARK 4.5 REVISED IER-49/42
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 12A REVISED. IER-510 (AUG 1986).
C
C     G01AEF - THE ROUTINE CONSTRUCTS A FREQUENCY DISTRIBUTION
C     FOR VALUES IN AN ARRAY X WITH EITHER ROUTINE
C     CALCULATED OR USER SUPPLIED CLASS INTERVALS
C
C     USES NAG LIBRARY ROUTINE P01AAF
C

G01AFF
      SUBROUTINE G01AFF(INOB,IPRED,M,N,NOBS,NUM,PRED,CHIS,P,NPOS,NDF,M1,
     *                  N1,IFAIL)
C     MARK 4 RELEASE NAG COPYRIGHT 1974.
C     MARK 4.5 REVISED LER-14B
C     MARK 6B REVISED  IER-120 (MAR 1978)
C     MARK 8E REVISED. IER-278 (JAN 1981).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     G01AFF - THE ROUTINE PERFORMS AN ANALYSIS OF A TWO-WAY
C     CONTINGENCY TABLE.  YATES CORRECTION FOR 2*2 TABLE
C     OR FISHERS EXACT TEST WHEN TOTAL FREQUENCY LE MINTAB
C
C     USES NAG LIBRARY ROUTINES P01AAF, S14AAF
C

G01AGF
      SUBROUTINE G01AGF(X,Y,NOBS,ISORT,NSTEPX,NSTEPY,IFAIL)
C     MARK 14 RE-ISSUE.  NAG COPYRIGHT 1989.
C     G01AGF PLOTS TWO ARRAYS AGAINST ONE ANOTHER
C     ON A CHARACTER PRINTING DEVICE WITH A CHOSEN NUMBER
C     OF CHARACTER POSITIONS IN EACH DIRECTION

G01AHF
      SUBROUTINE G01AHF(X,NOBS,NSTEPX,NSTEPY,ISTAND,IWORK,WORK,LWORK,
     *                  XSORT,XBAR,XSTD,IFAIL)
C     MARK 14 RE-ISSUE. NAG COPYRIGHT 1989.
C     G01AHF PLOTS AN ARRAY OF RESIDUALS AGAINST THE NORMAL SCORES
C     FOR A SAMPLE OF THE SAME SIZE, ON A CHARACTER PRINTING DEVICE
C     WITH A CHOSEN NUMBER OF CHARACTER POSITIONS IN EACH DIRECTION

G01AJF
      SUBROUTINE G01AJF(X,N,NSTEPX,NSTEPY,ITYPE,ISPACE,XMIN,XMAX,XSTEP,
     *                  N1,MULTY,IFAIL)
C     MARK 10 RELEASE. NAG COPYRIGHT 1982
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     G01AJF PRINTS A HISTOGRAM OF A VECTOR OF REAL DATA,
C     WITH A CHOSEN NUMBER OF CHARACTER POSITIONS IN EACH DIRECTION.
C

G01ALF
      SUBROUTINE G01ALF(N,X,IWRK,RES,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.

G01ARF
      SUBROUTINE G01ARF(RANGE,PRT,N,Y,NSTEPX,NSTEPY,UNIT,PLOT,LDP,LINES,
     *                  SORTY,IWORK,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     Produce a Stem-and-Leaf display of the data in Y()
C
C     IWORK() is an integer work array. SORTY() is a real work array.
C
C     UNIT       is the leaf unit used.  Is converted to a power of ten.
C     NSTEPX     is the maximum width of the plot horizontally
C     NSTEPY     is the maximum number of lines to feature the display.
C     LDP        is the leading dimension of the plotting array.
C     EPSI       is the machine-related epsilon.
C     IMAXIN     is the maximum permitted integer value
C

G01ASF
      SUBROUTINE G01ASF(PRT,M,N,X,LDX,NSTEPX,NSTEPY,PLOT,LDP,WORK,IWORK,
     *                  IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.

G01BJF
      SUBROUTINE G01BJF(N,P,K,PLEK,PGTK,PEQK,IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.
C
C     Returns the lower tail, upper tail and point probabilities
C     associated with a Binomial distribution.
C
C     Let X denote a random variable having a binomial distribution with
C     parameters N and P. The routine computes for given N, P, K:
C
C     PLEK = Prob (X .LE. K)
C     PGTK = Prob (X .GT. K)
C     PEQK = Prob (X .EQ. K)
C
C     Reference: L. Knusel, Computation of the Chi-square and Poisson
C     distribution, SIAM J. Sci. Statist. Comput. 7, pp 1022-1036, 1986.
C

G01BKF
      SUBROUTINE G01BKF(RLAMDA,K,PLEK,PGTK,PEQK,IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.
C
C     Returns the lower tail, upper tail and point probabilities
C     associated with a Poisson distribution.
C
C     Let Z denote a random variable having a Poisson distribution with
C     parameters N and P. The routine computes for given RLAMDA and K:
C
C     PLEK = Prob (Z .LE. K)
C     PGTK = Prob (Z .GT. K)
C     PEQK = Prob (Z .EQ. K)
C
C     Reference: L. Knusel, Computation of the Chi-square and Poisson
C     distribution, SIAM J. Sci. Statist. Comput. 7, pp 1022-1036, 1986.
C

G01BLF
      SUBROUTINE G01BLF(N,L,M,K,PLEK,PGTK,PEQK,IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.
C
C     Returns the lower tail, upper tail and point probabilities
C     associated with a hypergeometric distribution.
C
C     Let X denote a random variable having a hypergeometric
C     distribution with parameters N, L and M. The routine computes for
C     given N, L, M and K:
C
C     PLEK = Prob (X .LE. K)
C     PGTK = Prob (X .GT. K)
C     PEQK = Prob (X .EQ. K)
C
C     Reference: L. Knusel, Computation of the Chisquare and Poisson
C     distribution, SIAM J. Sci. Stat. Comput. 7, pp 1022-1036, 1986.
C

G01DAF
      SUBROUTINE G01DAF(N,PP,ETOL,ERREST,WORK,IW,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     G01DAF COMPUTES A SET OF NORMAL SCORES OF SIZE N
C     PARAMETERS -
C     N         THE NUMBER OF NORMAL SCORES TO BE COMPUTED
C     PP        THE SCORES OBTAINED ARE STORED IN PP(1) TO PP(N)
C     ETOL      AN ATTEMPT IS MADE TO COMPUTE THE SCORES WITH
C     AN ESTIMATED ACCURACY OF ETOL OR BETTER
C     FOR EXAMPLE ETOL MAY BE GIVEN THE VALUE 0.000001
C     ERREST    THE COMPUTED ESTIMATE OF THE MAXIMUM ERROR
C     WORK      WORK ARRAY OF DIMENSION  IW ( AT LEAST 3*N/2 )
C     IW        THE DIMENSION OF WORK
C     IFAIL     GIVEN THE FOLLOWING VALUES
C     0       SUCCESS
C     1       IF N IS LESS THAN  1
C     2       IF ETOL IS LESS THAN OR EQUAL TO ZERO
C     3       IF THE ACCURACY REQUESTED THROUGH ETOL
C     COULD NOT BE OBTAINED, PP AND ERREST
C     REFER TO THE BEST SOLUTION OBTAINED
C     4       IF THE VALUE OF IW IS TOO SMALL

G01DBF
      SUBROUTINE G01DBF(N,PP,IFAIL)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C
C     AS APPL. STATIST. ALGORITHM AS 177.3 (1982), VOL. 31
C
C     COMPUTES AN APPROXIMATION TO THE EXPECTED VALUES OF NORMAL ORDER
C     STATISTICS FOR A SAMPLE OF SIZE N.
C

G01DCF
      SUBROUTINE G01DCF(N,EX1,EX2,SUMM2,VAPVEC,IFAIL)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C     MARK 13 REVISED. IER-639 (APR 1988).
C
C     AS APPL. STATIST. ALGORITHM AS 128 (1978), VOL. 27
C     DAVIS C.S. AND STEPHENS M.A.
C
C     COMPUTES AND NORMALISES THE DAVID-JOHNSON APPROXIMATION
C     FOR THE COVARIANCE MATRIX OF NORMAL ORDER STATISTICS.
C
C     (ANP/AJS)
C

G01DDF
      SUBROUTINE G01DDF(X,N,CALWTS,A,W,PW,IFAIL)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C
C     MODIFICATION OF ALGORITHM AS 181  APPL. STATIST. (1982)
C
C     CALCULATES SHAPIRO AND WILK W STATISTIC AND ITS SIG. LEVEL
C

G01DHF
      SUBROUTINE G01DHF(SCORES,TIES,N,X,R,IWRK,IFAIL)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C
C     The character variables SCORES is used to indicate
C     what type of scores are required
C
C     ... SCORES ...
C     R --- RANKS
C     B --- BLOM VERSION
C     T --- TUKEY VERSION
C     V --- VAN DER WAERDEN
C     N --- NORMAL
C     S --- SAVAGE
C
C     The character variables TIES is used to indicate
C     how ties should be handled
C
C     ... TIES ...
C     A --- AVERAGE
C     L --- LOWEST
C     H --- HIGHEST
C     R --- RANDOM
C     I --- IGNORE
C

G01EAF
      DOUBLE PRECISION FUNCTION G01EAF(TAIL,X,IFAIL)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

G01EBF
      DOUBLE PRECISION FUNCTION G01EBF(TAIL,T,DF,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     G01EBF  --  RETURNS THE PROBABILITY ASSOCIATED WITH EITHER
C     (OR BOTH) TAIL(S) OF THE STUDENTS T-DISTRIBUTION WITH DF DEGREES
C     OF FREEDOM THROUGH THE FUNCTION NAME.
C     IF TAIL = 'U' or 'u' THE UPPER TAIL PROBABILITY IS RETURNED,
C     IF TAIL = 'S' or 's' THE TWO TAIL (SIGNIFICANCE LEVEL)
C                                          PROBABILITY IS RETURNED,
C     IF TAIL = 'C' or 'c' THE TWO TAIL (CONFIDENCE INTERVAL)
C                                          PROBABILITY IS RETURNED,
C     IF TAIL = 'L' or 'l' THE LOWER TAIL PROBABILITY IS RETURNED.
C
C     USES NAG LIBRARY ROUTINES P01AAF, S15ABF, G01EEF
C

G01ECF
      DOUBLE PRECISION FUNCTION G01ECF(TAIL,X,DF,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     Computes the lower tail probability of X for a
C     CHI-squared distribution with DF degrees of freedom.
C

G01EDF
      DOUBLE PRECISION FUNCTION G01EDF(TAIL,F,DF1,DF2,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     Computes the lower/upper tail probability of F for the
C     F-distribution with DF1 and DF2 degrees of freedom.
C

G01EEF
      SUBROUTINE G01EEF(X,A,B,TOL,P,Q,PDF,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C     MARK 16A REVISED. IER-1031 (JUN 1993).
C
C        COMPUTES INCOMPLETE BETA FUNCTIONS P(a,b,x) and Q(a,b,x),
C        and also the PROBABILITY DENSITY FUNCTION.
C
C        BASED ON :-
C        ALGORITHM AS 63  APPL. STATIST. (1973) VOL.22, P.409
C

G01EFF
      DOUBLE PRECISION FUNCTION G01EFF(TAIL,G,A,B,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.

G01EMF
      DOUBLE PRECISION FUNCTION G01EMF(Q,V,IR,IFAIL)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C
C     COMPUTES THE PROBABILITY INTEGRAL FROM 'ZERO' TO 'Q'.
C     OF THE STUDENTIZED RANGE DISTRIBUTION
C

G01EPF
      SUBROUTINE G01EPF(N,IP,D,PDL,PDU,WORK,IFAIL)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C
C     Calculates upper and lower bounds for the significance of a
C     Durbin-Watson statistic.
C

G01ERF
      DOUBLE PRECISION FUNCTION G01ERF(T,VK,IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1993.
C     --------------------------------------------------------
C     G01ERF returns the left tail area of the Von Mises
C     distribution, equal to the incomplete modified Bessel
C     function, of the first kind and zero-th order.
C
C     Parameters :
C
C         T = Angle in radians, treated as deviation from zero
C             (mean) reduced modulo 2PI to the range (-PI,+PI).
C
C        VK = concentration parameter, Kappa, VK.GE.0.0.
C
C     IFAIL = Error parameter
C
C             IFAIL = 1 : On input value of VK was .lt. 0.0.
C
C     --------------------------------------------------------

G01EYF
      DOUBLE PRECISION FUNCTION G01EYF(N,D,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.

G01EZF
      DOUBLE PRECISION FUNCTION G01EZF(N1,N2,D,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.

G01FAF
      DOUBLE PRECISION FUNCTION G01FAF(TAIL,P,IFAIL)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

G01FBF
      DOUBLE PRECISION FUNCTION G01FBF(TAIL,P,DF,IFAIL)
C     MARK 15 RE-ISSUE. NAG COPYRIGHT 1991.
C
C     G01FBF RETURNS THE DEVIATE ASSOCIATED
C     WITH THE LOWER, UPPER OR TWO TAIL PROBABILITY P FROM
C     THE T DISTRIBUTION WITH DF DEGREES OF FREEDOM.
C
C     IF TAIL = 'U' or 'u' THE UPPER TAIL PROB IS RETURNED
C        TAIL = 'S' or 's' THE (SIG. LEVEL) TWO TAIL PROB IS RETURNED
C        TAIL = 'C' or 'c' THE (CONF. INT.) TWO TAIL PROB IS RETURNED
C        TAIL = 'L' or 'l' THE LOWER TAIL PROB IS RETURNED.
C
C     BASED ON CACM ALGORITHM 396,CACM,VOL.13,NO.10,1970
C

G01FCF
      DOUBLE PRECISION FUNCTION G01FCF(P,DF,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     COMPUTES PERCENTAGE POINTS OF THE CHISQUARE DISTRIBUTION.
C     CALLS G01FFF WITH SUITABLE VALUES OF THE PARAMETERS
C

G01FDF
      DOUBLE PRECISION FUNCTION G01FDF(P,DF1,DF2,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C     MARK 15 REVISED. IER-932 (APR 1991).
C
C     Computes the deviate associated with the lower
C     tail probability P, of a F-distribution with DF1 and
C     DF2 degrees of freedom.
C

G01FEF
      DOUBLE PRECISION FUNCTION G01FEF(P,A,B,TOL,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C     MARK 15 REVISED. IER-918 (APR 1991).
C
C     G01FEF RETURNS THE DEVIATE ASSOCIATED
C     WITH THE LOWER TAIL PROBABILITY P FROM
C     THE BETA DISTRIBUTION OF THE FIRST KIND
C     WITH PARAMETERS A AND B.
C
C     BASED ON ALGORITHM AS 109 APPL. STATIST. (1977), VOL.26, NO.1
C

G01FFF
      DOUBLE PRECISION FUNCTION G01FFF(P,A,B,TOL,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C     MARK 15 REVISED. IER-933 (APR 1991).
C
C     Based on:
C     Algorithm as 91 Appl. Statist. (1975) Vol.24, P.385.
C     Computes the deviate associated with the lower tail
C     probability P, of the Gamma distribution with shape
C     parameter A and scale parameter B.
C

G01FMF
      DOUBLE PRECISION FUNCTION G01FMF(P,V,IR,IFAIL)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C
C     COMPUTES THE QUANTILE FOR A GIVEN PROBABIITY.
C

G01GBF
      DOUBLE PRECISION FUNCTION G01GBF(T,DF,DELTA,TOL,MAXIT,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     G01GBF  --  RETURNS THE PROBABILITY ASSOCIATED WITH THE LOWER
C     TAIL OF THE NON-CENTRAL STUDENTS T-DISTRIBUTION
C     WITH DF DEGREES OF FREEDOM THROUGH THE FUNCTION NAME
C

G01GCF
      DOUBLE PRECISION FUNCTION G01GCF(X,DF,RLAMDA,TOL,MAXIT,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C     MARK 16A REVISED. IER-1032 (JUN 1993).
C
C     Computes the lower tail probability of X for the non-central
C     CHI-Squared distribution with degrees of freedom DF.
C

G01GDF
      DOUBLE PRECISION FUNCTION G01GDF(F,DF1,DF2,RLAMDA,TOL,MAXIT,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     Computes the lower tail probability of F for the non-central
C     F distribution with DF1 and DF2 degrees of freedom.
C

G01GEF
      DOUBLE PRECISION FUNCTION G01GEF(X,A,B,RLAMDA,TOL,MAXIT,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     Based on algorithm AS226 APPL. STATIST. (1987) VOL. 36, NO. 2
C
C     Returns the cumulative probability of X for the non - central
C     Beta Distribution with parameters A, B and noncentrality RLAMDA.
C

G01HAF
      DOUBLE PRECISION FUNCTION G01HAF(X,Y,RHO,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C     MARK 15B REVISED. IER-953 (NOV 1991).
C
C     This function computes the bivariate normal probability;
C             PROB(X.LE.x, Y.LE.y)
C     where X and Y are standardised with correlation  RHO.
C     The algorithm given by D. R. Divgi is used with a 15 term series.
C     Ref : Divgi, d.r.,(1979), Calculation of univariate and bivariate
C           normal probability functions. The Annals of Statistics,
C           7,4,903-910
C

G01HBF
      DOUBLE PRECISION FUNCTION G01HBF(TAIL,N,A,B,XMU,SIG,LDSIG,TOL,WK,
     *                                 LWK,IFAIL)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C
C     Computes the multivariate normal probabilities.
C

G01JCF
      SUBROUTINE G01JCF(A,MULT,RLAMDA,N,C,P,PDF,TOL,MAXIT,WRK,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.

G01JDF
      SUBROUTINE G01JDF(METHOD,N,RLAM,D,C,PROB,WORK,IFAIL)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C
C     Calculates the lower tail probability for a linear combination
C     of (central) chi-square variables.
C

G01MBF
      DOUBLE PRECISION FUNCTION G01MBF(X)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C
C     G01MBF returns the reciprocal of Mills ratio
C     i.e. it returns the value of Z(X)/Q(X).
C

G01NAF
      SUBROUTINE G01NAF(MOM,MEAN,N,A,LDA,EMU,SIGMA,LDSIG,L,RKUM,RMOM,WK,
     *                  IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1993.
C
C       Calculates cumulants and moments of a
C       quadratic form in normal variables
C       Based on routine CUM by Jan Magnus and Bahram Pesaran
C

G01NBF
      SUBROUTINE G01NBF(CASE,MEAN,N,A,LDA,B,LDB,C,LDC,ELA,EMU,SIGMA,
     *                  LDSIG,L1,L2,LMAX,RMOM,ABSERR,EPS,WK,IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1993.
C
C       Works out L1-th to L2-th moments relating to
C       ratios of quadratic forms in normal variables.
C       Based on routine QRMOM by Jan Magnus and Bahran Pesaran
C
C       Maximum number of moments set by ISDIM (and ISPAR) is 12.
C

G02BAF
      SUBROUTINE G02BAF(N,M,X,IX,XBAR,STD,SSP,ISSP,R,IR,IFAIL)
C     MARK 4 RELEASE NAG COPYRIGHT 1974.
C     MARK 4.5 REVISED
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     NAG SUBROUTINE G02BAF
C     WRITTEN 16. 7.73 BY PAUL GRIFFITHS (OXFORD UNIVERSITY)
C     (REVAMP OF G02AAF ALLOWING MORE FLEXIBLE ARRAY DIMENSIONS)
C
C     COMPUTES MEANS, STANDARD DEVIATIONS, SUMS OF SQUARES AND
C     CROSS-PRODUCTS OF DEVIATIONS FROM MEANS, AND PEARSON PRODUCT-
C     MOMENT CORRELATION COEFFICIENTS FOR A SET OF DATA IN THE
C     ARRAY X.
C
C     USES NAG ERROR ROUTINE P01AAF
C
C
C     ABOVE DATA STATEMENT MAY BE MACHINE DEPENDENT -- DEPENDS ON
C     NUMBER OF CHARACTERS WHICH CAN BE STORED IN A REAL VARIABLE
C

G02BBF
      SUBROUTINE G02BBF(N,M,X,IX,MISS,XMISS,XBAR,STD,SSP,ISSP,R,IR,
     *                  NCASES,IFAIL)
C     MARK 4 RELEASE NAG COPYRIGHT 1974.
C     MARK 4.5 REVISED
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     NAG SUBROUTINE G02BBF
C     WRITTEN 16. 7.73 BY PAUL GRIFFITHS (OXFORD UNIVERSITY)
C
C     COMPUTES MEANS, STANDARD DEVIATIONS, SUMS OF SQUARES AND
C     CROSS-PRODUCTS OF DEVIATIONS FROM MEANS, AND PEARSON PRODUCT-
C     MOMENT CORRELATION COEFFICIENTS FOR A SET OF DATA IN THE
C     ARRAY X, OMITTING COMPLETELY ANY CASES WITH A MISSING
C     OBSERVATION FOR ANY VARIABLE
C
C     USES NAG ERROR ROUTINE P01AAF
C     NAG LIBRARY ROUTINE    X02BEF
C
C
C     ABOVE DATA STATEMENT MAY BE MACHINE DEPENDENT -- DEPENDS ON
C     NUMBER OF CHARACTERS WHICH MAY BE STORED IN A REAL VARIABLE
C

G02BCF
      SUBROUTINE G02BCF(N,M,X,IX,MISS,XMISS,XBAR,STD,SSP,ISSP,R,IR,
     *                  NCASES,COUNT,IC,IFAIL)
C     MARK 4 RELEASE NAG COPYRIGHT 1974.
C     MARK 4.5 REVISED
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     NAG SUBROUTINE G02BCF
C     WRITTEN 16. 7.73 BY PAUL GRIFFITHS (OXFORD UNIVERSITY)
C
C     COMPUTES MEANS, STANDARD DEVIATIONS, SUMS OF SQUARES AND
C     CROSS-PRODUCTS OF DEVIATIONS FROM MEANS, AND PEARSON PRODUCT-
C     MOMENT CORRELATION COEFFICIENTS FOR A SET OF DATA IN THE
C     ARRAY X, OMITTING CASES WITH MISSING VALUES FROM ONLY THOSE
C     CALCULATIONS INVOLVING THE VARIABLES FOR WHICH THE VALUES
C     ARE MISSING
C
C     USES NAG ERROR ROUTINE P01AAF
C     NAG LIBRARY ROUTINE    X02BEF
C
C
C     ABOVE DATA STATEMENT MAY BE MACHINE DEPENDENT -- DEPENDS ON
C     NUMBER OF CHARACTERS WHICH MAY BE STORED IN A REAL VARIABLE
C

G02BDF
      SUBROUTINE G02BDF(N,M,X,IX,XBAR,STD,SSPZ,ISSPZ,RZ,IRZ,IFAIL)
C     MARK 4 RELEASE NAG COPYRIGHT 1974.
C     MARK 4.5 REVISED
C     MARK 10 REVISED. IER-380 (JUN 1982).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     NAG SUBROUTINE G02BDF
C     WRITTEN 17. 7.73 BY PAUL GRIFFITHS (OXFORD UNIVERSITY)
C
C     COMPUTES MEANS AND STANDARD DEVIATIONS OF VARIABLES SUMS OF
C     SQUARES AND CROSS-PRODUCTS ABOUT ZERO AND CORRELATION-LIKE
C     COEFFICIENTS FOR A SET OF DATA IN THE ARRAY X.
C
C     USES NAG ERROR ROUTINE P01AAF
C
C
C     ABOVE DATA STATEMENT MAY BE MACHINE-DEPENDENT -- DEPENDS ON
C     NUMBER OF CHARACTERS WHICH CAN BE STORED IN A REAL VARIABLE
C

G02BEF
      SUBROUTINE G02BEF(N,M,X,IX,MISS,XMISS,XBAR,STD,SSPZ,ISSPZ,RZ,IRZ,
     *                  NCASES,IFAIL)
C     MARK 4 RELEASE NAG COPYRIGHT 1974.
C     MARK 4.5 REVISED
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     NAG SUBROUTINE G02BEF
C     WRITTEN 17. 7.73 BY PAUL GRIFFITHS (OXFORD UNIVERSITY)
C
C     COMPUTES MEANS AND STANDARD DEVIATIONS OF VARIABLES, SUMS OF
C     SQUARES AND CROSS-PRODUCTS ABOUT ZERO AND CORRELATION-LIKE
C     COEFFICIENTS FOR A SET OF DATA IN THE ARRAY X, OMITTING
C     COMPLETELY ANY CASES WITH A MISSING OBSERVATION FOR ANY
C     VARIABLE
C
C     USES NAG ERROR ROUTINE P01AAF
C     NAG LIBRARY ROUTINE    X02BEF
C
C
C     ABOVE DATA STATEMENT MAY BE MACHINE-DEPENDENT -- DEPENDS ON
C     NUMBER OF CHARACTERS WHICH CAN BE STORED IN A REAL VARIABLE
C

G02BFF
      SUBROUTINE G02BFF(N,M,X,IX,MISS,XMISS,XBAR,STD,SSPZ,ISSPZ,RZ,IRZ,
     *                  NCASES,COUNT,IC,IFAIL)
C     MARK 4 RELEASE NAG COPYRIGHT 1974.
C     MARK 4.5 REVISED
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     NAG SUBROUTINE G02BFF
C     WRITTEN 17. 7.73 BY PAUL GRIFFITHS (OXFORD UNIVERSITY)
C
C     COMPUTES MEANS AND STANDARD DEVIATIONS OF VARIABLES, SUMS OF
C     SQUARES AND CROSS-PRODUCTS ABOUT ZERO AND CORRELATION-LIKE
C     COEFFICIENTS FOR A SET OF DATA IN THE ARRAY X, OMITTING CASES
C     WITH MISSING VALUES FROM ONLY THOSE CALCULATIONS INVOLVING
C     THE VARIABLES FOR WHICH THE VALUES ARE MISSING.
C
C     USES NAG ERROR ROUTINE P01AAF
C     NAG LIBRARY ROUTINE    X02BEF
C
C
C     ABOVE DATA STATEMENT MAY BE MACHINE-DEPENDENT -- DEPENDS ON
C     NUMBER OF CHARACTERS WHICH CAN BE STORED IN A REAL VARIABLE
C

G02BGF
      SUBROUTINE G02BGF(N,M,X,IX,NVARS,KVAR,XBAR,STD,SSP,ISSP,R,IR,
     *                  IFAIL)
C     MARK 4 RELEASE NAG COPYRIGHT 1974.
C     MARK 4.5 REVISED
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     NAG SUBROUTINE G02BGF
C     WRITTEN 17. 7.73 BY PAUL GRIFFITHS (OXFORD UNIVERSITY)
C
C     COMPUTES MEANS, STANDARD DEVIATIONS, SUMS OF SQUARES AND
C     CROSS-PRODUCTS OF DEVIATIONS FROM MEANS, AND PEARSON PRODUCT-
C     MOMENT CORRELATION COEFFICIENTS FOR A SET OF DATA IN
C     SPECIFIED COLUNNS OF THE ARRAY X
C
C     USES NAG ERROR ROUTINE P01AAF
C
C
C     ABOVE DATA STATEMENT MAY BE MACHINE DEPENDENT -- DEPENDS ON
C     NUMBER OF CHARACTERS WHICH MAY BE STORED IN A REAL VARIABLE
C

G02BHF
      SUBROUTINE G02BHF(N,M,X,IX,MISS,XMISS,MISTYP,NVARS,KVAR,XBAR,STD,
     *                  SSP,ISSP,R,IR,NCASES,IFAIL)
C     MARK 4 RELEASE NAG COPYRIGHT 1974.
C     MARK 4.5 REVISED IER-53/46
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     NAG SUBROUTINE G02BHF
C     WRITTEN 17. 8.73 BY PAUL GRIFFITHS (OXFORD UNIVERSITY)
C
C     COMPUTES MEANS, STANDARD DEVIATIONS, SUMS OF SQUARES AND
C     CROSS-PRODUCTS OF DEVIATIONS FROM MEANS, AND PEARSON PRODUCT-
C     MOMENT CORRELATION COEFFICIENTS FOR A SET OF DATA IN
C     SPECIFIED COLUMNS OF THE ARRAY X, OMITTING COMPLETELY ANY
C     CASES WITH A MISSING OBSERVATION FOR ANY VARIABLE (OVER ALL M
C     VARIABLES IF MISTYP=1, OR OVER ONLY THE NVARS VARIABLES IN
C     THE SELECTED SUBSET IF MISTYP=0
C
C     USES NAG ERROR ROUTINE P01AAF
C     NAG LIBRARY ROUTINE    X02BEF
C
C
C     ABOVE DATA STATEMENT MAY BE MACHINE DEPENDENT -- DEPENDS ON
C     NUMBER OF CHARACTERS WHICH MAY BE STORED IN A REAL VARIABLE
C

G02BJF
      SUBROUTINE G02BJF(N,M,X,IX,MISS,XMISS,NVARS,KVAR,XBAR,STD,SSP,
     *                  ISSP,R,IR,NCASES,COUNT,IC,IFAIL)
C     MARK 4 RELEASE NAG COPYRIGHT 1974.
C     MARK 4.5 REVISED
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     NAG SUBROUTINE G02BJF
C     WRITTEN 17. 8.73 BY PAUL GRIFFITHS (OXFORD UNIVERSITY)
C
C     COMPUTES MEANS, STANDARD DEVIATIONS, SUMS OF SQUARES AND
C     CROSS-PRODUCTS OF DEVIATIONS FROM MEANS, AND PEARSON PRODUCT-
C     MOMENT CORRELATION COEFFICIENTS FOR A SET OF DATA IN
C     SPECIFIED COLUMNS OF THE ARRAY X, OMITTING CASES WITH MISSING
C     VALUES FROM ONLY THOSE CALCULATIONS INVOLVING THE VARIABLES
C     FOR WHICH THE VALUES ARE MISSING.
C
C     USES NAG ERROR ROUTINE P01AAF
C     NAG LIBRARY ROUTINE    X02BEF
C
C
C     ABOVE DATA STATEMENT MAY BE MACHINE DEPENDENT -- DEPENDS ON
C     NUMBER OF CHARACTERS WHICH MAY BE STORED IN A REAL VARIABLE
C

G02BKF
      SUBROUTINE G02BKF(N,M,X,IX,NVARS,KVAR,XBAR,STD,SSPZ,ISSPZ,RZ,IRZ,
     *                  IFAIL)
C     MARK 4 RELEASE NAG COPYRIGHT 1974.
C     MARK 4.5 REVISED
C     MARK 10 REVISED. IER-381 (JUN 1982).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     NAG SUBROUTINE G02BKF
C     WRITTEN 17. 8.73 BY PAUL GRIFFITHS (OXFORD UNIVERSITY)
C
C     COMPUTES MEANS AND STANDARD DEVIATIONS OF VARIABLES, SUMS OF
C     SQUARES AND CROSS-PRODUCTS ABOUT ZERO AND CORRELATION-LIKE
C     COEFFICIENTS FOR A SET OF DATA IN SPECIFIED COLUNNS OF THE
C     ARRAY X
C
C     USES NAG ERROR ROUTINE P01AAF
C
C
C     ABOVE DATA STATEMENT MAY BE MACHINE-DEPENDENT -- DEPENDS ON
C     NUMBER OF CHARACTERS WHICH MAY BE STORED IN A REAL VARIABLE
C

G02BLF
      SUBROUTINE G02BLF(N,M,X,IX,MISS,XMISS,MISTYP,NVARS,KVAR,XBAR,STD,
     *                  SSPZ,ISSPZ,RZ,IRZ,NCASES,IFAIL)
C     MARK 4 RELEASE NAG COPYRIGHT 1974.
C     MARK 4.5 REVISED
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     NAG SUBROUTINE G02BLF
C     WRITTEN 17.8.73 BY PAUL GRIFFITHS (OXFORD UNIVERSITY)
C
C     COMPUTES MEANS AND STANDARD DEVIATIONS OF VARIABLES, SUMS OF
C     SQUARES AND CROSS-PRODUCTS ABOUT ZERO AND CORRELATION-LIKE
C     COEFFICIENTS FOR A SET OF DATA IN SPECIFIED COLUMNS OF THE
C     ARRAY X, OMITTING COMPLETELY ANY CASES WITH A MISSING
C     OBSERVATION FOR ANY VARIABLE (OVER ALL M VARIABLES IF
C     MISTYP =1, OR OVER ONLY THE NVARS VARIABLES IN THE SELECTED
C     SUBSET IF MISTYP=0)
C
C     USES NAG ERROR ROUTINE P01AAF
C     NAG LIBRARY ROUTINE    X02BEF
C
C
C     ABOVE DATA STATEMENT MAY BE MACHINE-DEPENDENT -- DEPENDS ON
C     NUMBER OF CHARACTERS WHICH CAN BE STORED IN A REAL VARIABLE
C

G02BMF
      SUBROUTINE G02BMF(N,M,X,IX,MISS,XMISS,NVARS,KVAR,XBAR,STD,SSPZ,
     *                  ISSPZ,RZ,IRZ,NCASES,COUNT,IC,IFAIL)
C     MARK 4 RELEASE NAG COPYRIGHT 1974.
C     MARK 4.5 REVISED
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     NAG SUBROUTINE G02BMF
C     WRITTEN 17. 8. 73 BY PAUL GRIFFITHS (OXFORD UNIVERSITY)
C
C     COMPUTES MEANS AND STANDARD DEVIATIONS OF VARIABLES, SUMS OF
C     SQUARES AND CROSS-PRODUCTS ABOUT ZERO AND CORRELATION-LIKE
C     COEFFICIENTS FOR A SET OF DATA IN SPECIFIED COLUMNS OF THE
C     ARRAY X, OMITTING CASES WITH MISSING VALUES FROM ONLY THOSE
C     CALCULATIONS INVOLVING THE VARIABLES FOR WHICH THE VALUES ARE
C     MISSING
C
C     USES NAG ERROR ROUTINE P01AAF
C     NAG LIBRARY ROUTINE    X02BEF
C
C
C     ABOVE DATA STATEMENT MAY BE MACHINE-DEPENDENT -- DEPENDS ON
C     NUMBER OF CHARACTERS WHICH CAN BE STORED IN A REAL VARIABLE
C

G02BNF
      SUBROUTINE G02BNF(N,M,X,IX,ITYPE,RR,IRR,KWORKA,KWORKB,WORK1,WORK2,
     *                  IFAIL)
C     MARK 4 RELEASE NAG COPYRIGHT 1974.
C     MARK 4.5 REVISED
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     NAG SUBROUTINE G02BNF
C     WRITTEN 27. 7.73 BY PAUL GRIFFITHS (OXFORD UNIVERSITY)
C
C     COMPUTES KENDALL AND/OR SPEARMAN RANK CORRELATION
C     COEFFICIENTS
C     FOR A SET OF DATA IN THE ARRAY X -- THE ARRAY X IS
C     OVERWRITTEN
C     BY THE ROUTINE.
C
C     USES NAG ERROR ROUTINE P01AAF
C     AND AUXILIARY ROUTINES G02BNZ
C     G02BNX
C
C
C     ABOVE DATA STATEMENT MAY BE MACHINE-DEPENDENT -- DEPENDS ON
C     NUMBER OF CHARACTERS WHICH CAN BE STORED IN A REAL VARIABLE
C

G02BPF
      SUBROUTINE G02BPF(N,M,X,IX,MISS,XMISS,ITYPE,RR,IRR,NCASES,INCASE,
     *                  KWORKA,KWORKB,KWORKC,WORK1,WORK2,IFAIL)
C     MARK 4 RELEASE NAG COPYRIGHT 1974.
C     MARK 4.5 REVISED
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     NAG SUBROUTINE G02BPF
C     WRITTEN 30. 7.73 BY PAUL GRIFFITHS (OXFORD UNIVERSITY)
C
C     COMPUTES KENDALL AND/OR SPEARMAN RANK CORRELATION
C     COEFFICIENTS
C     FOR A SET OF DATA IN THE ARRAY X, OMITTING COMPLETELY ANY
C     CASES WITH A MISSING OBSERVATION FOR ANY VARIABLE -- THE
C     ARRAY X IS OVERWRITTEN BY THE ROUTINE
C
C
C     USES NAG ERROR ROUTINE P01AAF
C     NAG LIBRARY ROUTINE    X02BEF
C     AND AUXILIARY ROUTINES G02BNZ
C     G02BNX
C
C
C     ABOVE DATA STATEMENT MAY BE MACHINE-DEPENDENT -- DEPENDS ON
C     NUMBER OF CHARACTERS WHICH CAN BE STORED IN A REAL VARIABLE
C

G02BQF
      SUBROUTINE G02BQF(N,M,X,IX,ITYPE,RR,IRR,KWORKA,KWORKB,WORK1,WORK2,
     *                  IFAIL)
C     MARK 4 RELEASE NAG COPYRIGHT 1974.
C     MARK 4.5 REVISED
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     NAG SUBROUTINE G02BQF
C     WRITTEN 30. 7.73 BY PAUL GRIFFITHS (OXFORD UNIVERSITY)
C
C     COMPUTES KENDALL AND/OR SPEARMAN RANK CORRELATION
C     COEFFICIENTS
C     FOR A SET OF DATA IN THE ARRAY X -- THE ARRAY X IS PRESERVED.
C
C     USES NAG ERROR ROUTINE P01AAF
C     AND AUXILIARY ROUTINES G02BNZ
C     G02BNY
C
C
C     ABOVE DATA STATEMENT MAY BE MACHINE-DEPENDENT -- DEPENDS ON
C     NUMBER OF CHARACTERS WHICH CAN BE STORED IN A REAL VARIABLE
C

G02BRF
      SUBROUTINE G02BRF(N,M,X,IX,MISS,XMISS,ITYPE,RR,IRR,NCASES,INCASE,
     *                  KWORKA,KWORKB,KWORKC,WORK1,WORK2,IFAIL)
C     MARK 4 RELEASE NAG COPYRIGHT 1974.
C     MARK 4.5 REVISED
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     NAG SUBROUTINE G02BRF
C     WRITTEN 15. 8.73 BY PAUL GRIFFITHS (OXFORD UNIVERSITY)
C
C     COMPUTES KENDALL AND/OR SPEARMAN RANK CORRELATION
C     COEFFICIENTS
C     FOR A SET OF DATA IN THE ARRAY X, OMITTING COMPLETELY ANY
C     CASES WITH A MISSING OBSERVATION FOR ANY VARIABLE -- THE
C     ARRAY X IS PRESERVED.
C
C     USES NAG ERROR ROUTINE P01AAF
C     NAG LIBRARY ROUTINE    X02BEF
C     AND AUXILIARY ROUTINES G02BNZ
C     G02BNY
C     G02BRZ
C
C
C     ABOVE DATA STATEMENT MAY BE MACHINE DEPENDENT -- DEPENDS ON
C     NUMBER OF CHARACTERS WHICH CAN BE STORED IN A REAL VARIABLE
C

G02BSF
      SUBROUTINE G02BSF(N,M,X,IX,MISS,XMISS,ITYPE,RR,IRR,NCASES,COUNT,
     *                  IC,KWORKA,KWORKB,KWORKC,KWORKD,WORK1,WORK2,
     *                  IFAIL)
C     MARK 4 RELEASE NAG COPYRIGHT 1974.
C     MARK 4.5 REVISED
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     NAG SUBROUTINE G02BSF
C     WRITTEN 16. 8.73 BY PAUL GRIFFITHS (OXFORD UNIVERSITY)
C
C     COMPUTES KENDALL AND/OR SPEARMAN RANK CORRELATION
C     COEFFICIENTS
C     FOR A SET OF DATA IN THE ARRAY X, OMITTING CASES WITH MISSING
C     VALUES FROM ONLY THOSE CALCULATIONS INVOLVING THE VARIABLES
C     FOR WHICH THE VALUES ARE MISSING--THE ARRAY X IS PRESERVED.
C
C     USES NAG ERROR ROUTINE P01AAF
C     NAG LIBRARY ROUTINE    X02BEF
C     AND AUXILIARY ROUTINES G02BNZ
C     G02BNY
C     G02BRZ
C
C
C     ABOVE DATA STATEMENT MAY BE MACHINE-DEPENDENT -- DEPENDS ON
C     NUMBER OF CHARACTERS WHICH CAN BE STORED IN A REAL VARIABLE
C

G02BTF
      SUBROUTINE G02BTF(MEAN,M,WT,X,INCX,SW,XBAR,C,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     G02BTF RETURNS THE SUM OF MEAN SQUARED DEVIATIONS
C     AND THE SUM OF SQUARES OF A DATA SET.
C     THESE VALUES ARE CALCULATED USING A STABLE UPDATING METHOD
C     WHICH REVISES THE EXISTING VALUES IN A SINGLE PASS.
C
C     BASED ON ALGORITHM AS (WV2) COMM. ACM., (1979), VOL.22, NO.9
C
C     USES NAG LIBRARY ROUTINE P01ABF
C

G02BUF
      SUBROUTINE G02BUF(MEAN,WEIGHT,N,M,X,LDX,WT,SW,WMEAN,C,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     G02BUF CALCULATES :
C                         WEIGHTED SUMS OF SQUARES MATRIX
C                    OR UNWEIGHTED SUMS OF SQUARES MATRIX
C                    OR   WEIGHTED SUMS OF SQUARES ABOUT ZERO MATRIX
C                    OR UNWEIGHTED SUMS OF SQUARES ABOUT ZERO MATRIX
C
C     THESE VALUES ARE CALCULATED USING A STABLE UPDATING METHOD
C     WHICH REVISES THE EXISTING VALUES IN A SINGLE PASS.
C
C     BASED ON ALGORITHM AS (WV2) COMM. ACM., (1979), VOL.22, NO.9
C
C     USES NAG LIBRARY ROUTINE P01ABF
C

G02BWF
      SUBROUTINE G02BWF(M,R,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     CALCULATES CORRELATION MATRIX FROM SUM OF
C     SQUARES AND CROSS-PRODUCTS OF DEVIATIONS
C     STORED IN PACKED FORM UPPER-TRIANGULAR BY COLUMNS
C

G02BXF
      SUBROUTINE G02BXF(WEIGHT,N,M,X,LDX,WT,XBAR,STD,V,LDV,R,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.

G02CAF
      SUBROUTINE G02CAF(N,X,Y,RESULT,IFAIL)
C     MARK 4 RELEASE NAG COPYRIGHT 1974.
C     MARK 4.5 REVISED
C     MARK 5C REVISED
C     MARK 8 REVISED. IER-229 (APR 1980).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C
C     NAG SUBROUTINE G02CAF
C     WRITTEN  6.10.73 BY PAUL GRIFFITHS (OXFORD UNIVERSITY)
C
C     PERFORMS A SIMPLE LINEAR REGRESSION WITH DEPENDENT VARIABLE Y
C     AND INDEPENDENT VARIABLE X.
C
C     USES NAG ERROR ROUTINE P01AAF
C     NAG LIBRARY ROUTINES    X02AKF, X02ALF
C
C
C     ABOVE DATA STATEMENT MAY BE MACHINE-DEPENDENT -- DEPENDS ON
C     NUMBER OF CHARACTERS WHICH CAN BE STORED IN A REAL VARIABLE
C

G02CBF
      SUBROUTINE G02CBF(N,X,Y,RESULT,IFAIL)
C     MARK 4 RELEASE NAG COPYRIGHT 1974.
C     MARK 4.5 REVISED
C     MARK 5C REVISED
C     MARK 8 REVISED. IER-229 (APR 1980).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C
C     NAG SUBROUTINE G02CBF
C     WRITTEN  6.10.73 BY PAUL GRIFFITHS (OXFORD UNIVERSITY)
C
C     PERFORMS A SIMPLE LINEAR REGRESSION WITH NO CONSTANT WITH
C     DEPENDENT VARIABLE Y AND INDEPENDENT VARIABLE X.
C
C     USES NAG ERROR ROUTINE P01AAF
C     NAG LIBRARY ROUTINES    X02AKF, X02ALF
C
C
C     ABOVE DATA STATEMENT MAY BE MACHINE-DEPENDENT -- DEPENDS ON
C     NUMBER OF CHARACTERS WHICH CAN BE STORED IN A REAL VARIABLE
C

G02CCF
      SUBROUTINE G02CCF(N,X,Y,XMISS,YMISS,RESULT,IFAIL)
C     MARK 4 RELEASE NAG COPYRIGHT 1974.
C     MARK 4.5 REVISED
C     MARK 5C REVISED
C     MARK 8 REVISED. IER-229 (APR 1980).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C
C     NAG SUBROUTINE G02CCF
C     WRITTEN  6.10.73 BY PAUL GRIFFITHS (OXFORD UNIVERSITY)
C
C     PERFORMS A SIMPLE LINEAR REGRESSION WITH DEPENDENT VARIABLE Y
C     AND INDEPENDENT VARIABLE X, OMITTING CASES INVOLVING MISSING
C     VALUES.
C
C     USES NAG ERROR ROUTINE P01AAF
C     NAG LIBRARY ROUTINES   X02AKF, X02ALF
C     X02BEF
C
C
C     ABOVE DATA STATEMENT MAY BE MACHINE-DEPENDENT -- DEPENDS ON
C     NUMBER OF CHARACTERS WHICH CAN BE STORED IN A REAL VARIABLE
C

G02CDF
      SUBROUTINE G02CDF(N,X,Y,XMISS,YMISS,RESULT,IFAIL)
C     MARK 4 RELEASE NAG COPYRIGHT 1974.
C     MARK 4.5 REVISED
C     MARK 5C REVISED
C     MARK 8 REVISED. IER-229 (APR 1980).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C
C     NAG SUBROUTINE G02CDF
C     WRITTEN  6.10.73 BY PAUL GRIFFITHS (OXFORD UNIVERSITY)
C
C     PERFORMS A SIMPLE LINEAR REGRESSION WITH NO CONSTANT WITH
C     DEPENDENT VARIABLE Y AND INDEPENDENT VARIABLE X, OMITTING
C     CASES INVOLVING MISSING VALUES.
C
C     USES NAG ERROR ROUTINE P01AAF
C     NAG LIBRARY ROUTINES   X02AKF, X02ALF
C     X02BEF
C
C
C     ABOVE DATA STATEMENT MAY BE MACHINE-DEPENDENT -- DEPENDS ON
C     NUMBER OF CHARACTERS WHICH CAN BE STORED IN A REAL VARIABLE
C

G02CEF
      SUBROUTINE G02CEF(NVARS,XBAR,STD,SSP,ISSP,R,IR,NVARS2,KORDER,
     *                  XBAR2,STD2,SSP2,ISSP2,R2,IR2,IFAIL)
C     MARK 4 RELEASE NAG COPYRIGHT 1974.
C     MARK 4.5 REVISED
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     NAG SUBROUTINE G02CEF
C     WRITTEN  6.10.73 BY PAUL GRIFFITHS (OXFORD UNIVERSITY)
C
C     TAKES SELECTED ELEMENTS FROM TWO VECTORS (TYPICALLY VECTORS
C     OF
C     MEANS AND STANDARD DEVIATIONS) TO FORM TWO SMALLER VECTORS,
C     AND SELECTED ROWS AND COLUMNS FROM TWO MATRICES (TYPICALLY
C     EITHER MATRICES OF SUMS OF SQUARES AND CROSS-PRODUCTS OF
C     DEVIATIONS FROM MEANS AND PEARSON PRODUCT-MOMENT CORRELATION
C     COEFFICIENTS, OR MATRICES OF SUMS OF SQUARES AND
C     CROSS-PRODUCTS
C     ABOUT ZERO AND CORRELATION-LIKE COEFFICIENTS) TO FORM TWO
C     SMALLER MATRICES, ALLOWING RE-ORDERING OF ELEMENTS IN THE
C     PROCESS.
C
C     USES NAG ERROR ROUTINE P01AAF
C
C
C     ABOVE DATA STATEMENT MAY BE MACHINE-DEPENDENT -- DEPENDS ON
C     NUMBER OF CHARACTERS WHICH CAN BE STORED IN A REAL VARIABLE
C

G02CFF
      SUBROUTINE G02CFF(NVARS,KORDER,XBAR,STD,SSP,ISSP,R,IR,KWORK,IFAIL)
C     MARK 4 RELEASE NAG COPYRIGHT 1974.
C     MARK 4.5 REVISED
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     NAG SUBROUTINE G02CFF
C     WRITTEN  6.10.73 BY PAUL GRIFFITHS (OXFORD UNIVERSITY)
C
C     RE-ORDERS THE ELEMENTS IN TWO VECTORS (TYPICALLY VECTORS OF
C     MEANS AND STANDARD DEVIATIONS), AND THE ROWS AND COLUMNS IN
C     TWO MATRICES (TYPICALLY EITHER MATRICES OF SUMS OF SQUARES
C     AND
C     CROSS-PRODUCTS OF DEVIATIONS FROM MEANS AND PEARSON PRODUCT-
C     MOMENT CORRELATION COEFFICIENTS, OR MATRICES OF SUMS OF
C     SQUARES
C     AND CROSS-PRODUCTS ABOUT ZERO AND CORRELATION-LIKE
C     COEFFICIENTS).
C
C     USES NAG ERROR ROUTINE P01AAF
C
C
C     ABOVE DATA STATEMENT MAY BE MACHINE-DEPENDENT -- DEPENDS ON
C     NUMBER OF CHARACTERS WHICH CAN BE STORED IN A REAL VARIABLE
C

G02CGF
      SUBROUTINE G02CGF(NCASES,NVARS,NIND,XBAR,SSP,ISSP,R,IR,RESULT,
     *                  COEFF,ICOEFF,CONST,RINV,IRINV,C,IC,WKZ,IWKZ,
     *                  IFAIL)
C     MARK 4 RELEASE NAG COPYRIGHT 1974.
C     MARK 4.5 REVISED
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     NAG SUBROUTINE G02CGF
C     WRITTEN  7.10.73 BY PAUL GRIFFITHS (OXFORD UNIVERSITY)
C
C     PERFORMS A MULTIPLE LINEAR REGRESSION ON THE SET OF VARIABLES
C     WHOSE MEANS, SUMS OF SQUARES AND CROSS-PRODUCTS OF DEVIATIONS
C     FROM MEANS, AND PEARSON PRODUCT-MOMENT CORRELATION
C     COEFFICIENTS
C     ARE GIVEN, WHEN THE CORRELATION MATRIX R IS
C     POSITIVE-DEFINITE.
C
C     USES NAG ERROR ROUTINE P01AAF
C     NAG LIBRARY ROUTINE    F04ABF
C     AND AUXILIARY ROUTINES G02CGZ
C     G02CGY
C
C
C     ABOVE DATA STATEMENT MAY BE MACHINE-DEPENDENT -- DEPENDS ON
C     NUMBER OF CHARACTERS WHICH CAN BE STORED IN A REAL VARIABLE
C

G02CHF
      SUBROUTINE G02CHF(NCASES,NVARS,NIND,SSPZ,ISSPZ,RZ,IRZ,RESULT,
     *                  COEFF,ICOEFF,RZINV,IRZINV,CZ,ICZ,WKZ,IWKZ,IFAIL)
C     MARK 4 RELEASE NAG COPYRIGHT 1974.
C     MARK 4.5 REVISED
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     NAG SUBROUTINE G02CHF
C     WRITTEN  7.10.73 BY PAUL GRIFFITHS (OXFORD UNIVERSITY)
C
C     PERFORMS A MULTIPLE LINEAR REGRESSION WITH NO CONSTANT ON THE
C     SET OF VARIABLES WHOSE SUMS OF SQUARES AND CROSS-PRODUCTS
C     ABOUT ZERO AND CORRELATION-LIKE COEFFICIENTS ARE GIVEN, WHEN
C     THE CORRELATION-LIKE MATRIX RZ IS POSITIVE-DEFINITE.
C
C     USES NAG ERROR ROUTINE P01AAF
C     NAG LIBRARY ROUTINE    F04ABF
C     AND AUXILIARY ROUTINE  G02CGZ
C
C
C     ABOVE DATA STATEMENT MAY BE MACHINE-DEPENDENT -- DEPENDS ON
C     NUMBER OF CHARACTERS WHICH CAN BE STORED IN A REAL VARIABLE
C

G02DAF
      SUBROUTINE G02DAF(MEAN,WEIGHT,N,X,LDX,M,ISX,IP,Y,WT,RSS,IDF,B,SE,
     *                  COV,RES,H,Q,LDQ,SVD,IRANK,P,TOL,WK,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C     MARK 15B REVISED. IER-954 (NOV 1991).
C     COMPUTES LINEAR REGRESSION
C
C     The non-full rank case is covered.
C     A QR/SVD approach is used.
C
C

G02DCF
      SUBROUTINE G02DCF(UPDATE,MEAN,WEIGHT,M,ISX,Q,LDQ,IP,X,IX,Y,WT,RSS,
     *                  WK,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C     MARK 15 REVISED. IER-919 (APR 1991).
C
C     ADD (UPDATE='A') OR DROPS (UPDATE='D') AN OBSERVATION
C     FROM A LINEAR REGRESSION RETURNING THE UPDATED RSS AND NEW R
C     MATRIX AND Q'Y MATRIX STORED IN Q (SEE G02DAF)
C

G02DDF
      SUBROUTINE G02DDF(N,IP,Q,LDQ,RSS,IDF,B,SE,COV,SVD,IRANK,P,TOL,WK,
     *                  IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     COMPUTES REGRESSION PARAMETERS ETC FROM R MATRIX AND Q'Y VECTOR
C     THESE ARE STORED IN Q
C

G02DEF
      SUBROUTINE G02DEF(WEIGHT,N,IP,Q,LDQ,P,WT,X,RSS,TOL,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     G02DEF adds a new variable to a regression. The R and Q'Y matrices
C     are updated.
C

G02DFF
      SUBROUTINE G02DFF(IP,Q,LDQ,INDX,RSS,WK,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     REMOVES THE INDX TH X VARIABLE FROM THE REGRESSION.
C     ONLY R AND Q'Y ARE UPDATED.
C

G02DGF
      SUBROUTINE G02DGF(WEIGHT,N,WT,RSS,IP,IRANK,COV,Q,LDQ,SVD,P,Y,B,SE,
     *                  RES,WK,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     CALCULATES A REGRESSION FOR NEW Y VARIABLE
C     G02DGF SHOULD BE CALLED AFTER G02DAF
C     NOTE: THE FIRST COLUMN OF Q IS OVERWRITTEN
C

G02DKF
      SUBROUTINE G02DKF(IP,ICONST,P,C,LDC,B,RSS,IDF,SE,COV,WK,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     CALCULATES LEAST SQUARES ESTIMATES FOR GIVEN SET OF LINEAR
C     CONSTRAINTS GIVEN THE SVD SOLUTION FROM G02DAF
C

G02DNF
      SUBROUTINE G02DNF(IP,IRANK,B,COV,P,F,EST,STAT,SESTAT,T,TOL,WK,
     *                  IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     GIVES ESTIMATE AND SE OF ESTIMABLE FUNCTION
C

G02EAF
      SUBROUTINE G02EAF(MEAN,WEIGHT,N,M,X,LDX,NAME,ISX,Y,WT,NMOD,MODEL,
     *                  LDM,RSS,NTERMS,MRANK,WK,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     CALCULATES ALL POSSIBLE REGRESION USING QR METHOD
C

G02ECF
      SUBROUTINE G02ECF(MEAN,N,SIGSQ,TSS,NMOD,NTERMS,RSS,RSQ,CP,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     CALCULATES CP STATISTIC AND R-SQUARED VALUES
C     FROM RESIDUAL SUM OF SQUARES
C

G02EEF
      SUBROUTINE G02EEF(ISTEP,MEAN,WEIGHT,N,M,X,LDX,NAME,ISX,MAXIP,Y,WT,
     *                  FIN,ADDVAR,NEWVAR,CHRSS,F,MODEL,NTERM,RSS,IDF,
     *                  IFR,FREE,EXSS,Q,LDQ,P,WK,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     FITS A REGRESSION MODEL BY FORWARD SELECTION
C

G02FAF
      SUBROUTINE G02FAF(N,IP,NRES,RES,H,RMS,SRES,LDS,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C     MARK 14C REVISED. IER-887 (NOV 1990).
C
C     CALCULATES STANDARDIZED RESIDUALS FROM RESIDUALS
C     AND DIAGONAL OF HAT MATRIX
C
C

G02FCF
      SUBROUTINE G02FCF(N,IP,RES,D,PDL,PDU,WORK,IFAIL)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C

G02GAF
      SUBROUTINE G02GAF(LINK,MEAN,OFFSET,WEIGHT,N,X,LDX,M,ISX,IP,Y,WT,S,
     *                  A,RSS,IDF,B,IRANK,SE,COV,V,LDV,TOL,MAXIT,IPRINT,
     *                  EPS,WK,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     GLM FOR NORMAL DISTN
C
C
C     V(I,1) = ETA, LINEAR PREDICTOR
C     V(I,2) = FV, FITTED VALUES
C     V(I,3) = VAR, ESTIMATED VARIANCE OF Y(I)
C     V(I,4) = WWT, FINAL VALUE OF WORKING WEIGHT
C     V(I,5) = R, STANDARDIZED RESIDUALS (PRIOR Y)
C     V(I,6) = H, LEVERAGE
C     V(I,7) = OFFSET
C     V(I,8+) = R (IF QR USED) P' (IF SVD USED)
C

G02GBF
      SUBROUTINE G02GBF(LINK,MEAN,OFFSET,WEIGHT,N,X,LDX,M,ISX,IP,Y,T,WT,
     *                  DEV,IDF,B,IRANK,SE,COV,V,LDV,TOL,MAXIT,IPRINT,
     *                  EPS,WK,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     GLM FOR BINOMIAL DATA
C
C
C     V(I,1) = ETA, LINEAR PREDICTOR
C     V(I,2) = FV, FITTED VALUES
C     V(I,3) = VAR, ESTIMATED VARIANCE OF Y(I)
C     V(I,4) = WWT, FINAL VALUE OF WORKING WEIGHT
C     V(I,5) = R, STANDARDIZED RESIDUALS
C     V(I,6) = H, LEVERAGE
C     V(I,7) = OFFSET
C     V(I,8+) = R (IF QR USED) P' (IF SVD USED)
C

G02GCF
      SUBROUTINE G02GCF(LINK,MEAN,OFFSET,WEIGHT,N,X,LDX,M,ISX,IP,Y,WT,A,
     *                  DEV,IDF,B,IRANK,SE,COV,V,LDV,TOL,MAXIT,IPRINT,
     *                  EPS,WK,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     GENERALIZED LINEAR MODEL WITH POISSON ERRORS
C
C     V(I,1) = ETA, LINEAR PREDICTOR
C     V(I,2) = FV, FITTED VALUES
C     V(I,3) = VAR, ESTIMATED VARIANCE OF Y(I)
C     V(I,4) = WWT, FINAL VALUE OF WORKING WEIGHT
C     V(I,5) = R, STANDARDIZED RESIDUALS
C     V(I,6) = H, LEVERAGE
C     V(I,7) = OFFSET
C     V(I,8+) = R (IF QR USED) P' (IF SVD USED)
C

G02GDF
      SUBROUTINE G02GDF(LINK,MEAN,OFFSET,WEIGHT,N,X,LDX,M,ISX,IP,Y,WT,S,
     *                  A,DEV,IDF,B,IRANK,SE,COV,V,LDV,TOL,MAXIT,IPRINT,
     *                  EPS,WK,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     V(I,1) = ETA, LINEAR PREDICTOR
C     V(I,2) = FV, FITTED VALUES
C     V(I,3) = VAR, ESTIMATED VARIANCE OF Y(I)
C     V(I,4) = WWT, FINAL VALUE OF WORKING WEIGHT
C     V(I,5) = R, STANDARDIZED RESIDUALS (PRIOR Y)
C     V(I,6) = H, LEVERAGE
C     V(I,7) = OFFSET
C     V(I,8+) = R (IF QR USED) P' (IF SVD USED)
C

G02GKF
      SUBROUTINE G02GKF(IP,ICONST,V,LDV,C,LDC,B,S,SE,COV,WK,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     CALCULATES MAXIMUM LIKELIHOOD ESTIMATES FOR GIVEN SET OF LINEAR
C     CONSTRAINTS GIVEN THE SVD SOLUTION FROM G02DAF
C

G02GNF
      SUBROUTINE G02GNF(IP,IRANK,B,COV,V,LDV,F,EST,STAT,SESTAT,Z,TOL,WK,
     *                  IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     GIVES MAXIMUM LIKELIHOOD ESTIMATE AND SE OF ESTIMABLE FUNCTION
C

G02HAF
      SUBROUTINE G02HAF(INDW,IPSI,ISIGMA,INDC,N,M,X,IX,Y,CPSI,H1,H2,H3,
     *                  CUCV,DCHI,THETA,SIGMA,C,IC,RS,WGT,TOL,MAXIT,
     *                  NITMON,WORK,IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.
C
C     MASTER ROUTINE FOR ROBUST REGRESSION USING ROBETH ROUTINES
C

G02HBF
      SUBROUTINE G02HBF(UCV,N,M,X,IX,A,Z,BL,BD,TOL,MAXIT,NITMON,NIT,WK,
     *                  IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.
C
C     ITERATIVE ALGORITHM FOR THE COMPUTATION OF THE MATRIX A
C     (STANDARDIZED CASE, A LOWER TRIANGULAR)
C     WHERE INV(A'A) IS A ROBUST EXTIMATE OF X'X
C     BASED ON ROUTINES IN ROBETH BY A. MARAZZI
C

G02HDF
      SUBROUTINE G02HDF(CHI,PSI,PSIP0,BETA,INDW,ISIGMA,N,M,X,IX,Y,WGT,
     *                  THETA,K,SIGMA,RS,TOL,EPS,MAXIT,NITMON,NIT,WK,
     *                  IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.
C
C     PURPOSE
C     -------
C     IWLS-ALGORITHM FOR ROBUST AND BOUNDED INFLUENCE LINEAR REGRESSION
C     BASED ON ROUTINES IN ROBETH BY A MARAZZI
C

G02HFF
      SUBROUTINE G02HFF(PSI,PSP,INDW,INDC,SIGMA,N,M,X,IX,RS,WGT,C,IC,WK,
     *                  IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.
C     MARK 16 REVISED. IER-1034 (JUN 1993).
C
C     CALCULATION OF ROBUST ASYMPTOTIC VARIANCE-COVARIANCE MATRIX
C     FOR ROBUST REGRESSION
C     FOR HUBER TYPE REGRESSION C=FACT*INV(X'X)
C     FOR MALLOWS OR SCHWEPPE TYPE REGRESSION
C           C=FACT*INV(S1)*S2*INV(S1)
C     WHERE S1=(1/N)*(X'DX)  AND S2=(1/N)*(X'EX)
C
C     BASED ON ROUTINES FROM ROBETH BY A. MARAZZI
C

G02HKF
      SUBROUTINE G02HKF(N,M,X,LDX,EPS,COV,THETA,MAXIT,NITMON,TOL,NIT,WK,
     *                  IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C     MARK 15A REVISED. IER-921 (APR 1991).
C
C     MASTER ROUTINE FOR ROBUST COVARIANCE
C     BASED ON ROUTINES IN ROBETH BY A. MARAZZI
C

G02HLF
      SUBROUTINE G02HLF(UCV,USERP,INDM,N,M,X,LDX,COV,A,WT,THETA,BL,BD,
     *                  MAXIT,NITMON,TOL,NIT,WK,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C  ITERATIVE ALGORITHM FOR THE COMPUTATION OF THE MATRIX A
C  AND ROBUST ESIMATE OF COVARIANCE
C  HUBER'S (NEWTON-RAPHSON) METHOD
C  BASED ON ROUTINES IN ROBETH BY A. MARAZZI
C
C
C  PARAMETER CHECK AND INITIALIZATION
C

G02HMF
      SUBROUTINE G02HMF(UCV,USERP,INDM,N,M,X,LDX,COV,A,WT,THETA,BL,BD,
     *                  MAXIT,NITMON,TOL,NIT,WK,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     ITERATIVE ALGORITHM FOR THE COMPUTATION OF THE MATRIX A
C     AND ROBUST ESIMATE OF COVARIANCE
C     STAHEL'S  METHOD
C     BASED ON ROUTINES IN ROBETH BY A. MARAZZI
C
C
C     PARAMETER CHECK AND INITIALIZATION
C

G03AAF
      SUBROUTINE G03AAF(MATRIX,STD,WEIGHT,N,M,X,LDX,ISX,S,WT,NVAR,E,LDE,
     *                  P,LDP,V,LDV,WK,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C     MARK 16A REVISED. IER-1035 (JUN 1993).
C
C     PRINCIPAL COMPONENT ANALYSIS
C

G03ACF
      SUBROUTINE G03ACF(WEIGHT,N,M,X,LDX,ISX,NX,ING,NG,WT,NIG,CVM,LDCVM,
     *                  E,LDE,NCV,CVX,LDCVX,TOL,IRANKX,WK,IWK,IFAIL)

G03ADF
      SUBROUTINE G03ADF(WEIGHT,N,M,Z,LDZ,ISZ,NX,NY,WT,E,LDE,NCV,CVX,
     *                  LDCVX,MCV,CVY,LDCVY,TOL,WK,IWK,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.

G03BAF
      SUBROUTINE G03BAF(STAND,G,NVAR,K,FL,LDF,FLR,R,LDR,ACC,MAXIT,ITER,
     *                  WK,IFAIL)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C     MARK 16 REVISED. IER-1036 (JUN 1993).
C
C     Performs orthogonal rotations.
C
C     The NVAR x K matrix in FL is rotated to give matrix in FLR using
C     the rotations in R.
C     If G = 1 varimax rotation is used
C     If G = 0 quartimax rotation is used
C     If STAND = 'S' or 's' the rotations are computed from the
C     row-standardized matrix.
C

G03BCF
      SUBROUTINE G03BCF(STAND,PSCALE,N,M,X,LDX,Y,LDY,YHAT,R,LDR,ALPHA,
     *                  RSS,RES,WK,IFAIL)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C     MARK 16 REVISED. IER-1112 (JUL 1993).
C
C     Computes Procrustes Rotations ( returned in R) for target matrix Y
C     for data in X and fitted values in YHAT
C
C     STAND indicates initial scaling/translation
C           STAND = 'N' no translation or scaling
C           STAND = 'Z' translation to origin
C           STAND = 'C' translation to Y centre
C           STAND = 'U' unit scaling, no translation
C           STAND = 'M' matched scaling and translation to Y
C           STAND = 'S' unit scaling and translation to zero
C
C     PSCALE indicates if post-rotation scaling is required
C            (Unscaled/Scaled)
C
C     ALPHA is the least-squares scaling coefficient
C
C     RSS is the residual sum of squares
C
C     RES is the distance between observed and fitted points
C

G03CAF
      SUBROUTINE G03CAF(MATRIX,WEIGHT,N,M,X,LDX,NVAR,ISX,NFAC,WT,E,STAT,
     *                  COM,PSI,RES,FL,LDFL,IOP,IWK,WK,LWK,IFAIL)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C
C     Computes maximum likelihood estimates of factor loadings
C     The marginal likelihood is maximized using E04LBF
C

G03CCF
      SUBROUTINE G03CCF(METHOD,ROTATE,NVAR,NFAC,FL,LDFL,PSI,E,R,LDR,FS,
     *                  LDFS,WK,IFAIL)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C
C     Computes factor score coefficients in FS from factor
C     unrotated loadings in FL.
C     Either Bartlett's method (METHOD='B') or the Regression
C     method (METHOD='R') is used.
C     Optionally rotations can be supplied in R
C

G03DAF
      SUBROUTINE G03DAF(WEIGHT,N,M,X,LDX,ISX,NVAR,ING,NG,WT,NIG,GMEAN,
     *                  LDG,DET,GC,STAT,DF,SIG,WK,IWK,IFAIL)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C
C     Computes test for equality of within group covariance matrices
C

G03DBF
      SUBROUTINE G03DBF(EQUAL,MODE,NVAR,NG,GMEAN,LDG,GC,NOBS,M,ISX,X,
     *                  LDX,D,LDD,WK,IFAIL)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C
C      computes generalized distance from point X to group centroids
C
C      for use after G03DAF
C

G03DCF
      SUBROUTINE G03DCF(TYPE,EQUAL,PRIORS,NVAR,NG,NIG,GMEAN,LDG,GC,DET,
     *                  NOBS,M,ISX,X,LDX,PRIOR,P,LDP,IAG,ATIQ,ATI,WK,
     *                  IFAIL)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C
C      Allocates observations to groups according to posterior
C      probabilities.
C
C      for use after G03DAF
C

G03EAF
      SUBROUTINE G03EAF(UPDATE,DIST,SCALE,N,M,X,LDX,ISX,S,D,IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1993.
C
C     Computes a distance matrix, D.
C
C     Three distances can be computed
C     DIST = A - absolute distances
C     DIST = E - Euclidean distances
C     DIST = S - Euclidean squared distance
C
C     SCALE indicates the scaling of the variables to be used
C     SCALE = S - standard deviation
C     SCALE = R - range
C     SCALE = G - scaling Given in S
C     SCALE = U - unscaled
C
C     The UPDATE option allows an existing matrix to be updated
C

G03ECF
      SUBROUTINE G03ECF(METHOD,N,D,ILC,IUC,CD,IORD,DORD,IWK,IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1993.
C
C     Performs Hierarchical Cluster Analysis using distance matrix D.
C
C     METHOD indicates which type is performed
C     METHOD = 1 - single link
C     METHOD = 2 - complete link
C     METHOD = 3 - group average
C     METHOD = 4 - centroid
C     METHOD = 5 - median
C     METHOD = 6 - minimum variance
C
C     ILC, IUC and CD give information about the clustering process
C
C     IORD and DORD give information for printing the dendrogram
C

G03EFF
      SUBROUTINE G03EFF(WEIGHT,N,M,X,LDX,ISX,NVAR,K,CMEANS,LDC,WT,INC,
     *                  NIC,CSS,CSW,MAXIT,IWK,WK,IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1993.
C
C     K-Means clustering
C

G03EHF
      SUBROUTINE G03EHF(ORIENT,N,DORD,DMIN,DSTEP,NSYM,C,LENC,IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1993.
C
C     Prints dendogram to character array
C
C     Uses results from G03ECF
C

G03EJF
      SUBROUTINE G03EJF(N,CD,IORD,DORD,K,DLEVEL,IC,IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1993.
C
C     Computes an indicator of group allocation from results of G03ECF
C
C     Either the number of clusters required, K, or the distance at
C     which clusters are to taken, DLEVEL, can be entered.
C

G03ZAF
      SUBROUTINE G03ZAF(N,M,X,LDX,NVAR,ISX,S,E,Z,LDZ,IFAIL)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C
C     Computes standardized values (z-scores) for data matrix X.
C

G04AGF
      SUBROUTINE G04AGF(Y,N,K,LSUB,NOBS,L,NGP,GBAR,SGBAR,GM,SS,IDF,F,FP,
     *                  IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 16 REVISED. IER-1115 (JUL 1993).
C     G04AGF PERFORMS AN ANALYSIS OF VARIANCE FOR A
C     TWO-WAY HIERARCHICAL CLASSIFICATION WITH
C     SUBGROUPS OF POSSIBLY UNEQUAL SIZE , AND ALSO
C     COMPUTES THE TREATMENT GROUP AND
C     SUBGROUP MEANS.
C     CHECK PARAMETERS

G04BBF
      SUBROUTINE G04BBF(N,Y,IBLOCK,NT,IT,GMEAN,BMEAN,TMEAN,TABLE,LDT,C,
     *                  LDC,IREP,R,EF,TOL,IRDF,WK,IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1993.
C
C     Analysis for a block design with one factor.
C     Special cases are:
C                       completely randomised (one-way) design,
C                       randomised complete block,
C

G04CAF
      SUBROUTINE G04CAF(N,Y,NFAC,LFAC,NBLOCK,INTER,IRDF,MTERM,TABLE,
     *                  ITOTAL,TMEAN,MAXT,E,IMEAN,SEMEAN,BMEAN,R,IWK,
     *                  IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1993.
C
C     Computes ANOVA for general complete factorial design, optionally
C     in blocks.
C

G05CAF
      DOUBLE PRECISION FUNCTION G05CAF(X)
C     MARK 14 RE-ISSUE. NAG COPYRIGHT 1989.
C
C     Returns a pseudo-random number uniformly distributed between
C     A and B.
C
C     Pseudo-random numbers are generated by the auxiliary routine
C     G05CAY, 63 at a time, and stored in the array RV in common block
C     CG05CA. G05CAF copies one number from the array RV into X,
C     calling G05CAY to replenish RV when necessary.
C
C     This revised version of G05CAF has been introduced for
C     compatibility with the new routines G05FAF, G05FBF and G05FDF,
C     introduced at Mark 14.
C
C     Jeremy Du Croz, NAG Ltd, June 1989.
C

G05CBF
      SUBROUTINE G05CBF(I)
C     MARK 14 RE-ISSUE. NAG COPYRIGHT 1989.
C
C     initializes the internal variables used by the generator
C     routines to produce a repeatable sequence
C
C     G05CBF initializes the notional internal variable N in G05CAY
C     to 2*ABS(I)+1 and then calls G05CAY to fill the buffer with the
C     next LV pseudo-random numbers.
C
C     G05CBF also re-initializes the varibles NORMAL, GAMMA and VNORML
C     which are used by G05DDF, G05DGF and G05FDF respectively.
C
C     ******************** ADVICE FOR IMPLEMENTORS *********************
C
C     This version of G05CBF must be used in conjunction with the
C     new auxiliary routine G05CAY which has been introduced at Mark 14.
C
C     These notes are intended to guide implementors through the text
C     changes necessary to implement the basic random number generator
C     routines G05CAY, G05CAZ, G05CBF, G05CCF, G05CFZ, G05CGZ. Please
C     follow these guidelines, and consult NAG Central Office if in any
C     doubt or difficulty. Please send a listing of your final text for
C     these routines to Central Office.
C
C     1.  Prepare code for G05CAY following guidelines supplied there.
C
C     2.  Read "DETAILS-NOTE-1" below.
C
C     3.  Activate all lines beginning CAnn, where nn is the value of
C         ILIM used in G05CAY.
C
C     ******************************************************************
C
C     ************************ DETAILS-NOTE-1 **************************
C
C     G05CBF must be implemented consistently with G05CAY.
C
C     If G05CAY has been implemented simply by selecting suitable
C     variant code according to the value of ILIM, then a consistent
C     implementation of G05CBF may be obtained by using the variant
C     code supplied in comments beginning CAnn where the digits nn
C     are the value of ILIM.
C
C     If G05CAY has been implemented in machine code, it will still
C     be possible on many machines to implement G05CBF in Fortran
C     and this will be satisfactory since it is not important for
C     G05CBF to be particularly efficient. Essentially the code for
C     G05CBF depends only on how the internal variable N is stored in
C     the array B in the common block /AG05CA/ and the code given
C     below should be applicable provided that N is stored in
C     accordance with a particular value of ILIM as defined in the
C     text of G05CAY.
C
C     ******************************************************************
C

G05CCF
      SUBROUTINE G05CCF
C     MARK 14 RE-ISSUE. NAG COPYRIGHT 1989.
C     MARK 14B REVISED. IER-833 (MAR 1990).
C
C     initializes the internal variables used by the generator
C     routines to produce a non-repeatable sequence
C
C     G05CCF initializes the notional internal variable N in G05CAY
C     to some unpredictable value and then calls G05CAY to fill the
C     buffer with the next LV pseudo-random numbers.
C
C     G05CCF also re-initializes the varibles NORMAL, GAMMA and VNORML
C     which are used by G05DDF, G05DGF and G05FDF respectively.
C
C     ******************** ADVICE FOR IMPLEMENTORS *********************
C
C     This version of G05CCF must be used in conjunction with the
C     new auxiliary routine G05CAY which has been introduced at Mark 14.
C
C     These notes are intended to guide implementors through the text
C     changes necessary to implement the basic random number generator
C     routines G05CAY, G05CAZ, G05CBF, G05CCF, G05CFZ, G05CGZ. Please
C     follow these guidelines, and consult NAG Central Office if in any
C     doubt or difficulty. Please send a listing of your final text for
C     these routines to Central Office.
C
C     1.  Prepare code for G05CAY following guidelines supplied there.
C
C     2.  Read "DETAILS-NOTE-1" below.
C
C     3.  Activate all lines beginning CAnn, where nn is the value of
C         ILIM used in G05CAY.
C
C     ******************************************************************
C
C     ************************ DETAILS-NOTE-1 **************************
C
C     G05CCF must be implemented consistently with G05CAY.
C
C     If G05CAY has been implemented simply by selecting suitable
C     variant code according to the value of ILIM, then a consistent
C     implementation of G05CCF may be obtained by using the variant
C     code supplied in comments beginning CAnn where the digits nn
C     are the value of ILIM.
C
C     If G05CAY has been implemented in machine code, it will still
C     be possible on many machines to implement G05CCF in Fortran
C     and this will be satisfactory since it is not important for
C     G05CCF to be particularly efficient. Essentially the code for
C     G05CCF depends only on how the internal variable N is stored in
C     the array B in the common block /AG05CA/ and the code given
C     below should be applicable provided that N is stored in
C     accordance with a particular value of ILIM as defined in the
C     text of G05CAY.
C
C     ******************************************************************
C

G05CFF
      SUBROUTINE G05CFF(IA,NI,XA,NX,IFAIL)
C     MARK 14 RE-ISSUE. NAG COPYRIGHT 1989.
C     WRITTEN BY N.M.MACLAREN
C     UNIVERSITY OF CAMBRIDGE COMPUTER LABORATORY
C     THIS SAVES THE GENERATOR STATE IN IA AND XA.
C
C     This revised version of G05CFF has been introduced for
C     compatibility with the new routine G05FDF, introduced at Mark 14.
C     G05CFZ now saves three values in XA(2), XA(3) and XA(4) for use
C     by G05FDF, G05DDF and G05DGF respectively, and XA(1) is used for
C     check-summing.
C
C     Jeremy Du Croz, NAG Ltd, June 1989.
C

G05CGF
      SUBROUTINE G05CGF(IA,NI,XA,NX,IFAIL)
C     MARK 14 RE-ISSUE. NAG COPYRIGHT 1989.
C     WRITTEN BY N.M.MACLAREN
C     UNIVERSITY OF CAMBRIDGE COMPUTER LABORATORY
C     THIS RESTORES THE GENERATOR STATE FROM IA AND XA.
C
C     This revised version of G05CGF has been introduced for
C     compatibility with the new routine G05FDF, introduced at Mark 14.
C     G05CGZ now restores three values from XA(2), XA(3) and XA(4) for
C     use by G05FDF, G05DDF and G05DGF respectively, and XA(1) is used
C     for check-summing.
C
C     Jeremy Du Croz, NAG Ltd, June 1989.
C

G05DAF
      DOUBLE PRECISION FUNCTION G05DAF(A,B)
C     MARK 6 RELEASE  NAG COPYRIGHT 1976
C     MARK 6B REVISED  IER-115 (MAR 1978)
C     MARK 7 REVISED IER-135 (DEC 1978)
C     MARK 7C REVISED IER-188 (MAY 1979)
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     WRITTEN BY N.M.MACLAREN
C     UNIVERSITY OF CAMBRIDGE COMPUTER LABORATORY
C     THIS RETURNS A REAL NUMBER, UNIFORMLY DISTRIBUTED
C     BETWEEN A AND B.
C     THE CONTORTED PROGRAMMING IS TO GIVE CORRECT RESULTS AND TO
C     AVOID DIAGNOSTICS IN CASES WHERE ROUNDING CAUSES OVERFLOW OF
C     THE RANGE (A,B).

G05DBF
      DOUBLE PRECISION FUNCTION G05DBF(A)
C     MARK 6 RELEASE  NAG COPYRIGHT 1976
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     WRITTEN BY N.M.MACLAREN
C     UNIVERSITY OF CAMBRIDGE COMPUTER LABORATORY
C     THIS RETURNS A REAL NUMBER, NEGATIVE EXPONENTIALLY
C     DISTRIBUTED WITH MEAN A.

G05DCF
      DOUBLE PRECISION FUNCTION G05DCF(A,B)
C     MARK 6 RELEASE  NAG COPYRIGHT 1976
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     WRITTEN BY N.M.MACLAREN
C     UNIVERSITY OF CAMBRIDGE COMPUTER LABORATORY
C     THIS RETURNS A REAL NUMBER, LOGISTICALLY DISTRIBUTED WITH
C     MEAN A AND STANDARD DEVIATION B*PI/SQRT(3).

G05DDF
      DOUBLE PRECISION FUNCTION G05DDF(A,B)
C     MARK 6 RELEASE  NAG COPYRIGHT 1976
C     MARK 11 REVISED. IER-441 (FEB 1984).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     WRITTEN BY N.M.MACLAREN
C     UNIVERSITY OF CAMBRIDGE COMPUTER LABORATORY
C     THIS RETURNS A REAL NUMBER, NORMALLY DISTRIBUTED (GAUSSIAN)
C     WITH MEAN A AND STANDARD DEVIATION B.
C     THE METHOD USED IS A MODIFICATION OF CACM ALGORITHM 488
C     (BY R.P.BRENT).
C     THE FOLLOWING CAN BE EXTENDED IF A TRUNCATION PROBABILITY
C     OF 1.0E-12 IS REGARDED AS UNSATISFACTORY.
C     THE CODE ASSUMES THAT THE CONTENTS OF COMMON BLOCK /BG05CA/
C     ARE SAVED BETWEEN CALLS OF THIS ROUTINE AND CALLS OF OTHER
C     G05 ROUTINES THAT REFERENCE IT. A SAVE STATEMENT
C     ENSURES THAT THIS IS SO.

G05DEF
      DOUBLE PRECISION FUNCTION G05DEF(A,B)
C     MARK 6 RELEASE  NAG COPYRIGHT 1976
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     WRITTEN BY N.M.MACLAREN
C     UNIVERSITY OF CAMBRIDGE COMPUTER LABORATORY
C     THIS RETURNS A REAL NUMBER, LOGNORMALLY DISTRIBUTED WITH
C     MEAN EXP(A+B*B/2) AND VARIANCE EXP(2*A+B*B)*(EXP(B*B)-1).

G05DFF
      DOUBLE PRECISION FUNCTION G05DFF(A,B)
C     MARK 6 RELEASE  NAG COPYRIGHT 1976
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     WRITTEN BY N.M.MACLAREN
C     UNIVERSITY OF CAMBRIDGE COMPUTER LABORATORY
C     THIS RETURNS A REAL NUMBER FROM THE CAUCHY DISTRIBUTION WITH
C     MEDIAN A AND SEMI-INTERQUARTILE RANGE B.

G05DHF
      DOUBLE PRECISION FUNCTION G05DHF(N,IFAIL)
C     MARK 6 RELEASE  NAG COPYRIGHT 1976
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 16 REVISED. IER-1128 (JUL 1993).
C     WRITTEN BY N.M.MACLAREN
C     UNIVERSITY OF CAMBRIDGE COMPUTER LABORATORY
C     THIS RETURNS A REAL NUMBER FROM THE CHI-SQUARED DISTRIBUTION
C     WITH N DEGREES OF FREEDOM.

G05DJF
      DOUBLE PRECISION FUNCTION G05DJF(N,IFAIL)
C     MARK 6 RELEASE  NAG COPYRIGHT 1976
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 16 REVISED. IER-1129 (JUL 1993).
C     WRITTEN BY N.M.MACLAREN
C     UNIVERSITY OF CAMBRIDGE COMPUTER LABORATORY
C     THIS RETURNS A REAL NUMBER FROM STUDENTS T DISTRIBUTION
C     WITH N DEGREES OF FREEDOM.

G05DKF
      DOUBLE PRECISION FUNCTION G05DKF(M,N,IFAIL)
C     MARK 6 RELEASE  NAG COPYRIGHT 1976
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 16 REVISED. IER-1130 (JUL 1993).
C     WRITTEN BY N.M.MACLAREN
C     UNIVERSITY OF CAMBRIDGE COMPUTER LABORATORY
C     THIS RETURNS A REAL NUMBER FROM SNEDECORS F DISTRIBUTION
C     WITH M AND N DEGREES OF FREEDOM.

G05DPF
      DOUBLE PRECISION FUNCTION G05DPF(A,B,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     G05DPF RETURNS A PSEUDO-RANDOM NUMBER TAKEN FROM A
C     TWO-PARAMETER WEIBULL DISTRIBUTION WITH SHAPE
C     PARAMETER A AND SCALE PARAMETER B.
C
C     WRITTEN BY N.M.MACLAREN
C     UNIVERSITY OF CAMBRIDGE COMPUTER LABORATORY

G05DRF
      INTEGER FUNCTION G05DRF(ALAMDA,IFAIL)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C
C     G05DRF returns a Poisson variate from a distribution with the
C     supplied parameter. It returns zero if the supplied parameter
C     is negative or greater than MAXINT/2.
C
C
C
C
C
C
C

G05DYF
      INTEGER FUNCTION G05DYF(M,N)
C     MARK 6 RELEASE  NAG COPYRIGHT 1976
C     MARK 7 REVISED IER-135 (DEC 1978)
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     WRITTEN BY N.M.MACLAREN
C     UNIVERSITY OF CAMBRIDGE COMPUTER LABORATORY
C     THIS RETURNS AN INTEGER RESULT, UNIFORMLY DISTRIBUTED
C     BETWEEN M AND N INCLUSIVE.
C     THE CONTORTED PROGRAMMING IS TO GIVE CORRECT RESULTS AND TO
C     AVOID DIAGNOSTICS IN CASES WHERE:
C     1) ROUNDING CAUSES OVERFLOW OF THE RANGE (M,N).
C     2) INTEGER/REAL CONVERSION IS NOT EXACT.
C     3) INT TRUNCATES TOWARDS MINUS INFINITY.

G05DZF
      LOGICAL FUNCTION G05DZF(P)
C     MARK 6 RELEASE  NAG COPYRIGHT 1976
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     WRITTEN BY N.M.MACLAREN
C     UNIVERSITY OF CAMBRIDGE COMPUTER LABORATORY
C     THIS RETURNS A LOGICAL RESULT, TRUE WITH PROBABILITY P.

G05EAF
      SUBROUTINE G05EAF(A,N,C,IC,EPS,R,NR,IFAIL)
C     MARK 10 RELEASE. NAG COPYRIGHT 1982.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C
C     G05EAF CONVERTS A VECTOR OF MEANS AND A COVARIANCE
C     MATRIX INTO A FORM THAT IS EFFICIENT FOR THE GENERATION OF
C     MULTIVARIATE NORMAL VECTORS WITH THE SPECIFIED PARAMETERS.
C
C     THE REFERENCE VECTOR HAS THE FOLLOWING VALUES AT THE
C     FOLLOWING LOCATIONS -
C     1) THE DIMENSION OF THE DISTRIBUTION (N)
C     2) THE MEAN OF THE DISTRIBUTION
C     N+2) THE LOWER TRIANGULAR MATRIX L SUCH THAT L.L(T) IS
C     THE COVARIANCE MATRIX, STORED BY COLUMNS.
C
C     WRITTEN BY N.M.MACLAREN
C     UNIVERSITY OF CAMBRIDGE COMPUTER LABORATORY
C

G05EBF
      SUBROUTINE G05EBF(M,N,R,NR,IFAIL)
C     MARK 6 RELEASE  NAG COPYRIGHT 1976
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     WRITTEN BY N.M.MACLAREN
C     UNIVERSITY OF CAMBRIDGE COMPUTER LABORATORY
C     THIS SETS UP THE REFERENCE VECTOR FOR A UNIFORM DISTRIBUTION.

G05ECF
      SUBROUTINE G05ECF(T,R,NR,IFAIL)
C     MARK 6 RELEASE  NAG COPYRIGHT 1976
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     WRITTEN BY N.M.MACLAREN
C     UNIVERSITY OF CAMBRIDGE COMPUTER LABORATORY
C     THIS SETS UP THE REFERENCE VECTOR FOR A POISSON DISTRIBUTION.
C     ADD AND TIMES CAN BE CHANGED IF A TRUNCATION PROBABILITY OF
C     1.0E-12 IS REGARDED AS UNSATISFACTORY.

G05EDF
      SUBROUTINE G05EDF(N,P,R,NR,IFAIL)
C     MARK 6 RELEASE  NAG COPYRIGHT 1976
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     WRITTEN BY N.M.MACLAREN
C     UNIVERSITY OF CAMBRIDGE COMPUTER LABORATORY
C     THIS SETS UP THE REFERENCE VECTOR FOR A BINOMIAL
C     DISTRIBUTION.
C     ADD AND TIMES CAN BE CHANGED IF A TRUNCATION PROBABILITY OF
C     1.0E-12 IS REGARDED AS UNSATISFACTORY.

G05EEF
      SUBROUTINE G05EEF(N,P,R,NR,IFAIL)
C     MARK 6 RELEASE  NAG COPYRIGHT 1976
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     WRITTEN BY N.M.MACLAREN
C     UNIVERSITY OF CAMBRIDGE COMPUTER LABORATORY
C     THIS SETS UP THE REFERENCE VECTOR FOR A NEGATIVE BINOMIAL
C     DISTRIBUTION.
C     ADD, TIMES AND TIMES2 CAN BE CHANGED IF A TRUNCATION
C     PROBABILITY
C     OF 1.0E-12 IS REGARDED AS UNSATISFACTORY.

G05EFF
      SUBROUTINE G05EFF(L,M,N,R,NR,IFAIL)
C     MARK 6 RELEASE  NAG COPYRIGHT 1976
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     WRITTEN BY N.M.MACLAREN
C     UNIVERSITY OF CAMBRIDGE COMPUTER LABORATORY
C     THIS SETS UP THE REFERENCE VECTOR FOR A HYPERGEOMETRIC
C     DISTRIBUTION.
C     ADD AND TIMES CAN BE CHANGED IF A TRUNCATION PROBABILITY OF
C     1.0E-12 IS REGARDED AS UNSATISFACTORY.

G05EGF
      SUBROUTINE G05EGF(E,A,NA,B,NB,R,NR,VAR,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C     MARK 14 REVISED. IER-747 (DEC 1989).
C
C     G05EGF SETS UP A REFERENCE VECTOR FOR AN AUTOREGRESSIVE
C     MOVING-AVERAGE TIME-SERIES MODEL WITH NORMALLY
C     DISTRIBUTED ERRORS, SO THAT G05EWF MAY BE USED TO
C     GENERATE SUCCESSIVE TERMS. IT ALSO INITIALISES
C     THE  SERIES TO A STATIONARY POSITION.
C
C     THE METHOD IS FROM A PAPER OF G.TUNNICLIFFE WILSON IN THE
C     JOURNAL FOR STATISTICAL COMPUTATION AND SIMULATION (C.1978).
C     THE REFERENCE VECTOR CONTAINS THE FOLLOWING VALUES
C     1) NA, THE AUTOREGRESSIVE ORDER.
C     2) NB, THE MOVING AVERAGE ORDER.
C     3) A POINTER TO THE LAST VALUE OF THE PURE AUTOREGRESSIVE
C        SERIES.
C     4) E, THE MEAN OF THE ERROR TERM.
C     5) A, THE AUTOREGRESSIVE COEFFICIENTS.
C     NA+5) B, THE MOVING-AVERAGE COEFFICIENTS.
C     NA+NB+5) THE LAST MAX(NA,NB) VALUES OF THE PURE AUTOREGRESSIVE
C              SERIES IN A CIRCULAR BUFFER.
C
C     WRITTEN BY N.M.MACLAREN
C     UNIVERSITY OF CAMBRIDGE COMPUTER LABORATORY
C

G05EHF
      SUBROUTINE G05EHF(INDEX,N,IFAIL)
C     MARK 10 RELEASE. NAG COPYRIGHT 1982.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     G05EHF RANDOMLY PERMUTES AN INTEGER VECTOR.
C
C     WRITTEN BY N.M.MACLAREN
C     UNIVERSITY OF CAMBRIDGE COMPUTER LABORATORY
C

G05EJF
      SUBROUTINE G05EJF(IA,N,IZ,M,IFAIL)
C     MARK 10 RELEASE. NAG COPYRIGHT 1982.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     G05EJF TAKES A RANDOM SAMPLE OF SIZE M FROM IA (OF
C     SIZE N) AND PUTS IT INTO IZ.
C
C     WRITTEN BY N.M.MACLAREN
C     UNIVERSITY OF CAMBRIDGE COMPUTER LABORATORY
C

G05EWF
      DOUBLE PRECISION FUNCTION G05EWF(R,NR,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 14 REVISED. IER-748 (DEC 1989).
C
C     G05EWF GENERATES THE NEXT TERM FROM AN AUTOREGRESSIVE
C     MOVING-AVERAGE TIME-SERIES USING A REFERENCE VECTOR
C     SET UP BY G05EGF.
C     WRITTEN BY N.M.MACLAREN
C     UNIVERSITY OF CAMBRIDGE COMPUTER LABORATORY
C

G05EXF
      SUBROUTINE G05EXF(P,NP,IP,LP,R,NR,IFAIL)
C     MARK 6 RELEASE  NAG COPYRIGHT 1976
C     MARK 7 REVISED IER-134 (DEC 1978)
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C     WRITTEN BY N.M.MACLAREN
C     UNIVERSITY OF CAMBRIDGE COMPUTER LABORATORY
C     THIS SETS UP A REFERENCE VECTOR FROM A PDF OR CDF.

G05EYF
      INTEGER FUNCTION G05EYF(R,NR)
C     MARK 6 RELEASE  NAG COPYRIGHT 1976
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     WRITTEN BY N.M.MACLAREN
C     UNIVERSITY OF CAMBRIDGE COMPUTER LABORATORY
C     THIS RETURNS AN INTEGER FROM THE REFERENCE VECTOR IN R.

G05EZF
      SUBROUTINE G05EZF(Z,N,R,NR,IFAIL)
C     MARK 10 RELEASE. NAG COPYRIGHT 1982.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     G05EZF RETURNS A MULTIVARIATE NORMAL VECTOR FROM THE
C     PARAMETERS CONVERTED BY ROUTINE G05EAF.
C
C     WRITTEN BY N.M.MACLAREN
C     UNIVERSITY OF CAMBRIDGE COMPUTER LABORATORY
C

G05FAF
      SUBROUTINE G05FAF(A,B,N,X)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     Returns a vector of N pseudo-random numbers uniformly distributed
C     between A and B.
C
C     Pseudo-random numbers are generated by the auxiliary routine
C     G05CAY, 63 at a time, and stored in the array RV in common block
C     CG05CA. G05FAF copies numbers from the array RV into X,
C     transforming them to the interval (A, B), and calling G05CAY to
C     replenish RV when necessary.
C
C     A call of G05FAF returns the same sequence of pseudo-random
C     numbers as N consecutive calls to G05DAF.
C
C     Jeremy Du Croz, NAG Ltd, June 1989.
C

G05FBF
      SUBROUTINE G05FBF(A,N,X)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     Returns a vector of N pseudo-random numbers from a (negative)
C     exponential distribution with mean A.
C
C     Pseudo-random numbers are generated by the auxiliary routine
C     G05CAY, 63 at a time, and stored in the array RV in common block
C     CG05CA. G05FBF copies numbers from the array RV into X,
C     transforming them to the exponential distribution, and calling
C     G05CAY to replenish RV when necessary.
C
C     A call of G05FBF returns the same sequence of pseudo-random
C     numbers as N consecutive calls to G05DBF.
C
C     Jeremy Du Croz, NAG Ltd, June 1989.
C

G05FDF
      SUBROUTINE G05FDF(A,B,N,X)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C     MARK 16A REVISED. IER-1038 (JUN 1993).
C
C     Returns a vector of N pseudo-random numbers from a normal
C     distribution with mean A and standard deviation B.
C
C     Pseudo-random numbers are generated by the auxiliary routine
C     G05CAY, 63 at a time, and stored in the array RV in common block
C     CG05CA. G05FDF copies numbers from RV to X, using the Box-Muller
C     method to transform to the normal distribution two at a time,
C     and calling G05CAY to replenish RV when necessary.
C
C     A call of G05FDF does *not* return the same sequence of
C     pseudo-random numbers as N consecutive calls to G05DDF,
C     because G05DDF uses a different transformation (Brent's method).
C     G05FDF uses the Box-Muller method because it is more amenable
C     to vectorization.
C
C     Jeremy Du Croz, NAG Ltd, May 1989.
C

G05FEF
      SUBROUTINE G05FEF(A,B,N,X,IFAIL)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C
C     G05FEF generates a vector of pseudo-random Beta deviates with
C     shape parameters A and B.
C     A = alpha
C     B = beta
C     N = number of observations
C     X = the output vector which contains Beta deviates
C

G05FFF
      SUBROUTINE G05FFF(A,B,N,X,IFAIL)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C
C     G05FFF generates a vector of pseudo-random Gamma deviates with
C     shape parameters A and B.
C     A = alpha
C     B = beta
C     N = number of observations
C     X = the output vector which contains Gamma deviates
C

G05FSF
      SUBROUTINE G05FSF(VK,N,T,IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1993.
C
C     Subroutine generates random variates in the range
C     [-Pi,Pi] from a Von Mises distribution with
C     density proportional to exp(VK*COS(VMISES))
C     using best and fisher's method
C
C     VK=Parameter of distribution (0

G05GAF
      SUBROUTINE G05GAF(SIDE,INIT,M,N,A,LDA,WK,IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1993.
C
C     Based on a LAPACK test routine
C
C
C     Purpose
C     =======
C
C     GO5GAF pre- or post-multiplies an M by N matrix A by a random
C     orthogonal matrix U, overwriting A. A may optionally be
C     initialized to the identity matrix before multiplying by U.
C     U is generated using the method of G.W. Stewart
C     ( SIAM J. Numer. Anal. 17, 1980, pp. 403-409 ).
C
C     Arguments
C     =========
C
C     SIDE   - CHARACTER*1
C           SIDE specifies whether A is multiplied on the left or right
C           by U.
C              SIDE = 'L'     Multiply A on the left (premultiply)
C              SIDE = 'R'     Multiply A on the right (postmultiply)
C           Unchanged on exit.
C
C     INIT   - CHARACTER*1
C           INIT specifies whether or not A should be initialized to
C           the identity matrix.
C              INIT = 'I'     Initialize A to (a section of) the
C                             identity matrix before applying U.
C              INIT = 'N'     No initialization.  Apply U to the
C                             input matrix A.
C           Unchanged on exit.
C
C     M      - INTEGER
C           Number of rows of A. Unchanged on exit.
C
C     N      - INTEGER
C           Number of columns of A. Unchanged on exit.
C
C     A      - REAL               array of DIMENSION ( LDA, N )
C           Input array. Overwritten by U*A ( if SIDE = 'L' )
C           or by A*U ( if SIDE = 'R' ) on exit.
C
C     LDA    - INTEGER
C           Leading dimension of A. Must be at least M.
C           Unchanged on exit.
C
C     WK      - REAL               array of DIMENSION (2 * MAX( M, N ) )
C           Workspace. Of length 2*M if SIDE = 'L' and of length 2*N
C           if SIDE = 'R'. Overwritten on exit.
C
C

G05GBF
      SUBROUTINE G05GBF(N,D,C,LDC,EPS,WK,IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1993.
C
C       This algorithm randomly selects a correlation matrix from the
C       class of all correlation matrices with specified eigenvalues
C

G05HDF
      SUBROUTINE G05HDF(MODE,K,IP,IQ,MEAN,PAR,LPAR,QQ,IK,N,W,REF,LREF,
     *                  IWORK,LIWORK,IFAIL)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

G07AAF
      SUBROUTINE G07AAF(N,K,CLEVEL,PL,PU,IFAIL)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C     MARK 15B REVISED. IER-956 (NOV 1991).
C

G07ABF
      SUBROUTINE G07ABF(N,XMEAN,CLEVEL,TL,TU,IFAIL)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C

G07BBF
      SUBROUTINE G07BBF(METHOD,N,X,XC,IC,XMU,XSIG,TOL,MAXIT,SEXMU,
     *                  SEXSIG,CORR,DEV,NOBS,NIT,WK,IFAIL)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C
C     PROGRAM COMPUTES MAXIMUM-LIKELIHOOD ESTIMATES FOR PARAMETERS OF
C     THE NORMAL DISTRIBUTION FROM GROUPED AND/OR CENSORED DATA USING
C     EITHER A NEWTON-RAPHSON OR EXPECTATION-MAXIMIZATION APPROACH.
C

G07BEF
      SUBROUTINE G07BEF(CENS,N,X,IC,BETA,GAMMA,TOL,MAXIT,SEBETA,SEGAM,
     *                  CORR,DEV,NIT,WK,IFAIL)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C
C     PROGRAM FOR ESTIMATING PARAMETERS OF THE WEIBULL DISTRIBUTION.
C

G07CAF
      SUBROUTINE G07CAF(TAIL,EQUAL,NX,NY,XMEAN,YMEAN,XSTD,YSTD,CLEVEL,T,
     *                  DF,PROB,DL,DU,IFAIL)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C
C     This routines performs the two sample t-test for both equal
C     and unequal variances.
C

G07DAF
      SUBROUTINE G07DAF(N,X,Y,XME,XMD,XSD,IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.
C     MARK 14A REVISED. IER-692 (DEC 1989).

G07DBF
      SUBROUTINE G07DBF(ISIGMA,N,X,IPSI,C,H1,H2,H3,DCHI,THETA,SIGMA,
     *                  MAXIT,TOL,RS,NIT,WRK,IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.

G07DCF
      SUBROUTINE G07DCF(CHI,PSI,ISIGMA,N,X,BETA,THETA,SIGMA,MAXIT,TOL,
     *                  RS,NIT,WRK,IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.
C     MARK 13B REVISED. IER-666 (AUG 1988).

G07DDF
      SUBROUTINE G07DDF(N,X,ALPHA,TMEAN,WMEAN,TVAR,WVAR,K,SX,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     Given data X(1), X(2), ..., X(N) in non-decreasing order,
C     this routine finds the alpha-trimmed mean TMEAN, and the
C     estimated variance of TMEAN, TVAR.
C

G07EAF
      SUBROUTINE G07EAF(METHOD,N,X,CLEVEL,THETA,THETAL,THETAU,ESTCL,
     *                  WLOWER,WUPPER,WRK,IWRK,IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1993.
C

G07EBF
      SUBROUTINE G07EBF(METHOD,N,X,M,Y,CLEVEL,THETA,THETAL,THETAU,ESTCL,
     *                  ULOWER,UUPPER,WRK,IWRK,IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1993.
C

G08AAF
      SUBROUTINE G08AAF(X,Y,N,IS,N1,P,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 9 REVISED. IER-333 (SEP 1981).
C     MARK 9A REVISED. IER-352 (NOV 1981)
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 16 REVISED. IER-1123 (JUL 1993).
C     G08AAF PERFORMS THE SIGN TEST ON TWO RELATED SAMPLES OF SIZE N

G08ACF
      SUBROUTINE G08ACF(X,N,N1,W1,I1,I2,P,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 16 REVISED. IER-1116 (JUL 1993).
C     G08ACF PERFORMS THE MEDIAN TEST ON TWO INDEPENDENT
C     SAMPLES OF POSSIBLY UNEQUAL SIZE

G08AEF
      SUBROUTINE G08AEF(X,IX,K,N,W1,W2,FR,P,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 9 REVISED. IER-335 (SEP 1981).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 16 REVISED. IER 1117 (JUL 1993).
C     G08AEF PERFORMS THE FRIEDMAN TWO-WAY ANALYSIS OF VARIANCE
C     BY RANKS ON K RELATED SAMPLES OF SIZE N.

G08AFF
      SUBROUTINE G08AFF(X,LX,L,K,W1,H,P,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 9 REVISED. IER-336 (SEP 1981).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 16 REVISED. IER-1118 (JUL 1993).
C     G08AFF PERFORMS THE KRUSKAL-WALLIS ONE-WAY ANALYSIS OF
C     VARIANCE BY RANKS ON K INDEPENDENT SAMPLES OF
C     POSSIBLY UNEQUAL SIZE

G08AGF
      SUBROUTINE G08AGF(N,X,XME,TAIL,ZEROS,RS,RSNOR,P,NZ1,WRK,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C     MARK 15A REVISED. IER-922 (APR 1991).
C
C     G08AGF performs the one-sample Wilcoxon signed rank test.
C

G08AHF
      SUBROUTINE G08AHF(N1,X,N2,Y,TAIL,U,UNOR,P,TIES,RANKS,WRK,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     G08AHF performs the Mann-Whitney U test on two independent
C     samples of possibly unequal size. The tail probaility is
C     returned via P and corresponds to the TAIL option chosen.
C     P is based on the normal approximation. To calculate the
C     exact probability routine G08AHY or G08AHZ must be used.
C

G08AJF
      SUBROUTINE G08AJF(N1,N2,TAIL,U,P,WRK,LWRK,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     The tail probaility is returned via P and corresponds to
C     the TAIL option chosen. This routine calculates the exact
C     probability routine using G08AJZ for the case of no ties.
C

G08AKF
      SUBROUTINE G08AKF(N1,N2,TAIL,RANKS,U,P,WRK,LWRK,IWRK,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     THIS ROUTINE CALCULATES THE TAIL PROBABILITY P FOR
C     THE WILCOXON-MANN-WHINEY STATISTIC U FOR SAMPLE SIZES
C     N1 AND N2 FOR THE CASE OF TIES IN THE POOLED SAMPLE.
C

G08ALF
      SUBROUTINE G08ALF(N,K,X,LDX,Q,PROB,IFAIL)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C
C     Performs the Cochran Q test.
C

G08BAF
      SUBROUTINE G08BAF(X,N,N1,R,ITEST,W,V,PW,PV,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 10B REVISED. IER-404 (JAN 1983).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     G08DAF PERFORMS MOODS AND DAVIDS TESTS FOR DISPERSION
C     DIFFERENCES BETWEEN TWO INDEPENDENT SAMPLES OF
C     POSSIBLY UNEQUAL SIZE.
C
C     REFERENCE  - B.E.COOPER - STATISTICS FOR EXPERIMENTALISTS
C     AUTHOR     - J. LLOYD-JONES (U.M.R.C.C.)
C
C     PARAMETERS -
C     X     - DATA FOR TWO SAMPLES
C     N     - TOTAL SIZE OF BOTH SAMPLES
C     N1    - SIZE OF FIRST SAMPLE
C     R     - VECTOR OF RANKS
C     ITEST - TEST REQUIRED - SET TO 1 FOR DAVIDS TEST
C                                    2 FOR MOODS TEST
C                                    0 FOR BOTH
C     W     - MOODS MEASURE OF DISPERSION DIFFERENCES
C     V     - DAVIDS MEASURE OF DISPERSION DIFFERENCES
C     PW    - SIGNIFICANCE OF W
C     PV    - SIGNIFICANCE OF V
C
C     CHECK PARAMETERS

G08CBF
      SUBROUTINE G08CBF(N,X,DIST,PAR,ESTIMA,NTYPE,D,Z,P,SX,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.

G08CCF
      SUBROUTINE G08CCF(N,X,CDF,NTYPE,D,Z,P,SX,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     G08CCF performs the Kolmogorov-Smirnov one sample test. The
C     test statistic D is computed and the tail probability is
C     returned via P. This routine requires the user to provide a
C     distribuiton function through CDF.
C

G08CDF
      SUBROUTINE G08CDF(N1,X,N2,Y,NTYPE,D,Z,P,SX,SY,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.

G08CGF
      SUBROUTINE G08CGF(K2,IFREQ,CINT,DIST,PAR,IPARAM,PROB,CHISQ,P,NDF,
     *                  EVAL,CHISQI,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.

G08DAF
      SUBROUTINE G08DAF(X,IX,K,N,RNK,W,P,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 16 REVISED. IER 1119 (JUL 1993).
C
C     G08DAF CALCULATES KENDALLS COEFFICIENT OF CONCORDANCE
C     ON K INDEPENDENT RANKINGS OF N OBJECTS OR INDIVIDUALS.
C
C     REFERENCE - S SIEGEL - NONPARAMETRIC STATISTICS FOR
C                            THE BEHAVIORAL SCIENCES ( P 229 )
C     AUTHOR    - J. LLOYD-JONES (U.M.R.C.C.)
C
C     PARAMETERS -
C     X     - MATRIX OF RANKS
C     IX    - FIRST DIMENSION OF X
C     K     - NUMBER OF COMPARISONS
C     N     - NUMBER OF OBJECTS BEING COMPARED
C     RNK   - RANKED DATA
C     W     - COEFFICIENT OF CONCORDANCE
C     P     - SIGNIFICANCE LEVEL OUTPUT BY G01ECF
C     IFAIL - ERROR PARAMETER
C
C     LOCAL VARIABLES -
C     RMEAN - OVERALL AVERAGE RANK
C     IDF   - DEGREES OF FREEDOM(=N-1) INPUT TO G01ECF
C     CHI   - CHI SQUARE VALUE INPUT TO G01ECF
C
C     CHECK PARAMETERS

G08EAF
      SUBROUTINE G08EAF(CL,N,X,M,MAXR,NRUNS,NCOUNT,EX,C,LDC,CHI,DF,PROB,
     *                  WRK,LWRK,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.

G08EBF
      SUBROUTINE G08EBF(CL,N,X,MSIZE,LAG,NCOUNT,LDC,EX,CHI,DF,P,WRK,
     *                  IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.

G08ECF
      SUBROUTINE G08ECF(CL,N,X,MSIZE,NCOUNT,LDC,EX,CHI,DF,P,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.

G08EDF
      SUBROUTINE G08EDF(CL,N,X,M,K,RL,RU,TIL,NGAPS,NCOUNT,EX,CHI,DF,
     *                  PROB,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C

G08RAF
      SUBROUTINE G08RAF(NS,NV,NSUM,Y,IP,X,NX,IDIST,NMAX,TOL,PARVAR,
     *                  NPVAR,IRANK,ZIN,ETA,VAPVEC,PAREST,WORK,LWORK,
     *                  IWA,IFAIL)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

G08RBF
      SUBROUTINE G08RBF(NS,NV,NSUM,Y,IP,X,NX,ICEN,GAMMA,NMAX,TOL,PARVAR,
     *                  NPVAR,IRANK,ZIN,ETA,VAPVEC,PAREST,WORK,LWORK,
     *                  IWA,IFAIL)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

G10ABF
      SUBROUTINE G10ABF(MODE,WEIGHT,N,X,Y,WT,RHO,YHAT,C,LDC,RSS,DF,RES,
     *                  H,WK,IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1993.
C
C     Fits a cubic smoothing spline
C     Option MODE allows different stages to be performed
C     Note: WK is used to store results between calls.
C

G10ACF
      SUBROUTINE G10ACF(METHOD,WEIGHT,N,X,Y,WT,YHAT,C,LDC,RSS,RDF,RES,H,
     *                  CRIT,RHO,U,TOL,MAXCAL,WK,IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1993.
C
C     H IS USED TO STORE WWT UNTIL G10ABW
C
C

G10BAF
      SUBROUTINE G10BAF(N,X,WINDOW,SLO,SHI,NS,SMOOTH,T,USEFFT,FFT,IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1993.
C
C       Algorithm AS 176 APPL. STATIST. (1982) VOL. 31, NO.1
C
C       Find density estimate by kernel method using Gaussian
C       kernel. The interval on which the estimate is evaluated
C       has end points SLO and SHI. If USEFT is not zero
C       then it is assumed that the routine has been
C       called before with the same data and end points
C       and that the array FT has not been altered.
C

G10CAF
      SUBROUTINE G10CAF(ITYPE,N,Y,SMOOTH,ROUGH,IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1993.
C
C     EDA SMOOTHERS
C
C     ITYPE  specifies the smoother to be used
C            ITYPE=0 specifies 4253H, twice
C            ITYPE=1 specifies 3RSSH, twice
C

G10ZAF
      SUBROUTINE G10ZAF(WEIGHT,N,X,Y,WT,NORD,XORD,YORD,WWT,RSS,IWRK,
     *                  IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1993.
C
C      Subroutine G10ZAF is an auxiliary to spline fitting routines,
C     given an unordered data set, weighted or non-weighted, it
C     will order the observations and reweight them if necessary.
C
C

G11AAF
      SUBROUTINE G11AAF(NROW,NCOL,NOBST,LDT,EXPT,CHIST,PROB,CHI,G,DF,
     *                  IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1993.

G11SAF
      SUBROUTINE G11SAF(N2,N,GPROB,S,X,NROWXR,RL,A,C,IPRINT,CGETOL,
     *                  MAXIT,CHISQR,ISHOW,NITER,ALPHA,GAMMA,VAR,IAA,G,
     *                  EXPP,IA,OBS,P,Y,XL,OB,LL,CHI,IDF,SIGLEV,W,LW,
     *                  IFAIL)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C     MARK 13A REVISED. IER-634 (APR 1988).
C
C     MAXIMUM LIKELIHOOD ESTIMATION OF ITEM PARAMETERS VIA THE
C     E-M ALGORITHM FOR THE FOLLOWING MODELS
C
C          (1) LOGIT
C          (2) PROBIT
C

G11SBF
      SUBROUTINE G11SBF(N2,N,S,X,NRX,RL,IFAIL)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.

G12AAF
      SUBROUTINE G12AAF(N,T,IC,FREQ,IFREQ,ND,TP,P,PSIG,IWK,IFAIL)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C

G13AAF
      SUBROUTINE G13AAF(X,NX,ND,NDS,NS,XD,NXD,IFAIL)
C     MARK 9 RELEASE. NAG COPYRIGHT 1981.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     G13AAF CARRIES OUT NON-SEASONAL AND SEASONAL DIFFERENCING
C     ON AN INPUT TIME SERIES.
C
C     CONTRIBUTORS - G. TUNNICLIFFE WILSON, C. DALY (LANCASTER
C     UNIV.)
C     VALIDATOR    - T. LAMBERT (NAG CENTRAL OFFICE)
C
C     USES NAG LIBRARY ROUTINE P01AAF
C
C
C     TEST THAT NONE OF THE ORDERS IS NEGATIVE
C

G13ABF
      SUBROUTINE G13ABF(X,NX,NK,XM,XV,R,STAT,IFAIL)
C     MARK 9 RELEASE. NAG COPYRIGHT 1981.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 12A REVISED. IER-512 (AUG 1986).
C
C     G13ABF COMPUTES THE SAMPLE AUTOCORRELATION FUNCTION
C     OF AN INPUT TIME SERIES. IT ALSO COMPUTES THE SAMPLE MEAN,
C     THE SAMPLE VARIANCE, AND A STATISTIC WHICH MAY BE USED TO
C     TEST THE HYPOTHESIS THAT THE TRUE AUTOCORRELATION
C     FUNCTION IS ZERO.
C
C     CONTRIBUTORS - G. TUNNICLIFFE WILSON, C. DALY (LANCASTER
C     UNIV.)
C     VALIDATOR    - T. LAMBERT (NAG CENTRAL OFFICE)
C
C     USES NAG LIBRARY ROUTINE P01AAF
C

G13ACF
      SUBROUTINE G13ACF(R,NK,NL,P,V,AR,NVL,IFAIL)
C     MARK 9 RELEASE. NAG COPYRIGHT 1981.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     G13ACF CALCULATES PARTIAL AUTOCORRELATION COEFFICIENTS
C     GIVEN A SET OF AUTOCORRELATION COEFFICIENTS. IT ALSO
C     CALCULATES THE PREDICTION ERROR VARIANCE RATIOS FOR
C     INCREASING ORDER OF FINITE LAG AUTOREGRESSIVE PREDICTOR,
C     AND THE AUTOREGRESSIVE PARAMETERS ASSOCIATED WITH THE
C     PREDICTOR OF MAXIMUM ORDER.
C
C     CONTRIBUTORS - G. TUNNICLIFFE WILSON, C. DALY (LANCASTER
C     UNIV.)
C     VALIDATOR    - T. LAMBERT (NAG CENTRAL OFFICE)
C
C     USES NAG LIBRARY ROUTINE P01AAF
C

G13ADF
      SUBROUTINE G13ADF(MR,R,NK,XV,NPAR,WA,NWA,PAR,RV,ISF,IFAIL)
C     MARK 9 RELEASE. NAG COPYRIGHT 1981.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     G13ADF CALCULATES PRELIMINARY ESTIMATES OF THE
C     PARAMETERS OF AN AUTOREGRESSIVE MOVING-AVERAGE
C     (ARMA) MODEL FROM AN AUTOCORRELATION FUNCTION.
C
C     CONTRIBUTORS - G. TUNNICLIFFE WILSON, M. HURLEY (LANCASTER U.)
C     VALIDATOR    - T. LAMBERT (NAG CENTRAL OFFICE)
C
C     ALGORITHM DUE TO G.E.P. BOX AND G.M. JENKINS,
C     TIME SERIES ANALYSIS FORECASTING AND CONTROL
C     (HOLDEN DAY) PART 5 PROGRAM 2
C
C     USES NAG LIBRARY ROUTINES G13ADZ, P01AAF
C

G13AEF
      SUBROUTINE G13AEF(MR,PAR,NPAR,C,KFC,X,NX,ICOUNT,EX,EXR,AL,IEX,S,G,
     *                  IGH,SD,H,IH,ST,IST,NST,PIV,KPIV,NIT,ITC,ZSP,
     *                  KZSP,ISF,WA,IWA,HC,IFAIL)
C     MARK 9 RELEASE. NAG COPYRIGHT 1981.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C     MARK 16 REVISED. IER-1041 (JUN 1993).
C
C     G13AEF FITS A SEASONAL ARIMA MODEL TO AN OBSERVED TIME SERIES
C     USING A NON-LINEAR LEAST SQUARES PROCEDURE INCORPORATING
C     BACKFORECASTING. PARAMETER ESTIMATES ARE OBTAINED, TOGETHER
C     WITH APPROPRIATE STANDARD ERRORS. THE RESIDUAL SERIES IS
C     RETURNED, AND INFORMATION FOR USE IN FORECASTING THE SERIES IS
C     PRODUCED FOR USE IN THE ROUTINES G13AGF AND G13AHF.
C
C     THE ESTIMATION PROCEDURE IS ITERATIVE, STARTING WITH INITIAL
C     PARAMETER VALUES SUCH AS MAY BE OBTAINED USING THE ROUTINE
C     G13ADF. IT CONTINUES UNTIL A SPECIFIED CONVERGENCE CITERION
C     IS SATISFIED, OR UNTIL A SPECIFIED NUMBER OF ITERATIONS HAVE
C     BEEN CARRIED OUT. THE PROGRESS OF THE PROCEDURE CAN BE
C     MONITORED BY MEANS OF A USER-SUPPLIED ROUTINE.
C
C     CONTRIBUTORS - G. TUNNICLIFFE WILSON, C. DALY (LANCASTER
C     UNIV.)
C     VALIDATOR    - T. LAMBERT (NAG CENTRAL OFFICE)
C
C     PIV

G13AFF
      SUBROUTINE G13AFF(MR,PAR,NPAR,C,KFC,X,NX,S,NDF,SD,NPPC,CM,ICM,ST,
     *                  NST,KPIV,NIT,ITC,ISF,RES,IRES,NRES,IFAIL)
C     MARK 9 RELEASE. NAG COPYRIGHT 1981.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     G13AFF IS AN EASY TO USE VERSION OF G13AEF.
C     IT FITS A SEASONAL ARIMA MODEL TO AN OBSERVED TIME SERIES,
C     USING
C     A NON-LINEAR LEAST SQUARES TECHNIQUE INCORPORATING
C     BACKFORECASTING
C
C     USES NAG LIBRARY ROUTINES G13AEF AND P01AAF
C

G13AGF
      SUBROUTINE G13AGF(ST,NST,MR,PAR,NPAR,C,ANX,NUV,ANEXR,WA,NWA,IFAIL)
C     MARK 9 RELEASE. NAG COPYRIGHT 1981.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     G13AGF ACCEPTS A SERIES OF NEW OBSERVATIONS OF A TIME SERIES,
C     THE MODEL OF WHICH IS ALREADY FULLY SPECIFIED, AND UPDATES THE
C     STATE SET INFORMATION FOR USE IN CONSTRUCTING FURTHER
C     FORECASTS
C
C     USES NAG LIBRARY ROUTINE P01AAF
C
C     CONTRIBUTORS - G. TUNNICLIFFE WILSON, C. DALY (LANCASTER
C     UNIV.)
C     VALIDATOR    - T. LAMBERT (NAG CENTRAL OFFICE)
C
C
C     ABSTRACT INFORMATION FROM THE ORDERS VECTOR
C

G13AHF
      SUBROUTINE G13AHF(ST,NST,MR,PAR,NPAR,C,RMS,NFV,FVA,FSD,WA,NWA,
     *                  IFAIL)
C     MARK 9 RELEASE. NAG COPYRIGHT 1981.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     G13AHF PRODUCES FORECASTS OF A TIME SERIES, GIVEN A TIME
C     SERIES
C     MODEL WHICH HAS ALREADY BEEN FITTED TO THE TIME SERIES USING
C     ROUTINE G13AEF OR G13AFF.
C
C     USES NAG LIBRARY ROUTINE P01AAF
C
C     CONTRIBUTORS - G. TUNNICLIFFE WILSON, C. DALY (LANCASTER
C     UNIVERSIT
C     VALIDATOR    - T. LAMBERT (NAG CENTRAL OFFICE)
C
C
C     ABSTRACT INFORMATION FROM ORDERS VECTOR
C

G13AJF
      SUBROUTINE G13AJF(MR,PAR,NPAR,C,KFC,X,NX,RMS,ST,IST,NST,NFV,FVA,
     *                  FSD,IFV,ISF,W,IW,IFAIL)
C     MARK 10 RELEASE. NAG COPYRIGHT 1982.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     G13AJF APPLIES A SEASONAL ARIMA MODEL TO AN OBSERVED
C     TIME SERIES AND DERIVES THE STATE SET FOR USE IN
C     FORECASTING, AND ANY SPECIFIED NUMBER OF FORECASTS
C     WITH STANDARD ERRORS.
C
C     CONTRIBUTORS - G. TUNNICLIFFE WILSON, C. DALY (LANCASTER
C     UNIV. )
C     VALIDATOR    - T. LAMBERT (NAG CENTRAL OFFICE)
C
C     USES NAG LIBRARY ROUTINES G13AHZ, G13AJY, G13AJZ, P01AAF
C

G13ASF
      SUBROUTINE G13ASF(N,V,MR,M,PAR,NPAR,ISHOW,C,ACFVAR,IM,SUM2,IDF,
     *                  SIGLEV,INTGR,LMAX,WORK,LWORK,IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.
C     MARK 15 REVISED. IER-942 (APR 1991).
C     MARK 16 REVISED. IER-1121 (JUL 1993).

G13AUF
      SUBROUTINE G13AUF(N,Z,M,K,RS,Y,MEAN,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.

G13BAF
      SUBROUTINE G13BAF(Y,NY,MR,NMR,PAR,NPAR,CY,WA,NWA,B,NB,IFAIL)
C     MARK 10 RELEASE. NAG COPYRIGHT 1982.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     G13BAF FILTERS A TIME SERIES BY AN AUTOREGRESSIVE
C     INTEGRATED MOVING AVERAGE MODEL.
C
C     CONTRIBUTORS - G.TUNNICLIFFE WILSON,M. HURLEY (LANC. UNIV.)
C     VALIDATOR    - T. LAMBERT ( NAG CENTRAL OFFICE )
C
C     USES NAG LIBRARY ROUTINES G13BAY, G13BAZ, P01AAF
C

G13BBF
      SUBROUTINE G13BBF(Y,NY,MR,NMR,PAR,NPAR,CY,WA,IWA,B,NB,IFAIL)
C     MARK 11 RELEASE. NAG COPYRIGHT 1983.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C        ----------------------------------------------------
C
C        NAG LIBRARY ROUTINE G13BBF FILTERS A TIME SERIES
C        BY AN TF MODEL
C
C        ORIGIN OF SOFTWARE - LANCASTER UNIVERSITY
C        DATE OF INCEPTION - FEBRUARY 1981
C        DATE OF COMPLETION - FEBRUARY 1981
C
C        ALGORITHM DUE TO
C        G.E.P. BOX AND G.M. JENKINS
C        TIME SERIES ANALYSIS  FORECASTING AND CONTROL
C        HOLDEN-DAY
C        BACKFORECASTING FEATURE DUE TO G. TUNICLIFFE-WILSON
C
C        M.A.H.(PROGRAMMER)
C
C        -----------------------------------------------------
C
C        G13BBF CHECKS THE USER SUPPLIED PARAMETERS AND MAKES A
C        FUDGED CALL TO AUXILIARY G13BAZ WHICH CARRIES OUT THE
C        CALCULATIONS.
C

G13BCF
      SUBROUTINE G13BCF(X,Y,NXY,NL,S,R0,R,STAT,IFAIL)
C     MARK 10 RELEASE. NAG COPYRIGHT 1982.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     G13BCF CALCULATES CROSS CORRELATIONS BETWEEN TWO TIME SERIES
C
C     CONTRIBUTORS - G. TUNNICLIFFE WILSON,M. HURLEY (LANC. UNIV.)
C     VALIDATOR    - T. LAMBERT ( NAG CENTRAL OFFICE )
C
C     USES NAG LIBRARY ROUTINES G13BCZ, P01AAF
C

G13BDF
      SUBROUTINE G13BDF(R0,R,NL,NNA,S,NWDS,WA,IWA,WDS,ISF,IFAIL)
C     MARK 11 RELEASE. NAG COPYRIGHT 1983.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C        -------------------------------------------------------
C
C        NAG LIBRARY ROUTINE G13BDF CALCULATES PRELIMINARY
C        ESTIMATES FO THE PARAMETERS OF A TRANSFER FUNCTION MODEL.
C
C        ORIGIN OF SOFTWARE - LANCASTER UNIVERSITY
C        DATE OF INCEPTION - MARCH 1981
C        DATE OF COMPLETION - APRIL 1981
C
C        ALGORITHM DUE TO
C        G.E.P. BOX AND G.M. JENKINS
C        TIME SERIES ANALYSIS  FORECASTING AND CONTROL
C        HOLDEN-DAY
C
C        M.A.H. (PROGRAMMER)
C
C        --------------------------------------------------------
C
C        G13BDF CHECKS THE USER SUPPLIED PARAMETERS AND CALLS THE
C        AUXILIARY G13BDZ TO CARRY OUT THE CALCULATIONS
C

G13BEF
      SUBROUTINE G13BEF(MR,NSER,MT,PARA,NPARA,KFC,NXXY,XXY,IXXY,KEF,NIT,
     *                  KZSP,ZSP,ITC,SD,CM,ICM,S,D,NDF,KZEF,RES,STTF,
     *                  ISTTF,NSTTF,WA,IWA,MWA,IMWA,KPRIV,IFAIL)
C     MARK 11 RELEASE. NAG COPYRIGHT 1983.
C     MARK 11A REVISED. IER-452 (JUN 1984).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 12 REVISED. IER-521 (AUG 1986).
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C
C     SUBROUTINE G13BEF ACCEPTS AN OUTPUT (Y) SERIES AND
C     ANY NUMBER OF INPUT (X) SERIES, THE ORDERS OF ALL
C     THESE SERIES BEING SPECIFIED. THE Y SERIES IS CHARACTERISED
C     BY AN ARIMA MODEL SPECIFICATION AND A SET OF INITIAL PARAMETER
C     ESTIMATES WHICH MAY BE ZERO.
C     THE ROUTINE CARRIES OUT AN ITERATIVE OPTIMISATION
C     PROCEDURE TO OBTAIN A SET OF FINAL ESTIMATES WHICH
C     SATISFY A SPECIFIED CONVERGENCE CRITERION OR WHICH
C     ARE THE RESULTS OF A SPECIFIED NUMBER OF ITERATIONS.
C

G13BGF
      SUBROUTINE G13BGF(STTF,NSTTF,MR,NSER,MT,PARA,NPARA,NNV,XXYN,IXXYN,
     *                  KZEF,RES,WA,IWA,IFAIL)
C     MARK 11 RELEASE. NAG COPYRIGHT 1983.
C     MARK 11A REVISED. IER-453 (JUN 1984).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     G13BFF UPDATES A STATE SET WHEN NEW VALUES OF X AND Y
C     ARE ADDED TO A FULLY SPECIFIED TRANSFER FUNCTION TIME
C     SERIES MODEL
C
C
C     BREAK DOWN MR(ORDERS ARRAY FOR Y) INTO COMPONENT PARTS
C

G13BHF
      SUBROUTINE G13BHF(STTF,NSTTF,MR,NSER,MT,PARA,NPARA,NFV,XXYN,IXXYN,
     *                  MRX,PARX,IPARX,RMSXY,KZEF,FVA,FSD,WA,IWA,IFAIL)
C     MARK 11 RELEASE. NAG COPYRIGHT 1983.
C     MARK 11A REVISED. IER-454 (JUN 1984).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     SUBROUTINE G13BHF DERIVES FORECAST VALUES AND THEIR
C     STANDARD DEVIATIONS IN A TRANSFER FUNCTION CONTEXT
C
C
C     MXA,MXB,MXC AND MXD ARE USED IN DERIVATION OF IWAA
C

G13BJF
      SUBROUTINE G13BJF(MR,NSER,MT,PARA,NPARA,KFC,NEV,NFV,XXY,IXXY,KZEF,
     *                  RMSXY,MRX,PARX,IPARX,FVA,FSD,STTF,ISTTF,NSTTF,
     *                  WA,IWA,MWA,IMWA,IFAIL)
C     MARK 11 RELEASE. NAG COPYRIGHT 1983.
C     MARK 11A REVISED. IER-455 (JUN 1984).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C
C     G13BJF PRODUCES FORECASTS WHEN NO STATE SET
C     IS AVAILABLE. IT REQUIRES A FULLY SPECIFIED
C     MODEL AND A SET OF OBSERVATIONS OF INPUT AND
C     OUTPUT SERIES.
C

G13CAF
      SUBROUTINE G13CAF(NX,MTX,PX,IW,MW,IC,NC,C,KC,L,LG,NXG,XG,NG,STATS,
     *                  IFAIL)
C     MARK 10 RELEASE. NAG COPYRIGHT 1982.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     G13CAF CALCULATES THE SMOOTHED SAMPLE SPECTRUM OF A
C     UNIVARIATE TIME SERIES USING ONE OF FOUR LAG WINDOWS
C     - RECTANGULAR, BARTLETT, TUKEY OR PARZEN WINDOW.
C
C     CONTRIBUTORS - G. TUNNICLIFFE WILSON, M. HURLEY (LANC. UNIV.)
C     VALIDATOR    - T. LAMBERT ( NAG CENTRAL OFFICE )
C
C     USES NAG LIBRARY ROUTINES G13CAZ, P01AAF
C
C

G13CBF
      SUBROUTINE G13CBF(NX,MTX,PX,MW,PW,L,KC,LG,XG,NG,STATS,IFAIL)
C     MARK 10 RELEASE. NAG COPYRIGHT 1982.
C     MARK 10B REVISED. IER-405 (JAN 1983).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     G13CBF CALCULATES THE SMOOTHED SAMPLE SPECTRUM OF A
C     UNIVARIATE TIME SERIES USING SPECTRAL SMOOTHING BY
C     THE TRAPEZIUM FREQUENCY (DANIELL) WINDOW.
C
C     CONTRIBUTORS - G. TUNNICLIFFE WILSON,M. HURLEY (LANC. UNIV.)
C     VALIDATOR    - T. LAMBERT ( NAG CENTRAL OFFICE )
C
C     USES NAG LIBRARY ROUTINES G13CAZ, P01AAF
C

G13CCF
      SUBROUTINE G13CCF(NXY,MTXY,PXY,IW,MW,IS,IC,NC,CXY,CYX,KC,L,NXYG,
     *                  XG,YG,NG,IFAIL)
C     MARK 10 RELEASE. NAG COPYRIGHT 1982.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     G13CCF CALCULATES THE SMOOTHED SAMPLE CROSS SPECTRUM
C     OF A BIVARIATE TIME SERIES USING ONE OF FOUR LAG
C     WINDOWS - RECTANGULAR, BARTLETT, TUKEY, OR PARZEN
C     WINDOW.
C
C     CONTRIBUTORS - G. TUNNICLIFFE WILSON,M. HURLEY (LANC. UNIV.)
C     VALIDATOR    - T. LAMBERT ( NAG CENTRAL OFFICE )
C
C     USES NAG LIBRARY ROUTINES G13CCZ, P01AAF
C

G13CDF
      SUBROUTINE G13CDF(NXY,MTXY,PXY,MW,IS,PW,L,KC,XG,YG,NG,IFAIL)
C     MARK 10 RELEASE. NAG COPYRIGHT 1982.
C     MARK 10B REVISED. IER-406 (JAN 1983).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     G13CDF CALCULATES THE SMOOTHED SAMPLE CROSS SPECTRUM
C     OF A BIVARIATE TIME SERIES USING SPECTRAL SMOOTHING
C     BY THE TRAPEZIUM FREQUENCY (DANIELL) WINDOW.
C
C     CONTRIBUTORS - G. TUNNICLIFFE WILSON,M. HURLEY (LANC. UNIV.)
C     VALIDATOR    - T. LAMBERT ( NAG CENTRAL OFFICE )
C
C     USES NAG LIBRARY ROUTINES G13CCZ, P01AAF
C

G13CEF
      SUBROUTINE G13CEF(XG,YG,XYRG,XYIG,NG,STATS,CA,CALW,CAUP,T,SC,SCLW,
     *                  SCUP,IFAIL)
C     MARK 10 RELEASE. NAG COPYRIGHT 1982.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     FOR A BIVARIATE TIME SERIES, G13CEF CALCULATES THE
C     CROSS AMPLITUDE SPECTRUM AND SQUARED COHERENCY, TOGETHER
C     WITH LOWER AND UPPER BOUNDS FROM THE UNIVARIATE AND
C     BIVARIATE (CROSS) SPECTRA
C
C     CONTRIBUTORS - G. TUNNICLIFFE WILSON,M. HURLEY (LANC. UNIV.)
C     VALIDATOR    - T. LAMBERT ( NAG CENTRAL OFFICE )
C
C     USES NAG LIBRARY ROUTINES G13CEZ, P01AAF
C

G13CFF
      SUBROUTINE G13CFF(XG,YG,XYRG,XYIG,NG,STATS,GN,GNLW,GNUP,PH,PHLW,
     *                  PHUP,IFAIL)
C     MARK 10 RELEASE. NAG COPYRIGHT 1982.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     FOR A BIVARIATE TIME SERIES, G13CFF CALCULATES THE
C     GAIN AND THE PHASE TOGETHER WITH LOWER AND UPPER
C     BOUNDS FROM THE UNIVARIATE AND BIVARIATE SPECTRA.
C
C     CONTRIBUTORS - G. TUNNICLIFFE WILSON,M. HURLEY (LANC. UNIV.)
C
C     USES NAG LIBRARY ROUTINES G13CFZ, P01AAF
C

G13CGF
      SUBROUTINE G13CGF(XG,YG,XYRG,XYIG,NG,STATS,L,N,ER,ERLW,ERUP,RF,
     *                  RFSE,IFAIL)
C     MARK 10 RELEASE. NAG COPYRIGHT 1982.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     FOR A BIVARIATE TIME SERIES, G13CGF CALCULATES THE
C     NOISE SPECTRUM  TOGETHER WITH MULTIPLYING FACTORS
C     FOR THE BOUNDS AND THE IMPULSE RESPONSE FUNCTION
C     AND ITS STANDARD ERROR, FROM THE UNIVARIATE
C     AND BIVARIATE SPECTRA.
C
C     CONTRIBUTORS - G. TUNNICLIFFE WILSON,M. HURLEY (LANC. UNIV.)
C     VALIDATOR    - T. LAMBERT ( NAG CENTRAL OFFICE )
C
C     USES NAG LIBRARY ROUTINES G13CGZ, P01AAF
C

G13DBF
      SUBROUTINE G13DBF(C0,C,NSM,NS,NL,NK,P,V0,V,D,DB,W,WB,NVP,WA,IWA,
     *                  IFAIL)
C     MARK 11 RELEASE. NAG COPYRIGHT 1983.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C        -----------------------------------------------------
C
C        NAG LIBRARY ROUTINE G13DBF CALCULATES THE MULTIVARIATE PARTIAL
C        AUTOCORRELATION FUNCTION OF A MULTIVARIATE TIME SERIES.
C
C        ORIGIN OF SOFTWARE - LANCASTER UNIVERSITY
C        DATE OF INCEPTION - OCTOBER 1981
C        DATE OF COMPLETION - JANUARY 1982
C
C        M.A.H. (PROGRAMMER)
C
C        ----------------------------------------------------
C
C        G13DBF CHECKS THE USER SUPPLIED PARAMETERS AND CALLS THE
C        AUXILIARY G13DBZ TO CARRY OUT THE CALCULATIONS
C

G13DCF
      SUBROUTINE G13DCF(K,N,P,Q,MEAN,X,N4,QQ,IK,W,PARHLD,CONDS,IPRINT,
     *                  CGETOL,MAXCAL,ISHOW,NITER,LOGL,V,G,DISP,IDISP,
     *                  W2,LW,IW,LIW,IFAIL)
C     MARK 14 RE-ISSUE.  NAG COPYRIGHT 1989.
C     MARK 16 REVISED. IER-1111 (JUL 1993).

G13DJF
      SUBROUTINE G13DJF(K,N,Z,IK,TR,ID,DELTA,IP,IQ,MEAN,PAR,LPAR,QQ,V,
     *                  LMAX,PREDZ,SEFZ,REF,LREF,WORK,LWORK,IWORK,
     *                  LIWORK,IFAIL)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C     MARK 15B REVISED. IER-957 (NOV 1991).

G13DKF
      SUBROUTINE G13DKF(K,LMAX,M,MLAST,Z,IK,REF,LREF,V,PREDZ,SEFZ,WORK,
     *                  IFAIL)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

G13DLF
      SUBROUTINE G13DLF(K,N,Z,IK,TR,ID,DELTA,W,ND,WORK,IFAIL)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

G13DMF
      SUBROUTINE G13DMF(MATRIX,K,N,M,W,IK,WMEAN,R0,R,IFAIL)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C     MARK 16A REVISED. IER-1044 (JUN 1993).
C
C     This subroutine calculates the sample cross-covariance
C     (MATRIX = 'V') or cross-correlation (MATRIX = 'R')
C     matrices of a multivariate time series.
C

G13DNF
      SUBROUTINE G13DNF(K,N,M,IK,R0,R,MAXLAG,PARLAG,X,PVALUE,WORK,LWORK,
     *                  IFAIL)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C
C     This subroutine calculates the sample partial lag correlation
C     matrices of a multivariate time series using the recursive
C     algorithm of Heyse and Wei.
C

G13DPF
      SUBROUTINE G13DPF(K,N,Z,IK,M,MAXLAG,PARLAG,SE,QQ,X,PVALUE,LOGLHD,
     *                  WORK,LWORK,IWORK,IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1993.

G13DSF
      SUBROUTINE G13DSF(K,N,V,IK,P,Q,M,PAR,PARHLD,QQ,ISHOW,R0,C,ACFVAR,
     *                  IM,CHI,IDF,SIGLEV,IW,LIW,WORK,LWORK,IFAIL)
C     MARK 15 RE-ISSUE. NAG COPYRIGHT 1991.

G13DXF
      SUBROUTINE G13DXF(K,IP,PAR,RR,RI,RMOD,WORK,IWORK,IFAIL)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.

H02BBF
      SUBROUTINE H02BBF(ITMAX,MSGLVL,N,M,A,LDA,BL,BU,INTVAR,CVEC,MAXNOD,
     *                  INTFST,MAXDPT,TOLIV,TOLFES,BIGBND,X,OBJMIP,
     *                  IWORK,LIWORK,RWORK,LRWORK,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C     MARK 14B REVISED. IER-843 (MAR 1990).
C     MARK 15 REVISED. IER-927 (APR 1991).
C     MARK 16 RE-ISSUE. NAG COPYRIGHT 1992.

H02BFF
      SUBROUTINE H02BFF(INFILE,MAXN,MAXM,OPTIM,XBLDEF,XBUDEF,MAXDPT,
     *                  MSGLVL,N,M,X,CRNAME,IWORK,LIWORK,RWORK,LRWORK,
     *                  IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1993.

H02BUF
      SUBROUTINE H02BUF(INFILE,MAXN,MAXM,OPTIM,XBLDEF,XBUDEF,NMOBJ,
     *                  NMRHS,NMRNG,NMBND,MPSLST,N,M,A,BL,BU,CVEC,X,
     *                  INTVAR,CRNAME,NMPROB,IWORK,IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1993.

H02BVF
      SUBROUTINE H02BVF(N,M,A,LDA,BL,BU,X,CLAMDA,ISTATE,CRNAME,IFAIL)
C     MARK 16 RELEASE. NAG COPYRIGHT 1993.

H02BZF
      SUBROUTINE H02BZF(N,M,BL,BU,CLAMDA,ISTATE,IWORK,LIWORK,RWORK,
     *                  LRWORK,IFAIL)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C     MARK 16 RE-ISSUE. NAG COPYRIGHT 1992.

H03ABF
      SUBROUTINE H03ABF(KOST,MMM,MA,MB,M,K15,MAXIT,K7,K9,NUMIT,K6,K8,
     *                  K11,K12,Z,IFAIL)
C     NAG COPYRIGHT 1975
C     MARK 4.5 REVISED
C     MARK 6 REVISED  IER-91
C     MARK 7C REVISED IER-189 (MAY 1979)
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     H03ABF SOLVES THE CLASSICAL TRANSPORTATION PROBLEM IN THAT IT
C     MINIMIZES THE COST OF SENDING GOODS FROM SOURCES TO
C     DESTINATIONS
C     SUBJECT TO CONSTRAINTS ON THE AVAILABILITIES AND
C     REQUIREMENTS.

M01CAF
      SUBROUTINE M01CAF(RV,M1,M2,ORDER,IFAIL)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C
C     M01CAF SORTS A VECTOR OF REAL NUMBERS INTO ASCENDING
C     OR DESCENDING ORDER.
C
C     M01CAF IS BASED ON SINGLETON'S IMPLEMENTATION OF THE
C     'MEDIAN-OF-THREE' QUICKSORT ALGORITHM, BUT WITH TWO
C     ADDITIONAL MODIFICATIONS. FIRST, SMALL SUBFILES ARE
C     SORTED BY AN INSERTION SORT ON A SEPARATE FINAL PASS.
C     SECOND, IF A SUBFILE IS PARTITIONED INTO TWO VERY
C     UNBALANCED SUBFILES, THE LARGER OF THEM IS FLAGGED FOR
C     SPECIAL TREATMENT: BEFORE IT IS PARTITIONED, ITS END-
C     POINTS ARE SWAPPED WITH TWO RANDOM POINTS WITHIN IT;
C     THIS MAKES THE WORST CASE BEHAVIOUR EXTREMELY UNLIKELY.
C
C     THE MAXIMUM LENGTH OF A SMALL SUBFILE IS DEFINED BY THE
C     VARIABLE MINQIK, SET TO 15.
C
C     THE ROUTINE ASSUMES THAT THE NUMBER OF ELEMENTS TO BE
C     SORTED DOES NOT EXCEED MINQIK*2**MAXSTK.
C
C     WRITTEN BY N.M.MACLAREN, UNIVERSITY OF CAMBRIDGE.
C     REVISED BY NAG CENTRAL OFFICE.
C

M01CBF
      SUBROUTINE M01CBF(IV,M1,M2,ORDER,IFAIL)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C
C     M01CBF SORTS A VECTOR OF INTEGER NUMBERS INTO ASCENDING
C     OR DESCENDING ORDER.
C
C     M01CBF IS BASED ON SINGLETON'S IMPLEMENTATION OF THE
C     'MEDIAN-OF-THREE' QUICKSORT ALGORITHM, BUT WITH TWO
C     ADDITIONAL MODIFICATIONS. FIRST, SMALL SUBFILES ARE
C     SORTED BY AN INSERTION SORT ON A SEPARATE FINAL PASS.
C     SECOND, IF A SUBFILE IS PARTITIONED INTO TWO VERY
C     UNBALANCED SUBFILES, THE LARGER OF THEM IS FLAGGED FOR
C     SPECIAL TREATMENT: BEFORE IT IS PARTITIONED, ITS END-
C     POINTS ARE SWAPPED WITH TWO RANDOM POINTS WITHIN IT;
C     THIS MAKES THE WORST CASE BEHAVIOUR EXTREMELY UNLIKELY.
C
C     THE MAXIMUM LENGTH OF A SMALL SUBFILE IS DEFINED BY THE
C     VARIABLE MINQIK, SET TO 15.
C
C     THE ROUTINE ASSUMES THAT THE NUMBER OF ELEMENTS TO BE
C     SORTED DOES NOT EXCEED MINQIK*2**MAXSTK.
C
C     WRITTEN BY N.M.MACLAREN, UNIVERSITY OF CAMBRIDGE.
C     REVISED BY NAG CENTRAL OFFICE.
C

M01CCF
      SUBROUTINE M01CCF(CH,M1,M2,L1,L2,ORDER,IFAIL)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C
C     M01CCF RE-ARRANGES A VECTOR OF CHARACTER DATA SO THAT A
C     SPECIFIED SUBSTRING IS IN ASCII OR REVERSE ASCII ORDER.
C
C     M01CCF IS BASED ON SINGLETON'S IMPLEMENTATION OF THE
C     'MEDIAN-OF-THREE' QUICKSORT ALGORITHM, BUT WITH TWO
C     ADDITIONAL MODIFICATIONS. FIRST, SMALL SUBFILES ARE
C     SORTED BY AN INSERTION SORT ON A SEPARATE FINAL PASS.
C     SECOND, IF A LARGER OF THEM IS FLAGGED FOR SPECIAL
C     TREATMENT: BEFORE IT IS PARTITIONED, ITS END-POINTS
C     ARE SWAPPED WITH TWO RANDOM POINTS WITHIN IT; THIS
C     MAKES THE WORST CASE BEHAVIOUR EXTREMELY UNLIKELY.
C
C     ONLY THE SUBSTRING (L1:L2) OF EACH ELEMENT OF THE ARRAY
C     CH IS USED TO DETERMINE THE SORTED ORDER, BUT THE ENTIRE
C     ELEMENTS ARE RE-ARRANGED INTO SORTED ORDER.
C
C     THE MAXIMUM LENGTH OF A SMALL SUBFILE IS DEFINED BY THE
C     VARIABLE MINQIK, SET TO 15.
C
C     THE ROUTINE ASSUMES THAT THE NUMBER OF ELEMENTS TO BE
C     SORTED DOES NOT EXCEED MINQIK*2**MAXSTK.
C
C     THE MAXIMUM PERMITTED LENGTH OF EACH ELEMENT OF THE ARRAY CH
C     IS DEFINED BY THE PARAMETER MAXLCH. THIS RESTRICTION IS
C     IMPOSED BY THE NEED TO SPECIFY A LENGTH FOR THE INTERNAL
C     CHARACTER VARIABLE A.
C
C     WRITTEN BY NAG CENTRAL OFFICE.
C

M01DAF
      SUBROUTINE M01DAF(RV,M1,M2,ORDER,IRANK,IFAIL)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C
C     M01DAF RANKS A VECTOR OF REAL NUMBERS IN ASCENDING
C     OR DESCENDING ORDER.
C
C     M01DAF USES A VARIANT OF LIST-MERGING, AS DESCRIBED
C     BY KNUTH. THE ROUTINE TAKES ADVANTAGE OF NATURAL
C     ORDERING IN THE DATA, AND USES A SIMPLE LIST INSERTION
C     IN A PREPARATORY PASS TO GENERATE ORDERED LISTS OF
C     LENGTH AT LEAST 10. THE RANKING IS STABLE: EQUAL ELEMENTS
C     PRESERVE THEIR ORDERING IN THE INPUT DATA.
C
C     THE MINIMUM LENGTH OF THE LISTS AT THE END OF THE
C     PREPARATORY PASS IS DEFINED BY THE VARIABLE MAXINS.
C
C     WRITTEN BY N.M.MACLAREN, UNIVERSITY OF CAMBRIDGE.
C     REVISED BY NAG CENTRAL OFFICE.
C

M01DBF
      SUBROUTINE M01DBF(IV,M1,M2,ORDER,IRANK,IFAIL)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C
C     M01DBF RANKS A VECTOR OF INTEGER NUMBERS IN ASCENDING
C     OR DESCENDING ORDER.
C
C     M01DBF USES A VARIANT OF LIST-MERGING, AS DESCRIBED
C     BY KNUTH. THE ROUTINE TAKES ADVANTAGE OF NATURAL
C     ORDERING IN THE DATA, AND USES A SIMPLE LIST INSERTION
C     IN A PREPARATORY PASS TO GENERATE ORDERED LISTS OF
C     LENGTH AT LEAST 10. THE RANKING IS STABLE: EQUAL ELEMENTS
C     PRESERVE THEIR ORDERING IN THE INPUT DATA.
C
C     THE MINIMUM LENGTH OF THE LISTS AT THE END OF THE
C     PREPARATORY PASS IS DEFINED BY THE VARIABLE MAXINS.
C
C     WRITTEN BY N.M.MACLAREN, UNIVERSITY OF CAMBRIDGE.
C     REVISED BY NAG CENTRAL OFFICE.
C

M01DCF
      SUBROUTINE M01DCF(CH,M1,M2,L1,L2,ORDER,IRANK,IFAIL)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C
C     M01DCF RANKS A VECTOR OF CHARACTER DATA IN ASCII OR
C     REVERSE ASCII ORDER OF A SPECIFIED SUBSTRING.
C
C     M01DCF USES A VARIANT OF LIST-MERGING, AS DESCRIBED
C     BY KNUTH. THE ROUTINE TAKES ADVANTAGE OF NATURAL
C     ORDERING IN THE DATA, AND USES A SIMPLE LIST INSERTION
C     IN A PREPARATORY PASS TO GENERATE ORDERED LISTS OF
C     LENGTH AT LEAST 10. THE RANKING IS STABLE: EQUAL ELEMENTS
C     PRESERVE THEIR ORDERING IN THE INPUT DATA.
C
C     ONLY THE SUBSTRING (L1:L2) OF EACH ELEMENT OF THE ARRAY
C     CH IS USED TO DETERMINE THE RANK ORDER.
C
C     THE MINIMUM LENGTH OF THE LISTS AT THE END OF THE
C     PREPARATORY PASS IS DEFINED BY THE VARIABLE MAXINS.
C
C     THE MAXIMUM PERMITTED LENGTH OF EACH ELEMENT OF THE ARRAY CH
C     IS DEFINED BY THE PARAMETER MAXLCH. THIS RESTRICTION IS
C     IMPOSED BY THE NEED TO SPECIFY A LENGTH FOR THE INTERNAL
C     CHARACTER VARIABLES A, B AND C.
C
C     WRITTEN BY NAG CENTRAL OFFICE.
C

M01DEF
      SUBROUTINE M01DEF(RM,LDM,M1,M2,N1,N2,ORDER,IRANK,IFAIL)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C
C     M01DEF RANKS THE ROWS OF A MATRIX OF REAL NUMBERS
C     IN ASCENDING OR DESCENDING ORDER.
C
C     M01DEF RANKS ROWS M1 TO M2 OF A MATRIX, USING THE DATA
C     IN COLUMNS N1 TO N2 OF THOSE ROWS. THE ORDERING IS
C     DETERMINED BY FIRST RANKING THE DATA IN COLUMN N1,
C     THEN RANKING ANY TIED ROWS ACCORDING TO THE DATA IN
C     COLUMN N1+1, AND SO ON UP TO COLUMN N2.
C
C     M01DEF USES A VARIANT OF LIST-MERGING, AS DESCRIBED BY
C     KNUTH. THE ROUTINE TAKES ADVANTAGE OF NATURAL ORDERING
C     IN THE DATA, AND USES A SIMPLE LIST INSERTION IN A
C     PREPARATORY PASS TO GENERATE ORDERED LISTS OF LENGTH AT
C     LEAST 10. THE RANKING IS STABLE: EQUAL ROWS PRESERVE
C     THEIR ORDERING IN THE INPUT DATA.
C
C     THE MINIMUM LENGTH OF THE LISTS AT THE END OF THE
C     PREPARATORY PASS IS DEFINED BY THE VARIABLE MAXINS.
C
C     WRITTEN BY N.M.MACLAREN, UNIVERSITY OF CAMBRIDGE.
C     REVISED BY NAG CENTRAL OFFICE.
C

M01DFF
      SUBROUTINE M01DFF(IV,LDM,M1,M2,N1,N2,ORDER,IRANK,IFAIL)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C
C     M01DFF RANKS THE ROWS OF A MATRIX OF INTEGER NUMBERS
C     IN ASCENDING OR DESCENDING ORDER.
C
C     M01DFF RANKS ROWS M1 TO M2 OF A MATRIX, USING THE DATA
C     IN COLUMNS N1 TO N2 OF THOSE ROWS. THE ORDERING IS
C     DETERMINED BY FIRST RANKING THE DATA IN COLUMN N1,
C     THEN RANKING ANY TIED ROWS ACCORDING TO THE DATA IN
C     COLUMN N1+1, AND SO ON UP TO COLUMN N2.
C
C     M01DFF USES A VARIANT OF LIST-MERGING, AS DESCRIBED BY
C     KNUTH. THE ROUTINE TAKES ADVANTAGE OF ANY NATURAL ORDERING
C     IN THE DATA, AND USES A SIMPLE LIST INSERTION IN A
C     PREPARATORY PASS TO GENERATE ORDERED LISTS OF LENGTH AT
C     LEAST 10. THE RANKING IS STABLE: EQUAL ROWS PRESERVE
C     THEIR ORDERING IN THE INPUT DATA.
C
C     THE MINIMUM LENGTH OF THE LISTS AT THE END OF THE
C     PREPARATORY PASS IS DEFINED BY THE VARIABLE MAXINS.
C
C     WRITTEN BY N.M.MACLAREN, UNIVERSITY OF CAMBRIDGE.
C     REVISED BY NAG CENTRAL OFFICE.
C

M01DJF
      SUBROUTINE M01DJF(RM,LDM,M1,M2,N1,N2,ORDER,IRANK,IFAIL)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C
C     M01DJF RANKS THE COLUMNS OF A MATRIX OF REAL NUMBERS IN
C     ASCENDING OR DESCENDING ORDER.
C
C     M01DJF RANKS COLUMNS N1 TO N2 OF A MATRIX, USING THE DATA
C     IN ROWS M1 TO M2 OF THOSE COLUMNS. THE ORDERING IS
C     DETERMINED BY FIRST RANKING THE DATA IN ROW M1, THEN
C     RANKING ANY TIED COLUMNS ACCORDING TO THE DATA IN ROW
C     M1+1, AND SO ON UP TO ROW M2.
C
C     M01DJF USES A VARIANT OF LIST-MERGING, AS DECRIBED BY
C     KNUTH. THE ROUTINE TAKES ADVANTAGE OF ANY NATURAL ORDERING
C     IN THE DATA, AND USES A SIMPLE LIST INSERTION IN A
C     PREPARATORY PASS TO GENERATE ORDERED LISTS OF LENGTH AT
C     LEAST 10. THE RANKING IS STABLE: EQUAL COLUMNS PRESERVE
C     THEIR ORDERING IN THE INPUT DATA.
C
C     THE MINIMUM LENGTH OF THE LISTS AT THE END OF THE
C     PREPARATORY PASS IS DEFINED BY THE VARIABLE MAXINS.
C
C     WRITTEN BY N.M.MACLAREN, UNIVERSITY OF CAMBRIDGE.
C     REVISED BY NAG CENTRAL OFFICE.

M01DKF
      SUBROUTINE M01DKF(IM,LDM,M1,M2,N1,N2,ORDER,IRANK,IFAIL)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C
C     M01DKF RANKS THE COLUMNS OF A MATRIX OF INTEGER NUMBERS IN
C     ASCENDING OR DESCENDING ORDER.
C
C     M01DKF RANKS COLUMNS N1 TO N2 OF A MATRIX, USING THE DATA
C     IN ROWS M1 TO M2 OF THOSE COLUMNS. THE ORDERING IS
C     DETERMINED BY FIRST RANKING THE DATA IN ROW M1, THEN
C     RANKING ANY TIED COLUMNS ACCORDING TO THE DATA IN ROW
C     M1+1, AND SO ON UP TO ROW M2.
C
C     M01DKF USES A VARIANT OF LIST-MERGING, AS DECRIBED BY
C     KNUTH. THE ROUTINE TAKES ADVANTAGE OF ANY NATURAL ORDERING
C     IN THE DATA, AND USES A SIMPLE LIST INSERTION IN A
C     PREPARATORY PASS TO GENERATE ORDERED LISTS OF LENGTH AT
C     LEAST 10. THE RANKING IS STABLE: EQUAL COLUMNS PRESERVE
C     THEIR ORDERING IN THE INPUT DATA.
C
C     THE MINIMUM LENGTH OF THE LISTS AT THE END OF THE
C     PREPARATORY PASS IS DEFINED BY THE VARIABLE MAXINS.
C
C     WRITTEN BY N.M.MACLAREN, UNIVERSITY OF CAMBRIDGE.
C     REVISED BY NAG CENTRAL OFFICE.

M01DZF
      SUBROUTINE M01DZF(COMPAR,M1,M2,IRANK,IFAIL)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C
C     M01DZF RANKS ARBITRARY DATA ACCORDING TO A USER-SUPPLIED
C     COMPARISON ROUTINE.
C
C     M01DZF IS A GENERAL-PURPOSE ROUTINE FOR RANKING ARBITRARY
C     DATA. M01DZF DOES NOT ACCESS THE DATA DIRECTLY; INSTEAD IT
C     CALLS A USER-SUPPLIED ROUTINE COMPAR TO DETERMINE THE RELATIVE
C     ORDERING OF ANY TWO DATA ITEMS. THE DATA ITEMS ARE IDENTIFIED
C     SIMPLY BY AN INTEGER IN THE RANGE M1 TO M2.
C
C     M01DZF USES A VARIANT OF LIST-MERGING, AS DESCRIBED BY KNUTH.
C     THE ROUTINE TAKES ADVANTAGE OF ANY NATURAL ORDERING IN THE
C     DATA, AND USES A SIMPLE LIST INSERTION IN A PREPARATORY PASS
C     TO GENERATE ORDERED LISTS OF LENGTH AT LEAST 10.
C
C     THE MINIMUM LENGTH OF THE LISTS AT THE END OF THE
C     PREPARATORY PASS IS DEFINED BY THE VARIABLE MAXINS.
C
C     WRITTEN BY NAG CENTRAL OFFICE.
C

M01EAF
      SUBROUTINE M01EAF(RV,M1,M2,IRANK,IFAIL)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C
C     M01EAF RE-ARRANGES A VECTOR OF REAL NUMBERS INTO
C     THE ORDER SPECIFIED BY A VECTOR OF RANKS.
C
C     M01EAF IS DESIGNED TO BE USED TYPICALLY IN CONJUNCTION
C     WITH THE M01D- RANKING ROUTINES. AFTER ONE OF THE M01D-
C     ROUTINES HAS BEEN CALLED TO DETERMINE A VECTOR OF RANKS,
C     M01EAF CAN BE CALLED TO RE-ARRANGE A VECTOR OF REAL
C     NUMBERS INTO THE RANK ORDER. IF THE VECTOR OF RANKS HAS
C     BEEN GENERATED IN SOME OTHER WAY, THEN M01ZBF SHOULD BE
C     CALLED TO CHECK ITS VALIDITY BEFORE M01EAF IS CALLED.
C
C     WRITTEN BY N.M.MACLAREN, UNIVERSITY OF CAMBRIDGE.
C     REVISED BY NAG CENTRAL OFFICE.
C

M01EBF
      SUBROUTINE M01EBF(IV,M1,M2,IRANK,IFAIL)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C
C     M01EBF RE-ARRANGES A VECTOR OF INTEGER NUMBERS INTO
C     THE ORDER SPECIFIED BY A VECTOR OF RANKS.
C
C     M01EBF IS DESIGNED TO BE USED TYPICALLY IN CONJUNCTION
C     WITH THE M01D- RANKING ROUTINES. AFTER ONE OF THE M01D-
C     ROUTINES HAS BEEN CALLED TO DETERMINE A VECTOR OF RANKS,
C     M01EBF CAN BE CALLED TO RE-ARRANGE A VECTOR OF INTEGER
C     NUMBERS INTO THE RANK ORDER. IF THE VECTOR OF RANKS HAS
C     BEEN GENERATED IN SOME OTHER WAY, THEN M01ZBF SHOULD BE
C     CALLED TO CHECK ITS VALIDITY BEFORE M01EBF IS CALLED.
C
C     WRITTEN BY N.M.MACLAREN, UNIVERSITY OF CAMBRIDGE.
C     REVISED BY NAG CENTRAL OFFICE
C

M01ECF
      SUBROUTINE M01ECF(CH,M1,M2,IRANK,IFAIL)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C
C     M01ECF RE-ARRANGES A VECTOR OF CHARACTER DATA INTO
C     THE ORDER SPECIFIED BY A VECTOR OF RANKS.
C
C     M01ECF IS DESIGNED TO BE USED TYPICALLY IN CONJUNCTION
C     WITH THE M01D- RANKING ROUTINES. AFTER ONE OF THE M01D-
C     ROUTINES HAS BEEN CALLED TO DETERMINE A VECTOR OF RANKS,
C     M01ECF CAN BE CALLED TO RE-ARRANGE A VECTOR OF CHARACTER
C     DATA INTO THE RANK ORDER. IF THE VECTOR OF RANKS HAS
C     BEEN GENERATED IN SOME OTHER WAY, THEN M01ZBF SHOULD BE
C     CALLED TO CHECK ITS VALIDITY BEFORE M01ECF IS CALLED.
C
C     THE MAXIMUM PERMITTED LENGTH OF EACH ELEMENT OF THE ARRAY CH
C     IS DEFINED BY THE PARAMETER MAXLCH. THIS RESTRICTION IS
C     IMPOSED BY THE NEED TO SPECIFY A LENGTH FOR THE INTERNAL
C     CHARACTER VARIABLES A AND B.
C
C     WRITTEN BY NAG CENTRAL OFFICE
C

M01ZAF
      SUBROUTINE M01ZAF(IPERM,M1,M2,IFAIL)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C
C     M01ZAF INVERTS A PERMUTATION, AND HENCE CONVERTS A RANK VECTOR TO
C     AN INDEX VECTOR, OR VICE VERSA.
C
C     WRITTEN BY N.M.MACLAREN, UNIVERSITY OF CAMBRIDGE.
C     REVISED BY NAG CENTRAL OFFICE.
C

M01ZBF
      SUBROUTINE M01ZBF(IPERM,M1,M2,IFAIL)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C
C     M01ZBF CHECKS THE VALIDITY OF A PERMUTATION.
C
C     M01ZBF CHECKS THAT ELEMENTS M1 TO M2 OF IPERM CONTAIN A VALID
C     PERMUTATION OF THE INTEGERS M1 TO M2. THE CONTENTS OF IPERM ARE
C     UNCHANGED ON EXIT.
C
C     WRITTEN BY N.N.MACLAREN, UNIVERSITY OF CAMBRIDGE.
C     REVISED BY NAG CENTRAL OFFICE.
C

M01ZCF
      SUBROUTINE M01ZCF(IPERM,M1,M2,ICYCL,IFAIL)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C
C     M01ZCF DECOMPOSES A PERMUTATION INTO CYCLES, AS AN AID TO
C     RE-ORDERING RANKED DATA.
C
C     GIVEN A VECTOR IRANK WHICH SPECIFIES THE RANKS OF THE DATA
C     (AS GENERATED BY THE M01D- ROUTINES), M01ZCF GENERATES A NEW
C     VECTOR ICYCL, IN WHICH THE PERMUTATION IS REPRESENTED IN ITS
C     COMPONENT CYCLES, WITH THE FIRST ELEMENT IN EACH CYCLE
C     NEGATED. FOR EXAMPLE, THE PERMUTATION
C
C           5   7   4   2   1   6   3
C
C     IS COMPOSED OF THE CYCLES
C
C          (1   5) (2   7   3   4) (6)
C
C     AND THE VECTOR ICYCL GENERATED BY M01ZCF CONTAINS
C
C          -1   5  -2   7   3   4  -6
C
C     WRITTEN BY NAG CENTRAL OFFICE
C

P01ABF
      INTEGER FUNCTION P01ABF(IFAIL,IERROR,SRNAME,NREC,REC)
C     MARK 11.5(F77) RELEASE. NAG COPYRIGHT 1986.
C     MARK 13 REVISED. IER-621 (APR 1988).
C     MARK 13B REVISED. IER-668 (AUG 1988).
C
C     P01ABF is the error-handling routine for the NAG Library.
C
C     P01ABF either returns the value of IERROR through the routine
C     name (soft failure), or terminates execution of the program
C     (hard failure). Diagnostic messages may be output.
C
C     If IERROR = 0 (successful exit from the calling routine),
C     the value 0 is returned through the routine name, and no
C     message is output
C
C     If IERROR is non-zero (abnormal exit from the calling routine),
C     the action taken depends on the value of IFAIL.
C
C     IFAIL =  1: soft failure, silent exit (i.e. no messages are
C                 output)
C     IFAIL = -1: soft failure, noisy exit (i.e. messages are output)
C     IFAIL =-13: soft failure, noisy exit but standard messages from
C                 P01ABF are suppressed
C     IFAIL =  0: hard failure, noisy exit
C
C     For compatibility with certain routines included before Mark 12
C     P01ABF also allows an alternative specification of IFAIL in which
C     it is regarded as a decimal integer with least significant digits
C     cba. Then
C
C     a = 0: hard failure  a = 1: soft failure
C     b = 0: silent exit   b = 1: noisy exit
C
C     except that hard failure now always implies a noisy exit.
C
C     S.Hammarling, M.P.Hooper and J.J.du Croz, NAG Central Office.
C

S01BAF
      DOUBLE PRECISION FUNCTION S01BAF(X,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     Computes log(1+x) retaining full precision when x is small.
C     Following a suggestion of N.M.Temme, uses the Chebyshev expansion
C       log((1+p*p+2*p*z)/(1+p*p-2*p*z)) =
C         4 * SUM (k=0 to infinity) p**(2*k+1) * T(2*k+1)(z) / (2*k+1)
C     (Lyusternik et al, Handbook for Computing Elementary Functions,
C     Pergamon Press, 1965).
C     Equating (1+x) with (1+p*p+2*p*z)/(1+p*p-2*p*z), we get
C       z = x*(1+p*p)/(2*p*(x+2)).
C     Choosing p as (sqrt(sqrt(2))-1)/(sqrt(sqrt(2))+1) =
C     0.0864..., the expansion will converge with a very small number
C     of terms, and be valid in the range [1/sqrt(2)-1,sqrt(2)-1].
C     Outside this range, the standard Fortran log function is good
C     enough.
C
C     **************************************************************
C
C     TO EXTRACT THE CORRECT CODE FOR A PARTICULAR MACHINE-RANGE,
C     ACTIVATE THE STATEMENTS CONTAINED IN COMMENTS BEGINNING  CDD ,
C     WHERE  DD  IS THE APPROXIMATE NUMBER OF SIGNIFICANT DECIMAL
C     DIGITS REPRESENTED BY THE MACHINE
C     DELETE THE ILLEGAL DUMMY STATEMENT OF THE FORM
C     * EXPANSION (NNNN) *
C
C     **************************************************************
C

S01EAF
      COMPLEX*16  FUNCTION S01EAF(Z,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C     Returns exp(Z) for complex Z.

S07AAF
      DOUBLE PRECISION FUNCTION S07AAF(X,IFAIL)
C     MARK 5A REVISED  -  NAG COPYRIGHT 1976
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     TAN(X)
C

S09AAF
      DOUBLE PRECISION FUNCTION S09AAF(X,IFAIL)
C     MARK 5A REVISED - NAG COPYRIGHT 1976
C     MARK 6A REVISED  IER-94
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     ARCSIN(X)
C

S09ABF
      DOUBLE PRECISION FUNCTION S09ABF(X,IFAIL)
C     MARK 5A REVISED - NAG COPYRIGHT 1976
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     ARCCOS(X)
C

S10AAF
      DOUBLE PRECISION FUNCTION S10AAF(X,IFAIL)
C     MARK 5A REVISED - NAG COPYRIGHT 1976
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     TANH(X)
C

S10ABF
      DOUBLE PRECISION FUNCTION S10ABF(X,IFAIL)
C     MARK 5A REVISED - NAG COPYRIGHT 1976
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 14 REVISED. IER-749 (DEC 1989).
C     SINH(X)
C     **************************************************************
C
C     TO EXTRACT THE CORRECT CODE FOR A PARTICULAR MACHINE-RANGE,
C     ACTIVATE THE STATEMENTS CONTAINED IN COMMENTS BEGINNING  CDD ,
C     WHERE  DD  IS THE APPROXIMATE NUMBER OF SIGNIFICANT DECIMAL
C     DIGITS REPRESENTED BY THE MACHINE
C     DELETE THE ILLEGAL DUMMY STATEMENTS OF THE FORM
C     * EXPANSION (NNNN) *
C
C     ALSO INSERT APPROPRIATE DATA STATEMENTS TO DEFINE CONSTANTS
C     WHICH DEPEND ON THE RANGE OF NUMBERS REPRESENTED BY THE
C     MACHINE, RATHER THAN THE PRECISION (SUITABLE STATEMENTS FOR
C     SOME MACHINES ARE CONTAINED IN COMMENTS BEGINNING CRD WHERE
C     D IS A DIGIT WHICH SIMPLY DISTINGUISHES A GROUP OF MACHINES).
C     DELETE THE ILLEGAL DUMMY DATA STATEMENTS WITH VALUES WRITTEN
C     *VALUE*
C
C     **************************************************************
C

S10ACF
      DOUBLE PRECISION FUNCTION S10ACF(X,IFAIL)
C     MARK 5A REVISED - NAG COPYRIGHT 1976
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 14 REVISED. IER-750 (DEC 1989).
C     COSH(X)
C     **************************************************************
C
C     TO EXTRACT THE CORRECT CODE FOR A PARTICULAR MACHINE-RANGE,
C     ACTIVATE THE STATEMENTS CONTAINED IN COMMENTS BEGINNING  CDD ,
C     WHERE  DD  IS THE APPROXIMATE NUMBER OF SIGNIFICANT DECIMAL
C     DIGITS REPRESENTED BY THE MACHINE
C     DELETE THE ILLEGAL DUMMY STATEMENTS OF THE FORM
C     * EXPANSION (NNNN) *
C
C     ALSO INSERT APPROPRIATE DATA STATEMENTS TO DEFINE CONSTANTS
C     WHICH DEPEND ON THE RANGE OF NUMBERS REPRESENTED BY THE
C     MACHINE, RATHER THAN THE PRECISION (SUITABLE STATEMENTS FOR
C     SOME MACHINES ARE CONTAINED IN COMMENTS BEGINNING CRD WHERE
C     D IS A DIGIT WHICH SIMPLY DISTINGUISHES A GROUP OF MACHINES).
C     DELETE THE ILLEGAL DUMMY DATA STATEMENTS WITH VALUES WRITTEN
C     *VALUE*
C
C     **************************************************************
C

S11AAF
      DOUBLE PRECISION FUNCTION S11AAF(X,IFAIL)
C     MARK 5A REVISED - NAG COPYRIGHT 1976
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     ARCTANH(X)
C

S11ABF
      DOUBLE PRECISION FUNCTION S11ABF(X,IFAIL)
C     MARK 5A REVISED - NAG COPYRIGHT 1976
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     ARCSINH(X)
C

S11ACF
      DOUBLE PRECISION FUNCTION S11ACF(X,IFAIL)
C     MARK 5A REVISED - NAG COPYRIGHT 1976
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 16 REVISED. IER-1045 (JUN 1993).
C     ARCCOSH(X)
C

S13AAF
      DOUBLE PRECISION FUNCTION S13AAF(X,IFAIL)
C     MARK 5A REVISED - NAG COPYRIGHT 1976
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 14 REVISED. IER-751 (DEC 1989).
C     MARK 16 RE-ISSUE. NAG COPYRIGHT 1993.
C     EXPONENTIAL INTEGRAL E1(X)
C
C     **************************************************************
C
C     TO EXTRACT THE CORRECT CODE FOR A PARTICULAR MACHINE-RANGE,
C     ACTIVATE THE STATEMENTS CONTAINED IN COMMENTS BEGINNING  CDD ,
C     WHERE  DD  IS THE APPROXIMATE NUMBER OF SIGNIFICANT DECIMAL
C     DIGITS REPRESENTED BY THE MACHINE
C     DELETE THE ILLEGAL DUMMY STATEMENTS OF THE FORM
C     * EXPANSION (NNNN) *
C
C     ALSO INSERT APPROPRIATE DATA STATEMENTS TO DEFINE CONSTANTS
C     WHICH DEPEND ON THE RANGE OF NUMBERS REPRESENTED BY THE
C     MACHINE, RATHER THAN THE PRECISION (SUITABLE STATEMENTS FOR
C     SOME MACHINES ARE CONTAINED IN COMMENTS BEGINNING CRD WHERE
C     D IS A DIGIT WHICH SIMPLY DISTINGUISHES A GROUP OF MACHINES).
C     DELETE THE ILLEGAL DUMMY DATA STATEMENTS WITH VALUES WRITTEN
C     *VALUE*
C
C     **************************************************************

S13ACF
      DOUBLE PRECISION FUNCTION S13ACF(X,IFAIL)
C     MARK 5A REVISED - NAG COPYRIGHT 1976
C     MARK 5C REVISED
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     COSINE INTEGRAL  CI(X)
C

S13ADF
      DOUBLE PRECISION FUNCTION S13ADF(X,IFAIL)
C     MARK 5A REVISED - NAG COPYRIGHT 1976
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 14 REVISED. IER-752 (DEC 1989).
C     SINE INTEGRAL  SI(X)
C

S14AAF
      DOUBLE PRECISION FUNCTION S14AAF(X,IFAIL)
C     MARK 7 RELEASE. NAG COPYRIGHT 1978.
C     MARK 7C REVISED IER-184 (MAY 1979)
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     GAMMA FUNCTION
C
C     **************************************************************
C
C     TO EXTRACT THE CORRECT CODE FOR A PARTICULAR MACHINE-RANGE,
C     ACTIVATE THE STATEMENTS CONTAINED IN COMMENTS BEGINNING  CDD ,
C     WHERE  DD  IS THE APPROXIMATE NUMBER OF SIGNIFICANT DECIMAL
C     DIGITS REPRESENTED BY THE MACHINE
C     DELETE THE ILLEGAL DUMMY STATEMENTS OF THE FORM
C     * EXPANSION (NNNN) *
C
C     ALSO INSERT APPROPRIATE DATA STATEMENTS TO DEFINE CONSTANTS
C     WHICH DEPEND ON THE RANGE OF NUMBERS REPRESENTED BY THE
C     MACHINE, RATHER THAN THE PRECISION (SUITABLE STATEMENTS FOR
C     SOME MACHINES ARE CONTAINED IN COMMENTS BEGINNING CRD WHERE
C     D IS A DIGIT WHICH SIMPLY DISTINGUISHES A GROUP OF MACHINES).
C     DELETE THE ILLEGAL DUMMY DATA STATEMENTS WITH VALUES WRITTEN
C     *VALUE*
C
C     **************************************************************
C

S14ABF
      DOUBLE PRECISION FUNCTION S14ABF(X,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C        LNGAMMA(X) FUNCTION
C        ABRAMOWITZ AND STEGUN  CH.6
C
C     **************************************************************
C
C     TO EXTRACT THE CORRECT CODE FOR A PARTICULAR MACHINE-RANGE,
C     ACTIVATE THE STATEMENTS CONTAINED IN COMMENTS BEGINNING  CDD ,
C     WHERE  DD  IS THE APPROXIMATE NUMBER OF SIGNIFICANT DECIMAL
C     DIGITS REPRESENTED BY THE MACHINE
C     DELETE THE ILLEGAL DUMMY STATEMENTS OF THE FORM
C     * EXPANSION (NNNN) *
C
C     ALSO INSERT APPROPRIATE DATA STATEMENTS TO DEFINE CONSTANTS
C     WHICH DEPEND ON THE RANGE OF NUMBERS REPRESENTED BY THE
C     MACHINE, RATHER THAN THE PRECISION (SUITABLE STATEMENTS FOR
C     SOME MACHINES ARE CONTAINED IN COMMENTS BEGINNING CRD WHERE
C     D IS A DIGIT WHICH SIMPLY DISTINGUISHES A GROUP OF MACHINES).
C     DELETE THE ILLEGAL DUMMY DATA STATEMENTS WITH VALUES WRITTEN
C     *VALUE*
C
C     **************************************************************
C
C        IMPLEMENTATION DEPENDENT CONSTANTS
C
C        IF(X.LT.XSMALL)GAMMA(X)=1/X
C             I.E.   XSMALL*EULGAM.LE.XRELPR
C        LNGAM(XVBIG)=GBIG.LE.XOVFLO
C        LNR2PI=LN(SQRT(2*PI))
C        IF(X.GT.XBIG)LNGAM(X)=(X-0.5)LN(X)-X+LNR2PI
C

S14ACF
      DOUBLE PRECISION FUNCTION S14ACF(X,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C     Driver routine for S14ACZ.
C     Returns psi(X) - log(X).

S14ADF
      SUBROUTINE S14ADF(X,N,M,W,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C     Driver routine for S14ACZ.
C     Returns w(k,x) = ( (-1)**(k+1) * psi(x) SUP (k) ) / k! ,
C     where psi(x) SUP (k) is the kth derivative of psi(x),
C     for k = N, N+1, ... N + M - 1.

S14BAF
      SUBROUTINE S14BAF(A,X,TOL,P,Q,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.

S15ABF
      DOUBLE PRECISION FUNCTION S15ABF(X,IFAIL)
C     MARK 5A REVISED - NAG COPYRIGHT 1976
C     MARK 5C REVISED
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 14 REVISED. IER-753 (DEC 1989).
C     CUMULATIVE NORMAL DISTRIBUTION P(X)
C     ******************************************************************
C     TO SELECT THE CORRECT VALUE FOR A PARTICULAR MACHINE-RANGE,
C     ACTIVATE THE STATEMENT CONTAINED IN A COMMENT BEGINNING  CDD ,
C     WHERE  DD  IS THE APPROXIMATE NUMBER OF SIGNIFICANT DECIMAL
C     DIGITS REPRESENTED BY THE MACHINE.
C     DELETE THE ILLEGAL DUMMY STATEMENT OF THE FORM
C     * EXPANSION (DATA) *
C     ******************************************************************
C

S15ACF
      DOUBLE PRECISION FUNCTION S15ACF(X,IFAIL)
C     MARK 5A REVISED - NAG COPYRIGHT 1976
C     MARK 5C REVISED
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 14 REVISED. IER-754 (DEC 1989).
C     COMPLEMENT OF CUMULATIVE NORMAL DISTRIBUTION Q(X)
C     ******************************************************************
C     TO SELECT THE CORRECT VALUE FOR A PARTICULAR MACHINE-RANGE,
C     ACTIVATE THE STATEMENT CONTAINED IN A COMMENT BEGINNING  CDD ,
C     WHERE  DD  IS THE APPROXIMATE NUMBER OF SIGNIFICANT DECIMAL
C     DIGITS REPRESENTED BY THE MACHINE.
C     DELETE THE ILLEGAL DUMMY STATEMENT OF THE FORM
C     * EXPANSION (DATA) *
C     ******************************************************************
C

S15ADF
      DOUBLE PRECISION FUNCTION S15ADF(X,IFAIL)
C     MARK 5A REVISED - NAG COPYRIGHT 1976
C     MARK 5C REVISED
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     COMPLEMENT OF ERROR FUNCTION ERFC(X)
C

S15AEF
      DOUBLE PRECISION FUNCTION S15AEF(X,IFAIL)
C     MARK 4 RELEASE NAG COPYRIGHT 1974.
C     MARK 4.5 REVISED
C     MARK 8 REVISED. IER-221 (MAR 1980)
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 14 REVISED. IER-755 (DEC 1989).
C     ERF(X)
C
C     **************************************************************
C
C     TO EXTRACT THE CORRECT CODE FOR A PARTICULAR MACHINE-RANGE,
C     ACTIVATE THE STATEMENTS CONTAINED IN COMMENTS BEGINNING  CDD ,
C     WHERE  DD  IS THE APPROXIMATE NUMBER OF SIGNIFICANT DECIMAL
C     DIGITS REPRESENTED BY THE MACHINE
C     DELETE THE ILLEGAL DUMMY STATEMENT OF THE FORM
C     * EXPANSION (DATA) *
C
C     **************************************************************

S15AFF
      DOUBLE PRECISION FUNCTION S15AFF(X,IFAIL)
C     MARK 7 RELEASE. NAG COPYRIGHT 1978.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 14 REVISED. IER-756 (DEC 1989).
C     DAWSONS INTEGRAL
C
C     **************************************************************
C
C     TO EXTRACT THE CORRECT CODE FOR A PARTICULAR MACHINE-RANGE,
C     ACTIVATE THE STATEMENTS CONTAINED IN COMMENTS BEGINNING  CDD ,
C     WHERE  DD  IS THE APPROXIMATE NUMBER OF SIGNIFICANT DECIMAL
C     DIGITS REPRESENTED BY THE MACHINE
C     DELETE THE ILLEGAL DUMMY STATEMENTS OF THE FORM
C     * EXPANSION (NNNN) *
C
C     ALSO INSERT APPROPRIATE DATA STATEMENTS TO DEFINE CONSTANTS
C     WHICH DEPEND ON THE RANGE OF NUMBERS REPRESENTED BY THE
C     MACHINE, RATHER THAN THE PRECISION (SUITABLE STATEMENTS FOR
C     SOME MACHINES ARE CONTAINED IN COMMENTS BEGINNING CRD WHERE
C     D IS A DIGIT WHICH SIMPLY DISTINGUISHES A GROUP OF MACHINES).
C     DELETE THE ILLEGAL DUMMY DATA STATEMENTS WITH VALUES WRITTEN
C     *VALUE*
C
C     **************************************************************
C

S15DDF
      COMPLEX*16  FUNCTION S15DDF(Z,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C     Evaluates the function w(z) = exp(-z*z)*erfc(-iz), for
C     complex z. Derived from ACM Algorithm 363. See W.Gautschi,
C     Efficient Computation of the Complex Error Function, SIAM
C     J. Numer. Anal. 7, 1970, pp 187-198.

S17ACF
      DOUBLE PRECISION FUNCTION S17ACF(X,IFAIL)
C     MARK 7 RELEASE. NAG COPYRIGHT 1978.
C     MARK 7C REVISED IER-185 (MAY 1979)
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     BESSEL FUNCTION Y0(X)
C
C     **************************************************************
C
C     TO EXTRACT THE CORRECT CODE FOR A PARTICULAR MACHINE-RANGE,
C     ACTIVATE THE STATEMENTS CONTAINED IN COMMENTS BEGINNING  CDD ,
C     WHERE  DD  IS THE APPROXIMATE NUMBER OF SIGNIFICANT DECIMAL
C     DIGITS REPRESENTED BY THE MACHINE
C     DELETE THE ILLEGAL DUMMY STATEMENTS OF THE FORM
C     * EXPANSION (NNNN) *
C
C     NOTE - THE VALUE OF THE CONSTANT XBIG (DEFINED IN A DATA
C     STATEMENT) SHOULD BE REDUCED IF NECESSARY TO ENSURE THAT SIN
C     AND COS WILL RETURN A RESULT WITHOUT AN EXECUTION ERROR FOR
C     ALL ARGUMENTS X SUCH THAT ABS(X) .LE. XBIG
C
C     **************************************************************
C

S17ADF
      DOUBLE PRECISION FUNCTION S17ADF(X,IFAIL)
C     MARK 7 RELEASE. NAG COPYRIGHT 1978.
C     MARK 7C REVISED IER-185 (MAY 1979)
C     MARK 7D REVISED IER-196 (JUL 1979)
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 14 REVISED. IER-757 (DEC 1989).
C     BESSEL FUNCTION Y1(X)
C
C     **************************************************************
C
C     TO EXTRACT THE CORRECT CODE FOR A PARTICULAR MACHINE-RANGE,
C     ACTIVATE THE STATEMENTS CONTAINED IN COMMENTS BEGINNING  CDD ,
C     WHERE  DD  IS THE APPROXIMATE NUMBER OF SIGNIFICANT DECIMAL
C     DIGITS REPRESENTED BY THE MACHINE
C     DELETE THE ILLEGAL DUMMY STATEMENTS OF THE FORM
C     * EXPANSION (NNNN) *
C
C     ALSO INSERT APPROPRIATE DATA STATEMENTS TO DEFINE CONSTANTS
C     WHICH DEPEND ON THE RANGE OF NUMBERS REPRESENTED BY THE
C     MACHINE, RATHER THAN THE PRECISION (SUITABLE STATEMENTS FOR
C     SOME MACHINES ARE CONTAINED IN COMMENTS BEGINNING CRD WHERE
C     D IS A DIGIT WHICH SIMPLY DISTINGUISHES A GROUP OF MACHINES).
C     DELETE THE ILLEGAL DUMMY DATA STATEMENTS WITH VALUES WRITTEN
C     *VALUE*
C
C     NOTE - THE VALUE OF THE CONSTANT XBIG (DEFINED IN A DATA
C     STATEMENT) SHOULD BE REDUCED IF NECESSARY TO ENSURE THAT SIN
C     AND COS WILL RETURN A RESULT WITHOUT AN EXECUTION ERROR FOR
C     ALL ARGUMENTS X SUCH THAT ABS(X) .LE. XBIG
C
C     **************************************************************
C

S17AEF
      DOUBLE PRECISION FUNCTION S17AEF(X,IFAIL)
C     MARK 7 RELEASE. NAG COPYRIGHT 1978.
C     MARK 7C REVISED IER-185 (MAY 1979)
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     BESSEL FUNCTION J0(X)
C
C     **************************************************************
C
C     TO EXTRACT THE CORRECT CODE FOR A PARTICULAR MACHINE-RANGE,
C     ACTIVATE THE STATEMENTS CONTAINED IN COMMENTS BEGINNING  CDD ,
C     WHERE  DD  IS THE APPROXIMATE NUMBER OF SIGNIFICANT DECIMAL
C     DIGITS REPRESENTED BY THE MACHINE
C     DELETE THE ILLEGAL DUMMY STATEMENTS OF THE FORM
C     * EXPANSION (NNNN) *
C
C     NOTE - THE VALUE OF THE CONSTANT XBIG (DEFINED IN A DATA
C     STATEMENT) SHOULD BE REDUCED IF NECESSARY TO ENSURE THAT SIN
C     AND COS WILL RETURN A RESULT WITHOUT AN EXECUTION ERROR FOR
C     ALL ARGUMENTS X SUCH THAT ABS(X) .LE. XBIG
C
C     **************************************************************
C

S17AFF
      DOUBLE PRECISION FUNCTION S17AFF(X,IFAIL)
C     MARK 7 RELEASE. NAG COPYRIGHT 1978.
C     MARK 7C REVISED IER-185 (MAY 1979)
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 14 REVISED. IER-758 (DEC 1989).
C     BESSEL FUNCTION J1(X)
C
C     **************************************************************
C
C     TO EXTRACT THE CORRECT CODE FOR A PARTICULAR MACHINE-RANGE,
C     ACTIVATE THE STATEMENTS CONTAINED IN COMMENTS BEGINNING  CDD ,
C     WHERE  DD  IS THE APPROXIMATE NUMBER OF SIGNIFICANT DECIMAL
C     DIGITS REPRESENTED BY THE MACHINE
C     DELETE THE ILLEGAL DUMMY STATEMENTS OF THE FORM
C     * EXPANSION (NNNN) *
C
C     NOTE - THE VALUE OF THE CONSTANT XBIG (DEFINED IN A DATA
C     STATEMENT) SHOULD BE REDUCED IF NECESSARY TO ENSURE THAT SIN
C     AND COS WILL RETURN A RESULT WITHOUT AN EXECUTION ERROR FOR
C     ALL ARGUMENTS X SUCH THAT ABS(X) .LE. XBIG
C
C     **************************************************************
C

S17AGF
      DOUBLE PRECISION FUNCTION S17AGF(X,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 8A REVISED. IER-263 (AUG 1980)
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C
C     AIRY FUNCTION AI(X)
C
C     **************************************************************
C
C     TO EXTRACT THE CORRECT CODE FOR A PARTICULAR MACHINE-RANGE,
C     ACTIVATE THE STATEMENTS CONTAINED IN COMMENTS BEGINNING  CDD ,
C     WHERE  DD  IS THE APPROXIMATE NUMBER OF SIGNIFICANT DECIMAL
C     DIGITS REPRESENTED BY THE MACHINE
C     DELETE THE ILLEGAL DUMMY STATEMENTS OF THE FORM
C     * EXPANSION (NNNN) *
C
C     ALSO INSERT APPROPRIATE DATA STATEMENTS TO DEFINE CONSTANTS
C     WHICH DEPEND ON THE RANGE OF NUMBERS REPRESENTED BY THE
C     MACHINE, RATHER THAN THE PRECISION (SUITABLE STATEMENTS FOR
C     SOME MACHINES ARE CONTAINED IN COMMENTS BEGINNING CRD WHERE
C     D IS A DIGIT WHICH SIMPLY DISTINGUISHES A GROUP OF MACHINES).
C     DELETE THE ILLEGAL DUMMY DATA STATEMENTS WITH VALUES WRITTEN
C     *VALUE*
C
C     **************************************************************
C

S17AHF
      DOUBLE PRECISION FUNCTION S17AHF(X,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 8A REVISED. IER-263 (AUG 1980)
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C
C     AIRY FUNCTION BI(X)
C
C     **************************************************************
C
C     TO EXTRACT THE CORRECT CODE FOR A PARTICULAR MACHINE-RANGE,
C     ACTIVATE THE STATEMENTS CONTAINED IN COMMENTS BEGINNING  CDD ,
C     WHERE  DD  IS THE APPROXIMATE NUMBER OF SIGNIFICANT DECIMAL
C     DIGITS REPRESENTED BY THE MACHINE
C     DELETE THE ILLEGAL DUMMY STATEMENTS OF THE FORM
C     * EXPANSION (NNNN) *
C
C     ALSO INSERT APPROPRIATE DATA STATEMENTS TO DEFINE CONSTANTS
C     WHICH DEPEND ON THE RANGE OF NUMBERS REPRESENTED BY THE
C     MACHINE, RATHER THAN THE PRECISION (SUITABLE STATEMENTS FOR
C     SOME MACHINES ARE CONTAINED IN COMMENTS BEGINNING CRD WHERE
C     D IS A DIGIT WHICH SIMPLY DISTINGUISHES A GROUP OF MACHINES).
C     DELETE THE ILLEGAL DUMMY DATA STATEMENTS WITH VALUES WRITTEN
C     *VALUE*
C
C     **************************************************************
C

S17AJF
      DOUBLE PRECISION FUNCTION S17AJF(X,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 8A REVISED. IER-263 (AUG 1980)
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C
C     AIRY FUNCTION AIP(X)
C
C     **************************************************************
C
C     TO EXTRACT THE CORRECT CODE FOR A PARTICULAR MACHINE-RANGE,
C     ACTIVATE THE STATEMENTS CONTAINED IN COMMENTS BEGINNING  CDD ,
C     WHERE  DD  IS THE APPROXIMATE NUMBER OF SIGNIFICANT DECIMAL
C     DIGITS REPRESENTED BY THE MACHINE
C     DELETE THE ILLEGAL DUMMY STATEMENTS OF THE FORM
C     * EXPANSION (NNNN) *
C
C     ALSO INSERT APPROPRIATE DATA STATEMENTS TO DEFINE CONSTANTS
C     WHICH DEPEND ON THE RANGE OF NUMBERS REPRESENTED BY THE
C     MACHINE, RATHER THAN THE PRECISION (SUITABLE STATEMENTS FOR
C     SOME MACHINES ARE CONTAINED IN COMMENTS BEGINNING CRD WHERE
C     D IS A DIGIT WHICH SIMPLY DISTINGUISHES A GROUP OF MACHINES).
C     DELETE THE ILLEGAL DUMMY DATA STATEMENTS WITH VALUES WRITTEN
C     *VALUE*
C
C     **************************************************************
C

S17AKF
      DOUBLE PRECISION FUNCTION S17AKF(X,IFAIL)
C     MARK 8 RELEASE. NAG COPYRIGHT 1979.
C     MARK 8A REVISED. IER-263 (AUG 1980)
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 13 REVISED. USE OF MARK 12 X02 FUNCTIONS (APR 1988).
C
C     AIRY FUNCTION BIP(X)
C
C     **************************************************************
C
C     TO EXTRACT THE CORRECT CODE FOR A PARTICULAR MACHINE-RANGE,
C     ACTIVATE THE STATEMENTS CONTAINED IN COMMENTS BEGINNING  CDD ,
C     WHERE  DD  IS THE APPROXIMATE NUMBER OF SIGNIFICANT DECIMAL
C     DIGITS REPRESENTED BY THE MACHINE
C     DELETE THE ILLEGAL DUMMY STATEMENTS OF THE FORM
C     * EXPANSION (NNNN) *
C
C     ALSO INSERT APPROPRIATE DATA STATEMENTS TO DEFINE CONSTANTS
C     WHICH DEPEND ON THE RANGE OF NUMBERS REPRESENTED BY THE
C     MACHINE, RATHER THAN THE PRECISION (SUITABLE STATEMENTS FOR
C     SOME MACHINES ARE CONTAINED IN COMMENTS BEGINNING CRD WHERE
C     D IS A DIGIT WHICH SIMPLY DISTINGUISHES A GROUP OF MACHINES).
C     DELETE THE ILLEGAL DUMMY DATA STATEMENTS WITH VALUES WRITTEN
C     *VALUE*
C
C     **************************************************************
C

S17DCF
      SUBROUTINE S17DCF(FNU,Z,N,SCALE,CY,NZ,CWRK,IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.
C     MARK 14 REVISED. IER-759 (DEC 1989).
C
C     Original name: CBESY
C
C     PURPOSE  TO COMPUTE THE Y-BESSEL FUNCTION OF A COMPLEX ARGUMENT
C     DESCRIPTION
C     ===========
C
C         ON SCALE='U', S17DCF COMPUTES AN N MEMBER SEQUENCE OF COMPLEX
C         BESSEL FUNCTIONS CY(I)=Y(FNU+I-1,Z) FOR REAL, NONNEGATIVE
C         ORDERS FNU+I-1, I=1,...,N AND COMPLEX Z IN THE CUT PLANE
C         -PI.LT.ARG(Z).LE.PI. ON SCALE='S', S17DCF RETURNS THE SCALED
C         FUNCTIONS
C
C         CY(I)=EXP(-ABS(Y))*Y(FNU+I-1,Z)   I = 1,...,N , Y=AIMAG(Z)
C
C         WHICH REMOVE THE EXPONENTIAL GROWTH IN BOTH THE UPPER AND
C         LOWER HALF PLANES FOR Z TO INFINITY. DEFINITIONS AND NOTATION
C         ARE FOUND IN THE NBS HANDBOOK OF MATHEMATICAL FUNCTIONS
C         (REF. 1).
C
C         INPUT
C           Z      - Z=CMPLX(X,Y), Z.NE.CMPLX(0.,0.),-PI.LT.ARG(Z).LE.PI
C           FNU    - ORDER OF INITIAL Y FUNCTION, FNU.GE.0.0E0
C           SCALE  - A PARAMETER TO INDICATE THE SCALING OPTION
C                   SCALE= 'U' OR 'u' RETURNS
C                             CY(I)=Y(FNU+I-1,Z), I=1,...,N
C                        = 'S' OR 's' RETURNS
C                             CY(I)=Y(FNU+I-1,Z)*EXP(-ABS(Y)), I=1,...,N
C                             WHERE Y=AIMAG(Z)
C           N      - NUMBER OF MEMBERS OF THE SEQUENCE, N.GE.1
C           CWRK   - A COMPLEX WORK VECTOR OF DIMENSION AT LEAST N
C
C         OUTPUT
C           CY     - A COMPLEX VECTOR WHOSE FIRST N COMPONENTS CONTAIN
C                    VALUES FOR THE SEQUENCE
C                    CY(I)=Y(FNU+I-1,Z)  OR
C                    CY(I)=Y(FNU+I-1,Z)*EXP(-ABS(Y))  I=1,...,N
C                    DEPENDING ON PARAMETER SCALE.
C           NZ     - NZ=0 , A NORMAL RETURN
C                    NZ.GT.0 , NZ COMPONENTS OF CY SET TO ZERO DUE TO
C                    UNDERFLOW (GENERALLY ON SCALE='S')
C           IFAIL  - ERROR FLAG
C                    IFAIL=0, NORMAL RETURN - COMPUTATION COMPLETED
C                    IFAIL=1, INPUT ERROR   - NO COMPUTATION
C                    IFAIL=2, OVERFLOW      - NO COMPUTATION, CABS(Z) IS
C                             TOO SMALL
C                    IFAIL=3, OVERFLOW      - NO COMPUTATION, FNU+N-1 IS
C                             TOO LARGE
C                    IFAIL=4, CABS(Z) OR FNU+N-1 LARGE - COMPUTATION DON
C                             BUT LOSSES OF SIGNIFICANCE BY ARGUMENT
C                             REDUCTION PRODUCE LESS THAN HALF OF MACHIN
C                             ACCURACY
C                    IFAIL=5, CABS(Z) OR FNU+N-1 TOO LARGE - NO COMPUTA-
C                             TION BECAUSE OF COMPLETE LOSSES OF SIGNIFI
C                             CANCE BY ARGUMENT REDUCTION
C                    IFAIL=6, ERROR              - NO COMPUTATION,
C                             ALGORITHM TERMINATION CONDITION NOT MET
C
C     LONG DESCRIPTION
C     ================
C
C         THE COMPUTATION IS CARRIED OUT BY THE FORMULA
C
C         Y(FNU,Z)=0.5*(H(1,FNU,Z)-H(2,FNU,Z))/I
C
C         WHERE I**2 = -1 AND THE HANKEL BESSEL FUNCTIONS H(1,FNU,Z)
C         AND H(2,FNU,Z) ARE CALCULATED IN S17DLF.
C
C         FOR NEGATIVE ORDERS,THE FORMULA
C
C              Y(-FNU,Z) = Y(FNU,Z)*COS(PI*FNU) + J(FNU,Z)*SIN(PI*FNU)
C
C         CAN BE USED. HOWEVER,FOR LARGE ORDERS CLOSE TO HALF ODD
C         INTEGERS THE FUNCTION CHANGES RADICALLY. WHEN FNU IS A LARGE
C         POSITIVE HALF ODD INTEGER,THE MAGNITUDE OF Y(-FNU,Z)=J(FNU,Z)*
C         SIN(PI*FNU) IS A LARGE NEGATIVE POWER OF TEN. BUT WHEN FNU IS
C         NOT A HALF ODD INTEGER, Y(FNU,Z) DOMINATES IN MAGNITUDE WITH A
C         LARGE POSITIVE POWER OF TEN AND THE MOST THAT THE SECOND TERM
C         CAN BE REDUCED IS BY UNIT ROUNDOFF FROM THE COEFFICIENT. THUS,
C         WIDE CHANGES CAN OCCUR WITHIN UNIT ROUNDOFF OF A LARGE HALF
C         ODD INTEGER. HERE, LARGE MEANS FNU.GT.CABS(Z).
C
C         IN MOST COMPLEX VARIABLE COMPUTATION, ONE MUST EVALUATE ELE-
C         MENTARY FUNCTIONS. WHEN THE MAGNITUDE OF Z OR FNU+N-1 IS
C         LARGE, LOSSES OF SIGNIFICANCE BY ARGUMENT REDUCTION OCCUR.
C         CONSEQUENTLY, IF EITHER ONE EXCEEDS U1=SQRT(0.5/UR), THEN
C         LOSSES EXCEEDING HALF PRECISION ARE LIKELY AND AN ERROR FLAG
C         IFAIL=4 IS TRIGGERED WHERE UR=X02AJF()=UNIT ROUNDOFF. ALSO
C         IF EITHER IS LARGER THAN U2=0.5/UR, THEN ALL SIGNIFICANCE IS
C         LOST AND IFAIL=5. IN ORDER TO USE THE INT FUNCTION, ARGUMENTS
C         MUST BE FURTHER RESTRICTED NOT TO EXCEED THE LARGEST MACHINE
C         INTEGER, U3=X02BBF(). THUS, THE MAGNITUDE OF Z AND FNU+N-1 IS
C         RESTRICTED BY MIN(U2,U3). ON 32 BIT MACHINES, U1,U2, AND U3
C         ARE APPROXIMATELY 2.0E+3, 4.2E+6, 2.1E+9 IN SINGLE PRECISION
C         ARITHMETIC AND 1.3E+8, 1.8E+16, 2.1E+9 IN DOUBLE PRECISION
C         ARITHMETIC RESPECTIVELY. THIS MAKES U2 AND U3 LIMITING IN
C         THEIR RESPECTIVE ARITHMETICS. THIS MEANS THAT ONE CAN EXPECT
C         TO RETAIN, IN THE WORST CASES ON 32 BIT MACHINES, NO DIGITS
C         IN SINGLE AND ONLY 7 DIGITS IN DOUBLE PRECISION ARITHMETIC.
C         SIMILAR CONSIDERATIONS HOLD FOR OTHER MACHINES.
C
C         THE APPROXIMATE RELATIVE ERROR IN THE MAGNITUDE OF A COMPLEX
C         BESSEL FUNCTION CAN BE EXPRESSED BY P*10**S WHERE P=MAX(UNIT
C         ROUNDOFF,1.0E-18) IS THE NOMINAL PRECISION AND 10**S REPRE-
C         SENTS THE INCREASE IN ERROR DUE TO ARGUMENT REDUCTION IN THE
C         ELEMENTARY FUNCTIONS. HERE, S=MAX(1,ABS(LOG10(CABS(Z))),
C         ABS(LOG10(FNU))) APPROXIMATELY (I.E. S=MAX(1,ABS(EXPONENT OF
C         CABS(Z),ABS(EXPONENT OF FNU)) ). HOWEVER, THE PHASE ANGLE MAY
C         HAVE ONLY ABSOLUTE ACCURACY. THIS IS MOST LIKELY TO OCCUR WHEN
C         ONE COMPONENT (IN ABSOLUTE VALUE) IS LARGER THAN THE OTHER BY
C         SEVERAL ORDERS OF MAGNITUDE. IF ONE COMPONENT IS 10**K LARGER
C         THAN THE OTHER, THEN ONE CAN EXPECT ONLY MAX(ABS(LOG10(P))-K,
C         0) SIGNIFICANT DIGITS; OR, STATED ANOTHER WAY, WHEN K EXCEEDS
C         THE EXPONENT OF P, NO SIGNIFICANT DIGITS REMAIN IN THE SMALLER
C         COMPONENT. HOWEVER, THE PHASE ANGLE RETAINS ABSOLUTE ACCURACY
C         BECAUSE, IN COMPLEX ARITHMETIC WITH PRECISION P, THE SMALLER
C         COMPONENT WILL NOT (AS A RULE) DECREASE BELOW P TIMES THE
C         MAGNITUDE OF THE LARGER COMPONENT. IN THESE EXTREME CASES,
C         THE PRINCIPAL PHASE ANGLE IS ON THE ORDER OF +P, -P, PI/2-P,
C         OR -PI/2+P.
C
C     REFERENCES
C     ==========
C               HANDBOOK OF MATHEMATICAL FUNCTIONS BY M. ABRAMOWITZ
C                 AND I. A. STEGUN, NBS AMS SERIES 55, U.S. DEPT. OF
C                 COMMERCE, 1955.
C
C               COMPUTATION OF BESSEL FUNCTIONS OF COMPLEX ARGUMENT
C                 BY D. E. AMOS, SAND83-0083, MAY, 1983.
C
C               COMPUTATION OF BESSEL FUNCTIONS OF COMPLEX ARGUMENT
C                 AND LARGE ORDER BY D. E. AMOS, SAND83-0643, MAY, 1983
C
C               A SUBROUTINE PACKAGE FOR BESSEL FUNCTIONS OF A COMPLEX
C                 ARGUMENT AND NONNEGATIVE ORDER BY D. E. AMOS, SAND85-
C                 1018, MAY, 1985
C
C               A PORTABLE PACKAGE FOR BESSEL FUNCTIONS OF A COMPLEX
C                 ARGUMENT AND NONNEGATIVE ORDER BY D. E. AMOS, TRANS.
C                 MATH. SOFTWARE, 1986
C
C     DATE WRITTEN   830501   (YYMMDD)
C     REVISION DATE  830501   (YYMMDD)
C     AUTHOR  AMOS, DONALD E., SANDIA NATIONAL LABORATORIES
C

S17DEF
      SUBROUTINE S17DEF(FNU,Z,N,SCALE,CY,NZ,IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.
C     MARK 14 REVISED. IER-760 (DEC 1989).
C
C     Original name: CBESJ
C
C     PURPOSE  TO COMPUTE THE J-BESSEL FUNCTION OF A COMPLEX ARGUMENT
C
C     DESCRIPTION
C     ===========
C
C         ON SCALE='U', S17DEF COMPUTES AN N MEMBER  SEQUENCE OF COMPLEX
C         BESSEL FUNCTIONS CY(I)=J(FNU+I-1,Z) FOR REAL, NONNEGATIVE
C         ORDERS FNU+I-1, I=1,...,N AND COMPLEX Z IN THE CUT PLANE
C         -PI.LT.ARG(Z).LE.PI. ON SCALE='S', S17DEF RETURNS THE SCALED
C         FUNCTIONS
C
C         CY(I)=EXP(-ABS(Y))*J(FNU+I-1,Z)   I = 1,...,N , Y=AIMAG(Z)
C
C         WHICH REMOVE THE EXPONENTIAL GROWTH IN BOTH THE UPPER AND
C         LOWER HALF PLANES FOR Z TO INFINITY. DEFINITIONS AND NOTATION
C         ARE FOUND IN THE NBS HANDBOOK OF MATHEMATICAL FUNCTIONS
C         (REF. 1).
C
C         INPUT
C           Z      - Z=CMPLX(X,Y),  -PI.LT.ARG(Z).LE.PI
C           FNU    - ORDER OF INITIAL J FUNCTION, FNU.GE.0.0E0
C           SCALE  - A PARAMETER TO INDICATE THE SCALING OPTION
C                    SCALE= 'U' OR 'u' RETURNS
C                              CY(I)=J(FNU+I-1,Z), I=1,...,N
C                         = 'S' OR 's' RETURNS
C                              CY(I)=J(FNU+I-1,Z)*EXP(-ABS(Y)), I=1,...
C           N      - NUMBER OF MEMBERS OF THE SEQUENCE, N.GE.1
C
C         OUTPUT
C           CY     - A COMPLEX VECTOR WHOSE FIRST N COMPONENTS CONTAIN
C                    VALUES FOR THE SEQUENCE
C                    CY(I)=J(FNU+I-1,Z)  OR
C                    CY(I)=J(FNU+I-1,Z)*EXP(-ABS(Y))  I=1,...,N
C                    DEPENDING ON SCALE, Y=AIMAG(Z).
C           NZ     - NUMBER OF COMPONENTS SET TO ZERO DUE TO UNDERFLOW,
C                    NZ= 0   , NORMAL RETURN
C                    NZ.GT.0 , LAST NZ COMPONENTS OF CY SET TO ZERO
C                              DUE TO UNDERFLOW, CY(I)=CMPLX(0.0,0.0),
C                              I = N-NZ+1,...,N
C           IFAIL  - ERROR FLAG
C                   IFAIL=0, NORMAL RETURN - COMPUTATION COMPLETED
C                   IFAIL=1, INPUT ERROR   - NO COMPUTATION
C                   IFAIL=2, OVERFLOW      - NO COMPUTATION, AIMAG(Z)
C                            TOO LARGE ON SCALE='U'
C                   IFAIL=3, CABS(Z) OR FNU+N-1 LARGE - COMPUTATION DONE
C                            BUT LOSSES OF SIGNIFCANCE BY ARGUMENT
C                            REDUCTION PRODUCE LESS THAN HALF OF MACHINE
C                            ACCURACY
C                   IFAIL=4, CABS(Z) OR FNU+N-1 TOO LARGE - NO COMPUTA-
C                            TION BECAUSE OF COMPLETE LOSSES OF SIGNIFI-
C                            CANCE BY ARGUMENT REDUCTION
C                   IFAIL=5, ERROR              - NO COMPUTATION,
C                            ALGORITHM TERMINATION CONDITION NOT MET
C
C     LONG DESCRIPTION
C     ================
C
C         THE COMPUTATION IS CARRIED OUT BY THE FORMULA
C
C         J(FNU,Z)=EXP( FNU*PI*I/2)*I(FNU,-I*Z)    AIMAG(Z).GE.0.0
C
C         J(FNU,Z)=EXP(-FNU*PI*I/2)*I(FNU, I*Z)    AIMAG(Z).LT.0.0
C
C         WHERE I**2 = -1 AND I(FNU,Z) IS THE I BESSEL FUNCTION.
C
C         FOR NEGATIVE ORDERS,THE FORMULA
C
C              J(-FNU,Z) = J(FNU,Z)*COS(PI*FNU) - Y(FNU,Z)*SIN(PI*FNU)
C
C         CAN BE USED. HOWEVER,FOR LARGE ORDERS CLOSE TO INTEGERS, THE
C         THE FUNCTION CHANGES RADICALLY. WHEN FNU IS A LARGE POSITIVE
C         INTEGER,THE MAGNITUDE OF J(-FNU,Z)=J(FNU,Z)*COS(PI*FNU) IS A
C         LARGE NEGATIVE POWER OF TEN. BUT WHEN FNU IS NOT AN INTEGER,
C         Y(FNU,Z) DOMINATES IN MAGNITUDE WITH A LARGE POSITIVE POWER OF
C         TEN AND THE MOST THAT THE SECOND TERM CAN BE REDUCED IS BY
C         UNIT ROUNDOFF FROM THE COEFFICIENT. THUS, WIDE CHANGES CAN
C         OCCUR WITHIN UNIT ROUNDOFF OF A LARGE INTEGER FOR FNU. HERE,
C         LARGE MEANS FNU.GT.CABS(Z).
C
C         IN MOST COMPLEX VARIABLE COMPUTATION, ONE MUST EVALUATE ELE-
C         MENTARY FUNCTIONS. WHEN THE MAGNITUDE OF Z OR FNU+N-1 IS
C         LARGE, LOSSES OF SIGNIFICANCE BY ARGUMENT REDUCTION OCCUR.
C         CONSEQUENTLY, IF EITHER ONE EXCEEDS U1=SQRT(0.5/UR), THEN
C         LOSSES EXCEEDING HALF PRECISION ARE LIKELY AND AN ERROR FLAG
C         IFAIL=3 IS TRIGGERED WHERE UR=X02AJF()=UNIT ROUNDOFF. ALSO
C         IF EITHER IS LARGER THAN U2=0.5/UR, THEN ALL SIGNIFICANCE IS
C         LOST AND IFAIL=4. IN ORDER TO USE THE INT FUNCTION, ARGUMENTS
C         MUST BE FURTHER RESTRICTED NOT TO EXCEED THE LARGEST MACHINE
C         INTEGER, U3=X02BBF(). THUS, THE MAGNITUDE OF Z AND FNU+N-1 IS
C         RESTRICTED BY MIN(U2,U3). ON 32 BIT MACHINES, U1,U2, AND U3
C         ARE APPROXIMATELY 2.0E+3, 4.2E+6, 2.1E+9 IN SINGLE PRECISION
C         ARITHMETIC AND 1.3E+8, 1.8E+16, 2.1E+9 IN DOUBLE PRECISION
C         ARITHMETIC RESPECTIVELY. THIS MAKES U2 AND U3 LIMITING IN
C         THEIR RESPECTIVE ARITHMETICS. THIS MEANS THAT ONE CAN EXPECT
C         TO RETAIN, IN THE WORST CASES ON 32 BIT MACHINES, NO DIGITS
C         IN SINGLE AND ONLY 7 DIGITS IN DOUBLE PRECISION ARITHMETIC.
C         SIMILAR CONSIDERATIONS HOLD FOR OTHER MACHINES.
C
C         THE APPROXIMATE RELATIVE ERROR IN THE MAGNITUDE OF A COMPLEX
C         BESSEL FUNCTION CAN BE EXPRESSED BY P*10**S WHERE P=MAX(UNIT
C         ROUNDOFF,1.0E-18) IS THE NOMINAL PRECISION AND 10**S REPRE-
C         SENTS THE INCREASE IN ERROR DUE TO ARGUMENT REDUCTION IN THE
C         ELEMENTARY FUNCTIONS. HERE, S=MAX(1,ABS(LOG10(CABS(Z))),
C         ABS(LOG10(FNU))) APPROXIMATELY (I.E. S=MAX(1,ABS(EXPONENT OF
C         CABS(Z),ABS(EXPONENT OF FNU)) ). HOWEVER, THE PHASE ANGLE MAY
C         HAVE ONLY ABSOLUTE ACCURACY. THIS IS MOST LIKELY TO OCCUR WHEN
C         ONE COMPONENT (IN ABSOLUTE VALUE) IS LARGER THAN THE OTHER BY
C         SEVERAL ORDERS OF MAGNITUDE. IF ONE COMPONENT IS 10**K LARGER
C         THAN THE OTHER, THEN ONE CAN EXPECT ONLY MAX(ABS(LOG10(P))-K,
C         0) SIGNIFICANT DIGITS; OR, STATED ANOTHER WAY, WHEN K EXCEEDS
C         THE EXPONENT OF P, NO SIGNIFICANT DIGITS REMAIN IN THE SMALLER
C         COMPONENT. HOWEVER, THE PHASE ANGLE RETAINS ABSOLUTE ACCURACY
C         BECAUSE, IN COMPLEX ARITHMETIC WITH PRECISION P, THE SMALLER
C         COMPONENT WILL NOT (AS A RULE) DECREASE BELOW P TIMES THE
C         MAGNITUDE OF THE LARGER COMPONENT. IN THESE EXTREME CASES,
C         THE PRINCIPAL PHASE ANGLE IS ON THE ORDER OF +P, -P, PI/2-P,
C         OR -PI/2+P.
C
C     REFERENCES
C     ==========
C               HANDBOOK OF MATHEMATICAL FUNCTIONS BY M. ABRAMOWITZ
C                 AND I. A. STEGUN, NBS AMS SERIES 55, U.S. DEPT. OF
C                 COMMERCE, 1955.
C
C               COMPUTATION OF BESSEL FUNCTIONS OF COMPLEX ARGUMENT
C                 BY D. E. AMOS, SAND83-0083, MAY, 1983.
C
C               COMPUTATION OF BESSEL FUNCTIONS OF COMPLEX ARGUMENT
C                 AND LARGE ORDER BY D. E. AMOS, SAND83-0643, MAY, 1983
C
C               A SUBROUTINE PACKAGE FOR BESSEL FUNCTIONS OF A COMPLEX
C                 ARGUMENT AND NONNEGATIVE ORDER BY D. E. AMOS, SAND85-
C                 1018, MAY, 1985
C
C               A PORTABLE PACKAGE FOR BESSEL FUNCTIONS OF A COMPLEX
C                 ARGUMENT AND NONNEGATIVE ORDER BY D. E. AMOS, TRANS.
C                 MATH. SOFTWARE, 1986
C
C     DATE WRITTEN   830501   (YYMMDD)
C     REVISION DATE  830501   (YYMMDD)
C     AUTHOR  AMOS, DONALD E., SANDIA NATIONAL LABORATORIES
C

S17DGF
      SUBROUTINE S17DGF(DERIV,Z,SCALE,AI,NZ,IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.
C     MARK 14 REVISED. IER-770 (DEC 1989).
C
C     Original name: CAIRY
C
C     PURPOSE  TO COMPUTE AIRY FUNCTIONS AI(Z) AND DAI(Z) FOR COMPLEX Z
C
C     DESCRIPTION
C     ===========
C
C         ON SCALE='U', S17DGF COMPUTES THE COMPLEX AIRY FUNCTION AI(Z)
C         OR ITS DERIVATIVE DAI(Z)/DZ ON DERIV='F' OR DERIV='D'
C         RESPECTIVELY. ON SCALE='S', A SCALING OPTION
C         CEXP(ZTA)*AI(Z) OR CEXP(ZTA)*DAI(Z)/DZ IS PROVIDED TO REMOVE
C         THE EXPONENTIAL DECAY IN -PI/3.LT.ARG(Z).LT.PI/3 AND THE
C         EXPONENTIAL GROWTH IN PI/3.LT.ABS(ARG(Z)).LT.PI WHERE
C         ZTA=(2/3)*Z*CSQRT(Z)
C
C         WHILE THE AIRY FUNCTIONS AI(Z) AND DAI(Z)/DZ ARE ANALYTIC IN
C         THE WHOLE Z PLANE, THE CORRESPONDING SCALED FUNCTIONS DEFINED
C         FOR SCALE='S' HAVE A CUT ALONG THE NEGATIVE REAL AXIS.
C         DEFINITIONS AND NOTATION ARE FOUND IN THE NBS HANDBOOK OF
C         MATHEMATICAL FUNCTIONS (REF. 1).
C
C         INPUT
C           Z      - Z=CMPLX(X,Y)
C           DERIV  - RETURN FUNCTION (DERIV='F') OR DERIVATIVE
C                    (DERIV='D')
C           SCALE  - A PARAMETER TO INDICATE THE SCALING OPTION
C                    SCALE = 'U' OR 'u' RETURNS
C                             AI=AI(Z)                ON DERIV='F' OR
C                             AI=DAI(Z)/DZ            ON DERIV='D'
C                    SCALE = 'S' OR 's' RETURNS
C                             AI=CEXP(ZTA)*AI(Z)      ON DERIV='F' OR
C                             AI=CEXP(ZTA)*DAI(Z)/DZ  ON DERIV='D' WHERE
C                             ZTA=(2/3)*Z*CSQRT(Z)
C
C         OUTPUT
C           AI     - COMPLEX ANSWER DEPENDING ON THE CHOICES FOR DERIV
C                    AND SCALE
C           NZ     - UNDERFLOW INDICATOR
C                    NZ= 0   , NORMAL RETURN
C                    NZ= 1   , AI=CMPLX(0.0,0.0) DUE TO UNDERFLOW IN
C                              -PI/3.LT.ARG(Z).LT.PI/3 ON SCALE='U'
C           IFAIL  - ERROR FLAG
C                   IFAIL=0, NORMAL RETURN - COMPUTATION COMPLETED
C                   IFAIL=1, INPUT ERROR   - NO COMPUTATION
C                   IFAIL=2, OVERFLOW      - NO COMPUTATION, REAL(ZTA)
C                            TOO LARGE WITH SCALE = 'U'
C                   IFAIL=3, CABS(Z) LARGE      - COMPUTATION COMPLETED
C                            LOSSES OF SIGNIFCANCE BY ARGUMENT REDUCTION
C                            PRODUCE LESS THAN HALF OF MACHINE ACCURACY
C                   IFAIL=4, CABS(Z) TOO LARGE  - NO COMPUTATION
C                            COMPLETE LOSS OF ACCURACY BY ARGUMENT
C                            REDUCTION
C                   IFAIL=5, ERROR              - NO COMPUTATION,
C                            ALGORITHM TERMINATION CONDITION NOT MET
C
C     LONG DESCRIPTION
C     ================
C
C         AI AND DAI ARE COMPUTED FOR CABS(Z).GT.1.0 FROM THE K BESSEL
C         FUNCTIONS BY
C
C            AI(Z)=C*SQRT(Z)*K(1/3,ZTA) , DAI(Z)=-C*Z*K(2/3,ZTA)
C                           C=1.0/(PI*SQRT(3.0))
C                           ZTA=(2/3)*Z**(3/2)
C
C         WITH THE POWER SERIES FOR CABS(Z).LE.1.0.
C
C         IN MOST COMPLEX VARIABLE COMPUTATION, ONE MUST EVALUATE ELE-
C         MENTARY FUNCTIONS. WHEN THE MAGNITUDE OF Z IS LARGE, LOSSES
C         OF SIGNIFICANCE BY ARGUMENT REDUCTION OCCUR. CONSEQUENTLY, IF
C         THE MAGNITUDE OF ZETA=(2/3)*Z**1.5 EXCEEDS U1=SQRT(0.5/UR),
C         THEN LOSSES EXCEEDING HALF PRECISION ARE LIKELY AND AN ERROR
C         FLAG IFAIL=3 IS TRIGGERED WHERE UR=X02AJF()=UNIT ROUNDOFF.
C         ALSO, IF THE MAGNITUDE OF ZETA IS LARGER THAN U2=0.5/UR, THEN
C         ALL SIGNIFICANCE IS LOST AND IFAIL=4. IN ORDER TO USE THE INT
C         FUNCTION, ZETA MUST BE FURTHER RESTRICTED NOT TO EXCEED THE
C         LARGEST INTEGER, U3=X02BBF(). THUS, THE MAGNITUDE OF ZETA
C         MUST BE RESTRICTED BY MIN(U2,U3). ON 32 BIT MACHINES, U1,U2,
C         AND U3 ARE APPROXIMATELY 2.0E+3, 4.2E+6, 2.1E+9 IN SINGLE
C         PRECISION ARITHMETIC AND 1.3E+8, 1.8E+16, 2.1E+9 IN DOUBLE
C         PRECISION ARITHMETIC RESPECTIVELY. THIS MAKES U2 AND U3 LIMIT-
C         ING IN THEIR RESPECTIVE ARITHMETICS. THIS MEANS THAT THE MAG-
C         NITUDE OF Z CANNOT EXCEED 3.1E+4 IN SINGLE AND 2.1E+6 IN
C         DOUBLE PRECISION ARITHMETIC. THIS ALSO MEANS THAT ONE CAN
C         EXPECT TO RETAIN, IN THE WORST CASES ON 32 BIT MACHINES,
C         NO DIGITS IN SINGLE PRECISION AND ONLY 7 DIGITS IN DOUBLE
C         PRECISION ARITHMETIC. SIMILAR CONSIDERATIONS HOLD FOR OTHER
C         MACHINES.
C
C         THE APPROXIMATE RELATIVE ERROR IN THE MAGNITUDE OF A COMPLEX
C         BESSEL FUNCTION CAN BE EXPRESSED BY P*10**S WHERE P=MAX(UNIT
C         ROUNDOFF,1.0E-18) IS THE NOMINAL PRECISION AND 10**S REPRE-
C         SENTS THE INCREASE IN ERROR DUE TO ARGUMENT REDUCTION IN THE
C         ELEMENTARY FUNCTIONS. HERE, S=MAX(1,ABS(LOG10(CABS(Z))),
C         ABS(LOG10(FNU))) APPROXIMATELY (I.E. S=MAX(1,ABS(EXPONENT OF
C         CABS(Z),ABS(EXPONENT OF FNU)) ). HOWEVER, THE PHASE ANGLE MAY
C         HAVE ONLY ABSOLUTE ACCURACY. THIS IS MOST LIKELY TO OCCUR WHEN
C         ONE COMPONENT (IN ABSOLUTE VALUE) IS LARGER THAN THE OTHER BY
C         SEVERAL ORDERS OF MAGNITUDE. IF ONE COMPONENT IS 10**K LARGER
C         THAN THE OTHER, THEN ONE CAN EXPECT ONLY MAX(ABS(LOG10(P))-K,
C         0) SIGNIFICANT DIGITS; OR, STATED ANOTHER WAY, WHEN K EXCEEDS
C         THE EXPONENT OF P, NO SIGNIFICANT DIGITS REMAIN IN THE SMALLER
C         COMPONENT. HOWEVER, THE PHASE ANGLE RETAINS ABSOLUTE ACCURACY
C         BECAUSE, IN COMPLEX ARITHMETIC WITH PRECISION P, THE SMALLER
C         COMPONENT WILL NOT (AS A RULE) DECREASE BELOW P TIMES THE
C         MAGNITUDE OF THE LARGER COMPONENT. IN THESE EXTREME CASES,
C         THE PRINCIPAL PHASE ANGLE IS ON THE ORDER OF +P, -P, PI/2-P,
C         OR -PI/2+P.
C
C     REFERENCES
C     ==========
C               HANDBOOK OF MATHEMATICAL FUNCTIONS BY M. ABRAMOWITZ
C                 AND I. A. STEGUN, NBS AMS SERIES 55, U.S. DEPT. OF
C                 COMMERCE, 1955.
C
C               COMPUTATION OF BESSEL FUNCTIONS OF COMPLEX ARGUMENT
C                 AND LARGE ORDER BY D. E. AMOS, SAND83-0643, MAY, 1983
C
C               A SUBROUTINE PACKAGE FOR BESSEL FUNCTIONS OF A COMPLEX
C                 ARGUMENT AND NONNEGATIVE ORDER BY D. E. AMOS, SAND85-
C                 1018, MAY, 1985
C
C               A PORTABLE PACKAGE FOR BESSEL FUNCTIONS OF A COMPLEX
C                 ARGUMENT AND NONNEGATIVE ORDER BY D. E. AMOS, TRANS.
C                 MATH. SOFTWARE, 1986
C
C     DATE WRITTEN   830501   (YYMMDD)
C     REVISION DATE  830501   (YYMMDD)
C     AUTHOR  AMOS, DONALD E., SANDIA NATIONAL LABORATORIES
C

S17DHF
      SUBROUTINE S17DHF(DERIV,Z,SCALE,BI,IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.
C     MARK 14 REVISED. IER-780 (DEC 1989).
C
C     Original name: CBIRY
C
C     PURPOSE  TO COMPUTE AIRY FUNCTIONS BI(Z) AND DBI(Z) FOR COMPLEX Z
C     DESCRIPTION
C     ===========
C
C         ON SCALE='U', S17DHF COMPUTES THE COMPLEX AIRY FUNCTION BI(Z)
C         OR ITS DERIVATIVE DBI(Z)/DZ ON DERIV='F' OR DERIV='D'
C         RESPECTIVELY. ON
C         SCALE='S', A SCALING OPTION CEXP(-AXZTA)*BI(Z) OR CEXP(-AXZTA)
C         *DBI(Z)/DZ IS PROVIDED TO REMOVE THE EXPONENTIAL BEHAVIOR IN
C         BOTH THE LEFT AND RIGHT HALF PLANES WHERE
C         ZTA=(2/3)*Z*CSQRT(Z)=CMPLX(XZTA,YZTA) AND AXZTA=ABS(XZTA).
C         DEFINITIONS AND NOTATION ARE FOUND IN THE NBS HANDBOOK OF
C         MATHEMATICAL FUNCTIONS (REF. 1).
C
C         INPUT
C           Z      - Z=CMPLX(X,Y)
C           DERIV  - RETURN FUNCTION (DERIV='F') OR DERIVATIVE
C                    (DERIV='D')
C           SCALE  - A PARAMETER TO INDICATE THE SCALING OPTION
C                    SCALE = 'U' OR SCALE = 'u' RETURNS
C                           BI=BI(Z)                  ON DERIV='F' OR
C                           BI=DBI(Z)/DZ              ON DERIV='D'
C                    SCALE = 'S' OR SCALE = 's' RETURNS
C                           BI=CEXP(-AXZTA)*BI(Z)     ON DERIV='F' OR
C                           BI=CEXP(-AXZTA)*DBI(Z)/DZ ON DERIV='D' WHERE
C                           ZTA=(2/3)*Z*CSQRT(Z)=CMPLX(XZTA,YZTA)
C                           AND AXZTA=ABS(XZTA)
C         OUTPUT
C           BI     - COMPLEX ANSWER DEPENDING ON THE CHOICES FOR DERIV
C                    AND SCALE
C           IFAIL  - ERROR FLAG
C                   IFAIL=0, NORMAL RETURN - COMPUTATION COMPLETED
C                   IFAIL=1, INPUT ERROR   - NO COMPUTATION
C                   IFAIL=2, OVERFLOW      - NO COMPUTATION, REAL(Z)
C                            TOO LARGE WITH SCALE = 'U'
C                   IFAIL=3, CABS(Z) LARGE      - COMPUTATION COMPLETED
C                            LOSSES OF SIGNIFCANCE BY ARGUMENT REDUCTION
C                            PRODUCE LESS THAN HALF OF MACHINE ACCURACY
C                   IFAIL=4, CABS(Z) TOO LARGE  - NO COMPUTATION
C                            COMPLETE LOSS OF ACCURACY BY ARGUMENT
C                            REDUCTION
C                   IFAIL=5, ERROR              - NO COMPUTATION,
C                            ALGORITHM TERMINATION CONDITION NOT MET
C
C     LONG DESCRIPTION
C     ================
C
C         BI AND DBI ARE COMPUTED FOR CABS(Z).GT.1.0 FROM THE I BESSEL
C         FUNCTIONS BY
C
C                BI(Z)=C*SQRT(Z)*( I(-1/3,ZTA) + I(1/3,ZTA) )
C               DBI(Z)=C *  Z  * ( I(-2/3,ZTA) + I(2/3,ZTA) )
C                               C=1.0/SQRT(3.0)
C                               ZTA=(2/3)*Z**(3/2)
C
C         WITH THE POWER SERIES FOR CABS(Z).LE.1.0.
C
C         IN MOST COMPLEX VARIABLE COMPUTATION, ONE MUST EVALUATE ELE-
C         MENTARY FUNCTIONS. WHEN THE MAGNITUDE OF Z IS LARGE, LOSSES
C         OF SIGNIFICANCE BY ARGUMENT REDUCTION OCCUR. CONSEQUENTLY, IF
C         THE MAGNITUDE OF ZETA=(2/3)*Z**1.5 EXCEEDS U1=SQRT(0.5/UR),
C         THEN LOSSES EXCEEDING HALF PRECISION ARE LIKELY AND AN ERROR
C         FLAG IFAIL=3 IS TRIGGERED WHERE UR=X02AJF()=UNIT ROUNDOFF.
C         ALSO, IF THE MAGNITUDE OF ZETA IS LARGER THAN U2=0.5/UR, THEN
C         ALL SIGNIFICANCE IS LOST AND IFAIL=4. IN ORDER TO USE THE INT
C         FUNCTION, ZETA MUST BE FURTHER RESTRICTED NOT TO EXCEED THE
C         LARGEST INTEGER, U3=X02BBF(). THUS, THE MAGNITUDE OF ZETA
C         MUST BE RESTRICTED BY MIN(U2,U3). ON 32 BIT MACHINES, U1,U2,
C         AND U3 ARE APPROXIMATELY 2.0E+3, 4.2E+6, 2.1E+9 IN SINGLE
C         PRECISION ARITHMETIC AND 1.3E+8, 1.8E+16, 2.1E+9 IN DOUBLE
C         PRECISION ARITHMETIC RESPECTIVELY. THIS MAKES U2 AND U3 LIMIT-
C         ING IN THEIR RESPECTIVE ARITHMETICS. THIS MEANS THAT THE MAG-
C         NITUDE OF Z CANNOT EXCEED 3.1E+4 IN SINGLE AND 2.1E+6 IN
C         DOUBLE PRECISION ARITHMETIC. THIS ALSO MEANS THAT ONE CAN
C         EXPECT TO RETAIN, IN THE WORST CASES ON 32 BIT MACHINES,
C         NO DIGITS IN SINGLE PRECISION AND ONLY 7 DIGITS IN DOUBLE
C         PRECISION ARITHMETIC.
C
C         THE APPROXIMATE RELATIVE ERROR IN THE MAGNITUDE OF A COMPLEX
C         BESSEL FUNCTION CAN BE EXPRESSED BY P*10**S WHERE P=MAX(UNIT
C         ROUNDOFF,1.0E-18) IS THE NOMINAL PRECISION AND 10**S REPRE-
C         SENTS THE INCREASE IN ERROR DUE TO ARGUMENT REDUCTION IN THE
C         ELEMENTARY FUNCTIONS. HERE, S=MAX(1,ABS(LOG10(CABS(Z))),
C         ABS(LOG10(FNU))) APPROXIMATELY (I.E. S=MAX(1,ABS(EXPONENT OF
C         CABS(Z),ABS(EXPONENT OF FNU)) ). HOWEVER, THE PHASE ANGLE MAY
C         HAVE ONLY ABSOLUTE ACCURACY. THIS IS MOST LIKELY TO OCCUR WHEN
C         ONE COMPONENT (IN ABSOLUTE VALUE) IS LARGER THAN THE OTHER BY
C         SEVERAL ORDERS OF MAGNITUDE. IF ONE COMPONENT IS 10**K LARGER
C         THAN THE OTHER, THEN ONE CAN EXPECT ONLY MAX(ABS(LOG10(P))-K,
C         0) SIGNIFICANT DIGITS; OR, STATED ANOTHER WAY, WHEN K EXCEEDS
C         THE EXPONENT OF P, NO SIGNIFICANT DIGITS REMAIN IN THE SMALLER
C         COMPONENT. HOWEVER, THE PHASE ANGLE RETAINS ABSOLUTE ACCURACY
C         BECAUSE, IN COMPLEX ARITHMETIC WITH PRECISION P, THE SMALLER
C         COMPONENT WILL NOT (AS A RULE) DECREASE BELOW P TIMES THE
C         MAGNITUDE OF THE LARGER COMPONENT. IN THESE EXTREME CASES,
C         THE PRINCIPAL PHASE ANGLE IS ON THE ORDER OF +P, -P, PI/2-P,
C         OR -PI/2+P.
C
C     REFERENCES
C     ==========
C               HANDBOOK OF MATHEMATICAL FUNCTIONS BY M. ABRAMOWITZ
C                 AND I. A. STEGUN, NBS AMS SERIES 55, U.S. DEPT. OF
C                 COMMERCE, 1955.
C
C               COMPUTATION OF BESSEL FUNCTIONS OF COMPLEX ARGUMENT
C                 AND LARGE ORDER BY D. E. AMOS, SAND83-0643, MAY, 1983
C
C               A SUBROUTINE PACKAGE FOR BESSEL FUNCTIONS OF A COMPLEX
C                 ARGUMENT AND NONNEGATIVE ORDER BY D. E. AMOS, SAND85-
C                 1018, MAY, 1985
C
C               A PORTABLE PACKAGE FOR BESSEL FUNCTIONS OF A COMPLEX
C                 ARGUMENT AND NONNEGATIVE ORDER BY D. E. AMOS, TRANS.
C                 MATH. SOFTWARE, 1986
C
C     DATE WRITTEN   830501   (YYMMDD)
C     REVISION DATE  830501   (YYMMDD)
C     AUTHOR  AMOS, DONALD E., SANDIA NATIONAL LABORATORIES
C

S17DLF
      SUBROUTINE S17DLF(M,FNU,Z,N,SCALE,CY,NZ,IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.
C     MARK 14 REVISED. IER-781 (DEC 1989).
C
C     Original name: CBESH
C
C     PURPOSE  TO COMPUTE THE H-BESSEL FUNCTIONS OF A COMPLEX ARGUMENT
C
C     DESCRIPTION
C     ===========
C
C         ON SCALE='U', S17DLF COMPUTES AN N MEMBER SEQUENCE OF COMPLEX
C         HANKEL (BESSEL) FUNCTIONS CY(J)=H(M,FNU+J-1,Z) FOR KINDS M=1
C         OR 2, REAL, NONNEGATIVE ORDERS FNU+J-1, J=1,...,N, AND COMPLEX
C         Z.NE.CMPLX(0.0E0,0.0E0) IN THE CUT PLANE -PI.LT.ARG(Z).LE.PI.
C         ON SCALE='S', S17DLF COMPUTES THE SCALED HANKEL FUNCTIONS
C
C         CY(I)=H(M,FNU+J-1,Z)*EXP(-MM*Z*I)       MM=3-2M,      I**2=-1.
C
C         WHICH REMOVES THE EXPONENTIAL BEHAVIOR IN BOTH THE UPPER
C         AND LOWER HALF PLANES. DEFINITIONS AND NOTATION ARE FOUND IN
C         THE NBS HANDBOOK OF MATHEMATICAL FUNCTIONS (REF. 1).
C
C         INPUT
C           Z      - Z=CMPLX(X,Y), Z.NE.CMPLX(0.,0.),-PI.LT.ARG(Z).LE.PI
C           FNU    - ORDER OF INITIAL H FUNCTION, FNU.GE.0.0E0
C           SCALE  - A PARAMETER TO INDICATE THE SCALING OPTION
C                    SCALE = 'U' OR SCALE = 'u' RETURNS
C                             CY(J)=H(M,FNU+J-1,Z),      J=1,...,N
C                          = 'S' OR SCALE = 's' RETURNS
C                             CY(J)=H(M,FNU+J-1,Z)*EXP(-I*Z*(3-2M))
C                                  J=1,...,N  ,  I**2=-1
C           M      - KIND OF HANKEL FUNCTION, M=1 OR 2
C           N      - NUMBER OF MEMBERS OF THE SEQUENCE, N.GE.1
C
C         OUTPUT
C           CY     - A COMPLEX VECTOR WHOSE FIRST N COMPONENTS CONTAIN
C                    VALUES FOR THE SEQUENCE
C                    CY(J)=H(M,FNU+J-1,Z)  OR
C                    CY(J)=H(M,FNU+J-1,Z)*EXP(-I*Z*(3-2M))  J=1,...,N
C                    DEPENDING ON SCALE, I**2=-1.
C           NZ     - NUMBER OF COMPONENTS SET TO ZERO DUE TO UNDERFLOW,
C                    NZ= 0   , NORMAL RETURN
C                    NZ.GT.0 , FIRST NZ COMPONENTS OF CY SET TO ZERO
C                              DUE TO UNDERFLOW, CY(J)=CMPLX(0.0,0.0)
C                              J=1,...,NZ WHEN Y.GT.0.0 AND M=1 OR
C                              Y.LT.0.0 AND M=2. FOR THE COMPLMENTARY
C                              HALF PLANES, NZ STATES ONLY THE NUMBER
C                              OF UNDERFLOWS.
C           IERR    -ERROR FLAG
C                    IERR=0, NORMAL RETURN - COMPUTATION COMPLETED
C                    IERR=1, INPUT ERROR   - NO COMPUTATION
C                    IERR=2, OVERFLOW      - NO COMPUTATION,
C                            CABS(Z) TOO SMALL
C                    IERR=3  OVERFLOW      - NO COMPUTATION,
C                            FNU+N-1 TOO LARGE
C                    IERR=4, CABS(Z) OR FNU+N-1 LARGE - COMPUTATION DONE
C                            BUT LOSSES OF SIGNIFCANCE BY ARGUMENT
C                            REDUCTION PRODUCE LESS THAN HALF OF MACHINE
C                            ACCURACY
C                    IERR=5, CABS(Z) OR FNU+N-1 TOO LARGE - NO COMPUTA-
C                            TION BECAUSE OF COMPLETE LOSSES OF SIGNIFI-
C                            CANCE BY ARGUMENT REDUCTION
C                    IERR=6, ERROR              - NO COMPUTATION,
C                            ALGORITHM TERMINATION CONDITION NOT MET
C
C     LONG DESCRIPTION
C     ================
C
C         THE COMPUTATION IS CARRIED OUT BY THE RELATION
C
C         H(M,FNU,Z)=(1/MP)*EXP(-MP*FNU)*K(FNU,Z*EXP(-MP))
C             MP=MM*HPI*I,  MM=3-2*M,  HPI=PI/2,  I**2=-1
C
C         FOR M=1 OR 2 WHERE THE K BESSEL FUNCTION IS COMPUTED FOR THE
C         RIGHT HALF PLANE RE(Z).GE.0.0. THE K FUNCTION IS CONTINUED
C         TO THE LEFT HALF PLANE BY THE RELATION
C
C         K(FNU,Z*EXP(MP)) = EXP(-MP*FNU)*K(FNU,Z)-MP*I(FNU,Z)
C         MP=MR*PI*I, MR=+1 OR -1, RE(Z).GT.0, I**2=-1
C
C         WHERE I(FNU,Z) IS THE I BESSEL FUNCTION.
C
C         EXPONENTIAL DECAY OF H(M,FNU,Z) OCCURS IN THE UPPER HALF Z
C         PLANE FOR M=1 AND THE LOWER HALF Z PLANE FOR M=2.  EXPONENTIAL
C         GROWTH OCCURS IN THE COMPLEMENTARY HALF PLANES.  SCALING
C         BY EXP(-MM*Z*I) REMOVES THE EXPONENTIAL BEHAVIOR IN THE
C         WHOLE Z PLANE FOR Z TO INFINITY.
C
C         FOR NEGATIVE ORDERS,THE FORMULAE
C
C               H(1,-FNU,Z) = H(1,FNU,Z)*CEXP( PI*FNU*I)
C               H(2,-FNU,Z) = H(2,FNU,Z)*CEXP(-PI*FNU*I)
C                         I**2=-1
C
C         CAN BE USED.
C
C         IN MOST COMPLEX VARIABLE COMPUTATION, ONE MUST EVALUATE ELE-
C         MENTARY FUNCTIONS. WHEN THE MAGNITUDE OF Z OR FNU+N-1 IS
C         LARGE, LOSSES OF SIGNIFICANCE BY ARGUMENT REDUCTION OCCUR.
C         CONSEQUENTLY, IF EITHER ONE EXCEEDS U1=SQRT(0.5/UR), THEN
C         LOSSES EXCEEDING HALF PRECISION ARE LIKELY AND AN ERROR FLAG
C         IERR=4 IS TRIGGERED WHERE UR=X02AJF()=UNIT ROUNDOFF. ALSO
C         IF EITHER IS LARGER THAN U2=0.5/UR, THEN ALL SIGNIFICANCE IS
C         LOST AND IERR=5. IN ORDER TO USE THE INT FUNCTION, ARGUMENTS
C         MUST BE FURTHER RESTRICTED NOT TO EXCEED THE LARGEST MACHINE
C         INTEGER, U3=X02BBF(). THUS, THE MAGNITUDE OF Z AND FNU+N-1 IS
C         RESTRICTED BY MIN(U2,U3). ON 32 BIT MACHINES, U1,U2, AND U3
C         ARE APPROXIMATELY 2.0E+3, 4.2E+6, 2.1E+9 IN SINGLE PRECISION
C         ARITHMETIC AND 1.3E+8, 1.8E+16, 2.1E+9 IN DOUBLE PRECISION
C         ARITHMETIC RESPECTIVELY. THIS MAKES U2 AND U3 LIMITING IN
C         THEIR RESPECTIVE ARITHMETICS. THIS MEANS THAT ONE CAN EXPECT
C         TO RETAIN, IN THE WORST CASES ON 32 BIT MACHINES, NO DIGITS
C         IN SINGLE AND ONLY 7 DIGITS IN DOUBLE PRECISION ARITHMETIC.
C         SIMILAR CONSIDERATIONS HOLD FOR OTHER MACHINES.
C
C         THE APPROXIMATE RELATIVE ERROR IN THE MAGNITUDE OF A COMPLEX
C         BESSEL FUNCTION CAN BE EXPRESSED BY P*10**S WHERE P=MAX(UNIT
C         ROUNDOFF,1.0E-18) IS THE NOMINAL PRECISION AND 10**S REPRE-
C         SENTS THE INCREASE IN ERROR DUE TO ARGUMENT REDUCTION IN THE
C         ELEMENTARY FUNCTIONS. HERE, S=MAX(1,ABS(LOG10(CABS(Z))),
C         ABS(LOG10(FNU))) APPROXIMATELY (I.E. S=MAX(1,ABS(EXPONENT OF
C         CABS(Z),ABS(EXPONENT OF FNU)) ). HOWEVER, THE PHASE ANGLE MAY
C         HAVE ONLY ABSOLUTE ACCURACY. THIS IS MOST LIKELY TO OCCUR WHEN
C         ONE COMPONENT (IN ABSOLUTE VALUE) IS LARGER THAN THE OTHER BY
C         SEVERAL ORDERS OF MAGNITUDE. IF ONE COMPONENT IS 10**K LARGER
C         THAN THE OTHER, THEN ONE CAN EXPECT ONLY MAX(ABS(LOG10(P))-K,
C         0) SIGNIFICANT DIGITS; OR, STATED ANOTHER WAY, WHEN K EXCEEDS
C         THE EXPONENT OF P, NO SIGNIFICANT DIGITS REMAIN IN THE SMALLER
C         COMPONENT. HOWEVER, THE PHASE ANGLE RETAINS ABSOLUTE ACCURACY
C         BECAUSE, IN COMPLEX ARITHMETIC WITH PRECISION P, THE SMALLER
C         COMPONENT WILL NOT (AS A RULE) DECREASE BELOW P TIMES THE
C         MAGNITUDE OF THE LARGER COMPONENT. IN THESE EXTREME CASES,
C         THE PRINCIPAL PHASE ANGLE IS ON THE ORDER OF +P, -P, PI/2-P,
C         OR -PI/2+P.
C
C     REFERENCES
C     ==========
C               HANDBOOK OF MATHEMATICAL FUNCTIONS BY M. ABRAMOWITZ
C                 AND I. A. STEGUN, NBS AMS SERIES 55, U.S. DEPT. OF
C                 COMMERCE, 1955.
C
C               COMPUTATION OF BESSEL FUNCTIONS OF COMPLEX ARGUMENT
C                 BY D. E. AMOS, SAND83-0083, MAY, 1983.
C
C               COMPUTATION OF BESSEL FUNCTIONS OF COMPLEX ARGUMENT
C                 AND LARGE ORDER BY D. E. AMOS, SAND83-0643, MAY, 1983
C
C               A SUBROUTINE PACKAGE FOR BESSEL FUNCTIONS OF A COMPLEX
C                 ARGUMENT AND NONNEGATIVE ORDER BY D. E. AMOS, SAND85-
C                 1018, MAY, 1985
C
C               A PORTABLE PACKAGE FOR BESSEL FUNCTIONS OF A COMPLEX
C                 ARGUMENT AND NONNEGATIVE ORDER BY D. E. AMOS, TRANS.
C                 MATH. SOFTWARE, 1986
C
C     DATE WRITTEN   830501   (YYMMDD)
C     REVISION DATE  830501   (YYMMDD)
C     AUTHOR  AMOS, DONALD E., SANDIA NATIONAL LABORATORIES
C

S18ACF
      DOUBLE PRECISION FUNCTION S18ACF(X,IFAIL)
C     MARK 7 RELEASE. NAG COPYRIGHT 1978.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     BESSEL FUNCTION K0(X)
C
C     **************************************************************
C
C     TO EXTRACT THE CORRECT CODE FOR A PARTICULAR MACHINE-RANGE,
C     ACTIVATE THE STATEMENTS CONTAINED IN COMMENTS BEGINNING  CDD ,
C     WHERE  DD  IS THE APPROXIMATE NUMBER OF SIGNIFICANT DECIMAL
C     DIGITS REPRESENTED BY THE MACHINE
C     DELETE THE ILLEGAL DUMMY STATEMENTS OF THE FORM
C     * EXPANSION (NNNN) *
C
C     ALSO INSERT APPROPRIATE DATA STATEMENTS TO DEFINE CONSTANTS
C     WHICH DEPEND ON THE RANGE OF NUMBERS REPRESENTED BY THE
C     MACHINE, RATHER THAN THE PRECISION (SUITABLE STATEMENTS FOR
C     SOME MACHINES ARE CONTAINED IN COMMENTS BEGINNING CRD WHERE
C     D IS A DIGIT WHICH SIMPLY DISTINGUISHES A GROUP OF MACHINES).
C     DELETE THE ILLEGAL DUMMY DATA STATEMENTS WITH VALUES WRITTEN
C     *VALUE*
C
C     **************************************************************
C

S18ADF
      DOUBLE PRECISION FUNCTION S18ADF(X,IFAIL)
C     MARK 7 RELEASE. NAG COPYRIGHT 1978.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     BESSEL FUNCTION K1(X)
C
C     **************************************************************
C
C     TO EXTRACT THE CORRECT CODE FOR A PARTICULAR MACHINE-RANGE,
C     ACTIVATE THE STATEMENTS CONTAINED IN COMMENTS BEGINNING  CDD ,
C     WHERE  DD  IS THE APPROXIMATE NUMBER OF SIGNIFICANT DECIMAL
C     DIGITS REPRESENTED BY THE MACHINE
C     DELETE THE ILLEGAL DUMMY STATEMENTS OF THE FORM
C     * EXPANSION (NNNN) *
C
C     ALSO INSERT APPROPRIATE DATA STATEMENTS TO DEFINE CONSTANTS
C     WHICH DEPEND ON THE RANGE OF NUMBERS REPRESENTED BY THE
C     MACHINE, RATHER THAN THE PRECISION (SUITABLE STATEMENTS FOR
C     SOME MACHINES ARE CONTAINED IN COMMENTS BEGINNING CRD WHERE
C     D IS A DIGIT WHICH SIMPLY DISTINGUISHES A GROUP OF MACHINES).
C     DELETE THE ILLEGAL DUMMY DATA STATEMENTS WITH VALUES WRITTEN
C     *VALUE*
C
C     **************************************************************
C

S18AEF
      DOUBLE PRECISION FUNCTION S18AEF(X,IFAIL)
C     MARK 7 RELEASE. NAG COPYRIGHT 1978.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     BESSEL FUNCTION I0(X)
C
C     **************************************************************
C
C     TO EXTRACT THE CORRECT CODE FOR A PARTICULAR MACHINE-RANGE,
C     ACTIVATE THE STATEMENTS CONTAINED IN COMMENTS BEGINNING  CDD ,
C     WHERE  DD  IS THE APPROXIMATE NUMBER OF SIGNIFICANT DECIMAL
C     DIGITS REPRESENTED BY THE MACHINE
C     DELETE THE ILLEGAL DUMMY STATEMENTS OF THE FORM
C     * EXPANSION (NNNN) *
C
C     ALSO INSERT APPROPRIATE DATA STATEMENTS TO DEFINE CONSTANTS
C     WHICH DEPEND ON THE RANGE OF NUMBERS REPRESENTED BY THE
C     MACHINE, RATHER THAN THE PRECISION (SUITABLE STATEMENTS FOR
C     SOME MACHINES ARE CONTAINED IN COMMENTS BEGINNING CRD WHERE
C     D IS A DIGIT WHICH SIMPLY DISTINGUISHES A GROUP OF MACHINES).
C     DELETE THE ILLEGAL DUMMY DATA STATEMENTS WITH VALUES WRITTEN
C     *VALUE*
C
C     **************************************************************
C

S18AFF
      DOUBLE PRECISION FUNCTION S18AFF(X,IFAIL)
C     MARK 7 RELEASE. NAG COPYRIGHT 1978.
C     MARK 8C REVISED. IER-269 (OCT.1980).
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     BESSEL FUNCTION I1(X)
C
C     **************************************************************
C
C     TO EXTRACT THE CORRECT CODE FOR A PARTICULAR MACHINE-RANGE,
C     ACTIVATE THE STATEMENTS CONTAINED IN COMMENTS BEGINNING  CDD ,
C     WHERE  DD  IS THE APPROXIMATE NUMBER OF SIGNIFICANT DECIMAL
C     DIGITS REPRESENTED BY THE MACHINE
C     DELETE THE ILLEGAL DUMMY STATEMENTS OF THE FORM
C     * EXPANSION (NNNN) *
C
C     ALSO INSERT APPROPRIATE DATA STATEMENTS TO DEFINE CONSTANTS
C     WHICH DEPEND ON THE RANGE OF NUMBERS REPRESENTED BY THE
C     MACHINE, RATHER THAN THE PRECISION (SUITABLE STATEMENTS FOR
C     SOME MACHINES ARE CONTAINED IN COMMENTS BEGINNING CRD WHERE
C     D IS A DIGIT WHICH SIMPLY DISTINGUISHES A GROUP OF MACHINES).
C     DELETE THE ILLEGAL DUMMY DATA STATEMENTS WITH VALUES WRITTEN
C     *VALUE*
C
C     **************************************************************
C

S18CCF
      DOUBLE PRECISION FUNCTION S18CCF(X,IFAIL)
C     MARK 10 RELEASE. NAG COPYRIGHT 1982.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     SCALED BESSEL FUNCTION K0(X)EXP(X)
C
C     **************************************************************
C
C     TO EXTRACT THE CORRECT CODE FOR A PARTICULAR MACHINE-RANGE,
C     ACTIVATE THE STATEMENTS CONTAINED IN COMMENTS BEGINNING  CDD ,
C     WHERE  DD  IS THE APPROXIMATE NUMBER OF SIGNIFICANT DECIMAL
C     DIGITS REPRESENTED BY THE MACHINE
C     DELETE THE ILLEGAL DUMMY STATEMENTS OF THE FORM
C     * EXPANSION (NNNN) *
C
C     **************************************************************
C

S18CDF
      DOUBLE PRECISION FUNCTION S18CDF(X,IFAIL)
C     MARK 10 RELEASE. NAG COPYRIGHT 1982.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     SCALED BESSEL FUNCTION K1(X)EXP(X)
C
C     **************************************************************
C
C     TO EXTRACT THE CORRECT CODE FOR A PARTICULAR MACHINE-RANGE,
C     ACTIVATE THE STATEMENTS CONTAINED IN COMMENTS BEGINNING  CDD ,
C     WHERE  DD  IS THE APPROXIMATE NUMBER OF SIGNIFICANT DECIMAL
C     DIGITS REPRESENTED BY THE MACHINE
C     DELETE THE ILLEGAL DUMMY STATEMENTS OF THE FORM
C     * EXPANSION (NNNN) *
C
C     ALSO INSERT APPROPRIATE DATA STATEMENTS TO DEFINE CONSTANTS
C     WHICH DEPEND ON THE RANGE OF NUMBERS REPRESENTED BY THE
C     MACHINE, RATHER THAN THE PRECISION (SUITABLE STATEMENTS FOR
C     SOME MACHINES ARE CONTAINED IN COMMENTS BEGINNING CRD WHERE
C     D IS A DIGIT WHICH SIMPLY DISTINGUISHES A GROUP OF MACHINES).
C     DELETE THE ILLEGAL DUMMY DATA STATEMENTS WITH VALUES WRITTEN
C     *VALUE*
C
C     **************************************************************
C

S18CEF
      DOUBLE PRECISION FUNCTION S18CEF(X,IFAIL)
C     MARK 10 RELEASE. NAG COPYRIGHT 1982.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     SCALED BESSEL FUNCTION I0(X)*EXP(-ABS(X))
C
C     **************************************************************
C
C     TO EXTRACT THE CORRECT CODE FOR A PARTICULAR MACHINE-RANGE,
C     ACTIVATE THE STATEMENTS CONTAINED IN COMMENTS BEGINNING  CDD ,
C     WHERE  DD  IS THE APPROXIMATE NUMBER OF SIGNIFICANT DECIMAL
C     DIGITS REPRESENTED BY THE MACHINE
C     DELETE THE ILLEGAL DUMMY STATEMENTS OF THE FORM
C     * EXPANSION (NNNN) *
C
C     **************************************************************
C

S18CFF
      DOUBLE PRECISION FUNCTION S18CFF(X,IFAIL)
C     MARK 10 RELEASE. NAG COPYRIGHT 1982.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     SCALED BESSEL FUNCTION I1(X)*EXP(-ABS(X))
C
C     **************************************************************
C
C     TO EXTRACT THE CORRECT CODE FOR A PARTICULAR MACHINE-RANGE,
C     ACTIVATE THE STATEMENTS CONTAINED IN COMMENTS BEGINNING  CDD ,
C     WHERE  DD  IS THE APPROXIMATE NUMBER OF SIGNIFICANT DECIMAL
C     DIGITS REPRESENTED BY THE MACHINE
C     DELETE THE ILLEGAL DUMMY STATEMENTS OF THE FORM
C     * EXPANSION (NNNN) *
C
C     **************************************************************
C

S18DCF
      SUBROUTINE S18DCF(FNU,Z,N,SCALE,CY,NZ,IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.
C     MARK 14 REVISED. IER-784 (DEC 1989).
C
C     Original name: CBESK
C
C     PURPOSE  TO COMPUTE K-BESSEL FUNCTIONS OF COMPLEX ARGUMENT
C
C     DESCRIPTION
C     ===========
C
C         ON SCALE='U', S18DCF COMPUTES AN N MEMBER SEQUENCE OF COMPLEX
C         BESSEL FUNCTIONS CY(J)=K(FNU+J-1,Z) FOR REAL, NONNEGATIVE
C         ORDERS FNU+J-1, J=1,...,N AND COMPLEX Z.NE.CMPLX(0.0,0.0)
C         IN THE CUT PLANE -PI.LT.ARG(Z).LE.PI. ON SCALE='S', S18DCF
C         RETURNS THE SCALED K FUNCTIONS,
C
C         CY(J)=EXP(Z)*K(FNU+J-1,Z) , J=1,...,N,
C
C         WHICH REMOVE THE EXPONENTIAL BEHAVIOR IN BOTH THE LEFT AND
C         RIGHT HALF PLANES FOR Z TO INFINITY. DEFINITIONS AND
C         NOTATION ARE FOUND IN THE NBS HANDBOOK OF MATHEMATICAL
C         FUNCTIONS (REF. 1).
C
C         INPUT
C           Z      - Z=CMPLX(X,Y),Z.NE.CMPLX(0.,0.),-PI.LT.ARG(Z).LE.PI
C           FNU    - ORDER OF INITIAL K FUNCTION, FNU.GE.0.0E0
C           N      - NUMBER OF MEMBERS OF THE SEQUENCE, N.GE.1
C           SCALE  - A PARAMETER TO INDICATE THE SCALING OPTION
C                    SCALE = 'U' OR SCALE = 'u' RETURNS
C                             CY(I)=K(FNU+I-1,Z), I=1,...,N
C                    SCALE = 'S' OR SCALE = 's' RETURNS
C                             CY(I)=K(FNU+I-1,Z)*EXP(Z), I=1,...,N
C
C         OUTPUT
C           CY     - A COMPLEX VECTOR WHOSE FIRST N COMPONENTS CONTAIN
C                    VALUES FOR THE SEQUENCE
C                    CY(I)=K(FNU+I-1,Z), I=1,...,N OR
C                    CY(I)=K(FNU+I-1,Z)*EXP(Z), I=1,...,N
C                    DEPENDING ON SCALE
C           NZ     - NUMBER OF COMPONENTS SET TO ZERO DUE TO UNDERFLOW.
C                    NZ= 0   , NORMAL RETURN
C                    NZ.GT.0 , FIRST NZ COMPONENTS OF CY SET TO ZERO
C                              DUE TO UNDERFLOW, CY(I)=CMPLX(0.0,0.0),
C                              I=1,...,N WHEN X.GE.0.0. WHEN X.LT.0.0
C                              NZ STATES ONLY THE NUMBER OF UNDERFLOWS
C                              IN THE SEQUENCE.
C           IFAIL  - ERROR FLAG
C                   IFAIL=0, NORMAL RETURN - COMPUTATION COMPLETED
C                   IFAIL=1, INPUT ERROR   - NO COMPUTATION
C                   IFAIL=2, OVERFLOW      - NO COMPUTATION, CABS(Z) IS
C                            TOO SMALL
C                   IFAIL=3, OVERFLOW      - NO COMPUTATION, FNU+N-1 IS
C                            TOO LARGE
C                   IFAIL=4, CABS(Z) OR FNU+N-1 LARGE - COMPUTATION DONE
C                            BUT LOSSES OF SIGNIFCANCE BY ARGUMENT
C                            REDUCTION PRODUCE LESS THAN HALF OF MACHINE
C                            ACCURACY
C                   IFAIL=5, CABS(Z) OR FNU+N-1 TOO LARGE - NO COMPUTA-
C                            TION BECAUSE OF COMPLETE LOSSES OF SIGNIFI-
C                            CANCE BY ARGUMENT REDUCTION
C                   IFAIL=6, ERROR              - NO COMPUTATION,
C                            ALGORITHM TERMINATION CONDITION NOT MET
C
C     LONG DESCRIPTION
C     ================
C
C         EQUATIONS OF THE REFERENCE ARE IMPLEMENTED FOR SMALL ORDERS
C         DNU AND DNU+1.0 IN THE RIGHT HALF PLANE X.GE.0.0. FORWARD
C         RECURRENCE GENERATES HIGHER ORDERS. K IS CONTINUED TO THE LEFT
C         HALF PLANE BY THE RELATION
C
C         K(FNU,Z*EXP(MP)) = EXP(-MP*FNU)*K(FNU,Z)-MP*I(FNU,Z)
C         MP=MR*PI*I, MR=+1 OR -1, RE(Z).GT.0, I**2=-1
C
C         WHERE I(FNU,Z) IS THE I BESSEL FUNCTION.
C
C         FOR LARGE ORDERS, FNU.GT.FNUL, THE K FUNCTION IS COMPUTED
C         BY MEANS OF ITS UNIFORM ASYMPTOTIC EXPANSIONS.
C
C         FOR NEGATIVE ORDERS, THE FORMULA
C
C                       K(-FNU,Z) = K(FNU,Z)
C
C         CAN BE USED.
C
C         S18DCF ASSUMES THAT A SIGNIFICANT DIGIT SINH(X) FUNCTION IS
C         AVAILABLE.
C
C         IN MOST COMPLEX VARIABLE COMPUTATION, ONE MUST EVALUATE ELE-
C         MENTARY FUNCTIONS. WHEN THE MAGNITUDE OF Z OR FNU+N-1 IS
C         LARGE, LOSSES OF SIGNIFICANCE BY ARGUMENT REDUCTION OCCUR.
C         CONSEQUENTLY, IF EITHER ONE EXCEEDS U1=SQRT(0.5/UR), THEN
C         LOSSES EXCEEDING HALF PRECISION ARE LIKELY AND AN ERROR FLAG
C         IFAIL=4 IS TRIGGERED WHERE UR=X02AJF()=UNIT ROUNDOFF. ALSO
C         IF EITHER IS LARGER THAN U2=0.5/UR, THEN ALL SIGNIFICANCE IS
C         LOST AND IFAIL=5. IN ORDER TO USE THE INT FUNCTION, ARGUMENTS
C         MUST BE FURTHER RESTRICTED NOT TO EXCEED THE LARGEST MACHINE
C         INTEGER, U3=X02BBF(). THUS, THE MAGNITUDE OF Z AND FNU+N-1 IS
C         RESTRICTED BY MIN(U2,U3). ON 32 BIT MACHINES, U1,U2, AND U3
C         ARE APPROXIMATELY 2.0E+3, 4.2E+6, 2.1E+9 IN SINGLE PRECISION
C         ARITHMETIC AND 1.3E+8, 1.8E+16, 2.1E+9 IN DOUBLE PRECISION
C         ARITHMETIC RESPECTIVELY. THIS MAKES U2 AND U3 LIMITING IN
C         THEIR RESPECTIVE ARITHMETICS. THIS MEANS THAT ONE CAN EXPECT
C         TO RETAIN, IN THE WORST CASES ON 32 BIT MACHINES, NO DIGITS
C         IN SINGLE AND ONLY 7 DIGITS IN DOUBLE PRECISION ARITHMETIC.
C         SIMILAR CONSIDERATIONS HOLD FOR OTHER MACHINES.
C
C         THE APPROXIMATE RELATIVE ERROR IN THE MAGNITUDE OF A COMPLEX
C         BESSEL FUNCTION CAN BE EXPRESSED BY P*10**S WHERE P=MAX(UNIT
C         ROUNDOFF,1.0E-18) IS THE NOMINAL PRECISION AND 10**S REPRE-
C         SENTS THE INCREASE IN ERROR DUE TO ARGUMENT REDUCTION IN THE
C         ELEMENTARY FUNCTIONS. HERE, S=MAX(1,ABS(LOG10(CABS(Z))),
C         ABS(LOG10(FNU))) APPROXIMATELY (I.E. S=MAX(1,ABS(EXPONENT OF
C         CABS(Z),ABS(EXPONENT OF FNU)) ). HOWEVER, THE PHASE ANGLE MAY
C         HAVE ONLY ABSOLUTE ACCURACY. THIS IS MOST LIKELY TO OCCUR WHEN
C         ONE COMPONENT (IN ABSOLUTE VALUE) IS LARGER THAN THE OTHER BY
C         SEVERAL ORDERS OF MAGNITUDE. IF ONE COMPONENT IS 10**K LARGER
C         THAN THE OTHER, THEN ONE CAN EXPECT ONLY MAX(ABS(LOG10(P))-K,
C         0) SIGNIFICANT DIGITS; OR, STATED ANOTHER WAY, WHEN K EXCEEDS
C         THE EXPONENT OF P, NO SIGNIFICANT DIGITS REMAIN IN THE SMALLER
C         COMPONENT. HOWEVER, THE PHASE ANGLE RETAINS ABSOLUTE ACCURACY
C         BECAUSE, IN COMPLEX ARITHMETIC WITH PRECISION P, THE SMALLER
C         COMPONENT WILL NOT (AS A RULE) DECREASE BELOW P TIMES THE
C         MAGNITUDE OF THE LARGER COMPONENT. IN THESE EXTREME CASES,
C         THE PRINCIPAL PHASE ANGLE IS ON THE ORDER OF +P, -P, PI/2-P,
C         OR -PI/2+P.
C
C     REFERENCES
C     ==========
C               HANDBOOK OF MATHEMATICAL FUNCTIONS BY M. ABRAMOWITZ
C                 AND I. A. STEGUN, NBS AMS SERIES 55, U.S. DEPT. OF
C                 COMMERCE, 1955.
C
C               COMPUTATION OF BESSEL FUNCTIONS OF COMPLEX ARGUMENT
C                 BY D. E. AMOS, SAND83-0083, MAY, 1983.
C
C               COMPUTATION OF BESSEL FUNCTIONS OF COMPLEX ARGUMENT
C                 AND LARGE ORDER BY D. E. AMOS, SAND83-0643, MAY, 1983.
C
C               A SUBROUTINE PACKAGE FOR BESSEL FUNCTIONS OF A COMPLEX
C                 ARGUMENT AND NONNEGATIVE ORDER BY D. E. AMOS, SAND85-
C                 1018, MAY, 1985
C
C               A PORTABLE PACKAGE FOR BESSEL FUNCTIONS OF A COMPLEX
C                 ARGUMENT AND NONNEGATIVE ORDER BY D. E. AMOS, TRANS.
C                 MATH. SOFTWARE, 1986
C
C     DATE WRITTEN   830501   (YYMMDD)
C     REVISION DATE  830501   (YYMMDD)
C     AUTHOR  AMOS, DONALD E., SANDIA NATIONAL LABORATORIES
C

S18DEF
      SUBROUTINE S18DEF(FNU,Z,N,SCALE,CY,NZ,IFAIL)
C     MARK 13 RELEASE. NAG COPYRIGHT 1988.
C     MARK 14 REVISED. IER-787 (DEC 1989).
C
C     Original name: CBESI
C
C     PURPOSE  TO COMPUTE I-BESSEL FUNCTIONS OF COMPLEX ARGUMENT
C
C     DESCRIPTION
C     ===========
C
C         ON SCALE='U', S18DEF COMPUTES AN N MEMBER SEQUENCE OF COMPLEX
C         BESSEL FUNCTIONS CY(J)=I(FNU+J-1,Z) FOR REAL, NONNEGATIVE
C         ORDERS FNU+J-1, J=1,...,N AND COMPLEX Z IN THE CUT PLANE
C         -PI.LT.ARG(Z).LE.PI. ON SCALE='S', S18DEF RETURNS THE SCALED
C         FUNCTIONS
C
C         CY(J)=EXP(-ABS(X))*I(FNU+J-1,Z)   J = 1,...,N , X=REAL(Z)
C
C         WITH THE EXPONENTIAL GROWTH REMOVED IN BOTH THE LEFT AND
C         RIGHT HALF PLANES FOR Z TO INFINITY. DEFINITIONS AND
C         NOTATION ARE FOUND IN THE NBS HANDBOOK OF MATHEMATICAL
C         FUNCTIONS (REF.1)
C
C         INPUT
C           Z      - Z=CMPLX(X,Y),  -PI.LT.ARG(Z).LE.PI
C           FNU    - ORDER OF INITIAL I FUNCTION, FNU.GE.0.0E0
C           SCALE  - A PARAMETER TO INDICATE THE SCALING OPTION
C                    SCALE = 'U' OR SCALE = 'u' RETURNS
C                             CY(J)=I(FNU+J-1,Z), J=1,...,N
C                    SCALE = 'S' OR SCALE = 's' RETURNS
C                             CY(J)=I(FNU+J-1,Z)*EXP(-ABS(X)), J=1,...,N
C           N      - NUMBER OF MEMBERS OF THE SEQUENCE, N.GE.1
C
C         OUTPUT
C           CY     - A COMPLEX VECTOR WHOSE FIRST N COMPONENTS CONTAIN
C                    VALUES FOR THE SEQUENCE
C                    CY(J)=I(FNU+J-1,Z)  OR
C                    CY(J)=I(FNU+J-1,Z)*EXP(-ABS(X))  J=1,...,N
C                    DEPENDING ON SCALE, X=REAL(Z)
C           NZ     - NUMBER OF COMPONENTS SET TO ZERO DUE TO UNDERFLOW,
C                    NZ= 0   , NORMAL RETURN
C                    NZ.GT.0 , LAST NZ COMPONENTS OF CY SET TO ZERO
C                              DUE TO UNDERFLOW, CY(J)=CMPLX(0.0,0.0),
C                              J = N-NZ+1,...,N
C           IFAIL  - ERROR FLAG
C                   IFAIL=0, NORMAL RETURN - COMPUTATION COMPLETED
C                   IFAIL=1, INPUT ERROR   - NO COMPUTATION
C                   IFAIL=2, OVERFLOW      - NO COMPUTATION, REAL(Z) TOO
C                            LARGE ON SCALE='U'
C                   IFAIL=3, CABS(Z) OR FNU+N-1 LARGE - COMPUTATION DONE
C                            BUT LOSSES OF SIGNIFCANCE BY ARGUMENT
C                            REDUCTION PRODUCE LESS THAN HALF OF MACHINE
C                            ACCURACY
C                   IFAIL=4, CABS(Z) OR FNU+N-1 TOO LARGE - NO COMPUTA-
C                            TION BECAUSE OF COMPLETE LOSSES OF SIGNIFI-
C                            CANCE BY ARGUMENT REDUCTION
C                   IFAIL=5, ERROR              - NO COMPUTATION,
C                            ALGORITHM TERMINATION CONDITION NOT MET
C
C     LONG DESCRIPTION
C     ================
C
C         THE COMPUTATION IS CARRIED OUT BY THE POWER SERIES FOR
C         SMALL CABS(Z), THE ASYMPTOTIC EXPANSION FOR LARGE CABS(Z),
C         THE MILLER ALGORITHM NORMALIZED BY THE WRONSKIAN AND A
C         NEUMANN SERIES FOR IMTERMEDIATE MAGNITUDES, AND THE
C         UNIFORM ASYMPTOTIC EXPANSIONS FOR I(FNU,Z) AND J(FNU,Z)
C         FOR LARGE ORDERS. BACKWARD RECURRENCE IS USED TO GENERATE
C         SEQUENCES OR REDUCE ORDERS WHEN NECESSARY.
C
C         THE CALCULATIONS ABOVE ARE DONE IN THE RIGHT HALF PLANE AND
C         CONTINUED INTO THE LEFT HALF PLANE BY THE FORMULA
C
C         I(FNU,Z*EXP(M*PI)) = EXP(M*PI*FNU)*I(FNU,Z)  REAL(Z).GT.0.0
C                       M = +I OR -I,  I**2=-1
C
C         FOR NEGATIVE ORDERS,THE FORMULA
C
C              I(-FNU,Z) = I(FNU,Z) + (2/PI)*SIN(PI*FNU)*K(FNU,Z)
C
C         CAN BE USED. HOWEVER,FOR LARGE ORDERS CLOSE TO INTEGERS, THE
C         THE FUNCTION CHANGES RADICALLY. WHEN FNU IS A LARGE POSITIVE
C         INTEGER,THE MAGNITUDE OF I(-FNU,Z)=I(FNU,Z) IS A LARGE
C         NEGATIVE POWER OF TEN. BUT WHEN FNU IS NOT AN INTEGER,
C         K(FNU,Z) DOMINATES IN MAGNITUDE WITH A LARGE POSITIVE POWER OF
C         TEN AND THE MOST THAT THE SECOND TERM CAN BE REDUCED IS BY
C         UNIT ROUNDOFF FROM THE COEFFICIENT. THUS, WIDE CHANGES CAN
C         OCCUR WITHIN UNIT ROUNDOFF OF A LARGE INTEGER FOR FNU. HERE,
C         LARGE MEANS FNU.GT.CABS(Z).
C
C         IN MOST COMPLEX VARIABLE COMPUTATION, ONE MUST EVALUATE ELE-
C         MENTARY FUNCTIONS. WHEN THE MAGNITUDE OF Z OR FNU+N-1 IS
C         LARGE, LOSSES OF SIGNIFICANCE BY ARGUMENT REDUCTION OCCUR.
C         CONSEQUENTLY, IF EITHER ONE EXCEEDS U1=SQRT(0.5/UR), THEN
C         LOSSES EXCEEDING HALF PRECISION ARE LIKELY AND AN ERROR FLAG
C         IFAIL=3 IS TRIGGERED WHERE UR=X02AJF()=UNIT ROUNDOFF. ALSO
C         IF EITHER IS LARGER THAN U2=0.5/UR, THEN ALL SIGNIFICANCE IS
C         LOST AND IFAIL=4. IN ORDER TO USE THE INT FUNCTION, ARGUMENTS
C         MUST BE FURTHER RESTRICTED NOT TO EXCEED THE LARGEST MACHINE
C         INTEGER, U3=X02BBF(). THUS, THE MAGNITUDE OF Z AND FNU+N-1 IS
C         RESTRICTED BY MIN(U2,U3). ON 32 BIT MACHINES, U1,U2, AND U3
C         ARE APPROXIMATELY 2.0E+3, 4.2E+6, 2.1E+9 IN SINGLE PRECISION
C         ARITHMETIC AND 1.3E+8, 1.8E+16, 2.1E+9 IN DOUBLE PRECISION
C         ARITHMETIC RESPECTIVELY. THIS MAKES U2 AND U3 LIMITING IN
C         THEIR RESPECTIVE ARITHMETICS. THIS MEANS THAT ONE CAN EXPECT
C         TO RETAIN, IN THE WORST CASES ON 32 BIT MACHINES, NO DIGITS
C         IN SINGLE AND ONLY 7 DIGITS IN DOUBLE PRECISION ARITHMETIC.
C         SIMILAR CONSIDERATIONS HOLD FOR OTHER MACHINES.
C
C         THE APPROXIMATE RELATIVE ERROR IN THE MAGNITUDE OF A COMPLEX
C         BESSEL FUNCTION CAN BE EXPRESSED BY P*10**S WHERE P=MAX(UNIT
C         ROUNDOFF,1.0E-18) IS THE NOMINAL PRECISION AND 10**S REPRE-
C         SENTS THE INCREASE IN ERROR DUE TO ARGUMENT REDUCTION IN THE
C         ELEMENTARY FUNCTIONS. HERE, S=MAX(1,ABS(LOG10(CABS(Z))),
C         ABS(LOG10(FNU))) APPROXIMATELY (I.E. S=MAX(1,ABS(EXPONENT OF
C         CABS(Z),ABS(EXPONENT OF FNU)) ). HOWEVER, THE PHASE ANGLE MAY
C         HAVE ONLY ABSOLUTE ACCURACY. THIS IS MOST LIKELY TO OCCUR WHEN
C         ONE COMPONENT (IN ABSOLUTE VALUE) IS LARGER THAN THE OTHER BY
C         SEVERAL ORDERS OF MAGNITUDE. IF ONE COMPONENT IS 10**K LARGER
C         THAN THE OTHER, THEN ONE CAN EXPECT ONLY MAX(ABS(LOG10(P))-K,
C         0) SIGNIFICANT DIGITS; OR, STATED ANOTHER WAY, WHEN K EXCEEDS
C         THE EXPONENT OF P, NO SIGNIFICANT DIGITS REMAIN IN THE SMALLER
C         COMPONENT. HOWEVER, THE PHASE ANGLE RETAINS ABSOLUTE ACCURACY
C         BECAUSE, IN COMPLEX ARITHMETIC WITH PRECISION P, THE SMALLER
C         COMPONENT WILL NOT (AS A RULE) DECREASE BELOW P TIMES THE
C         MAGNITUDE OF THE LARGER COMPONENT. IN THESE EXTREME CASES,
C         THE PRINCIPAL PHASE ANGLE IS ON THE ORDER OF +P, -P, PI/2-P,
C         OR -PI/2+P.
C
C     REFERENCES
C     ==========
C               HANDBOOK OF MATHEMATICAL FUNCTIONS BY M. ABRAMOWITZ
C                 AND I. A. STEGUN, NBS AMS SERIES 55, U.S. DEPT. OF
C                 COMMERCE, 1955.
C
C               COMPUTATION OF BESSEL FUNCTIONS OF COMPLEX ARGUMENT
C                 BY D. E. AMOS, SAND83-0083, MAY, 1983.
C
C               COMPUTATION OF BESSEL FUNCTIONS OF COMPLEX ARGUMENT
C                 AND LARGE ORDER BY D. E. AMOS, SAND83-0643, MAY, 1983
C
C               A SUBROUTINE PACKAGE FOR BESSEL FUNCTIONS OF A COMPLEX
C                 ARGUMENT AND NONNEGATIVE ORDER BY D. E. AMOS, SAND85-
C                 1018, MAY, 1985
C
C               A PORTABLE PACKAGE FOR BESSEL FUNCTIONS OF A COMPLEX
C                 ARGUMENT AND NONNEGATIVE ORDER BY D. E. AMOS, TRANS.
C                 MATH. SOFTWARE, 1986
C
C     DATE WRITTEN   830501   (YYMMDD)
C     REVISION DATE  830501   (YYMMDD)
C     AUTHOR  AMOS, DONALD E., SANDIA NATIONAL LABORATORIES
C

S19AAF
      DOUBLE PRECISION FUNCTION S19AAF(X,IFAIL)
C     MARK 11 RELEASE. NAG COPYRIGHT 1983.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     KELVIN FUNCTION BER(X)
C
C     **************************************************************
C
C     TO EXTRACT THE CORRECT CODE FOR A PARTICULAR MACHINE-RANGE,
C     ACTIVATE THE STATEMENTS CONTAINED IN COMMENTS BEGINNING  CDD ,
C     WHERE  DD  IS THE APPROXIMATE NUMBER OF SIGNIFICANT DECIMAL
C     DIGITS REPRESENTED BY THE MACHINE
C     DELETE THE ILLEGAL DUMMY STATEMENTS OF THE FORM
C     * EXPANSION (NNNN) *
C
C     **************************************************************
C

S19ABF
      DOUBLE PRECISION FUNCTION S19ABF(X,IFAIL)
C     MARK 11 RELEASE. NAG COPYRIGHT 1983.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     KELVIN FUNCTION BEI(X)
C
C     **************************************************************
C
C     TO EXTRACT THE CORRECT CODE FOR A PARTICULAR MACHINE-RANGE,
C     ACTIVATE THE STATEMENTS CONTAINED IN COMMENTS BEGINNING  CDD ,
C     WHERE  DD  IS THE APPROXIMATE NUMBER OF SIGNIFICANT DECIMAL
C     DIGITS REPRESENTED BY THE MACHINE
C     DELETE THE ILLEGAL DUMMY STATEMENTS OF THE FORM
C     * EXPANSION (NNNN) *
C
C     ALSO INSERT APPROPRIATE DATA STATEMENTS TO DEFINE CONSTANTS
C     WHICH DEPEND ON THE RANGE OF NUMBERS REPRESENTED BY THE
C     MACHINE, RATHER THAN THE PRECISION (SUITABLE STATEMENTS FOR
C     SOME MACHINES ARE CONTAINED IN COMMENTS BEGINNING CRD WHERE
C     D IS A DIGIT WHICH SIMPLY DISTINGUISHES A GROUP OF MACHINES).
C     DELETE THE ILLEGAL DUMMY DATA STATEMENTS WITH VALUES WRITTEN
C     *VALUE*
C
C     **************************************************************
C

S19ACF
      DOUBLE PRECISION FUNCTION S19ACF(X,IFAIL)
C     MARK 11 RELEASE. NAG COPYRIGHT 1983.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 12B REVISED. IER-544 (FEB 1987).
C     KELVIN FUNCTION KER(X)
C
C     **************************************************************
C
C     TO EXTRACT THE CORRECT CODE FOR A PARTICULAR MACHINE-RANGE,
C     ACTIVATE THE STATEMENTS CONTAINED IN COMMENTS BEGINNING  CDD ,
C     WHERE  DD  IS THE APPROXIMATE NUMBER OF SIGNIFICANT DECIMAL
C     DIGITS REPRESENTED BY THE MACHINE
C     DELETE THE ILLEGAL DUMMY STATEMENTS OF THE FORM
C     * EXPANSION (NNNN) *
C
C     ALSO INSERT APPROPRIATE DATA STATEMENTS TO DEFINE CONSTANTS
C     WHICH DEPEND ON THE RANGE OF NUMBERS REPRESENTED BY THE
C     MACHINE, RATHER THAN THE PRECISION (SUITABLE STATEMENTS FOR
C     SOME MACHINES ARE CONTAINED IN COMMENTS BEGINNING CRD WHERE
C     D IS A DIGIT WHICH SIMPLY DISTINGUISHES A GROUP OF MACHINES).
C     DELETE THE ILLEGAL DUMMY DATA STATEMENTS WITH VALUES WRITTEN
C     *VALUE*
C
C     **************************************************************
C

S19ADF
      DOUBLE PRECISION FUNCTION S19ADF(X,IFAIL)
C     MARK 11 RELEASE. NAG COPYRIGHT 1983.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     KELVIN FUNCTION KEI(X)
C
C     **************************************************************
C
C     TO EXTRACT THE CORRECT CODE FOR A PARTICULAR MACHINE-RANGE,
C     ACTIVATE THE STATEMENTS CONTAINED IN COMMENTS BEGINNING  CDD ,
C     WHERE  DD  IS THE APPROXIMATE NUMBER OF SIGNIFICANT DECIMAL
C     DIGITS REPRESENTED BY THE MACHINE
C     DELETE THE ILLEGAL DUMMY STATEMENTS OF THE FORM
C     * EXPANSION (NNNN) *
C
C     ALSO INSERT APPROPRIATE DATA STATEMENTS TO DEFINE CONSTANTS
C     WHICH DEPEND ON THE RANGE OF NUMBERS REPRESENTED BY THE
C     MACHINE, RATHER THAN THE PRECISION (SUITABLE STATEMENTS FOR
C     SOME MACHINES ARE CONTAINED IN COMMENTS BEGINNING CRD WHERE
C     D IS A DIGIT WHICH SIMPLY DISTINGUISHES A GROUP OF MACHINES).
C     DELETE THE ILLEGAL DUMMY DATA STATEMENTS WITH VALUES WRITTEN
C     *VALUE*
C
C     **************************************************************
C

S20ACF
      DOUBLE PRECISION FUNCTION S20ACF(X,IFAIL)
C     MARK 7 RELEASE. NAG COPYRIGHT 1978.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     FRESNEL INTEGRAL S(X)
C
C     **************************************************************
C
C     TO EXTRACT THE CORRECT CODE FOR A PARTICULAR MACHINE-RANGE,
C     ACTIVATE THE STATEMENTS CONTAINED IN COMMENTS BEGINNING  CDD ,
C     WHERE  DD  IS THE APPROXIMATE NUMBER OF SIGNIFICANT DECIMAL
C     DIGITS REPRESENTED BY THE MACHINE
C     DELETE THE ILLEGAL DUMMY STATEMENTS OF THE FORM
C     * EXPANSION (NNNN) *
C
C     ALSO INSERT APPROPRIATE DATA STATEMENTS TO DEFINE CONSTANTS
C     WHICH DEPEND ON THE RANGE OF NUMBERS REPRESENTED BY THE
C     MACHINE, RATHER THAN THE PRECISION (SUITABLE STATEMENTS FOR
C     SOME MACHINES ARE CONTAINED IN COMMENTS BEGINNING CRD WHERE
C     D IS A DIGIT WHICH SIMPLY DISTINGUISHES A GROUP OF MACHINES).
C     DELETE THE ILLEGAL DUMMY DATA STATEMENTS WITH VALUES WRITTEN
C     *VALUE*
C
C     **************************************************************
C

S20ADF
      DOUBLE PRECISION FUNCTION S20ADF(X,IFAIL)
C     MARK 7 RELEASE. NAG COPYRIGHT 1978.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     FRESNEL INTEGRAL C(X)
C
C     **************************************************************
C
C     TO EXTRACT THE CORRECT CODE FOR A PARTICULAR MACHINE-RANGE,
C     ACTIVATE THE STATEMENTS CONTAINED IN COMMENTS BEGINNING  CDD ,
C     WHERE  DD  IS THE APPROXIMATE NUMBER OF SIGNIFICANT DECIMAL
C     DIGITS REPRESENTED BY THE MACHINE
C     DELETE THE ILLEGAL DUMMY STATEMENTS OF THE FORM
C     * EXPANSION (NNNN) *
C
C     ALSO INSERT APPROPRIATE DATA STATEMENTS TO DEFINE CONSTANTS
C     WHICH DEPEND ON THE RANGE OF NUMBERS REPRESENTED BY THE
C     MACHINE, RATHER THAN THE PRECISION (SUITABLE STATEMENTS FOR
C     SOME MACHINES ARE CONTAINED IN COMMENTS BEGINNING CRD WHERE
C     D IS A DIGIT WHICH SIMPLY DISTINGUISHES A GROUP OF MACHINES).
C     DELETE THE ILLEGAL DUMMY DATA STATEMENTS WITH VALUES WRITTEN
C     *VALUE*
C
C     **************************************************************
C

S21BAF
      DOUBLE PRECISION FUNCTION S21BAF(X,Y,IFAIL)
C     MARK 14 RE-ISSUE.  NAG COPYRIGHT 1989.
C
C     ******************************************************************
C
C     Calculates an approximate value for the function
C     Rc(x,y) related to the elliptic integrals.
C     The function is as defined by  Carlson - Special
C           Functions of Applied Mathematics - Academic Press(1977)
C
C     Rc(x,y)=integral(zero to infinity) of
C               0.5/(sqrt(t+x)*(t+y)) dt
C
C     subject to restrictions
C          x.ge.0.0 and y.ne.0.0
C     ******************************************************************
C     Precision-dependent constant
C
C        ACC  Controls final truncation accuracy. An accuracy
C                 close to full machine precision can be obtained
C                 for all legal arguments if ACC is chosen so that
C           16.0*ACC**6/(1.0-2.0*ACC).le.X02AJF/X02BHF
C
C     To select the correct value for a particular machine-range,
C     activate the statement contained in a comment beginning  CDD ,
C     where  DD  is the approximate number of significant decimal
C     digits represented by the machine.
C     * EXPANSION (DATA) *
C     ******************************************************************
C

S21BBF
      DOUBLE PRECISION FUNCTION S21BBF(X,Y,Z,IFAIL)
C     MARK 14 RE-ISSUE.  NAG COPYRIGHT 1989.
C
C     ******************************************************************
C
C      Calculates an approximate value for the elliptic integral of
C      the first kind, Rf(X,Y,Z), as defined by B.C.Carlson.
C      - Special Functions of Applied Maths - Academic Press(1977).
C      The algorithm is also due to Carlson but has been recoded by
C      J.L.Schonfelder to avoid intermediate under and overflows.
C
C      Rf(X,Y,Z)=integral(zero to infinity) of
C          0.5/sqrt((t+X)*(t+Y)*(t+Z)) dt
C
C      for X,Y,Z all .ge. zero and at most one equal to zero.
C
C     ******************************************************************
C     Precision-dependent constant
C
C        ACC  Controls final truncation accuracy. An accuracy
C                 close to full machine precision can be obtained
C                 for all legal arguments if ACC is chosen so that
C           0.25*ACC**6/(1.0-ACC).le.X02AJF/X02BHF
C
C     To select the correct value for a particular machine-range,
C     activate the statement contained in a comment beginning  CDD ,
C     where  DD  is the approximate number of significant decimal
C     digits represented by the machine.
C     * EXPANSION (DATA) *
C     ******************************************************************
C

S21BCF
      DOUBLE PRECISION FUNCTION S21BCF(X,Y,Z,IFAIL)
C     MARK 14 RE-ISSUE.  NAG COPYRIGHT 1989.
C
C     ******************************************************************
C
C      Calculates an approximate value for the elliptic integral of
C      the second kind, Rd(X,Y,Z), as defined by B.C.Carlson.
C       - Special Functions of Applied Maths - Academic Press(1977).
C      The algorithm is also due to Carlson.
C
C      Rd(X,Y,Z)=integral(zero to infinity) of
C          1.5/sqrt((t+X)*(t+Y)*(t+Z)**3) dt
C
C      for X.ge.0.0 , Y.ge.0.0, Z.gt.0.0 and at most one of X
C      and Y equal to 0.0.
C
C     ******************************************************************
C     Precision-dependent constant
C
C        ACC  Controls final truncation accuracy. An accuracy
C                 close to full machine precision can be obtained
C                 for all legal arguments if ACC is chosen so that
C           3.0*ACC**6/(1.0-ACC)**1.5.le.X02AJF/X02BHF
C
C     To select the correct value for a particular machine-range,
C     activate the statement contained in a comment beginning  CDD ,
C     where  DD  is the approximate number of significant decimal
C     digits represented by the machine.
C     * EXPANSION (DATA) *
C     ******************************************************************
C

S21BDF
      DOUBLE PRECISION FUNCTION S21BDF(X,Y,Z,R,IFAIL)
C     MARK 14 RE-ISSUE.  NAG COPYRIGHT 1989.
C
C     ******************************************************************
C
C      Calculates an approximate value for the elliptic integral of
C      the third kind, Rj(X,Y,Z,R), as defined by B.C.Carlson.
C      - Special Functions of Applied Maths - Academic Press(1977).
C      The algorithm is also due to Carlson
C
C      Rj(X,Y,Z,R)=integral(zero to infinity) of
C          1.5/(sqrt((t+X)*(t+Y)*(t+Z))*(t+R)) dt
C
C      for X.ge.0.0 , Y.ge.0.0 , Z.ge.0.0
C         X+Y.gt.0.0
C         Y+Z.gt.0.0
C         Z+X.gt.0.0
C         R.ne.0.0
C
C     ******************************************************************
C     Precision-dependent constant
C
C        ACC  Controls final truncation accuracy. An accuracy
C                 close to full machine precision can be obtained
C                 for all legal arguments if ACC is chosen so that
C           3.0*ACC**6/(1.0-ACC)**1.5.le.X02AJF/X02BHF
C
C     To select the correct value for a particular machine-range,
C     activate the statement contained in a comment beginning  CDD,
C     where  DD  is the approximate number of significant decimal
C     digits represented by the machine.
C     * EXPANSION (DATA) *
C     ******************************************************************
C

S21CAF
      SUBROUTINE S21CAF(U,M,SN,CN,DN,IFAIL)
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C
C     Returns Jacobian elliptic functions sn, cn, dn.
C     Based on routine by R. Bulirsch (Num. Math. 7, pp 76-90, 1965).
C

X01AAF
      DOUBLE PRECISION FUNCTION X01AAF(X)
C     MARK 8 RE-ISSUE. NAG COPYRIGHT 1980.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     RETURNS THE VALUE OF THE MATHEMATICAL CONSTANT PI.
C
C     X IS A DUMMY ARGUMENT
C
C     IT MAY BE NECESSARY TO ROUND THE REAL CONSTANT IN THE
C     ASSIGNMENT STATEMENT TO A SMALLER NUMBER OF SIGNIFICANT
C     DIGITS IN ORDER TO AVOID COMPILATION PROBLEMS.  IF SO, THEN
C     THE NUMBER OF DIGITS RETAINED SHOULD NOT BE LESS THAN
C     .     2 + INT(FLOAT(IT)*ALOG10(IB))
C     WHERE  IB  IS THE BASE FOR THE REPRESENTATION OF FLOATING-
C     .             POINT NUMBERS
C     . AND  IT  IS THE NUMBER OF IB-ARY DIGITS IN THE MANTISSA OF
C     .             A FLOATING-POINT NUMBER.
C

X01ABF
      DOUBLE PRECISION FUNCTION X01ABF(X)
C     MARK 8 RE-ISSUE. NAG COPYRIGHT 1980.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     RETURNS THE VALUE OF THE MATHEMATICAL CONSTANT GAMMA.
C
C     X IS A DUMMY ARGUMENT
C
C     IT MAY BE NECESSARY TO ROUND THE REAL CONSTANT IN THE
C     ASSIGNMENT STATEMENT TO A SMALLER NUMBER OF SIGNIFICANT
C     DIGITS IN ORDER TO AVOID COMPILATION PROBLEMS.  IF SO, THEN
C     THE NUMBER OF DIGITS RETAINED SHOULD NOT BE LESS THAN
C     .     2 + INT(FLOAT(IT)*ALOG10(IB))
C     WHERE  IB  IS THE BASE FOR THE REPRESENTATION OF FLOATING-
C     .             POINT NUMBERS
C     . AND  IT  IS THE NUMBER OF IB-ARY DIGITS IN THE MANTISSA OF
C     .             A FLOATING-POINT NUMBER.
C

X02AHF
      DOUBLE PRECISION FUNCTION X02AHF(X)
C     MARK 9 RELEASE. NAG COPYRIGHT 1981.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     * MAXIMUM ARGUMENT FOR SIN AND COS *
C     RETURNS THE LARGEST POSITIVE REAL NUMBER MAXSC SUCH THAT
C     SIN(MAXSC) AND COS(MAXSC) CAN BE SUCCESSFULLY COMPUTED
C     BY THE COMPILER SUPPLIED SIN AND COS ROUTINES.
C

X02AJF
      DOUBLE PRECISION FUNCTION X02AJF()
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C
C     RETURNS  (1/2)*B**(1-P)  IF ROUNDS IS .TRUE.
C     RETURNS  B**(1-P)  OTHERWISE
C
      DOUBLE PRECISION X02CON
      INTEGER      Z(2)
      EQUIVALENCE (Z,X02CON)
C     DATA X02CON /Z'3CA0000000000001' /
      DATA Z  /Z'00000001',Z'3CA00000' /

X02AKF
      DOUBLE PRECISION FUNCTION X02AKF()
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C
C     RETURNS  B**(EMIN-1)  (THE SMALLEST POSITIVE MODEL NUMBER)
C
      DOUBLE PRECISION X02CON
      INTEGER      Z(2)
      EQUIVALENCE (Z,X02CON)
C     DATA X02CON /Z'0010000000000000' /
      DATA Z  /Z'00000000',Z'00100000' /

X02ALF
      DOUBLE PRECISION FUNCTION X02ALF()
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C
C     RETURNS  (1 - B**(-P)) * B**EMAX  (THE LARGEST POSITIVE MODEL
C     NUMBER)
C
      DOUBLE PRECISION X02CON
      INTEGER      Z(2)
      EQUIVALENCE (Z,X02CON)
C     DATA X02CON /Z'7FEFFFFFFFFFFFFF' /
      DATA Z  /Z'FFFFFFFF',Z'7FEFFFFF' /

X02AMF
      DOUBLE PRECISION FUNCTION X02AMF()
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C
C     RETURNS THE 'SAFE RANGE' PARAMETER
C     I.E. THE SMALLEST POSITIVE MODEL NUMBER Z SUCH THAT
C     FOR ANY X WHICH SATISFIES X.GE.Z AND X.LE.1/Z
C     THE FOLLOWING CAN BE COMPUTED WITHOUT OVERFLOW, UNDERFLOW OR OTHER
C     ERROR
C
C        -X
C        1.0/X
C        SQRT(X)
C        LOG(X)
C        EXP(LOG(X))
C        Y**(LOG(X)/LOG(Y)) FOR ANY Y
C
      DOUBLE PRECISION X02CON
      INTEGER      Z(2)
      EQUIVALENCE (Z,X02CON)
C     DATA X02CON /Z'0010000000000000' /
      DATA  Z /Z'00000000',Z'00100000' /

X02ANF
      DOUBLE PRECISION FUNCTION X02ANF()
C     MARK 15 RELEASE. NAG COPYRIGHT 1991.
C
C     Returns the 'safe range' parameter for complex numbers,
C     i.e. the smallest positive model number Z such that
C     for any X which satisfies X.ge.Z and X.le.1/Z
C     the following can be computed without overflow, underflow or other
C     error
C
C        -W
C        1.0/W
C        SQRT(W)
C        LOG(W)
C        EXP(LOG(W))
C        Y**(LOG(W)/LOG(Y)) for any Y
C        ABS(W)
C
C     where W is any of cmplx(X,0), cmplx(0,X), cmplx(X,X),
C                   cmplx(1/X,0), cmplx(0,1/X), cmplx(1/X,1/X).
C
      DOUBLE PRECISION X02CON
      INTEGER      Z(2)
      EQUIVALENCE (Z,X02CON)
C     DATA X02CON /Z'0020000000000000' /
      DATA Z  /Z'00000000',Z'00200000' /

X02BBF
      INTEGER FUNCTION X02BBF(X)
C     NAG COPYRIGHT 1975
C     MARK 4.5 RELEASE
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     * MAXINT *
C     RETURNS THE LARGEST INTEGER REPRESENTABLE ON THE COMPUTER
C     THE X PARAMETER IS NOT USED

X02BEF
      INTEGER FUNCTION X02BEF(X)
C     NAG COPYRIGHT 1975
C     MARK 4.5 RELEASE
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     * MAXDEC *
C     RETURNS THE MAXIMUM NUMBER OF DECIMAL DIGITS THAT CAN BE
C     ACCURATELY REPRESENTED IN THE COMPUTER OVER THE WHOLE RANGE
C     OF FLOATING-POINT NUMBERS.
C     THE X PARAMETER IS NOT USED.

X02BHF
      INTEGER FUNCTION X02BHF()
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C
C     RETURNS THE MODEL PARAMETER, B.
C

X02BJF
      INTEGER FUNCTION X02BJF()
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C
C     RETURNS THE MODEL PARAMETER, p.
C

X02BKF
      INTEGER FUNCTION X02BKF()
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C
C     RETURNS THE MODEL PARAMETER, EMIN.
C

X02BLF
      INTEGER FUNCTION X02BLF()
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C
C     RETURNS THE MODEL PARAMETER, EMAX.
C

X02DAF
      LOGICAL FUNCTION X02DAF(X)
C     MARK 8 RELEASE. NAG COPYRIGHT 1980.
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C
C     RETURNS .FALSE. IF THE SYSTEM SETS UNDERFLOWING QUANTITIES
C     TO ZERO, WITHOUT ANY ERROR INDICATION OR UNDESIRABLE WARNING
C     OR SYSTEM OVERHEAD.
C     RETURNS .TRUE. OTHERWISE, IN WHICH CASE CERTAIN LIBRARY
C     ROUTINES WILL TAKE SPECIAL PRECAUTIONS TO AVOID UNDERFLOW
C     (USUALLY AT SOME COST IN EFFICIENCY).
C
C     X IS A DUMMY ARGUMENT
C

X02DJF
      LOGICAL FUNCTION X02DJF()
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C
C     RETURNS THE MODEL PARAMETER, ROUNDS.
C

X03AAF
      SUBROUTINE X03AAF(A,ISIZEA,B,ISIZEB,N,ISTEPA,ISTEPB,C1,C2,D1,D2,
     *                  SW,IFAIL)
C     MARK 10 RE-ISSUE. NAG COPYRIGHT 1982
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 12 REVISED. IER-524 (AUG 1986).
C     DOUBLE PRECISION BASE VERSION
C
C     CALCULATES THE VALUE OF A SCALAR PRODUCT USING BASIC OR
C     ADDITIONAL PRECISION AND ADDS IT TO A BASIC OR ADDITIONAL
C     PRECISION INITIAL VALUE.
C
C     FOR THIS DOUBLE PRECISION VERSION, ALL ADDITIONAL (I.E.
C     QUADRUPLE) PRECISION COMPUTATION IS PERFORMED BY THE AUXILIARY
C     ROUTINE X03AAY.  SEE THE COMMENTS AT THE HEAD OF THAT ROUTINE
C     CONCERNING IMPLEMENTATION.
C
C

X03ABF
      SUBROUTINE X03ABF(A,ISIZEA,B,ISIZEB,N,ISTEPA,ISTEPB,CX,DX,SW,
     *                  IFAIL)
C     MARK 10 RE-ISSUE. NAG COPYRIGHT 1982
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     DOUBLE PRECISION COMPLEX BASE VERSION
C
C     CALCULATES THE VALUE OF A COMPLEX SCALAR PRODUCT USING BASIC
C     OR ADDITIONAL PRECISION AND ADDS IT TO A BASIC PRECISION
C     INITIAL VALUE.
C
C     FOR THIS DOUBLE PRECISION COMPLEX VERSION, ALL ADDITIONAL
C     (I.E. QUADRUPLE) PRECISION COMPUTATION IS PERFORMED BY THE
C     AUXILIARY ROUTINE X03ABY.  SEE THE COMMENTS AT THE HEAD OF
C     THAT ROUTINE CONCERNING IMPLEMENTATION.
C
C

X04AAF
      SUBROUTINE X04AAF(I,NERR)
C     MARK 7 RELEASE. NAG COPYRIGHT 1978
C     MARK 7C REVISED IER-190 (MAY 1979)
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 14 REVISED. IER-829 (DEC 1989).
C     IF I = 0, SETS NERR TO CURRENT ERROR MESSAGE UNIT NUMBER
C     (STORED IN NERR1).
C     IF I = 1, CHANGES CURRENT ERROR MESSAGE UNIT NUMBER TO
C     VALUE SPECIFIED BY NERR.
C

X04ABF
      SUBROUTINE X04ABF(I,NADV)
C     MARK 7 RELEASE. NAG COPYRIGHT 1978
C     MARK 7C REVISED IER-190 (MAY 1979)
C     MARK 11.5(F77) REVISED. (SEPT 1985.)
C     MARK 14 REVISED. IER-830 (DEC 1989).
C      IF I = 0, SETS NADV TO CURRENT ADVISORY MESSAGE UNIT NUMBER
C     (STORED IN NADV1).
C     IF I = 1, CHANGES CURRENT ADVISORY MESSAGE UNIT NUMBER TO
C     VALUE SPECIFIED BY NADV.
C

X04BAF
      SUBROUTINE X04BAF(NOUT,REC)
C     MARK 11.5(F77) RELEASE. NAG COPYRIGHT 1986.
C
C     X04BAF writes the contents of REC to the unit defined by NOUT.
C
C     Trailing blanks are not output, except that if REC is entirely
C     blank, a single blank character is output.
C     If NOUT.lt.0, i.e. if NOUT is not a valid Fortran unit identifier,
C     then no output occurs.
C

X04BBF
      SUBROUTINE X04BBF(NIN,REC,IFAIL)
C     MARK 12 RELEASE. NAG COPYRIGHT 1986.
C
C     X04BBF reads a record from device NIN into REC.
C     IFAIL is set to unity if an End-Of-File is found.
C

X04CAF
      SUBROUTINE X04CAF(MATRIX,DIAG,M,N,A,LDA,TITLE,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C     Prints a general real matrix.
C     Easy to use driver for X04CBF.

X04CBF
      SUBROUTINE X04CBF(MATRIX,DIAG,M,N,A,LDA,FORMAT,TITLE,LABROW,RLABS,
     *                  LABCOL,CLABS,NCOLS,INDENT,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C     MARK 16A REVISED. IER-1047 (JUN 1993).
C     Prints a general real matrix.

X04CCF
      SUBROUTINE X04CCF(UPLO,DIAG,N,A,TITLE,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C     Prints a real triangular matrix stored in packed vector form.
C     Easy to use driver for X04CDF.

X04CDF
      SUBROUTINE X04CDF(UPLO,DIAG,N,A,FORMAT,TITLE,LABROW,RLABS,LABCOL,
     *                  CLABS,NCOLS,INDENT,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C     MARK 16A REVISED. IER-1048 (JUN 1993).
C     Prints a real triangular matrix stored in packed vector form.

X04CEF
      SUBROUTINE X04CEF(M,N,KL,KU,A,LDA,TITLE,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C     Prints a real banded matrix stored in packed form.
C     Easy to use driver for X04CFF.

X04CFF
      SUBROUTINE X04CFF(M,N,KL,KU,A,LDA,FORMAT,TITLE,LABROW,RLABS,
     *                  LABCOL,CLABS,NCOLS,INDENT,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C     Prints a real banded matrix stored in packed form.

X04DAF
      SUBROUTINE X04DAF(MATRIX,DIAG,M,N,A,LDA,TITLE,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C     Prints a general complex matrix.
C     Easy to use driver for X04DBF.

X04DBF
      SUBROUTINE X04DBF(MATRIX,DIAG,M,N,A,LDA,USEFRM,FORMAT,TITLE,
     *                  LABROW,RLABS,LABCOL,CLABS,NCOLS,INDENT,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C     MARK 16A REVISED. IER-1049 (JUN 1993).
C     Prints a general complex matrix.

X04DCF
      SUBROUTINE X04DCF(UPLO,DIAG,N,A,TITLE,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C     Prints a complex triangular matrix stored in packed vector form.
C     Easy to use driver for X04DDF.

X04DDF
      SUBROUTINE X04DDF(UPLO,DIAG,N,A,USEFRM,FORMAT,TITLE,LABROW,RLABS,
     *                  LABCOL,CLABS,NCOLS,INDENT,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C     Prints a complex triangular matrix stored in packed vector form.

X04DEF
      SUBROUTINE X04DEF(M,N,KL,KU,A,LDA,TITLE,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C     Prints a complex banded matrix stored in packed form.
C     Easy to use driver for X04DFF.

X04DFF
      SUBROUTINE X04DFF(M,N,KL,KU,A,LDA,USEFRM,FORMAT,TITLE,LABROW,
     *                  RLABS,LABCOL,CLABS,NCOLS,INDENT,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C     Prints a complex banded matrix stored in packed form.

X04EAF
      SUBROUTINE X04EAF(MATRIX,DIAG,M,N,A,LDA,TITLE,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C     Prints a general integer matrix.
C     Easy to use driver for X04EBF.

X04EBF
      SUBROUTINE X04EBF(MATRIX,DIAG,M,N,A,LDA,FORMAT,TITLE,LABROW,RLABS,
     *                  LABCOL,CLABS,NCOLS,INDENT,IFAIL)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C     MARK 16A REVISED. IER-1050 (JUN 1993).
C     Prints a general integer matrix.

X05AAF
      SUBROUTINE X05AAF(ITIME)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     Returns the current date and time in the integer array ITIME.
C     On exit, ITIME should contain the following values:
C       ITIME(1) : the current year.
C       ITIME(2) : the current month, in the range 1 - 12.
C       ITIME(3) : the current day, in the range 1 - 31.
C       ITIME(4) : the current hour, in the range 0 - 23.
C       ITIME(5) : the current minute, in the range 0 - 59.
C       ITIME(6) : the current second, in the range 0 - 59.
C       ITIME(7) : the current millisecond, in the range 0 - 999.
C
      INTEGER TIME,C
C     INTEGER*8 TARRAY(9)
      INTEGER*4 TARRAY(9)
      INTEGER ITIME(7)
      EXTERNAL TIME,LTIME
      C=TIME()
      CALL LTIME(C,TARRAY)
      ITIME(1) = TARRAY(6)+1900 
      ITIME(2) = TARRAY(5)+1
      ITIME(3) = TARRAY(4)
      ITIME(4) = TARRAY(3)
      ITIME(5) = TARRAY(2)
      ITIME(6) = TARRAY(1)
      ITIME(7) = 0
C
      RETURN
      END

X05ABF
      CHARACTER*30 FUNCTION X05ABF(ITIME)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     Converts from the seven-integer format date/time in ITIME, as
C     returned by subroutine X05AAF, into a character string.
C     The character string has the format, for example,
C     'Thu 20th Apr 1989 16:37:57.320' .
C

X05ACF
      INTEGER FUNCTION X05ACF(CTIME1,CTIME2)
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     Compares the date/time strings CTIME1 and CTIME2.
C     Returns -1 if CTIME1 is earlier than CTIME2,
C              0 if CTIME1 is the same as CTIME2,
C          and 1 if CTIME1 is later than CTIME2.
C

X05BAF
      DOUBLE PRECISION FUNCTION X05BAF()
C     MARK 14 RELEASE. NAG COPYRIGHT 1989.
C
C     Returns the amount of CPU time used since some previous time,
C     in seconds. The previous time is arbitrary, but may be the time
C     that the job or the program started, for example. The difference
C     between two separate calls of this routine is then (approximately)
C     the CPU time used between the calls.
C
C     
      EXTERNAL ETIME
      REAL ETIME
      X05BAF = ETIME(0)
      RETURN
      END