Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)?

like image 748
Iris Breda Avatar asked Oct 15 '25 21:10

Iris Breda


1 Answers

Just count the non-zero elements

print *, count(value/=0)
like image 93
Vladimir F Героям слава Avatar answered Oct 18 '25 12:10

Vladimir F Героям слава



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!