Index: branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/iceforcing.F90
===================================================================
--- branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/iceforcing.F90	(revision 8486)
+++ branches/2017/dev_r8183_ICEMODEL/NEMOGCM/NEMO/LIM_SRC_3/iceforcing.F90	(revision 8498)
@@ -65,5 +65,5 @@
       IF( kt == nit000 .AND. lwp ) THEN
          WRITE(numout,*)
-         WRITE(numout,*)'ice_forcing_tau'
+         WRITE(numout,*)'ice_forcing_tau : Surface boundary condition for sea ice (momentum)'
          WRITE(numout,*)'~~~~~~~~~~~~~~~'
       ENDIF
@@ -124,5 +124,5 @@
       IF( kt == nit000 .AND. lwp ) THEN
          WRITE(numout,*)
-         WRITE(numout,*)'ice_forcing_flx'
+         WRITE(numout,*)'ice_forcing_flx : Surface boundary condition for sea ice (flux)'
          WRITE(numout,*)'~~~~~~~~~~~~~~~'
       ENDIF
@@ -132,13 +132,6 @@
 
       ! albedo depends on cloud fraction because of non-linear spectral effects
-      DO jl = 1, jpl
-         DO jj = 2, jpjm1
-            DO ji = 2, jpim1
 !!gm cldf_ice is a real, DOCTOR naming rule: start with cd means CHARACTER passed in argument !
-               alb_ice(ji,jj,jl) = ( 1. - cldf_ice ) * zalb_cs(ji,jj,jl) + cldf_ice * zalb_os(ji,jj,jl)
-            END DO
-         END DO
-      END DO
-      CALL lbc_lnk( alb_ice, 'T', 1. )
+      alb_ice(:,:,:) = ( 1. - cldf_ice ) * zalb_cs(:,:,:) + cldf_ice * zalb_os(:,:,:)
       
       SELECT CASE( ksbc )      !==  fluxes over sea ice  ==!
@@ -198,52 +191,52 @@
       INTEGER  ::   jl      ! dummy loop index
       !
-      REAL(wp), DIMENSION(jpi,jpj) :: zalb_m    ! Mean albedo over all categories
-      REAL(wp), DIMENSION(jpi,jpj) :: ztem_m    ! Mean temperature over all categories
-      !
-      REAL(wp), DIMENSION(jpi,jpj) :: z_qsr_m   ! Mean solar heat flux over all categories
-      REAL(wp), DIMENSION(jpi,jpj) :: z_qns_m   ! Mean non solar heat flux over all categories
-      REAL(wp), DIMENSION(jpi,jpj) :: z_evap_m  ! Mean sublimation over all categories
-      REAL(wp), DIMENSION(jpi,jpj) :: z_dqn_m   ! Mean d(qns)/dT over all categories
-      REAL(wp), DIMENSION(jpi,jpj) :: z_devap_m ! Mean d(evap)/dT over all categories
+      REAL(wp), DIMENSION(jpi,jpj) ::   z1_at_i   ! inverse of concentration
+      !
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   z_qsr_m   ! Mean solar heat flux over all categories
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   z_qns_m   ! Mean non solar heat flux over all categories
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   z_evap_m  ! Mean sublimation over all categories
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   z_dqn_m   ! Mean d(qns)/dT over all categories
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   z_devap_m ! Mean d(evap)/dT over all categories
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   zalb_m    ! Mean albedo over all categories
+      REAL(wp), ALLOCATABLE, DIMENSION(:,:) ::   ztem_m    ! Mean temperature over all categories
       !!----------------------------------------------------------------------
       !
       IF( nn_timing == 1 )  CALL timing_start('ice_flx_dist')
       !
+      WHERE ( at_i (:,:) > 0._wp )   ; z1_at_i(:,:) = 1._wp / at_i (:,:)
+      ELSEWHERE                      ; z1_at_i(:,:) = 0._wp
+      END WHERE
+      
       SELECT CASE( k_limflx )       !==  averaged on all ice categories  ==!
       !
       CASE( 0 , 1 )
-         z_qns_m  (:,:) = fice_ice_ave( pqns_ice  (:,:,:) )
-         z_qsr_m  (:,:) = fice_ice_ave( pqsr_ice  (:,:,:) )
-         z_dqn_m  (:,:) = fice_ice_ave( pdqn_ice  (:,:,:) )
-         z_evap_m (:,:) = fice_ice_ave( pevap_ice (:,:,:) )
-         z_devap_m(:,:) = fice_ice_ave( pdevap_ice(:,:,:) )
-!!gm faster coding
-!    REAL(wp), DIMENSION(jpi,jpj) ::   z1_at_i   ! 
-! ...
-!      WHERE ( at_i (:,:) > 0._wp )   ; z1_at_i(:,:) = 1._wp / at_i (:,:)
-!      ELSEWHERE                      ; z1_at_i(:,:) = 0._wp
-!      END WHERE
-!      z_qns_m  (:,:) = SUM( a_i(:,:,:) * pqns_ice  (:,:,:) , dim=3 ) * z1_at_i(:,:)
-!      z_qsr_m  (:,:) = SUM( a_i(:,:,:) * pqsr_ice  (:,:,:) , dim=3 ) * z1_at_i(:,:)
-!      z_dqn_m  (:,:) = SUM( a_i(:,:,:) * pdqn_ice  (:,:,:) , dim=3 ) * z1_at_i(:,:)
-!      z_evap_m (:,:) = SUM( a_i(:,:,:) * pevap_ice (:,:,:) , dim=3 ) * z1_at_i(:,:)
-!      z_devap_m(:,:) = SUM( a_i(:,:,:) * pdevap_ice(:,:,:) , dim=3 ) * z1_at_i(:,:)
-!! and remove the 2 functions: fice_ice_ave and fice_cell_ave
-!!gm
+         !
+         ALLOCATE( z_qns_m(jpi,jpj), z_qsr_m(jpi,jpj), z_dqn_m(jpi,jpj), z_evap_m(jpi,jpj), z_devap_m(jpi,jpj) )  
+         !
+         z_qns_m  (:,:) = SUM( a_i(:,:,:) * pqns_ice  (:,:,:) , dim=3 ) * z1_at_i(:,:)
+         z_qsr_m  (:,:) = SUM( a_i(:,:,:) * pqsr_ice  (:,:,:) , dim=3 ) * z1_at_i(:,:)
+         z_dqn_m  (:,:) = SUM( a_i(:,:,:) * pdqn_ice  (:,:,:) , dim=3 ) * z1_at_i(:,:)
+         z_evap_m (:,:) = SUM( a_i(:,:,:) * pevap_ice (:,:,:) , dim=3 ) * z1_at_i(:,:)
+         z_devap_m(:,:) = SUM( a_i(:,:,:) * pdevap_ice(:,:,:) , dim=3 ) * z1_at_i(:,:)
          DO jl = 1, jpl
-            pdqn_ice  (:,:,jl) = z_dqn_m  (:,:)
-            pdevap_ice(:,:,jl) = z_devap_m(:,:)
             pqns_ice  (:,:,jl) = z_qns_m (:,:)
             pqsr_ice  (:,:,jl) = z_qsr_m (:,:)
+            pdqn_ice  (:,:,jl) = z_dqn_m  (:,:)
             pevap_ice (:,:,jl) = z_evap_m(:,:)
+            pdevap_ice(:,:,jl) = z_devap_m(:,:)
          END DO
          !
+         DEALLOCATE( z_qns_m, z_qsr_m, z_dqn_m, z_evap_m, z_devap_m )  
+         !
       END SELECT
       !
       SELECT CASE( k_limflx )       !==  redistribution on all ice categories  ==!
+      !
       CASE( 1 , 2 )
          !
-         zalb_m(:,:) = fice_ice_ave( palb_ice(:,:,:) )
-         ztem_m(:,:) = fice_ice_ave( ptn_ice (:,:,:) )
+         ALLOCATE( zalb_m(jpi,jpj), ztem_m(jpi,jpj) )  
+         !
+         zalb_m(:,:) = SUM( a_i(:,:,:) * palb_ice(:,:,:) , dim=3 ) * z1_at_i(:,:)
+         ztem_m(:,:) = SUM( a_i(:,:,:) * ptn_ice (:,:,:) , dim=3 ) * z1_at_i(:,:)
          DO jl = 1, jpl
             pqns_ice (:,:,jl) = pqns_ice (:,:,jl) + pdqn_ice  (:,:,jl) * ( ptn_ice(:,:,jl) - ztem_m(:,:) )
@@ -252,4 +245,6 @@
          END DO
          !
+         DEALLOCATE( zalb_m, ztem_m )  
+         !
       END SELECT
       !
@@ -257,34 +252,4 @@
       !
    END SUBROUTINE ice_flx_dist
-
-!!gm TO BE REMOVED ====>>>>>
-   FUNCTION fice_cell_ave ( ptab )
-      !!--------------------------------------------------------------------------
-      !! * Compute average over categories, for grid cell (ice covered and free ocean)
-      !!--------------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj,jpl), INTENT(in) :: ptab
-      REAL(wp), DIMENSION(jpi,jpj)                 :: fice_cell_ave
-      INTEGER :: jl
-      !!--------------------------------------------------------------------------
-      fice_cell_ave(:,:) = a_i(:,:,1) * ptab (:,:,1)
-      DO jl = 2, jpl
-         fice_cell_ave(:,:) = fice_cell_ave(:,:) + a_i(:,:,jl) * ptab (:,:,jl)
-      END DO
-   END FUNCTION fice_cell_ave
-
-
-   FUNCTION fice_ice_ave ( ptab )
-      !!--------------------------------------------------------------------------
-      !! * Compute average over categories, for ice covered part of grid cell
-      !!--------------------------------------------------------------------------
-      REAL(wp), DIMENSION(jpi,jpj,jpl), INTENT(in) ::   ptab   !
-      REAL(wp), DIMENSION(jpi,jpj)                 :: fice_ice_ave
-      !!--------------------------------------------------------------------------
-      WHERE ( at_i (:,:) > 0.0_wp ) ; fice_ice_ave (:,:) = fice_cell_ave( ptab (:,:,:) ) / at_i (:,:)
-      ELSEWHERE                     ; fice_ice_ave (:,:) = 0.0_wp
-      END WHERE
-   END FUNCTION fice_ice_ave
-
-!!gm <<<<<<====  end of TO BE REMOVED 
 
 #else
