Changeset 2327 in lmdz_wrf for trunk/tools/module_scientific.f90
- Timestamp:
- Feb 11, 2019, 2:47:36 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/module_scientific.f90
r2319 r2327 90 90 ! write_overlap_polys_ascii: Subroutine to write to an ASCII file the associated polygons at a given time-step 91 91 ! write_overlap_tracks_ascii: Subroutine to write to an ASCII the polygons associated to a trajectory at a given time step 92 ! zones_homogenization: Subroutine to homogenize 2D contiguous zones, zones might be contiguous, but 93 ! with different number assigned ! 92 94 93 95 !!! *Functions/Subroutines to sort values adpated. The method used is usually referred to as "selection" method. … … 6703 6705 END SUBROUTINE coincident_gridsin2D 6704 6706 6707 SUBROUTINE zones_homogenization(dx, dy, inzones, outzones) 6708 ! Subroutine to homogenize 2D contiguous zones, zones might be contiguous, but with different number assigned ! 6709 ! Here we have a 2D matrix of integers, with contiguous integer filled zones, zero outside any zone 6710 ! It might be, that within the same zone, might be lines which do not share the same integer 6711 ! 0 0 0 0 0 0 0 0 0 0 6712 ! 0 1 1 0 0 0 1 1 0 0 6713 ! 0 2 0 0 1 == > 0 1 0 0 2 6714 ! 0 1 1 0 0 0 1 1 0 0 6715 6716 IMPLICIT NONE 6717 6718 INTEGER, INTENT(in) :: dx, dy 6719 INTEGER, DIMENSION(dx,dy), INTENT(in) :: inzones 6720 INTEGER, DIMENSION(dx,dy), INTENT(out) :: outzones 6721 6722 ! Local 6723 INTEGER :: i,j,k 6724 INTEGER :: Nmaxzones, TOTzones 6725 LOGICAL :: assigned 6726 INTEGER, DIMENSION(dy) :: prevline 6727 INTEGER, DIMENSION(dx) :: Nyzones 6728 INTEGER, DIMENSION(:,:,:), ALLOCATABLE :: zones 6729 6730 !!!!!!! Variables 6731 ! dx, dy: Shape of the 2D space 6732 ! inzones: zones to homogenize 6733 ! outzones: zones homogenized 6734 6735 fname = 'zones_homogenization' 6736 6737 ! Maximum possible number of zones 6738 Nmaxzones = INT((dx/2)*(dy/2)) 6739 6740 ! Matrix with [i,j,Nzone,izone/ezone] 6741 IF (ALLOCATED(zones)) DEALLOCATE(zones) 6742 ALLOCATE(zones(dx,Nmaxzones,3)) 6743 6744 zones = 0 6745 Nyzones = 0 6746 ! Getting beginning/end of y-bands 6747 DO i=1, dx 6748 k = 0 6749 j = 1 6750 IF (inzones(i,j) /= 0) THEN 6751 k = k + 1 6752 zones(i,k,1) = j 6753 zones(i,k,3) = k 6754 END IF 6755 DO j=2, dy 6756 IF ( (inzones(i,j) /= 0) .AND. (inzones(i,j-1) == 0)) THEN 6757 k = k+1 6758 zones(i,k,1) = j 6759 zones(i,k,3) = k 6760 ELSE IF ( (inzones(i,j-1) /= 0) .AND. (inzones(i,j) == 0)) THEN 6761 zones(i,k,2) = j-1 6762 zones(i,k,3) = k 6763 END IF 6764 END DO 6765 IF (k > 0) THEN 6766 IF (zones(i,k,2) == 0) zones(i,k,2) = dy 6767 END IF 6768 Nyzones(i) = k 6769 END DO 6770 6771 ! Homogenizing contigous zones 6772 outzones = 0 6773 TOTzones = 0 6774 i = 1 6775 DO k = 1, Nyzones(i) 6776 TOTzones = TOTzones + 1 6777 DO j=zones(i,k,1), zones(i,k,2) 6778 outzones(i,j) = TOTzones 6779 END DO 6780 END DO 6781 6782 DO i=2, dx 6783 prevline = outzones(i-1,:) 6784 DO k = 1, Nyzones(i) 6785 assigned = .FALSE. 6786 DO j=zones(i,k,1), zones(i,k,2) 6787 IF (prevline(j) /= 0) THEN 6788 outzones(i,zones(i,k,1):zones(i,k,2)) = prevline(j) 6789 assigned = .TRUE. 6790 EXIT 6791 END IF 6792 END DO 6793 IF (.NOT.assigned) THEN 6794 TOTzones = TOTzones + 1 6795 DO j=zones(i,k,1), zones(i,k,2) 6796 outzones(i,j) = TOTzones 6797 END DO 6798 END IF 6799 END DO 6800 END DO 6801 6802 IF (ALLOCATED(zones)) DEALLOCATE(zones) 6803 6804 END SUBROUTINE zones_homogenization 6805 6705 6806 END MODULE module_scientific
Note: See TracChangeset
for help on using the changeset viewer.