(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
我收到此错误消息:
<块引用> + 'espec.fits'1
错误:(1) 处名称中的字符无效
有人可以帮助我吗?其实我不知道这个错误是什么.该目录是 100% 正确的.当我将档案移动到一个更简单的目录以便能够在一行中编写所有内容时,它就可以工作了!那么+"有什么问题吗?
谢谢.
编辑1
实际上,当我添加&"时在行尾,它给了我这个错误信息:
<块引用> namech='/home/matheus/Documents/UFABC/IC/Spectra/Elliptical/'&1
错误:(1) 处的不可分类声明Codigo.f:60.7:
+ 'espec.fits'1
错误:(1) 处名称中的字符无效
并用//":
<块引用> namech='/home/matheus/Documents/UFABC/IC/Spectra/Elliptical/'//1
错误:(1) 处的表达式中存在语法错误Codigo.f:60.7:
+ 'espec.fits'1
错误:(1) 处名称中的字符无效
编辑2
非常感谢您帮助我.好吧,我解决了切换到.f90"表单的问题.
还有一个问题:你知道为什么它不能识别代码中注释的c"吗?再次感谢你!:)
这部分你的编译语句:
gfortran Codigo.f
会将带有 .f
后缀的源文件视为固定格式的源文件.这意味着续行由第 6 列中的任何字符(空白或 0
除外)指示.
但是,您收到的错误消息表明代码段第二行中的 +
不在第 6 列中,并且编译器将其视为新实体名称中的初始字符这是无效的.+
与上一行中的 n
垂直对齐的事实使我更加怀疑这可能是您问题的根源.
如果您继续告诉编译器它正在处理固定格式的源文件,那么添加与号(如现在已删除的答案中所建议的)在这种情况下实际上并没有帮助.&
仅用于在自由格式的源文件中继续.添加字符串连接运算符 //
也无济于事,因为它后面不是另一个字符串而是行尾.//&
会有所帮助,但可能没有必要.
我认为您有两种可能的解决方案,但只能选择一种:
- 坚持固定形式,正确对齐.
- 将文件后缀更改为
.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屋!