当传递多维数组的大小调整 [英] Resizing of Multi-Dimensional Arrays when Passed

查看:184
本文介绍了当传递多维数组的大小调整的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这个帖子阵列的所有引用都是多维的。

All references to arrays in this post are multi-dimensional.

我来知道,当一个数组传递一个子程序,它可以具有不同尺寸/大小作为呼叫者声明。

I came to know that when an array is passed a subroutine, it can be declared with different dimensions/sizes as the caller.

作为具体的例子,BMAIN声明与主程序尺寸(6,5)。 BMAIN传递到子程序作为BSUB,它被声明为:

As a specific example, BMAIN is declared with DIMENSION(6,5) in the main program. BMAIN is passed to a subroutine as BSUB, which is declared as:

INTEGER, INTENT(IN) :: BSUB(3,2,0:4)

问题:

在BSUB的条目只是一个从SBMAIN充满直到把它充满(在这里顺序<一个解释href=\"http://stackoverflow.com/questions/24472166/linear-indexing-of-multi-dimension-arrays-in-fortran\">Linear多维数组Fortran中)?的索引

是否有编译器执行任意尺寸匹配?例如,已经BSUB被宣布为BSUB(0:4,3,2),将它仍然保持在正确的地方,正确的条目

Are there any dimension matching performed by the compiler? For instance, had BSUB been declared as BSUB(0:4,3,2), would it still hold the correct entries in the correct places?

推荐答案

从的Fortran 2008标准(12.5.2.11.4):

From the Fortran 2008 standard (12.5.2.11.4):

这再次$ P $的实际参数psents元素序列
  对应于这是一个伪参数数组的序列
  与哑参相关联的,如果伪参数是一个
  明确形或假定大小的数组。实际的等级和形状
  参数不需要与伪参数的等级和形状同意,
  但元素的哑参数不得超过
  实际参数的元素序列中元素的个数。如果
  在伪参数假定大小,在元件的数目
  伪参数是元素中的元素数完全
  序列。

An actual argument that represents an element sequence and corresponds to a dummy argument that is an array is sequence associated with the dummy argument if the dummy argument is an explicit-shape or assumed-size array. The rank and shape of the actual argument need not agree with the rank and shape of the dummy argument, but the number of elements in the dummy argument shall not exceed the number of elements in the element sequence of the actual argument. If the dummy argument is assumed-size, the number of elements in the dummy argument is exactly the number of elements in the element sequence.

这是完全合法的使用在子程序阵列的不同的形状和排名,只是不引用更多的元素在子程序比数组实际上有。阵临时可能是必要的,但往往事实并非如此。

It is completely legal to use a different shape and rank of the array in the subroutine, just do not reference more elements in the subroutine than the array actually has. Array temporary may be necessary, but often it is not.

这篇关于当传递多维数组的大小调整的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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