|
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
|