calc_moments_1D Subroutine

private subroutine calc_moments_1D(tab, mask, mx, nb_mom)

Function to calculate the statistical moments of a 1D array with mask, see calc_moments

Arguments

Type IntentOptional Attributes Name
real(kind=R8), intent(in), dimension(:) :: tab

1D array

logical(kind=I4), intent(in), optional, dimension(:) :: mask

1D mask

type(moment_stat), intent(out) :: mx

moment_stat result

integer(kind=I4), intent(in) :: nb_mom

number of desired moments


Called by

proc~~calc_moments_1d~~CalledByGraph proc~calc_moments_1d calc_moments_1D proc~calc_moments calc_moments proc~calc_moments->proc~calc_moments_1d 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_1D(tab, mask, mx, nb_mom)
   !================================================================================================
   !! Function to calculate the statistical moments of a 1D array with mask, see [[calc_moments]]
   !------------------------------------------------------------------------------------------------
   implicit none
   integer (kind=I4), intent(in )                         :: nb_mom !! *number of desired moments*
   real    (kind=R8), intent(in ), dimension(:)           :: tab    !! *1D array*
   logical (kind=I4), intent(in ), dimension(:), optional :: mask   !! *1D mask*
   type(moment_stat), intent(out)                         :: mx     !! [[moment_stat]] *result*

      integer(kind=I4) :: lg, nz
      integer(kind=I4) :: i, ii
      real(kind=R8)    :: tmp

      real(kind=R8), allocatable, dimension(:) :: tab_tmp

      lg = size( tab )
      nz = lg

      if ( present(mask) ) then

         nz = count( mask )
         allocate( tab_tmp(1:nz) )

         ii = 0
         do i = 1, lg
            if ( mask(i) ) then
               ii = ii + 1
               tab_tmp(ii) = tab(i)
            endif
         enddo
         if (ii /= nz) stop 'error calc_moments'

      else

         tab_tmp = tab

      endif

      mx%mu = 0
      mx%si = 0
      mx%va = 0
      mx%Sk = 0
      mx%Ku = 0

      mx%Ss = 0
      mx%Kk = 0

      do i = 1, nz
         mx%mu = mx%mu +tab_tmp(i)/nz
      enddo
      if (nb_mom == 1) return

      do i = 1, nz
         mx%va = mx%va +( (tab_tmp(i) -mx%mu)**2 )/nz
      enddo
      mx%si = sqrt( mx%va )
      if (nb_mom==2) return         ! don't go further

      if (mx%si < 1.e-15_R8) then   ! if the standard deviation is too small, quit
         stop 'calc_moments, std too small'
      endif

      do i = 1, nz
         tmp = ( tab_tmp(i) -mx%mu )/mx%si
         mx%Sk = mx%Sk +(tmp**3)/nz
         mx%Ku = mx%Ku +(tmp**4)/nz
      enddo
      if (nb_mom == 4) return

      do i = 1, nz
         tmp = ( tab_tmp(i) -mx%mu )/mx%si
         mx%Ss = mx%Ss +(tmp**5)/nz
         mx%Kk = mx%Kk +(tmp**6)/nz
      enddo

      deallocate( tab_tmp )

   return
   endsubroutine calc_moments_1D