how to link between MATLAB and FORTRAN?

6 visualizaciones (últimos 30 días)
Mohamed Youssef
Mohamed Youssef el 14 de Mzo. de 2020
Respondida: Shiva Kalyan Diwakaruni el 18 de Mzo. de 2020
i need a code that can execute a fortran program from the MATLAB.
I had 2 programs:
  1. MATLAB which execute a data from an excel file then save this data as .txt to be an input for the main program fortran.
  2. a Fortran program which does a lot of calculations using intel compiler and Visual studio IDE
I need a code that can execute the fortran program by using matlab inorder to only use one program. instead of running matlab then executing fortran using visual studio.
Thank you
  1 comentario
dpb
dpb el 14 de Mzo. de 2020
doc system
The only issue may be in how the Fortran executable obtains its input...but we have no information on that.

Iniciar sesión para comentar.

Respuestas (1)

Shiva Kalyan Diwakaruni
Shiva Kalyan Diwakaruni el 18 de Mzo. de 2020
Hi,
To compile a MATLAB Engine Fortran application in the Microsoft Visual Studio 2008 environment, perform the steps outlined below:
1. Set up a project in Visual Studio as follows:
a. Open Microsoft Visual Studio and navigate to 'File' -> 'New' -> 'Project'.
b. Select 'Intel Visual Fortran' -> 'Console Application' -> 'Empty Project'.
c. Following this, enter the name of the project and its location in the indicated text areas and click OK.
2. Add FORTRAN program to the project
a. Copy the file FORTRAN program to the folder where you created the Visual Studio project. This file may be obtained from the following location:
$MATLABROOT/extern/examples/eng_mat
where $MATLABROOT is the MATLAB root directory, and may be determined by entering the command:
>> matlabroot
at the MATLAB command prompt.
b. In Visual Studio, right-click on the 'Source Files' folder in the 'Solution Explorer' and click 'Add' -> 'Existing Item...'.
c. Select FORTRAN program and click 'Add'.
4. Right click on the project name and select 'Properties' in the solution explorer to open the project
properties. Once this window has opened, make the following changes:
a. Under 'Fortran' -> 'General', add the directory
$MATLABROOT\extern\include
to the field 'Additional Include Directories'.
b. Under 'Fortran' -> 'Preprocessor', choose 'Yes(/fpp)' for 'Preprocess Source File'.
c. Under 'Linker' -> 'General', add the directory
$MATLABROOT\extern\lib\win32\microsoft
to the 'Additional Library Directories' field.
d. Under 'Linker' -> 'Input', add the following names:
libmx.lib
libmat.lib
libeng.lib
to the 'Additional Dependencies' field.
e. Click on 'Ok'.
5. You should now be able to build the project.
6. To run the executable, you may have to add the folder where MATLAB executable is saved to the system path. In a DOS command prompt:
set PATH=$MATLABROOT\bin\win32;%PATH%

Categorías

Más información sobre Fortran with MATLAB en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by