forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

You Cannot Compare Logical Values with EQ.

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General
View previous topic :: View next topic  
Author Message
BillJohnson



Joined: 31 Aug 2011
Posts: 30
Location: Connecticut

PostPosted: Sat Apr 23, 2016 3:13 pm    Post subject: You Cannot Compare Logical Values with EQ. Reply with quote

Dear Forum,

I am having issues with compiling someone's FORTRAN code. The silver frost compiler is complaining about "you cannot compare logical values with eq." on lines 2765 and 2771.

Here are the code snippets for those lines:

Code:

c  store variables for reguli-falsi, but only if they are smaller than the current values
      if (ft(jt).lt.0.0) then
 Line2765>       if ((ft(jt).gt.fneg.and.lneg.eq..true.).or.lneg.eq..false.) then
          tneg=tt(jt)
          fneg=ft(jt)
        endif
        lneg=.true.
      else
 Line2771>       if ((ft(jt).lt.fpos.and.lpos.eq..true.).or.lpos.eq..false.) then
          tpos=tt(jt)
          fpos=ft(jt)
        endif
        lpos=.true.
      end if
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 4867
Location: Salford, UK

PostPosted: Sat Apr 23, 2016 3:35 pm    Post subject: Reply with quote

In FORTRAN, if lneg is LOGICAL then you can write

if(.not. lneg) then ...

or

if(lneg .eqv. .false.) then...

but not

if(lneg .eq. .false.) then...
Back to top
View user's profile Send private message
mecej4



Joined: 31 Oct 2006
Posts: 712

PostPosted: Sat Apr 23, 2016 3:48 pm    Post subject: Reply with quote

The operators .EQ., .NE., .GT., .LT., etc., apply to integer operands and not to logical operands. Older compilers may have allowed code with errors of this nature to pass with no error messages, and the compiled code may even have run correctly, but these are bugs that have to be fixed some day.

For a detailed explanation, see https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/274462 .

Not only is an expression such as IF (<logical expression> .EQ. .TRUE.) incorrect (because it uses the disallowed operator .EQ.), but it also contains syntax that adds nothing to the intended meaning. IF (<logical expression>) suffices. If you find yourself writing IF (<logical expression> .NE. .TRUE.), you should correct that to IF ( .NOT. <logical expression> ).
Back to top
View user's profile Send private message
BillJohnson



Joined: 31 Aug 2011
Posts: 30
Location: Connecticut

PostPosted: Sat Apr 23, 2016 4:04 pm    Post subject: Reply with quote

How do you in fortran declare / dimension a variablebas LOGICAL?
Back to top
View user's profile Send private message
mecej4



Joined: 31 Oct 2006
Posts: 712

PostPosted: Sat Apr 23, 2016 4:22 pm    Post subject: Reply with quote

In the same way as variables of other types, using the type name LOGICAL instead of REAL, CHARACTER, INTEGER, etc.

In the section of code that you showed above, you have variables LPOS and LNET that are logical. In the declarations section of the program unit from which you took the displayed code, you should find the declarations of these variables as LOGICAL.
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 1644
Location: Yateley, Hants, UK

PostPosted: Sun Apr 24, 2016 4:03 pm    Post subject: Reply with quote

Rather fascinatingly, FTN95 uses byte patterns for .false. and .true. that appear as 0 and 1 if interpreted as integer - I canít remember which way round it is but I think thatís right. You can, for example, pass 1 to USE_RGB_COLOURS@ in place of .true.- and it works fine.

Hence, the logical only needs one bit, or in effect LOGICAL*0.125 !

In practice, you canít use less than one byte, so logical variables are comparatively wasteful, especially if they are more than one byte long.

In the past, when one was desperately short of RAM, logical results could be packed in 8 to a byte using the bit manipulation routines listed in the FTN77 documentation. I imagine that it isn't worth the trouble any more.
Back to top
View user's profile Send private message
BillJohnson



Joined: 31 Aug 2011
Posts: 30
Location: Connecticut

PostPosted: Mon Apr 25, 2016 3:03 am    Post subject: Reply with quote

Okay Guys. Still getting the compilation errors. I've change the "EQ" to "EQV" for the if-then-else conditional statements and the silver frost compiler is still complaining about these lines of code. I really don't care about the arguments of memory storage. I just want to compile this code so I can do some work. Please help. What is wrong with these lines of code??!!! Here's the latest snippet of code:

Code:

     if (ft(jt).lt.0.0) then
        if ((ft(jt).gt.fneg.and.lneg.eqv..true.).or.lneg.eqv..false.) then
          tneg=tt(jt)
          fneg=ft(jt)
        endif
        lneg=.true.
      else
        if ((ft(jt).lt.fpos.and.lpos.eqv..true.).or.lpos.eqv..false.) then
          tpos=tt(jt)
          fpos=ft(jt)
        endif
        lpos=.true.
      end if
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 4867
Location: Salford, UK

PostPosted: Mon Apr 25, 2016 6:44 am    Post subject: Reply with quote

Nothing immediately wrong that I can see.
Try using IMPLICIT NONE and give every variable an explicit type.
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 1644
Location: Yateley, Hants, UK

PostPosted: Mon Apr 25, 2016 9:47 am    Post subject: Reply with quote

So what is the complaint issued by FTN95? Might it be that you have gone over column 72? It was when I copied your code and dressed it up with a PROGRAM statement and declarations to make it compile (treating it as fixed format). With free format the line lengths don't matter.
Back to top
View user's profile Send private message
mecej4



Joined: 31 Oct 2006
Posts: 712

PostPosted: Mon Apr 25, 2016 9:57 am    Post subject: Reply with quote

You have made the new snippet so small that it contains no errors, provided LNEG and LPOS are declared logical, JT integer and the other variables REAL or DOUBLE PRECISION.

It would be nice to have from you a piece of code that can be run through the compiler and produces the error messages that you mentioned.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group