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 12229 for NEMO/branches/2019/dev_r11943_MERGE_2019/src/NST/agrif_user.F90 – NEMO

Ignore:
Timestamp:
2019-12-12T17:41:04+01:00 (4 years ago)
Author:
acc
Message:

2019/dev_r11943_MERGE_2019: Merge in dev_AGRIF-01-05_merged. Fully SETTE tested

File:
1 edited

Legend:

Unmodified
Added
Removed
  • NEMO/branches/2019/dev_r11943_MERGE_2019/src/NST/agrif_user.F90

    r11960 r12229  
    66   !! Software governed by the CeCILL license (see ./LICENSE) 
    77   !!---------------------------------------------------------------------- 
    8 SUBROUTINE agrif_user 
    9 END SUBROUTINE agrif_user 
    10  
    11 SUBROUTINE agrif_before_regridding 
    12 END SUBROUTINE agrif_before_regridding 
    13  
    14 SUBROUTINE Agrif_InitWorkspace 
    15       !!---------------------------------------------------------------------- 
    16       !!                 *** ROUTINE Agrif_InitWorkspace *** 
    17       !!---------------------------------------------------------------------- 
    18    USE par_oce 
    19    USE dom_oce 
    20    USE nemogcm 
    21    USE mppini 
    22       !! 
    23    IMPLICIT NONE 
    24       !!---------------------------------------------------------------------- 
    25    ! 
    26    IF( .NOT. Agrif_Root() ) THEN 
    27       ! no more static variables 
    28 !!$! JC: change to allow for different vertical levels 
    29 !!$!     jpk is already set 
    30 !!$!     keep it jpk possibly different from jpkglo which  
    31 !!$!     hold parent grid vertical levels number (set earlier) 
    32 !!$!      jpk     = jpkglo  
    33    ENDIF 
    34    ! 
    35 END SUBROUTINE Agrif_InitWorkspace 
    36  
    37  
    38 SUBROUTINE Agrif_InitValues 
     8   SUBROUTINE agrif_user 
     9   END SUBROUTINE agrif_user 
     10 
     11   SUBROUTINE agrif_before_regridding 
     12   END SUBROUTINE agrif_before_regridding 
     13 
     14   SUBROUTINE Agrif_InitWorkspace 
     15   END SUBROUTINE Agrif_InitWorkspace 
     16 
     17   SUBROUTINE Agrif_InitValues 
    3918      !!---------------------------------------------------------------------- 
    4019      !!                 *** ROUTINE Agrif_InitValues *** 
    41       !! 
    42       !! ** Purpose :: Declaration of variables to be interpolated 
    43       !!---------------------------------------------------------------------- 
    44    USE Agrif_Util 
    45    USE oce  
    46    USE dom_oce 
    47    USE nemogcm 
    48    USE tradmp 
    49    USE bdy_oce   , ONLY: ln_bdy 
    50    !! 
    51    IMPLICIT NONE 
    52       !!---------------------------------------------------------------------- 
    53    ! 
    54    CALL nemo_init       !* Initializations of each fine grid 
    55    Kbb_a = Nbb; Kmm_a = Nnn; Krhs_a = Nrhs   ! agrif_oce module copies of time level indices 
    56  
    57    !                    !* Agrif initialization 
    58    CALL agrif_nemo_init 
    59    CALL Agrif_InitValues_cont_dom 
    60    CALL Agrif_InitValues_cont 
     20      !!---------------------------------------------------------------------- 
     21      USE nemogcm 
     22      !!---------------------------------------------------------------------- 
     23      ! 
     24      CALL nemo_init       !* Initializations of each fine grid 
     25      Kbb_a = Nbb; Kmm_a = Nnn; Krhs_a = Nrhs   ! agrif_oce module copies of time level indices 
     26      ! 
     27      !                    !* Agrif initialization 
     28      CALL agrif_nemo_init 
     29      CALL Agrif_InitValues_cont_dom 
     30      CALL Agrif_InitValues_cont 
    6131# if defined key_top 
    62    CALL Agrif_InitValues_cont_top 
     32      CALL Agrif_InitValues_cont_top 
    6333# endif 
    6434# if defined key_si3 
    65    CALL Agrif_InitValues_cont_ice 
    66 # endif 
    67    !     
    68 END SUBROUTINE Agrif_initvalues 
    69  
    70  
    71 SUBROUTINE Agrif_InitValues_cont_dom 
    72       !!---------------------------------------------------------------------- 
    73       !!                 *** ROUTINE Agrif_InitValues_cont *** 
    74       !! 
    75       !! ** Purpose ::   Declaration of variables to be interpolated 
    76       !!---------------------------------------------------------------------- 
    77    USE Agrif_Util 
    78    USE oce  
    79    USE dom_oce 
    80    USE nemogcm 
    81    USE in_out_manager 
    82    USE agrif_oce_update 
    83    USE agrif_oce_interp 
    84    USE agrif_oce_sponge 
    85    ! 
    86    IMPLICIT NONE 
    87       !!---------------------------------------------------------------------- 
    88    ! 
    89    ! Declaration of the type of variable which have to be interpolated 
    90    ! 
    91    CALL agrif_declare_var_dom 
    92    ! 
    93 END SUBROUTINE Agrif_InitValues_cont_dom 
    94  
    95  
    96 SUBROUTINE agrif_declare_var_dom 
    97       !!---------------------------------------------------------------------- 
    98       !!                 *** ROUTINE agrif_declare_var *** 
    99       !! 
    100       !! ** Purpose :: Declaration of variables to be interpolated 
    101       !!---------------------------------------------------------------------- 
    102    USE agrif_util 
    103    USE par_oce        
    104    USE oce 
    105    ! 
    106    IMPLICIT NONE 
    107    ! 
    108    INTEGER :: ind1, ind2, ind3 
     35      CALL Agrif_InitValues_cont_ice 
     36# endif 
     37      !     
     38   END SUBROUTINE Agrif_initvalues 
     39 
     40   SUBROUTINE Agrif_InitValues_cont_dom 
     41      !!---------------------------------------------------------------------- 
     42      !!                 *** ROUTINE Agrif_InitValues_cont_dom *** 
     43      !!---------------------------------------------------------------------- 
     44      ! 
     45      CALL agrif_declare_var_dom 
     46      ! 
     47   END SUBROUTINE Agrif_InitValues_cont_dom 
     48 
     49   SUBROUTINE agrif_declare_var_dom 
     50      !!---------------------------------------------------------------------- 
     51      !!                 *** ROUTINE agrif_declare_var_dom *** 
     52      !!---------------------------------------------------------------------- 
     53      USE par_oce, ONLY:  nbghostcells       
     54      ! 
     55      IMPLICIT NONE 
     56      ! 
     57      INTEGER :: ind1, ind2, ind3 
    10958      !!---------------------------------------------------------------------- 
    11059 
    11160      ! 1. Declaration of the type of variable which have to be interpolated 
    11261      !--------------------------------------------------------------------- 
    113    ind1 =     nbghostcells 
    114    ind2 = 1 + nbghostcells 
    115    ind3 = 2 + nbghostcells 
    116    CALL agrif_declare_variable((/1,2/),(/ind2,ind3/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),e1u_id) 
    117    CALL agrif_declare_variable((/2,1/),(/ind3,ind2/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),e2v_id) 
     62      ind1 =     nbghostcells 
     63      ind2 = 1 + nbghostcells 
     64      ind3 = 2 + nbghostcells 
     65      CALL agrif_declare_variable((/1,2/),(/ind2,ind3/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),e1u_id) 
     66      CALL agrif_declare_variable((/2,1/),(/ind3,ind2/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),e2v_id) 
    11867 
    11968      ! 2. Type of interpolation 
    12069      !------------------------- 
    121    CALL Agrif_Set_bcinterp( e1u_id, interp1=Agrif_linear, interp2=AGRIF_ppm    ) 
    122    CALL Agrif_Set_bcinterp( e2v_id, interp1=AGRIF_ppm   , interp2=Agrif_linear ) 
     70      CALL Agrif_Set_bcinterp( e1u_id, interp1=Agrif_linear, interp2=AGRIF_ppm    ) 
     71      CALL Agrif_Set_bcinterp( e2v_id, interp1=AGRIF_ppm   , interp2=Agrif_linear ) 
    12372 
    12473      ! 3. Location of interpolation 
    12574      !----------------------------- 
    126    CALL Agrif_Set_bc(e1u_id,(/0,ind1-1/)) 
    127    CALL Agrif_Set_bc(e2v_id,(/0,ind1-1/)) 
     75      CALL Agrif_Set_bc(e1u_id,(/0,ind1-1/)) 
     76      CALL Agrif_Set_bc(e2v_id,(/0,ind1-1/)) 
    12877 
    12978      ! 4. Update type 
    13079      !---------------  
    13180# if defined UPD_HIGH 
    132    CALL Agrif_Set_Updatetype(e1u_id,update1 = Agrif_Update_Average, update2=Agrif_Update_Full_Weighting) 
    133    CALL Agrif_Set_Updatetype(e2v_id,update1 = Agrif_Update_Full_Weighting, update2=Agrif_Update_Average) 
     81      CALL Agrif_Set_Updatetype(e1u_id,update1 = Agrif_Update_Average, update2=Agrif_Update_Full_Weighting) 
     82      CALL Agrif_Set_Updatetype(e2v_id,update1 = Agrif_Update_Full_Weighting, update2=Agrif_Update_Average) 
    13483#else 
    135    CALL Agrif_Set_Updatetype(e1u_id,update1 = Agrif_Update_Copy, update2=Agrif_Update_Average) 
    136    CALL Agrif_Set_Updatetype(e2v_id,update1 = Agrif_Update_Average, update2=Agrif_Update_Copy) 
     84      CALL Agrif_Set_Updatetype(e1u_id,update1 = Agrif_Update_Copy, update2=Agrif_Update_Average) 
     85      CALL Agrif_Set_Updatetype(e2v_id,update1 = Agrif_Update_Average, update2=Agrif_Update_Copy) 
    13786#endif 
    13887 
    139 END SUBROUTINE agrif_declare_var_dom 
    140  
    141  
    142 SUBROUTINE Agrif_InitValues_cont 
     88   END SUBROUTINE agrif_declare_var_dom 
     89 
     90   SUBROUTINE Agrif_InitValues_cont 
    14391      !!---------------------------------------------------------------------- 
    14492      !!                 *** ROUTINE Agrif_InitValues_cont *** 
    145       !! 
    146       !! ** Purpose ::   Declaration of variables to be interpolated 
    147       !!---------------------------------------------------------------------- 
    148    USE agrif_oce_update 
    149    USE agrif_oce_interp 
    150    USE agrif_oce_sponge 
    151    USE Agrif_Util 
    152    USE oce  
    153    USE dom_oce 
    154    USE zdf_oce 
    155    USE nemogcm 
    156    ! 
    157    USE lib_mpp 
    158    USE in_out_manager 
    159    ! 
    160    IMPLICIT NONE 
    161    ! 
    162    LOGICAL :: check_namelist 
    163    CHARACTER(len=15) :: cl_check1, cl_check2, cl_check3, cl_check4  
    164       !!---------------------------------------------------------------------- 
    165  
    166    ! 1. Declaration of the type of variable which have to be interpolated 
    167    !--------------------------------------------------------------------- 
    168    CALL agrif_declare_var 
    169  
    170    ! 2. First interpolations of potentially non zero fields 
    171    !------------------------------------------------------- 
    172    Agrif_SpecialValue    = 0._wp 
    173    Agrif_UseSpecialValue = .TRUE. 
    174    CALL Agrif_Bc_variable(tsn_id,calledweight=1.,procname=interptsn) 
    175    CALL Agrif_Sponge 
    176    tabspongedone_tsn = .FALSE. 
    177    CALL Agrif_Bc_variable(tsn_sponge_id,calledweight=1.,procname=interptsn_sponge) 
    178    ! reset ts(:,:,:,:,Krhs_a) to zero 
    179    ts(:,:,:,:,Krhs_a) = 0. 
    180  
    181    Agrif_UseSpecialValue = ln_spc_dyn 
    182    CALL Agrif_Bc_variable(un_interp_id,calledweight=1.,procname=interpun) 
    183    CALL Agrif_Bc_variable(vn_interp_id,calledweight=1.,procname=interpvn) 
    184    tabspongedone_u = .FALSE. 
    185    tabspongedone_v = .FALSE. 
    186    CALL Agrif_Bc_variable(un_sponge_id,calledweight=1.,procname=interpun_sponge) 
    187    tabspongedone_u = .FALSE. 
    188    tabspongedone_v = .FALSE. 
    189    CALL Agrif_Bc_variable(vn_sponge_id,calledweight=1.,procname=interpvn_sponge) 
    190  
    191    Agrif_UseSpecialValue = .TRUE. 
    192    CALL Agrif_Bc_variable(sshn_id,calledweight=1., procname=interpsshn ) 
    193    hbdy_w(:,:) = 0.e0 ; hbdy_e(:,:) = 0.e0 ; hbdy_n(:,:) = 0.e0 ; hbdy_s(:,:) = 0.e0 
    194    ssh(:,:,Krhs_a) = 0.e0 
    195  
    196    IF ( ln_dynspg_ts ) THEN 
     93      !!---------------------------------------------------------------------- 
     94      USE agrif_oce 
     95      USE agrif_oce_interp 
     96      USE agrif_oce_sponge 
     97      USE dom_oce 
     98      USE oce 
     99      USE lib_mpp 
     100      USE lbclnk 
     101      ! 
     102      IMPLICIT NONE 
     103      ! 
     104      INTEGER :: ji, jj 
     105      LOGICAL :: check_namelist 
     106      CHARACTER(len=15) :: cl_check1, cl_check2, cl_check3, cl_check4  
     107#if defined key_vertical 
     108      REAL(wp), DIMENSION(jpi,jpj) ::   zk   ! workspace 
     109#endif 
     110      !!---------------------------------------------------------------------- 
     111 
     112      ! 1. Declaration of the type of variable which have to be interpolated 
     113      !--------------------------------------------------------------------- 
     114      CALL agrif_declare_var 
     115 
     116      ! 2. First interpolations of potentially non zero fields 
     117      !------------------------------------------------------- 
     118 
     119#if defined key_vertical 
     120      ! Build consistent parent bathymetry and number of levels 
     121      ! on the child grid  
     122      Agrif_UseSpecialValue = .FALSE. 
     123      ht0_parent(:,:) = 0._wp 
     124      mbkt_parent(:,:) = 0 
     125      ! 
     126      CALL Agrif_Bc_variable(ht0_id ,calledweight=1.,procname=interpht0 ) 
     127      CALL Agrif_Bc_variable(mbkt_id,calledweight=1.,procname=interpmbkt) 
     128      ! 
     129      ! Assume step wise change of bathymetry near interface 
     130      ! TODO: Switch to linear interpolation of bathymetry in the s-coordinate case 
     131      !       and no refinement 
     132      DO jj = 1, jpjm1 
     133         DO ji = 1, jpim1 
     134            mbku_parent(ji,jj) = MIN(  mbkt_parent(ji+1,jj  ) , mbkt_parent(ji,jj)  ) 
     135            mbkv_parent(ji,jj) = MIN(  mbkt_parent(ji  ,jj+1) , mbkt_parent(ji,jj)  ) 
     136         END DO 
     137      END DO 
     138      IF ( ln_sco.AND.Agrif_Parent(ln_sco) ) THEN  
     139         DO jj = 1, jpjm1 
     140            DO ji = 1, jpim1 
     141               hu0_parent(ji,jj) = 0.5_wp * ( ht0_parent(ji,jj)+ht0_parent(ji+1,jj) ) 
     142               hv0_parent(ji,jj) = 0.5_wp * ( ht0_parent(ji,jj)+ht0_parent(ji,jj+1) ) 
     143            END DO 
     144         END DO 
     145      ELSE 
     146         DO jj = 1, jpjm1 
     147            DO ji = 1, jpim1 
     148               hu0_parent(ji,jj) = MIN( ht0_parent(ji,jj), ht0_parent(ji+1,jj)) 
     149               hv0_parent(ji,jj) = MIN( ht0_parent(ji,jj), ht0_parent(ji,jj+1)) 
     150            END DO 
     151         END DO 
     152 
     153      ENDIF 
     154      ! 
     155      CALL lbc_lnk( 'Agrif_InitValues_cont', hu0_parent, 'U', 1. ) 
     156      CALL lbc_lnk( 'Agrif_InitValues_cont', hv0_parent, 'V', 1. ) 
     157      zk(:,:) = REAL( mbku_parent(:,:), wp )   ;   CALL lbc_lnk( 'Agrif_InitValues_cont', zk, 'U', 1. ) 
     158      mbku_parent(:,:) = MAX( NINT( zk(:,:) ), 1 ) 
     159      zk(:,:) = REAL( mbkv_parent(:,:), wp )   ;   CALL lbc_lnk( 'Agrif_InitValues_cont', zk, 'V', 1. ) 
     160      mbkv_parent(:,:) = MAX( NINT( zk(:,:) ), 1 )    
     161#endif 
     162 
     163      Agrif_SpecialValue    = 0._wp 
     164      Agrif_UseSpecialValue = .TRUE. 
     165      CALL Agrif_Bc_variable(tsn_id,calledweight=1.,procname=interptsn) 
     166      CALL Agrif_Sponge 
     167      tabspongedone_tsn = .FALSE. 
     168      CALL Agrif_Bc_variable(tsn_sponge_id,calledweight=1.,procname=interptsn_sponge) 
     169      ! reset ts(:,:,:,:,Krhs_a) to zero 
     170      ts(:,:,:,:,Krhs_a) = 0._wp 
     171 
    197172      Agrif_UseSpecialValue = ln_spc_dyn 
    198       CALL Agrif_Bc_variable(unb_id,calledweight=1.,procname=interpunb) 
    199       CALL Agrif_Bc_variable(vnb_id,calledweight=1.,procname=interpvnb) 
    200       CALL Agrif_Bc_variable(ub2b_interp_id,calledweight=1.,procname=interpub2b) 
    201       CALL Agrif_Bc_variable(vb2b_interp_id,calledweight=1.,procname=interpvb2b) 
    202       ubdy_w(:,:) = 0.e0 ; vbdy_w(:,:) = 0.e0 
    203       ubdy_e(:,:) = 0.e0 ; vbdy_e(:,:) = 0.e0 
    204       ubdy_n(:,:) = 0.e0 ; vbdy_n(:,:) = 0.e0 
    205       ubdy_s(:,:) = 0.e0 ; vbdy_s(:,:) = 0.e0 
    206    ENDIF 
    207  
    208    Agrif_UseSpecialValue = .FALSE.  
    209    ! reset velocities to zero 
    210    uu(:,:,:,Krhs_a) = 0. 
    211    vv(:,:,:,Krhs_a) = 0. 
    212  
    213    ! 3. Some controls 
    214    !----------------- 
    215    check_namelist = .TRUE. 
    216  
    217    IF( check_namelist ) THEN  
    218  
    219       ! Check time steps            
    220       IF( NINT(Agrif_Rhot()) * NINT(rdt) .NE. Agrif_Parent(rdt) ) THEN 
    221          WRITE(cl_check1,*)  NINT(Agrif_Parent(rdt)) 
    222          WRITE(cl_check2,*)  NINT(rdt) 
    223          WRITE(cl_check3,*)  NINT(Agrif_Parent(rdt)/Agrif_Rhot()) 
    224          CALL ctl_stop( 'Incompatible time step between ocean grids',   & 
    225                &               'parent grid value : '//cl_check1    ,   &  
    226                &               'child  grid value : '//cl_check2    ,   &  
    227                &               'value on child grid should be changed to : '//cl_check3 ) 
    228       ENDIF 
    229  
    230       ! Check run length 
    231       IF( Agrif_IRhot() * (Agrif_Parent(nitend)- & 
    232             Agrif_Parent(nit000)+1) .NE. (nitend-nit000+1) ) THEN 
    233          WRITE(cl_check1,*)  (Agrif_Parent(nit000)-1)*Agrif_IRhot() + 1 
    234          WRITE(cl_check2,*)   Agrif_Parent(nitend)   *Agrif_IRhot() 
    235          CALL ctl_warn( 'Incompatible run length between grids'                      ,   & 
    236                &               'nit000 on fine grid will be changed to : '//cl_check1,   & 
    237                &               'nitend on fine grid will be changed to : '//cl_check2    ) 
    238          nit000 = (Agrif_Parent(nit000)-1)*Agrif_IRhot() + 1 
    239          nitend =  Agrif_Parent(nitend)   *Agrif_IRhot() 
    240       ENDIF 
    241  
    242       ! Check free surface scheme 
    243       IF ( ( Agrif_Parent(ln_dynspg_ts ).AND.ln_dynspg_exp ).OR.& 
    244          & ( Agrif_Parent(ln_dynspg_exp).AND.ln_dynspg_ts ) ) THEN 
    245          WRITE(cl_check1,*)  Agrif_Parent( ln_dynspg_ts ) 
    246          WRITE(cl_check2,*)  ln_dynspg_ts 
    247          WRITE(cl_check3,*)  Agrif_Parent( ln_dynspg_exp ) 
    248          WRITE(cl_check4,*)  ln_dynspg_exp 
    249          CALL ctl_stop( 'Incompatible free surface scheme between grids' ,  & 
    250                &               'parent grid ln_dynspg_ts  :'//cl_check1  ,  &  
    251                &               'child  grid ln_dynspg_ts  :'//cl_check2  ,  & 
    252                &               'parent grid ln_dynspg_exp :'//cl_check3  ,  & 
    253                &               'child  grid ln_dynspg_exp :'//cl_check4  ,  & 
    254                &               'those logicals should be identical' )                  
    255          STOP 
    256       ENDIF 
    257  
    258       ! Check if identical linear free surface option 
    259       IF ( ( Agrif_Parent(ln_linssh ).AND.(.NOT.ln_linssh )).OR.& 
    260          & ( (.NOT.Agrif_Parent(ln_linssh)).AND.ln_linssh ) ) THEN 
    261          WRITE(cl_check1,*)  Agrif_Parent(ln_linssh ) 
    262          WRITE(cl_check2,*)  ln_linssh 
    263          CALL ctl_stop( 'Incompatible linearized fs option between grids',  & 
    264                &               'parent grid ln_linssh  :'//cl_check1     ,  & 
    265                &               'child  grid ln_linssh  :'//cl_check2     ,  & 
    266                &               'those logicals should be identical' )                   
    267          STOP 
     173      CALL Agrif_Bc_variable(un_interp_id,calledweight=1.,procname=interpun) 
     174      CALL Agrif_Bc_variable(vn_interp_id,calledweight=1.,procname=interpvn) 
     175      tabspongedone_u = .FALSE. 
     176      tabspongedone_v = .FALSE. 
     177      CALL Agrif_Bc_variable(un_sponge_id,calledweight=1.,procname=interpun_sponge) 
     178      tabspongedone_u = .FALSE. 
     179      tabspongedone_v = .FALSE. 
     180      CALL Agrif_Bc_variable(vn_sponge_id,calledweight=1.,procname=interpvn_sponge) 
     181      uu(:,:,:,Krhs_a) = 0._wp 
     182      vv(:,:,:,Krhs_a) = 0._wp 
     183 
     184      Agrif_UseSpecialValue = .TRUE. 
     185      CALL Agrif_Bc_variable(sshn_id,calledweight=1., procname=interpsshn ) 
     186      hbdy(:,:) = 0._wp 
     187      ssh(:,:,Krhs_a) = 0._wp 
     188 
     189      IF ( ln_dynspg_ts ) THEN 
     190         Agrif_UseSpecialValue = ln_spc_dyn 
     191         CALL Agrif_Bc_variable(unb_id,calledweight=1.,procname=interpunb) 
     192         CALL Agrif_Bc_variable(vnb_id,calledweight=1.,procname=interpvnb) 
     193         CALL Agrif_Bc_variable(ub2b_interp_id,calledweight=1.,procname=interpub2b) 
     194         CALL Agrif_Bc_variable(vb2b_interp_id,calledweight=1.,procname=interpvb2b) 
     195         ubdy(:,:) = 0._wp 
     196         vbdy(:,:) = 0._wp 
     197      ENDIF 
     198 
     199      Agrif_UseSpecialValue = .FALSE. 
     200 
     201      ! 3. Some controls 
     202      !----------------- 
     203      check_namelist = .TRUE. 
     204 
     205      IF( check_namelist ) THEN  
     206 
     207         ! Check time steps            
     208         IF( NINT(Agrif_Rhot()) * NINT(rdt) .NE. Agrif_Parent(rdt) ) THEN 
     209            WRITE(cl_check1,*)  NINT(Agrif_Parent(rdt)) 
     210            WRITE(cl_check2,*)  NINT(rdt) 
     211            WRITE(cl_check3,*)  NINT(Agrif_Parent(rdt)/Agrif_Rhot()) 
     212            CALL ctl_stop( 'Incompatible time step between ocean grids',   & 
     213                  &               'parent grid value : '//cl_check1    ,   &  
     214                  &               'child  grid value : '//cl_check2    ,   &  
     215                  &               'value on child grid should be changed to : '//cl_check3 ) 
     216         ENDIF 
     217 
     218         ! Check run length 
     219         IF( Agrif_IRhot() * (Agrif_Parent(nitend)- & 
     220               Agrif_Parent(nit000)+1) .NE. (nitend-nit000+1) ) THEN 
     221            WRITE(cl_check1,*)  (Agrif_Parent(nit000)-1)*Agrif_IRhot() + 1 
     222            WRITE(cl_check2,*)   Agrif_Parent(nitend)   *Agrif_IRhot() 
     223            CALL ctl_warn( 'Incompatible run length between grids'                      ,   & 
     224                  &               'nit000 on fine grid will be changed to : '//cl_check1,   & 
     225                  &               'nitend on fine grid will be changed to : '//cl_check2    ) 
     226            nit000 = (Agrif_Parent(nit000)-1)*Agrif_IRhot() + 1 
     227            nitend =  Agrif_Parent(nitend)   *Agrif_IRhot() 
     228         ENDIF 
     229 
     230         ! Check free surface scheme 
     231         IF ( ( Agrif_Parent(ln_dynspg_ts ).AND.ln_dynspg_exp ).OR.& 
     232            & ( Agrif_Parent(ln_dynspg_exp).AND.ln_dynspg_ts ) ) THEN 
     233            WRITE(cl_check1,*)  Agrif_Parent( ln_dynspg_ts ) 
     234            WRITE(cl_check2,*)  ln_dynspg_ts 
     235            WRITE(cl_check3,*)  Agrif_Parent( ln_dynspg_exp ) 
     236            WRITE(cl_check4,*)  ln_dynspg_exp 
     237            CALL ctl_stop( 'Incompatible free surface scheme between grids' ,  & 
     238                  &               'parent grid ln_dynspg_ts  :'//cl_check1  ,  &  
     239                  &               'child  grid ln_dynspg_ts  :'//cl_check2  ,  & 
     240                  &               'parent grid ln_dynspg_exp :'//cl_check3  ,  & 
     241                  &               'child  grid ln_dynspg_exp :'//cl_check4  ,  & 
     242                  &               'those logicals should be identical' )                  
     243            STOP 
     244         ENDIF 
     245 
     246         ! Check if identical linear free surface option 
     247         IF ( ( Agrif_Parent(ln_linssh ).AND.(.NOT.ln_linssh )).OR.& 
     248            & ( (.NOT.Agrif_Parent(ln_linssh)).AND.ln_linssh ) ) THEN 
     249            WRITE(cl_check1,*)  Agrif_Parent(ln_linssh ) 
     250            WRITE(cl_check2,*)  ln_linssh 
     251            CALL ctl_stop( 'Incompatible linearized fs option between grids',  & 
     252                  &               'parent grid ln_linssh  :'//cl_check1     ,  & 
     253                  &               'child  grid ln_linssh  :'//cl_check2     ,  & 
     254                  &               'those logicals should be identical' )                   
     255            STOP 
     256         ENDIF 
     257 
    268258      ENDIF 
    269259 
    270260      ! check if masks and bathymetries match 
    271261      IF(ln_chk_bathy) THEN 
     262         Agrif_UseSpecialValue = .FALSE. 
    272263         ! 
     264         IF(lwp) WRITE(numout,*) ' ' 
    273265         IF(lwp) WRITE(numout,*) 'AGRIF: Check Bathymetry and masks near bdys. Level: ', Agrif_Level() 
    274266         ! 
    275267         kindic_agr = 0 
    276          ! check if umask agree with parent along western and eastern boundaries: 
    277          CALL Agrif_Bc_variable(umsk_id,calledweight=1.,procname=interpumsk) 
    278          ! check if vmask agree with parent along northern and southern boundaries: 
    279          CALL Agrif_Bc_variable(vmsk_id,calledweight=1.,procname=interpvmsk) 
    280          ! check if tmask and vertical scale factors agree with parent over first two coarse grid points: 
     268# if ! defined key_vertical 
     269         ! 
     270         ! check if tmask and vertical scale factors agree with parent in sponge area: 
    281271         CALL Agrif_Bc_variable(e3t_id,calledweight=1.,procname=interpe3t) 
    282272         ! 
     273# else 
     274         ! 
     275         ! In case of vertical interpolation, check only that total depths agree between child and parent: 
     276         DO ji = 1, jpi 
     277            DO jj = 1, jpj 
     278               IF ((mbkt_parent(ji,jj)/=0).AND.(ABS(ht0_parent(ji,jj)-ht_0(ji,jj))>1.e-3)) kindic_agr = kindic_agr + 1 
     279               IF ((mbku_parent(ji,jj)/=0).AND.(ABS(hu0_parent(ji,jj)-hu_0(ji,jj))>1.e-3)) kindic_agr = kindic_agr + 1 
     280               IF ((mbkv_parent(ji,jj)/=0).AND.(ABS(hv0_parent(ji,jj)-hv_0(ji,jj))>1.e-3)) kindic_agr = kindic_agr + 1 
     281            END DO 
     282         END DO 
     283# endif 
    283284         CALL mpp_sum( 'agrif_user', kindic_agr ) 
    284285         IF( kindic_agr /= 0 ) THEN 
    285             CALL ctl_stop('Child Bathymetry is not correct near boundaries.') 
     286            CALL ctl_stop('==> Child Bathymetry is NOT correct near boundaries.') 
    286287         ELSE 
    287             IF(lwp) WRITE(numout,*) 'Child Bathymetry is ok near boundaries.' 
    288          END IF 
    289       ENDIF 
    290       ! 
    291    ENDIF 
    292    !  
    293 END SUBROUTINE Agrif_InitValues_cont 
    294  
    295 SUBROUTINE agrif_declare_var 
    296       !!---------------------------------------------------------------------- 
    297       !!                 *** ROUTINE agrif_declarE_var *** 
    298       !! 
    299       !! ** Purpose :: Declaration of variables to be interpolated 
    300       !!---------------------------------------------------------------------- 
    301    USE agrif_util 
    302    USE agrif_oce 
    303    USE par_oce       ! ocean parameters 
    304    USE zdf_oce       ! vertical physics 
    305    USE oce 
    306    ! 
    307    IMPLICIT NONE 
    308    ! 
    309    INTEGER :: ind1, ind2, ind3 
    310       !!---------------------------------------------------------------------- 
    311  
    312    ! 1. Declaration of the type of variable which have to be interpolated 
    313    !--------------------------------------------------------------------- 
    314    ind1 =     nbghostcells 
    315    ind2 = 1 + nbghostcells 
    316    ind3 = 2 + nbghostcells 
     288            IF(lwp) WRITE(numout,*) '==> Child Bathymetry is ok near boundaries.' 
     289            IF(lwp) WRITE(numout,*) ' ' 
     290         END IF   
     291         !     
     292      ENDIF 
     293 
    317294# if defined key_vertical 
    318    CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jpts+1/),tsn_id) 
    319    CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jpts+1/),tsn_sponge_id) 
    320  
    321    CALL agrif_declare_variable((/1,2,0,0/),(/ind2,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,2/),un_interp_id) 
    322    CALL agrif_declare_variable((/2,1,0,0/),(/ind3,ind2,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,2/),vn_interp_id) 
    323    CALL agrif_declare_variable((/1,2,0,0/),(/ind2,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,2/),un_update_id) 
    324    CALL agrif_declare_variable((/2,1,0,0/),(/ind3,ind2,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,2/),vn_update_id) 
    325    CALL agrif_declare_variable((/1,2,0,0/),(/ind2,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,2/),un_sponge_id) 
    326    CALL agrif_declare_variable((/2,1,0,0/),(/ind3,ind2,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,2/),vn_sponge_id) 
     295      ! Additional constrain that should be removed someday: 
     296      IF ( Agrif_Parent(jpk).GT.jpk ) THEN 
     297    CALL ctl_stop( ' With key_vertical, child grids must have jpk greater or equal to the parent value' ) 
     298      ENDIF 
     299# endif 
     300      !  
     301   END SUBROUTINE Agrif_InitValues_cont 
     302 
     303   SUBROUTINE agrif_declare_var 
     304      !!---------------------------------------------------------------------- 
     305      !!                 *** ROUTINE agrif_declare_var *** 
     306      !!---------------------------------------------------------------------- 
     307      USE agrif_util 
     308      USE agrif_oce 
     309      USE par_oce 
     310      USE zdf_oce  
     311      USE oce 
     312      ! 
     313      IMPLICIT NONE 
     314      ! 
     315      INTEGER :: ind1, ind2, ind3 
     316      !!---------------------------------------------------------------------- 
     317 
     318      ! 1. Declaration of the type of variable which have to be interpolated 
     319      !--------------------------------------------------------------------- 
     320      ind1 =     nbghostcells 
     321      ind2 = 1 + nbghostcells 
     322      ind3 = 2 + nbghostcells 
     323# if defined key_vertical 
     324      CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jpts+1/),tsn_id) 
     325      CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jpts+1/),tsn_sponge_id) 
     326 
     327      CALL agrif_declare_variable((/1,2,0,0/),(/ind2,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,2/),un_interp_id) 
     328      CALL agrif_declare_variable((/2,1,0,0/),(/ind3,ind2,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,2/),vn_interp_id) 
     329      CALL agrif_declare_variable((/1,2,0,0/),(/ind2,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,2/),un_update_id) 
     330      CALL agrif_declare_variable((/2,1,0,0/),(/ind3,ind2,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,2/),vn_update_id) 
     331      CALL agrif_declare_variable((/1,2,0,0/),(/ind2,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,2/),un_sponge_id) 
     332      CALL agrif_declare_variable((/2,1,0,0/),(/ind3,ind2,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,2/),vn_sponge_id) 
    327333# else 
    328    CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jpts/),tsn_id) 
    329    CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jpts/),tsn_sponge_id) 
    330  
    331    CALL agrif_declare_variable((/1,2,0,0/),(/ind2,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,1/),un_interp_id) 
    332    CALL agrif_declare_variable((/2,1,0,0/),(/ind3,ind2,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,1/),vn_interp_id) 
    333    CALL agrif_declare_variable((/1,2,0,0/),(/ind2,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,1/),un_update_id) 
    334    CALL agrif_declare_variable((/2,1,0,0/),(/ind3,ind2,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,1/),vn_update_id) 
    335    CALL agrif_declare_variable((/1,2,0,0/),(/ind2,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,1/),un_sponge_id) 
    336    CALL agrif_declare_variable((/2,1,0,0/),(/ind3,ind2,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,1/),vn_sponge_id) 
    337 # endif 
    338  
    339    CALL agrif_declare_variable((/2,2,0/),(/ind3,ind3,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpk/),e3t_id) 
    340    CALL agrif_declare_variable((/1,2,0/),(/ind2,ind3,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpk/),umsk_id) 
    341    CALL agrif_declare_variable((/2,1,0/),(/ind3,ind2,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpk/),vmsk_id) 
    342  
    343    CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,3/),scales_t_id) 
    344  
    345    CALL agrif_declare_variable((/1,2/),(/ind2,ind3/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),unb_id) 
    346    CALL agrif_declare_variable((/2,1/),(/ind3,ind2/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),vnb_id) 
    347    CALL agrif_declare_variable((/1,2/),(/ind2,ind3/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),ub2b_interp_id) 
    348    CALL agrif_declare_variable((/2,1/),(/ind3,ind2/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),vb2b_interp_id) 
    349    CALL agrif_declare_variable((/1,2/),(/ind2,ind3/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),ub2b_update_id) 
    350    CALL agrif_declare_variable((/2,1/),(/ind3,ind2/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),vb2b_update_id) 
    351  
    352    CALL agrif_declare_variable((/2,2/),(/ind3,ind3/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),sshn_id) 
    353  
    354    IF( ln_zdftke.OR.ln_zdfgls ) THEN 
    355 !      CALL agrif_declare_variable((/2,2,0/),(/ind3,ind3,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpk/), en_id) 
    356 !      CALL agrif_declare_variable((/2,2,0/),(/ind3,ind3,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpk/),avt_id) 
     334      CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jpts/),tsn_id) 
     335      CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jpts/),tsn_sponge_id) 
     336 
     337      CALL agrif_declare_variable((/1,2,0,0/),(/ind2,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,1/),un_interp_id) 
     338      CALL agrif_declare_variable((/2,1,0,0/),(/ind3,ind2,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,1/),vn_interp_id) 
     339      CALL agrif_declare_variable((/1,2,0,0/),(/ind2,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,1/),un_update_id) 
     340      CALL agrif_declare_variable((/2,1,0,0/),(/ind3,ind2,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,1/),vn_update_id) 
     341      CALL agrif_declare_variable((/1,2,0,0/),(/ind2,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,1/),un_sponge_id) 
     342      CALL agrif_declare_variable((/2,1,0,0/),(/ind3,ind2,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,1/),vn_sponge_id) 
     343# endif 
     344 
     345      CALL agrif_declare_variable((/2,2,0/),(/ind3,ind3,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpk/),e3t_id) 
     346 
    357347# if defined key_vertical 
    358       CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,2/),avm_id) 
     348      CALL agrif_declare_variable((/2,2/),(/ind3,ind3/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),mbkt_id) 
     349      CALL agrif_declare_variable((/2,2/),(/ind3,ind3/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),ht0_id) 
     350# endif 
     351 
     352      CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,3/),scales_t_id) 
     353 
     354      CALL agrif_declare_variable((/1,2/),(/ind2,ind3/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),unb_id) 
     355      CALL agrif_declare_variable((/2,1/),(/ind3,ind2/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),vnb_id) 
     356      CALL agrif_declare_variable((/1,2/),(/ind2,ind3/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),ub2b_interp_id) 
     357      CALL agrif_declare_variable((/2,1/),(/ind3,ind2/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),vb2b_interp_id) 
     358      CALL agrif_declare_variable((/1,2/),(/ind2,ind3/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),ub2b_update_id) 
     359      CALL agrif_declare_variable((/2,1/),(/ind3,ind2/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),vb2b_update_id) 
     360 
     361      CALL agrif_declare_variable((/2,2/),(/ind3,ind3/),(/'x','y'/),(/1,1/),(/nlci,nlcj/),sshn_id) 
     362 
     363      IF( ln_zdftke.OR.ln_zdfgls ) THEN 
     364!         CALL agrif_declare_variable((/2,2,0/),(/ind3,ind3,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpk/), en_id) 
     365!         CALL agrif_declare_variable((/2,2,0/),(/ind3,ind3,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpk/),avt_id) 
     366# if defined key_vertical 
     367         CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,2/),avm_id) 
    359368# else 
    360       CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,1/),avm_id) 
    361 # endif 
    362    ENDIF 
    363  
    364    ! 2. Type of interpolation 
    365    !------------------------- 
    366    CALL Agrif_Set_bcinterp(tsn_id,interp=AGRIF_linear) 
    367  
    368    CALL Agrif_Set_bcinterp(un_interp_id,interp1=Agrif_linear,interp2=AGRIF_ppm) 
    369    CALL Agrif_Set_bcinterp(vn_interp_id,interp1=AGRIF_ppm,interp2=Agrif_linear) 
    370  
    371    CALL Agrif_Set_bcinterp(tsn_sponge_id,interp=AGRIF_linear) 
    372  
    373    CALL Agrif_Set_bcinterp(sshn_id,interp=AGRIF_linear) 
    374    CALL Agrif_Set_bcinterp(unb_id,interp1=Agrif_linear,interp2=AGRIF_ppm) 
    375    CALL Agrif_Set_bcinterp(vnb_id,interp1=AGRIF_ppm,interp2=Agrif_linear) 
    376    CALL Agrif_Set_bcinterp(ub2b_interp_id,interp1=Agrif_linear,interp2=AGRIF_ppm) 
    377    CALL Agrif_Set_bcinterp(vb2b_interp_id,interp1=AGRIF_ppm,interp2=Agrif_linear) 
    378  
    379  
    380    CALL Agrif_Set_bcinterp(un_sponge_id,interp1=Agrif_linear,interp2=AGRIF_ppm) 
    381    CALL Agrif_Set_bcinterp(vn_sponge_id,interp1=AGRIF_ppm,interp2=Agrif_linear) 
    382  
    383    CALL Agrif_Set_bcinterp(e3t_id,interp=AGRIF_constant) 
    384    CALL Agrif_Set_bcinterp(umsk_id,interp=AGRIF_constant) 
    385    CALL Agrif_Set_bcinterp(vmsk_id,interp=AGRIF_constant) 
    386  
    387    IF( ln_zdftke.OR.ln_zdfgls )   CALL Agrif_Set_bcinterp( avm_id, interp=AGRIF_linear ) 
    388  
    389    ! 3. Location of interpolation 
    390    !----------------------------- 
    391    CALL Agrif_Set_bc(       tsn_id, (/0,ind1/) ) 
    392    CALL Agrif_Set_bc( un_interp_id, (/0,ind1/) ) 
    393    CALL Agrif_Set_bc( vn_interp_id, (/0,ind1/) ) 
    394  
    395    CALL Agrif_Set_bc( tsn_sponge_id, (/-nn_sponge_len*Agrif_irhox()-1,0/) )  ! if west and rhox=3 and sponge=2 and ghost=1: columns 2 to 9  
    396    CALL Agrif_Set_bc(  un_sponge_id, (/-nn_sponge_len*Agrif_irhox()-1,0/) ) 
    397    CALL Agrif_Set_bc(  vn_sponge_id, (/-nn_sponge_len*Agrif_irhox()-1,0/) ) 
    398  
    399    CALL Agrif_Set_bc(        sshn_id, (/0,ind1-1/) ) 
    400    CALL Agrif_Set_bc(         unb_id, (/0,ind1-1/) ) 
    401    CALL Agrif_Set_bc(         vnb_id, (/0,ind1-1/) ) 
    402    CALL Agrif_Set_bc( ub2b_interp_id, (/0,ind1-1/) ) 
    403    CALL Agrif_Set_bc( vb2b_interp_id, (/0,ind1-1/) ) 
    404  
    405    CALL Agrif_Set_bc(  e3t_id, (/-nn_sponge_len*Agrif_irhox(),ind1-1/) )   ! if west and rhox=3 and ghost=1: column 2 to 6  
    406    CALL Agrif_Set_bc( umsk_id, (/0,0/) ) 
    407    CALL Agrif_Set_bc( vmsk_id, (/0,0/) ) 
    408  
    409  
    410    IF( ln_zdftke.OR.ln_zdfgls )   CALL Agrif_Set_bc( avm_id, (/0,ind1/) ) 
    411  
    412    ! 4. Update type 
    413    !---------------  
    414    CALL Agrif_Set_Updatetype(scales_t_id, update = AGRIF_Update_Average) 
     369         CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,1/),avm_id) 
     370# endif 
     371      ENDIF 
     372 
     373      ! 2. Type of interpolation 
     374      !------------------------- 
     375      CALL Agrif_Set_bcinterp(tsn_id,interp=AGRIF_linear) 
     376 
     377      CALL Agrif_Set_bcinterp(un_interp_id,interp1=Agrif_linear,interp2=AGRIF_ppm) 
     378      CALL Agrif_Set_bcinterp(vn_interp_id,interp1=AGRIF_ppm,interp2=Agrif_linear) 
     379 
     380      CALL Agrif_Set_bcinterp(tsn_sponge_id,interp=AGRIF_linear) 
     381 
     382      CALL Agrif_Set_bcinterp(sshn_id,interp=AGRIF_linear) 
     383      CALL Agrif_Set_bcinterp(unb_id,interp1=Agrif_linear,interp2=AGRIF_ppm) 
     384      CALL Agrif_Set_bcinterp(vnb_id,interp1=AGRIF_ppm,interp2=Agrif_linear) 
     385      CALL Agrif_Set_bcinterp(ub2b_interp_id,interp1=Agrif_linear,interp2=AGRIF_ppm) 
     386      CALL Agrif_Set_bcinterp(vb2b_interp_id,interp1=AGRIF_ppm,interp2=Agrif_linear) 
     387! 
     388! > Divergence conserving alternative: 
     389!      CALL Agrif_Set_bcinterp(sshn_id,interp=AGRIF_constant) 
     390!      CALL Agrif_Set_bcinterp(unb_id,interp1=Agrif_linear,interp2=AGRIF_constant) 
     391!      CALL Agrif_Set_bcinterp(vnb_id,interp1=AGRIF_constant,interp2=Agrif_linear) 
     392!      CALL Agrif_Set_bcinterp(ub2b_interp_id,interp1=Agrif_linear,interp2=AGRIF_constant) 
     393!      CALL Agrif_Set_bcinterp(vb2b_interp_id,interp1=AGRIF_constant,interp2=Agrif_linear) 
     394!< 
     395 
     396      CALL Agrif_Set_bcinterp(un_sponge_id,interp1=Agrif_linear,interp2=AGRIF_ppm) 
     397      CALL Agrif_Set_bcinterp(vn_sponge_id,interp1=AGRIF_ppm,interp2=Agrif_linear) 
     398 
     399      CALL Agrif_Set_bcinterp(e3t_id,interp=AGRIF_constant) 
     400 
     401# if defined key_vertical 
     402      CALL Agrif_Set_bcinterp(mbkt_id,interp=AGRIF_constant) 
     403      CALL Agrif_Set_bcinterp(ht0_id ,interp=AGRIF_constant) 
     404# endif 
     405 
     406      IF( ln_zdftke.OR.ln_zdfgls )   CALL Agrif_Set_bcinterp( avm_id, interp=AGRIF_linear ) 
     407 
     408      ! 3. Location of interpolation 
     409      !----------------------------- 
     410      CALL Agrif_Set_bc(       tsn_id, (/0,ind1-1/) ) ! if west,  rhox=3 and nbghost=3: columns 2 to 4 
     411      CALL Agrif_Set_bc( un_interp_id, (/0,ind1-1/) )  
     412      CALL Agrif_Set_bc( vn_interp_id, (/0,ind1-1/) ) 
     413 
     414      CALL Agrif_Set_bc( tsn_sponge_id, (/-nn_sponge_len*Agrif_irhox()-1,0/) )  ! if west,  rhox=3, nn_sponge_len=2  
     415      CALL Agrif_Set_bc(  un_sponge_id, (/-nn_sponge_len*Agrif_irhox()-1,0/) )  ! and nbghost=3:  
     416      CALL Agrif_Set_bc(  vn_sponge_id, (/-nn_sponge_len*Agrif_irhox()-1,0/) )  ! columns 4 to 11 
     417 
     418      CALL Agrif_Set_bc(        sshn_id, (/0,ind1-1/) ) 
     419      CALL Agrif_Set_bc(         unb_id, (/0,ind1-1/) ) 
     420      CALL Agrif_Set_bc(         vnb_id, (/0,ind1-1/) ) 
     421      CALL Agrif_Set_bc( ub2b_interp_id, (/0,ind1-1/) ) 
     422      CALL Agrif_Set_bc( vb2b_interp_id, (/0,ind1-1/) ) 
     423 
     424!      CALL Agrif_Set_bc(  e3t_id, (/-nn_sponge_len*Agrif_irhox(),ind1-1/) )   
     425! JC: check near the boundary only until matching in sponge has been sorted out: 
     426      CALL Agrif_Set_bc(  e3t_id, (/0,ind1-1/) )   
     427 
     428# if defined key_vertical  
     429      ! extend the interpolation zone by 1 more point than necessary: 
     430      CALL Agrif_Set_bc(  mbkt_id, (/-nn_sponge_len*Agrif_irhox()-2,ind1/) ) 
     431      CALL Agrif_Set_bc(  ht0_id,  (/-nn_sponge_len*Agrif_irhox()-2,ind1/) ) 
     432# endif 
     433 
     434      IF( ln_zdftke.OR.ln_zdfgls )   CALL Agrif_Set_bc( avm_id, (/0,ind1/) ) 
     435 
     436      ! 4. Update type 
     437      !---------------  
     438      CALL Agrif_Set_Updatetype(scales_t_id, update = AGRIF_Update_Average) 
    415439 
    416440# if defined UPD_HIGH 
    417    CALL Agrif_Set_Updatetype(tsn_id, update = Agrif_Update_Full_Weighting) 
    418    CALL Agrif_Set_Updatetype(un_update_id,update1 = Agrif_Update_Average, update2 = Agrif_Update_Full_Weighting) 
    419    CALL Agrif_Set_Updatetype(vn_update_id,update1 = Agrif_Update_Full_Weighting, update2 = Agrif_Update_Average) 
    420  
    421    CALL Agrif_Set_Updatetype(ub2b_update_id,update1 = Agrif_Update_Average, update2 = Agrif_Update_Full_Weighting) 
    422    CALL Agrif_Set_Updatetype(vb2b_update_id,update1 = Agrif_Update_Full_Weighting, update2 = Agrif_Update_Average) 
    423    CALL Agrif_Set_Updatetype(sshn_id, update = Agrif_Update_Full_Weighting) 
    424    CALL Agrif_Set_Updatetype(e3t_id, update = Agrif_Update_Full_Weighting) 
    425  
    426    IF( ln_zdftke.OR.ln_zdfgls ) THEN 
    427 !      CALL Agrif_Set_Updatetype( en_id, update = AGRIF_Update_Full_Weighting) 
    428 !      CALL Agrif_Set_Updatetype(avt_id, update = AGRIF_Update_Full_Weighting) 
    429 !      CALL Agrif_Set_Updatetype(avm_id, update = AGRIF_Update_Full_Weighting) 
    430    ENDIF 
     441      CALL Agrif_Set_Updatetype(tsn_id, update = Agrif_Update_Full_Weighting) 
     442      CALL Agrif_Set_Updatetype(un_update_id,update1 = Agrif_Update_Average, update2 = Agrif_Update_Full_Weighting) 
     443      CALL Agrif_Set_Updatetype(vn_update_id,update1 = Agrif_Update_Full_Weighting, update2 = Agrif_Update_Average) 
     444 
     445      CALL Agrif_Set_Updatetype(ub2b_update_id,update1 = Agrif_Update_Average, update2 = Agrif_Update_Full_Weighting) 
     446      CALL Agrif_Set_Updatetype(vb2b_update_id,update1 = Agrif_Update_Full_Weighting, update2 = Agrif_Update_Average) 
     447      CALL Agrif_Set_Updatetype(sshn_id,update = Agrif_Update_Full_Weighting) 
     448      CALL Agrif_Set_Updatetype(e3t_id, update = Agrif_Update_Full_Weighting) 
     449 
     450      IF( ln_zdftke.OR.ln_zdfgls ) THEN 
     451!         CALL Agrif_Set_Updatetype( en_id, update = AGRIF_Update_Full_Weighting) 
     452!         CALL Agrif_Set_Updatetype(avt_id, update = AGRIF_Update_Full_Weighting) 
     453!         CALL Agrif_Set_Updatetype(avm_id, update = AGRIF_Update_Full_Weighting) 
     454      ENDIF 
    431455 
    432456#else 
    433    CALL Agrif_Set_Updatetype(tsn_id, update = AGRIF_Update_Average) 
    434    CALL Agrif_Set_Updatetype(un_update_id,update1 = Agrif_Update_Copy, update2 = Agrif_Update_Average) 
    435    CALL Agrif_Set_Updatetype(vn_update_id,update1 = Agrif_Update_Average, update2 = Agrif_Update_Copy) 
    436  
    437    CALL Agrif_Set_Updatetype(ub2b_update_id,update1 = Agrif_Update_Copy, update2 = Agrif_Update_Average) 
    438    CALL Agrif_Set_Updatetype(vb2b_update_id,update1 = Agrif_Update_Average, update2 = Agrif_Update_Copy) 
    439    CALL Agrif_Set_Updatetype(sshn_id, update = AGRIF_Update_Average) 
    440    CALL Agrif_Set_Updatetype(e3t_id, update = AGRIF_Update_Average) 
    441  
    442    IF( ln_zdftke.OR.ln_zdfgls ) THEN 
    443 !      CALL Agrif_Set_Updatetype( en_id, update = AGRIF_Update_Average) 
    444 !      CALL Agrif_Set_Updatetype(avt_id, update = AGRIF_Update_Average) 
    445 !      CALL Agrif_Set_Updatetype(avm_id, update = AGRIF_Update_Average) 
    446    ENDIF 
     457      CALL Agrif_Set_Updatetype(tsn_id, update = AGRIF_Update_Average) 
     458      CALL Agrif_Set_Updatetype(un_update_id,update1 = Agrif_Update_Copy, update2 = Agrif_Update_Average) 
     459      CALL Agrif_Set_Updatetype(vn_update_id,update1 = Agrif_Update_Average, update2 = Agrif_Update_Copy) 
     460 
     461      CALL Agrif_Set_Updatetype(ub2b_update_id,update1 = Agrif_Update_Copy, update2 = Agrif_Update_Average) 
     462      CALL Agrif_Set_Updatetype(vb2b_update_id,update1 = Agrif_Update_Average, update2 = Agrif_Update_Copy) 
     463      CALL Agrif_Set_Updatetype(sshn_id,update = AGRIF_Update_Average) 
     464      CALL Agrif_Set_Updatetype(e3t_id, update = AGRIF_Update_Average) 
     465 
     466      IF( ln_zdftke.OR.ln_zdfgls ) THEN 
     467!         CALL Agrif_Set_Updatetype( en_id, update = AGRIF_Update_Average) 
     468!         CALL Agrif_Set_Updatetype(avt_id, update = AGRIF_Update_Average) 
     469!         CALL Agrif_Set_Updatetype(avm_id, update = AGRIF_Update_Average) 
     470      ENDIF 
    447471 
    448472#endif 
    449    ! 
    450 END SUBROUTINE agrif_declare_var 
     473      ! 
     474   END SUBROUTINE agrif_declare_var 
    451475 
    452476#if defined key_si3 
     
    454478      !!---------------------------------------------------------------------- 
    455479      !!                 *** ROUTINE Agrif_InitValues_cont_ice *** 
     480      !!---------------------------------------------------------------------- 
     481      USE Agrif_Util 
     482      USE sbc_oce, ONLY : nn_fsbc  ! clem: necessary otherwise Agrif_Parent(nn_fsbc) = nn_fsbc 
     483      USE ice 
     484      USE agrif_ice 
     485      USE in_out_manager 
     486      USE agrif_ice_interp 
     487      USE lib_mpp 
     488      ! 
     489      IMPLICIT NONE 
     490      !!---------------------------------------------------------------------- 
     491      ! 
     492      ! Declaration of the type of variable which have to be interpolated (parent=>child) 
     493      !---------------------------------------------------------------------------------- 
     494      CALL agrif_declare_var_ice 
     495 
     496      ! Controls 
     497 
     498      ! clem: For some reason, nn_fsbc(child)/=1 does not work properly (signal can be largely degraded by the agrif zoom) 
     499      !          the run must satisfy CFL=Uice/(dx/dt) < 0.6/nn_fsbc(child) 
     500      !          therefore, if nn_fsbc(child)>1 one must reduce the time-step in proportion to nn_fsbc(child), which is not acceptable 
     501      !       If a solution is found, the following stop could be removed because the rest of the code take nn_fsbc(child) into account 
     502      IF( nn_fsbc > 1 )  CALL ctl_stop('nn_fsbc(child) must be set to 1 otherwise agrif and sea-ice may not work properly') 
     503 
     504      ! stop if rhot * nn_fsbc(parent) /= N * nn_fsbc(child) with N being integer 
     505      IF( MOD( Agrif_irhot() * Agrif_Parent(nn_fsbc), nn_fsbc ) /= 0 )  THEN 
     506         CALL ctl_stop('rhot * nn_fsbc(parent) /= N * nn_fsbc(child), therefore nn_fsbc(child) should be set to 1 or nn_fsbc(parent)') 
     507      ENDIF 
     508      ! First Interpolations (using "after" ice subtime step => nbstep_ice=1) 
     509      !---------------------------------------------------------------------- 
     510      nbstep_ice = ( Agrif_irhot() * Agrif_Parent(nn_fsbc) / nn_fsbc ) ! clem: to have calledweight=1 in interp (otherwise the western border of the zoom is wrong) 
     511      CALL agrif_interp_ice('U') ! interpolation of ice velocities 
     512      CALL agrif_interp_ice('V') ! interpolation of ice velocities 
     513      CALL agrif_interp_ice('T') ! interpolation of ice tracers  
     514      nbstep_ice = 0    
     515      ! 
     516   END SUBROUTINE Agrif_InitValues_cont_ice 
     517 
     518   SUBROUTINE agrif_declare_var_ice 
     519      !!---------------------------------------------------------------------- 
     520      !!                 *** ROUTINE agrif_declare_var_ice *** 
     521      !!---------------------------------------------------------------------- 
     522      USE Agrif_Util 
     523      USE ice 
     524      USE par_oce, ONLY : nbghostcells 
     525      ! 
     526      IMPLICIT NONE 
     527      ! 
     528      INTEGER :: ind1, ind2, ind3 
     529      !!---------------------------------------------------------------------- 
     530      ! 
     531      ! 1. Declaration of the type of variable which have to be interpolated (parent=>child) 
     532      !       agrif_declare_variable(position,1st point index,--,--,dimensions,name) 
     533      !           ex.:  position=> 1,1 = not-centered (in i and j) 
     534      !                            2,2 =     centered (    -     ) 
     535      !                 index   => 1,1 = one ghost line 
     536      !                            2,2 = two ghost lines 
     537      !------------------------------------------------------------------------------------- 
     538      ind1 =     nbghostcells 
     539      ind2 = 1 + nbghostcells 
     540      ind3 = 2 + nbghostcells 
     541      CALL agrif_declare_variable((/2,2,0/),(/ind3,ind3,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpl*(8+nlay_s+nlay_i)/),tra_ice_id) 
     542      CALL agrif_declare_variable((/1,2/)  ,(/ind2,ind3/)  ,(/'x','y'/)    ,(/1,1/)  ,(/nlci,nlcj/)                      ,u_ice_id  ) 
     543      CALL agrif_declare_variable((/2,1/)  ,(/ind3,ind2/)  ,(/'x','y'/)    ,(/1,1/)  ,(/nlci,nlcj/)                      ,v_ice_id  ) 
     544 
     545      ! 2. Set interpolations (normal & tangent to the grid cell for velocities) 
     546      !----------------------------------- 
     547      CALL Agrif_Set_bcinterp(tra_ice_id, interp  = AGRIF_linear) 
     548      CALL Agrif_Set_bcinterp(u_ice_id  , interp1 = Agrif_linear,interp2 = AGRIF_ppm   ) 
     549      CALL Agrif_Set_bcinterp(v_ice_id  , interp1 = AGRIF_ppm   ,interp2 = Agrif_linear) 
     550 
     551      ! 3. Set location of interpolations 
     552      !---------------------------------- 
     553      CALL Agrif_Set_bc(tra_ice_id,(/0,ind1/)) 
     554      CALL Agrif_Set_bc(u_ice_id  ,(/0,ind1/)) 
     555      CALL Agrif_Set_bc(v_ice_id  ,(/0,ind1/)) 
     556 
     557      ! 4. Set update type in case 2 ways (child=>parent) (normal & tangent to the grid cell for velocities) 
     558      !-------------------------------------------------- 
     559# if defined UPD_HIGH 
     560      CALL Agrif_Set_Updatetype(tra_ice_id, update  = Agrif_Update_Full_Weighting) 
     561      CALL Agrif_Set_Updatetype(u_ice_id  , update1 = Agrif_Update_Average       , update2 = Agrif_Update_Full_Weighting) 
     562      CALL Agrif_Set_Updatetype(v_ice_id  , update1 = Agrif_Update_Full_Weighting, update2 = Agrif_Update_Average       ) 
     563#else 
     564      CALL Agrif_Set_Updatetype(tra_ice_id, update  = AGRIF_Update_Average) 
     565      CALL Agrif_Set_Updatetype(u_ice_id  , update1 = Agrif_Update_Copy   , update2 = Agrif_Update_Average) 
     566      CALL Agrif_Set_Updatetype(v_ice_id  , update1 = Agrif_Update_Average, update2 = Agrif_Update_Copy   ) 
     567#endif 
     568 
     569   END SUBROUTINE agrif_declare_var_ice 
     570#endif 
     571 
     572 
     573# if defined key_top 
     574   SUBROUTINE Agrif_InitValues_cont_top 
     575      !!---------------------------------------------------------------------- 
     576      !!                 *** ROUTINE Agrif_InitValues_cont_top *** 
     577      !!---------------------------------------------------------------------- 
     578      USE Agrif_Util 
     579      USE oce  
     580      USE dom_oce 
     581      USE nemogcm 
     582      USE par_trc 
     583      USE lib_mpp 
     584      USE trc 
     585      USE in_out_manager 
     586      USE agrif_oce_sponge 
     587      USE agrif_top_update 
     588      USE agrif_top_interp 
     589      USE agrif_top_sponge 
    456590      !! 
    457       !! ** Purpose :: Initialisation of variables to be interpolated for ice 
    458       !!---------------------------------------------------------------------- 
    459    USE Agrif_Util 
    460    USE sbc_oce, ONLY : nn_fsbc  ! clem: necessary otherwise Agrif_Parent(nn_fsbc) = nn_fsbc 
    461    USE ice 
    462    USE agrif_ice 
    463    USE in_out_manager 
    464    USE agrif_ice_interp 
    465    USE lib_mpp 
    466    ! 
    467    IMPLICIT NONE 
    468       !!---------------------------------------------------------------------- 
    469    ! 
    470    ! Declaration of the type of variable which have to be interpolated (parent=>child) 
    471    !---------------------------------------------------------------------------------- 
    472    CALL agrif_declare_var_ice 
    473  
    474    ! Controls 
    475  
    476    ! clem: For some reason, nn_fsbc(child)/=1 does not work properly (signal can be largely degraded by the agrif zoom) 
    477    !          the run must satisfy CFL=Uice/(dx/dt) < 0.6/nn_fsbc(child) 
    478    !          therefore, if nn_fsbc(child)>1 one must reduce the time-step in proportion to nn_fsbc(child), which is not acceptable 
    479    !       If a solution is found, the following stop could be removed because the rest of the code take nn_fsbc(child) into account 
    480    IF( nn_fsbc > 1 )  CALL ctl_stop('nn_fsbc(child) must be set to 1 otherwise agrif and sea-ice may not work properly') 
    481  
    482    ! stop if rhot * nn_fsbc(parent) /= N * nn_fsbc(child) with N being integer 
    483    IF( MOD( Agrif_irhot() * Agrif_Parent(nn_fsbc), nn_fsbc ) /= 0 )  THEN 
    484       CALL ctl_stop('rhot * nn_fsbc(parent) /= N * nn_fsbc(child), therefore nn_fsbc(child) should be set to 1 or nn_fsbc(parent)') 
    485    ENDIF 
    486    ! First Interpolations (using "after" ice subtime step => nbstep_ice=1) 
    487    !---------------------------------------------------------------------- 
    488    nbstep_ice = ( Agrif_irhot() * Agrif_Parent(nn_fsbc) / nn_fsbc ) ! clem: to have calledweight=1 in interp (otherwise the western border of the zoom is wrong) 
    489    CALL agrif_interp_ice('U') ! interpolation of ice velocities 
    490    CALL agrif_interp_ice('V') ! interpolation of ice velocities 
    491    CALL agrif_interp_ice('T') ! interpolation of ice tracers  
    492    nbstep_ice = 0 
    493     
    494    ! 
    495 END SUBROUTINE Agrif_InitValues_cont_ice 
    496  
    497 SUBROUTINE agrif_declare_var_ice 
    498       !!---------------------------------------------------------------------- 
    499       !!                 *** ROUTINE agrif_declare_var_ice *** 
    500       !! 
    501       !! ** Purpose :: Declaration of variables to be interpolated for ice 
    502       !!---------------------------------------------------------------------- 
    503    USE Agrif_Util 
    504    USE ice 
    505    USE par_oce, ONLY : nbghostcells 
    506    ! 
    507    IMPLICIT NONE 
    508    ! 
    509    INTEGER :: ind1, ind2, ind3 
    510       !!---------------------------------------------------------------------- 
    511    ! 
    512    ! 1. Declaration of the type of variable which have to be interpolated (parent=>child) 
    513    !       agrif_declare_variable(position,1st point index,--,--,dimensions,name) 
    514    !           ex.:  position=> 1,1 = not-centered (in i and j) 
    515    !                            2,2 =     centered (    -     ) 
    516    !                 index   => 1,1 = one ghost line 
    517    !                            2,2 = two ghost lines 
    518    !------------------------------------------------------------------------------------- 
    519    ind1 =     nbghostcells 
    520    ind2 = 1 + nbghostcells 
    521    ind3 = 2 + nbghostcells 
    522    CALL agrif_declare_variable((/2,2,0/),(/ind3,ind3,0/),(/'x','y','N'/),(/1,1,1/),(/nlci,nlcj,jpl*(8+nlay_s+nlay_i)/),tra_ice_id) 
    523    CALL agrif_declare_variable((/1,2/)  ,(/ind2,ind3/)  ,(/'x','y'/)    ,(/1,1/)  ,(/nlci,nlcj/)                      ,u_ice_id  ) 
    524    CALL agrif_declare_variable((/2,1/)  ,(/ind3,ind2/)  ,(/'x','y'/)    ,(/1,1/)  ,(/nlci,nlcj/)                      ,v_ice_id  ) 
    525  
    526    ! 2. Set interpolations (normal & tangent to the grid cell for velocities) 
    527    !----------------------------------- 
    528    CALL Agrif_Set_bcinterp(tra_ice_id, interp  = AGRIF_linear) 
    529    CALL Agrif_Set_bcinterp(u_ice_id  , interp1 = Agrif_linear,interp2 = AGRIF_ppm   ) 
    530    CALL Agrif_Set_bcinterp(v_ice_id  , interp1 = AGRIF_ppm   ,interp2 = Agrif_linear) 
    531  
    532    ! 3. Set location of interpolations 
    533    !---------------------------------- 
    534    CALL Agrif_Set_bc(tra_ice_id,(/0,ind1/)) 
    535    CALL Agrif_Set_bc(u_ice_id  ,(/0,ind1/)) 
    536    CALL Agrif_Set_bc(v_ice_id  ,(/0,ind1/)) 
    537  
    538    ! 4. Set update type in case 2 ways (child=>parent) (normal & tangent to the grid cell for velocities) 
    539    !-------------------------------------------------- 
    540 # if defined UPD_HIGH 
    541    CALL Agrif_Set_Updatetype(tra_ice_id, update  = Agrif_Update_Full_Weighting) 
    542    CALL Agrif_Set_Updatetype(u_ice_id  , update1 = Agrif_Update_Average       , update2 = Agrif_Update_Full_Weighting) 
    543    CALL Agrif_Set_Updatetype(v_ice_id  , update1 = Agrif_Update_Full_Weighting, update2 = Agrif_Update_Average       ) 
    544 #else 
    545    CALL Agrif_Set_Updatetype(tra_ice_id, update  = AGRIF_Update_Average) 
    546    CALL Agrif_Set_Updatetype(u_ice_id  , update1 = Agrif_Update_Copy   , update2 = Agrif_Update_Average) 
    547    CALL Agrif_Set_Updatetype(v_ice_id  , update1 = Agrif_Update_Average, update2 = Agrif_Update_Copy   ) 
    548 #endif 
    549  
    550 END SUBROUTINE agrif_declare_var_ice 
    551 #endif 
    552  
    553  
    554 # if defined key_top 
    555 SUBROUTINE Agrif_InitValues_cont_top 
    556       !!---------------------------------------------------------------------- 
    557       !!                 *** ROUTINE Agrif_InitValues_cont_top *** 
    558       !! 
    559       !! ** Purpose :: Declaration of variables to be interpolated 
    560       !!---------------------------------------------------------------------- 
    561    USE Agrif_Util 
    562    USE oce  
    563    USE dom_oce 
    564    USE nemogcm 
    565    USE par_trc 
    566    USE lib_mpp 
    567    USE trc 
    568    USE in_out_manager 
    569    USE agrif_oce_sponge 
    570    USE agrif_top_update 
    571    USE agrif_top_interp 
    572    USE agrif_top_sponge 
    573    !! 
    574    IMPLICIT NONE 
    575    ! 
    576    CHARACTER(len=10) :: cl_check1, cl_check2, cl_check3 
    577    LOGICAL :: check_namelist 
    578       !!---------------------------------------------------------------------- 
    579  
    580  
    581    ! 1. Declaration of the type of variable which have to be interpolated 
    582    !--------------------------------------------------------------------- 
    583    CALL agrif_declare_var_top 
    584  
    585    ! 2. First interpolations of potentially non zero fields 
    586    !------------------------------------------------------- 
    587    Agrif_SpecialValue=0. 
    588    Agrif_UseSpecialValue = .TRUE. 
    589    CALL Agrif_Bc_variable(trn_id,calledweight=1.,procname=interptrn) 
    590    Agrif_UseSpecialValue = .FALSE. 
    591    CALL Agrif_Sponge 
    592    tabspongedone_trn = .FALSE. 
    593    CALL Agrif_Bc_variable(trn_sponge_id,calledweight=1.,procname=interptrn_sponge) 
    594    ! reset ts(:,:,:,:,Krhs_a) to zero 
    595    tr(:,:,:,:,Krhs_a) = 0. 
    596  
    597  
    598    ! 3. Some controls 
    599    !----------------- 
    600    check_namelist = .TRUE. 
    601  
    602    IF( check_namelist ) THEN 
    603       ! Check time steps 
     591      IMPLICIT NONE 
     592      ! 
     593      CHARACTER(len=10) :: cl_check1, cl_check2, cl_check3 
     594      LOGICAL :: check_namelist 
     595      !!---------------------------------------------------------------------- 
     596 
     597      ! 1. Declaration of the type of variable which have to be interpolated 
     598      !--------------------------------------------------------------------- 
     599      CALL agrif_declare_var_top 
     600 
     601      ! 2. First interpolations of potentially non zero fields 
     602      !------------------------------------------------------- 
     603      Agrif_SpecialValue=0._wp 
     604      Agrif_UseSpecialValue = .TRUE. 
     605      CALL Agrif_Bc_variable(trn_id,calledweight=1.,procname=interptrn) 
     606      Agrif_UseSpecialValue = .FALSE. 
     607      CALL Agrif_Sponge 
     608      tabspongedone_trn = .FALSE. 
     609      CALL Agrif_Bc_variable(trn_sponge_id,calledweight=1.,procname=interptrn_sponge) 
     610      ! reset ts(:,:,:,:,Krhs_a) to zero 
     611      tr(:,:,:,:,Krhs_a) = 0._wp 
     612 
     613      ! 3. Some controls 
     614      !----------------- 
     615      check_namelist = .TRUE. 
     616 
     617      IF( check_namelist ) THEN 
     618         ! Check time steps 
    604619      IF( NINT(Agrif_Rhot()) * NINT(rdt) .NE. Agrif_Parent(rdt) ) THEN 
    605620         WRITE(cl_check1,*)  Agrif_Parent(rdt) 
     
    627642   ENDIF 
    628643   ! 
    629 END SUBROUTINE Agrif_InitValues_cont_top 
    630  
    631  
    632 SUBROUTINE agrif_declare_var_top 
     644   END SUBROUTINE Agrif_InitValues_cont_top 
     645 
     646 
     647   SUBROUTINE agrif_declare_var_top 
    633648      !!---------------------------------------------------------------------- 
    634649      !!                 *** ROUTINE agrif_declare_var_top *** 
     650      !!---------------------------------------------------------------------- 
     651      USE agrif_util 
     652      USE agrif_oce 
     653      USE dom_oce 
     654      USE trc 
    635655      !! 
    636       !! ** Purpose :: Declaration of TOP variables to be interpolated 
    637       !!---------------------------------------------------------------------- 
    638    USE agrif_util 
    639    USE agrif_oce 
    640    USE dom_oce 
    641    USE trc 
    642    !! 
    643    IMPLICIT NONE 
    644    ! 
    645    INTEGER :: ind1, ind2, ind3 
    646       !!---------------------------------------------------------------------- 
    647  
    648    ! 1. Declaration of the type of variable which have to be interpolated 
    649    !--------------------------------------------------------------------- 
    650    ind1 =     nbghostcells 
    651    ind2 = 1 + nbghostcells 
    652    ind3 = 2 + nbghostcells 
     656      IMPLICIT NONE 
     657      ! 
     658      INTEGER :: ind1, ind2, ind3 
     659      !!---------------------------------------------------------------------- 
     660 
     661      ! 1. Declaration of the type of variable which have to be interpolated 
     662      !--------------------------------------------------------------------- 
     663      ind1 =     nbghostcells 
     664      ind2 = 1 + nbghostcells 
     665      ind3 = 2 + nbghostcells 
    653666# if defined key_vertical 
    654    CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jptra+1/),trn_id) 
    655    CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jptra+1/),trn_sponge_id) 
     667      CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jptra+1/),trn_id) 
     668      CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jptra+1/),trn_sponge_id) 
    656669# else 
    657    CALL agrif_declare_variable((/2,2,0,0/),(/3,3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jptra/),trn_id) 
    658    CALL agrif_declare_variable((/2,2,0,0/),(/3,3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jptra/),trn_sponge_id) 
    659 # endif 
    660  
    661    ! 2. Type of interpolation 
    662    !------------------------- 
    663    CALL Agrif_Set_bcinterp(trn_id,interp=AGRIF_linear) 
    664    CALL Agrif_Set_bcinterp(trn_sponge_id,interp=AGRIF_linear) 
    665  
    666    ! 3. Location of interpolation 
    667    !----------------------------- 
    668    CALL Agrif_Set_bc(trn_id,(/0,ind1/)) 
    669    CALL Agrif_Set_bc(trn_sponge_id,(/-nn_sponge_len*Agrif_irhox()-1,0/)) 
    670  
    671    ! 4. Update type 
    672    !---------------  
     670      CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jptra/),trn_id) 
     671      CALL agrif_declare_variable((/2,2,0,0/),(/ind3,ind3,0,0/),(/'x','y','N','N'/),(/1,1,1,1/),(/nlci,nlcj,jpk,jptra/),trn_sponge_id) 
     672# endif 
     673 
     674      ! 2. Type of interpolation 
     675      !------------------------- 
     676      CALL Agrif_Set_bcinterp(trn_id,interp=AGRIF_linear) 
     677      CALL Agrif_Set_bcinterp(trn_sponge_id,interp=AGRIF_linear) 
     678 
     679      ! 3. Location of interpolation 
     680      !----------------------------- 
     681      CALL Agrif_Set_bc(trn_id,(/0,ind1-1/)) 
     682      CALL Agrif_Set_bc(trn_sponge_id,(/-nn_sponge_len*Agrif_irhox()-1,0/)) 
     683 
     684      ! 4. Update type 
     685      !---------------  
    673686# if defined UPD_HIGH 
    674    CALL Agrif_Set_Updatetype(trn_id, update = Agrif_Update_Full_Weighting) 
     687      CALL Agrif_Set_Updatetype(trn_id, update = Agrif_Update_Full_Weighting) 
    675688#else 
    676    CALL Agrif_Set_Updatetype(trn_id, update = AGRIF_Update_Average) 
     689      CALL Agrif_Set_Updatetype(trn_id, update = AGRIF_Update_Average) 
    677690#endif 
    678691   ! 
    679 END SUBROUTINE agrif_declare_var_top 
    680 # endif 
    681  
    682 SUBROUTINE Agrif_detect( kg, ksizex ) 
     692   END SUBROUTINE agrif_declare_var_top 
     693# endif 
     694 
     695   SUBROUTINE Agrif_detect( kg, ksizex ) 
    683696      !!---------------------------------------------------------------------- 
    684697      !!                      *** ROUTINE Agrif_detect *** 
    685698      !!---------------------------------------------------------------------- 
    686    INTEGER, DIMENSION(2) :: ksizex 
    687    INTEGER, DIMENSION(ksizex(1),ksizex(2)) :: kg  
    688       !!---------------------------------------------------------------------- 
    689    ! 
    690    RETURN 
    691    ! 
    692 END SUBROUTINE Agrif_detect 
    693  
    694  
    695 SUBROUTINE agrif_nemo_init 
     699      INTEGER, DIMENSION(2) :: ksizex 
     700      INTEGER, DIMENSION(ksizex(1),ksizex(2)) :: kg  
     701      !!---------------------------------------------------------------------- 
     702      ! 
     703      RETURN 
     704      ! 
     705   END SUBROUTINE Agrif_detect 
     706 
     707   SUBROUTINE agrif_nemo_init 
    696708      !!---------------------------------------------------------------------- 
    697709      !!                     *** ROUTINE agrif_init *** 
    698710      !!---------------------------------------------------------------------- 
    699    USE agrif_oce  
    700    USE agrif_ice 
    701    USE in_out_manager 
    702    USE lib_mpp 
    703    !! 
    704    IMPLICIT NONE 
    705    ! 
    706    INTEGER  ::   ios                 ! Local integer output status for namelist read 
    707    INTEGER  ::   iminspon 
    708    NAMELIST/namagrif/ rn_sponge_tra, rn_sponge_dyn, ln_spc_dyn, ln_chk_bathy 
     711      USE agrif_oce  
     712      USE agrif_ice 
     713      USE in_out_manager 
     714      USE lib_mpp 
     715      !! 
     716      IMPLICIT NONE 
     717      ! 
     718      INTEGER  ::   ios                 ! Local integer output status for namelist read 
     719      NAMELIST/namagrif/ ln_agrif_2way, rn_sponge_tra, rn_sponge_dyn, rn_trelax_tra, rn_trelax_dyn, & 
     720                       & ln_spc_dyn, ln_chk_bathy 
    709721      !!-------------------------------------------------------------------------------------- 
    710    ! 
    711    READ  ( numnam_ref, namagrif, IOSTAT = ios, ERR = 901) 
     722      ! 
     723      READ  ( numnam_ref, namagrif, IOSTAT = ios, ERR = 901) 
    712724901 IF( ios /= 0 )   CALL ctl_nam ( ios , 'namagrif in reference namelist' ) 
    713    READ  ( numnam_cfg, namagrif, IOSTAT = ios, ERR = 902 ) 
     725      READ  ( numnam_cfg, namagrif, IOSTAT = ios, ERR = 902 ) 
    714726902 IF( ios >  0 )   CALL ctl_nam ( ios , 'namagrif in configuration namelist' ) 
    715    IF(lwm) WRITE ( numond, namagrif ) 
    716    ! 
    717    IF(lwp) THEN                    ! control print 
    718       WRITE(numout,*) 
    719       WRITE(numout,*) 'agrif_nemo_init : AGRIF parameters' 
    720       WRITE(numout,*) '~~~~~~~~~~~~~~~' 
    721       WRITE(numout,*) '   Namelist namagrif : set AGRIF parameters' 
    722       WRITE(numout,*) '      sponge coefficient for tracers    rn_sponge_tra = ', rn_sponge_tra, ' s' 
    723       WRITE(numout,*) '      sponge coefficient for dynamics   rn_sponge_tra = ', rn_sponge_dyn, ' s' 
    724       WRITE(numout,*) '      use special values for dynamics   ln_spc_dyn    = ', ln_spc_dyn 
    725       WRITE(numout,*) '      check bathymetry                  ln_chk_bathy  = ', ln_chk_bathy 
    726    ENDIF 
    727    ! 
    728    ! convert DOCTOR namelist name into OLD names 
    729    visc_tra      = rn_sponge_tra 
    730    visc_dyn      = rn_sponge_dyn 
    731    ! 
    732    ! Check sponge length: 
    733    iminspon = MIN(FLOOR(REAL(jpiglo-4)/REAL(2*Agrif_irhox())), FLOOR(REAL(jpjglo-4)/REAL(2*Agrif_irhox())) ) 
    734    IF (lk_mpp) iminspon = MIN(iminspon,FLOOR(REAL(jpi-2)/REAL(Agrif_irhox())), FLOOR(REAL(jpj-2)/REAL(Agrif_irhox())) ) 
    735    IF (nn_sponge_len > iminspon)  CALL ctl_stop('agrif sponge length is too large') 
    736    ! 
    737    IF( agrif_oce_alloc()  > 0 )   CALL ctl_warn('agrif agrif_oce_alloc: allocation of arrays failed') 
    738    ! 
    739 END SUBROUTINE agrif_nemo_init 
     727      IF(lwm) WRITE ( numond, namagrif ) 
     728      ! 
     729      IF(lwp) THEN                    ! control print 
     730         WRITE(numout,*) 
     731         WRITE(numout,*) 'agrif_nemo_init : AGRIF parameters' 
     732         WRITE(numout,*) '~~~~~~~~~~~~~~~' 
     733         WRITE(numout,*) '   Namelist namagrif : set AGRIF parameters' 
     734         WRITE(numout,*) '      Two way nesting activated ln_agrif_2way         = ', ln_agrif_2way 
     735         WRITE(numout,*) '      sponge coefficient for tracers    rn_sponge_tra = ', rn_sponge_tra, ' m^2/s' 
     736         WRITE(numout,*) '      sponge coefficient for dynamics   rn_sponge_tra = ', rn_sponge_dyn, ' m^2/s' 
     737         WRITE(numout,*) '      time relaxation for tracers       rn_trelax_tra = ', rn_trelax_tra, ' ad.' 
     738         WRITE(numout,*) '      time relaxation for dynamics      rn_trelax_dyn = ', rn_trelax_dyn, ' ad.' 
     739         WRITE(numout,*) '      use special values for dynamics   ln_spc_dyn    = ', ln_spc_dyn 
     740         WRITE(numout,*) '      check bathymetry                  ln_chk_bathy  = ', ln_chk_bathy 
     741      ENDIF 
     742      ! 
     743      ! 
     744      IF( agrif_oce_alloc()  > 0 )   CALL ctl_warn('agrif agrif_oce_alloc: allocation of arrays failed') 
     745      ! 
     746   END SUBROUTINE agrif_nemo_init 
    740747 
    741748# if defined key_mpp_mpi 
    742749 
    743 SUBROUTINE Agrif_InvLoc( indloc, nprocloc, i, indglob ) 
     750   SUBROUTINE Agrif_InvLoc( indloc, nprocloc, i, indglob ) 
    744751      !!---------------------------------------------------------------------- 
    745752      !!                     *** ROUTINE Agrif_InvLoc *** 
    746753      !!---------------------------------------------------------------------- 
    747    USE dom_oce 
    748    !! 
    749    IMPLICIT NONE 
    750    ! 
    751    INTEGER :: indglob, indloc, nprocloc, i 
    752       !!---------------------------------------------------------------------- 
    753    ! 
    754    SELECT CASE( i ) 
    755    CASE(1)   ;   indglob = indloc + nimppt(nprocloc+1) - 1 
    756    CASE(2)   ;   indglob = indloc + njmppt(nprocloc+1) - 1 
    757    CASE DEFAULT 
    758       indglob = indloc 
    759    END SELECT 
    760    ! 
    761 END SUBROUTINE Agrif_InvLoc 
    762  
    763  
    764 SUBROUTINE Agrif_get_proc_info( imin, imax, jmin, jmax ) 
     754      USE dom_oce 
     755      !! 
     756      IMPLICIT NONE 
     757      ! 
     758      INTEGER :: indglob, indloc, nprocloc, i 
     759      !!---------------------------------------------------------------------- 
     760      ! 
     761      SELECT CASE( i ) 
     762      CASE(1)   ;   indglob = indloc + nimppt(nprocloc+1) - 1 
     763      CASE(2)   ;   indglob = indloc + njmppt(nprocloc+1) - 1 
     764      CASE DEFAULT 
     765         indglob = indloc 
     766      END SELECT 
     767      ! 
     768   END SUBROUTINE Agrif_InvLoc 
     769 
     770   SUBROUTINE Agrif_get_proc_info( imin, imax, jmin, jmax ) 
    765771      !!---------------------------------------------------------------------- 
    766772      !!                 *** ROUTINE Agrif_get_proc_info *** 
    767773      !!---------------------------------------------------------------------- 
    768    USE par_oce 
    769    !! 
    770    IMPLICIT NONE 
    771    ! 
    772    INTEGER, INTENT(out) :: imin, imax 
    773    INTEGER, INTENT(out) :: jmin, jmax 
    774       !!---------------------------------------------------------------------- 
    775    ! 
    776    imin = nimppt(Agrif_Procrank+1)  ! ????? 
    777    jmin = njmppt(Agrif_Procrank+1)  ! ????? 
    778    imax = imin + jpi - 1 
    779    jmax = jmin + jpj - 1 
    780    !  
    781 END SUBROUTINE Agrif_get_proc_info 
    782  
    783  
    784 SUBROUTINE Agrif_estimate_parallel_cost(imin, imax,jmin, jmax, nbprocs, grid_cost) 
     774      USE par_oce 
     775      !! 
     776      IMPLICIT NONE 
     777      ! 
     778      INTEGER, INTENT(out) :: imin, imax 
     779      INTEGER, INTENT(out) :: jmin, jmax 
     780      !!---------------------------------------------------------------------- 
     781      ! 
     782      imin = nimppt(Agrif_Procrank+1)  ! ????? 
     783      jmin = njmppt(Agrif_Procrank+1)  ! ????? 
     784      imax = imin + jpi - 1 
     785      jmax = jmin + jpj - 1 
     786      !  
     787   END SUBROUTINE Agrif_get_proc_info 
     788 
     789   SUBROUTINE Agrif_estimate_parallel_cost(imin, imax,jmin, jmax, nbprocs, grid_cost) 
    785790      !!---------------------------------------------------------------------- 
    786791      !!                 *** ROUTINE Agrif_estimate_parallel_cost *** 
    787792      !!---------------------------------------------------------------------- 
    788    USE par_oce 
    789    !! 
    790    IMPLICIT NONE 
    791    ! 
    792    INTEGER,  INTENT(in)  :: imin, imax 
    793    INTEGER,  INTENT(in)  :: jmin, jmax 
    794    INTEGER,  INTENT(in)  :: nbprocs 
    795    REAL(wp), INTENT(out) :: grid_cost 
    796       !!---------------------------------------------------------------------- 
    797    ! 
    798    grid_cost = REAL(imax-imin+1,wp)*REAL(jmax-jmin+1,wp) / REAL(nbprocs,wp) 
    799    ! 
    800 END SUBROUTINE Agrif_estimate_parallel_cost 
     793      USE par_oce 
     794      !! 
     795      IMPLICIT NONE 
     796      ! 
     797      INTEGER,  INTENT(in)  :: imin, imax 
     798      INTEGER,  INTENT(in)  :: jmin, jmax 
     799      INTEGER,  INTENT(in)  :: nbprocs 
     800      REAL(wp), INTENT(out) :: grid_cost 
     801      !!---------------------------------------------------------------------- 
     802      ! 
     803      grid_cost = REAL(imax-imin+1,wp)*REAL(jmax-jmin+1,wp) / REAL(nbprocs,wp) 
     804      ! 
     805   END SUBROUTINE Agrif_estimate_parallel_cost 
    801806 
    802807# endif 
    803808 
    804809#else 
    805 SUBROUTINE Subcalledbyagrif 
     810   SUBROUTINE Subcalledbyagrif 
    806811      !!---------------------------------------------------------------------- 
    807812      !!                   *** ROUTINE Subcalledbyagrif *** 
    808813      !!---------------------------------------------------------------------- 
    809    WRITE(*,*) 'Impossible to be here' 
    810 END SUBROUTINE Subcalledbyagrif 
     814      WRITE(*,*) 'Impossible to be here' 
     815   END SUBROUTINE Subcalledbyagrif 
    811816#endif 
Note: See TracChangeset for help on using the changeset viewer.