LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-24-2011, 01:29 AM   #1
vjramana
Member
 
Registered: Sep 2009
Posts: 89

Rep: Reputation: 0
logical statement in fortran


I am trying to group set of data according some condition using FORTRAN code. The code is as below

Code:
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:

Code:
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

Thanks in advance
 
Old 10-24-2011, 05:23 AM   #2
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948
In Fortran (and most other programming languages) comparison operators compare exactly two expressions. You have three expressions with two operators. Although yours is logical, Fortran does not support your form.

The correct way to express condition a > b < c in Fortran is
Code:
(a > b .and. b < c)
Also, I believe you have a logic error in your if clause. Another way to write your current logic is
Code:
if (dihedral(i) > -120 .and. dihedral(i) < 120 .and. dihedral(i) /= 0) then
which somehow I think does not match your intent. I could be wrong, of course.
 
1 members found this post helpful.
Old 10-24-2011, 05:33 AM   #3
ajschaeffer
LQ Newbie
 
Registered: Oct 2011
Posts: 3

Rep: Reputation: Disabled
Alternatively, you could use:
Code:
if ( abs(dihedral(i))<120. .and. dihedral(i)/=0. ) then
 
1 members found this post helpful.
Old 10-24-2011, 06:02 AM   #4
vjramana
Member
 
Registered: Sep 2009
Posts: 89

Original Poster
Rep: Reputation: 0
Thank you.
It works now.
Regards
 
  


Reply

Tags
fortran



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Shell script for adding a statement in a file after a particular statement Aquarius_Girl Programming 4 06-28-2010 03:07 AM
Problem with if statement in a find -exec statement romsieze Programming 2 10-02-2008 12:38 AM
g77 in gcc 4.1.0 not found only gfortran fortran 95 compiler! I need fortran 77. TheBrick Linux - Software 3 07-04-2007 06:39 AM
Gnu Fortran versus Intel Fortran tomatoefish Linux - Software 3 02-20-2006 01:31 PM
does linux fortran compiler in fedora 4 support VAX FORTRAN? terrence Programming 17 08-31-2005 08:59 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration