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