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

◆ HBWrite()

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

Purpose
This routine writes a sparse (CSR, CSC oe COO format) or finite-element matrix (unassembled format) to the Harwell-Boeing file.

The data is written as it is without checking the contents such as the order.
Parameters
[in]FnameOutput file name.
[in]TitleTitle string.
[in]KeyKey string.
[in]NrowNumber of rows of the matrix (if sparse matrix).
Number of variables (Nu) (if finite-element matrix).
(Nrow >= 0) (If Nrow = 0, returns without computation)
[in]NcolNumber of columns of the matrix (if sparse matrix).
Number of elemental matrices (if finite-element matrix).
(Ncol >= 0) (If Ncol = 0, returns without computation)
[in]NnzNumber of non-zero elements (if sparse matrix). (= Ptr(Nrow) - Ptr(0) (CSR) or Ptr(Ncol) - Ptr(0) (CSC))
Number of variable indices (if finite-element matrix). (= Ptr(Ne) - Ptr(0))
(Nnz >= 0) (If Nnz = 0, returns without computation)
[in]NeltvlNot used (if sparse matrix).
Number of elements (if finite-element matrix). (Neltvl >= 0) (If Neltvl = 0, returns without computation)
[in]Val()Array Val(LVal - 1) (LInd >= Nnz (if sparse matrix), LInd >= Neltvl (if finite-element matrix))
Nonzero elements of sparse matrix (if sparse matrix).
Numerical values of elements (if finite-element matrix).
[in]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).
[in]Ind()Array Ind(LInd - 1) (LInd >= Nnz)
Column indices (if CSR or COO) or row indices (if CSC) (if sparse matrix).
Variable indices (if finite-element matrix).
[in]NrhsNumber of columns of RHS matrix. (Nrhs >= 0)
[in]NrhsixNumber of row indices of RHS matrix. (Nrhsix > 0) (If RhsForm = 1, MatForm = 0 (sparse matrix))
[in]Rhsval()Array Rhsval(LRhsval - 1) (LRhsval >= Nrow*Nrhs (if RhsForm = 0 (dense matrix)), LRhsval >= Nrhsix (if RhsForm = 1 and MatForm = 0 (sparse matrix)), LRhsval >= Nu*Nrhs (if RhsForm = 1 and MatForm = 1 (finite element matrix)))
RHS matrix values.
[in]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))
[in]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))
[in]Sguess()Array Sguess(LSguess - 1) (LSguess >= Nrow*Nrhs)
Initial guess vector. (if IniVec = 1)
[in]Xexact()Array Xexact(LXexact - 1) (LXexact >= Nrow*Nrhs)
Exact solution vector. (if SolVec = 1)
[in]DataTypeData type of the matrix.
= 0: Real.
= 2: Pattern.
[in]MatShapeMatrix shape.
= 0: Unsymmetric.
= 1: Symmetric.
= 2: Skew-symmetric.
= 4: Rectangular.
[in]MatFormStorage format of the coefficient matrix.
= 0: Sparse matrix.
= 1: Finite element matrix.
[in]RhsFormStorage format of the RHS matrix.
= 0: Dense matrix.
= 1: Same format with coefficient matrix.
[in]IniVecInitial guess vector.
= 0: Not stored.
= 1: Stored.
[in]SolVecExact solution vector.
= 0: Not stored.
= 1: Stored.
[out]Info(Optional)
= 0: Successful exit.
= i < 0: The (-i)-th argument is invalid.
= 1: Failed to open file.
= 2: File already exists.
= 5: Memory error.
[in]Fchk(Optional)
Flag to check if output file exists. (default = 0)
= 0: Overwrite without checking if the specified file already exists.
= 1: Return as error (Info = 2) if the specified file already exists.
[in]Base(Optional)
Index style of Ptr and Ind. (default = Ptr(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]IntN(Optional)
Output format of integer (Numbers per line). (default: IntN = 8, IntW = 10)
[in]IntW(Optional)
Output format of integer (Width (number of digits)).
[in]DblN(Optional)
Output format of double (Numbers per line). (default: DblN = 3, DblW = 23, DblD = 15)
[in]DblW(Optional)
Output format of double (Width (number of digits)).
[in]DblD(Optional)
Output format of double (Width of fractional part (number of digits)).
Example Program
Writes the following matrices A and B to the file (Test_HBWrite.rua) in Harwell-Boeing format.
( 0.2 -0.11 -0.93 ) ( -0.3727 )
A = ( -0.32 0.81 0.37 ), B = ( 0.4319 )
( -0.8 -0.92 -0.29 ) ( -1.4247 )
Sub Ex_HBWrite()
Const Title = "Test HBWrite", Key = "Key"
Const M = 3, N = 3, Nnz = M * N, Neltvl = 0, Nrhs = 1, Nrhsix = 0
Const DataType = 0, MatShape = 0, MatForm = 0, RhsForm = 0, IniVec = 0, SolVec = 0
Dim A(Nnz - 1) As Double, Ia(M) As Long, Ja(Nnz - 1) As Long, B(M - 1) As Double, IDummy() As Long, Dummy() As Double
Dim Info As Long
A(0) = 0.2: A(1) = -0.11: A(2) = -0.93: A(3) = -0.32: A(4) = 0.81: A(5) = 0.37: A(6) = -0.8: A(7) = -0.92: A(8) = -0.29
Ia(0) = 0: Ia(1) = 3: Ia(2) = 6: Ia(3) = 9
Ja(0) = 0: Ja(1) = 1: Ja(2) = 2: Ja(3) = 0: Ja(4) = 1: Ja(5) = 2: Ja(6) = 0: Ja(7) = 1: Ja(8) = 2
B(0) = -0.3727: B(1) = 0.4319: B(2) = -1.4247
Call HBWrite("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 "HBWrite: Info =" + Str(Info)
End Sub
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
Example Results
HBWrite: Info = 0
Example Results (Test_HBWrite.rua file)
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