1
c=======================================================================
2
c=== RBio/RBraw_mex_64 =================================================
3
c=======================================================================
5
c RBio: a MATLAB toolbox for reading and writing sparse matrices in
6
c Rutherford/Boeing format.
7
c Copyright (c) 2007, Timothy A. Davis, Univ. of Florida
10
c-----------------------------------------------------------------------
11
c RBraw mexFunction: read the raw contents of a Rutherford/Boeing file
12
c-----------------------------------------------------------------------
14
c [mtype Ap Ai Ax title key nrow] = RBraw (filename)
16
c mtype: Rutherford/Boeing matrix type (psa, rua, rsa, rse, ...)
17
c Ap: column pointers (1-based)
18
c Ai: row indices (1-based)
19
c Ax: numerical values (real, complex, or integer). Empty for p*a
20
c matrices. A complex matrix is read in as a single double array
21
c Ax, where the kth entry has real value Ax(2*k-1) and imaginary
23
c title: a string containing the title from the first line of the file
24
c key: a string containing the 8-char key, from 1st line of the file
25
c nrow: number of rows in the matrix
27
c This function works for both assembled and unassembled (finite-
28
c element) matrices. It is also useful for checking the contents of a
29
c Rutherford/Boeing file in detail, in case the file has invalid column
30
c pointers, unsorted columns, duplicate entries, entries in the upper
31
c triangular part of the file for a symmetric matrix, etc.
36
c RBwrite ('mywest', west0479, [ ], 'My west0479 file', 'west0479') ;
37
c [mtype Ap Ai Ax title key nrow] = RBraw ('mywest') ;
39
c See also RBfix, RBread, RBreade.
40
c-----------------------------------------------------------------------
42
subroutine mexfunction (nargout, pargout, nargin, pargin)
44
$ pargout (*), pargin (*)
45
integer*4 nargout, nargin
47
c ----------------------------------------------------------------
49
c ----------------------------------------------------------------
51
integer*4 mxIsChar, mxClassIDFromClassName
54
$ mxGetString, mxCreateString, mxCreateDoubleScalar,
55
$ mxCreateNumericMatrix, mxGetData
57
c ----------------------------------------------------------------
59
c ----------------------------------------------------------------
62
$ nrow, ncol, nnz, mkind, info, skind, k, nelnz, one, zero
63
integer*4 iclass, cmplex, wcmplex
64
character title*72, key*8, mtype*3, ptrfmt*16, indfmt*16,
65
$ valfmt*20, filename*1024
68
c ----------------------------------------------------------------
70
c ----------------------------------------------------------------
72
if (nargin .ne. 1 .or. nargout .gt. 7 .or.
73
$ mxIsChar (pargin (1)) .ne. 1) then
75
$ ('Usage: [mtype Ap Ai Ax title key nrow] = RBraw (filename)')
78
c ----------------------------------------------------------------
79
c get filename and open file
80
c ----------------------------------------------------------------
82
if (mxGetString (pargin (1), filename, 1024) .ne. 0) then
83
call mexErrMsgTxt ('filename too long')
86
open (unit = 7, file = filename, status = 'OLD', err = 998)
88
c ----------------------------------------------------------------
89
c read the header and determine the matrix type
90
c ----------------------------------------------------------------
92
call RBheader (title, key, mtype, nrow, ncol, nnz,
93
$ ptrfmt, indfmt, valfmt,
94
$ mkind, cmplex, skind, nelnz, info)
97
c ----------------------------------------------------------------
98
c return the matrix type to MATLAB
99
c ----------------------------------------------------------------
101
pargout (1) = mxCreateString (mtype)
103
c ----------------------------------------------------------------
104
c read in the column pointers
105
c ----------------------------------------------------------------
107
iclass = mxClassIDFromClassName ('int64')
111
if (nargout .ge. 2) then
112
pargout (2) = mxCreateNumericMatrix
113
$ (ncol+1, one, iclass, wcmplex)
114
call RBiread (ptrfmt, ncol+1,
115
$ %val(mxGetData (pargout (2))), info)
119
c ----------------------------------------------------------------
120
c read in the row indices
121
c ----------------------------------------------------------------
123
if (nargout .ge. 3) then
124
pargout (3) = mxCreateNumericMatrix
125
$ (nnz, one, iclass, wcmplex)
126
call RBiread (indfmt, nnz,
127
$ %val(mxGetData (pargout (3))), info)
128
if (info .lt. 0) then
134
c ----------------------------------------------------------------
135
c read in the numerical values
136
c ----------------------------------------------------------------
138
if (nelnz .eq. 0) then
144
if (nargout .ge. 4) then
146
if (mkind .eq. 1) then
148
c pattern-only: create an empty numerical array
149
pargout (4) = mxCreateNumericMatrix (zero, zero,
150
$ mxClassIDFromClassName ('double'), wcmplex)
152
elseif (mkind .eq. 3) then
154
c read in the numerical values (integer)
155
pargout (4) = mxCreateNumericMatrix
156
$ (k, one, iclass, wcmplex)
157
call RBiread (valfmt, k,
158
$ %val(mxGetData (pargout (4))), info)
163
c read in the numerical values (real or complex)
164
if (cmplex .eq. 1) then
167
pargout (4) = mxCreateNumericMatrix (k, one,
168
$ mxClassIDFromClassName ('double'), wcmplex)
169
call RBxread (valfmt, k,
170
$ %val(mxGetData (pargout (4))), info)
176
c ----------------------------------------------------------------
178
c ----------------------------------------------------------------
180
if (nargout .ge. 5) then
181
pargout (5) = mxCreateString (title)
184
c ----------------------------------------------------------------
186
c ----------------------------------------------------------------
188
if (nargout .ge. 6) then
189
pargout (6) = mxCreateString (key)
192
c ----------------------------------------------------------------
193
c return the number of rows
194
c ----------------------------------------------------------------
196
if (nargout .ge. 7) then
198
pargout (7) = mxCreateDoubleScalar (x)
201
c ----------------------------------------------------------------
203
c ----------------------------------------------------------------
208
c ----------------------------------------------------------------
210
c ----------------------------------------------------------------
212
998 call mexErrMsgTxt ('error opening file')