Changeset 1652 in lmdz_wrf
- Timestamp:
- Sep 21, 2017, 7:32:58 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/module_scientific.f90
r1651 r1652 7 7 ! coincidence_all_polys: Subtourine to determine which is the coincident polygon when a boolean polygon is provided 8 8 ! to a map of integer polygons 9 ! coincidence_all_polys_area: Subtourine to determine which is the coincident polygon when a boolean polygon is provided 10 ! to a map of integer polygons filtrered by a minimal area 9 11 ! coincidence_poly: Subtourine to determine which is the coincident polygon when a boolean polygon is provided 10 12 ! to a map of integer polygons 13 ! coincidence_poly_area: Subtourine to determine which is the coincident polygon when a boolean polygon is provided 14 ! to a map of integer polygons filtrered by a minimal area 11 15 ! clean_polygons: Subroutine to clean polygons from non-used paths, polygons only left as path since they are inner path of a hole 12 16 ! FindMinimumR_K*: Function returns the location of the minimum in the section between Start and End. … … 22 26 ! poly_overlap_tracks: Subroutine to determine tracks of a series of consecutive 2D field with polygons using 23 27 ! maximum overlaping/coincidence! PrintQuantilesR_K: Subroutine to print the quantiles of values REAL(r_k) 28 ! poly_overlap_tracks_area: Subroutine to determine tracks of a series of consecutive 2D field with polygons using 29 ! maximum overlaping/coincidence filtrered by a minimal area 24 30 ! quantilesR_K: Subroutine to provide the quantiles of a given set of values of type real 'r_k' 25 31 ! rand_sample: Subroutine to randomly sample a range of indices … … 38 44 39 45 40 SUBROUTINE poly_overlap_tracks(dbg, dx, dy, dt, Nallpolys, allpolys, ctrpolys, areapolys, Nmaxpoly, & 41 Nmaxtracks, tracks, finaltracks) 46 SUBROUTINE poly_overlap_tracks_area(dbg, dx, dy, dt, minarea, inNallpolys, allpolys, ctrpolys, & 47 areapolys, Nmaxpoly, Nmaxtracks, tracks, finaltracks) 48 ! Subroutine to determine tracks of a series of consecutive 2D field with polygons using maximum 49 ! overlaping/coincidence filtrered by a minimal area 50 51 IMPLICIT NONE 52 53 LOGICAL, INTENT(in) :: dbg 54 INTEGER, INTENT(in) :: dx, dy, dt, Nmaxpoly, Nmaxtracks 55 INTEGER, DIMENSION(dt), INTENT(in) :: inNallpolys 56 INTEGER, DIMENSION(dx,dy,dt), INTENT(in) :: allpolys 57 REAL(r_k), INTENT(in) :: minarea 58 REAL(r_k), DIMENSION(2,Nmaxpoly,dt), INTENT(in) :: ctrpolys 59 REAL(r_k), DIMENSION(Nmaxpoly,dt), INTENT(in) :: areapolys 60 REAL(r_k), DIMENSION(5,Nmaxpoly,Nmaxtracks,dt), & 61 INTENT(out) :: tracks 62 REAL(r_k), DIMENSION(4,Nmaxtracks,dt), INTENT(out) :: finaltracks 63 64 ! Local 65 INTEGER :: i, j, ip, it, iip, itt 66 INTEGER :: ierr 67 REAL(r_k), DIMENSION(2,Nmaxpoly,dt) :: Actrpolys 68 REAL(r_k), DIMENSION(Nmaxpoly,dt) :: Aareapolys 69 INTEGER, DIMENSION(dt) :: Nallpolys 70 INTEGER, DIMENSION(dx,dy) :: meetpolys, searchpolys 71 INTEGER, DIMENSION(Nmaxpoly) :: coincidencies 72 INTEGER, DIMENSION(Nmaxpoly) :: prevID, currID 73 INTEGER, DIMENSION(:), ALLOCATABLE :: coins 74 INTEGER, DIMENSION(:,:), ALLOCATABLE :: coinsNpts 75 INTEGER, DIMENSION(Nmaxpoly,dt) :: polycoincidencies 76 INTEGER, DIMENSION(Nmaxpoly,Nmaxpoly,dt) :: coincidenciesNpts 77 INTEGER :: Nmeet, Nsearch, Nindep 78 INTEGER, DIMENSION(dt) :: Nindeppolys 79 CHARACTER(len=5) :: NcoinS 80 INTEGER, DIMENSION(Nmaxpoly,Nmaxpoly,dt) :: polysIndep 81 INTEGER, DIMENSION(Nmaxpoly,dt) :: NpolysIndep 82 INTEGER, DIMENSION(Nmaxpoly,dt) :: SpolysIndep 83 INTEGER :: iindep, iiprev 84 INTEGER :: Nprev, NNprev, Ntprev 85 LOGICAL :: Indeppolychained 86 INTEGER :: itrack, ictrack 87 INTEGER :: ixp, iyp, ttrack 88 INTEGER, DIMENSION(dt) :: Ntracks 89 INTEGER :: idtrack, maxtrack 90 91 !!!!!!! Variables 92 ! dx,dy,dt: space/time dimensions 93 ! Nallpolys: Vector with the number of polygons at each time-step 94 ! allpolys: Series of 2D field with the polygons 95 ! minarea: minimal area (in same units as areapolys) to perform the tracking 96 ! ctrpolys: center of the polygons 97 ! areapolys: area of the polygons 98 ! Nmaxpoly: Maximum possible number of polygons 99 ! Nmaxtracks: maximum number of tracks 100 ! tracks: series of consecutive polygons 101 ! trackperiod: period of the track in time-steps 102 103 fname = 'poly_overlap_tracks_area' 104 105 IF (dbg) PRINT *,TRIM(fname) 106 107 polycoincidencies = fillvalI 108 coincidenciesNpts = fillvalI 109 ! Number of independent polygons by time step 110 Nindeppolys = 0 111 ! Number of polygons attached to each independent polygons by time step 112 NpolysIndep = 0 113 ! ID of searching polygon attached to each independent polygons by time step 114 SpolysIndep = 0 115 ! ID of polygons attached to each independent polygons by time step 116 polysIndep = 0 117 ! ID of polygons from previous time-step 118 prevID = 0 119 ! ID of polygons from current time-step 120 currID = 0 121 122 ! First time-step all are independent polygons 123 it = 1 124 Nmeet = inNallpolys(it) 125 Nindeppolys(it) = Nmeet 126 ip = 0 127 meetpolys = allpolys(:,:,it) 128 DO i=1, Nmeet 129 IF (areapolys(i,it) >= minarea) THEN 130 ip = ip + 1 131 SpolysIndep(ip,it) = i 132 currID(ip) = i 133 NpolysIndep(ip,it) = 1 134 polysIndep(ip,1,it) = i 135 Actrpolys(1,ip,it) = ctrpolys(1,i,it) 136 Actrpolys(2,ip,it) = ctrpolys(2,i,it) 137 Aareapolys(ip,it) = areapolys(i,it) 138 ELSE 139 WHERE (meetpolys == i) 140 meetpolys = 0 141 END WHERE 142 END IF 143 END DO 144 Nallpolys(1) = ip 145 Nindeppolys(1) = ip 146 147 ! Starting step 148 it = 0 149 IF (dbg) THEN 150 PRINT *,' time step:',it+1,' number to look polygons:', Nmeet,' searching polygons:',0 151 PRINT *,' number of independent polygons:', Nindeppolys(it+1) 152 PRINT *,' indep_polygon prev_step_polygon Nassociated_polygons curr_ass_polygons _______' 153 DO i=1, Nindeppolys(it+1) 154 PRINT *,i, SpolysIndep(i,it+1), NpolysIndep(i,it+1), ':', & 155 polysIndep(i,1:NpolysIndep(i,it+1),it+1) 156 END DO 157 END IF 158 159 ! Looking for the coincidencies at each time step 160 DO it=1, dt-1 161 ! Number of times that a polygon has a coincidence 162 coincidencies = 0 163 164 Nmeet = inNallpolys(it+1) 165 searchpolys = meetpolys 166 meetpolys = allpolys(:,:,it+1) 167 prevID = 0 168 prevID = currID 169 ip = 0 170 171 DO i=1, Nmeet 172 IF (areapolys(i,it+1) >= minarea) THEN 173 ip = ip + 1 174 currID(ip) = i 175 Actrpolys(1,ip,it+1) = ctrpolys(1,i,it+1) 176 Actrpolys(2,ip,it+1) = ctrpolys(2,i,it+1) 177 Aareapolys(ip,it+1) = areapolys(i,it+1) 178 ELSE 179 WHERE (meetpolys == i) 180 meetpolys = 0 181 END WHERE 182 END IF 183 END DO 184 Nallpolys(it+1) = ip 185 Nindeppolys(it+1) = ip 186 187 Nmeet = Nallpolys(it+1) 188 ! Looking throughout the independent polygons 189 Nsearch = Nindeppolys(it) 190 191 IF (ALLOCATED(coins)) DEALLOCATE(coins) 192 ALLOCATE(coins(Nmeet), STAT=ierr) 193 msg="Problems allocating 'coins'" 194 CALL ErrMsg(msg,fname,ierr) 195 196 IF (ALLOCATED(coinsNpts)) DEALLOCATE(coinsNpts) 197 ALLOCATE(coinsNpts(Nmeet, Nsearch), STAT=ierr) 198 msg="Problems allocating 'coinsNpts'" 199 CALL ErrMsg(msg,fname,ierr) 200 201 CALL coincidence_all_polys_area(dbg, dx,dy, Nmeet, currID, meetpolys, Actrpolys(:,1:Nmeet,it+1),& 202 Nsearch, prevID, searchpolys, Actrpolys(:,1:Nsearch,it), Aareapolys(1:Nsearch,it), coins, & 203 coinsNpts) 204 205 polycoincidencies(1:Nmeet,it+1) = coins 206 coincidenciesNpts(1:Nmeet,1:Nsearch,it+1) = coinsNpts 207 208 ! Counting the number of times that a polygon has a coincidency 209 IF (dbg) THEN 210 PRINT *,' Coincidencies for the given time-step:', it+1,' _______' 211 DO i=1, Nmeet 212 PRINT *,currID(i), coins(i),' N search pts:', coinsNpts(i,:) 213 END DO 214 END IF 215 216 ! Looking for the same equivalencies 217 Nindep = 0 218 DO i=1, Nmeet 219 IF (coins(i) == -1) THEN 220 Nindep = Nindep + 1 221 SpolysIndep(Nindep,it+1) = -1 222 NpolysIndep(Nindep,it+1) = NpolysIndep(Nindep,it+1) + 1 223 polysIndep(Nindep,NpolysIndep(Nindep,it+1),it+1) = currID(i) 224 ELSE IF (coins(i) == -9) THEN 225 WRITE(NcoinS,'(I5)')coins(i) 226 msg="coins= "//TRIM(NcoinS)//" This is an error. One should have always only one " // & 227 "coincidence of polygon" 228 CALL ErrMsg(msg, fname, -1) 229 ELSE 230 ! Looking for coincidences with previous independent polygons 231 DO ip=1, Nsearch 232 ! Looking into the polygons associated 233 NNprev = NpolysIndep(ip,it) 234 DO j=1, NNprev 235 IF (coins(i) == polysIndep(ip,j,it)) THEN 236 IF (coincidencies(ip) == 0) THEN 237 Nindep = Nindep + 1 238 SpolysIndep(Nindep,it+1) = coins(i) 239 END IF 240 ! Which index corresponds to this coincidence? 241 iindep = Index1DArrayI(SpolysIndep(1:Nmeet,it+1), Nindep, coins(i)) 242 IF (iindep < 0) THEN 243 msg = 'Wrong index! There must be an index here' 244 CALL ErrMsg(msg,fname,iindep) 245 END IF 246 coincidencies(ip) = coincidencies(ip) + 1 247 NpolysIndep(iindep,it+1) = NpolysIndep(iindep,it+1) + 1 248 polysIndep(iindep,NpolysIndep(iindep,it+1),it+1) = currID(i) 249 EXIT 250 END IF 251 END DO 252 END DO 253 END IF 254 END DO 255 Nindeppolys(it+1) = Nindep 256 257 IF (dbg) THEN 258 PRINT *,' time step:',it+1,' number to look polygons:', Nmeet,' searching polygons:',Nsearch 259 PRINT *,' number of independent polygons:', Nindeppolys(it+1) 260 PRINT *,' indep_polygon prev_step_polygon Nassociated_polygons curr_ass_polygons _______' 261 DO i=1, Nindeppolys(it+1) 262 PRINT *,i, SpolysIndep(i,it+1), NpolysIndep(i,it+1), ':', & 263 polysIndep(i,1:NpolysIndep(i,it+1),it+1) 264 END DO 265 END IF 266 END DO 267 268 IF (dbg) THEN 269 PRINT *, 'Coincidencies to connect _______' 270 DO it=1, dt 271 PRINT *,' it:', it, ' Nindep:', Nindeppolys(it) 272 PRINT '(4x,3(A6,1x))','Nindep', 'PrevID', 'IDs' 273 DO ip=1, Nindeppolys(it) 274 PRINT '(4x,I6,A1,I6,A1,100(I6))', ip, ',', SpolysIndep(ip,it), ':', & 275 polysIndep(ip,1:NpolysIndep(ip,it),it) 276 END DO 277 END DO 278 279 END IF 280 281 ! Trajectories 282 ! It should be done following the number of 'independent' polygons 283 ! One would concatenate that independent polygons which share IDs from one step to another 284 285 ! First time-step. Take all polygons 286 itrack = 0 287 tracks = 0. 288 Ntracks = 0 289 DO ip=1, Nindeppolys(1) 290 itrack = itrack + 1 291 tracks(1,1,itrack,1) = itrack*1. 292 tracks(2,1,itrack,1) = SpolysIndep(ip,1) 293 tracks(3,1,itrack,1) = ctrpolys(1,ip,1) 294 tracks(4,1,itrack,1) = ctrpolys(2,ip,1) 295 tracks(5,1,itrack,1) = 1 296 Ntracks(1) = Ntracks(1) + 1 297 END DO 298 299 ! Looping allover already assigned tracks 300 timesteps: DO it=2, dt 301 IF (dbg) PRINT *,'track-timestep:', it, 'N indep polys:', Nindeppolys(it) 302 ! Indep polygons current time-step 303 current_poly: DO i=1, Nindeppolys(it) 304 IF (dbg) PRINT *,' curent poly:', i, 'Prev poly:', SpolysIndep(i,it), ' N ass. polygons:', & 305 NpolysIndep(i,it), 'ass. poly:', polysIndep(i,1:NpolysIndep(i,it),it) 306 Indeppolychained = .FALSE. 307 308 ! Number of tracks previous time-step 309 ! Looping overall 310 it1_tracks: DO itt=1, Ntracks(it-1) 311 itrack = tracks(1,1,itt,it-1) 312 ! Number polygons ID assigned 313 Ntprev = COUNT(tracks(2,:,itt,it-1) /= 0) 314 IF (dbg) PRINT *,itt,' track:', itrack, 'assigned:', tracks(2,1:Ntprev,itt,it-1) 315 316 ! Looking for coincidencies 317 DO iip=1, Ntprev 318 IF (tracks(2,iip,itt,it-1) == SpolysIndep(i,it)) THEN 319 Indeppolychained = .TRUE. 320 IF (dbg) PRINT *,' coincidence found by polygon:', tracks(2,iip,itt,it-1) 321 EXIT 322 END IF 323 END DO 324 IF (Indeppolychained) THEN 325 Ntracks(it) = Ntracks(it) + 1 326 ictrack = Ntracks(it) 327 ! Assigning all the IDs to the next step of the track 328 DO iip=1, NpolysIndep(i,it) 329 iiprev = polysIndep(i,iip,it) 330 tracks(1,iip,ictrack,it) = itrack 331 tracks(2,iip,ictrack,it) = iiprev 332 ixp = ctrpolys(1,iiprev,it) 333 iyp = ctrpolys(2,iiprev,it) 334 tracks(3,iip,ictrack,it) = ixp 335 tracks(4,iip,ictrack,it) = iyp 336 tracks(5,iip,ictrack,it) = it 337 END DO 338 EXIT 339 END IF 340 IF (Indeppolychained) EXIT 341 END DO it1_tracks 342 343 ! Creation of a new track 344 IF (.NOT.Indeppolychained) THEN 345 Ntracks(it) = Ntracks(it) + 1 346 ictrack = Ntracks(it) 347 ! ID of new track 348 maxtrack = INT(MAXVAL(tracks(1,:,:,:)*1.)) 349 IF (dbg) PRINT *,' New track!', maxtrack+1 350 351 ! Assigning all the IDs to the next step of the track 352 DO j=1, NpolysIndep(i,it) 353 iiprev = polysIndep(i,j,it) 354 tracks(1,j,ictrack,it) = maxtrack+1 355 tracks(2,j,ictrack,it) = iiprev 356 ixp = ctrpolys(1,iiprev,it) 357 iyp = ctrpolys(2,iiprev,it) 358 tracks(3,j,ictrack,it) = ixp 359 tracks(4,j,ictrack,it) = iyp 360 tracks(5,j,ictrack,it) = it 361 END DO 362 END IF 363 364 END DO current_poly 365 366 IF (dbg) THEN 367 PRINT *,' At this time-step:', it, ' N trajectories:', Ntracks(it) 368 DO i=1, Ntracks(it) 369 Nprev = COUNT(INT(tracks(2,:,i,it)) /= 0) 370 PRINT *,i ,'ID tracks:', tracks(1,1,i,it), 'ID polygon:', tracks(2,1:Nprev,i,it) 371 END DO 372 END IF 373 374 END DO timesteps 375 376 ! Summarizing trajectories 377 ! When multiple polygons are available, the mean of their central positions determines the position 378 379 finaltracks = 0. 380 maxtrack = MAXVAL(tracks(1,:,:,:)) 381 382 DO it=1, dt 383 DO itt=1, Ntracks(it) 384 itrack = INT(tracks(1,1,itt,it)) 385 Nprev = COUNT(INT(tracks(2,:,itt,it)) /= 0) 386 PRINT *,'it:', it,'itrack:', itrack, 'Nprev:', Nprev 387 PRINT *,' coordinates ix iy _______' 388 DO i=1,Nprev 389 PRINT *,' ',tracks(3,i,itt,it),tracks(4,i,itt,it) 390 END DO 391 finaltracks(1,itrack,it) = itrack*1. 392 finaltracks(2,itrack,it) = SUM(tracks(3,:,itt,it))/Nprev 393 finaltracks(3,itrack,it) = SUM(tracks(4,:,itt,it))/Nprev 394 finaltracks(4,itrack,it) = it*1. 395 PRINT *,' finaltrack:', finaltracks(:,itrack,it) 396 END DO 397 END DO 398 399 RETURN 400 401 END SUBROUTINE poly_overlap_tracks_area 402 403 SUBROUTINE coincidence_all_polys_area(dbg, dx, dy, Nallpoly, IDallpoly, allpoly, icpolys, Npoly, & 404 IDpolys, polys, cpolys, apolys, polycoins, coinNptss) 405 ! Subtourine to determine which is the coincident polygon when a boolean polygon is provided to a map of integer polygons 406 ! In case of multiple coincidencies, the closest and then the biggest is taken filtrered by a minimal area 407 ! Here the difference is that the index does not coincide with its ID 408 409 IMPLICIT NONE 410 411 LOGICAL, INTENT(in) :: dbg 412 INTEGER, INTENT(in) :: dx, dy, Nallpoly, Npoly 413 INTEGER, DIMENSION(dx,dy), INTENT(in) :: allpoly, polys 414 INTEGER, DIMENSION(Nallpoly), INTENT(in) :: IDallpoly 415 INTEGER, DIMENSION(Npoly), INTENT(in) :: IDpolys 416 REAL(r_k), DIMENSION(2,Nallpoly), INTENT(in) :: icpolys 417 REAL(r_k), DIMENSION(2,Npoly), INTENT(in) :: cpolys 418 REAL(r_k), DIMENSION(Npoly), INTENT(in) :: apolys 419 INTEGER, DIMENSION(Nallpoly), INTENT(out) :: polycoins 420 INTEGER, DIMENSION(Nallpoly,Npoly), INTENT(out) :: coinNptss 421 422 ! Local 423 INTEGER :: i, j, ip 424 INTEGER :: maxcorr 425 INTEGER :: Nmaxcorr 426 LOGICAL, DIMENSION(dx,dy) :: boolpoly 427 INTEGER :: maxcoin 428 REAL :: dist, maxcoindist, maxcoinarea 429 INTEGER, DIMENSION(Npoly) :: IDcoins 430 431 !!!!!!! Variables 432 ! dx,dy: dimension of the space 433 ! Nallpoly: Number of polygons to find coincidence 434 ! allpoly: space with the polygons to meet 435 ! icpolys: center of the polygons to look for the coincidence 436 ! Npoly: number of polygons on the 2D space 437 ! polys: 2D field of polygons identified by their integer number (0 for no polygon) 438 ! cpolys: center of the polygons 439 ! apolys: area of the polygons 440 ! polycoins: coincident polyogn 441 ! -1: no-coincidence 442 ! 1 < Npoly: single coincidence with a given polygon 443 ! -9: coincidence with more than one polygon 444 ! coinNptss: number of points coincident with each polygon 445 446 fname = 'coincidence_all_polys_area' 447 IF (dbg) PRINT *,TRIM(fname) 448 449 DO ip=1, Nallpoly 450 boolpoly = allpoly == IDallpoly(ip) 451 CALL coincidence_poly_area(dbg, dx, dy, boolpoly, Npoly, polys, polycoins(ip), IDcoins, & 452 coinNptss(ip,:)) 453 IF (dbg) PRINT *,' polygon', IDallpoly(ip), ' coincidence with:', polycoins(ip), 'IDpolys:', IDpolys(1:Npoly) 454 455 ! Coincidence with more than one polygon 456 IF (polycoins(ip) == -9) THEN 457 maxcoindist = -10. 458 maxcoinarea = -10. 459 maxcoin = MAXVAL(coinNptss(ip,:)) 460 DO j=1, Npoly 461 IF (coinNptss(ip,j) == maxcoin) THEN 462 dist = SQRT( (icpolys(1,ip)*1.-cpolys(1,j)*1.)**2 + (icpolys(2,ip)*1.-cpolys(2,j)*1.)**2 ) 463 IF ( dist > maxcoindist) THEN 464 maxcoindist = dist 465 maxcoinarea = apolys(j) 466 polycoins(ip) = IDcoins(j) 467 ELSE IF ( dist == maxcoindist) THEN 468 IF (apolys(j) > maxcoinarea) THEN 469 polycoins(ip) = IDcoins(j) 470 maxcoinarea = apolys(j) 471 END IF 472 END IF 473 END IF 474 END DO 475 END IF 476 END DO 477 478 RETURN 479 480 END SUBROUTINE coincidence_all_polys_area 481 482 SUBROUTINE coincidence_poly_area(dbg, dx, dy, poly, Npoly, polys, polycoin, IDpoly, coinNpts) 483 ! Subtourine to determine which is the coincident polygon when a boolean polygon is provided to a map of integer polygons 484 ! Here the difference is that the index does not coincide with its ID 485 486 IMPLICIT NONE 487 488 LOGICAL, INTENT(in) :: dbg 489 INTEGER, INTENT(in) :: dx, dy, Npoly 490 LOGICAL, DIMENSION(dx,dy), INTENT(in) :: poly 491 INTEGER, DIMENSION(dx,dy), INTENT(in) :: polys 492 INTEGER, INTENT(out) :: polycoin 493 INTEGER, DIMENSION(Npoly), INTENT(out) :: IDpoly, coinNpts 494 495 ! Local 496 INTEGER :: i, j, ip 497 INTEGER :: maxcorr 498 INTEGER :: Nmaxcorr 499 500 !!!!!!! Variables 501 ! dx,dy: dimension of the space 502 ! poly: bolean polygon to meet 503 ! Npoly: number of polygons on the 2D space 504 ! polys: 2D field of polygons identified by their integer number (0 for no polygon) 505 ! polycoin: coincident polyogn 506 ! -1: no-coincidence 507 ! 1 < Npoly: single coincidence with a given polygon 508 ! -9: coincidence with more than one polygon 509 ! IDpoly: ID of the found polygon 510 ! coinNpts: number of points coincident with each polygon 511 512 fname = 'coincidence_poly_area' 513 IF (dbg) PRINT *,TRIM(fname) 514 515 IF (dbg) THEN 516 PRINT *,' Boolean polygon to search coincidences ...' 517 DO i=1,dx 518 PRINT *,poly(i,:) 519 END DO 520 521 PRINT *,' 2D polygons space ...' 522 DO i=1,dx 523 PRINT '(1000(I3,1x))',polys(i,:) 524 END DO 525 END IF 526 527 ! Looking for coincient points for the polygon 528 coinNpts = 0 529 IDpoly = 0 530 ip = 0 531 DO i=1,dx 532 DO j=1,dy 533 IF (poly(i,j) .AND. polys(i,j) .NE. 0) THEN 534 IF (.NOT.ANY(IDpoly == polys(i,j))) THEN 535 ip = ip + 1 536 IDpoly(ip) = polys(i,j) 537 ELSE 538 ip = Index1DarrayI(IDpoly, Npoly, polys(i,j)) 539 END IF 540 coinNpts(ip) = coinNpts(ip) + 1 541 END IF 542 END DO 543 END DO 544 545 maxcorr = 0 546 maxcorr = INT(MAXVAL(coinNpts*1.)) 547 548 IF (dbg) PRINT *,' Maximum coincidence:', maxcorr 549 IF (maxcorr == 0) THEN 550 polycoin = -1 551 ELSE 552 Nmaxcorr = 0 553 DO ip=1, Npoly 554 IF (coinNpts(ip) == maxcorr) THEN 555 Nmaxcorr = Nmaxcorr+1 556 polycoin = IDpoly(ip) 557 END IF 558 END DO 559 IF (Nmaxcorr > 1) polycoin = -9 560 END IF 561 562 IF (dbg) THEN 563 PRINT *,' Coincidences for each polygon _______', Npoly 564 DO ip=1, Npoly 565 PRINT *,' ',ip, ' ID:', IDpoly(ip),': ', coinNpts(ip) 566 END DO 567 END IF 568 569 RETURN 570 571 END SUBROUTINE coincidence_poly_area 572 573 SUBROUTINE poly_overlap_tracks(dbg, dx, dy, dt, minarea, Nallpolys, allpolys, ctrpolys, & 574 areapolys, Nmaxpoly, Nmaxtracks, tracks, finaltracks) 42 575 ! Subroutine to determine tracks of a series of consecutive 2D field with polygons using maximum overlaping/coincidence 43 576 … … 48 581 INTEGER, DIMENSION(dt), INTENT(in) :: Nallpolys 49 582 INTEGER, DIMENSION(dx,dy,dt), INTENT(in) :: allpolys 583 REAL(r_k), INTENT(in) :: minarea 50 584 REAL(r_k), DIMENSION(2,Nmaxpoly,dt), INTENT(in) :: ctrpolys 51 585 REAL(r_k), DIMENSION(Nmaxpoly,dt), INTENT(in) :: areapolys … … 80 614 ! Nallpolys: Vector with the number of polygons at each time-step 81 615 ! allpolys: Series of 2D field with the polygons 616 ! minarea: minimal area (in same units as areapolys) to perform the tracking 82 617 ! ctrpolys: center of the polygons 83 618 ! areapolys: area of the polygons … … 286 821 END DO current_poly 287 822 288 IF (dbg) PRINT *,' At this time-step:', it, ' N trajectories:', Ntracks(it) 289 DO i=1, Ntracks(it) 290 Nprev = COUNT(INT(tracks(2,:,i,it)) /= 0) 291 PRINT *,i,'tracks:', tracks(2,1:Nprev,i,it) 292 END DO 823 IF (dbg) THEN 824 PRINT *,' At this time-step:', it, ' N trajectories:', Ntracks(it) 825 DO i=1, Ntracks(it) 826 Nprev = COUNT(INT(tracks(2,:,i,it)) /= 0) 827 PRINT *,i,'tracks:', tracks(2,1:Nprev,i,it) 828 END DO 829 END IF 293 830 294 831 END DO timesteps
Note: See TracChangeset
for help on using the changeset viewer.