Index: NEMO/branches/UKMO/NEMO_4.0.4_FOAM_pcbias/src/OCE/ASM/bias.F90
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.4_FOAM_pcbias/src/OCE/ASM/bias.F90	(revision 15602)
+++ NEMO/branches/UKMO/NEMO_4.0.4_FOAM_pcbias/src/OCE/ASM/bias.F90	(revision 15704)
@@ -59,4 +59,5 @@
    !!   bias_opn   : open bias files for restart capabilities
    !!   bias_wrt   : write bias fies "     "          "
+   !!   bias_deallocate : deallocate variables
    !!----------------------------------------------------------------------
    !! * Modules used
@@ -108,5 +109,6 @@
       &   dyn_bias,    &   !: " density correction for pressure gradient.
       &   bias_opn,    &
-      &   bias_wrt
+      &   bias_wrt,    &
+      &   bias_deallocate
 
    !! * Shared variables
@@ -516,21 +518,20 @@
          ! Use the inertial ramp.
          lenscl_bias = ( rn_maxlat_bias - rn_minlat_bias )*2._wp
+	 fbcoef(:,:) = 1._wp - exp( -( abs( gphit(:,:) ) - rn_minlat_bias ) &
+                       * ( abs( gphit(:,:) ) - rn_minlat_bias ) / lenscl_bias )   
          WHERE ( abs( gphit(:,:) ) <= rn_minlat_bias )         
             fbcoef(:,:) = 0._wp          
-         ELSEWHERE ( abs( gphit(:,:) ) >= rn_maxlat_bias )         
-            fbcoef(:,:) = 1._wp                    
-         ELSEWHERE        
-            fbcoef(:,:) = 1._wp - exp( -( abs( gphit(:,:) ) - rn_minlat_bias ) &
-                           * ( abs( gphit(:,:) ) - rn_minlat_bias ) / lenscl_bias )                         
+         ENDWHERE 
+         WHERE ( abs( gphit(:,:) ) >= rn_maxlat_bias )         
+            fbcoef(:,:) = 1._wp                                         
          ENDWHERE 
       ELSEIF ( nn_lat_ramp == 2 ) THEN   
          ! Use a linear ramp consist with the geostrophic velocity balance ramp in NEMOVAR
-     
+         fbcoef(:,:) = 1._wp - ((rn_maxlat_bias - abs( gphit(:,:)))/(rn_maxlat_bias - rn_minlat_bias))
          WHERE ( abs( gphit(:,:) ) <= rn_minlat_bias )
             fbcoef(:,:) = 0._wp
-         ELSEWHERE ( abs( gphit(:,:) ) >= rn_maxlat_bias ) 
+         ENDWHERE
+         WHERE ( abs( gphit(:,:) ) >= rn_maxlat_bias ) 
             fbcoef(:,:) = 1._wp
-         ELSEWHERE
-            fbcoef(:,:) = 1._wp - ((rn_maxlat_bias - abs( gphit(:,:)))/(rn_maxlat_bias - rn_minlat_bias))
          ENDWHERE
       ELSE
@@ -544,10 +545,10 @@
          minlat_bias = 3.0_wp
          maxlat_bias = 8.0_wp  
+         fbcoef_stscale(:,:)=1._wp - ((maxlat_bias - abs( gphit(:,:)))/(maxlat_bias-minlat_bias))
          WHERE ( abs( gphit(:,:) ) <= minlat_bias )
             fbcoef_stscale(:,:)=0._wp
-         ELSEWHERE ( abs( gphit(:,:) ) >= maxlat_bias ) 
+         ENDWHERE 
+         WHERE ( abs( gphit(:,:) ) >= maxlat_bias ) 
             fbcoef_stscale(:,:)=1._wp
-         ELSEWHERE
-            fbcoef_stscale(:,:)=1._wp - ((maxlat_bias - abs( gphit(:,:)))/(maxlat_bias-minlat_bias))
          ENDWHERE   
       ENDIF 
@@ -1011,3 +1012,44 @@
    END SUBROUTINE bias_wrt
 
+
+   SUBROUTINE bias_deallocate
+      !!---------------------------------------------------------------------
+      !!                   ***  ROUTINE bias_deallocate  ***
+      !!                     
+      !! ** Purpose :   Deallocate bias fields
+      !!
+      !!
+      !!----------------------------------------------------------------------
+      !!----------------------------------------------------------------------
+      !
+      IF ( ALLOCATED( tbias ) ) DEALLOCATE( tbias )
+      IF ( ALLOCATED( sbias ) ) DEALLOCATE( sbias )
+      IF ( ALLOCATED( tbias_p ) ) DEALLOCATE( tbias_p )
+      IF ( ALLOCATED( sbias_p ) ) DEALLOCATE( sbias_p )
+      IF ( ALLOCATED( tbias_i ) ) DEALLOCATE( tbias_i )
+      IF ( ALLOCATED( sbias_i ) ) DEALLOCATE( sbias_i )
+      IF ( ALLOCATED( rhd_pc ) ) DEALLOCATE( rhd_pc )
+      IF ( ALLOCATED( fbcoef ) ) DEALLOCATE( fbcoef )
+      IF ( ALLOCATED( fbcoef_stscale ) ) DEALLOCATE( fbcoef_stscale )
+      IF ( ALLOCATED( tbias_asm ) ) DEALLOCATE( tbias_asm )
+      IF ( ALLOCATED( sbias_asm ) ) DEALLOCATE( sbias_asm )
+      IF ( ALLOCATED( tbias_asm_out ) ) DEALLOCATE( tbias_asm_out )
+      IF ( ALLOCATED( sbias_asm_out ) ) DEALLOCATE( sbias_asm_out )
+      IF ( ALLOCATED( tbias_p_out ) ) DEALLOCATE( tbias_p_out )
+      IF ( ALLOCATED( sbias_p_out ) ) DEALLOCATE( sbias_p_out )
+      IF ( ALLOCATED( tbias_rlx ) ) DEALLOCATE( tbias_rlx )
+      IF ( ALLOCATED( sbias_rlx ) ) DEALLOCATE( sbias_rlx )
+      IF ( ALLOCATED( tbias_rlx_out ) ) DEALLOCATE( tbias_rlx_out )
+      IF ( ALLOCATED( sbias_rlx_out ) ) DEALLOCATE( sbias_rlx_out )
+      IF ( ALLOCATED( tbias_asm_stscale ) ) DEALLOCATE( tbias_asm_stscale )
+      IF ( ALLOCATED( sbias_asm_stscale ) ) DEALLOCATE( sbias_asm_stscale )
+      IF ( ALLOCATED( tbias_asm_stscale_out ) ) DEALLOCATE( tbias_asm_stscale_out )
+      IF ( ALLOCATED( sbias_asm_stscale_out ) ) DEALLOCATE( sbias_asm_stscale_out )
+      IF ( ALLOCATED( tbias_i_out ) ) DEALLOCATE( tbias_i_out )
+      IF ( ALLOCATED( sbias_i_out ) ) DEALLOCATE( sbias_i_out )
+      IF ( ALLOCATED( sf_tbias_ofl ) ) DEALLOCATE( sf_tbias_ofl )
+      IF ( ALLOCATED( sf_sbias_ofl ) ) DEALLOCATE( sf_sbias_ofl )
+      !
+   END SUBROUTINE bias_deallocate
+
 END MODULE bias
Index: NEMO/branches/UKMO/NEMO_4.0.4_FOAM_pcbias/src/OCE/nemogcm.F90
===================================================================
--- NEMO/branches/UKMO/NEMO_4.0.4_FOAM_pcbias/src/OCE/nemogcm.F90	(revision 15602)
+++ NEMO/branches/UKMO/NEMO_4.0.4_FOAM_pcbias/src/OCE/nemogcm.F90	(revision 15704)
@@ -215,5 +215,7 @@
       !
       IF( ln_icebergs )   CALL icb_end( nitend )
-
+      !
+      IF( lk_asminc    )  CALL bias_deallocate
+      !
       !                            !------------------------!
       !                            !==  finalize the run  ==!
