A Error Compare Logical(4) -- Help

1,089 views
Skip to first unread message

Shangshu Cai

unread,
Jun 11, 2009, 12:44:45 PM6/11/09
to gg95
Dear All:

I am totally a newbie to Fortran and G95. I wrote a small
program. The compiler gave me the error as followed:

g95 -o test test.f90 -L. ex.dll
In file test.f90:7

IF (WFLG /= .FALSE.) r = 1
1
Error: Operands of comparison operator '.ne.' at (1) are LOGICAL(4)/
LOGICAL(4)

How to solve this problem?

Thanks.


Source Code:
program main
integer i
logical WFLG
common /have/ r
WFLG = .FALSE.
IF (WFLG /= .FALSE.) r = 1
r=1
i = 6
call ex(i)
print *, i
end

Robert Funnell

unread,
Jun 11, 2009, 1:21:14 PM6/11/09
to gg...@googlegroups.com
On Thu, 11 Jun 2009, Shangshu Cai wrote:

> I am totally a newbie to Fortran and G95. I wrote a small
> program. The compiler gave me the error as followed:
>
> g95 -o test test.f90 -L. ex.dll
> In file test.f90:7
>
> IF (WFLG /= .FALSE.) r = 1
> 1
> Error: Operands of comparison operator '.ne.' at (1) are LOGICAL(4)/
> LOGICAL(4)

Normally one would just say
IF (WFLG) r = 1
or
IF (.NOT.WFLG) r = 1

- Robert

Shangshu Cai

unread,
Jun 11, 2009, 3:38:33 PM6/11/09
to gg95
Thanks.

shangshu

Ted Stern

unread,
Jun 11, 2009, 3:50:27 PM6/11/09
to gg...@googlegroups.com, Ted Stern
Several things here:


1) Common blocks have been deprecated for 30 years. If you want to
share memory, use a module.

module have_mod
real r
end module have_mod

program main
use have_mod

! etc.

end program main

The advantage of this is encapsulation. You can also put
subroutines and functions in a module, and within the module scope,
you don't need to declare the shared memory objects.

2) The symbolic operators ==, /=, >, < are for numbers, not logicals.

For logicals, use .eqv. (equivalent) or .neqv. (not equivalent)
instead of the numeric relational operators.

This is in fact the specific cause of your error.

3) As others have pointed out, since IF statements require a logical
result, you don't even have to do a logical relation.

4) It would be better to have r's value be set within an entire IF
block:

IF (WFLG) THEN
r = 1.
ELSE
r = 2.
ENDIF

Ted
--
Frango ut patefaciam -- I break so that I may reveal

Shangshu Cai

unread,
Jun 11, 2009, 4:00:18 PM6/11/09
to gg...@googlegroups.com
Hello, Ted:

Thank you for your information. That's solve my problem.

I am a really newbie Fortran programmer. Recently, I involved
in a project which needs to
compile a very old style Fortran project. The project is compiled by
Visual Compad Fortran successfully.
But it is failed to be compiled by g95.

Based on your suggestions, I will go back to change some
lines in my program.

Thanks again.

shangshu
--
Regards,
Sincerely,
shangshu
=================================================
Shangshu Cai
Dept. of Electrical and Computer Engineering
Mississippi State University
sc...@gri.msstate.edu
662-325-2065 (o)
662-617-4647 (c)
==================================================

Ted Stern

unread,
Jun 11, 2009, 4:10:53 PM6/11/09
to gg...@googlegroups.com, Ted Stern
Hi Shangshu,

In the past, I've had to maintain a 9000 file 700K-line Fortran
structural analysis program with roots that go back to 1962. It can
be quite difficult.

Some newer compilers don't support the old structures. I would
recommend looking up a list of deprecated and obsolescent features in
Fortran 77, Fortran 90, Fortran 95 and Fortran 2003 to get an idea of
language changes that might be causing problems for you.

Ted

Shangshu Cai

unread,
Jun 11, 2009, 4:32:31 PM6/11/09
to gg...@googlegroups.com
Hi, Ted:

9000 Files? My God. I cann't imagine how you did that.
200 files make me crazy.

I found the style of the code of my project is Fortran 77.
However, An error is reported that unrecognized statement
name at "USE xxxx_mod" when I compile it by g77. Do you
have any suggestions about the website or links that I can find
the deprecated and obsolescent features about Fortran?

Thanks.

shangshu

Shangshu Cai

unread,
Jun 11, 2009, 5:08:58 PM6/11/09
to gg...@googlegroups.com
Hello, Ted:

I appreciate your replying. Since my project is very old, it
seems that I cann't correct all the logical
comparison to the .enq. or .enqv. . Does g95 have compile switch to force g95
allow me to comparison logical variables as: logicalA .en. LogicalB?

Thanks,
Sincerely,
shangshu

On Thu, Jun 11, 2009 at 2:50 PM, Ted Stern<lgted...@gmail.com> wrote:
>
Reply all
Reply to author
Forward
0 new messages