Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
101 Views

Compiler mistakenly reads loop condition as array, not scalar

When I try to start a loop as

do while (t_iter .LT. time(ubound(time)))

I get the following compiler error:

-------------- Build: Debug in NewIntegrateSEFromProfiles (compiler: Intel Fortran Compiler for Windows)---------------

ifort.exe /nologo /warn:all  /debug:full  /fpp /free /QxHost /O2    /module:obj\Debug\ /c main.f90 /object:obj\Debug\main.obj
ifort.exe /nologo  /exe:bin\Debug\NewIntegrateSEFromProfiles.exe  obj\Debug\main.obj  
ifort: command line remark #10382: option '/QxHOST' setting '/QxCORE-AVX2'
main.f90(32): error #6512: A scalar-valued expression is required in this context.
    do while (t_iter .LT. time(ubound(time)))

If I switch ubound() to size(), however, it works fine. Both of these functions return the same value (since the array is 1-indexed), and the first iteration returns a single boolean True, not an array. This error seems like unexpected behaviour to me.

(platform = windows 7 64 bit, ifort 18 update 1 in CodeBeans IDE)

0 Kudos
2 Replies
Highlighted
101 Views

If there is no "dim" keyword on the UBOUND intrinsic, the result is an array.  Yes, to us humans a one-element one-dimensional array looks just like a scalar, but to the Fortran standard and to the compiler, it's still an array.

It should work to say "ubound(time,1)" which will give you a scalar that is the upperbound of "time".

                          --Lorri

0 Kudos
Highlighted
101 Views

Ah I see... I'm too used to being coddled by python printing a 1-item list as [1] instead of 1. Thanks

0 Kudos