Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Unable to create mex file from Fortran 90 code
Replies: 8   Last Post: Apr 9, 2013 2:35 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Charles

Posts: 17
Registered: 2/15/12
Unable to create mex file from Fortran 90 code
Posted: Apr 7, 2013 7:00 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Hi,
I am pretty new to both Fortran and creating/using mex files. I created a simple Fortran 90 subroutine that takes a 2-dimensional array and creates a 3-dimensional array after doing some multiplication. I have tested it it in Fortran and it seems to work fine. I am now trying to create a mex file from it. However, when I try to create the mex file I get the following error:

"Warning: timesmultmex.f90:1: Illegal preprocessor directive
timesmultmex.f90:23.2:

A => mxGetPr(prhs(1))
1
Error: Different types in pointer assignment at (1)
timesmultmex.f90:35.2:

B => mxGetPr(plhs(1))
1
Error: Different types in pointer assignment at (1)

mex: compile of ' "timesmultmex.f90"' failed.

Error using mex (line 206)
Unable to complete successfully."



Can somebody please help me figure out what I have done wrong. I am hoping it is a pretty simple fix, but I am not quite sure. Unfortunately, there does not seem to be much documentation about using Fortran 90 in Matlab. If I have major mistakes, can you please point me to a good source of information to help me fix this. Thanks in advance.

The file I am using is called timesmultmex.f90 and I enter "mex timesmultmex.f90" into Matlab.






Here is the contents of timesmultmex.f90

"
#include "fintrf.h"


subroutine mexFunction(nlhs, plhs, nrhs, prhs)
implicit none

integer, intent(in) :: nlhs, nrhs
real (kind=8), intent(in), dimension(*) :: prhs
real (kind=8), intent(out), dimension(*) :: plhs
integer, pointer :: mxGetPr
integer :: mxGetM, mxGetN, type,mxCreateDoubleMatrix
integer :: mxCreateNumericArray, ndim, classid, ComplexFlag, mxClassIDFromClassName
integer, dimension(3) :: dims
integer :: m,n
real (kind=8), pointer :: A,B ! These are the pointers to the matrix data


! Get data and size of the input matrix
A => mxGetPr(prhs(1))
m = mxGetM(prhs(1))
n = mxGetN(prhs(1))

!Define dimensions
ndim=3
dims(1)=m
dims(2)=n
dims(3)=m
classid=mxClassIDFromClassName('double')
ComplexFlag=0
! Create output matrix
plhs(1) = mxCreateNumericArray(ndim,dims,classid,ComplexFlag)
B => mxGetPr(plhs(1))

! Call subroutine for multiplication
call timesmultmex(A,B,n,m)

end subroutine mexFunction



SUBROUTINE timesmultmex(A,B,n,m)
IMPLICIT NONE

INTEGER, INTENT(IN) :: n, m
REAL (kind=8), DIMENSION(m,n), INTENT(INOUT) :: A
REAL (kind=8), DIMENSION(m,n,m), INTENT(INOUT) :: B
INTEGER :: kk,jj

! Multiplication loop
DO kk=1,m
Do jj=kk,m
B(jj,:,kk)=A(jj,:)*A(kk,:)
END Do
END DO

!Loop to define some rows as being equal to previous calculations

DO kk=2,m
DO jj=1,kk-1
B(jj,:,kk)=B(kk,:,jj)
END Do
END DO


END SUBROUTINE timesmultmex
"



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.