0

I have an array, from which I want to have some information.

I wrote a small DO-loop, but I don't know why it always returns

integer :: inn=0
parameter :: m=115200
real*8 :: da1(m)

DO i=1, 115200
    IF( i<=19200 .and. da1(i)>1 .and. da1(i)<999.9999 .and. da1(i)<-1 )then
        inn=inn+1
    END IF
END DO
write(*,*) 'inn=',inn
  1. why it always prints 0, whereas, I checked in the file and this array indeed has many values in the defined range
  2. If the fault is in logic, could someone please give me some pointers on not making such mistakes in the future?
Alexander Vogt
  • 17,879
  • 13
  • 52
  • 68
PT2009
  • 117
  • 1
  • 10

2 Answers2

2

The problem is your conditional:

da1(i).gt.1.00 .and. da1(i).lt.999.9999 .and. da1(i).lt.-1.000

How can a number (here: da1(i)) be > 1 and < -1 at the same time? That conditional is always false, and inn is never incremented.

Alexander Vogt
  • 17,879
  • 13
  • 52
  • 68
2

Extended comment rather than answer. The loop could be entirely replaced, probably by

count( da1(1:19200)>1 .and. da1(1:19200)<999.999 )

I write probably because I haven't tested this.

I think looping over a range i = 1, 115200 and then, inside the loop, testing that i<=19200 is just wrong. If you want to loop, write i = 1, 19200.

High Performance Mark
  • 77,191
  • 7
  • 105
  • 161