View previous topic :: View next topic |
Author |
Message |
BillJohnson
Joined: 31 Aug 2011 Posts: 30 Location: Connecticut
|
Posted: Sat Apr 23, 2016 3:13 pm Post subject: You Cannot Compare Logical Values with EQ. |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7924 Location: Salford, UK
|
Posted: Sat Apr 23, 2016 3:35 pm Post subject: |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
mecej4
Joined: 31 Oct 2006 Posts: 1886
|
Posted: Sat Apr 23, 2016 3:48 pm Post subject: |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
BillJohnson
Joined: 31 Aug 2011 Posts: 30 Location: Connecticut
|
Posted: Sat Apr 23, 2016 4:04 pm Post subject: |
|
|
How do you in fortran declare / dimension a variablebas LOGICAL? |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
mecej4
Joined: 31 Oct 2006 Posts: 1886
|
Posted: Sat Apr 23, 2016 4:22 pm Post subject: |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2388 Location: Yateley, Hants, UK
|
Posted: Sun Apr 24, 2016 4:03 pm Post subject: |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
BillJohnson
Joined: 31 Aug 2011 Posts: 30 Location: Connecticut
|
Posted: Mon Apr 25, 2016 3:03 am Post subject: |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7924 Location: Salford, UK
|
Posted: Mon Apr 25, 2016 6:44 am Post subject: |
|
|
Nothing immediately wrong that I can see.
Try using IMPLICIT NONE and give every variable an explicit type. |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
LitusSaxonicum
Joined: 23 Aug 2005 Posts: 2388 Location: Yateley, Hants, UK
|
Posted: Mon Apr 25, 2016 9:47 am Post subject: |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
mecej4
Joined: 31 Oct 2006 Posts: 1886
|
Posted: Mon Apr 25, 2016 9:57 am Post subject: |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
|