Path: news.mathworks.com!not-for-mail
From: "Weijie " <mricad@yahoo.no000spppam.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: MEX FORTRAN programming
Date: Wed, 24 Oct 2007 20:51:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 64
Message-ID: <ffob7m$s8b$1@fred.mathworks.com>
References: <ffnt1c$5fk$1@fred.mathworks.com> <ffo69s$2pf$1@aioe.org>
Reply-To: "Weijie " <mricad@yahoo.no000spppam.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1193259062 28939 172.30.248.35 (24 Oct 2007 20:51:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 24 Oct 2007 20:51:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 544673
Xref: news.mathworks.com comp.soft-sys.matlab:434488



dpb <none@non.net> wrote in message <ffo69s$2pf$1@aioe.org>...
> Weijie wrote:
> ...
> > In Matlab, I would like to call
> >
M>[r1,r2...]=myfnc(v1,str1,str2,par1,par2,mpar1,mpar2,mpar3...)
> > where myfnc is a compiled MEX function that use mexFunction
> > and old Fortran code to do the computation task; v1 is a
> > vector parameter, str1 and str2 are two strings representing
> > the names of two Matlab functions (.m files). par1 and par2
> > are other parameters to myfnc; mpar1,mpar2...are input
> > arguments to str1.m and str2.m (assume they have exactly the
> > same arguments). In the mex function, I'll call a Fortran
> > function (previously developed and tested):
> > 
> > call oldfnc(n, d, x, objf, objg, iv, liv, lv, v,
uip,urp,ufp)
> > 
> > where objf and objg are two Fortran functions and uip, urp,
> > and ufp are user-defined parameters input to objf and objg.
> > 
> > Now, in the Fortran functions objf and objg that I define, I
> > would like to use mexCallMATLAB(...) to call str1.m and
> > str2.m respectively. 
> > 
> > It's easy to see that once I done all these, the users can
> > define their own str1.m and str2.m and call myfnc to do
> > thier job using the old Fortran package.
> > 
> > The key difficulty is that: how to transfer mpar1,
> > mpar2...to uip, urp, and ufp in mes function AND then, in
> > objf and objg, how to transfer uip, urp, and ufp to input
> > arguments of mexCallMATLAB function?
> > 
> > Thanks a million! I'd share my experience once I complete
> > this project.
> 
> The parameters to the called function would have to be
wrapped in 
> mxArray per the calling protocol as expected by
mexCallMATLAB.  The user 
> parameters and functions have to be aware of the
expectations on both 
> the caller and the callee side.  Other than that, I don't
see the problem?
> 

The problem is just how to wrap-up the parameters. I forgot
to note that uip must be an integer vector, and urp must be
a float vector. To avoid the pack-unpack, I tried to use the
static (global) variables like the following:

      MODULE global
        character*10 :: MATLAB_OBJ_NAME,MATLAB_GRAD_NAME
        mwPointer :: mprhs, mplhs
      END MODULE global

The idea is that, then in the mexFunction, I got the
contents of MATLAB_OBJ_NAME from str1, and other input
arguments from prhs (e.g., mprhs=prhs(3)). Then in the objf,
I set the nlhs and nrhs and together with the global
variables mprhs, mplhs, and MATLAB_OBJ_NAME to call
mexCallMATLAB function. But it's not working so far....am I
in the right direction?