|
EpetraExt
Development
|
00001 /* 00002 //@HEADER 00003 // *********************************************************************** 00004 // 00005 // EpetraExt: Epetra Extended - Linear Algebra Services Package 00006 // Copyright (2011) Sandia Corporation 00007 // 00008 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 00009 // the U.S. Government retains certain rights in this software. 00010 // 00011 // Redistribution and use in source and binary forms, with or without 00012 // modification, are permitted provided that the following conditions are 00013 // met: 00014 // 00015 // 1. Redistributions of source code must retain the above copyright 00016 // notice, this list of conditions and the following disclaimer. 00017 // 00018 // 2. Redistributions in binary form must reproduce the above copyright 00019 // notice, this list of conditions and the following disclaimer in the 00020 // documentation and/or other materials provided with the distribution. 00021 // 00022 // 3. Neither the name of the Corporation nor the names of the 00023 // contributors may be used to endorse or promote products derived from 00024 // this software without specific prior written permission. 00025 // 00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00037 // 00038 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00039 // 00040 // *********************************************************************** 00041 //@HEADER 00042 */ 00043 00044 /* 00045 * Matrix Market I/O library for ANSI C 00046 * 00047 * See http://math.nist.gov/MatrixMarket for details. 00048 * 00049 * 00050 */ 00051 00052 #include <cstdio> 00053 #include <cstdlib> 00054 00055 #ifndef MM_IO_H 00056 #define MM_IO_H 00057 00058 #define MM_MAX_LINE_LENGTH 1025 00059 #define MatrixMarketBanner "%%MatrixMarket" 00060 #define MM_MAX_TOKEN_LENGTH 64 00061 00062 typedef char MM_typecode[4]; 00063 00064 namespace EpetraExt { 00065 00066 void mm_typecode_to_str(MM_typecode matcode, char * buffer); 00067 00068 int mm_read_banner(std::FILE *f, MM_typecode *matcode); 00069 int mm_read_mtx_crd_size(std::FILE *f, int *M, int *N, int *nz); 00070 int mm_read_mtx_crd_size(std::FILE *f, long long *M, long long *N, long long *nz); 00071 int mm_read_mtx_array_size(std::FILE *f, int *M, int *N); 00072 00073 int mm_write_banner(std::FILE *f, MM_typecode matcode); 00074 int mm_write_mtx_crd_size(std::FILE *f, long long M, long long N, long long nz); 00075 int mm_write_mtx_array_size(std::FILE *f, long long M, long long N); 00076 00077 00078 /********************* MM_typecode query fucntions ***************************/ 00079 00080 #define mm_is_matrix(typecode) ((typecode)[0]=='M') 00081 00082 #define mm_is_sparse(typecode) ((typecode)[1]=='C') 00083 #define mm_is_coordinate(typecode)((typecode)[1]=='C') 00084 #define mm_is_dense(typecode) ((typecode)[1]=='A') 00085 #define mm_is_array(typecode) ((typecode)[1]=='A') 00086 00087 #define mm_is_complex(typecode) ((typecode)[2]=='C') 00088 #define mm_is_real(typecode) ((typecode)[2]=='R') 00089 #define mm_is_pattern(typecode) ((typecode)[2]=='P') 00090 #define mm_is_integer(typecode) ((typecode)[2]=='I') 00091 00092 #define mm_is_symmetric(typecode)((typecode)[3]=='S') 00093 #define mm_is_general(typecode) ((typecode)[3]=='G') 00094 #define mm_is_skew(typecode) ((typecode)[3]=='K') 00095 #define mm_is_hermitian(typecode)((typecode)[3]=='H') 00096 00097 int mm_is_valid(MM_typecode matcode); /* too complex for a macro */ 00098 00099 00100 /********************* MM_typecode modify fucntions ***************************/ 00101 00102 #define mm_set_matrix(typecode) ((*typecode)[0]='M') 00103 #define mm_set_coordinate(typecode) ((*typecode)[1]='C') 00104 #define mm_set_array(typecode) ((*typecode)[1]='A') 00105 #define mm_set_dense(typecode) mm_set_array(typecode) 00106 #define mm_set_sparse(typecode) mm_set_coordinate(typecode) 00107 00108 #define mm_set_complex(typecode)((*typecode)[2]='C') 00109 #define mm_set_real(typecode) ((*typecode)[2]='R') 00110 #define mm_set_pattern(typecode)((*typecode)[2]='P') 00111 #define mm_set_integer(typecode)((*typecode)[2]='I') 00112 00113 00114 #define mm_set_symmetric(typecode)((*typecode)[3]='S') 00115 #define mm_set_general(typecode)((*typecode)[3]='G') 00116 #define mm_set_skew(typecode) ((*typecode)[3]='K') 00117 #define mm_set_hermitian(typecode)((*typecode)[3]='H') 00118 00119 #define mm_clear_typecode(typecode) ((*typecode)[0]=(*typecode)[1]= \ 00120 (*typecode)[2]=' ',(*typecode)[3]='G') 00121 00122 #define mm_initialize_typecode(typecode) mm_clear_typecode(typecode) 00123 00124 00125 /********************* Matrix Market error codes ***************************/ 00126 00127 00128 #define MM_COULD_NOT_READ_FILE 11 00129 #define MM_PREMATURE_EOF 12 00130 #define MM_NOT_MTX 13 00131 #define MM_NO_HEADER 14 00132 #define MM_UNSUPPORTED_TYPE 15 00133 #define MM_LINE_TOO_LONG 16 00134 #define MM_COULD_NOT_WRITE_FILE 17 00135 00136 00137 /******************** Matrix Market internal definitions ******************** 00138 00139 MM_matrix_typecode: 4-character sequence 00140 00141 ojbect sparse/ data storage 00142 dense type scheme 00143 00144 string position: [0] [1] [2] [3] 00145 00146 Matrix typecode: M(atrix) C(oord) R(eal) G(eneral) 00147 A(array) C(omplex) H(ermitian) 00148 P(attern) S(ymmetric) 00149 I(nteger) K(kew) 00150 00151 ***********************************************************************/ 00152 00153 #define MM_MTX_STR "matrix" 00154 #define MM_ARRAY_STR "array" 00155 #define MM_DENSE_STR "array" 00156 #define MM_COORDINATE_STR "coordinate" 00157 #define MM_SPARSE_STR "coordinate" 00158 #define MM_COMPLEX_STR "complex" 00159 #define MM_REAL_STR "real" 00160 #define MM_INT_STR "integer" 00161 #define MM_GENERAL_STR "general" 00162 #define MM_SYMM_STR "symmetric" 00163 #define MM_HERM_STR "hermitian" 00164 #define MM_SKEW_STR "skew-symmetric" 00165 #define MM_PATTERN_STR "pattern" 00166 00167 00168 /* high level routines */ 00169 00170 int mm_write_mtx_crd(char fname[], int M, int N, int nz, int I[], int J[], 00171 double val[], MM_typecode matcode); 00172 int mm_read_mtx_crd_data(std::FILE *f, int M, int N, int nz, int I[], int J[], 00173 double val[], MM_typecode matcode); 00174 int mm_read_mtx_crd_entry(std::FILE *f, int *I, int *J, double *real, double *img, 00175 MM_typecode matcode); 00176 int mm_read_mtx_crd_entry(std::FILE *f, long long *I, long long *J, double *real, double *img, 00177 MM_typecode matcode); 00178 00179 int mm_read_unsymmetric_sparse(const char *fname, int *M_, int *N_, int *nz_, 00180 double **val_, int **I_, int **J_); 00181 00182 00183 } // namespace EpetraExt 00184 00185 #endif
1.7.6.1