Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Line length in FORTRAN

Status
Not open for further replies.

Samohtvii

Programmer
Aug 2, 2012
21
AU
Is there a set length you of line you can put code on?
Eventually if a line goes too long i get an error and it clearly just stops mid line and outputs a random error.
It's really annoying when i want a line of text on one line

so is there a way i can say print this on one line:
print *, 'This is some text that will get an error cause it's too long'

cause if i have to split it up it will look lame like this:
This is some text that will get
an error cause it's too long


Also while i'm here. When printing does it matter whether you use ' or " seem to both work but maybe there is something i don't know

Thanks
 
It depends on which version of Fortran you are using.

On F77, the default is 72. Some compilers allow the line to be extended to 80 or even 132 characters: these are the original line printer widths.

On F90, F95 and F03, there is no theoretical limit but there may be a compiler limit. Check your compiler documentation. The lines can always be split with continuation lines
Code:
      print *, 'a very very ' //
     &   'short long line'

Code:
   print *, 'a very very ' // &
      'short long line'

 
Please (google or something) read about continuation line in fortran.

Here is an example that shows how to break a long line in your code that needs to be printed in a single line:
Code:
program ml
    write(*,*) 'multiline-coded "line" printed &
               &on a single line'
end program ml

Single and double quotes can both be used to enclose strings...it depends on what's easier for you should you also need to quote something within the string (see example above).
 
As far as I know, all Fortran 90+ Standards specify 132 as max free form line length (for default i.e ASCII charset).
 
I've seen that syntax for long variable names but not for text strings. Oh well, learn something new every day.

Sorry - my bad. You're right the limit is 132 + 39 continuation lines for free form.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top