In a nutshell, the common conventions are: .f
or .for
for fixed-form source code, .f90
for free-form source code, .F
, .F90
(on UNIX/Linux) for fixed-form or free-form source code that must be preprocessed in a C/C++ like style using Macros, e.g., #define BLAH_BLAH = 42
.
Now, while the notion of a "file extension" is ubiquitous on Windows platforms, other platforms such as UNIX/Linux/Mac OS do not attach any special meaning to the last bit of a file name. In fact, Mac OS doesn't even distinguish between main.f
or MAIN.F
, they are in fact equivalent.
Second, unlike Java, C/C++, Python, etc, there is no concept of a file as an organizational unit for the source code in FORTRAN/Fortran. More specifically, there can be no code outside the program
, subroutine
, function
, or (sub)module
, whence; the ISO Fortran standard itself does not define any extension, it does not even prescribe the use of files on disk to represent the source code. This may seem odd at first, but there are good reasons for this: an operating system might use a database of some sort to store all information in, so if the standard prescribed files on disk as the medium, it would exclude such (pre-command line/terminal) systems.
Generally speaking, the extensions .f90
, .f95
, .f03
, and .f08
are used for modern, free-form source code conforming to the Fortran 90, Fortran 95, Fortran 2003, and Fortran 2008 standards, respectively. For older, fixed-form code, such as FORTRAN 77, the .f
or .for
extensions are typically used.
I highly advise against using the .f95
, .f03
, .f08
file extensions (not to mention .f15
). Not only are these extension not recognized by all compilers, but Fortran 2008 code can be still be written as fixed-form source; it’s still part of that standard.
Therefore, always use *.f90
to indicate free-form source code.