Changeset 2354 in lmdz_wrf


Ignore:
Timestamp:
Feb 19, 2019, 10:07:39 PM (6 years ago)
Author:
lfita
Message:

Adding:

  • `spaceweight_Icount': Subroutine to compute the percentage of a series of categories using weights
  • `multi_spaceweightcount_in3DRK3_slc3v3': Subroutine to compute an spatial percentage of coverture of categories from a 3D RK matrix using 3rd dimension as running one into a matrix of 3-variables slices of rank 3 using spatial weights
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/module_scientific.f90

    r2353 r2354  
    4444! multi_index_mat3DRK: Subroutine to provide the indices of the different locations of a value inside a 3D RK matrix
    4545! multi_index_mat4DRK: Subroutine to provide the indices of the different locations of a value inside a 4D RK matrix
     46! multi_spaceweightcount_in3DRK3_slc3v3: Subroutine to compute an spatial percentage of coverture of
     47!   categories from a 3D RK matrix using 3rd dimension as running one into a matrix of 3-variables
     48!   slices of rank 3 using spatial weights
    4649! multi_spaceweightstats_in1DRKno_slc3v3: Subroutine to compute an spatial statistics value from a 1D RK matrix without
    4750!   running one into a matrix of 3-variables slices of rank 3 using spatial weights
     
    8487! SortR_K*: Subroutine receives an array x() r_K and sorts it into ascending order.
    8588! spacepercen: Subroutine to compute the space-percentages of a series of grid cells (B) into another series of grid-cells (A)
     89! spaceweight_Icount: Subroutine to compute the percentage of a series of categories using weights
    8690! spaceweightstats: Subroutine to compute an spatial statistics value from a matrix B into a matrix A using weights
    8791! StatsR_K: Subroutine to provide the minmum, maximum, mean, the quadratic mean, and the standard deviation of a
     
    56715675! percentages: weights as percentages of space of grid in matrix A covered by grid of matrix B
    56725676! stats: name of the spatial statistics to compute inside each grid of matrix A using values from
    5673 !     matrix B. Avaialbe ones:
     5677!     matrix B. Available ones:
    56745678!   'min': minimum value
    56755679!   'max': maximum value
     
    57805784  END SUBROUTINE spaceweightstats
    57815785
     5786  SUBROUTINE spaceweight_Icount(Ncat, cats, varin, Ngridsin, percentages, varout)
     5787  ! Subroutine to compute the percentage of a series of categories using weights
     5788
     5789    IMPLICIT NONE
     5790
     5791    INTEGER, INTENT(in)                                  :: Ncat, Ngridsin
     5792    INTEGER, DIMENSION(Ncat), INTENT(in)                 :: cats
     5793    INTEGER, DIMENSION(Ngridsin), INTENT(in)             :: varin
     5794    REAL(r_k), DIMENSION(Ngridsin), INTENT(in)           :: percentages
     5795    REAL(r_k), DIMENSION(Ncat), INTENT(out)              :: varout
     5796
     5797! Local
     5798    INTEGER                                              :: iv, ic
     5799
     5800!!!!!!! Variables
     5801! Ncat: number of categories
     5802! cats: categories to use
     5803! varin: variable with the integer values
     5804! Ngridsin: number of grids
     5805! percentages: weights as percentages of the grids to use
     5806! varout: output statistical variable
     5807
     5808    fname = 'spaceweight_Icount'
     5809
     5810    varout = zeroRK
     5811    DO iv=1, Ngridsin
     5812      DO ic=1, Ncat
     5813        IF (varin(iv) == cats(ic)) THEN
     5814          varout(ic) = varout(ic) + percentages(iv)
     5815        END IF
     5816      END DO
     5817    END DO
     5818
     5819  END SUBROUTINE spaceweight_Icount
     5820
    57825821  SUBROUTINE multi_spaceweightstats_in1DRKno_slc3v3(varin, idv, Ngridsin, gridsin, percentages,       &
    57835822    varout, di1, ds1, ds2, ds3, maxNgridsin)
     
    58315870
    58325871    fname = 'multi_spaceweightstats_in1DRKno_slc3v3'
    5833 
    5834     varout = fillval64
    58355872
    58365873    ss1 = 8 + 1
     
    59796016    fname = 'multi_spaceweightstats_in2DRKno_slc3v3'
    59806017
    5981     varout = fillval64
    5982 
    59836018    ss1 = 8 + 1
    59846019    ss2 = 5 + 1
     
    61156150
    61166151    fname = 'multi_spaceweightstats_in3DRK3_slc3v3'
    6117 
    6118     varout = fillval64
    61196152
    61206153    ss1 = 8 + 1
     
    62556288
    62566289    fname = 'multi_spaceweightstats_in4DRK3_4_slc3v3'
    6257 
    6258     varout = fillval64
    62596290
    62606291    ! Let's be efficient?
     
    63926423    fname = 'multi_spaceweightstats_in3DRK3_slc3v4'
    63936424
    6394     varout = fillval64
    6395 
    63966425    ! Let's be efficient?
    63976426    varout = fillVal64
     
    70187047  END SUBROUTINE coincident_gridsin2D
    70197048
     7049  SUBROUTINE multi_spaceweightcount_in3DRK3_slc3v3(varin, Ngridsin, gridsin, percentages, Ncat,       &
     7050    categories, varout, di1, di2, di3, ds1, ds2, ds3, maxNgridsin)
     7051  ! Subroutine to compute an spatial percentage of coverture of categories from a 3D RK matrix using
     7052  !   3rd dimension as running one into a matrix of 3-variables slices of rank 3 using spatial weights
     7053
     7054    IMPLICIT NONE
     7055
     7056    INTEGER, INTENT(in)                                  :: di1, di2, di3, ds1, ds2, ds3
     7057    INTEGER, INTENT(in)                                  :: Ncat, maxNgridsin
     7058    INTEGER, DIMENSION(ds1,ds2,ds3), INTENT(in)          :: Ngridsin
     7059    INTEGER, DIMENSION(ds1,ds2,ds3,maxNgridsin,2),                                                    &
     7060      INTENT(in)                                         :: gridsin
     7061    INTEGER, DIMENSION(di1,di2,di3), INTENT(in)          :: varin
     7062    REAL(r_k), INTENT(in),                                                                            &
     7063      DIMENSION(ds1,ds2,ds3,maxNgridsin)                 :: percentages
     7064    INTEGER, DIMENSION(Ncat), INTENT(in)                 :: categories
     7065    REAL(r_k), DIMENSION(ds1,ds2,ds3,di3,Ncat),                                                       &
     7066      INTENT(out)                                        :: varout
     7067
     7068! Local
     7069    INTEGER                                              :: i1, i2, i3, s1, s2, s3, iv
     7070    INTEGER                                              :: ii3, ss1, ss2, ss3, Nin
     7071    REAL(r_k), DIMENSION(:), ALLOCATABLE                 :: pin
     7072    INTEGER, DIMENSION(:,:), ALLOCATABLE                 :: gin
     7073    REAL(r_k), DIMENSION(:), ALLOCATABLE                 :: svin
     7074    INTEGER, DIMENSION(:,:), ALLOCATABLE                 :: vin
     7075
     7076!!!!!!! Variables
     7077! di1, di2, di3: length of dimensions of the 3D matrix of values
     7078! ds[1-3]: length of dimensions of matrix with the slices
     7079! maxNgridsin: maximum number of grid points from the 3D matrix in any slice
     7080! varin: 3D RK variable to be used
     7081! Ngridsin: number of grids from 3D RK matrix for each slice
     7082! gridsin: coordinates of grids of the 3D RK matrix B to matrix of slices
     7083! percentages: weights as percentages of space of 3D RK matrix for each slice
     7084! Ncat: number of categories
     7085! categories: category values to classify with
     7086! varout: percentage of each category at each point along d3
     7087
     7088    fname = 'multi_spaceweightcount_in3DRK3_slc3v3'
     7089
     7090    ! Let's be efficient?
     7091    varout = fillVal64
     7092    DO s1 =1, ds1
     7093      DO s2 =1, ds2
     7094        DO s3 =1, ds3
     7095          Nin = Ngridsin(s1,s2,s3)
     7096          ! Computing along d3
     7097          IF (Nin >= 1) THEN
     7098            IF (ALLOCATED(gin)) DEALLOCATE(gin)
     7099            ALLOCATE(gin(Nin,2))
     7100            IF (ALLOCATED(pin)) DEALLOCATE(pin)
     7101            ALLOCATE(pin(Nin))
     7102            IF (ALLOCATED(vin)) DEALLOCATE(vin)
     7103            ALLOCATE(vin(Nin,di3))
     7104            IF (ALLOCATED(svin)) DEALLOCATE(svin)
     7105            ALLOCATE(svin(Nin))
     7106            gin = gridsin(s1,s2,s3,1:Nin,:)
     7107            pin = percentages(s1,s2,s3,1:Nin)
     7108
     7109            ! Getting the values
     7110            DO iv=1, Nin
     7111              i1 = gin(iv,1)
     7112              i2 = gin(iv,2)
     7113              vin(iv,:) = varin(i1,i2,:)
     7114            END DO
     7115            DO i3=1, di3
     7116              CALL spaceweight_Icount(Ncat, categories, vin(:,i3), Nin, pin, varout(s1,s2,s3,i3,:))
     7117            END DO
     7118          ELSE
     7119            varout(s1,s2,s3,:,1) = fillval64
     7120          END IF
     7121        END DO
     7122      END DO
     7123    END DO
     7124
     7125    IF (ALLOCATED(gin)) DEALLOCATE(gin)
     7126    IF (ALLOCATED(pin)) DEALLOCATE(pin)
     7127    IF (ALLOCATED(vin)) DEALLOCATE(vin)
     7128    IF (ALLOCATED(svin)) DEALLOCATE(svin)
     7129   
     7130    RETURN
     7131
     7132  END SUBROUTINE multi_spaceweightcount_in3DRK3_slc3v3
     7133
    70207134END MODULE module_scientific
Note: See TracChangeset for help on using the changeset viewer.