I've seen this asked for other languages, but having just found out how nicely Fortran can handle arrays, I thought there might be an easy way to do this without loops.
Currently I'm searching over a 3D array looking at 'nearest neighbours' to see if they contain the letter 'n', and whenever it finds this value, I want it to perform some clusterLabel assignment (which isn't relevant for this question)
I wanted to use if(lastNeighArray.eq."n") then...<rest of code>
but for obvious reasons it doesn't like checking an array against a value. Neither does it like me using lastNeighArray(:)
, even though I'd like it to check each of the elements one at a time. where(lastNeighArray.eq."n")
doesn't work as I have a case statement inside the where loop and I get the error WHERE statements and constructs must not be nested.
So I'm a little stuck. What I really want is something like when(lastNeighArray.eq."n")
but that doesn't exist.
I've also looked at any
and forall
but they don't seem like the right choice.
By default, Fortran indexes the first element of an array as 1. C and C++ index it as 0.
elements in a logical MASK , or, if the DIM argument is supplied, counts the number of elements along each row of the array in the DIM direction. If the array has zero size, or all of the elements of MASK are . FALSE. , then the result is 0 . The type shall be LOGICAL .
ANY should actually be the right choice
if ( ANY( lastNeighArray=="n" ) ) then
there is also ALL if you wanted the whole array to contain that value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With