I have most likely a silly question, and asking perhaps a wrong forum, but don't know where to go. OK, I work with gfortran via ratfor90 (it is a nice little preprocessor for gfortran and fortran90, which is very simple, looks C-like, and has been developed for low-lives like me...) You write a very short ratfor90, then it is translated into full-blown gfortran code, and the calcs go from there... My question: is there an "inverse" translator that takes a full-blown gfortran code and translates it to much shorter and easy readable ratfor90 file?

(Just in case -- my comp is Dell Precision M, ubuntu 14.04, KDE environment...)

  • note, there is f2c for f77 to C. It's neither fortran90 nor ratfor90 but it might be able to extract some control structure out of a fortran program if you massage it a bit first. The effort depends on how big the code you want to back-convert is. – meuh Oct 22 '16 at 21:03
  • Good idea, thanks; I didn't know of f2C, it might be helpful for other purposes, too. My problem, though, is that I need to work with f90, not f77 (and the difference is substantial right where I need the f90 features), and the original codes are big, otherwise I would manage it "by hand" (I hope:-). – Al Kap Oct 23 '16 at 6:50

Someone might have done this as a research project, but

  • that's something like a decompiler (not many of those to discuss), and
  • ratfor doesn't have a lot of developers to begin with.

That said, all that I see in the area is old (which is expected given the two points mentioned):

  • Reverse Compilation Techniques, Cristina Cifuentes, 1994, mentions a program described in B.S. Baker. An algorithm for structuring flowgraphs. Journal of the ACM, 24(1):98–120, January 1977.

    Baker[Bak77] presented an algorithm to structure flowgraph s into equivalent flowgraphs that made use of the following control structures: if..then..else, multilevel break, multilevel next, and endless loops. Gotos were used whenever the graph could not be structured using the previous structures. The algorithm was extended to irreducible graphs as well. It was demonstrated that the algorithm generated well-formed and properly nested programs, and that any goto statements in the final graph jumped forward. This algorithm was implemented in the struct program on a PDP11/54 running under Unix. It was used to rewrite Fortran programs into Ratfor, an extended Fortran language that made use of control structures. The struct program was later used by J.Reuter in the decomp decompiler to structure graphs built from object files with symbol information.

  • Help on disassembler/decompilers, usenet thread in 1990, comment by Mark William Hopkin says

    There is a standard UNIX utility (at least for the 4.3 bsd we're running) that does something just like this: "struct". This utility takes standard Fortran-77 programs and generated from it Ratfor code. Ratfor is a 'rationalized' Fortran that includes all the Algol-derived control structured.

As you can see, both comment on the same program from the 1970s. The comment about 4.3BSD shows that you might find its source online. What I found concludes the manual page with this:

       Struct knows Fortran 66 syntax, but not full Fortran 77.
       If  an  input  Fortran  program contains identifiers which are reserved
       words in Ratfor, the structured version of the program will  not  be  a
       valid Ratfor program.
       The labels generated cannot go above 32767.
       If you get a goto without a target, try −e .

That is, the program was not complete, and (aside from another research project) likely would not do what you need.

  • gosh! it was a lot of research on your part; thanks! It sounds though not very promising... Even ratfor77 was too advanced for STRUCT; I feel it would be hopeless for ratfor90... (ratfor90, same as f90, has dynamic allocations for arrays, and can operate with objects...) But you gave me some pointers, I will try to locate some more advanced projects if any, perhaps trying to reach people you mentioned... ratfor90 isn't that exotic; there is a great community in geo-sciences and atmospheric studies they keep using and advancing it... Thanks again! – Al Kap Oct 22 '16 at 20:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.