2

I was wondering which high-level langunage allows the easiest manner in which to call Fortran subroutines? I currently use MATLAB and calling MEX files seems to be relatively complicated compared to other languages.

I'm particularly interested in how the following compares in terms of getting "up and running" quickly:

*Python via f2py *R via ? *MATLAB via MEX files

Another way of asking this would be "If you were to start over and learn a new language, which one would you choose if your objective was calling Fortran subroutines?"

I'm trying to getbthe "best of both worlds" i.e. having good data handling and graphics combined with the ability to call fast Fortran subroutines.

Thank you all in advance for any help you can provide. Alas, if someone knows of a good MEX tutorial for Fortran, that would be appreciated as well.

EcoDude
  • 21
  • 1

3 Answers3

6

I was wondering which high-level langunage allows the easiest manner in which to call Fortran subroutines?

The obvious answer is Fortran itself. So-called Modern Fortran (2003 & 2008) has a lot of high-level features. And obviously it's easy to call legacy FORTRAN code (my guess is that you have old FORTRAN code base) from the modern one.

Wildcat
  • 8,701
  • 6
  • 42
  • 63
4

Python via f2py is very nice. I had a little bit of trouble getting it going on Windows with IVF, but it didn't take long to figure out, and the mailing list gives prompt responses. On Linux, it worked without any issues.

I haven't used R, but as I understand it, it's only useful if you do a lot of statistics with large amounts of data. As for MATLAB, it's a horrible language, if you're just calling FORTRAN, you're better off with Python.

bdforbes
  • 1,486
  • 1
  • 13
  • 31
  • Thanks for the response! Of course, using Fortran directly is the trivial solution but as I mentioned before I'd like to have the best of both worlds. I've seen several tutorials regarding f2py and it appears ro be very easy to call from Python, unlike MATLAB, which is much more difficult. I also discovered this link, which may be of interest to others: http://nag.com/numeric/MB/start.asp. This is the NAG Fortran numerical subroutines that are callable from MATLAB without (it appears) much fuss. Thnaks again for allof your responses! – EcoDude Sep 11 '11 at 17:56
  • Amen to Python. My experience has been that if you write the Fortran subroutines in the way that you should anyway (e.g. specifying intents for arguments, etc.) then the f2py conversion becomes nearly trivial. Plus, you have integration with all sorts of other libraries to do text processing, network communication, and other goodies. I tried to do MEX files when I was using MATLAB, and the day I tried f2py and realized I never had to worry about MEX files again was a *great* day. – Tim Whitcomb Sep 12 '11 at 15:35
  • Thanks for the comment! I do not understand why MATLAB makes it so difficult to write MEX files. I've received many positive comments regarding Python in terms of linking it to Fortran. I have also heard good things about the R/Fortran connection so that is another possibility. I'm disappointed that MATLAB has not deemed it necessary to streamline the process of linking their code to C and Fortran. – EcoDude Sep 13 '11 at 02:19
1

What I usually do in your case is create Fortran programs that I can pass command line arguments to as input. This is readily available by Fortran 2003 standard using intrinsic get_command_argument subroutine. You can then parse Fortran program output from whatever language you are using as a wrapper (assuming language has access to system shell). In the past, I did this with shell scripts, MATLAB (avoid), Python.

milancurcic
  • 6,202
  • 2
  • 34
  • 47