|
|
◆ MMWrite()
| Sub MMWrite |
( |
Fname 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 Matrix Market file
- Purpose
- This function writes a sparse (CSR, CSC oe COO format) or dense matrix to the Matrix Market file.
The data is written as it is without checking the contents.
- Parameters
-
| [in] | Fname | Output file name. |
| [in] | Nrow | Number of rows of the matrix. |
| [in] | Ncol | Number of columns of the matrix. |
| [in] | Nnz | Number of nonzero elements of the matrix. |
| [in] | Val() | Array Val(LVal - 1) (LVal is as follows)
Storage Data type Matrix shape LVal (min. value)
---------- ------------------------ -------------- -----------------
0 (sparse) 0 (real) or 3 (integer) Nnz
1 (dense) 0 (real) or 3 (integer) 0 (gegeral) Nrow*Ncol
1 (symmetric) Ncol*(Ncol + 1)/2
2 (skew) Ncol*(Ncol - 1)/2
Nonzero elements of sparse matrix, or, all elements of dense matrix.
If data type is integer, the value will be rounded when writing.
Not referenced if data type = 2 (pattern). |
| [in] | Ptr() | Array Ptr(LPtr - 1) (LPtr >= Ncol + 1 (if matrix is stored in CSC format), LPtr >= Nrow + 1 (if matrix is stored in CSR format) or LPtr >= Nnz (if matrix is stored in COO format))
Row pointers (if matrix is stored in CSR format), column pointers (if matrix is stored in CSC format) or row indices (if matrix is stored in COO format) of nonzero elements.
Not referenced if storage format = 1 (dense). |
| [in] | Ind() | Array Ind(LInd - 1) (LInd >= Nnz)
Row indices (if matrix is stored in CSC format) or column indices (if matrix is stored in CSR or COO format) of nonzero elements.
Not referenced if storage format = 1 (dense). |
| [in] | DataType | Data type of the matrix.
= 0: Real.
= 2: Pattern.
= 3: Integer. |
| [in] | MatShape | Matrix shape.
= 0: General.
= 1: Symmetric.
= 2: Skew-symmetric. |
| [in] | MatForm | Storage format of the matrix.
= 0: Sparse.
= 1: Dense. |
| [out] | Info | (Optional)
= 0: Successful exit.
= i < 0: The (-i)-th argument is invalid.
= 1: Failed to open file.
= 2: File already exists.
= 4: Invalid type. |
| [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 when Sparse matrix (MatForm = 0). (default = Ptr(0) if CSR or CSC (Format = 0 or 1), 0 if COO (Format = 2))
= 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. |
- Example Program
- Writes the following matrix to the file (Test_MMWrite.mtx) in Matrix Market format.
( 0.2 -0.11 -0.93 )
A = ( -0.32 0.81 0.37 )
( -0.8 -0.92 -0.29 )
Sub Ex_MMWrite()
Const M = 3, N = 3, Nnz = M * N
Const DataType = 0, MatShape = 0, MatForm = 0
Dim A(Nnz - 1) As Double, Ia(M) As Long, Ja(Nnz - 1) As Long
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
Call MMWrite("Test_MMWrite.mtx", M, N, Nnz, A(), Ia(), Ja(), DataType, MatShape, MatForm, Info)
Debug.Print " MMWrite: Info =" + Str(Info)
End Sub
Sub MMWrite(Fname 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 Matrix Market file
- Example Results
- Example Results (Test_MMWrite.mtx file)
%%MatrixMarket matrix coordinate real general
3 3 9
1 1 2.000000000000000e-01
1 2 -1.100000000000000e-01
1 3 -9.300000000000000e-01
2 1 -3.200000000000000e-01
2 2 8.100000000000001e-01
2 3 3.700000000000000e-01
3 1 -8.000000000000000e-01
3 2 -9.200000000000000e-01
3 3 -2.900000000000000e-01
|