consider the following code:
program test
implicit none
integer :: i
integer, parameter :: N=6
integer :: inx(0:N-1)
type a2
integer, pointer :: xp(:)
end type a2
type(a2), allocatable :: new(:)
allocate(new(0:N-1))
inx=[2, 2, 0, 3, 6, 5]
do i=0,N-1
if (inx(i)==0) then
allocate(new(i)%xp(inx(i))); new(i)%xp(inx(i))=i
print*, 'i, new%xp(i)=', i, new(i)%xp(inx(i))
end if
end do
end program test
When I run this with gfortran
I get the following error:
At line 28 of file test.f90
Fortran runtime error: Index '0' of dimension 1 of array 'new%xp' below lower bound of 1
which I am having trouble understanding. Why is the component xp
of new
not allowed to have index 0
?