Silverfrost Forums

Welcome to our forums

You Cannot Compare Logical Values with EQ.

23 Apr 2016 2:13 #17451

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:

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
23 Apr 2016 2:35 #17453

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...

23 Apr 2016 2:48 #17454

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> ).

23 Apr 2016 3:04 #17455

How do you in fortran declare / dimension a variablebas LOGICAL?

23 Apr 2016 3:22 #17456

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.

24 Apr 2016 3:03 #17457

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.

25 Apr 2016 2:03 #17458

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:

     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
25 Apr 2016 5:44 #17459

Nothing immediately wrong that I can see. Try using IMPLICIT NONE and give every variable an explicit type.

25 Apr 2016 8:47 #17460

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.

25 Apr 2016 8:57 #17461

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.

Please login to reply.