After I installed Gfortran in Ubuntu (16.04) is pointing to f95. I see in gfortran manual that -std option can be given for f95 and forward. The default -std
option value I see from manual is "gnu". I am not sure of implications of internals of compiling if I use f95 for f90 code.
How do I use gfortran for Fortran 90 files with .for extension? I do not want to use Fortran 95 compiler for Fortran 90 code though Fortran 95 might be able to (not sure) compile Fortran 90.
Fortran 90 is dead. It had serious deficiencies, especially with allocatables, that were fixed by Fortran 95. For example, it allowed existence of undefined allocation ststus.
Many times someone says he is using Fortran 90 he is in fact using something else.
Fortran 90 and Fortran 95 are so close that there is even no option to enable Fortran 90 in compilers. It would mostly just enable those errors and oversights in the standard and disable just a few features.
Gfortran, in the default mode gnu
is actually close to a Fortran 2003 or 2008 compiler. Some of the default settings are different from Fortran 90 and 95. For example the automatic re-allocation on assignment. But it is normally good for programs in Fortran 90 and 95 and even some in 77. It enables certain common extensions to the standard. Certsin less common extensions can be enabled by special flags.
There is no reason to worry. Fortran 95 is the standard people should care about. Fortran 90 is not.
Regarding the .for extension, the compiler should process correctly if it is conforming fixed form source, be it 77, 90, 95, 2008, whatever.
The differences between f90
and f95
are really minor, but with the extension .for
or .f
, gfortran expects the code to be in fixed-form.
Try adding the -ffree-form
option to the compiler.
That said, I'd recommend to have the file extension .f90
for free-form Fortran code. It will make things much easier in the long run.
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.