Index: branches/UKMO/dev_r5518_GO6_package/NEMOGCM/NEMO/OPA_SRC/SBC/sbccpl.F90
===================================================================
--- branches/UKMO/dev_r5518_GO6_package/NEMOGCM/NEMO/OPA_SRC/SBC/sbccpl.F90	(revision 11101)
+++ branches/UKMO/dev_r5518_GO6_package/NEMOGCM/NEMO/OPA_SRC/SBC/sbccpl.F90	(revision 11107)
@@ -55,4 +55,8 @@
    USE lib_fortran, ONLY: glob_sum
 
+#if defined key_oasis3
+   USE mod_oasis, ONLY : OASIS_Sent, OASIS_ToRest, OASIS_SentOut, OASIS_ToRestOut
+#endif
+
    IMPLICIT NONE
    PRIVATE
@@ -156,4 +160,12 @@
 	                                              ! i.e. specifically nmol/L (= umol/m3)
 
+#if ! defined key_oasis3
+   ! Dummy variables to enable compilation when oasis3 is not being used
+   INTEGER                    ::   OASIS_Sent        = -1
+   INTEGER                    ::   OASIS_SentOut     = -1
+   INTEGER                    ::   OASIS_ToRest      = -1
+   INTEGER                    ::   OASIS_ToRestOut   = -1
+#endif
+
    !                                                         !!** namelist namsbc_cpl **
    TYPE ::   FLD_C
@@ -177,4 +189,5 @@
    LOGICAL     ::   ln_usecplmask          !  use a coupling mask file to merge data received from several models
                                            !   -> file cplmask.nc with the float variable called cplmask (jpi,jpj,nn_cplmodel)
+   LOGICAL, PUBLIC ::   ln_fix_sea_ice_fluxes     ! Apply sea ice flux bug fixes (GMED#449)
 
    TYPE ::   DYNARR     
@@ -203,5 +216,5 @@
       !!             ***  FUNCTION sbc_cpl_alloc  ***
       !!----------------------------------------------------------------------
-      INTEGER :: ierr(3)
+      INTEGER :: ierr(4)
       !!----------------------------------------------------------------------
       ierr(:) = 0
@@ -215,5 +228,8 @@
       ! Hardwire only two models as nn_cplmodel has not been read in
       ! from the namelist yet.
-      ALLOCATE( xcplmask(jpi,jpj,0:2) , STAT=ierr(3) )   
+      ALLOCATE( xcplmask(jpi,jpj,0:2) , STAT=ierr(3) ) 
+#if defined key_cice
+      ALLOCATE( a_i_last_couple(jpi,jpj,jpl) , STAT=ierr(4) ) 
+#endif
       !
       sbc_cpl_alloc = MAXVAL( ierr )
@@ -250,5 +266,6 @@
          &                  ln_usecplmask, nn_coupled_iceshelf_fluxes, ln_iceshelf_init_atmos,        &
          &                  rn_greenland_total_fw_flux, rn_greenland_calving_fraction, &
-         &                  rn_antarctica_total_fw_flux, rn_antarctica_calving_fraction, rn_iceshelf_fluxes_tolerance
+         &                  rn_antarctica_total_fw_flux, rn_antarctica_calving_fraction, rn_iceshelf_fluxes_tolerance, &
+         &                  ln_fix_sea_ice_fluxes
       !!---------------------------------------------------------------------
 
@@ -321,4 +338,5 @@
          WRITE(numout,*)'  nn_cplmodel                         = ', nn_cplmodel
          WRITE(numout,*)'  ln_usecplmask                       = ', ln_usecplmask
+         WRITE(numout,*)'  ln_fix_sea_ice_fluxes               = ', ln_fix_sea_ice_fluxes
          WRITE(numout,*)'  nn_coupled_iceshelf_fluxes          = ', nn_coupled_iceshelf_fluxes
          WRITE(numout,*)'  ln_iceshelf_init_atmos              = ', ln_iceshelf_init_atmos
@@ -1844,7 +1862,15 @@
          IF ( TRIM(sn_rcv_emp%clcat) == 'yes' ) THEN
             ! zemp_ice is the sum of frcv(jpr_ievp)%z3(:,:,1) over all layers - snow
-            zemp_ice(:,:) = - frcv(jpr_snow)%z3(:,:,1)
+            IF ( ln_fix_sea_ice_fluxes ) THEN
+               zemp_ice(:,:) = - frcv(jpr_snow)%z3(:,:,1) * zicefr(:,:)
+            ELSE
+               zemp_ice(:,:) = - frcv(jpr_snow)%z3(:,:,1)
+            ENDIF
             DO jl=1,jpl
-               zemp_ice(:,:   ) = zemp_ice(:,:) + frcv(jpr_ievp)%z3(:,:,jl)
+               IF ( ln_fix_sea_ice_fluxes ) THEN
+                  zemp_ice(:,:   ) = zemp_ice(:,:) + frcv(jpr_ievp)%z3(:,:,jl) * a_i_last_couple(:,:,jl)
+               ELSE
+                  zemp_ice(:,:   ) = zemp_ice(:,:) + frcv(jpr_ievp)%z3(:,:,jl)
+               ENDIF
             ENDDO
             ! latent heat coupled for each category in CICE
@@ -2357,4 +2383,17 @@
          END SELECT
          IF( ssnd(jps_fice)%laction )   CALL cpl_snd( jps_fice, isec, ztmp3, info )
+
+#if defined key_lim2 || defined key_cice
+         ! If this coupling was successful then save ice fraction for use between coupling points.
+         ! This is needed for some calculations where the ice fraction at the last coupling point
+         ! is needed.
+         IF( info == OASIS_Sent     .OR. info == OASIS_ToRest .OR.   &
+                     & info == OASIS_SentOut  .OR. info == OASIS_ToRestOut ) THEN
+           IF ( sn_snd_thick%clcat == 'yes' ) THEN
+             a_i_last_couple(:,:,:) = a_i(:,:,:)
+           ENDIF
+         ENDIF
+#endif
+         
       ENDIF
       
