Modernizing Fortran Code: Transitioning to Fortran 90+

I’m currently working with legacy Fortran code, and I’m interested in modernizing it to take advantage of the features and improvements introduced in Fortran 90 and later versions. The existing codebase is written in Fortran 77 and contains many outdated practices.

My goal is to make the code more maintainable, readable, and potentially more efficient by adopting modern Fortran standards. However, I’m not sure where to start and what common pitfalls to watch out for.

Could experienced Fortran developers provide guidance on the steps involved in transitioning from Fortran 77 to Fortran 90+? Are there specific language features or coding patterns that I should focus on incorporating or avoiding? Additionally, are there tools or best practices for ensuring a smooth transition and minimizing potential issues? Any insights or code examples would be greatly appreciated. Thank you!

I would suggest you first change the build system to FPM, second add as many as necessary tests in FPM to be able to detect possible bugs during modernization of the code.

1 Like

This work by @Arjen might be of help:

Also, if you work with gfortran, you can play by switching on/off this option -std=legacy. When using it you will be able to compile your old codes, when turning it off, you’ll have a bunch of compile-time errors, It does help to catch certain things.

As @alirezagh76 suggested, Isolating a copy with fpm to play around is certainly a very good idea!! I did that once to modernize a library and it did help. The test base is definitely the most important part.

1 Like

See: Tools for refactoring legacy codes

1 Like

I think that the first step is to make a regression test. If you are going to make systematic changes you need to know that you haven’t broken anything :wink:

fpt (http://simconglobal.com ) will probably do a large part of what you want. It will change the code to free format, pretty-print it, and reprogram many legacy constructs. We are currently working on a system to move COMMON blocks into modules.

1 Like