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

**URL:** <https://fortran-lang.discourse.group/t/error-if-clause-at-1-requires-a-scalar-logical-expression/3537>\
**Category:** Help\
**Created:** [May 24, 2022, 12:38am UTC](https://fortran-lang.discourse.group/t/error-if-clause-at-1-requires-a-scalar-logical-expression/3537 "2022-05-24T00:38:09Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![giraffe2](https://avatars.discourse-cdn.com/v4/letter/g/7bcc69/32.png) [@giraffe2](https://fortran-lang.discourse.group/u/giraffe2)\
**Post date:** [May 24, 2022, 12:38am UTC](https://fortran-lang.discourse.group/t/error-if-clause-at-1-requires-a-scalar-logical-expression/3537/1 "2022-05-24T00:38:09Z")

</div>

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

```auto
  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

```

```auto
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,

---

<div class="post-metadata">

**Author:** ![mecej4](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/mecej4/32/855_2.png) [@mecej4](https://fortran-lang.discourse.group/u/mecej4)\
**Post date:** [May 24, 2022, 1:06am UTC](https://fortran-lang.discourse.group/t/error-if-clause-at-1-requires-a-scalar-logical-expression/3537/2 "2022-05-24T01:06:11Z")

</div>

This appears to be a restart of an [earlier thread](https://fortran-lang.discourse.group/t/error-rank-mismatch-in-argument-std-at-1-scalar-and-rank-1/3529), under a different user-id. [An even earlier one exists](https://fortran-lang.discourse.group/t/error-rank-mismatch-in-argument-cars-at-1-scalar-and-rank-1/3062), 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.

---

<div class="post-metadata">

**Author:** ![everythingfunctional](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/everythingfunctional/32/176_2.png) [@everythingfunctional](https://fortran-lang.discourse.group/u/everythingfunctional)\
**Post date:** [May 24, 2022, 1:24am UTC](https://fortran-lang.discourse.group/t/error-if-clause-at-1-requires-a-scalar-logical-expression/3537/3 "2022-05-24T01:24:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![milancurcic](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/milancurcic/32/2_2.png) [@milancurcic](https://fortran-lang.discourse.group/u/milancurcic)\
**Post date:** [May 24, 2022, 1:29am UTC](https://fortran-lang.discourse.group/t/error-if-clause-at-1-requires-a-scalar-logical-expression/3537/4 "2022-05-24T01:29:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hamblingreg52](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/hamblingreg52/32/468_2.png) [@hamblingreg52](https://fortran-lang.discourse.group/u/hamblingreg52)\
**Post date:** [May 24, 2022, 7:01am UTC](https://fortran-lang.discourse.group/t/error-if-clause-at-1-requires-a-scalar-logical-expression/3537/5 "2022-05-24T07:01:11Z")

</div>

I understand @everythingfunctional and completely agree with you.

---

<div class="post-metadata">

**Author:** ![ivanpribec](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/ivanpribec/32/3290_2.png) [@ivanpribec](https://fortran-lang.discourse.group/u/ivanpribec)\
**Post date:** [May 24, 2022, 7:28am UTC](https://fortran-lang.discourse.group/t/error-if-clause-at-1-requires-a-scalar-logical-expression/3537/6 "2022-05-24T07:28:34Z")

</div>

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](https://meta.discourse.org/t/how-to-handle-multiple-account/15244). @milancurcic, do you know if the Fortran Discourse has `flag_sockpuppets` enabled?

---

<div class="post-metadata">

**Author:** ![mecej4](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/mecej4/32/855_2.png) [@mecej4](https://fortran-lang.discourse.group/u/mecej4)\
**Post date:** [May 24, 2022, 7:38am UTC](https://fortran-lang.discourse.group/t/error-if-clause-at-1-requires-a-scalar-logical-expression/3537/7 "2022-05-24T07:38:53Z")

</div>

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:

```auto
     WRITE (*,*) 'STEP1 SUCCESSFUL'
     END

```

---

<div class="post-metadata">

**Author:** ![Arjen](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Arjen](https://fortran-lang.discourse.group/u/Arjen)\
**Post date:** [May 24, 2022, 9:00am UTC](https://fortran-lang.discourse.group/t/error-if-clause-at-1-requires-a-scalar-logical-expression/3537/9 "2022-05-24T09:00:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![milancurcic](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/milancurcic/32/2_2.png) [@milancurcic](https://fortran-lang.discourse.group/u/milancurcic)\
**Post date:** [May 24, 2022, 2:04pm UTC](https://fortran-lang.discourse.group/t/error-if-clause-at-1-requires-a-scalar-logical-expression/3537/11 "2022-05-24T14:04:04Z")

</div>

> [@ivanpribec](#):
>
> 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](https://meta.discourse.org/t/how-to-handle-multiple-account/15244). @milancurcic, do you know if the Fortran Discourse has `flag_sockpuppets` enabled?

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.

---

<div class="post-metadata">

**Author:** ![CRquantum](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/crquantum/32/730_2.png) [@CRquantum](https://fortran-lang.discourse.group/u/CRquantum)\
**Post date:** [May 25, 2022, 7:21am UTC](https://fortran-lang.discourse.group/t/error-if-clause-at-1-requires-a-scalar-logical-expression/3537/13 "2022-05-25T07:21:23Z")

</div>

Sorry for a naive question.

```auto
CHARACTER CARD1*(*)

```

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

---

<div class="post-metadata">

**Author:** ![Arjen](https://avatars.discourse-cdn.com/v4/letter/a/b9bd4f/32.png) [@Arjen](https://fortran-lang.discourse.group/u/Arjen)\
**Post date:** [May 25, 2022, 7:29am UTC](https://fortran-lang.discourse.group/t/error-if-clause-at-1-requires-a-scalar-logical-expression/3537/14 "2022-05-25T07:29:17Z")

</div>

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

```auto
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:

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

---

<div class="post-metadata">

**Author:** ![ivanpribec](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/ivanpribec/32/3290_2.png) [@ivanpribec](https://fortran-lang.discourse.group/u/ivanpribec)\
**Post date:** [May 25, 2022, 7:09pm UTC](https://fortran-lang.discourse.group/t/error-if-clause-at-1-requires-a-scalar-logical-expression/3537/16 "2022-05-25T19:09:01Z")

</div>

> [@giraffe](#):
>
> ` CHARACTER(*) :: CARD2(:)`

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)](https://fortran-lang.discourse.group/t/error-rank-mismatch-in-argument-std-at-1-scalar-and-rank-1/3529)) 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

```fortran
       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…

---

<div class="post-metadata">

**Author:** ![ivanpribec](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/ivanpribec/32/3290_2.png) [@ivanpribec](https://fortran-lang.discourse.group/u/ivanpribec)\
**Post date:** [May 25, 2022, 7:19pm UTC](https://fortran-lang.discourse.group/t/error-if-clause-at-1-requires-a-scalar-logical-expression/3537/18 "2022-05-25T19:19:30Z")

</div>

> [@giraffe](#):
>
> I defined CARD2 differently to get by a warning message.

🤦‍♂️

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

---

<div class="post-metadata">

**Author:** ![ivanpribec](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/ivanpribec/32/3290_2.png) [@ivanpribec](https://fortran-lang.discourse.group/u/ivanpribec)\
**Post date:** [May 25, 2022, 7:42pm UTC](https://fortran-lang.discourse.group/t/error-if-clause-at-1-requires-a-scalar-logical-expression/3537/20 "2022-05-25T19:42:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ivanpribec](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/ivanpribec/32/3290_2.png) [@ivanpribec](https://fortran-lang.discourse.group/u/ivanpribec)\
**Post date:** [May 25, 2022, 7:58pm UTC](https://fortran-lang.discourse.group/t/error-if-clause-at-1-requires-a-scalar-logical-expression/3537/23 "2022-05-25T19:58:49Z")

</div>

> [@giraffe](#):
>
> Modern Fortran explained by Metcalf, Reid, and Cohen

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](https://fortran-lang.discourse.group/t/error-rank-mismatch-in-argument-cars-at-1-scalar-and-rank-1/3062/8) also contains the hints. Maybe this helps:

```fortran
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

```

> [@giraffe](#):
>
> Can you explain to me in detail how “ANY” works? I don’t want to put a bug in the code.

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

---

<div class="post-metadata">

**Author:** ![milancurcic](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/milancurcic/32/2_2.png) [@milancurcic](https://fortran-lang.discourse.group/u/milancurcic)\
**Post date:** [May 25, 2022, 7:59pm UTC](https://fortran-lang.discourse.group/t/error-if-clause-at-1-requires-a-scalar-logical-expression/3537/24 "2022-05-25T19:59:01Z")

</div>

> [@giraffe](#):
>
> I have the following two book on my desk:
> 
> - Modern Fortran by Milan Curcic
> - Modern Fortran explained by Metcalf, Reid, and Cohen
> 
> Where should I look in these books? Will they help?

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.

---

<div class="post-metadata">

**Author:** ![ivanpribec](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/ivanpribec/32/3290_2.png) [@ivanpribec](https://fortran-lang.discourse.group/u/ivanpribec)\
**Post date:** [May 25, 2022, 8:22pm UTC](https://fortran-lang.discourse.group/t/error-if-clause-at-1-requires-a-scalar-logical-expression/3537/25 "2022-05-25T20:22:09Z")

</div>

> [@giraffe](#):
>
> Can you explain to me in detail how “ANY” works? I don’t want to put a bug in the code.

You shouldn’t put `ANY` in. It was just my [tongue-in-cheek](https://en.wikipedia.org/wiki/Tongue-in-cheek) remark.

> [@giraffe](#):
>
> CARD2 was originally defined like CARD1.

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

> [@Error: Rank mismatch in argument 'std' at (1) (scalar and rank-1)](https://fortran-lang.discourse.group/t/error-rank-mismatch-in-argument-std-at-1-scalar-and-rank-1/3529/1):
>
> If I change the definition of:
> 
> ```auto
> CHARACTER CARD1*(*)
> To:
> CHARACTER CARD1(*)
> 
> ```
> 
> I get the error:
> 
> ```auto
> 18 IF (RUZE(REPRESENT(1:7),STD(1:7)))THEN
> 1
> Error: Rank mismatch in argument 'card2' at (1) (scalar and rank-1)
> 
> ```
> 
> What do I do?
> 
> ```auto
> LOGICAL FUNCTION RUZE(CARD1,CARD2)
> IMPLICIT NONE
> CHARACTER CARD1*(*),CARD2*(*)
> 
> ```

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

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

- this one,
- [Error: Rank mismatch in argument 'std' at (1) (scalar and rank-1)](https://fortran-lang.discourse.group/t/error-rank-mismatch-in-argument-std-at-1-scalar-and-rank-1/3529)
- [Error: Procedure at (1) with assumed-shape dummy argument must have an explicit interface - #6 by Pap](https://fortran-lang.discourse.group/t/error-procedure-at-1-with-assumed-shape-dummy-argument-must-have-an-explicit-interface/3546/6)
- [Fatal Error: Can't open module file 'first\_module.mod' for reading at (1): No such file or directory - #4 by Pap](https://fortran-lang.discourse.group/t/fatal-error-cant-open-module-file-first-module-mod-for-reading-at-1-no-such-file-or-directory/3553/4)

I’ve mentioned the [XY problem](https://xyproblem.info/) in one of your earlier threads. The [How To Ask Questions The Smart Way](http://www.catb.org/esr/faqs/smart-questions.html) 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.

---

<div class="post-metadata">

**Author:** ![conradoat](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/conradoat/32/1537_2.png) [@conradoat](https://fortran-lang.discourse.group/u/conradoat)\
**Post date:** [May 25, 2022, 8:28pm UTC](https://fortran-lang.discourse.group/t/error-if-clause-at-1-requires-a-scalar-logical-expression/3537/26 "2022-05-25T20:28:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mecej4](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/mecej4/32/855_2.png) [@mecej4](https://fortran-lang.discourse.group/u/mecej4)\
**Post date:** [May 26, 2022, 12:29pm UTC](https://fortran-lang.discourse.group/t/error-if-clause-at-1-requires-a-scalar-logical-expression/3537/31 "2022-05-26T12:29:17Z")

</div>

> [@giraffe](#):
>
> But, what if I have the following definition in make\_move() and make the following funcdtion call within make\_move():

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](https://www.gutenberg.org/files/829/829-h/829-h.htm#part03).

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.

---

<div class="post-metadata">

**Author:** ![everythingfunctional](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/everythingfunctional/32/176_2.png) [@everythingfunctional](https://fortran-lang.discourse.group/u/everythingfunctional)\
**Post date:** [May 26, 2022, 3:57pm UTC](https://fortran-lang.discourse.group/t/error-if-clause-at-1-requires-a-scalar-logical-expression/3537/32 "2022-05-26T15:57:13Z")

</div>

> [@giraffe](#):
>
> Here’s the original code untouched by me. How do you get it to compile and make the statements work?

What does work mean?
