EpetraExt Development
EpetraExt_mmio.h
Go to the documentation of this file.
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_array_size(std::FILE *f, int *M, int *N);
00071 
00072 int mm_write_banner(std::FILE *f, MM_typecode matcode);
00073 int mm_write_mtx_crd_size(std::FILE *f, int M, int N, int nz);
00074 int mm_write_mtx_array_size(std::FILE *f, int M, int N);
00075 
00076 
00077 /********************* MM_typecode query fucntions ***************************/
00078 
00079 #define mm_is_matrix(typecode)  ((typecode)[0]=='M')
00080 
00081 #define mm_is_sparse(typecode)  ((typecode)[1]=='C')
00082 #define mm_is_coordinate(typecode)((typecode)[1]=='C')
00083 #define mm_is_dense(typecode) ((typecode)[1]=='A')
00084 #define mm_is_array(typecode) ((typecode)[1]=='A')
00085 
00086 #define mm_is_complex(typecode) ((typecode)[2]=='C')
00087 #define mm_is_real(typecode)    ((typecode)[2]=='R')
00088 #define mm_is_pattern(typecode) ((typecode)[2]=='P')
00089 #define mm_is_integer(typecode) ((typecode)[2]=='I')
00090 
00091 #define mm_is_symmetric(typecode)((typecode)[3]=='S')
00092 #define mm_is_general(typecode) ((typecode)[3]=='G')
00093 #define mm_is_skew(typecode)  ((typecode)[3]=='K')
00094 #define mm_is_hermitian(typecode)((typecode)[3]=='H')
00095 
00096 int mm_is_valid(MM_typecode matcode);   /* too complex for a macro */
00097 
00098 
00099 /********************* MM_typecode modify fucntions ***************************/
00100 
00101 #define mm_set_matrix(typecode) ((*typecode)[0]='M')
00102 #define mm_set_coordinate(typecode) ((*typecode)[1]='C')
00103 #define mm_set_array(typecode)  ((*typecode)[1]='A')
00104 #define mm_set_dense(typecode)  mm_set_array(typecode)
00105 #define mm_set_sparse(typecode) mm_set_coordinate(typecode)
00106 
00107 #define mm_set_complex(typecode)((*typecode)[2]='C')
00108 #define mm_set_real(typecode) ((*typecode)[2]='R')
00109 #define mm_set_pattern(typecode)((*typecode)[2]='P')
00110 #define mm_set_integer(typecode)((*typecode)[2]='I')
00111 
00112 
00113 #define mm_set_symmetric(typecode)((*typecode)[3]='S')
00114 #define mm_set_general(typecode)((*typecode)[3]='G')
00115 #define mm_set_skew(typecode) ((*typecode)[3]='K')
00116 #define mm_set_hermitian(typecode)((*typecode)[3]='H')
00117 
00118 #define mm_clear_typecode(typecode) ((*typecode)[0]=(*typecode)[1]= \
00119                   (*typecode)[2]=' ',(*typecode)[3]='G')
00120 
00121 #define mm_initialize_typecode(typecode) mm_clear_typecode(typecode)
00122 
00123 
00124 /********************* Matrix Market error codes ***************************/
00125 
00126 
00127 #define MM_COULD_NOT_READ_FILE  11
00128 #define MM_PREMATURE_EOF    12
00129 #define MM_NOT_MTX        13
00130 #define MM_NO_HEADER      14
00131 #define MM_UNSUPPORTED_TYPE   15
00132 #define MM_LINE_TOO_LONG    16
00133 #define MM_COULD_NOT_WRITE_FILE 17
00134 
00135 
00136 /******************** Matrix Market internal definitions ********************
00137 
00138    MM_matrix_typecode: 4-character sequence
00139 
00140             ojbect    sparse/     data        storage 
00141                   dense       type        scheme
00142 
00143    string position:  [0]        [1]     [2]         [3]
00144 
00145    Matrix typecode:  M(atrix)  C(oord)    R(eal)    G(eneral)
00146                     A(array)  C(omplex)   H(ermitian)
00147                       P(attern)   S(ymmetric)
00148                         I(nteger) K(kew)
00149 
00150  ***********************************************************************/
00151 
00152 #define MM_MTX_STR    "matrix"
00153 #define MM_ARRAY_STR  "array"
00154 #define MM_DENSE_STR  "array"
00155 #define MM_COORDINATE_STR "coordinate" 
00156 #define MM_SPARSE_STR "coordinate"
00157 #define MM_COMPLEX_STR  "complex"
00158 #define MM_REAL_STR   "real"
00159 #define MM_INT_STR    "integer"
00160 #define MM_GENERAL_STR  "general"
00161 #define MM_SYMM_STR   "symmetric"
00162 #define MM_HERM_STR   "hermitian"
00163 #define MM_SKEW_STR   "skew-symmetric"
00164 #define MM_PATTERN_STR  "pattern"
00165 
00166 
00167 /*  high level routines */
00168 
00169 int mm_write_mtx_crd(char fname[], int M, int N, int nz, int I[], int J[],
00170      double val[], MM_typecode matcode);
00171 int mm_read_mtx_crd_data(std::FILE *f, int M, int N, int nz, int I[], int J[],
00172     double val[], MM_typecode matcode);
00173 int mm_read_mtx_crd_entry(std::FILE *f, int *I, int *J, double *real, double *img,
00174       MM_typecode matcode);
00175 
00176 int mm_read_unsymmetric_sparse(const char *fname, int *M_, int *N_, int *nz_,
00177                 double **val_, int **I_, int **J_);
00178 
00179 
00180 } // namespace EpetraExt
00181 
00182 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines