how to write wrapper for 'allocate'

后端 未结 2 1476
天命终不由人
天命终不由人 2020-12-01 08:50

I am trying to write a wrapper for \'allocate\' function, i.e. function which receives an array and dimensions, allocates memory and returns allocated array. The most import

2条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-01 09:14

    subroutine memory(array, length) has as it first dummy parameter 1-dimensional array (real(8), allocatable, intent(out), dimension(:) :: array).

    Calling this subroutine from your main program with 3-dimensional array foo (real(8), allocatable, dimension(:,:,:) :: foo) is error obviously. And this is what compiler actually said.

    If you really need such subroutines write one pair memory/freem subroutines for each array of different dimension - one subroutines pair for 1-dimensional array, another for 2-dimensional array, etc.

    By the way, memory subroutines will be different in general because in order to allocate n-dimensional array you need to pass n extents to above-mentioned subroutine.

提交回复
热议问题