escript  Revision_
mmio.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2016 by The University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Apache License, version 2.0
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development 2012-2013 by School of Earth Sciences
13 * Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 *
15 *****************************************************************************/
16 
17 
18 /*
19 * Matrix Market I/O library for ANSI C
20 *
21 * See http://math.nist.gov/MatrixMarket for details.
22 *
23 */
24 
25 #ifndef MM_IO_H
26 #define MM_IO_H
27 
28 #include <fstream>
29 
30 #define MM_MAX_LINE_LENGTH 1025
31 #define MatrixMarketBanner "%%MatrixMarket"
32 #define MM_MAX_TOKEN_LENGTH 64
33 
34 typedef char MM_typecode[4];
35 
36 char *mm_typecode_to_str(MM_typecode matcode);
37 
38 int mm_read_banner(std::istream& f, MM_typecode *matcode);
39 int mm_read_mtx_crd_size(std::istream& f, int *M, int *N, int *nz);
40 int mm_read_mtx_array_size(std::istream& f, int *M, int *N);
41 
42 int mm_write_banner(std::ostream& f, MM_typecode matcode);
43 int mm_write_mtx_crd_size(std::ostream& f, int M, int N, int nz);
44 int mm_write_mtx_array_size(std::ostream& f, int M, int N);
45 
46 
47 /********************* MM_typecode query functions ***************************/
48 
49 #define mm_is_matrix(typecode) ((typecode)[0]=='M')
50 
51 #define mm_is_sparse(typecode) ((typecode)[1]=='C')
52 #define mm_is_coordinate(typecode)((typecode)[1]=='C')
53 #define mm_is_dense(typecode) ((typecode)[1]=='A')
54 #define mm_is_array(typecode) ((typecode)[1]=='A')
55 
56 #define mm_is_complex(typecode) ((typecode)[2]=='C')
57 #define mm_is_real(typecode) ((typecode)[2]=='R')
58 #define mm_is_pattern(typecode) ((typecode)[2]=='P')
59 #define mm_is_integer(typecode) ((typecode)[2]=='I')
60 
61 #define mm_is_symmetric(typecode)((typecode)[3]=='S')
62 #define mm_is_general(typecode) ((typecode)[3]=='G')
63 #define mm_is_skew(typecode) ((typecode)[3]=='K')
64 #define mm_is_hermitian(typecode)((typecode)[3]=='H')
65 
66 int mm_is_valid(MM_typecode matcode); /* too complex for a macro */
67 
68 
69 /********************* MM_typecode modify functions ***************************/
70 
71 #define mm_set_matrix(typecode) ((*typecode)[0]='M')
72 #define mm_set_coordinate(typecode) ((*typecode)[1]='C')
73 #define mm_set_array(typecode) ((*typecode)[1]='A')
74 #define mm_set_dense(typecode) mm_set_array(typecode)
75 #define mm_set_sparse(typecode) mm_set_coordinate(typecode)
76 
77 #define mm_set_complex(typecode)((*typecode)[2]='C')
78 #define mm_set_real(typecode) ((*typecode)[2]='R')
79 #define mm_set_pattern(typecode)((*typecode)[2]='P')
80 #define mm_set_integer(typecode)((*typecode)[2]='I')
81 
82 
83 #define mm_set_symmetric(typecode)((*typecode)[3]='S')
84 #define mm_set_general(typecode)((*typecode)[3]='G')
85 #define mm_set_skew(typecode) ((*typecode)[3]='K')
86 #define mm_set_hermitian(typecode)((*typecode)[3]='H')
87 
88 #define mm_clear_typecode(typecode) ((*typecode)[0]=(*typecode)[1]= \
89  (*typecode)[2]=' ',(*typecode)[3]='G')
90 
91 #define mm_initialize_typecode(typecode) mm_clear_typecode(typecode)
92 
93 
94 /********************* Matrix Market error codes ***************************/
95 
96 
97 #define MM_COULD_NOT_READ_FILE 11
98 #define MM_PREMATURE_EOF 12
99 #define MM_NOT_MTX 13
100 #define MM_NO_HEADER 14
101 #define MM_UNSUPPORTED_TYPE 15
102 #define MM_LINE_TOO_LONG 16
103 #define MM_COULD_NOT_WRITE_FILE 17
104 
105 
106 /******************** Matrix Market internal definitions ********************
107 
108  MM_matrix_typecode: 4-character sequence
109 
110  object sparse/ data storage
111  dense type scheme
112 
113  string position: [0] [1] [2] [3]
114 
115  Matrix typecode: M(atrix) C(oord) R(eal) G(eneral)
116  A(array) C(omplex) H(ermitian)
117  P(attern) S(ymmetric)
118  I(nteger) sKew
119 
120  ****************************************************************************/
121 
122 #define MM_MTX_STR "matrix"
123 #define MM_ARRAY_STR "array"
124 #define MM_DENSE_STR "array"
125 #define MM_COORDINATE_STR "coordinate"
126 #define MM_SPARSE_STR "coordinate"
127 #define MM_COMPLEX_STR "complex"
128 #define MM_REAL_STR "real"
129 #define MM_INT_STR "integer"
130 #define MM_GENERAL_STR "general"
131 #define MM_SYMM_STR "symmetric"
132 #define MM_HERM_STR "hermitian"
133 #define MM_SKEW_STR "skew-symmetric"
134 #define MM_PATTERN_STR "pattern"
135 
136 
137 /* high level routines */
138 
139 int mm_write_mtx_crd(char* fname, int M, int N, int nz, int* i, int* j,
140  double* val, MM_typecode matcode);
141 
142 int mm_read_mtx_crd_data(std::istream& f, int M, int N, int nz, int* i, int* j,
143  double* val, MM_typecode matcode);
144 
145 int mm_read_mtx_crd_entry(std::istream& f, int* i, int* j, double* real,
146  double* img, MM_typecode matcode);
147 
148 int mm_read_unsymmetric_sparse(const char* fname, int* M, int* N, int* nz,
149  double** val, int** I, int** J);
150 
151 #endif
152 
153 /*
154  * $Log$
155  * Revision 1.1 2004/10/26 06:53:59 jgs
156  * Initial revision
157  *
158  * Revision 1.1 2004/07/02 00:48:35 gross
159  * matrix market io function added
160  *
161  *
162  */
int mm_read_mtx_array_size(std::istream &f, int *M, int *N)
Definition: mmio.cpp:210
int mm_write_banner(std::ostream &f, MM_typecode matcode)
Definition: mmio.cpp:356
int mm_write_mtx_crd(char *fname, int M, int N, int nz, int *i, int *j, double *val, MM_typecode matcode)
Definition: mmio.cpp:364
int mm_read_mtx_crd_entry(std::istream &f, int *i, int *j, double *real, double *img, MM_typecode matcode)
Definition: mmio.cpp:282
static dim_t M
Definition: SparseMatrix_saveHB.cpp:37
int mm_write_mtx_crd_size(std::ostream &f, int M, int N, int nz)
Definition: mmio.cpp:173
int mm_read_banner(std::istream &f, MM_typecode *matcode)
Definition: mmio.cpp:103
static dim_t N
Definition: SparseMatrix_saveHB.cpp:37
char MM_typecode[4]
Definition: mmio.h:34
int mm_read_mtx_crd_size(std::istream &f, int *M, int *N, int *nz)
Definition: mmio.cpp:181
int mm_write_mtx_array_size(std::ostream &f, int M, int N)
Definition: mmio.cpp:239
int mm_read_mtx_crd_data(std::istream &f, int M, int N, int nz, int *i, int *j, double *val, MM_typecode matcode)
Definition: mmio.cpp:254
int mm_is_valid(MM_typecode matcode)
Definition: mmio.cpp:93
int mm_read_unsymmetric_sparse(const char *fname, int *M, int *N, int *nz, double **val, int **I, int **J)
Definition: mmio.cpp:32
static dim_t nz
Definition: SparseMatrix_saveHB.cpp:37
char * mm_typecode_to_str(MM_typecode matcode)
Definition: mmio.cpp:405