\HeaderA{externalFormats}{Read and write external matrix formats}{externalFormats}
\aliasA{readHB}{externalFormats}{readHB}
\aliasA{readMM}{externalFormats}{readMM}
\aliasA{writeMM}{externalFormats}{writeMM}
\aliasA{writeMM,CsparseMatrix-method}{externalFormats}{writeMM,CsparseMatrix.Rdash.method}
\aliasA{writeMM,TsparseMatrix-method}{externalFormats}{writeMM,TsparseMatrix.Rdash.method}
\keyword{IO}{externalFormats}
\keyword{array}{externalFormats}
\keyword{algebra}{externalFormats}
\begin{Description}\relax
Read matrices stored in the Harwell-Boeing or MatrixMarket formats
or write sparseMatrix objects to one of these formats.
\end{Description}
\begin{Usage}
\begin{verbatim}
readHB(file)
readMM(file)
writeMM(obj, file, ...)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{obj}] a real sparse matrix
\item[\code{file}] for \code{writeMM} - the name of the file to be written.
For \code{readHB} and \code{readMM} the name of the file to read, as
a character scalar.  The names of files storing matrices in the
Harwell-Boeing format usually end in \code{".rua"} or \code{".rsa"}.
Those storing matrices in the MatrixMarket format usually end in
\code{".mtx"}.

Alternatively, \code{readHB} and \code{readMM} accept connection objects.
\item[\code{...}] optional additional arguments. Currently none are used in
any methods.
\end{ldescription}
\end{Arguments}
\begin{Value}
The \code{readHB} and \code{readMM} functions return an object that
inherits from the \code{"\LinkA{Matrix}{Matrix.Rdash.class}"} class.  Methods for the
\code{writeMM} generic functions usually return
\code{\LinkA{NULL}{NULL}} and, as a side effect, the matrix \code{obj} is
written to \code{file} in the MatrixMarket format (writeMM).
\end{Value}
\begin{Note}\relax
The Harwell-Boeing format is older and less flexible than the
MatrixMarket format.  The function \code{writeHB} was deprecated and
has now been removed.  Please use \code{writeMM} instead.
\end{Note}
\begin{References}\relax
\url{http://math.nist.gov/MatrixMarket}

\url{http://www.cise.ufl.edu/research/sparse/matrices}
\end{References}
\begin{Examples}
\begin{ExampleCode}
str(pores <- readMM(system.file("external/pores_1.mtx",
                                package = "Matrix")))
str(utm <- readHB(system.file("external/utm300.rua",
                               package = "Matrix")))
str(lundA <- readMM(system.file("external/lund_a.mtx",
                                package = "Matrix")))
str(lundA <- readHB(system.file("external/lund_a.rsa",
                                package = "Matrix")))
## Not run: 
## NOTE: The following examples take quite some time
## ----  even on a fast internet connection:
if(FALSE) # the URL has been corrected, but we need an un-tar step!
str(sm <-
 readHB(gzcon(url("http://www.cise.ufl.edu/research/sparse/RB/Boeing/msc00726.tar.gz"))))

str(jgl009 <-
 readMM(gzcon(url("ftp://math.nist.gov/pub/MatrixMarket2/Harwell-Boeing/counterx/jgl009.mtx.gz"))))
## End(Not run)
data(KNex)
writeMM(KNex$mm, "mmMM.mtx")
\end{ExampleCode}
\end{Examples}

