convert 'C' code to 'Fortran'

S

sam

Hi,
Can anyone help me find a software that can convert a code in 'C'
to 'Fortran77/90' automatically?

Thanks in advance.

Sam.
 
J

john blackburn

sam said:
Hi,
Can anyone help me find a software that can convert a code in 'C'
to 'Fortran77/90' automatically?

Thanks in advance.

Sam.

Wow, - good luck :)
 
M

Michael Mair

sam said:
Hi,
Can anyone help me find a software that can convert a code in 'C'
to 'Fortran77/90' automatically?

This is not really on-topic.
However, there is a slightly more topical version: Why fix something
that is not broken?
C modules can communicate with fortran modules.
Now the problem is just how to fit the two together.
Google for "mix fortran and C". It basically comes down to
providing interfaces, creating the right headers and intelligent
makefiles.

Cheers
Michael
 
G

Gordon Burditt

Can anyone help me find a software that can convert a code in 'C'
to 'Fortran77/90' automatically?

Good luck. You'll need it. C concepts like pointers don't
translate very well into FORTRAN.

Gordon L. Burditt
 
D

Default User

sam said:
Hi,
Can anyone help me find a software that can convert a code in 'C'
to 'Fortran77/90' automatically?


This is off-topic for this newsgroup. However, I suggest using a search
engine for f2c.



Brian
 
T

Tim Prince

Tak-Shing Chan said:
That is in the wrong direction...
So you can use it to check your result, in the unexpected case that the
original C code fell within the subset of C used by f2c, and your OS gets
along with the f2c conventions.
 
C

Chris Barts

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Michael Mair wrote:
| sam wrote:
|
|> Hi,
|> Can anyone help me find a software that can convert a code in 'C'
|> to 'Fortran77/90' automatically?
|
|
| This is not really on-topic.
| However, there is a slightly more topical version: Why fix something
| that is not broken?

Maybe because the Fortran compiler's optimization is better than the
platform's C compiler. Or to make calling the code from Fortran easier.
Or a small number of other possible reasons.

Obviously, going the other way is a lot more common. The Fortran FAQ
I'll link to later says that there aren't any tools to automate the c2f
conversion.

| C modules can communicate with fortran modules.

True, but it isn't always easy. There are more issues involved in this
than I'll go into here, but there is a (long) discussion of it at
section 3.1.3 of the Fortran FAQ at this address:

~ http://www.faqs.org/faqs/fortran-faq/

| Now the problem is just how to fit the two together.

And it is, indeed, a problem. ;)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFBkxGaKxatjOtX+j0RArp4AJ9kXvMBB1BHuetZobFJS5bB9iwkCwCeOCdR
GpWhVHxh1RLZn/JHtRI+rkk=
=Z1NT
-----END PGP SIGNATURE-----
 
M

Michael Mair

Chris said:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Michael Mair wrote:
| sam wrote:
|
|> Hi,
|> Can anyone help me find a software that can convert a code in 'C'
|> to 'Fortran77/90' automatically?
|
|
| This is not really on-topic.
| However, there is a slightly more topical version: Why fix something
| that is not broken?

Maybe because the Fortran compiler's optimization is better than the
platform's C compiler. Or to make calling the code from Fortran easier.
Or a small number of other possible reasons.

Well, as the OP did not give a _good_ reasons, I assumed (s)he was not
aware of this way.

Obviously, going the other way is a lot more common. The Fortran FAQ
I'll link to later says that there aren't any tools to automate the c2f
conversion.

Yep, this I know. I would rather go for the f2c but the OP seemed
to want to have Fortran.
| C modules can communicate with fortran modules.

True, but it isn't always easy. There are more issues involved in this
than I'll go into here, but there is a (long) discussion of it at
section 3.1.3 of the Fortran FAQ at this address:

~ http://www.faqs.org/faqs/fortran-faq/

| Now the problem is just how to fit the two together.

And it is, indeed, a problem. ;)

*g* Maybe.
Up to now, I only had the dubious pleasure of getting F77 code
to work together with C code, always the C code calling -- and
this went always straight by recipe.

Thanks for the additional information :)
Michael
 
B

beliavsky

Chris Barts said:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Michael Mair wrote:
| sam wrote:
|
|> Hi,
|> Can anyone help me find a software that can convert a code in 'C'
|> to 'Fortran77/90' automatically?
|
|
| This is not really on-topic.
| However, there is a slightly more topical version: Why fix something
| that is not broken?

Maybe because the Fortran compiler's optimization is better than the
platform's C compiler. Or to make calling the code from Fortran easier.
Or a small number of other possible reasons.

Obviously, going the other way is a lot more common. The Fortran FAQ
I'll link to later says that there aren't any tools to automate the c2f
conversion.

That FAQ at http://www.faqs.org/faqs/fortran-faq/
is almost 8 years old and is thus out of date. The OP posted the same
message to comp.lang.fortran (a breach of etiquette), where I
mentioned a Fortran 90 program C2F at
http://home.cfl.rr.com/davegemini/c2f.f90 as a PARTIAL translator from
C to Fortran. I earlier wrote about it at
http://groups.google.com/[email protected]&rnum=1
..

The c.l.f crowd agrees with the c.l.c crowd that translation (as
opposed to linking) is probably not the way to go.
 
K

Keith Thompson

Chris Barts said:
Michael Mair wrote:
|> Can anyone help me find a software that can convert a code in 'C'
|> to 'Fortran77/90' automatically?
|
| This is not really on-topic.
| However, there is a slightly more topical version: Why fix something
| that is not broken?

Maybe because the Fortran compiler's optimization is better than the
platform's C compiler. Or to make calling the code from Fortran easier.
Or a small number of other possible reasons.

I'm skeptical that optimization is a good reason to convert C to
Fortran. Leaving pointer issues aside (and I think recent versions of
Fortran have something similar to pointers), automatically generated
Fortran is likely to be ugly and difficult to optimize.

If you want to be able to maintain the Fortran code, the best tool for
the job is probably a programmer who knows both C and Fortran and is
willing to do it for what you can afford to pay.
 
D

Dan Pop

In said:
Can anyone help me find a software that can convert a code in 'C'
to 'Fortran77/90' automatically?

Converting from a lower level language to a higher level language is
seldom possible. Only a subset of C could be converted to Fortran
automatically.

The comp.lang.fortran FAQ might have some pointers.

Dan
 
D

Dan Pop

In said:
I'm skeptical that optimization is a good reason to convert C to
Fortran. Leaving pointer issues aside (and I think recent versions of
Fortran have something similar to pointers),

Not quite. It's similar to Pascal pointers: you can't perform pointer
arithmetic on them.
automatically generated
Fortran is likely to be ugly and difficult to optimize.

Ugly to the human eye doesn't necessarily imply difficult to optimize for
the Fortran compiler. It is basically the strict aliasing rules of
Fortran that allow Fortran optimisers to be (significantly) more
aggressive than C optimisers.

Dan
 
J

John Bode

Hi,
Can anyone help me find a software that can convert a code in 'C'
to 'Fortran77/90' automatically?

Thanks in advance.

Sam.

This is why God created interns.
 
D

Dan Pop

In said:
This is not really on-topic.
However, there is a slightly more topical version: Why fix something
that is not broken?
C modules can communicate with fortran modules.
Now the problem is just how to fit the two together.
Google for "mix fortran and C". It basically comes down to
providing interfaces, creating the right headers and intelligent
makefiles.

The real problem is that the solution is not portable. The details of
interfacing C and Fortran are highly system specific. Everything could
just work by "magic", as was the case under VAX/VMS, but many other
platforms require the C code to have inside knowledge about the workings
of the Fortran compiler and/or vice versa.

The best attempt at hiding these details was made by the cfortran.h
project: http://www-zeus.desy.de/~burow/cfortran/

IIRC, it is only the last Fortran standard that addresses the issue.

Dan
 
J

john blackburn

Keith said:
I'm skeptical that optimization is a good reason to convert C to
Fortran. Leaving pointer issues aside (and I think recent versions of
Fortran have something similar to pointers), automatically generated
Fortran is likely to be ugly and difficult to optimize.

If you want to be able to maintain the Fortran code, the best tool for
the job is probably a programmer who knows both C and Fortran and is
willing to do it for what you can afford to pay.

If he does it himself, it will be a good way to learn Fortran ?
 
L

Lawrence Kirby

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Michael Mair wrote:
| sam wrote:
|
|> Hi,
|> Can anyone help me find a software that can convert a code in 'C'
|> to 'Fortran77/90' automatically?
|
|
| This is not really on-topic.
| However, there is a slightly more topical version: Why fix something
| that is not broken?

Maybe because the Fortran compiler's optimization is better than the
platform's C compiler.

However the comparison isn't between the Fortran compiler's optimiser and
rhe C compiler's optimiser, it is between the C compiler's optimiser and
the combined effects of the 2 compilers' translations. C compilers can
be pretty good at optimising C code. That can still result in slower code
than a Fortran compiler compiling Fortran code because the C language
semantics can be harder to optimise. A C to F compiler will have to
preserve the C language semantics of the code it translates and probably
generate pretty nasty Fortran code as a result. It is a reasonable bet
that a Fortran compiler will be less good at optimising C language
semantics than a C compiler, especially from an intermediate language that
doesn't express those semantics naturally.

Lawrence
 
K

Keith Thompson

The real problem is that the solution is not portable. The details of
interfacing C and Fortran are highly system specific. Everything could
just work by "magic", as was the case under VAX/VMS, but many other
platforms require the C code to have inside knowledge about the workings
of the Fortran compiler and/or vice versa.

C doesn't define an interface to Fortran, but Ada defines interfaces
to both C and Fortran, so one solution might be to write the main
program in Ada. (Assuming an Ada compiler is available on the system,
and that it defines interfaces to the particular C and Fortran
implementations.)
 
D

Dan Pop

In said:
(e-mail address removed) (Dan Pop) writes:
[...]
The real problem is that the solution is not portable. The details of
interfacing C and Fortran are highly system specific. Everything could
just work by "magic", as was the case under VAX/VMS, but many other
platforms require the C code to have inside knowledge about the workings
of the Fortran compiler and/or vice versa.

C doesn't define an interface to Fortran, but Ada defines interfaces
to both C and Fortran, so one solution might be to write the main
program in Ada. (Assuming an Ada compiler is available on the system,
and that it defines interfaces to the particular C and Fortran
implementations.)

It's not the main program you want to write in Ada, but the interface
between the C and the Fortran code. I.e. if the Fortran code needs to
call a C function, provide an Ada wrapper that is Fortran callable and
that knows how to call the C function. Then again, it is not clear how
portable the solution would be in the real world (see your own
parenthetical remark).

Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top