Changeset 5099 for LMDZ6/branches/Amaury_dev/libf/phylmd/cospv2/mrgrnk.F90
- Timestamp:
- Jul 22, 2024, 9:29:09 PM (4 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
LMDZ6/branches/Amaury_dev/libf/phylmd/cospv2/mrgrnk.F90
r5095 r5099 2 2 ! Copyright (c) 2015, Regents of the University of Colorado 3 3 ! All rights reserved. 4 ! 4 5 5 ! Redistribution and use in source and binary forms, with or without modification, are 6 6 ! permitted provided that the following conditions are met: 7 ! 7 8 8 ! 1. Redistributions of source code must retain the above copyright notice, this list of 9 9 ! conditions and the following disclaimer. 10 ! 10 11 11 ! 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 12 ! of conditions and the following disclaimer in the documentation and/or other 13 13 ! materials provided with the distribution. 14 ! 14 15 15 ! 3. Neither the name of the copyright holder nor the names of its contributors may be 16 16 ! used to endorse or promote products derived from this software without specific prior 17 17 ! written permission. 18 ! 18 19 19 ! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 20 ! EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF … … 26 26 ! LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 27 ! OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 ! 28 29 29 ! History: 30 30 ! May 2015: Dustin Swales - Modified for COSPv2.0 31 ! 31 32 32 ! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 33 33 Module m_mrgrnk … … 56 56 ! __________________________________________________________ 57 57 Real (wp) :: XVALA, XVALB 58 ! 58 59 59 Integer, Dimension (SIZE(IRNGT)) :: JWRKT 60 60 Integer :: LMTNA, LMTNC, IRNG1, IRNG2 61 61 Integer :: NVAL, IIND, IWRKD, IWRK, IWRKF, JINDA, IINDA, IINDB 62 ! 62 63 63 NVAL = Min (SIZE(XDONT), SIZE(IRNGT)) 64 64 Select Case (NVAL) … … 71 71 Continue 72 72 End Select 73 ! 73 74 74 ! Fill-in the index array, creating ordered couples 75 ! 75 76 76 Do IIND = 2, NVAL, 2 77 77 If (XDONT(IIND-1) <= XDONT(IIND)) Then … … 86 86 IRNGT (NVAL) = NVAL 87 87 End If 88 ! 88 89 89 ! We will now have ordered subsets A - B - A - B - ... 90 90 ! and merge A and B couples into C - C - ... 91 ! 91 92 92 LMTNA = 2 93 93 LMTNC = 4 94 ! 94 95 95 ! First iteration. The length of the ordered subsets goes from 2 to 4 96 ! 96 97 97 Do 98 98 If (NVAL <= 2) Exit 99 ! 99 100 100 ! Loop on merges of A and B into C 101 ! 101 102 102 Do IWRKD = 0, NVAL - 1, 4 103 103 If ((IWRKD+4) > NVAL) Then 104 104 If ((IWRKD+2) >= NVAL) Exit 105 ! 105 106 106 ! 1 2 3 107 ! 107 108 108 If (XDONT(IRNGT(IWRKD+2)) <= XDONT(IRNGT(IWRKD+3))) Exit 109 ! 109 110 110 ! 1 3 2 111 ! 111 112 112 If (XDONT(IRNGT(IWRKD+1)) <= XDONT(IRNGT(IWRKD+3))) Then 113 113 IRNG2 = IRNGT (IWRKD+2) 114 114 IRNGT (IWRKD+2) = IRNGT (IWRKD+3) 115 115 IRNGT (IWRKD+3) = IRNG2 116 ! 116 117 117 ! 3 1 2 118 ! 118 119 119 Else 120 120 IRNG1 = IRNGT (IWRKD+1) … … 125 125 Exit 126 126 End If 127 ! 127 128 128 ! 1 2 3 4 129 ! 129 130 130 If (XDONT(IRNGT(IWRKD+2)) <= XDONT(IRNGT(IWRKD+3))) Cycle 131 ! 131 132 132 ! 1 3 x x 133 ! 133 134 134 If (XDONT(IRNGT(IWRKD+1)) <= XDONT(IRNGT(IWRKD+3))) Then 135 135 IRNG2 = IRNGT (IWRKD+2) … … 143 143 IRNGT (IWRKD+4) = IRNG2 144 144 End If 145 ! 145 146 146 ! 3 x x x 147 ! 147 148 148 Else 149 149 IRNG1 = IRNGT (IWRKD+1) … … 168 168 End If 169 169 End Do 170 ! 170 171 171 ! The Cs become As and Bs 172 ! 172 173 173 LMTNA = 4 174 174 Exit 175 175 End Do 176 ! 176 177 177 ! Iteration loop. Each time, the length of the ordered subsets 178 178 ! is doubled. 179 ! 179 180 180 Do 181 181 If (LMTNA >= NVAL) Exit 182 182 IWRKF = 0 183 183 LMTNC = 2 * LMTNC 184 ! 184 185 185 ! Loop on merges of A and B into C 186 ! 186 187 187 Do 188 188 IWRK = IWRKF … … 196 196 IINDA = 1 197 197 IINDB = JINDA + 1 198 ! 198 199 199 ! Shortcut for the case when the max of A is smaller 200 200 ! than the min of B. This line may be activated when the 201 201 ! initial set is already close to sorted. 202 ! 202 203 203 ! IF (XDONT(IRNGT(JINDA)) <= XDONT(IRNGT(IINDB))) CYCLE 204 ! 204 205 205 ! One steps in the C subset, that we build in the final rank array 206 ! 206 207 207 ! Make a copy of the rank array for the merge iteration 208 ! 208 209 209 JWRKT (1:LMTNA) = IRNGT (IWRKD:JINDA) 210 ! 210 211 211 XVALA = XDONT (JWRKT(IINDA)) 212 212 XVALB = XDONT (IRNGT(IINDB)) 213 ! 213 214 214 Do 215 215 IWRK = IWRK + 1 216 ! 216 217 217 ! We still have unprocessed values in both A and B 218 ! 218 219 219 If (XVALA > XVALB) Then 220 220 IRNGT (IWRK) = IRNGT (IINDB) … … 232 232 XVALA = XDONT (JWRKT(IINDA)) 233 233 End If 234 ! 234 235 235 End Do 236 236 End Do 237 ! 237 238 238 ! The Cs become As and Bs 239 ! 239 240 240 LMTNA = 2 * LMTNA 241 241 End Do 242 ! 242 243 243 Return 244 ! 244 245 245 End Subroutine D_mrgrnk 246 246 … … 256 256 ! __________________________________________________________ 257 257 Real(wp) :: XVALA, XVALB 258 ! 258 259 259 Integer, Dimension (SIZE(IRNGT)) :: JWRKT 260 260 Integer :: LMTNA, LMTNC, IRNG1, IRNG2 261 261 Integer :: NVAL, IIND, IWRKD, IWRK, IWRKF, JINDA, IINDA, IINDB 262 ! 262 263 263 NVAL = Min (SIZE(XDONT), SIZE(IRNGT)) 264 264 Select Case (NVAL) … … 271 271 Continue 272 272 End Select 273 ! 273 274 274 ! Fill-in the index array, creating ordered couples 275 ! 275 276 276 Do IIND = 2, NVAL, 2 277 277 If (XDONT(IIND-1) <= XDONT(IIND)) Then … … 286 286 IRNGT (NVAL) = NVAL 287 287 End If 288 ! 288 289 289 ! We will now have ordered subsets A - B - A - B - ... 290 290 ! and merge A and B couples into C - C - ... 291 ! 291 292 292 LMTNA = 2 293 293 LMTNC = 4 294 ! 294 295 295 ! First iteration. The length of the ordered subsets goes from 2 to 4 296 ! 296 297 297 Do 298 298 If (NVAL <= 2) Exit 299 ! 299 300 300 ! Loop on merges of A and B into C 301 ! 301 302 302 Do IWRKD = 0, NVAL - 1, 4 303 303 If ((IWRKD+4) > NVAL) Then 304 304 If ((IWRKD+2) >= NVAL) Exit 305 ! 305 306 306 ! 1 2 3 307 ! 307 308 308 If (XDONT(IRNGT(IWRKD+2)) <= XDONT(IRNGT(IWRKD+3))) Exit 309 ! 309 310 310 ! 1 3 2 311 ! 311 312 312 If (XDONT(IRNGT(IWRKD+1)) <= XDONT(IRNGT(IWRKD+3))) Then 313 313 IRNG2 = IRNGT (IWRKD+2) 314 314 IRNGT (IWRKD+2) = IRNGT (IWRKD+3) 315 315 IRNGT (IWRKD+3) = IRNG2 316 ! 316 317 317 ! 3 1 2 318 ! 318 319 319 Else 320 320 IRNG1 = IRNGT (IWRKD+1) … … 325 325 Exit 326 326 End If 327 ! 327 328 328 ! 1 2 3 4 329 ! 329 330 330 If (XDONT(IRNGT(IWRKD+2)) <= XDONT(IRNGT(IWRKD+3))) Cycle 331 ! 331 332 332 ! 1 3 x x 333 ! 333 334 334 If (XDONT(IRNGT(IWRKD+1)) <= XDONT(IRNGT(IWRKD+3))) Then 335 335 IRNG2 = IRNGT (IWRKD+2) … … 343 343 IRNGT (IWRKD+4) = IRNG2 344 344 End If 345 ! 345 346 346 ! 3 x x x 347 ! 347 348 348 Else 349 349 IRNG1 = IRNGT (IWRKD+1) … … 368 368 End If 369 369 End Do 370 ! 370 371 371 ! The Cs become As and Bs 372 ! 372 373 373 LMTNA = 4 374 374 Exit 375 375 End Do 376 ! 376 377 377 ! Iteration loop. Each time, the length of the ordered subsets 378 378 ! is doubled. 379 ! 379 380 380 Do 381 381 If (LMTNA >= NVAL) Exit 382 382 IWRKF = 0 383 383 LMTNC = 2 * LMTNC 384 ! 384 385 385 ! Loop on merges of A and B into C 386 ! 386 387 387 Do 388 388 IWRK = IWRKF … … 396 396 IINDA = 1 397 397 IINDB = JINDA + 1 398 ! 398 399 399 ! Shortcut for the case when the max of A is smaller 400 400 ! than the min of B. This line may be activated when the 401 401 ! initial set is already close to sorted. 402 ! 402 403 403 ! IF (XDONT(IRNGT(JINDA)) <= XDONT(IRNGT(IINDB))) CYCLE 404 ! 404 405 405 ! One steps in the C subset, that we build in the final rank array 406 ! 406 407 407 ! Make a copy of the rank array for the merge iteration 408 ! 408 409 409 JWRKT (1:LMTNA) = IRNGT (IWRKD:JINDA) 410 ! 410 411 411 XVALA = XDONT (JWRKT(IINDA)) 412 412 XVALB = XDONT (IRNGT(IINDB)) 413 ! 413 414 414 Do 415 415 IWRK = IWRK + 1 416 ! 416 417 417 ! We still have unprocessed values in both A and B 418 ! 418 419 419 If (XVALA > XVALB) Then 420 420 IRNGT (IWRK) = IRNGT (IINDB) … … 432 432 XVALA = XDONT (JWRKT(IINDA)) 433 433 End If 434 ! 434 435 435 End Do 436 436 End Do 437 ! 437 438 438 ! The Cs become As and Bs 439 ! 439 440 440 LMTNA = 2 * LMTNA 441 441 End Do 442 ! 442 443 443 Return 444 ! 444 445 445 End Subroutine R_mrgrnk 446 446 Subroutine I_mrgrnk (XDONT, IRNGT) … … 455 455 ! __________________________________________________________ 456 456 Integer :: XVALA, XVALB 457 ! 457 458 458 Integer, Dimension (SIZE(IRNGT)) :: JWRKT 459 459 Integer :: LMTNA, LMTNC, IRNG1, IRNG2 460 460 Integer :: NVAL, IIND, IWRKD, IWRK, IWRKF, JINDA, IINDA, IINDB 461 ! 461 462 462 NVAL = Min (SIZE(XDONT), SIZE(IRNGT)) 463 463 Select Case (NVAL) … … 470 470 Continue 471 471 End Select 472 ! 472 473 473 ! Fill-in the index array, creating ordered couples 474 ! 474 475 475 Do IIND = 2, NVAL, 2 476 476 If (XDONT(IIND-1) <= XDONT(IIND)) Then … … 485 485 IRNGT (NVAL) = NVAL 486 486 End If 487 ! 487 488 488 ! We will now have ordered subsets A - B - A - B - ... 489 489 ! and merge A and B couples into C - C - ... 490 ! 490 491 491 LMTNA = 2 492 492 LMTNC = 4 493 ! 493 494 494 ! First iteration. The length of the ordered subsets goes from 2 to 4 495 ! 495 496 496 Do 497 497 If (NVAL <= 2) Exit 498 ! 498 499 499 ! Loop on merges of A and B into C 500 ! 500 501 501 Do IWRKD = 0, NVAL - 1, 4 502 502 If ((IWRKD+4) > NVAL) Then 503 503 If ((IWRKD+2) >= NVAL) Exit 504 ! 504 505 505 ! 1 2 3 506 ! 506 507 507 If (XDONT(IRNGT(IWRKD+2)) <= XDONT(IRNGT(IWRKD+3))) Exit 508 ! 508 509 509 ! 1 3 2 510 ! 510 511 511 If (XDONT(IRNGT(IWRKD+1)) <= XDONT(IRNGT(IWRKD+3))) Then 512 512 IRNG2 = IRNGT (IWRKD+2) 513 513 IRNGT (IWRKD+2) = IRNGT (IWRKD+3) 514 514 IRNGT (IWRKD+3) = IRNG2 515 ! 515 516 516 ! 3 1 2 517 ! 517 518 518 Else 519 519 IRNG1 = IRNGT (IWRKD+1) … … 524 524 Exit 525 525 End If 526 ! 526 527 527 ! 1 2 3 4 528 ! 528 529 529 If (XDONT(IRNGT(IWRKD+2)) <= XDONT(IRNGT(IWRKD+3))) Cycle 530 ! 530 531 531 ! 1 3 x x 532 ! 532 533 533 If (XDONT(IRNGT(IWRKD+1)) <= XDONT(IRNGT(IWRKD+3))) Then 534 534 IRNG2 = IRNGT (IWRKD+2) … … 542 542 IRNGT (IWRKD+4) = IRNG2 543 543 End If 544 ! 544 545 545 ! 3 x x x 546 ! 546 547 547 Else 548 548 IRNG1 = IRNGT (IWRKD+1) … … 567 567 End If 568 568 End Do 569 ! 569 570 570 ! The Cs become As and Bs 571 ! 571 572 572 LMTNA = 4 573 573 Exit 574 574 End Do 575 ! 575 576 576 ! Iteration loop. Each time, the length of the ordered subsets 577 577 ! is doubled. 578 ! 578 579 579 Do 580 580 If (LMTNA >= NVAL) Exit 581 581 IWRKF = 0 582 582 LMTNC = 2 * LMTNC 583 ! 583 584 584 ! Loop on merges of A and B into C 585 ! 585 586 586 Do 587 587 IWRK = IWRKF … … 595 595 IINDA = 1 596 596 IINDB = JINDA + 1 597 ! 597 598 598 ! Shortcut for the case when the max of A is smaller 599 599 ! than the min of B. This line may be activated when the 600 600 ! initial set is already close to sorted. 601 ! 601 602 602 ! IF (XDONT(IRNGT(JINDA)) <= XDONT(IRNGT(IINDB))) CYCLE 603 ! 603 604 604 ! One steps in the C subset, that we build in the final rank array 605 ! 605 606 606 ! Make a copy of the rank array for the merge iteration 607 ! 607 608 608 JWRKT (1:LMTNA) = IRNGT (IWRKD:JINDA) 609 ! 609 610 610 XVALA = XDONT (JWRKT(IINDA)) 611 611 XVALB = XDONT (IRNGT(IINDB)) 612 ! 612 613 613 Do 614 614 IWRK = IWRK + 1 615 ! 615 616 616 ! We still have unprocessed values in both A and B 617 ! 617 618 618 If (XVALA > XVALB) Then 619 619 IRNGT (IWRK) = IRNGT (IINDB) … … 631 631 XVALA = XDONT (JWRKT(IINDA)) 632 632 End If 633 ! 633 634 634 End Do 635 635 End Do 636 ! 636 637 637 ! The Cs become As and Bs 638 ! 638 639 639 LMTNA = 2 * LMTNA 640 640 End Do 641 ! 641 642 642 Return 643 ! 643 644 644 End Subroutine I_mrgrnk 645 645 end module m_mrgrnk
Note: See TracChangeset
for help on using the changeset viewer.