Skip to content

Latest commit

 

History

History

finmatlab

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Run Fortran in Matlab

diego domenzain March 2021 @ Colorado School of Mines

How to run Fortran functions in Matlab

Taken from the Matlab docs.

See here for more examples.

An example with matrix I/O can be found in

projects/pdes/hdd/src/hhd_solve.F

which is used in

projects/pdes/hdd/src/hhd_.m & projects/pdes/hdd/hhd_cooler.m

Basic technicalities

Main Fortran routine is,

/Applications/MATLAB_R2014b.app/extern/examples/refbook/timestwo.F

The header needed for this to work is,

/Applications/MATLAB_R2014b.app/extern/include/fintrf.h

To compile and use do:

>> mex -v timestwo.F
>> x = 99;
>> y = timestwo(x)

Advanced technicalities

C     Gateway routine
      subroutine mexFunction(nlhs, plhs, nrhs, prhs)

C     Declarations

C     Statements

      return
      end

Trouble-shooting

In my experience, this was quite annoying.

First, check which versions you have of these:

$> xcrun --show-sdk-version
$> xcodebuild -showsdks

Then in Matlab type,

>> compilerCfg = mex.getCompilerConfigurations
>> open(compilerCfg(1).MexOpt)

Alternatively, you can just open this file,

/Users/username/.matlab/R2014b/mexopts.sh

Then edit this file with the right versions.