Array Expression

Hello, why does this little program give me an error?

  • program array
    real :: a(4),b(4)

a=(/0.,3.,3.,1./)
b=(/0.,3.,3.,1./)

if (a.eq.b) write (6,*) “a and b are the same”

stop
end

PGF90-S-0083-Vector expression used where scalar expression required (array.f: 8)
0 inform, 0 warnings, 1 severes, 0 fatal for array

I thought Fortran 90 allowed these expressions. Thanks!

Hi lionel,

The expression “a.eq.b” is valid. However, the expression returns an array of logicals which can’t be used in an if statement. Adding the ‘all’ intrinsic to perform a reduction should get the desired behavior:

% cat tmp.f90
      program array
      real :: a(4),b(4)

      a=(/0.,3.,3.,1./)
      b=(/0.,3.,3.,1./)

      if (all(a.eq.b)) write (6,*) "a and b are the same"

      stop
      end
% pgf90 tmp.f90
% a.out
 a and b are the same
FORTRAN STOP

Hope this helps,
Mat