Mex Fortran Gateway Function
Show older comments
Hi,
Can someone help me write a mex gateway function for making a call to some fortran subroutines. The routines are written in fortran 77 and I'm using Microsoft Visual Studio 2005 with Intel Visual Fortran Compiler 10.1. The subroutines compile fine, but I'm having difficulty with the mex gateway function.
I'm trying to make a mex gateway function that will support a call to the following fortran subroutine:
subroutine crvfit(xfit,yfit,xfite,yfite,imode,yfit2,nptsf,delfac)
or
call crvfit(xfit,yfit,xfite,yfite,imode,yfit2,nptsf,delfac)
Inputs:
xfit, yfit - x and y data vectors to be fitted
xfite, yfite - the errors for the x and y vectors
imode = 1 (integer)
nptsf - the number of points to be fitted, i.e. length of xfit, yfit, xfite, and yfite
delfac = 500 (integer)
Outputs:
xfit, yfit
xfite, yfite
imode
yfit2 - temporary fit vector
nptsf2
delfac
So given these inputs, I want to return all of these outputs. The inputs will be passed to the function in MATLAB like:
[xfit, yfit, xfite, yfite, imode, yfit2, nptsf, delfac] = crvfit(xfit, yfit, xfite, yfite, imode, yfit2, nptsf, delfac)
I've tried to do this myself using example fortran mex gateway functions, but I'm very confused with using mex functions and having pointers to data types being passed through mex functions and returning them to MATLAB.
Thanks!
2 Comments
Jan
on 11 Jun 2011
Although we could try to create the mexFunction for you, but as long as you are too confused by the details, you have no chance to adjust any details. Therefire I assume the most efficient method to solve your problem is to learn how to use pointers. Have you inspected the examples shipped with Matlab?
Aaron
on 12 Jun 2011
Accepted Answer
More Answers (1)
James Tursa
on 11 Jun 2011
Please provide the exact interface for this routine:
subroutine crvfit(xfit,yfit,xfite,yfite,imode,yfit2,nptsf,delfac)
i.e., give the type, rank, and size specifications for each of the arguments as they are listed in the subroutine. Then it will likely not be too hard to create the mex gateway for this using my Fortran 95 Interface package from the FEX:
I can help you once I know the exact interface for the routine.
5 Comments
Aaron
on 12 Jun 2011
James Tursa
on 12 Jun 2011
Follow-up question about your proposed calling syntax:
[xfit, yfit, xfite, yfite, imode, yfit2, nptsf, delfac] = crvfit(xfit, yfit, xfite, yfite, imode, yfit2, nptsf, delfac)
Why is *everything* listed as both an input and an output? Aren't some of these just inputs and some just outputs? e.g., does the crvfit routine change the value of nptsf? If not, then why is it an output? And is xfite really an input, or is this really just an output that is calculated by crvfit? Please clarify what, exactly, are the inputs and outputs.
Aaron
on 13 Jun 2011
James Tursa
on 13 Jun 2011
Sorry if I keep pestering you with questions, but the interface code will depend on the answers you give. My interpretation of what you have said thus far is that xfit, yfit, xfite, yfite, and yfit2 are all pre-populated vectors of size nptsf on input, but that the crvfit routine will return a *different* value of nptsf (presumably *less* than the input value of nptsf?) and that you want the returned size of these vectors to be this new value of nptsf. Is that correct?
Aaron
on 13 Jun 2011
Categories
Find more on Fortran with MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!