Fortran:行到长/附加行 - 但末尾有文本?
我有一行 Fortran 代码,其中包含一些文本。 我正在更改文本,这使得代码行对于 Fortran 来说太长,因此我使用“a”将其分成两行。
是:
IF (MYVAR .EQ. 1) THEN
WRITE(iott,'(A) (A)') 'ABC=', SOMEVAR
更改为:
IF (MYVAR .EQ. 1) THEN
WRITE(iott,'(A) (A)') 'ABC DEF GHI JK
a ' // 'L=', SOMEVAR
我的问题是,在新行(以 'a' 开头)上,'a' 和第一个 ' 之间的空格是否附加到字符串中? 或者我是否需要 ' 成为 a 旁边的字符以防止出现额外的空格?
正如你所知,我不习惯 Fortran...
I have a line of Fortran code, which includes some text. I'm changing the text, which makes the code line too long for Fortran, so I split it over two lines using 'a'.
Was:
IF (MYVAR .EQ. 1) THEN
WRITE(iott,'(A) (A)') 'ABC=', SOMEVAR
Changed to:
IF (MYVAR .EQ. 1) THEN
WRITE(iott,'(A) (A)') 'ABC DEF GHI JK
a ' // 'L=', SOMEVAR
My question is, on the new line (starting with 'a'), does the white space between the 'a' and the first ' get appended to the string? Or do I need the ' to be the char next to a to prevent additional white space?
As you can tell, I'm not used to Fortran...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您担心超过 72 列限制,那么我假设您使用的是 Fortran 77。Fortran 77 的语法要求您从第 7 列开始,连续行除外,连续行需要在第 6 列中使用连续字符。使用以下方法告诉我一个语句继续有多少行(第一行只是显示列):
这将打印:
您不必担心不在引号中的空格。 无论如何,所有的空格在 Fortran 中都会被压缩。
学习如何使用 format 语句是值得的。 它们可以使输出变得更加容易。 如果您来自 C,它有点类似于 printf 语句。您指定具有不同类型参数的格式,然后给出变量或文字来填充该格式。
并且不用担心您没有使用当今热门的新语言。 你可以从 Fortran 中学到很多东西,甚至是 Fortran 77,而且如果使用得当,Fortran 甚至可以很优雅。 我见过 Fortran 77 的编写方式就好像它是一种面向对象语言,具有动态内存。 我喜欢说“old.ne.bad”。
If you're worried about exceeding a 72 column limit, then I assume you're using Fortran 77. The syntax for Fortran 77 requires that you start with column 7, except for continued lines, which need a continuation character in column 6. I use the following method to tell me how many lines are continued for one statement (the first line is just to show the columns):
This would print:
You don't have to worry about spaces that aren't in quotes. All whitespace gets compressed in Fortran, anyway.
It's worthwhile learning how to use format statements. They can make output a lot easier. It's somewhat similar to printf statements, if you're coming from C. You specify a format with different types of parameters, then give variables or literals to fill out that format.
And don't worry that you're not working with the hot, new, language of the day. You can learn a lot from Fortran, even Fortran 77, and when used properly, Fortran can even be elegant. I've seen Fortran 77 written as if it were an object oriented language, complete with dynamic memory. I like to say, "old.ne.bad".
我已经记不起 FORTRAN 的旧列要求了(而且它们甚至可能不像以前那么严格)。
但是,这不是快速测试就能立即告诉您的吗?
It's been too long for me to remember the old column requirements of FORTRAN (and they may not even be as strict as they were way back when).
But - isn't this something that a quick test run will tell you straight off?
a
是一个连续字符,基本上它只是意味着将连续字符(第 6 列,对吧?)之后的这一行的其余部分附加到上一行。a
is a continuation character and basically it just means append the rest of this line starting after the continuation character (col 6, right?) to the previous line.@Mike B:
在理想的情况下是的,但在这种情况下,代码是在一台机器上开发的,并提交到构建服务器,该服务器具有可供其构建的适当的第3方软件/SDK/许可证。 构建也不是很快。
@Mike B:
In an ideal world yes, but in this case the code is developed on one machine, and submitted to a build server which has the appropriate 3rd party software / SDK's / licenses available to it to build. The build isn't exactly quick either.