I am trying to understand (and reproduce) the following array declaration in a fortran code segment I am editing
real, dimension (-posint:) :: test_array
Here, posint
is a positive integer. I am confused about how the negative indexing syntax works, as I have attempted to reproduce with a MWE, but it failed to compile:
program Array_Games
implicit none
integer, dimension(-3:,3) :: test_array
test_array = reshape((/ 1, 2, 3, 4, 5, 6, 7, 8, 9 /), shape(test_array))
end program Array_Games
The compilation error is: Error: Bad array specification for assumed shape array at (1)
.
However, changing the array index declaration slightly in test_array
compiles successfully:
program Array_Games
implicit none
integer, dimension(-3:-1,3) :: test_array
test_array = reshape((/ 1, 2, 3, 4, 5, 6, 7, 8, 9 /), shape(test_array))
end program Array_Games
Therefore, the question is: how does the array declaration, here,
real, dimension (-posint:) :: test_array
work (i.e. compile without error)? I would have expected it to look more like
real, dimension (-posint:another_number) :: test_array
where another_number
is another integer.