I am trying to test the Fortran 2003 feature that allows to add an element to an array. Consider the following code:
program test
implicit none
integer :: i
integer, parameter :: n=6, j=2
integer, allocatable :: inx(:)
open(3, file='check.dat')
allocate(inx(0:1)); inx=0
do i=0,1
write(3,*) i, inx(i)
end do
do i=1,n
inx=[inx,i+j]
end do
do i=0,n
write(3,*) i, inx(i)
end do
end program test
I get the following runtime error:
At line 22 of file test.f90
Fortran runtime error: Index '0' of dimension 1 of array 'inx' below lower bound of 1
I explicitly set inx(0:1)
, so that inx
's index starts from zero ( I want inx(0:some number))
but it seems that's it's reallocating from 1
?