Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
398 views
in Technique[技术] by (71.8m points)

fortran90 - Zero indexed array in Fortran?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 arrays defaultly start with index 1 when you declare them

INTEGER, DIMENSION(3) :: v

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

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

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.

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 )

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...