Reputation: 205
I am trying to compile a fortran code. It will analyze an X file in an Y directory and then create a new file Z with the results. But there is something wrong occurring.
When I write the directory I see that it is too much for one line and then I try to continue it in the next one doing this:
namech='/home/matheus/Documents/UFABC/IC/Spectra/Elliptical/'
+ 'espec.fits'
But, when I try to compile using the command
gfortran Codigo.f -o TESTE -Lcfitsio -lcfitsio
I get this error message:
+ 'espec.fits' 1
Error: Invalid character in name at (1)
Can someone help me? Actually I do not know what this error is. The directory is 100% right. And when I move the archives to a simpler directory to be able to write everything in one line, it works! So is there something wrong with the "+"?
Thank you.
Actually, when I add "&" in the end of the line, it gives me this error message:
namech='/home/matheus/Documents/UFABC/IC/Spectra/Elliptical/'& 1
Error: Unclassifiable statement at (1) Codigo.f:60.7:
+ 'espec.fits' 1
Error: Invalid character in name at (1)
And with "//":
namech='/home/matheus/Documents/UFABC/IC/Spectra/Elliptical/'// 1
Error: Syntax error in expression at (1) Codigo.f:60.7:
+ 'espec.fits' 1
Error: Invalid character in name at (1)
Thank you so much for helping me. Well, I solved the problem switching to the ".f90" form.
Just one more question: do you know why it does not recognize the "c" for comments in the code? Thank you again! :)
Upvotes: 0
Views: 5812
Reputation: 78316
This part of your compilation statement:
gfortran Codigo.f
will treat the source file, with its .f
suffix, as fixed form source. This means that a continuation line is indicated by any character (other than a blank or a 0
) in column 6.
However, the error message you get suggests that the +
in the second line of your snippet is not in column 6 and that the compiler is treating it as the initial character in a new entity name for which it is not valid. The fact that the +
is aligned, vertically, with n
in the previous line strengthens my suspicion that this may the root of your problem.
Adding the ampersand, as suggested in a now-deleted answer, doesn't actually help in this case if you continue to tell the compiler that it is dealing with a fixed form source file. &
is only used for continuation in free form source files. Adding the string-concatenation operator, //
, doesn't help either since it is not followed by another string but a line ending. //&
would help but is probably unnecessary.
I think you have 2 possible solutions, but choose only one:
.f90
which will cause gfortran
to treat the source file as free-form.If you go for option 2 (which I would recommend) you can then either use &
at the end of the continued line or you could simply merge the lines. In free-form the maximum line length is 132 characters.
Upvotes: 4
Reputation: 29391
Adding to High Performance Mark's answer:
If you continue with FORTRAN 77, most compilers have an option to increase the allowed line length, e.g., -ffixed-form -ffixed-line-length-none
for gfortran. As already stated, Fortran >=90 has line length of 132, so you wouldn't need to split the line.
Finally, if you want to split the line in Fortran >=90, you need two ampersands. In most cases you need one, but to split a string you need two:
namech='/home/matheus/Documents/UFABC/IC/Spectra/Elliptical/&
&espec.fits'
Upvotes: 2