Allcoate 2-Dimensional array of type: real
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real, | intent(inout), | dimension(:, :), allocatable | :: | var | Variable to which memory is allocated |
|
integer, | intent(in) | :: | start1 | Starting index of Var array's dimension |
||
integer, | intent(in) | :: | stop1 | Last index of Var array's dimension |
||
integer, | intent(in) | :: | start2 | Starting index of Var array's dimension |
||
integer, | intent(in) | :: | stop2 | Last index of Var array's dimension |
||
character(len=*), | intent(in), | optional | :: | errmsg | Error message to print if mem_stat is not 0(successful) |
subroutine alloc_rank2_real(var, start1, stop1, start2, stop2, errmsg)
!< Allcoate 2-Dimensional array of type: real
implicit none
real, dimension(:, :), intent(inout), allocatable :: var
!< Variable to which memory is allocated
integer, intent(in) :: start1, start2
!< Starting index of Var array's dimension
integer, intent(in) :: stop1, stop2
!< Last index of Var array's dimension
integer :: mem_stat
!< Status of the memory allocation process
character(len=*), intent(in), optional :: errmsg
!< Error message to print if mem_stat is not 0(successful)
allocate(var(start1:stop1, start2:stop2), stat=mem_stat)
if (mem_stat /= 0) then
if (present(errmsg)) then
print *, errmsg
else
print *, 'Error: Could not allocate memory.'
end if
print *, 'Required extent: ', stop1 - start1 + 1, &
stop2 - start2 + 1
stop
end if
end subroutine alloc_rank2_real