On Wed, 24 Oct 2007 20:52:05 +0000 (UTC), "Weijie "
<mricad@yahoo.no000spppam.com> wrote:
>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 userdefined 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 wrapup the parameters. I forgot
>to note that uip must be an integer vector, and urp must be
>a float vector. To avoid the packunpack, 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?
I am still not quite sure what the basic problem is. Are you simply
trying to convert mexFunction input prhs() mxArray pointers into
Fortran variables? And then at some point later on convert Fortran
variables into mxArray pointers for use with the mexCallMATLAB
function? Are you doing this only for integer scalar, integer rank 1,
rank 2, ...? Float scalar, rank 1, 2, ...? Just real or possibly
complex? Do you need your code to check to see if integer compiles as
integer*4 or integer*8? Do you need to handle dynamically sized
variables (i.e., allocatable) or will they always be the same fixed
size? Etc etc. And what do you mean by "not working?" Are you getting
the MATLAB version of a stack dump? Is it not compiling? I can help
with all of this if you can be more specific.
James Tursa
