calc_moments Subroutine

public 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

Arguments

Type IntentOptional 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


Calls

proc~~calc_moments~~CallsGraph proc~calc_moments calc_moments proc~calc_moments_1d calc_moments_1D proc~calc_moments->proc~calc_moments_1d

Called by

proc~~calc_moments~~CalledByGraph proc~calc_moments calc_moments proc~abbott_param abbott_param proc~abbott_param->proc~calc_moments proc~acv acv proc~acv->proc~calc_moments proc~indice_fractal indice_fractal proc~indice_fractal->proc~calc_moments proc~median_filter median_filter proc~median_filter->proc~calc_moments program~test_morpho test_morpho program~test_morpho->proc~calc_moments program~test_stat test_stat program~test_stat->proc~calc_moments proc~correlation_parameters correlation_parameters proc~correlation_parameters->proc~acv program~test_abbott test_abbott program~test_abbott->proc~abbott_param program~test_asfc test_asfc program~test_asfc->proc~indice_fractal program~test_smooth test_smooth program~test_smooth->proc~median_filter program~test_anisotropy test_anisotropy program~test_anisotropy->proc~correlation_parameters

Source Code

   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