Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!
26747 Discussions

Compiler mistakenly reads loop condition as array, not scalar

Skinner__Taylor
Beginner
465 Views

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
Lorri_M_Intel
Employee
465 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

Skinner__Taylor
Beginner
465 Views

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

Reply