Bill,
Thanks for the example. I have expanded and this appears to be an error.
If after testing the status of vector, if I deallocate, the program crashes.
Alternatively, if I allocate, test is correct and then deallocate test is now correct.
type abcd
! sequence
integer :: n
integer,allocatable :: vector(:)
end type
type (abcd), allocatable :: my_def(:)
integer :: n, stat
write (*,*) 'allocated my_def =',allocated(my_def)
allocate ( my_def(5), stat=stat )
write (*,*) 'allocate my_def(5), stat=',stat
write (*,*) 'allocated my_def =',allocated(my_def)
if ( allocated(my_def(1)%vector) ) then
print *,'This is in error'
!z this code crashes program
!z deallocate ( my_def(1)%vector, stat=stat )
!z write (*,*) 'deallocate my_def(1)%vector, stat=',stat
!z write (*,*) 'allocated(my_def(1)%vector =', allocated(my_def(1)%vector)
else
print *,'This is correct'
end if
write (*,*) 'allocated(my_def(1)%vector =', allocated(my_def(1)%vector)
allocate ( my_def(1)%vector(10), stat=stat )
write (*,*) 'allocate my_def(1)%vector(10), stat=',stat
write (*,*) 'allocated(my_def(1)%vector =', allocated(my_def(1)%vector)
if( .not. allocated(my_def(1)%vector)) then
print *,'This is in error'
else
print *,'This is correct'
endif
deallocate ( my_def(1)%vector, stat=stat )
write (*,*) 'deallocate my_def(1)%vector, stat=',stat
write (*,*) 'allocated(my_def(1)%vector =', allocated(my_def(1)%vector)
allocate ( my_def(1)%vector(10), stat=stat )
write (*,*) 'allocate my_def(1)%vector(10), stat=',stat
write (*,*) 'allocated(my_def(1)%vector =', allocated(my_def(1)%vector)
end
In my actual code, I use allocatable components in a module type array but rarely deallocate these components.