NAG Library Manual, Mark 28.3
```    Program f11jb_p0w_fe

!     F11JB_P0W_F Example Program Text

!     Mark 28.3 Release. NAG Copyright 2022.

!     .. Use Statements ..
Use iso_c_binding, Only: c_ptr
Use nagad_library, Only: f11ja_p0w_f, f11jb_p0w_f, f11za_p0w_f,          &
f11zb_p0w_f
Use nag_library, Only: nag_wp
!     .. Implicit None Statement ..
Implicit None
!     .. Parameters ..
Integer, Parameter               :: nin = 5, nout = 6
!     .. Local Scalars ..
Real (Kind=nag_wp)               :: dscale, dtol
Integer                          :: i, ifail, la, lfill, liwork, n, nnz, &
nnzc, npivm
Character (1)                    :: check, mic, pstrat
!     .. Local Arrays ..
Real (Kind=nag_wp), Allocatable  :: a(:), x(:), y(:)
Integer, Allocatable             :: icol(:), ipiv(:), irow(:), istr(:),  &
iwork(:), perm_fwd(:), perm_inv(:)
!     .. Executable Statements ..
Write (nout,*) 'F11JB_P0W_F Example Program Results'
!     Skip heading in data file

!     Read order of matrix and number of nonzero entries

la = 3*nnz
liwork = 2*la + 7*n + 1

Allocate (a(la),x(n),y(n),icol(la),ipiv(n),irow(la),istr(n+1),           &
iwork(liwork),perm_fwd(n),perm_inv(n))

Do i = 1, nnz
End Do

!     Calculate Cholesky factorization
lfill = -1
dtol = 0.0E0_nag_wp
mic = 'N'
dscale = 0.0E0_nag_wp
pstrat = 'M'

iwork = 0
!     Compute reverse Cuthill-McKee permutation for bandwidth reduction

ifail = 0
pstrat,ipiv,istr,nnzc,npivm,iwork,liwork,ifail)

!     Check the output value of NPIVM
If (npivm/=0) Then
Write (nout,99998) 'Factorization is not complete', npivm
Else
!       Solve P L D L^T P^T x = y
x = 0.0_nag_wp
check = 'C'
ifail = 0
!       Output results
Write (nout,*) ' Solution of linear system with Reverse Cuthill-McKee'
Write (nout,99999)(x(perm_inv(i)),i=1,n)
End If

99999 Format (1X,E16.4)
99998 Format (1X,A,I20)
Contains

!       .. Use Statements ..
Use iso_c_binding, Only: c_ptr
Use nag_library, Only: f11yef
!       .. Parameters ..
Logical, Parameter             :: lopts(5) = (/.False.,.False.,.True., &
.True.,.True./)
!       .. Scalar Arguments ..
!       .. Array Arguments ..
Real (Kind=nag_wp), Intent (Inout) :: a(la), y(n)
Integer, Intent (Inout)        :: icol(la), irow(la), istr(n+1),       &
iwork(*)
Integer, Intent (Out)          :: perm_fwd(n), perm_inv(n)
!       .. Local Scalars ..
Integer                        :: i, ifail, j, nnz_cs, nnz_scs
!       .. Local Arrays ..
Real (Kind=nag_wp), Allocatable :: rwork(:)
!       .. Intrinsic Procedures ..
Intrinsic                      :: size
!       .. Executable Statements ..

!       SCS to CS, must add the upper triangle entries.
j = nnz + 1
Do i = 1, nnz
If (irow(i)>icol(i)) Then
!           strictly lower triangle, add the transposed
a(j) = a(i)
irow(j) = icol(i)
icol(j) = irow(i)
j = j + 1
End If
End Do
nnz_cs = j - 1

!       Reorder, CS to CCS, icolzp in istr
ifail = 0
ifail)

!       Calculate reverse Cuthill-McKee
ifail = 0

!       compute inverse perm, in perm_inv(1:n)
Do i = 1, n
perm_inv(perm_fwd(i)) = i
End Do

!       Apply permutation on column/row indices
icol(1:nnz_cs) = perm_inv(icol(1:nnz_cs))
irow(1:nnz_cs) = perm_inv(irow(1:nnz_cs))

!       restrict to lower triangle, SCS format
!       copying entries upwards
j = 1
Do i = 1, nnz_cs
If (irow(i)>=icol(i)) Then
!           non-upper triangle, bubble up
a(j) = a(i)
icol(j) = icol(i)
irow(j) = irow(i)
j = j + 1
End If
End Do
nnz_scs = j - 1

!       sort
ifail = 0