Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29004 Discussions

Multiple Condition Evaluation - Compaq 6 v Intel 10

m_cash_stramel
Beginner
480 Views
Hi -

We are currently moving some code from Compaq 6 to Intel 10 and I am having difficulty with a particular item of code in a subroutine provided by a supplier.

My issue concerns multiple conditions in 'do while' or 'if' type statements. The code in question follows.

i = len( b )
do while( i.ge.1 .and. b(i:i).eq.' ' )
i = i - 1
enddo

Let's assume that b = ' ', a four character string in which all characters are blank spaces. In the code above, 'i' will eventually become 0 (which is the desired result), and then the last time that the 'do while' evaluates the conditions, it will see i.ge.1 (0.ge.1 = FALSE) and b(i:i).eq.' ' (b(0).eq. ' ' ---> ERROR, subscript less than 1). Now, I can think of better ways to write this particular item so that I don't get this error, but because it is part of larger code provided by a third party I'd rather not modify it. Yes, I can ask them to modify it but that is a whole other story.

My question is this (and I'm sure I'm not the first to ask), but why is the second condition evaluated at all if the first condition is FALSE?

If I compile/run the code in CVF6 I have no issue here and the code completes correctly. However, if I compile/run in IVF10, I get the subscript less than 1 error. Am I correct in assuming that this is being caused by the compiler? If so, is there a setting that I am missing in IVF10 that would turn off evaluation of 'downstream' conditions if the first turns out to be FALSE?

My apologies for being long winded but thanks in advance for any assistance.
0 Kudos
4 Replies
ArturGuzik
Valued Contributor I
480 Views
Hi,

I believe you need to modify the code. Take a look at this (one of many) post related to evaluating IF in IVF and CVF. Steve already explained it very clearly several times.

A.
0 Kudos
m_cash_stramel
Beginner
480 Views
Thank you for the link. I assummed this was a topic that would have been well covered. I just wasn't able to come up with the correct combination of keywords in my search on this forum.

I had actually just found and entirely different thread on the same topic on usenet.

Anyway, as I said above, the code is not mine. It is provided by a third party supplier and I was looking for a quick and easy way to avoid going to them to fix their code.
0 Kudos
Steven_L_Intel1
Employee
480 Views
There is no "quick and easy" way - the code is illegal and broken and must be fixed.
0 Kudos
jimdempseyatthecove
Honored Contributor III
480 Views

The programmer apparently wasthinking C/C++ boolian expression evaluation rules were in effect whereas Fortran rules are in effect. If you do change the code the replace the 4 statements with

i = LEN_TRIM( b )

Jim Dempsey

0 Kudos
Reply