Index: /trunk/NEMO/OPA_SRC/DIA/diafwb.F90
===================================================================
--- /trunk/NEMO/OPA_SRC/DIA/diafwb.F90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/DIA/diafwb.F90	(revision 389)
@@ -202,5 +202,5 @@
          END SELECT
          ! 
-      ENDIF
+      
       DO jk = 1, 18 
          zt = 0.5 * ( tn(ji,jj,jk) + tn(ji+1,jj,jk) )
@@ -218,4 +218,5 @@
          ENDIF
       END DO
+      ENDIF
       
       ! Mean flow at Cadiz
@@ -242,5 +243,5 @@
          END SELECT
          ! 
-      ENDIF
+      
       DO jk = 1, 23 
          zt = 0.5 * ( tn(ji,jj,jk) + tn(ji+1,jj,jk) )
@@ -258,4 +259,5 @@
          ENDIF
       END DO
+      ENDIF
 
       ! Mean flow at Red Sea entrance
@@ -282,5 +284,5 @@
          END SELECT
          ! 
-      ENDIF
+      
       DO jk = 1, 15 
          zt = 0.5 * ( tn(ji,jj,jk) + tn(ji+1,jj,jk) )
@@ -298,4 +300,5 @@
          ENDIF
       END DO
+      ENDIF
 
       ! Mean flow at Baltic Sea entrance
@@ -322,5 +325,5 @@
          END SELECT
          ! 
-      ENDIF
+      
       DO jk = 1, 20
          zt = 0.5 * ( tn(ji,jj,jk) + tn(ji+1,jj,jk) )
@@ -338,4 +341,5 @@
          ENDIF
       END DO
+      ENDIF
 
       ! Sum at each time-step
Index: /trunk/NEMO/OPA_SRC/DIA/diaptr.F90
===================================================================
--- /trunk/NEMO/OPA_SRC/DIA/diaptr.F90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/DIA/diaptr.F90	(revision 389)
@@ -88,8 +88,15 @@
       !! * local declarations
       INTEGER  ::   ji, jj, jk        ! dummy loop arguments
+#if ! defined key_AGRIF
       INTEGER  ::   ijpj = jpj        ! ???
+#else
+      INTEGER  ::   ijpj             ! ???
+#endif      
       REAL(wp),DIMENSION(jpj) ::   &
          p_fval                       ! function value
       !!--------------------------------------------------------------------
+#if defined key_AGRIF
+      ijpj = jpj
+#endif      
 
       p_fval(:) = 0.e0
@@ -129,8 +136,15 @@
       !! * local declarations
       INTEGER  ::   ji,jj             ! dummy loop arguments
+#if ! defined key_AGRIF
       INTEGER  ::   ijpj = jpj        ! ???
+#else
+      INTEGER  ::   ijpj             ! ???
+#endif      
       REAL(wp),DIMENSION(jpj) ::   &
          p_fval                       ! function value
       !!--------------------------------------------------------------------
+#if defined key_AGRIF
+      ijpj = jpj
+#endif      
  
       p_fval(:) = 0.e0
Index: /trunk/NEMO/OPA_SRC/DIA/diawri.F90
===================================================================
--- /trunk/NEMO/OPA_SRC/DIA/diawri.F90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/DIA/diawri.F90	(revision 389)
@@ -120,4 +120,5 @@
       REAL(wp), DIMENSION(jpi,jpj) :: &
          zw2d                            ! temporary workspace
+      CHARACTER (len=80) :: clname
       !!----------------------------------------------------------------------
       
@@ -172,5 +173,6 @@
          ! WRITE root name in date.file for use by postpro
          CALL dia_nam( clhstnam, nwrite,' ' )
-         CALL ctlopn( inum, 'date.file', 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL', 1, numout, lwp, 1 )
+         clname = 'date.file'
+         CALL ctlopn( inum, clname,  'UNKNOWN', 'FORMATTED', 'SEQUENTIAL', 1, numout, lwp, 1 )
          WRITE(inum,*) clhstnam
          CLOSE(inum)
Index: /trunk/NEMO/OPA_SRC/DIA/diawri_dimg.h90
===================================================================
--- /trunk/NEMO/OPA_SRC/DIA/diawri_dimg.h90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/DIA/diawri_dimg.h90	(revision 389)
@@ -272,5 +272,5 @@
          &   .OR.       kindic <   0            &
          &   .OR. ( kt == 1 .AND. kindic > 0)  ) THEN
-       OPEN (14,FILE='datrj.out',FORM='FORMATTED', STATUS='UNKNOWN',POSITION='APPEND ')
+       OPEN (14,FILE='datrj.out',FORM='FORMATTED', STATUS='UNKNOWN',POSITION='APPEND')
 
        IF (lwp) WRITE(14,'(f10.4,1x,i8)') adatrj, ndastp
Index: /trunk/NEMO/OPA_SRC/DOM/dom_oce.F90
===================================================================
--- /trunk/NEMO/OPA_SRC/DOM/dom_oce.F90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/DOM/dom_oce.F90	(revision 389)
@@ -197,4 +197,12 @@
       !                        ! parameterize exchanges through straits
 
-   !!----------------------------------------------------------------------
+#if defined key_AGRIF
+   !!----------------------------------------------------------------------
+   !! agrif sponge layer
+   !!----------------------------------------------------------------------
+      LOGICAL :: spongedoneT = .FALSE.
+      REAL(wp), DIMENSION(jpi,jpj) :: zspe1ur, zspe2vr ,zspbtr2
+   !!----------------------------------------------------------------------
+#endif
+
 END MODULE dom_oce
Index: /trunk/NEMO/OPA_SRC/DOM/domain.F90
===================================================================
--- /trunk/NEMO/OPA_SRC/DOM/domain.F90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/DOM/domain.F90	(revision 389)
@@ -97,4 +97,5 @@
       hu(:,:) = 0.
       hv(:,:) = 0.
+
       DO jk = 1, jpk
          hu(:,:) = hu(:,:) + fse3u(:,:,jk) * umask(:,:,jk)
@@ -104,8 +105,10 @@
       hur(:,:) = fse3u(:,:,1)             ! Lower bound : thickness of the first model level
       hvr(:,:) = fse3v(:,:,1)
+      
       DO jk = 2, jpk                      ! Sum of the vertical scale factors
          hur(:,:) = hur(:,:) + fse3u(:,:,jk) * umask(:,:,jk)
          hvr(:,:) = hvr(:,:) + fse3v(:,:,jk) * vmask(:,:,jk)
       END DO
+
       ! Compute and mask the inverse of the local depth
       hur(:,:) = 1. / hur(:,:) * umask(:,:,1)
@@ -137,6 +140,6 @@
       !! * Modules used
       USE ioipsl
-      NAMELIST/namrun/ no    , cexper   , ln_rstart , nrstdt , nit000,          &
-         &             nitend, ndate0   , nleapy   , ninist , nstock,           &
+      NAMELIST/namrun/ no    , cexper   , ln_rstart , nrstdt , nit000,         &
+         &             nitend, ndate0   , nleapy   , ninist , nstock,          &
          &             nprint, nwrite   , nrunoff  , ln_ctl , nictls, nictle,   &
          &             njctls, njctle   , nbench   , isplt  , jsplt
@@ -261,4 +264,7 @@
       ENDIF
 
+#if defined key_AGRIF
+      if ( Agrif_Root() ) then
+#endif
       SELECT CASE ( nleapy )   ! Choose calendar for IOIPSL
       CASE (  1 ) 
@@ -272,4 +278,7 @@
          IF(lwp) WRITE(numout,*) '           The IOIPSL calendar is "360d", i.e. 360 days in a year'
       END SELECT
+#if defined key_AGRIF
+      endif
+#endif
 
       SELECT CASE ( nleapy )   ! year=raajj*days day=rjjhh*hours hour=rhhmm*minutes etc ...
Index: /trunk/NEMO/OPA_SRC/DOM/domhgr.F90
===================================================================
--- /trunk/NEMO/OPA_SRC/DOM/domhgr.F90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/DOM/domhgr.F90	(revision 389)
@@ -110,4 +110,6 @@
          zlam1, zcos_alpha, zim1 , zjm1 , ze1, ze1deg,   &
          zphi1, zsin_alpha, zim05, zjm05
+         
+         real,dimension(:,:),pointer :: ffparent
       !!----------------------------------------------------------------------
 
@@ -233,4 +235,13 @@
          glam0 = 0.e0
          gphi0 = - ppe2_m * 1.e-3
+         
+#if defined key_AGRIF && defined key_eel_r6
+         IF (.Not.Agrif_Root()) THEN
+           glam0  = Agrif_Parent(glam0) + (Agrif_ix())*Agrif_Parent(ppe1_m) * 1.e-3
+           gphi0  = Agrif_Parent(gphi0) + (Agrif_iy())*Agrif_Parent(ppe2_m) * 1.e-3
+           ppe1_m = Agrif_Parent(ppe1_m)/Agrif_Rhox()
+           ppe2_m = Agrif_Parent(ppe2_m)/Agrif_Rhoy()          
+         ENDIF
+#endif         
          DO jj = 1, jpj
             DO ji = 1, jpi
@@ -422,8 +433,14 @@
          zbeta   = 2. * omega * COS( rad * ppgphi0 ) / ra                       ! beta at latitude ppgphi0
          zphi0   = ppgphi0 - FLOAT( jpjglo/2) * ppe2_m / ( ra * rad )           ! latitude of the first row F-points
+         
+#if defined key_AGRIF && defined key_eel_r6
+         IF (.Not.Agrif_Root()) THEN
+           zphi0 = ppgphi0 - FLOAT( Agrif_Parent(jpjglo)/2)*Agrif_Parent(ppe2_m) / (ra * rad)
+         ENDIF
+#endif         
          zf0     = 2. * omega * SIN( rad * zphi0 )                              ! compute f0 1st point south
 
          ff(:,:) = ( zf0  + zbeta * gphif(:,:) * 1.e+3 )                        ! f = f0 +beta* y ( y=0 at south)
-       
+         
          IF(lwp) WRITE(numout,*) 
          IF(lwp) WRITE(numout,*) ' Beta-plane: Beta parameter = constant = ', ff(1,1)
@@ -486,5 +503,5 @@
       !! * Local declarations
       LOGICAL ::   llog = .FALSE.
-      CHARACTER(len=21) ::   clname = 'coordinates'
+      CHARACTER(len=21) ::   clname
       INTEGER  ::   ji, jj              ! dummy loop indices
       INTEGER  ::   inum                ! temporary logical unit
@@ -495,4 +512,10 @@
          zlamt, zphit, zdta             ! temporary workspace (NetCDF read)
       !!----------------------------------------------------------------------
+      clname = 'coordinates'
+#if defined key_AGRIF
+      if ( .NOT. Agrif_Root() ) then
+         clname = TRIM(Agrif_CFixed())//'_'//TRIM(clname)
+      endif
+#endif         
 
 
@@ -515,5 +538,5 @@
          &                  itime , zdate0, zdt   , inum, domain_id=nidom )
 
-      CALL restget( inum, 'glamt', jpidta, jpjdta, 1, 0, llog, zdta )
+      CALL restget( inum, 'glamt', jpidta, jpjdta, 1, itime, llog, zdta )
       DO jj = 1, nlcj
          DO ji = 1, nlci
@@ -521,5 +544,5 @@
          END DO
       END DO
-      CALL restget( inum, 'glamu', jpidta, jpjdta, 1, 0, llog, zdta )
+      CALL restget( inum, 'glamu', jpidta, jpjdta, 1, itime, llog, zdta )
       DO jj = 1, nlcj
          DO ji = 1, nlci
@@ -527,5 +550,5 @@
          END DO
       END DO
-      CALL restget( inum, 'glamv', jpidta, jpjdta, 1, 0, llog, zdta )
+      CALL restget( inum, 'glamv', jpidta, jpjdta, 1, itime, llog, zdta )
       DO jj = 1, nlcj
          DO ji = 1, nlci
@@ -533,5 +556,5 @@
          END DO
       END DO
-      CALL restget( inum, 'glamf', jpidta, jpjdta, 1, 0, llog, zdta )
+      CALL restget( inum, 'glamf', jpidta, jpjdta, 1, itime, llog, zdta )
       DO jj = 1, nlcj
          DO ji = 1, nlci
@@ -539,5 +562,5 @@
          END DO
       END DO
-      CALL restget( inum, 'gphit', jpidta, jpjdta, 1, 0, llog, zdta )
+      CALL restget( inum, 'gphit', jpidta, jpjdta, 1, itime, llog, zdta )
       DO jj = 1, nlcj
          DO ji = 1, nlci
@@ -545,5 +568,5 @@
          END DO
       END DO
-      CALL restget( inum, 'gphiu', jpidta, jpjdta, 1, 0, llog, zdta )
+      CALL restget( inum, 'gphiu', jpidta, jpjdta, 1, itime, llog, zdta )
       DO jj = 1, nlcj
          DO ji = 1, nlci
@@ -551,5 +574,5 @@
          END DO
       END DO
-      CALL restget( inum, 'gphiv', jpidta, jpjdta, 1, 0, llog, zdta )
+      CALL restget( inum, 'gphiv', jpidta, jpjdta, 1, itime, llog, zdta )
       DO jj = 1, nlcj
          DO ji = 1, nlci
@@ -557,5 +580,5 @@
          END DO
       END DO
-      CALL restget( inum, 'gphif', jpidta, jpjdta, 1, 0, llog, zdta )
+      CALL restget( inum, 'gphif', jpidta, jpjdta, 1, itime, llog, zdta )
       DO jj = 1, nlcj
          DO ji = 1, nlci
@@ -563,5 +586,5 @@
          END DO
       END DO
-      CALL restget( inum, 'e1t', jpidta, jpjdta, 1, 0, llog, zdta )
+      CALL restget( inum, 'e1t', jpidta, jpjdta, 1, itime, llog, zdta )
       DO jj = 1, nlcj
          DO ji = 1, nlci
@@ -569,5 +592,5 @@
          END DO
       END DO
-      CALL restget( inum, 'e1u', jpidta, jpjdta, 1, 0, llog, zdta )
+      CALL restget( inum, 'e1u', jpidta, jpjdta, 1, itime, llog, zdta )
       DO jj = 1, nlcj
          DO ji = 1, nlci
@@ -575,5 +598,5 @@
          END DO
       END DO
-      CALL restget( inum, 'e1v', jpidta, jpjdta, 1, 0, llog, zdta )
+      CALL restget( inum, 'e1v', jpidta, jpjdta, 1, itime, llog, zdta )
       DO jj = 1, nlcj
          DO ji = 1, nlci
@@ -581,5 +604,5 @@
          END DO
       END DO
-      CALL restget( inum, 'e1f', jpidta, jpjdta, 1, 0, llog, zdta )
+      CALL restget( inum, 'e1f', jpidta, jpjdta, 1, itime, llog, zdta )
       DO jj = 1, nlcj
          DO ji = 1, nlci
@@ -587,5 +610,5 @@
          END DO
       END DO
-      CALL restget( inum, 'e2t', jpidta, jpjdta, 1, 0, llog, zdta )
+      CALL restget( inum, 'e2t', jpidta, jpjdta, 1, itime, llog, zdta )
       DO jj = 1, nlcj
          DO ji = 1, nlci
@@ -593,5 +616,5 @@
          END DO
       END DO
-      CALL restget( inum, 'e2u', jpidta, jpjdta, 1, 0, llog, zdta )
+      CALL restget( inum, 'e2u', jpidta, jpjdta, 1, itime, llog, zdta )
       DO jj = 1, nlcj
          DO ji = 1, nlci
@@ -599,5 +622,5 @@
          END DO
       END DO
-      CALL restget( inum, 'e2v', jpidta, jpjdta, 1, 0, llog, zdta )
+      CALL restget( inum, 'e2v', jpidta, jpjdta, 1, itime, llog, zdta )
       DO jj = 1, nlcj
          DO ji = 1, nlci
@@ -605,5 +628,5 @@
          END DO
       END DO
-      CALL restget( inum, 'e2f', jpidta, jpjdta, 1, 0, llog, zdta )
+      CALL restget( inum, 'e2f', jpidta, jpjdta, 1, itime, llog, zdta )
       DO jj = 1, nlcj
          DO ji = 1, nlci
Index: /trunk/NEMO/OPA_SRC/DOM/domwri.F90
===================================================================
--- /trunk/NEMO/OPA_SRC/DOM/domwri.F90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/DOM/domwri.F90	(revision 389)
@@ -87,9 +87,9 @@
 
       CHARACTER (len=21) ::      &
-         clnam0 = 'mesh_mask',   &  ! filename (mesh and mask informations)
-         clnam1 = 'mesh'     ,   &  ! filename (mesh informations)
-         clnam2 = 'mask'     ,   &  ! filename (mask informations)
-         clnam3 = 'mesh_hgr' ,   &  ! filename (horizontal mesh informations)
-         clnam4 = 'mesh_zgr'        ! filename (vertical   mesh informations)
+         clnam0  ,   &  ! filename (mesh and mask informations)
+         clnam1  ,   &  ! filename (mesh informations)
+         clnam2  ,   &  ! filename (mask informations)
+         clnam3  ,   &  ! filename (horizontal mesh informations)
+         clnam4         ! filename (vertical   mesh informations)
       !!----------------------------------------------------------------------
 
@@ -97,4 +97,20 @@
        IF(lwp) WRITE(numout,*) 'dom_wri : create NetCDF mesh and mask information file(s)'
        IF(lwp) WRITE(numout,*) '~~~~~~~'
+
+         clnam0 = 'mesh_mask'  ! filename (mesh and mask informations)
+         clnam1 = 'mesh'       ! filename (mesh informations)
+         clnam2 = 'mask'       ! filename (mask informations)
+         clnam3 = 'mesh_hgr'   ! filename (horizontal mesh informations)
+         clnam4 = 'mesh_zgr'   ! filename (vertical   mesh informations)
+
+#if defined key_AGRIF
+      if ( .NOT. Agrif_Root() ) then
+        clnam0 = TRIM(Agrif_CFixed())//'_'//TRIM(clnam0)
+        clnam1 = TRIM(Agrif_CFixed())//'_'//TRIM(clnam1)
+        clnam2 = TRIM(Agrif_CFixed())//'_'//TRIM(clnam2)
+        clnam3 = TRIM(Agrif_CFixed())//'_'//TRIM(clnam3)
+        clnam4 = TRIM(Agrif_CFixed())//'_'//TRIM(clnam4)
+      endif
+#endif
 
       CALL ymds2ju( 0, 1, 1, 0.e0, zdate0 )    ! calendar initialization
Index: /trunk/NEMO/OPA_SRC/DOM/domzgr.F90
===================================================================
--- /trunk/NEMO/OPA_SRC/DOM/domzgr.F90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/DOM/domzgr.F90	(revision 389)
@@ -289,5 +289,5 @@
 
       !! * Local declarations
-      CHARACTER (len=15) ::   clname    ! temporary characters
+      CHARACTER (len=18) ::   clname    ! temporary characters
       LOGICAL ::   llbon                ! check the existence of bathy files
       INTEGER ::   ji, jj, jl, jk       ! dummy loop indices
@@ -380,5 +380,4 @@
          !  EEL R5 configuration with east and west open boundaries.
          !  Two rows of zeroes are needed at the south and north for OBCs
-         !  This is for compatibility with the rigid lid option. 
           
          IF( cp_cfg == "eel" .AND. jp_cfg == 5 ) THEN
@@ -390,50 +389,63 @@
       ELSEIF( ntopo == 1 ) THEN                       !   read in file  !
          !                                            ! =============== !
-         IF( lk_zco ) THEN
-            clname = 'bathy_level.nc'                       ! Level bathymetry
-            INQUIRE( FILE=clname, EXIST=llbon )
-            IF( llbon ) THEN
-               IF(lwp) WRITE(numout,*)
-               IF(lwp) WRITE(numout,*) '         read level bathymetry in ', clname
-               IF(lwp) WRITE(numout,*)
-               itime = 1
-               ipi = jpidta
-               ipj = jpjdta
-               ipk = 1
-               zdt = rdt
-               CALL flinopen( clname, 1, jpidta, 1, jpjdta, .FALSE.,   &
-                              ipi, ipj, ipk, zlamt, zphit, zdept, itime, istep, zdate0, zdt, inum )
-               CALL flinget( inum, 'Bathy_level', jpidta, jpjdta, 1,   &
-                             itime, 1, 1, 1, jpidta, 1, jpjdta, zdta(:,:) )
-               idta(:,:) = zdta(:,:)
-               CALL flinclo( inum )
-
-            ELSE
-               IF(lwp) WRITE(numout,cform_err)
-               IF(lwp) WRITE(numout,*)'    zgr_bat : unable to read the file', clname
-               nstop = nstop + 1
-            ENDIF   
-  
-         ELSEIF( lk_zps ) THEN
-            clname = 'bathy_meter.nc'                       ! meter bathymetry
-            INQUIRE( FILE=clname, EXIST=llbon )
-            IF( llbon ) THEN
-               IF(lwp) WRITE(numout,*)
-               IF(lwp) WRITE(numout,*) '         read meter bathymetry in ', clname
-               IF(lwp) WRITE(numout,*)
-               itime = 1
-               ipi = jpidta
-               ipj = jpjdta
-               ipk = 1
-               zdt = rdt
-               CALL flinopen( clname, 1, jpidta, 1, jpjdta, .FALSE.,   &    
-                              ipi, ipj, ipk, zlamt, zphit, zdept, itime, istep, zdate0, zdt, inum )
-               CALL flinget( inum, 'Bathymetry', jpidta, jpjdta, 1,   &
-                             itime, 1, 1, 1, jpidta, 1, jpjdta, zdta(:,:) ) 
-               CALL flinclo( inum )
-            ELSE
+
+         clname = 'bathy_level.nc'                       ! Level bathymetry
+#if defined key_AGRIF
+      if ( .NOT. Agrif_Root() ) then
+         clname = TRIM(Agrif_CFixed())//'_'//TRIM(clname)
+      endif
+#endif         
+         INQUIRE( FILE=clname, EXIST=llbon )
+         IF( llbon ) THEN
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) '         read level bathymetry in ', clname
+            IF(lwp) WRITE(numout,*)
+            itime = 1
+            ipi = jpidta
+            ipj = jpjdta
+            ipk = 1
+            zdt = rdt
+            CALL flinopen( clname, 1, jpidta, 1, jpjdta, .FALSE.,   &
+                           ipi, ipj, ipk, zlamt, zphit, zdept, itime, istep, zdate0, zdt, inum )
+            CALL flinget( inum, 'Bathy_level', jpidta, jpjdta, 1,   &
+                          itime, 1, 1, 1, jpidta, 1, jpjdta, zdta(:,:) )
+            idta(:,:) = zdta(:,:)
+            CALL flinclo( inum )
+
+         ELSE
+            IF(lwp) WRITE(numout,cform_err)
+            IF(lwp) WRITE(numout,*)'    zgr_bat : unable to read the file', clname
+            nstop = nstop + 1
+         ENDIF     
+
+         clname = 'bathy_meter.nc'                       ! meter bathymetry
+#if defined key_AGRIF
+      if ( .NOT. Agrif_Root() ) then
+         clname = TRIM(Agrif_CFixed())//'_'//TRIM(clname)
+      endif
+#endif   	 
+         INQUIRE( FILE=clname, EXIST=llbon )
+         IF( llbon ) THEN
+            IF(lwp) WRITE(numout,*)
+            IF(lwp) WRITE(numout,*) '         read meter bathymetry in ', clname
+            IF(lwp) WRITE(numout,*)
+            itime = 1
+            ipi = jpidta
+            ipj = jpjdta
+            ipk = 1
+            zdt = rdt
+            CALL flinopen( clname, 1, jpidta, 1, jpjdta, .FALSE.,   &    
+                           ipi, ipj, ipk, zlamt, zphit, zdept, itime, istep, zdate0, zdt, inum )
+            CALL flinget( inum, 'Bathymetry', jpidta, jpjdta, 1,   &
+                          itime, 1, 1, 1, jpidta, 1, jpjdta, zdta(:,:) ) 
+            CALL flinclo( inum )
+         ELSE
+            IF( lk_zps .OR. lk_sco ) THEN
                IF(lwp) WRITE(numout,cform_err)       
                IF(lwp) WRITE(numout,*)'    zgr_bat : unable to read the file', clname
                nstop = nstop + 1
+            ELSE
+               zdta(:,:) = 0.e0
+               IF(lwp) WRITE(numout,*)'    zgr_bat : bathy_meter not found, but not used, bathy array set to zero'
             ENDIF
          ENDIF
@@ -593,92 +605,94 @@
       IF( .NOT. lk_cfg_1d )   THEN
 
-         ! Suppress isolated ocean grid points
-
+      ! Suppress isolated ocean grid points
+
+      IF(lwp) WRITE(numout,*)
+      IF(lwp) WRITE(numout,*)'                   suppress isolated ocean grid points'
+      IF(lwp) WRITE(numout,*)'                   -----------------------------------'
+
+      icompt = 0
+      
+      DO jl = 1, 2
+
+         IF( nperio == 1 .OR. nperio  ==  4 .OR. nperio  ==  6 ) THEN
+            mbathy( 1 ,:) = mbathy(jpim1,:)
+            mbathy(jpi,:) = mbathy(  2  ,:)
+         ENDIF
+         DO jj = 2, jpjm1
+            DO ji = 2, jpim1
+               ibtest = MAX( mbathy(ji-1,jj), mbathy(ji+1,jj),   &
+                  mbathy(ji,jj-1),mbathy(ji,jj+1) )
+               IF( ibtest < mbathy(ji,jj) ) THEN
+                  IF(lwp) WRITE(numout,*) ' the number of ocean level at ',   &
+                     'grid-point (i,j) =  ',ji,jj,' is changed from ',   &
+                     mbathy(ji,jj),' to ', ibtest
+                  mbathy(ji,jj) = ibtest
+                  icompt = icompt + 1
+               ENDIF
+            END DO
+         END DO
+
+      END DO
+      IF( icompt == 0 ) THEN
+         IF(lwp) WRITE(numout,*)'     no isolated ocean grid points'
+      ELSE
+         IF(lwp) WRITE(numout,*)'    ',icompt,' ocean grid points suppressed'
+      ENDIF
+      IF( lk_mpp ) THEN
+         zbathy(:,:) = FLOAT( mbathy(:,:) )
+         CALL lbc_lnk( zbathy, 'T', 1. )
+         mbathy(:,:) = INT( zbathy(:,:) )
+      ENDIF
+
+      ! 3.2 East-west cyclic boundary conditions
+
+      IF( nperio == 0 ) THEN
+         IF(lwp) WRITE(numout,*) ' mbathy set to 0 along east and west',   &
+            ' boundary: nperio = ', nperio
+         IF( lk_mpp ) THEN
+            IF( nbondi == -1 .OR. nbondi == 2 ) THEN
+               IF( jperio /= 1 )   mbathy(1,:) = 0
+            ENDIF
+            IF( nbondi == 1 .OR. nbondi == 2 ) THEN
+               IF( jperio /= 1 )   mbathy(nlci,:) = 0
+            ENDIF
+         ELSE
+            mbathy( 1 ,:) = 0
+            mbathy(jpi,:) = 0
+         ENDIF
+      ELSEIF( nperio == 1 .OR. nperio == 4 .OR. nperio ==  6 ) THEN
+         IF(lwp) WRITE(numout,*)' east-west cyclic boundary conditions',   &
+            ' on mbathy: nperio = ', nperio
+         mbathy( 1 ,:) = mbathy(jpim1,:)
+         mbathy(jpi,:) = mbathy(  2  ,:)
+      ELSEIF( nperio == 2 ) THEN
+         IF(lwp) WRITE(numout,*) '   equatorial boundary conditions',   &
+            ' on mbathy: nperio = ', nperio
+      ELSE
+         IF(lwp) WRITE(numout,*) '    e r r o r'
+         IF(lwp) WRITE(numout,*) '    parameter , nperio = ', nperio
+         !         STOP 'dom_mba'
+      ENDIF
+
+      ! Set to zero mbathy over islands if necessary  (lk_isl=F)
+      IF( .NOT. lk_isl ) THEN    ! No island
          IF(lwp) WRITE(numout,*)
-         IF(lwp) WRITE(numout,*)'                   suppress isolated ocean grid points'
-         IF(lwp) WRITE(numout,*)'                   -----------------------------------'
-
-         icompt = 0
-
-         DO jl = 1, 2
-
-            IF( nperio == 1 .OR. nperio  ==  4 .OR. nperio  ==  6 ) THEN
-               mbathy( 1 ,:) = mbathy(jpim1,:)
-               mbathy(jpi,:) = mbathy(  2  ,:)
-            ENDIF
-            DO jj = 2, jpjm1
-               DO ji = 2, jpim1
-                  ibtest = MAX( mbathy(ji-1,jj), mbathy(ji+1,jj),   &
-                     mbathy(ji,jj-1),mbathy(ji,jj+1) )
-                  IF( ibtest < mbathy(ji,jj) ) THEN
-                     IF(lwp) WRITE(numout,*) ' the number of ocean level at ',   &
-                        'grid-point (i,j) =  ',ji,jj,' is changed from ',   &
-                        mbathy(ji,jj),' to ', ibtest
-                     mbathy(ji,jj) = ibtest
-                     icompt = icompt + 1
-                  ENDIF
-               END DO
-            END DO
-
-         END DO
-         IF( icompt == 0 ) THEN
-            IF(lwp) WRITE(numout,*)'     no isolated ocean grid points'
-         ELSE
-            IF(lwp) WRITE(numout,*)'    ',icompt,' ocean grid points suppressed'
-         ENDIF
-         IF( lk_mpp ) THEN
-            zbathy(:,:) = FLOAT( mbathy(:,:) )
+         IF(lwp) WRITE(numout,*) '         mbathy set to 0 over islands'
+         IF(lwp) WRITE(numout,*) '         ----------------------------'
+
+         mbathy(:,:) = MAX( 0, mbathy(:,:) )
+
+         !  Boundary condition on mbathy
+         IF( .NOT.lk_mpp ) THEN 
+            
+	    !!bug ???  y reflechir!
+            !   ... mono- or macro-tasking: T-point, >0, 2D array, no slab
+            
+	    zbathy(:,:) = FLOAT( mbathy(:,:) )
             CALL lbc_lnk( zbathy, 'T', 1. )
             mbathy(:,:) = INT( zbathy(:,:) )
          ENDIF
 
-         ! 3.2 East-west cyclic boundary conditions
-
-         IF( nperio == 0 ) THEN
-            IF(lwp) WRITE(numout,*) ' mbathy set to 0 along east and west',   &
-               ' boundary: nperio = ', nperio
-            IF( lk_mpp ) THEN
-               IF( nbondi == -1 .OR. nbondi == 2 ) THEN
-                  IF( jperio /= 1 )   mbathy(1,:) = 0
-               ENDIF
-               IF( nbondi == 1 .OR. nbondi == 2 ) THEN
-                  IF( jperio /= 1 )   mbathy(nlci,:) = 0
-               ENDIF
-            ELSE
-               mbathy( 1 ,:) = 0
-               mbathy(jpi,:) = 0
-            ENDIF
-         ELSEIF( nperio == 1 .OR. nperio == 4 .OR. nperio ==  6 ) THEN
-            IF(lwp) WRITE(numout,*)' east-west cyclic boundary conditions',   &
-               ' on mbathy: nperio = ', nperio
-            mbathy( 1 ,:) = mbathy(jpim1,:)
-            mbathy(jpi,:) = mbathy(  2  ,:)
-         ELSEIF( nperio == 2 ) THEN
-            IF(lwp) WRITE(numout,*) '   equatorial boundary conditions',   &
-               ' on mbathy: nperio = ', nperio
-         ELSE
-            IF(lwp) WRITE(numout,*) '    e r r o r'
-            IF(lwp) WRITE(numout,*) '    parameter , nperio = ', nperio
-            !         STOP 'dom_mba'
-         ENDIF
-
-         ! Set to zero mbathy over islands if necessary  (lk_isl=F)
-         IF( .NOT. lk_isl ) THEN    ! No island
-            IF(lwp) WRITE(numout,*)
-            IF(lwp) WRITE(numout,*) '         mbathy set to 0 over islands'
-            IF(lwp) WRITE(numout,*) '         ----------------------------'
-
-            mbathy(:,:) = MAX( 0, mbathy(:,:) )
-
-            !  Boundary condition on mbathy
-            IF( .NOT.lk_mpp ) THEN 
-               !!bug ???  y reflechir!
-               !   ... mono- or macro-tasking: T-point, >0, 2D array, no slab
-               zbathy(:,:) = FLOAT( mbathy(:,:) )
-               CALL lbc_lnk( zbathy, 'T', 1. )
-               mbathy(:,:) = INT( zbathy(:,:) )
-            ENDIF
-
-         ENDIF
+      ENDIF
 
       ENDIF
Index: /trunk/NEMO/OPA_SRC/DOM/domzgr_zps.h90
===================================================================
--- /trunk/NEMO/OPA_SRC/DOM/domzgr_zps.h90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/DOM/domzgr_zps.h90	(revision 389)
@@ -397,23 +397,23 @@
    IF(lwp) THEN
       WRITE(numout,*) ' e3t lev 21 '
-      CALL prihre(e3t_ps(1,1,21),jpi,jpj,50,59,1,1,5,1,0.,numout)
+      CALL prihre(e3t_ps(:,:,21),jpi,jpj,50,59,1,1,5,1,0.,numout)
       WRITE(numout,*) ' e3w lev 21  '
-      CALL prihre(e3w_ps(1,1,21),jpi,jpj,50,59,1,1,5,1,0.,numout)
+      CALL prihre(e3w_ps(:,:,21),jpi,jpj,50,59,1,1,5,1,0.,numout)
       WRITE(numout,*) ' e3u lev 21  '
-      CALL prihre(e3u_ps(1,1,21),jpi,jpj,50,59,1,1,5,1,0.,numout)
+      CALL prihre(e3u_ps(:,:,21),jpi,jpj,50,59,1,1,5,1,0.,numout)
       WRITE(numout,*) ' e3v lev 21  '
-      CALL prihre(e3v_ps(1,1,21),jpi,jpj,50,59,1,1,5,1,0.,numout)
+      CALL prihre(e3v_ps(:,:,21),jpi,jpj,50,59,1,1,5,1,0.,numout)
       WRITE(numout,*) ' e3f lev 21  '
-      CALL prihre(e3f_ps(1,1,21),jpi,jpj,50,59,1,1,5,1,0.,numout)
+      CALL prihre(e3f_ps(:,:,21),jpi,jpj,50,59,1,1,5,1,0.,numout)
       WRITE(numout,*) ' e3t lev 22 '
-      CALL prihre(e3t_ps(1,1,22),jpi,jpj,50,59,1,1,5,1,0.,numout)
+      CALL prihre(e3t_ps(:,:,22),jpi,jpj,50,59,1,1,5,1,0.,numout)
       WRITE(numout,*) ' e3w lev 22  '
-      CALL prihre(e3w_ps(1,1,22),jpi,jpj,50,59,1,1,5,1,0.,numout)
+      CALL prihre(e3w_ps(:,:,22),jpi,jpj,50,59,1,1,5,1,0.,numout)
       WRITE(numout,*) ' e3u lev 22  '
-      CALL prihre(e3u_ps(1,1,22),jpi,jpj,50,59,1,1,5,1,0.,numout)
+      CALL prihre(e3u_ps(:,:,22),jpi,jpj,50,59,1,1,5,1,0.,numout)
       WRITE(numout,*) ' e3v lev 22  '
-      CALL prihre(e3v_ps(1,1,22),jpi,jpj,50,59,1,1,5,1,0.,numout)
+      CALL prihre(e3v_ps(:,:,22),jpi,jpj,50,59,1,1,5,1,0.,numout)
       WRITE(numout,*) ' e3f lev 22  '
-      CALL prihre(e3f_ps(1,1,22),jpi,jpj,50,59,1,1,5,1,0.,numout)
+      CALL prihre(e3f_ps(:,:,22),jpi,jpj,50,59,1,1,5,1,0.,numout)
    ENDIF
 
Index: /trunk/NEMO/OPA_SRC/DTA/dtasal.F90
===================================================================
--- /trunk/NEMO/OPA_SRC/DTA/dtasal.F90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/DTA/dtasal.F90	(revision 389)
@@ -121,4 +121,9 @@
          
          clname = 'data_1m_salinity_nomask'
+#if defined key_AGRIF
+         if ( .NOT. Agrif_Root() ) then
+            clname = TRIM(Agrif_CFixed())//'_'//TRIM(clname)
+         endif
+#endif          
          CALL flinopen(TRIM(clname),mig(1),nlci,mjg(1),nlcj,.FALSE.   &
               ,ipi,ipj,ipk,zlon,zlat,zlev,itime,istep,zdate0,rdt,numsdt)
@@ -270,9 +275,9 @@
             WRITE(numout,*)
             WRITE(numout,*) ' Levitus month = ',nsal1,'  level = 1'
-            CALL prihre(saldta(1,1,1,1),jpi,jpj,1,jpi,20,1,jpj,20,1.,numout)
+            CALL prihre(saldta(:,:,1,1),jpi,jpj,1,jpi,20,1,jpj,20,1.,numout)
             WRITE(numout,*) ' Levitus month = ',nsal1,'  level = ',jpk/2
-            CALL prihre(saldta(1,1,jpk/2,1),jpi,jpj,1,jpi,20,1,jpj,20,1.,numout)
+            CALL prihre(saldta(:,:,jpk/2,1),jpi,jpj,1,jpi,20,1,jpj,20,1.,numout)
             WRITE(numout,*) ' Levitus month = ',nsal1,'  level = ',jpkm1
-            CALL prihre(saldta(1,1,jpkm1,1),jpi,jpj,1,jpi,20,1,jpj,20,1.,numout)
+            CALL prihre(saldta(:,:,jpkm1,1),jpi,jpj,1,jpi,20,1,jpj,20,1.,numout)
          ENDIF
       ENDIF
Index: /trunk/NEMO/OPA_SRC/DTA/dtasst.F90
===================================================================
--- /trunk/NEMO/OPA_SRC/DTA/dtasst.F90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/DTA/dtasst.F90	(revision 389)
@@ -91,7 +91,12 @@
       REAL(wp) ::   zlon(jpi,jpj), zlat(jpi,jpj), zlev(jpk)
       CHARACTER (len=45) ::   &
-         clname = "sst_1d.nc"      ! filename for daily SST
+         clname       ! filename for daily SST
       !!----------------------------------------------------------------------
-
+         clname = 'sst_1d.nc'
+#if defined key_AGRIF
+      if ( .NOT. Agrif_Root() ) then
+         clname = TRIM(Agrif_CFixed())//'_'//TRIM(clname)
+      endif
+#endif         
       IF( kt == nit000 ) THEN
          IF(lwp) WRITE(numout,*)
Index: /trunk/NEMO/OPA_SRC/DTA/dtatem.F90
===================================================================
--- /trunk/NEMO/OPA_SRC/DTA/dtatem.F90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/DTA/dtatem.F90	(revision 389)
@@ -28,6 +28,6 @@
 
    !! * Module variables
-   CHARACTER (len=38) ::   &
-      cl_tdata = 'data_1m_potential_temperature_nomask '
+   CHARACTER (len=45) ::   &
+      cl_tdata
    INTEGER ::   &
       nlecte =  0,   &  ! switch for the first read
@@ -98,4 +98,11 @@
       !!----------------------------------------------------------------------
 
+      cl_tdata = 'data_1m_potential_temperature_nomask '
+
+#if defined key_AGRIF
+      if ( .NOT. Agrif_Root() ) then
+         cl_tdata = TRIM(Agrif_CFixed())//'_'//TRIM(cl_tdata)
+      endif
+#endif         
 
       ! 0. Initialization
@@ -262,9 +269,9 @@
             WRITE(numout,*)
             WRITE(numout,*) ' Levitus month = ', ntem1, '  level = 1'
-            CALL prihre( temdta(1,1,1,1), jpi, jpj, 1, jpi, 20, 1, jpj, 20, 1., numout )
+            CALL prihre( temdta(:,:,1,1), jpi, jpj, 1, jpi, 20, 1, jpj, 20, 1., numout )
             WRITE(numout,*) ' Levitus month = ', ntem1, '  level = ', jpk/2
-            CALL prihre( temdta(1,1,jpk/2,1), jpi, jpj, 1, jpi, 20, 1, jpj, 20, 1., numout )
+            CALL prihre( temdta(:,:,jpk/2,1), jpi, jpj, 1, jpi, 20, 1, jpj, 20, 1., numout )
             WRITE(numout,*) ' Levitus month = ',ntem1,'  level = ', jpkm1
-            CALL prihre( temdta(1,1,jpkm1,1), jpi, jpj, 1, jpi, 20, 1, jpj, 20, 1., numout )
+            CALL prihre( temdta(:,:,jpkm1,1), jpi, jpj, 1, jpi, 20, 1, jpj, 20, 1., numout )
          ENDIF
       ENDIF
Index: /trunk/NEMO/OPA_SRC/DYN/divcur.F90
===================================================================
--- /trunk/NEMO/OPA_SRC/DYN/divcur.F90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/DYN/divcur.F90	(revision 389)
@@ -117,5 +117,5 @@
                hdivn(ji,jj,jk) = (  e2u(ji,jj) * un(ji,jj,jk) - e2u(ji-1,jj  ) * un(ji-1,jj  ,jk)      &
                   &               + e1v(ji,jj) * vn(ji,jj,jk) - e1v(ji  ,jj-1) * vn(ji  ,jj-1,jk)  )   &
-                  &            / ( e1t(ji,jj) * e2t(ji,jj) )
+     &            / ( e1t(ji,jj) * e2t(ji,jj) )
 #endif
             END DO
@@ -130,4 +130,12 @@
          IF( lp_obc_south )   hdivn(nis0  :nis1  ,njs0  :njs1  ,jk) = 0.e0      ! south
 #endif         
+#if defined key_AGRIF
+         if ( .NOT. AGRIF_Root() ) then
+            IF ((nbondi ==  1).OR.(nbondi == 2)) hdivn(nlci-1 , :     ,jk) = 0.e0      ! east
+            IF ((nbondi == -1).OR.(nbondi == 2)) hdivn(2      , :     ,jk) = 0.e0      ! west
+            IF ((nbondj ==  1).OR.(nbondj == 2)) hdivn(:      ,nlcj-1 ,jk) = 0.e0      ! north
+            IF ((nbondj == -1).OR.(nbondj == 2)) hdivn(:      ,2      ,jk) = 0.e0      ! south
+         endif
+#endif       
 
          !                                             ! --------
@@ -326,4 +334,12 @@
          IF( lp_obc_south )   hdivn(nis0  :nis1  ,njs0  :njs1  ,jk) = 0.e0      ! south
 #endif         
+#if defined key_AGRIF
+         if ( .NOT. AGRIF_Root() ) then
+            IF ((nbondi ==  1).OR.(nbondi == 2)) hdivn(nlci-1 , :     ,jk) = 0.e0      ! east
+            IF ((nbondi == -1).OR.(nbondi == 2)) hdivn(2      , :     ,jk) = 0.e0      ! west
+            IF ((nbondj ==  1).OR.(nbondj == 2)) hdivn(:      ,nlcj-1 ,jk) = 0.e0      ! north
+            IF ((nbondj == -1).OR.(nbondj == 2)) hdivn(:      ,2      ,jk) = 0.e0      ! south
+         endif
+#endif       
          !                                             ! --------
          ! relative vorticity                          !   rot 
Index: /trunk/NEMO/OPA_SRC/DYN/dynnxt.F90
===================================================================
--- /trunk/NEMO/OPA_SRC/DYN/dynnxt.F90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/DYN/dynnxt.F90	(revision 389)
@@ -19,4 +19,6 @@
    USE lbclnk          ! lateral boundary condition (or mpp link)
    USE prtctl          ! Print control
+   USE agrif_opa_update
+   USE agrif_opa_interp
 
    IMPLICIT NONE
@@ -133,4 +135,14 @@
          !                                             ! ===============
 # endif
+# if defined key_AGRIF
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+      ! Update (ua,va) along open boundaries (only in the rigid-lid case)
+      CALL Agrif_dyn( kt )
+      !                                                ! ===============
+      DO jk = 1, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+# endif
 #endif
          ! Time filter and swap of dynamics arrays
@@ -166,4 +178,8 @@
       ENDIF
 
+#if defined key_AGRIF
+      IF (.NOT.Agrif_Root())    CALL Agrif_Update_Dyn( kt )
+#endif      
+
    END SUBROUTINE dyn_nxt
 
Index: /trunk/NEMO/OPA_SRC/DYN/dynspg_flt.F90
===================================================================
--- /trunk/NEMO/OPA_SRC/DYN/dynspg_flt.F90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/DYN/dynspg_flt.F90	(revision 389)
@@ -33,4 +33,5 @@
    USE prtctl          ! Print control
    USE in_out_manager  ! I/O manager
+   USE agrif_opa_interp
 
    IMPLICIT NONE
@@ -163,4 +164,5 @@
          END DO
       END DO
+
 #if defined key_obc
       ! Update velocities on each open boundary with the radiation algorithm
@@ -168,4 +170,10 @@
       ! Correction of the barotropic componant velocity to control the volume of the system
       CALL obc_vol( kt )
+#endif
+#if defined key_AGRIF
+      ! Update velocities on each coarse/fine interfaces
+
+      CALL Agrif_dyn( kt )
+
 #endif
 #if defined key_orca_r2
@@ -230,4 +238,23 @@
       ! applied the lateral boundary conditions
       IF( nsolv == 4 )   CALL lbc_lnk_e( gcb, c_solver_pt, 1. )   
+
+#if defined key_AGRIF
+
+       If (.NOT.AGRIF_ROOT()) THEN
+
+         ! add contribution of gradient of after barotropic transport divergence 
+        IF ((nbondi == -1).OR.(nbondi == 2)) gcb(3,:) = gcb(3,:) &
+                        -znugdt * z2dt*laplacu(2,:)*gcdprc(3,:)*hu(2,:)*e2u(2,:)
+        IF ((nbondi == 1).OR.(nbondi == 2))  gcb(nlci-2,:) = gcb(nlci-2,:) &
+                       +znugdt * z2dt*laplacu(nlci-2,:)*gcdprc(nlci-2,:)*hu(nlci-2,:)*e2u(nlci-2,:)
+        IF ((nbondj == -1).OR.(nbondj == 2)) gcb(:,3) = gcb(:,3) &
+                       -znugdt * z2dt*laplacv(:,2)*gcdprc(:,3)*hv(:,2)*e1v(:,2)
+        IF ((nbondj == 1).OR.(nbondj == 2))  gcb(:,nlcj-2) = gcb(:,nlcj-2) &
+                       +znugdt * z2dt*laplacv(:,nlcj-2)*gcdprc(:,nlcj-2)*hv(:,nlcj-2)*e1v(:,nlcj-2)
+
+       ENDIF
+
+#endif
+
 
       ! Relative precision (computation on one processor)
@@ -288,6 +315,15 @@
       END DO
 
-      ! Add the trends multiplied by z2dt to the after velocity
-      ! -------------------------------------------------------
+#if defined key_AGRIF      
+      IF (.NOT. Agrif_Root()) THEN
+      ! caution : grad D (fine) = grad D (coarse) at coarse/fine interface
+        IF ((nbondi == -1).OR.(nbondi == 2)) spgu(2,:) = znugdt * z2dt * laplacu(2,:) * umask(2,:,1)
+        IF ((nbondi == 1).OR.(nbondi == 2)) spgu(nlci-2,:) = znugdt * z2dt * laplacu(nlci-2,:) * umask(nlci-2,:,1)
+        IF ((nbondj == -1).OR.(nbondj == 2)) spgv(:,2) = znugdt * z2dt * laplacv(:,2) * vmask(:,2,1)
+        IF ((nbondj == 1).OR.(nbondj == 2)) spgv(:,nlcj-2) = znugdt * z2dt * laplacv(:,nlcj-2) * vmask(:,nlcj-2,1)
+      ENDIF
+#endif      
+      ! 7.  Add the trends multiplied by z2dt to the after velocity
+      ! -----------------------------------------------------------
       !     ( c a u t i o n : (ua,va) here are the after velocity not the
       !                       trend, the leap-frog time stepping will not
Index: /trunk/NEMO/OPA_SRC/OBC/obcdta.F90
===================================================================
--- /trunk/NEMO/OPA_SRC/OBC/obcdta.F90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/OBC/obcdta.F90	(revision 389)
@@ -1273,4 +1273,8 @@
      WRITE(*,*) 'obc_dta: You should not have seen this print! error?', kt
    END SUBROUTINE obc_dta
+   SUBROUTINE obc_dta_bt( kt, jn)             ! Dummy routine
+     INTEGER, INTENT (in) :: kt, jn
+     WRITE(*,*) 'obc_dta_bt: You should not have seen this print! error?', kt
+   END SUBROUTINE obc_dta_bt
 #endif
 
Index: /trunk/NEMO/OPA_SRC/SBC/flx_bulk_daily.h90
===================================================================
--- /trunk/NEMO/OPA_SRC/SBC/flx_bulk_daily.h90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/SBC/flx_bulk_daily.h90	(revision 389)
@@ -79,7 +79,12 @@
       REAL(wp), DIMENSION(jpk) ::   zlev           ! ???
       CHARACTER(len=45)  ::  &
-         clname_n = 'tair_1d.nc',        &
-         clname_c = 'hum_cloud_1m.nc',   &
-         clname_x = 'rain_1m.nc',        &
+         clname_n ,        &
+         clname_c ,   &
+         clname_x ,        &
+         clname_w 
+      !!---------------------------------------------------------------------
+         clname_n = 'tair_1d.nc'
+         clname_c = 'hum_cloud_1m.nc'
+         clname_x = 'rain_1m.nc'
          clname_w = 'wspd_1d.nc'
       !!---------------------------------------------------------------------
Index: /trunk/NEMO/OPA_SRC/SBC/flx_bulk_monthly.h90
===================================================================
--- /trunk/NEMO/OPA_SRC/SBC/flx_bulk_monthly.h90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/SBC/flx_bulk_monthly.h90	(revision 389)
@@ -95,6 +95,7 @@
          zlon   , zlat                 ! ???
       CHARACTER (len=32) ::   &
-         clname = 'flx.nc'             ! flux filename
+         clname            ! flux filename
       !!---------------------------------------------------------------------
+         clname = 'flx.nc'
 
 
@@ -131,4 +132,9 @@
 
          ! title, dimensions and tests
+#if defined key_AGRIF
+      if ( .NOT. Agrif_Root() ) then
+         clname = TRIM(Agrif_CFixed())//'_'//TRIM(clname)
+      endif
+#endif 	 
          CALL flinopen( clname, mig(1), nlci, mjg(1), nlcj,   &
             &          .FALSE., ipi, ipj, ipk, zlon, zlat, zlev,   &
@@ -202,5 +208,5 @@
                WRITE(numout,*)
                WRITE(numout,*) 'Clio mounth: ',nflx1,'  field: ',jm,' multiply by ',0.1
-               CALL prihre(flxdta(1,1,1,jm),jpi,jpj,1,jpi,20,1,jpj,10,.1,numout)
+               CALL prihre(flxdta(:,:,1,jm),jpi,jpj,1,jpi,20,1,jpj,10,.1,numout)
             END DO
          ENDIF
@@ -269,5 +275,5 @@
                WRITE(numout,*) 'jpf =  ', jpf !C a u t i o n : information need for SX5NEC compilo bug
                WRITE(numout,*) 'Clio mounth: ',nflx11,'  field: ',jm,' multiply by ',0.1
-               CALL prihre(flxdta(1,1,1,jm),jpi,jpj,1,jpi,20,1,jpj,10,.1,numout)
+               CALL prihre(flxdta(:,:,1,jm),jpi,jpj,1,jpi,20,1,jpj,10,.1,numout)
                WRITE(numout,*)
             END DO
Index: /trunk/NEMO/OPA_SRC/SBC/flx_forced_daily.h90
===================================================================
--- /trunk/NEMO/OPA_SRC/SBC/flx_forced_daily.h90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/SBC/flx_forced_daily.h90	(revision 389)
@@ -118,9 +118,14 @@
          ! Close/open file if new year 
 
-         IF( nyearflx /= 0 )   CALL flinclo(numflx)
+         IF( nyearflx /= 0 .AND. kt /= nit000 )   CALL flinclo(numflx)
 
          iy = nyear
          IF(lwp) WRITE (numout,*) iy
          WRITE(clname,'("flx_1d.nc")') 
+#if defined key_AGRIF
+      if ( .NOT. Agrif_Root() ) then
+         clname = TRIM(Agrif_CFixed())//'_'//TRIM(clname)
+      endif
+#endif         
          IF(lwp) WRITE (numout,*)' open flx file = ',clname
          CALL FLUSH(numout)
@@ -172,11 +177,11 @@
                   WRITE(numout,*)
                   WRITE(numout,*) ' Q * .1, day: ',ndastp
-                  CALL prihre(flxdta(1,1,1),jpi,jpj,1,jpi,20,1,jpj,10,.1,numout)
+                  CALL prihre(flxdta(:,:,1),jpi,jpj,1,jpi,20,1,jpj,10,.1,numout)
                   WRITE(numout,*)
                   WRITE(numout,*) ' QSR * .1, day: ',ndastp
-                  CALL prihre(flxdta(1,1,2),jpi,jpj,1,jpi,20,1,jpj,10,.1,numout)
+                  CALL prihre(flxdta(:,:,2),jpi,jpj,1,jpi,20,1,jpj,10,.1,numout)
                   WRITE(numout,*)
                   WRITE(numout,*) ' E-P *86400, day: ',ndastp
-                  CALL prihre(flxdta(1,1,3),jpi,jpj,1,jpi,20,1,jpj,10,86400.,numout)
+                  CALL prihre(flxdta(:,:,3),jpi,jpj,1,jpi,20,1,jpj,10,86400.,numout)
                   WRITE(numout,*) ' '
                ENDIF
Index: /trunk/NEMO/OPA_SRC/SBC/flxrnf.F90
===================================================================
--- /trunk/NEMO/OPA_SRC/SBC/flxrnf.F90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/SBC/flxrnf.F90	(revision 389)
@@ -104,5 +104,5 @@
 # endif
       CHARACTER (len=32) ::   &
-         clname = 'runoff_1m_nomask'       ! monthly runoff filename
+         clname                            ! monthly runoff filename
       INTEGER, PARAMETER :: jpmois = 12
       INTEGER  ::   ipi, ipj, ipk          ! temporary integers
@@ -117,4 +117,5 @@
          zcoefr                            ! coeff of advection link to runoff
       !!----------------------------------------------------------------------
+         clname = 'runoff_1m_nomask'       ! monthly runoff filename
       
       IF( kt == nit000 ) THEN
@@ -266,9 +267,9 @@
          ! when reading the NetCDF file runoff_1m_nomask.nc
          IF( cp_cfg == 'orca' .AND. jp_cfg == 2 )   THEN
-            DO jj = 1, jpj
-               DO ji = 1, jpi
-                  IF( gphit(ji,jj) > 40 .AND. gphit(ji,jj) < 65 )   runoff(ji,jj) = 0.85 * runoff(ji,jj)
-               END DO
+         DO jj = 1, jpj
+            DO ji = 1, jpi
+               IF( gphit(ji,jj) > 40 .AND. gphit(ji,jj) < 65 )   runoff(ji,jj) = 0.85 * runoff(ji,jj)
             END DO
+         END DO
          ENDIF
          
Index: /trunk/NEMO/OPA_SRC/SBC/tau_forced_daily.h90
===================================================================
--- /trunk/NEMO/OPA_SRC/SBC/tau_forced_daily.h90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/SBC/tau_forced_daily.h90	(revision 389)
@@ -14,6 +14,6 @@
 
    CHARACTER (len=34) ::   &      !!! * monthly climatology/interanual fields
-      cl_taux = 'taux.nc',  & ! generic name of the i-component monthly NetCDF file
-      cl_tauy = 'tauy.nc'     ! generic name of the j-component monthly NetCDF file
+      cl_taux ,  & ! generic name of the i-component monthly NetCDF file
+      cl_tauy      ! generic name of the j-component monthly NetCDF file
    !!----------------------------------------------------------------------
    !!   OPA 9.0 , LOCEAN-IPSL (2005) 
@@ -67,4 +67,6 @@
       REAL(wp) ::   zsecond, zdate0
       !!---------------------------------------------------------------------
+      cl_taux = 'taux.nc'
+      cl_tauy = 'tauy.nc'
 
       ! -------------- !
@@ -91,4 +93,9 @@
          ENDIF
          ! title, dimensions and tests
+#if defined key_AGRIF
+      if ( .NOT. Agrif_Root() ) then
+         cl_taux = TRIM(Agrif_CFixed())//'_'//TRIM(cl_taux)
+      endif
+#endif
          
          CALL flinopen( cl_taux, mig(1), nlci, mjg(1), nlcj,   &   ! taux on U-grid
@@ -110,4 +117,9 @@
             nstop = nstop + 1
          ENDIF
+#if defined key_AGRIF
+      if ( .NOT. Agrif_Root() ) then
+         cl_tauy = TRIM(Agrif_CFixed())//'_'//TRIM(cl_tauy)
+      endif
+#endif
 
          CALL flinopen( cl_tauy, mig(1), nlci, mjg(1), nlcj,   &   ! tauy on V-grid
Index: /trunk/NEMO/OPA_SRC/SBC/tau_forced_monthly.h90
===================================================================
--- /trunk/NEMO/OPA_SRC/SBC/tau_forced_monthly.h90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/SBC/tau_forced_monthly.h90	(revision 389)
@@ -14,6 +14,6 @@
 
    CHARACTER (len=34) ::   &      !!! * monthly climatology/interanual fields
-      cl_taux = 'taux_1m.nc',  & ! generic name of the i-component monthly NetCDF file
-      cl_tauy = 'tauy_1m.nc'     ! generic name of the j-component monthly NetCDF file
+      cl_taux,  & ! generic name of the i-component monthly NetCDF file
+      cl_tauy     ! generic name of the j-component monthly NetCDF file
 
    REAL(wp), DIMENSION(jpi,jpj,2) ::   &
@@ -77,4 +77,6 @@
          zxy          ! coefficient of the linear time interpolation
       !!---------------------------------------------------------------------
+      cl_taux = 'taux_1m.nc'
+      cl_tauy = 'tauy_1m.nc'
 
       ! -------------- !
@@ -106,4 +108,10 @@
          
          ! title, dimensions and tests
+
+#if defined key_AGRIF
+      if ( .NOT. Agrif_Root() ) then
+         cl_taux = TRIM(Agrif_CFixed())//'_'//TRIM(cl_taux)
+      endif
+#endif
          
          CALL flinopen( cl_taux, mig(1), nlci, mjg(1), nlcj,   &   ! taux on U-grid
@@ -126,5 +134,9 @@
             nstop = nstop + 1
          ENDIF
-
+#if defined key_AGRIF
+      if ( .NOT. Agrif_Root() ) then
+         cl_tauy = TRIM(Agrif_CFixed())//'_'//TRIM(cl_tauy)
+      endif
+#endif
          CALL flinopen( cl_tauy, mig(1), nlci, mjg(1), nlcj,   &   ! tauy on V-grid
                         .FALSE., ipi   , ipj, ipk   ,        &
@@ -185,8 +197,8 @@
             WRITE(numout,*)
             WRITE(numout,*) ' month: ', ntau1, '  taux: 1 multiply by ', 1.
-            CALL prihre( taux_dta(1,1,1), jpi, jpj, 1, jpi, 20, 1, jpj, 10, 1., numout )
+            CALL prihre( taux_dta(:,:,1), jpi, jpj, 1, jpi, 20, 1, jpj, 10, 1., numout )
             WRITE(numout,*)
             WRITE(numout,*) ' month: ', ntau2, '  tauy: 2 multiply by ', 1.
-            CALL prihre( tauy_dta(1,1,2), jpi, jpj, 1, jpi, 20, 1, jpj, 10, 1., numout )
+            CALL prihre( tauy_dta(:,:,2), jpi, jpj, 1, jpi, 20, 1, jpj, 10, 1., numout )
          ENDIF
 
Index: /trunk/NEMO/OPA_SRC/SOL/sol_oce.F90
===================================================================
--- /trunk/NEMO/OPA_SRC/SOL/sol_oce.F90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/SOL/sol_oce.F90	(revision 389)
@@ -67,4 +67,8 @@
       gccd             !: vector such that ca.gccd=a.d (ca-1=gcdprc)
 
+#if defined key_AGRIF
+      REAL(wp), DIMENSION(jpi,jpj) :: laplacu, laplacv
+#endif
+
 #if defined key_feti
    !!----------------------------------------------------------------------
Index: /trunk/NEMO/OPA_SRC/SOL/solmat.F90
===================================================================
--- /trunk/NEMO/OPA_SRC/SOL/solmat.F90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/SOL/solmat.F90	(revision 389)
@@ -182,4 +182,55 @@
       
 !!cr  ENDIF
+#endif
+#if defined key_AGRIF
+       IF (.NOT.AGRIF_ROOT()) THEN
+       
+       IF ( (nbondi == -1)  .OR. (nbondi == 2) ) bmask(2,:)=0.
+       IF ( (nbondi ==  1)  .OR. (nbondi == 2) ) bmask(nlci-1,:)=0.
+       IF ( (nbondj == -1)  .OR. (nbondj == 2) ) bmask(:,2)=0.
+       IF ( (nbondj ==  1)  .OR. (nbondj == 2) ) bmask(:,nlcj-1)=0.
+
+      DO jj = 2, jpjm1
+         DO ji = 2, jpim1
+            zcoef = z2dt * z2dt * grav * rnu * bmask(ji,jj)
+            !  south coefficient
+            IF( ((nbondj == -1)  .OR. (nbondj == 2)) .AND. ( jj == 3 ) ) THEN
+               zcoefs = -zcoef * hv(ji,jj-1) * e1v(ji,jj-1)/e2v(ji,jj-1)*(1.-vmask(ji,jj-1,1))
+            ELSE
+               zcoefs = -zcoef * hv(ji,jj-1) * e1v(ji,jj-1)/e2v(ji,jj-1)
+            END IF
+            gcp(ji,jj,1) = zcoefs
+
+            !  west coefficient
+	    IF( ( (nbondi == -1)  .OR. (nbondi == 2) ) .AND. ( ji == 3 )  ) THEN
+               zcoefw = -zcoef * hu(ji-1,jj) * e2u(ji-1,jj)/e1u(ji-1,jj)*(1.-umask(ji-1,jj,1))
+            ELSE
+               zcoefw = -zcoef * hu(ji-1,jj) * e2u(ji-1,jj)/e1u(ji-1,jj)
+            END IF
+            gcp(ji,jj,2) = zcoefw
+
+            !   east coefficient
+            IF( ((nbondi == 1)  .OR. (nbondi == 2)) .AND. ( ji == nlci-2 ) ) THEN
+               zcoefe = -zcoef * hu(ji,jj) * e2u(ji,jj)/e1u(ji,jj)*(1.-umask(ji,jj,1))
+            ELSE
+               zcoefe = -zcoef * hu(ji,jj) * e2u(ji,jj)/e1u(ji,jj)
+            END IF
+            gcp(ji,jj,3) = zcoefe
+
+            !   north coefficient
+            IF( ((nbondj == 1)  .OR. (nbondj == 2)) .AND. ( jj == nlcj-2 ) ) THEN
+               zcoefn = -zcoef * hv(ji,jj) * e1v(ji,jj)/e2v(ji,jj)*(1.-vmask(ji,jj,1))
+            ELSE
+               zcoefn = -zcoef * hv(ji,jj) * e1v(ji,jj)/e2v(ji,jj)
+            END IF
+            gcp(ji,jj,4) = zcoefn
+
+            ! diagonal coefficient
+            gcdmat(ji,jj) = e1t(ji,jj)*e2t(ji,jj)*bmask(ji,jj) &
+                            - zcoefs -zcoefw -zcoefe -zcoefn
+         END DO
+      END DO
+      
+       ENDIF
 #endif
 
Index: /trunk/NEMO/OPA_SRC/SOL/solver.F90
===================================================================
--- /trunk/NEMO/OPA_SRC/SOL/solver.F90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/SOL/solver.F90	(revision 389)
@@ -79,4 +79,5 @@
       !! * Local declarations
       INTEGER :: ji, jj   ! dummy loop indices
+      CHARACTER(len=80) :: clname
 
       NAMELIST/namsol/ nsolv, nsol_arp, nmin, nmax, nmod, eps, resmax, sor, epsisl, nmisl, rnu
@@ -88,5 +89,6 @@
 
       ! open elliptic solver statistics file
-      CALL ctlopn( numsol, 'solver.stat', 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL',   &
+      clname = 'solver.stat'
+      CALL ctlopn( numsol, clname, 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL',   &
                    1, numout, lwp, 1 )
 
Index: /trunk/NEMO/OPA_SRC/TRA/trabbc.F90
===================================================================
--- /trunk/NEMO/OPA_SRC/TRA/trabbc.F90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/TRA/trabbc.F90	(revision 389)
@@ -189,4 +189,9 @@
          ! read the geothermal fluxes in mW/m2
          clname = 'geothermal_heating'
+#if defined key_AGRIF
+      if ( .NOT. Agrif_Root() ) then
+         clname = TRIM(Agrif_CFixed())//'_'//TRIM(clname)
+      endif
+#endif 	 
          itime = 1
          zlamt(:,:) = 0.
@@ -195,5 +200,5 @@
          CALL restini( clname, jpidta, jpjdta, zlamt, zphit, 1, zdept , 'NONE',   &
             &          itime, zdate0, zdt, inum, domain_id=nidom )
-         CALL restget( inum, 'heatflow', jpidta, jpjdta, 1, 0, .FALSE., zdta )
+         CALL restget( inum, 'heatflow', jpidta, jpjdta, 1, itime, .FALSE., zdta )
          DO jj = 1, nlcj
             DO ji = 1, nlci
Index: /trunk/NEMO/OPA_SRC/TRA/tradmp.F90
===================================================================
--- /trunk/NEMO/OPA_SRC/TRA/tradmp.F90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/TRA/tradmp.F90	(revision 389)
@@ -35,5 +35,9 @@
 
    !! * Shared module variables
-   LOGICAL , PUBLIC, PARAMETER ::   lk_tradmp = .TRUE.    !: internal damping flag
+   LOGICAL , PUBLIC &
+#if ! defined key_AGRIF
+   , PARAMETER  &
+#endif
+   ::   lk_tradmp = .TRUE.    !: internal damping flag
 
    REAL(wp), PUBLIC, DIMENSION(jpi,jpj,jpk) ::   &
Index: /trunk/NEMO/OPA_SRC/TRA/tranxt.F90
===================================================================
--- /trunk/NEMO/OPA_SRC/TRA/tranxt.F90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/TRA/tranxt.F90	(revision 389)
@@ -16,4 +16,6 @@
    USE obctra          ! open boundary condition (obc_tra routine)
    USE prtctl          ! Print control
+   USE agrif_opa_update
+   USE agrif_opa_interp
 
    IMPLICIT NONE
@@ -108,4 +110,16 @@
          !                                             ! ===============
 #endif
+#if defined key_AGRIF
+         !                                             ! ===============
+      END DO                                           !   End of slab
+      !                                                ! ===============
+
+      ! Update tracers on open boundaries.
+      CALL Agrif_tra( kt )
+
+      !                                                ! ===============
+      DO jk = 1, jpkm1                                 ! Horizontal slab
+         !                                             ! ===============
+#endif
 
 
@@ -170,4 +184,8 @@
             &         tab3d_2=sn, clinfo2=' Sn: ', mask2=tmask)
       ENDIF
+      
+#if defined key_AGRIF
+      IF (.NOT.Agrif_Root())    CALL Agrif_Update_Tra( kt )
+#endif      
 
    END SUBROUTINE tra_nxt
Index: /trunk/NEMO/OPA_SRC/istate.F90
===================================================================
--- /trunk/NEMO/OPA_SRC/istate.F90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/istate.F90	(revision 389)
@@ -330,4 +330,9 @@
             itime  = 0
             clname = 'eel.initemp'
+#if defined key_AGRIF
+      if ( .NOT. Agrif_Root() ) then
+         clname = TRIM(Agrif_CFixed())//'_'//TRIM(clname)
+      endif
+#endif                
             llog   = .FALSE.
             ilev   = jpk
Index: /trunk/NEMO/OPA_SRC/lib_isml.f90
===================================================================
--- /trunk/NEMO/OPA_SRC/lib_isml.f90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/lib_isml.f90	(revision 389)
@@ -118,5 +118,5 @@
       DIMENSION X(I)
       ISAMAX = 0
-      XMIN = -1e+50
+      XMIN = -huge(1.)
       DO N = 1, I
          IF(ABS(X(N)) > XMIN ) THEN
Index: /trunk/NEMO/OPA_SRC/lib_mpp.F90
===================================================================
--- /trunk/NEMO/OPA_SRC/lib_mpp.F90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/lib_mpp.F90	(revision 389)
@@ -95,5 +95,7 @@
    !!  MPI  variable definition !!
    !! ========================= !!
+!$AGRIF_DO_NOT_TREAT
 #  include <mpif.h>
+!$AGRIF_END_DO_NOT_TREAT
 
    INTEGER ::   &
@@ -286,12 +288,30 @@
       CASE ( 'S' )                ! Standard mpi send (blocking)
          WRITE(numout,*) '           Standard blocking mpi send (send)'
+#if defined key_AGRIF
+         IF ( Agrif_Root() ) THEN
+#endif      
          CALL mpi_init( ierr )
+#if defined key_AGRIF
+         ENDIF
+#endif	 
       CASE ( 'B' )                ! Buffer mpi send (blocking)
          WRITE(numout,*) '           Buffer blocking mpi send (bsend)'
+#if defined key_AGRIF
+         IF ( Agrif_Root() ) THEN
+#endif      
          CALL mpi_init_opa( ierr )
+#if defined key_AGRIF
+         ENDIF
+#endif	 
       CASE ( 'I' )                ! Immediate mpi send (non-blocking send)
          WRITE(numout,*) '           Immediate non-blocking send (isend)'
          l_isend = .TRUE.
+#if defined key_AGRIF
+         IF ( Agrif_Root() ) THEN
+#endif      
          CALL mpi_init( ierr )
+#if defined key_AGRIF
+         ENDIF
+#endif	 
       CASE DEFAULT
          WRITE(numout,cform_err)
@@ -4398,5 +4418,8 @@
    SUBROUTINE mpi_init_opa(code)
       IMPLICIT NONE
+
+!$AGRIF_DO_NOT_TREAT
 #     include <mpif.h>
+!$AGRIF_END_DO_NOT_TREAT
 
       INTEGER                                 :: code,rang
Index: /trunk/NEMO/OPA_SRC/mppini.F90
===================================================================
--- /trunk/NEMO/OPA_SRC/mppini.F90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/mppini.F90	(revision 389)
@@ -143,4 +143,5 @@
          iimppt, ijmppt, ilcit, ilcjt       ! temporary workspace
       REAL(wp) ::   zidom, zjdom            ! temporary scalars
+      CHARACTER(len=80) :: clname
       !!----------------------------------------------------------------------
 
@@ -350,6 +351,7 @@
        IF (lwp) THEN
         inum = 11    
-
-        OPEN(inum,FILE='layout.dat')
+        clname = 'layout.dat'
+        CALL ctlopn(inum, clname, 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL', 1, numout, lwp, 0)
+        
         WRITE(inum,'(6i8)') jpnij,jpi,jpj,jpk,jpiglo,jpjglo
         WRITE(inum,'(a)') 'NAREA nlci nlcj nldi nldj nlei nlej nimpp njmpp'
Index: /trunk/NEMO/OPA_SRC/mppini_2.h90
===================================================================
--- /trunk/NEMO/OPA_SRC/mppini_2.h90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/mppini_2.h90	(revision 389)
@@ -122,4 +122,9 @@
             clvar = 'Bathy_level'
          ENDIF
+#if defined key_AGRIF
+      if ( .NOT. Agrif_Root() ) then
+         clname = TRIM(Agrif_CFixed())//'_'//TRIM(clname)
+      endif
+#endif         
 
          INQUIRE( FILE=clname, EXIST=llbon )
@@ -588,5 +593,5 @@
          IF( ij == jpnj ) npolj = 5
       ENDIF
-      
+
       ! Prepare NetCDF output file (if necessary)
       CALL mpp_init_ioipsl
Index: /trunk/NEMO/OPA_SRC/opa.F90
===================================================================
--- /trunk/NEMO/OPA_SRC/opa.F90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/opa.F90	(revision 389)
@@ -60,4 +60,5 @@
    !! * Routine accessibility
    PUBLIC opa_model      ! called by model.F90
+   PUBLIC opa_init
    !!----------------------------------------------------------------------
    !!  OPA 9.0 , LOCEAN-IPSL (2005) 
@@ -105,139 +106,23 @@
       !! * Local declarations
       INTEGER ::   istp       ! time step index
-#if defined key_coupled
-      INTEGER ::   itro, istp0        ! ???
-#endif
       CHARACTER (len=64) ::        &
          cform_aaa="( /, 'AAAAAAAA', / ) "     ! flag for output listing
-      CHARACTER (len=28) :: file_out
-      !!----------------------------------------------------------------------
+      !!----------------------------------------------------------------------
+
+#if defined key_AGRIF
+
+      Call Agrif_Init_Grids()
+#endif
       
-      
-      ! Initializations
-      ! ===============
-
-      file_out = 'ocean.output'
-      
-      ! open listing and namelist units
-      IF ( numout /= 0 .AND. numout /= 6 ) THEN 
-         OPEN( UNIT=numout, FILE=TRIM(file_out), FORM='FORMATTED' )
-      ENDIF
-
-      OPEN( UNIT=numnam, FILE='namelist', FORM='FORMATTED', STATUS='OLD' )
-
-      WRITE(numout,*)
-      WRITE(numout,*) '                 L O D Y C - I P S L'
-      WRITE(numout,*) '                     O P A model'
-      WRITE(numout,*) '            Ocean General Circulation Model'
-      WRITE(numout,*) '               version OPA 9.0  (2005) '
-      WRITE(numout,*)
-      WRITE(numout,*)
-
-      ! Nodes selection
-      narea = mynode()
-      narea = narea + 1    ! mynode return the rank of proc (0 --> jpnij -1 )
-      lwp   = narea == 1
-
-      !                                     ! ============================== !
-      !                                     !  Model general initialization  !
-      !                                     ! ============================== !
-
-      IF(lwp) WRITE(numout,cform_aaa)       ! Flag AAAAAAA
-
-                                            ! Domain decomposition
-      IF( jpni*jpnj == jpnij ) THEN
-         CALL mpp_init                          ! standard cutting out
-      ELSE
-         CALL mpp_init2                         ! eliminate land processors
-      ENDIF
-      
-      CALL phy_cst                          ! Physical constants
-
-      CALL dom_cfg                          ! Domain configuration
-      
-      CALL dom_init                         ! Domain
-
-      IF( ln_ctl )      CALL prt_ctl_init   ! Print control
-
-      IF( lk_cfg_1d )   CALL fcorio_1d      ! redefine Coriolis at T-point
-
-      IF( lk_obc    )   CALL obc_init       ! Open boundaries 
-
-      IF( lk_dynspg_flt .OR. lk_dynspg_rl ) THEN
-         CALL solver_init                   ! Elliptic solver
-      ENDIF
-
-      CALL day( nit000 )                    ! Calendar
-
-      CALL istate_init                      ! ocean initial state (Dynamics and tracers)
-!!add
-                       CALL eos( tb, sb, rhd, rhop )        ! before potential and in situ densities
-
-                       CALL bn2( tb, sb, rn2 )              ! before Brunt-Vaisala frequency
-
-      IF( lk_zps .AND. .NOT. lk_cfg_1d )   &
-         &             CALL zps_hde( nit000, tb, sb, rhd,  &  ! Partial steps: before Horizontal DErivative
-                                            gtu, gsu, gru, &  ! of t, s, rd at the bottom ocean level
-                                            gtv, gsv, grv )
-
-!!add
-
-      CALL oc_fz_pt                         ! Surface freezing point
-
-#if defined key_ice_lim
-      CALL ice_init                         ! Sea ice model
-#endif
-
-      !                                     ! Ocean scheme
-
-      CALL opa_flg                              ! Choice of algorithms
-
-      !                                     ! Ocean physics
-
-      CALL tra_qsr_init                         ! Solar radiation penetration
-
-      CALL ldf_dyn_init                         ! Lateral ocean momentum physics
-
-      CALL ldf_tra_init                         ! Lateral ocean tracer physics
-
-      CALL zdf_init                             ! Vertical ocean physics
-
-      !                                     ! Ocean trends
-      ! Control parameters 
-      IF( lk_trdtra .OR. lk_trdmld )   l_trdtra = .TRUE.
-      IF( lk_trddyn .OR. lk_trdvor )   l_trddyn = .TRUE.
-
-      IF( lk_trddyn .OR. lk_trdtra )   &
-         &            CALL trd_icp_init         ! active tracers and/or momentum
-
-      IF( lk_trdmld ) CALL trd_mld_init         ! mixed layer
-
-      IF( lk_trdvor ) CALL trd_vor_init         ! vorticity
-
-#if defined key_passivetrc
-      CALL ini_trc                           ! Passive tracers
-#endif
-
-#if defined key_coupled
-      itro  = nitend - nit000 + 1           ! Coupled
-      istp0 = NINT( rdt )
-      CALL cpl_init( itro, nexco, istp0 )   ! Signal processing and process id exchange
-#endif
-
-      CALL flx_fwb_init                     ! FreshWater Budget correction
-
-      CALL dia_ptr_init                     ! Poleward TRansports initialization
-
-      !                                     ! =============== !
-      !                                     !  time stepping  !
-      !                                     ! =============== !
-
-      IF(lwp) WRITE(numout,cform_aaa)       ! Flag AAAAAAA
+      Call opa_init  ! Initializations
 
       IF( lk_cfg_1d  )  THEN 
-         CALL init_1d
          istp = nit000
          DO WHILE ( istp <= nitend .AND. nstop == 0 )
+#if defined key_AGRIF
+            CALL Agrif_Step(stp_1d)
+#else
             CALL stp_1d( istp )
+#endif
             istp = istp + 1
          END DO
@@ -245,5 +130,9 @@
          istp = nit000
          DO WHILE ( istp <= nitend .AND. nstop == 0 )
+#if defined key_AGRIF
+            CALL Agrif_Step(stp)
+#else
             CALL stp( istp )
+#endif
             istp = istp + 1
          END DO
@@ -346,3 +235,154 @@
 
    !!======================================================================
+   SUBROUTINE opa_init
+      !!----------------------------------------------------------------------
+      !!                     ***  ROUTINE opa_init  ***
+      !!
+      !! ** Purpose :   initialization of the opa model
+      !!
+      !! ** Method  : 
+      !!
+      !! References :
+      !!----------------------------------------------------------------------
+      !! * Local declarations
+
+#if defined key_coupled
+      INTEGER ::   itro, istp0        ! ???
+#endif
+      CHARACTER (len=64) ::        &
+         cform_aaa="( /, 'AAAAAAAA', / ) "     ! flag for output listing
+      CHARACTER (len=20) :: namelistname
+      CHARACTER (len=28) :: file_out
+      !!----------------------------------------------------------------------
+
+      ! Initializations
+      ! ===============
+
+      file_out = 'ocean.output'
+      
+      ! open listing and namelist units
+      IF ( numout /= 0 .AND. numout /= 6 ) THEN 
+         CALL ctlopn(numout,file_out,'UNKNOWN', 'FORMATTED',   &
+                      'SEQUENTIAL',1,numout,.FALSE.,1)
+!         OPEN( UNIT=numout, FILE=TRIM(file_out), FORM='FORMATTED' )
+      ENDIF
+
+      namelistname = 'namelist'
+      CALL ctlopn(numnam,namelistname,'OLD', 'FORMATTED', 'SEQUENTIAL',   &
+                     1,numout,.FALSE.,1)
+!!!!      OPEN( UNIT=numnam, FILE='namelist', FORM='FORMATTED', STATUS='OLD' )
+
+      WRITE(numout,*)
+      WRITE(numout,*) '                 L O D Y C - I P S L'
+      WRITE(numout,*) '                     O P A model'
+      WRITE(numout,*) '            Ocean General Circulation Model'
+      WRITE(numout,*) '               version OPA 9.0  (2005) '
+      WRITE(numout,*)
+      WRITE(numout,*)
+
+      ! Nodes selection
+      narea = mynode()
+      narea = narea + 1    ! mynode return the rank of proc (0 --> jpnij -1 )
+      lwp   = narea == 1
+
+      !                                     ! ============================== !
+      !                                     !  Model general initialization  !
+      !                                     ! ============================== !
+
+      IF(lwp) WRITE(numout,cform_aaa)       ! Flag AAAAAAA
+
+                                            ! Domain decomposition
+      IF( jpni*jpnj == jpnij ) THEN
+         CALL mpp_init                          ! standard cutting out
+      ELSE
+         CALL mpp_init2                         ! eliminate land processors
+      ENDIF
+      
+      CALL phy_cst                          ! Physical constants
+
+      CALL dom_cfg                          ! Domain configuration
+      
+      CALL dom_init                         ! Domain
+      IF( ln_ctl )      CALL prt_ctl_init   ! Print control
+
+      IF( lk_cfg_1d )   CALL fcorio_1d      ! redefine Coriolis at T-point
+
+      IF( lk_obc    )   CALL obc_init       ! Open boundaries 
+
+      IF( lk_dynspg_flt .OR. lk_dynspg_rl ) THEN
+      CALL solver_init                      ! Elliptic solver
+      ENDIF
+
+      CALL day( nit000 )                    ! Calendar
+
+      CALL istate_init                      ! ocean initial state (Dynamics and tracers)
+!!add
+                       CALL eos( tb, sb, rhd, rhop )        ! before potential and in situ densities
+
+                       CALL bn2( tb, sb, rn2 )              ! before Brunt-Vaisala frequency
+
+      IF( lk_zps .AND. .NOT. lk_cfg_1d )   &
+         &             CALL zps_hde( nit000, tb, sb, rhd,  &  ! Partial steps: before Horizontal DErivative
+                                            gtu, gsu, gru, &  ! of t, s, rd at the bottom ocean level
+                                            gtv, gsv, grv )
+
+!!add
+
+      CALL oc_fz_pt                         ! Surface freezing point
+
+#if defined key_ice_lim
+      CALL ice_init                         ! Sea ice model
+#endif
+
+      !                                     ! Ocean scheme
+
+      CALL opa_flg                              ! Choice of algorithms
+
+      !                                     ! Ocean physics
+
+      CALL tra_qsr_init                         ! Solar radiation penetration
+
+      CALL ldf_dyn_init                         ! Lateral ocean momentum physics
+
+      CALL ldf_tra_init                         ! Lateral ocean tracer physics
+
+      CALL zdf_init                             ! Vertical ocean physics
+
+      !                                     ! Ocean trends
+      ! Control parameters 
+      IF( lk_trdtra .OR. lk_trdmld )   l_trdtra = .TRUE.
+      IF( lk_trddyn .OR. lk_trdvor )   l_trddyn = .TRUE.
+
+      IF( lk_trddyn .OR. lk_trdtra )   &
+         &            CALL trd_icp_init         ! active tracers and/or momentum
+
+      IF( lk_trdmld ) CALL trd_mld_init         ! mixed layer
+
+      IF( lk_trdvor ) CALL trd_vor_init         ! vorticity
+
+#if defined key_passivetrc
+      CALL ini_trc                           ! Passive tracers
+#endif
+
+#if defined key_coupled
+      itro  = nitend - nit000 + 1           ! Coupled
+      istp0 = NINT( rdt )
+      CALL cpl_init( itro, nexco, istp0 )   ! Signal processing and process id exchange
+#endif
+
+      CALL flx_fwb_init                     ! FreshWater Budget correction
+
+      CALL dia_ptr_init                     ! Poleward TRansports initialization
+
+      !                                     ! =============== !
+      !                                     !  time stepping  !
+      !                                     ! =============== !
+
+      IF(lwp) WRITE(numout,cform_aaa)       ! Flag AAAAAAA
+
+      IF( lk_cfg_1d  )  THEN 
+         CALL init_1d
+      ENDIF
+   END SUBROUTINE opa_init
+   !!======================================================================
 END MODULE opa
Index: /trunk/NEMO/OPA_SRC/par_EEL_R2.h90
===================================================================
--- /trunk/NEMO/OPA_SRC/par_EEL_R2.h90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/par_EEL_R2.h90	(revision 389)
@@ -8,7 +8,15 @@
    !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
    !!----------------------------------------------------------------------
-   CHARACTER (len=16), PARAMETER ::   &  !:
+   CHARACTER (len=16)      &
+#if !defined key_AGRIF
+      , PARAMETER  &
+#endif
+      ::    &  
       cp_cfg = "eel"            !: name of the configuration
-   INTEGER, PARAMETER ::     &  !:
+   INTEGER     &
+#if !defined key_AGRIF
+      , PARAMETER  &
+#endif
+      :: &
       jp_cfg = 2   ,         &  !: resolution of the configuration (km)
 
Index: /trunk/NEMO/OPA_SRC/par_EEL_R5.h90
===================================================================
--- /trunk/NEMO/OPA_SRC/par_EEL_R5.h90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/par_EEL_R5.h90	(revision 389)
@@ -8,7 +8,15 @@
    !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
    !!----------------------------------------------------------------------
-   CHARACTER (len=16), PARAMETER ::   &  !:
+   CHARACTER (len=16)      &
+#if !defined key_AGRIF
+      , PARAMETER  &
+#endif
+      ::    &  
+   INTEGER     &
+#if !defined key_AGRIF
+      , PARAMETER  &
+#endif
+      :: &
       cp_cfg = "eel"            !: name of the configuration
-   INTEGER, PARAMETER ::     &  !:
       jp_cfg = 5      ,      &  !: resolution of the configuration (km)
 
Index: /trunk/NEMO/OPA_SRC/par_EEL_R6.h90
===================================================================
--- /trunk/NEMO/OPA_SRC/par_EEL_R6.h90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/par_EEL_R6.h90	(revision 389)
@@ -8,7 +8,15 @@
    !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
    !!----------------------------------------------------------------------
-   CHARACTER (len=16), PARAMETER ::   &  !:
+   CHARACTER (len=16)      &
+#if !defined key_AGRIF
+      , PARAMETER  &
+#endif
+      ::    &  
       cp_cfg = "eel"            !: name of the configuration
-   INTEGER, PARAMETER ::     &  !:
+   INTEGER     &
+#if !defined key_AGRIF
+      , PARAMETER  &
+#endif
+      ::     &
       jp_cfg = 6      ,      &  !: resolution of the configuration (km)
 
@@ -53,5 +61,9 @@
       !   The mercator grid starts only approximately at gphi0 because
       !   of the constraint that the equator be a T point.
-   REAL(wp) ,PARAMETER ::     &  !:
+   REAL(wp) &
+#if !defined key_AGRIF
+      , PARAMETER  &
+#endif
+      ::     &  !:
       ppglam0  =    0.0_wp,   &  !: longitude of first raw and column T-point (jphgr_msh = 1)
       ppgphi0  =   35.0_wp,   &  !: latitude  of first raw and column T-point (jphgr_msh = 1)
Index: /trunk/NEMO/OPA_SRC/par_GYRE.h90
===================================================================
--- /trunk/NEMO/OPA_SRC/par_GYRE.h90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/par_GYRE.h90	(revision 389)
@@ -8,7 +8,15 @@
    !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
    !!----------------------------------------------------------------------
-   CHARACTER (len=16), PARAMETER ::   &  !:
+   CHARACTER (len=16)      &
+#if !defined key_AGRIF
+      , PARAMETER  &
+#endif
+      ::    &  
       cp_cfg = "gyre"           !: name of the configuration
-   INTEGER, PARAMETER ::     &  !:
+   INTEGER     &
+#if !defined key_AGRIF
+      , PARAMETER  &
+#endif
+      :: &
       jp_cfg =  1   ,        &  !: 
 
Index: /trunk/NEMO/OPA_SRC/par_ORCA_R025.h90
===================================================================
--- /trunk/NEMO/OPA_SRC/par_ORCA_R025.h90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/par_ORCA_R025.h90	(revision 389)
@@ -9,7 +9,15 @@
    !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
    !!----------------------------------------------------------------------
-   CHARACTER (len=16), PARAMETER ::   &
+   CHARACTER (len=16)      &
+#if !defined key_AGRIF
+      , PARAMETER  &
+#endif
+      ::    &  
       cp_cfg = "orca"           !: name of the configuration
-   INTEGER, PARAMETER ::     &
+   INTEGER     &
+#if !defined key_AGRIF
+      , PARAMETER  &
+#endif
+      :: &
       jp_cfg = 025  ,        &  !: resolution of the configuration (degrees)
       ! Original data size
Index: /trunk/NEMO/OPA_SRC/par_ORCA_R05.h90
===================================================================
--- /trunk/NEMO/OPA_SRC/par_ORCA_R05.h90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/par_ORCA_R05.h90	(revision 389)
@@ -9,7 +9,15 @@
    !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
    !!----------------------------------------------------------------------
-   CHARACTER (len=16), PARAMETER ::   &
+   CHARACTER (len=16)      &
+#if !defined key_AGRIF
+      , PARAMETER  &
+#endif
+      ::    &  
       cp_cfg = "orca"           !: name of the configuration
-   INTEGER, PARAMETER ::     &
+   INTEGER     &
+#if !defined key_AGRIF
+      , PARAMETER  &
+#endif
+      :: &
       jp_cfg = 05  ,         &  !: resolution of the configuration (degrees)
 
@@ -20,6 +28,10 @@
 
 #if defined key_antarctic
-   INTEGER, PARAMETER ::     &
-      ! zoom domain size       !!! * antarctic zoom *
+      ! zoom domain size       !!! *  antarctic zoom  * 
+   INTEGER     &
+#if !defined key_AGRIF
+      , PARAMETER  &
+#endif
+      :: &
       jpiglo  = jpidta,      &  !: 1st dimension of global domain --> i
       jpjglo  = 187   ,      &  !: 2nd     "                 "    --> j 
@@ -34,5 +46,10 @@
 
 #elif defined key_arctic
-   INTEGER, PARAMETER ::     &
+      ! zoom domain size       !!! *  arctic zoom  *
+   INTEGER    &
+#if !defined key_AGRIF
+      , PARAMETER  &
+#endif
+      :: &
       ! zoom domain size       !!! *  arctic zoom  *
       jpiglo  = 562,         &  !: 1st dimension of global domain --> i
@@ -48,6 +65,10 @@
 
 #else
-   INTEGER, PARAMETER ::     &
-      ! global domain size     !!! * full domain *
+      ! global domain size     !!! *  global domain  *
+   INTEGER    &
+#if !defined key_AGRIF
+      , PARAMETER  &
+#endif
+      :: &
       jpiglo  = jpidta,      &  !: 1st dimension of global domain --> i
       jpjglo  = jpjdta,      &  !: 2nd     "                 "    --> j
Index: /trunk/NEMO/OPA_SRC/par_ORCA_R2.h90
===================================================================
--- /trunk/NEMO/OPA_SRC/par_ORCA_R2.h90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/par_ORCA_R2.h90	(revision 389)
@@ -9,7 +9,15 @@
    !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
    !!----------------------------------------------------------------------
-   CHARACTER (len=16), PARAMETER ::    &  
+   CHARACTER (len=16)      &
+#if !defined key_AGRIF
+      , PARAMETER  &
+#endif
+      ::    &  
       cp_cfg = "orca"           !: name of the configuration 
-   INTEGER, PARAMETER ::     &
+   INTEGER     &
+#if !defined key_AGRIF
+      , PARAMETER  &
+#endif
+      :: &
       jp_cfg = 2,            &  !: resolution of the configuration (degrees)
 
@@ -21,5 +29,9 @@
 #if defined key_antarctic
       ! zoom domain size       !!! *  antarctic zoom  * 
-   INTEGER, PARAMETER ::     &
+   INTEGER     &
+#if !defined key_AGRIF
+      , PARAMETER  &
+#endif
+      :: &
       jpiglo  = jpidta,      &  !: 1st dimension of global domain --> i
       jpjglo  = 50,          &  !: 2nd    "                  "    --> j
@@ -35,5 +47,9 @@
 #elif defined key_arctic
       ! zoom domain size       !!! *  arctic zoom  *
-   INTEGER, PARAMETER ::     &
+   INTEGER    &
+#if !defined key_AGRIF
+      , PARAMETER  &
+#endif
+      :: &
       jpiglo  = 142   ,      &  !: 1st dimension of global domain --> i
       jpjglo  = jpjdta-97+1, &  !: 2nd    "                  "    --> j
@@ -49,5 +65,9 @@
 #elif defined key_cfg_1d
       ! global domain size     !!! *  global domain  *
-   INTEGER, PARAMETER ::     &
+   INTEGER    &
+#if !defined key_AGRIF
+      , PARAMETER  &
+#endif
+      :: &
       jpiglo  = 3     ,      &  !: 1st dimension of global domain --> i
       jpjglo  = 3     ,      &  !: 2nd    "                  "    --> j
@@ -74,5 +94,9 @@
 #else
       ! global domain size     !!! *  global domain  *
-   INTEGER, PARAMETER ::     &
+   INTEGER    &
+#if !defined key_AGRIF
+      , PARAMETER  &
+#endif
+      :: &
       jpiglo  = jpidta,      &  !: 1st dimension of global domain --> i
       jpjglo  = jpjdta,      &  !: 2nd    "                  "    --> j
@@ -85,4 +109,5 @@
       jpisl   =  18   ,      &  !: number of islands
       jpnisl  = 800             !: maximum number of points per island
+
 #endif
 
Index: /trunk/NEMO/OPA_SRC/par_ORCA_R4.h90
===================================================================
--- /trunk/NEMO/OPA_SRC/par_ORCA_R4.h90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/par_ORCA_R4.h90	(revision 389)
@@ -9,7 +9,15 @@
    !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt 
    !!----------------------------------------------------------------------
-   CHARACTER (len=16), PARAMETER ::    &
-      cp_cfg = "orca"           !: name of the configuration
-   INTEGER, PARAMETER ::     &
+   CHARACTER (len=16)      &
+#if !defined key_AGRIF
+      , PARAMETER  &
+#endif
+       ::    &  
+     cp_cfg = "orca"           !: name of the configuration
+   INTEGER     &
+#if !defined key_AGRIF
+      , PARAMETER  &
+#endif
+      :: &
       jp_cfg = 4      ,      &  !: resolution of the configuration (degrees)
       ! Original data size
Index: /trunk/NEMO/OPA_SRC/par_oce.F90
===================================================================
--- /trunk/NEMO/OPA_SRC/par_oce.F90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/par_oce.F90	(revision 389)
@@ -168,5 +168,9 @@
    !! Domain Matrix size
    !!---------------------------------------------------------------------
-   INTEGER, PUBLIC, PARAMETER ::   &  !:
+   INTEGER  &  !:
+#if !defined key_AGRIF
+      ,PARAMETER  &
+#endif
+    :: &
       jpi = ( jpiglo-2*jpreci + (jpni-1) ) / jpni + 2*jpreci ,   &  !: first  dimension
       jpj = ( jpjglo-2*jprecj + (jpnj-1) ) / jpnj + 2*jprecj ,   &  !: second dimension
@@ -176,4 +180,12 @@
       jpij  = jpi*jpj                                               !:  jpi x jpj
 
+#if defined key_AGRIF
+   !!---------------------------------------------------------------------
+   !! Agrif variables
+   !!---------------------------------------------------------------------
+   INTEGER, PUBLIC, PARAMETER :: nbghostcells = 1
+   INTEGER, PUBLIC :: nbcellsx = jpiglo - 2 - 2*nbghostcells
+   INTEGER, PUBLIC :: nbcellsy = jpjglo - 2 - 2*nbghostcells
+#endif
    !!---------------------------------------------------------------------
    !! Optimization/control flags
Index: /trunk/NEMO/OPA_SRC/restart.F90
===================================================================
--- /trunk/NEMO/OPA_SRC/restart.F90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/restart.F90	(revision 389)
@@ -88,4 +88,7 @@
       REAL(wp), DIMENSION(10) ::   zinfo(10)
       REAL(wp), DIMENSION(jpi,jpj) :: ztab 
+#if defined key_AGRIF
+       Integer :: knum
+#endif
       !!----------------------------------------------------------------------
 
@@ -124,6 +127,12 @@
          INQUIRE( FILE=crestart, EXIST=llbon )
          IF(llbon) THEN
+#if defined key_AGRIF
+       knum =Agrif_Get_Unit()
+            OPEN( UNIT=knum, FILE=crestart, STATUS='old' )
+            CLOSE( knum, STATUS='delete' )
+#else            
             OPEN( UNIT=numwrs, FILE=crestart, STATUS='old' )
             CLOSE( numwrs, STATUS='delete' )
+#endif
          ENDIF
 
@@ -247,5 +256,5 @@
       LOGICAL ::   llog
       CHARACTER (len=8 ) ::   clvnames(50)
-      CHARACTER (len=32) ::   clname = 'restart'
+      CHARACTER (len=32) ::   clname
       INTEGER  ::   &
          itime, ibvar,     &  !
@@ -265,4 +274,9 @@
       !!  OPA 8.5, LODYC-IPSL (2002)
       !!----------------------------------------------------------------------
+      clname = 'restart'
+#if defined key_AGRIF       
+       inum = Agrif_Get_Unit()
+       If(.NOT. Agrif_root() ) clname = TRIM(Agrif_CFixed())//'_'//TRIM(clname)
+#endif 
 
       IF(lwp) WRITE(numout,*)
Index: /trunk/NEMO/OPA_SRC/restart_dimg.h90
===================================================================
--- /trunk/NEMO/OPA_SRC/restart_dimg.h90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/restart_dimg.h90	(revision 389)
@@ -62,4 +62,8 @@
        irecl8= jpi * jpj * wp
        WRITE(clres,'(a,i3.3)') 'restart.output.',narea
+#if defined key_AGRIF 
+       inum = Agrif_Get_Unit()      
+       If(.NOT. Agrif_root() ) clres = TRIM(Agrif_CFixed())//'_'//TRIM(clres)
+#endif 
        OPEN(inum,FILE=clres,FORM='UNFORMATTED', ACCESS='DIRECT', RECL=irecl8 )
 
@@ -166,7 +170,8 @@
 
        ! TKE arrays
+
 #if defined key_zdftke
          DO jk = 1, jpk
-            WRITE(inum,REC=irec) en(:,:,jk)   ;   irec = irec + 1 
+            WRITE(inum,REC=irec) en(:,:,jk) ; irec = irec + 1 
          END DO
 #endif
@@ -174,17 +179,17 @@
 #if defined key_ice_lim
           zfice(1) = FLOAT( nfice )                                      ! Louvain La Neuve Sea Ice Model
-          WRITE(inum,REC=irec) zfice(:)      ;   irec = irec + 1
-          WRITE(inum,REC=irec) sst_io(:,:)   ;   irec = irec + 1
-          WRITE(inum,REC=irec) sss_io(:,:)   ;   irec = irec + 1
-          WRITE(inum,REC=irec) u_io  (:,:)   ;   irec = irec + 1
-          WRITE(inum,REC=irec) v_io  (:,:)   ;   irec = irec + 1
+          WRITE(inum,REC=irec) zfice(:)     ; irec = irec + 1
+          WRITE(inum,REC=irec) sst_io(:,:)  ; irec = irec + 1
+          WRITE(inum,REC=irec) sss_io(:,:)  ; irec = irec + 1
+          WRITE(inum,REC=irec) u_io  (:,:)  ; irec = irec + 1
+          WRITE(inum,REC=irec) v_io  (:,:)  ; irec = irec + 1
 #    if defined key_coupled
-          WRITE(inum,REC=irec) alb_ice(:,:)  ;   irec = irec + 1
+          WRITE(inum,REC=irec) alb_ice(:,:)  ; irec = irec + 1
 #    endif
 #endif
 # if defined key_flx_bulk_monthly || defined key_flx_bulk_daily
           zfblk(1) = FLOAT( nfbulk )                                 ! Bulk
-          WRITE(inum,REC=irec) zfblk(:)   ;   irec = irec + 1
-          WRITE(inum,REC=irec) gsst(:,:)  ;   irec = irec + 1
+          WRITE(inum,REC=irec) zfblk(:)   ; irec = irec + 1
+          WRITE(inum,REC=irec) gsst(:,:)  ; irec = irec + 1
 # endif
 
@@ -229,5 +234,5 @@
     LOGICAL   :: lstop
 
-    REAL(wp), DIMENSION( 1) ::   zfice, zfblk   ! used only in case of ice & bulk
+      REAL(wp), DIMENSION( 1) ::   zfice, zfblk   ! used only in case of ice & bulk
     !!----------------------------------------------------------------------
 
@@ -268,5 +273,8 @@
     ! Open direct access file, with reclength for 2D wp fields
     WRITE(clres,'(a,i3.3)') 'restart.',narea
-
+#if defined key_AGRIF       
+    inum = Agrif_Get_Unit()
+    If(.NOT. Agrif_root() ) clres = TRIM(Agrif_CFixed())//'_'//TRIM(clres)
+#endif
     OPEN(inum,FILE=clres,FORM='UNFORMATTED', ACCESS='DIRECT', RECL=8 )
     READ(inum,REC=1)irecl8
@@ -278,7 +286,8 @@
     ! --------------
 
-    READ(inum,REC=1) irecl8, ino1, it1, isor1, ipcg1, itke1,   &
-       &             iice1, ibulk1, ios1, ios2, ios3, ios4,    &
-       &             idast1, adatrj0,  ipi,ipj,ipk,ipni,ipnj,ipnij,iarea
+
+    READ(inum,REC=1) irecl8, ino1, it1, isor1, ipcg1, itke1, &
+     &  iice1, ibulk1, ios1, ios2, ios3, ios4, &
+     &  idast1, adatrj0,  ipi,ipj,ipk,ipni,ipnj,ipnij,iarea
 
     ! Performs checks on the file
@@ -416,4 +425,5 @@
 
     ! TKE arrays
+
 #if defined key_zdftke
     IF ( itke1 == 1 ) THEN
@@ -433,12 +443,12 @@
     ! check if it was in the previous run
     IF ( ios1 == 1 ) THEN
-       READ(inum,REC=irec) zfice(:)      ;   irec = irec + 1
-       READ(inum,REC=irec) sst_io(:,:)   ;   irec = irec + 1
-       READ(inum,REC=irec) sss_io(:,:)   ;   irec = irec + 1
-       READ(inum,REC=irec) u_io  (:,:)   ;   irec = irec + 1
-       READ(inum,REC=irec) v_io  (:,:)   ;   irec = irec + 1
-# if defined key_coupled
-       READ(inum,REC=irec) alb_ice(:,:)   ;   irec = irec + 1
-# endif
+       READ(inum,REC=irec) zfice(:)    ; irec = irec + 1
+       READ(inum,REC=irec) sst_io(:,:) ; irec = irec + 1
+       READ(inum,REC=irec) sss_io(:,:) ; irec = irec + 1
+       READ(inum,REC=irec) u_io  (:,:) ; irec = irec + 1
+       READ(inum,REC=irec) v_io  (:,:) ; irec = irec + 1
+#  if defined key_coupled
+       READ(inum,REC=irec) alb_ice(:,:) ; irec = irec + 1
+#  endif
     ENDIF
     IF ( zfice(1) /= FLOAT(nfice) .OR. ios1 == 0 ) THEN
@@ -454,7 +464,7 @@
             END DO
          END DO
-# if defined key_coupled
+#    if defined key_coupled
          alb_ice(:,:) = 0.8 * tmask(:,:,1)
-# endif
+#    endif
     ENDIF
 #endif
@@ -489,3 +499,4 @@
     ENDIF
 
+
   END SUBROUTINE rst_read
Index: /trunk/NEMO/OPA_SRC/step.F90
===================================================================
--- /trunk/NEMO/OPA_SRC/step.F90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/step.F90	(revision 389)
@@ -118,4 +118,8 @@
    USE prtctl          ! Print control                    (prt_ctl routine)
 
+#if defined key_AGRIF
+   USE agrif_opa_sponge ! Momemtum and tracers sponges
+#endif
+
    IMPLICIT NONE
    PRIVATE
@@ -135,6 +139,9 @@
 CONTAINS
 
-   SUBROUTINE stp( kstp )
-      !!----------------------------------------------------------------------
+   SUBROUTINE stp( &
+#if !defined key_AGRIF
+   kstp &
+#endif   
+   )      !!----------------------------------------------------------------------
       !!                     ***  ROUTINE stp  ***
       !!                      
@@ -165,8 +172,11 @@
       !!    "   !  04-08  (C. Talandier) New trends organization
       !!    "   !  05-01  (C. Ethe) Add the KPP closure scheme
-      !!    "   !  05-11  (V. Garnier) Surface pressure gradient organization
       !!----------------------------------------------------------------------
       !! * Arguments
-      INTEGER, INTENT( in ) ::   kstp   ! ocean time-step index
+      INTEGER &
+#if !defined key_AGRIF   
+      , INTENT( in ) &
+#endif      
+      ::   kstp   ! ocean time-step index
 
       !! * local declarations
@@ -174,4 +184,9 @@
       !! ---------------------------------------------------------------------
 
+#if defined key_AGRIF
+      kstp = nit000 + Agrif_Nb_Step()
+      IF ( Agrif_Root() .and. lwp) Write(*,*) '---'
+      IF (lwp) Write(*,*) 'Grid N°',Agrif_Fixed(),' time step ',kstp
+#endif   
       indic = 1                    ! reset to no error condition
       adatrj = adatrj + rdt/86400._wp
@@ -321,4 +336,7 @@
       IF( l_traldf_iso_zps )   CALL tra_ldf_iso_zps( kstp )           ! partial step iso-neutral/geopot. laplacian
 
+#if defined key_AGRIF
+      IF (.NOT. Agrif_Root())  CALL Agrif_Sponge_tra( kstp )          ! tracers sponge
+#endif
       !                                                       ! vertical diffusion
       IF( l_trazdf_exp     )   CALL tra_zdf_exp     ( kstp )          ! explicit time stepping (time splitting scheme)
@@ -353,5 +371,5 @@
                                va(:,:,:) = 0.e0
 
-                               CALL dyn_keg( kstp )           ! horizontal gradient of kinetic energy
+      CALL dyn_keg( kstp )           ! horizontal gradient of kinetic energy
 
       !                                                       ! vorticity term including Coriolis
@@ -361,5 +379,5 @@
       IF( ln_dynvor_mix    )   CALL dyn_vor_mixed    ( kstp )        ! mixed energy/enstrophy conserving scheme
       IF( ln_dynvor_een    )   CALL dyn_vor_ene_ens  ( kstp )        ! combined energy/enstrophy conserving scheme
-
+      
       !                                                       ! lateral mixing 
       IF( l_dynldf_lap     )   CALL dyn_ldf_lap    ( kstp )          ! iso-level laplacian
@@ -368,4 +386,7 @@
       IF( l_dynldf_iso     )   CALL dyn_ldf_iso    ( kstp )          ! iso-neutral laplacian 
 
+#if defined key_AGRIF
+      IF (.NOT. Agrif_Root())  CALL Agrif_Sponge_dyn( kstp )         ! momemtum sponge
+#endif
       !                                                       ! horizontal gradient of Hydrostatic pressure 
       IF ( lk_jki ) THEN
@@ -375,5 +396,5 @@
       ENDIF
 
-                               CALL dyn_zad    ( kstp )       ! vertical advection       
+      CALL dyn_zad    ( kstp )       ! vertical advection       
 
       !                                                       ! vertical diffusion
Index: /trunk/NEMO/OPA_SRC/stpctl.F90
===================================================================
--- /trunk/NEMO/OPA_SRC/stpctl.F90	(revision 388)
+++ /trunk/NEMO/OPA_SRC/stpctl.F90	(revision 389)
@@ -56,4 +56,5 @@
       INTEGER, DIMENSION(3) ::   ilocu      ! 
       INTEGER, DIMENSION(2) ::   ilocs      ! 
+      CHARACTER(len=80) :: clname
       !!----------------------------------------------------------------------
       !!  OPA 9.0 , LOCEAN-IPSL (2005) 
@@ -67,5 +68,6 @@
          WRITE(numout,*) '~~~~~~~'
          ! open time.step file
-         CALL ctlopn( numstp, 'time.step', 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL', 1, numout, lwp, 1 )
+         clname = 'time.step'
+         CALL ctlopn( numstp, clname, 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL', 1, numout, lwp, 1 )
       ENDIF
 
@@ -80,26 +82,26 @@
       ! --------------------------
       IF( lk_dynspg_flt .OR. lk_dynspg_rl ) THEN
-         ! Solver
-         IF(lwp) WRITE(numsol,9200) kt, niter, res, SQRT(epsr)/eps
+      ! Solver
+      IF(lwp) WRITE(numsol,9200) kt, niter, res, SQRT(epsr)/eps
 
-         ! Islands (if exist)
-         IF( lk_isl )   CALL isl_stp_ctl( kt, kindic )
+      ! Islands (if exist)
+      IF( lk_isl )   CALL isl_stp_ctl( kt, kindic )
 
 
-         ! Output in numwso and numwvo IF kindic<0
-         ! ---------------------------------------
-         !    (i.e. problem for the solver)
-         IF( kindic < 0 ) THEN
-            IF(lwp) THEN
-               WRITE(numout,*) ' stpctl: the elliptic solver DO not converge or explode'
-               WRITE(numout,*) ' ====== '
-               WRITE(numout,9200) kt, niter, res, sqrt(epsr)/eps
-               WRITE(numout,*)
-               WRITE(numout,*) ' stpctl: output of last fields in numwso'
-               WRITE(numout,*) '                                  numwvo'
-               WRITE(numout,*) ' ======  *******************************'
-            ENDIF
-            CALL dia_wri( kt, kindic )
+      ! Output in numwso and numwvo IF kindic<0
+      ! ---------------------------------------
+      !    (i.e. problem for the solver)
+      IF( kindic < 0 ) THEN
+         IF(lwp) THEN
+            WRITE(numout,*) ' stpctl: the elliptic solver DO not converge or explode'
+            WRITE(numout,*) ' ====== '
+            WRITE(numout,9200) kt, niter, res, sqrt(epsr)/eps
+            WRITE(numout,*)
+            WRITE(numout,*) ' stpctl: output of last fields in numwso'
+            WRITE(numout,*) '                                  numwvo'
+            WRITE(numout,*) ' ======  *******************************'
          ENDIF
+         CALL dia_wri( kt, kindic )
+      ENDIF
       ENDIF
 
@@ -140,4 +142,5 @@
          ENDIF
          kindic  = -3
+
          CALL dia_wri( kt, kindic )
       ENDIF
