subroutine maskArrayLimits(mask, minXi, maxXi, minYi, maxYi) logical(bool), intent(in) :: mask(:,:) integer(int16), intent(out) :: minXi, maxXi, minYi, maxYi end subroutine
!*** erase the status variable from the actual routine!
Example:
logical(bool) :: mask(4,5) mask(1,:) = ((/0, 0, 0, 0, 0/) > 0) mask(2,:) = ((/0, 1, 1, 0, 0/) > 0) mask(3,:) = ((/1, 1, 0, 1, 0/) > 0) mask(4,:) = ((/1, 0, 0, 0, 0/) > 0) call maskArrayLimits(mask, minXi, maxXi, minYi, maxYi) ! returns minXi=1, maxXi=4, minYi=2, maxYi=4 mask = .false. call maskArrayLimits(mask, minXi, maxXi, minYi, maxYi) ! returns minXi=6, maxXi=0, minYi=5, maxYi=0 (ie, nonsense)
The same nonsense return occurs if mask is of zero size in either direction. It is up to the user to check that the mask is neither empty nor of zero size before calling maskArrayLimits.