Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can gfortran tell if I am compiling f90 or f95 code?

I understand gfortran can compile f90 or f95? How does it know which one it is compiling? Also can it compile f77 code? Does ubuntu already have a fortran compiler or do I need to download gfortran?

like image 223
ilyas patanam Avatar asked Jun 04 '12 15:06

ilyas patanam


1 Answers

gfortran can guess certain things from the file extension; if the file has an extension of .f, .f90, f95, .f03, or .f08 it will assume fixed (.f) or free format with the appropriate standards. But you can force it to compile (say) fortran2003 code with the option -std=f2003. Eg, from the documentation,

-std=std

Specify the standard to which the program is expected to conform, which may be one of f95, f2003, f2008, f2018, gnu, or legacy. The default value for std is gnu, which specifies a superset of the latest Fortran standard that includes all of the extensions supported by GNU Fortran, although warnings will be given for obsolete extensions not recommended for use in new code. The legacy value is equivalent but without the warnings for obsolete extensions, and may be useful for old non-standard programs. The f95, f2003, f2008, and f2018 values specify strict conformance to the Fortran 95, Fortran 2003, Fortran 2008 and Fortran 2018 standards, respectively; errors are given for all extensions beyond the relevant language standard, and warnings are given for the Fortran 77 features that are permitted but obsolescent in later standards. -std=f2008ts allows the Fortran 2008 standard including the additions of the Technical Specification (TS) 29113 on Further Interoperability of Fortran with C and TS 18508 on Additional Parallel Features in Fortran.

Note that, with a few exceptions, the fortran standards are highly backwards-compatable, so that much "nice", standard conforming, fortran-77 code is also valid fortran 2003 code. The main problem with that is that much fortran code from the 80s and earlier is neither "nice" nor standard-conforming.

like image 153
Jonathan Dursi Avatar answered Sep 20 '22 15:09

Jonathan Dursi