Fortran 中的逻辑表达式
*我正在尝试使用 FORTRAN 代码根据某些条件对数据集进行分组。 代码如下。
gauche = 0.0
trans = 0.0
do i = 1, total_data
!write(*,*) nombor(i), dihedral(i)
if ( (0 > dihedral(i) < 120) .or. (-120 > dihedral(i) < 0) ) then
gauche = gauche + 1
else
trans = trans + 1
endif
end do
write(20,*) "Layer1_seg_total= ",(gauche+trans)," ","gauche_seg= ",gauche,"trans_seg= trans
但是当我编译时,我收到如下错误消息:
if ((0 > dihedral(i) < 120) .or. (-120 > dihedral(i) < 0)) then
1
Error: Expected a right parenthesis in expression at (1)
population.f90:42.5:
else
1
Error: Unexpected ELSE statement at (1)
population.f90:44.4:
endif
1
Error: Expecting END DO statement at (1)
我无法跟踪错误。任何人都可以提出错误吗?
注意:这不是作业
*I am trying to group set of data according some condition using FORTRAN code.
The code is as below.
gauche = 0.0
trans = 0.0
do i = 1, total_data
!write(*,*) nombor(i), dihedral(i)
if ( (0 > dihedral(i) < 120) .or. (-120 > dihedral(i) < 0) ) then
gauche = gauche + 1
else
trans = trans + 1
endif
end do
write(20,*) "Layer1_seg_total= ",(gauche+trans)," ","gauche_seg= ",gauche,"trans_seg= trans
But when I compile I get error message as below:
if ((0 > dihedral(i) < 120) .or. (-120 > dihedral(i) < 0)) then
1
Error: Expected a right parenthesis in expression at (1)
population.f90:42.5:
else
1
Error: Unexpected ELSE statement at (1)
population.f90:44.4:
endif
1
Error: Expecting END DO statement at (1)
I can not trace the error. Can anyone suggest the mistake?
NOTE: this is not an assignment
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Fortran 90 有六个关系运算符:<、<=、>、>=、==、/=
这六个关系运算符中的每一个都采用两个表达式,比较它们的值,并产生 .TRUE。或.FALSE。
因此,a> b< c 是错误的,因为 a < b 是逻辑数,c 是实数。
将您的测试重写为:
Fortran 90 has six relational operators: <, <=, >, >=, ==, /=
Each of these six relational operators takes two expressions, compares their values, and yields .TRUE. or .FALSE.
Thus, a > b < c is wrong, because a < b is LOGICAL and c is REAL.
Rewrite your test as:
您不能像这样组合表达式:
a> b< c
在 Fortran 语言中
写这样的东西:
a>乐队。 b< c
You cannot combine expressions like this:
a > b < c
in Fortran
Write something like this:
a > b .and. b < c
这是什么?
如果它是一个< x < b 那么它应该写成“
如果是别的什么……”
What is this?
If it is a < x < b then it should be written like
If it something else...