Allcoate 1-Dimensional array of type: integer
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | 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 |
||
character(len=*), | intent(in), | optional | :: | errmsg | Error message to print if mem_stat is not 0(successful) |
subroutine alloc_rank1_integer(var, start1, stop1, errmsg)
!< Allcoate 1-Dimensional array of type: integer
implicit none
integer, dimension(:), intent(inout), 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 :: 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), 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
stop
end if
end subroutine alloc_rank1_integer