views:

2644

answers:

4

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

A: 

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?

Michael Burr
A: 
  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.
tvanfosson
A: 

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

The GNU Compiler Collection includes a Fortran compiler. That would probably be sufficient to let you answer questions such as this.
Jonathan Leffler
+2  A: 

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

Scottie T