Fast Auxiliary Space Preconditioning  1.8.4 Feb/15/2016
io.c File Reference

Matrix/vector input/output subroutines. More...

#include "fasp.h"
#include "fasp_functs.h"
#include "hb_io.h"

Go to the source code of this file.

Functions

void fasp_dcsrvec1_read (const char *filename, dCSRmat *A, dvector *b)
 Read A and b from a SINGLE disk file. More...
 
void fasp_dcsrvec2_read (const char *filemat, const char *filerhs, dCSRmat *A, dvector *b)
 Read A and b from two disk files. More...
 
void fasp_dcsr_read (const char *filename, dCSRmat *A)
 Read A from matrix disk file in IJ format. More...
 
void fasp_dcoo_read (const char *filename, dCSRmat *A)
 Read A from matrix disk file in IJ format – indices starting from 0. More...
 
void fasp_dcoo1_read (const char *filename, dCOOmat *A)
 Read A from matrix disk file in IJ format – indices starting from 1. More...
 
void fasp_dcoo_shift_read (const char *filename, dCSRmat *A)
 Read A from matrix disk file in IJ format – indices starting from 0. More...
 
void fasp_dmtx_read (const char *filename, dCSRmat *A)
 Read A from matrix disk file in MatrixMarket general format. More...
 
void fasp_dmtxsym_read (const char *filename, dCSRmat *A)
 Read A from matrix disk file in MatrixMarket sym format. More...
 
void fasp_dstr_read (const char *filename, dSTRmat *A)
 Read A from a disk file in dSTRmat format. More...
 
void fasp_dbsr_read (const char *filename, dBSRmat *A)
 Read A from a disk file in dBSRmat format. More...
 
void fasp_dvecind_read (const char *filename, dvector *b)
 Read b from matrix disk file. More...
 
void fasp_dvec_read (const char *filename, dvector *b)
 Read b from a disk file in array format. More...
 
void fasp_ivecind_read (const char *filename, ivector *b)
 Read b from matrix disk file. More...
 
void fasp_ivec_read (const char *filename, ivector *b)
 Read b from a disk file in array format. More...
 
void fasp_dcsrvec1_write (const char *filename, dCSRmat *A, dvector *b)
 Write A and b to a SINGLE disk file. More...
 
void fasp_dcsrvec2_write (const char *filemat, const char *filerhs, dCSRmat *A, dvector *b)
 Write A and b to two disk files. More...
 
void fasp_dcoo_write (const char *filename, dCSRmat *A)
 Write a matrix to disk file in IJ format (coordinate format) More...
 
void fasp_dstr_write (const char *filename, dSTRmat *A)
 Write a dSTRmat to a disk file. More...
 
void fasp_dbsr_write (const char *filename, dBSRmat *A)
 Write a dBSRmat to a disk file. More...
 
void fasp_dvec_write (const char *filename, dvector *vec)
 Write a dvector to disk file. More...
 
void fasp_dvecind_write (const char *filename, dvector *vec)
 Write a dvector to disk file in coordinate format. More...
 
void fasp_ivec_write (const char *filename, ivector *vec)
 Write a ivector to disk file in coordinate format. More...
 
void fasp_dvec_print (INT n, dvector *u)
 Print first n entries of a vector of REAL type. More...
 
void fasp_ivec_print (INT n, ivector *u)
 Print first n entries of a vector of INT type. More...
 
void fasp_dcsr_print (dCSRmat *A)
 Print out a dCSRmat matrix in coordinate format. More...
 
void fasp_dcoo_print (dCOOmat *A)
 Print out a dCOOmat matrix in coordinate format. More...
 
void fasp_dbsr_print (dBSRmat *A)
 Print out a dBSRmat matrix in coordinate format. More...
 
void fasp_dbsr_write_coo (const char *filename, const dBSRmat *A)
 Print out a dBSRmat matrix in coordinate format for matlab spy. More...
 
void fasp_dcsr_write_coo (const char *filename, const dCSRmat *A)
 Print out a dCSRmat matrix in coordinate format for matlab spy. More...
 
void fasp_dstr_print (dSTRmat *A)
 Print out a dSTRmat matrix in coordinate format. More...
 
void fasp_matrix_read (const char *filename, void *A)
 Read matrix from different kinds of formats from both ASCII and binary files. More...
 
void fasp_matrix_read_bin (const char *filename, void *A)
 Read matrix in binary format. More...
 
void fasp_matrix_write (const char *filename, void *A, INT flag)
 write matrix from different kinds of formats from both ASCII and binary files More...
 
void fasp_vector_read (const char *filerhs, void *b)
 Read RHS vector from different kinds of formats from both ASCII and binary files. More...
 
void fasp_vector_write (const char *filerhs, void *b, INT flag)
 write RHS vector from different kinds of formats in both ASCII and binary files More...
 
void fasp_hb_read (const char *input_file, dCSRmat *A, dvector *b)
 Read matrix and right-hans side from a HB format file. More...
 

Variables

INT ilength
 
INT dlength
 

Detailed Description

Matrix/vector input/output subroutines.

Note
Read, write or print a matrix or a vector in various formats.

Definition in file io.c.

Function Documentation

void fasp_dbsr_print ( dBSRmat A)

Print out a dBSRmat matrix in coordinate format.

Parameters
APointer to the dBSRmat matrix A
Author
Ziteng Wang
Date
12/24/2012

Modified by Chunsheng Feng on 11/16/2013

Definition at line 1444 of file io.c.

void fasp_dbsr_read ( const char *  filename,
dBSRmat A 
)

Read A from a disk file in dBSRmat format.

Parameters
filenameFile name for matrix A
APointer to the dBSRmat A
Note
This routine reads a dBSRmat matrix from a disk file in the following format:
File format:
  • ROW, COL, NNZ
  • nb: size of each block
  • storage_manner: storage manner of each block
  • ROW+1: length of IA
  • IA(i), i=0:ROW
  • NNZ: length of JA
  • JA(i), i=0:NNZ-1
  • NNZ*nb*nb: length of val
  • val(i), i=0:NNZ*nb*nb-1
Author
Xiaozhe Hu
Date
10/29/2010

Definition at line 691 of file io.c.

void fasp_dbsr_write ( const char *  filename,
dBSRmat A 
)

Write a dBSRmat to a disk file.

Parameters
filenameFile name for A
APointer to the dBSRmat matrix A
Note
 The routine writes the specified REAL vector in BSR format.
 Refer to the reading subroutine \ref fasp_dbsr_read.
Author
Shiquan Zhang
Date
10/29/2010

Definition at line 1202 of file io.c.

void fasp_dbsr_write_coo ( const char *  filename,
const dBSRmat A 
)

Print out a dBSRmat matrix in coordinate format for matlab spy.

Parameters
filenameName of file to write to
APointer to the dBSRmat matrix A
Author
Chunsheng Feng
Date
11/14/2013

Modified by Chensong Zhang on 06/14/2014: Fix index problem.

Definition at line 1481 of file io.c.

void fasp_dcoo1_read ( const char *  filename,
dCOOmat A 
)

Read A from matrix disk file in IJ format – indices starting from 1.

Parameters
filenameFile name for matrix
APointer to the COO matrix
Note
File format:
  • nrow ncol nnz % number of rows, number of columns, and nnz
  • i j a_ij % i, j a_ij in each line
difference between fasp_dcoo_read and this funciton is this function do not change to CSR format
Author
Xiaozhe Hu
Date
03/24/2013

Definition at line 369 of file io.c.

void fasp_dcoo_print ( dCOOmat A)

Print out a dCOOmat matrix in coordinate format.

Parameters
APointer to the dCOOmat matrix A
Author
Ziteng Wang
Date
12/24/2012

Definition at line 1423 of file io.c.

void fasp_dcoo_read ( const char *  filename,
dCSRmat A 
)

Read A from matrix disk file in IJ format – indices starting from 0.

Parameters
filenameFile name for matrix
APointer to the CSR matrix
Note
File format:
  • nrow ncol nnz % number of rows, number of columns, and nnz
  • i j a_ij % i, j a_ij in each line
After reading, it converts the matrix to dCSRmat format.
Author
Xuehai Huang, Chensong Zhang
Date
03/29/2009

Definition at line 318 of file io.c.

void fasp_dcoo_shift_read ( const char *  filename,
dCSRmat A 
)

Read A from matrix disk file in IJ format – indices starting from 0.

Parameters
filenameFile name for matrix
APointer to the CSR matrix
Note
File format:
  • nrow ncol nnz % number of rows, number of columns, and nnz
  • i j a_ij % i, j a_ij in each line
i and j suppose to start with index 1!!!
After read in, it shifts the index to C fashin and converts the matrix to dCSRmat format.
Author
Xiaozhe Hu
Date
04/01/2014

Definition at line 420 of file io.c.

void fasp_dcoo_write ( const char *  filename,
dCSRmat A 
)

Write a matrix to disk file in IJ format (coordinate format)

Parameters
Apointer to the dCSRmat matrix
filenamechar for vector file name
Note
 The routine writes the specified REAL vector in COO format.
 Refer to the reading subroutine \ref fasp_dcoo_read.
File format:
  • The first line of the file gives the number of rows, the number of columns, and the number of nonzeros.
  • Then gives nonzero values in i j a(i,j) format.
Author
Chensong Zhang
Date
03/29/2009

Definition at line 1102 of file io.c.

void fasp_dcsr_print ( dCSRmat A)

Print out a dCSRmat matrix in coordinate format.

Parameters
APointer to the dCSRmat matrix A
Author
Xuehai Huang
Date
03/29/2009

Definition at line 1401 of file io.c.

void fasp_dcsr_read ( const char *  filename,
dCSRmat A 
)

Read A from matrix disk file in IJ format.

Parameters
*filenamechar for matrix file name
*Apointer to the CSR matrix
Author
Ziteng Wang
Date
12/25/2012

Definition at line 257 of file io.c.

void fasp_dcsr_write_coo ( const char *  filename,
const dCSRmat A 
)

Print out a dCSRmat matrix in coordinate format for matlab spy.

Parameters
filenameName of file to write to
APointer to the dCSRmat matrix A
Author
Chunsheng Feng
Date
11/14/2013

Definition at line 1531 of file io.c.

void fasp_dcsrvec1_read ( const char *  filename,
dCSRmat A,
dvector b 
)

Read A and b from a SINGLE disk file.

Parameters
filenameFile name
APointer to the CSR matrix
bPointer to the dvector
Note
This routine reads a dCSRmat matrix and a dvector vector from a single disk file.
 The difference between this and fasp_dcoovec_read is that this
 routine support non-square matrices.
File format:
  • nrow ncol % number of rows and number of columns
  • ia(j), j=0:nrow % row index
  • ja(j), j=0:nnz-1 % column index
  • a(j), j=0:nnz-1 % entry value
  • n % number of entries
  • b(j), j=0:n-1 % entry value
Author
Xuehai Huang
Date
03/29/2009

Modified by Chensong Zhang on 03/14/2012

Definition at line 86 of file io.c.

void fasp_dcsrvec1_write ( const char *  filename,
dCSRmat A,
dvector b 
)

Write A and b to a SINGLE disk file.

Parameters
filenameFile name
APointer to the CSR matrix
bPointer to the dvector
Note
This routine writes a dCSRmat matrix and a dvector vector to a single disk file.
File format:
  • nrow ncol % number of rows and number of columns
  • ia(j), j=0:nrow % row index
  • ja(j), j=0:nnz-1 % column index
  • a(j), j=0:nnz-1 % entry value
  • n % number of entries
  • b(j), j=0:n-1 % entry value
Author
Feiteng Huang
Date
05/19/2012

Modified by Chensong on 12/26/2012

Definition at line 953 of file io.c.

void fasp_dcsrvec2_read ( const char *  filemat,
const char *  filerhs,
dCSRmat A,
dvector b 
)

Read A and b from two disk files.

Parameters
filematFile name for matrix
filerhsFile name for right-hand side
APointer to the dCSR matrix
bPointer to the dvector
Note
 This routine reads a dCSRmat matrix and a dvector vector from a disk file.
CSR matrix file format:
  • nrow % number of columns (rows)
  • ia(j), j=0:nrow % row index
  • ja(j), j=0:nnz-1 % column index
  • a(j), j=0:nnz-1 % entry value
RHS file format:
  • n % number of entries
  • b(j), j=0:nrow-1 % entry value
Indices start from 1, NOT 0!!!
Author
Zhiyang Zhou
Date
2010/08/06

Modified by Chensong Zhang on 2011/03/01 Modified by Chensong Zhang on 2012/01/05

Definition at line 178 of file io.c.

void fasp_dcsrvec2_write ( const char *  filemat,
const char *  filerhs,
dCSRmat A,
dvector b 
)

Write A and b to two disk files.

Parameters
filematFile name for matrix
filerhsFile name for right-hand side
APointer to the dCSR matrix
bPointer to the dvector
Note
 This routine writes a dCSRmat matrix and a dvector vector to two disk files.
CSR matrix file format:
  • nrow % number of columns (rows)
  • ia(j), j=0:nrow % row index
  • ja(j), j=0:nnz-1 % column index
  • a(j), j=0:nnz-1 % entry value
RHS file format:
  • n % number of entries
  • b(j), j=0:nrow-1 % entry value
Indices start from 1, NOT 0!!!
Author
Feiteng Huang
Date
05/19/2012

Definition at line 1031 of file io.c.

void fasp_dmtx_read ( const char *  filename,
dCSRmat A 
)

Read A from matrix disk file in MatrixMarket general format.

Parameters
filenameFile name for matrix
APointer to the CSR matrix
Note
File format: This routine reads a MatrixMarket general matrix from a mtx file. And it converts the matrix to dCSRmat format. For details of mtx format, please refer to http://math.nist.gov/MatrixMarket/.
Indices start from 1, NOT 0!!!
Author
Chensong Zhang
Date
09/05/2011

Definition at line 472 of file io.c.

void fasp_dmtxsym_read ( const char *  filename,
dCSRmat A 
)

Read A from matrix disk file in MatrixMarket sym format.

Parameters
filenameFile name for matrix
APointer to the CSR matrix
Note
File format: This routine reads a MatrixMarket symmetric matrix from a mtx file. And it converts the matrix to dCSRmat format. For details of mtx format, please refer to http://math.nist.gov/MatrixMarket/.
 Indices start from 1, NOT 0!!!
Author
Chensong Zhang
Date
09/02/2011

Definition at line 534 of file io.c.

void fasp_dstr_print ( dSTRmat A)

Print out a dSTRmat matrix in coordinate format.

Parameters
APointer to the dSTRmat matrix A
Author
Ziteng Wang
Date
12/24/2012

Definition at line 1570 of file io.c.

void fasp_dstr_read ( const char *  filename,
dSTRmat A 
)

Read A from a disk file in dSTRmat format.

Parameters
filenameFile name for the matrix
APointer to the dSTRmat
Note
This routine reads a dSTRmat matrix from a disk file. After done, it converts the matrix to dCSRmat format.
File format:
  • nx, ny, nz
  • nc: number of components
  • nband: number of bands
  • n: size of diagonal, you must have diagonal
  • diag(j), j=0:n-1
  • offset, length: offset and length of off-diag1
  • offdiag(j), j=0:length-1
Author
Xuehai Huang
Date
03/29/2009

Definition at line 611 of file io.c.

void fasp_dstr_write ( const char *  filename,
dSTRmat A 
)

Write a dSTRmat to a disk file.

Parameters
filenameFile name for A
APointer to the dSTRmat matrix A
Note
 The routine writes the specified REAL vector in STR format.
 Refer to the reading subroutine \ref fasp_dstr_read.
Author
Shiquan Zhang
Date
03/29/2010

Definition at line 1142 of file io.c.

void fasp_dvec_print ( INT  n,
dvector u 
)

Print first n entries of a vector of REAL type.

Parameters
nAn interger (if n=0, then print all entries)
uPointer to a dvector
Author
Chensong Zhang
Date
03/29/2009

Definition at line 1362 of file io.c.

void fasp_dvec_read ( const char *  filename,
dvector b 
)

Read b from a disk file in array format.

Parameters
filenameFile name for vector b
bPointer to the dvector b (output)
Note
File Format:
  • nrow
  • val_j, j=0:nrow-1
Author
Chensong Zhang
Date
03/29/2009

Definition at line 810 of file io.c.

void fasp_dvec_write ( const char *  filename,
dvector vec 
)

Write a dvector to disk file.

Parameters
vecPointer to the dvector
filenameFile name
Author
Xuehai Huang
Date
03/29/2009

Definition at line 1257 of file io.c.

void fasp_dvecind_read ( const char *  filename,
dvector b 
)

Read b from matrix disk file.

Parameters
filenameFile name for vector b
bPointer to the dvector b (output)
Note
File Format:
  • nrow
  • ind_j, val_j, j=0:nrow-1
Because the index is given, order is not important!
Author
Chensong Zhang
Date
03/29/2009

Definition at line 760 of file io.c.

void fasp_dvecind_write ( const char *  filename,
dvector vec 
)

Write a dvector to disk file in coordinate format.

Parameters
vecPointer to the dvector
filenameFile name
Note
The routine writes the specified REAL vector in IJ format.
  • The first line of the file is the length of the vector;
  • After that, each line gives index and value of the entries.
Author
Xuehai Huang
Date
03/29/2009

Definition at line 1293 of file io.c.

fasp_hb_read ( const char *  input_file,
dCSRmat A,
dvector b 
)

Read matrix and right-hans side from a HB format file.

Parameters
input_fileFile name of vector file
APointer to the matrix
bPointer to the vector
Note
Modified from the c code hb_io_prb.c by John Burkardt
Author
Xiaoehe Hu
Date
05/30/2014

Definition at line 2061 of file io.c.

void fasp_ivec_print ( INT  n,
ivector u 
)

Print first n entries of a vector of INT type.

Parameters
nAn interger (if n=0, then print all entries)
uPointer to an ivector
Author
Chensong Zhang
Date
03/29/2009

Definition at line 1382 of file io.c.

void fasp_ivec_read ( const char *  filename,
ivector b 
)

Read b from a disk file in array format.

Parameters
filenameFile name for vector b
bPointer to the dvector b (output)
Note
File Format:
  • nrow
  • val_j, j=0:nrow-1
Author
Xuehai Huang
Date
03/29/2009

Definition at line 902 of file io.c.

void fasp_ivec_write ( const char *  filename,
ivector vec 
)

Write a ivector to disk file in coordinate format.

Parameters
vecPointer to the dvector
filenameFile name
Note
The routine writes the specified INT vector in IJ format.
  • The first line of the file is the length of the vector;
  • After that, each line gives index and value of the entries.
Author
Xuehai Huang
Date
03/29/2009

Definition at line 1328 of file io.c.

void fasp_ivecind_read ( const char *  filename,
ivector b 
)

Read b from matrix disk file.

Parameters
filenameFile name for vector b
bPointer to the dvector b (output)
Note
File Format:
  • nrow
  • ind_j, val_j ... j=0:nrow-1
Author
Chensong Zhang
Date
03/29/2009

Definition at line 862 of file io.c.

fasp_matrix_read ( const char *  filemat,
void *  A 
)

Read matrix from different kinds of formats from both ASCII and binary files.

Parameters
filematFile name of matrix file
APointer to the matrix
Note
Flags for matrix file format:
  • fileflag % fileflag = 1: binary, fileflag = 0000: ASCII
  • formatflag % a 3-digit number for internal use, see below
  • matrix % different types of matrix
Meaning of formatflag:
  • matrixflag % first digit of formatflag
    • matrixflag = 1: CSR format
    • matrixflag = 2: BSR format
    • matrixflag = 3: STR format
    • matrixflag = 4: COO format
    • matrixflag = 5: MTX format
    • matrixflag = 6: MTX symmetrical format
  • ilength % third digit of formatflag, length of INT
  • dlength % fourth digit of formatflag, length of REAL
Author
Ziteng Wang
Date
12/24/2012

Modified by Chensong Zhang on 05/01/2013

Definition at line 1604 of file io.c.

void fasp_matrix_read_bin ( const char *  filemat,
void *  A 
)

Read matrix in binary format.

Parameters
filematFile name of matrix file
APointer to the matrix
Author
Xiaozhe Hu
Date
04/14/2013

Modified by Chensong Zhang on 05/01/2013: Use it to read binary files!!!

Definition at line 1709 of file io.c.

fasp_matrix_write ( const char *  filemat,
void *  A,
INT  flag 
)

write matrix from different kinds of formats from both ASCII and binary files

Parameters
filematFile name of matrix file
APointer to the matrix
flagType of file and matrix, a 3-digit number
Note
Meaning of flag:
  • fileflag % fileflag = 1: binary, fileflag = 0: ASCII
  • matrixflag
    • matrixflag = 1: CSR format
    • matrixflag = 2: BSR format
    • matrixflag = 3: STR format
Matrix file format:
  • fileflag % fileflag = 1: binary, fileflag = 0000: ASCII
  • formatflag % a 3-digit number
  • matrixflag % different kinds of matrix judged by formatflag
Author
Ziteng Wang
Date
12/24/2012

Definition at line 1783 of file io.c.

fasp_vector_read ( const char *  filerhs,
void *  b 
)

Read RHS vector from different kinds of formats from both ASCII and binary files.

Parameters
filerhsFile name of vector file
bPointer to the vector
Note
Matrix file format:
  • fileflag % fileflag = 1: binary, fileflag = 0000: ASCII
  • formatflag % a 3-digit number
  • vector % different kinds of vector judged by formatflag
Meaning of formatflag:
  • vectorflag % first digit of formatflag
    • vectorflag = 1: dvec format
    • vectorflag = 2: ivec format
    • vectorflag = 3: dvecind format
    • vectorflag = 4: ivecind format
  • ilength % second digit of formatflag, length of INT
  • dlength % third digit of formatflag, length of REAL
Author
Ziteng Wang
Date
12/24/2012

Definition at line 1876 of file io.c.

fasp_vector_write ( const char *  filerhs,
void *  b,
INT  flag 
)

write RHS vector from different kinds of formats in both ASCII and binary files

Parameters
filerhsFile name of vector file
bPointer to the vector
flagType of file and vector, a 2-digit number
Note
Meaning of the flags
  • fileflag % fileflag = 1: binary, fileflag = 0: ASCII
  • vectorflag
    • vectorflag = 1: dvec format
    • vectorflag = 2: ivec format
    • vectorflag = 3: dvecind format
    • vectorflag = 4: ivecind format
Matrix file format:
  • fileflag % fileflag = 1: binary, fileflag = 0000: ASCII
  • formatflag % a 2-digit number
  • vectorflag % different kinds of vector judged by formatflag
Author
Ziteng Wang
Date
12/24/2012

Modified by Chensong Zhang on 05/02/2013: fix a bug when writing in binary format

Definition at line 1973 of file io.c.

Variable Documentation

INT dlength

Length of REAL in byte

Definition at line 14 of file io.c.

INT ilength

Length of INT in byte

Definition at line 13 of file io.c.