Question

I'm a bloody beginner in Fortran.

I wonder: what is the difference between the .f and .F extensions of Fortran files. I know that much: f is for free and F is for fixed.

What do free and fixed actually mean and why can they totally screw up the compilation process? (I'm using gfortran and ifort).

I've googled fortran difference between f and F extension. I wasn't happy with the outcome, which is why I turn to stackoverflow.

If you could suggest a good reference to read up on this, I'd be very happy to do so.

Was it helpful?

Solution

As far as I know, .f and .F are both extensions associated with the FORTRAN 77 fixed format. Fixed format is limitted to 72 columns, where the first six columns serve special purposes. E.g. a & at position 6 indicates a line continuation from the previous line.

Free-form was introduced with Fortran 90 and is typically indicated by .f90 and .F90. For free-form you can use up to 132 columns, and no special columns exist. Line continuation is indicated by an ampersand at the end of the line.

Capital letters in the file extension usually turn the pre-processor on.

Note that these are conventions that can be overridden with compile options for most compilers.

OTHER TIPS

This is compiler dependent and should maybe not relied on. Usually capital suffixes indicate, that pre-processing should be used. The distinction between free and fixed format is usually made by .f90 (free) vs. .f (fixed).

As this is compiler dependent, a good documentation would be the one of your compiler. If you happen to use gfortran, you might have a look at its options and the section on preprocessing.

In gfortran, free-form (no special meaning for cols 7, 72) is set by the compiler switch -ffree-form and has nothing to do with .f or .F file suffixes. The difference between .f and .F is that the latter goes through a pre-processor, the most common use of which is allowing C-like #define statements. For example:

#define MAXN 100
program example
integer N(MAXN)
end

will compile if it is .F but not if it is .f

The capital F denotes that a C-like compiler should be used.

http://fortranwiki.org/fortran/show/File+extensions

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top