Calculate the number of cells in a mask, as well as the cell median size
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=I4), | intent(inout), | dimension(1:long, 1:larg) | :: | msk |
mask |
|
integer(kind=I4), | intent(in) | :: | long |
2D array length |
||
integer(kind=I4), | intent(in) | :: | larg |
2D array height |
||
integer(kind=I4), | intent(out) | :: | nbr_cell |
number of cells |
||
real(kind=R8), | intent(out), | optional | :: | med_cell |
median size of the cells |
subroutine count_cell(msk, long, larg, nbr_cell, med_cell) !================================================================================================ !! Calculate the number of cells in a mask, as well as the cell median size !------------------------------------------------------------------------------------------------ implicit none integer(kind=I4), intent(in ) :: long !! *2D array length* integer(kind=I4), intent(in ) :: larg !! *2D array height* integer(kind=I4), intent(out ) :: nbr_cell !! *number of cells* real (kind=R8), intent(out ), optional :: med_cell !! *median size of the cells* integer(kind=I4), intent(inout), dimension(1:long, 1:larg) :: msk !! *mask* integer(kind=I4) :: i, j, k, nb real(kind=R8), dimension(1:long*larg) :: cell cell(1:long*larg) = 0 k = 1 do call flood( masque = msk(1:long, 1:larg), & ! INOUT taille = nb, & ! OUT nx = long, & ! IN ny = larg, & ! IN niv = k + 1) ! IN if ( nb == 0 ) exit cell(k) = nb k = k + 1 enddo nbr_cell = k - 1 med_cell = 0._R8 if (.not.present(med_cell)) return if (k > 0) then call calc_median( tab = cell(1:nbr_cell), & ! IN md = med_cell ) ! OUT med_cell = 100*med_cell/(long*larg) else med_cell = 0 endif return endsubroutine count_cell