How to check if Fortran array contains value?
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.
AncientSwordRage
I'm just this guy, y'know? (he/him) Secret ninja-muslim programmer, roleplayer and all-round nuisance. Desh by marriage. I have approximate knowledge of many things Cat thumb-servant. I moderate Sci-fi StackExchange, but I'm active on RPG.se, Puzzling.se and I dabble on the writing and worldbuilding StackExchanges. Sci-Fi I used to be the secretary of my university Sci-fi and fantasy club and I love everything from Horror to 'Saturday morning cartoons'. I help moderate this stack (with a diamond), and I'm active/interested in the marvel, back-to-the-future, star-wars and ghostbusters tags. Happy to meet and greet new users, as well as point people in the right direction for story-id questions. RPG TO BE FILLED StackOverflow TO BE FILLED
Updated on March 17, 2020Comments
-
AncientSwordRage about 4 years
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 usinglastNeighArray(:)
, 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 errorWHERE 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
andforall
but they don't seem like the right choice.