LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This 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


Reply
  Search this Thread
Old 08-22-2019, 04:45 PM   #1
bsdaemon
LQ Newbie
 
Registered: Aug 2019
Location: The People's Republic of Boulder, CO
Distribution: Slackware 14.2
Posts: 18
Blog Entries: 2

Rep: Reputation: Disabled
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
 
Old 08-22-2019, 08:35 PM   #2
flshope
Member
 
Registered: Jul 2009
Location: Tennessee (United States)
Distribution: Debian 11.6, Ubuntu 22.04.2, 18.04.6, Android 11
Posts: 236
Blog Entries: 44

Rep: Reputation: 80
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.
 
1 members found this post helpful.
Old 08-22-2019, 10:06 PM   #3
bsdaemon
LQ Newbie
 
Registered: Aug 2019
Location: The People's Republic of Boulder, CO
Distribution: Slackware 14.2
Posts: 18

Original Poster
Blog Entries: 2

Rep: Reputation: Disabled
Thanks!
 
Old 08-23-2019, 01:29 PM   #4
flshope
Member
 
Registered: Jul 2009
Location: Tennessee (United States)
Distribution: Debian 11.6, Ubuntu 22.04.2, 18.04.6, Android 11
Posts: 236
Blog Entries: 44

Rep: Reputation: 80
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.
 
1 members found this post helpful.
Old 08-23-2019, 04:37 PM   #5
ehartman
Senior Member
 
Registered: Jul 2007
Location: Delft, The Netherlands
Distribution: Slackware
Posts: 1,674

Rep: Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888
Quote:
Originally Posted by flshope View Post
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/
 
4 members found this post helpful.
Old 08-23-2019, 07:09 PM   #6
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,800

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Quote:
Originally Posted by bsdaemon View Post
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...
 
2 members found this post helpful.
Old 08-23-2019, 07:33 PM   #7
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,800

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Quote:
Originally Posted by ehartman View Post
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...
 
1 members found this post helpful.
Old 08-24-2019, 10:21 AM   #8
flshope
Member
 
Registered: Jul 2009
Location: Tennessee (United States)
Distribution: Debian 11.6, Ubuntu 22.04.2, 18.04.6, Android 11
Posts: 236
Blog Entries: 44

Rep: Reputation: 80
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.
 
1 members found this post helpful.
Old 08-25-2019, 04:13 PM   #9
bsdaemon
LQ Newbie
 
Registered: Aug 2019
Location: The People's Republic of Boulder, CO
Distribution: Slackware 14.2
Posts: 18

Original Poster
Blog Entries: 2

Rep: Reputation: Disabled
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.

Cheers!

BS.d
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Curl to get word translation (wordnet) and translation from CLI? Xeratul Linux - General 3 05-24-2012 12:21 PM
g77 in gcc 4.1.0 not found only gfortran fortran 95 compiler! I need fortran 77. TheBrick Linux - Software 3 07-04-2007 06:39 AM
Gnu Fortran versus Intel Fortran tomatoefish Linux - Software 3 02-20-2006 01:31 PM
does linux fortran compiler in fedora 4 support VAX FORTRAN? terrence Programming 17 08-31-2005 08:59 AM
IP address translation? mikeshn Linux - Software 5 05-25-2002 05:51 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration