Changeset 2345 in lmdz_wrf for trunk/tools
- Timestamp:
- Feb 18, 2019, 4:00:24 PM (6 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/module_ForDiagnostics.f90
r2341 r2345 1056 1056 ! Homogenizing indices of the ranges 1057 1057 CALL continguos_homogene_zones(d1, d2, iranges, Nranges, ranges) 1058 WHERE (ranges == -1) 1059 ranges = fillValI 1060 END WHERE 1058 1061 1059 1062 RETURN -
trunk/tools/module_scientific.f90
r2341 r2345 2573 2573 2574 2574 ! Local 2575 INTEGER :: i, j, ip, ipp, Nppt2575 INTEGER :: i, j, k, ip, ipp, Nppt 2576 2576 INTEGER :: ierr 2577 2577 INTEGER, DIMENSION(:,:), ALLOCATABLE :: borders … … 2618 2618 ! Filling with the points of all the space with .TRUE. 2619 2619 Npts = COUNT(boolmat) 2620 PRINT * ,'Lluis Npts:', Npts, 'Nppt:', Nppt2620 PRINT *, dx, dy, 'Lluis Npts:', Npts, 'Nppt:', Nppt 2621 2621 2622 2622 IF (ALLOCATED(points)) DEALLOCATE(points) 2623 ALLOCATE(points( Npts,2), STAT=ierr)2623 ALLOCATE(points(dy,2), STAT=ierr) 2624 2624 msg = "Problems allocating matrix 'points'" 2625 2625 CALL ErrMsg(msg, fname, ierr) 2626 2627 ! We only want to localize that points 'inside'2628 ip = 12629 DO i=1, dx2630 DO j=1, dy2631 IF (boolmat(i,j)) THEN2632 points(ip,1) = i2633 points(ip,2) = j2634 ip = ip + 12635 END IF2636 END DO2637 END DO2638 2626 2639 2627 CALL borders_matrixL(dbg, dx, dy, Nppt, boolmat, borders, isborder, isbordery) … … 2654 2642 2655 2643 isin = .FALSE. 2656 2657 IF (dbg) THEN2658 PRINT *, ' path:', ip, ' N pts:', Nptpaths(ip)2659 DO j=1, Nptpaths(ip)2660 PRINT *, ' ',j,':',paths(ip,j,:)2661 END DO2662 END IF2663 2644 2664 2645 borderp = .FALSE. … … 2681 2662 END IF 2682 2663 2683 CALL gridpoints_InsidePolygon(dbg, dx, dy, isbordery, Nptpaths(ip), paths(ip,1:Nptpaths(ip),:), & 2684 Nvertx, xtrx, xtry, vertxs, Npts, points, isin) 2685 2686 ! Filling polygons 2687 DO ipp=1, Npts 2688 IF (isin(ipp)) polys(points(ipp,1),points(ipp,2)) = ip 2664 ! CALL gridpoints_InsidePolygon(dbg, dx, dy, isbordery, Nptpaths(ip), paths(ip,1:Nptpaths(ip),:), & 2665 ! Nvertx, xtrx, xtry, vertxs, Npts, points, isin) 2666 2667 ! We only want to localize that points 'inside' 2668 Npts = 1 2669 DO i=xtrx(1), xtrx(2) 2670 DO j=1, dy 2671 IF (boolmat(i,j)) THEN 2672 points(Npts,1) = i 2673 points(Npts,2) = j 2674 Npts = Npts + 1 2675 END IF 2676 END DO 2677 CALL gridpoints_InsidePolygon_ray(dbg,dy,borderp(i,:), Nptpaths(ip), paths(ip,1:Nptpaths(ip),:),& 2678 Nvertx, xtrx, xtry, vertxs, Npts, points, isin) 2679 2680 ! Filling polygons 2681 DO ipp=1, Npts 2682 IF (isin(ipp)) polys(points(ipp,1),points(ipp,2)) = ip 2683 END DO 2684 2685 IF (dbg) THEN 2686 PRINT *,' path boolmat isborder isborderp polygon (', xtrx(1), ',', xtry(1), ')x(', xtrx(2), & 2687 ',', xtry(2), ') _______' , Npts 2688 PRINT *,ip,'<>', i,':',boolmat(i,xtry(1):xtry(2)), ' border ', isborder(i,xtry(1):xtry(2)), & 2689 ' isbordery ', borderp(i,xtry(1):xtry(2)), ' polygon ', polys(i,xtry(1):xtry(2)) 2690 END IF 2691 2689 2692 END DO 2690 2691 IF (dbg) THEN2692 PRINT *,' boolmat isborder isbordery polygon (',xtrx(1),',',xtry(1),')x(',xtrx(2),',',xtry(2), &2693 ') _______'2694 DO i=xtrx(1), xtrx(2)2695 PRINT *,i,':',boolmat(i,xtry(1):xtry(2)), ' border ', isborder(i,xtry(1):xtry(2)), &2696 ' isbordery ', isbordery(i,xtry(1):xtry(2)), ' polygon ', polys(i,xtry(1):xtry(2))2697 END DO2698 END IF2699 2700 2693 END DO 2694 PRINT *,' PRE-clean ' 2701 2695 2702 2696 ! Cleaning polygons matrix of not-used and paths around holes 2703 CALL clean_polygons(dx, dy, boolmat, polys, Npoly, dbg)2697 !CALL clean_polygons(dx, dy, boolmat, polys, Npoly, dbg) 2704 2698 2705 2699 IF (ALLOCATED(borders)) DEALLOCATE (borders) … … 3022 3016 3023 3017 END SUBROUTINE gridpoints_InsidePolygon 3018 3019 3020 SUBROUTINE gridpoints_InsidePolygon_ray(dbg, dy, isbrdr, Npath, path, Nvrtx, xpathxtrm, ypathxtrm, & 3021 vrtxs, Npts, pts, inside) 3022 ! Subroutine to determine if a series of grid points are inside a polygon following ray casting algorithm 3023 ! FROM: https://en.wikipedia.org/wiki/Point_in_polygon 3024 3025 IMPLICIT NONE 3026 3027 INTEGER, INTENT(in) :: dy,Npath,Nvrtx,Npts 3028 LOGICAL, INTENT(in) :: dbg 3029 LOGICAL, DIMENSION(dy), INTENT(in) :: isbrdr 3030 INTEGER, DIMENSION(Npath,2), INTENT(in) :: path 3031 INTEGER, DIMENSION(2), INTENT(in) :: xpathxtrm, ypathxtrm 3032 INTEGER, DIMENSION(Npath,2) :: vrtxs 3033 INTEGER, DIMENSION(dy,2), INTENT(in) :: pts 3034 LOGICAL, DIMENSION(Npts), INTENT(out) :: inside 3035 3036 ! Local 3037 INTEGER :: i,j,ip,ix,iy 3038 INTEGER :: Nintersecs, isvertex, ispath 3039 INTEGER :: ierr 3040 LOGICAL, DIMENSION(:), ALLOCATABLE :: halo_brdr 3041 INTEGER :: Nbrbrdr 3042 3043 !!!!!!! Variables 3044 ! dy: y-axis space size 3045 ! Npath: number of points of the path of the polygon 3046 ! path: path of the polygon 3047 ! isbrdr: boolean matrix of the space wqith .T. on polygon border 3048 ! Nvrtx: number of vertexs of the path 3049 ! [x/y]pathxtrm extremes of the path 3050 ! vrtxs: vertexs of the path along y-axis 3051 ! Npts: number of points 3052 ! pts: points to look for 3053 ! inside: vector wether point is inside or not (coincident to a border is inside) 3054 3055 fname = 'gridpoints_InsidePolygon_ray' 3056 3057 ! Creation of a 1-grid point larger matrix to deal with points reaching the limits 3058 IF (ALLOCATED(halo_brdr)) DEALLOCATE(halo_brdr) 3059 ALLOCATE(halo_brdr(dy+2), STAT=ierr) 3060 msg = "Problems allocating matrix 'halo_brdr'" 3061 CALL ErrMsg(msg, fname, ierr) 3062 halo_brdr = .FALSE. 3063 3064 IF (dbg) PRINT *,'Border _______' 3065 halo_brdr(2:dy+1) = isbrdr(:) 3066 IF (dbg) PRINT *,isbrdr(:) 3067 3068 inside = .FALSE. 3069 3070 DO ip=1,dy 3071 Nintersecs = 0 3072 ix = pts(ip,1) 3073 iy = pts(ip,2) 3074 ! Point might be outside path range... 3075 IF (ix >= xpathxtrm(1) .AND. ix <= xpathxtrm(2) .AND. iy >= ypathxtrm(1) .AND. & 3076 iy <= ypathxtrm(2)) THEN 3077 3078 ! It is a border point? 3079 ispath = index_list_coordsI(Npath, path, (/ix,iy/)) 3080 IF (isbrdr(iy) .AND. (ispath /= -1)) THEN 3081 inside(ip) = .TRUE. 3082 CYCLE 3083 END IF 3084 3085 ! Looking along y-axis 3086 ! Accounting for consecutives borders 3087 Nbrbrdr = 0 3088 DO j=MAX(1,ypathxtrm(1)-1),iy-1 3089 ! Only counting that borders that are not vertexs 3090 ispath = index_list_coordsI(Npath, path, (/ix,j/)) 3091 isvertex = index_list_coordsI(Npath, vrtxs, (/ix,j/)) 3092 3093 IF (halo_brdr(j+1) .AND. (ispath /= -1) .AND. (isvertex == -1) ) Nintersecs = Nintersecs + 1 3094 IF (halo_brdr(j+1) .AND. (ispath /= -1) .AND. (halo_brdr(j+1) .EQV. halo_brdr(j+2))) THEN 3095 Nbrbrdr = Nbrbrdr + 1 3096 IF (dbg) PRINT *,' ',Nbrbrdr,' Consec brdrs:', halo_brdr(j+1), halo_brdr(j+2), '(', & 3097 ix,j,';', ix,j+1,')', '(', ix,j,';', ix,j+1,')', isbrdr(j), isbrdr(j+1) 3098 ELSE 3099 ! Will remove that consecutive borders above 2 3100 IF (Nbrbrdr /= 0) THEN 3101 IF (dbg) PRINT *, ix,',',iy,';', Nintersecs, ' amount of consecutive borders:', Nbrbrdr, & 3102 ' removing:', MAX(Nbrbrdr-1, 0) 3103 Nintersecs = Nintersecs - MAX(Nbrbrdr-1, 0) 3104 Nbrbrdr = 0 3105 END IF 3106 END IF 3107 END DO 3108 IF (MOD(Nintersecs,2) /= 0) inside(ip) = .TRUE. 3109 IF (dbg) PRINT *,ip,' point:', ix, iy, 'isbrdr:', isbrdr(1:iy-1), 'y-ray:', halo_brdr(1:iy), & 3110 'inside:', inside(ip) 3111 END IF 3112 3113 END DO 3114 3115 RETURN 3116 3117 END SUBROUTINE gridpoints_InsidePolygon_ray 3024 3118 3025 3119 SUBROUTINE look_clockwise_borders(dx,dy,Nbrdrs,brdrs,gbrdr,isbrdr,ix,iy,dbg,xf,yf,iff)
Note: See TracChangeset
for help on using the changeset viewer.