Changeset 2289 in lmdz_wrf for trunk


Ignore:
Timestamp:
Jan 25, 2019, 8:31:33 PM (7 years ago)
Author:
lfita
Message:

Adding:

  • `coincident_gridsin2D': Subroutine to determine which lists of 2D gridsin points of an A list are also found in a B list
  • `coincident_list_2Dcoords': Subroutine to determine which 2D points of an A list are also found in a B list
  • `grid_spacepercen_providing_polys': Subroutine to compute the space-percentages of a series of grid cells (B) which lay inside another series of grid-cells (A) providing coincident polygons
  • `grid_spacepercen_within_reg_providing_polys': Subroutine to compute the percentage of grid space of a series of grid cells which are encompassed by a polygon providing coordinates of the resultant polygons
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/module_scientific.f90

    r2288 r2289  
    1313! coincidence_poly_area: Subtourine to determine which is the coincident polygon when a boolean polygon is provided
    1414!   to a map of integer polygons filtrered by a minimal area
     15! coincident_gridsin2D: Subroutine to determine which lists of 2D gridsin points of an A list are also found in a B list
     16! coincident_list_2Dcoords: Subroutine to determine which 2D points of an A list are also found in a B list
    1517! clean_polygons: Subroutine to clean polygons from non-used paths, polygons only left as path since they are inner path of a hole
    1618! coincident_polygon: Subroutine to provide the intersection polygon between two polygons
     
    2224! grid_spacepercen: Subroutine to compute the space-percentages of a series of grid cells (B) which lay inside another
    2325!   series of grid-cells (A)
     26! grid_spacepercen_providing_polys: Subroutine to compute the space-percentages of a series of grid cells (B) which lay inside another
     27!   series of grid-cells (A) providing coincident polygons
    2428! grid_spacepercen_within_reg: Subroutine to compute the percentage of grid space of a series of grid cells which are encompassed
    2529!   by a polygon
     30! grid_spacepercen_within_reg_providing_polys: Subroutine to compute the percentage of grid space of a series of grid
     31!   cells which are encompassed by a polygon providing coordinates of the resultant polygons
    2632! gridpoints_InsidePolygon: Subroutine to determine if a series of grid points are inside a polygon
    2733!   following ray casting algorithm
     
    48934899
    48944900      ! Getting common vertices
    4895       NvertexAgrid = NvertexA*Nvertex
     4901      NvertexAgrid = NvertexA*Nvertex*2
    48964902      IF (ALLOCATED(icoinpoly)) DEALLOCATE(icoinpoly)
    48974903      ALLOCATE(icoinpoly(NvertexAgrid,2))
     
    50145020
    50155021      ! Getting common vertices
    5016       NvertexAgrid = NvertexA*Nvertex
     5022      NvertexAgrid = NvertexA*Nvertex*2
    50175023      IF (ALLOCATED(icoinpoly)) DEALLOCATE(icoinpoly)
    50185024      ALLOCATE(icoinpoly(NvertexAgrid,2))
     
    50475053
    50485054  END SUBROUTINE grid_spacepercen_within_reg
     5055
     5056  SUBROUTINE grid_spacepercen_within_reg_providing_polys(NvertexA, polygonA, dx, dy, Nvertexmax,      &
     5057    xBvals, yBvals, Ngridsin, gridsin, strict, Nmaxver2, Ncoinpoly, ccoinpoly, gridspace, percentages)
     5058  ! Subroutine to compute the percentage of grid space of a series of grid cells which are encompassed
     5059  !   by a polygon providing coordinates of the resultant polygons
     5060  ! NOTE: Assuming coordinates on the plane with rectilinar, distance preserved and perpendicular x
     5061  !   and y axes.
     5062
     5063    IMPLICIT NONE
     5064
     5065    INTEGER, INTENT(in)                                  :: NvertexA, dx, dy, Nvertexmax, Nmaxver2
     5066    REAL(r_k), DIMENSION(NvertexA,2), INTENT(in)         :: polygonA
     5067    REAL(r_k), DIMENSION(dx,dy,Nvertexmax), INTENT(in)   :: xBvals, yBvals
     5068    INTEGER, INTENT(in)                                  :: Ngridsin
     5069    INTEGER, DIMENSION(Ngridsin,2), INTENT(in)           :: gridsin
     5070    LOGICAL, INTENT(in)                                  :: strict
     5071    INTEGER, DIMENSION(Ngridsin), INTENT(out)            :: Ncoinpoly
     5072    REAL(r_k), DIMENSION(Ngridsin,Nmaxver2,2),                                                        &
     5073      INTENT(out)                                        :: ccoinpoly
     5074    REAL(r_k), DIMENSION(Ngridsin), INTENT(out)          :: gridspace, percentages
     5075
     5076! Local
     5077   INTEGER                                               :: ig, iv, ix, iy
     5078   INTEGER                                               :: Nvertex, NvertexAgrid, Ncoin, Nsort
     5079   CHARACTER(len=20)                                     :: DS
     5080   REAL(r_k)                                             :: areapoly, areagpoly
     5081   REAL(r_k), ALLOCATABLE, DIMENSION(:,:)                :: vertexgrid, icoinpoly, coinpoly,          &
     5082     sortpoly, poly
     5083
     5084!!!!!!! Variables
     5085! NvertexA: Number of vertices of the polygon to find the grids
     5086! polygonA: ordered vertices of the polygon
     5087! dx, dy: shape of the matrix with the grid points
     5088! xCvals, yCvals: coordinates of the center of the grid cells
     5089! Nvertexmax: Maximum number of vertices of the grid cells
     5090! xBvals, yBvals: coordinates of th vertices of the grid cells (-99999 for no vertex)
     5091! Ngridsin: number of grids with some extension within the polygon
     5092! gridsin: grids within the polygon
     5093! strict: give an error if the area of the polygon is not fully covered
     5094! Nmaxver2: maximum possible number of vertices of the coincident polygon
     5095! Ncoinpoly: number of vertices of the coincident polygon
     5096! coinpoly: coordinates of the vertices of the coincident polygon
     5097! gridspace: area of each of the grids
     5098! percentages: percentages of grid area of each of the grids within the polygon
     5099
     5100    fname = 'grid_spacepercen_within_reg_providing_polys'
     5101
     5102    gridspace = zeroRK
     5103    percentages = zeroRK
     5104
     5105    DO ig = 1, Ngridsin
     5106      ix = gridsin(ig,1)
     5107      iy = gridsin(ig,2)
     5108
     5109     ! Getting grid vertices
     5110      Nvertex = 0
     5111      DO iv=1, Nvertexmax
     5112        IF (xBvals(ix,iy,iv) /= fillvalI) THEN
     5113          Nvertex = Nvertex + 1
     5114        END IF
     5115      END DO
     5116      IF (ALLOCATED(vertexgrid)) DEALLOCATE(vertexgrid)
     5117      ALLOCATE(vertexgrid(Nvertex,2))
     5118      vertexgrid(:,1) = xBvals(ix,iy,1:Nvertex)
     5119      vertexgrid(:,2) = yBvals(ix,iy,1:Nvertex)
     5120      areapoly = shoelace_area_polygon(Nvertex, vertexgrid)
     5121
     5122      ! Getting common vertices
     5123      NvertexAgrid = NvertexA*Nvertex*2
     5124      IF (ALLOCATED(icoinpoly)) DEALLOCATE(icoinpoly)
     5125      ALLOCATE(icoinpoly(NvertexAgrid,2))
     5126      CALL coincident_polygon(NvertexA, Nvertex, NvertexAgrid, polygonA, vertexgrid, Ncoin, icoinpoly)
     5127
     5128      IF (ALLOCATED(coinpoly)) DEALLOCATE(coinpoly)
     5129      ALLOCATE(coinpoly(Ncoin,2))
     5130      DO iv=1, Ncoin
     5131        coinpoly(iv,:) = icoinpoly(iv,:)
     5132      END DO
     5133
     5134      IF (ALLOCATED(sortpoly)) DEALLOCATE(sortpoly)
     5135      ALLOCATE(sortpoly(Ncoin,2))
     5136      CALL sort_polygon(Ncoin, coinpoly, 1, Nsort, sortpoly)
     5137
     5138      IF (ALLOCATED(poly)) DEALLOCATE(poly)
     5139      ALLOCATE(poly(Nsort,2))
     5140      DO iv=1, Nsort
     5141        poly(iv,:) = sortpoly(iv,:)
     5142      END DO
     5143
     5144      areagpoly = shoelace_area_polygon(Nsort, poly)
     5145      Ncoinpoly(ig)= Nsort
     5146      ccoinpoly(ig,:,:) = poly(:,:)
     5147      gridspace(ig) = ABS(areapoly)
     5148      percentages(ig) = ABS(areagpoly / areapoly)
     5149    END DO
     5150
     5151    IF (ALLOCATED(vertexgrid)) DEALLOCATE(vertexgrid)
     5152    IF (ALLOCATED(icoinpoly)) DEALLOCATE(icoinpoly)
     5153    IF (ALLOCATED(coinpoly)) DEALLOCATE(coinpoly)
     5154    IF (ALLOCATED(sortpoly)) DEALLOCATE(sortpoly)
     5155    IF (ALLOCATED(poly)) DEALLOCATE(poly)
     5156
     5157  END SUBROUTINE grid_spacepercen_within_reg_providing_polys
    50495158
    50505159  SUBROUTINE spacepercen(xCAvals, yCAvals, xBAvals, yBAvals, xCBvals, yCBvals, xBBvals, yBBvals,      &
     
    51325241
    51335242  SUBROUTINE grid_spacepercen(xCAvals, yCAvals, xBAvals, yBAvals, xCBvals, yCBvals, xBBvals, yBBvals, &
    5134     dxA, dyA, NAvertexmax, dxB, dyB, dxyB, NBvertexmax, strict, Ngridsin, gridsin, areas, percentages)
     5243    dxA, dyA, NAvertexmax, dxB, dyB, dxyB, NBvertexmax, strict, Ngridsin, gridsin,  areas, percentages)
    51355244  ! Subroutine to compute the space-percentages of a series of grid cells (B) which lay inside another
    5136   !   series of grid-cells (A)
     5245  !   series of grid-cells (A) porviding coincident polygons
    51375246  ! NOTE: Assuming coordinates on the plane with rectilinar, distance preserved and perpendicular x
    51385247  !   and y axes.
     
    52075316        END DO
    52085317
    5209         CALL grid_spacepercen_within_reg(Nvertex, vertexgrid, dxB, dyB, NBvertexmax, xBBvals,       &
     5318        CALL grid_spacepercen_within_reg(Nvertex, vertexgrid, dxB, dyB, NBvertexmax, xBBvals,        &
    52105319          yBBvals, Ngridsin(ix,iy), poinsin, strict, pareas, percentages(ix,iy,:))
    52115320
     
    52255334
    52265335  END SUBROUTINE grid_spacepercen
     5336
     5337  SUBROUTINE grid_spacepercen_providing_polys(xCAvals, yCAvals, xBAvals, yBAvals, xCBvals, yCBvals,   &
     5338    xBBvals, yBBvals, dxA, dyA, NAvertexmax, dxB, dyB, dxyB, NBvertexmax, strict, Nmaxvercoin,        &
     5339    Nvercoinpolys, vercoinpolys, Ngridsin, gridsin,  areas, percentages)
     5340  ! Subroutine to compute the space-percentages of a series of grid cells (B) which lay inside another
     5341  !   series of grid-cells (A) providing coincident polygons
     5342  ! NOTE: Assuming coordinates on the plane with rectilinar, distance preserved and perpendicular x
     5343  !   and y axes.
     5344
     5345    IMPLICIT NONE
     5346
     5347    INTEGER, INTENT(in)                                  :: dxA, dyA, NAvertexmax
     5348    INTEGER, INTENT(in)                                  :: dxB, dyB, NBvertexmax, dxyB
     5349    INTEGER, INTENT(in)                                  :: Nmaxvercoin
     5350    REAL(r_k), DIMENSION(dxA,dyA), INTENT(in)            :: xCAvals, yCAvals
     5351    REAL(r_k), DIMENSION(dxB,dyB), INTENT(in)            :: xCBvals, yCBvals
     5352    REAL(r_k), DIMENSION(dxA,dyA,NAvertexmax), INTENT(in):: xBAvals, yBAvals
     5353    REAL(r_k), DIMENSION(dxB,dyB,NBvertexmax), INTENT(in):: xBBvals, yBBvals
     5354    LOGICAL, INTENT(in)                                  :: strict
     5355    INTEGER, DIMENSION(dxA,dyA,dxyB,Nmaxvercoin),                                                     &
     5356      INTENT(out)                                        :: Nvercoinpolys
     5357    REAL(r_k), DIMENSION(dxA,dyA,dxyB,Nmaxvercoin,2),                                                 &
     5358      INTENT(out)                                        :: vercoinpolys
     5359    INTEGER, DIMENSION(dxA,dyA), INTENT(out)             :: Ngridsin
     5360    INTEGER, DIMENSION(dxA,dyA,dxyB,2), INTENT(out)      :: gridsin
     5361    REAL(r_k), DIMENSION(dxB,dyB), INTENT(out)           :: areas
     5362    REAL(r_k), DIMENSION(dxA,dyA,dxyB), INTENT(out)      :: percentages
     5363
     5364! Local
     5365   INTEGER                                               :: iv, ix, iy
     5366   INTEGER                                               :: Nvertex
     5367   INTEGER, ALLOCATABLE, DIMENSION(:,:)                  :: poinsin
     5368   CHARACTER(len=20)                                     :: IS
     5369   REAL(r_k), ALLOCATABLE, DIMENSION(:)                  :: pareas
     5370   REAL(r_k), ALLOCATABLE, DIMENSION(:,:)                :: vertexgrid
     5371
     5372!!!!!!! Variables
     5373! dxA, dyA: shape of the matrix with the grid points A
     5374! xCAvals, yCAvals: coordinates of the center of the grid cells A
     5375! NAvertexmax: Maximum number of vertices of the grid cells A
     5376! xBAvals, yBAvals: coordinates of th vertices of the grid cells A (-99999 for no vertex)
     5377! dxB, dyB: shape of the matrix with the grid points B
     5378! xCBvals, yCBvals: coordinates of the center of the grid cells B
     5379! NBvertexmax: Maximum number of vertices of the grid cells B
     5380! xBBvals, yBBvals: coordinates of th vertices of the grid cells B (-99999 for no vertex)
     5381! strict: give an error if the area of the polygon is not fully covered
     5382! Nvercoinpolys: number of vertices of the coincident polygon of each grid
     5383! coinpolys: of vertices of the coincident polygon of each grid
     5384! Ngridsin: number of grids from grid B with some extension within the grid cell A
     5385! gridsin: indices of B grids within the grids of A
     5386! areas: areas of the grids
     5387! percentages: percentages of area of cells B of each of the grids inside the grid cell A
     5388
     5389    fname = 'grid_spacepercen_providing_polys'
     5390
     5391    areas = zeroRK
     5392
     5393    DO ix = 1, dxA
     5394      DO iy = 1, dyA
     5395
     5396        ! Getting grid vertices
     5397        Nvertex = 0
     5398        DO iv=1, NAvertexmax
     5399          IF (xBAvals(ix,iy,iv) /= fillval64) THEN
     5400           Nvertex = Nvertex + 1
     5401          END IF
     5402        END DO
     5403        IF (ALLOCATED(vertexgrid)) DEALLOCATE(vertexgrid)
     5404        ALLOCATE(vertexgrid(Nvertex,2))
     5405        vertexgrid(:,1) = xBAvals(ix,iy,1:Nvertex)
     5406        vertexgrid(:,2) = yBAvals(ix,iy,1:Nvertex)
     5407 
     5408        CALL grid_within_polygon(Nvertex, vertexgrid, dxB, dyB, dxB*dyB, xCBvals, yCBvals,            &
     5409          NBvertexmax, xBBvals, yBBvals, Ngridsin(ix,iy), gridsin(ix,iy,:,:))
     5410   
     5411        IF (ALLOCATED(poinsin)) DEALLOCATE(poinsin)
     5412        ALLOCATE(poinsin(Ngridsin(ix,iy),2))
     5413        IF (ALLOCATED(pareas)) DEALLOCATE(pareas)
     5414        ALLOCATE(pareas(Ngridsin(ix,iy)))
     5415
     5416        DO iv=1, Ngridsin(ix,iy)
     5417          poinsin(iv,1) = gridsin(ix,iy,iv,1)
     5418          poinsin(iv,2) = gridsin(ix,iy,iv,2)
     5419        END DO
     5420
     5421        CALL grid_spacepercen_within_reg_providing_polys(Nvertex, vertexgrid, dxB, dyB, NBvertexmax, &
     5422          xBBvals, yBBvals, Ngridsin(ix,iy), poinsin, strict, Nmaxvercoin, Nvercoinpolys(ix,iy,:,:), &
     5423          vercoinpolys(ix,iy,:,:,:), pareas, percentages(ix,iy,:))
     5424
     5425        ! Filling areas
     5426        DO iv = 1, Ngridsin(ix,iy)
     5427          IF (areas(poinsin(iv,1), poinsin(iv,2)) == zeroRK) THEN
     5428            areas(poinsin(iv,1), poinsin(iv,2)) = pareas(iv)
     5429          END IF
     5430        END DO
     5431
     5432      END DO
     5433    END DO
     5434
     5435    IF (ALLOCATED(vertexgrid)) DEALLOCATE(vertexgrid)
     5436    IF (ALLOCATED(pareas)) DEALLOCATE(pareas)
     5437    IF (ALLOCATED(poinsin)) DEALLOCATE(poinsin)
     5438
     5439  END SUBROUTINE grid_spacepercen_providing_polys
    52275440
    52285441  SUBROUTINE unique_matrixRK2D(dx, dy, dxy, matrix2D, Nunique, unique)
     
    57685981  END SUBROUTINE multi_index_mat4DRK
    57695982
     5983  SUBROUTINE coincident_list_2Dcoords(NpointsA, pointsA, NpointsB, pointsB, Npoints, points, inpA,    &
     5984    inpB)
     5985  ! Subroutine to determine which 2D points of an A list are also found in a B list
     5986
     5987    IMPLICIT NONE
     5988
     5989    INTEGER, INTENT(in)                                  :: NpointsA, NpointsB
     5990    INTEGER, DIMENSION(NpointsA,2), INTENT(in)           :: pointsA
     5991    INTEGER, DIMENSION(NpointsB,2), INTENT(in)           :: pointsB
     5992    INTEGER, INTENT(out)                                 :: Npoints
     5993    INTEGER, DIMENSION(NpointsA,2), INTENT(out)          :: points
     5994    INTEGER, DIMENSION(NpointsA), INTENT(out)            :: inpA, inpB
     5995
     5996    ! Local
     5997    INTEGER                                              :: iA, iB
     5998
     5999!!!!!!! Variables
     6000! NpointsA: Number of points of the list A
     6001! pointsA: points of the list A
     6002! NpointsB: Number of points of the list B
     6003! pointsB: points of the list B
     6004! Npoints: Number of coincident points
     6005! points: coincident points
     6006! inpA: coincident points list A
     6007! inpB: coincident points list B
     6008
     6009
     6010    fname = 'coincident_list_2Dcoords'
     6011
     6012    Npoints = 0
     6013    points = 0
     6014    inpA = 0
     6015    inpB = 0
     6016
     6017    DO iA = 1, NpointsA
     6018      DO iB = 1, NpointsB
     6019        IF ( (pointsA(iA,1) == pointsB(iB,1)) .AND. (pointsA(iA,2) == pointsB(iB,2)) ) THEN
     6020          Npoints = Npoints + 1
     6021          points(Npoints,:) = pointsA(iA,:)
     6022          inpA(Npoints) = iA
     6023          inpB(Npoints) = iB
     6024          EXIT
     6025        END IF
     6026
     6027      END DO
     6028    END DO
     6029
     6030  END SUBROUTINE coincident_list_2Dcoords
     6031
     6032  SUBROUTINE coincident_gridsin2D(dxA, dyA, dxyA, NpointsA, pointsA, dxB, dyB, dxyB, NpointsB,        &
     6033    pointsB, Npoints, points, inpointsA, inpointsB)
     6034  ! Subroutine to determine which lists of 2D gridsin points of an A list are also found in a B list
     6035
     6036    IMPLICIT NONE
     6037
     6038    INTEGER, INTENT(in)                                  :: dxA, dyA, dxyA
     6039    INTEGER, INTENT(in)                                  :: dxB, dyB, dxyB
     6040    INTEGER, DIMENSION(dxA, dyA), INTENT(in)             :: NpointsA
     6041    INTEGER, DIMENSION(dxB, dyB), INTENT(in)             :: NpointsB
     6042    INTEGER, DIMENSION(dxA, dyA, dxyA, 2), INTENT(in)    :: pointsA
     6043    INTEGER, DIMENSION(dxA, dyA, dxyB, 2), INTENT(in)    :: pointsB
     6044    INTEGER, DIMENSION(dxA, dyA, dxB, dyB), INTENT(out)  :: Npoints
     6045    INTEGER, DIMENSION(dxA, dyA, dxB, dyB, dxyA, 2),                                                  &
     6046      INTENT(out)                                        :: points
     6047    INTEGER, DIMENSION(dxA, dyA, dxyA), INTENT(out)      :: inpointsA
     6048    INTEGER, DIMENSION(dxB, dyB, dxyA), INTENT(out)      :: inpointsB
     6049
     6050    ! Local
     6051    INTEGER                                              :: ixA, iyA, ixB, iyB
     6052    INTEGER                                              :: NA, NB
     6053
     6054!!!!!!! Variables
     6055! dxA, dyA: 2D shape of the list A
     6056! NpointsA: 2D Number of points of the list A
     6057! pointsA: points of the list A
     6058! dxB, dyB: 2D shape of the list B
     6059! NpointsB: 2D Number of points of the list B
     6060! pointsB: points of the list B
     6061! Npoints: Number of coincident points
     6062! points: coincident points
     6063! inpointsA: coincident points list A
     6064! inpointsB: coincident points list B
     6065
     6066    fname = 'coincident_gridsin2D'
     6067
     6068    Npoints = 0
     6069    points = 0
     6070    inpointsA = 0
     6071    inpointsB = 0
     6072
     6073    DO ixA=1, dxA
     6074      DO iyA=1, dyA
     6075        NA = NpointsA(ixA,iyA)
     6076        DO ixB=1, dxB
     6077          DO iyB=1, dyB
     6078            NB = NpointsA(ixB,iyB)
     6079            CALL coincident_list_2Dcoords(NA, pointsA(ixA,iyA,1:NA,:), NB, pointsB(ixB,iyB,1:NB,:),   &
     6080              Npoints(ixA,iyA,ixB,iyB), points(ixA,iyA,ixB,iyB,:,:), inpointsA(ixA,iyA,:),            &
     6081              inpointsB(ixB,iyB,:))
     6082          END DO
     6083        END DO
     6084      END DO
     6085    END DO
     6086
     6087  END SUBROUTINE coincident_gridsin2D
     6088
    57706089END MODULE module_scientific
Note: See TracChangeset for help on using the changeset viewer.