- Timestamp:
- 2011-03-04T12:04:28+01:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/nemogcm.F90
r2647 r2651 502 502 !! ** Method : 503 503 !!---------------------------------------------------------------------- 504 USE par_oce505 504 INTEGER, INTENT(in) :: num_pes ! The number of MPI processes we have 506 ! Local variables505 ! 507 506 INTEGER, PARAMETER :: nfactmax = 20 508 507 INTEGER :: nfact ! The no. of factors returned 509 508 INTEGER :: ierr ! Error flag 510 INTEGER :: i509 INTEGER :: ji 511 510 INTEGER :: idiff, mindiff, imin ! For choosing pair of factors that are closest in value 512 511 INTEGER, DIMENSION(nfactmax) :: ifact ! Array of factors … … 526 525 mindiff = 1000000 527 526 imin = 1 528 DO i=1,nfact-1,2529 idiff = ABS( ifact(i) - ifact(i+1))530 IF( idiff < mindiff)THEN527 DO ji = 1, nfact-1, 2 528 idiff = ABS( ifact(ji) - ifact(ji+1) ) 529 IF( idiff < mindiff ) THEN 531 530 mindiff = idiff 532 imin = i533 END 531 imin = ji 532 ENDIF 534 533 END DO 535 534 jpnj = ifact(imin) … … 543 542 544 543 545 SUBROUTINE factorise( ifax, maxfax, nfax, n, ierr )544 SUBROUTINE factorise( kfax, kmaxfax, knfax, kn, kerr ) 546 545 !!---------------------------------------------------------------------- 547 546 !! *** ROUTINE factorise *** 548 547 !! 549 548 !! ** Purpose : return the prime factors of n. 550 !! nfax factors are returned in array ifax which is of551 !! maximum dimension maxfax.549 !! knfax factors are returned in array kfax which is of 550 !! maximum dimension kmaxfax. 552 551 !! ** Method : 553 552 !!---------------------------------------------------------------------- 554 INTEGER , INTENT(in) :: n,maxfax555 INTEGER , INTENT(Out) :: ierr,nfax556 INTEGER, INTENT(out) :: ifax(maxfax)557 ! Local variables.558 INTEGER :: i , ifac, l,nu553 INTEGER , INTENT(in ) :: kn, kmaxfax 554 INTEGER , INTENT( out) :: kerr, knfax 555 INTEGER, DIMENSION(kmaxfax), INTENT( out) :: kfax 556 ! 557 INTEGER :: ifac, jl, inu 559 558 INTEGER, PARAMETER :: ntest = 14 560 INTEGER :: lfax(ntest)559 INTEGER :: ilfax(ntest) 561 560 562 561 ! lfax contains the set of allowed factors. 563 data ( lfax(i),i=1,ntest) / 16384, 8192, 4096, 2048, 1024, 512, 256, &564 & 128, 64, 32, 16, 8, 4, 2 /562 data (ilfax(jl),jl=1,ntest) / 16384, 8192, 4096, 2048, 1024, 512, 256, & 563 & 128, 64, 32, 16, 8, 4, 2 / 565 564 !!---------------------------------------------------------------------- 566 565 567 566 ! Clear the error flag and initialise output vars 568 ierr = 0569 ifax = 1570 nfax = 0567 kerr = 0 568 kfax = 1 569 knfax = 0 571 570 572 571 ! Find the factors of n. 573 IF( n == 1 )GOTO 20572 IF( kn == 1 ) GOTO 20 574 573 575 574 ! nu holds the unfactorised part of the number. 576 ! nfax holds the number of factors found.575 ! knfax holds the number of factors found. 577 576 ! l points to the allowed factor list. 578 577 ! ifac holds the current factor. 579 578 580 nu =n581 nfax = 0582 583 DO l = ntest, 1, -1579 inu = kn 580 knfax = 0 581 582 DO jl = ntest, 1, -1 584 583 ! 585 ifac = lfax(l)586 IF( ifac > nu)CYCLE584 ifac = ilfax(jl) 585 IF( ifac > inu ) CYCLE 587 586 588 587 ! Test whether the factor will divide. 589 588 590 IF( MOD( nu,ifac) == 0 ) THEN589 IF( MOD(inu,ifac) == 0 ) THEN 591 590 ! 592 nfax = nfax+1 ! Add the factor to the list593 IF( nfax >maxfax ) THEN594 ierr = 6595 write (*,*) 'FACTOR: insufficient space in factor array ', nfax591 knfax = knfax + 1 ! Add the factor to the list 592 IF( knfax > kmaxfax ) THEN 593 kerr = 6 594 write (*,*) 'FACTOR: insufficient space in factor array ', knfax 596 595 return 597 596 ENDIF 598 ifax(nfax) = ifac597 kfax(knfax) = ifac 599 598 ! Store the other factor that goes with this one 600 nfax = nfax + 1 601 ifax(nfax) = nu / ifac 602 !WRITE (*,*) 'ARPDBG, factors ',nfax-1,' & ',nfax,' are ', & 603 ! ifax(nfax-1),' and ',ifax(nfax) 599 knfax = knfax + 1 600 kfax(knfax) = inu / ifac 601 !WRITE (*,*) 'ARPDBG, factors ',knfax-1,' & ',knfax,' are ', kfax(knfax-1),' and ',kfax(knfax) 604 602 ENDIF 605 603 ! … … 608 606 20 CONTINUE ! Label 20 is the exit point from the factor search loop. 609 607 ! 610 RETURN611 !612 608 END SUBROUTINE factorise 613 609
Note: See TracChangeset
for help on using the changeset viewer.