如何增加数组大小上即时Fortran语言? [英] How to increase array size on-the-fly in Fortran?

查看:573
本文介绍了如何增加数组大小上即时Fortran语言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序正在运行,虽然3D阵列,标签'集群',它发现,然后做一些检查,看是否有邻居簇比当前群集较高的标签。还有一个保存'适当'簇标签第二个阵列。如果发现第n相邻集群正确标记,该元素被分配到0,否则将其分配给正确的标签(例如,如果第n个站点有标签2,和邻居标记为3的第三元素labelArray设置为2)。我有一个很好的理由这样做,说实话!

My programme is running though 3D array, labelling 'clusters' that it finds and then doing some checks to see if any neighbouring clusters have a label higher than the current cluster. There's a second array that holds the 'proper' cluster label. If it finds that the nth adjoining cluster is labelled correctly, that element is assigned to 0, otherwise is assigns it to the correct label (for instance if the nth site has label 2, and a neighbour is labeled 3, the 3rd element of the labelArray is set to 2). I've got a good reason to do this, honest!

我要的是能够给labelArray的第n个元素分配的飞行。我看着分配数组,并宣布事情 labelArray(*),但我真的不理解这些,尽管在网上搜索,计算器和

All I want is to be able to assign the nth element of the labelArray on the fly. I've looked at allocatable arrays and declaring things as labelArray(*) but I don't really understand these, despite searching the web, and stackoverflow.

因此​​,对这样的帮助将是真棒。

So any help on doing this would be awesome.

推荐答案

下面是一些code例子显示使用Fortran的可分配数组的几种方式堆栈溢出问题:<一href=\"http://stackoverflow.com/questions/8264336/how-to-get-priorly-unkown-array-as-the-output-of-a-function-in-fortran\">How获得而先行 - 未知的数组中的Fortran 函数的输出:声明,分配,用于测试已被被分配,使用上分配新MOVE_ALLOC和分配。未显示有明确的释放,因为例子都使用MOVE_ALLOC和自动释放的过程中退出。

Here is a Stack Overflow question with some code examples showing several ways of using Fortran allocatable arrays: How to get priorly-unkown array as the output of a function in Fortran: declaring, allocating, testing for being already being allocated, using the new move_alloc and allocation on assignment. Not shown there is explicit deallocation, since the examples are using move_alloc and automatic deallocation on exit of a procedure.

P.S。如果你想重复添加一个元素,你应该考虑一下你的数据结构的方法。通过生长阵列添加一次一个元素不是一个有效的方法。成长从N个元素,以N + 1的Fortran数组可能意味着建立一个新的数组和复制所有现有元素。一个更合适的数据结构可能是一个链表。您可以通过创建一个用户定义的类型和使用指针创建Fortran语言链表。你成员链一起,从一个到下一个指点。的开销增加另一成员是未成年人。的缺点是,它是最简单的访问列表的成员中的顺序。你没有一个数组的能力,方便使用索引来访问成员以任何顺序。

P.S. If you want to repeatedly add one element you should think about your data structure approach. Adding one element at a time by growing an array is not an efficient approach. To grow an array from N elements to N+1 in Fortran will likely mean creating a new array and copying all of the existing elements. A more appropriate data structure might be a linked list. You can create a linked list in Fortran by creating a user-defined type and using pointers. You chain the members together, pointing from one to the next. The overhead to adding another member is minor. The drawback is that it is easiest to access the members of the list in order. You don't have the easy ability of an array, using indices, to access the members in any order.

信息有关的Fortran链表,我在网上找到:<一href=\"http://www-uxsup.csx.cam.ac.uk/courses/Fortran/paper_12.pdf\">http://www-uxsup.csx.cam.ac.uk/courses/Fortran/paper_12.pdf和<一个href=\"http://www.iag.uni-stuttgart.de/IAG/institut/abteilungen/numerik/images/4/4c/Pointer_Introduction.pdf\">http://www.iag.uni-stuttgart.de/IAG/institut/abteilungen/numerik/images/4/4c/Pointer_Introduction.pdf

Info about linked lists in Fortran that I found on the web: http://www-uxsup.csx.cam.ac.uk/courses/Fortran/paper_12.pdf and http://www.iag.uni-stuttgart.de/IAG/institut/abteilungen/numerik/images/4/4c/Pointer_Introduction.pdf

这篇关于如何增加数组大小上即时Fortran语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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