Fortran: line to long / append line - but with text at the end?

好久不见. 提交于 2019-12-24 10:47:46

问题


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


回答1:


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




回答2:


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?




回答3:


  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.



回答4:


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



来源:https://stackoverflow.com/questions/373342/fortran-line-to-long-append-line-but-with-text-at-the-end

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!