无效字符名称(1) [英] invalid character name at (1)
问题描述
我想编译一个fortran代码。它将分析Y目录中的X文件,然后使用结果创建新文件Z.但是发生了一些错误。
当我写目录时,我发现它对于一行来说太多,然后我尝试继续它在下一个做这个:
namech ='/ home / matheus / Documents / UFABC / IC / Spectra / Elliptical /'
+' espec.fits'
但是,当我尝试使用命令
gfortran Codigo.f -o TESTE -Lcfitsio -lcfitsio
I收到此错误讯息:
+'espec.fits'
1
错误:名称中的字符无效(1)
有人可以帮助我吗?其实我不知道这个错误是什么。该目录是100%正确。当我把档案移动到一个更简单的目录,以便能够在一行中写一切,它的工作原理!那么+有什么问题吗?
谢谢。
Edit1
其实,当我添加&在行末,它会给我这个错误消息:
namech ='/ home / matheus / Documents / UFABC / IC / Spectra / Elliptical /'&
1
错误:不可分类语句(1)
Codigo.f: 60.7:+'espec.fits'
pre>
1
错误:(1)名称中的字符无效
与//:
namech ='/ home / matheus / Documents / UFABC / IC / Spectra / Elliptical /'//
1
错误: 1)
Codigo.f:60.7:+'espec.fits'
1
错误:名称中的字符无效(1)
Edit2
非常感谢您的帮助。好了,我解决了问题切换到.f90形式。
还有一个问题:你知道为什么它不认可c代码?再次感谢你! :)
这部分编译语句:
gfortran Codigo.f
会处理源文件, code> .f 后缀,作为固定格式源。这意味着第6列中的任何字符(第6列中的空格或 0
除外)表示连续行。
但是,您得到的错误消息表明,代码段第二行中的 +
不在第6列,并且编译器将其视为初始字符其无效的新实体名称。事实上, +
与上一行中的 n
垂直对齐,这加强了我的怀疑,这可能是根
根据现在删除的答案建议添加&符号在这种情况下实际上不会有帮助,如果您继续告诉编译器它是处理固定形式的源文件。 &
仅用于自由格式源文件中的续续。添加字符串连接运算符 //
没有帮助,因为它后面没有另一个字符串,而是一个行结尾。 //&
会帮助但可能不必要。
我认为你有2种可能的解决方案,一个:
- 坚持使用固定格式并获得对齐。
- 将文件后缀更改为
.f90
,它会导致gfortran
将源文件视为自由格式。
如果你选择选项2(我会推荐),你可以使用&
的连续行,或者你可以简单地合并行。在自由格式中,最大行长为132个字符。
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.
Edit1
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)
Edit2
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! :)
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:
- Stick with fixed form and get the alignment right.
- Change the file suffix to
.f90
which will causegfortran
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.
这篇关于无效字符名称(1)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!