Alex
Alex

Reputation: 2040

Fortran multidimensional array syntax

Two quick syntax question

Would

real(4), ALLOCATABLE:: thing1(:,:)

Create a 2D array with 2 columns, an as of yet undefined number of rows, where each element is an array of 4 reals?

Secondly, would

real(4) box(3,3),versions,revert

Create two arrays of length 4, and 2D array of size 3x3 where each element is an array of length 4.

Upvotes: 0

Views: 269

Answers (1)

dwwork
dwwork

Reputation: 858

The short answer is no to both.

REAL(4) does not create an array of reals, it determines the KIND of REAL. I refer you to this question: Fortran 90 kind parameter to explain this.

Secondly, thing1(:,:) does not declare two columns, it declares two dimensions. The first being rows, the second being columns.

Your second would create a 3x3 array "box" of reals of kind == 4, which is typically precision "float" in C language.

I'm not sure what versions,revert is supposed to be.

Also, when creating an array, it is typical, and a little more explicit, to use the DIMENSION parameter as such:

REAL(4),ALLOCATABLE,DIMENSION(:,:,:) :: thing1

which can then be allocated later on as:

ALLOCATE(thing1(x,2,4)) Assuming you still wanted 2 columns, x rows, and an array of 4 in each location.

Upvotes: 5

Related Questions