User`s manual
3 Creating Fortran MEX-Files
3-30
C Get the size and pointers to input data.
m = mxGetM(prhs(1))
n = mxGetN(prhs(1))
pr = mxGetPr(prhs(1))
C Allocate space.
C NOTE: Assume at most 20% of the data is sparse.
nzmax = dble(m*n) *.20 + .5
C NOTE: The maximum number of non-zero elements cannot be less
C than the number of columns in the matrix.
if (n .gt. nzmax) then
nzmax = n
endif
plhs(1) = mxCreateSparse(m,n,nzmax,0)
sr = mxGetPr(plhs(1))
irs = mxGetIr(plhs(1))
jcs = mxGetJc(plhs(1))
C Load the sparse data.
if (loadsparse(%val(pr),%val(sr),%val(irs),%val(jcs),
+m,n,nzmax) .eq. 1) then
call mexPrintf('Truncating output, input is > 20%% sparse')
endif
return
end
This is the subroutine that fulltosparse calls to fill the mxArray with the
sparse data.
C $Revision: 1.4 $
C===============================================================
C
C loadsparse.f
C This is the subfunction called by fulltosparse that fills the
C mxArray with the sparse data. Your version of
C loadsparse can operate however you would like it to on the
C data.