|
|
◆ HBRead1()
| Sub HBRead1 |
( |
Fname As |
String, |
|
|
Title As |
String, |
|
|
Key As |
String, |
|
|
Nrow As |
Long, |
|
|
Ncol As |
Long, |
|
|
Nnz As |
Long, |
|
|
Val() As |
Double, |
|
|
Ptr() As |
Long, |
|
|
Ind() As |
Long, |
|
|
DataType As |
Long, |
|
|
MatShape As |
Long, |
|
|
MatForm As |
Long, |
|
|
Optional Info As |
Long, |
|
|
Optional Nrhs As |
Long, |
|
|
Optional Base As |
Long = 0, |
|
|
Optional Format As |
Long = 0, |
|
|
Optional Sort As |
Long = 0 |
|
) |
| |
Read a matrix from the Harwell-Boeing file (Simple driver)
- Purpose
- This routine reads a sparse 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.
RHS (including initial guess and exact solution) is not read. Nrhs, however, is returned through optional parameter.
- Parameters
-
| [in] | Fname | Input file name. |
| [out] | Title | Title string. |
| [out] | Key | Key string. |
| [out] | Nrow | Number of rows of the matrix. |
| [out] | Ncol | Number of columns of the matrix. |
| [out] | Nnz | Number of non-zero elements. |
| [out] | Val() | Array Val(LVal - 1) (LVal >= Nnz)
Nonzero elements of sparse matrix. |
| [out] | Ptr() | Array Ptr(LPtr - 1) (LPtr >= Nrow + 1 (CSR), LPtr >= Ncol + 1 (CSC) or LPtr >= Nnz (COO))
Row pointers (if CSR), column pointers (if CSC), or row indices (if COO). |
| [out] | Ind() | Array Ind(LInd - 1) (LInd >= Nnz) Column indices (if CSR or COO) or row indices (if CSC). |
| [out] | DataType | Data type of the matrix.
= 0: Real.
= 2: Pattern. |
| [out] | MatShape | Matrix shape.
= 0: Unsymmetric.
= 1: Symmetric.
= 2: Skew-symmetric.
= 4: Rectangular. |
| [out] | MatForm | Storage format of the matrix.
= 0: Sparse matrix. |
| [out] | Info | (Optional)
= 0: Successful exit.
< 0: The (-Info)-th argument is invalid.
= 1: Could not open file.
= 3: File read error.
= 4: Invalid read format.
= 5: Memory error. |
| [out] | Nrhs | (Optional)
Number of columns of RHS matrix. |
| [in] | Base | (Optional)
Index style of Ptr and Ind. (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_HBWrite1.rua) in Harwell-Boeing format.
6 1 2 3 0
RUA 3 3 9 0
(8I10) (8I10) (3D23.15) (3D23.15)
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
Sub HBWrite1(Fname As String, ByVal Title As String, Key As String, Nrow As Long, Ncol As Long, Nnz As Long, Val() As Double, Ptr() As Long, Ind() As Long, DataType As Long, MatShape As Long, MatForm As Long, Optional Info As Long, Optional Fchk As Long=0, Optional Base As Long=-1, Optional Format As Long=0) Write a matrix to the Harwell-Boeing file (Simple driver)
Sub Ex_HBRead1()
Dim Title As String, Key As String
Dim M As Long, N As Long, Nnz As Long, DataType As Long, MatShape As Long, MatForm As Long
Dim A(8) As Double, Ia(3) As Long, Ja(8) As Long
Dim Info As Long
Call HBRead1("Test_HBWrite1.rua", Title, Key, M, N, Nnz, A(), Ia(), Ja(), DataType, MatShape, MatForm, Info)
Debug.Print " HBRead1: Info =" + Str(Info)
Debug.Print "Title = """ + Title + """, Key = """ + Key + """, M =" + Str(M) + ", N =" + Str(N) + ", Nnz =" + Str(Nnz)
Debug.Print "DataType =" + Str(DataType) + ", MatShape =" + Str(MatShape) + ", MatForm =" + Str(MatForm)
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)
End Sub
Sub HBRead1(Fname As String, Title As String, Key As String, Nrow As Long, Ncol As Long, Nnz As Long, Val() As Double, Ptr() As Long, Ind() As Long, DataType As Long, MatShape As Long, MatForm As Long, Optional Info As Long, Optional Nrhs As Long, Optional Base As Long=0, Optional Format As Long=0, Optional Sort As Long=0) Read a matrix from the Harwell-Boeing file (Simple driver)
- Example Results
Title = "Test HBWrite1", Key = "Key", M = 3, N = 3, Nnz = 9
DataType = 0, MatShape = 0, MatForm = 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
|