Fortran:行到长/附加行 - 但末尾有文本?

发布于 2024-07-10 01:49:13 字数 435 浏览 11 评论 0原文

我有一行 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

请持续率性 2024-07-17 01:49:13

如果您担心超过 72 列限制,那么我假设您使用的是 Fortran 77。Fortran 77 的语法要求您从第 7 列开始,连续行除外,连续行需要在第 6 列中使用连续字符。使用以下方法告诉我一个语句继续有多少行(第一行只是显示列):

!234567890
      write(*,*)"Lorem Ipsum",
     1 " Foo",
     2 " Bar"

这将打印:

Lorem Ipsum Foo Bar

您不必担心不在引号中的空格。 无论如何,所有的空格在 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):

!234567890
      write(*,*)"Lorem Ipsum",
     1 " Foo",
     2 " Bar"

This would print:

Lorem Ipsum Foo Bar

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".

季末如歌 2024-07-17 01:49:13

我已经记不起 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?

如梦亦如幻 2024-07-17 01:49:13
  1. 是的,a 是一个连续字符,基本上它只是意味着将连续字符(第 6 列,对吧?)之后的这一行的其余部分附加到上一行。
  2. 您的 Fortran 编译器可能有一个选项可以打开“自由格式”输入,而不是使用“固定格式”输入。 使用这个,你就不必担心线的长度。
  3. 如果您的 Fortran 编译器早于 F90——我认为自由格式输入能力就是在那时开始的,我对您表示哀悼。
  1. Yes, the 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.
  2. Your Fortran compiler probably has an option to turn on "free form" input instead of using "fixed form" input. Use this and you won't have to worry about line length.
  3. If your Fortran compiler is older than F90 -- which is when I think the free form input ability started, you have my condolences.
月亮邮递员 2024-07-17 01:49:13

@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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文