Fortran 中的零索引数组?

Zero indexed array in Fortran?

有人可以解释什么是 Fortran 中的 零索引数组以及示例。我在 Internet 上没有获得任何内容。

一个零索引数组是一个索引原点为ZERO的数组。这意味着数组的第一个元素由索引 0.

引用

Fortran 数组在声明时默认以索引 1 开头

INTEGER, DIMENSION(3) :: v

这里,符号v表示一个大小为3的一维数组,元素为v(1)v(2)v(3).

但是,Fortran standard 使您可以设置数组的开始和结束索引。例如:

INTEGER, DIMENSION(0:2) :: w

在这种情况下,符号 w 再次表示大小为 3 的一维数组。但现在有了元素 w(0)w(1)w(2)。由于起始索引是 0,这是一个 零索引数组

对于显式形状数组 Section 5.3.8.2 of the standard 声明 DIMENSION 属性可以声明为

DIMENSION ( [lower-bound :] upper-bound )

所以一切皆有可能,如果您愿意,可以从 -42 开始并以 +42 结束。

The values of each lower-bound and upper-bound determine the bounds of the array along a particular dimension and hence the extent of the array in that dimension. If lower-bound appears it specifies the lower bound; otherwise the lower bound is 1. The value of a lower bound or an upper bound may be positive, negative, or zero. The subscript range of the array in that dimension is the set of integer values between and including the lower and upper bounds, provided the upper bound is not less than the lower bound. If the upper bound is less than the lower bound, the range is empty, the extent in that dimension is zero, and the array is of zero size.