Search code examples
arraysfortrando-loops

Fortran: Counter inside DO-loop


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?

Solution

  • 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.