~logan/ubuntu/trusty/suitesparse/4.2.1-3ubuntu1

« back to all changes in this revision

Viewing changes to RBio/RBraw_mex_64.f

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Prud'homme
  • Date: 2007-05-29 09:36:29 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070529093629-zowquo0b7slkk6nc
Tags: 3.0.0-2
* suitesparse builds properly twice in a row
* Bug fix: "suitesparse - FTBFS: Broken build depens: libgfortran1-dev",
  thanks to Bastian Blank (Closes: #426349).
* Bug fix: "suitesparse_3.0.0-1: FTBFS: build-depends on
  libgfortran1-dev", thanks to Steve Langasek (Closes: #426354).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
c=======================================================================
 
2
c=== RBio/RBraw_mex_64 =================================================
 
3
c=======================================================================
 
4
 
 
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
 
8
 
 
9
 
 
10
c-----------------------------------------------------------------------
 
11
c RBraw mexFunction: read the raw contents of a Rutherford/Boeing file
 
12
c-----------------------------------------------------------------------
 
13
c
 
14
c   [mtype Ap Ai Ax title key nrow] = RBraw (filename)
 
15
c
 
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
 
22
c       value Ax(2*k).
 
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
 
26
c
 
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.
 
32
c
 
33
c Example:
 
34
c
 
35
c   load west0479
 
36
c   RBwrite ('mywest', west0479, [ ], 'My west0479 file', 'west0479') ;
 
37
c   [mtype Ap Ai Ax title key nrow] = RBraw ('mywest') ;
 
38
c
 
39
c See also RBfix, RBread, RBreade.
 
40
c-----------------------------------------------------------------------
 
41
 
 
42
        subroutine mexfunction (nargout, pargout, nargin, pargin)
 
43
        integer*8
 
44
     $      pargout (*), pargin (*)
 
45
        integer*4 nargout, nargin
 
46
 
 
47
c       ----------------------------------------------------------------
 
48
c       MATLAB functions
 
49
c       ----------------------------------------------------------------
 
50
 
 
51
        integer*4 mxIsChar, mxClassIDFromClassName
 
52
 
 
53
        integer*8
 
54
     $      mxGetString, mxCreateString, mxCreateDoubleScalar,
 
55
     $      mxCreateNumericMatrix, mxGetData
 
56
 
 
57
c       ----------------------------------------------------------------
 
58
c       local variables
 
59
c       ----------------------------------------------------------------
 
60
 
 
61
        integer*8
 
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
 
66
        double precision x
 
67
 
 
68
c       ----------------------------------------------------------------
 
69
c       check inputs
 
70
c       ----------------------------------------------------------------
 
71
 
 
72
        if (nargin .ne. 1 .or. nargout .gt. 7 .or.
 
73
     $      mxIsChar (pargin (1)) .ne. 1) then
 
74
            call mexErrMsgTxt
 
75
     $    ('Usage: [mtype Ap Ai Ax title key nrow] = RBraw (filename)')
 
76
        endif
 
77
 
 
78
c       ----------------------------------------------------------------
 
79
c       get filename and open file
 
80
c       ----------------------------------------------------------------
 
81
 
 
82
        if (mxGetString (pargin (1), filename, 1024) .ne. 0) then
 
83
            call mexErrMsgTxt ('filename too long')
 
84
        endif
 
85
        close (unit = 7)
 
86
        open (unit = 7, file = filename, status = 'OLD', err = 998)
 
87
 
 
88
c       ----------------------------------------------------------------
 
89
c       read the header and determine the matrix type
 
90
c       ----------------------------------------------------------------
 
91
 
 
92
        call RBheader (title, key, mtype, nrow, ncol, nnz,
 
93
     $      ptrfmt, indfmt, valfmt,
 
94
     $      mkind, cmplex, skind, nelnz, info)
 
95
        call RBerr (info)
 
96
 
 
97
c       ----------------------------------------------------------------
 
98
c       return the matrix type to MATLAB
 
99
c       ----------------------------------------------------------------
 
100
 
 
101
        pargout (1) = mxCreateString (mtype)
 
102
 
 
103
c       ----------------------------------------------------------------
 
104
c       read in the column pointers
 
105
c       ----------------------------------------------------------------
 
106
 
 
107
        iclass = mxClassIDFromClassName ('int64')
 
108
        one = 1
 
109
        zero = 0
 
110
        wcmplex = 0
 
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)
 
116
            call RBerr (info)
 
117
        endif
 
118
 
 
119
c       ----------------------------------------------------------------
 
120
c       read in the row indices
 
121
c       ----------------------------------------------------------------
 
122
 
 
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
 
129
                info = -93
 
130
            endif
 
131
            call RBerr (info)
 
132
        endif
 
133
 
 
134
c       ----------------------------------------------------------------
 
135
c       read in the numerical values
 
136
c       ----------------------------------------------------------------
 
137
 
 
138
        if (nelnz .eq. 0) then
 
139
            k = nnz
 
140
        else
 
141
            k = nelnz
 
142
        endif
 
143
 
 
144
        if (nargout .ge. 4) then
 
145
 
 
146
            if (mkind .eq. 1) then
 
147
 
 
148
c               pattern-only: create an empty numerical array
 
149
                pargout (4) = mxCreateNumericMatrix (zero, zero,
 
150
     $              mxClassIDFromClassName ('double'), wcmplex)
 
151
 
 
152
            elseif (mkind .eq. 3) then
 
153
 
 
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)
 
159
                call RBerr (info)
 
160
 
 
161
            else
 
162
 
 
163
c               read in the numerical values (real or complex)
 
164
                if (cmplex .eq. 1) then
 
165
                    k = 2*k
 
166
                endif
 
167
                pargout (4) = mxCreateNumericMatrix (k, one,
 
168
     $              mxClassIDFromClassName ('double'), wcmplex)
 
169
                call RBxread (valfmt, k,
 
170
     $              %val(mxGetData (pargout (4))), info)
 
171
                call RBerr (info)
 
172
            endif
 
173
 
 
174
        endif
 
175
 
 
176
c       ----------------------------------------------------------------
 
177
c       return the title
 
178
c       ----------------------------------------------------------------
 
179
 
 
180
        if (nargout .ge. 5) then
 
181
            pargout (5) = mxCreateString (title)
 
182
        endif
 
183
 
 
184
c       ----------------------------------------------------------------
 
185
c       return the key
 
186
c       ----------------------------------------------------------------
 
187
 
 
188
        if (nargout .ge. 6) then
 
189
            pargout (6) = mxCreateString (key)
 
190
        endif
 
191
 
 
192
c       ----------------------------------------------------------------
 
193
c       return the number of rows
 
194
c       ----------------------------------------------------------------
 
195
 
 
196
        if (nargout .ge. 7) then
 
197
            x = nrow
 
198
            pargout (7) = mxCreateDoubleScalar (x)
 
199
        endif
 
200
 
 
201
c       ----------------------------------------------------------------
 
202
c       close file
 
203
c       ----------------------------------------------------------------
 
204
 
 
205
        close (unit = 7)
 
206
        return
 
207
 
 
208
c       ----------------------------------------------------------------
 
209
c       error return
 
210
c       ----------------------------------------------------------------
 
211
 
 
212
998     call mexErrMsgTxt ('error opening file')
 
213
        end
 
214