未知的错误在一个Fortran数组code [英] unknown wrong in a fortran array code

查看:1395
本文介绍了未知的错误在一个Fortran数组code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我检查这个code很多次,无法弄清楚如何纠正它。

I checked this code many times and could not figure out how to correct it.

program main
implicit none

real, parameter :: dx=1
real, parameter :: dy=1

real :: a1, a2, a3, a4, a5
a1=dy/dx
a2=dx/dy
a3=-2*(dy/dx+dx/dy)
a4=dx/dy
a5=dy/dx

REAL, DIMENSION(5,1):: a
DATA a/a1,a2,a3,a4,a5/

!write (*,*) a(1),a(2)
pause
endprogram 

非常感谢你和错误:结果
错误#6236:一个规范语句不能出现在执行部分
错误#6404:这个名字没有一个类型,而且必须有一个明确的类型。 [一个]
错误#6211:符号必须在此背景下定义的参数

推荐答案

您在混合规范(数据声明)语句和可执行语句。声明语句必须先走的可执行语句只能追赶他们每个编译单元或块中。

You are mixing specification (data declaration) statements and executable statements. The declaration statements must go first and the executable statements can only follow after them inside each compilation unit or block.

此外,在 DATA 语句用于初始化实体必须是一个常量前pression。

Also, entity used for initialization in the DATA statement must be a constant expression.

解决您的code的方法之一是:

One way to fix your code is:

program main
  implicit none

  real, parameter :: dx=1
  real, parameter :: dy=1

  real, parameter :: a1=dy/dx
  real, parameter :: a2=dx/dy
  real, parameter :: a3=-2*(dy/dx+dx/dy)
  real, parameter :: a4=dx/dy
  real, parameter :: a5=dy/dx

  REAL, DIMENSION(5,1):: a
  DATA a/a1,a2,a3,a4,a5/

  !write (*,*) a(1),a(2)

end program

不要使用暂停语句。它是由现代化的Fortran删除,它是不明确(可移植)又该它实际上即使在较早的版本。

Don't use the PAUSE statement. It is deleted from modern Fortran and it is not clear (portably) what should it actually do even in the older versions.

您也可以使用初始化数组构造器的阵列。你并不需要不断的前pressions在这种情况下:

You can also initialize the array using an array constructor. You don't need constant expressions in that case:

program main
  implicit none

  real, parameter :: dx=1
  real, parameter :: dy=1
  REAL, DIMENSION(5,1) :: a

  a = reshape([dy/dx, dx/dy, -2*(dy/dx+dx/dy), dx/dy, dy/dx], [5,1])
end program

这篇关于未知的错误在一个Fortran数组code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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