- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Many Fortran code! How to call Fortran code from C/C++?
As a C/C++ programmer, there are a few reasons to use Fortran:
(1) Fortran is very similar to Matlab and easy to port;
(2) Fortran has support of complex numbers and vectorized numbers and
the operations in Fortran are naturally element-wise, operating on a
whole vector.
(3) There are many scientific codes are in Fortran.
-------------
So how do I call Fortran program from my C program?
I am using MSVS. NET 2003, VisualC++ and Intel C++ therein, and also
the Intel Visual Fortran therein.
To give an example, I want to call a Fortran program from C++, which
is in its bare form, it is a function that evaluates something and
pass the results back; I also want to call C++ from Fortran, one
example is that many good numerical integral codes are in Fortran, but
I want to provide my integrand function in C++.
How to do these interfaces? Pointers and readings are appreciated!
Thanks for your help!
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There is a lot of material on this subject in the docs folder which comes with ifort, on traditional, CVF compatible, and Fortran 2003 standard interfaces. Metcalf, Reid, Cohen "fortran 95/2003 explained" has a chapter on ISO C binding, as well as significant errata posted on the web. For C++, you must declare all Fortran references with "extern C" in order to use the traditional or f2003 interface.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
As mentioned, there is a large chapter in the Intel Fortran documentation on mixed-language programming, and there are some sample C-Fortran programs installed along with the compiler (in version 10).
![](/skins/images/B7BA37F9CE4B52FF7CAE1FB0388839C8/responsive_peak/images/icon_anonymous_message.png)
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page