Convert Fortran to C or C ++

I have a numeric code that I need to convert to C or C ++. I tried using f2c, but it will not work with Fortran code. f2c complains because the code uses C-style preprocessor directives (#include). The readme code states that it is Fortran77, which works with the fort77 linker, which will extend them.

Does anyone know how to successfully convert this code?

My last resort is to write a simple preprocessor to extend these inclusions, and then submit the code to f2c.

Note. I work in a Windows / Visual C ++ environment here, so any gcc-shenanigans will probably have more problems than they are worth it ...

+3
source share
4 answers

This may be to go a little on a limb, but you thought that since you are probably using C-style, can you actually run the C preprocessor in a file to include these files? Then you can take this output and run it through f2c.

(I am not an expert on this. Please reduce this if necessary.)

+8
source

I worked for many years in an engineering research group. We never managed to do automatic conversions from Fortran to C. The code was not particularly clear, and it was difficult to maintain. Our best luck was using Fortran code as a template for the algorithm and reimplementing everything we expected to continue to use. In addition, you can upgrade Fortran to use more modern Fortran constructs and get much the same value as when you migrated to C / C ++. We also had some success that called Fortran subroutines from C, although sometimes calling conventions sometimes made things difficult.

+8
source

You may be able to manually convert

#include "whatsit.f90"

to

INCLUDE 'whatsit.f90'

and then try converting f2c again.

+7
source

Don't have a pre-processor? Unix may have a separate cpp program that will accept Fortran with #include directives and convert them to Fortran without #include directives. Alternatively, you can rename the source from xyz.f77 ( xyz.f ) to xyz.c , then run the C compiler only in "pre-processor-only" mode and grab the output as new input to the f2c program. You may need to worry about options that eliminate #line directives on output, etc., or you might be better off working with output through a simple filter ( sed or perl spring).

+4
source

All Articles