We want to create a structure holding strings that vary greatly in length that can be modified during program execution. So we are using deferred length pointers. However, we are running into a problem deallocating them later. Below is a greatly simplified program that demonstrates the issue. The deallocate in the main program works. The one in subroutine a crashes.
character(:), pointer :: ptr1
character(:), pointer :: ptr2
integer ierr
allocate(character(12) :: ptr1, stat = ierr)
ptr1 = "ABCDEFGHIJKLM"
ptr2 => ptr1
deallocate(ptr2)
allocate(character(12) :: ptr1, stat = ierr)
ptr1 = "MLKJIHGFEDCBA"
call a(ptr1)
contains
subroutine a(ptr)
character(:), pointer :: ptr
ptr2 => ptr
deallocate(ptr2)
end subroutine a
end