28 mwpointer plhs(*), prhs(*)
36 mwpointer mxcreatestring
37 mwpointer mxgetstring, getstring_stat
43 mwpointer mxgetpr, mxgetpi
44 mwpointer mxcreatedoublematrix
45 mwpointer mxgetm, mxgetn
51 character(len=100) :: filename
52 character(len=7) :: file_status
57 mwpointer mrows, ncols
63 integer*8,
allocatable :: ia_int8(:), ja_int8(:)
64 integer*4,
allocatable :: ia(:), ja(:)
65 complex*16,
allocatable :: a(:)
80 call mexerrmsgidandtxt (
'MATLAB:export_real_sparse:nInput',
81 +
'Two inputs required.')
82 elseif(nlhs .gt. 0)
then 83 call mexerrmsgidandtxt (
'MATLAB:export_real_sparse:nOutput',
84 +
'Too many output arguments.')
90 if ((mxisdouble(prhs(1)) .eq. 0))
then 91 call mexerrmsgidandtxt (
'MATLAB:export_real_sparse:NonDouble',
92 +
'Input must be a double.')
96 if ((mxiscomplex(prhs(1)) .ne. 1) )
then 97 call mexerrmsgidandtxt (
'MATLAB:convec:NonComplex',
98 +
'Inputs must be complex.')
102 if(mxischar(prhs(2)) .ne. 1)
then 103 call mexerrmsgidandtxt (
'MATLAB:export_real_sparse:NonString',
104 +
'Input filename must be a string.')
108 mrows = mxgetm(prhs(2))
109 ncols = mxgetn(prhs(2))
112 strlen = int(mrows*ncols, 4)
113 if (strlen .gt. len(filename))
then 114 call mexerrmsgidandtxt (
'MATLAB:export_real_sparse:NonDouble',
115 +
'input filename is greater than max str size.')
120 + mxgetstring(prhs(2), filename, int(len(filename), 8))
123 write(line,*)
'Input file name: ',filename, new_line(
'A')
124 tmp = mexprintf(line)
129 nonzerosa = mxgetnzmax(prhs(1))
130 sizeam = mxgetm(prhs(1))
131 sizean = mxgetn(prhs(1))
135 allocate(ia_int8(sizean+1))
136 allocate(ja_int8(nonzerosa))
137 allocate(ia(sizean+1))
138 allocate(ja(nonzerosa))
139 allocate(a(nonzerosa))
142 if (.not. (
allocated(ia_int8) .and.
143 +
allocated(ja_int8) .and.
144 +
allocated(ia) .and.
145 +
allocated(ja) .and.
146 +
allocated(a) ))
then 147 call mexerrmsgidandtxt (
'MATLAB:dgetSchur:BadAllocation',
148 +
'The allocation of variables was unsuccesfull.')
152 call mxcopyptrtointeger8(
153 + mxgetjc(prhs(1)), ia_int8, sizean+1 )
154 call mxcopyptrtointeger8(
155 + mxgetir(prhs(1)), ja_int8, nonzerosa )
156 call mxcopyptrtocomplex16( mxgetpr(prhs(1)), mxgetpi(prhs(1)),
159 ia = int(ia_int8, 4) + 1
160 ja = int(ja_int8, 4) + 1
167 inquire(file=trim(filename),exist=fileexist)
168 if(.not.fileexist)
then 171 file_status =
'REPLACE' 173 OPEN(unit=6, file=trim(filename),status=file_status
174 + ,form=
'UNFORMATTED')
176 WRITE(6) int(sizean, 4)
177 WRITE(6) int(nonzerosa, 4)
subroutine mexfunction(nlhs, plhs, nrhs, prhs)