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