Path: news.mathworks.com!newsfeed-00.mathworks.com!nntp.TheWorld.com!newsswitch.lcs.mit.edu!elk.ncren.net!usenet01.sei.cmu.edu!nntp.club.cc.cmu.edu!69.16.185.11.MISMATCH!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!newsfe07.iad.POSTED!f8a62740!not-for-mail
From: Geico Caveman <spammers-go-here@spam.invalid>
Organization: Some
Newsgroups: comp.soft-sys.matlab
Message-ID: <2009102115045916807-spammersgohere@spaminvalid>
References: <2009102112385016807-spammersgohere@spaminvalid> <hbnv28$c5h$1@fred.mathworks.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit
Subject: Re: mxGetNumberOfDimensions missing ?
User-Agent: Unison/1.8.1
Lines: 121
X-Complaints-To: abuse@teranews.com
NNTP-Posting-Date: Wed, 21 Oct 2009 22:04:58 UTC
Date: Wed, 21 Oct 2009 15:04:59 -0700
Xref: news.mathworks.com comp.soft-sys.matlab:579117


On 2009-10-21 14:39:20 -0700, "James Tursa" 
<aclassyguy_with_a_k_not_a_c@hotmail.com> said:

> Geico Caveman <spammers-go-here@spam.invalid> wrote in message 
> <2009102112385016807-spammersgohere@spaminvalid>...
>> Mac OSX 10.5.6
>> Matlab R2009a
>> 
>> gfortran/gcc
>> 
>> Code fragment:
>> 
>> subroutine mexFunction(nlhs, plhs, nrhs, prhs)
>> use matlabmex
>> 
>> implicit none
>> 
>> integer, intent(in) :: nlhs, nrhs
>> integer, intent(in), dimension(:), pointer :: prhs
>> integer, intent(out), dimension(:), pointer :: plhs
>> 
>> integer(i4b) :: l,m,n
>> integer(i4b), pointer :: n1
>> integer(i4b), pointer :: A
>> 
>> if(nrhs /= 2) then
>> call mexErrMsgTxt('Function requires four input arguments.');
>> end if
>> 
>> A = mxGetData(prhs(1))
>> n1 = mxGetDimensions(prhs(1))
>> 
>> end subroutine mexFunction
>> 
>> 
>> matlabmex.f90 contains:
>> 
>> integer (kind=4) function mxGetData(pm)
>> use constants
>> integer (kind=4)  :: pm
>> end function mxGetData
>> 
>> integer (kind=4) function mxGetDimensions(pm)
>> use constants
>> integer (kind=4)  :: pm
>> end function mxGetDimensions
>> 
>> integer(kind=4) function mxGetNumberOfDimensions(pm)
>> use constants
>> integer(kind=4) :: pm
>> end function mxGetNumberOfDimensions
>> 
>> in the interface block.
>> 
>> Compilation:
>> 
>> /Applications/MATLAB2009a/MATLAB_R2009a.app/bin/mex -maci mexFunction.f90
>> Undefined symbols:
>> "_mxgetdimensions_", referenced from:
>> _mexfunction_ in mexFunction.o
>> ld: symbol(s) not found
>> collect2: ld returned 1 exit status
>> 
>> mex: link of ' "mexFunction.mexmaci"' failed.
>> 
>> It can find mxGetData() but not mxGetNumberOfDimensions()
>> 
>> I have checked my matlab documentation to confirm that the function exists.
> 
> Before I make more comments, I would like a few things cleared up. I 
> have never seen this type of mex programming before. It looks like you 
> are attempting to define an interface for the mx functions in a module. 
> And in that module you have functions with the same name as the MATLAB 
> API functions. e.g., let's start with the function 
> mxGetNumberOfDimensions. Is the code you show a function contained in 
> the module, or is it part of an interface definition? What you have 
> shown is not

This file is a modification of the commonly used f90 mex interface definition:

http://aede.osu.edu/people/roberts.628/papers/research/fmex/toolsandlinks.htm


>  at all clear on this. How is the connection to the actual function in 
> the MATLAB library actually made? And then there is the mxGetDimensions 
> function. The MATLAB API function for this returns an integer*4 on a 
> 32-bit system (used for storing a 32-bit address). You are apparently 
> attempting to get this result, and then return it as an actual Fortran 
> integer pointer type. Is that correct? And then there is the
> prhs and plhs definitions that you have. You declared them as pointers 
> to integers. Is that really what you intended? What is the point (no 
> pun intended) of this?
> 
> James Tursa

The functions mxGetData, or mxGetPr are also defined similarly, and 
also return an integer (please consult original post). Since I am 
utterly new to mex programming (not new to Fortran (a bit rusty) or 
Matlab), I am guessing that the address to the arrays (in these cases) 
is returned as an integer that you can use a fortran pointer to point 
to.

The point of all this is that function calls from mexFunction.f90 need 
to have an interface to call.

The existing mex fortran examples in the documentation, even for R2009a 
and R2009b appear to presume that the user is employing fortran 77, 
which is obsolescent now in terms of new code development (though there 
is plenty of legacy code in f77).

So, it has been a little difficult to get this to work given the 
paucity of Mathworks authenticated information.

I used the following example as the starting point of my efforts:

http://www.physik3.gwdg.de/~engster/mex_fortran90.html

I would be glad of any pointers (no pun intended either) to the proper 
way of passing a 3D array to fortran, extracting the data and shape 
from prhs(1), and creating a 3D array for plhs(1).