Fortran控制字符(滑架控制)仍然在编译器中实现? [英] Are Fortran control characters (carriage control) still implemented in compilers?

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

问题描述

在书 Fortran 95/2003 for Scientists and Engineers 中,有很多说明识别格式语句中的第一列为控制字符保留的重要性。我也看过在互联网上被称为支架控制的控制字符。



为了避免混淆,通过控制字符,我指的是字符1,即\ s),0和+作为对放置在FORMAT语句的第一列(字符)中的输出垂直间距的影响。



此外,请参阅完全使用固定宽度字体的纯文字网页: Fortran支架控制(因为没有什么尖叫的准确性和古代比散文在等宽字体)。我发现这个网页和其他人都不太清楚。



根据 Fortran 95/2003 for Scientists and Engineers ,未能记住第一列保留用于托架控制可能会导致难以预料的输出。转述 Dave Barry ,键入错误的字符,并在挪威发射核导弹。



但是,当我试图坚持这个严厉的警告,我发现gfortran不知道我在说什么。 / p>

请允许我用一些示例代码来说明我的观点。我打算输出数字Pi:

 程序test_format 
IMPLICIT无

REAL :: PI = 2 * ACOS(0.0)

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

  1新页:3.141592741 
单空格:3.141592741
0空格:3.141592741

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



我的问题是,这是:





为了清楚起见,这里是我的 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- -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
线程模型:posix
gcc版本4.4.0(GCC)

解决方案

在过去的几年里,忽略第一列的使用可能会导致坏事打印机,像页面弹出 - 但是什么时候是最后一次看到行式打印机?否则是输出设备,编译器和操作系统。 Fortran 95/2003的科学家和工程师的建议是优秀的大约15或20年前。随着终端,后记和其他现代打印机,第一列不再特别。



Fortran 2003标准将托架控制列为已删除 >,这是Fortran语言标准很少做的事情。请参见Fortran 95/2003说明的第359页或Fortran 2003手册的第326页。也许用gfortran选择-std = f2003或-std = f2008将保证列1不会被使用托架控制,所以坏事是完全不可能的。


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.

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.

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.

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.

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

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

This is the output:

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

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

My question, then, is this:

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

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

Using built-in specs. Target: powerpc-apple-darwin9 Configured with: ../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 Thread model: posix gcc version 4.4.0 (GCC)

解决方案

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.

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天全站免登陆