(1) 处的无效字符名称 [英] invalid character name at (1)

查看:18
本文介绍了(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 垂直对齐的事实加强了我的怀疑,这可能是您问题的根源.

如现在已删除的答案中所建议的那样,如果您继续告诉编译器它正在处理固定格式的源文件,那么在这种情况下添加与号实际上并没有帮助.& 仅用于自由格式源文件的延续.添加字符串连接运算符 // 也无济于事,因为它后面不是另一个字符串,而是一个行结尾.//& 会有所帮助,但可能没有必要.

我认为您有两种可能的解决方案,但只能选择一种:

  1. 坚持固定形式并正确对齐.
  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:

  1. Stick with fixed form and get the alignment right.
  2. Change the file suffix to .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.

这篇关于(1) 处的无效字符名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆