Fortran语言:如何检查是否数组包含的价值? [英] Fortran:How to check if array contains value?

查看:369
本文介绍了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.

目前我正在寻找在一个三维阵列看着'近邻',看看他们是否包含字母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)

我想用如果然后...&LT(lastNeighArray.eq的n); code取代的休息;
但显而易见的原因,它不会像检查对值的数组。无论是用做它像我 lastNeighArray(:),即使我想它在同一时间检查每个元素之一。 在哪里(lastNeighArray.eq。N),因为我有哪里循环内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实际上应该是正确的选择。

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语言:如何检查是否数组包含的价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆