gfortran如何告诉我是否正在编译f90或f95代码? [英] How can gfortran tell if I am compiling f90 or f95 code?

查看:860
本文介绍了gfortran如何告诉我是否正在编译f90或f95代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道gfortran可以编译f90或f95吗?它如何知道它正在编译哪一个?也可以编译F77代码? ubuntu是否已经安装了Fortran编译器或者是否需要下载gfortran?

gfortran可以从文件扩展名猜出某些东西;如果文件的扩展名为.f,.f90,f95,.f03或.f08,则它将采用固定的(.f)格式或带有适当标准的自由格式。但是你可以强迫它用-std = f2003选项编译(比如说)fortran2003代码。例如,从 documentation


-std = std



指定程序符合的标准,
可能是'f95','f2003','f2008','gnu'或'legacy'之一。 std的
默认值为`gnu',它指定了
Fortran 95标准的超集,其中包含
GNU Fortran支持的所有扩展,尽管警告将用于过时的扩展
不建议用于新代码。 传统值相当于
,但没有过时扩展的警告,对于旧的非标准程序可能有用
。 'f95','f2003'和'f2008'值
分别严格符合Fortran 95,Fortran 2003和Fortran
2008标准;对于超出相关语言标准的所有扩展
给出了错误,并且给出了允许的
Fortran 77功能的警告,但是在后来的
标准中已经过时。 `-std = f2008ts'允许Fortran 2008标准包括
技术规范(TS)29113的补充
Fortran与C的互操作性

请注意,除了少数例外,fortran标准具有高度向后兼容性,因此fortran-77代码也是有效的Fortran 2003代码。这个问题的主要问题是,80年代以前的Fortran代码既不美观也不符合标准。


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?

解决方案

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', `gnu', or `legacy'. The default value for std is `gnu', which specifies a superset of the Fortran 95 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' and `f2008' values specify strict conformance to the Fortran 95, Fortran 2003 and Fortran 2008 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.

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.

这篇关于gfortran如何告诉我是否正在编译f90或f95代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆