X04 Chapter Contents
X04 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentX04CDF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

X04CDF prints a real triangular matrix stored in a packed one-dimensional array.

## 2  Specification

 SUBROUTINE X04CDF ( UPLO, DIAG, N, A, FORM, TITLE, LABROW, RLABS, LABCOL, CLABS, NCOLS, INDENT, IFAIL)
 INTEGER N, NCOLS, INDENT, IFAIL REAL (KIND=nag_wp) A(*) CHARACTER(*) FORM, TITLE, RLABS(*), CLABS(*) CHARACTER(1) UPLO, DIAG, LABROW, LABCOL

## 3  Description

X04CDF prints a real triangular matrix stored in packed form, using a format specifier supplied by you. The matrix must be packed by column. The matrix is output to the unit defined by X04ABF.

None.

## 5  Parameters

1:     $\mathrm{UPLO}$ – CHARACTER(1)Input
On entry: indicates the type of the matrix to be printed
${\mathbf{UPLO}}=\text{'L'}$
The matrix is lower triangular. In this case, the packed array A holds the matrix elements in the following order: $\left(1,1\right),\left(2,1\right),\dots ,\left({\mathbf{N}},1\right),\left(2,2\right),\left(3,2\right),\dots ,\left({\mathbf{N}},2\right)$, etc.
${\mathbf{UPLO}}=\text{'U'}$
The matrix is upper triangular. In this case, the packed array A holds the matrix elements in the following order: $\left(1,1\right),\left(1,2\right),\left(2,2\right),\left(1,3\right),\left(2,3\right),\left(3,3\right),\left(1,4\right)$, etc.
Constraint: ${\mathbf{UPLO}}=\text{'L'}$ or $\text{'U'}$.
2:     $\mathrm{DIAG}$ – CHARACTER(1)Input
On entry: indicates whether the diagonal elements of the matrix are to be printed.
${\mathbf{DIAG}}=\text{'B'}$
The diagonal elements of the matrix are not referenced and not printed.
${\mathbf{DIAG}}=\text{'U'}$
The diagonal elements of the matrix are not referenced, but are assumed all to be unity, and are printed as such.
${\mathbf{DIAG}}=\text{'N'}$
The diagonal elements of the matrix are referenced and printed.
Constraint: ${\mathbf{DIAG}}=\text{'B'}$, $\text{'U'}$ or $\text{'N'}$.
3:     $\mathrm{N}$ – INTEGERInput
On entry: the order of the matrix to be printed.
If N is less than $1$, X04CDF will exit immediately after printing TITLE; no row or column labels are printed.
4:     $\mathrm{A}\left(*\right)$ – REAL (KIND=nag_wp) arrayInput
Note: the dimension of the array A must be at least $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{N}}×\left({\mathbf{N}}+1\right)/2\right)$.
On entry: the matrix to be printed. Note that A must have space for the diagonal elements of the matrix, even if these are not stored.
More precisely,
• if ${\mathbf{UPLO}}=\text{'U'}$, the upper triangle of $A$ must be stored with element ${A}_{ij}$ in ${\mathbf{A}}\left(i+j\left(j-1\right)/2\right)$ for $i\le j$;
• if ${\mathbf{UPLO}}=\text{'L'}$, the lower triangle of $A$ must be stored with element ${A}_{ij}$ in ${\mathbf{A}}\left(i+\left(2n-j\right)\left(j-1\right)/2\right)$ for $i\ge j$.
If ${\mathbf{DIAG}}=\text{'U'}$, the diagonal elements of $A$ are assumed to be $1$, and are not referenced; the same storage scheme is used whether ${\mathbf{DIAG}}=\text{'N'}$ or ‘U’.
5:     $\mathrm{FORM}$ – CHARACTER(*)Input
On entry: describes the Fortran format code for printing the elements of the matrix A. The format code may be any allowed on the system, whether it is standard Fortran or not. It may or may not be enclosed in brackets.
In addition, there are the following special codes which force X04CDF to choose its own format code:
X04CDF will choose a format code such that numbers will be printed with an F8.4, an F11.4 or a 1PE13.4 format. The F8.4 code is chosen if the sizes of all the matrix elements to be printed lie between $0.001$ and $1.0$. The F11.4 code is chosen if the sizes of all the matrix elements to be printed lie between $0.001$ and $9999.9999$. Otherwise the 1PE13.4 code is chosen.
${\mathbf{FORM}}=\text{'*'}$
X04CDF will choose a format code such that numbers will be printed to as many significant digits as are necessary to distinguish between neighbouring machine numbers. Thus any two numbers that are stored with different internal representations should look different on output. Whether they do in fact look different will depend on the run-time library of the Fortran compiler in use.
By preceding the desired format code by the string ‘MATLAB’, X04CDF will print the matrix such that it can be input into MATLAB, and TITLE will be used as the name of the matrix.
Examples of valid values for FORM are $\text{'F11.4'}$, $\text{'1PE13.5'}$, $\text{'G14.5'}$, $\text{'MATLABF11.4'}$, $\text{'MATLAB*'}$.
Constraint: the character length of the format specifier in FORM must be $\text{}\le 80$.
6:     $\mathrm{TITLE}$ – CHARACTER(*)Input
On entry: a title to be printed above the matrix, or name of the matrix.
If , no title (and no blank line) will be printed.
If TITLE contains more than NCOLS characters, the contents of TITLE will be wrapped onto more than one line, with the break after NCOLS characters.
Any trailing blank characters in TITLE are ignored.
If printing in MATLAB mode, TITLE will be used as the name of the matrix.
7:     $\mathrm{LABROW}$ – CHARACTER(1)Input
On entry: indicates the type of labelling to be applied to the rows of the matrix, except in MATLAB mode where LABROW is ignored.
${\mathbf{LABROW}}=\text{'N'}$
Prints no row labels.
${\mathbf{LABROW}}=\text{'I'}$
Prints integer row labels.
${\mathbf{LABROW}}=\text{'C'}$
Prints character labels, which must be supplied in array RLABS.
Constraint: ${\mathbf{LABROW}}=\text{'N'}$, $\text{'I'}$ or $\text{'C'}$.
8:     $\mathrm{RLABS}\left(*\right)$ – CHARACTER(*) arrayInput
Note: the dimension of the array RLABS must be at least ${\mathbf{N}}$ if ${\mathbf{LABROW}}=\text{'C'}$, and at least $1$ otherwise.
On entry: if ${\mathbf{LABROW}}=\text{'C'}$, RLABS must contain labels for the rows of the matrix, except in MATLAB mode where RLABS is ignored.
Labels are right-justified when output, in a field which is as wide as necessary to hold the longest row label. Note that this field width is subtracted from the number of usable columns, NCOLS.
9:     $\mathrm{LABCOL}$ – CHARACTER(1)Input
On entry: indicates the type of labelling to be applied to the columns of the matrix, except in MATLAB mode where LABCOL is ignored.
${\mathbf{LABCOL}}=\text{'N'}$
Prints no column labels.
${\mathbf{LABCOL}}=\text{'I'}$
Prints integer column labels.
${\mathbf{LABCOL}}=\text{'C'}$
Prints character labels, which must be supplied in array CLABS.
Constraint: ${\mathbf{LABCOL}}=\text{'N'}$, $\text{'I'}$ or $\text{'C'}$.
10:   $\mathrm{CLABS}\left(*\right)$ – CHARACTER(*) arrayInput
Note: the dimension of the array CLABS must be at least ${\mathbf{N}}$ if ${\mathbf{LABCOL}}=\text{'C'}$, and at least $1$ otherwise.
On entry: if ${\mathbf{LABCOL}}=\text{'C'}$, CLABS must contain labels for the columns of the matrix, except in MATLAB mode where CLABS is ignored.
Labels are right-justified when output. Any label that is too long for the column width, which is determined by FORM, is truncated.
11:   $\mathrm{NCOLS}$ – INTEGERInput
On entry: the maximum output record length. If the number of columns of the matrix is too large to be accommodated in NCOLS characters, the matrix will be printed in parts, containing the largest possible number of matrix columns, and each part separated by a blank line.
NCOLS must be large enough to hold at least one column of the matrix using the format specifier in FORM. If a value less than 0 or greater than $132$ is supplied for NCOLS, then the value $80$ is used instead.
12:   $\mathrm{INDENT}$ – INTEGERInput
On entry: the number of columns by which the matrix (and any title and labels) should be indented. The effective value of NCOLS is reduced by INDENT columns. If a value less than $0$ or greater than NCOLS is supplied for INDENT, the value $0$ is used instead.
13:   $\mathrm{IFAIL}$ – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is $0$. When the value $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit: ${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{1}}$, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
${\mathbf{IFAIL}}=1$
 On entry, ${\mathbf{UPLO}}\ne \text{'L'}$ or $\text{'U'}$.
${\mathbf{IFAIL}}=2$
 On entry, ${\mathbf{DIAG}}\ne \text{'N'}$, $\text{'U'}$ or $\text{'B'}$.
${\mathbf{IFAIL}}=3$
 On entry, the format specifier in FORM is more than $80$ characters long.
${\mathbf{IFAIL}}=4$
The format specifier in FORM cannot be used to output a number. The specifier probably has too wide a field width or contains an illegal edit descriptor.
${\mathbf{IFAIL}}=5$
 On entry, either LABROW or ${\mathbf{LABCOL}}\ne \text{'N'}$, $\text{'I'}$ or $\text{'C'}$.
${\mathbf{IFAIL}}=6$
The quantity ${\mathbf{NCOLS}}-{\mathbf{INDENT}}-\mathit{labwid}$ (where $\mathit{labwid}$ is the width needed for the row labels) is not large enough to hold at least one column of the matrix.
${\mathbf{IFAIL}}=-99$
See Section 3.8 in the Essential Introduction for further information.
${\mathbf{IFAIL}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 3.7 in the Essential Introduction for further information.
${\mathbf{IFAIL}}=-999$
Dynamic memory allocation failed.
See Section 3.6 in the Essential Introduction for further information.

Not applicable.

Not applicable.

None.

## 10  Example

This example calls X04CDF three times, first to print $4$ by $4$ lower triangular matrix, and then twice to print a $5$ by $5$ upper triangular matrix; various options for labelling and formatting are illustrated.

### 10.1  Program Text

Program Text (x04cdfe.f90)

None.

### 10.3  Program Results

Program Results (x04cdfe.r)