LCOV - code coverage report
Current view: top level - cicecore/cicedyn/general - ice_flux.F90 (source / functions) Hit Total Coverage
Test: 231018-211459:8916b9ff2c:1:quick Lines: 296 384 77.08 %
Date: 2023-10-18 15:30:36 Functions: 7 7 100.00 %

          Line data    Source code
       1             : !=======================================================================
       2             : 
       3             : ! Flux variable declarations; these include fields sent from the coupler
       4             : ! ("in"), sent to the coupler ("out"), written to diagnostic history files
       5             : ! ("diagnostic"), and used internally ("internal").
       6             : !
       7             : ! author Elizabeth C. Hunke, LANL
       8             : !
       9             : ! 2004: Block structure added by William Lipscomb
      10             : !       Swappped, revised, and added some subroutines
      11             : ! 2006: Converted to free source form (F90) by Elizabeth Hunke
      12             : 
      13             :       module ice_flux
      14             : 
      15             :       use ice_kinds_mod
      16             :       use ice_fileunits, only: nu_diag
      17             :       use ice_blocks, only: nx_block, ny_block
      18             :       use ice_domain_size, only: max_blocks, ncat, max_nstrm, nilyr
      19             :       use ice_constants, only: c0, c1, c5, c10, c20, c180
      20             :       use ice_exit, only: abort_ice
      21             :       use icepack_intfc, only: icepack_warnings_flush, icepack_warnings_aborted
      22             :       use icepack_intfc, only: icepack_query_tracer_flags, icepack_query_tracer_indices
      23             :       use icepack_intfc, only: icepack_query_parameters
      24             :       use icepack_intfc, only: icepack_liquidus_temperature
      25             : 
      26             :       implicit none
      27             :       private
      28             :       public :: init_coupler_flux, init_history_therm, init_history_dyn, &
      29             :                 init_flux_ocn, init_flux_atm, scale_fluxes, alloc_flux
      30             : 
      31             :       character (char_len), public :: &
      32             :          default_season ! seasonal default values for forcing
      33             : 
      34             :       !-----------------------------------------------------------------
      35             :       ! Dynamics component
      36             :       ! All variables are assumed to be on the atm or ocn thermodynamic
      37             :       ! grid except as noted
      38             :       !
      39             :       ! scale_fluxes divides several of these by aice "in place", so
      40             :       ! the state of some of these variables is not well defined.  In the
      41             :       ! future, we need to refactor and add "_iavg" versions of the
      42             :       ! fields to clearly differentiate fields that have been divided
      43             :       ! by aice and others that are not.  The challenge is that we need
      44             :       ! to go thru each field carefully to see which version is used.
      45             :       ! For instance, in diagnostics, there are places where these
      46             :       ! fields are multiplied by aice to compute things properly.
      47             :       ! strocn[x,y]T_iavg is the first field defined using _iavg.
      48             :       !-----------------------------------------------------------------
      49             : 
      50             :       real (kind=dbl_kind), dimension (:,:,:), allocatable, public :: &
      51             : 
      52             :        ! in from atmos (if .not.calc_strair)
      53             :          strax   , & ! wind stress components (N/m^2), on grid_atm_dynu
      54             :          stray   , & !                                 on grid_atm_dynv   ! LCOV_EXCL_LINE
      55             : 
      56             :        ! in from ocean
      57             :          uocn    , & ! ocean current, x-direction (m/s),     on grid_ocn_dynu
      58             :          vocn    , & ! ocean current, y-direction (m/s),     on grid_ocn_dynv   ! LCOV_EXCL_LINE
      59             :          ss_tltx , & ! sea surface slope, x-direction (m/m), on grid_ocn_dynu   ! LCOV_EXCL_LINE
      60             :          ss_tlty , & ! sea surface slope, y-direction,       on grid_ocn_dynv   ! LCOV_EXCL_LINE
      61             :          hwater  , & ! water depth for seabed stress calc (landfast ice)   ! LCOV_EXCL_LINE
      62             : 
      63             :        ! out to atmosphere
      64             :          strairxT, & ! stress on ice by air, x-direction at T points, computed in icepack
      65             :          strairyT, & ! stress on ice by air, y-direction at T points, computed in icepack   ! LCOV_EXCL_LINE
      66             : 
      67             :        ! out to ocean          T-cell (kg/m s^2)
      68             :        ! Note, CICE_IN_NEMO uses strocnx and strocny for coupling
      69             :          strocnxT_iavg, & ! ice-ocean stress, x-direction at T points, per ice fraction (scaled flux)
      70             :          strocnyT_iavg    ! ice-ocean stress, y-direction at T points, per ice fraction (scaled flux)
      71             : 
      72             :        ! diagnostic
      73             : 
      74             :       real (kind=dbl_kind), dimension (:,:,:), allocatable, public :: &
      75             :          sig1    , & ! normalized principal stress component   ! LCOV_EXCL_LINE
      76             :          sig2    , & ! normalized principal stress component   ! LCOV_EXCL_LINE
      77             :          sigP    , & ! internal ice pressure (N/m)   ! LCOV_EXCL_LINE
      78             :          taubxU  , & ! seabed stress (x) (N/m^2)   ! LCOV_EXCL_LINE
      79             :          taubyU  , & ! seabed stress (y) (N/m^2)   ! LCOV_EXCL_LINE
      80             :          strairxU, & ! stress on ice by air, x-direction at U points   ! LCOV_EXCL_LINE
      81             :          strairyU, & ! stress on ice by air, y-direction at U points   ! LCOV_EXCL_LINE
      82             :          strocnxU, & ! ice-ocean stress, x-direction at U points, computed in dyn_finish   ! LCOV_EXCL_LINE
      83             :          strocnyU, & ! ice-ocean stress, y-direction at U points, computed in dyn_finish   ! LCOV_EXCL_LINE
      84             :          strtltxU, & ! stress due to sea surface slope, x-direction   ! LCOV_EXCL_LINE
      85             :          strtltyU, & ! stress due to sea surface slope, y-direction   ! LCOV_EXCL_LINE
      86             :          strintxU, & ! divergence of internal ice stress, x (N/m^2)   ! LCOV_EXCL_LINE
      87             :          strintyU, & ! divergence of internal ice stress, y (N/m^2)   ! LCOV_EXCL_LINE
      88             :          taubxN  , & ! seabed stress (x) at N points (N/m^2)   ! LCOV_EXCL_LINE
      89             :          taubyN  , & ! seabed stress (y) at N points (N/m^2)   ! LCOV_EXCL_LINE
      90             :          strairxN, & ! stress on ice by air, x-direction at N points   ! LCOV_EXCL_LINE
      91             :          strairyN, & ! stress on ice by air, y-direction at N points   ! LCOV_EXCL_LINE
      92             :          strocnxN, & ! ice-ocean stress, x-direction at N points, computed in dyn_finish   ! LCOV_EXCL_LINE
      93             :          strocnyN, & ! ice-ocean stress, y-direction at N points, computed in dyn_finish   ! LCOV_EXCL_LINE
      94             :          strtltxN, & ! stress due to sea surface slope, x-direction at N points   ! LCOV_EXCL_LINE
      95             :          strtltyN, & ! stress due to sea surface slope, y-direction at N points   ! LCOV_EXCL_LINE
      96             :          strintxN, & ! divergence of internal ice stress, x at N points (N/m^2)   ! LCOV_EXCL_LINE
      97             :          strintyN, & ! divergence of internal ice stress, y at N points (N/m^2)   ! LCOV_EXCL_LINE
      98             :          taubxE  , & ! seabed stress (x) at E points (N/m^2)   ! LCOV_EXCL_LINE
      99             :          taubyE  , & ! seabed stress (y) at E points (N/m^2)   ! LCOV_EXCL_LINE
     100             :          strairxE, & ! stress on ice by air, x-direction at E points   ! LCOV_EXCL_LINE
     101             :          strairyE, & ! stress on ice by air, y-direction at E points   ! LCOV_EXCL_LINE
     102             :          strocnxE, & ! ice-ocean stress, x-direction at E points, computed in dyn_finish   ! LCOV_EXCL_LINE
     103             :          strocnyE, & ! ice-ocean stress, y-direction at E points, computed in dyn_finish   ! LCOV_EXCL_LINE
     104             :          strtltxE, & ! stress due to sea surface slope, x-direction at E points   ! LCOV_EXCL_LINE
     105             :          strtltyE, & ! stress due to sea surface slope, y-direction at E points   ! LCOV_EXCL_LINE
     106             :          strintxE, & ! divergence of internal ice stress, x at E points (N/m^2)   ! LCOV_EXCL_LINE
     107             :          strintyE, & ! divergence of internal ice stress, y at E points (N/m^2)   ! LCOV_EXCL_LINE
     108             :          daidtd  , & ! ice area tendency due to transport   (1/s)   ! LCOV_EXCL_LINE
     109             :          dvidtd  , & ! ice volume tendency due to transport (m/s)   ! LCOV_EXCL_LINE
     110             :          dagedtd , & ! ice age tendency due to transport (s/s)   ! LCOV_EXCL_LINE
     111             :          dardg1dt, & ! rate of area loss by ridging ice (1/s)   ! LCOV_EXCL_LINE
     112             :          dardg2dt, & ! rate of area gain by new ridges (1/s)   ! LCOV_EXCL_LINE
     113             :          dvirdgdt, & ! rate of ice volume ridged (m/s)   ! LCOV_EXCL_LINE
     114             :          opening     ! rate of opening due to divergence/shear (1/s)
     115             : 
     116             :       real (kind=dbl_kind), &
     117             :          dimension (:,:,:,:), allocatable, public :: &   ! LCOV_EXCL_LINE
     118             :        ! ridging diagnostics in categories
     119             :          dardg1ndt, & ! rate of area loss by ridging ice (1/s)
     120             :          dardg2ndt, & ! rate of area gain by new ridges (1/s)   ! LCOV_EXCL_LINE
     121             :          dvirdgndt, & ! rate of ice volume ridged (m/s)   ! LCOV_EXCL_LINE
     122             :          aparticn,  & ! participation function   ! LCOV_EXCL_LINE
     123             :          krdgn,     & ! mean ridge thickness/thickness of ridging ice   ! LCOV_EXCL_LINE
     124             :          ardgn,     & ! fractional area of ridged ice   ! LCOV_EXCL_LINE
     125             :          vrdgn,     & ! volume of ridged ice   ! LCOV_EXCL_LINE
     126             :          araftn,    & ! rafting ice area   ! LCOV_EXCL_LINE
     127             :          vraftn,    & ! rafting ice volume   ! LCOV_EXCL_LINE
     128             :          aredistn,  & ! redistribution function: fraction of new ridge area   ! LCOV_EXCL_LINE
     129             :          vredistn     ! redistribution function: fraction of new ridge volume
     130             : 
     131             :        ! restart
     132             : 
     133             :       real (kind=dbl_kind), dimension (:,:,:), allocatable, public :: &
     134             :        ! ice stress tensor in each corner of T cell (kg/s^2)
     135             :          stressp_1, stressp_2, stressp_3, stressp_4 , & ! sigma11+sigma22
     136             :          stressm_1, stressm_2, stressm_3, stressm_4 , & ! sigma11-sigma22   ! LCOV_EXCL_LINE
     137             :          stress12_1,stress12_2,stress12_3,stress12_4, & ! sigma12   ! LCOV_EXCL_LINE
     138             :        ! ice stress tensor at U and T locations (grid_ice = 'C|CD') (kg/s^2)
     139             :          stresspT, stressmT, stress12T, & ! sigma11+sigma22, sigma11-sigma22, sigma12
     140             :          stresspU, stressmU, stress12U    ! "
     141             : 
     142             :        ! internal
     143             : 
     144             :       real (kind=dbl_kind), dimension (:,:,:), allocatable, public :: &
     145             :          fmU      , & ! Coriolis param. * mass in U-cell (kg/s)   ! LCOV_EXCL_LINE
     146             :          TbU      , & ! factor for seabed stress (N/m^2)   ! LCOV_EXCL_LINE
     147             :          fmE      , & ! Coriolis param. * mass in E-cell (kg/s)   ! LCOV_EXCL_LINE
     148             :          TbE      , & ! factor for seabed stress (N/m^2)   ! LCOV_EXCL_LINE
     149             :          fmN      , & ! Coriolis param. * mass in N-cell (kg/s)   ! LCOV_EXCL_LINE
     150             :          TbN          ! factor for seabed stress (N/m^2)
     151             : 
     152             :       !-----------------------------------------------------------------
     153             :       ! Thermodynamic component
     154             :       !-----------------------------------------------------------------
     155             : 
     156             :        ! in from atmosphere (if calc_Tsfc)
     157             : 
     158             :       real (kind=dbl_kind), dimension (:,:,:), allocatable, public :: &
     159             :          zlvl    , & ! atm level height (momentum) (m)   ! LCOV_EXCL_LINE
     160             :          zlvs    , & ! atm level height (scalar quantities) (m)   ! LCOV_EXCL_LINE
     161             :          uatm    , & ! wind velocity components (m/s), on grid_atm_dynu   ! LCOV_EXCL_LINE
     162             :          vatm    , & !                                 on grid_atm_dynv   ! LCOV_EXCL_LINE
     163             :          wind    , & ! wind speed (m/s)              , on grid_atm_dynu   ! LCOV_EXCL_LINE
     164             :          potT    , & ! air potential temperature  (K)   ! LCOV_EXCL_LINE
     165             :          Tair    , & ! air temperature  (K)   ! LCOV_EXCL_LINE
     166             :          Qa      , & ! specific humidity (kg/kg)   ! LCOV_EXCL_LINE
     167             :          rhoa    , & ! air density (kg/m^3)   ! LCOV_EXCL_LINE
     168             :          swvdr   , & ! sw down, visible, direct  (W/m^2)   ! LCOV_EXCL_LINE
     169             :          swvdf   , & ! sw down, visible, diffuse (W/m^2)   ! LCOV_EXCL_LINE
     170             :          swidr   , & ! sw down, near IR, direct  (W/m^2)   ! LCOV_EXCL_LINE
     171             :          swidf   , & ! sw down, near IR, diffuse (W/m^2)   ! LCOV_EXCL_LINE
     172             :          flw         ! incoming longwave radiation (W/m^2)
     173             : 
     174             :        ! in from atmosphere (if .not. Tsfc_calc)
     175             :        ! required for coupling to HadGEM3
     176             :        ! NOTE: when in CICE_IN_NEMO mode, these are gridbox mean fields,
     177             :        ! not per ice area. When in standalone mode, these are per ice area.
     178             : 
     179             :       real (kind=dbl_kind), &
     180             :          dimension (:,:,:,:), allocatable, public :: &   ! LCOV_EXCL_LINE
     181             :          fsurfn_f   , & ! net flux to top surface, excluding fcondtop   ! LCOV_EXCL_LINE
     182             :          fcondtopn_f, & ! downward cond flux at top surface (W m-2)   ! LCOV_EXCL_LINE
     183             :          fsensn_f   , & ! sensible heat flux (W m-2)   ! LCOV_EXCL_LINE
     184             :          flatn_f        ! latent heat flux (W m-2)
     185             : 
     186             :        ! in from atmosphere
     187             : 
     188             :       real (kind=dbl_kind), dimension (:,:,:), allocatable, public :: &
     189             :          frain   , & ! rainfall rate (kg/m^2 s)   ! LCOV_EXCL_LINE
     190             :          fsnow       ! snowfall rate (kg/m^2 s)
     191             : 
     192             :        ! in from ocean
     193             : 
     194             :       real (kind=dbl_kind), dimension (:,:,:), allocatable, public :: &
     195             :          sss     , & ! sea surface salinity (ppt)   ! LCOV_EXCL_LINE
     196             :          sst     , & ! sea surface temperature (C)   ! LCOV_EXCL_LINE
     197             :          frzmlt  , & ! freezing/melting potential (W/m^2)   ! LCOV_EXCL_LINE
     198             :          frzmlt_init, & ! frzmlt used in current time step (W/m^2)   ! LCOV_EXCL_LINE
     199             :          Tf      , & ! freezing temperature (C)   ! LCOV_EXCL_LINE
     200             :          qdp     , & ! deep ocean heat flux (W/m^2), negative upward   ! LCOV_EXCL_LINE
     201             :          hmix    , & ! mixed layer depth (m)   ! LCOV_EXCL_LINE
     202             :          daice_da    ! data assimilation concentration increment rate
     203             :                      ! (concentration s-1)(only used in hadgem drivers)
     204             : 
     205             :        ! out to atmosphere (if calc_Tsfc)
     206             :        ! note Tsfc is in ice_state.F
     207             : 
     208             :       real (kind=dbl_kind), dimension (:,:,:), allocatable, public :: &
     209             :          fsens   , & ! sensible heat flux (W/m^2)   ! LCOV_EXCL_LINE
     210             :          flat    , & ! latent heat flux   (W/m^2)   ! LCOV_EXCL_LINE
     211             :          fswabs  , & ! shortwave flux absorbed in ice and ocean (W/m^2)   ! LCOV_EXCL_LINE
     212             :          fswint_ai, & ! SW absorbed in ice interior below surface (W/m^2)   ! LCOV_EXCL_LINE
     213             :          flwout  , & ! outgoing longwave radiation (W/m^2)   ! LCOV_EXCL_LINE
     214             :          Tref    , & ! 2m atm reference temperature (K)   ! LCOV_EXCL_LINE
     215             :          Qref    , & ! 2m atm reference spec humidity (kg/kg)   ! LCOV_EXCL_LINE
     216             :          Uref    , & ! 10m atm reference wind speed (m/s)   ! LCOV_EXCL_LINE
     217             :          evap    , & ! evaporative water flux (kg/m^2/s)   ! LCOV_EXCL_LINE
     218             :          evaps   , & ! evaporative water flux over snow (kg/m^2/s)   ! LCOV_EXCL_LINE
     219             :          evapi       ! evaporative water flux over ice (kg/m^2/s)
     220             : 
     221             :        ! albedos aggregated over categories (if calc_Tsfc)
     222             :       real (kind=dbl_kind), dimension (:,:,:), allocatable, public :: &
     223             :          alvdr   , & ! visible, direct   (fraction)   ! LCOV_EXCL_LINE
     224             :          alidr   , & ! near-ir, direct   (fraction)   ! LCOV_EXCL_LINE
     225             :          alvdf   , & ! visible, diffuse  (fraction)   ! LCOV_EXCL_LINE
     226             :          alidf   , & ! near-ir, diffuse  (fraction)   ! LCOV_EXCL_LINE
     227             :          ! grid-box-mean versions
     228             :          alvdr_ai, & ! visible, direct   (fraction)
     229             :          alidr_ai, & ! near-ir, direct   (fraction)   ! LCOV_EXCL_LINE
     230             :          alvdf_ai, & ! visible, diffuse  (fraction)   ! LCOV_EXCL_LINE
     231             :          alidf_ai, & ! near-ir, diffuse  (fraction)   ! LCOV_EXCL_LINE
     232             :          ! components for history
     233             :          albice    , & ! bare ice albedo
     234             :          albsno    , & ! snow albedo   ! LCOV_EXCL_LINE
     235             :          albpnd    , & ! melt pond albedo   ! LCOV_EXCL_LINE
     236             :          apeff_ai  , & ! effective pond area used for radiation calculation   ! LCOV_EXCL_LINE
     237             :          snowfrac  , & ! snow fraction used in radiation   ! LCOV_EXCL_LINE
     238             :          ! components for diagnostic
     239             :          alvdr_init, & ! visible, direct   (fraction)
     240             :          alidr_init, & ! near-ir, direct   (fraction)   ! LCOV_EXCL_LINE
     241             :          alvdf_init, & ! visible, diffuse  (fraction)   ! LCOV_EXCL_LINE
     242             :          alidf_init    ! near-ir, diffuse  (fraction)
     243             : 
     244             :       real (kind=dbl_kind), dimension(:,:,:,:), allocatable, public :: &
     245             :          albcnt       ! counter for zenith angle
     246             : 
     247             :        ! out to ocean
     248             :        ! (Note CICE_IN_NEMO does not use these for coupling.
     249             :        !  It uses fresh_ai,fsalt_ai,fhocn_ai and fswthru_ai)
     250             :       real (kind=dbl_kind), dimension (:,:,:), allocatable, public :: &
     251             :          fpond   , & ! fresh water flux to ponds (kg/m^2/s)   ! LCOV_EXCL_LINE
     252             :          fresh   , & ! fresh water flux to ocean (kg/m^2/s)   ! LCOV_EXCL_LINE
     253             :          fsalt   , & ! salt flux to ocean (kg/m^2/s)   ! LCOV_EXCL_LINE
     254             :          fhocn   , & ! net heat flux to ocean (W/m^2)   ! LCOV_EXCL_LINE
     255             :          fsloss  , & ! rate of snow loss to leads (kg/m^2/s)   ! LCOV_EXCL_LINE
     256             :          fswthru , & ! shortwave penetrating to ocean (W/m^2)   ! LCOV_EXCL_LINE
     257             :          fswthru_vdr , & ! vis dir shortwave penetrating to ocean (W/m^2)   ! LCOV_EXCL_LINE
     258             :          fswthru_vdf , & ! vis dif shortwave penetrating to ocean (W/m^2)   ! LCOV_EXCL_LINE
     259             :          fswthru_idr , & ! nir dir shortwave penetrating to ocean (W/m^2)   ! LCOV_EXCL_LINE
     260             :          fswthru_idf     ! nir dif shortwave penetrating to ocean (W/m^2)
     261             : 
     262             :        ! internal
     263             : 
     264             :       real (kind=dbl_kind), dimension (:,:,:), allocatable, public :: &
     265             :          scale_factor! scaling factor for shortwave components
     266             : 
     267             :       logical (kind=log_kind), public :: &
     268             :          update_ocn_f, & ! if true, update fresh water and salt fluxes   ! LCOV_EXCL_LINE
     269             :          l_mpond_fresh   ! if true, include freshwater feedback from meltponds
     270             :                          ! when running in ice-ocean or coupled configuration
     271             : 
     272             :       character (char_len), public :: &
     273             :          cpl_frazil      ! type of coupling for frazil ice, 'fresh_ice_correction','internal','external'
     274             : 
     275             :       real (kind=dbl_kind), dimension (:,:,:,:), allocatable, public :: &
     276             :          meltsn      , & ! snow melt in category n (m)   ! LCOV_EXCL_LINE
     277             :          melttn      , & ! top melt in category n (m)   ! LCOV_EXCL_LINE
     278             :          meltbn      , & ! bottom melt in category n (m)   ! LCOV_EXCL_LINE
     279             :          congeln     , & ! congelation ice formation in category n (m)   ! LCOV_EXCL_LINE
     280             :          snoicen         ! snow-ice formation in category n (m)
     281             : 
     282             :       real (kind=dbl_kind), dimension (:,:,:,:), allocatable, public :: &
     283             :          keffn_top       ! effective thermal conductivity of the top ice layer
     284             :                          ! on categories (W/m^2/K)
     285             : 
     286             :       ! quantities passed from ocean mixed layer to atmosphere
     287             :       ! (for running with CAM)
     288             : 
     289             :       real (kind=dbl_kind), dimension (:,:,:), allocatable, public :: &
     290             :          strairx_ocn , & ! stress on ocean by air, x-direction   ! LCOV_EXCL_LINE
     291             :          strairy_ocn , & ! stress on ocean by air, y-direction   ! LCOV_EXCL_LINE
     292             :          fsens_ocn   , & ! sensible heat flux (W/m^2)   ! LCOV_EXCL_LINE
     293             :          flat_ocn    , & ! latent heat flux   (W/m^2)   ! LCOV_EXCL_LINE
     294             :          flwout_ocn  , & ! outgoing longwave radiation (W/m^2)   ! LCOV_EXCL_LINE
     295             :          evap_ocn    , & ! evaporative water flux (kg/m^2/s)   ! LCOV_EXCL_LINE
     296             :          alvdr_ocn   , & ! visible, direct   (fraction)   ! LCOV_EXCL_LINE
     297             :          alidr_ocn   , & ! near-ir, direct   (fraction)   ! LCOV_EXCL_LINE
     298             :          alvdf_ocn   , & ! visible, diffuse  (fraction)   ! LCOV_EXCL_LINE
     299             :          alidf_ocn   , & ! near-ir, diffuse  (fraction)   ! LCOV_EXCL_LINE
     300             :          Tref_ocn    , & ! 2m atm reference temperature (K)   ! LCOV_EXCL_LINE
     301             :          Qref_ocn        ! 2m atm reference spec humidity (kg/kg)
     302             : 
     303             :       ! diagnostic
     304             : 
     305             :       real (kind=dbl_kind), dimension (:,:,:), allocatable, public :: &
     306             :          fsurf , & ! net surface heat flux (excluding fcondtop)(W/m^2)   ! LCOV_EXCL_LINE
     307             :          fcondtop,&! top surface conductive flux        (W/m^2)   ! LCOV_EXCL_LINE
     308             :          fcondbot,&! bottom surface conductive flux     (W/m^2)   ! LCOV_EXCL_LINE
     309             :          fbot,   & ! heat flux at bottom surface of ice (excluding excess) (W/m^2)   ! LCOV_EXCL_LINE
     310             :          Tbot,   & ! temperature at bottom surface of ice (deg C)   ! LCOV_EXCL_LINE
     311             :          Tsnice,  & ! temperature at snow ice interface (deg C)   ! LCOV_EXCL_LINE
     312             :          congel, & ! basal ice growth         (m/step-->cm/day)   ! LCOV_EXCL_LINE
     313             :          frazil, & ! frazil ice growth        (m/step-->cm/day)   ! LCOV_EXCL_LINE
     314             :          snoice, & ! snow-ice formation       (m/step-->cm/day)   ! LCOV_EXCL_LINE
     315             :          meltt , & ! top ice melt             (m/step-->cm/day)   ! LCOV_EXCL_LINE
     316             :          melts , & ! snow melt                (m/step-->cm/day)   ! LCOV_EXCL_LINE
     317             :          meltb , & ! basal ice melt           (m/step-->cm/day)   ! LCOV_EXCL_LINE
     318             :          meltl , & ! lateral ice melt         (m/step-->cm/day)   ! LCOV_EXCL_LINE
     319             :          dsnow,  & ! change in snow thickness (m/step-->cm/day)   ! LCOV_EXCL_LINE
     320             :          daidtt, & ! ice area tendency thermo.   (s^-1)   ! LCOV_EXCL_LINE
     321             :          dvidtt, & ! ice volume tendency thermo. (m/s)   ! LCOV_EXCL_LINE
     322             :          dagedtt,& ! ice age tendency thermo.    (s/s)   ! LCOV_EXCL_LINE
     323             :          mlt_onset, &! day of year that sfc melting begins   ! LCOV_EXCL_LINE
     324             :          frz_onset, &! day of year that freezing begins (congel or frazil)   ! LCOV_EXCL_LINE
     325             :          frazil_diag ! frazil ice growth diagnostic (m/step-->cm/day)
     326             : 
     327             :       real (kind=dbl_kind), &
     328             :          dimension (:,:,:,:), allocatable, public :: &   ! LCOV_EXCL_LINE
     329             :          fsurfn,   & ! category fsurf   ! LCOV_EXCL_LINE
     330             :          fcondtopn,& ! category fcondtop   ! LCOV_EXCL_LINE
     331             :          fcondbotn,& ! category fcondbot   ! LCOV_EXCL_LINE
     332             :          fsensn,   & ! category sensible heat flux   ! LCOV_EXCL_LINE
     333             :          flatn       ! category latent heat flux
     334             : 
     335             :       real (kind=dbl_kind), &
     336             :          dimension (:,:,:,:), allocatable, public :: &   ! LCOV_EXCL_LINE
     337             :          snwcnt       ! counter for presence of snow
     338             : 
     339             :       ! As above but these remain grid box mean values i.e. they are not
     340             :       ! divided by aice at end of ice_dynamics.  These are used in
     341             :       ! CICE_IN_NEMO for coupling and also for generating
     342             :       ! ice diagnostics and history files as these are more accurate.
     343             :       ! (The others suffer from problem of incorrect values at grid boxes
     344             :       !  that change from an ice free state to an icy state.)
     345             : 
     346             :       real (kind=dbl_kind), dimension (:,:,:), allocatable, public :: &
     347             :          fresh_ai, & ! fresh water flux to ocean (kg/m^2/s)   ! LCOV_EXCL_LINE
     348             :          fsalt_ai, & ! salt flux to ocean (kg/m^2/s)   ! LCOV_EXCL_LINE
     349             :          fhocn_ai, & ! net heat flux to ocean (W/m^2)   ! LCOV_EXCL_LINE
     350             :          fswthru_ai  ! shortwave penetrating to ocean (W/m^2)
     351             : 
     352             :       ! Used with data assimilation in hadgem drivers
     353             :       real (kind=dbl_kind), dimension (:,:,:), allocatable, public :: &
     354             :          fresh_da, & ! fresh water flux to ocean due to data assim (kg/m^2/s)   ! LCOV_EXCL_LINE
     355             :          fsalt_da    ! salt flux to ocean due to data assimilation(kg/m^2/s)
     356             : 
     357             :       real (kind=dbl_kind), dimension (:,:,:,:), allocatable, public :: &
     358             :          fswthrun_ai  ! per-category fswthru * ai (W/m^2)
     359             : 
     360             :       logical (kind=log_kind), public :: send_i2x_per_cat = .false.
     361             : 
     362             :       !-----------------------------------------------------------------
     363             :       ! internal
     364             :       !-----------------------------------------------------------------
     365             : 
     366             :       real (kind=dbl_kind), dimension (:,:,:), allocatable, public :: &
     367             :          uatmT   , & ! uatm on T grid (m/s)   ! LCOV_EXCL_LINE
     368             :          vatmT   , & ! vatm on T grid (m/s)   ! LCOV_EXCL_LINE
     369             :          rside   , & ! fraction of ice that melts laterally   ! LCOV_EXCL_LINE
     370             :          fside   , & ! lateral heat flux (W/m^2)   ! LCOV_EXCL_LINE
     371             :          wlat    , & ! lateral heat rate (m/s)   ! LCOV_EXCL_LINE
     372             :          fsw     , & ! incoming shortwave radiation (W/m^2)   ! LCOV_EXCL_LINE
     373             :          coszen  , & ! cosine solar zenith angle, < 0 for sun below horizon   ! LCOV_EXCL_LINE
     374             :          rdg_conv, & ! convergence term for ridging (1/s)   ! LCOV_EXCL_LINE
     375             :          rdg_shear   ! shear term for ridging (1/s)
     376             : 
     377             :       real (kind=dbl_kind), dimension(:,:,:,:), allocatable, public :: &
     378             :          salinz    ,&   ! initial salinity  profile (ppt)   ! LCOV_EXCL_LINE
     379             :          Tmltz          ! initial melting temperature (^oC)
     380             : 
     381             : !=======================================================================
     382             : 
     383             :       contains
     384             : 
     385             : !=======================================================================
     386             : !
     387             : ! Allocate space for all variables
     388             : !
     389          37 :       subroutine alloc_flux
     390             : 
     391             :       use ice_grid, only : grid_ice
     392             : 
     393             :       integer (int_kind) :: ierr
     394             : 
     395             :       allocate( &
     396             :          strax      (nx_block,ny_block,max_blocks), & ! wind stress components (N/m^2)   ! LCOV_EXCL_LINE
     397             :          stray      (nx_block,ny_block,max_blocks), & !   ! LCOV_EXCL_LINE
     398             :          uocn       (nx_block,ny_block,max_blocks), & ! ocean current, x-direction (m/s)   ! LCOV_EXCL_LINE
     399             :          vocn       (nx_block,ny_block,max_blocks), & ! ocean current, y-direction (m/s)   ! LCOV_EXCL_LINE
     400             :          ss_tltx    (nx_block,ny_block,max_blocks), & ! sea surface slope, x-direction (m/m)   ! LCOV_EXCL_LINE
     401             :          ss_tlty    (nx_block,ny_block,max_blocks), & ! sea surface slope, y-direction   ! LCOV_EXCL_LINE
     402             :          hwater     (nx_block,ny_block,max_blocks), & ! water depth for seabed stress calc (landfast ice)   ! LCOV_EXCL_LINE
     403             :          strairxT   (nx_block,ny_block,max_blocks), & ! stress on ice by air, x-direction   ! LCOV_EXCL_LINE
     404             :          strairyT   (nx_block,ny_block,max_blocks), & ! stress on ice by air, y-direction   ! LCOV_EXCL_LINE
     405             :          strocnxT_iavg(nx_block,ny_block,max_blocks), & ! ice-ocean stress, x-direction, per ice area   ! LCOV_EXCL_LINE
     406             :          strocnyT_iavg(nx_block,ny_block,max_blocks), & ! ice-ocean stress, y-direction, per ice area   ! LCOV_EXCL_LINE
     407             :          sig1       (nx_block,ny_block,max_blocks), & ! normalized principal stress component   ! LCOV_EXCL_LINE
     408             :          sig2       (nx_block,ny_block,max_blocks), & ! normalized principal stress component   ! LCOV_EXCL_LINE
     409             :          sigP       (nx_block,ny_block,max_blocks), & ! internal ice pressure (N/m)   ! LCOV_EXCL_LINE
     410             :          taubxU     (nx_block,ny_block,max_blocks), & ! seabed stress (x) (N/m^2)   ! LCOV_EXCL_LINE
     411             :          taubyU     (nx_block,ny_block,max_blocks), & ! seabed stress (y) (N/m^2)   ! LCOV_EXCL_LINE
     412             :          strairxU   (nx_block,ny_block,max_blocks), & ! stress on ice by air, x-direction   ! LCOV_EXCL_LINE
     413             :          strairyU   (nx_block,ny_block,max_blocks), & ! stress on ice by air, y-direction   ! LCOV_EXCL_LINE
     414             :          strocnxU   (nx_block,ny_block,max_blocks), & ! ice-ocean stress, x-direction   ! LCOV_EXCL_LINE
     415             :          strocnyU   (nx_block,ny_block,max_blocks), & ! ice-ocean stress, y-direction   ! LCOV_EXCL_LINE
     416             :          strtltxU   (nx_block,ny_block,max_blocks), & ! stress due to sea surface slope, x-direction   ! LCOV_EXCL_LINE
     417             :          strtltyU   (nx_block,ny_block,max_blocks), & ! stress due to sea surface slope, y-direction   ! LCOV_EXCL_LINE
     418             :          strintxU   (nx_block,ny_block,max_blocks), & ! divergence of internal ice stress, x (N/m^2)   ! LCOV_EXCL_LINE
     419             :          strintyU   (nx_block,ny_block,max_blocks), & ! divergence of internal ice stress, y (N/m^2)   ! LCOV_EXCL_LINE
     420             :          daidtd     (nx_block,ny_block,max_blocks), & ! ice area tendency due to transport   (1/s)   ! LCOV_EXCL_LINE
     421             :          dvidtd     (nx_block,ny_block,max_blocks), & ! ice volume tendency due to transport (m/s)   ! LCOV_EXCL_LINE
     422             :          dagedtd    (nx_block,ny_block,max_blocks), & ! ice age tendency due to transport (s/s)   ! LCOV_EXCL_LINE
     423             :          dardg1dt   (nx_block,ny_block,max_blocks), & ! rate of area loss by ridging ice (1/s)   ! LCOV_EXCL_LINE
     424             :          dardg2dt   (nx_block,ny_block,max_blocks), & ! rate of area gain by new ridges (1/s)   ! LCOV_EXCL_LINE
     425             :          dvirdgdt   (nx_block,ny_block,max_blocks), & ! rate of ice volume ridged (m/s)   ! LCOV_EXCL_LINE
     426             :          opening    (nx_block,ny_block,max_blocks), & ! rate of opening due to divergence/shear (1/s)   ! LCOV_EXCL_LINE
     427             :          stressp_1  (nx_block,ny_block,max_blocks), & ! sigma11+sigma22   ! LCOV_EXCL_LINE
     428             :          stressp_2  (nx_block,ny_block,max_blocks), & ! sigma11+sigma22   ! LCOV_EXCL_LINE
     429             :          stressp_3  (nx_block,ny_block,max_blocks), & ! sigma11+sigma22   ! LCOV_EXCL_LINE
     430             :          stressp_4  (nx_block,ny_block,max_blocks), & ! sigma11+sigma22   ! LCOV_EXCL_LINE
     431             :          stressm_1  (nx_block,ny_block,max_blocks), & ! sigma11-sigma22   ! LCOV_EXCL_LINE
     432             :          stressm_2  (nx_block,ny_block,max_blocks), & ! sigma11-sigma22   ! LCOV_EXCL_LINE
     433             :          stressm_3  (nx_block,ny_block,max_blocks), & ! sigma11-sigma22   ! LCOV_EXCL_LINE
     434             :          stressm_4  (nx_block,ny_block,max_blocks), & ! sigma11-sigma22   ! LCOV_EXCL_LINE
     435             :          stress12_1 (nx_block,ny_block,max_blocks), & ! sigma12   ! LCOV_EXCL_LINE
     436             :          stress12_2 (nx_block,ny_block,max_blocks), & ! sigma12   ! LCOV_EXCL_LINE
     437             :          stress12_3 (nx_block,ny_block,max_blocks), & ! sigma12   ! LCOV_EXCL_LINE
     438             :          stress12_4 (nx_block,ny_block,max_blocks), & ! sigma12   ! LCOV_EXCL_LINE
     439             :          fmU        (nx_block,ny_block,max_blocks), & ! Coriolis param. * mass in U-cell (kg/s)   ! LCOV_EXCL_LINE
     440             :          TbU        (nx_block,ny_block,max_blocks), & ! factor for seabed stress (landfast ice)   ! LCOV_EXCL_LINE
     441             :          zlvl       (nx_block,ny_block,max_blocks), & ! atm level height (momentum) (m)   ! LCOV_EXCL_LINE
     442             :          zlvs       (nx_block,ny_block,max_blocks), & ! atm level height (scalar quantities) (m)   ! LCOV_EXCL_LINE
     443             :          uatm       (nx_block,ny_block,max_blocks), & ! wind velocity components (m/s)   ! LCOV_EXCL_LINE
     444             :          vatm       (nx_block,ny_block,max_blocks), &   ! LCOV_EXCL_LINE
     445             :          wind       (nx_block,ny_block,max_blocks), & ! wind speed (m/s)   ! LCOV_EXCL_LINE
     446             :          potT       (nx_block,ny_block,max_blocks), & ! air potential temperature  (K)   ! LCOV_EXCL_LINE
     447             :          Tair       (nx_block,ny_block,max_blocks), & ! air temperature  (K)   ! LCOV_EXCL_LINE
     448             :          Qa         (nx_block,ny_block,max_blocks), & ! specific humidity (kg/kg)   ! LCOV_EXCL_LINE
     449             :          rhoa       (nx_block,ny_block,max_blocks), & ! air density (kg/m^3)   ! LCOV_EXCL_LINE
     450             :          swvdr      (nx_block,ny_block,max_blocks), & ! sw down, visible, direct  (W/m^2)   ! LCOV_EXCL_LINE
     451             :          swvdf      (nx_block,ny_block,max_blocks), & ! sw down, visible, diffuse (W/m^2)   ! LCOV_EXCL_LINE
     452             :          swidr      (nx_block,ny_block,max_blocks), & ! sw down, near IR, direct  (W/m^2)   ! LCOV_EXCL_LINE
     453             :          swidf      (nx_block,ny_block,max_blocks), & ! sw down, near IR, diffuse (W/m^2)   ! LCOV_EXCL_LINE
     454             :          flw        (nx_block,ny_block,max_blocks), & ! incoming longwave radiation (W/m^2)   ! LCOV_EXCL_LINE
     455             :          frain      (nx_block,ny_block,max_blocks), & ! rainfall rate (kg/m^2 s)   ! LCOV_EXCL_LINE
     456             :          fsnow      (nx_block,ny_block,max_blocks), & ! snowfall rate (kg/m^2 s)   ! LCOV_EXCL_LINE
     457             :          sss        (nx_block,ny_block,max_blocks), & ! sea surface salinity (ppt)   ! LCOV_EXCL_LINE
     458             :          sst        (nx_block,ny_block,max_blocks), & ! sea surface temperature (C)   ! LCOV_EXCL_LINE
     459             :          frzmlt     (nx_block,ny_block,max_blocks), & ! freezing/melting potential (W/m^2)   ! LCOV_EXCL_LINE
     460             :          frzmlt_init(nx_block,ny_block,max_blocks), & ! frzmlt used in current time step (W/m^2)   ! LCOV_EXCL_LINE
     461             :          Tf         (nx_block,ny_block,max_blocks), & ! freezing temperature (C)   ! LCOV_EXCL_LINE
     462             :          qdp        (nx_block,ny_block,max_blocks), & ! deep ocean heat flux (W/m^2), negative upward   ! LCOV_EXCL_LINE
     463             :          hmix       (nx_block,ny_block,max_blocks), & ! mixed layer depth (m)   ! LCOV_EXCL_LINE
     464             :          daice_da   (nx_block,ny_block,max_blocks), & ! data assimilation concentration increment rate (concentration s-1)   ! LCOV_EXCL_LINE
     465             :                                                       ! (only used in hadgem drivers)
     466             :          fsens      (nx_block,ny_block,max_blocks), & ! sensible heat flux (W/m^2)
     467             :          flat       (nx_block,ny_block,max_blocks), & ! latent heat flux   (W/m^2)   ! LCOV_EXCL_LINE
     468             :          fswabs     (nx_block,ny_block,max_blocks), & ! shortwave flux absorbed in ice and ocean (W/m^2)   ! LCOV_EXCL_LINE
     469             :          fswint_ai  (nx_block,ny_block,max_blocks), & ! SW absorbed in ice interior below surface (W/m^2)   ! LCOV_EXCL_LINE
     470             :          flwout     (nx_block,ny_block,max_blocks), & ! outgoing longwave radiation (W/m^2)   ! LCOV_EXCL_LINE
     471             :          Tref       (nx_block,ny_block,max_blocks), & ! 2m atm reference temperature (K)   ! LCOV_EXCL_LINE
     472             :          Qref       (nx_block,ny_block,max_blocks), & ! 2m atm reference spec humidity (kg/kg)   ! LCOV_EXCL_LINE
     473             :          Uref       (nx_block,ny_block,max_blocks), & ! 10m atm reference wind speed (m/s)   ! LCOV_EXCL_LINE
     474             :          evap       (nx_block,ny_block,max_blocks), & ! evaporative water flux (kg/m^2/s)   ! LCOV_EXCL_LINE
     475             :          evaps      (nx_block,ny_block,max_blocks), & ! evaporative water flux over snow (kg/m^2/s)   ! LCOV_EXCL_LINE
     476             :          evapi      (nx_block,ny_block,max_blocks), & ! evaporative water flux over ice (kg/m^2/s)   ! LCOV_EXCL_LINE
     477             :          alvdr      (nx_block,ny_block,max_blocks), & ! visible, direct   (fraction)   ! LCOV_EXCL_LINE
     478             :          alidr      (nx_block,ny_block,max_blocks), & ! near-ir, direct   (fraction)   ! LCOV_EXCL_LINE
     479             :          alvdf      (nx_block,ny_block,max_blocks), & ! visible, diffuse  (fraction)   ! LCOV_EXCL_LINE
     480             :          alidf      (nx_block,ny_block,max_blocks), & ! near-ir, diffuse  (fraction)   ! LCOV_EXCL_LINE
     481             :          alvdr_ai   (nx_block,ny_block,max_blocks), & ! visible, direct   (fraction)   ! LCOV_EXCL_LINE
     482             :          alidr_ai   (nx_block,ny_block,max_blocks), & ! near-ir, direct   (fraction)   ! LCOV_EXCL_LINE
     483             :          alvdf_ai   (nx_block,ny_block,max_blocks), & ! visible, diffuse  (fraction)   ! LCOV_EXCL_LINE
     484             :          alidf_ai   (nx_block,ny_block,max_blocks), & ! near-ir, diffuse  (fraction)   ! LCOV_EXCL_LINE
     485             :          albice     (nx_block,ny_block,max_blocks), & ! bare ice albedo   ! LCOV_EXCL_LINE
     486             :          albsno     (nx_block,ny_block,max_blocks), & ! snow albedo   ! LCOV_EXCL_LINE
     487             :          albpnd     (nx_block,ny_block,max_blocks), & ! melt pond albedo   ! LCOV_EXCL_LINE
     488             :          apeff_ai   (nx_block,ny_block,max_blocks), & ! effective pond area used for radiation calculation   ! LCOV_EXCL_LINE
     489             :          snowfrac   (nx_block,ny_block,max_blocks), & ! snow fraction used in radiation   ! LCOV_EXCL_LINE
     490             :          alvdr_init (nx_block,ny_block,max_blocks), & ! visible, direct   (fraction)   ! LCOV_EXCL_LINE
     491             :          alidr_init (nx_block,ny_block,max_blocks), & ! near-ir, direct   (fraction)   ! LCOV_EXCL_LINE
     492             :          alvdf_init (nx_block,ny_block,max_blocks), & ! visible, diffuse  (fraction)   ! LCOV_EXCL_LINE
     493             :          alidf_init (nx_block,ny_block,max_blocks), & ! near-ir, diffuse  (fraction)   ! LCOV_EXCL_LINE
     494             :          fpond      (nx_block,ny_block,max_blocks), & ! fresh water flux to ponds (kg/m^2/s)   ! LCOV_EXCL_LINE
     495             :          fresh      (nx_block,ny_block,max_blocks), & ! fresh water flux to ocean (kg/m^2/s)   ! LCOV_EXCL_LINE
     496             :          fsalt      (nx_block,ny_block,max_blocks), & ! salt flux to ocean (kg/m^2/s)   ! LCOV_EXCL_LINE
     497             :          fhocn      (nx_block,ny_block,max_blocks), & ! net heat flux to ocean (W/m^2)   ! LCOV_EXCL_LINE
     498             :          fsloss     (nx_block,ny_block,max_blocks), & ! rate of snow loss to leads (kg/m^2/s)   ! LCOV_EXCL_LINE
     499             :          fswthru    (nx_block,ny_block,max_blocks), & ! shortwave penetrating to ocean (W/m^2)   ! LCOV_EXCL_LINE
     500             :          fswthru_vdr (nx_block,ny_block,max_blocks), & ! vis dir shortwave penetrating to ocean (W/m^2)   ! LCOV_EXCL_LINE
     501             :          fswthru_vdf (nx_block,ny_block,max_blocks), & ! vis dif shortwave penetrating to ocean (W/m^2)   ! LCOV_EXCL_LINE
     502             :          fswthru_idr (nx_block,ny_block,max_blocks), & ! nir dir shortwave penetrating to ocean (W/m^2)   ! LCOV_EXCL_LINE
     503             :          fswthru_idf (nx_block,ny_block,max_blocks), & ! nir dif shortwave penetrating to ocean (W/m^2)   ! LCOV_EXCL_LINE
     504             :          scale_factor (nx_block,ny_block,max_blocks), & ! scaling factor for shortwave components   ! LCOV_EXCL_LINE
     505             :          strairx_ocn(nx_block,ny_block,max_blocks), & ! stress on ocean by air, x-direction   ! LCOV_EXCL_LINE
     506             :          strairy_ocn(nx_block,ny_block,max_blocks), & ! stress on ocean by air, y-direction   ! LCOV_EXCL_LINE
     507             :          fsens_ocn  (nx_block,ny_block,max_blocks), & ! sensible heat flux (W/m^2)   ! LCOV_EXCL_LINE
     508             :          flat_ocn   (nx_block,ny_block,max_blocks), & ! latent heat flux   (W/m^2)   ! LCOV_EXCL_LINE
     509             :          flwout_ocn (nx_block,ny_block,max_blocks), & ! outgoing longwave radiation (W/m^2)   ! LCOV_EXCL_LINE
     510             :          evap_ocn   (nx_block,ny_block,max_blocks), & ! evaporative water flux (kg/m^2/s)   ! LCOV_EXCL_LINE
     511             :          alvdr_ocn  (nx_block,ny_block,max_blocks), & ! visible, direct   (fraction)   ! LCOV_EXCL_LINE
     512             :          alidr_ocn  (nx_block,ny_block,max_blocks), & ! near-ir, direct   (fraction)   ! LCOV_EXCL_LINE
     513             :          alvdf_ocn  (nx_block,ny_block,max_blocks), & ! visible, diffuse  (fraction)   ! LCOV_EXCL_LINE
     514             :          alidf_ocn  (nx_block,ny_block,max_blocks), & ! near-ir, diffuse  (fraction)   ! LCOV_EXCL_LINE
     515             :          Tref_ocn   (nx_block,ny_block,max_blocks), & ! 2m atm reference temperature (K)   ! LCOV_EXCL_LINE
     516             :          Qref_ocn   (nx_block,ny_block,max_blocks), & ! 2m atm reference spec humidity (kg/kg)   ! LCOV_EXCL_LINE
     517             :          fsurf      (nx_block,ny_block,max_blocks), & ! net surface heat flux (excluding fcondtop)(W/m^2)   ! LCOV_EXCL_LINE
     518             :          fcondtop   (nx_block,ny_block,max_blocks), & ! top surface conductive flux (W/m^2)   ! LCOV_EXCL_LINE
     519             :          fcondbot   (nx_block,ny_block,max_blocks), & ! bottom surface conductive flux (W/m^2)   ! LCOV_EXCL_LINE
     520             :          fbot       (nx_block,ny_block,max_blocks), & ! heat flux at bottom surface of ice (excluding excess) (W/m^2)   ! LCOV_EXCL_LINE
     521             :          Tbot       (nx_block,ny_block,max_blocks), & ! temperature at bottom surface of ice (deg C)   ! LCOV_EXCL_LINE
     522             :          Tsnice     (nx_block,ny_block,max_blocks), & ! temperature at snow ice interface (deg C)   ! LCOV_EXCL_LINE
     523             :          congel     (nx_block,ny_block,max_blocks), & ! basal ice growth         (m/step-->cm/day)   ! LCOV_EXCL_LINE
     524             :          frazil     (nx_block,ny_block,max_blocks), & ! frazil ice growth        (m/step-->cm/day)   ! LCOV_EXCL_LINE
     525             :          snoice     (nx_block,ny_block,max_blocks), & ! snow-ice formation       (m/step-->cm/day)   ! LCOV_EXCL_LINE
     526             :          meltt      (nx_block,ny_block,max_blocks), & ! top ice melt             (m/step-->cm/day)   ! LCOV_EXCL_LINE
     527             :          melts      (nx_block,ny_block,max_blocks), & ! snow melt                (m/step-->cm/day)   ! LCOV_EXCL_LINE
     528             :          meltb      (nx_block,ny_block,max_blocks), & ! basal ice melt           (m/step-->cm/day)   ! LCOV_EXCL_LINE
     529             :          meltl      (nx_block,ny_block,max_blocks), & ! lateral ice melt         (m/step-->cm/day)   ! LCOV_EXCL_LINE
     530             :          dsnow      (nx_block,ny_block,max_blocks), & ! change in snow thickness (m/step-->cm/day)   ! LCOV_EXCL_LINE
     531             :          daidtt     (nx_block,ny_block,max_blocks), & ! ice area tendency thermo.   (s^-1)   ! LCOV_EXCL_LINE
     532             :          dvidtt     (nx_block,ny_block,max_blocks), & ! ice volume tendency thermo. (m/s)   ! LCOV_EXCL_LINE
     533             :          dagedtt    (nx_block,ny_block,max_blocks), & ! ice age tendency thermo.    (s/s)   ! LCOV_EXCL_LINE
     534             :          mlt_onset  (nx_block,ny_block,max_blocks), & ! day of year that sfc melting begins   ! LCOV_EXCL_LINE
     535             :          frz_onset  (nx_block,ny_block,max_blocks), & ! day of year that freezing begins (congel or frazil)   ! LCOV_EXCL_LINE
     536             :          frazil_diag(nx_block,ny_block,max_blocks), & ! frazil ice growth diagnostic (m/step-->cm/day)   ! LCOV_EXCL_LINE
     537             :          fresh_ai   (nx_block,ny_block,max_blocks), & ! fresh water flux to ocean (kg/m^2/s)   ! LCOV_EXCL_LINE
     538             :          fsalt_ai   (nx_block,ny_block,max_blocks), & ! salt flux to ocean (kg/m^2/s)   ! LCOV_EXCL_LINE
     539             :          fhocn_ai   (nx_block,ny_block,max_blocks), & ! net heat flux to ocean (W/m^2)   ! LCOV_EXCL_LINE
     540             :          fswthru_ai (nx_block,ny_block,max_blocks), &  ! shortwave penetrating to ocean (W/m^2)   ! LCOV_EXCL_LINE
     541             :          fresh_da   (nx_block,ny_block,max_blocks), & ! fresh water flux to ocean due to data assim (kg/m^2/s)   ! LCOV_EXCL_LINE
     542             :          fsalt_da   (nx_block,ny_block,max_blocks), & ! salt flux to ocean due to data assimilation(kg/m^2/s)   ! LCOV_EXCL_LINE
     543             :          uatmT      (nx_block,ny_block,max_blocks), & ! uatm on T grid   ! LCOV_EXCL_LINE
     544             :          vatmT      (nx_block,ny_block,max_blocks), & ! vatm on T grid   ! LCOV_EXCL_LINE
     545             :          rside      (nx_block,ny_block,max_blocks), & ! fraction of ice that melts laterally   ! LCOV_EXCL_LINE
     546             :          fside      (nx_block,ny_block,max_blocks), & ! lateral melt flux (W/m^2)   ! LCOV_EXCL_LINE
     547             :          wlat       (nx_block,ny_block,max_blocks), & ! lateral melt rate (m/s)   ! LCOV_EXCL_LINE
     548             :          fsw        (nx_block,ny_block,max_blocks), & ! incoming shortwave radiation (W/m^2)   ! LCOV_EXCL_LINE
     549             :          coszen     (nx_block,ny_block,max_blocks), & ! cosine solar zenith angle, < 0 for sun below horizon   ! LCOV_EXCL_LINE
     550             :          rdg_conv   (nx_block,ny_block,max_blocks), & ! convergence term for ridging (1/s)   ! LCOV_EXCL_LINE
     551             :          rdg_shear  (nx_block,ny_block,max_blocks), & ! shear term for ridging (1/s)   ! LCOV_EXCL_LINE
     552             :          dardg1ndt  (nx_block,ny_block,ncat,max_blocks), & ! rate of area loss by ridging ice (1/s)   ! LCOV_EXCL_LINE
     553             :          dardg2ndt  (nx_block,ny_block,ncat,max_blocks), & ! rate of area gain by new ridges (1/s)   ! LCOV_EXCL_LINE
     554             :          dvirdgndt  (nx_block,ny_block,ncat,max_blocks), & ! rate of ice volume ridged (m/s)   ! LCOV_EXCL_LINE
     555             :          aparticn   (nx_block,ny_block,ncat,max_blocks), & ! participation function   ! LCOV_EXCL_LINE
     556             :          krdgn      (nx_block,ny_block,ncat,max_blocks), & ! mean ridge thickness/thickness of ridging ice   ! LCOV_EXCL_LINE
     557             :          ardgn      (nx_block,ny_block,ncat,max_blocks), & ! fractional area of ridged ice   ! LCOV_EXCL_LINE
     558             :          vrdgn      (nx_block,ny_block,ncat,max_blocks), & ! volume of ridged ice   ! LCOV_EXCL_LINE
     559             :          araftn     (nx_block,ny_block,ncat,max_blocks), & ! rafting ice area   ! LCOV_EXCL_LINE
     560             :          vraftn     (nx_block,ny_block,ncat,max_blocks), & ! rafting ice volume   ! LCOV_EXCL_LINE
     561             :          aredistn   (nx_block,ny_block,ncat,max_blocks), & ! redistribution function: fraction of new ridge area   ! LCOV_EXCL_LINE
     562             :          vredistn   (nx_block,ny_block,ncat,max_blocks), & ! redistribution function: fraction of new ridge volume   ! LCOV_EXCL_LINE
     563             :          fsurfn_f   (nx_block,ny_block,ncat,max_blocks), & ! net flux to top surface, excluding fcondtop   ! LCOV_EXCL_LINE
     564             :          fcondtopn_f(nx_block,ny_block,ncat,max_blocks), & ! downward cond flux at top surface (W m-2)   ! LCOV_EXCL_LINE
     565             :          fsensn_f   (nx_block,ny_block,ncat,max_blocks), & ! sensible heat flux (W m-2)   ! LCOV_EXCL_LINE
     566             :          flatn_f    (nx_block,ny_block,ncat,max_blocks), & ! latent heat flux (W m-2)   ! LCOV_EXCL_LINE
     567             :          meltsn     (nx_block,ny_block,ncat,max_blocks), & ! snow melt in category n (m)   ! LCOV_EXCL_LINE
     568             :          melttn     (nx_block,ny_block,ncat,max_blocks), & ! top melt in category n (m)   ! LCOV_EXCL_LINE
     569             :          meltbn     (nx_block,ny_block,ncat,max_blocks), & ! bottom melt in category n (m)   ! LCOV_EXCL_LINE
     570             :          congeln    (nx_block,ny_block,ncat,max_blocks), & ! congelation ice formation in category n (m)   ! LCOV_EXCL_LINE
     571             :          snoicen    (nx_block,ny_block,ncat,max_blocks), & ! snow-ice formation in category n (m)   ! LCOV_EXCL_LINE
     572             :          keffn_top  (nx_block,ny_block,ncat,max_blocks), & ! effective thermal conductivity of the top ice layer   ! LCOV_EXCL_LINE
     573             :          fsurfn     (nx_block,ny_block,ncat,max_blocks), & ! category fsurf   ! LCOV_EXCL_LINE
     574             :          fcondtopn  (nx_block,ny_block,ncat,max_blocks), & ! category fcondtop   ! LCOV_EXCL_LINE
     575             :          fcondbotn  (nx_block,ny_block,ncat,max_blocks), & ! category fcondbot   ! LCOV_EXCL_LINE
     576             :          fsensn     (nx_block,ny_block,ncat,max_blocks), & ! category sensible heat flux   ! LCOV_EXCL_LINE
     577             :          flatn      (nx_block,ny_block,ncat,max_blocks), & ! category latent heat flux   ! LCOV_EXCL_LINE
     578             :          albcnt     (nx_block,ny_block,max_blocks,max_nstrm), & ! counter for zenith angle   ! LCOV_EXCL_LINE
     579             :          snwcnt     (nx_block,ny_block,max_blocks,max_nstrm), & ! counter for snow   ! LCOV_EXCL_LINE
     580             :          salinz     (nx_block,ny_block,nilyr+1,max_blocks), & ! initial salinity  profile (ppt)   ! LCOV_EXCL_LINE
     581             :          Tmltz      (nx_block,ny_block,nilyr+1,max_blocks), & ! initial melting temperature (^oC)   ! LCOV_EXCL_LINE
     582          37 :          stat=ierr)
     583          37 :       if (ierr/=0) call abort_ice('(alloc_flux): Out of memory')
     584             : 
     585          37 :       if (grid_ice == "CD" .or. grid_ice == "C") &
     586             :          allocate( &   ! LCOV_EXCL_LINE
     587             :          taubxN     (nx_block,ny_block,max_blocks), & ! seabed stress (x) at N points (N/m^2)   ! LCOV_EXCL_LINE
     588             :          taubyN     (nx_block,ny_block,max_blocks), & ! seabed stress (y) at N points (N/m^2)   ! LCOV_EXCL_LINE
     589             :          strairxN   (nx_block,ny_block,max_blocks), & ! stress on ice by air, x-direction at N points   ! LCOV_EXCL_LINE
     590             :          strairyN   (nx_block,ny_block,max_blocks), & ! stress on ice by air, y-direction at N points   ! LCOV_EXCL_LINE
     591             :          strocnxN   (nx_block,ny_block,max_blocks), & ! ice-ocean stress, x-direction at N points   ! LCOV_EXCL_LINE
     592             :          strocnyN   (nx_block,ny_block,max_blocks), & ! ice-ocean stress, y-direction at N points   ! LCOV_EXCL_LINE
     593             :          strtltxN   (nx_block,ny_block,max_blocks), & ! stress due to sea surface slope, x-direction at N points   ! LCOV_EXCL_LINE
     594             :          strtltyN   (nx_block,ny_block,max_blocks), & ! stress due to sea surface slope, y-direction at N points   ! LCOV_EXCL_LINE
     595             :          strintxN   (nx_block,ny_block,max_blocks), & ! divergence of internal ice stress, x at N points (N/m^2)   ! LCOV_EXCL_LINE
     596             :          strintyN   (nx_block,ny_block,max_blocks), & ! divergence of internal ice stress, y at N points (N/m^2)   ! LCOV_EXCL_LINE
     597             :          fmN        (nx_block,ny_block,max_blocks), & ! Coriolis param. * mass in N-cell (kg/s)   ! LCOV_EXCL_LINE
     598             :          TbN        (nx_block,ny_block,max_blocks), & ! factor for seabed stress (landfast ice)   ! LCOV_EXCL_LINE
     599             :          taubxE     (nx_block,ny_block,max_blocks), & ! seabed stress (x) at E points (N/m^2)   ! LCOV_EXCL_LINE
     600             :          taubyE     (nx_block,ny_block,max_blocks), & ! seabed stress (y) at E points (N/m^2)   ! LCOV_EXCL_LINE
     601             :          strairxE   (nx_block,ny_block,max_blocks), & ! stress on ice by air, x-direction at E points   ! LCOV_EXCL_LINE
     602             :          strairyE   (nx_block,ny_block,max_blocks), & ! stress on ice by air, y-direction at E points   ! LCOV_EXCL_LINE
     603             :          strocnxE   (nx_block,ny_block,max_blocks), & ! ice-ocean stress, x-direction at E points   ! LCOV_EXCL_LINE
     604             :          strocnyE   (nx_block,ny_block,max_blocks), & ! ice-ocean stress, y-direction at E points   ! LCOV_EXCL_LINE
     605             :          strtltxE   (nx_block,ny_block,max_blocks), & ! stress due to sea surface slope, x-direction at E points   ! LCOV_EXCL_LINE
     606             :          strtltyE   (nx_block,ny_block,max_blocks), & ! stress due to sea surface slope, y-direction at E points   ! LCOV_EXCL_LINE
     607             :          strintxE   (nx_block,ny_block,max_blocks), & ! divergence of internal ice stress, x at E points (N/m^2)   ! LCOV_EXCL_LINE
     608             :          strintyE   (nx_block,ny_block,max_blocks), & ! divergence of internal ice stress, y at E points (N/m^2)   ! LCOV_EXCL_LINE
     609             :          fmE        (nx_block,ny_block,max_blocks), & ! Coriolis param. * mass in E-cell (kg/s)   ! LCOV_EXCL_LINE
     610             :          TbE        (nx_block,ny_block,max_blocks), & ! factor for seabed stress (landfast ice)   ! LCOV_EXCL_LINE
     611             :          stresspT   (nx_block,ny_block,max_blocks), & ! sigma11+sigma22   ! LCOV_EXCL_LINE
     612             :          stressmT   (nx_block,ny_block,max_blocks), & ! sigma11-sigma22   ! LCOV_EXCL_LINE
     613             :          stress12T  (nx_block,ny_block,max_blocks), & ! sigma12   ! LCOV_EXCL_LINE
     614             :          stresspU   (nx_block,ny_block,max_blocks), & ! sigma11+sigma22   ! LCOV_EXCL_LINE
     615             :          stressmU   (nx_block,ny_block,max_blocks), & ! sigma11-sigma22   ! LCOV_EXCL_LINE
     616             :          stress12U  (nx_block,ny_block,max_blocks), & ! sigma12   ! LCOV_EXCL_LINE
     617           0 :          stat=ierr)
     618          37 :       if (ierr/=0) call abort_ice('(alloc_flux): Out of memory')
     619             : 
     620          37 :       end subroutine alloc_flux
     621             : 
     622             : !=======================================================================
     623             : 
     624             : ! Initialize all fluxes exchanged with flux coupler
     625             : ! and some data-derived fields
     626             : !
     627             : ! author Elizabeth C. Hunke, LANL
     628             : 
     629          37 :       subroutine init_coupler_flux
     630             : 
     631             :       use ice_arrays_column, only: Cdn_atm
     632             :       use ice_flux_bgc, only: flux_bio_atm, flux_bio, faero_atm, fiso_atm, &
     633             :            fnit, famm, fsil, fdmsp, fdms, fhum, fdust, falgalN, &   ! LCOV_EXCL_LINE
     634             :            fdoc, fdon, fdic, ffed, ffep
     635             :       use ice_grid, only: bathymetry
     636             : 
     637             :       integer (kind=int_kind) :: n
     638             : 
     639             :       integer (kind=int_kind), parameter :: max_d = 6
     640             :       real (kind=dbl_kind) :: fcondtopn_d(max_d), fsurfn_d(max_d)
     641           8 :       real (kind=dbl_kind) :: stefan_boltzmann, Tffresh
     642           8 :       real (kind=dbl_kind) :: vonkar, zref, iceruf
     643             : 
     644             :       integer :: i, j, iblk
     645             : 
     646             :       character(len=*), parameter :: subname = '(init_coupler_flux)'
     647             : 
     648             :       data fcondtopn_d / -50.0_dbl_kind,-17.0_dbl_kind,-12.0_dbl_kind, &
     649             :                           -9.0_dbl_kind, -7.0_dbl_kind, -3.0_dbl_kind /
     650             :       data fsurfn_d    /  0.20_dbl_kind, 0.15_dbl_kind, 0.10_dbl_kind, &
     651             :                           0.05_dbl_kind, 0.01_dbl_kind, 0.01_dbl_kind /
     652             : 
     653             :       call icepack_query_parameters(stefan_boltzmann_out=stefan_boltzmann, &
     654          37 :          Tffresh_out=Tffresh, vonkar_out=vonkar, zref_out=zref, iceruf_out=iceruf)
     655          37 :       call icepack_warnings_flush(nu_diag)
     656          37 :       if (icepack_warnings_aborted()) call abort_ice(error_message=subname, &
     657           0 :          file=__FILE__, line=__LINE__)
     658             : 
     659             :       !-----------------------------------------------------------------
     660             :       ! fluxes received from atmosphere
     661             :       !-----------------------------------------------------------------
     662      111936 :       zlvl  (:,:,:) = c10             ! atm level height (momentum) (m)
     663      111936 :       zlvs  (:,:,:) = c10             ! atm level height (scalar quantities) (m)
     664      111936 :       rhoa  (:,:,:) = 1.3_dbl_kind    ! air density (kg/m^3)
     665      111936 :       uatm  (:,:,:) = c5              ! wind velocity    (m/s)
     666      111936 :       vatm  (:,:,:) = c5
     667      111936 :       strax (:,:,:) = 0.05_dbl_kind
     668      111936 :       stray (:,:,:) = 0.05_dbl_kind
     669      111936 :       fsnow (:,:,:) = c0              ! snowfall rate (kg/m2/s)
     670             :                                       ! fsnow must be 0 for exact restarts
     671          37 :       if (trim(default_season) == 'winter') then
     672             :          ! typical winter values
     673      111936 :          potT  (:,:,:) = 253.0_dbl_kind  ! air potential temp (K)
     674      111936 :          Tair  (:,:,:) = 253.0_dbl_kind  ! air temperature  (K)
     675      111936 :          Qa    (:,:,:) = 0.0006_dbl_kind ! specific humidity (kg/kg)
     676      111936 :          swvdr (:,:,:) = c0              ! shortwave radiation (W/m^2)
     677      111936 :          swvdf (:,:,:) = c0              ! shortwave radiation (W/m^2)
     678      111936 :          swidr (:,:,:) = c0              ! shortwave radiation (W/m^2)
     679      111936 :          swidf (:,:,:) = c0              ! shortwave radiation (W/m^2)
     680      111936 :          flw   (:,:,:) = c180            ! incoming longwave rad (W/m^2)
     681      111936 :          frain (:,:,:) = c0              ! rainfall rate (kg/m2/s)
     682         222 :          do n = 1, ncat              ! conductive heat flux (W/m^2)
     683      559717 :             fcondtopn_f(:,:,n,:) = fcondtopn_d(min(n,max_d))
     684             :          enddo
     685      559730 :          fsurfn_f = fcondtopn_f      ! surface heat flux (W/m^2)
     686      559693 :          flatn_f (:,:,:,:) = c0          ! latent heat flux (kg/m2/s)
     687      559693 :          fsensn_f(:,:,:,:) = c0          ! sensible heat flux (W/m^2)
     688           0 :       elseif (trim(default_season) == 'summer') then
     689             :          ! typical summer values
     690           0 :          potT  (:,:,:) = 273.0_dbl_kind  ! air potential temp (K)
     691           0 :          Tair  (:,:,:) = 273.0_dbl_kind  ! air temperature  (K)
     692           0 :          Qa    (:,:,:) = 0.0035_dbl_kind ! specific humidity (kg/kg)
     693           0 :          swvdr (:,:,:) = 50._dbl_kind    ! shortwave radiation (W/m^2)
     694           0 :          swvdf (:,:,:) = 50._dbl_kind    ! shortwave radiation (W/m^2)
     695           0 :          swidr (:,:,:) = 50._dbl_kind    ! shortwave radiation (W/m^2)
     696           0 :          swidf (:,:,:) = 50._dbl_kind    ! shortwave radiation (W/m^2)
     697           0 :          flw   (:,:,:) = 280.0_dbl_kind  ! incoming longwave rad (W/m^2)
     698           0 :          frain (:,:,:) = c0              ! rainfall rate (kg/m2/s)
     699           0 :          do n = 1, ncat                   ! surface heat flux (W/m^2)
     700           0 :             fsurfn_f(:,:,n,:) = fsurfn_d(min(n,max_d))
     701             :          enddo
     702           0 :          fcondtopn_f(:,:,:,:) =  0.0_dbl_kind ! conductive heat flux (W/m^2)
     703           0 :          flatn_f    (:,:,:,:) = -2.0_dbl_kind ! latent heat flux (W/m^2)
     704           0 :          fsensn_f   (:,:,:,:) =  c0           ! sensible heat flux (W/m^2)
     705             :       else
     706             :          ! typical spring values
     707           0 :          potT  (:,:,:) = 263.15_dbl_kind ! air potential temp (K)
     708           0 :          Tair  (:,:,:) = 263.15_dbl_kind ! air temperature  (K)
     709           0 :          Qa    (:,:,:) = 0.001_dbl_kind  ! specific humidity (kg/kg)
     710           0 :          swvdr (:,:,:) = 25._dbl_kind    ! shortwave radiation (W/m^2)
     711           0 :          swvdf (:,:,:) = 25._dbl_kind    ! shortwave radiation (W/m^2)
     712           0 :          swidr (:,:,:) = 25._dbl_kind    ! shortwave radiation (W/m^2)
     713           0 :          swidf (:,:,:) = 25._dbl_kind    ! shortwave radiation (W/m^2)
     714           0 :          flw   (:,:,:) = 230.0_dbl_kind  ! incoming longwave rad (W/m^2)
     715           0 :          frain (:,:,:) = c0              ! rainfall rate (kg/m2/s)
     716           0 :          do n = 1, ncat                   ! surface heat flux (W/m^2)
     717           0 :             fsurfn_f(:,:,n,:) = fsurfn_d(min(n,max_d))
     718             :          enddo
     719           0 :          fcondtopn_f(:,:,:,:) =  c0           ! conductive heat flux (W/m^2)
     720           0 :          flatn_f    (:,:,:,:) = -1.0_dbl_kind ! latent heat flux (W/m^2)
     721           0 :          fsensn_f   (:,:,:,:) =  c0           ! sensible heat flux (W/m^2)
     722             :       endif !
     723             : 
     724      335895 :       fiso_atm  (:,:,:,:) = c0           ! isotope deposition rate (kg/m2/s)
     725      671592 :       faero_atm (:,:,:,:) = c0           ! aerosol deposition rate (kg/m2/s)
     726     3245269 :       flux_bio_atm (:,:,:,:) = c0        ! zaero and bio deposition rate (kg/m2/s)
     727             : 
     728             :       !-----------------------------------------------------------------
     729             :       ! fluxes received from ocean
     730             :       !-----------------------------------------------------------------
     731             : 
     732      111936 :       ss_tltx (:,:,:) = c0              ! sea surface tilt (m/m)
     733      111936 :       ss_tlty (:,:,:) = c0
     734      111936 :       uocn    (:,:,:) = c0              ! surface ocean currents (m/s)
     735      111936 :       vocn    (:,:,:) = c0
     736      111936 :       frzmlt  (:,:,:) = c0              ! freezing/melting potential (W/m^2)
     737      111936 :       frzmlt_init(:,:,:) = c0           ! freezing/melting potential (W/m^2)
     738      111936 :       sss     (:,:,:) = 34.0_dbl_kind   ! sea surface salinity (ppt)
     739             : 
     740         198 :       do iblk = 1, size(Tf,3)
     741        5372 :       do j = 1, size(Tf,2)
     742      111899 :       do i = 1, size(Tf,1)
     743      111738 :          Tf (i,j,iblk) = icepack_liquidus_temperature(sss(i,j,iblk)) ! freezing temp (C)
     744             :       enddo
     745             :       enddo
     746             :       enddo
     747             : 
     748      111936 :       sst   (:,:,:) = Tf(:,:,:)       ! sea surface temp (C)
     749      111936 :       qdp   (:,:,:) = c0              ! deep ocean heat flux (W/m^2)
     750      111936 :       hmix  (:,:,:) = c20             ! ocean mixed layer depth (m)
     751      111936 :       hwater(:,:,:) = bathymetry(:,:,:) ! ocean water depth (m)
     752      111936 :       daice_da(:,:,:) = c0            ! data assimilation increment rate
     753             : 
     754             :       !-----------------------------------------------------------------
     755             :       ! fluxes sent to atmosphere
     756             :       !-----------------------------------------------------------------
     757             : 
     758      111936 :       strairxT(:,:,:) = c0            ! wind stress, T grid
     759      111936 :       strairyT(:,:,:) = c0
     760             : 
     761      111936 :       fsens   (:,:,:) = c0
     762      111936 :       flat    (:,:,:) = c0
     763      111936 :       fswabs  (:,:,:) = c0
     764      111936 :       fswint_ai(:,:,:) = c0
     765      111936 :       flwout  (:,:,:) = -stefan_boltzmann*Tffresh**4
     766             :                         ! in case atm model diagnoses Tsfc from flwout
     767      111936 :       evap    (:,:,:) = c0
     768      111936 :       evaps   (:,:,:) = c0
     769      111936 :       evapi   (:,:,:) = c0
     770      111936 :       Tref    (:,:,:) = c0
     771      111936 :       Qref    (:,:,:) = c0
     772      111936 :       Uref    (:,:,:) = c0
     773      111936 :       alvdr   (:,:,:) = c0
     774      111936 :       alidr   (:,:,:) = c0
     775      111936 :       alvdf   (:,:,:) = c0
     776      111936 :       alidf   (:,:,:) = c0
     777             : 
     778             :       !-----------------------------------------------------------------
     779             :       ! fluxes sent to ocean
     780             :       !-----------------------------------------------------------------
     781             : 
     782      111936 :       strocnxT_iavg (:,:,:) = c0 ! ice-ocean stress, x-direction (T-cell)
     783      111936 :       strocnyT_iavg (:,:,:) = c0 ! ice-ocean stress, y-direction (T-cell)
     784      111936 :       fresh   (:,:,:) = c0
     785      111936 :       fsalt   (:,:,:) = c0
     786      111936 :       fpond   (:,:,:) = c0
     787      111936 :       fhocn   (:,:,:) = c0
     788      111936 :       fswthru (:,:,:) = c0
     789      111936 :       fswthru_vdr (:,:,:) = c0
     790      111936 :       fswthru_vdf (:,:,:) = c0
     791      111936 :       fswthru_idr (:,:,:) = c0
     792      111936 :       fswthru_idf (:,:,:) = c0
     793      111936 :       fresh_da(:,:,:) = c0    ! data assimilation
     794      111936 :       fsalt_da(:,:,:) = c0
     795     3245269 :       flux_bio (:,:,:,:) = c0 ! bgc
     796      111936 :       fnit    (:,:,:) = c0
     797      111936 :       fsil    (:,:,:) = c0
     798      111936 :       famm    (:,:,:) = c0
     799      111936 :       fdmsp   (:,:,:) = c0
     800      111936 :       fdms    (:,:,:) = c0
     801      111936 :       fhum    (:,:,:) = c0
     802      111936 :       fdust   (:,:,:) = c0
     803      335895 :       falgalN(:,:,:,:)= c0
     804      335895 :       fdoc   (:,:,:,:)= c0
     805      112097 :       fdic   (:,:,:,:)= c0
     806      112097 :       fdon   (:,:,:,:)= c0
     807      223996 :       ffep   (:,:,:,:)= c0
     808      223996 :       ffed   (:,:,:,:)= c0
     809             : 
     810          37 :       allocate(fswthrun_ai(nx_block,ny_block,ncat,max_blocks))
     811      559693 :       fswthrun_ai(:,:,:,:) = c0
     812             : 
     813             :       !-----------------------------------------------------------------
     814             :       ! derived or computed fields
     815             :       !-----------------------------------------------------------------
     816             : 
     817      111936 :       coszen  (:,:,:) = c0            ! Cosine of the zenith angle
     818      111936 :       fsw     (:,:,:) = c0            ! shortwave radiation (W/m^2)
     819      111936 :       scale_factor(:,:,:) = c1        ! shortwave scaling factor
     820           0 :       wind    (:,:,:) = sqrt(uatm(:,:,:)**2 &
     821      111936 :                            + vatm(:,:,:)**2)  ! wind speed, (m/s)
     822           0 :       Cdn_atm(:,:,:) = (vonkar/log(zref/iceruf)) &
     823      111936 :                      * (vonkar/log(zref/iceruf)) ! atmo drag for RASM
     824      111936 :       alvdr_init(:,:,:) = c0
     825      111936 :       alidr_init(:,:,:) = c0
     826      111936 :       alvdf_init(:,:,:) = c0
     827      111936 :       alidf_init(:,:,:) = c0
     828             : 
     829             : 
     830          37 :       end subroutine init_coupler_flux
     831             : 
     832             : !=======================================================================
     833             : 
     834             : ! Initialize some fluxes sent to coupler for use by the atm model
     835             : !
     836             : ! author: Elizabeth C. Hunke, LANL
     837             : 
     838        5784 :       subroutine init_flux_atm
     839             : 
     840             :       use ice_flux_bgc, only: fiso_evap, Qref_iso, Qa_iso
     841             : 
     842             :       character(len=*), parameter :: subname = '(init_flux_atm)'
     843             : 
     844             :       !-----------------------------------------------------------------
     845             :       ! initialize albedo and fluxes
     846             :       !-----------------------------------------------------------------
     847             : 
     848    16221984 :       strairxT(:,:,:) = c0      ! wind stress, T grid
     849    16221984 :       strairyT(:,:,:) = c0
     850             :       ! for rectangular grid tests without thermo
     851             :       ! strairxT(:,:,:) = 0.15_dbl_kind
     852             :       ! strairyT(:,:,:) = 0.15_dbl_kind
     853             : 
     854    16221984 :       fsens   (:,:,:) = c0
     855    16221984 :       flat    (:,:,:) = c0
     856    16221984 :       fswabs  (:,:,:) = c0
     857    16221984 :       flwout  (:,:,:) = c0
     858    16221984 :       evap    (:,:,:) = c0
     859    16221984 :       Tref    (:,:,:) = c0
     860    16221984 :       Qref    (:,:,:) = c0
     861    16221984 :       Uref    (:,:,:) = c0
     862             : 
     863    48677448 :       fiso_evap(:,:,:,:) = c0
     864    48677448 :       Qref_iso (:,:,:,:) = c0
     865    48677448 :       Qa_iso   (:,:,:,:) = c0
     866             : 
     867        5784 :       end subroutine init_flux_atm
     868             : 
     869             : !=======================================================================
     870             : ! Initialize some fluxes sent to coupler for use by the ocean model
     871             : !
     872             : ! NOTE: These fluxes should be initialized immediately after the
     873             : !       call to the coupler.  The atmospheric fluxes can be initialized
     874             : !       at the beginning of the following time step because they are
     875             : !       not modified by any subroutines between the call to_coupler
     876             : !       and the end of the time step.
     877             : !
     878             : ! author: Elizabeth C. Hunke, LANL
     879             : 
     880        5784 :       subroutine init_flux_ocn
     881             : 
     882             :       use ice_flux_bgc, only: faero_ocn, fiso_ocn, HDO_ocn, H2_16O_ocn, H2_18O_ocn
     883             : 
     884             :       character(len=*), parameter :: subname = '(init_flux_ocn)'
     885             : 
     886             :       !-----------------------------------------------------------------
     887             :       ! fluxes sent
     888             :       !-----------------------------------------------------------------
     889             : 
     890    16221984 :       fresh    (:,:,:)   = c0
     891    16221984 :       fsalt    (:,:,:)   = c0
     892    16221984 :       fpond    (:,:,:)   = c0
     893    16221984 :       fhocn    (:,:,:)   = c0
     894    16221984 :       fswthru  (:,:,:)   = c0
     895    16221984 :       fswthru_vdr  (:,:,:)   = c0
     896    16221984 :       fswthru_vdf  (:,:,:)   = c0
     897    16221984 :       fswthru_idr  (:,:,:)   = c0
     898    16221984 :       fswthru_idf  (:,:,:)   = c0
     899             : 
     900    97326048 :       faero_ocn (:,:,:,:) = c0
     901    48677448 :       fiso_ocn  (:,:,:,:) = c0
     902    16221984 :       HDO_ocn     (:,:,:) = c0
     903    16221984 :       H2_16O_ocn  (:,:,:) = c0
     904    16221984 :       H2_18O_ocn  (:,:,:) = c0
     905             : 
     906        5784 :       if (send_i2x_per_cat) then
     907           0 :          fswthrun_ai(:,:,:,:) = c0
     908             :       endif
     909             : 
     910        5784 :       end subroutine init_flux_ocn
     911             : 
     912             : !=======================================================================
     913             : 
     914             : ! Initialize thermodynamic fields written to history files.
     915             : !
     916             : ! authors: William H. Lipscomb, LANL
     917             : !          Elizabeth C. Hunke, LANL
     918             : 
     919        5821 :       subroutine init_history_therm
     920             : 
     921             :       use ice_state, only: aice, vice, trcr
     922             :       use ice_arrays_column, only: &
     923             :           hfreebd, hdraft, hridge, distrdg, hkeel, dkeel, lfloe, dfloe, &   ! LCOV_EXCL_LINE
     924             :           Cdn_atm_skin, Cdn_atm_floe, Cdn_atm_pond, Cdn_atm_rdg, &   ! LCOV_EXCL_LINE
     925             :           Cdn_ocn_skin, Cdn_ocn_floe, Cdn_ocn_keel, Cdn_atm_ratio, &   ! LCOV_EXCL_LINE
     926             :           Cdn_atm, Cdn_ocn
     927             : 
     928             :       logical (kind=log_kind) :: &
     929             :           formdrag, &   ! LCOV_EXCL_LINE
     930             :           tr_iage
     931             : 
     932             :       integer (kind=int_kind) :: &
     933             :           nt_iage
     934             : 
     935             :       real (kind=dbl_kind) :: &
     936             :           dragio, &   ! LCOV_EXCL_LINE
     937             :           vonkar, &   ! LCOV_EXCL_LINE
     938             :           zref, &   ! LCOV_EXCL_LINE
     939        1448 :           iceruf
     940             : 
     941             :       character(len=*), parameter :: subname = '(init_history_therm)'
     942             : 
     943        5821 :       call icepack_query_parameters(formdrag_out=formdrag)
     944        5821 :       call icepack_query_tracer_flags(tr_iage_out=tr_iage)
     945        5821 :       call icepack_query_tracer_indices(nt_iage_out=nt_iage)
     946             :       call icepack_query_parameters( dragio_out=dragio, &
     947        5821 :          vonkar_out=vonkar, zref_out=zref, iceruf_out=iceruf)
     948        5821 :       call icepack_warnings_flush(nu_diag)
     949        5821 :       if (icepack_warnings_aborted()) call abort_ice(error_message=subname, &
     950           0 :          file=__FILE__, line=__LINE__)
     951             : 
     952    16333920 :       fsurf  (:,:,:) = c0
     953    16333920 :       fcondtop(:,:,:)= c0
     954    16333920 :       fcondbot(:,:,:)= c0
     955    16333920 :       congel (:,:,:) = c0
     956    16333920 :       fbot   (:,:,:) = c0
     957    16333920 :       Tbot   (:,:,:) = c0
     958    16333920 :       Tsnice  (:,:,:) = c0
     959    16333920 :       frazil (:,:,:) = c0
     960    16333920 :       snoice (:,:,:) = c0
     961    16333920 :       dsnow  (:,:,:) = c0
     962    16333920 :       meltt  (:,:,:) = c0
     963    16333920 :       melts  (:,:,:) = c0
     964    16333920 :       meltb  (:,:,:) = c0
     965    16333920 :       meltl  (:,:,:) = c0
     966    16333920 :       daidtt (:,:,:) = aice(:,:,:) ! temporary initial area
     967    16333920 :       dvidtt (:,:,:) = vice(:,:,:) ! temporary initial volume
     968        5821 :       if (tr_iage) then
     969    16333920 :          dagedtt(:,:,:) = trcr(:,:,nt_iage,:) ! temporary initial age
     970             :       else
     971           0 :          dagedtt(:,:,:) = c0
     972             :       endif
     973    81669541 :       fsurfn    (:,:,:,:) = c0
     974    81669541 :       fcondtopn (:,:,:,:) = c0
     975    81669541 :       fcondbotn (:,:,:,:) = c0
     976    81669541 :       flatn     (:,:,:,:) = c0
     977    81669541 :       fsensn    (:,:,:,:) = c0
     978    16333920 :       fresh_ai  (:,:,:) = c0
     979    16333920 :       fsalt_ai  (:,:,:) = c0
     980    16333920 :       fhocn_ai  (:,:,:) = c0
     981    16333920 :       fswthru_ai(:,:,:) = c0
     982    16333920 :       albice (:,:,:) = c0
     983    16333920 :       albsno (:,:,:) = c0
     984    16333920 :       albpnd (:,:,:) = c0
     985    16333920 :       apeff_ai (:,:,:) = c0
     986    16333920 :       snowfrac (:,:,:) = c0
     987    16333920 :       frazil_diag (:,:,:) = c0
     988             : 
     989             :       ! drag coefficients are computed prior to the atmo_boundary call,
     990             :       ! during the thermodynamics section
     991    16333920 :       Cdn_ocn(:,:,:) = dragio
     992           0 :       Cdn_atm(:,:,:) = (vonkar/log(zref/iceruf)) &
     993    16333920 :                      * (vonkar/log(zref/iceruf)) ! atmo drag for RASM
     994    16333920 :       Cdn_atm_ratio(:,:,:)= c0
     995             : 
     996        5821 :       if (formdrag) then
     997           0 :         Cdn_atm_rdg (:,:,:) = c0
     998           0 :         Cdn_atm_floe(:,:,:) = c0
     999           0 :         Cdn_atm_pond(:,:,:) = c0
    1000           0 :         Cdn_atm_skin(:,:,:) = c0
    1001           0 :         Cdn_ocn_skin(:,:,:) = c0
    1002           0 :         Cdn_ocn_keel(:,:,:) = c0
    1003           0 :         Cdn_ocn_floe(:,:,:) = c0
    1004           0 :         hfreebd     (:,:,:) = c0
    1005           0 :         hdraft      (:,:,:) = c0
    1006           0 :         hridge      (:,:,:) = c0
    1007           0 :         distrdg     (:,:,:) = c0
    1008           0 :         hkeel       (:,:,:) = c0
    1009           0 :         dkeel       (:,:,:) = c0
    1010           0 :         lfloe       (:,:,:) = c0
    1011           0 :         dfloe       (:,:,:) = c0
    1012             :       endif
    1013             : 
    1014        5821 :       end subroutine init_history_therm
    1015             : 
    1016             : !=======================================================================
    1017             : 
    1018             : ! Initialize dynamic fields written to history files.
    1019             : !
    1020             : ! authors: William H. Lipscomb, LANL
    1021             : !          Elizabeth C. Hunke, LANL
    1022             : 
    1023        5821 :       subroutine init_history_dyn
    1024             : 
    1025             :       use ice_state, only: aice, vice, trcr, strength
    1026             :       use ice_grid,  only: grid_ice
    1027             : 
    1028             :       logical (kind=log_kind) :: &
    1029             :           tr_iage
    1030             : 
    1031             :       integer (kind=int_kind) :: &
    1032             :           nt_iage
    1033             : 
    1034             :       character(len=*), parameter :: subname = '(init_history_dyn)'
    1035             : 
    1036        5821 :       call icepack_query_tracer_flags(tr_iage_out=tr_iage)
    1037        5821 :       call icepack_query_tracer_indices(nt_iage_out=nt_iage)
    1038        5821 :       call icepack_warnings_flush(nu_diag)
    1039        5821 :       if (icepack_warnings_aborted()) call abort_ice(error_message=subname, &
    1040           0 :          file=__FILE__, line=__LINE__)
    1041             : 
    1042    16333920 :       sig1    (:,:,:) = c0
    1043    16333920 :       sig2    (:,:,:) = c0
    1044    16333920 :       taubxU  (:,:,:) = c0
    1045    16333920 :       taubyU  (:,:,:) = c0
    1046    16333920 :       strength (:,:,:) = c0
    1047    16333920 :       strocnxU(:,:,:) = c0
    1048    16333920 :       strocnyU(:,:,:) = c0
    1049    16333920 :       strairxU(:,:,:) = c0
    1050    16333920 :       strairyU(:,:,:) = c0
    1051    16333920 :       strtltxU(:,:,:) = c0
    1052    16333920 :       strtltyU(:,:,:) = c0
    1053    16333920 :       strintxU(:,:,:) = c0
    1054    16333920 :       strintyU(:,:,:) = c0
    1055    16333920 :       dardg1dt(:,:,:) = c0
    1056    16333920 :       dardg2dt(:,:,:) = c0
    1057    16333920 :       dvirdgdt(:,:,:) = c0
    1058    16333920 :       opening (:,:,:) = c0
    1059    16333920 :       daidtd  (:,:,:) = aice(:,:,:) ! temporary initial area
    1060    16333920 :       dvidtd  (:,:,:) = vice(:,:,:) ! temporary initial volume
    1061        5821 :       if (tr_iage) &
    1062    16333920 :          dagedtd (:,:,:) = trcr(:,:,nt_iage,:) ! temporary initial age
    1063    16333920 :       fmU     (:,:,:) = c0
    1064    81669541 :       ardgn   (:,:,:,:) = c0
    1065    81669541 :       vrdgn   (:,:,:,:) = c0
    1066    81669541 :       krdgn   (:,:,:,:) = c1
    1067    81669541 :       aparticn(:,:,:,:) = c0
    1068    81669541 :       aredistn(:,:,:,:) = c0
    1069    81669541 :       vredistn(:,:,:,:) = c0
    1070    81669541 :       dardg1ndt(:,:,:,:) = c0
    1071    81669541 :       dardg2ndt(:,:,:,:) = c0
    1072    81669541 :       dvirdgndt(:,:,:,:) = c0
    1073    81669541 :       araftn   (:,:,:,:) = c0
    1074    81669541 :       vraftn   (:,:,:,:) = c0
    1075    81669541 :       aredistn (:,:,:,:) = c0
    1076    81669541 :       vredistn (:,:,:,:) = c0
    1077             : 
    1078        5821 :       if (grid_ice == "CD" .or. grid_ice == "C") then
    1079           0 :          taubxE     (:,:,:) = c0
    1080           0 :          taubyE     (:,:,:) = c0
    1081           0 :          strocnxE   (:,:,:) = c0
    1082           0 :          strocnyE   (:,:,:) = c0
    1083           0 :          strairxE   (:,:,:) = c0
    1084           0 :          strairyE   (:,:,:) = c0
    1085           0 :          strtltxE   (:,:,:) = c0
    1086           0 :          strtltyE   (:,:,:) = c0
    1087           0 :          strintxE   (:,:,:) = c0
    1088           0 :          strintyE   (:,:,:) = c0
    1089           0 :          fmE        (:,:,:) = c0
    1090           0 :          TbE        (:,:,:) = c0
    1091           0 :          taubxN     (:,:,:) = c0
    1092           0 :          taubyN     (:,:,:) = c0
    1093           0 :          strocnxN   (:,:,:) = c0
    1094           0 :          strocnyN   (:,:,:) = c0
    1095           0 :          strairxN   (:,:,:) = c0
    1096           0 :          strairyN   (:,:,:) = c0
    1097           0 :          strtltxN   (:,:,:) = c0
    1098           0 :          strtltyN   (:,:,:) = c0
    1099           0 :          strintxN   (:,:,:) = c0
    1100           0 :          strintyN   (:,:,:) = c0
    1101           0 :          fmN        (:,:,:) = c0
    1102           0 :          TbN        (:,:,:) = c0
    1103             :       end if
    1104        5821 :       end subroutine init_history_dyn
    1105             : 
    1106             : !=======================================================================
    1107             : 
    1108             : !  Divide ice fluxes by ice area before sending them to the
    1109             : !  coupler, since the coupler multiplies by ice area.
    1110             : !
    1111             : ! authors: C.M.Bitz, William H. Lipscomb
    1112             : 
    1113       22944 :       subroutine scale_fluxes (nx_block, ny_block, &
    1114             :                                tmask,              &   ! LCOV_EXCL_LINE
    1115             :                                nbtrcr,   max_aero, &   ! LCOV_EXCL_LINE
    1116             :                                aice,     Tf,       &   ! LCOV_EXCL_LINE
    1117             :                                Tair,     Qa,       &   ! LCOV_EXCL_LINE
    1118             :                                strairxT, strairyT, &   ! LCOV_EXCL_LINE
    1119             :                                fsens,    flat,     &   ! LCOV_EXCL_LINE
    1120             :                                fswabs,   flwout,   &   ! LCOV_EXCL_LINE
    1121             :                                evap,               &   ! LCOV_EXCL_LINE
    1122             :                                Tref,     Qref,     &   ! LCOV_EXCL_LINE
    1123             :                                fresh,    fsalt,    &   ! LCOV_EXCL_LINE
    1124             :                                fhocn,    fswthru,  &   ! LCOV_EXCL_LINE
    1125             :                                fswthru_vdr, fswthru_vdf, &   ! LCOV_EXCL_LINE
    1126             :                                fswthru_idr, fswthru_idf, &   ! LCOV_EXCL_LINE
    1127             :                                faero_ocn,          &   ! LCOV_EXCL_LINE
    1128             :                                alvdr,    alidr,    &   ! LCOV_EXCL_LINE
    1129             :                                alvdf,    alidf,    &   ! LCOV_EXCL_LINE
    1130             :                                flux_bio,           &   ! LCOV_EXCL_LINE
    1131             :                                fsurf,    fcondtop, &   ! LCOV_EXCL_LINE
    1132             :                                Uref,     wind,     &   ! LCOV_EXCL_LINE
    1133             :                                Qref_iso,           &   ! LCOV_EXCL_LINE
    1134       45888 :                                fiso_evap,fiso_ocn)
    1135             : 
    1136             :       use icepack_intfc, only: icepack_max_iso
    1137             : 
    1138             :       integer (kind=int_kind), intent(in) :: &
    1139             :           nx_block, ny_block, &    ! block dimensions   ! LCOV_EXCL_LINE
    1140             :           nbtrcr            , &    ! number of biology tracers   ! LCOV_EXCL_LINE
    1141             :           max_aero                 ! maximum number of aerosols
    1142             : 
    1143             :       logical (kind=log_kind), dimension (nx_block,ny_block), intent(in) :: &
    1144             :           tmask     ! land/boundary mask, thickness (T-cell)
    1145             : 
    1146             : 
    1147             :       real (kind=dbl_kind), dimension(nx_block,ny_block), intent(in) :: &
    1148             :           aice    , & ! fractional ice area   ! LCOV_EXCL_LINE
    1149             :           Tf      , & ! freezing temperature            (C)   ! LCOV_EXCL_LINE
    1150             :           Tair    , & ! surface air temperature         (K)   ! LCOV_EXCL_LINE
    1151             :           Qa          ! sfc air specific humidity       (kg/kg)
    1152             : 
    1153             :       real (kind=dbl_kind), dimension(nx_block,ny_block), optional, intent(in) :: &
    1154             :           wind        ! wind speed                      (m/s)
    1155             : 
    1156             :       real (kind=dbl_kind), dimension(nx_block,ny_block), intent(inout) :: &
    1157             :           strairxT, & ! air/ice zonal  stress           (N/m**2)   ! LCOV_EXCL_LINE
    1158             :           strairyT, & ! air/ice merdnl stress           (N/m**2)   ! LCOV_EXCL_LINE
    1159             :           fsens   , & ! sensible heat flx               (W/m**2)   ! LCOV_EXCL_LINE
    1160             :           flat    , & ! latent   heat flx               (W/m**2)   ! LCOV_EXCL_LINE
    1161             :           fswabs  , & ! shortwave absorbed heat flx     (W/m**2)   ! LCOV_EXCL_LINE
    1162             :           flwout  , & ! upwd lw emitted heat flx        (W/m**2)   ! LCOV_EXCL_LINE
    1163             :           evap    , & ! evaporation                     (kg/m2/s)   ! LCOV_EXCL_LINE
    1164             :           Tref    , & ! air tmp reference level         (K)   ! LCOV_EXCL_LINE
    1165             :           Qref    , & ! air sp hum reference level      (kg/kg)   ! LCOV_EXCL_LINE
    1166             :           fresh   , & ! fresh water flux to ocean       (kg/m2/s)   ! LCOV_EXCL_LINE
    1167             :           fsalt   , & ! salt flux to ocean              (kg/m2/s)   ! LCOV_EXCL_LINE
    1168             :           fhocn   , & ! actual ocn/ice heat flx         (W/m**2)   ! LCOV_EXCL_LINE
    1169             :           fswthru , & ! sw radiation through ice bot    (W/m**2)   ! LCOV_EXCL_LINE
    1170             :           fswthru_vdr , & ! vis dir sw radiation through ice bot    (W/m**2)   ! LCOV_EXCL_LINE
    1171             :           fswthru_vdf , & ! vis dif sw radiation through ice bot    (W/m**2)   ! LCOV_EXCL_LINE
    1172             :           fswthru_idr , & ! nir dir sw radiation through ice bot    (W/m**2)   ! LCOV_EXCL_LINE
    1173             :           fswthru_idf , & ! nir dif sw radiation through ice bot    (W/m**2)   ! LCOV_EXCL_LINE
    1174             :           alvdr   , & ! visible, direct   (fraction)   ! LCOV_EXCL_LINE
    1175             :           alidr   , & ! near-ir, direct   (fraction)   ! LCOV_EXCL_LINE
    1176             :           alvdf   , & ! visible, diffuse  (fraction)   ! LCOV_EXCL_LINE
    1177             :           alidf       ! near-ir, diffuse  (fraction)
    1178             : 
    1179             :       real (kind=dbl_kind), dimension(nx_block,ny_block), optional, intent(inout) :: &
    1180             :           Uref        ! air speed reference level       (m/s)
    1181             : 
    1182             :       real (kind=dbl_kind), dimension(nx_block,ny_block,nbtrcr), intent(inout) :: &
    1183             :           flux_bio    ! tracer flux to ocean from biology (mmol/m2/s)
    1184             : 
    1185             :       real (kind=dbl_kind), dimension(nx_block,ny_block,max_aero), intent(inout) :: &
    1186             :           faero_ocn   ! aerosol flux to ocean            (kg/m2/s)
    1187             : 
    1188             :       ! For hadgem drivers. Assumes either both fields are passed or neither
    1189             :       real (kind=dbl_kind), dimension(nx_block,ny_block), intent(inout), optional :: &
    1190             :           fsurf   , & ! surface heat flux               (W/m**2)   ! LCOV_EXCL_LINE
    1191             :           fcondtop    ! top surface conductive flux     (W/m**2)
    1192             : 
    1193             :       ! isotopes
    1194             :       real (kind=dbl_kind), dimension(nx_block,ny_block,icepack_max_iso), &
    1195             :           optional, intent(inout) :: &   ! LCOV_EXCL_LINE
    1196             :           Qref_iso , & ! isotope air sp hum reference level      (kg/kg)   ! LCOV_EXCL_LINE
    1197             :           fiso_evap, & ! isotope evaporation (kg/m2/s)   ! LCOV_EXCL_LINE
    1198             :           fiso_ocn     ! isotope flux to ocean (kg/m2/s)
    1199             : 
    1200             :       ! local variables
    1201             : 
    1202             :       real (kind=dbl_kind) :: &
    1203             :           ar, &   ! 1/aice   ! LCOV_EXCL_LINE
    1204             :           stefan_boltzmann, &   ! LCOV_EXCL_LINE
    1205        5760 :           Tffresh
    1206             : 
    1207             :       integer (kind=int_kind) :: &
    1208             :           i, j    ! horizontal indices
    1209             : 
    1210             :       character(len=*), parameter :: subname = '(scale_fluxes)'
    1211             : 
    1212             :       call icepack_query_parameters(stefan_boltzmann_out=stefan_boltzmann, &
    1213       22944 :          Tffresh_out=Tffresh)
    1214       22944 :       call icepack_warnings_flush(nu_diag)
    1215       22944 :       if (icepack_warnings_aborted()) call abort_ice(error_message=subname, &
    1216           0 :          file=__FILE__, line=__LINE__)
    1217             : 
    1218      753576 :       do j = 1, ny_block
    1219    16186320 :       do i = 1, nx_block
    1220    16163376 :          if (tmask(i,j) .and. aice(i,j) > c0) then
    1221     7575466 :             ar = c1 / aice(i,j)
    1222     7575466 :             strairxT(i,j) = strairxT(i,j) * ar
    1223     7575466 :             strairyT(i,j) = strairyT(i,j) * ar
    1224     7575466 :             fsens   (i,j) = fsens   (i,j) * ar
    1225     7575466 :             flat    (i,j) = flat    (i,j) * ar
    1226     7575466 :             fswabs  (i,j) = fswabs  (i,j) * ar
    1227     7575466 :             flwout  (i,j) = flwout  (i,j) * ar
    1228     7575466 :             evap    (i,j) = evap    (i,j) * ar
    1229     7575466 :             Tref    (i,j) = Tref    (i,j) * ar
    1230     7575466 :             Qref    (i,j) = Qref    (i,j) * ar
    1231     7575466 :             if (present(Uref)) &
    1232           0 :                Uref (i,j) = Uref    (i,j) * ar
    1233     7575466 :             fresh   (i,j) = fresh   (i,j) * ar
    1234     7575466 :             fsalt   (i,j) = fsalt   (i,j) * ar
    1235     7575466 :             fhocn   (i,j) = fhocn   (i,j) * ar
    1236     7575466 :             fswthru (i,j) = fswthru (i,j) * ar
    1237     7575466 :             fswthru_vdr (i,j) = fswthru_vdr (i,j) * ar
    1238     7575466 :             fswthru_vdf (i,j) = fswthru_vdf (i,j) * ar
    1239     7575466 :             fswthru_idr (i,j) = fswthru_idr (i,j) * ar
    1240     7575466 :             fswthru_idf (i,j) = fswthru_idf (i,j) * ar
    1241     7575466 :             alvdr   (i,j) = alvdr   (i,j) * ar
    1242     7575466 :             alidr   (i,j) = alidr   (i,j) * ar
    1243     7575466 :             alvdf   (i,j) = alvdf   (i,j) * ar
    1244     7575466 :             alidf   (i,j) = alidf   (i,j) * ar
    1245     7575466 :             flux_bio (i,j,:) = flux_bio (i,j,:) * ar
    1246    53028262 :             faero_ocn(i,j,:) = faero_ocn(i,j,:) * ar
    1247    30301864 :             if (present(Qref_iso )) Qref_iso (i,j,:) = Qref_iso (i,j,:) * ar
    1248    30301864 :             if (present(fiso_evap)) fiso_evap(i,j,:) = fiso_evap(i,j,:) * ar
    1249    30301864 :             if (present(fiso_ocn )) fiso_ocn (i,j,:) = fiso_ocn (i,j,:) * ar
    1250             :          else                   ! zero out fluxes
    1251     7857278 :             strairxT(i,j) = c0
    1252     7857278 :             strairyT(i,j) = c0
    1253     7857278 :             fsens   (i,j) = c0
    1254     7857278 :             flat    (i,j) = c0
    1255     7857278 :             fswabs  (i,j) = c0
    1256     7857278 :             flwout  (i,j) = -stefan_boltzmann *(Tf(i,j) + Tffresh)**4
    1257             :                ! to make upward longwave over ocean reasonable for history file
    1258     7857278 :             evap    (i,j) = c0
    1259     7857278 :             Tref    (i,j) = Tair(i,j)
    1260     7857278 :             Qref    (i,j) = Qa  (i,j)
    1261     7857278 :             if (present(Uref) .and. present(wind)) &
    1262           0 :                Uref (i,j) = wind(i,j)
    1263     7857278 :             fresh   (i,j) = c0
    1264     7857278 :             fsalt   (i,j) = c0
    1265     7857278 :             fhocn   (i,j) = c0
    1266     7857278 :             fswthru (i,j) = c0
    1267     7857278 :             fswthru_vdr (i,j) = c0
    1268     7857278 :             fswthru_vdf (i,j) = c0
    1269     7857278 :             fswthru_idr (i,j) = c0
    1270     7857278 :             fswthru_idf (i,j) = c0
    1271     7857278 :             alvdr   (i,j) = c0  ! zero out albedo where ice is absent
    1272     7857278 :             alidr   (i,j) = c0
    1273     7857278 :             alvdf   (i,j) = c0
    1274     7857278 :             alidf   (i,j) = c0
    1275     7857278 :             flux_bio (i,j,:) = c0
    1276    55000946 :             faero_ocn(i,j,:) = c0
    1277    31429112 :             if (present(Qref_iso )) Qref_iso (i,j,:) = c0
    1278    31429112 :             if (present(fiso_evap)) fiso_evap(i,j,:) = c0
    1279    31429112 :             if (present(fiso_ocn )) fiso_ocn (i,j,:) = c0
    1280             :          endif                  ! tmask and aice > 0
    1281             :       enddo                     ! i
    1282             :       enddo                     ! j
    1283             : 
    1284             :       ! Scale fluxes for history output
    1285       22944 :       if (present(fsurf) .and. present(fcondtop) ) then
    1286             : 
    1287           0 :         do j = 1, ny_block
    1288           0 :         do i = 1, nx_block
    1289           0 :            if (tmask(i,j) .and. aice(i,j) > c0) then
    1290           0 :               ar = c1 / aice(i,j)
    1291           0 :               fsurf   (i,j) = fsurf   (i,j) * ar
    1292           0 :               fcondtop(i,j) = fcondtop(i,j) * ar
    1293             :            else                   ! zero out fluxes
    1294           0 :               fsurf   (i,j) = c0
    1295           0 :               fcondtop(i,j) = c0
    1296             :            endif                  ! tmask and aice > 0
    1297             :         enddo                     ! i
    1298             :         enddo                     ! j
    1299             : 
    1300             :       endif                       ! present(fsurf & fcondtop)
    1301             : 
    1302       91776 :       end subroutine scale_fluxes
    1303             : 
    1304             : !=======================================================================
    1305             : 
    1306             :       end module ice_flux
    1307             : 
    1308             : !=======================================================================

Generated by: LCOV version 1.14-6-g40580cd