7

I've written a small snippet of code, trying to adhere to the Fortran 2003 standard. The code is available on github.

This is my makefile:

FC = gfortran
FLGS = -g -pg -std=f2003 -I. -fbounds-check
DEPS = camx.prm
OBJ = unit-test-hadvppm.o hadvppm.o

#linker macro
%.o: %.f03 $(DEPS)
        $(FC) -c -o $@ $< $(FLGS)

#build targets

gnu-amd64-linux: $(OBJ)
        $(FC) -o $@ $^ $(FLGS)

clean: gnu-amd64-linux
        rm *.o

The code compiles without a problem using the above makefile and gfortran.

However, if I try to compile it with iFort, using just

ifort -o ifort-amd64-linux unit-test-hadvppm.f03 hadvppm.f03

it doesn't work, see the output below. I suppose that this has to do with the .f03 free file format. Is there a flag in iFort similar to gfortran's -std=f2003 flag? I tried to find this in the iFort Documentation, should I look harder?

enter image description here

vaultah
  • 44,105
  • 12
  • 114
  • 143
seb
  • 2,251
  • 9
  • 30
  • 44
  • 3
    Why not simply rename your files to `*.f90` or `*.F90`? The file ending should be independent of the Standard ;-) I mostly code in Fortran 2003/2008 and *always* use `*.F90` - I had issues with some compilers when using `*.F03` a few years back that disappeared after renaming the files. – Alexander Vogt Nov 28 '13 at 14:54
  • 2
    It may be worth noting that several compilers for Linux (including ifort) by default interpret the `.F90` extension as files to be passed to a preprocessor. Of course, it is a matter of style whether to use just the upper case extension or both. – sigma Jun 20 '14 at 22:20
  • Also see [How to use gfortran for .f90 file extension?](https://stackoverflow.com/q/40034609/608639), [How can gfortran tell if I am compiling f90 or f95 code?](https://stackoverflow.com/q/10884260/608639), [Makefile with different source types](https://stackoverflow.com/q/8940552/608639), [cmake, fortran 2008, and .f08 file extension](https://stackoverflow.com/q/25005017/608639), etc. – jww Jun 12 '17 at 06:24

2 Answers2

15

There is nothing in the standard that specifies the suffix of the files. Intel always stated, that they treat *.f90 as the suffix for the free source format irrespective of the standard version. It is just a convention not based on any standard document.

Maybe the f90 suffix is little unfortunate, looking like just for Fortran 90, but you shouldn't hesitate to use it for every free-format source file.

Personally, I also do not like the practice of .f95,.f03, .f08 files. Should I rename the source file just because I call some intrinsic from a newer standard?

  • If there is no standard and I am not using intel's fortran compiler, then does this matter? It seems questionable to take one compiler's conventions and treat them as language specification. – Joshua Cheek Oct 02 '16 at 20:52
  • Why not just use `.f` suffix? Note that when I do this, it requires me to have 7 spaces in front of every line, so it would seem that the suffixes tell the compiler which features to turn on, which is a pretty good argument for `.f08` suffix. – Joshua Cheek Oct 02 '16 at 20:54
  • The point is that all compilers support .f90, why use anything else? f90 is not Fortran 90, it is free source form. I hope people won't come with f15 files now... – Vladimir F Героям слава Oct 02 '16 at 20:55
  • So, my compiler, gfortran (part of gcc), will behave the same for `.f90` and `.f08`? – Joshua Cheek Oct 02 '16 at 20:57
  • @JoshuaCheek .f is fixed source form, .f90 is free source form. Keep it simple. Yes gfortran supports many suffixes, but f90 is de-facto standard. The portability is why Fortran is still here after 60 years. Fixing to one compiler is directly against that. – Vladimir F Героям слава Oct 02 '16 at 20:58
  • And yes, @JoshuaCheek, your compiler should treat `.f90` files *exactly* the same as `.f08` files - all free form source. `.f` files are special - they indicate fixed, as mentioned. – Ross Aug 18 '19 at 01:20
5

You can specify the source form used in a source file using the -free and -fixed ifort command line options, for free and fixed form respectively.

As a separate issue, you can set the standard to issue diagnostics against using the -stand[:xxx] option. This doesn't change the code generated by the compiler, it just changes the diagnostics that the compiler issues. This is the equivalent of gfortran's -std=xxx option.

As another separate issue, you can specify that the compiler should change its behaviour to match that specified using the Fortran standard using the -standard-semantics compiler option. This covers scenarios where the compiler's behaviour historically was different from what the Fortran standard has ended up requiring or recommending.

As recommended in the comments and Vladimir's answer - the easiest option is to just use .f90 for any free form source file (which will be treated as free form source by ifort in the absence of the -fixed command line option), regardless of the standard that it has been written to.

IanH
  • 21,026
  • 2
  • 37
  • 59