mxGetIr使我的Matlab崩溃

时间:2013-07-24 21:20:51

标签: matlab fortran mex

我正在编写一个MEX文件,涉及从Matlab读取稀疏矩阵,但每次运行程序时Matlab都会崩溃。然后我编写一个测试文件,发现问题正好在mxGetIr命令中。我不知道为什么会这样。请帮帮我......非常感谢你!

我在Mac OS X 10.8.1的Matlab 2013a下工作。

#include "fintrh.h"

  subroutine mexFunction(nlhs, plhs, nrhs, prhs)

  mwpointer plhs(*), prhs(*)
  integer nlhs, nrhs

  integer temp, nzmax
  integer, dimension(2) :: dimx

  real, dimension (:), allocatable :: sr
  integer, dimension (:), allocatable :: irs, jcs

  mwpointer mxGetPr
  mwpointer mxCreateDoubleMatrix
  mwsize  mxGetM, mxGetN, mxGetNzmax

  mwpointer mxGetIr, mxGetJc

  mwpointer temp_pr, spr

  dimx(1) = mxGetM(prhs(1))
  dimx(2) = mxGetN(prhs(1))
  nzmax = mxGetNzmax(prhs(1))
  allocate(sr(1:nzmax))
  allocate(irs(1:nzmax))
  allocate(jcs(1:(dimx(2)+1)))
  temp_pr = mxGetPr(prhs(1))
  call getreal(temp_pr,sr,nzmax)

  temp_pr = mxGetJc(prhs(1))

  plhs(1) = mxCreateDoubleMatrix(nzmax,1,0)
  temp_pr = mxGetPr(plhs(1))
  call putreal(sr, temp_pr, nzmax)

  end

  subroutine real8toreal(x, y, size)
  integer size
  real*8 x(size)
  real y(size)
  do 10 i=1,size
     y(i)= x(i)
  10   continue
  return
  end

  subroutine getreal(pr,x,size)
  mwpointer pr
  integer size
  real x(size)
  real*8, dimension (:), allocatable :: temp
  allocate(temp(1:size))
  call mxCopyPtrToReal8(pr,temp,size)
  call real8toreal(temp,x,size)
  deallocate(temp)      
  return
  end

  subroutine putreal(x,pr,size)
  mwpointer pr
  integer size
  real x(size)
  real*8, dimension (:), allocatable :: temp
  allocate(temp(1:size))
  call realtoreal8(x,temp,size)
  call mxCopyReal8ToPtr(temp,pr,size)
  deallocate(temp)      
  return
  end

1 个答案:

答案 0 :(得分:0)

检查the documentation后,我认为您可能需要另外调用它。

从那里我会猜到这样的事情:

mwPointer mxGetIr(pm)
mwPointer pm