Convert a (signed, possibly out-of-range) real cell index to an integer cell index clamped to [0, nCells-1].
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=prec), | intent(in) | :: | rIdx | |||
| integer, | intent(in) | :: | nCells |
pure function ClampCell(rIdx,nCells) result(c)
!! Convert a (signed, possibly out-of-range) real cell index to an integer
!! cell index clamped to [0, nCells-1].
implicit none
real(prec),intent(in) :: rIdx
integer,intent(in) :: nCells
integer :: c
c = int(floor(rIdx))
if(c < 0) c = 0
if(c > nCells-1) c = nCells-1
endfunction ClampCell