Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting FORTRAN to C / C++

As part of my Final Year Project, I need to convert some FORTRAN code into C or C++ (it doesn't matter which language as long as I can understand it, and I can understand C style languages).

I have discovered f2c, a program that allegedly converts FORTRAN to C, and tried to install it, following instructions, by saving a makefile.vc file on my drive and then doing

copy makefile.vc makefile
nmake

(here is the part of the README file about installing f2c that is included in the f2c download page)

To compile f2c on Linux or Unix systems, copy makefile.u to makefile, edit makefile if necessary (see the comments in it and below) and type "make" (or maybe "nmake", depending on your system).

To compile f2c.exe on MS Windows systems with Microsoft Visual C++,

copy makefile.vc makefile nmake

With other PC compilers, you may need to compile xsum.c with -DMSDOS (i.e., with MSDOS #defined).

If your compiler does not understand ANSI/ISO C syntax (i.e., if you have a K&R C compiler), compile with -DKR_headers .

On non-Unix systems where files have separate binary and text modes, you may need to "make xsumr.out" rather than "make xsum.out".

I am running x64 bit version of Windows Vista and tried "nmake", but I get

'nmake' is not recognised as an internal or external command, operable program or batch file.

I downloaded Nmake15.exe after some searching but it doesn't work on x64 bit machines and apparently there is not version of it that does. So I downloaded the Windows SDK, after being told that would work, but it didn't change anything.

Where have I gone wrong in all this, if I have, and is there any way of converting that FORTRAN code into C or C++?

like image 755
OddCore Avatar asked Nov 30 '10 13:11

OddCore


1 Answers

I found there is a small toolkit named fable fable - Automatic Fortran to C++ conversion which is dedicated to such conversion.

THere is also a review of such a tool. Abstract from the review authors:

Background

In scientific computing, Fortran was the dominant implementation language throughout most of the second part of the 20th century. The many tools accumulated during this time have been difficult to integrate with modern software, which is now dominated by object-oriented languages.

Results

Driven by the requirements of a large-scale scientific software project, we have developed a Fortran to C++ source-to-source conversion tool named FABLE. This enables the continued development of new methods even while switching languages. We report the application of FABLE in three major projects and present detailed comparisons of Fortran and C++ runtime performances.

Conclusions

Our experience suggests that most Fortran 77 codes can be converted with an effort that is minor (measured in days) compared to the original development time (often measured in years). With FABLE it is possible to reuse and evolve legacy work in modern object-oriented environments, in a portable and maintainable way. FABLE is available under a nonrestrictive open source license. In FABLE the analysis of the Fortran sources is separated from the generation of the C++ sources. Therefore parts of FABLE could be reused for other target languages.

like image 139
LCFactorization Avatar answered Sep 24 '22 21:09

LCFactorization