17#define _maybe_unused __attribute__((unused))
21 double **val_,
int **I_,
int **J_)
30 if ((f = fopen(fname,
"r")) == NULL)
36 printf(
"mm_read_unsymetric: Could not process Matrix Market banner ");
37 printf(
" in file [%s]\n", fname);
46 fprintf(stderr,
"Sorry, this application does not support ");
47 fprintf(stderr,
"Market Market type: [%s]\n",
56 fprintf(stderr,
"read_unsymmetric_sparse(): could not parse matrix size.\n");
66 I = (
int *) malloc(nz *
sizeof(
int));
67 J = (
int *) malloc(nz *
sizeof(
int));
68 val = (
double *) malloc(nz *
sizeof(
double));
80 int res = fscanf(f,
"%d %d %lg\n", &I[i], &J[i], &val[i]);
81 if ((res!=EOF) && (res==3)){
85 fprintf(stderr,
"error reading file %s at data line %d\n",fname,i);
121 if (sscanf(line,
"%s %s %s %s %s", banner, mtx, crd, data_type,
122 storage_scheme) != 5)
125 for (
p=mtx; *
p!=
'\0'; *
p=tolower(*
p),
p++);
126 for (
p=crd; *
p!=
'\0'; *
p=tolower(*
p),
p++);
127 for (
p=data_type; *
p!=
'\0'; *
p=tolower(*
p),
p++);
128 for (
p=storage_scheme; *
p!=
'\0'; *
p=tolower(*
p),
p++);
192 if (fprintf(f,
"%d %d %d\n", M, N, nz) != 3)
211 }
while (line[0] ==
'%');
214 if (sscanf(line,
"%d %d %d", M, N, nz) == 3)
220 num_items_read = fscanf(f,
"%d %d %d", M, N, nz);
223 while (num_items_read != 3);
241 }
while (line[0] ==
'%');
244 if (sscanf(line,
"%d %d", M, N) == 2)
250 num_items_read = fscanf(f,
"%d %d", M, N);
253 while (num_items_read != 2);
260 if (fprintf(f,
"%d %d\n", M, N) != 2)
281 if (fscanf(f,
"%d %d %lg %lg", &I[i], &J[i], &val[2*i], &val[2*i+1])
288 if (fscanf(f,
"%d %d %lg\n", &I[i], &J[i], &val[i])
297 if (fscanf(f,
"%d %d", &I[i], &J[i])
312 if (fscanf(f,
"%d %d %lg %lg", I, J, real, imag)
317 if (fscanf(f,
"%d %d %lg\n", I, J, real)
348 if (strcmp(fname,
"stdin") == 0) f=stdin;
350 if ((f = fopen(fname,
"r")) == NULL)
365 *I = (
int *) malloc(*nz *
sizeof(
int));
366 *J = (
int *) malloc(*nz *
sizeof(
int));
371 *val = (
double *) malloc(*nz * 2 *
sizeof(
double));
374 if (ret_code != 0)
return ret_code;
378 *val = (
double *) malloc(*nz *
sizeof(
double));
381 if (ret_code != 0)
return ret_code;
388 if (ret_code != 0)
return ret_code;
391 if (f != stdin) fclose(f);
414 if (strcmp(fname,
"stdout") == 0)
417 if ((f = fopen(fname,
"w")) == NULL)
425 fprintf(f,
"%d %d %d\n", M, N, nz);
430 fprintf(f,
"%d %d\n", I[i], J[i]);
434 fprintf(f,
"%d %d %20.16g\n", I[i], J[i], val[i]);
438 fprintf(f,
"%d %d %20.16g %20.16g\n", I[i], J[i], val[2*i],
442 if (f != stdout) fclose(f);
446 if (f !=stdout) fclose(f);
460 char *s2 = (
char *) malloc((len+1)*
sizeof(char));
461 return strcpy(s2, s);
517 sprintf(buffer,
"%s %s %s %s", types[0], types[1], types[2], types[3]);
int mm_write_banner(FILE *f, MM_typecode matcode)
Write the Matrix Market banner to a file.
int mm_read_mtx_crd(char *fname, int *M, int *N, int *nz, int **I, int **J, double **val, MM_typecode *matcode)
int mm_write_mtx_array_size(FILE *f, int M, int N)
Write dimensions for an array (dense) matrix.
char * mm_typecode_to_str(MM_typecode matcode)
Convert a Matrix Market typecode to a human-readable string.
int mm_write_mtx_crd(char fname[], int M, int N, int nz, int I[], int J[], double val[], MM_typecode matcode)
Write a coordinate matrix to a file.
int mm_read_mtx_crd_data(FILE *f, _maybe_unused int M, _maybe_unused int N, int nz, int I[], int J[], double val[], MM_typecode matcode)
int mm_read_mtx_array_size(FILE *f, int *M, int *N)
Read dimensions for an array (dense) matrix.
int mm_read_unsymmetric_sparse(const char *fname, int *M_, int *N_, int *nz_, double **val_, int **I_, int **J_)
High-level routine to read an unsymmetric sparse matrix in coordinate format.
int mm_read_mtx_crd_entry(FILE *f, int *I, int *J, double *real, double *imag, MM_typecode matcode)
Read a single coordinate entry from a file.
int mm_is_valid(MM_typecode matcode)
char * mm_strdup(const char *s)
int mm_read_mtx_crd_size(FILE *f, int *M, int *N, int *nz)
Read dimensions and number of non-zero entries for a coordinate matrix.
int mm_write_mtx_crd_size(FILE *f, int M, int N, int nz)
Write dimensions and number of non-zero entries for a coordinate matrix.
int mm_read_banner(FILE *f, MM_typecode *matcode)
Read the Matrix Market banner from a file.
#define mm_is_dense(typecode)
#define mm_is_complex(typecode)
#define mm_set_complex(typecode)
#define mm_set_hermitian(typecode)
#define MM_COULD_NOT_READ_FILE
#define mm_set_general(typecode)
#define MM_MAX_LINE_LENGTH
#define mm_set_skew(typecode)
#define mm_set_sparse(typecode)
#define mm_is_matrix(typecode)
#define mm_is_hermitian(typecode)
#define mm_clear_typecode(typecode)
#define MM_MAX_TOKEN_LENGTH
#define mm_set_symmetric(typecode)
#define mm_is_real(typecode)
#define mm_is_skew(typecode)
#define MM_UNSUPPORTED_TYPE
#define MM_COULD_NOT_WRITE_FILE
#define mm_set_integer(typecode)
#define mm_is_pattern(typecode)
#define mm_is_general(typecode)
#define mm_set_matrix(typecode)
#define mm_set_dense(typecode)
#define mm_set_pattern(typecode)
#define mm_is_integer(typecode)
#define mm_is_symmetric(typecode)
#define mm_is_sparse(typecode)
#define mm_set_real(typecode)
#define MatrixMarketBanner