Linking Fortran to matlab

Hi I'm using a matlab on a linux machine and am having trouble using xfoil with it. I'm trying to use xfoil with the system command but am getting the error. At line 135 of file ../src/userio.f (unit = 5, file = 'fort.5') Fortran runtime error: End of file ans = 2
I can run xfoil from outside matlab without incident. As an aside while researching the solution to this problem I found a post where somebody talked about compiling xfoil to a mex file and using it this way. What if any are the advantages to this approach.

4 Kommentare

dpb
dpb am 17 Jun. 2013
LU 5/6 are often stdio and I presume highly likely is for the compiler in question. LU 5 in that case will be input so the app is asking for input either from the keyboard or it appears from the error message to the default implicitly-opened file 'fort.5'.
The crystal ball tells me that the most likely problem is that when you run the code manually either you give a file name directly to the app that contains the input or if it is using the default name then when you start the shell session it is starting in a different directory location than where you're running it manually.
I suspect there's a good chance I was the one who suggested the mex route; I seem to recall a question not too long ago in that vein. :)
The advantages are that you have control over what's going on and can return i/o directly into the Matlab workspace w/o the shell session. The disadvantage is, of course, you have to write/debug the glue code--how difficult that is depends on the complexity of the code and your level of proficiency in Fortran and the mex interfaces.
Reuben
Reuben am 17 Jun. 2013
I'm trying to redirect the input so that the xfoil commands are provided by a text file. This has worked on a windows machine it is only the linux implementation that has problems. I suspect the problem is to do with me incorrectly fixing the prevous problem which was GFortran 1.4 not found. This was solved by essentially following the instructions in this link http://judsonsnotes.com/notes/index.php?option=com_content&view=article&id=659%3ainstalling-matlab-in-ubuntu-1110&catid=37%3atech-notes&Itemid=59 but I'm at a loss for how to proceed now. Thanks for your patience and time.
dpb
dpb am 17 Jun. 2013
'Fraid I can't help you much on unix-like installation questions--I've never worked on a system w/ it other than a very long time ago did some compiling on already-configured Sun workstation for the plant simulator and a previous life's day job.
AFAIK redirection is basically the same on the command line aren't they? The error message indicated the Fortran code was explicitly trying to read a file named fort.5, however. I used implicit i/o units so rarely I have to admit I've forgotten the Fortran rules for implicit open precisely as to sequence, etc. The name itself is compiler-specific, of course.
What command are you using at command line and what did you use for the system() command?
You can also do something like return the output of a simple 'ls' or the like to determine the working directory of a shell and see if that's what you want/think it should be. Beyond that you probably a more unix-savvy respondent as even my crystal ball is untrained in the area. :)
Marco.Caboni
Marco.Caboni am 12 Jul. 2013
Hello Reuben,
I am having the same your problem. Trying to execute Xfoil through Matlab, I get: "At line 135 of file ../src/userio.f (unit = 5, file = 'fort.5') Fortran runtime error: End of file".
Did you manage to solve it eventually?
Thanks,
Marco

Melden Sie sich an, um zu kommentieren.

Antworten (2)

K
K am 25 Okt. 2013

2 Stimmen

I realise this is a bit old, but it's a top hit on Google, so I will respond with the answer that worked for me.
Before running xfoil, execute the following commands:
setenv(GFORTRAN_STDIN_UNIT, 5)
setenv(GFORTRAN_STDOUT_UNIT, 6)
setenv(GFORTRAN_STDERR_UNIT, 0)
To restore the environment the way it was afterwards:
setenv(GFORTRAN_STDIN_UNIT, -1)
setenv(GFORTRAN_STDOUT_UNIT, -1)
setenv(GFORTRAN_STDERR_UNIT, -1)

2 Kommentare

benho
benho am 17 Feb. 2016
Is this meant to work on windows as well? I have inserted the commands but I am still getting the same error
At line 85 of file ../src/userio.f (unit = 5, file = 'fort.5') Fortran runtime error: End of file ans = 2
Daniel
Daniel am 30 Mär. 2016
I had the same problem and resetting the environment variables worked for me. For the record, I am running Matlab 2013b on Ubuntu 12.04 LTS.
Cheers!

Melden Sie sich an, um zu kommentieren.

Jason Botha
Jason Botha am 23 Jan. 2014

0 Stimmen

Thank you! I've been struggling since 2012 to get matlab to talk to xfoil.
Is there any explanation about why this works?

Kategorien

Mehr zu Fortran with MATLAB finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 17 Jun. 2013

Kommentiert:

am 30 Mär. 2016

Community Treasure Hunt

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

Start Hunting!

Translated by