Thread Subject: Fortran Mex file: copied integers are zero?

Subject: Fortran Mex file: copied integers are zero?

From: jochen

Date: 5 Nov, 2009 23:25:20

Message: 1 of 1

Hello,

this is the first time, i try to write a more complex mex-file. It compiles, but it seems that when I take values from the input parameters, they remain zero within the scope of the mex-file itself. However, I need those values to check input dimensions and for memory allocation. I tried something along those lines (whole code is long, and I post it on request too):

#include <fintrf.h>

subroutine mexfunction(nargout, pargout, nargin, pargin)

implicit none

! overhead
mwPointer :: pargout(*), pargin(*)
integer :: nargout, nargin

       mwPointer :: mxCreateDoubleMatrix, mxGetPr
mwPointer :: mxCreateNumericArray
mwSize :: mxGetM, mxGetN
integer :: mxClassIDFromClassName
! end overhead


! declarations
mwPointer :: eposp, elecnop
mwPointer :: potendp
mwSize :: m, n
character*120 :: line
integer*4 :: elecno
integer*4, allocatable, dimension(:) :: epos
real*8, allocatable, dimension(:) :: potend

! elecno
m = mxGetM(pargin(5))
n = mxGetN(pargin(5))
if ((m .ne. 1) .or. (n .ne. 1)) then
call mexErrMsgTxt('arg5: elecno !scalar!')
endif
elecnop = mxGetPr(pargin(5))
call mxCopyPtrToInteger4(elecnop,elecno,m*n)

! epos
m = mxGetM(pargin(1))
n = mxGetN(pargin(1))
if (min(m,n) .ne. 1) then
call mexErrMsgTxt('!arg1: epos nx1!')
endif
if (max(m,n) .ne. elecno) then
write (line,*) 'elecno =', elecno
call mexErrMsgTxt(line)
endif
allocate(epos(max(m,n)))
eposp = mxGetPr(pargin(1))
call mxCopyPtrToInteger4(eposp,epos,m*n)

               ....

allocate (potend(elecno))

                ...

end subroutine mexfunction


Ok, the point is the variable 'elecno' prints 0 and whatever I pass, and
  if (max(m,n) .ne. elecno) under !epos
always fails. The dimensions of elecno are checked correctly before though. Is this normal behaviour? Any help is appreciated.

Jochen

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
fortran jochen 5 Nov, 2009 18:29:04
mex jochen 5 Nov, 2009 18:29:03
rssFeed for this Thread

Contact us at files@mathworks.com