名称 1 中的无效字符
invalid character at name 1
正在为一个项目学习 Fortran。在一个非常简单的程序中,我收到 无效字符 错误。
program foo
implicit none
integer :: n_samp
integer :: samp_len
integer :: x_len
integer :: y_len
n_samp=2
samp_len=2
y_len=11
x_len=2
real(8),dimension(n_samp,samp_len,y_len,x_len)=Yvec
end program foo
由 GFORTRAN
生成的错误
t.f90:11.12:
real(8), dimension(n_samp,samp_len,y_len,x_len)=Yvec
1
Error: Invalid character in name at (1)
这个错误的原因是什么?
正确的语法是
real(8), dimension(n_samp,samp_len,y_len,x_len) :: Yvec
指定任何属性时 ::
是强制性的(如您的情况下的 dimension
)。
正如@AlexanderVoigt 指出的,所有变量声明都必须放在代码的声明部分,即开头。
我不推荐使用 real(8)
因为它没有明确定义,8
可以表示任何意思,它是 table 种类的索引,不同的编译器可以有8
的地方 table 有所不同。参见 Fortran 90 kind parameter
很简单:主体中不允许有声明(即在一些指令之后)!相反,您应该使用参数:
program foo
implicit none
integer,parameter :: n_samp=2
integer,parameter :: samp_len=2
integer,parameter :: x_len=11
integer,parameter :: y_len=2
real(8),dimension(n_samp,samp_len,y_len,x_len) :: Yvec ! Add. typo here
end program foo
正在为一个项目学习 Fortran。在一个非常简单的程序中,我收到 无效字符 错误。
program foo
implicit none
integer :: n_samp
integer :: samp_len
integer :: x_len
integer :: y_len
n_samp=2
samp_len=2
y_len=11
x_len=2
real(8),dimension(n_samp,samp_len,y_len,x_len)=Yvec
end program foo
由 GFORTRAN
生成的错误t.f90:11.12:
real(8), dimension(n_samp,samp_len,y_len,x_len)=Yvec
1
Error: Invalid character in name at (1)
这个错误的原因是什么?
正确的语法是
real(8), dimension(n_samp,samp_len,y_len,x_len) :: Yvec
指定任何属性时 ::
是强制性的(如您的情况下的 dimension
)。
正如@AlexanderVoigt 指出的,所有变量声明都必须放在代码的声明部分,即开头。
我不推荐使用 real(8)
因为它没有明确定义,8
可以表示任何意思,它是 table 种类的索引,不同的编译器可以有8
的地方 table 有所不同。参见 Fortran 90 kind parameter
很简单:主体中不允许有声明(即在一些指令之后)!相反,您应该使用参数:
program foo
implicit none
integer,parameter :: n_samp=2
integer,parameter :: samp_len=2
integer,parameter :: x_len=11
integer,parameter :: y_len=2
real(8),dimension(n_samp,samp_len,y_len,x_len) :: Yvec ! Add. typo here
end program foo