简体   繁体   中英

logical expression in fortran

*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

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:

if  ( (0 > dihedral(i) .and. dihedral(i) < 120) .or. (-120 > dihedral(i) .and. dihedral(i) < 0) )  then

You cannot combine expressions like this: a > b < c in Fortran Write something like this: a > b .and. b < c

What is this?

0 > dihedral(i) < 120

If it is a < x < b then it should be written like

a < x .and. x < b

If it something else...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM