subroutine ps_AddProvenanceRecord(ps,creator,date,annotation)
type(ps_t), intent(inout) :: ps
character(len=*), intent(in) :: creator
character(len=*), intent(in) :: date
type(ps_annotation_t), intent(in), target :: annotation
type(provenance_t), pointer :: p
type(provenance_t), pointer :: q
integer :: depth
allocate(p)
!
! Find the depth of the provenance stack
!
depth = 0
q => ps%provenance
do while (associated(q))
depth = depth + 1
q => q%next
enddo
q => ps%provenance
if (associated(q)) then
p%next => q
q%prev => p
endif
ps%provenance => p
p%record_number = depth + 1
p%creator = trim(creator)
p%date = trim(date)
p%annotation= annotation
end subroutine ps_AddProvenanceRecord