Changeset 1661 in lmdz_wrf


Ignore:
Timestamp:
Oct 4, 2017, 12:27:56 AM (8 years ago)
Author:
lfita
Message:

Finally working version!

  • Three different methods have been added to determine the correct coordinate of the trajectory on multiple coincidencies 'mean': get coordinates from the areal-weighted mean of the centers of the given polygons and their areas 'largest': get the coorindates of the largest polygon 'closest': get the coordinates of the closest polygon
Location:
trunk/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/module_scientific.f90

    r1660 r1661  
    5858
    5959    INTEGER, INTENT(in)                                  :: funit, dt, itrack
    60     REAL(r_k), DIMENSION(4,dt), INTENT(out)              :: ftrack
     60    REAL(r_k), DIMENSION(5,dt), INTENT(out)              :: ftrack
    6161
    6262! Local
     
    7979    DO WHILE (.NOT.found)
    8080
    81       READ(funit,10)ftrack(1,1), Str1, ((ftrack(i,j),Str1,i=2,4),Str1,j=1,dt)
     81      READ(funit,10)ftrack(1,1), Str1, ((ftrack(i,j),Str1,i=2,5),Str1,j=1,dt)
    8282      IF (INT(ftrack(1,1)) == itrack) THEN
    8383        ftrack(1,2:dt) = ftrack(1,1)
     
    9292    RETURN
    9393
    94  10 FORMAT(I10000000,1x,A1,1x,10000000(3(F20.10,A1),A1))
     94 10 FORMAT(I10000000,1x,A1,1x,10000000(4(F20.10,A1),A1))
    9595
    9696  END SUBROUTINE read_finaltrack_ascii
     
    102102
    103103    INTEGER, INTENT(in)                                  :: funit, dt
    104     REAL(r_k), DIMENSION(4,dt), INTENT(in)               :: ftrack
     104    REAL(r_k), DIMENSION(5,dt), INTENT(in)               :: ftrack
    105105
    106106! Local
     
    113113
    114114    fname = 'write_finaltrack_ascii'
    115     WRITE(funit,10)INT(ftrack(1,1)), ';', ((ftrack(i,j), ',', i=2,4), ':', j=1,dt)
     115    WRITE(funit,10)INT(ftrack(1,1)), ';', ((ftrack(i,j), ',', i=2,5), ':', j=1,dt)
    116116
    117117    RETURN
    118118
    119  10 FORMAT(I10,1x,A1,1x,10000000(3(F20.10,A1),A1))
     119 10 FORMAT(I10,1x,A1,1x,10000000(4(F20.10,A1),A1))
    120120
    121121  END SUBROUTINE write_finaltrack_ascii
     
    373373
    374374  SUBROUTINE poly_overlap_tracks_area_ascii(dbg, compute, dx, dy, dt, minarea, inNallpolys, allpolys, &
    375     ctrpolys, areapolys, Nmaxpoly, Nmaxtracks)
     375    ctrpolys, areapolys, Nmaxpoly, Nmaxtracks, methodmulti)
    376376! Subroutine to determine tracks of a series of consecutive 2D field with polygons using maximum
    377377!   overlaping/coincidence filtrered by a minimal area writting theoutput on an ASCII file (memory limitations)
     
    380380
    381381    LOGICAL, INTENT(in)                                  :: dbg
    382     CHARACTER(LEN=*), INTENT(in)                         :: compute
     382    CHARACTER(LEN=*), INTENT(in)                         :: compute, methodmulti
    383383    INTEGER, INTENT(in)                                  :: dx, dy, dt, Nmaxpoly, Nmaxtracks
    384384    INTEGER, DIMENSION(dt), INTENT(in)                   :: inNallpolys
     
    398398    INTEGER, DIMENSION(Nmaxpoly)                         :: prevID, currID
    399399    REAL(r_k), DIMENSION(5,Nmaxpoly,Nmaxtracks,2)        :: tracks
    400     REAL(r_k), DIMENSION(4,dt)                           :: finaltracks
     400    REAL(r_k), DIMENSION(5,dt)                           :: finaltracks
    401401    INTEGER, DIMENSION(:), ALLOCATABLE                   :: coins
    402402    INTEGER, DIMENSION(:,:), ALLOCATABLE                 :: coinsNpts
     
    415415    INTEGER                                              :: idtrack, maxtrack
    416416    REAL(r_k), DIMENSION(5,Nmaxpoly,dt)                  :: singletrack
     417    REAL(r_k)                                            :: totArea, dist, mindist, maxarea, areai
    417418
    418419!!!!!!! Variables
     
    428429! Nmaxpoly: Maximum possible number of polygons
    429430! Nmaxtracks: maximum number of tracks
     431! methodmulti: methodology to follow when multiple polygons are given for the same track
     432!   'mean': get coordinates from the areal-weighted mean of the centers of the given polygons and their areas
     433!   'largest': get the coorindates of the largest polygon
     434!   'closest': get the coordinates of the closest polygon
    430435
    431436    fname = 'poly_overlap_tracks_area_ascii'
     
    475480    END SELECT
    476481
     482    ! Checking multi-polygon methodology
     483    IF ( (TRIM(methodmulti) /= 'mean') .AND. (TRIM(methodmulti) /= 'largest') .AND.                   &
     484      (TRIM(methodmulti) /= 'closest')) THEN
     485      msg= "methodology for multiple-polygons: '"//TRIM(methodmulti)//"' not ready" // NEW_LINE('a')//&
     486        " available ones: 'mean', 'largest', 'closest'"
     487      CALL ErrMsg(msg, fname, -1)
     488    END IF
     489
    477490    IF (dooverlap) THEN
    478491      ! ASCII file for all the polygons and their previous associated one
     
    585598        msg="Problems allocating 'coinsNpts'"
    586599        CALL ErrMsg(msg,fname,ierr)
    587 
    588         PRINT *,'  Lluis max(searchpolys):', MAXVAL(searchpolys), ' Nsearch:', Nsearch
    589600
    590601        CALL coincidence_all_polys_area(dbg, dx, dy, Nmeet, currID, meetpolys, Ccurrpolys(:,1:Nmeet),   &
     
    719730      ! First time-step. Take all polygons
    720731      itrack = 0
    721       tracks = 0.
     732      tracks = zeroRK
    722733      Ntracks = 0
    723734      it = 1
     
    776787                tracks(1,iip,ictrack,it) = itrack
    777788                tracks(2,iip,ictrack,it) = iiprev
    778                 ixp = ctrpolys(1,iiprev,iit)
    779                 iyp = ctrpolys(2,iiprev,iit)
    780                 tracks(3,iip,ictrack,it) = ixp
    781                 tracks(4,iip,ictrack,it) = iyp
     789                tracks(3,iip,ictrack,it) = ctrpolys(1,iiprev,iit)
     790                tracks(4,iip,ictrack,it) = ctrpolys(2,iiprev,iit)
    782791                tracks(5,iip,ictrack,it) = iit
    783792              END DO
     
    800809              tracks(1,j,ictrack,it) = maxtrack
    801810              tracks(2,j,ictrack,it) = iiprev
    802               ixp = ctrpolys(1,iiprev,iit)
    803               iyp = ctrpolys(2,iiprev,iit)
    804               tracks(3,j,ictrack,it) = ixp
    805               tracks(4,j,ictrack,it) = iyp
     811              tracks(3,j,ictrack,it) = ctrpolys(1,iiprev,iit)
     812              tracks(4,j,ictrack,it) = ctrpolys(2,iiprev,iit)
    806813              tracks(5,j,ictrack,it) = iit
    807814            END DO
     
    820827        CALL write_overlap_tracks_ascii(ftrackunit,iit,Nmaxpoly,Ntracks(it),tracks(:,:,1:Ntracks(it),it))
    821828        ! Re-initializing for the next time-step
    822         tracks(:,:,:,it-1) = 0
     829        tracks(:,:,:,it-1) = zeroRK
    823830        Ntracks(it-1) = Ntracks(it)
    824831        tracks(:,:,1:Ntracks(it-1),it-1) = tracks(:,:,1:Ntracks(it),it)
    825832        Ntracks(it) = 0
    826         tracks(:,:,:,it) = 0
     833        tracks(:,:,:,it) = zeroRK
    827834
    828835      END DO timesteps
     
    849856      CALL ErrMsg(msg,fname,ios)
    850857
    851       finaltracks = 0.
     858      finaltracks = zeroRK
    852859
    853860      DO itt=1, Nmaxtracks
     
    869876
    870877        finaltracks = zeroRK
    871         finaltracks(1,:) = itrack*1.
     878        finaltracks(1,:) = itrack*oneRK
    872879        DO it =1, dt     
    873880          Nprev = COUNT(INT(singletrack(2,:,it)) /= zeroRK)
    874881          IF (Nprev /= 0) THEN
    875             finaltracks(2,it) = SUM(singletrack(3,:,it))/Nprev*1.
    876             finaltracks(3,it) = SUM(singletrack(4,:,it))/Nprev*1.
    877             finaltracks(4,it) = it*1.
     882            finaltracks(5,it) = it*oneRK
     883            IF (TRIM(methodmulti) == 'largest') THEN
     884              maxarea = -10.*oneRK
     885              DO ip=1, Nprev
     886                IF (areapolys(singletrack(2,ip,it),it) > maxarea) THEN
     887                  maxarea = areapolys(singletrack(2,ip,it),it)
     888                  i = ip
     889                END IF
     890              END DO
     891              IF (dbg) THEN
     892                PRINT *,'  Determine the trajectory coordinates to the largest polygon:', i,          &
     893                  ' area:', maxarea
     894              END IF
     895              finaltracks(2,it) = singletrack(2,i,it)*oneRK
     896              finaltracks(3,it) = singletrack(3,i,it)
     897              finaltracks(4,it) = singletrack(4,i,it)
     898            ELSE IF (TRIM(methodmulti) == 'closest') THEN
     899              IF (it > 1) THEN
     900                mindist = 10000000.*oneRK
     901                DO ip=1, Nprev
     902                  dist = SQRT((singletrack(3,ip,it)-finaltracks(3,it-1))**2 +                         &
     903                    (singletrack(4,ip,it)-finaltracks(4,it-1))**2 )
     904                  IF (dist < mindist) THEN
     905                    mindist = dist
     906                    i = ip
     907                  END IF
     908                END DO
     909                finaltracks(2,it) = singletrack(3,i,it)*oneRK
     910                finaltracks(3,it) = singletrack(3,i,it)
     911                finaltracks(4,it) = singletrack(4,i,it)
     912                IF (dbg) THEN
     913                  PRINT *,'  Determine the trajectory coordinates to the closest previous polygon:',i,&
     914                    ' distance:', mindist
     915                END IF
     916              ELSE
     917                maxarea = -10.*oneRK
     918                DO ip=1, Nprev
     919                  IF (areapolys(singletrack(2,ip,it),it) > maxarea) THEN
     920                    maxarea = areapolys(singletrack(2,ip,it),it)
     921                    i = ip
     922                  END IF
     923                END DO
     924                IF (dbg) THEN
     925                  PRINT *, '  Determine the trajectory coordinates to the largest polygon:', i,        &
     926                    ' area:', maxarea, ' at the first time-step then to the closest'
     927                END IF
     928                finaltracks(2,it) = i*oneRK
     929                finaltracks(3,it) = singletrack(3,i,it)
     930                finaltracks(4,it) = singletrack(4,i,it)             
     931              END IF
     932            ELSE
     933              totArea = zeroRK
     934              finaltracks(2,it) = -oneRK
     935              finaltracks(3,it) = zeroRK
     936              finaltracks(4,it) = zeroRK
     937              DO ip=1, Nprev
     938                areai = areapolys(singletrack(2,ip,it),it)
     939                totArea = totArea + areai
     940                finaltracks(3,it) = finaltracks(3,it) + singletrack(3,ip,it)*areai
     941                finaltracks(4,it) = finaltracks(4,it) + singletrack(4,ip,it)*areai
     942              END DO
     943              finaltracks(3,it) = finaltracks(3,it)/totArea
     944              finaltracks(4,it) = finaltracks(4,it)/totArea
     945              IF (dbg) THEN
     946                PRINT *,'  Determine the trajectory coordinates to the area-averaged polygon ' //     &
     947                  ' total area:', totArea
     948              END IF
     949
     950            END IF
     951
    878952          END IF
    879953        END DO
     
    9331007    LOGICAL                                              :: Indeppolychained
    9341008    INTEGER                                              :: itrack, ictrack
    935     INTEGER                                              :: ixp, iyp, ttrack
     1009    REAL(r_k)                                            :: ixp, iyp
     1010    INTEGER                                              :: ttrack
    9361011    INTEGER, DIMENSION(dt)                               :: Ntracks
    9371012    INTEGER                                              :: idtrack, maxtrack
     
    12521327    IDpolys, polys, cpolys, apolys, polycoins, coinNptss)
    12531328! Subtourine to determine which is the coincident polygon when a boolean polygon is provided to a map of integer polygons
    1254 !   In case of multiple coincidencies, the closest and then the biggest is taken filtrered by a minimal area
     1329!   In case of multiple coincidencies, the closest and then the largest is taken filtrered by a minimal area
    12551330!   Here the difference is that the index does not coincide with its ID
    12561331
     
    13991474        IF (poly(i,j) .AND. polys(i,j) .NE. 0) THEN
    14001475          IF (.NOT.ANY(IDpoly == polys(i,j))) THEN
    1401             IF ((ip) > 0) PRINT *,'  Lluis ip:', ip, ' Npoly:', Npoly, ' ID:', polys(i,j), ' IDpoly:', IDpoly(1:ip), &
    1402               ' coinNpts:', coinNpts(ip)
    14031476            ip = ip + 1
    14041477            IDpoly(ip) = polys(i,j)
     
    17251798    apolys, polycoins, coinNptss)
    17261799! Subtourine to determine which is the coincident polygon when a boolean polygon is provided to a map of integer polygons
    1727 !   In case of multiple coincidencies, the closest and then the biggest is taken
     1800!   In case of multiple coincidencies, the closest and then the largest is taken
    17281801
    17291802    IMPLICIT NONE
  • trunk/tools/trajectories_overlap.f90

    r1660 r1661  
    2121  CHARACTER(len=50)                                      :: polyfilename
    2222  CHARACTER(len=50)                                      :: poly2Dn, polyNn, polywctrn, polywarean,   &
    23     varnresx, varnresy, timen, projectn, waycomp
     23    varnresx, varnresy, timen, projectn, waycomp, waymulti
    2424  LOGICAL                                                :: debug
    2525
     
    4242
    4343  NAMELIST /files/ polyfilename, poly2Dn, polyNn, polywctrn, polywarean, varnresx, varnresy, timen
    44   NAMELIST /config/ missing_value, minarea, projectn, waycomp, debug
     44  NAMELIST /config/ missing_value, minarea, projectn, waycomp, waymulti, debug
    4545
    4646!!!!!!!
     
    6363!   'scratch': everything from the beginning
    6464!   'continue': skipt that parts which already have the ascii file written
     65! waymulti: methodology to follow when multiple polygons are given for the same track
     66!   'mean': get coordinates from the areal-weighted mean of the centers of the given polygons and their areas
     67!   'largest': get the coorindates of the largest polygon
     68!   'closest': get the coordinates of the closest polygon
    6569
    6670  fname = 'trajectories_overlap'
     
    213217  ! Computing trajectories
    214218  CALL poly_overlap_tracks_area_ascii(debug, waycomp, dimx, dimy, dimt, minarea, polyN, polys,        &
    215     polywctrs, polyas, Nmaxpoly, Nmaxtrack)
     219    polywctrs, polyas, Nmaxpoly, Nmaxtrack, waymulti)
    216220
    217221  ! Writting trajectory files
Note: See TracChangeset for help on using the changeset viewer.