New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
Changeset 3837 for branches/2011/DEV_r2739_STFC_dCSE/NEMOGCM/NEMO/OPA_SRC/LBC/exchmod.F90 – NEMO

Ignore:
Timestamp:
2013-03-12T15:55:32+01:00 (11 years ago)
Author:
trackstand2
Message:

Merge of finiss

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2011/DEV_r2739_STFC_dCSE/NEMOGCM/NEMO/OPA_SRC/LBC/exchmod.F90

    r3432 r3837  
    1111  ! Make some key parameters from mapcomm_mod available to all who  
    1212  ! USE this module 
    13   USE mapcomm_mod, ONLY: Iminus, Iplus, Jminus, Jplus, NONE 
     13  USE mapcomm_mod, ONLY: Iminus, Iplus, Jminus, Jplus, NONE, & 
     14                         jeub 
    1415  IMPLICIT none 
    1516 
     
    6364  INTEGER, DIMENSION(:), ALLOCATABLE, SAVE :: nrank_north  ! dim. ndim_rank_north, number 
    6465                                                           ! of the procs belonging to ncomm_north 
     66  LOGICAL, SAVE :: do_nfold ! Whether this PE contributes to N-fold exchange 
     67                            !  -  takes domain trimming into account. 
    6568  INTEGER, PARAMETER :: num_nfold_rows = 4 ! No. of rows at the top of the  
    6669                                           ! global domain to use in applying  
    6770                                           ! the north-fold condition (no value 
    68                                            ! other than 4 currently supported) 
     71                                           ! other than 4 currently tested) 
     72 
     73  INTEGER, DIMENSION(:), ALLOCATABLE, SAVE :: nfold_npts ! How many points each 
     74                                                         ! northern proc contrib 
     75                                                         ! to nfold exchange 
    6976 
    7077!FTRANS r3dptr :I :I :z 
     
    112119         nrank_north, north_root, ndim_rank_north, & 
    113120         ngrp_north, ngrp_world, ncomm_north, & 
     121         num_nfold_rows, do_nfold, nfold_npts, & 
    114122         exchmod_alloc, add_exch, bound_exch_list, & 
    115          Iminus, Iplus, Jminus, Jplus, NONE, num_nfold_rows, & 
    116          lbc_exch3, lbc_exch2, & !lbc_exch3i, lbc_exch2i, & 
    117          MPI_COMM_WORLD, MPI_Wtime 
     123         Iminus, Iplus, Jminus, Jplus, NONE, & 
     124         lbc_exch3, lbc_exch2 
     125 
     126#if defined key_mpp_mpi 
     127  PUBLIC MPI_COMM_WORLD, MPI_Wtime 
     128#endif 
    118129 
    119130  ! MPI only 
     
    285296 
    286297  SUBROUTINE bound_exch_generic ( b2, ib2, b3, ib3, nhalo, nhexch, & 
    287        comm1, comm2, comm3, comm4,      & 
    288        cd_type, lfill, isgn, lzero ) 
     298                                  comm1, comm2, comm3, comm4,      & 
     299                                  cd_type, lfill, pval, isgn, lzero ) 
    289300    USE par_oce, ONLY: wp, jpreci, jprecj, jpim1 
    290301    USE dom_oce, ONLY: nlci, nlcj, nldi, nlei, nldj, nlej, & 
    291          nperio, nbondi, npolj 
     302                       nperio, nbondi, npolj, narea 
    292303    USE mapcomm_mod, ONLY: Iminus, Iplus, NONE, ilbext, iubext, cyclic_bc 
     304    USE mapcomm_mod, ONLY: trimmed, eidx, widx 
    293305    IMPLICIT none 
    294306    INTEGER, INTENT(in)  :: nhalo,nhexch 
     
    302314    CHARACTER(len=1),  INTENT(in) :: cd_type 
    303315    LOGICAL, OPTIONAL, INTENT(in) :: lfill 
     316    REAL(wp),OPTIONAL, INTENT(in) :: pval  ! background value (used at closed boundaries) 
    304317    INTEGER, OPTIONAL, INTENT(in) :: isgn 
    305     LOGICAL, OPTIONAL, INTENT(in) :: lzero ! Whether to zero halos on closed boundaries 
     318    LOGICAL, OPTIONAL, INTENT(in) :: lzero ! Whether to set halo values on closed boundaries 
    306319    ! Local arguments 
    307320    INTEGER :: itag          ! Communication handle 
     
    310323    INTEGER :: ileft, iright ! First and last x-coord of internal points 
    311324    INTEGER :: kdim1 
     325    INTEGER  :: iland ! Land values - zero by default unless pval passed in. 
     326    REAL(wp) :: zland !  "     " 
    312327    LOGICAL :: lfillarg, lzeroarg 
    313328    !!-------------------------------------------------------------------- 
     
    324339    lfillarg = .FALSE. 
    325340    isgnarg = 1 
     341    zland = 0.0_wp 
    326342 
    327343    IF( PRESENT(lfill) ) lfillarg = lfill 
    328344    IF( PRESENT(isgn)  ) isgnarg  = isgn 
    329345    IF( PRESENT(lzero) ) lzeroarg = lzero 
     346    IF( PRESENT(pval)  ) zland    = pval  
     347    iland=INT(zland) 
    330348 
    331349    ! Find out the size of 3rd dimension of the array 
     
    356374       ! have cyclic E-W boundary conditions. 
    357375       ileft = nldi 
    358        IF(ilbext .AND. cyclic_bc)ileft = ileft + 1 
     376       IF( (ilbext .AND. (.NOT. trimmed(widx,narea))) .AND. cyclic_bc) & 
     377                                                     ileft = ileft + 1 
    359378 
    360379       iright = nlei 
    361        IF(iubext .AND. cyclic_bc)iright = iright - 1 
     380       IF( (iubext .AND. (.NOT. trimmed(eidx,narea))) .AND. cyclic_bc) & 
     381                                                    iright = iright - 1 
    362382 
    363383       IF ( PRESENT(b2) ) THEN 
     
    527547       END IF 
    528548 
    529     ELSE ! lfillarg is .FALSE. 
     549    ELSE ! lfillarg is .FALSE. - standard closed or cyclic treatment 
    530550 
    531551       !                                        ! East-West boundaries 
    532552       !                                        ! ==================== 
     553       !   nbondi == 2 when a single sub-domain spans the whole width 
     554       !   of the global domain 
    533555       IF( nbondi == 2 .AND.   &      ! Cyclic east-west 
    534556            &    (nperio == 1 .OR. nperio == 4 .OR. nperio == 6) ) THEN 
     
    568590                SELECT CASE ( cd_type ) 
    569591                CASE ( 'T', 'U', 'V', 'W' , 'I' ) 
    570                    b2(1:jpreci         , :) = 0._wp ! Western halo 
    571                    b2(nlci-jpreci+1:jpi, :) = 0._wp ! Eastern halo 
     592                   b2(1:jpreci         , :) = zland ! Western halo 
     593                   b2(nlci-jpreci+1:jpi, :) = zland ! Eastern halo 
    572594                CASE ( 'F' ) 
    573                    b2(nlci-jpreci+1:jpi, :) = 0._wp ! Eastern halo 
     595                   b2(nlci-jpreci+1:jpi, :) = zland ! Eastern halo 
    574596                END SELECT 
    575597             ELSE IF ( PRESENT(ib2) ) THEN 
    576598                SELECT CASE ( cd_type ) 
    577599                CASE ( 'T', 'U', 'V', 'W' , 'I' ) 
    578                    ib2(1:jpreci         , :) = 0 ! Western halo 
    579                    ib2(nlci-jpreci+1:jpi, :) = 0 ! Eastern halo 
     600                   ib2(1:jpreci         , :) = iland ! Western halo 
     601                   ib2(nlci-jpreci+1:jpi, :) = iland ! Eastern halo 
    580602                CASE ( 'F' ) 
    581                    ib2(nlci-jpreci+1:jpi, :) = 0 ! Eastern halo 
     603                   ib2(nlci-jpreci+1:jpi, :) = iland ! Eastern halo 
    582604                END SELECT 
    583605             ELSE IF ( PRESENT(b3) ) THEN 
     
    588610                      DO ji=1,jpreci,1 
    589611                         DO jk=1,jpk,1 
    590                             b3(ji, jj, jk) = 0._wp 
     612                            b3(ji, jj, jk) = zland 
    591613                         END DO 
    592614                      END DO 
    593615                      DO ji=nlci-jpreci+1,jpi,1 
    594616                         DO jk=1,jpk,1 
    595                             b3(ji, jj, jk) = 0._wp 
     617                            b3(ji, jj, jk) = zland 
    596618                         END DO 
    597619                      END DO 
    598620                   END DO 
    599621#else 
    600                    b3(1:jpreci         , :, :) = 0._wp 
    601                    b3(nlci-jpreci+1:jpi, :, :) = 0._wp 
     622                   b3(1:jpreci         , :, :) = zland 
     623                   b3(nlci-jpreci+1:jpi, :, :) = zland 
    602624#endif 
    603625                CASE ( 'F' ) 
     
    606628                      DO ji = nlci-jpreci+1,jpi,1 
    607629                         DO jk = 1,jpk,1 
    608                             b3(ji, jj, jk) = 0._wp 
     630                            b3(ji, jj, jk) = zland 
    609631                         END DO 
    610632                      END DO 
    611633                   END DO 
    612634#else 
    613                    b3(nlci-jpreci+1:jpi, :, :) = 0._wp 
     635                   b3(nlci-jpreci+1:jpi, :, :) = zland 
    614636#endif 
    615637                END SELECT 
     
    617639                SELECT CASE ( cd_type ) 
    618640                CASE ( 'T', 'U', 'V', 'W' ) 
    619                    ib3(1:jpreci         , :, :) = 0 
    620                    ib3(nlci-jpreci+1:jpi, :, :) = 0 
     641                   ib3(1:jpreci         , :, :) = iland 
     642                   ib3(nlci-jpreci+1:jpi, :, :) = iland 
    621643                CASE ( 'F' ) 
    622                    ib3(nlci-jpreci+1:jpi, :, :) = 0 
     644                   ib3(nlci-jpreci+1:jpi, :, :) = iland 
    623645                END SELECT 
    624646             END IF 
     
    630652       IF( lzeroarg )THEN 
    631653 
    632           !                                        ! North-South boundaries 
    633           !                                        ! ====================== 
     654          !                             ! North-South boundaries (always closed) 
     655          !                             ! ====================== 
    634656          IF ( PRESENT(b2) ) THEN 
    635657             SELECT CASE ( cd_type ) 
    636658             CASE ( 'T', 'U', 'V', 'W' , 'I' ) 
    637                 b2(:,1:nldj-1         ) = 0._wp 
    638                 b2(:,nlcj-jprecj+1:jpj) = 0._wp 
     659                !b2(:,1:nldj-1         ) = zland 
     660                ! Below is what is done in original lib_mpp.F90 
     661                b2(:,1:jprecj         ) = zland 
     662                b2(:,nlcj-jprecj+1:jpj) = zland 
    639663             CASE ( 'F' ) 
    640                 b2(:,nlcj-jprecj+1:jpj) = 0._wp 
     664                b2(:,nlcj-jprecj+1:jpj) = zland 
    641665             END SELECT 
    642666          ELSE IF ( PRESENT(ib2) ) THEN 
    643667             SELECT CASE ( cd_type ) 
    644668             CASE ( 'T', 'U', 'V', 'W' , 'I' ) 
    645                 ib2(:,1:jprecj         ) = 0 
    646                 ib2(:,nlcj-jprecj+1:jpj) = 0 
     669                ib2(:,1:jprecj         ) = iland 
     670                ib2(:,nlcj-jprecj+1:jpj) = iland 
    647671             CASE ( 'F' ) 
    648                 ib2(:,nlcj-jprecj+1:jpj) = 0 
     672                ib2(:,nlcj-jprecj+1:jpj) = iland 
    649673             END SELECT 
    650674          ELSE IF ( PRESENT(b3) ) THEN 
     
    652676             CASE ( 'T', 'U', 'V', 'W' ) 
    653677#if defined key_z_first 
    654                 DO jj=1,nldj-1,1 
     678                DO jj=1,jprecj,1 
    655679                   DO ji=1,jpi,1 
    656680                      DO jk = 1,jpk,1 
    657                          b3(ji, jj, jk) = 0._wp 
     681                         b3(ji, jj, jk) = zland 
    658682                      END DO 
    659683                   END DO 
     
    662686                   DO ji=1,jpi,1 
    663687                      DO jk = 1,jpk,1 
    664                          b3(ji, jj, jk) = 0._wp 
     688                         b3(ji, jj, jk) = zland 
    665689                      END DO 
    666690                   END DO 
    667691                END DO 
    668692#else 
    669                 b3(:, 1:nldj-1         , :) = 0._wp 
    670                 b3(:, nlcj-jprecj+1:jpj, :) = 0._wp 
     693                b3(:, 1:jprecj         , :) = zland 
     694                b3(:, nlcj-jprecj+1:jpj, :) = zland 
    671695#endif 
    672696             CASE ( 'F' ) 
     
    675699                   DO ji=1,jpi,1 
    676700                      DO jk = 1,jpk,1 
    677                          b3(ji, jj, jk) = 0._wp 
     701                         b3(ji, jj, jk) = zland 
    678702                      END DO 
    679703                   END DO 
    680704                END DO 
    681705#else 
    682                 b3(:, nlcj-jprecj+1:jpj, :) = 0._wp 
     706                b3(:, nlcj-jprecj+1:jpj, :) = zland 
    683707#endif 
    684708             END SELECT 
     
    686710             SELECT CASE ( cd_type ) 
    687711             CASE ( 'T', 'U', 'V', 'W' ) 
    688                 ib3(:, 1:jprecj         , :) = 0 
    689                 ib3(:, nlcj-jprecj+1:jpj, :) = 0 
     712                ib3(:, 1:jprecj         , :) = iland 
     713                ib3(:, nlcj-jprecj+1:jpj, :) = iland 
    690714             CASE ( 'F' ) 
    691                 ib3(:, nlcj-jprecj+1:jpj, :) = 0 
     715                ib3(:, nlcj-jprecj+1:jpj, :) = iland 
    692716             END SELECT 
    693717          END IF 
     
    726750       ! We only need to repeat the East and West halo swap if there 
    727751       ! IS a north-fold in the configuration. 
    728        SELECT CASE (npolj) 
    729  
    730        CASE ( 3, 4, 5, 6 ) 
    731  
    732           ! Update East and West halos as required 
     752       !SELECT CASE (npolj) 
     753 
     754       !CASE ( 3, 4, 5, 6 ) 
     755       IF(ndim_rank_north > 0)THEN 
     756 
     757          ! Update East and West halos as required - no data sent north 
     758          ! as it's only the northern-most PEs that have been affected  
     759          ! by the north-fold condition. 
    733760          ! ARPDBG - inefficient since all PEs do halo swap and only  
    734761          ! those affected by the north fold actually need to - can  
    735762          ! this be done within apply_north_fold? 
    736763          CALL exchs_generic (b2=b2,ib2=ib2,b3=b3,ib3=ib3, nhalo=nhalo, & 
    737                nhexch=nhexch, handle=itag,               & 
    738                comm1=Iplus,comm2=Iminus,comm3=NONE,comm4=NONE, & 
    739                cd_type=cd_type, lfill=lfillarg) 
     764                              nhexch=nhexch, handle=itag,               & 
     765                              comm1=Iplus,comm2=Iminus,comm3=Jplus,comm4=Jminus, & 
     766                              cd_type=cd_type, lfill=lfillarg) 
    740767 
    741768          !CALL exchr_generic (b2=b2,ib2=ib2,b3=b3,ib3=ib3,nhalo=nhalo, & 
     
    743770          !                    comm1=Iplus,comm2=Iminus,comm3=NONE,comm4=NONE) 
    744771          !                           comm1=comm1,comm2=comm2,comm3=comm3,comm4=comm4 ) 
    745        END SELECT    ! npolj  
     772       END IF        ! ndim_rank_north > 0 
     773       !END SELECT    ! npolj  
    746774 
    747775    END IF 
     
    11601188 
    11611189       DO ifield = 1, nfields, 1 
    1162           IF( npolj /= 0 )THEN ! only for northern procs. 
     1190          IF( npolj /= 0 .AND. do_nfold )THEN ! only for northern procs. 
    11631191 
    11641192             IF(ASSOCIATED(list(ifield)%r2dptr))THEN 
     
    11801208       END DO 
    11811209 
    1182 !!$       IF( npolj /= 0 ) CALL mpp_lbc_north_list( list, nfields ) ! only for northern procs. 
     1210!!$       IF( npolj /= 0 .AND. do_nfold ) CALL mpp_lbc_north_list( list, nfields ) ! only for northern procs. 
    11831211 
    11841212    END SELECT   ! jpni 
     
    19431971 
    19441972    CASE DEFAULT   ! more than 1 proc along I 
    1945        IF( npolj /= 0 CALL mpp_lbc_north( b2, cd_type, psgn )   ! only for northern procs. 
     1973       IF( npolj /= 0 .AND. do_nfold ) CALL mpp_lbc_north( b2, cd_type, psgn )   ! only for northern procs. 
    19461974 
    19471975    END SELECT   ! jpni 
     
    20742102 
    20752103    CASE DEFAULT   ! more than 1 proc along I 
    2076        IF( npolj /= 0 CALL mpp_lbc_north( ib2, cd_type, isgn )   ! only for northern procs. 
     2104       IF( npolj /= 0 .AND. do_nfold) CALL mpp_lbc_north( ib2, cd_type, isgn )   ! only for northern procs. 
    20772105 
    20782106    END SELECT   ! jpni 
     
    22852313 
    22862314    CASE DEFAULT ! more than 1 proc along I 
    2287        IF ( npolj /= 0 ) CALL mpp_lbc_north (b3, cd_type, psgn) ! only for northern procs. 
     2315       IF ( npolj /= 0 .AND. do_nfold) CALL mpp_lbc_north (b3, cd_type, psgn) ! only for northern procs. 
    22882316 
    22892317    END SELECT ! jpni  
     
    24932521 
    24942522    CASE DEFAULT ! more than 1 proc along I 
    2495        IF ( npolj /= 0 ) CALL mpp_lbc_north ( ib3, cd_type, isgn) ! only for northern procs. 
     2523       IF ( npolj /= 0 .AND. do_nfold) CALL mpp_lbc_north ( ib3, cd_type, isgn) ! only for northern procs. 
    24962524 
    24972525    END SELECT ! jpni  
     
    25572585    ELSE 
    25582586       ! This section is both for error checking and allows me to be lazy in the  
    2559        ! testing code - I don't have to check which arrays I've been passed. 
     2587       ! testing code - I don't have to check which arrays I've been passed  
     2588       ! before I call this routine. 
    25602589       WRITE (*,*) 'WARNING: add_exch called without a ptr to an array - will be ignored' 
    25612590       RETURN 
     
    25882617   SUBROUTINE bound_exch2 (b, nhalo, nhexch,           & 
    25892618                           comm1, comm2, comm3, comm4, & 
    2590                            cd_type, lfill, isgn, lzero ) 
     2619                           cd_type, lfill, pval, isgn, lzero ) 
    25912620      !!---------------------------------------------------------------------- 
    25922621      !!---------------------------------------------------------------------- 
     
    26002629      INTEGER, OPTIONAL, INTENT(in) :: isgn 
    26012630      LOGICAL, OPTIONAL, INTENT(in) :: lzero 
     2631      REAL(wp),OPTIONAL, INTENT(in) :: pval 
    26022632 
    26032633      CALL bound_exch_generic( b2=b,nhalo=nhalo,nhexch=nhexch, & 
    26042634              comm1=comm1,comm2=comm2,comm3=comm3,comm4=comm4, & 
    2605               cd_type=cd_type, lfill=lfill, isgn=isgn, lzero=lzero ) 
     2635              cd_type=cd_type, lfill=lfill, pval=pval,         & 
     2636              isgn=isgn, lzero=lzero ) 
    26062637      RETURN 
    26072638   END SUBROUTINE bound_exch2 
     
    26092640 
    26102641   SUBROUTINE bound_exch2i (b, nhalo, nhexch, comm1, comm2, comm3, comm4, & 
    2611                             cd_type, lfill, isgn, lzero ) 
     2642                            cd_type, lfill, pval, isgn, lzero ) 
    26122643      !!---------------------------------------------------------------------- 
    26132644      !!---------------------------------------------------------------------- 
     
    26212652      INTEGER, OPTIONAL, INTENT(in) :: isgn 
    26222653      LOGICAL, OPTIONAL, INTENT(in) :: lzero 
     2654      REAL(wp),OPTIONAL, INTENT(in) :: pval 
    26232655 
    26242656      CALL bound_exch_generic (ib2=b,nhalo=nhalo,nhexch=nhexch,           & 
    26252657                         comm1=comm1,comm2=comm2,comm3=comm3,comm4=comm4, & 
    2626                          cd_type=cd_type, lfill=lfill, isgn=isgn, lzero=lzero ) 
     2658                         cd_type=cd_type, lfill=lfill, pval=pval,         & 
     2659                         isgn=isgn, lzero=lzero ) 
    26272660      RETURN 
    26282661   END SUBROUTINE bound_exch2i 
     
    26302663 
    26312664   SUBROUTINE bound_exch3 (b, nhalo, nhexch, comm1, comm2, comm3, & 
    2632                           comm4, cd_type, lfill, isgn, lzero) 
     2665                          comm4, cd_type, lfill, pval, isgn, lzero) 
    26332666      !!---------------------------------------------------------------------- 
    26342667      !!---------------------------------------------------------------------- 
     
    26422675      INTEGER, OPTIONAL, INTENT(in) :: isgn 
    26432676      LOGICAL, OPTIONAL, INTENT(in) :: lzero 
     2677      REAL(wp),OPTIONAL, INTENT(in) :: pval 
    26442678 
    26452679      CALL bound_exch_generic ( b3=b,nhalo=nhalo,nhexch=nhexch,& 
    26462680              comm1=comm1,comm2=comm2,comm3=comm3,comm4=comm4, & 
    2647               cd_type=cd_type, lfill=lfill, isgn=isgn, lzero=lzero ) 
     2681              cd_type=cd_type, lfill=lfill, pval=pval,         & 
     2682              isgn=isgn, lzero=lzero ) 
    26482683      RETURN 
    26492684   END SUBROUTINE bound_exch3 
     
    26512686 
    26522687   SUBROUTINE bound_exch3i (b, nhalo, nhexch, comm1, comm2, comm3, & 
    2653                            comm4, cd_type, lfill, isgn, lzero) 
     2688                           comm4, cd_type, lfill, pval, isgn, lzero) 
    26542689      !!---------------------------------------------------------------------- 
    26552690      !!---------------------------------------------------------------------- 
     
    26622697      INTEGER, OPTIONAL, INTENT(in) :: isgn 
    26632698      LOGICAL, OPTIONAL, INTENT(in) :: lzero 
     2699      REAL(wp),OPTIONAL, INTENT(in) :: pval 
    26642700 
    26652701      CALL bound_exch_generic ( ib3=b,nhalo=nhalo,nhexch=nhexch, & 
    26662702                comm1=comm1,comm2=comm2,comm3=comm3,comm4=comm4, & 
    2667                 cd_type=cd_type, lfill=lfill, isgn=isgn, lzero=lzero ) 
     2703                cd_type=cd_type, lfill=lfill, pval=pval,         & 
     2704                isgn=isgn, lzero=lzero ) 
    26682705 
    26692706   END SUBROUTINE bound_exch3i 
     
    26952732      LOGICAL :: lfill 
    26962733 
    2697       ! ARPDBG - don't know whether pval currently maps into exchmod framework 
    2698       IF(PRESENT(pval))THEN 
    2699          CALL ctl_stop('STOP','lbc_exch2: got pval argument - NOT IMPLEMENTED') 
    2700          RETURN 
    2701       END IF 
    2702  
    27032734      lfill = .FALSE. 
    27042735      IF(PRESENT(cd_mpp))THEN 
     
    27082739      CALL bound_exch_generic( b2=pt2d,nhalo=jpreci,nhexch=jpreci, & 
    27092740            comm1=Iplus,comm2=Iminus,comm3=Jplus,comm4=Jminus, & 
    2710             cd_type=cd_type, lfill=lfill, isgn=INT(psgn), lzero=lzero ) 
     2741            cd_type=cd_type, lfill=lfill, pval=pval, isgn=INT(psgn), & 
     2742            lzero=lzero ) 
    27112743 
    27122744   END SUBROUTINE lbc_exch2 
     
    27312763      LOGICAL :: lfill 
    27322764 
    2733       ! ARPDBG - don't know whether pval currently maps into exchmod framework 
    2734       IF(PRESENT(pval))THEN 
    2735          CALL ctl_stop('STOP','lbc_exch3: got pval argument - NOT IMPLEMENTED') 
    2736          RETURN 
    2737       END IF 
    2738  
    27392765      lfill = .FALSE. 
    27402766      IF(PRESENT(cd_mpp))THEN 
     
    27422768      END IF 
    27432769 
    2744       CALL bound_exch_generic ( b3=ptab3d,nhalo=jpreci,nhexch=jpreci,& 
    2745              comm1=Iplus,comm2=Iminus,comm3=Jplus,comm4=Jminus, & 
    2746              cd_type=cd_type, lfill=lfill, isgn=INT(psgn), lzero=lzero ) 
     2770      CALL bound_exch_generic ( b3=ptab3d,nhalo=jpreci,nhexch=jpreci, & 
     2771             comm1=Iplus,comm2=Iminus,comm3=Jplus,comm4=Jminus,       & 
     2772             cd_type=cd_type, lfill=lfill, pval=pval, isgn=INT(psgn), & 
     2773             lzero=lzero ) 
    27472774 
    27482775   END SUBROUTINE lbc_exch3 
     
    27732800    USE mapcomm_mod, ONLY: Iplus, Jplus, Iminus, Jminus, IplusJplus,       & 
    27742801                           IminusJminus, IplusJminus, IminusJplus,  & 
    2775                            nsend, nxsend, nysend, nxsendp,nysendp,nsendp, & 
     2802                           nsend, nxsend, nysend, nxsendp,nysendp,nzsendp, & 
     2803                           nsendp, & 
    27762804                           destination,dirsend, dirrecv,                  & 
    27772805                           isrcsendp,jsrcsendp, idesrecvp, jdesrecvp,     & 
    2778                            nrecv, nxrecv,nyrecv,nxrecvp,nyrecvp,nrecvp,   & 
     2806                           nrecv,  & 
     2807                           nxrecvp,nyrecvp,nzrecvp, nrecvp, nrecvp2d,  & 
    27792808                           source, iesub, jesub,  & 
    27802809                           MaxCommDir, MaxComm, cyclic_bc,      & 
    27812810                           nrecvp, npatchsend, npatchrecv 
    2782     USE lib_mpp,     ONLY: mpi_comm_opa, ctl_stop 
     2811    USE lib_mpp,     ONLY: ctl_stop 
     2812#if defined key_mpp_mpi 
     2813    USE lib_mpp,     ONLY: mpi_comm_opa 
     2814#endif 
    27832815#if ( defined DEBUG && defined DEBUG_EXCHANGE ) || defined DEBUG_COMMS 
    27842816    USE dom_oce,     ONLY: narea 
     
    27932825 
    27942826    LOGICAL :: enabled(0:MaxCommDir, maxExchItems) 
    2795     INTEGER :: ides, ierr, irecv, isend, & 
    2796                isrc, jdes, jsrc, nxr, nyr,        & 
    2797                nxs, nys, tag, tag_orig,           & 
     2827    INTEGER :: ides, ierr, irecv, isend,        & 
     2828               isrc, jdes, jsrc, tag, tag_orig, & 
    27982829               ibeg, iend, jbeg, jend 
    27992830    INTEGER :: i, j, k, ic, ifield, ipatch ! Loop counters 
     
    28012832    INTEGER :: npacked 
    28022833    INTEGER :: handle 
     2834#if defined key_mpp_mpi 
    28032835    INTEGER :: status(MPI_status_size) 
    28042836    INTEGER :: astatus(MPI_status_size,MaxComm) 
     2837#endif 
    28052838    INTEGER :: r2dcount, r3dcount, i2dcount, i3dcount 
    28062839    ! Indices into int and real copy buffers 
     
    28262859#endif 
    28272860 
    2828     CALL prof_region_begin(ARPEXCHS_LIST, "Exchs_list", iprofStat) 
     2861    !CALL prof_region_begin(ARPEXCHS_LIST, "Exchs_list", iprofStat) 
    28292862 
    28302863    ! Allocate a communications tag/handle and a flags array. 
     
    28412874       ! Check halo width is in range. 
    28422875       IF ( list(ifield)%halo_width.GT.jpreci ) THEN 
    2843           CALL ctl_stop('STOP','exchs: halo width greater than maximum') 
     2876          CALL ctl_stop('STOP', & 
     2877                        'exchs_generic_list: halo width greater than maximum') 
    28442878          RETURN 
    28452879       ENDIF 
     
    28812915    IF( have_real_field )THEN 
    28822916 
    2883        ALLOCATE(recvBuff(jpkdta*maxrecvpts*nfields,nrecv),stat=ierr) 
     2917       ALLOCATE(recvBuff(maxrecvpts*nfields,nrecv),stat=ierr) 
    28842918       !WRITE(*,"('Allocated ',I7,' reals for recv buff')") & 
    28852919       !                                 jpkdta*maxrecvpts*nfields 
     
    28982932    IF( have_int_field .AND. (ierr == 0) )THEN 
    28992933 
    2900        ALLOCATE(recvIBuff(jpkdta*maxrecvpts*nfields,nrecv),stat=ierr) 
     2934       ALLOCATE(recvIBuff(maxrecvpts*nfields,nrecv),stat=ierr) 
    29012935       !WRITE(*,"('Allocated ',I7,' ints for recv buff')") & 
    29022936       !                                 jpkdta*maxrecvpts*nfields 
     
    29272961       i3dcount = 0 
    29282962 
    2929        IF(source(irecv).GE.0 .AND. nrecvp(irecv,1).GT.0 ) THEN 
     2963       IF( source(irecv).GE.0 .AND. & 
     2964           ( (nrecvp(irecv,1) > 0) .OR. (nrecvp2d(irecv,1) > 0) ) ) THEN 
    29302965 
    29312966          ! This loop is to allow for different fields to have different 
     
    29352970             IF ( enabled(dirrecv(irecv), ifield) ) THEN 
    29362971                IF( ASSOCIATED(list(ifield)%r2dptr) )THEN 
    2937                    r2dcount = r2dcount + 1 
     2972                   r2dcount = r2dcount + nrecvp2d(irecv,1) 
    29382973                ELSE IF( ASSOCIATED(list(ifield)%i2dptr) )THEN 
    2939                    i2dcount = i2dcount + 1 
     2974                   i2dcount = i2dcount + nrecvp2d(irecv,1) 
    29402975                ELSE IF( ASSOCIATED(list(ifield)%r3dptr) )THEN 
    29412976                   ! Allow for varying size of third dimension 
    2942                    r3dcount = r3dcount + SIZE(list(ifield)%r3dptr, index_z) 
     2977                   r3dcount = r3dcount + nrecvp(irecv,1) 
    29432978                ELSE IF( ASSOCIATED(list(ifield)%i3dptr) )THEN 
    29442979                   ! Allow for varying size of third dimension 
    2945                    i3dcount = i3dcount + SIZE(list(ifield)%i3dptr, index_z) 
     2980                   i3dcount = i3dcount + nrecvp(irecv,1) 
    29462981                END IF 
    29472982             END IF 
     
    29572992 
    29582993          IF ( r2dcount > 0 .OR. r3dcount > 0 ) THEN 
    2959              CALL MPI_irecv (recvBuff(1,irecv),((r2dcount+r3dcount)*nrecvp(irecv,1)),     & 
     2994             CALL MPI_irecv (recvBuff(1,irecv),(r2dcount+r3dcount),     & 
    29602995                             MPI_DOUBLE_PRECISION, source(irecv), tag, mpi_comm_opa, & 
    29612996                             exch_flags(handle,irecv,indexr), ierr) 
    29622997          END IF 
    29632998          IF ( i2dcount > 0 .OR. i3dcount > 0 ) THEN 
    2964              CALL MPI_irecv (recvIBuff(1,irecv),((i2dcount+i3dcount)*nrecvp(irecv,1)),       & 
     2999             CALL MPI_irecv (recvIBuff(1,irecv),(i2dcount+i3dcount),       & 
    29653000                             MPI_INTEGER, source(irecv),tag, mpi_comm_opa, & 
    29663001                             exch_flags(handle,irecv,indexr),ierr) 
     
    29933028 
    29943029    ierr = 0 
    2995     newSize = jpkdta*maxsendpts*nfields 
     3030    newSize = maxsendpts*nfields 
    29963031    IF( have_real_field .AND. newSize > sendBuffSize)THEN 
    29973032       sendBuffSize=newSize 
     
    30103045 
    30113046    IF (ierr .ne. 0) THEN 
    3012        WRITE(*,*) 'ARPDBG: failed to allocate send buf' 
    30133047       CALL ctl_stop('STOP','exchs_generic_list: unable to allocate send buff') 
    30143048    END IF 
     
    31113145                      DO j=jbeg, jend, 1 
    31123146                         DO i=ibeg, iend, 1 
    3113                             DO k=1, SIZE(list(ifield)%r3dptr, index_z), 1 
    3114 #else 
    3115                       DO k=1, SIZE(list(ifield)%r3dptr, index_z), 1 
     3147                            !DO k=1, SIZE(list(ifield)%r3dptr, index_z), 1 
     3148                            DO k=1, nzsendp(ipatch,isend,1), 1 
     3149#else 
     3150                      !DO k=1, SIZE(list(ifield)%r3dptr, index_z), 1 
     3151                      DO k=1, nzsendp(ipatch,isend,1), 1 
    31163152                         DO j=jbeg, jend, 1 
    31173153                            DO i=ibeg, iend, 1 
     
    31243160                    
    31253161                      npacked =  nxsendp(ipatch,isend,1) * & 
    3126                                  nysendp(ipatch,isend,1) 
    3127                       rstart   = rstart + npacked*SIZE(list(ifield)%r3dptr, index_z) 
    3128                       r3dcount = r3dcount + npacked*SIZE(list(ifield)%r3dptr, index_z) 
     3162                                 nysendp(ipatch,isend,1) * & 
     3163                                 nzsendp(ipatch,isend,1) 
     3164                      rstart   = rstart + npacked 
     3165                      r3dcount = r3dcount + npacked 
     3166 
    31293167                   END DO pack_patches3r 
    31303168 
     
    31433181                      DO j=jbeg, jend, 1 
    31443182                         DO i=ibeg, iend, 1 
    3145                             DO k=1, SIZE(list(ifield)%i3dptr, index_z),1 
    3146 #else 
    3147                       DO k=1, SIZE(list(ifield)%i3dptr, index_z),1 
     3183                            !DO k=1, SIZE(list(ifield)%i3dptr, index_z),1 
     3184                            DO k=1, nzsendp(ipatch,isend,1), 1 
     3185#else 
     3186                      !DO k=1, SIZE(list(ifield)%i3dptr, index_z),1 
     3187                      DO k=1, nzsendp(ipatch,isend,1), 1 
    31483188                         DO j=jbeg, jend, 1 
    31493189                            DO i=ibeg, iend, 1 
     
    31553195                      END DO 
    31563196 
    3157                       istart   = istart +  nxs*nys*SIZE(list(ifield)%i3dptr, index_z) 
    3158                       i3dcount = i3dcount + nxs*nys*SIZE(list(ifield)%i3dptr, index_z) 
     3197                      npacked = nxsendp(ipatch,isend,1)* & 
     3198                                nysendp(ipatch,isend,1)* & 
     3199                                nzsendp(ipatch,isend,1) 
     3200                      istart   = istart +  npacked 
     3201                      i3dcount = i3dcount + npacked 
    31593202                   END DO pack_patches3i 
    31603203 
     
    31723215          ! Now do the send(s) for all fields 
    31733216          IF(r2dcount > 0 .OR. r3dcount > 0 )THEN 
    3174              CALL MPI_Isend(sendBuff(1,isend),(r2dcount+r3dcount),MPI_DOUBLE_PRECISION, & 
    3175                             destination(isend),tag,mpi_comm_opa, & 
     3217             CALL MPI_Isend(sendBuff(1,isend),(r2dcount+r3dcount), & 
     3218                            MPI_DOUBLE_PRECISION,                  & 
     3219                            destination(isend),tag,mpi_comm_opa,   & 
    31763220                            exch_flags(handle,isend,indexs),ierr) 
    31773221          END IF 
     
    32283272 
    32293273                ! Increment starting index for next field data in buffer 
    3230                 rstart = rstart + nrecvp(irecv,1) 
     3274                rstart = ic + 1 !rstart + nrecvp(irecv,1) 
    32313275 
    32323276             ELSE IF ( ASSOCIATED(list(ifield)%i2dptr) ) THEN 
     
    32503294 
    32513295                ! Increment starting index for next field data in buffer 
    3252                 istart = istart + nrecvp(irecv,1) 
     3296                istart = ic + 1 !istart + nrecvp(irecv,1) 
    32533297 
    32543298             ELSE IF (ASSOCIATED(list(ifield)%r3dptr) ) THEN 
     
    32643308                   DO j=jbeg, jend, 1 
    32653309                      DO i=ibeg, iend, 1 
    3266                          DO k=1,SIZE(list(ifield)%r3dptr, index_z), 1 
    3267 #else 
    3268                    DO k=1,  SIZE(list(ifield)%r3dptr, index_z), 1 
     3310                         DO k=1, nzrecvp(ipatch,irecv,1), 1 
     3311#else 
     3312                   DO k=1, nzrecvp(ipatch,irecv,1), 1 
    32693313                      DO j=jbeg, jend, 1 
    32703314                         DO i=ibeg, iend, 1 
     
    32783322 
    32793323                ! Increment starting index for next field data in buffer 
    3280                 rstart = rstart + nrecvp(irecv,1)*SIZE(list(ifield)%r3dptr,index_z) 
     3324                rstart = ic + 1 ! rstart + nrecvp(irecv,1) !*SIZE(list(ifield)%r3dptr,index_z) 
    32813325 
    32823326             ELSE IF ( ASSOCIATED(list(ifield)%i3dptr) ) THEN 
     
    32923336                   DO j=jbeg, jend, 1 
    32933337                      DO i=ibeg, iend, 1 
    3294                          DO k=1,SIZE(list(ifield)%i3dptr,index_z),1 
    3295 #else 
    3296                    DO k=1,SIZE(list(ifield)%i3dptr,index_z),1 
     3338                         DO k=1,nzrecvp(ipatch,irecv,1),1 
     3339#else 
     3340                   DO k=1,nzrecvp(ipatch,irecv,1),1 
    32973341                      DO j=jbeg, jend, 1 
    32983342                         DO i=ibeg, iend, 1 
     
    33063350 
    33073351                ! Increment starting index for next field data in buffer 
    3308                 istart = istart + nrecvp(irecv,1)*SIZE(list(ifield)%i3dptr,index_z) 
     3352                istart = ic + 1 !istart + nrecvp(irecv,1) !*SIZE(list(ifield)%i3dptr,index_z) 
    33093353 
    33103354             END IF 
     
    33953439    CALL free_exch_handle(handle) 
    33963440 
    3397     CALL prof_region_end(ARPEXCHS_LIST, iprofStat) 
     3441    !CALL prof_region_end(ARPEXCHS_LIST, iprofStat) 
    33983442     
    33993443  END SUBROUTINE exchs_generic_list 
     
    34313475    ! ******************************************************************* 
    34323476    USE par_oce,     ONLY: wp, jpreci, jprecj, jpni, jpkdta 
    3433     USE mapcomm_mod, ONLY: Iplus, Jplus, Iminus, Jminus, IplusJplus, & 
    3434                            IminusJminus, IplusJminus, IminusJplus,   & 
    3435                            nrecv, nsend, nrecvp, nsendp, nxsend,nysend,& 
    3436                            destination,dirsend, dirrecv, & 
    3437                            isrcsend, jsrcsend, idesrecv, jdesrecv, & 
    3438                            isrcsendp,jsrcsendp,idesrecvp,jdesrecvp, & 
    3439                            nxrecv,nyrecv,source, iesub, jesub, & 
    3440                            MaxCommDir, MaxComm, idessend, jdessend, & 
    3441                            nxsendp, nysendp, nxrecvp, nyrecvp,      & 
    3442                            npatchsend, npatchrecv, & 
    3443                            cyclic_bc 
    3444     USE lib_mpp,     ONLY: mpi_comm_opa, ctl_stop 
     3477    USE mapcomm_mod, ONLY: Iplus, Jplus, Iminus, Jminus, IplusJplus,   & 
     3478                           IminusJminus, IplusJminus, IminusJplus,     & 
     3479                           nrecv, nsend, nrecvp, nsendp,               & 
     3480                           nrecvp2d, nsendp2d,  nxsend, nysend,        & 
     3481                           destination,dirsend, dirrecv,               & 
     3482                           isrcsend, jsrcsend, idesrecv, jdesrecv,     & 
     3483                           isrcsendp,jsrcsendp,idesrecvp,jdesrecvp,    & 
     3484                           nxrecv,source, iesub, jesub,         & 
     3485                           MaxCommDir, MaxComm, idessend, jdessend,    & 
     3486                           nxsendp, nysendp, nzsendp,                  & 
     3487                           nxrecvp, nyrecvp, nzrecvp,                  & 
     3488                           npatchsend, npatchrecv, cyclic_bc 
     3489    USE lib_mpp,     ONLY: ctl_stop 
     3490#if defined key_mpp_mpi 
     3491    USE lib_mpp,     ONLY: mpi_comm_opa 
     3492#endif 
    34453493    USE dom_oce,     ONLY: narea 
    34463494    USE in_out_manager, ONLY: numout 
     
    34743522    INTEGER :: index  ! To hold index returned from MPI_waitany 
    34753523    INTEGER, DIMENSION(3) :: isubsizes, istarts ! isizes 
     3524#if defined key_mpp_mpi 
    34763525    INTEGER :: status(MPI_status_size) 
    34773526    INTEGER :: astatus(MPI_status_size,MaxComm) 
     3527#endif 
    34783528    LOGICAL, SAVE :: first_time = .TRUE. 
    34793529#if defined key_z_first 
     
    34893539 
    34903540    !CALL prof_region_begin(ARPEXCHS_GENERIC, "Exchs_indiv", iprofStat) 
    3491 !    CALL timing_start('exchs_generic') 
     3541    !CALL timing_start('exchs_generic') 
    34923542 
    34933543    ierr = 0 
    34943544 
    3495     ! Find out the sizes of the arrays. 
    3496  
    3497     kdim1 = 1 
    3498     IF ( PRESENT(b3) ) THEN 
    3499        kdim1 = SIZE(b3,dim=index_z) 
    3500     ELSEIF ( PRESENT(ib3) ) THEN 
    3501        kdim1 = SIZE(ib3,dim=index_z) 
    3502     ELSEIF ( PRESENT(b2) ) THEN 
    3503        kdim1 = SIZE(b2,dim=2) 
    3504     ELSEIF ( PRESENT(ib2) ) THEN 
    3505        kdim1 = SIZE(ib2,dim=2) 
    3506     ENDIF 
    3507  
    35083545    ! Check nhexch is in range. 
    35093546 
    35103547    IF ( nhexch.GT.jpreci ) THEN 
    3511        STOP 'exchs: halo width greater than maximum' 
     3548       CALL ctl_stop('STOP','exchs: halo width greater than maximum') 
    35123549    ENDIF 
    35133550 
     
    35443581       IF(.NOT. ALLOCATED(sendBuff))THEN 
    35453582          ! Only allocate the sendBuff once 
    3546           ALLOCATE(recvBuff(jpkdta*maxrecvpts,nrecv), & 
    3547                    sendBuff(jpkdta*maxsendpts,nsend),stat=ierr) 
     3583          ALLOCATE(recvBuff(maxrecvpts,nrecv), & 
     3584                   sendBuff(maxsendpts,nsend),stat=ierr) 
    35483585       ELSE 
    3549           ALLOCATE(recvBuff(jpkdta*maxrecvpts,nrecv),stat=ierr) 
     3586          ALLOCATE(recvBuff(maxrecvpts,nrecv),stat=ierr) 
    35503587       END IF 
    35513588    ELSE IF(PRESENT(ib2) .OR. PRESENT(ib3))THEN 
    35523589       IF(.NOT. ALLOCATED(sendIBuff))THEN 
    3553           ALLOCATE(recvIBuff(jpkdta*maxrecvpts,nrecv), & 
    3554                    sendIBuff(jpkdta*maxsendpts,nsend),stat=ierr) 
     3590          ALLOCATE(recvIBuff(maxrecvpts,nrecv), & 
     3591                   sendIBuff(maxsendpts,nsend),stat=ierr) 
    35553592       ELSE 
    3556           ALLOCATE(recvIBuff(jpkdta*maxrecvpts,nrecv),stat=ierr) 
     3593          ALLOCATE(recvIBuff(maxrecvpts,nrecv),stat=ierr) 
    35573594       END IF 
    35583595    END IF 
     
    35783615          !          that isn't used 
    35793616          IF ( PRESENT(b2) ) THEN 
    3580              CALL MPI_irecv (recvBuff(1,irecv),nrecvp(irecv,1),  & 
     3617             CALL MPI_irecv (recvBuff(1,irecv),nrecvp2d(irecv,1), & 
    35813618                             MPI_DOUBLE_PRECISION, source(irecv), & 
    35823619                             tag, mpi_comm_opa,                   & 
    35833620                             exch_flags(handle,irecv,indexr), ierr) 
    35843621          ELSEIF ( PRESENT(ib2) ) THEN 
     3622             CALL MPI_irecv (recvIBuff(1,irecv),nrecvp2d(irecv,1), & 
     3623                             MPI_INTEGER, source(irecv),         & 
     3624                             tag, mpi_comm_opa,                  & 
     3625                             exch_flags(handle,irecv,indexr),ierr) 
     3626          ELSEIF ( PRESENT(b3) ) THEN 
     3627             CALL MPI_irecv (recvBuff(1,irecv),nrecvp(irecv,1),   & 
     3628                             MPI_DOUBLE_PRECISION, source(irecv), & 
     3629                             tag, mpi_comm_opa,                   & 
     3630                             exch_flags(handle,irecv,indexr),ierr) 
     3631          ELSEIF ( PRESENT(ib3) ) THEN 
    35853632             CALL MPI_irecv (recvIBuff(1,irecv),nrecvp(irecv,1), & 
    35863633                             MPI_INTEGER, source(irecv),         & 
    35873634                             tag, mpi_comm_opa,                  & 
    35883635                             exch_flags(handle,irecv,indexr),ierr) 
    3589           ELSEIF ( PRESENT(b3) ) THEN 
    3590              CALL MPI_irecv (recvBuff(1,irecv),nrecvp(irecv,1)*kdim1,   & 
    3591                              MPI_DOUBLE_PRECISION, source(irecv), & 
    3592                              tag, mpi_comm_opa,                   & 
    3593                              exch_flags(handle,irecv,indexr),ierr) 
    3594           ELSEIF ( PRESENT(ib3) ) THEN 
    3595              CALL MPI_irecv (recvIBuff(1,irecv),nrecvp(irecv,1)*kdim1, & 
    3596                              MPI_INTEGER, source(irecv),         & 
    3597                              tag, mpi_comm_opa,                  & 
    3598                              exch_flags(handle,irecv,indexr),ierr) 
    35993636          ENDIF 
    3600           IF ( ierr.NE.0 ) THEN 
    3601              WRITE (numout,*) 'ARPDBG - irecv hit error' 
    3602              CALL flush(numout) 
    3603              CALL MPI_abort(mpi_comm_opa,1,ierr) 
    3604           END IF 
     3637          ! No point checking for MPI errors because default MPI error handler 
     3638          ! aborts run without returning control to calling program. 
     3639          !IF ( ierr.NE.0 ) THEN 
     3640          !   WRITE (numout,*) 'ARPDBG - irecv hit error' 
     3641          !   CALL flush(numout) 
     3642          !   CALL MPI_abort(mpi_comm_opa,1,ierr) 
     3643          !END IF 
    36053644 
    36063645#if defined DEBUG_COMMS 
    36073646          WRITE (*,FMT="(I4,': exchs post recv : hand = ',I2,' dirn = ',I1,' src = ',I3,' tag = ',I4,' npoints = ',I6)") & 
    36083647                  narea-1,handle,dirrecv(irecv), & 
    3609                   source(irecv), tag, nrecvp(irecv,1)*kdim1 
     3648                  source(irecv), tag, nrecvp(irecv,1) 
    36103649#endif 
    36113650 
     
    36353674 
    36363675       IF ( enabled(dirsend(isend)) .AND. & 
    3637             destination(isend).GE.0 .AND. nxsend(isend).GT.0 ) THEN 
     3676            destination(isend) >= 0 .AND. nxsend(isend) > 0 ) THEN 
    36383677 
    36393678          isrc = isrcsend(isend) 
     
    36473686          IF(PRESENT(b3))THEN 
    36483687             WRITE (*,FMT="(I4,': handle ',I4,' tag ',I4,' sending to ',I4,' data ',I4,' direction ',I3)") &   
    3649                narea-1, handle, tag, destination(isend),nsendp(isend,1)*kdim1,dirsend(isend) 
     3688               narea-1, handle, tag, destination(isend),nsendp(isend,1),dirsend(isend) 
    36503689          ELSE IF(PRESENT(b2))THEN 
    36513690             WRITE (*,FMT="(I4,': handle ',I4,' tag ',I4,' sending to ',I4,' data ',I4,' direction ',I3)") &   
    3652                narea-1, handle, tag, destination(isend),nsendp(isend,1),dirsend(isend) 
     3691               narea-1, handle, tag, destination(isend),nsendp2d(isend,1),dirsend(isend) 
    36533692          END IF 
    36543693#endif 
     
    36733712                END DO 
    36743713 
     3714!!$                ! For 'stupid' compiler that refuses to do a memcpy for above 
    36753715!!$                CALL do_real8_copy( nxsendp(patch,isend,1)*nysendp(patch,isend,1), & 
    36763716!!$                                    b2(istart,jstart),                             & 
     
    37093749          ELSEIF ( PRESENT(b3) )THEN 
    37103750 
    3711 !            CALL timing_start('3dr_pack') 
     3751             ! CALL timing_start('3dr_pack') 
    37123752             ic = 0 
    37133753             pack_patches3r: DO ipatch=1,npatchsend(isend,1) 
     
    37203760                DO j=jstart, jend, 1 
    37213761                   DO i=istart, iend, 1 
    3722                       DO k=1,kdim1,1 
    3723 #else 
    3724                 DO k=1,kdim1,1 
     3762                      DO k=1,nzsendp(ipatch,isend,1),1 
     3763#else 
     3764                DO k=1,nzsendp(ipatch,isend,1),1 
    37253765                   DO j=jstart, jend, 1 
    37263766                      DO i=istart, iend, 1 
     
    37323772                END DO 
    37333773             END DO pack_patches3r 
    3734 !             CALL timing_stop('3dr_pack') 
     3774 
     3775             ! CALL timing_stop('3dr_pack') 
    37353776 
    37363777             CALL MPI_Isend(sendBuff(1,isend),ic,                  & 
     
    37403781 
    37413782#if defined DEBUG_COMMS 
    3742           WRITE (*,FMT="(I4,': Isend of ',I3,' patches, ',I6,' points, to ',I3)") & 
     3783             WRITE (*,FMT="(I4,': Isend of ',I3,' patches, ',I6,' points, to ',I3)") & 
    37433784                     narea-1, npatchsend(isend,1),ic, & 
    37443785                     destination(isend) 
     
    37563797                 DO j=jstart, jend, 1 
    37573798                    DO i=istart, iend, 1 
    3758                        DO k=1,kdim1,1 
    3759 #else 
    3760                  DO k=1,kdim1,1 
     3799                       DO k=1,nzsendp(ipatch,isend,1),1 
     3800#else 
     3801                 DO k=1,nzsendp(ipatch,isend,1),1 
    37613802                    DO j=jstart, jend, 1 
    37623803                       DO i=istart, iend, 1 
     
    37753816          ENDIF 
    37763817 
    3777           IF ( ierr.NE.0 ) CALL MPI_abort(mpi_comm_opa,1,ierr) 
     3818          !IF ( ierr.NE.0 ) CALL MPI_abort(mpi_comm_opa,1,ierr) 
    37783819 
    37793820       ELSE 
     
    37853826    ENDDO ! Loop over sends 
    37863827 
    3787 !    CALL timing_stop('mpi_sends') 
     3828    ! CALL timing_stop('mpi_sends') 
    37883829 
    37893830#if ( defined DEBUG && defined DEBUG_EXCHANGE ) || defined DEBUG_COMMS 
     
    37933834    ! Wait on the receives that were posted earlier 
    37943835 
    3795 !    CALL timing_start('mpi_recvs') 
     3836    ! CALL timing_start('mpi_recvs') 
    37963837 
    37973838    ! Copy just the set of flags we're interested in for passing  
     
    38143855          WRITE (*,"(I3,': ERROR: exchs_generic: MPI_waitany returned unrecognised error')") narea-1 
    38153856       END IF 
    3816        CALL ctl_stop('STOP') 
     3857       CALL ctl_stop('STOP','exchs_generic: MPI_waitany returned error') 
    38173858    END IF 
    38183859 
     
    38213862          IF ( PRESENT(b2) ) THEN 
    38223863 
    3823 !            CALL timing_start('2dr_unpack') 
     3864             ! CALL timing_start('2dr_unpack') 
    38243865 
    38253866             ! Copy received data back into array 
     
    38393880             END DO unpack_patches2r 
    38403881 
    3841 !            CALL timing_stop('2dr_unpack') 
     3882             ! CALL timing_stop('2dr_unpack') 
    38423883 
    38433884          ELSE IF ( PRESENT(ib2) ) THEN 
     
    38613902           ELSE IF (PRESENT(b3) ) THEN 
    38623903 
    3863 !            CALL timing_start('3dr_unpack') 
     3904              ! CALL timing_start('3dr_unpack') 
    38643905             ic = 0 
    38653906             unpack_patches3r: DO ipatch=1,npatchrecv(irecv,nhexch) 
     
    38723913                DO j=jstart, jend, 1 
    38733914                   DO i=istart, iend, 1 
    3874                       DO k=1,kdim1,1 
    3875 #else 
    3876                 DO k=1,kdim1,1 
     3915                      DO k=1,nzrecvp(ipatch,irecv,1),1 
     3916#else 
     3917                DO k=1,nzrecvp(ipatch,irecv,1),1 
    38773918                   DO j=jstart, jend, 1 
    38783919                      DO i=istart, iend, 1 
     
    38813922                         b3(i,j,k) = recvBuff(ic,irecv) 
    38823923                      END DO 
     3924#if defined key_z_first 
     3925                      ! ARPDBG - wipe anything below the ocean bottom 
     3926                      DO k=nzrecvp(ipatch,irecv,1)+1,jpk,1 
     3927                         b3(i,j,k) = 0.0_wp 
     3928                      END DO 
     3929#endif 
    38833930                   END DO 
    38843931                END DO 
     3932 
     3933                ! ARPDBG - wipe anything below the ocean bottom 
     3934#if ! defined key_z_first 
     3935                DO k=nzrecvp(ipatch,irecv,1)+1,jpk,1 
     3936                   DO j=jstart, jend, 1 
     3937                      DO i=istart, iend, 1 
     3938                         b3(i,j,k) = 0.0_wp 
     3939                      END DO 
     3940                   END DO 
     3941                END DO 
     3942#endif  
     3943 
    38853944             END DO unpack_patches3r 
    38863945 
     
    38993958                DO j=jstart, jend, 1 
    39003959                   DO i=istart, iend, 1 
    3901                       DO k=1,kdim1,1 
    3902 #else 
    3903                 DO k=1,kdim1,1 
     3960                      DO k=1,nzrecvp(ipatch,irecv,1),1 
     3961#else 
     3962                DO k=1,nzrecvp(ipatch,irecv,1),1 
    39043963                   DO j=jstart, jend, 1 
    39053964                      DO i=istart, iend, 1 
     
    39153974 
    39163975       CALL MPI_waitany (nrecv, exch_flags1d, irecv, status, ierr) 
    3917        IF ( ierr.NE.0 ) CALL MPI_abort(mpi_comm_opa,1,ierr) 
     3976       !IF ( ierr.NE.0 ) CALL MPI_abort(mpi_comm_opa,1,ierr) 
    39183977 
    39193978    END DO ! while irecv != MPI_UNDEFINED 
    39203979 
    3921 !    CALL timing_stop('mpi_recvs') 
     3980    ! CALL timing_stop('mpi_recvs') 
    39223981 
    39233982    ! All receives done and unpacked so can deallocate the associated 
    39243983    ! buffers 
    3925     IF(ALLOCATED(recvBuff ))DEALLOCATE(recvBuff) 
    3926     IF(ALLOCATED(recvIBuff))DEALLOCATE(recvIBuff) 
     3984    !IF(ALLOCATED(recvBuff ))DEALLOCATE(recvBuff) 
     3985    !IF(ALLOCATED(recvIBuff))DEALLOCATE(recvIBuff) 
    39273986 
    39283987#if defined DEBUG_COMMS 
     
    39403999    !          loop! 
    39414000    IF ( cyclic_bc .AND. (jpni.EQ.1) ) THEN 
     4001 
     4002       ! Find out the sizes of the arrays. 
     4003       kdim1 = 1 
     4004       IF ( PRESENT(b3) ) THEN 
     4005          kdim1 = SIZE(b3,dim=index_z) 
     4006       ELSEIF ( PRESENT(ib3) ) THEN 
     4007          kdim1 = SIZE(ib3,dim=index_z) 
     4008       ENDIF 
     4009 
    39424010 
    39434011       IF ( enabled(Iplus) ) THEN 
     
    39964064       ENDIF 
    39974065 
    3998     ENDIF 
     4066    ENDIF ! cyclic_bc .AND. jpni == 1 
    39994067 
    40004068    ! Copy just the set of flags we're interested in for passing to   
     
    40094077    IF( ALLOCATED(recvIBuff) )DEALLOCATE(recvIBuff) 
    40104078 
    4011 !    CALL timing_stop('exchs_generic') 
     4079    ! CALL timing_stop('exchs_generic') 
    40124080    !CALL prof_region_end(ARPEXCHS_GENERIC, iprofStat) 
    40134081 
     
    43134381    CALL prof_region_begin(ARPNORTHLISTCOMMS, "NorthList", iprofStat) 
    43144382 
     4383#if defined key_mpp_mpi 
     4384 
    43154385    ! If we get into this routine it's because : North fold condition and mpp  
    43164386    ! with more than one PE across i : we deal only with the North condition 
    43174387 
    43184388    ! Set no. of rows from a module parameter that is also used in exchtestmod 
     4389    ! and mpp_ini_north 
    43194390    ijpj = num_nfold_rows 
    43204391 
     
    52445315    CALL prof_region_end(NORTHLISTSCATTER, iprofStat) 
    52455316 
     5317#endif /* key_mpp_mpi */ 
     5318 
    52465319    CALL prof_region_end(ARPNORTHLISTCOMMS, iprofStat) 
    52475320 
     
    52555328    !! 
    52565329    !! ** Purpose : 
    5257     !!      Ensure proper north fold horizontal bondary condition in mpp configuration 
    5258     !!      in case of jpn1 > 1 (for 2d array ) 
     5330    !!      Ensure proper north fold horizontal bondary condition in mpp  
     5331    !!      configuration in case of jpn1 > 1 (for 2d array ) 
    52595332    !! 
    52605333    !! ** Method : 
     
    52665339    !!   8.5  !  03-09  (J.M. Molines ) For mpp folding condition at north 
    52675340    !!                                  from lbc routine 
    5268     !!   9.0  !  03-12  (J.M. Molines ) encapsulation into lib_mpp, coding rules of lbc_lnk 
     5341    !!   9.0  !  03-12  (J.M. Molines ) encapsulation into lib_mpp, coding  
     5342    !!                                  rules of lbc_lnk 
    52695343    !!---------------------------------------------------------------------- 
    52705344    USE par_oce,     ONLY : jpni, jpi, jpj 
     
    52735347    USE mapcomm_mod, ONLY : pielb, piesub 
    52745348    USE lib_mpp,     ONLY : ctl_stop 
     5349    USE arpdebugging, ONLY: dump_array 
    52755350    IMPLICIT none 
    52765351    !! * Arguments 
     
    52875362    !! * Local declarations 
    52885363 
    5289     INTEGER, PARAMETER :: ijpj = 4 
     5364    INTEGER :: ijpj 
    52905365    INTEGER :: ji, jj,  jr, jproc 
    52915366    INTEGER :: ierr 
     
    53035378    ! with more than one PE across i : we deal only with the North condition 
    53045379 
     5380    ! Set local from public PARAMETER 
     5381    ijpj = num_nfold_rows 
     5382 
    53055383    CALL prof_region_begin(ARPNORTHCOMMS2D, "North2D", iprofStat) 
    53065384 
     5385#if defined key_mpp_mpi 
     5386 
    53075387    IF(.not. ALLOCATED(ztab2))THEN 
    53085388 
    5309        ALLOCATE(ztab2(jpiglo,4),                & 
    5310                 znorthgloio2(nwidthmax,4,jpni), & 
    5311                 znorthloc2(nwidthmax,4),        & 
     5389       ALLOCATE(ztab2(jpiglo,ijpj),                & 
     5390                znorthgloio2(nwidthmax,ijpj,ndim_rank_north), & 
     5391                znorthloc2(nwidthmax,ijpj),        & 
    53125392                STAT=ierr) 
    53135393       IF(ierr .ne. 0)THEN 
     
    53215401    ijpjm1=ijpj-1 
    53225402 
    5323     ! put the last 4 jlines of pt2d into znorthloc2 
     5403    ! put the last ijpj jlines of pt2d into znorthloc2 
    53245404    znorthloc2(:,:) = 0_wp ! because of padding for nwidthmax 
    5325     DO ij = 1, ijpj, 1 
     5405 
     5406    ! jeub is the upper j limit of current domain in global coords 
     5407    ! 
     5408    !                      |======================= jpjglo     ^  
     5409    !    <Trimmed>         |                                  /|\ 
     5410    !                      |----------------------- jpjglo-1   | 
     5411    !                      |                                   | 
     5412    ! |---------jeub--------------------------------            
     5413    ! |                    |                                   j 
     5414    ! |--------------------------------------------             
     5415    ! |                    |                                   | 
     5416    ! |--------------------------------------------            | 
     5417    ! 
     5418    ! No. of trimmed rows = jpjglo - jeub 
     5419    ! No. of valid rows for n-fold = ijpj - <no. trimmed rows> 
     5420    !                              = ijpj - jpjglo + jeub 
     5421    ! Need an iterator that ends with max value ijpj and has (ijpj-jpjglo+jeub) 
     5422    ! distinct values so start point must be: 
     5423    !  ij_start = ijpj - (ijpj-jpjglo+jeub) + 1 = jpjglo - jeub + 1 
     5424    ! => if jeub == jpjglo then we recover a starting value of 1. 
     5425    !    if jeub == jpjglo - 10 then ij_start = 11 so no loop iterations 
     5426    !    will be performed. 
     5427 
     5428#if defined NO_NFOLD_GATHER 
     5429    ! Post receives for other PE's north-fold data 
     5430    DO iproc = 1, ndim_rank_north, 1 
     5431 
     5432       IF( iproc-1 ==  nrank_north(iproc) ) CYCLE ! Skip this PE 
     5433 
     5434       CALL MPI_IRecv(znorthgloio2(), north_pts(iproc), MPI_DOUBLE_PRECISION, & 
     5435                      nrank_north(iproc), iproc, tag, ncomm_north,            & 
     5436                      nexch_flag(iproc) ) 
     5437    END DO 
     5438#endif 
     5439 
     5440    DO ij = jpjglo - jeub + 1, ijpj, 1 
     5441 
    53265442       jj = nlcj - ijpj + ij 
    53275443       znorthloc2(nldi:nlei,ij)=pt2d(nldi:nlei,jj) 
    53285444    END DO 
     5445 
     5446!    CALL dump_array(0,'znorthloc2',znorthloc2,withHalos=.TRUE.,toGlobal=.FALSE.) 
    53295447 
    53305448    IF (npolj /= 0 ) THEN 
     
    53355453                       znorthgloio2,itaille,MPI_DOUBLE_PRECISION,  & 
    53365454                       0, ncomm_north, ierr) 
     5455 
    53375456    ENDIF 
    53385457 
    53395458    IF (narea == north_root+1 ) THEN 
    53405459       ! recover the global north array 
     5460       ! ztab2 has full width of global domain 
    53415461       ztab2(:,:) = 0_wp 
    53425462 
     
    53505470       END DO 
    53515471 
     5472!       CALL dump_array(0,'ztab2',ztab2,withHalos=.TRUE.,toGlobal=.FALSE.) 
    53525473 
    53535474       ! 2. North-Fold boundary conditions 
     
    54955616      ENDIF 
    54965617 
    5497       ! put in the last ijpj jlines of pt2d znorthloc2 
    5498       DO ij = 1, ijpj, 1 
     5618      ! Put the last ijpj jlines of pt2d into znorthloc2 while allowing 
     5619      ! for any trimming of domain (see earlier comments and diagram) 
     5620      DO ij = jpjglo - jeub + 1, ijpj, 1 
    54995621         jj = nlcj - ijpj + ij 
    55005622         pt2d(nldi:nlei,jj)= znorthloc2(nldi:nlei,ij) 
    55015623      END DO 
     5624 
     5625#endif /* key_mpp_mpi */ 
    55025626 
    55035627      CALL prof_region_end(ARPNORTHCOMMS2D, iprofStat) 
     
    55125636    !! 
    55135637    !! ** Purpose : 
    5514     !!      Ensure proper north fold horizontal bondary condition in mpp configuration 
    5515     !!      in case of jpn1 > 1 (for 2d array ) 
     5638    !!      Ensure proper north fold horizontal bondary condition in mpp  
     5639    !!      configuration in case of jpn1 > 1 (for 2d array ) 
    55165640    !! 
    55175641    !! ** Method : 
     
    55455669    !! * Local declarations 
    55465670 
    5547     INTEGER, PARAMETER :: ijpj = 4 
     5671    INTEGER :: ijpj 
    55485672    INTEGER :: ji, jj,  jr, jproc 
    55495673    INTEGER :: ierr 
     
    55615685    ! with more than one PE across i : we deal only with the North condition 
    55625686 
     5687#if defined key_mpp_mpi 
     5688 
     5689    ijpj = num_nfold_rows 
     5690    ijpjm1=ijpj - 1 
     5691 
     5692 
    55635693     IF(.not. ALLOCATED(ztab2))THEN 
    55645694 
    5565         ALLOCATE(ztab2(jpiglo,4),                & 
    5566                  znorthgloio2(nwidthmax,4,jpni), & 
    5567                  znorthloc2(nwidthmax,4),        & 
     5695        ALLOCATE(ztab2(jpiglo,ijpj),                & 
     5696                 znorthgloio2(nwidthmax,ijpj,jpni), & 
     5697                 znorthloc2(nwidthmax,ijpj),        & 
    55685698                 STAT=ierr) 
    55695699        IF(ierr .ne. 0)THEN 
     
    55755705    ! --------------- 
    55765706 
    5577     ijpjm1=ijpj - 1 
    5578  
    5579     ! put in znorthloc2 the last 4 jlines of ib2 
     5707    ! Put the last ijpj jlines of ib2 into znorthloc2 while allowing 
     5708    ! for any trimming of domain (see earlier comments and diagram in 
     5709    ! mpp_lbc_north_2d). 
    55805710    znorthloc2(:,:) = 0  ! because of padding for nwidthmax 
    5581     DO ij = 1, ijpj, 1 
     5711    DO ij = jpjglo - jeub + 1, ijpj, 1 
    55825712       jj = nlcj - ijpj + ij 
    55835713       znorthloc2(nldi:nlei,ij)=ib2(nldi:nlei,jj) 
     
    56025732          ilei=nleit (jproc) 
    56035733          iilb=pielb(jproc) 
    5604           WRITE (*,*)'ARPDBG, jproc = ',jproc,' ildi, ilei, iilb and ijpj = ',ildi, ilei, iilb, ijpj 
     5734          !WRITE (*,*)'ARPDBG, jproc = ',jproc,' ildi, ilei, iilb and ijpj = ',& 
     5735          !            ildi, ilei, iilb, ijpj 
    56055736          ztab2(iilb:iilb+piesub(jproc)-1,1:ijpj) = & 
    56065737                                     znorthgloio2(ildi:ilei,1:ijpj,jr) 
     
    57405871            ilei=nleit (jproc) 
    57415872            iilb=pielb(jproc) 
    5742             znorthgloio2(ildi:ilei,1:ijpj,jr)=ztab2(iilb:iilb+piesub(jproc)-1,1:ijpj) 
     5873            znorthgloio2(ildi:ilei,1:ijpj,jr) = & 
     5874                                ztab2(iilb:iilb+piesub(jproc)-1,1:ijpj) 
    57435875         END DO 
    57445876 
     
    57525884      ENDIF 
    57535885 
    5754       ! put in the last ijpj jlines of ib2 znorthloc2 
    5755       DO ij = 1, ijpj, 1 
     5886      ! put in the last ijpj jlines of ib2 from znorthloc2 while allowing 
     5887      ! for any trimming of domain (see earlier comments and diagram in 
     5888      ! mpp_lbc_north_2d). 
     5889      DO ij = jpjglo - jeub + 1, ijpj, 1 
    57565890         jj = nlcj - ijpj + ij 
    57575891         ib2(nldi:nlei,jj)= znorthloc2(nldi:nlei,ij) 
    57585892      END DO 
    57595893      WRITE(*,*) 'ARPDBG: finished in mpp_lbc_north_i2d' 
     5894 
     5895#endif /* key_mpp_mpi */ 
     5896 
    57605897   END SUBROUTINE mpp_lbc_north_i2d 
    57615898 
     
    57975934 
    57985935     !! * Local declarations 
    5799      INTEGER, PARAMETER :: ijpj = 4 
     5936     INTEGER :: ijpj 
    58005937     INTEGER :: ji, jj, jk, jr, jproc 
    58015938     INTEGER :: ierr 
     
    58145951     ! mpp with more than one proc across i : we deal only with the North  
    58155952     ! condition 
     5953#if defined key_mpp_mpi 
     5954 
     5955     ijpj = num_nfold_rows 
     5956     ijpjm1=ijpj - 1 
    58165957 
    58175958     IF(.not. ALLOCATED(ztab))THEN 
    58185959 
    5819         ALLOCATE(ztab(jpiglo,4,jpk),                & 
    5820                  znorthgloio(nwidthmax,4,jpk,jpni), & 
    5821                  znorthloc(nwidthmax,4,jpk),        & 
     5960        ALLOCATE(ztab(jpiglo,ijpj,jpk),                & 
     5961                 znorthgloio(nwidthmax,ijpj,jpk,jpni), & 
     5962                 znorthloc(nwidthmax,ijpj,jpk),        & 
    58225963                 STAT=ierr) 
    58235964        IF(ierr .ne. 0)THEN 
     
    58355976     ! --------------- 
    58365977 
    5837     ijpjm1=ijpj - 1 
    5838  
    5839     ! Put the last ijpj jlines of pt3d into znorthloc 
    5840     !ARPDBG znorthloc(:,:,:) = 999_wp ! because of padding for nwidthmax - 999 is 
    5841                               ! for debugging 
    5842 #if defined key_z_first 
    5843     DO ij = 1, ijpj, 1 
     5978    ! Put the last ijpj jlines of pt3d into znorthloc while allowing 
     5979    ! for any trimming of domain (see earlier comments and diagram in 
     5980    ! mpp_lbc_north_2d). 
     5981    ! Have to initialise all to zero in case chunks are missing due to domain 
     5982    ! trimming 
     5983    znorthloc(:,:,:) = 0.0_wp 
     5984#if defined key_z_first 
     5985    DO ij = jpjglo - jeub + 1, ijpj, 1 
    58445986       jj = nlcj - ijpj + ij 
    58455987       DO jk = 1, jpk  
    58465988#else 
    58475989    DO jk = 1, jpk  
    5848        DO ij = 1, ijpj, 1 
     5990       DO ij = jpjglo - jeub + 1, ijpj, 1 
    58495991          jj = nlcj - ijpj + ij 
    58505992#endif 
     
    58565998    IF (npolj /= 0 ) THEN 
    58575999       ! Build in proc 0 of ncomm_north the znorthgloio 
    5858        !ARPDBG znorthgloio(:,:,:,:) = 0_wp 
    58596000 
    58606001#ifdef key_mpp_shmem 
     
    58756016    IF (narea == north_root+1 ) THEN 
    58766017       ! recover the global north array 
    5877        !ARPDBG ztab(:,:,:) = 0_wp 
     6018       ztab(:,:,:) = 0_wp 
    58786019 
    58796020       DO jr = 1, ndim_rank_north 
     
    58906031       ! =============== 
    58916032#if defined key_z_first 
    5892  
    58936033 
    58946034       ! 2. North-Fold boundary conditions 
     
    61796319#endif 
    61806320 
    6181     ! put in the last ijpj jlines of pt3d znorthloc 
    6182 #if defined key_z_first 
    6183     DO ij = 1, ijpj, 1 
     6321    ! put in the last ijpj jlines of pt3d znorthloc while allowing 
     6322    ! for any trimming of domain (see earlier comments and diagram in 
     6323    ! mpp_lbc_north_2d). 
     6324#if defined key_z_first 
     6325    DO ij = jpjglo - jeub + 1, ijpj, 1 
    61846326       jj = nlcj - ijpj + ij 
    61856327       DO jk = 1 , jpk  
    61866328#else 
    61876329    DO jk = 1 , jpk  
    6188        DO ij = 1, ijpj, 1 
     6330       DO ij = jpjglo - jeub + 1, ijpj, 1 
    61896331          jj = nlcj - ijpj + ij 
    61906332#endif 
     
    61946336 
    61956337    CALL prof_region_end(NORTH3DSCATTER, iprofStat) 
     6338 
     6339#endif /* key_mpp_mpi */ 
    61966340 
    61976341  END SUBROUTINE mpp_lbc_north_3d 
     
    62356379 
    62366380     !! * Local declarations 
    6237      INTEGER, PARAMETER :: ijpj = 4 
    6238      INTEGER, PARAMETER :: ijpjm1 = ijpj - 1 
     6381     INTEGER :: ijpj 
     6382     INTEGER :: ijpjm1 
    62396383     INTEGER :: ii, ji, jj, jk, jr, jproc 
    62406384     INTEGER :: ierr 
     
    62546398     ! mpp with more than one proc across i : we deal only with the North  
    62556399     ! condition 
     6400 
     6401     ijpj = num_nfold_rows 
     6402     ijpjm1 = ijpj - 1 
    62566403 
    62576404     IF(.not. ALLOCATED(ztab))THEN 
     
    62696416     ! --------------- 
    62706417 
    6271     ! put in znorthloc the last ijpj jlines of pt3d 
    6272     znorthloc(:,:,:) = 0 ! because of padding for nwidthmax 
    6273 #if defined key_z_first 
    6274     DO ij = 1, ijpj, 1 
     6418    ! put in znorthloc the last ijpj jlines of pt3d while allowing 
     6419    ! for any trimming of domain (see earlier comments and diagram in 
     6420    ! mpp_lbc_north_2d). 
     6421    znorthloc(:,:,:) = 0 ! because of padding for nwidthmax and domain 
     6422                         ! trimming 
     6423#if defined key_z_first 
     6424    DO ij = jpjglo - jeub + 1, ijpj, 1 
    62756425       jj = nlcj - ijpj + ij 
    62766426       DO jk = 1, jpk  
    62776427#else 
    62786428    DO jk = 1, jpk  
    6279        DO ij = 1, ijpj, 1 
     6429       DO ij = jpjglo - jeub + 1, ijpj, 1 
    62806430          jj = nlcj - ijpj + ij 
    62816431#endif 
     
    66086758#endif 
    66096759 
    6610     ! put in the last ijpj jlines of pt3d znorthloc 
    6611 #if defined key_z_first 
    6612     DO ij = 1, ijpj, 1 
     6760    ! put in the last ijpj jlines of pt3d znorthloc while allowing 
     6761    ! for any trimming of domain (see earlier comments and diagram in 
     6762    ! mpp_lbc_north_2d). 
     6763#if defined key_z_first 
     6764    DO ij = jpjglo - jeub + 1, ijpj, 1 
    66136765       jj = nlcj - ijpj + ij 
    66146766       DO ii = nldi, nlei, 1 
     
    66166768#else 
    66176769    DO jk = 1 , jpk  
    6618        DO ij = 1, ijpj, 1 
     6770       DO ij = jpjglo - jeub + 1, ijpj, 1 
    66196771          jj = nlcj - ijpj + ij 
    66206772          DO ii = nldi, nlei, 1 
Note: See TracChangeset for help on using the changeset viewer.