0

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.

2
  • 3
    Get a good Fortran book, I would suggest Metcalf, Reid and Cohen. Commented Jul 25, 2013 at 19:03
  • So this is one of those questions you lazily write at the end of being awake for way too many hours (while reading someone else's code) and your brain decides to all but shut down. I appreciate the lack of name calling, because it's certainly deserved! Commented Jul 26, 2013 at 14:49

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.