Index: branches/2013/dev_r4028_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/BDY/bdyini.F90
===================================================================
--- branches/2013/dev_r4028_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/BDY/bdyini.F90	(revision 4035)
+++ branches/2013/dev_r4028_CNRS_LIM3/NEMOGCM/NEMO/OPA_SRC/BDY/bdyini.F90	(revision 4332)
@@ -96,6 +96,6 @@
          &             nn_dyn3d, nn_dyn3d_dta, nn_tra, nn_tra_dta,         &  
          &             ln_tra_dmp, ln_dyn3d_dmp, rn_time_dmp,              &
-#if defined key_lim2
-         &             nn_ice_lim2, nn_ice_lim2_dta,                       &
+#if ( defined key_lim2 || defined key_lim3 )
+         &             nn_ice_lim, nn_ice_lim_dta,                       &
 #endif
          &             ln_vol, nn_volctl, nn_rimwidth
@@ -137,7 +137,7 @@
       ln_dyn3d_dmp(:)   = .false.
       rn_time_dmp(:)    = 1.
-#if defined key_lim2
-      nn_ice_lim2(:)    = 0
-      nn_ice_lim2_dta(:)= -1  ! uninitialised flag
+#if ( defined key_lim2 || defined key_lim3 )
+      nn_ice_lim(:)    = 0
+      nn_ice_lim_dta(:)= -1  ! uninitialised flag
 #endif
       ln_vol            = .false.
@@ -161,4 +161,5 @@
 
       DO ib_bdy = 1,nb_bdy
+        icount = 0 ! flag to set max rimwidth to 1 if no relaxation
         IF(lwp) WRITE(numout,*) ' ' 
         IF(lwp) WRITE(numout,*) '------ Open boundary data set ',ib_bdy,'------' 
@@ -175,4 +176,5 @@
           CASE(jp_none)         ;   IF(lwp) WRITE(numout,*) '      no open boundary condition'        
           CASE(jp_frs)          ;   IF(lwp) WRITE(numout,*) '      Flow Relaxation Scheme'
+          icount = icount + 1
           CASE(jp_flather)      ;   IF(lwp) WRITE(numout,*) '      Flather radiation condition'
           CASE DEFAULT   ;   CALL ctl_stop( 'unrecognised value for nn_dyn2d' )
@@ -196,4 +198,5 @@
           CASE(jp_none)  ;   IF(lwp) WRITE(numout,*) '      no open boundary condition'        
           CASE(jp_frs)   ;   IF(lwp) WRITE(numout,*) '      Flow Relaxation Scheme'
+          icount = icount + 1
           CASE( 2 )      ;   IF(lwp) WRITE(numout,*) '      Specified value'
           CASE( 3 )      ;   IF(lwp) WRITE(numout,*) '      Zero baroclinic velocities (runoff case)'
@@ -215,4 +218,5 @@
               CALL ctl_stop( 'Use FRS OR relaxation' )
            ELSE
+              icount = icount + 1
               IF(lwp) WRITE(numout,*) '      + baroclinic velocities relaxation zone'
               IF(lwp) WRITE(numout,*) '      Damping time scale: ',rn_time_dmp(ib_bdy),' days'
@@ -228,4 +232,5 @@
           CASE(jp_none)  ;   IF(lwp) WRITE(numout,*) '      no open boundary condition'        
           CASE(jp_frs)   ;   IF(lwp) WRITE(numout,*) '      Flow Relaxation Scheme'
+          icount = icount + 1
           CASE( 2 )      ;   IF(lwp) WRITE(numout,*) '      Specified value'
           CASE( 3 )      ;   IF(lwp) WRITE(numout,*) '      Neumann conditions'
@@ -248,4 +253,5 @@
               CALL ctl_stop( 'Use FRS OR relaxation' )
            ELSE
+              icount = icount + 1
               IF(lwp) WRITE(numout,*) '      + T/S relaxation zone'
               IF(lwp) WRITE(numout,*) '      Damping time scale: ',rn_time_dmp(ib_bdy),' days'
@@ -257,23 +263,27 @@
         IF(lwp) WRITE(numout,*)
 
-#if defined key_lim2
+#if ( defined key_lim2 || defined key_lim3 )
         IF(lwp) WRITE(numout,*) 'Boundary conditions for sea ice:  '
-        SELECT CASE( nn_ice_lim2(ib_bdy) )                  
+        SELECT CASE( nn_ice_lim(ib_bdy) )                  
           CASE( 0 )      ;   IF(lwp) WRITE(numout,*) '      no open boundary condition'        
           CASE( 1 )      ;   IF(lwp) WRITE(numout,*) '      Flow Relaxation Scheme'
+          icount = icount + 1
           CASE DEFAULT   ;   CALL ctl_stop( 'unrecognised value for nn_tra' )
         END SELECT
-        IF( nn_ice_lim2(ib_bdy) .gt. 0 ) THEN 
-           SELECT CASE( nn_ice_lim2_dta(ib_bdy) )                   ! 
+        IF( nn_ice_lim(ib_bdy) .gt. 0 ) THEN 
+           SELECT CASE( nn_ice_lim_dta(ib_bdy) )                   ! 
               CASE( 0 )      ;   IF(lwp) WRITE(numout,*) '      initial state used for bdy data'        
               CASE( 1 )      ;   IF(lwp) WRITE(numout,*) '      boundary data taken from file'
-              CASE DEFAULT   ;   CALL ctl_stop( 'nn_ice_lim2_dta must be 0 or 1' )
+              CASE DEFAULT   ;   CALL ctl_stop( 'nn_ice_lim_dta must be 0 or 1' )
            END SELECT
         ENDIF
         IF(lwp) WRITE(numout,*)
 #endif
-
-        IF(lwp) WRITE(numout,*) '      Width of relaxation zone = ', nn_rimwidth(ib_bdy)
-        IF(lwp) WRITE(numout,*)
+        IF ( icount>0 ) THEN
+           IF(lwp) WRITE(numout,*) '      Width of relaxation zone = ', nn_rimwidth(ib_bdy)
+           IF(lwp) WRITE(numout,*)
+        ELSE
+           nn_rimwidth(ib_bdy) = 1 ! no relaxation
+        ENDIF
 
       ENDDO
@@ -387,9 +397,10 @@
             DO igrd = 1, jpbgrd
                id_dummy = iom_varid( inum, 'nbi'//cgrid(igrd), kdimsz=kdimsz )  
-               nblendta(igrd,ib_bdy) = kdimsz(1)
-               jpbdtau = MAX(jpbdtau, kdimsz(1))
+               !clem nblendta(igrd,ib_bdy) = kdimsz(1)
+               !clem jpbdtau = MAX(jpbdtau, kdimsz(1))
+               nblendta(igrd,ib_bdy) = MAXVAL(kdimsz)
+               jpbdtau = MAX(jpbdtau, MAXVAL(kdimsz))
             ENDDO
             CALL iom_close( inum )
-
          ENDIF 
 
@@ -398,5 +409,4 @@
       IF (nb_bdy>0) THEN
          jpbdta = MAXVAL(nblendta(1:jpbgrd,1:nb_bdy))
-
          ! Allocate arrays
          !---------------
@@ -446,5 +456,5 @@
          ENDIF 
 
-      ENDDO      
+      ENDDO     
     
       ! 2. Now fill indices corresponding to straight open boundary arrays:
@@ -752,5 +762,6 @@
                ! check if point is in local domain
                IF(  nbidta(ib,igrd,ib_bdy) >= iw .AND. nbidta(ib,igrd,ib_bdy) <= ie .AND.   &
-                  & nbjdta(ib,igrd,ib_bdy) >= is .AND. nbjdta(ib,igrd,ib_bdy) <= in       ) THEN
+                  & nbjdta(ib,igrd,ib_bdy) >= is .AND. nbjdta(ib,igrd,ib_bdy) <= in .AND.   &
+                  & nbrdta(ib,igrd,ib_bdy) <= nn_rimwidth(ib_bdy)     ) THEN      
                   !
                   icount = icount  + 1
@@ -765,5 +776,7 @@
          ! Allocate index arrays for this boundary set
          !--------------------------------------------
-         ilen1 = MAXVAL(idx_bdy(ib_bdy)%nblen(:))
+
+         ilen1 = MAXVAL(idx_bdy(ib_bdy)%nblen(1:jpbgrd))
+         ilen1 = MAX(1,ilen1)
          ALLOCATE( idx_bdy(ib_bdy)%nbi(ilen1,jpbgrd) )
          ALLOCATE( idx_bdy(ib_bdy)%nbj(ilen1,jpbgrd) )
@@ -773,5 +786,5 @@
          ALLOCATE( idx_bdy(ib_bdy)%nbw(ilen1,jpbgrd) )
          ALLOCATE( idx_bdy(ib_bdy)%flagu(ilen1) )
-         ALLOCATE( idx_bdy(ib_bdy)%flagv(ilen1) )
+         ALLOCATE( idx_bdy(ib_bdy)%flagv(ilen1) )      
 
          ! Dispatch mapping indices and discrete distances on each processor
@@ -1008,5 +1021,8 @@
       ! bdytmask = 1  on the computational domain AND on open boundaries
       !          = 0  elsewhere   
- 
+      bdytmask(:,:) = 1.e0
+      bdyumask(:,:) = 1.e0
+      bdyvmask(:,:) = 1.e0
+
       IF( ln_mask_file ) THEN
          CALL iom_open( cn_mask_file, inum )
@@ -1053,17 +1069,4 @@
       
       bdytmask(:,:) = tmask(:,:,1)
-      IF( .not. ln_mask_file ) THEN
-         ! If .not. ln_mask_file then we need to derive mask on U and V grid 
-         ! from mask on T grid here.
-         bdyumask(:,:) = 0.e0
-         bdyvmask(:,:) = 0.e0
-         DO ij=1, jpjm1
-            DO ii=1, jpim1
-               bdyumask(ii,ij)=bdytmask(ii,ij)*bdytmask(ii+1, ij )
-               bdyvmask(ii,ij)=bdytmask(ii,ij)*bdytmask(ii  ,ij+1)  
-            END DO
-         END DO
-         CALL lbc_lnk( bdyumask(:,:), 'U', 1. )   ;   CALL lbc_lnk( bdyvmask(:,:), 'V', 1. )      ! Lateral boundary cond.
-      ENDIF
 
       ! bdy masks and bmask are now set to zero on boundary points:
