Changeset 2522 in lmdz_wrf


Ignore:
Timestamp:
May 9, 2019, 11:41:33 AM (6 years ago)
Author:
lfita
Message:

Adding:

  • `multi_spaceweightstats_in2DRKno_slc2v2': Subroutine to compute an spatial statistics value from a 2D RK matrix without running one into a matrix of 2-variables slices of rank 2 using spatial weights
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/module_scientific.f90

    r2354 r2522  
    5151! multi_spaceweightstats_in2DRKno_slc3v3: Subroutine to compute an spatial statistics value from a 2D RK matrix without
    5252!   running one into a matrix of 3-variables slices of rank 3 using spatial weights
     53! multi_spaceweightstats_in2DRKno_slc2v2: Subroutine to compute an spatial statistics value from a 2D RK matrix without
     54!   running one into a matrix of 2-variables slices of rank 2 using spatial weights
    5355! multi_spaceweightstats_in3DRK3_slc3v3: Subroutine to compute an spatial statistics value from a 3D RK matrix using
    5456!   3rd dimension as running one into a matrix of 3-variables slices of rank 3 using spatial weights
     
    61016103  END SUBROUTINE multi_spaceweightstats_in2DRKno_slc3v3
    61026104
     6105  SUBROUTINE multi_spaceweightstats_in2DRKno_slc2v2(varin, Ngridsin, gridsin, percentages, varout,    &
     6106    di1, di2, ds1, ds2, maxNgridsin)
     6107  ! Subroutine to compute an spatial statistics value from a 2D RK matrix without running one into a
     6108  !   matrix of 2-variables slices of rank 2 using spatial weights
     6109
     6110    IMPLICIT NONE
     6111
     6112    INTEGER, INTENT(in)                                  :: di1, di2, ds1, ds2
     6113    INTEGER, INTENT(in)                                  :: maxNgridsin
     6114    INTEGER, DIMENSION(ds1,ds2), INTENT(in)              :: Ngridsin
     6115    INTEGER, DIMENSION(ds1,ds2,maxNgridsin,2),                                                        &
     6116      INTENT(in)                                         :: gridsin
     6117    REAL(r_k), DIMENSION(di1,di2), INTENT(in)            :: varin
     6118    REAL(r_k), INTENT(in),                                                                            &
     6119      DIMENSION(ds1,ds2,maxNgridsin)                     :: percentages
     6120    REAL(r_k), DIMENSION(ds1,ds2,7), INTENT(out)         :: varout
     6121
     6122! Local
     6123    INTEGER                                              :: i1, i2, i3, s1, s2, iv
     6124    INTEGER                                              :: ii3, ss1, ss2
     6125    INTEGER                                              :: Ncounts, Nin
     6126    CHARACTER(len=3)                                     :: val1S, val2S
     6127    CHARACTER(len=30)                                    :: val3S
     6128    REAL(r_k)                                            :: minv, maxv, meanv, mean2v, stdv, medv
     6129    REAL(r_k), DIMENSION(:), ALLOCATABLE                 :: pin
     6130    INTEGER, DIMENSION(:,:), ALLOCATABLE                 :: gin
     6131    REAL(r_k), DIMENSION(:), ALLOCATABLE                 :: svin
     6132    REAL(r_k), DIMENSION(:), ALLOCATABLE                 :: vin
     6133
     6134!!!!!!! Variables
     6135! di1, di2: length of dimensions of the 2D matrix of values
     6136! ds[1-2]: length of dimensions of matrix with the slices
     6137! maxNgridsin: maximum number of grid points from the 2D matrix in any slice
     6138! varin: 2D RK variable to be used
     6139! Ngridsin: number of grids from 2D RK matrix for each slice
     6140! gridsin: coordinates of grids of the 2D RK matrix B to matrix of slices
     6141! percentages: weights as percentages of space of 2D RK matrix for each slice
     6142!!!!!
     6143! Available spatial statistics to compute inside each slice using values from 2D RK matrix
     6144!   'min': minimum value
     6145!   'max': maximum value
     6146!   'mean': space weighted mean value
     6147!   'mean2': space weighted quadratic mean value
     6148!   'stddev': space weighted standard deviation value
     6149!   'median': median value
     6150!   'count': percentage of the space of matrix A covered by each different value of matrix B
     6151! varout: output statistical variable
     6152
     6153    fname = 'multi_spaceweightstats_in2DRKno_slc2v2'
     6154
     6155    ss1 = 8 + 1
     6156    ss2 = 5 + 1
     6157    ii3 = 1 + 1
     6158
     6159    ! Let's be efficient?
     6160    varout = fillVal64
     6161    DO s1 =1, ds1
     6162      DO s2 =1, ds2
     6163        Nin = Ngridsin(s1,s2)
     6164        ! Computing along d2
     6165        IF (Nin > 1) THEN
     6166          IF (ALLOCATED(gin)) DEALLOCATE(gin)
     6167          ALLOCATE(gin(Nin,2))
     6168          IF (ALLOCATED(pin)) DEALLOCATE(pin)
     6169          ALLOCATE(pin(Nin))
     6170          IF (ALLOCATED(vin)) DEALLOCATE(vin)
     6171          ALLOCATE(vin(Nin))
     6172          IF (ALLOCATED(svin)) DEALLOCATE(svin)
     6173          ALLOCATE(svin(Nin))
     6174          gin = gridsin(s1,s2,1:Nin,:)
     6175          pin = percentages(s1,s2,1:Nin)
     6176
     6177          ! Getting the values
     6178          DO iv=1, Nin
     6179            i1 = gin(iv,1)
     6180            i2 = gin(iv,2)
     6181            vin(iv) = varin(i1,i2)
     6182          END DO
     6183          minv = fillVal64
     6184          maxv = -fillVal64
     6185          meanv = zeroRK
     6186          mean2v = zeroRK
     6187          stdv = zeroRK
     6188          minv = MINVAL(vin)
     6189          maxv = MAXVAL(vin)
     6190          meanv = SUM(vin*pin)
     6191          mean2v = SUM(vin**2*pin)
     6192          DO iv=1,Nin
     6193            stdv = stdv + ( (meanv - vin(iv))*pin(iv) )**2
     6194          END DO
     6195          stdv = SQRT(stdv)
     6196          svin = vin(:)
     6197          CALL SortR_K(svin, Nin)
     6198          medv = svin(INT(Nin/2))
     6199          varout(s1,s2,1) = minv
     6200          varout(s1,s2,2) = maxv
     6201          varout(s1,s2,3) = meanv
     6202          varout(s1,s2,4) = mean2v
     6203          varout(s1,s2,5) = stdv
     6204          varout(s1,s2,6) = medv
     6205          varout(s1,s2,7) = Nin*1.
     6206        ELSE IF (Nin == 1) THEN
     6207          i1 = gridsin(s1,s2,1,1)
     6208          i2 = gridsin(s1,s2,1,2)
     6209          varout(s1,s2,1) = varin(i1,i2)
     6210          varout(s1,s2,2) = varin(i1,i2)
     6211          varout(s1,s2,3) = varin(i1,i2)
     6212          varout(s1,s2,4) = varin(i1,i2)*varin(i1,i2)
     6213          varout(s1,s2,5) = zeroRK
     6214          varout(s1,s2,6) = varin(i1,i2)
     6215          varout(s1,s2,7) = Nin*1.
     6216        ELSE
     6217          varout(s1,s2,1) = fillval64
     6218          varout(s1,s2,2) = fillval64
     6219          varout(s1,s2,3) = fillval64
     6220          varout(s1,s2,4) = fillval64
     6221          varout(s1,s2,5) = fillval64
     6222          varout(s1,s2,6) = fillval64
     6223          varout(s1,s2,7) = zeroRK
     6224        END IF
     6225      END DO
     6226    END DO
     6227
     6228    IF (ALLOCATED(gin)) DEALLOCATE(gin)
     6229    IF (ALLOCATED(pin)) DEALLOCATE(pin)
     6230    IF (ALLOCATED(vin)) DEALLOCATE(vin)
     6231    IF (ALLOCATED(svin)) DEALLOCATE(svin)
     6232   
     6233    RETURN
     6234
     6235  END SUBROUTINE multi_spaceweightstats_in2DRKno_slc2v2
     6236
    61036237  SUBROUTINE multi_spaceweightstats_in3DRK3_slc3v3(varin, Ngridsin, gridsin, percentages, varout,     &
    61046238    di1, di2, di3, ds1, ds2, ds3, maxNgridsin)
Note: See TracChangeset for help on using the changeset viewer.