SparseLibrary  Version 1.6.0
mmio.h
1 /*
2  * Copyright (c) 2007-2014, A. N. Yzelman, Utrecht University 2007-2011;
3  * KU Leuven 2011-2014.
4  * R. H. Bisseling, Utrecht University 2007-2014.
5  *
6  * This file is part of the Sparse Library.
7  *
8  * This library was developed under supervision of Prof. dr. Rob H. Bisseling at
9  * Utrecht University, from 2007 until 2011. From 2011-2014, development continued
10  * at KU Leuven, where Prof. dr. Dirk Roose contributed significantly to the ideas
11  * behind the newer parts of the library code.
12  *
13  * The Sparse Library is free software: you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by the
15  * Free Software Foundation, either version 3 of the License, or (at your
16  * option) any later version.
17  *
18  * The Sparse Library is distributed in the hope that it will be useful, but
19  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  * for more details.
22  *
23  * You should have received a copy of the GNU General Public License along
24  * with the Sparse Library. If not, see <http://www.gnu.org/licenses/>.
25  */
26 
27 
28 /*
29 * Matrix Market I/O library for ANSI C.
30 * See http://math.nist.gov/MatrixMarket for details.
31 *
32 * Copyright holders are presumably the US National Institute of Standards and
33 * Technology, but the code is freely available from the above link.
34 *
35 * This code does not fall under the copyright of SPARSE_LIB.
36 */
37 
38 
39 #ifndef MM_IO_H
40 #define MM_IO_H
41 
42 #define MM_MAX_LINE_LENGTH 1025
43 #define MatrixMarketBanner "%%MatrixMarket"
44 #define MM_MAX_TOKEN_LENGTH 64
45 
46 typedef char MM_typecode[4];
47 
48 char *mm_typecode_to_str(MM_typecode matcode);
49 
50 int mm_read_banner(FILE *f, MM_typecode *matcode);
51 int mm_read_mtx_crd_size(FILE *f, int *M, int *N, int *nz);
52 int mm_read_mtx_array_size(FILE *f, int *M, int *N);
53 
54 int mm_write_banner(FILE *f, MM_typecode matcode);
55 int mm_write_mtx_crd_size(FILE *f, int M, int N, int nz);
56 int mm_write_mtx_array_size(FILE *f, int M, int N);
57 
58 
59 /********************* MM_typecode query fucntions ***************************/
60 
61 #define mm_is_matrix(typecode) ((typecode)[0]=='M')
62 
63 #define mm_is_sparse(typecode) ((typecode)[1]=='C')
64 #define mm_is_coordinate(typecode)((typecode)[1]=='C')
65 #define mm_is_dense(typecode) ((typecode)[1]=='A')
66 #define mm_is_array(typecode) ((typecode)[1]=='A')
67 
68 #define mm_is_complex(typecode) ((typecode)[2]=='C')
69 #define mm_is_real(typecode) ((typecode)[2]=='R')
70 #define mm_is_pattern(typecode) ((typecode)[2]=='P')
71 #define mm_is_integer(typecode) ((typecode)[2]=='I')
72 
73 #define mm_is_symmetric(typecode)((typecode)[3]=='S')
74 #define mm_is_general(typecode) ((typecode)[3]=='G')
75 #define mm_is_skew(typecode) ((typecode)[3]=='K')
76 #define mm_is_hermitian(typecode)((typecode)[3]=='H')
77 
78 int mm_is_valid(MM_typecode matcode); /* too complex for a macro */
79 
80 
81 /********************* MM_typecode modify fucntions ***************************/
82 
83 #define mm_set_matrix(typecode) ((*typecode)[0]='M')
84 #define mm_set_coordinate(typecode) ((*typecode)[1]='C')
85 #define mm_set_array(typecode) ((*typecode)[1]='A')
86 #define mm_set_dense(typecode) mm_set_array(typecode)
87 #define mm_set_sparse(typecode) mm_set_coordinate(typecode)
88 
89 #define mm_set_complex(typecode)((*typecode)[2]='C')
90 #define mm_set_real(typecode) ((*typecode)[2]='R')
91 #define mm_set_pattern(typecode)((*typecode)[2]='P')
92 #define mm_set_integer(typecode)((*typecode)[2]='I')
93 
94 
95 #define mm_set_symmetric(typecode)((*typecode)[3]='S')
96 #define mm_set_general(typecode)((*typecode)[3]='G')
97 #define mm_set_skew(typecode) ((*typecode)[3]='K')
98 #define mm_set_hermitian(typecode)((*typecode)[3]='H')
99 
100 #define mm_clear_typecode(typecode) ((*typecode)[0]=(*typecode)[1]= \
101  (*typecode)[2]=' ',(*typecode)[3]='G')
102 
103 #define mm_initialize_typecode(typecode) mm_clear_typecode(typecode)
104 
105 
106 /********************* Matrix Market error codes ***************************/
107 
108 
109 #define MM_COULD_NOT_READ_FILE 11
110 #define MM_PREMATURE_EOF 12
111 #define MM_NOT_MTX 13
112 #define MM_NO_HEADER 14
113 #define MM_UNSUPPORTED_TYPE 15
114 #define MM_LINE_TOO_LONG 16
115 #define MM_COULD_NOT_WRITE_FILE 17
116 
117 
118 /******************** Matrix Market internal definitions ********************
119 
120  MM_matrix_typecode: 4-character sequence
121 
122  ojbect sparse/ data storage
123  dense type scheme
124 
125  string position: [0] [1] [2] [3]
126 
127  Matrix typecode: M(atrix) C(oord) R(eal) G(eneral)
128  A(array) C(omplex) H(ermitian)
129  P(attern) S(ymmetric)
130  I(nteger) K(kew)
131 
132  ***********************************************************************/
133 
134 extern const char *MM_MTX_STR;
135 extern const char *MM_ARRAY_STR;
136 extern const char *MM_DENSE_STR;
137 extern const char *MM_COORDINATE_STR;
138 extern const char *MM_SPARSE_STR;
139 extern const char *MM_COMPLEX_STR;
140 extern const char *MM_REAL_STR;
141 extern const char *MM_INT_STR;
142 extern const char *MM_GENERAL_STR;
143 extern const char *MM_SYMM_STR;
144 extern const char *MM_HERM_STR;
145 extern const char *MM_SKEW_STR;
146 extern const char *MM_PATTERN_STR;
147 
148 
149 /* high level routines */
150 
151 int mm_write_mtx_crd(char fname[], int M, int N, int nz, int I[], int J[],
152  double val[], MM_typecode matcode);
153 int mm_read_mtx_crd_data(FILE *f, int M, int N, int nz, int I[], int J[],
154  double val[], MM_typecode matcode);
155 int mm_read_mtx_crd_entry(FILE *f, int *I, int *J, double *real, double *img,
156  MM_typecode matcode);
157 
158 int mm_read_unsymmetric_sparse(const char *fname, int *M_, int *N_, int *nz_,
159  double **val_, int **I_, int **J_);
160 
161 
162 
163 #endif