Fortran 控制字符(回车控制)是否仍在编译器中实现? [英] Are Fortran control characters (carriage control) still implemented in compilers?

查看:18
本文介绍了Fortran 控制字符(回车控制)是否仍在编译器中实现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在书中Fortran 95/2003 供科学家和工程师使用,有很多关于认识到格式语句中的第一列是为控制字符保留的重要性的讨论.我还在互联网上看到了被称为回车控制的控制字符.

In the book Fortran 95/2003 for Scientists and Engineers, there is much talk given to the importance of recognizing that the first column in a format statement is reserved for control characters. I've also seen control characters referred to as carriage control on the internet.

为避免混淆,对于控制字符,我将字符1、空白(即s)、0 和+"称为对输出的垂直间距有影响的第一个放置在 中的字符 FORMAT 语句的列(字符).

To avoid confusion, by control characters, I refer to the characters "1, a blank (i.e. s), 0, and +" as having an effect on the vertical spacing of output when placed in the first column (character) of a FORMAT statement.

另外,请参阅完全用固定宽度字体编写的纯文本网页:Fortran 回车控制(因为没有什么比等宽字体的散文更能体现准确性和古老性了).我发现这个页面和其他类似的页面不太清楚.

Also, see this text-only web page written entirely in fixed-width typeface : Fortran carriage-control (because nothing screams accuracy and antiquity better than prose in monospaced font). I found this page and others like it to be not quite clear.

根据 Fortran 95/2003 for Scientists and Engineers,如果不记得第一列是为回车控制保留的,可能会导致 可怕的 意外输出.解释 Dave Barry,输入错误的字符,然后核导弹向挪威发射.

According to Fortran 95/2003 for Scientists and Engineers, failure to recall that the first column is reserved for carriage control can lead to horrible unintended output. Paraphrasing Dave Barry, type the wrong character, and nuclear missiles get fired at Norway.

但是,当我尝试遵守这个严厉的警告时,我发现 gfortran 不知道我在说什么.

However, when I attempt to adhere to this stern warning, I find that gfortran has no idea what I'm talking about.

请允许我用一些示例代码来说明我的观点.我正在尝试打印数字 Pi:

Allow me to illustrate my point with some example code. I am trying to print out the number Pi:

PROGRAM test_format
IMPLICIT NONE

REAL :: PI = 2 * ACOS(0.0)

WRITE (*, 100) PI
WRITE (*, 200) PI
WRITE (*, 300) PI
100 FORMAT ('1', "New page: ", F11.9)
200 FORMAT (' ', "Single Space: ", F11.9)
300 FORMAT ('0', "Double Space: ", F11.9)
END PROGRAM test_format

这是输出:

1New page: 3.141592741
Single Space: 3.141592741
0Double Space: 3.141592741

1"和0"不是拼写错误.看来 gfortran 完全忽略了控制字符列.

The "1" and "0" are not typos. It appears that gfortran is completely ignoring the control character column.

那么,我的问题是这样的:

My question, then, is this:

控制字符是否仍然在符合标准的编译器中实现,或者 gfortran 根本不符合标准?

Are control characters still implemented in standards compliant compilers or is gfortran simply not standards compliant?

为清楚起见,这是我的 gfortran -v

For clarity, here is the output of my gfortran -v

使用内置规范.目标:powerpc-apple-darwin9配置:../gcc-4.4.0/configure --prefix=/sw --prefix=/sw/lib/gcc4.4 --mandir=/sw/share/man --infodir=/sw/share/info --enable-languages=c,c++,fortran,objc,java --with-gmp=/sw --with-libiconv-prefix=/sw --with-ppl=/sw --with-cloog=/sw--with-system-zlib --x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib --disable-libjava-multilib --build=powerpc-apple-darwin9 --host=powerpc-apple-darwin9 --target=powerpc-apple-darwin9线程模型:posixgcc 版本 4.4.0 (GCC)

推荐答案

在过去的几年里,忽略对第一列的这种使用可能会导致行式打印机出现问题,例如页面弹出 - 但你最后一次是什么时候看到行式打印机了吗?否则,它取决于输出设备、编译器和操作系统.大约 15 或 20 年前,面向科学家和工程师的 Fortran 95/2003"的建议非常好.对于终端、postscript 和其他现代打印机,第一列不再特别.我不再特别关注第一列,也没有遇到麻烦.

In years past, ignoring this use of the first column could cause bad things on a line printer, like page ejects -- but when was the last time that you saw a line printer? Otherwise it was output device, compiler and OS dependent. The advice of "Fortran 95/2003 for Scientists and Engineers" was excellent for about 15 or 20 years ago. With terminals, postscript and other modern printers, column one isn't special any more. I don't pay special attention to column one anymore and I haven't gotten into trouble.

Fortran 2003 标准将回车控制列为已删除,这是 Fortran 语言标准很少这样做的.请参阅Fortran 95/2003 解释"的第 359 页或Fortran 2003 手册"的第 326 页.也许使用 gfortran 选择 -std=f2003 或 -std=f2008 将保证第 1 列不会用作回车控件,因此完全不可能出现坏事".

The Fortran 2003 standard lists carriage control as deleted, which is something that the Fortran language standards rarely do. See page 359 of "Fortran 95/2003 explained" or page 326 of "The Fortran 2003 Handbook". Perhaps selecting -std=f2003 or -std=f2008 with gfortran will guarantee that column 1 won't be used a carriage control so that "bad things" are completely impossible.

这篇关于Fortran 控制字符(回车控制)是否仍在编译器中实现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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