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