Note
Function to calculate the statistical moments of an array with mask, of shape dim. 1 or 2
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
real(kind=R8), | intent(in), | dimension(..) | :: | tab |
1D or 2D array |
|
logical(kind=I4), | intent(in), | optional, | dimension(..) | :: | mask |
1D or 2D mask |
type(moment_stat), | intent(out) | :: | mx |
moment_stat result |
||
integer(kind=I4), | intent(in) | :: | nb_mom |
number of desired moments |
subroutine calc_moments(tab, mask, mx, nb_mom) !================================================================================================ !< @note Function to calculate the statistical moments of an array with mask, of shape dim. 1 or 2 !< !< \begin{align*} !< mu &= \frac{1}{n^2}\sum_{i,j=1}^{n}\eta_{i,j} \\ !< va &= \frac{1}{n^2}\sum_{i,j=1}^{n}(\eta_{i,j}-\mu)^2 \\ !< Sk &= \frac{1}{n^2}\sum_{i,j=1}^{n}\left(\frac{\eta_{i,j}-\mu}{\sigma}\right)^3 \\ !< Ku &= \frac{1}{n^2}\sum_{i,j=1}^{n}\left(\frac{\eta_{i,j}-\mu}{\sigma}\right)^4 !< \end{align*} !< !< @endnote !------------------------------------------------------------------------------------------------ implicit none integer (kind=I4), intent(in ) :: nb_mom !! *number of desired moments* real (kind=R8), intent(in ), dimension(..) :: tab !! *1D or 2D array* logical (kind=I4), intent(in ), dimension(..), optional :: mask !! *1D or 2D mask* type(moment_stat), intent(out) :: mx !! [[moment_stat]] *result* integer (kind=I4) :: size_tab real(kind=R8), allocatable, dimension(:) :: tab_tmp logical(kind=I4), allocatable, dimension(:) :: msk_tmp select rank (tab) rank (1) if ( present( mask ) ) then select rank (mask) rank (1) call calc_moments_1D(tab, mask, mx, nb_mom) rank default stop "bad rank in mask 'calc_moments'" endselect else call calc_moments_1D(tab = tab, mx = mx, nb_mom = nb_mom) endif rank (2) size_tab = product( shape( tab ) ) allocate( tab_tmp(1:size_tab) ) tab_tmp = reshape( tab, [size_tab] ) if ( present( mask ) ) then allocate( msk_tmp(1:size_tab) ) select rank (mask) rank (2) msk_tmp = reshape( mask, [size_tab] ) call calc_moments_1D(tab_tmp, msk_tmp, mx, nb_mom) deallocate( msk_tmp ) rank default stop "bad rank in mask 'calc_moments'" endselect else call calc_moments_1D(tab = tab_tmp, mx = mx, nb_mom = nb_mom) endif deallocate( tab_tmp ) rank default stop "bad rank in 'calc_moments'" endselect return endsubroutine calc_moments