Joined: 29 Nov 2006
|Posted: Sat Jun 25, 2005 3:34 am Post subject: Using MatLab 6.5 (and later versions) with FTN95
|MATLAB © The MathWorks Inc.
You can download the files mentioned in this item [url="http://www.silverfrost.com/public_downloads/MatLab.zip"]here[/url]:
This document describes how to use the Salford Fortran compiler FTN95 with MATLAB 6.5. For this purpose you will need the following Salford files:
SF95opts.bat and SF95opts.stp
(these go in C:MATLAB6p5binwin32mexopts)
(this must go in C:Program FilesSalford SoftwareFTN95include)
(this can go in the current working directory)
salflibc.dll and salflibc.lib
(you need a contemporary version of these standard Salford libraries)
Build.bat is an optional extra for building from a DOS box.
use.c is the code for use.dll. This was compiled using a Microsoft compiler.
timestwo.f is a sample Fortran program.
Configuring MATLAB to use FTN95
After you have put the above two files into the mexopts sub-directory, from the MATLAB command line type:
As directed, ask for a list of compilers and select FTN95.
As a test, change to the directory for the above sample timestwo.f and type:
Finally type something like:
y = timestwo(4)
The "use" command is a temporary work around that explicitly loads timestwo.dll. Otherwise when you first use timestwo you will get a floating point exception. After this failure a second attempt will work. Using the "use" command simply avoids the unsightly error message.
Changes required in the Fortran samples
timestwo.f illustrates the changes that need to be made to the standard MATLAB sample programs.
1. From MATLAB version 6.0 onwards you must define the 'Gateway' function mexFunction as F_STDCALL.
2. Include <matlab.ins> as the first line of mexFunction.
3. Instead of %val, use DCORE8 for DOUBLE PRECISION and CORE4 for INTEGER.
4. Functions like mxCopyPtrToReal8 are not needed because DCORE8 can be used instead (see timestwo.f).
5. For NULL use CORE4(0).
Note that DCORE8 and CORE4 etc. are interchangable. Different names are used to maintain consistent types.