ergo
mmio.h
Go to the documentation of this file.
1/* Ergo, version 3.8.2, a program for linear scaling electronic structure
2 * calculations.
3 * Copyright (C) 2023 Elias Rudberg, Emanuel H. Rubensson, Pawel Salek,
4 * and Anastasia Kruchinina.
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * Primary academic reference:
20 * Ergo: An open-source program for linear-scaling electronic structure
21 * calculations,
22 * Elias Rudberg, Emanuel H. Rubensson, Pawel Salek, and Anastasia
23 * Kruchinina,
24 * SoftwareX 7, 107 (2018),
25 * <http://dx.doi.org/10.1016/j.softx.2018.03.005>
26 *
27 * For further information about Ergo, see <http://www.ergoscf.org>.
28 */
29
38#ifndef MM_IO_H
39#define MM_IO_H
40
41#define MM_MAX_LINE_LENGTH 1025
42#define MatrixMarketBanner "%%MatrixMarket"
43#define MM_MAX_TOKEN_LENGTH 64
44
45#ifdef __cplusplus
46#define EXTERN_C extern "C"
47#else
48#define EXTERN_C
49#endif
50
51
52typedef char MM_typecode[4];
53
55
56EXTERN_C int mm_read_banner(FILE *f, MM_typecode *matcode);
57EXTERN_C int mm_read_mtx_crd_size(FILE *f, int *M, int *N, int *nz);
58EXTERN_C int mm_read_mtx_array_size(FILE *f, int *M, int *N);
59
60EXTERN_C int mm_write_banner(FILE *f, MM_typecode matcode);
61EXTERN_C int mm_write_mtx_crd_size(FILE *f, int M, int N, int nz);
62EXTERN_C int mm_write_mtx_array_size(FILE *f, int M, int N);
63
64
65/********************* MM_typecode query fucntions ***************************/
66
67#define mm_is_matrix(typecode) ((typecode)[0]=='M')
68
69#define mm_is_sparse(typecode) ((typecode)[1]=='C')
70#define mm_is_coordinate(typecode)((typecode)[1]=='C')
71#define mm_is_dense(typecode) ((typecode)[1]=='A')
72#define mm_is_array(typecode) ((typecode)[1]=='A')
73
74#define mm_is_complex(typecode) ((typecode)[2]=='C')
75#define mm_is_real(typecode) ((typecode)[2]=='R')
76#define mm_is_pattern(typecode) ((typecode)[2]=='P')
77#define mm_is_integer(typecode) ((typecode)[2]=='I')
78
79#define mm_is_symmetric(typecode)((typecode)[3]=='S')
80#define mm_is_general(typecode) ((typecode)[3]=='G')
81#define mm_is_skew(typecode) ((typecode)[3]=='K')
82#define mm_is_hermitian(typecode)((typecode)[3]=='H')
83
84int mm_is_valid(MM_typecode matcode); /* too complex for a macro */
85
86
87/********************* MM_typecode modify fucntions ***************************/
88
89#define mm_set_matrix(typecode) ((*typecode)[0]='M')
90#define mm_set_coordinate(typecode) ((*typecode)[1]='C')
91#define mm_set_array(typecode) ((*typecode)[1]='A')
92#define mm_set_dense(typecode) mm_set_array(typecode)
93#define mm_set_sparse(typecode) mm_set_coordinate(typecode)
94
95#define mm_set_complex(typecode)((*typecode)[2]='C')
96#define mm_set_real(typecode) ((*typecode)[2]='R')
97#define mm_set_pattern(typecode)((*typecode)[2]='P')
98#define mm_set_integer(typecode)((*typecode)[2]='I')
99
100
101#define mm_set_symmetric(typecode)((*typecode)[3]='S')
102#define mm_set_general(typecode)((*typecode)[3]='G')
103#define mm_set_skew(typecode) ((*typecode)[3]='K')
104#define mm_set_hermitian(typecode)((*typecode)[3]='H')
105
106#define mm_clear_typecode(typecode) ((*typecode)[0]=(*typecode)[1]= \
107 (*typecode)[2]=' ',(*typecode)[3]='G')
108
109#define mm_initialize_typecode(typecode) mm_clear_typecode(typecode)
110
111
112/********************* Matrix Market error codes ***************************/
113
114
115#define MM_COULD_NOT_READ_FILE 11
116#define MM_PREMATURE_EOF 12
117#define MM_NOT_MTX 13
118#define MM_NO_HEADER 14
119#define MM_UNSUPPORTED_TYPE 15
120#define MM_LINE_TOO_LONG 16
121#define MM_COULD_NOT_WRITE_FILE 17
122
123
124/******************** Matrix Market internal definitions ********************
125
126 MM_matrix_typecode: 4-character sequence
127
128 ojbect sparse/ data storage
129 dense type scheme
130
131 string position: [0] [1] [2] [3]
132
133 Matrix typecode: M(atrix) C(oord) R(eal) G(eneral)
134 A(array) C(omplex) H(ermitian)
135 P(attern) S(ymmetric)
136 I(nteger) K(kew)
137
138 ***********************************************************************/
139
140#define MM_MTX_STR "matrix"
141#define MM_ARRAY_STR "array"
142#define MM_DENSE_STR "array"
143#define MM_COORDINATE_STR "coordinate"
144#define MM_SPARSE_STR "coordinate"
145#define MM_COMPLEX_STR "complex"
146#define MM_REAL_STR "real"
147#define MM_INT_STR "integer"
148#define MM_GENERAL_STR "general"
149#define MM_SYMM_STR "symmetric"
150#define MM_HERM_STR "hermitian"
151#define MM_SKEW_STR "skew-symmetric"
152#define MM_PATTERN_STR "pattern"
153
154
155/* high level routines */
156
157int mm_write_mtx_crd(char fname[], int M, int N, int nz, int I[], int J[],
158 double val[], MM_typecode matcode);
159int mm_read_mtx_crd_data(FILE *f, int M, int N, int nz, int I[], int J[],
160 double val[], MM_typecode matcode);
161int mm_read_mtx_crd_entry(FILE *f, int *I, int *J, double *real, double *img,
162 MM_typecode matcode);
163
164int mm_read_unsymmetric_sparse(const char *fname, int *M_, int *N_, int *nz_,
165 double **val_, int **I_, int **J_);
166
167
168
169#endif
ergo_real real
Definition test.cc:46
EXTERN_C int mm_read_mtx_crd_size(FILE *f, int *M, int *N, int *nz)
Definition mmio.c:222
char MM_typecode[4]
Definition mmio.h:52
EXTERN_C int mm_write_mtx_array_size(FILE *f, int M, int N)
Definition mmio.c:282
EXTERN_C int mm_write_mtx_crd_size(FILE *f, int M, int N, int nz)
Definition mmio.c:214
EXTERN_C char * mm_typecode_to_str(MM_typecode matcode)
Definition mmio.c:488
int mm_write_mtx_crd(char fname[], int M, int N, int nz, int I[], int J[], double val[], MM_typecode matcode)
Definition mmio.c:432
EXTERN_C int mm_write_banner(FILE *f, MM_typecode matcode)
Definition mmio.c:419
int mm_read_unsymmetric_sparse(const char *fname, int *M_, int *N_, int *nz_, double **val_, int **I_, int **J_)
Definition mmio.c:46
int mm_read_mtx_crd_data(FILE *f, int M, int N, int nz, int I[], int J[], double val[], MM_typecode matcode)
Definition mmio.c:298
int mm_is_valid(MM_typecode matcode)
Definition mmio.c:119
EXTERN_C int mm_read_banner(FILE *f, MM_typecode *matcode)
Definition mmio.c:129
#define EXTERN_C
Definition mmio.h:48
EXTERN_C int mm_read_mtx_array_size(FILE *f, int *M, int *N)
Definition mmio.c:253
int mm_read_mtx_crd_entry(FILE *f, int *I, int *J, double *real, double *img, MM_typecode matcode)
Definition mmio.c:331