LAMA
|
00001 00033 /* 00034 * Matrix Market I/O library 00035 * 00036 * See http://math.nist.gov/matrixMarket for details. 00037 * 00038 */ 00039 00040 #ifndef MM_IO_HPP 00041 #define MM_IO_HPP 00042 00043 #define MM_MAX_LINE_LENGTH 1025 00044 #define matrixMarketBanner "%%MatrixMarket" 00045 #define MM_MAX_TOKEN_LENGTH 64 00046 00047 #include <stdio.h> 00048 00049 typedef char MM_typecode[4]; 00050 00051 char* mm_typecode_to_str( MM_typecode matcode ); 00052 00053 int mm_read_banner( FILE* f, MM_typecode* matcode ); 00054 int mm_read_mtx_crd_size( FILE* f, int* M, int* N, int* nz ); 00055 int mm_read_mtx_array_size( FILE* f, int* M, int* N ); 00056 00057 int mm_write_banner( FILE* f, MM_typecode matcode ); 00058 int mm_write_mtx_crd_size( FILE* f, int M, int N, int nz ); 00059 int mm_write_mtx_array_size( FILE* f, int M, int N ); 00060 00061 00062 /********************* MM_typecode query fucntions ***************************/ 00063 00064 #define mm_is_matrix(typecode) ((typecode)[0]=='M') 00065 00066 #define mm_is_sparse(typecode) ((typecode)[1]=='C') 00067 #define mm_is_coordinate(typecode)((typecode)[1]=='C') 00068 #define mm_is_dense(typecode) ((typecode)[1]=='A') 00069 #define mm_is_array(typecode) ((typecode)[1]=='A') 00070 00071 #define mm_is_complex(typecode) ((typecode)[2]=='C') 00072 #define mm_is_real(typecode) ((typecode)[2]=='R') 00073 #define mm_is_pattern(typecode) ((typecode)[2]=='P') 00074 #define mm_is_integer(typecode) ((typecode)[2]=='I') 00075 00076 #define mm_is_symmetric(typecode)((typecode)[3]=='S') 00077 #define mm_is_general(typecode) ((typecode)[3]=='G') 00078 #define mm_is_skew(typecode) ((typecode)[3]=='K') 00079 #define mm_is_hermitian(typecode)((typecode)[3]=='H') 00080 00081 int mm_is_valid( MM_typecode matcode ); /* too complex for a macro */ 00082 00083 00084 /********************* MM_typecode modify fucntions ***************************/ 00085 00086 #define mm_set_matrix(typecode) ((*typecode)[0]='M') 00087 #define mm_set_coordinate(typecode) ((*typecode)[1]='C') 00088 #define mm_set_array(typecode) ((*typecode)[1]='A') 00089 #define mm_set_dense(typecode) mm_set_array(typecode) 00090 #define mm_set_sparse(typecode) mm_set_coordinate(typecode) 00091 00092 #define mm_set_complex(typecode)((*typecode)[2]='C') 00093 #define mm_set_real(typecode) ((*typecode)[2]='R') 00094 #define mm_set_pattern(typecode)((*typecode)[2]='P') 00095 #define mm_set_integer(typecode)((*typecode)[2]='I') 00096 00097 00098 #define mm_set_symmetric(typecode)((*typecode)[3]='S') 00099 #define mm_set_general(typecode)((*typecode)[3]='G') 00100 #define mm_set_skew(typecode) ((*typecode)[3]='K') 00101 #define mm_set_hermitian(typecode)((*typecode)[3]='H') 00102 00103 #define mm_clear_typecode(typecode) ((*typecode)[0]=(*typecode)[1]= \ 00104 (*typecode)[2]=' ',(*typecode)[3]='G') 00105 00106 #define mm_initialize_typecode(typecode) mm_clear_typecode(typecode) 00107 00108 00109 /********************* Matrix Market error codes ***************************/ 00110 00111 00112 #define MM_COULD_NOT_READ_FILE 11 00113 #define MM_PREMATURE_EOF 12 00114 #define MM_NOT_MTX 13 00115 #define MM_NO_HEADER 14 00116 #define MM_UNSUPPORTED_TYPE 15 00117 #define MM_LINE_TOO_LONG 16 00118 #define MM_COULD_NOT_WRITE_FILE 17 00119 00120 char* getErrorString( int error ); 00121 00122 /******************** Matrix Market internal definitions ******************** 00123 00124 MM_matrix_typecode: 4-character sequence 00125 00126 ojbect sparse/ data storage 00127 dense type scheme 00128 00129 string position: [0] [1] [2] [3] 00130 00131 Matrix typecode: M(atrix) C(oord) R(eal) G(eneral) 00132 A(array) C(omplex) H(ermitian) 00133 P(attern) S(ymmetric) 00134 I(nteger) K(kew) 00135 00136 ***********************************************************************/ 00137 00138 #define MM_MTX_STR "matrix" 00139 #define MM_ARRAY_STR "array" 00140 #define MM_DENSE_STR "array" 00141 #define MM_COORDINATE_STR "coordinate" 00142 #define MM_SPARSE_STR "coordinate" 00143 #define MM_COMPLEX_STR "complex" 00144 #define MM_REAL_STR "real" 00145 #define MM_INT_STR "integer" 00146 #define MM_GENERAL_STR "general" 00147 #define MM_SYMM_STR "symmetric" 00148 #define MM_HERM_STR "hermitian" 00149 #define MM_SKEW_STR "skew-symmetric" 00150 #define MM_PATTERN_STR "pattern" 00151 00152 00153 /* high level routines */ 00154 00155 int mm_write_mtx_crd( char fname[], int M, int N, int nz, int I[], int J[], 00156 double val[], MM_typecode matcode ); 00157 int mm_read_mtx_crd_data( FILE* f, int M, int N, int nz, int I[], int J[], 00158 double val[], MM_typecode matcode ); 00159 int mm_read_mtx_crd_entry( FILE* f, int* I, int* J, double* real, double* img, 00160 MM_typecode matcode ); 00161 00162 int mm_read_unsymmetric_sparse( const char* fname, int* M_, int* N_, int* nz_, 00163 double** val_, int** I_, int** J_ ); 00164 00165 #endif