Post by n o s p a m p l e a s ePost by Catherine Rees LayThere are, however, lots of ways to use Fortran code in a C project.
What do you actually need to do?
I have interface a model written in Fortran to a simulation that
understands models in C++ only. I am told it is possible in one of the
* The model written in Fortran can be directly linked to a C interface,
or
* The model written in Fortran can be converted to C++ using a f2c
converter and then be interfaced.
Which is the easiest, reliable and computationally efficient? I guess
the second option. Any suggestions how it can be done.
No, definitely the first!
It is much easier and more reliable to create a thin layer of C to call
your
well-developed and well-tested Fortran routines than to have them
converted
by an automatic tool. I know f2c is well up to the task of converting
FORTRAN 77
code, but I doubt it is able to do Fortran 90/95 in the same way.
As for computationally efficient: a well-tuned C program is probably
just
as efficient as a well-tuned Fortran program (all reports about one
being
faster than the other are anecdotal at best and almost certainly
biased,
in the sense that for a particular small class of programs you may get
these
results and you may also get them by not tuning either language well
enough). However, my own experiments with Fortran 90/95 constructs
like array operations indicate that in general these are faster than
explicit loops. C does not have the comfort of array operations.
So, there is my conclusion: option 1 is the best choice.
Regards,
Arjen