MATLAB: Out of memory using a fortran-compiled mex

memory fortran mex

Hi All,
I compiled a fortran file download from http://oces.us/RNT/ using
>>mex rnt_oa3d_mex.f
and got rnt_oa3d_mex.mexa64 without errors.
Then, I run a matlab function "rnt_oa3d" in which rnt_oa3d_mex.mexa64 will be called, but I got a "out of memory" error:
>>[dataout,error,pmap]=rnt_oa3d(lonin,latin,zrin,tracer,lonout,latout,zrout,a,b,''); Error using rnt_oa3d_mex Out of memory. Type HELP MEMORY for your options.
Error in rnt_oa3d (line 50) [t2,error]=rnt_oa3d_mex(lonr,latr,zr,t1, lon,lat,z,pmap,a,b);
The OS of my computer is CentOS 6 with a 64-bit AMD CPU. The mexfunction in the nt_oa3d_mex.f is shown below.
Can anyone help me out? I have no idea where I can debug where the error is from. Thanks.
Li
subroutine mexfunction(nlhs, plhs, nrhs, prhs)
implicit none
C-----------------------------------------------------------------------
C (integer) Replace integer by integer*8 on the DEC Alpha and the
C SGI 64-bit platforms
C
integer*8 plhs(*), prhs(*)
integer*8 x,y,z,datain,xhat,yhat,zhat
integer*8 pmap,dataout,errout,a,b
integer*8 mxGetPr, mxCreateDoubleMatrix
C-----------------------------------------------------------------------
C
! matlab call:
! [dataout,errout]=oaTest(x,y,data,xhat,yhat);
integer nlhs, nrhs, mxGetM, mxGetN
integer m_in, n_in, size,PtIn,PtOut,PtIns,
c PtZin,PtZout
! get address of input arrays
x = mxGetPr(prhs(1))
y = mxGetPr(prhs(2))
z = mxGetPr(prhs(3))
datain = mxGetPr(prhs(4))
xhat = mxGetPr(prhs(5))
yhat = mxGetPr(prhs(6))
zhat = mxGetPr(prhs(7))
pmap = mxGetPr(prhs(8))
a = mxGetPr(prhs(9))
b = mxGetPr(prhs(10))
! set output matrix according to sizes of Sn (3)
m_in = mxGetM(prhs(4))
n_in = mxGetN(prhs(4))
PtIn = m_in
PtZin= n_in
m_in = mxGetM(prhs(7))
n_in = mxGetN(prhs(7))
PtOut = m_in
PtZout= n_in
plhs(1) = mxCreateDoubleMatrix(m_in, n_in, 0)
dataout = mxGetPr(plhs(1))
n_in = 1
plhs(2) = mxCreateDoubleMatrix(m_in, n_in, 0)
errout = mxGetPr(plhs(2))
m_in = mxGetM(prhs(8))
n_in = mxGetN(prhs(8))
PtIns = n_in
call oa_ex(%val(x), %val(y),%val(z),%val(datain),
c %val(xhat),%val(yhat),%val(zhat),
c PtIn,PtOut,PtZin,PtZout,%val(dataout),
c %val(errout),%val(a), %val(b),
c PtIns, %val(pmap))
return
end

Best Answer

Ok. I think I found the problem. Line 15-17 should be changed to fit a 64-bit system.
Original:
integer nlhs, nrhs, mxGetM, mxGetN
integer m_in, n_in, size,PtIn,PtOut,PtIns,
c PtZin,PtZout
change to
integer*8 nlhs, nrhs, mxGetM, mxGetN
integer*8 m_in, n_in, size,PtIn,PtOut,PtIns,
c PtZin,PtZout
In this case, matlab gives "out of memory" error. Maybe some mathworks people can give a answer why.
Li