Index: branches/2014/dev_r4650_UKMO14.12_STAND_ALONE_OBSOPER/NEMOGCM/NEMO/OPA_SRC/BDY/bdyice_lim.F90
===================================================================
--- branches/2014/dev_r4650_UKMO14.12_STAND_ALONE_OBSOPER/NEMOGCM/NEMO/OPA_SRC/BDY/bdyice_lim.F90	(revision 5600)
+++ branches/2014/dev_r4650_UKMO14.12_STAND_ALONE_OBSOPER/NEMOGCM/NEMO/OPA_SRC/BDY/bdyice_lim.F90	(revision 6043)
@@ -59,13 +59,15 @@
       !!
       !!----------------------------------------------------------------------
-      INTEGER, INTENT( in ) :: kt     ! Main time step counter
-      INTEGER               :: ib_bdy ! Loop index
-
+      INTEGER, INTENT( in ) ::   kt   ! Main time step counter
+      !
+      INTEGER ::   ib_bdy   ! Loop index
+      !!----------------------------------------------------------------------
+      !
 #if defined key_lim3
       CALL lim_var_glo2eqv
 #endif
-
+      !
       DO ib_bdy=1, nb_bdy
-
+         !
          SELECT CASE( cn_ice_lim(ib_bdy) )
          CASE('none')
@@ -76,13 +78,14 @@
             CALL ctl_stop( 'bdy_ice_lim : unrecognised option for open boundaries for ice fields' )
          END SELECT
-
+         !
       END DO
-
+      !
 #if defined key_lim3
       CALL lim_var_zapsmall
       CALL lim_var_agg(1)
 #endif
-
+      !
    END SUBROUTINE bdy_ice_lim
+
 
    SUBROUTINE bdy_ice_frs( idx, dta, kt, ib_bdy )
@@ -96,19 +99,22 @@
       !!             dimensional baroclinic ocean model with realistic topography. Tellus, 365-382.
       !!------------------------------------------------------------------------------
-      TYPE(OBC_INDEX), INTENT(in) ::   idx  ! OBC indices
-      TYPE(OBC_DATA),  INTENT(in) ::   dta  ! OBC external data
-      INTEGER,         INTENT(in) ::   kt   ! main time-step counter
+      TYPE(OBC_INDEX), INTENT(in) ::   idx     ! OBC indices
+      TYPE(OBC_DATA),  INTENT(in) ::   dta     ! OBC external data
+      INTEGER,         INTENT(in) ::   kt      ! main time-step counter
       INTEGER,         INTENT(in) ::   ib_bdy  ! BDY set index
-
+      !
       INTEGER  ::   jpbound            ! 0 = incoming ice
-                                       ! 1 = outgoing ice
+      !                                ! 1 = outgoing ice
       INTEGER  ::   jb, jk, jgrd, jl   ! dummy loop indices
       INTEGER  ::   ji, jj, ii, ij     ! local scalar
       REAL(wp) ::   zwgt, zwgt1        ! local scalar
       REAL(wp) ::   ztmelts, zdh
-
-      !!------------------------------------------------------------------------------
-      !
-      IF( nn_timing == 1 ) CALL timing_start('bdy_ice_frs')
+#if  defined key_lim2 && ! defined key_lim2_vp && defined key_agrif
+     USE ice_2, vt_s => hsnm
+     USE ice_2, vt_i => hicm
+#endif
+      !!------------------------------------------------------------------------------
+      !
+      IF( nn_timing == 1 )   CALL timing_start('bdy_ice_frs')
       !
       jgrd = 1      ! Everything is at T-points here
@@ -177,30 +183,29 @@
             ! condition on ice thickness depends on the ice velocity
             ! if velocity is outward (strictly), then ice thickness, volume... must be equal to adjacent values
-            jpbound = 0; ii = ji; ij = jj;
-
+            jpbound = 0   ;   ii = ji   ;   ij = jj
+            !
             IF( u_ice(ji+1,jj  ) < 0. .AND. umask(ji-1,jj  ,1) == 0. ) jpbound = 1; ii = ji+1; ij = jj
             IF( u_ice(ji-1,jj  ) > 0. .AND. umask(ji+1,jj  ,1) == 0. ) jpbound = 1; ii = ji-1; ij = jj
             IF( v_ice(ji  ,jj+1) < 0. .AND. vmask(ji  ,jj-1,1) == 0. ) jpbound = 1; ii = ji  ; ij = jj+1
             IF( v_ice(ji  ,jj-1) > 0. .AND. vmask(ji  ,jj+1,1) == 0. ) jpbound = 1; ii = ji  ; ij = jj-1
-
+            !
             IF( nn_ice_lim_dta(ib_bdy) == 0 ) jpbound = 0; ii = ji; ij = jj   ! case ice boundaries = initial conditions
-                                                                              !      do not make state variables dependent on velocity
-               
-
+            !                                                                 !      do not make state variables dependent on velocity
+            !
             rswitch = MAX( 0.0_wp , SIGN ( 1.0_wp , at_i(ii,ij) - 0.01 ) ) ! 0 if no ice
-
+            !
             ! concentration and thickness
             a_i (ji,jj,jl) = a_i (ii,ij,jl) * rswitch
             ht_i(ji,jj,jl) = ht_i(ii,ij,jl) * rswitch
             ht_s(ji,jj,jl) = ht_s(ii,ij,jl) * rswitch
-
+            !
             ! Ice and snow volumes
             v_i(ji,jj,jl) = ht_i(ji,jj,jl) * a_i(ji,jj,jl)
             v_s(ji,jj,jl) = ht_s(ji,jj,jl) * a_i(ji,jj,jl)
-
+            !
             SELECT CASE( jpbound )
-
-            CASE( 0 ) ! velocity is inward
-
+            !
+            CASE( 0 )   ! velocity is inward
+               !
                ! Ice salinity, age, temperature
                sm_i(ji,jj,jl)   = rswitch * rn_ice_sal(ib_bdy)  + ( 1.0 - rswitch ) * rn_simin
@@ -214,7 +219,7 @@
                   s_i(ji,jj,jk,jl) = rswitch * rn_ice_sal(ib_bdy) + ( 1.0 - rswitch ) * rn_simin
                END DO
-               
-            CASE( 1 ) ! velocity is outward
- 
+               !
+            CASE( 1 )   ! velocity is outward
+               !
                ! Ice salinity, age, temperature
                sm_i(ji,jj,jl)   = rswitch * sm_i(ii,ij,jl)  + ( 1.0 - rswitch ) * rn_simin
@@ -228,13 +233,12 @@
                   s_i(ji,jj,jk,jl) = rswitch * s_i(ii,ij,jk,jl) + ( 1.0 - rswitch ) * rn_simin
                END DO
-
+               !
             END SELECT
-
-            ! if salinity is constant, then overwrite rn_ice_sal
-            IF( nn_icesal == 1 ) THEN
-               sm_i(ji,jj,jl)   = rn_icesal
+            !
+            IF( nn_icesal == 1 ) THEN     ! constant salinity : overwrite rn_ice_sal
+               sm_i(ji,jj  ,jl) = rn_icesal
                s_i (ji,jj,:,jl) = rn_icesal
             ENDIF
-
+            !
             ! contents
             smv_i(ji,jj,jl)  = MIN( sm_i(ji,jj,jl) , sss_m(ji,jj) ) * v_i(ji,jj,jl)
@@ -255,7 +259,7 @@
                e_i(ji,jj,jk,jl) = e_i(ji,jj,jk,jl) * a_i(ji,jj,jl) * ht_i(ji,jj,jl) * r1_nlay_i
             END DO
-
+            !
          END DO
- 
+         !
          CALL lbc_bdy_lnk(  a_i(:,:,jl), 'T', 1., ib_bdy )
          CALL lbc_bdy_lnk( ht_i(:,:,jl), 'T', 1., ib_bdy )
@@ -263,5 +267,5 @@
          CALL lbc_bdy_lnk(  v_i(:,:,jl), 'T', 1., ib_bdy )
          CALL lbc_bdy_lnk(  v_s(:,:,jl), 'T', 1., ib_bdy )
- 
+         !
          CALL lbc_bdy_lnk( smv_i(:,:,jl), 'T', 1., ib_bdy )
          CALL lbc_bdy_lnk(  sm_i(:,:,jl), 'T', 1., ib_bdy )
@@ -276,10 +280,10 @@
             CALL lbc_bdy_lnk(e_i(:,:,jk,jl), 'T', 1., ib_bdy )
          END DO
-
+         !
       END DO !jl
-    
+      !
 #endif
       !      
-      IF( nn_timing == 1 ) CALL timing_stop('bdy_ice_frs')
+      IF( nn_timing == 1 )   CALL timing_stop('bdy_ice_frs')
       !
    END SUBROUTINE bdy_ice_frs
@@ -296,11 +300,11 @@
       !! 2013-06 : C. Rousset
       !!------------------------------------------------------------------------------
-      !!
       CHARACTER(len=1), INTENT(in)  ::   cd_type   ! nature of velocity grid-points
+      !
       INTEGER  ::   jb, jgrd           ! dummy loop indices
       INTEGER  ::   ji, jj             ! local scalar
       INTEGER  ::   ib_bdy             ! Loop index
       REAL(wp) ::   zmsk1, zmsk2, zflag
-     !!------------------------------------------------------------------------------
+      !!------------------------------------------------------------------------------
       !
       IF( nn_timing == 1 ) CALL timing_start('bdy_ice_lim_dyn')
@@ -309,18 +313,15 @@
          !
          SELECT CASE( cn_ice_lim(ib_bdy) )
-
+         !
          CASE('none')
-
             CYCLE
-            
+            !
          CASE('frs')
-            
+            !
             IF( nn_ice_lim_dta(ib_bdy) == 0 ) CYCLE            ! case ice boundaries = initial conditions 
-                                                               !      do not change ice velocity (it is only computed by rheology)
- 
+            !                                                  !      do not change ice velocity (it is only computed by rheology)
             SELECT CASE ( cd_type )
-               
-            CASE ( 'U' )
-               
+            !     
+            CASE ( 'U' )  
                jgrd = 2      ! u velocity
                DO jb = 1, idx_bdy(ib_bdy)%nblen(jgrd)
@@ -328,10 +329,10 @@
                   jj    = idx_bdy(ib_bdy)%nbj(jb,jgrd)
                   zflag = idx_bdy(ib_bdy)%flagu(jb,jgrd)
-                  
+                  !
                   IF ( ABS( zflag ) == 1. ) THEN  ! eastern and western boundaries
                      ! one of the two zmsk is always 0 (because of zflag)
                      zmsk1 = 1._wp - MAX( 0.0_wp, SIGN ( 1.0_wp , - vt_i(ji+1,jj) ) ) ! 0 if no ice
                      zmsk2 = 1._wp - MAX( 0.0_wp, SIGN ( 1.0_wp , - vt_i(ji-1,jj) ) ) ! 0 if no ice
-                     
+                     !  
                      ! u_ice = u_ice of the adjacent grid point except if this grid point is ice-free (then u_ice = u_oce)
                      u_ice (ji,jj) = u_ice(ji+1,jj) * 0.5_wp * ABS( zflag + 1._wp ) * zmsk1 + &
@@ -345,11 +346,9 @@
                   rswitch = MAX( 0.0_wp , SIGN ( 1.0_wp , at_i(ji,jj) - 0.01_wp ) ) ! 0 if no ice
                   u_ice(ji,jj) = rswitch * u_ice(ji,jj)
-                  
-               ENDDO
-               
+                  !
+               END DO
                CALL lbc_bdy_lnk( u_ice(:,:), 'U', -1., ib_bdy )
-               
+               !
             CASE ( 'V' )
-               
                jgrd = 3      ! v velocity
                DO jb = 1, idx_bdy(ib_bdy)%nblen(jgrd)
@@ -357,10 +356,10 @@
                   jj    = idx_bdy(ib_bdy)%nbj(jb,jgrd)
                   zflag = idx_bdy(ib_bdy)%flagv(jb,jgrd)
-                  
+                  !
                   IF ( ABS( zflag ) == 1. ) THEN  ! northern and southern boundaries
                      ! one of the two zmsk is always 0 (because of zflag)
                      zmsk1 = 1._wp - MAX( 0.0_wp, SIGN ( 1.0_wp , - vt_i(ji,jj+1) ) ) ! 0 if no ice
                      zmsk2 = 1._wp - MAX( 0.0_wp, SIGN ( 1.0_wp , - vt_i(ji,jj-1) ) ) ! 0 if no ice
-                     
+                     !  
                      ! u_ice = u_ice of the adjacent grid point except if this grid point is ice-free (then u_ice = u_oce)
                      v_ice (ji,jj) = v_ice(ji,jj+1) * 0.5_wp * ABS( zflag + 1._wp ) * zmsk1 + &
@@ -374,19 +373,18 @@
                   rswitch = MAX( 0.0_wp , SIGN ( 1.0_wp , at_i(ji,jj) - 0.01 ) ) ! 0 if no ice
                   v_ice(ji,jj) = rswitch * v_ice(ji,jj)
-                  
-               ENDDO
-               
+                  !
+               END DO
                CALL lbc_bdy_lnk( v_ice(:,:), 'V', -1., ib_bdy )
-                  
+               !
             END SELECT
-            
+            !
          CASE DEFAULT
             CALL ctl_stop( 'bdy_ice_lim_dyn : unrecognised option for open boundaries for ice fields' )
          END SELECT
-         
-      ENDDO
-
+         !
+      END DO
+      !
       IF( nn_timing == 1 ) CALL timing_stop('bdy_ice_lim_dyn')
-      
+      !
     END SUBROUTINE bdy_ice_lim_dyn
 
