Index: branches/2016/dev_merge_2016/NEMOGCM/CONFIG/WAD_TEST_CASES/MY_SRC/usrdef_istate.F90
===================================================================
--- branches/2016/dev_merge_2016/NEMOGCM/CONFIG/WAD_TEST_CASES/MY_SRC/usrdef_istate.F90	(revision 7577)
+++ branches/2016/dev_merge_2016/NEMOGCM/CONFIG/WAD_TEST_CASES/MY_SRC/usrdef_istate.F90	(revision 7580)
@@ -83,5 +83,5 @@
             !
             IF(lwp) WRITE(numout,*)
-            IF(lwp) WRITE(numout,*) 'istate_wad : Closed box with EW linear bottom slope'
+            IF(lwp) WRITE(numout,*) 'usr_def_istate : WAD Closed box with EW linear bottom slope'
             IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
             !
@@ -94,5 +94,5 @@
             !
             IF(lwp) WRITE(numout,*)
-            IF(lwp) WRITE(numout,*) 'istate_wad : Parobolic EW channel, mid-range initial ssh slope'
+            IF(lwp) WRITE(numout,*) 'usr_def_istate : WAD Parobolic EW channel, mid-range initial ssh slope'
             IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
             !
@@ -105,5 +105,5 @@
             !
             IF(lwp) WRITE(numout,*)
-            IF(lwp) WRITE(numout,*) 'istate_wad : Parobolic EW channel, extreme initial ssh slope' 
+            IF(lwp) WRITE(numout,*) 'usr_def_istate : WAD Parobolic EW channel, extreme initial ssh slope' 
             IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
             !
@@ -118,5 +118,5 @@
             !
             IF(lwp) WRITE(numout,*)
-            IF(lwp) WRITE(numout,*) 'istate_wad : Parobolic bowl, mid-range initial ssh slope' 
+            IF(lwp) WRITE(numout,*) 'usr_def_istate : WAD Parobolic bowl, mid-range initial ssh slope' 
             IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
             !
@@ -135,5 +135,5 @@
             !
             IF(lwp) WRITE(numout,*)
-            IF(lwp) WRITE(numout,*) 'istate_wad : Double slope with shelf'
+            IF(lwp) WRITE(numout,*) 'usr_def_istate : WAD Double slope with shelf'
             IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
             !
@@ -148,5 +148,5 @@
             !
             IF(lwp) WRITE(numout,*)
-            IF(lwp) WRITE(numout,*) 'istate_wad : Parobolic EW channel with gaussian ridge' 
+            IF(lwp) WRITE(numout,*) 'usr_def_istate : WAD Parobolic EW channel with gaussian ridge' 
             IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
             !
Index: branches/2016/dev_merge_2016/NEMOGCM/NEMO/OPA_SRC/DYN/wet_dry.F90
===================================================================
--- branches/2016/dev_merge_2016/NEMOGCM/NEMO/OPA_SRC/DYN/wet_dry.F90	(revision 7577)
+++ branches/2016/dev_merge_2016/NEMOGCM/NEMO/OPA_SRC/DYN/wet_dry.F90	(revision 7580)
@@ -45,5 +45,4 @@
    PUBLIC   wad_lmt                   ! routine called by sshwzv.F90
    PUBLIC   wad_lmt_bt                ! routine called by dynspg_ts.F90
-   PUBLIC   wad_istate                ! routine called by istate.F90 and domvvl.F90
 
    !! * Substitutions
@@ -109,5 +108,5 @@
       !
       INTEGER  ::   ji, jj, jk, jk1     ! dummy loop indices
-      INTEGER  ::   zflag               ! local scalar
+      INTEGER  ::   jflag               ! local scalar
       REAL(wp) ::   zcoef, zdep1, zdep2 ! local scalars
       REAL(wp) ::   zzflxp, zzflxn      ! local scalars
@@ -132,5 +131,5 @@
         !IF(lwp) WRITE(numout,*) 'wad_lmt : wetting/drying limiters and velocity limiting'
        
-        zflag  = 0
+        jflag  = 0
         zdepwd = 50._wp   !maximum depth on which that W/D could possibly happen
 
@@ -185,4 +184,5 @@
            zflxu1(:,:) = zflxu(:,:) * zwdlmtu(:,:)
            zflxv1(:,:) = zflxv(:,:) * zwdlmtv(:,:)
+           jflag = 0     ! flag indicating if any further iterations are needed
           
            DO jj = 2, jpj
@@ -203,8 +203,8 @@
           
                  IF(zdep1 > zdep2) THEN
-                   zflag = 1
+                   jflag = 1
                    wdmask(ji, jj) = 0
-                   !zcoef = ( ( zdep2 - rn_wdmin2 ) * ztmp - zzflxn * z2dt ) / ( zflxp(ji,jj) * z2dt )
-                   zcoef = ( ( zdep2 - rn_wdmin2 ) * ztmp - zzflxn * z2dt ) / ( zzflxp * z2dt )
+                   zcoef = ( ( zdep2 - rn_wdmin2 ) * ztmp - zzflxn * z2dt ) / ( zflxp(ji,jj) * z2dt )
+                   !zcoef = ( ( zdep2 - rn_wdmin2 ) * ztmp - zzflxn * z2dt ) / ( zzflxp * z2dt )
                    zcoef = max(zcoef, 0._wp)
                    IF(jk1 > nn_wdit) zcoef = 0._wp
@@ -220,9 +220,8 @@
            CALL lbc_lnk( zwdlmtv, 'V', 1. )
 
-           IF(lk_mpp) CALL mpp_max(zflag)   !max over the global domain
-
-           IF(zflag == 0) EXIT
-          
-           zflag = 0     ! flag indicating if any further iteration is needed?
+           IF(lk_mpp) CALL mpp_max(jflag)   !max over the global domain
+
+           IF(jflag == 0) EXIT
+          
         END DO  ! jk1 loop
        
@@ -240,5 +239,5 @@
         CALL lbc_lnk( vn_b, 'V', -1. )
        
-        IF(zflag == 1 .AND. lwp) WRITE(numout,*) 'Need more iterations in wad_lmt!!!'
+        IF(jflag == 1 .AND. lwp) WRITE(numout,*) 'Need more iterations in wad_lmt!!!'
        
         !IF( ln_rnf      )   CALL sbc_rnf_div( hdivn )          ! runoffs (update hdivn field)
@@ -270,5 +269,5 @@
       !
       INTEGER  ::   ji, jj, jk, jk1     ! dummy loop indices
-      INTEGER  ::   zflag         ! local scalar
+      INTEGER  ::   jflag               ! local scalar
       REAL(wp) ::   z2dt
       REAL(wp) ::   zcoef, zdep1, zdep2 ! local scalars
@@ -292,5 +291,5 @@
         !IF(lwp) WRITE(numout,*) 'wad_lmt_bt : wetting/drying limiters and velocity limiting'
        
-        zflag  = 0
+        jflag  = 0
         zdepwd = 50._wp   !maximum depth that ocean cells can have W/D processes
 
@@ -299,6 +298,4 @@
         zflxp(:,:)   = 0._wp
         zflxn(:,:)   = 0._wp
-        !zflxu(:,:)   = 0._wp
-        !zflxv(:,:)   = 0._wp
 
         zwdlmtu(:,:)  = 1._wp
@@ -319,4 +316,7 @@
 
               zdep2 = ht_wd(ji,jj) + sshn_e(ji,jj) - rn_wdmin1
+              IF(zdep2 .le. 0._wp) THEN  !add more safty, but not necessary
+                sshn_e(ji,jj) = rn_wdmin1 - ht_wd(ji,jj)
+              END IF
            ENDDO
         END DO
@@ -329,4 +329,5 @@
            zflxu1(:,:) = zflxu(:,:) * zwdlmtu(:,:)
            zflxv1(:,:) = zflxv(:,:) * zwdlmtv(:,:)
+           jflag = 0     ! flag indicating if any further iterations are needed
           
            DO jj = 2, jpj
@@ -344,11 +345,10 @@
           
                  zdep1 = (zzflxp + zzflxn) * z2dt / ztmp
-                 zdep2 = ht_wd(ji,jj) + sshn_e(ji,jj) - rn_wdmin1
-                 zdep2 = zdep2 - z2dt * zssh_frc(ji,jj)
+                 zdep2 = ht_wd(ji,jj) + sshn_e(ji,jj) - rn_wdmin1 - z2dt * zssh_frc(ji,jj)
           
                  IF(zdep1 > zdep2) THEN
-                   zflag = 1
-                   !zcoef = ( ( zdep2 - rn_wdmin2 ) * ztmp - zzflxn * z2dt ) / ( zflxp(ji,jj) * z2dt )
-                   zcoef = ( ( zdep2 - rn_wdmin2 ) * ztmp - zzflxn * z2dt ) / ( zzflxp * z2dt )
+                   jflag = 1
+                   zcoef = ( ( zdep2 - rn_wdmin2 ) * ztmp - zzflxn * z2dt ) / ( zflxp(ji,jj) * z2dt )
+                   !zcoef = ( ( zdep2 - rn_wdmin2 ) * ztmp - zzflxn * z2dt ) / ( zzflxp * z2dt )
                    zcoef = max(zcoef, 0._wp)
                    IF(jk1 > nn_wdit) zcoef = 0._wp
@@ -364,9 +364,8 @@
            CALL lbc_lnk( zwdlmtv, 'V', 1. )
 
-           IF(lk_mpp) CALL mpp_max(zflag)   !max over the global domain
-
-           IF(zflag == 0) EXIT
-          
-           zflag = 0     ! flag indicating if any further iteration is needed?
+           IF(lk_mpp) CALL mpp_max(jflag)   !max over the global domain
+
+           IF(jflag == 0) EXIT
+          
         END DO  ! jk1 loop
        
@@ -377,5 +376,5 @@
         CALL lbc_lnk( zflxv, 'V', -1. )
        
-        IF(zflag == 1 .AND. lwp) WRITE(numout,*) 'Need more iterations in wad_lmt_bt!!!'
+        IF(jflag == 1 .AND. lwp) WRITE(numout,*) 'Need more iterations in wad_lmt_bt!!!'
        
         !IF( ln_rnf      )   CALL sbc_rnf_div( hdivn )          ! runoffs (update hdivn field)
@@ -391,145 +390,4 @@
    END SUBROUTINE wad_lmt_bt
 
-   SUBROUTINE wad_istate
-      !!----------------------------------------------------------------------
-      !!                   ***  ROUTINE wad_istate  ***
-      !! 
-      !! ** Purpose :   Initialization of the dynamics and tracers for WAD test
-      !!      configurations (channels or bowls with initial ssh gradients)
-      !!
-      !! ** Method  : - set temperature field
-      !!              - set salinity field
-      !!              - set ssh slope (needs to be repeated in domvvl_rst_init to
-      !!                               set vertical metrics )
-      !!----------------------------------------------------------------------
-      !
-      INTEGER  ::   ji, jj            ! dummy loop indices
-      REAL(wp) ::   zi, zj
-      !!----------------------------------------------------------------------
-      !
-      ! Uniform T & S in all test cases
-      tsn(:,:,:,jp_tem) = 10._wp
-      tsb(:,:,:,jp_tem) = 10._wp
-      tsn(:,:,:,jp_sal) = 35._wp
-      tsb(:,:,:,jp_sal) = 35._wp
-      SELECT CASE ( nn_cfg ) 
-         !                                        ! ====================
-         CASE ( 1 )                               ! WAD 1 configuration
-            !                                     ! ====================
-            !
-            IF(lwp) WRITE(numout,*)
-            IF(lwp) WRITE(numout,*) 'istate_wad : Closed box with EW linear bottom slope'
-            IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
-            !
-            do ji = 1,jpi
-             sshn(ji,:) = ( -5.5_wp + 5.5_wp*FLOAT(mig(ji))/FLOAT(jpiglo-1))*tmask(ji,:,1)
-            end do
-            !                                     ! ====================
-         CASE ( 2 )                               ! WAD 2 configuration
-            !                                     ! ====================
-            !
-            IF(lwp) WRITE(numout,*)
-            IF(lwp) WRITE(numout,*) 'istate_wad : Parobolic EW channel, mid-range initial ssh slope'
-            IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
-            !
-            do ji = 1,jpi
-             sshn(ji,:) = ( -5.5_wp + 3.9_wp*FLOAT(jpiglo - mig(ji))/FLOAT(jpiglo-1))*tmask(ji,:,1)
-            end do
-            !                                     ! ====================
-         CASE ( 3 )                               ! WAD 3 configuration
-            !                                     ! ====================
-            !
-            IF(lwp) WRITE(numout,*)
-            IF(lwp) WRITE(numout,*) 'istate_wad : Parobolic EW channel, extreme initial ssh slope' 
-            IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
-            !
-            do ji = 1,jpi
-             sshn(ji,:) = ( -7.5_wp + 6.9_wp*FLOAT(jpiglo - mig(ji))/FLOAT(jpiglo-1))*tmask(ji,:,1)
-            end do
-
-            !
-            !                                     ! ====================
-         CASE ( 4 )                               ! WAD 4 configuration
-            !                                     ! ====================
-            !
-            IF(lwp) WRITE(numout,*)
-            IF(lwp) WRITE(numout,*) 'istate_wad : Parobolic bowl, mid-range initial ssh slope' 
-            IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
-            !
-            DO ji = 1, jpi
-               zi = MAX(1.0-FLOAT((mig(ji)-25)**2)/400.0, 0.0 )
-               DO jj = 1, jpj
-                  zj = MAX(1.0-FLOAT((mjg(jj)-17)**2)/144.0, 0.0 )
-                  sshn(ji,jj) = -8.5_wp + 8.5_wp*zi*zj
-               END DO
-            END DO
-
-            !
-            !                                    ! ===========================
-         CASE ( 5 )                              ! WAD 5 configuration
-            !                                    ! ====================
-            !
-            IF(lwp) WRITE(numout,*)
-            IF(lwp) WRITE(numout,*) 'istate_wad : Double slope with shelf'
-            IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
-            !
-            ! Needed rn_wdmin2 increased to 0.01 for this case?
-            do ji = 1,jpi
-             sshn(ji,:) = ( -5.5_wp + 9.0_wp*FLOAT(mig(ji))/FLOAT(jpiglo-1))*tmask(ji,:,1)
-            end do
-
-            !
-            !                                     ! ===========================
-         CASE ( 6 )                               ! WAD 6 configuration
-            !                                     ! ====================
-            !
-            IF(lwp) WRITE(numout,*)
-            IF(lwp) WRITE(numout,*) 'istate_wad : Parobolic EW channel with gaussian ridge' 
-            IF(lwp) WRITE(numout,*) '~~~~~~~~~~'
-            !
-            do ji = 1,jpi
-             !6a
-             !sshn(ji,:) = ( -5.5_wp + 9.0_wp*FLOAT(jpiglo - mig(ji))/FLOAT(jpiglo-1))*tmask(ji,:,1)
-             !Some variations in initial slope that have been tested
-             !6b
-             !sshn(ji,:) = ( -5.5_wp + 6.5_wp*FLOAT(jpiglo - mig(ji))/FLOAT(jpiglo-1))*tmask(ji,:,1)
-             !6c
-             !sshn(ji,:) = ( -5.5_wp + 7.5_wp*FLOAT(jpiglo - mig(ji))/FLOAT(jpiglo-1))*tmask(ji,:,1)
-             !6d
-             !sshn(ji,:) = ( -4.5_wp + 8.0_wp*FLOAT(jpiglo - mig(ji))/FLOAT(jpiglo-1))*tmask(ji,:,1)
-             !6e
-             sshn(ji,:) = ( -3.5_wp + 7.0_wp*FLOAT(jpiglo - mig(ji))/FLOAT(jpiglo-1))*tmask(ji,:,1)
-             !6f
-             !sshn(ji,:) = ( 0.5_wp + 3.75_wp*FLOAT(jpiglo - mig(ji))/FLOAT(jpiglo-1))*tmask(ji,:,1)
-            end do
-            !
-            do ji = mi0(jpiglo/2), mi0(jpiglo)
-             tsn(ji,:,:,jp_sal) = 30._wp
-             tsb(ji,:,:,jp_sal) = 30._wp
-            end do
-            !
-            !                                    ! ===========================
-         CASE DEFAULT                            ! NONE existing configuration
-            !                                    ! ===========================
-            WRITE(ctmp1,*) 'WAD test with a ', nn_cfg,' option is not coded'
-            !
-            CALL ctl_stop( ctmp1 )
-            !
-      END SELECT
-      !
-      ! Apply minimum wetdepth criterion
-      !
-      do jj = 1,jpj
-         do ji = 1,jpi
-            IF( ht_wd(ji,jj) + sshn(ji,jj) < rn_wdmin1 ) THEN
-               sshn(ji,jj) = tmask(ji,jj,1)*( rn_wdmin1 - ht_wd(ji,jj) )
-            ENDIF
-         end do
-      end do
-      sshb = sshn
-      ssha = sshn
-      !
-   END SUBROUTINE wad_istate
-
    !!==============================================================================
 END MODULE wet_dry
