LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Fortran to C Translation (https://www.linuxquestions.org/questions/linux-software-2/fortran-to-c-translation-4175659622/)

bsdaemon 08-22-2019 04:45 PM

Fortran to C Translation
 
Is anyone aware of a FOSS DEC Fortran to Gnu C translator?


I have the source code for the FCC's old Engineering Database, originally written in Fortran, for the VAX.
The Commission converted to a Sybase platform, and used an
(expensive) proprietary Fortran to C translator. The new system has neat features, like method of moments antenna analysis, but the price of the converter is beyond solo engineering practices.


Any ideas?


Thanks!
bsD

flshope 08-22-2019 08:35 PM

I use gfortran all the time. It is my understanding that the fortran code is converted to C code and then compiled with gcc. I'll see if I can find out more about this and report back. Gotta go for now.

bsdaemon 08-22-2019 10:06 PM

Thanks! :hattip:

flshope 08-23-2019 01:29 PM

Well, so far, in reading the gfortran documentation, I have not found anything (like a compiler option) to generate an intermediate file containing the C code. Documentation for gfortran is located at https://gcc.gnu.org/onlinedocs/ or, if you have gfortran installed, the command

Code:

gfortran --target-help|less
generates a lot of stuff.

ehartman 08-23-2019 04:37 PM

Quote:

Originally Posted by flshope (Post 6028434)
I use gfortran all the time. It is my understanding that the fortran code is converted to C code and then compiled with gcc.

No, it is converted to gcc "intermediate" code (low level) and then put through the backend of gcc (just like gcc itself does for C-code).
All the compilers of the gcc suite (g++, gnat, go, objc, etc) work that way: the FRONTend is language specific, the backend is common. So there's no real translating between languages, everything is compiled into this intermediate language.

PS: the backend is architecture specific, there's one for Intel (x86), for ARM, etc.

BTW: there is a "f2c" program, but that's for (the first version of) Fortran/77, not newer specs.
See for that en.wikipedia.org/wiki/F2c and www.netlib.org/f2c/

rnturn 08-23-2019 07:09 PM

Quote:

Originally Posted by bsdaemon (Post 6028385)
Is anyone aware of a FOSS DEC Fortran to Gnu C translator?


I have the source code for the FCC's old Engineering Database, originally written in Fortran, for the VAX.

Any ideas?

I got a hold of a MS-DOS-based demo for a FORTRAN->C conversion tool from Cobalt Blue back, shees, probably thirty years ago. I don't think they're in business any more, though. (I'm almost certainly still have it floating around on a floppy somewhere but would likely take forever to locate---long story.) The demo was limited in what it could do -- only so many lines of code it would take, etc. -- however fiddling with it for a while with some smaller programs showed me what needed to be done to turn FORTRAN-IV/F77 to C and I found it just as easy to do the translations myself---easy enough to convert a sizable amount of VAX FORTRAN to C. Once you get the hang of it, it's not difficult to convert by hand. I got good enough at it that I was able to convert a bunch of my own so-called "legacy" code from work, some old NASA software from their COSMIC library, and even find a few paying projects doing conversions.

Have you found any recent demos for commercial products that might work? Yes, they may be handcuffed in much the same way as the Cobalt Blue demo I used but it might get you started down the path of converting it yourself. I say that not having any idea how many lines of code you're faced with converting. (Sounds like it might be a lot.) It's not quick to do yourself but far from impossible.

If you can find a gfortran switch that creates/saves the intermediate C code (I haven't found one yet) I do recall from back in my PDP-11 days that intermediate code output can be about the ugliest code you can imagine. At least the output of the IFTRAN translator we used on RSX-11 surely was. The FORTRAN-IV created from the IFTRAN "structured programming" sources was almost unreadable (and the resulting MACRO-11 was even worse).

Good luck...

rnturn 08-23-2019 07:33 PM

Quote:

Originally Posted by ehartman (Post 6028757)
BTW: there is a "f2c" program, but that's for (the first version of) Fortran/77, not newer specs.
See for that en.wikipedia.org/wiki/F2c and www.netlib.org/f2c/

I'd forgotten about that tool. The OP's code was in VAX FORTRAN so f2c might be just the ticket. I just tried it on a simple "Hello, World" program
Code:

      program hello

      write (*, 10)
 10  format('Hello, world!')

      stop
      end

and the resulting C code doesn't look much like something I'd want to maintain. I can't imagine what the output looks like for a complex FORTRAN source file. Of course, different strokes...

Cheers...

flshope 08-24-2019 10:21 AM

ehartman: Thank you for setting me straight on that. I don't know where I got the idea.

I see that f2c is still in the Debian repository:

Code:

apt list --all-versions|grep f2c
which gives

Code:

f2c/oldstable 20100827-3 amd64
The command

Code:

apt show f2c/oldstable
gives

Code:

Package: f2c
Version: 20100827-3
Priority: optional
Section: devel
Maintainer: Barak A. Pearlmutter <bap@debian.org>
Installed-Size: 443 kB
Depends: libc6 (>= 2.14), libf2c2-dev
Recommends: gcc
Suggests: fort77
Homepage: http://www.netlib.org/f2c/
Tag: devel::compiler, devel::lang:fortran, interface::commandline,
 role::program, scope::utility, use::converting,
 works-with::software:source
Download-Size: 248 kB
APT-Sources: http://ftp.us.debian.org/debian stretch/main amd64 Packages
Description: FORTRAN 77 to C/C++ translator
 Translates FORTRAN 77 (with some extensions) into C, so that it can
 then be compiled and run on a system with no Fortran compiler.  The C
 files must then be linked against the appropriate libraries.
 .
 This is an actively maintained FORTRAN to C translator and with the
 fort77 frontend provides an ideal way to compile FORTRAN routines
 as black boxes (for example for invocation from C).  Source level
 debugging facilities are not available, and error messages are not as
 well developed as in g77.


bsdaemon 08-25-2019 04:13 PM

Busy li'l daemon...
 
First, thanks to all for pointing me in the right direction on this code conversion project! It looks like f2c may be just what I've been looking for. Not that it's going to be a panacea...I snarfed the source this morning, and built it on wintermute (my Slackware development box), and tried converting a couple of subroutines with it.
It took a few bites of old DEC Fortran, and acted like a cat with a VERY large hairball. <cough>..<HeAvE!!>...AACCCKKKKKKKKKKKK!!!!! (plop!).

As I said in an earlier post, this old app is loaded with poor syntax, uncommented kludges, and computed GO TO's , which make f2c shit kittens. So I'm cobbling together some perl to clean the cruft up, and as it's not the fastest thing I've seen, and I don't want to tie up a production box with this, I'm going to move everything over to the Octane2, and just let it run.

I may have something fit to feed GCC++ by next weekend. :party:

Cheers!

BS.d


All times are GMT -5. The time now is 10:22 AM.