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