Fortran中的零索引数组? [英] Zero indexed array in Fortran?

查看:260
本文介绍了Fortran中的零索引数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以举例说明什么是Fortran中的零索引数组.我没有从互联网上获得任何内容.

Can someone explain what is zero indexed array in Fortran along with example. I'm not getting any content on that on internet.

推荐答案

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

A zero indexed array is an array who's index origin is ZERO. This means that the first element of the array is referenced by index 0.

Fortran数组在声明时默认从索引1开始

Fortran arrays defaultly start with index 1 when you declare them

INTEGER, DIMENSION(3) :: v

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

Here, the symbol v represents a one-dimensional array of size 3 with elements v(1),v(2) and v(3).

但是, Fortran标准为您提供了设置数组的开始和结束索引的可能性.例如:

However, the Fortran standard gives you the possibility to set the starting and ending index of your array. E.g.:

INTEGER, DIMENSION(0:2) :: w

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

In this case, the symbol w represents again a one-dimensional array of size 3. But now with elements w(0),w(1) and w(2). As the starting index is 0 this is a zero indexed array.

对于显式形状数组标准的5.3.8.2节指出DIMENSION属性可以声明为

For an explicit shape array Section 5.3.8.2 of the standard states that the DIMENSION attribute can be declared as

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

因此,一切皆有可能,如果需要,您可以以-42开头,以+42结尾.

So anything is possible, you can start with -42 and end with +42 if you want.

每个lower-boundupper-bound的值确定 沿着特定维度的数组,因此 该维度中的数组.如果显示lower-bound,则指定下界;否则,将显示下界.否则下限为1.下限或上限的值可以为正,负或零.该数组在该维度上的下标范围是上下限之间(包括上下限)的一组整数值,前提是上限不小于下限.如果上限是 小于下限,范围为空,范围为 维为零,数组的大小为零.

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.

这篇关于Fortran中的零索引数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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