Error: IF clause at (1) requires a scalar LOGICAL expression

How do I fix this error?

  LOGICAL FUNCTION RUZE(CARD1,CARD2)
  IMPLICIT NONE
  CHARACTER CARD1*(*)
  CHARACTER(*) ::CARD2(:)
  
  CARD1 = 'K'
  CARD2 = 'Q'
  
  IF (CARD2(1:2).EQ.' ')THEN
   WRITE (*,*) 'STEP2 SUCCESSFUL'
  ENDIF 

  RUZE = .true.
  
  RETURN 
  END
  
  SUBROUTINE MAKE_MOVE(STD)
    IMPLICIT NONE
    LOGICAL RUZE
    CHARACTER(*) :: STD(:)
    CHARACTER REPRESENT*10
    
    IF(RUZE(REPRESENT(1:7),STD(1:7)))THEN
     WRITE (*,*) 'STEP1 SUCCESSFUL'
    ENDIF
        
    RETURN
  END

Program PLAYING
IMPLICIT NONE
INTEGER MOVES
PARAMETER (MOVES=100)
CHARACTER*15 BIGMOVE(MOVES)
CALL MAKE_MOVE(BIGMOVE)
End Program PLAYING

  gfortran -c -g play.f90 -o play.o -g -Wall -Werror -fmax-errors=1 -fcheck=all -fPIC
  gfortran -g play.o -o play.exe -lgfortran
Compilation failed due to following error(s).    
9 |       IF (CARD2(1:2).EQ.' ')THEN
      |          1
Error: IF clause at (1) requires a scalar LOGICAL expression
compilation terminated due to -fmax-errors=1.

Thank you,

This appears to be a restart of an earlier thread, under a different user-id. An even earlier one exists, quite similar to the current one.

As has been noted earlier, there is a pattern in these posts. Arbitrary changes are made to the source code in an attempt to make compilation errors go away. When that fails, a fresh post is made asking something along the lines of “what do I do to fix this?”. Such an approach is misguided and a waste of everyone’s time.

A computer program is an expression of ideas. For it to succeed, the ideas must be clear and based on a logical framework. The programmer has to be conversant, if not fluent, in the programming language chosen, willing to engage in well-reasoned discourse, and willing to read the appropriate language guides and reference manuals.

4 Likes

This user (and now also under a different user-id) does not appear to be interested in actually learning and understanding Fortran (or really even programming in general), properly understanding the existing software they are working on, nor respecting the time and efforts of the helpful community here. They appear to be (poorly) attempting to procure free consulting services in what is possibly the least effective way to do so. While some of their questions have provided learning opportunities and potentially useful discussions for future users, this user appears to have ignored nearly every word of it. I find it to be highly disrespectful and unprofessional conduct.

I propose a meta question for this forum: Should any action be taken towards such users and their posts, and if so what?

Edit: I actually don’t want to be that guy. As disrespectful as I find this user’s actions, I don’t want them silenced. I’d simply suggest that other users disregard any questions from them that aren’t likely to provide useful information to others and not necessarily worry about fixing their specific code.

5 Likes

The post is on-topic and doesn’t violate CoC. It’s OK for anybody to ignore it if they wish so.

I understand @everythingfunctional and completely agree with you.

1 Like

The code provided in this thread is more or less the same as in the earlier one. I see no point in having two separate threads to debug the same function of 12 lines of code.

More concerning is the perceived need to have two user accounts. I’ve found this thread on Meta Discourse: How to handle multiple account? - feature - Discourse Meta. @milancurcic, do you know if the Fortran Discourse has flag_sockpuppets enabled?

Let us set the syntax problems aside and look at the semantics of the program. The logical type function RUZE ignores the input values of its arguments, and always returns .TRUE. Therefore, the whole program could be replaced by just these two lines:

     WRITE (*,*) 'STEP1 SUCCESSFUL'
     END

It is not clear what the function RUZE is supposed to do. It receives two strings, it uses a single one and the result is independent of the arguments. I assume this is merely a first version to get something that the compiler can chew on, but can you explain what you want this function to do precisely? Then we can try and help getting it to work properly.

I looked and flag_sockpuppets wasn’t enabled. I just enabled it. Let’s see how it goes, we can always revert if we discover an issue with it. I think it will be a good change.

Sorry for a naive question.

CHARACTER CARD1*(*)

What does the first and second * mean in CARD1*(*)?

The notation is from the FORTRAN 77 era. It means the same thing as:

character(len=*) :: card1

The first * indicates for character variables that the length will follow and the second that the actual length is adopted from the calling program unit. You may also find:

character*20 string1, string2*40

where the first character variable, string1, gets the length 20 from the “character*20” part and the second, string2, gets a length 40 because a specific length is specified for that one.

2 Likes

Have you changed this line during your refactoring? Is CARD2 supposed to be an array of strings, or an array single characters?

A few answers in your other thread (Error: Rank mismatch in argument 'std' at (1) (scalar and rank-1)) have alluded to this, but without more information it’s difficult to know what you want to achieve, hence you continue wasting everyone’s time.

FWIW, if you just want to make a compilation error go away, do this

       IF (CARD1(1:1).EQ.'K') THEN
         IF (ANY(CARD2(1:2).EQ.' '))THEN

It’s a minor change (five extra characters), and should make the program compile. Does it do what you want? Probably not…

:man_facepalming:

Well if you can explain what “capability” that is, someone may be able to help you. Until then, good luck.

1 Like

You’re still conflating two concepts, arrays and multi-length character strings.

You can pick up a F77 or F90 book for pennies from second-hand book handlers. Libraries have been throwing them away for two or three decades now.

B.1.3, pg. 458 for the character*(*)
B.1.6, pg. 460 for function accepting assumed length character
2.11, pg. 26 for character substrings

The thread Error: Rank mismatch in argument ‘cars’ at (1) (scalar and rank-1) - #8 also contains the hints. Maybe this helps:

character     a     ! fixed-length character scalar (length = 1)
character*(4) b     ! fixed-length character scalar (length = 4)
character*(*) c     ! assumed-length character scalar

character*(*) d(:)  ! assumed-shape array of assumed-length characters
character*(*) e(*)  ! assumed-size array of assumed-length characters

Modern Fortran Explained (2018), Metcalf, Reid, Cohen, section 9.13, pg. 206

Chapter 5 for arrays, Chapter 6 for text, Chapter 11 for basic C-interop. It’s a learn-by-example kind of book so not good for looking up a specific function and its API.

Modern Fortran Explained is a reference book. I don’t recommend it for learning the language, but it’s the best for looking up how something works once you know you need it.

The two books work well together, IMO.

You shouldn’t put ANY in. It was just my tongue-in-cheek remark.

This means both of them were assumed-length character scalars, just like you showed in a previous thread.

You started from a false premise. Don’t make the change to begin with.

Instead, we have four open threads for the same problem,

I’ve mentioned the XY problem in one of your earlier threads. The How To Ask Questions The Smart Way linked on that page also contains some good advice:

Before asking a technical question by e-mail, or in a newsgroup, or on a website chat board, do the following:

  1. Try to find an answer by searching the archives of the forum or mailing list you plan to post to.
  2. Try to find an answer by searching the Web.
  3. Try to find an answer by reading the manual.
  4. Try to find an answer by reading a FAQ.
  5. Try to find an answer by inspection or experimentation.
  6. Try to find an answer by asking a skilled friend.
  7. If you’re a programmer, try to find an answer by reading the source code.

When you ask your question, display the fact that you have done these things first; this will help establish that you’re not being a lazy sponge and wasting people’s time. Better yet, display what you have learned from doing these things. We like answering questions for people who have demonstrated they can learn from the answers.

1 Like

Would not be easier just to write “I want to do this and I have tried this and this”, instead of such a mystery?

That is a rather pointless question, because your function ruze2 ignores the values of its arguments and always returns .true if the arguments are valid. If the arguments are invalid, the program is invalid, so “what if I have…” is again a pointless question.

You have not stated the purpose of your program despite repeated requests to do so by people trying to help. You have shown various versions of program code that cannot be compiled successfully, and whose purpose is unknown.

Jonathan Swift derided such an approach to discovering knowledge in the fifth chapter of his satirical novel Gulliver’s Travels, Part 3.

Expect fewer and fewer responses if you continue along the same path, because most people would consider it a waste of time to investigate the effect of making arbitrary changes to nonfunctioning programs.

What does work mean?

1 Like