ColPack
Utilities/mmio.h
Go to the documentation of this file.
00001 /* 
00002 *   Matrix Market I/O library for ANSI C
00003 *
00004 *   See http://math.nist.gov/MatrixMarket for details.
00005 *
00006 *
00007 */
00008 
00009 #ifndef MM_IO_H
00010 #define MM_IO_H
00011 
00012 #define MM_MAX_LINE_LENGTH 1025
00013 #define MatrixMarketBanner "%%MatrixMarket"
00014 #define MM_MAX_TOKEN_LENGTH 64
00015 
00016 typedef char MM_typecode[4];
00017 
00018 char *mm_typecode_to_str(MM_typecode matcode);
00019 
00020 int mm_read_banner(FILE *f, MM_typecode *matcode);
00021 int mm_read_mtx_crd_size(FILE *f, int *M, int *N, int *nz);
00022 int mm_read_mtx_array_size(FILE *f, int *M, int *N);
00023 
00024 int mm_write_banner(FILE *f, MM_typecode matcode);
00025 int mm_write_mtx_crd_size(FILE *f, int M, int N, int nz);
00026 int mm_write_mtx_array_size(FILE *f, int M, int N);
00027 
00028 
00029 /********************* MM_typecode query fucntions ***************************/
00030 
00031 #define mm_is_matrix(typecode)  ((typecode)[0]=='M')
00032 
00033 #define mm_is_sparse(typecode)  ((typecode)[1]=='C')
00034 #define mm_is_coordinate(typecode)((typecode)[1]=='C')
00035 #define mm_is_dense(typecode)   ((typecode)[1]=='A')
00036 #define mm_is_array(typecode)   ((typecode)[1]=='A')
00037 
00038 #define mm_is_complex(typecode) ((typecode)[2]=='C')
00039 #define mm_is_real(typecode)            ((typecode)[2]=='R')
00040 #define mm_is_pattern(typecode) ((typecode)[2]=='P')
00041 #define mm_is_integer(typecode) ((typecode)[2]=='I')
00042 
00043 #define mm_is_symmetric(typecode)((typecode)[3]=='S')
00044 #define mm_is_general(typecode) ((typecode)[3]=='G')
00045 #define mm_is_skew(typecode)    ((typecode)[3]=='K')
00046 #define mm_is_hermitian(typecode)((typecode)[3]=='H')
00047 
00048 int mm_is_valid(MM_typecode matcode);           /* too complex for a macro */
00049 
00050 
00051 /********************* MM_typecode modify fucntions ***************************/
00052 
00053 #define mm_set_matrix(typecode) ((*typecode)[0]='M')
00054 #define mm_set_coordinate(typecode)     ((*typecode)[1]='C')
00055 #define mm_set_array(typecode)  ((*typecode)[1]='A')
00056 #define mm_set_dense(typecode)  mm_set_array(typecode)
00057 #define mm_set_sparse(typecode) mm_set_coordinate(typecode)
00058 
00059 #define mm_set_complex(typecode)((*typecode)[2]='C')
00060 #define mm_set_real(typecode)   ((*typecode)[2]='R')
00061 #define mm_set_pattern(typecode)((*typecode)[2]='P')
00062 #define mm_set_integer(typecode)((*typecode)[2]='I')
00063 
00064 
00065 #define mm_set_symmetric(typecode)((*typecode)[3]='S')
00066 #define mm_set_general(typecode)((*typecode)[3]='G')
00067 #define mm_set_skew(typecode)   ((*typecode)[3]='K')
00068 #define mm_set_hermitian(typecode)((*typecode)[3]='H')
00069 
00070 #define mm_clear_typecode(typecode) ((*typecode)[0]=(*typecode)[1]= \
00071                                                                         (*typecode)[2]=' ',(*typecode)[3]='G')
00072 
00073 #define mm_initialize_typecode(typecode) mm_clear_typecode(typecode)
00074 
00075 
00076 /********************* Matrix Market error codes ***************************/
00077 
00078 
00079 #define MM_COULD_NOT_READ_FILE  11
00080 #define MM_PREMATURE_EOF                12
00081 #define MM_NOT_MTX                              13
00082 #define MM_NO_HEADER                    14
00083 #define MM_UNSUPPORTED_TYPE             15
00084 #define MM_LINE_TOO_LONG                16
00085 #define MM_COULD_NOT_WRITE_FILE 17
00086 
00087 
00088 /******************** Matrix Market internal definitions ********************
00089 
00090    MM_matrix_typecode: 4-character sequence
00091 
00092                                     ojbect              sparse/         data        storage 
00093                                                                 dense           type        scheme
00094 
00095    string position:      [0]        [1]                 [2]         [3]
00096 
00097    Matrix typecode:  M(atrix)  C(oord)          R(eal)          G(eneral)
00098                                                         A(array)        C(omplex)   H(ermitian)
00099                                                                                         P(attern)   S(ymmetric)
00100                                                                                 I(nteger)       K(kew)
00101 
00102  ***********************************************************************/
00103 
00104 #define MM_MTX_STR              "matrix"
00105 #define MM_ARRAY_STR    "array"
00106 #define MM_DENSE_STR    "array"
00107 #define MM_COORDINATE_STR "coordinate" 
00108 #define MM_SPARSE_STR   "coordinate"
00109 #define MM_COMPLEX_STR  "complex"
00110 #define MM_REAL_STR             "real"
00111 #define MM_INT_STR              "integer"
00112 #define MM_GENERAL_STR  "general"
00113 #define MM_SYMM_STR             "symmetric"
00114 #define MM_HERM_STR             "hermitian"
00115 #define MM_SKEW_STR             "skew-symmetric"
00116 #define MM_PATTERN_STR  "pattern"
00117 
00118 
00119 /*  high level routines */
00120 
00121 int mm_write_mtx_crd(char fname[], int M, int N, int nz, int I[], int J[],
00122                  double val[], MM_typecode matcode);
00123 int mm_read_mtx_crd_data(FILE *f, int M, int N, int nz, int I[], int J[],
00124                 double val[], MM_typecode matcode);
00125 int mm_read_mtx_crd_entry(FILE *f, int *I, int *J, double *real, double *img,
00126                         MM_typecode matcode);
00127 
00128 int mm_read_unsymmetric_sparse(const char *fname, int *M_, int *N_, int *nz_,
00129                 double **val_, int **I_, int **J_);
00130 
00131 
00132 
00133 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines