ergo
mmio.h
Go to the documentation of this file.
1 /* Ergo, version 3.8, a program for linear scaling electronic structure
2  * calculations.
3  * Copyright (C) 2019 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 
52 typedef char MM_typecode[4];
53 
55 
56 EXTERN_C int mm_read_banner(FILE *f, MM_typecode *matcode);
57 EXTERN_C int mm_read_mtx_crd_size(FILE *f, int *M, int *N, int *nz);
58 EXTERN_C int mm_read_mtx_array_size(FILE *f, int *M, int *N);
59 
60 EXTERN_C int mm_write_banner(FILE *f, MM_typecode matcode);
61 EXTERN_C int mm_write_mtx_crd_size(FILE *f, int M, int N, int nz);
62 EXTERN_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 
84 int 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 
157 int mm_write_mtx_crd(char fname[], int M, int N, int nz, int I[], int J[],
158  double val[], MM_typecode matcode);
159 int mm_read_mtx_crd_data(FILE *f, int M, int N, int nz, int I[], int J[],
160  double val[], MM_typecode matcode);
161 int mm_read_mtx_crd_entry(FILE *f, int *I, int *J, double *real, double *img,
162  MM_typecode matcode);
163 
164 int 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
MM_HERM_STR
#define MM_HERM_STR
Definition: mmio.h:150
mm_read_banner
EXTERN_C int mm_read_banner(FILE *f, MM_typecode *matcode)
Definition: mmio.c:129
MM_MTX_STR
#define MM_MTX_STR
Definition: mmio.h:140
mm_typecode_to_str
EXTERN_C char * mm_typecode_to_str(MM_typecode matcode)
Definition: mmio.c:488
mm_typecode_to_str
char * mm_typecode_to_str(MM_typecode matcode)
Definition: mmio.c:488
MM_PREMATURE_EOF
#define MM_PREMATURE_EOF
Definition: mmio.h:116
mm_write_mtx_array_size
int mm_write_mtx_array_size(FILE *f, int M, int N)
Definition: mmio.c:282
mm_read_unsymmetric_sparse
int mm_read_unsymmetric_sparse(const char *fname, int *M_, int *N_, int *nz_, double **val_, int **I_, int **J_)
Definition: mmio.c:46
mm_is_dense
#define mm_is_dense(typecode)
Definition: mmio.h:71
mm_set_sparse
#define mm_set_sparse(typecode)
Definition: mmio.h:93
MM_COULD_NOT_WRITE_FILE
#define MM_COULD_NOT_WRITE_FILE
Definition: mmio.h:121
mm_read_mtx_crd
int mm_read_mtx_crd(char *fname, int *M, int *N, int *nz, int **I, int **J, double **val, MM_typecode *matcode)
Definition: mmio.c:366
MM_NO_HEADER
#define MM_NO_HEADER
Definition: mmio.h:118
mm_read_mtx_crd_size
EXTERN_C int mm_read_mtx_crd_size(FILE *f, int *M, int *N, int *nz)
Definition: mmio.c:222
MM_SYMM_STR
#define MM_SYMM_STR
Definition: mmio.h:149
mm_set_real
#define mm_set_real(typecode)
Definition: mmio.h:96
mm_is_hermitian
#define mm_is_hermitian(typecode)
Definition: mmio.h:82
mm_read_mtx_crd_size
int mm_read_mtx_crd_size(FILE *f, int *M, int *N, int *nz)
Definition: mmio.c:222
mmio.h
Matrix Market I/O library for ANSI C. See http://math.nist.gov/MatrixMarket for details.
MM_MAX_TOKEN_LENGTH
#define MM_MAX_TOKEN_LENGTH
Definition: mmio.h:43
mm_is_general
#define mm_is_general(typecode)
Definition: mmio.h:80
mm_is_pattern
#define mm_is_pattern(typecode)
Definition: mmio.h:76
real
ergo_real real
Definition: test.cc:46
MM_UNSUPPORTED_TYPE
#define MM_UNSUPPORTED_TYPE
Definition: mmio.h:119
mm_read_mtx_crd_data
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
mm_read_mtx_crd_entry
int mm_read_mtx_crd_entry(FILE *f, int *I, int *J, double *real, double *img, MM_typecode matcode)
Definition: mmio.c:331
mm_set_skew
#define mm_set_skew(typecode)
Definition: mmio.h:103
mm_set_general
#define mm_set_general(typecode)
Definition: mmio.h:102
mm_clear_typecode
#define mm_clear_typecode(typecode)
Definition: mmio.h:106
mm_is_symmetric
#define mm_is_symmetric(typecode)
Definition: mmio.h:79
mm_read_mtx_crd_data
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
mm_is_integer
#define mm_is_integer(typecode)
Definition: mmio.h:77
mm_write_mtx_crd_size
int mm_write_mtx_crd_size(FILE *f, int M, int N, int nz)
Definition: mmio.c:214
mm_write_mtx_crd
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
mm_read_mtx_array_size
int mm_read_mtx_array_size(FILE *f, int *M, int *N)
Definition: mmio.c:253
MM_MAX_LINE_LENGTH
#define MM_MAX_LINE_LENGTH
Definition: mmio.h:41
mm_set_complex
#define mm_set_complex(typecode)
Definition: mmio.h:95
mm_set_pattern
#define mm_set_pattern(typecode)
Definition: mmio.h:97
MM_REAL_STR
#define MM_REAL_STR
Definition: mmio.h:146
MM_SKEW_STR
#define MM_SKEW_STR
Definition: mmio.h:151
mm_set_matrix
#define mm_set_matrix(typecode)
Definition: mmio.h:89
MM_typecode
char MM_typecode[4]
Definition: mmio.h:52
mm_set_dense
#define mm_set_dense(typecode)
Definition: mmio.h:92
mm_is_valid
int mm_is_valid(MM_typecode matcode)
Definition: mmio.c:119
mm_write_mtx_crd
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
MM_SPARSE_STR
#define MM_SPARSE_STR
Definition: mmio.h:144
MM_COMPLEX_STR
#define MM_COMPLEX_STR
Definition: mmio.h:145
mm_is_matrix
#define mm_is_matrix(typecode)
Definition: mmio.h:67
mm_is_skew
#define mm_is_skew(typecode)
Definition: mmio.h:81
mm_write_banner
int mm_write_banner(FILE *f, MM_typecode matcode)
Definition: mmio.c:419
mm_set_integer
#define mm_set_integer(typecode)
Definition: mmio.h:98
mm_write_banner
EXTERN_C int mm_write_banner(FILE *f, MM_typecode matcode)
Definition: mmio.c:419
mm_set_symmetric
#define mm_set_symmetric(typecode)
Definition: mmio.h:101
mm_is_complex
#define mm_is_complex(typecode)
Definition: mmio.h:74
MatrixMarketBanner
#define MatrixMarketBanner
Definition: mmio.h:42
mm_is_valid
int mm_is_valid(MM_typecode matcode)
Definition: mmio.c:119
mm_set_hermitian
#define mm_set_hermitian(typecode)
Definition: mmio.h:104
mm_strdup
char * mm_strdup(const char *s)
Create a new copy of a string s.
Definition: mmio.c:481
mm_read_mtx_array_size
EXTERN_C int mm_read_mtx_array_size(FILE *f, int *M, int *N)
Definition: mmio.c:253
mm_is_real
#define mm_is_real(typecode)
Definition: mmio.h:75
MM_PATTERN_STR
#define MM_PATTERN_STR
Definition: mmio.h:152
mm_write_mtx_crd_size
EXTERN_C int mm_write_mtx_crd_size(FILE *f, int M, int N, int nz)
Definition: mmio.c:214
MM_COULD_NOT_READ_FILE
#define MM_COULD_NOT_READ_FILE
Definition: mmio.h:115
EXTERN_C
#define EXTERN_C
Definition: mmio.h:48
mm_read_banner
int mm_read_banner(FILE *f, MM_typecode *matcode)
Definition: mmio.c:129
MM_INT_STR
#define MM_INT_STR
Definition: mmio.h:147
MM_GENERAL_STR
#define MM_GENERAL_STR
Definition: mmio.h:148
MM_DENSE_STR
#define MM_DENSE_STR
Definition: mmio.h:142
mm_write_mtx_array_size
EXTERN_C int mm_write_mtx_array_size(FILE *f, int M, int N)
Definition: mmio.c:282
mm_read_mtx_crd_entry
int mm_read_mtx_crd_entry(FILE *f, int *I, int *J, double *real, double *imag, MM_typecode matcode)
Definition: mmio.c:331
mm_read_unsymmetric_sparse
int mm_read_unsymmetric_sparse(const char *fname, int *M_, int *N_, int *nz_, double **val_, int **I_, int **J_)
Definition: mmio.c:46
mm_is_sparse
#define mm_is_sparse(typecode)
Definition: mmio.h:69