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