Changeset 1614 in lmdz_wrf


Ignore:
Timestamp:
Sep 1, 2017, 12:21:34 AM (7 years ago)
Author:
lfita
Message:

Fixing last issues on polygons detection
Adding direct acces to the 'module_scientific.f90' as `module_ForSci'

Location:
trunk/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/Makefile.llamp

    r1613 r1614  
    2525diagsrcs = module_definitions.f90 module_generic.f90 module_scientific.f90 module_ForDiagnosticsVars.f90 module_ForDiagnostics.f90
    2626intsrcs = module_definitions.f90 module_generic.f90 module_scientific.f90 module_ForInterpolate.f90
    27 scisrcs = module_definitions.f90 module_generic.f90 module_scientific.f90 module_ForInterpolate.f90
     27scisrcs = module_definitions.f90 module_generic.f90 module_scientific.f90
    2828
    2929####### ###### ##### #### ### ## #
  • trunk/tools/module_scientific.f90

    r1612 r1614  
    5252
    5353  polys = -1
     54  Npoly = 0
    5455
    5556  DO it=1,dt
    56     IF (dbg) THEN
    57       PRINT *,'  it:', it, ' bool _______'
    58       DO i=1,dx
    59         PRINT *,boolmatt(:,:,it)
    60       END DO
    61     END IF
    62     CALL polygons(dbg, dx, dy, boolmatt(:,:,it), polys(:,:,it), Npoly(it))
     57    IF (ANY(boolmatt(:,:,it))) THEN
     58      IF (dbg) THEN
     59        PRINT *,'  it:', it, ' num. TRUE:', COUNT(boolmatt(:,:,it)), 'bool _______'
     60        DO i=1,dx
     61          PRINT *,boolmatt(i,:,it)
     62        END DO
     63      END IF
     64      CALL polygons(dbg, dx, dy, boolmatt(:,:,it), polys(:,:,it), Npoly(it))
     65    ELSE
     66      IF (dbg) THEN
     67        PRINT *,'  it:', it, " without '.TRUE.' values skipiing it!!"
     68      END IF
     69    END IF
    6370  END DO
    6471
     
    8087  INTEGER                                                :: ierr
    8188  INTEGER, DIMENSION(:,:), ALLOCATABLE                   :: borders
    82   LOGICAL, DIMENSION(dx,dy)                              :: isborder
     89  LOGICAL, DIMENSION(dx,dy)                              :: isborder, isbordery
    8390  INTEGER, DIMENSION(:,:,:), ALLOCATABLE                 :: paths
    8491  INTEGER                                                :: Npath
    8592  INTEGER, DIMENSION(:), ALLOCATABLE                     :: Nptpaths
    8693  INTEGER, DIMENSION(2)                                  :: xtrx, xtry, meanpth
    87   INTEGER                                                :: Nvertx
     94  INTEGER                                                :: Nvertx, Npts
    8895  INTEGER, DIMENSION(:,:), ALLOCATABLE                   :: vertxs, points
    8996  LOGICAL, DIMENSION(:), ALLOCATABLE                     :: isin
     
    99106  polys = -1
    100107
    101   Nppt = dx*dy
     108  Nppt = dx*dy/10
     109  Npts = dx*dy
     110
    102111  IF (ALLOCATED(borders)) DEALLOCATE(borders)
    103112  ALLOCATE(borders(Nppt,2), STAT=ierr)
     
    117126  ! Filling with the points of all the space
    118127  IF (ALLOCATED(points)) DEALLOCATE(points)
    119   ALLOCATE(points(Nppt,2), STAT=ierr)
     128  ALLOCATE(points(Npts,2), STAT=ierr)
    120129  msg = "Problems allocating matrix 'points'"
    121130  CALL ErrMsg(msg, fname, ierr)
     
    130139  END DO
    131140
    132   CALL borders_matrixL(dx, dy, Nppt, boolmat, borders, isborder)
     141  CALL borders_matrixL(dx, dy, Nppt, boolmat, borders, isborder, isbordery)
    133142  CALL paths_border(dbg, dx, dy, isborder, Nppt, borders, paths, Npath, Nptpaths)
    134143
     
    142151
    143152    IF (ALLOCATED(isin)) DEALLOCATE(isin)
    144     ALLOCATE(isin(Nppt), STAT=ierr)
     153    ALLOCATE(isin(Npts), STAT=ierr)
    145154    msg = "Problems allocating matrix 'isin'"
    146155    CALL ErrMsg(msg, fname, ierr)
     
    164173    END IF
    165174 
    166     CALL gridpoints_InsidePolygon(dx, dy, boolmat, Nptpaths(ip), paths(ip,1:Nptpaths(ip),:), Nvertx,  &
    167       xtrx, xtry, vertxs, Nppt, points, isin)
     175    CALL gridpoints_InsidePolygon(dx, dy, isbordery, Nptpaths(ip), paths(ip,1:Nptpaths(ip),:), Nvertx,&
     176      xtrx, xtry, vertxs, Npts, points, isin)
    168177
    169178    ! Filling polygons
     
    175184      END DO
    176185    END DO
     186
     187    IF (dbg) THEN
     188      PRINT *,'  boolmat isborder isbordery polygon (',xtrx(1),',',xtry(1),')x(',xtrx(2),',',xtry(2), &
     189        ') _______'
     190      DO i=xtrx(1), xtrx(2)
     191        PRINT *,i,':',boolmat(i,xtry(1):xtry(2)), ' border ', isborder(i,xtry(1):xtry(2)),            &
     192          ' isbordery ', isbordery(i,xtry(1):xtry(2)), ' polygon ', polys(i,xtry(1):xtry(2))
     193      END DO
     194    END IF
    177195
    178196  END DO
     
    306324! Local
    307325  INTEGER                                                :: i,j,ip,ix,iy
    308   INTEGER                                                :: Nintersecs, isvertex
     326  INTEGER                                                :: Nintersecs, isvertex, ispath
    309327  INTEGER                                                :: ierr
    310328  LOGICAL, DIMENSION(:,:), ALLOCATABLE                   :: halo_brdr
     329  INTEGER                                                :: Nbrbrdr
    311330
    312331!!!!!!! Variables
     
    316335! isbrdr: boolean matrix of the space wqith .T. on polygon border
    317336! Nvrtx: number of vertexs of the path
     337! [x/y]pathxtrm extremes of the path
    318338! vrtxs: vertexs of the path along y-axis
    319339! Npts: number of points
     
    345365
    346366      ! It is a border point?
    347       IF (isbrdr(ix,iy)) THEN
     367      ispath = index_list_coordsI(Npath, path, (/ix,iy/))
     368      IF (isbrdr(ix,iy) .AND. (ispath /= -1)) THEN
    348369        inside(ip) = .TRUE.
    349370        CYCLE
     
    351372
    352373      ! Looking along y-axis
    353       DO j=1,iy
     374      ! Accounting for consecutives borders
     375      Nbrbrdr = 0
     376      DO j=MAX(1,ypathxtrm(1)-1),iy-1
    354377        ! Only counting that borders that are not vertexs
     378        ispath = index_list_coordsI(Npath, path, (/ix,j/))
    355379        isvertex = index_list_coordsI(Npath, vrtxs, (/ix,j/))
    356         IF (halo_brdr(ix+1,j+1) .AND. ( isvertex == -1)) Nintersecs = Nintersecs + 1
     380
     381        IF (halo_brdr(ix+1,j+1) .AND. (ispath /= -1) .AND. (isvertex == -1) ) Nintersecs = Nintersecs + 1
     382        IF (halo_brdr(ix+1,j+1) .AND. (ispath /= -1) .AND. (halo_brdr(ix+1,j+1) .EQV. halo_brdr(ix+1,j+2))) THEN
     383          Nbrbrdr = Nbrbrdr + 1
     384        ELSE
     385          ! Will remove that consecutive borders above 2
     386          IF (Nbrbrdr /= 0) THEN
     387            Nintersecs = Nintersecs - MAX(Nbrbrdr-1, 0)
     388            Nbrbrdr = 0
     389          END IF
     390        END IF
    357391      END DO
    358392      IF (MOD(Nintersecs,2) /= 0) inside(ip) = .TRUE.
     
    398432
    399433  ! Label of the search
    400   lclock = (/ 'N ', 'NE', 'E ', 'SE', 'S ', 'SW', 'W ', 'NW' /)
     434  lclock = (/ 'W ', 'NW', 'N ', 'NE', 'E ', 'SE', 'S ', 'SW' /)
    401435  ! Transformation to apply
    402   !spt = (/ (/0,1/), (/1,1/), (/1,0/), (/1,-1/), (/0,-1/), (/-1,-1/), (/-1,0/), (/-1,1/) /)
    403   spt(:,1) = (/ 0, 1, 1, 1, 0, -1, -1, -1 /)
    404   spt(:,2) = (/ 1, 1, 0, -1, -1, -1, 0, 1 /)
     436  !spt = (/ (/-1,0/), (/-1,1/), (/0,1/), (/1,1/), (/1,0/), (/1,-1/), (/0,-1/), (/-1,-1/) /)
     437  spt(:,1) = (/ -1, -1, 0, 1, 1, 1, 0, -1 /)
     438  spt(:,2) = (/ 0, 1, 1, 1, 0, -1, -1, -1 /)
    405439
    406440  xf = -1
     
    434468END SUBROUTINE look_clockwise_borders
    435469
    436 SUBROUTINE borders_matrixL(dx,dy,dxy,Lmat,brdrs,isbrdr)
     470SUBROUTINE borders_matrixL(dx,dy,dxy,Lmat,brdrs,isbrdr,isbrdry)
    437471! Subroutine to provide the borders of a logical array (interested in .TRUE.)
    438472
     
    442476  LOGICAL, DIMENSION(dx,dy), INTENT(in)                  :: Lmat
    443477  INTEGER, DIMENSION(dxy,2), INTENT(out)                 :: brdrs
    444   LOGICAL, DIMENSION(dx,dy), INTENT(out)                 :: isbrdr
     478  LOGICAL, DIMENSION(dx,dy), INTENT(out)                 :: isbrdr, isbrdry
    445479
    446480! Local
     
    453487! brdrs: list of coordinates of the borders
    454488! isbrdr: matrix with .T./.F. wether the given matrix point is a border or not
     489! isbrdry: matrix with .T./.F. wether the given matrix point is a border or not only along y-axis
    455490
    456491  fname = 'borders_matrixL'
     
    491526    END IF
    492527  END DO
     528
     529  isbrdry = isbrdr
    493530
    494531  ! Border as that when looking on x-axis points with Lmat(i) /= Lmat(i+1)
     
    514551          brdrs(ib,2) = j
    515552          isbrdr(i,j) = .TRUE.
     553          isbrdry(i,j) = .TRUE.
    516554          ib=ib+1
    517555        ELSE IF (Lmat(i,j+1) .AND. .NOT.isbrdr(i,j+1)) THEN
     
    519557          brdrs(ib,2) = j+1
    520558          isbrdr(i,j+1) = .TRUE.
     559          isbrdry(i,j+1) = .TRUE.
    521560          ib=ib+1
     561        END IF
     562      END IF
     563    END DO       
     564  END DO
     565
     566  DO i=1, dx-1
     567    DO j=1, dy-1
     568      ! y-axis
     569      IF ( Lmat(i,j) .NEQV. Lmat(i,j+1) ) THEN
     570        IF (Lmat(i,j)) THEN
     571          isbrdry(i,j) = .TRUE.
     572        ELSE IF (Lmat(i,j+1)) THEN
     573          isbrdry(i,j+1) = .TRUE.
     574        END IF
     575      END IF
     576    END DO       
     577  END DO
     578  ! only y-axis adding bands of 2 grid points
     579  DO i=1, dx-1
     580    DO j=2, dy-2
     581      IF ( (Lmat(i,j) .EQV. Lmat(i,j+1)) .AND. (Lmat(i,j).NEQV.Lmat(i,j-1)) .AND. (Lmat(i,j).NEQV.Lmat(i,j+2)) ) THEN
     582        IF (Lmat(i,j)) THEN
     583          isbrdry(i,j) = .TRUE.
     584          isbrdry(i,j+1) = .TRUE.
    522585        END IF
    523586      END IF
     
    578641   
    579642  IF (dbg) THEN
    580     PRINT *,'  isborder ______'
    581     DO i=1,dx
    582       PRINT *,isborder(i,:)
    583     END DO
    584 
    585643    PRINT *,'    borders _______'
    586644    DO i=1,Nbrdr
     
    651709          ELSE
    652710            Nptpaths(ipath) = Nptspath
    653             ! Let's have a look if the next point would be someone already in the path
    654             CALL look_clockwise_borders(dx,dy,Nppt,borders,gotbrdr,isborder,iip,ijp,.FALSE.,iif,jjf,  &
    655               iff)
    656             iff = index_list_coordsI(Nptspath, paths(ipath,:,:),(/iif,jjf/))
    657             IF (iff /= -1) THEN
    658               IF (dbg) THEN
    659                 PRINT *,'    point already in Path!'
    660                 PRINT *,'  path:', ipath, '_____'
    661                 DO i=1, Nptspath
    662                   PRINT *,'    ',i,':',paths(ipath,i,:)
    663                 END DO
     711            ! Let's have a look if the previous points in the path have already some 'non-located' neighbourgs
     712            DO i=Nptspath,1,-1
     713              iip = paths(ipath,i,1)
     714              ijp = paths(ipath,i,2)
     715              CALL look_clockwise_borders(dx,dy,Nppt,borders,gotbrdr,isborder,iip,ijp,.FALSE., iif,   &
     716                jjf,iff)
     717              IF (iif /= -1 .AND. iff /= -1) THEN
     718                IF (dbg) PRINT *,'    re-take path from point:', iif,',',jjf,' n-path:', iff
     719                found = .TRUE.
     720                iipth = index_list_coordsI(Nppt, borders, (/iip,ijp/))
     721                EXIT
    664722              END IF
    665               ! Continung unfinished path
    666               iip = paths(ipath,Nptspath,1)
    667               ijp = paths(ipath,Nptspath,2)
    668               iipth = index_list_coordsI(Nppt, borders, (/iip,ijp/))
    669             ELSE
     723            END DO
     724            IF (.NOT.found) THEN
    670725              ! Looking for the next available border point for the new path
    671726              DO i=1,Nbrdr
Note: See TracChangeset for help on using the changeset viewer.