Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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
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.
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,800
Rep:
Quote:
Originally Posted by bsdaemon
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).
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...
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.