Fortran: line for long / appended line - but with text at the end?
I have a Fortran line of code that contains some text. I'm changing the text, which increases the length of the Fortran line of code too much, so I split it into 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 a new line (starting with "a") does the space run between "a" and "first" in the string? Or do I need to "be char next to a to prevent extra whitespace?"
As you can tell, I'm not used to Fortran ...
If you are worried about exceeding the 72 column limit, I am assuming you are using Fortran 77. The syntax for Fortran 77 requires you to start at column 7, except for continued lines that need a continuation character in column 6. I use the following method, to tell me how many lines goes on for a single statement (the first line is just to show the columns):
!234567890
write(*,*)"Lorem Ipsum",
1 " Foo",
2 " Bar"
This will print:
Lorem Ipsum Foo Bar
You don't need to worry about spaces that are not quoted. In any case, all spaces are compressed in Fortran.
It's worth learning how to use format . They can make the exit much easier. It is somewhat similar to printf statements if you come from C. You specify a format with different types of parameters, then you give variables or literals to fill in that format.
And don't worry that you are not working with the hot, new, language of the day. You can learn a lot from Fortran, even Fortran 77, and if used correctly, Fortran can even be elegant. I've seen Fortran 77 written as if it were a dynamic memory object oriented language. I like to say "old.ne.bad".
source to share
- Yes, a character
a
is a continuation character and it basically means adding the rest of that line, starting with a continuation character (col 6, right?) To the previous line. - Your Fortran compiler probably has the option to enable "free-form" input instead of "fixed-form" input. Use this and you don't have to worry about line length.
- If your Fortran compiler is older than F90, that is, when I think free-form typing has started, you have my condolences.
source to share