test_2d Subroutine

public subroutine test_2d()

Arguments

None

Calls

proc~~test_2d~~CallsGraph proc~test_2d test_2d asserttrue asserttrue proc~test_2d->asserttrue interface~nearlyequal nearlyEqual proc~test_2d->interface~nearlyequal

Source Code

   subroutine test_2d()
      type (LocalMemReference) :: a
      integer (kind=INT32),allocatable :: i(:,:)
      integer (kind=INT64),allocatable :: j(:,:)
      real (kind=REAL32), allocatable  :: r(:,:)
      real (kind=REAL64), allocatable  :: d(:,:)

      integer ( kind=INT32), pointer :: iPtr(:,:)
      integer ( kind=INT64), pointer :: jPtr(:,:)
      real ( kind=REAL32), pointer :: rPtr(:,:)
      real ( kind=REAL64), pointer :: dPtr(:,:)

      allocate(i(10,2))
      i = 100
      a = LocalMemReference(i)
      call c_f_pointer(a%base_address, iptr,a%shape)
      @assertTrue(all(iptr == i))
      call a%deallocate()
      @assertTrue(.not. associated(a%i_ptr))

      allocate(j(10,5))
      j = 10000
      a = LocalMemReference(j)
      call c_f_pointer(a%base_address, jptr,shape(j))
      @assertTrue(all(jptr == j))
      call a%deallocate()
      @assertTrue(.not. associated(a%i_ptr))

      allocate(r(10,3))
      r = 100.0
      a = LocalMemReference(r)
      call c_f_pointer(a%base_address, rptr, a%shape)
      @assertTrue(nearlyEqual(rptr(:,1), r(:,1)))
      call a%deallocate()
      @assertTrue(.not. associated(a%i_ptr))

      allocate(d(2,3))
      d = 100.0d0
      a = LocalMemReference(d)
      call c_f_pointer(a%base_address, dptr,shape(d))
      @assertTrue(nearlyEqual(dptr(:,1), d(:,1)))
      call a%deallocate()
      @assertTrue(.not. associated(a%i_ptr))

      deallocate(i)
      allocate(i(0,2))
      a = LocalMemReference(i)
      call c_f_pointer(a%base_address, iptr,shape(i))
      !@assertFalse(associated(iptr))
      @assertTrue( size(a%i_ptr) ==0)
      call a%deallocate()
      @assertTrue(.not. associated(a%i_ptr))

   end subroutine test_2d