ESYS13
Revision_
|
00001 00002 /******************************************************* 00003 * 00004 * Copyright (c) 2003-2012 by University of Queensland 00005 * Earth Systems Science Computational Center (ESSCC) 00006 * http://www.uq.edu.au/esscc 00007 * 00008 * Primary Business: Queensland, Australia 00009 * Licensed under the Open Software License version 3.0 00010 * http://www.opensource.org/licenses/osl-3.0.php 00011 * 00012 *******************************************************/ 00013 00014 00015 /* 00016 * Matrix Market I/O library for ANSI C 00017 * 00018 * See http://math.nist.gov/MatrixMarket for details. 00019 * 00020 */ 00021 00022 #ifndef MM_IO_H 00023 #define MM_IO_H 00024 00025 #include <stdio.h> 00026 00027 #define MM_MAX_LINE_LENGTH 1025 00028 #define MatrixMarketBanner "%%MatrixMarket" 00029 #define MM_MAX_TOKEN_LENGTH 64 00030 00031 typedef char MM_typecode[4]; 00032 00033 char *mm_typecode_to_str(MM_typecode matcode); 00034 00035 int mm_read_banner(FILE *f, MM_typecode *matcode); 00036 int mm_read_mtx_crd_size(FILE *f, int *M, int *N, int *nz); 00037 int mm_read_mtx_array_size(FILE *f, int *M, int *N); 00038 00039 int mm_write_banner(FILE *f, MM_typecode matcode); 00040 int mm_write_mtx_crd_size(FILE *f, int M, int N, int nz); 00041 int mm_write_mtx_array_size(FILE *f, int M, int N); 00042 00043 00044 /********************* MM_typecode query functions ***************************/ 00045 00046 #define mm_is_matrix(typecode) ((typecode)[0]=='M') 00047 00048 #define mm_is_sparse(typecode) ((typecode)[1]=='C') 00049 #define mm_is_coordinate(typecode)((typecode)[1]=='C') 00050 #define mm_is_dense(typecode) ((typecode)[1]=='A') 00051 #define mm_is_array(typecode) ((typecode)[1]=='A') 00052 00053 #define mm_is_complex(typecode) ((typecode)[2]=='C') 00054 #define mm_is_real(typecode) ((typecode)[2]=='R') 00055 #define mm_is_pattern(typecode) ((typecode)[2]=='P') 00056 #define mm_is_integer(typecode) ((typecode)[2]=='I') 00057 00058 #define mm_is_symmetric(typecode)((typecode)[3]=='S') 00059 #define mm_is_general(typecode) ((typecode)[3]=='G') 00060 #define mm_is_skew(typecode) ((typecode)[3]=='K') 00061 #define mm_is_hermitian(typecode)((typecode)[3]=='H') 00062 00063 int mm_is_valid(MM_typecode matcode); /* too complex for a macro */ 00064 00065 00066 /********************* MM_typecode modify functions ***************************/ 00067 00068 #define mm_set_matrix(typecode) ((*typecode)[0]='M') 00069 #define mm_set_coordinate(typecode) ((*typecode)[1]='C') 00070 #define mm_set_array(typecode) ((*typecode)[1]='A') 00071 #define mm_set_dense(typecode) mm_set_array(typecode) 00072 #define mm_set_sparse(typecode) mm_set_coordinate(typecode) 00073 00074 #define mm_set_complex(typecode)((*typecode)[2]='C') 00075 #define mm_set_real(typecode) ((*typecode)[2]='R') 00076 #define mm_set_pattern(typecode)((*typecode)[2]='P') 00077 #define mm_set_integer(typecode)((*typecode)[2]='I') 00078 00079 00080 #define mm_set_symmetric(typecode)((*typecode)[3]='S') 00081 #define mm_set_general(typecode)((*typecode)[3]='G') 00082 #define mm_set_skew(typecode) ((*typecode)[3]='K') 00083 #define mm_set_hermitian(typecode)((*typecode)[3]='H') 00084 00085 #define mm_clear_typecode(typecode) ((*typecode)[0]=(*typecode)[1]= \ 00086 (*typecode)[2]=' ',(*typecode)[3]='G') 00087 00088 #define mm_initialize_typecode(typecode) mm_clear_typecode(typecode) 00089 00090 00091 /********************* Matrix Market error codes ***************************/ 00092 00093 00094 #define MM_COULD_NOT_READ_FILE 11 00095 #define MM_PREMATURE_EOF 12 00096 #define MM_NOT_MTX 13 00097 #define MM_NO_HEADER 14 00098 #define MM_UNSUPPORTED_TYPE 15 00099 #define MM_LINE_TOO_LONG 16 00100 #define MM_COULD_NOT_WRITE_FILE 17 00101 00102 00103 /******************** Matrix Market internal definitions ******************** 00104 00105 MM_matrix_typecode: 4-character sequence 00106 00107 object sparse/ data storage 00108 dense type scheme 00109 00110 string position: [0] [1] [2] [3] 00111 00112 Matrix typecode: M(atrix) C(oord) R(eal) G(eneral) 00113 A(array) C(omplex) H(ermitian) 00114 P(attern) S(ymmetric) 00115 I(nteger) sKew 00116 00117 ***********************************************************************/ 00118 00119 #define MM_MTX_STR "matrix" 00120 #define MM_ARRAY_STR "array" 00121 #define MM_DENSE_STR "array" 00122 #define MM_COORDINATE_STR "coordinate" 00123 #define MM_SPARSE_STR "coordinate" 00124 #define MM_COMPLEX_STR "complex" 00125 #define MM_REAL_STR "real" 00126 #define MM_INT_STR "integer" 00127 #define MM_GENERAL_STR "general" 00128 #define MM_SYMM_STR "symmetric" 00129 #define MM_HERM_STR "hermitian" 00130 #define MM_SKEW_STR "skew-symmetric" 00131 #define MM_PATTERN_STR "pattern" 00132 00133 00134 /* high level routines */ 00135 00136 int mm_write_mtx_crd(char fname[], int M, int N, int nz, int i[], int j[], 00137 double val[], MM_typecode matcode); 00138 int mm_read_mtx_crd_data(FILE *f, int M, int N, int nz, int i[], int j[], 00139 double val[], MM_typecode matcode); 00140 int mm_read_mtx_crd_entry(FILE *f, int *i, int *j, double *real, double *img, 00141 MM_typecode matcode); 00142 00143 int mm_read_unsymmetric_sparse(const char *fname, int *M_, int *N_, int *nz_, 00144 double **val_, int **I_, int **J_); 00145 00146 #endif 00147 00148 /* 00149 * $Log$ 00150 * Revision 1.1 2004/10/26 06:53:59 jgs 00151 * Initial revision 00152 * 00153 * Revision 1.1 2004/07/02 00:48:35 gross 00154 * matrix market io function added 00155 * 00156 * 00157 */