|
|
◆ ZHBRead1()
| Sub ZHBRead1 |
( |
Fname As |
String, |
|
|
Title As |
String, |
|
|
Key As |
String, |
|
|
Nrow As |
Long, |
|
|
Ncol As |
Long, |
|
|
Nnz As |
Long, |
|
|
Val() As |
Complex, |
|
|
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 (Complex matrix)
- 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.
= 1: Complex.
= 2: Pattern. |
| [out] | MatShape | Matrix shape.
= 0: Unsymmetric.
= 1: Symmetric.
= 2: Skew-symmetric.
= 3: Hermitian.
= 4: Rectangular. |
| [out] | MatForm | Storage format of the matrix.
= 0: Sparse matrix. |
| [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. |
| [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_ZHBWrite1.cua) in Harwell-Boeing format.
9 1 2 6 0
CUA 3 3 9 0
(8I10) (8I10) (3D23.15) (3D23.15)
1 4 7 10
1 2 3 1 2 3 1 2
3
7.800000000000000e-01 1.600000000000000e-01 7.300000000000000e-01
6.300000000000000e-01 2.300000000000000e-01 -1.370000000000000e+00
-9.000000000000000e-01 -1.460000000000000e+00 1.580000000000000e+00
-1.240000000000000e+00 7.900000000000000e-01 6.400000000000000e-01
4.800000000000000e-01 -1.080000000000000e+00 -4.100000000000000e-01
-9.100000000000000e-01 -7.300000000000000e-01 -1.500000000000000e+00
Sub ZHBWrite1(Fname As String, ByVal Title As String, Key As String, Nrow As Long, Ncol As Long, Nnz As Long, Val() As Complex, 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 (Complex matrix) (Simple driver)
Sub Ex_ZHBRead1()
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 Complex, Ia(3) As Long, Ja(8) As Long
Dim Info As Long
Call ZHBRead1("Test_ZHBWrite1.cua", Title, Key, M, N, Nnz, A(), Ia(), Ja(), DataType, MatShape, MatForm, Info)
Debug.Print " ZHBRead1: 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 "(" + Str( Creal(A(0))) + "," + Str( Cimag(A(0))) + ")", "(" + Str( Creal(A(1))) + "," + Str( Cimag(A(1))) + ")", "(" + Str( Creal(A(2))) + "," + Str( Cimag(A(2))) + ")"
Debug.Print "(" + Str( Creal(A(3))) + "," + Str( Cimag(A(3))) + ")", "(" + Str( Creal(A(4))) + "," + Str( Cimag(A(4))) + ")", "(" + Str( Creal(A(5))) + "," + Str( Cimag(A(5))) + ")"
Debug.Print "(" + Str( Creal(A(6))) + "," + Str( Cimag(A(6))) + ")", "(" + Str( Creal(A(7))) + "," + Str( Cimag(A(7))) + ")", "(" + Str( Creal(A(8))) + "," + Str( Cimag(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
Function Cimag(A As Complex) As Double Imaginary part of complex number
Function Creal(A As Complex) As Double Real part of complex number
Sub ZHBRead1(Fname As String, Title As String, Key As String, Nrow As Long, Ncol As Long, Nnz As Long, Val() As Complex, 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 (Complex matrix)
- Example Results
Title = "Test ZHBWrite1", Key = "Key", M = 3, N = 3, Nnz = 9
DataType = 1, MatShape = 0, MatForm = 0
( .78, .16) (-.9,-1.46) ( .48,-1.08)
( .73, .63) ( 1.58,-1.24) (-.41,-.91)
( .23,-1.37) ( .79, .64) (-.73,-1.5)
0 3 6 9
0 1 2 0 1 2 0 1 2
|