XLPack 7.0
XLPack Numerical Library (Excel VBA) Reference Manual
Loading...
Searching...
No Matches

◆ HBRead()

Sub HBRead ( Fname As  String,
Title As  String,
Key As  String,
Nrow As  Long,
Ncol As  Long,
Nnz As  Long,
Neltvl As  Long,
Val() As  Double,
Ptr() As  Long,
Ind() As  Long,
Nrhs As  Long,
Nrhsix As  Long,
Rhsval() As  Double,
Rhsptr() As  Long,
Rhsind() As  Long,
Sguess() As  Double,
Xexact() As  Double,
DataType As  Long,
MatShape As  Long,
MatForm As  Long,
RhsForm As  Long,
IniVec As  Long,
SolVec As  Long,
Optional Info As  Long,
Optional Skip As  Long = 0,
Optional Base As  Long = 0,
Optional Format As  Long = 0,
Optional Sort As  Long = 0 
)

Read a matrix from the Harwell-Boeing file

Purpose
This routine reads a sparse or finite element matrix from the file in Harwell-Boeing format.

The matrix data is stored in the array as it is without checking the contents such as the order. Sparse matrices are stored in CSR, CSC or COO format. However, it is possible to sort sparse matrix elements in ascending order of column or row number within each row or column by option.
Parameters
[in]FnameInput file name.
[out]TitleTitle string.
[out]KeyKey string.
[out]NrowNumber of rows of the matrix (if sparse matrix).
Number of variables (Nu) (if finite-element matrix).
[out]NcolNumber of columns of the matrix (if sparse matrix).
Number of elemental matrices (if finite-element matrix).
[out]NnzNumber of non-zero elements (if sparse matrix).
Number of variable indices (Nind) (if finite-element matrix).
[out]NeltvlNot used (if sparse matrix).
Number of elements (if finite-element matrix).
[out]Val()Array Val(LVal - 1) (LVal >= Nnz (if sparse matrix), LVal >= Neltvl (if finite-element matrix))
Nonzero elements of sparse matrix (if sparse matrix).
Numerical values of elements (if finite-element matrix).
[out]Ptr()Array Ptr(LPtr - 1) (LPtr >= Nrow + 1 (CSR), LPtr >= Ncol + 1 (CSC, finite-element matrix) or LPtr >= Nnz (COO))
Row pointers (if CSR), column pointers (if CSC), or row indices (if COO) (if sparse matrix).
Pointers to variable indices (if finite-element matrix).
[out]Ind()Array Ind(LInd - 1) (LInd >= Nnz) Column indices (if CSR or COO) or row indices (if CSC) (if sparse matrix).
Variable indices (if elemental matrix format).
[out]NrhsNumber of columns of RHS matrix.
[out]NrhsixNumber of row indices of RHS matrix. (If RhsForm = 1, MatForm = 0 (sparse matrix))
[out]Rhsval()Array Rhsval(LRhsval - 1) (LRhsval >= Nrow*Nrhs (if RhsForm = 0 (dense matrix)), LRhsval >= Nrhsix (if RhsForm = 1 and MatForm = 0 (sparse matrix)), LRhsval >= Nnz*Nrhs (if RhsForm = 1 and MatForm = 1 (finite element matrix)))
RHS matrix values.
[out]Rhsptr()Array Rhsptr(LRhsptr - 1) (LRhsptr >= Nrow + 1 (if CSR), LRhsptr >= Nrhs + 1 (if CSC), LRhsptr >= Nrhsix (if COO))
Row pointers (if CSR), column pointers (if CSC), or row indices (if COO) of RHS. (if RhsForm = 1 and MatForm = 0 (sparse matrix))
[out]Rhsind()Array Rhsind(LRhsind - 1) (LRhsind >= Nrhsix)
Column indices (if CSR or COO), or row indices (if CSC) of RHS. (if RhsForm = 1 and MatForm = 0 (sparse matrix))
[out]Sguess()Array Sguess(LSguess - 1) (LSguess >= Nrow*Nrhs)
Initial guess vector. (if IniVec = 1)
[out]Xexact()Array Xexact(LXexact - 1) (LXexact >= Nrow*Nrhs)
Exact solution vector. (if SolVec = 1)
[out]DataTypeData type of the matrix.
= 0: Real.
= 2: Pattern.
[out]MatShapeMatrix shape.
= 0: Unsymmetric.
= 1: Symmetric.
= 2: Skew-symmetric.
= 4: Rectangular.
[out]MatFormStorage format of the matrix.
= 0: Sparse matrix.
= 1: Finite element matrix.
[out]RhsFormStorage format of the RHS matrix.
= 0: Dense matrix.
= 1: Same format with coefficient matrix.
[out]IniVecInitial guess vector.
= 0: Not stored.
= 1: Stored.
[out]SolVecExact solution vector.
= 0: Not stored.
= 1: Stored.
[out]Info(Optional)
= 0: Successful exit.
= i < 0: The (-i)-th argument is invalid.
= 1: Could not open file.
= 3: File read error.
= 4: Invalid read format.
= 5: Memory error.
[in]Skip(Optional)
Set flag as follows to read a part of data. (default = 0)
Bit 1 (least significant bit) = 1: Do not read matrix data.
Bit 2 = 1: Do not read RHS matrix data (except initial guess and exact solution vactors).
Bit 3 = 1: Do not read initial guess vector.
Bit 4 = 1: Do not read wxact solution vector.
[in]Base(Optional)
Index style of Ptr, Ind, Rhsptr and Rhsind. (default = 0)
= 0: Zero-based (C style) indexing: Starting index is 0.
= 1: One-based (Fortran style) indexing: Starting index is 1.
[in]Format(Optional)
Sparse matrix format. (default = 0)
= 0: CSR format.
= 1: CSC format.
= 2: COO format.
[in]Sort(Optional)
Specify whether to sort elements of sparse matrix in ascending order of column number within each row (if CSR) or row number within each column (if CSC). (default = 0)
= 0: Do not sort elements.
= 1: Sort elements.
Example Program
Reads the following file (Test_HBWrite.rua) in Harwell-Boeing format.
Test HBWrite Key
7 1 2 3 1
RUA 3 3 9 0
(8I10) (8I10) (3D23.15) (3D23.15)
F 1 0
1 4 7 10
1 2 3 1 2 3 1 2
3
2.000000000000000e-01 -3.200000000000000e-01 -8.000000000000000e-01
-1.100000000000000e-01 8.100000000000001e-01 -9.200000000000000e-01
-9.300000000000000e-01 3.700000000000000e-01 -2.900000000000000e-01
-3.727000000000000e-01 4.319000000000000e-01 -1.424700000000000e+00
Sub HBWrite(Fname As String, ByVal Title As String, Key As String, Nrow As Long, Ncol As Long, Nnz As Long, Neltvl As Long, Val() As Double, Ptr() As Long, Ind() As Long, Nrhs As Long, Nrhsix As Long, Rhsval() As Double, Rhsptr() As Long, Rhsind() As Long, Sguess() As Double, Xexact() As Double, DataType As Long, MatShape As Long, MatForm As Long, RhsForm As Long, IniVec As Long, SolVec As Long, Optional Info As Long, Optional Fchk As Long=0, Optional Base As Long=-1, Optional Format As Long=0, Optional IntN As Long=8, Optional IntW As Long=10, Optional DblN As Long=3, Optional DblW As Long=23, Optional DblD As Long=15)
Write a matrix to the file in Harwell-Boeing format
Sub Ex_HBRead()
Dim Title As String, Key As String
Dim M As Long, N As Long, Nnz As Long, Neltvl As Long, Nrhs As Long, Nrhsix As Long
Dim DataType As Long, MatShape As Long, MatForm As Long, RhsForm As Long, IniVec As Long, SolVec As Long
Dim A(8) As Double, Ia(3) As Long, Ja(8) As Long, B(2) As Double, IDummy() As Long, Dummy() As Double
Dim Info As Long
Call HBRead("Test_HBWrite.rua", Title, Key, M, N, Nnz, Neltvl, A(), Ia(), Ja(), Nrhs, Nrhsix, B(), IDummy(), IDummy(), Dummy(), Dummy(), DataType, MatShape, MatForm, RhsForm, IniVec, SolVec, Info)
Debug.Print "HBRead: Info =" + Str(Info)
Debug.Print "Title = """ + Title + """, Key = """ + Key + """, M =" + Str(M) + ", N =" + Str(N) + ", Nnz =" + Str(Nnz) + ", Neltvl =" + Str(Neltvl) + ", Nrhs =" + Str(Nrhs) + ", Nrhsix =" + Str(Nrhsix)
Debug.Print "DataType =" + Str(DataType) + ", MatShape =" + Str(MatShape) + ", MatForm =" + Str(MatForm) + ", RhsForm = " + Str(RhsForm) + ", IniVec =" + Str(IniVec) + ", SolVec = " + Str(SolVec); ""
Debug.Print A(0), A(1), A(2), A(3), A(4), A(5), A(6), A(7), A(8)
Debug.Print Ia(0), Ia(1), Ia(2), Ia(3)
Debug.Print Ja(0), Ja(1), Ja(2), Ja(3), Ja(4), Ja(5), Ja(6), Ja(7), Ja(8)
Debug.Print B(0), B(1), B(2)
End Sub
Sub HBRead(Fname As String, Title As String, Key As String, Nrow As Long, Ncol As Long, Nnz As Long, Neltvl As Long, Val() As Double, Ptr() As Long, Ind() As Long, Nrhs As Long, Nrhsix As Long, Rhsval() As Double, Rhsptr() As Long, Rhsind() As Long, Sguess() As Double, Xexact() As Double, DataType As Long, MatShape As Long, MatForm As Long, RhsForm As Long, IniVec As Long, SolVec As Long, Optional Info As Long, Optional Skip As Long=0, Optional Base As Long=0, Optional Format As Long=0, Optional Sort As Long=0)
Read a matrix from the Harwell-Boeing file
Example Results
HBRead: Info = 0
Title = "Test HBWrite", Key = "Key", M = 3, N = 3, Nnz = 9, Neltvl = 0, Nrhs = 1, Nrhsix = 0
DataType = 0, MatShape = 0, MatForm = 0, RhsForm = 0, IniVec = 0, SolVec = 0
0.2 -0.11 -0.93 -0.32 0.81 0.37 -0.8 -0.92 -0.29
0 3 6 9
0 1 2 0 1 2 0 1 2
-0.3727 0.4319 -1.4247