- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I've a subroutine that's written in C. My main program and everything else are in fortran 90. I have a global data module which consist of some variables and it can be assessed globally ie
module global_data
implicit none
save
real :: dd(10)
end module global_data
I would like to pass the values of a variable (e.g. dd) to a C subroutine, do some calculation, and out comes the result of the variable.
How can I do this? Is there a sample code somewhere? I tried to find some info on the net but they seem quite complicated...
Btw, my environment is linux and it's using ifort and icc ver 9.1
Thanks in advance!
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Just call the C routine and pass the variable as an argument. On the C side, be sure to declare the argument as *float or something similar. There is a chapter of the documentation on mixed-language programming which will be of interest. You'll want the C routine to have a lowercase name with a trailing underscore, as that is the convention used for Fortran routines on Linux.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Since you're learning, you should consider the advantage of starting out with a Fortran compiler which supports the current standard method, ISO C interoperability. For example, you could install a pre-built Fortran from the gfortran wiki, or use ifort 10.1. As you point out, it could be confusing if you don't choose between current and legacy methods, which differ somewhat between linux, Windows, and various flavors of Unix.
If you mean that you want to use ifort 9.1, you should find examples in the documentation in the /doc/ directory of the installation. Both legacy linux style linkage and DEC directive methods are supported.
If you mean that you want to use ifort 9.1, you should find examples in the documentation in the /doc/ directory of the installation. Both legacy linux style linkage and DEC directive methods are supported.
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