0

I need to work on Fortran90 code on my Macbook Pro, which was written on Microsoft Developer Tools years ago. As a free option, I have installed gfortran on my Macbook to be able to compile it. The original code includes & continuation character for the long lines but I am not able to use it. Without & character, everything works fine. What might be the problem? Do I need to activate something to be able to use & character?

For example, I think something like this should work:

x = 1 
y = 2 
z = x+ 
&y 
end

But instead, I am having this error. It might be end of line error. How can I solve it?

3:72: Error: Syntax error in expression at (1) 
4:9: Error: Invalid character in name at (1) 
Alexander Vogt
  • 17,879
  • 13
  • 52
  • 68
mantrasuser3
  • 99
  • 2
  • 12
  • 1
    Could you give an example? – Alexander Vogt Mar 21 '16 at 14:21
  • 1
    You need to show the code, the `&` works in gfortran just fine if used properly. Also report the file name and the command you use and the errors you see. – Vladimir F Героям слава Mar 21 '16 at 14:26
  • More likely the end-of-line characters windows vs. unix cause your trouble. See for example http://stackoverflow.com/q/3891076/577108. – haraldkl Mar 21 '16 at 15:47
  • Alright, for example, something like that should work in Fortran as long as I know: x = 1 y = 2 z = x+ &y But instead, I am having this error. It might be end of line error. How can I solve it? 3:72: Error: Syntax error in expression at (1) 4:9: Error: Invalid character in name at (1) Error: Unexpected end of file – mantrasuser3 Mar 21 '16 at 15:56
  • @AlexanderVogt Thank you for your help. I edited the question. – mantrasuser3 Mar 21 '16 at 16:03

1 Answers1

2

In free-form Fortran, the line continuation character (&) at the end of the line to be continued. Your code should read:

program test
  x = 1 
  y = 2 
  z = x+ &
  y 
end program

This is stated in the Fortran Standard (here: 2008, but applicable as well for Fortran 90), Cl. 3.3.2.4 "Free form statement continuation":

1 The character “&” is used to indicate that the statement is continued on the next line that is not a comment line. [...]

2 If a noncharacter context is to be continued, an “&” shall be the last nonblank character on the line, or the last nonblank character before an “!”. [...]

Alexander Vogt
  • 17,879
  • 13
  • 52
  • 68