Discussion:
F2C converter
(too old to reply)
n o s p a m p l e a s e
2006-06-08 09:38:01 UTC
Permalink
What is a good Fortran to C converter?

Thanx
NSP
Catherine Rees Lay
2006-06-08 10:05:45 UTC
Permalink
Post by n o s p a m p l e a s e
What is a good Fortran to C converter?
Thanx
NSP
There isn't one.

Well, to be fair, there are some (possibly the most widely used is, in
fact, called F2C). But if what you have is well written Fortran, there
is no way to get the same standard of C code from a mechanical converter.

There are, however, lots of ways to use Fortran code in a C project.
What do you actually need to do?

Catherine.
n o s p a m p l e a s e
2006-06-08 11:36:28 UTC
Permalink
Post by Catherine Rees Lay
There 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
following two ways:

* 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.

Thanx
NSP
Jan Vorbrüggen
2006-06-08 11:52:18 UTC
Permalink
Post by n o s p a m p l e a s e
* The model written in Fortran can be directly linked to a C interface,
As every (?) C++ compiler also provides a C interface, you can easily go
this route. Just don't forget to turn off name-mangling by using extern "C".

Jan
Arjen Markus
2006-06-08 11:57:21 UTC
Permalink
Post by n o s p a m p l e a s e
Post by Catherine Rees Lay
There 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
Lynn McGuire
2006-06-08 15:42:17 UTC
Permalink
Post by n o s p a m p l e a s e
What is a good Fortran to C converter?
Cobalt Blue's FOR_C converter http://www.cobalt-blue.com/fc/fcmain.htm
has a very good reputation. I do know people who have used it in the
past for good results.

Lynn

Continue reading on narkive:
Loading...