Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in) | :: | elsize | Size of elements in bytes |
||
integer(kind=HSIZE_T), | intent(in), | dimension(*) | :: | dims | Dimensions of dataset |
|
integer(kind=HSIZE_T), | intent(out), | dimension(:) | :: | cdims | Maximum allowed chunk size/dims |
subroutine chunk_size(elsize, dims, cdims)
integer, intent(in) :: elsize
!+ Size of elements in bytes
integer(HSIZE_T), dimension(*), intent(in) :: dims
!+ Dimensions of dataset
integer(HSIZE_T), dimension(:), intent(out) :: cdims
!+ Maximum allowed chunk size/dims
real, parameter :: max_bytes = 4*1e9 !GigaBytes
integer :: d
real(Float64) :: nbytes
d = size(cdims)
cdims(1:d) = dims(1:d)
nbytes = elsize*product(1.d0*cdims)
do while ((nbytes.gt.max_bytes).and.(d.gt.0))
cdims(d) = max(floor(cdims(d)*max_bytes/nbytes,Int32),1)
nbytes = elsize*product(1.d0*cdims)
d = d - 1
enddo
end subroutine chunk_size