F01 Chapter Contents
F01 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentF01ZAF

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

F01ZAF copies a real triangular matrix stored in a packed one-dimensional array into an unpacked two-dimensional array, or vice versa.

## 2  Specification

 SUBROUTINE F01ZAF ( JOB, UPLO, DIAG, N, A, LDA, B, IFAIL)
 INTEGER N, LDA, IFAIL REAL (KIND=nag_wp) A(LDA,N), B((N*(N+1))/2) CHARACTER(1) JOB, UPLO, DIAG

## 3  Description

F01ZAF unpacks a triangular matrix stored in a vector into a two-dimensional array, or packs a triangular matrix stored in a two-dimensional array into a vector. The matrix is packed by column. This routine is intended for possible use in conjunction with routines from Chapters F06, F07 and F08 where some routines that use triangular matrices store them in the packed form described below.

None.

## 5  Parameters

1:     JOB – CHARACTER(1)Input
On entry: specifies whether the triangular matrix is to be packed or unpacked.
${\mathbf{JOB}}=\text{'P'}$ (Pack)
The matrix is to be packed into array B.
${\mathbf{JOB}}=\text{'U'}$ (Unpack)
The matrix is to be unpacked into array A.
Constraint: ${\mathbf{JOB}}=\text{'P'}$ or $\text{'U'}$.
2:     UPLO – CHARACTER(1)Input
On entry: specifies the type of the matrix to be copied
${\mathbf{UPLO}}=\text{'L'}$ (Lower)
The matrix is lower triangular. In this case the packed vector holds, or will hold on exit, 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'}$ (Upper)
The matrix is upper triangular. In this case the packed vector holds, or will hold on exit, 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'}$.
3:     DIAG – CHARACTER(1)Input
On entry: must specify whether the diagonal elements of the matrix are to be copied.
${\mathbf{DIAG}}=\text{'B'}$ (Blank)
The diagonal elements of the matrix are not referenced and not copied.
${\mathbf{DIAG}}=\text{'U'}$ (Unit diagonal)
The diagonal elements of the matrix are not referenced, but are assumed all to be unity, and are copied as such.
${\mathbf{DIAG}}=\text{'N'}$ (Non-unit diagonal)
The diagonal elements of the matrix are referenced and copied.
Constraint: ${\mathbf{DIAG}}=\text{'B'}$, $\text{'U'}$ or $\text{'N'}$.
4:     N – INTEGERInput
On entry: $n$, the number of rows and columns of the triangular matrix.
Constraint: ${\mathbf{N}}>0$.
5:     A(LDA,N) – REAL (KIND=nag_wp) arrayInput/Output
On entry: if ${\mathbf{JOB}}=\text{'P'}$, then the leading N by N part of A must contain the matrix to be copied, stored in unpacked form, in the upper or lower triangle depending on parameter UPLO. The opposite triangle of A is not referenced and need not be assigned.
On exit: if ${\mathbf{JOB}}=\text{'U'}$, then the leading N by N part of array A contains the copied matrix, stored in unpacked form, in the upper or lower triangle depending on parameter UPLO. The opposite triangle of A is not referenced.
6:     LDA – INTEGERInput
On entry: the first dimension of the array A as declared in the (sub)program from which F01ZAF is called.
Constraint: ${\mathbf{LDA}}\ge {\mathbf{N}}$.
7:     B($\left({\mathbf{N}}×\left({\mathbf{N}}+1\right)\right)/2$) – REAL (KIND=nag_wp) arrayInput/Output
On entry: if ${\mathbf{JOB}}=\text{'U'}$, then B must contain the triangular matrix packed by column.
On exit: if ${\mathbf{JOB}}=\text{'P'}$, then B contains the triangular matrix packed by column.
Note that B must have space for the diagonal elements of the matrix, even if these are not stored.
8:     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{JOB}}\ne \text{'P'}$ or $\text{'U'}$.
${\mathbf{IFAIL}}=2$
 On entry, ${\mathbf{UPLO}}\ne \text{'L'}$ or $\text{'U'}$.
${\mathbf{IFAIL}}=3$
 On entry, ${\mathbf{DIAG}}\ne \text{'N'}$, $\text{'U'}$ or $\text{'B'}$.
${\mathbf{IFAIL}}=4$
 On entry, ${\mathbf{N}}<1$.
${\mathbf{IFAIL}}=5$
 On entry, ${\mathbf{LDA}}<{\mathbf{N}}$.

Not applicable.

None.

## 9  Example

This example reads in a triangular matrix $A$, and copies it to the packed matrix $B$.

### 9.1  Program Text

Program Text (f01zafe.f90)

### 9.2  Program Data

Program Data (f01zafe.d)

### 9.3  Program Results

Program Results (f01zafe.r)