New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
Changeset 5260 for branches/2014/dev_r4650_UKMO10_Tidally_Meaned_Diagnostics/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim.F90 – NEMO

Ignore:
Timestamp:
2015-05-12T12:37:15+02:00 (9 years ago)
Author:
deazer
Message:

Merged branch with Trunk at revision 5253.
Checked with SETTE, passes modified iodef.xml for AMM12 experiment

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2014/dev_r4650_UKMO10_Tidally_Meaned_Diagnostics/NEMOGCM/NEMO/OPA_SRC/SBC/sbcice_lim.F90

    r4333 r5260  
    1212   !!            3.4  ! 2011-01  (A Porter)  dynamical allocation 
    1313   !!             -   ! 2012-10  (C. Rousset)  add lim_diahsb 
     14   !!            3.6  ! 2014-07  (M. Vancoppenolle, G. Madec, O. Marti) revise coupled interface 
    1415   !!---------------------------------------------------------------------- 
    1516#if defined key_lim3 
     
    1819   !!---------------------------------------------------------------------- 
    1920   !!   sbc_ice_lim  : sea-ice model time-stepping and update ocean sbc over ice-covered area 
    20    !!   lim_ctl       : alerts in case of ice model crash 
    21    !!   lim_prt_state : ice control print at a given grid point 
    2221   !!---------------------------------------------------------------------- 
    2322   USE oce             ! ocean dynamics and tracers 
    2423   USE dom_oce         ! ocean space and time domain 
    25    USE par_ice         ! sea-ice parameters 
    2624   USE ice             ! LIM-3: ice variables 
    27    USE iceini          ! LIM-3: ice initialisation 
     25   USE thd_ice         ! LIM-3: thermodynamical variables 
    2826   USE dom_ice         ! LIM-3: ice domain 
    2927 
     
    4038   USE limtrp          ! Ice transport 
    4139   USE limthd          ! Ice thermodynamics 
    42    USE limitd_th       ! Thermodynamics on ice thickness distribution  
    4340   USE limitd_me       ! Mechanics on ice thickness distribution 
    4441   USE limsbc          ! sea surface boundary condition 
     
    4643   USE limwri          ! Ice outputs 
    4744   USE limrst          ! Ice restarts 
    48    USE limupdate1       ! update of global variables 
    49    USE limupdate2       ! update of global variables 
     45   USE limupdate1      ! update of global variables 
     46   USE limupdate2      ! update of global variables 
    5047   USE limvar          ! Ice variables switch 
     48 
     49   USE limmsh          ! LIM mesh 
     50   USE limistate       ! LIM initial state 
     51   USE limthd_sal      ! LIM ice thermodynamics: salinity 
    5152 
    5253   USE c1d             ! 1D vertical configuration 
     
    5960   USE prtctl          ! Print control 
    6061   USE lib_fortran     !  
     62   USE limctl 
    6163 
    6264#if defined key_bdy  
     
    6870 
    6971   PUBLIC sbc_ice_lim  ! routine called by sbcmod.F90 
     72   PUBLIC sbc_lim_init ! routine called by sbcmod.F90 
    7073    
    7174   !! * Substitutions 
     
    7881   !!---------------------------------------------------------------------- 
    7982CONTAINS 
    80  
    81    FUNCTION fice_cell_ave ( ptab) 
    82       !!-------------------------------------------------------------------------- 
    83       !! * Compute average over categories, for grid cell (ice covered and free ocean) 
    84       !!-------------------------------------------------------------------------- 
    85       REAL (wp), DIMENSION (jpi,jpj) :: fice_cell_ave 
    86       REAL (wp), DIMENSION (jpi,jpj,jpl), INTENT (in) :: ptab 
    87       INTEGER :: jl ! Dummy loop index 
    88        
    89       fice_cell_ave (:,:) = 0.0_wp 
    90        
    91       DO jl = 1, jpl 
    92          fice_cell_ave (:,:) = fice_cell_ave (:,:) & 
    93             &                  + a_i (:,:,jl) * ptab (:,:,jl) 
    94       END DO 
    95        
    96    END FUNCTION fice_cell_ave 
    97     
    98    FUNCTION fice_ice_ave ( ptab) 
    99       !!-------------------------------------------------------------------------- 
    100       !! * Compute average over categories, for ice covered part of grid cell 
    101       !!-------------------------------------------------------------------------- 
    102       REAL (kind=wp), DIMENSION (jpi,jpj) :: fice_ice_ave 
    103       REAL (kind=wp), DIMENSION (jpi,jpj,jpl), INTENT(in) :: ptab 
    104  
    105       fice_ice_ave (:,:) = 0.0_wp 
    106       WHERE ( at_i (:,:) .GT. 0.0_wp ) fice_ice_ave (:,:) = fice_cell_ave ( ptab (:,:,:)) / at_i (:,:) 
    107  
    108    END FUNCTION fice_ice_ave 
    10983 
    11084   !!====================================================================== 
     
    131105      !!--------------------------------------------------------------------- 
    132106      INTEGER, INTENT(in) ::   kt      ! ocean time step 
    133       INTEGER, INTENT(in) ::   kblk    ! type of bulk (=3 CLIO, =4 CORE) 
    134       !! 
    135       INTEGER  ::   jl      ! dummy loop index 
    136       REAL(wp) ::   zcoef   ! local scalar 
    137       REAL(wp), POINTER, DIMENSION(:,:,:)   ::   zalb_ice_os, zalb_ice_cs  ! albedo of the ice under overcast/clear sky 
    138       REAL(wp), POINTER, DIMENSION(:,:,:)   ::   zalb_ice      ! mean albedo of ice (for coupled) 
    139  
    140       REAL(wp), POINTER, DIMENSION(:,:) :: zalb_ice_all    ! Mean albedo over all categories 
    141       REAL(wp), POINTER, DIMENSION(:,:) :: ztem_ice_all    ! Mean temperature over all categories 
    142        
    143       REAL(wp), POINTER, DIMENSION(:,:) :: z_qsr_ice_all   ! Mean solar heat flux over all categories 
    144       REAL(wp), POINTER, DIMENSION(:,:) :: z_qns_ice_all   ! Mean non solar heat flux over all categories 
    145       REAL(wp), POINTER, DIMENSION(:,:) :: z_qla_ice_all   ! Mean latent heat flux over all categories 
    146       REAL(wp), POINTER, DIMENSION(:,:) :: z_dqns_ice_all  ! Mean d(qns)/dT over all categories 
    147       REAL(wp), POINTER, DIMENSION(:,:) :: z_dqla_ice_all  ! Mean d(qla)/dT over all categories 
    148       !!---------------------------------------------------------------------- 
    149  
    150       !- O.M. : why do we allocate all these arrays even when MOD( kt-1, nn_fsbc ) /= 0 ????? 
     107      INTEGER, INTENT(in) ::   kblk    ! type of bulk (=3 CLIO, =4 CORE, =5 COUPLED) 
     108      !! 
     109      INTEGER  ::   jl                 ! dummy loop index 
     110      REAL(wp), POINTER, DIMENSION(:,:,:)   ::   zalb_os, zalb_cs  ! ice albedo under overcast/clear sky 
     111      REAL(wp), POINTER, DIMENSION(:,:,:)   ::   zalb_ice          ! mean ice albedo (for coupled) 
     112      !!---------------------------------------------------------------------- 
    151113 
    152114      IF( nn_timing == 1 )  CALL timing_start('sbc_ice_lim') 
    153115 
    154       CALL wrk_alloc( jpi,jpj,jpl, zalb_ice_os, zalb_ice_cs ) 
    155  
    156 #if defined key_coupled 
    157       IF ( ln_cpl .OR. ln_iceflx_ave .OR. ln_iceflx_linear ) CALL wrk_alloc( jpi,jpj,jpl, zalb_ice) 
    158       IF ( ln_iceflx_ave .OR. ln_iceflx_linear ) & 
    159          &   CALL wrk_alloc( jpi,jpj, ztem_ice_all, zalb_ice_all, z_qsr_ice_all, z_qns_ice_all, z_qla_ice_all, z_dqns_ice_all, z_dqla_ice_all) 
    160 #endif 
    161  
    162       IF( kt == nit000 ) THEN 
    163          IF(lwp) WRITE(numout,*) 
    164          IF(lwp) WRITE(numout,*) 'sbc_ice_lim : update ocean surface boudary condition'  
    165          IF(lwp) WRITE(numout,*) '~~~~~~~~~~~   via Louvain la Neuve Ice Model (LIM-3) time stepping' 
    166          ! 
    167          CALL ice_init 
    168          ! 
    169          IF( ln_nicep ) THEN      ! control print at a given point 
    170             jiindx = 177   ;   jjindx = 112 
    171             IF(lwp) WRITE(numout,*) ' The debugging point is : jiindx : ',jiindx, ' jjindx : ',jjindx 
    172          ENDIF 
    173       ENDIF 
    174  
    175       !                                        !----------------------! 
    176       IF( MOD( kt-1, nn_fsbc ) == 0 ) THEN     !  Ice time-step only  ! 
    177          !                                     !----------------------! 
    178          !                                           !  Bulk Formulea ! 
    179          !                                           !----------------! 
    180          ! 
    181          u_oce(:,:) = ssu_m(:,:)                     ! mean surface ocean current at ice velocity point 
    182          v_oce(:,:) = ssv_m(:,:)                     ! (C-grid dynamics :  U- & V-points as the ocean) 
    183          ! 
    184          t_bo(:,:) = tfreez( sss_m ) +  rt0          ! masked sea surface freezing temperature [Kelvin] 
    185          !                                           ! (set to rt0 over land) 
    186          CALL albedo_ice( t_su, ht_i, ht_s, zalb_ice_cs, zalb_ice_os )  ! ... ice albedo 
    187  
     116      IF( MOD( kt-1, nn_fsbc ) == 0 ) THEN     !  Ice time-step only 
     117         !-----------------------!                                            
     118         ! --- Bulk Formulae --- !                                            
     119         !-----------------------! 
     120         u_oce(:,:) = ssu_m(:,:) * umask(:,:,1)      ! mean surface ocean current at ice velocity point 
     121         v_oce(:,:) = ssv_m(:,:) * vmask(:,:,1)      ! (C-grid dynamics :  U- & V-points as the ocean) 
     122          
     123         ! masked sea surface freezing temperature [Kelvin] (set to rt0 over land) 
     124         t_bo(:,:) = ( eos_fzp( sss_m ) + rt0 ) * tmask(:,:,1) + rt0 * ( 1._wp - tmask(:,:,1) )   
     125         !                                                                                       
     126         ! Ice albedo 
     127         CALL wrk_alloc( jpi,jpj,jpl, zalb_os, zalb_cs, zalb_ice ) 
     128         CALL albedo_ice( t_su, ht_i, ht_s, zalb_cs, zalb_os )  ! cloud-sky and overcast-sky ice albedos 
     129 
     130         ! CORE and COUPLED bulk formulations 
     131         SELECT CASE( kblk ) 
     132         CASE( jp_core , jp_cpl ) 
     133 
     134            ! albedo depends on cloud fraction because of non-linear spectral effects 
     135            zalb_ice(:,:,:) = ( 1. - cldf_ice ) * zalb_cs(:,:,:) + cldf_ice * zalb_os(:,:,:) 
     136            ! In CLIO the cloud fraction is read in the climatology and the all-sky albedo  
     137            ! (zalb_ice) is computed within the bulk routine 
     138             
     139         END SELECT 
     140          
     141         ! Mask sea ice surface temperature (set to rt0 over land) 
    188142         DO jl = 1, jpl 
    189             t_su(:,:,jl) = t_su(:,:,jl) +  rt0 * ( 1. - tmask(:,:,1) ) 
     143            t_su(:,:,jl) = t_su(:,:,jl) * tmask(:,:,1) + rt0 * ( 1._wp - tmask(:,:,1) ) 
    190144         END DO 
    191  
    192          IF ( ln_cpl ) zalb_ice (:,:,:) = 0.5 * ( zalb_ice_cs (:,:,:) +  zalb_ice_os (:,:,:) ) 
    193           
    194 #if defined key_coupled 
    195          IF ( ln_iceflx_ave .OR. ln_iceflx_linear ) THEN 
    196             ! 
    197             ! Compute mean albedo and temperature 
    198             zalb_ice_all (:,:) = fice_ice_ave ( zalb_ice (:,:,:) )  
    199             ztem_ice_all (:,:) = fice_ice_ave ( tn_ice   (:,:,:) )  
    200             ! 
    201          ENDIF 
    202 #endif 
    203                                                ! Bulk formulea - provides the following fields: 
     145      
     146         ! Bulk formulae  - provides the following fields: 
    204147         ! utau_ice, vtau_ice : surface ice stress                     (U- & V-points)   [N/m2] 
    205148         ! qsr_ice , qns_ice  : solar & non solar heat flux over ice   (T-point)         [W/m2] 
     
    210153         ! 
    211154         SELECT CASE( kblk ) 
    212          CASE( 3 )                                       ! CLIO bulk formulation 
    213             CALL blk_ice_clio( t_su , zalb_ice_cs, zalb_ice_os,                           & 
     155         CASE( jp_clio )                                       ! CLIO bulk formulation 
     156            CALL blk_ice_clio( t_su , zalb_cs    , zalb_os    , zalb_ice  ,               & 
    214157               &                      utau_ice   , vtau_ice   , qns_ice   , qsr_ice   ,   & 
    215158               &                      qla_ice    , dqns_ice   , dqla_ice  ,               & 
     
    217160               &                      fr1_i0     , fr2_i0     , cp_ice_msh, jpl  ) 
    218161            !          
    219          CASE( 4 )                                       ! CORE bulk formulation 
    220             CALL blk_ice_core( t_su , u_ice     , v_ice     , zalb_ice_cs,               & 
     162            IF( nn_limflx /= 2 )   CALL ice_lim_flx( t_su, zalb_ice, qns_ice, qsr_ice ,   & 
     163               &                                           dqns_ice, qla_ice, dqla_ice, nn_limflx ) 
     164 
     165         CASE( jp_core )                                       ! CORE bulk formulation 
     166            CALL blk_ice_core( t_su , u_ice     , v_ice     , zalb_ice   ,               & 
    221167               &                      utau_ice  , vtau_ice  , qns_ice    , qsr_ice   ,   & 
    222168               &                      qla_ice   , dqns_ice  , dqla_ice   ,               & 
    223169               &                      tprecip   , sprecip   ,                            & 
    224170               &                      fr1_i0    , fr2_i0    , cp_ice_msh, jpl  ) 
     171               ! 
     172            IF( nn_limflx /= 2 )   CALL ice_lim_flx( t_su, zalb_ice, qns_ice, qsr_ice ,   & 
     173               &                                           dqns_ice, qla_ice, dqla_ice, nn_limflx ) 
    225174            ! 
    226          CASE ( 5 ) 
    227             zalb_ice (:,:,:) = 0.5 * ( zalb_ice_cs (:,:,:) +  zalb_ice_os (:,:,:) ) 
     175         CASE ( jp_cpl ) 
    228176             
    229177            CALL sbc_cpl_ice_tau( utau_ice , vtau_ice ) 
    230178 
    231             CALL sbc_cpl_ice_flx( p_frld=ato_i, palbi=zalb_ice, psst=sst_m, pist=tn_ice    ) 
    232  
    233             ! Latent heat flux is forced to 0 in coupled : 
    234             !  it is included in qns (non-solar heat flux) 
    235             qla_ice  (:,:,:) = 0.0e0_wp 
    236             dqla_ice (:,:,:) = 0.0e0_wp 
    237             ! 
    238179         END SELECT 
    239  
    240          ! Average over all categories 
    241 #if defined key_coupled 
    242          IF ( ln_iceflx_ave .OR. ln_iceflx_linear ) THEN 
    243  
    244             z_qns_ice_all  (:,:) = fice_ice_ave ( qns_ice  (:,:,:) ) 
    245             z_qsr_ice_all  (:,:) = fice_ice_ave ( qsr_ice  (:,:,:) ) 
    246             z_dqns_ice_all (:,:) = fice_ice_ave ( dqns_ice (:,:,:) ) 
    247             z_qla_ice_all  (:,:) = fice_ice_ave ( qla_ice  (:,:,:) ) 
    248             z_dqla_ice_all (:,:) = fice_ice_ave ( dqla_ice (:,:,:) ) 
    249  
    250             DO jl = 1, jpl 
    251                dqns_ice (:,:,jl) = z_dqns_ice_all (:,:) 
    252                dqla_ice (:,:,jl) = z_dqla_ice_all (:,:) 
    253             END DO 
    254             ! 
    255             IF ( ln_iceflx_ave ) THEN 
    256                DO jl = 1, jpl 
    257                   qns_ice  (:,:,jl) = z_qns_ice_all  (:,:) 
    258                   qsr_ice  (:,:,jl) = z_qsr_ice_all  (:,:) 
    259                   qla_ice  (:,:,jl) = z_qla_ice_all  (:,:) 
    260                END DO 
    261             END IF 
    262             ! 
    263             IF ( ln_iceflx_linear ) THEN 
    264                DO jl = 1, jpl 
    265                   qns_ice  (:,:,jl) = z_qns_ice_all(:,:) + z_dqns_ice_all(:,:) * (tn_ice(:,:,jl) - ztem_ice_all(:,:)) 
    266                   qla_ice  (:,:,jl) = z_qla_ice_all(:,:) + z_dqla_ice_all(:,:) * (tn_ice(:,:,jl) - ztem_ice_all(:,:)) 
    267                   qsr_ice  (:,:,jl) = (1.0e0_wp-zalb_ice(:,:,jl)) / (1.0e0_wp-zalb_ice_all(:,:)) * z_qsr_ice_all(:,:) 
    268                END DO 
    269             END IF 
    270          END IF 
    271 #endif 
    272          !                                           !----------------------! 
    273          !                                           ! LIM-3  time-stepping ! 
    274          !                                           !----------------------! 
    275          !  
     180          
     181         !------------------------------! 
     182         ! --- LIM-3 main time-step --- ! 
     183         !------------------------------! 
    276184         numit = numit + nn_fsbc                     ! Ice model time step 
    277          ! 
    278          !                                           ! Store previous ice values 
    279 !!gm : remark   old_...   should becomes ...b  as tn versus tb   
    280          old_a_i  (:,:,:)   = a_i  (:,:,:)     ! ice area 
    281          old_e_i  (:,:,:,:) = e_i  (:,:,:,:)   ! ice thermal energy 
    282          old_v_i  (:,:,:)   = v_i  (:,:,:)     ! ice volume 
    283          old_v_s  (:,:,:)   = v_s  (:,:,:)     ! snow volume  
    284          old_e_s  (:,:,:,:) = e_s  (:,:,:,:)   ! snow thermal energy 
    285          old_smv_i(:,:,:)   = smv_i(:,:,:)     ! salt content 
    286          old_oa_i (:,:,:)   = oa_i (:,:,:)     ! areal age content 
    287          ! 
    288          old_u_ice(:,:) = u_ice(:,:) 
    289          old_v_ice(:,:) = v_ice(:,:) 
    290          !                                           ! intialisation to zero    !!gm is it truly necessary ??? 
    291          d_a_i_thd  (:,:,:)   = 0._wp   ;   d_a_i_trp  (:,:,:)   = 0._wp 
    292          d_v_i_thd  (:,:,:)   = 0._wp   ;   d_v_i_trp  (:,:,:)   = 0._wp 
    293          d_e_i_thd  (:,:,:,:) = 0._wp   ;   d_e_i_trp  (:,:,:,:) = 0._wp 
    294          d_v_s_thd  (:,:,:)   = 0._wp   ;   d_v_s_trp  (:,:,:)   = 0._wp 
    295          d_e_s_thd  (:,:,:,:) = 0._wp   ;   d_e_s_trp  (:,:,:,:) = 0._wp 
    296          d_smv_i_thd(:,:,:)   = 0._wp   ;   d_smv_i_trp(:,:,:)   = 0._wp 
    297          d_oa_i_thd (:,:,:)   = 0._wp   ;   d_oa_i_trp (:,:,:)   = 0._wp 
    298          ! 
    299          d_u_ice_dyn(:,:) = 0._wp 
    300          d_v_ice_dyn(:,:) = 0._wp 
    301          ! 
    302          sfx    (:,:) = 0._wp   ;   sfx_thd  (:,:) = 0._wp 
    303          sfx_bri(:,:) = 0._wp   ;   sfx_mec  (:,:) = 0._wp   ;   sfx_res  (:,:) = 0._wp 
    304          fhbri  (:,:) = 0._wp   ;   fheat_mec(:,:) = 0._wp   ;   fheat_res(:,:) = 0._wp 
    305          fhmec  (:,:) = 0._wp   ;    
    306          fmmec  (:,:) = 0._wp 
    307          fmmflx (:,:) = 0._wp      
    308          focea2D(:,:) = 0._wp 
    309          fsup2D (:,:) = 0._wp 
    310  
    311          ! used in limthd.F90 
    312          rdvosif(:,:) = 0._wp   ! variation of ice volume at surface 
    313          rdvobif(:,:) = 0._wp   ! variation of ice volume at bottom 
    314          fdvolif(:,:) = 0._wp   ! total variation of ice volume 
    315          rdvonif(:,:) = 0._wp   ! lateral variation of ice volume 
    316          fstric (:,:) = 0._wp   ! part of solar radiation transmitted through the ice 
    317          ffltbif(:,:) = 0._wp   ! linked with fstric 
    318          qfvbq  (:,:) = 0._wp   ! linked with fstric 
    319          rdm_snw(:,:) = 0._wp   ! variation of snow mass per unit area 
    320          rdm_ice(:,:) = 0._wp   ! variation of ice mass per unit area 
    321          hicifp (:,:) = 0._wp   ! daily thermodynamic ice production.  
    322          ! 
    323          diag_sni_gr(:,:) = 0._wp   ;   diag_lat_gr(:,:) = 0._wp 
    324          diag_bot_gr(:,:) = 0._wp   ;   diag_dyn_gr(:,:) = 0._wp 
    325          diag_bot_me(:,:) = 0._wp   ;   diag_sur_me(:,:) = 0._wp 
    326          diag_res_pr(:,:) = 0._wp   ;   diag_trp_vi(:,:) = 0._wp 
    327          ! dynamical invariants 
    328          delta_i(:,:) = 0._wp       ;   divu_i(:,:) = 0._wp       ;   shear_i(:,:) = 0._wp 
    329  
    330                           CALL lim_rst_opn( kt )     ! Open Ice restart file 
    331          ! 
    332          IF( ln_nicep )   CALL lim_prt_state( kt, jiindx, jjindx, 1, ' - Beginning the time step - ' )   ! control print 
     185         !                                                    
     186         CALL sbc_lim_bef                   ! Store previous ice values 
     187 
     188         CALL sbc_lim_diag0                 ! set diag of mass, heat and salt fluxes to 0 
     189          
     190         CALL lim_rst_opn( kt )             ! Open Ice restart file 
     191         ! 
    333192         ! ---------------------------------------------- 
    334193         ! ice dynamics and transport (except in 1D case) 
    335194         ! ---------------------------------------------- 
    336195         IF( .NOT. lk_c1d ) THEN 
    337                           CALL lim_dyn( kt )              ! Ice dynamics    ( rheology/dynamics ) 
    338                           CALL lim_trp( kt )              ! Ice transport   ( Advection/diffusion ) 
    339                           CALL lim_var_glo2eqv            ! equivalent variables, requested for rafting 
    340          IF( ln_nicep )   CALL lim_prt_state( kt, jiindx, jjindx,-1, ' - ice dyn & trp - ' )   ! control print 
    341                           CALL lim_itd_me                 ! Mechanical redistribution ! (ridging/rafting) 
    342                           CALL lim_var_agg( 1 )  
     196             
     197            CALL lim_dyn( kt )              ! Ice dynamics    ( rheology/dynamics ) 
     198             
     199            CALL lim_trp( kt )              ! Ice transport   ( Advection/diffusion ) 
     200             
     201            IF( nn_monocat /= 2 ) CALL lim_itd_me  ! Mechanical redistribution ! (ridging/rafting) 
     202 
    343203#if defined key_bdy 
    344                           ! bdy ice thermo  
    345                           CALL lim_var_glo2eqv            ! equivalent variables 
    346                           CALL bdy_ice_lim( kt ) 
    347                           CALL lim_itd_me_zapsmall 
    348                           CALL lim_var_agg(1) 
    349          IF( ln_nicep )   CALL lim_prt_state( kt, jiindx, jjindx, 1, ' - ice thermo bdy - ' )   ! control print 
     204            CALL bdy_ice_lim( kt )         ! bdy ice thermo  
     205            IF( ln_icectl )   CALL lim_prt( kt, iiceprt, jiceprt, 1, ' - ice thermo bdy - ' ) 
    350206#endif 
    351                           CALL lim_update1 
     207            CALL lim_update1( kt ) 
     208             
    352209         ENDIF 
    353 !                         !- Change old values for new values 
    354                           old_u_ice(:,:)   = u_ice (:,:) 
    355                           old_v_ice(:,:)   = v_ice (:,:) 
    356                           old_a_i(:,:,:)   = a_i (:,:,:) 
    357                           old_v_s(:,:,:)   = v_s (:,:,:) 
    358                           old_v_i(:,:,:)   = v_i (:,:,:) 
    359                           old_e_s(:,:,:,:) = e_s (:,:,:,:) 
    360                           old_e_i(:,:,:,:) = e_i (:,:,:,:) 
    361                           old_oa_i(:,:,:)  = oa_i(:,:,:) 
    362                           old_smv_i(:,:,:) = smv_i (:,:,:) 
     210          
     211         CALL sbc_lim_bef                  ! Store previous ice values 
    363212  
    364213         ! ---------------------------------------------- 
    365          ! ice thermodynamic 
     214         ! ice thermodynamics 
    366215         ! ---------------------------------------------- 
    367                           CALL lim_var_glo2eqv            ! equivalent variables 
    368                           CALL lim_var_agg(1)             ! aggregate ice categories 
    369                           ! previous lead fraction and ice volume for flux calculations 
    370                           pfrld(:,:)   = 1._wp - at_i(:,:) 
    371                           phicif(:,:)  = vt_i(:,:) 
    372                           ! 
    373                           CALL lim_var_bv                 ! bulk brine volume (diag) 
    374                           CALL lim_thd( kt )              ! Ice thermodynamics  
    375                           zcoef = rdt_ice /rday           !  Ice natural aging 
    376                           oa_i(:,:,:) = oa_i(:,:,:) + a_i(:,:,:) * zcoef 
    377                           CALL lim_var_glo2eqv            ! this CALL is maybe not necessary (Martin) 
    378          IF( ln_nicep )   CALL lim_prt_state( kt, jiindx, jjindx, 1, ' - ice thermodyn. - ' )   ! control print 
    379                           CALL lim_itd_th( kt )           !  Remap ice categories, lateral accretion  ! 
    380                           CALL lim_var_agg( 1 )           ! requested by limupdate 
    381                           CALL lim_update2                ! Global variables update 
    382  
    383                           CALL lim_var_glo2eqv            ! equivalent variables (outputs) 
    384                           CALL lim_var_agg(2)             ! aggregate ice thickness categories 
    385          IF( ln_nicep )   CALL lim_prt_state( kt, jiindx, jjindx, 2, ' - Final state - ' )   ! control print 
    386          ! 
    387                           CALL lim_sbc_flx( kt )     ! Update surface ocean mass, heat and salt fluxes 
    388          ! 
    389          IF( ln_nicep )   CALL lim_prt_state( kt, jiindx, jjindx, 3, ' - Final state lim_sbc - ' )   ! control print 
    390          ! 
    391          !                                           ! Diagnostics and outputs  
    392          IF (ln_limdiaout) CALL lim_diahsb 
    393 !clem # if ! defined key_iomput 
    394                           CALL lim_wri( 1  )              ! Ice outputs  
    395 !clem # endif 
     216         CALL lim_var_agg(1) 
     217          
     218         ! previous lead fraction and ice volume for flux calculations 
     219         pfrld(:,:)   = 1._wp - at_i(:,:) 
     220         phicif(:,:)  = vt_i(:,:) 
     221          
     222         SELECT CASE( kblk ) 
     223         CASE ( jp_cpl ) 
     224            CALL sbc_cpl_ice_flx( p_frld=pfrld, palbi=zalb_ice, psst=sst_m, pist=t_su    ) 
     225            IF( nn_limflx == 2 )   CALL ice_lim_flx( t_su, zalb_ice, qns_ice, qsr_ice ,   & 
     226               &                                           dqns_ice, qla_ice, dqla_ice, nn_limflx ) 
     227            ! Latent heat flux is forced to 0 in coupled: it is included in qns (non-solar heat flux) 
     228            qla_ice  (:,:,:) = 0._wp 
     229            dqla_ice (:,:,:) = 0._wp 
     230         END SELECT 
     231         ! 
     232         CALL lim_thd( kt )                         ! Ice thermodynamics  
     233          
     234         CALL lim_update2( kt )                     ! Corrections 
     235         ! 
     236         CALL lim_sbc_flx( kt )                     ! Update surface ocean mass, heat and salt fluxes 
     237         ! 
     238         IF(ln_limdiaout) CALL lim_diahsb           ! Diagnostics and outputs  
     239          
     240         CALL lim_wri( 1 )                          ! Ice outputs  
     241          
    396242         IF( kt == nit000 .AND. ln_rstart )   & 
    397             &             CALL iom_close( numrir )        ! clem: close input ice restart file 
    398          ! 
    399          IF( lrst_ice )   CALL lim_rst_write( kt )        ! Ice restart file  
    400                           CALL lim_var_glo2eqv            ! ??? 
    401          ! 
    402          IF( ln_nicep )   CALL lim_ctl( kt )              ! alerts in case of model crash 
    403          ! 
    404       ENDIF                                    ! End sea-ice time step only 
    405  
    406       !                                        !--------------------------! 
    407       !                                        !  at all ocean time step  ! 
    408       !                                        !--------------------------! 
    409       !                                                
    410       !                                              ! Update surface ocean stresses (only in ice-dynamic case) 
    411       !                                                   ! otherwise the atm.-ocean stresses are used everywhere 
     243            &             CALL iom_close( numrir )  ! close input ice restart file 
     244         ! 
     245         IF( lrst_ice )   CALL lim_rst_write( kt )  ! Ice restart file  
     246         ! 
     247         IF( ln_icectl )  CALL lim_ctl( kt )        ! alerts in case of model crash 
     248         ! 
     249         CALL wrk_dealloc( jpi,jpj,jpl, zalb_os, zalb_cs, zalb_ice ) 
     250         ! 
     251      ENDIF   ! End sea-ice time step only 
     252 
     253      !--------------------------------! 
     254      ! --- at all ocean time step --- ! 
     255      !--------------------------------! 
     256      ! Update surface ocean stresses (only in ice-dynamic case) 
     257      !    otherwise the atm.-ocean stresses are used everywhere 
    412258      IF( ln_limdyn )     CALL lim_sbc_tau( kt, ub(:,:,1), vb(:,:,1) )  ! using before instantaneous surf. currents 
    413        
    414259!!gm   remark, the ocean-ice stress is not saved in ice diag call above .....  find a solution!!! 
    415260      ! 
    416       CALL wrk_dealloc( jpi,jpj,jpl, zalb_ice_os, zalb_ice_cs ) 
    417  
    418 #if defined key_coupled 
    419       IF ( ln_cpl .OR. ln_iceflx_ave .OR. ln_iceflx_linear ) CALL wrk_dealloc( jpi,jpj,jpl, zalb_ice) 
    420       IF ( ln_iceflx_ave .OR. ln_iceflx_linear ) & 
    421          &    CALL wrk_dealloc( jpi,jpj, ztem_ice_all, zalb_ice_all, z_qsr_ice_all, z_qns_ice_all, z_qla_ice_all, z_dqns_ice_all, z_dqla_ice_all) 
     261      IF( nn_timing == 1 )  CALL timing_stop('sbc_ice_lim') 
     262      ! 
     263   END SUBROUTINE sbc_ice_lim 
     264    
     265 
     266   SUBROUTINE sbc_lim_init 
     267      !!---------------------------------------------------------------------- 
     268      !!                  ***  ROUTINE sbc_lim_init  *** 
     269      !! 
     270      !! ** purpose :   Allocate all the dynamic arrays of the LIM-3 modules 
     271      !!---------------------------------------------------------------------- 
     272      INTEGER :: ierr 
     273      !!---------------------------------------------------------------------- 
     274      IF(lwp) WRITE(numout,*) 
     275      IF(lwp) WRITE(numout,*) 'sbc_ice_lim : update ocean surface boudary condition'  
     276      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~   via Louvain la Neuve Ice Model (LIM-3) time stepping' 
     277      ! 
     278                                       ! Open the reference and configuration namelist files and namelist output file  
     279      CALL ctl_opn( numnam_ice_ref, 'namelist_ice_ref',    'OLD',     'FORMATTED', 'SEQUENTIAL', -1, numout, lwp )  
     280      CALL ctl_opn( numnam_ice_cfg, 'namelist_ice_cfg',    'OLD',     'FORMATTED', 'SEQUENTIAL', -1, numout, lwp ) 
     281      IF(lwm) CALL ctl_opn( numoni, 'output.namelist.ice', 'UNKNOWN', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp, 1 ) 
     282 
     283      CALL ice_run                     ! set some ice run parameters 
     284      ! 
     285      !                                ! Allocate the ice arrays 
     286      ierr =        ice_alloc        ()      ! ice variables 
     287      ierr = ierr + dom_ice_alloc    ()      ! domain 
     288      ierr = ierr + sbc_ice_alloc    ()      ! surface forcing 
     289      ierr = ierr + thd_ice_alloc    ()      ! thermodynamics 
     290      ierr = ierr + lim_itd_me_alloc ()      ! ice thickness distribution - mechanics 
     291      ! 
     292      IF( lk_mpp    )   CALL mpp_sum( ierr ) 
     293      IF( ierr /= 0 )   CALL ctl_stop('STOP', 'sbc_lim_init : unable to allocate ice arrays') 
     294      ! 
     295      !                                ! adequation jpk versus ice/snow layers/categories 
     296      IF( jpl > jpk .OR. (nlay_i+1) > jpk .OR. nlay_s > jpk )   & 
     297         &      CALL ctl_stop( 'STOP',                          & 
     298         &     'sbc_lim_init: the 3rd dimension of workspace arrays is too small.',   & 
     299         &     'use more ocean levels or less ice/snow layers/categories.' ) 
     300      ! 
     301      CALL lim_itd_init                ! ice thickness distribution initialization 
     302      ! 
     303      CALL lim_thd_init                ! set ice thermodynics parameters 
     304      ! 
     305      CALL lim_thd_sal_init            ! set ice salinity parameters 
     306      ! 
     307      CALL lim_msh                     ! ice mesh initialization 
     308      ! 
     309      CALL lim_itd_me_init             ! ice thickness distribution initialization for mecanical deformation 
     310      !                                ! Initial sea-ice state 
     311      IF( .NOT. ln_rstart ) THEN              ! start from rest: sea-ice deduced from sst 
     312         numit = 0 
     313         numit = nit000 - 1 
     314         CALL lim_istate 
     315      ELSE                                    ! start from a restart file 
     316         CALL lim_rst_read 
     317         numit = nit000 - 1 
     318      ENDIF 
     319      CALL lim_var_agg(1) 
     320      CALL lim_var_glo2eqv 
     321      ! 
     322      CALL lim_sbc_init                 ! ice surface boundary condition    
     323      ! 
     324      fr_i(:,:)     = at_i(:,:)         ! initialisation of sea-ice fraction 
     325      tn_ice(:,:,:) = t_su(:,:,:)       ! initialisation of surface temp for coupled simu 
     326      ! 
     327      nstart = numit  + nn_fsbc       
     328      nitrun = nitend - nit000 + 1  
     329      nlast  = numit  + nitrun  
     330      ! 
     331      IF( nstock == 0 )   nstock = nlast + 1 
     332      ! 
     333   END SUBROUTINE sbc_lim_init 
     334 
     335 
     336   SUBROUTINE ice_run 
     337      !!------------------------------------------------------------------- 
     338      !!                  ***  ROUTINE ice_run *** 
     339      !!                  
     340      !! ** Purpose :   Definition some run parameter for ice model 
     341      !! 
     342      !! ** Method  :   Read the namicerun namelist and check the parameter  
     343      !!              values called at the first timestep (nit000) 
     344      !! 
     345      !! ** input   :   Namelist namicerun 
     346      !!------------------------------------------------------------------- 
     347      INTEGER  ::   ios                 ! Local integer output status for namelist read 
     348      NAMELIST/namicerun/ jpl, nlay_i, nlay_s, cn_icerst_in, cn_icerst_out,   & 
     349         &                ln_limdyn, rn_amax, ln_limdiahsb, ln_limdiaout, ln_icectl, iiceprt, jiceprt   
     350      !!------------------------------------------------------------------- 
     351      !                     
     352      REWIND( numnam_ice_ref )              ! Namelist namicerun in reference namelist : Parameters for ice 
     353      READ  ( numnam_ice_ref, namicerun, IOSTAT = ios, ERR = 901) 
     354901   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namicerun in reference namelist', lwp ) 
     355 
     356      REWIND( numnam_ice_cfg )              ! Namelist namicerun in configuration namelist : Parameters for ice 
     357      READ  ( numnam_ice_cfg, namicerun, IOSTAT = ios, ERR = 902 ) 
     358902   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namicerun in configuration namelist', lwp ) 
     359      IF(lwm) WRITE ( numoni, namicerun ) 
     360      ! 
     361      ! 
     362      IF(lwp) THEN                        ! control print 
     363         WRITE(numout,*) 
     364         WRITE(numout,*) 'ice_run : ice share parameters for dynamics/advection/thermo of sea-ice' 
     365         WRITE(numout,*) ' ~~~~~~' 
     366         WRITE(numout,*) '   number of ice  categories                               = ', jpl 
     367         WRITE(numout,*) '   number of ice  layers                                   = ', nlay_i 
     368         WRITE(numout,*) '   number of snow layers                                   = ', nlay_s 
     369         WRITE(numout,*) '   switch for ice dynamics (1) or not (0)      ln_limdyn   = ', ln_limdyn 
     370         WRITE(numout,*) '   maximum ice concentration                               = ', rn_amax  
     371         WRITE(numout,*) '   Diagnose heat/salt budget or not          ln_limdiahsb  = ', ln_limdiahsb 
     372         WRITE(numout,*) '   Output   heat/salt budget or not          ln_limdiaout  = ', ln_limdiaout 
     373         WRITE(numout,*) '   control prints in ocean.out for (i,j)=(iiceprt,jiceprt) = ', ln_icectl 
     374         WRITE(numout,*) '   i-index for control prints (ln_icectl=true)             = ', iiceprt 
     375         WRITE(numout,*) '   j-index for control prints (ln_icectl=true)             = ', jiceprt 
     376      ENDIF 
     377      ! 
     378      ! sea-ice timestep and inverse 
     379      rdt_ice   = nn_fsbc * rdttra(1)   
     380      r1_rdtice = 1._wp / rdt_ice  
     381 
     382      ! inverse of nlay_i and nlay_s 
     383      r1_nlay_i = 1._wp / REAL( nlay_i, wp ) 
     384      r1_nlay_s = 1._wp / REAL( nlay_s, wp ) 
     385      ! 
     386#if defined key_bdy 
     387      IF( lwp .AND. ln_limdiahsb )  CALL ctl_warn('online conservation check activated but it does not work with BDY') 
    422388#endif 
    423389      ! 
    424       IF( nn_timing == 1 )  CALL timing_stop('sbc_ice_lim') 
    425       ! 
    426    END SUBROUTINE sbc_ice_lim 
    427  
    428  
    429    SUBROUTINE lim_ctl( kt ) 
    430       !!----------------------------------------------------------------------- 
    431       !!                   ***  ROUTINE lim_ctl ***  
    432       !!                  
    433       !! ** Purpose :   Alerts in case of model crash 
     390   END SUBROUTINE ice_run 
     391 
     392 
     393   SUBROUTINE lim_itd_init 
     394      !!------------------------------------------------------------------ 
     395      !!                ***  ROUTINE lim_itd_init *** 
     396      !! 
     397      !! ** Purpose :   Initializes the ice thickness distribution 
     398      !! ** Method  :   ... 
     399      !! ** input   :   Namelist namiceitd 
    434400      !!------------------------------------------------------------------- 
    435       INTEGER, INTENT(in) ::   kt      ! ocean time step 
    436       INTEGER  ::   ji, jj, jk,  jl   ! dummy loop indices 
    437       INTEGER  ::   inb_altests       ! number of alert tests (max 20) 
    438       INTEGER  ::   ialert_id         ! number of the current alert 
    439       REAL(wp) ::   ztmelts           ! ice layer melting point 
    440       CHARACTER (len=30), DIMENSION(20)      ::   cl_alname   ! name of alert 
    441       INTEGER           , DIMENSION(20)      ::   inb_alp     ! number of alerts positive 
    442       !!------------------------------------------------------------------- 
    443  
    444       inb_altests = 10 
    445       inb_alp(:)  =  0 
    446  
    447       ! Alert if incompatible volume and concentration 
    448       ialert_id = 2 ! reference number of this alert 
    449       cl_alname(ialert_id) = ' Incompat vol and con         '    ! name of the alert 
     401      INTEGER  ::   ios                 ! Local integer output status for namelist read 
     402      NAMELIST/namiceitd/ nn_catbnd, rn_himean 
     403      ! 
     404      INTEGER  ::   jl                   ! dummy loop index 
     405      REAL(wp) ::   zc1, zc2, zc3, zx1   ! local scalars 
     406      REAL(wp) ::   zhmax, znum, zden, zalpha ! 
     407      !!------------------------------------------------------------------ 
     408      ! 
     409      REWIND( numnam_ice_ref )              ! Namelist namiceitd in reference namelist : Parameters for ice 
     410      READ  ( numnam_ice_ref, namiceitd, IOSTAT = ios, ERR = 903) 
     411903   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namiceitd in reference namelist', lwp ) 
     412 
     413      REWIND( numnam_ice_cfg )              ! Namelist namiceitd in configuration namelist : Parameters for ice 
     414      READ  ( numnam_ice_cfg, namiceitd, IOSTAT = ios, ERR = 904 ) 
     415904   IF( ios /= 0 ) CALL ctl_nam ( ios , 'namiceitd in configuration namelist', lwp ) 
     416      IF(lwm) WRITE ( numoni, namiceitd ) 
     417      ! 
     418      ! 
     419      IF(lwp) THEN                        ! control print 
     420         WRITE(numout,*) 
     421         WRITE(numout,*) 'ice_itd : ice cat distribution' 
     422         WRITE(numout,*) ' ~~~~~~' 
     423         WRITE(numout,*) '   shape of ice categories distribution                          nn_catbnd = ', nn_catbnd 
     424         WRITE(numout,*) '   mean ice thickness in the domain (only active if nn_catbnd=2) rn_himean = ', rn_himean 
     425      ENDIF 
     426 
     427      !---------------------------------- 
     428      !- Thickness categories boundaries  
     429      !---------------------------------- 
     430      IF(lwp) WRITE(numout,*) 
     431      IF(lwp) WRITE(numout,*) 'lim_itd_init : Initialization of ice cat distribution ' 
     432      IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~' 
     433 
     434      hi_max(:) = 0._wp 
     435 
     436      SELECT CASE ( nn_catbnd  )        
     437                                   !---------------------- 
     438         CASE (1)                  ! tanh function (CICE) 
     439                                   !---------------------- 
     440         zc1 =  3._wp / REAL( jpl, wp ) 
     441         zc2 = 10._wp * zc1 
     442         zc3 =  3._wp 
     443 
     444         DO jl = 1, jpl 
     445            zx1 = REAL( jl-1, wp ) / REAL( jpl, wp ) 
     446            hi_max(jl) = hi_max(jl-1) + zc1 + zc2 * (1._wp + TANH( zc3 * (zx1 - 1._wp ) ) ) 
     447         END DO 
     448 
     449                                   !---------------------- 
     450         CASE (2)                  ! h^(-alpha) function 
     451                                   !---------------------- 
     452         zalpha = 0.05             ! exponent of the transform function 
     453 
     454         zhmax  = 3.*rn_himean 
     455 
     456         DO jl = 1, jpl  
     457            znum = jpl * ( zhmax+1 )**zalpha 
     458            zden = ( jpl - jl ) * ( zhmax+1 )**zalpha + jl 
     459            hi_max(jl) = ( znum / zden )**(1./zalpha) - 1 
     460         END DO 
     461 
     462      END SELECT 
    450463 
    451464      DO jl = 1, jpl 
    452          DO jj = 1, jpj 
    453             DO ji = 1, jpi 
    454                IF(  v_i(ji,jj,jl) /= 0._wp   .AND.   a_i(ji,jj,jl) == 0._wp   ) THEN 
    455                   !WRITE(numout,*) ' ALERTE 2 :   Incompatible volume and concentration ' 
    456                   !WRITE(numout,*) ' at_i     ', at_i(ji,jj) 
    457                   !WRITE(numout,*) ' Point - category', ji, jj, jl 
    458                   !WRITE(numout,*) ' a_i *** a_i_old ', a_i      (ji,jj,jl), old_a_i  (ji,jj,jl) 
    459                   !WRITE(numout,*) ' v_i *** v_i_old ', v_i      (ji,jj,jl), old_v_i  (ji,jj,jl) 
    460                   !WRITE(numout,*) ' d_a_i_thd/trp   ', d_a_i_thd(ji,jj,jl), d_a_i_trp(ji,jj,jl) 
    461                   !WRITE(numout,*) ' d_v_i_thd/trp   ', d_v_i_thd(ji,jj,jl), d_v_i_trp(ji,jj,jl) 
    462                   inb_alp(ialert_id) = inb_alp(ialert_id) + 1 
    463                ENDIF 
    464             END DO 
     465         hi_mean(jl) = ( hi_max(jl) + hi_max(jl-1) ) * 0.5_wp 
     466      END DO 
     467 
     468      ! Set hi_max(jpl) to a big value to ensure that all ice is thinner than hi_max(jpl) 
     469      hi_max(jpl) = 99._wp 
     470 
     471      IF(lwp) WRITE(numout,*) ' Thickness category boundaries ' 
     472      IF(lwp) WRITE(numout,*) ' hi_max ', hi_max(0:jpl) 
     473      ! 
     474   END SUBROUTINE lim_itd_init 
     475 
     476    
     477   SUBROUTINE ice_lim_flx( ptn_ice, palb_ice, pqns_ice, pqsr_ice,   & 
     478         &                          pdqn_ice, pqla_ice, pdql_ice, k_limflx ) 
     479      !!--------------------------------------------------------------------- 
     480      !!                  ***  ROUTINE ice_lim_flx  *** 
     481      !!                    
     482      !! ** Purpose :   update the ice surface boundary condition by averaging and / or 
     483      !!                redistributing fluxes on ice categories                    
     484      !! 
     485      !! ** Method  :   average then redistribute  
     486      !! 
     487      !! ** Action  :    
     488      !!--------------------------------------------------------------------- 
     489      INTEGER                   , INTENT(in   ) ::   k_limflx   ! =-1 do nothing; =0 average ;  
     490                                                                ! =1 average and redistribute ; =2 redistribute 
     491      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   ptn_ice    ! ice surface temperature  
     492      REAL(wp), DIMENSION(:,:,:), INTENT(in   ) ::   palb_ice   ! ice albedo 
     493      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   pqns_ice   ! non solar flux 
     494      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   pqsr_ice   ! net solar flux 
     495      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   pdqn_ice   ! non solar flux sensitivity 
     496      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   pqla_ice   ! latent heat flux 
     497      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   pdql_ice   ! latent heat flux sensitivity 
     498      ! 
     499      INTEGER  ::   jl      ! dummy loop index 
     500      ! 
     501      REAL(wp), POINTER, DIMENSION(:,:) :: zalb_m    ! Mean albedo over all categories 
     502      REAL(wp), POINTER, DIMENSION(:,:) :: ztem_m    ! Mean temperature over all categories 
     503      ! 
     504      REAL(wp), POINTER, DIMENSION(:,:) :: z_qsr_m   ! Mean solar heat flux over all categories 
     505      REAL(wp), POINTER, DIMENSION(:,:) :: z_qns_m   ! Mean non solar heat flux over all categories 
     506      REAL(wp), POINTER, DIMENSION(:,:) :: z_qla_m   ! Mean latent heat flux over all categories 
     507      REAL(wp), POINTER, DIMENSION(:,:) :: z_dqn_m   ! Mean d(qns)/dT over all categories 
     508      REAL(wp), POINTER, DIMENSION(:,:) :: z_dql_m   ! Mean d(qla)/dT over all categories 
     509      !!---------------------------------------------------------------------- 
     510 
     511      IF( nn_timing == 1 )  CALL timing_start('ice_lim_flx') 
     512      ! 
     513      ! 
     514      SELECT CASE( k_limflx )                              !==  averaged on all ice categories  ==! 
     515      CASE( 0 , 1 ) 
     516         CALL wrk_alloc( jpi,jpj, z_qsr_m, z_qns_m, z_qla_m, z_dqn_m, z_dql_m) 
     517         ! 
     518         z_qns_m(:,:) = fice_ice_ave ( pqns_ice (:,:,:) ) 
     519         z_qsr_m(:,:) = fice_ice_ave ( pqsr_ice (:,:,:) ) 
     520         z_dqn_m(:,:) = fice_ice_ave ( pdqn_ice (:,:,:) ) 
     521         z_qla_m(:,:) = fice_ice_ave ( pqla_ice (:,:,:) ) 
     522         z_dql_m(:,:) = fice_ice_ave ( pdql_ice (:,:,:) ) 
     523         DO jl = 1, jpl 
     524            pdqn_ice(:,:,jl) = z_dqn_m(:,:) 
     525            pdql_ice(:,:,jl) = z_dql_m(:,:) 
    465526         END DO 
     527         ! 
     528         DO jl = 1, jpl 
     529            pqns_ice(:,:,jl) = z_qns_m(:,:) 
     530            pqsr_ice(:,:,jl) = z_qsr_m(:,:) 
     531            pqla_ice(:,:,jl) = z_qla_m(:,:) 
     532         END DO 
     533         ! 
     534         CALL wrk_dealloc( jpi,jpj, z_qsr_m, z_qns_m, z_qla_m, z_dqn_m, z_dql_m) 
     535      END SELECT 
     536 
     537      SELECT CASE( k_limflx )                              !==  redistribution on all ice categories  ==! 
     538      CASE( 1 , 2 ) 
     539         CALL wrk_alloc( jpi,jpj, zalb_m, ztem_m ) 
     540         ! 
     541         zalb_m(:,:) = fice_ice_ave ( palb_ice (:,:,:) )  
     542         ztem_m(:,:) = fice_ice_ave ( ptn_ice  (:,:,:) )  
     543         DO jl = 1, jpl 
     544            pqns_ice(:,:,jl) = pqns_ice(:,:,jl) + pdqn_ice(:,:,jl) * (ptn_ice(:,:,jl) - ztem_m(:,:)) 
     545            pqla_ice(:,:,jl) = pqla_ice(:,:,jl) + pdql_ice(:,:,jl) * (ptn_ice(:,:,jl) - ztem_m(:,:)) 
     546            pqsr_ice(:,:,jl) = pqsr_ice(:,:,jl) * ( 1._wp - palb_ice(:,:,jl) ) / ( 1._wp - zalb_m(:,:) )  
     547         END DO 
     548         ! 
     549         CALL wrk_dealloc( jpi,jpj, zalb_m, ztem_m ) 
     550      END SELECT 
     551      ! 
     552      IF( nn_timing == 1 )  CALL timing_stop('ice_lim_flx') 
     553      ! 
     554   END SUBROUTINE ice_lim_flx 
     555 
     556   SUBROUTINE sbc_lim_bef 
     557      !!---------------------------------------------------------------------- 
     558      !!                  ***  ROUTINE sbc_lim_bef  *** 
     559      !! 
     560      !! ** purpose :  store ice variables at "before" time step  
     561      !!---------------------------------------------------------------------- 
     562      a_i_b  (:,:,:)   = a_i  (:,:,:)     ! ice area 
     563      e_i_b  (:,:,:,:) = e_i  (:,:,:,:)   ! ice thermal energy 
     564      v_i_b  (:,:,:)   = v_i  (:,:,:)     ! ice volume 
     565      v_s_b  (:,:,:)   = v_s  (:,:,:)     ! snow volume  
     566      e_s_b  (:,:,:,:) = e_s  (:,:,:,:)   ! snow thermal energy 
     567      smv_i_b(:,:,:)   = smv_i(:,:,:)     ! salt content 
     568      oa_i_b (:,:,:)   = oa_i (:,:,:)     ! areal age content 
     569      u_ice_b(:,:)     = u_ice(:,:) 
     570      v_ice_b(:,:)     = v_ice(:,:) 
     571       
     572   END SUBROUTINE sbc_lim_bef 
     573 
     574   SUBROUTINE sbc_lim_diag0 
     575      !!---------------------------------------------------------------------- 
     576      !!                  ***  ROUTINE sbc_lim_diag0  *** 
     577      !! 
     578      !! ** purpose :  set ice-ocean and ice-atm. fluxes to zeros at the beggining 
     579      !!               of the time step 
     580      !!---------------------------------------------------------------------- 
     581      sfx    (:,:) = 0._wp   ; 
     582      sfx_bri(:,:) = 0._wp   ;  
     583      sfx_sni(:,:) = 0._wp   ;   sfx_opw(:,:) = 0._wp 
     584      sfx_bog(:,:) = 0._wp   ;   sfx_dyn(:,:) = 0._wp 
     585      sfx_bom(:,:) = 0._wp   ;   sfx_sum(:,:) = 0._wp 
     586      sfx_res(:,:) = 0._wp 
     587       
     588      wfx_snw(:,:) = 0._wp   ;   wfx_ice(:,:) = 0._wp 
     589      wfx_sni(:,:) = 0._wp   ;   wfx_opw(:,:) = 0._wp 
     590      wfx_bog(:,:) = 0._wp   ;   wfx_dyn(:,:) = 0._wp 
     591      wfx_bom(:,:) = 0._wp   ;   wfx_sum(:,:) = 0._wp 
     592      wfx_res(:,:) = 0._wp   ;   wfx_sub(:,:) = 0._wp 
     593      wfx_spr(:,:) = 0._wp   ;    
     594       
     595      hfx_in (:,:) = 0._wp   ;   hfx_out(:,:) = 0._wp 
     596      hfx_thd(:,:) = 0._wp   ;    
     597      hfx_snw(:,:) = 0._wp   ;   hfx_opw(:,:) = 0._wp 
     598      hfx_bog(:,:) = 0._wp   ;   hfx_dyn(:,:) = 0._wp 
     599      hfx_bom(:,:) = 0._wp   ;   hfx_sum(:,:) = 0._wp 
     600      hfx_res(:,:) = 0._wp   ;   hfx_sub(:,:) = 0._wp 
     601      hfx_spr(:,:) = 0._wp   ;   hfx_dif(:,:) = 0._wp  
     602      hfx_err(:,:) = 0._wp   ;   hfx_err_rem(:,:) = 0._wp 
     603      hfx_err_dif(:,:) = 0._wp   ; 
     604 
     605      afx_tot(:,:) = 0._wp   ; 
     606      afx_dyn(:,:) = 0._wp   ;   afx_thd(:,:) = 0._wp 
     607 
     608      diag_heat(:,:) = 0._wp ;   diag_smvi(:,:) = 0._wp ; 
     609      diag_vice(:,:) = 0._wp ;   diag_vsnw(:,:) = 0._wp ; 
     610       
     611   END SUBROUTINE sbc_lim_diag0 
     612       
     613   FUNCTION fice_cell_ave ( ptab ) 
     614      !!-------------------------------------------------------------------------- 
     615      !! * Compute average over categories, for grid cell (ice covered and free ocean) 
     616      !!-------------------------------------------------------------------------- 
     617      REAL (wp), DIMENSION (jpi,jpj) :: fice_cell_ave 
     618      REAL (wp), DIMENSION (jpi,jpj,jpl), INTENT (in) :: ptab 
     619      INTEGER :: jl ! Dummy loop index 
     620       
     621      fice_cell_ave (:,:) = 0.0_wp 
     622       
     623      DO jl = 1, jpl 
     624         fice_cell_ave (:,:) = fice_cell_ave (:,:) + a_i (:,:,jl) * ptab (:,:,jl) 
    466625      END DO 
    467  
    468       ! Alerte if very thick ice 
    469       ialert_id = 3 ! reference number of this alert 
    470       cl_alname(ialert_id) = ' Very thick ice               ' ! name of the alert 
    471       jl = jpl  
    472       DO jj = 1, jpj 
    473          DO ji = 1, jpi 
    474             IF(   ht_i(ji,jj,jl)  >  50._wp   ) THEN 
    475                !CALL lim_prt_state( kt, ji, jj, 2, ' ALERTE 3 :   Very thick ice ' ) 
    476                inb_alp(ialert_id) = inb_alp(ialert_id) + 1 
    477             ENDIF 
    478          END DO 
    479       END DO 
    480  
    481       ! Alert if very fast ice 
    482       ialert_id = 4 ! reference number of this alert 
    483       cl_alname(ialert_id) = ' Very fast ice               ' ! name of the alert 
    484       DO jj = 1, jpj 
    485          DO ji = 1, jpi 
    486             IF(   MAX( ABS( u_ice(ji,jj) ), ABS( v_ice(ji,jj) ) ) > 1.5  .AND.  & 
    487                &  at_i(ji,jj) > 0._wp   ) THEN 
    488                !CALL lim_prt_state( kt, ji, jj, 1, ' ALERTE 4 :   Very fast ice ' ) 
    489                !WRITE(numout,*) ' ice strength             : ', strength(ji,jj) 
    490                !WRITE(numout,*) ' oceanic stress utau      : ', utau(ji,jj)  
    491                !WRITE(numout,*) ' oceanic stress vtau      : ', vtau(ji,jj) 
    492                !WRITE(numout,*) ' sea-ice stress utau_ice  : ', utau_ice(ji,jj)  
    493                !WRITE(numout,*) ' sea-ice stress vtau_ice  : ', vtau_ice(ji,jj) 
    494                !WRITE(numout,*) ' oceanic speed u          : ', u_oce(ji,jj) 
    495                !WRITE(numout,*) ' oceanic speed v          : ', v_oce(ji,jj) 
    496                !WRITE(numout,*) ' sst                      : ', sst_m(ji,jj) 
    497                !WRITE(numout,*) ' sss                      : ', sss_m(ji,jj) 
    498                !WRITE(numout,*)  
    499                inb_alp(ialert_id) = inb_alp(ialert_id) + 1 
    500             ENDIF 
    501          END DO 
    502       END DO 
    503  
    504       ! Alert if there is ice on continents 
    505       ialert_id = 6 ! reference number of this alert 
    506       cl_alname(ialert_id) = ' Ice on continents           ' ! name of the alert 
    507       DO jj = 1, jpj 
    508          DO ji = 1, jpi 
    509             IF(   tms(ji,jj) <= 0._wp   .AND.   at_i(ji,jj) > 0._wp   ) THEN  
    510                !CALL lim_prt_state( kt, ji, jj, 1, ' ALERTE 6 :   Ice on continents ' ) 
    511                !WRITE(numout,*) ' masks s, u, v        : ', tms(ji,jj), tmu(ji,jj), tmv(ji,jj)  
    512                !WRITE(numout,*) ' sst                  : ', sst_m(ji,jj) 
    513                !WRITE(numout,*) ' sss                  : ', sss_m(ji,jj) 
    514                !WRITE(numout,*) ' at_i(ji,jj)          : ', at_i(ji,jj) 
    515                !WRITE(numout,*) ' v_ice(ji,jj)         : ', v_ice(ji,jj) 
    516                !WRITE(numout,*) ' v_ice(ji,jj-1)       : ', v_ice(ji,jj-1) 
    517                !WRITE(numout,*) ' u_ice(ji-1,jj)       : ', u_ice(ji-1,jj) 
    518                !WRITE(numout,*) ' u_ice(ji,jj)         : ', v_ice(ji,jj) 
    519                ! 
    520                inb_alp(ialert_id) = inb_alp(ialert_id) + 1 
    521             ENDIF 
    522          END DO 
    523       END DO 
    524  
    525 ! 
    526 !     ! Alert if very fresh ice 
    527       ialert_id = 7 ! reference number of this alert 
    528       cl_alname(ialert_id) = ' Very fresh ice               ' ! name of the alert 
    529       DO jl = 1, jpl 
    530          DO jj = 1, jpj 
    531             DO ji = 1, jpi 
    532                IF( sm_i(ji,jj,jl) < 0.1 .AND. a_i(ji,jj,jl) > 0._wp ) THEN 
    533 !                 CALL lim_prt_state(kt,ji,jj,1, ' ALERTE 7 :   Very fresh ice ' ) 
    534 !                 WRITE(numout,*) ' sst                  : ', sst_m(ji,jj) 
    535 !                 WRITE(numout,*) ' sss                  : ', sss_m(ji,jj) 
    536 !                 WRITE(numout,*) ' s_i_newice           : ', s_i_newice(ji,jj,1:jpl) 
    537 !                 WRITE(numout,*)  
    538                   inb_alp(ialert_id) = inb_alp(ialert_id) + 1 
    539                ENDIF 
    540             END DO 
    541          END DO 
    542       END DO 
    543 ! 
    544  
    545 !     ! Alert if too old ice 
    546       ialert_id = 9 ! reference number of this alert 
    547       cl_alname(ialert_id) = ' Very old   ice               ' ! name of the alert 
    548       DO jl = 1, jpl 
    549          DO jj = 1, jpj 
    550             DO ji = 1, jpi 
    551                IF ( ( ( ABS( o_i(ji,jj,jl) ) > rdt_ice ) .OR. & 
    552                       ( ABS( o_i(ji,jj,jl) ) < 0._wp) ) .AND. & 
    553                              ( a_i(ji,jj,jl) > 0._wp ) ) THEN 
    554                   !CALL lim_prt_state( kt, ji, jj, 1, ' ALERTE 9 :   Wrong ice age ') 
    555                   inb_alp(ialert_id) = inb_alp(ialert_id) + 1 
    556                ENDIF 
    557             END DO 
    558          END DO 
    559       END DO 
    560   
    561       ! Alert on salt flux 
    562       ialert_id = 5 ! reference number of this alert 
    563       cl_alname(ialert_id) = ' High salt flux               ' ! name of the alert 
    564       DO jj = 1, jpj 
    565          DO ji = 1, jpi 
    566             IF( ABS( sfx (ji,jj) ) .GT. 1.0e-2 ) THEN  ! = 1 psu/day for 1m ocean depth 
    567                !CALL lim_prt_state( kt, ji, jj, 3, ' ALERTE 5 :   High salt flux ' ) 
    568                !DO jl = 1, jpl 
    569                   !WRITE(numout,*) ' Category no: ', jl 
    570                   !WRITE(numout,*) ' a_i        : ', a_i      (ji,jj,jl) , ' old_a_i    : ', old_a_i  (ji,jj,jl)    
    571                   !WRITE(numout,*) ' d_a_i_trp  : ', d_a_i_trp(ji,jj,jl) , ' d_a_i_thd  : ', d_a_i_thd(ji,jj,jl)  
    572                   !WRITE(numout,*) ' v_i        : ', v_i      (ji,jj,jl) , ' old_v_i    : ', old_v_i  (ji,jj,jl)    
    573                   !WRITE(numout,*) ' d_v_i_trp  : ', d_v_i_trp(ji,jj,jl) , ' d_v_i_thd  : ', d_v_i_thd(ji,jj,jl)  
    574                   !WRITE(numout,*) ' ' 
    575                !END DO 
    576                inb_alp(ialert_id) = inb_alp(ialert_id) + 1 
    577             ENDIF 
    578          END DO 
    579       END DO 
    580  
    581       ! Alert if qns very big 
    582       ialert_id = 8 ! reference number of this alert 
    583       cl_alname(ialert_id) = ' fnsolar very big             ' ! name of the alert 
    584       DO jj = 1, jpj 
    585          DO ji = 1, jpi 
    586             IF( ABS( qns(ji,jj) ) > 1500._wp .AND. at_i(ji,jj) > 0._wp ) THEN 
    587                ! 
    588                !WRITE(numout,*) ' ALERTE 8 :   Very high non-solar heat flux' 
    589                !WRITE(numout,*) ' ji, jj    : ', ji, jj 
    590                !WRITE(numout,*) ' qns       : ', qns(ji,jj) 
    591                !WRITE(numout,*) ' sst       : ', sst_m(ji,jj) 
    592                !WRITE(numout,*) ' sss       : ', sss_m(ji,jj) 
    593                !WRITE(numout,*) ' qcmif     : ', qcmif(ji,jj) 
    594                !WRITE(numout,*) ' qldif     : ', qldif(ji,jj) 
    595                !WRITE(numout,*) ' qcmif     : ', qcmif(ji,jj) / rdt_ice 
    596                !WRITE(numout,*) ' qldif     : ', qldif(ji,jj) / rdt_ice 
    597                !WRITE(numout,*) ' qfvbq     : ', qfvbq(ji,jj) 
    598                !WRITE(numout,*) ' qdtcn     : ', qdtcn(ji,jj) 
    599                !WRITE(numout,*) ' qfvbq / dt: ', qfvbq(ji,jj) / rdt_ice 
    600                !WRITE(numout,*) ' qdtcn / dt: ', qdtcn(ji,jj) / rdt_ice 
    601                !WRITE(numout,*) ' fdtcn     : ', fdtcn(ji,jj)  
    602                !WRITE(numout,*) ' fhmec     : ', fhmec(ji,jj)  
    603                !WRITE(numout,*) ' fheat_mec : ', fheat_mec(ji,jj)  
    604                !WRITE(numout,*) ' fheat_res : ', fheat_res(ji,jj)  
    605                !WRITE(numout,*) ' fhbri     : ', fhbri(ji,jj)  
    606                ! 
    607                !CALL lim_prt_state( kt, ji, jj, 2, '   ') 
    608                inb_alp(ialert_id) = inb_alp(ialert_id) + 1 
    609                ! 
    610             ENDIF 
    611          END DO 
    612       END DO 
    613       !+++++ 
    614   
    615       ! Alert if very warm ice 
    616       ialert_id = 10 ! reference number of this alert 
    617       cl_alname(ialert_id) = ' Very warm ice                ' ! name of the alert 
    618       inb_alp(ialert_id) = 0 
    619       DO jl = 1, jpl 
    620          DO jk = 1, nlay_i 
    621             DO jj = 1, jpj 
    622                DO ji = 1, jpi 
    623                   ztmelts    =  -tmut * s_i(ji,jj,jk,jl) + rtt 
    624                   IF( t_i(ji,jj,jk,jl) >= ztmelts  .AND.  v_i(ji,jj,jl) > 1.e-10   & 
    625                      &                             .AND.  a_i(ji,jj,jl) > 0._wp   ) THEN 
    626                      !WRITE(numout,*) ' ALERTE 10 :   Very warm ice' 
    627                      !WRITE(numout,*) ' ji, jj, jk, jl : ', ji, jj, jk, jl 
    628                      !WRITE(numout,*) ' t_i : ', t_i(ji,jj,jk,jl) 
    629                      !WRITE(numout,*) ' e_i : ', e_i(ji,jj,jk,jl) 
    630                      !WRITE(numout,*) ' s_i : ', s_i(ji,jj,jk,jl) 
    631                      !WRITE(numout,*) ' ztmelts : ', ztmelts 
    632                      inb_alp(ialert_id) = inb_alp(ialert_id) + 1 
    633                   ENDIF 
    634                END DO 
    635             END DO 
    636          END DO 
    637       END DO 
    638  
    639       ! sum of the alerts on all processors 
    640       IF( lk_mpp ) THEN 
    641          DO ialert_id = 1, inb_altests 
    642             CALL mpp_sum(inb_alp(ialert_id)) 
    643          END DO 
    644       ENDIF 
    645  
    646       ! print alerts 
    647       IF( lwp ) THEN 
    648          ialert_id = 1                                 ! reference number of this alert 
    649          cl_alname(ialert_id) = ' NO alerte 1      '   ! name of the alert 
    650          WRITE(numout,*) ' time step ',kt 
    651          WRITE(numout,*) ' All alerts at the end of ice model ' 
    652          DO ialert_id = 1, inb_altests 
    653             WRITE(numout,*) ialert_id, cl_alname(ialert_id)//' : ', inb_alp(ialert_id), ' times ! ' 
    654          END DO 
    655       ENDIF 
    656      ! 
    657    END SUBROUTINE lim_ctl 
    658   
     626       
     627   END FUNCTION fice_cell_ave 
    659628    
    660    SUBROUTINE lim_prt_state( kt, ki, kj, kn, cd1 ) 
    661       !!----------------------------------------------------------------------- 
    662       !!                   ***  ROUTINE lim_prt_state ***  
    663       !!                  
    664       !! ** Purpose :   Writes global ice state on the (i,j) point  
    665       !!                in ocean.ouput  
    666       !!                3 possibilities exist  
    667       !!                n = 1/-1 -> simple ice state (plus Mechanical Check if -1) 
    668       !!                n = 2    -> exhaustive state 
    669       !!                n = 3    -> ice/ocean salt fluxes 
    670       !! 
    671       !! ** input   :   point coordinates (i,j)  
    672       !!                n : number of the option 
    673       !!------------------------------------------------------------------- 
    674       INTEGER         , INTENT(in) ::   kt      ! ocean time step 
    675       INTEGER         , INTENT(in) ::   ki, kj, kn    ! ocean gridpoint indices 
    676       CHARACTER(len=*), INTENT(in) ::   cd1           ! 
    677       !! 
    678       INTEGER :: jl, ji, jj 
    679       !!------------------------------------------------------------------- 
    680  
    681       DO ji = mi0(ki), mi1(ki) 
    682          DO jj = mj0(kj), mj1(kj) 
    683  
    684             WRITE(numout,*) ' time step ',kt,' ',cd1             ! print title 
    685  
    686             !---------------- 
    687             !  Simple state 
    688             !---------------- 
    689              
    690             IF ( kn == 1 .OR. kn == -1 ) THEN 
    691                WRITE(numout,*) ' lim_prt_state - Point : ',ji,jj 
    692                WRITE(numout,*) ' ~~~~~~~~~~~~~~ ' 
    693                WRITE(numout,*) ' Simple state ' 
    694                WRITE(numout,*) ' masks s,u,v   : ', tms(ji,jj), tmu(ji,jj), tmv(ji,jj) 
    695                WRITE(numout,*) ' lat - long    : ', gphit(ji,jj), glamt(ji,jj) 
    696                WRITE(numout,*) ' Time step     : ', numit 
    697                WRITE(numout,*) ' - Ice drift   ' 
    698                WRITE(numout,*) '   ~~~~~~~~~~~ ' 
    699                WRITE(numout,*) ' u_ice(i-1,j)  : ', u_ice(ji-1,jj) 
    700                WRITE(numout,*) ' u_ice(i  ,j)  : ', u_ice(ji,jj) 
    701                WRITE(numout,*) ' v_ice(i  ,j-1): ', v_ice(ji,jj-1) 
    702                WRITE(numout,*) ' v_ice(i  ,j)  : ', v_ice(ji,jj) 
    703                WRITE(numout,*) ' strength      : ', strength(ji,jj) 
    704                WRITE(numout,*) 
    705                WRITE(numout,*) ' - Cell values ' 
    706                WRITE(numout,*) '   ~~~~~~~~~~~ ' 
    707                WRITE(numout,*) ' cell area     : ', area(ji,jj) 
    708                WRITE(numout,*) ' at_i          : ', at_i(ji,jj)        
    709                WRITE(numout,*) ' vt_i          : ', vt_i(ji,jj)        
    710                WRITE(numout,*) ' vt_s          : ', vt_s(ji,jj)        
    711                DO jl = 1, jpl 
    712                   WRITE(numout,*) ' - Category (', jl,')' 
    713                   WRITE(numout,*) ' a_i           : ', a_i(ji,jj,jl) 
    714                   WRITE(numout,*) ' ht_i          : ', ht_i(ji,jj,jl) 
    715                   WRITE(numout,*) ' ht_s          : ', ht_s(ji,jj,jl) 
    716                   WRITE(numout,*) ' v_i           : ', v_i(ji,jj,jl) 
    717                   WRITE(numout,*) ' v_s           : ', v_s(ji,jj,jl) 
    718                   WRITE(numout,*) ' e_s           : ', e_s(ji,jj,1,jl)/1.0e9 
    719                   WRITE(numout,*) ' e_i           : ', e_i(ji,jj,1:nlay_i,jl)/1.0e9 
    720                   WRITE(numout,*) ' t_su          : ', t_su(ji,jj,jl) 
    721                   WRITE(numout,*) ' t_snow        : ', t_s(ji,jj,1,jl) 
    722                   WRITE(numout,*) ' t_i           : ', t_i(ji,jj,1:nlay_i,jl) 
    723                   WRITE(numout,*) ' sm_i          : ', sm_i(ji,jj,jl) 
    724                   WRITE(numout,*) ' smv_i         : ', smv_i(ji,jj,jl) 
    725                   WRITE(numout,*) 
    726                END DO 
    727             ENDIF 
    728             IF( kn == -1 ) THEN 
    729                WRITE(numout,*) ' Mechanical Check ************** ' 
    730                WRITE(numout,*) ' Check what means ice divergence ' 
    731                WRITE(numout,*) ' Total ice concentration ', at_i (ji,jj) 
    732                WRITE(numout,*) ' Total lead fraction     ', ato_i(ji,jj) 
    733                WRITE(numout,*) ' Sum of both             ', ato_i(ji,jj) + at_i(ji,jj) 
    734                WRITE(numout,*) ' Sum of both minus 1     ', ato_i(ji,jj) + at_i(ji,jj) - 1.00 
    735             ENDIF 
    736              
    737  
    738             !-------------------- 
    739             !  Exhaustive state 
    740             !-------------------- 
    741              
    742             IF ( kn .EQ. 2 ) THEN 
    743                WRITE(numout,*) ' lim_prt_state - Point : ',ji,jj 
    744                WRITE(numout,*) ' ~~~~~~~~~~~~~~ ' 
    745                WRITE(numout,*) ' Exhaustive state ' 
    746                WRITE(numout,*) ' lat - long ', gphit(ji,jj), glamt(ji,jj) 
    747                WRITE(numout,*) ' Time step ', numit 
    748                WRITE(numout,*)  
    749                WRITE(numout,*) ' - Cell values ' 
    750                WRITE(numout,*) '   ~~~~~~~~~~~ ' 
    751                WRITE(numout,*) ' cell area     : ', area(ji,jj) 
    752                WRITE(numout,*) ' at_i          : ', at_i(ji,jj)        
    753                WRITE(numout,*) ' vt_i          : ', vt_i(ji,jj)        
    754                WRITE(numout,*) ' vt_s          : ', vt_s(ji,jj)        
    755                WRITE(numout,*) ' u_ice(i-1,j)  : ', u_ice(ji-1,jj) 
    756                WRITE(numout,*) ' u_ice(i  ,j)  : ', u_ice(ji,jj) 
    757                WRITE(numout,*) ' v_ice(i  ,j-1): ', v_ice(ji,jj-1) 
    758                WRITE(numout,*) ' v_ice(i  ,j)  : ', v_ice(ji,jj) 
    759                WRITE(numout,*) ' strength      : ', strength(ji,jj) 
    760                WRITE(numout,*) ' d_u_ice_dyn   : ', d_u_ice_dyn(ji,jj), ' d_v_ice_dyn   : ', d_v_ice_dyn(ji,jj) 
    761                WRITE(numout,*) ' old_u_ice     : ', old_u_ice(ji,jj)  , ' old_v_ice     : ', old_v_ice(ji,jj)   
    762                WRITE(numout,*) 
    763                 
    764                DO jl = 1, jpl 
    765                   WRITE(numout,*) ' - Category (',jl,')' 
    766                   WRITE(numout,*) '   ~~~~~~~~         '  
    767                   WRITE(numout,*) ' ht_i       : ', ht_i(ji,jj,jl)             , ' ht_s       : ', ht_s(ji,jj,jl) 
    768                   WRITE(numout,*) ' t_i        : ', t_i(ji,jj,1:nlay_i,jl) 
    769                   WRITE(numout,*) ' t_su       : ', t_su(ji,jj,jl)             , ' t_s        : ', t_s(ji,jj,1,jl) 
    770                   WRITE(numout,*) ' sm_i       : ', sm_i(ji,jj,jl)             , ' o_i        : ', o_i(ji,jj,jl) 
    771                   WRITE(numout,*) ' a_i        : ', a_i(ji,jj,jl)              , ' old_a_i    : ', old_a_i(ji,jj,jl)    
    772                   WRITE(numout,*) ' d_a_i_trp  : ', d_a_i_trp(ji,jj,jl)        , ' d_a_i_thd  : ', d_a_i_thd(ji,jj,jl)  
    773                   WRITE(numout,*) ' v_i        : ', v_i(ji,jj,jl)              , ' old_v_i    : ', old_v_i(ji,jj,jl)    
    774                   WRITE(numout,*) ' d_v_i_trp  : ', d_v_i_trp(ji,jj,jl)        , ' d_v_i_thd  : ', d_v_i_thd(ji,jj,jl)  
    775                   WRITE(numout,*) ' v_s        : ', v_s(ji,jj,jl)              , ' old_v_s    : ', old_v_s(ji,jj,jl)   
    776                   WRITE(numout,*) ' d_v_s_trp  : ', d_v_s_trp(ji,jj,jl)        , ' d_v_s_thd  : ', d_v_s_thd(ji,jj,jl) 
    777                   WRITE(numout,*) ' e_i1       : ', e_i(ji,jj,1,jl)/1.0e9      , ' old_ei1    : ', old_e_i(ji,jj,1,jl)/1.0e9  
    778                   WRITE(numout,*) ' de_i1_trp  : ', d_e_i_trp(ji,jj,1,jl)/1.0e9, ' de_i1_thd  : ', d_e_i_thd(ji,jj,1,jl)/1.0e9 
    779                   WRITE(numout,*) ' e_i2       : ', e_i(ji,jj,2,jl)/1.0e9      , ' old_ei2    : ', old_e_i(ji,jj,2,jl)/1.0e9   
    780                   WRITE(numout,*) ' de_i2_trp  : ', d_e_i_trp(ji,jj,2,jl)/1.0e9, ' de_i2_thd  : ', d_e_i_thd(ji,jj,2,jl)/1.0e9 
    781                   WRITE(numout,*) ' e_snow     : ', e_s(ji,jj,1,jl)            , ' old_e_snow : ', old_e_s(ji,jj,1,jl)  
    782                   WRITE(numout,*) ' d_e_s_trp  : ', d_e_s_trp(ji,jj,1,jl)      , ' d_e_s_thd  : ', d_e_s_thd(ji,jj,1,jl) 
    783                   WRITE(numout,*) ' smv_i      : ', smv_i(ji,jj,jl)            , ' old_smv_i  : ', old_smv_i(ji,jj,jl)    
    784                   WRITE(numout,*) ' d_smv_i_trp: ', d_smv_i_trp(ji,jj,jl)      , ' d_smv_i_thd: ', d_smv_i_thd(ji,jj,jl)  
    785                   WRITE(numout,*) ' oa_i       : ', oa_i(ji,jj,jl)             , ' old_oa_i   : ', old_oa_i(ji,jj,jl) 
    786                   WRITE(numout,*) ' d_oa_i_trp : ', d_oa_i_trp(ji,jj,jl)       , ' d_oa_i_thd : ', d_oa_i_thd(ji,jj,jl) 
    787                END DO !jl 
    788                 
    789                WRITE(numout,*) 
    790                WRITE(numout,*) ' - Heat / FW fluxes ' 
    791                WRITE(numout,*) '   ~~~~~~~~~~~~~~~~ ' 
    792                WRITE(numout,*) ' emp        : ', emp      (ji,jj) 
    793                WRITE(numout,*) ' sfx        : ', sfx      (ji,jj) 
    794                WRITE(numout,*) ' sfx_thd    : ', sfx_thd(ji,jj) 
    795                WRITE(numout,*) ' sfx_bri    : ', sfx_bri  (ji,jj) 
    796                WRITE(numout,*) ' sfx_mec    : ', sfx_mec  (ji,jj) 
    797                WRITE(numout,*) ' sfx_res    : ', sfx_res(ji,jj) 
    798                WRITE(numout,*) ' fmmec      : ', fmmec    (ji,jj) 
    799                WRITE(numout,*) ' fhmec      : ', fhmec    (ji,jj) 
    800                WRITE(numout,*) ' fhbri      : ', fhbri    (ji,jj) 
    801                WRITE(numout,*) ' fheat_mec  : ', fheat_mec(ji,jj) 
    802                WRITE(numout,*)  
    803                WRITE(numout,*) ' sst        : ', sst_m(ji,jj)   
    804                WRITE(numout,*) ' sss        : ', sss_m(ji,jj)   
    805                WRITE(numout,*)  
    806                WRITE(numout,*) ' - Stresses ' 
    807                WRITE(numout,*) '   ~~~~~~~~ ' 
    808                WRITE(numout,*) ' utau_ice   : ', utau_ice(ji,jj)  
    809                WRITE(numout,*) ' vtau_ice   : ', vtau_ice(ji,jj) 
    810                WRITE(numout,*) ' utau       : ', utau    (ji,jj)  
    811                WRITE(numout,*) ' vtau       : ', vtau    (ji,jj) 
    812                WRITE(numout,*) ' oc. vel. u : ', u_oce   (ji,jj) 
    813                WRITE(numout,*) ' oc. vel. v : ', v_oce   (ji,jj) 
    814             ENDIF 
    815              
    816             !--------------------- 
    817             ! Salt / heat fluxes 
    818             !--------------------- 
    819              
    820             IF ( kn .EQ. 3 ) THEN 
    821                WRITE(numout,*) ' lim_prt_state - Point : ',ji,jj 
    822                WRITE(numout,*) ' ~~~~~~~~~~~~~~ ' 
    823                WRITE(numout,*) ' - Salt / Heat Fluxes ' 
    824                WRITE(numout,*) '   ~~~~~~~~~~~~~~~~ ' 
    825                WRITE(numout,*) ' lat - long ', gphit(ji,jj), glamt(ji,jj) 
    826                WRITE(numout,*) ' Time step ', numit 
    827                WRITE(numout,*) 
    828                WRITE(numout,*) ' - Heat fluxes at bottom interface ***' 
    829                WRITE(numout,*) ' qsr       : ', qsr(ji,jj) 
    830                WRITE(numout,*) ' qns       : ', qns(ji,jj) 
    831                WRITE(numout,*) ' fdtcn     : ', fdtcn(ji,jj) 
    832                WRITE(numout,*) ' qcmif     : ', qcmif(ji,jj) * r1_rdtice 
    833                WRITE(numout,*) ' qldif     : ', qldif(ji,jj) * r1_rdtice 
    834                WRITE(numout,*) 
    835                WRITE(numout,*) ' - Salt fluxes at bottom interface ***' 
    836                WRITE(numout,*) ' emp       : ', emp    (ji,jj) 
    837                WRITE(numout,*) ' sfx_bri   : ', sfx_bri(ji,jj) 
    838                WRITE(numout,*) ' sfx       : ', sfx    (ji,jj) 
    839                WRITE(numout,*) ' sfx_res   : ', sfx_res(ji,jj) 
    840                WRITE(numout,*) ' sfx_mec   : ', sfx_mec(ji,jj) 
    841                WRITE(numout,*) ' - Heat fluxes at bottom interface ***' 
    842                WRITE(numout,*) ' fheat_res : ', fheat_res(ji,jj) 
    843                WRITE(numout,*) 
    844                WRITE(numout,*) ' - Momentum fluxes ' 
    845                WRITE(numout,*) ' utau      : ', utau(ji,jj)  
    846                WRITE(numout,*) ' vtau      : ', vtau(ji,jj) 
    847             ENDIF 
    848             WRITE(numout,*) ' ' 
    849             ! 
    850          END DO 
    851       END DO 
    852  
    853    END SUBROUTINE lim_prt_state 
     629    
     630   FUNCTION fice_ice_ave ( ptab ) 
     631      !!-------------------------------------------------------------------------- 
     632      !! * Compute average over categories, for ice covered part of grid cell 
     633      !!-------------------------------------------------------------------------- 
     634      REAL (kind=wp), DIMENSION (jpi,jpj) :: fice_ice_ave 
     635      REAL (kind=wp), DIMENSION (jpi,jpj,jpl), INTENT(in) :: ptab 
     636 
     637      fice_ice_ave (:,:) = 0.0_wp 
     638      WHERE ( at_i (:,:) > 0.0_wp ) fice_ice_ave (:,:) = fice_cell_ave ( ptab (:,:,:)) / at_i (:,:) 
     639 
     640   END FUNCTION fice_ice_ave 
     641 
    854642 
    855643#else 
     
    861649      WRITE(*,*) 'sbc_ice_lim: You should not have seen this print! error?', kt, kblk 
    862650   END SUBROUTINE sbc_ice_lim 
     651   SUBROUTINE sbc_lim_init                 ! Dummy routine 
     652   END SUBROUTINE sbc_lim_init 
    863653#endif 
    864654 
Note: See TracChangeset for help on using the changeset viewer.