如何检查Fortran数组是否包含值

如何检查Fortran数组是否包含值

本文介绍了如何检查Fortran数组是否包含值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到这要求其他语言,但刚刚发现Fortran可以很好地处理数组,我想可能有一种简单的方法来做这个没有循环。

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.

目前我在搜索最近邻居的3D数组,看它们是否包含字母n,每当找到这个值时,我希望它执行一些clusterLabel赋值(这不是与此问题相关)

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)

我想使用 if(lastNeighArray.eq。n)然后...<其余代码>
但由于显而易见的原因,它不喜欢根据值检查数组。它也不像我使用 lastNeighArray(:),即使我希望它一次检查一个元素。 其中(lastNeighArray.eq。n)不起作用,因为我在where循环中有一个case语句,我得到错误 WHERE语句并且结构不能嵌套。

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.

所以我有点卡住了。我真正想要的是类似的时候(lastNeighArray.eq。n)但这不存在。

So I'm a little stuck. What I really want is something like when(lastNeighArray.eq."n") but that doesn't exist.

我还看了任何 forall 但它们似乎不是正确的选择。

I've also looked at any and forall but they don't seem like the right choice.

推荐答案

任何实际上都应该是正确的选择

ANY should actually be the right choice

if ( ANY( lastNeighArray=="n" ) ) then

如果你想让整个数组包含那个值,那么还有ALL。

there is also ALL if you wanted the whole array to contain that value.

这篇关于如何检查Fortran数组是否包含值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 17:03