Iris Breda
Iris Breda

Reputation: 41

How to know the number of non-zero elements of a Fortran array?

So I have something like this:

INTEGER i
REAL value(10)

DO i = 1,5 
  value(i) = 1
ENDDO

So now my value = (1,1,1,1,1,0,0,0,0,0). What would be the function that gives size = 5 (the size of the array without the zeros)?

Upvotes: 4

Views: 4919

Answers (1)

Just count the non-zero elements

print *, count(value/=0)

Upvotes: 8

Related Questions