An automated tool for upgrading Fortran codes

5 Likes

@milancurcic Thanks to the shape of the flow scheme .and. title of the publication, this is identified as link to the same publication mentioned by @vmagnin (2022-08-14) in the thread «resistance to modernization».

1 Like

CAUTION: Make sure that you have a backup of any Fortran source files that you expose to this tool.

Out of curiosity, I obtained the source files (in Python) to this tool and tested it. There are no instructions on how to use the tool, and the text of the associated paper suggests that it is intended to be used together with the Intel Fortran compiler on Windows, since it looks for the buildlog.htm file that is produced by a build attempt using Ifort in Visual Studio.

It turns out that the tool can be used by itself as long as Python is available. It scans all the Fortran source files in the current directory and attempts to “modernize” them. Unfortunately, it overwrites the original files that it scans with the “corrected” version, and royally mangles the source code in the process.

For the 30 line file sample.for at https://github.com/LMAK00/FordADT/tree/master/data , all that it does is to combine the two separate declarations of variables into one.

For the second test file that I used, downloaded from, https://archimede.dm.uniba.it/~testset/src/problems/beam.f , the result was a disaster. The input file contains a number of external subroutines, all Fortran 77. One of these subroutines:

      integer function pidate()
      pidate = 20060828
      return
      end

is transformed to

      INTEGER function pidate(),
     &neqn,ndisc,mljac,mujac,mlmas,mumas,ind(*),neqn,i,neqn ,
     &neqn, nindsol,indsol(neqn),ierr,ipar(*),ldim,neqn,ierr,ipar(*),
     &ldim,neqn,ierr,ipar(*),neqn
      pidate = 20060828
      return
      end

The spurious variables have leaked in from other subprograms in the same source file. Another subroutine, originally containing these lines

      subroutine init(neqn,t,y,yprime,consis)
      integer neqn
      double precision t,y(neqn),yprime(neqn)
      logical consis
      integer i
      do 10 i=1,neqn
         y(i) = 0d0
   10 continue
      return
      end

becomes

      subroutine init(neqn,t,y,yprime,consis)
      do 10 i=1,neqn
         y(i) = 0d0
   10 continue
      return
      end

I am curious to learn if any readers of this forum successfully used the tool to improve any non-trivial Fortran source code.

3 Likes

The project description (section 1.4 in the publication) clearly mentions

«The project is written in Python which checks for certain pattern matches ...»

and the “language bar” on GitHub states 99%+ of the project’s data is recognized as Python. While I have no experience (yet) to share with this program, I invited the authors of FordDAT to join the discussion.