本文介绍了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.

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

07-30 01:38
查看更多