Converts sizes to offsets
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(in), | DIMENSION(:) | :: | sizes |
array with sizes |
|
integer, | intent(out), | DIMENSION(:) | :: | offsets_start |
offsets of starts |
|
integer, | intent(out), | optional, | DIMENSION(:) | :: | offsets_stop |
offsets of ends |
PURE SUBROUTINE convert_sizes_to_offsets(sizes, & offsets_start, offsets_stop) !! Converts sizes to offsets INTEGER, DIMENSION(:), INTENT(IN) :: sizes !! array with sizes INTEGER, DIMENSION(:), INTENT(OUT) :: offsets_start !! offsets of starts INTEGER, DIMENSION(:), INTENT(OUT), OPTIONAL :: offsets_stop !! offsets of ends INTEGER :: i, n ! --------------------------------------------------------------------------- n = SIZE(sizes) IF (n .GT. 0) THEN offsets_start(1) = 1 IF (PRESENT(offsets_stop)) offsets_stop(1) = sizes(1) IF (.NOT. PRESENT(offsets_stop)) THEN DO i = 2, n offsets_start(i) = offsets_start(i - 1) + sizes(i - 1) END DO IF (SIZE(offsets_start) .GT. n) & offsets_start(n + 1) = offsets_start(n) + sizes(n) ELSE DO i = 2, n offsets_start(i) = offsets_start(i - 1) + sizes(i - 1) offsets_stop(i) = offsets_stop(i - 1) + sizes(i) END DO IF (SIZE(offsets_start) .GT. n) & offsets_start(n + 1) = offsets_start(n) + sizes(n) END IF ELSE IF (.NOT. PRESENT(offsets_stop)) THEN offsets_start(1) = 0 END IF END IF END SUBROUTINE convert_sizes_to_offsets