2

Using the g95 compiler, I have an error:

Error: Operands of comparison operator '.EQ.' at (1) are LOGICAL(4)/LOGICAL(4)

I have no idea what this means. I'm including the subroutine. Do you have any ideas how to fix this?

Thanks so much for your time.

  SUBROUTINE search(iarray, ItemSought, Found, Location)
CHARACTER(20), DIMENSION(50),INTENT(IN)::itemarray
CHARACTER(20)::ItemSought
LOGICAL, INTENT(OUT)::Found
INTEGER, INTENT(OUT)::Location
INTEGER:: First, Last, Middle

WRITE(*,'(1x,A)',ADVANCE="NO"),"What are you searching for? "
READ*, ItemSought

First=1
Last=SIZE(Iarray)
FOUND = .FALSE.

DO
    IF ((First > Last) .OR. Found) RETURN
        Middle = (First+Last)/2
    IF (ItemSought < Iarray(Middle)) THEN
        Last=Middle-1
    ELSE IF (ItemSought > Iarray(Middle)) THEN
        First=Middle+1
    ELSE
        Found = .TRUE.
        Location = Middle
    END IF
END DO


IF (Found == .TRUE.) THEN
PRINT*, Itemsought

END SUBROUTINE

2 Answers 2

6

I'm not going to admit the last time I used FORTRAN, but it sure looks a lot different than I remember. So this is just a guess.

Based on the error message I'd say it's on this line (you didn't say which):

IF (Found == .TRUE.) THEN

Again just guessing, you usually don't test a logical value by comparing to true/false, you use it directly:

IF (Found) THEN
Sign up to request clarification or add additional context in comments.

Comments

5

The .EQ. (or ==)relational operator, just like .NE. (/=), .LT. (<) and so on, is for comparing numbers only, for comparing logical values you should use .EQV. and .NEQV.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.