!----------------------------------------------------------------------
      module hist
      implicit none
      type history
        integer :: nlev
        real,pointer :: lev(:)
      end type history
      end module hist
!----------------------------------------------------------------------
      module get_hist
      use hist,only: history
      implicit none
      contains
!
      type(history) function gethist(nlev)
      integer,intent(in) :: nlev
      integer :: ier

      gethist%nlev = nlev
      if (associated(gethist%lev)) then
        write(6,"('deallocating gethist%lev..')")
        deallocate(gethist%lev)
      endif
      write(6,"('allocating gethist%lev: gethist%nlev=',i3)") 
     |  gethist%nlev
      allocate(gethist%lev(gethist%nlev),stat=ier)
      write(6,"('after allocate gethist%lev: gethist%nlev=',i3,
     |  ' ier=',i3)") gethist%nlev,ier

      end function gethist
      end module get_hist
!----------------------------------------------------------------------
      program testalloc
      use hist,only: history
      use get_hist,only: gethist
      implicit none
      type(history) :: h
      integer :: nlev
!
      nlev = 100
      h = gethist(nlev)
      end program testalloc
!----------------------------------------------------------------------
