!------------------------------------------------------------------------------
!
!  Program name:
!
!    pointer_status
!
!  Purpose:
!
!    This program shows the status of pointers at different stages
!
!  Note:
!
!    The disassociation of p did not affect q even though they were 
!    both pointing at the same object. After being nullified, p can 
!    be associated again either with the same or a different object later. 
!    The last line just illustrates that a NULLIFY statement can 
!    have more than one pointer argument. 
!
!------------------------------------------------------------------------------

PROGRAM array_pointers

  IMPLICIT NONE 
  REAL, POINTER :: p, q 	! undefined association status
  REAL, TARGET :: t1 = 3.4, t2 = 4.5 

  p => t1			! p points to t1
  PRINT *, "After p => t1, ASSOCIATED(p) = ", ASSOCIATED(p)    	! .T.

  q => t1			! q also points to t1
  PRINT *, "After q => t1, ASSOCIATED(q) = ", ASSOCIATED(q)    	! .T.

  PRINT *, "ASSOCIATED(p, q) = ", ASSOCIATED(p, q)             	! .T.
  PRINT *, "but ASSOCIATED(p, t2) = ", ASSOCIATED(p, t2)       	! .F.

  NULLIFY(p)			
  PRINT *, "After NULLIFY(p), ASSOCIATED(p) = ", ASSOCIATED(p) 	! .F.

  PRINT *, "ASSOCIATED(p, q) = ", ASSOCIATED(p, q)             	! .F.
  ! The disassociation of p did not affect q even though 
  ! they were both pointing at the same object.
  PRINT *, "ASSOCIATED(q, t1) = ", ASSOCIATED(q, t1)           	! .T.

  ! After being nullified, p can be associated again either 
  ! with the same or different object later
  p => t2			! p points to t2
  PRINT *, "After p => t2, ASSOCIATED(p) = ", ASSOCIATED(p)     ! .T.

  ! a NULLIFY statement can have more than one pointer argument
  NULLIFY(p, q)

END PROGRAM array_pointers
