MATLAB: Mex/Fortran passing data

mex fortran interface

Hello,
Is it possible to pass from matlab data labeled as follows and if so what would be the efficient way to do it?
AeroConfig_Hub_position %a (3*1) vector
AeroConfig_Hub_orientation %a (3*3) matrix
AeroConfig_Hub_translationvel %a (3*1)vector
AeroConfig_Hub_rotationvel %a (3*1) vector
through a mex interface that will format them to be read by the fortan code as:
Aeroconfig%Hub%position
Aeroconfig%Hub%orientation
AeroConfig%Hub%rotationvel
AeroConfig%Hub%translationvel
any help is greatly appreciated.

Best Answer

Download this package from the FEX:
Follow the instructions to compile the modules. Then you can do stuff like this:
m-code:
myFortranMexRoutine(AeroConfig_Hub_position,...
AeroConfig_Hub_orientation,...
AeroConfig_Hub_translationvel,...
AeroConfig_Hub_rotationvel);
Fortran code:
#include "fintrf.h"
subroutine mexFunction(nlhs,plhs,nrhs,prhs)
use MatlabAPImx
implicit none
integer nlhs, nrhs
mwPointer plhs(*), prhs(*)
__yourtype__ Aeroconfig
AeroConfig%Hub%position = fpGetPr1(prhs(1))
AeroConfig%Hub%orientation = fpGetPr(prhs(2))
AeroConfig%Hub%translationvel = fpGetPr1(prhs(3))
AeroConfig%Hub%rotationvel = fpGetPr1(prhs(4))
Caution: The above is just an outline with no error checking. In production code you would need to check nrhs and nlhs to see if there are the correct number of inputs & outputs. And you would have to retrieve the data pointers via fpGetPr1 and fpGetPr into separate variables and examine if they are associated prior to using them. Etc.