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

时光总嘲笑我的痴心妄想 提交于 2019-11-28 06:35:27
Jonathan Dursi

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.

Yes, gfortran can compile FORTRAN 77 and Fortran 90,95 etc. It has many features of 2003 & 2008 implemented. For Fortran 90/95/2003/2008 code a good extension to use is .f90. Some other compilers don't recognize .f95, .f2003, etc. And do you really want to rename your files when a new standard comes out? Use .f or .for for FORTRAN 77. The main difference is the source layout that the compiler will expect: free form for .f90, fixed form for .f or .for. (Upper-case filetypes will cause the preprocessor to be run.) You can force fixed-form layout with the options -ffixed-form -ffixed-line-length-none.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!