Fortran:行到长/追加行 - 但在最后的文本? [英] Fortran: line to long / append line - but with text at the end?

查看:228
本文介绍了Fortran:行到长/追加行 - 但在最后的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一行Fortran代码,其中包含一些文本。我正在改变文本,这使得Fortran的代码行太长,所以我使用'a'将它分成两行。



是:

  IF(MYVAR .EQ。1)THEN 
WRITE(iott,'(A)(A)')'ABC =',SOMEVAR



< ($)
$ b

  IF(MYVAR .EQ。1)then 
WRITE(iott,'(A) (A)')'ABC DEF GHI JK
a'//'L =',SOMEVAR

我的问题是,在新行上(以'a'开头),'a'和'first'之间的空格是否会附加到字符串?或者我需要'成为旁边的字符,以防止额外的空白?



正如你所知道的,我不习惯Fortran ...

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

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

这将打印:

  Lorem Ipsum Foo Bar 

您不必担心没有引号的空格。无论如何,所有空格都在Fortran中压缩。



值得学习如何使用 format 语句。他们可以使输出更容易。如果你来自C,那么它与printf语句有点类似。你可以指定一个格式,使用不同类型的参数,然后给变量或文字填写格式。



不要担心你没有使用当今最热门的新语言。您可以从Fortran学到很多东西,甚至是Fortran 77,如果使用得当,Fortran甚至可以优雅。我已经看到Fortran 77写成了面向对象的语言,并且具有动态内存。我喜欢说,old.ne.bad。


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

解决方案

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

这篇关于Fortran:行到长/追加行 - 但在最后的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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