module raboof_class implicit none private public raboof_t, new, delete public get_data type raboof_t private real(8), dimension(:,:), pointer :: a integer(4) :: b end type interface new module procedure init_raboof end interface interface delete module procedure del_raboof end interface contains subroutine init_raboof(self, n) type(raboof_t) :: self integer(4), intent(in) :: n allocate(self%a(n,n)) call do_some_stuff(self) end subroutine subroutine del_raboof(self) type(raboof_t) :: self deallocate(self%a) end subroutine subroutine get_data(self, d) type(raboof_t) :: self real(8), dimension(:,:), pointer :: d d=>self%a end subroutine subroutine do_some_stuff(self) type(raboof_t) :: self integer(4) :: i,j self%b=0 call filler contains subroutine filler() do i=1,size(self%a(1,:)) do j=1,size(self%a(:,1)) self%a(i,j)=dble(i+j) end do end do end subroutine end subroutine end module program foobar use raboof_class implicit none type(raboof_t) :: rb call new(rb, 10) call whatever(rb) contains subroutine whatever(rb) type(raboof_t) :: rb real(8), dimension(:,:), pointer :: bar call get_data(rb, bar) print *, bar end subroutine end program