Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fortran: difference between f and F extension

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.

like image 262
seb Avatar asked Nov 02 '13 15:11

seb


People also ask

What is F extension?

The F file extension usually refers to the text files that have the source codes for the FORTRAN computer programming language. FORTRAN is a general-purpose, procedural programming language commonly used for general numeric and scientific computation purposes.

What is .F file in Fortran?

f the Fortran development programs. The content . f a Fortran source code file is encoded and compiled using F format specifications and standards. The data contained in an F file includes source codes and other application details that correspond to a program developed using the Fortran programming language.

What is an f90 file?

Source code file written in the Fortran 90 (F90) language, a programming language suitable for numerical and scientific computing; often edited with text editors that provide syntax highlighting; can be a program module or an entire program.


3 Answers

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.

like image 88
Alexander Vogt Avatar answered Nov 22 '22 08:11

Alexander Vogt


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.

like image 29
haraldkl Avatar answered Nov 22 '22 09:11

haraldkl


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

like image 21
Ambar Chatterjee Avatar answered Nov 22 '22 09:11

Ambar Chatterjee