1 |
/* |
2 |
* Matrix Market I/O library for ANSI C |
3 |
* |
4 |
* See http://math.nist.gov/MatrixMarket for details. |
5 |
*/ |
6 |
|
7 |
#ifndef MM_IO_H |
8 |
#define MM_IO_H |
9 |
|
10 |
#define MM_MAX_LINE_LENGTH 1025 |
11 |
#define MatrixMarketBanner "%%MatrixMarket" |
12 |
#define MM_MAX_TOKEN_LENGTH 64 |
13 |
|
14 |
typedef char MM_typecode[4]; |
15 |
|
16 |
char *mm_typecode_to_str(MM_typecode matcode); |
17 |
|
18 |
int mm_read_banner(FILE *f, MM_typecode *matcode); |
19 |
int mm_read_mtx_crd_size(FILE *f, int *M, int *N, int *nz); |
20 |
int mm_read_mtx_array_size(FILE *f, int *M, int *N); |
21 |
|
22 |
int mm_write_banner(FILE *f, MM_typecode matcode); |
23 |
int mm_write_mtx_crd_size(FILE *f, int M, int N, int nz); |
24 |
int mm_write_mtx_array_size(FILE *f, int M, int N); |
25 |
|
26 |
|
27 |
/********************* MM_typecode query fucntions ***************************/ |
28 |
|
29 |
#define mm_is_matrix(typecode) ((typecode)[0]=='M') |
30 |
|
31 |
#define mm_is_sparse(typecode) ((typecode)[1]=='C') |
32 |
#define mm_is_coordinate(typecode)((typecode)[1]=='C') |
33 |
#define mm_is_dense(typecode) ((typecode)[1]=='A') |
34 |
#define mm_is_array(typecode) ((typecode)[1]=='A') |
35 |
|
36 |
#define mm_is_complex(typecode) ((typecode)[2]=='C') |
37 |
#define mm_is_real(typecode) ((typecode)[2]=='R') |
38 |
#define mm_is_pattern(typecode) ((typecode)[2]=='P') |
39 |
#define mm_is_integer(typecode) ((typecode)[2]=='I') |
40 |
|
41 |
#define mm_is_symmetric(typecode)((typecode)[3]=='S') |
42 |
#define mm_is_general(typecode) ((typecode)[3]=='G') |
43 |
#define mm_is_skew(typecode) ((typecode)[3]=='K') |
44 |
#define mm_is_hermitian(typecode)((typecode)[3]=='H') |
45 |
|
46 |
int mm_is_valid(MM_typecode matcode); /* too complex for a macro */ |
47 |
|
48 |
|
49 |
/********************* MM_typecode modify fucntions ***************************/ |
50 |
|
51 |
#define mm_set_matrix(typecode) ((*typecode)[0]='M') |
52 |
#define mm_set_coordinate(typecode) ((*typecode)[1]='C') |
53 |
#define mm_set_array(typecode) ((*typecode)[1]='A') |
54 |
#define mm_set_dense(typecode) mm_set_array(typecode) |
55 |
#define mm_set_sparse(typecode) mm_set_coordinate(typecode) |
56 |
|
57 |
#define mm_set_complex(typecode)((*typecode)[2]='C') |
58 |
#define mm_set_real(typecode) ((*typecode)[2]='R') |
59 |
#define mm_set_pattern(typecode)((*typecode)[2]='P') |
60 |
#define mm_set_integer(typecode)((*typecode)[2]='I') |
61 |
|
62 |
|
63 |
#define mm_set_symmetric(typecode)((*typecode)[3]='S') |
64 |
#define mm_set_general(typecode)((*typecode)[3]='G') |
65 |
#define mm_set_skew(typecode) ((*typecode)[3]='K') |
66 |
#define mm_set_hermitian(typecode)((*typecode)[3]='H') |
67 |
|
68 |
#define mm_clear_typecode(typecode) ((*typecode)[0]=(*typecode)[1]= \ |
69 |
(*typecode)[2]=' ',(*typecode)[3]='G') |
70 |
|
71 |
#define mm_initialize_typecode(typecode) mm_clear_typecode(typecode) |
72 |
|
73 |
|
74 |
/********************* Matrix Market error codes ***************************/ |
75 |
|
76 |
|
77 |
#define MM_COULD_NOT_READ_FILE 11 |
78 |
#define MM_PREMATURE_EOF 12 |
79 |
#define MM_NOT_MTX 13 |
80 |
#define MM_NO_HEADER 14 |
81 |
#define MM_UNSUPPORTED_TYPE 15 |
82 |
#define MM_LINE_TOO_LONG 16 |
83 |
#define MM_COULD_NOT_WRITE_FILE 17 |
84 |
|
85 |
|
86 |
/******************** Matrix Market internal definitions ******************** |
87 |
|
88 |
MM_matrix_typecode: 4-character sequence |
89 |
|
90 |
ojbect sparse/ data storage |
91 |
dense type scheme |
92 |
|
93 |
string position: [0] [1] [2] [3] |
94 |
|
95 |
Matrix typecode: M(atrix) C(oord) R(eal) G(eneral) |
96 |
A(array) C(omplex) H(ermitian) |
97 |
P(attern) S(ymmetric) |
98 |
I(nteger) K(kew) |
99 |
|
100 |
***********************************************************************/ |
101 |
|
102 |
#define MM_MTX_STR "matrix" |
103 |
#define MM_ARRAY_STR "array" |
104 |
#define MM_DENSE_STR "array" |
105 |
#define MM_COORDINATE_STR "coordinate" |
106 |
#define MM_SPARSE_STR "coordinate" |
107 |
#define MM_COMPLEX_STR "complex" |
108 |
#define MM_REAL_STR "real" |
109 |
#define MM_INT_STR "integer" |
110 |
#define MM_GENERAL_STR "general" |
111 |
#define MM_SYMM_STR "symmetric" |
112 |
#define MM_HERM_STR "hermitian" |
113 |
#define MM_SKEW_STR "skew-symmetric" |
114 |
#define MM_PATTERN_STR "pattern" |
115 |
|
116 |
|
117 |
/* high level routines */ |
118 |
|
119 |
int mm_write_mtx_crd(char fname[], int M, int N, int nz, int I[], int J[], |
120 |
double val[], MM_typecode matcode); |
121 |
int mm_read_mtx_crd_data(FILE *f, int M, int N, int nz, int I[], int J[], |
122 |
double val[], MM_typecode matcode); |
123 |
int mm_read_mtx_crd_entry(FILE *f, int *I, int *J, double *real, double *img, |
124 |
MM_typecode matcode); |
125 |
|
126 |
int mm_read_unsymmetric_sparse(const char *fname, int *M_, int *N_, int *nz_, |
127 |
double **val_, int **I_, int **J_); |
128 |
|
129 |
|
130 |
|
131 |
#endif |