LCOV - code coverage report
Current view: top level - cicecore/cicedyn/analysis - ice_history.F90 (source / functions) Hit Total Coverage
Test: 231018-211459:8916b9ff2c:1:quick Lines: 1210 2334 51.84 %
Date: 2023-10-18 15:30:36 Functions: 2 2 100.00 %

          Line data    Source code
       1             : !=======================================================================
       2             : ! Driver for core history output
       3             : !
       4             : ! The following variables are currently hard-wired as snapshots
       5             : !   (instantaneous rather than time-averages):
       6             : !   divu, shear, sig1, sig2, sigP, trsig, mlt_onset, frz_onset, hisnap, aisnap
       7             : !
       8             : ! Options for histfreq: '1','h','d','m','y','x', where x means that
       9             : !   output stream will not be used (recommended for efficiency).
      10             : ! histfreq_n can be any nonnegative integer, where 0 means that the
      11             : !   corresponding histfreq frequency will not be used.
      12             : ! The flags (f_<field>) can be set to '1','h','d','m','y' or 'x', where
      13             : !   n means the field will not be written.  To output the same field at
      14             : !   more than one frequency, for instance monthy and daily, set
      15             : !   f_<field> = 'md'.
      16             : !
      17             : ! authors Tony Craig and Bruce Briegleb, NCAR
      18             : !         Elizabeth C. Hunke and William H. Lipscomb, LANL
      19             : !         C. M. Bitz, UW
      20             : !
      21             : ! 2004 WHL: Block structure added
      22             : ! 2006 ECH: Accepted some CESM code into mainstream CICE
      23             : !           Added ice_present, aicen, vicen; removed aice1...10, vice1...1.
      24             : !           Added histfreq_n and histfreq='h' options, removed histfreq='w'
      25             : !           Converted to free source form (F90)
      26             : !           Added option for binary output instead of netCDF
      27             : ! 2009 D Bailey and ECH: Generalized for multiple frequency output
      28             : ! 2010 Alison McLaren and ECH: Added 3D capability
      29             : 
      30             :       module ice_history
      31             : 
      32             :       use ice_kinds_mod
      33             :       use ice_communicate, only: my_task, master_task
      34             :       use ice_constants, only: c0, c1, c2, c100, c360, c180, &
      35             :           p001, p25, p5, mps_to_cmpdy, kg_to_g, spval_dbl
      36             :       use ice_fileunits, only: nu_nml, nml_filename, nu_diag, &
      37             :           get_fileunit, release_fileunit, flush_fileunit
      38             :       use ice_exit, only: abort_ice
      39             :       use icepack_intfc, only: icepack_warnings_flush, icepack_warnings_aborted
      40             :       use icepack_intfc, only: icepack_snow_temperature, icepack_ice_temperature
      41             :       use icepack_intfc, only: icepack_query_parameters, &
      42             :           icepack_query_tracer_flags, icepack_query_tracer_indices
      43             : 
      44             :       implicit none
      45             :       private
      46             :       public :: init_hist, accum_hist
      47             : 
      48             : !=======================================================================
      49             : 
      50             :       contains
      51             : 
      52             : !=======================================================================
      53             : 
      54             : ! Initialize history files
      55             : !
      56             : ! authors Tony Craig, NCAR
      57             : !         Elizabeth C. Hunke, LANL
      58             : !         C.M. Bitz, UW
      59             : !         Bruce P. Briegleb, NCAR
      60             : !         William H. Lipscomb, LANL
      61             : 
      62          37 :       subroutine init_hist (dt)
      63             : 
      64             :       use ice_blocks, only: nx_block, ny_block
      65             :       use ice_broadcast, only: broadcast_scalar, broadcast_array
      66             :       use ice_calendar, only: yday, days_per_year, histfreq, &
      67             :           histfreq_n, nstreams
      68             :       use ice_domain_size, only: max_blocks, max_nstrm, nilyr, nslyr, nblyr, ncat, nfsd
      69             :       use ice_dyn_shared, only: kdyn
      70             :       use ice_flux, only: mlt_onset, frz_onset, albcnt, snwcnt
      71             :       use ice_grid, only: grid_ice, &
      72             :           grid_atm_thrm, grid_atm_dynu, grid_atm_dynv, &   ! LCOV_EXCL_LINE
      73             :           grid_ocn_thrm, grid_ocn_dynu, grid_ocn_dynv
      74             :       use ice_history_shared ! everything
      75             :       use ice_history_mechred, only: init_hist_mechred_2D, init_hist_mechred_3Dc
      76             :       use ice_history_pond, only: init_hist_pond_2D, init_hist_pond_3Dc
      77             :       use ice_history_snow, only: init_hist_snow_2D, init_hist_snow_3Dc
      78             :       use ice_history_bgc, only:init_hist_bgc_2D, init_hist_bgc_3Dc, &
      79             :           init_hist_bgc_3Db, init_hist_bgc_3Da
      80             :       use ice_history_drag, only: init_hist_drag_2D
      81             :       use ice_history_fsd, only: init_hist_fsd_2D, init_hist_fsd_3Df, &
      82             :           init_hist_fsd_4Df, f_afsd, f_afsdn
      83             :       use ice_restart_shared, only: restart
      84             :       use ice_fileunits, only: goto_nml
      85             : 
      86             :       real (kind=dbl_kind), intent(in) :: &
      87             :          dt      ! time step
      88             : 
      89             :       ! local variables
      90             : 
      91           8 :       real (kind=dbl_kind) :: rhofresh, Tffresh, secday, rad_to_deg
      92             :       logical (kind=log_kind) :: formdrag
      93             :       logical (kind=log_kind) :: tr_iage, tr_FY, tr_lvl, tr_pond, tr_aero, tr_brine
      94             :       logical (kind=log_kind) :: tr_fsd, tr_snow
      95             :       logical (kind=log_kind) :: skl_bgc, solve_zbgc, z_tracers
      96             :       integer (kind=int_kind) :: n, ns, ns1, ns2
      97             :       integer (kind=int_kind), dimension(max_nstrm) :: &
      98             :          ntmp
      99             :       integer (kind=int_kind) :: nml_error ! namelist i/o error flag
     100             :       character (len=25) :: &
     101             :          str2D_gat, str2d_gau, str2d_gav, &  ! dimensions for t, u, v atm grid (ga)   ! LCOV_EXCL_LINE
     102             :          str2D_got, str2d_gou, str2d_gov     ! dimensions for t, u, v ocn grid (go)
     103             :       character (len=25) :: &
     104             :          cstr_gat, cstr_gau, cstr_gav, &     ! mask area name for t, u, v atm grid (ga)   ! LCOV_EXCL_LINE
     105             :          cstr_got, cstr_gou, cstr_gov        ! mask area name for t, u, v ocn grid (go)
     106             :       character (len=25) :: &
     107             :          gridstr2D, gridstr                  ! temporary string names
     108             :       character(len=char_len)      :: description
     109             :       character(len=char_len_long) :: tmpstr2 ! for namelist check
     110             :       character(len=char_len)      :: nml_name ! text namelist name
     111             : 
     112             :       character(len=*), parameter :: subname = '(init_hist)'
     113             : 
     114             :       !-----------------------------------------------------------------
     115             :       ! set atm/ocn forcing grids
     116             :       !-----------------------------------------------------------------
     117             : 
     118             :       !--- ATM ---
     119             : 
     120          37 :       if     (grid_atm_thrm == 'T') then
     121          37 :          str2D_gat = tstr2D
     122          37 :          cstr_gat  = tcstr
     123           0 :       elseif (grid_atm_thrm == 'U') then
     124           0 :          str2D_gat = ustr2D
     125           0 :          cstr_gat  = ucstr
     126           0 :       elseif (grid_atm_thrm == 'N') then
     127           0 :          str2D_gat = nstr2D
     128           0 :          cstr_gat  = ncstr
     129           0 :       elseif (grid_atm_thrm == 'E') then
     130           0 :          str2D_gat = estr2D
     131           0 :          cstr_gat  = ecstr
     132             :       endif
     133             : 
     134          37 :       if     (grid_atm_dynu == 'T') then
     135          37 :          str2D_gau = tstr2D
     136          37 :          cstr_gau  = tcstr
     137           0 :       elseif (grid_atm_dynu == 'U') then
     138           0 :          str2D_gau = ustr2D
     139           0 :          cstr_gau  = ucstr
     140           0 :       elseif (grid_atm_dynu == 'N') then
     141           0 :          str2D_gau = nstr2D
     142           0 :          cstr_gau  = ncstr
     143           0 :       elseif (grid_atm_dynu == 'E') then
     144           0 :          str2D_gau = estr2D
     145           0 :          cstr_gau  = ecstr
     146             :       endif
     147             : 
     148          37 :       if     (grid_atm_dynv == 'T') then
     149          37 :          str2D_gav = tstr2D
     150          37 :          cstr_gav  = tcstr
     151           0 :       elseif (grid_atm_dynv == 'U') then
     152           0 :          str2D_gav = ustr2D
     153           0 :          cstr_gav  = ucstr
     154           0 :       elseif (grid_atm_dynv == 'N') then
     155           0 :          str2D_gav = nstr2D
     156           0 :          cstr_gav  = ncstr
     157           0 :       elseif (grid_atm_dynv == 'E') then
     158           0 :          str2D_gav = estr2D
     159           0 :          cstr_gav  = ecstr
     160             :       endif
     161             : 
     162             :       !--- OCN ---
     163             : 
     164          37 :       if     (grid_ocn_thrm == 'T') then
     165          37 :          str2D_got = tstr2D
     166          37 :          cstr_got  = tcstr
     167           0 :       elseif (grid_ocn_thrm == 'U') then
     168           0 :          str2D_got = ustr2D
     169           0 :          cstr_got  = ucstr
     170           0 :       elseif (grid_ocn_thrm == 'N') then
     171           0 :          str2D_got = nstr2D
     172           0 :          cstr_got  = ncstr
     173           0 :       elseif (grid_ocn_thrm == 'E') then
     174           0 :          str2D_got = estr2D
     175           0 :          cstr_got  = ecstr
     176             :       endif
     177             : 
     178          37 :       if     (grid_ocn_dynu == 'T') then
     179          21 :          str2D_gou = tstr2D
     180          21 :          cstr_gou  = tcstr
     181          16 :       elseif (grid_ocn_dynu == 'U') then
     182          16 :          str2D_gou = ustr2D
     183          16 :          cstr_gou  = ucstr
     184           0 :       elseif (grid_ocn_dynu == 'N') then
     185           0 :          str2D_gou = nstr2D
     186           0 :          cstr_gou  = ncstr
     187           0 :       elseif (grid_ocn_dynu == 'E') then
     188           0 :          str2D_gou = estr2D
     189           0 :          cstr_gou  = ecstr
     190             :       endif
     191             : 
     192          37 :       if     (grid_ocn_dynv == 'T') then
     193          21 :          str2D_gov = tstr2D
     194          21 :          cstr_gov  = tcstr
     195          16 :       elseif (grid_ocn_dynv == 'U') then
     196          16 :          str2D_gov = ustr2D
     197          16 :          cstr_gov  = ucstr
     198           0 :       elseif (grid_ocn_dynv == 'N') then
     199           0 :          str2D_gov = nstr2D
     200           0 :          cstr_gov  = ncstr
     201           0 :       elseif (grid_ocn_dynv == 'E') then
     202           0 :          str2D_gov = estr2D
     203           0 :          cstr_gov  = ecstr
     204             :       endif
     205             : 
     206             : 
     207             :       !-----------------------------------------------------------------
     208             :       ! set history dimensions
     209             :       !-----------------------------------------------------------------
     210             : 
     211          37 :       ncat_hist = ncat    ! number of thickness categories written <= ncat
     212          37 :       nfsd_hist = nfsd    ! number of floe size categories written <= nfsd
     213          37 :       nzilyr = nilyr      ! vertical dimension (allows alternative grids)
     214          37 :       nzslyr = nslyr      ! snow
     215          37 :       nzblyr = nblyr+2    ! bio grid
     216          37 :       nzalyr = nblyr+4    ! aerosols (2 snow & nblyr+2 bio)
     217             : 
     218             :       !-----------------------------------------------------------------
     219             :       ! read namelist
     220             :       !-----------------------------------------------------------------
     221             : 
     222             :       call icepack_query_parameters(rhofresh_out=rhofresh, Tffresh_out=Tffresh, &
     223          37 :          secday_out=secday, rad_to_deg_out=rad_to_deg)
     224             :       call icepack_query_parameters(formdrag_out=formdrag, skl_bgc_out=skl_bgc, &
     225          37 :          solve_zbgc_out=solve_zbgc, z_tracers_out=z_tracers)
     226             :       call icepack_query_tracer_flags(tr_iage_out=tr_iage, tr_FY_out=tr_FY, &
     227             :          tr_lvl_out=tr_lvl, tr_pond_out=tr_pond, tr_aero_out=tr_aero, &   ! LCOV_EXCL_LINE
     228          37 :          tr_brine_out=tr_brine, tr_fsd_out=tr_fsd, tr_snow_out=tr_snow)
     229          37 :       call icepack_warnings_flush(nu_diag)
     230          37 :       if (icepack_warnings_aborted()) call abort_ice(error_message=subname, &
     231           0 :          file=__FILE__, line=__LINE__)
     232             : 
     233          37 :       if (my_task == master_task) then
     234           7 :          nml_name = 'icefields_nml'
     235           7 :          write(nu_diag,*) subname,' Reading ', trim(nml_name)
     236             : 
     237             :          ! open file
     238           7 :          call get_fileunit(nu_nml)
     239           7 :          open (nu_nml, file=trim(nml_filename), status='old',iostat=nml_error)
     240           7 :          if (nml_error /= 0) then
     241             :             call abort_ice(subname//'ERROR: '//trim(nml_name)//' open file '// &
     242             :                trim(nml_filename), &   ! LCOV_EXCL_LINE
     243           0 :                file=__FILE__, line=__LINE__)
     244             :          endif
     245             : 
     246             :          ! seek to this namelist
     247           7 :          call goto_nml(nu_nml,trim(nml_name),nml_error)
     248           7 :          if (nml_error /= 0) then
     249             :             call abort_ice(subname//'ERROR: searching for '// trim(nml_name), &
     250           0 :                file=__FILE__, line=__LINE__)
     251             :          endif
     252             : 
     253             :          ! read namelist
     254           7 :          nml_error =  1
     255          14 :          do while (nml_error > 0)
     256           7 :             read(nu_nml, nml=icefields_nml,iostat=nml_error)
     257             :             ! check if error
     258           7 :             if (nml_error /= 0) then
     259             :                ! backspace and re-read erroneous line
     260           0 :                backspace(nu_nml)
     261           0 :                read(nu_nml,fmt='(A)') tmpstr2
     262             :                call abort_ice(subname//'ERROR: ' // trim(nml_name) // ' reading ' // &
     263           0 :                     trim(tmpstr2), file=__FILE__, line=__LINE__)
     264             :             endif
     265             :          end do
     266             : 
     267           7 :          close(nu_nml)
     268           7 :          call release_fileunit(nu_nml)
     269             :       endif
     270             : 
     271             :       ! histfreq options ('1','h','d','m','y')
     272          37 :       nstreams = 0
     273         222 :       do ns = 1, max_nstrm
     274          40 :          if (histfreq(ns) == '1' .or. histfreq(ns) == 'h' .or. &
     275             :              histfreq(ns) == 'd' .or. histfreq(ns) == 'm' .or. &   ! LCOV_EXCL_LINE
     276          37 :              histfreq(ns) == 'y') then
     277          37 :                 nstreams = nstreams + 1
     278          37 :                 if (ns >= 2) then
     279           0 :                    if (histfreq(ns-1) == 'x') then
     280           0 :                       call abort_ice(subname//'ERROR: histfreq all non x must be at start of array')
     281             :                    endif
     282             :                 endif
     283         148 :          else if (histfreq(ns) /= 'x') then
     284           0 :              call abort_ice(subname//'ERROR: histfreq contains illegal element')
     285             :          endif
     286             :       enddo
     287          37 :       if (nstreams == 0) write (nu_diag,*) 'WARNING: No history output'
     288          74 :       do ns1 = 1, nstreams
     289         111 :          do ns2 = 1, nstreams
     290           8 :             if (histfreq(ns1) == histfreq(ns2) .and. ns1/=ns2 &
     291          74 :                .and. my_task == master_task) then
     292           0 :                call abort_ice(subname//'ERROR: histfreq elements must be unique')
     293             :             endif
     294             :          enddo
     295             :       enddo
     296             : 
     297          37 :       if (.not. tr_iage) then
     298           0 :          f_iage = 'x'
     299           0 :          f_dagedtt = 'x'
     300           0 :          f_dagedtd = 'x'
     301             :       endif
     302          37 :       if (.not. tr_FY)   f_FY   = 'x'
     303          37 :       if (kdyn /= 2) then
     304          37 :            f_a11       = 'x'
     305          37 :            f_a12       = 'x'
     306          37 :            f_e11       = 'x'
     307          37 :            f_e12       = 'x'
     308          37 :            f_e22       = 'x'
     309          37 :            f_s11       = 'x'
     310          37 :            f_s12       = 'x'
     311          37 :            f_s22       = 'x'
     312          37 :            f_yieldstress11 = 'x'
     313          37 :            f_yieldstress12 = 'x'
     314          37 :            f_yieldstress22 = 'x'
     315             :       endif
     316             : 
     317             :       ! these must be output at the same frequency because of
     318             :       ! cos(zenith angle) averaging
     319          37 :       if (f_albice(1:1) /= 'x' .and. f_albsni(1:1) /= 'x') f_albice = f_albsni
     320          37 :       if (f_albsno(1:1) /= 'x') f_albsno = f_albice
     321          37 :       if (f_albpnd(1:1) /= 'x') f_albpnd = f_albice
     322          37 :       if (f_coszen(1:1) /= 'x' .and. f_albice(1:1) /= 'x') f_coszen = f_albice
     323          37 :       if (f_coszen(1:1) /= 'x' .and. f_albsni(1:1) /= 'x') f_coszen = f_albsni
     324             : 
     325             :       ! to prevent array-out-of-bounds when aggregating
     326          37 :       if (f_fmeltt_ai(1:1) /= 'x') f_fmelttn_ai = f_fmeltt_ai
     327             : 
     328             :      ! Turn on all CMIP fields in one go.
     329             : 
     330          37 :       if (f_CMIP(1:1) /= 'x') then
     331           0 :          f_sithick = 'mxxxx'
     332           0 :          f_sisnthick = 'mxxxx'
     333           0 :          f_siage = 'mxxxx'
     334           0 :          f_sitemptop = 'mxxxx'
     335           0 :          f_sitempsnic = 'mxxxx'
     336           0 :          f_sitempbot = 'mxxxx'
     337           0 :          f_sispeed = 'mxxxx'
     338           0 :          f_siu = 'mxxxx'
     339           0 :          f_siv = 'mxxxx'
     340           0 :          f_sidmasstranx = 'mxxxx'
     341           0 :          f_sidmasstrany = 'mxxxx'
     342           0 :          f_sistrxdtop = 'mxxxx'
     343           0 :          f_sistrydtop = 'mxxxx'
     344           0 :          f_sistrxubot = 'mxxxx'
     345           0 :          f_sistryubot = 'mxxxx'
     346           0 :          f_sicompstren = 'mxxxx'
     347           0 :          f_sialb = 'mxxxx'
     348           0 :          f_sihc = 'mxxxx'
     349           0 :          f_sisnhc = 'mxxxx'
     350           0 :          f_sidconcth = 'mxxxx'
     351           0 :          f_sidconcdyn = 'mxxxx'
     352           0 :          f_sidmassth = 'mxxxx'
     353           0 :          f_sidmassdyn = 'mxxxx'
     354           0 :          f_sidmassgrowthwat = 'mxxxx'
     355           0 :          f_sidmassgrowthbot = 'mxxxx'
     356           0 :          f_sidmasssi = 'mxxxx'
     357           0 :          f_sidmassevapsubl = 'mxxxx'
     358           0 :          f_sndmasssubl = 'mxxxx'
     359           0 :          f_sidmassmelttop = 'mxxxx'
     360           0 :          f_sidmassmeltbot = 'mxxxx'
     361           0 :          f_sidmasslat = 'mxxxx'
     362           0 :          f_sndmasssnf = 'mxxxx'
     363           0 :          f_sndmassmelt = 'mxxxx'
     364           0 :          f_siflswdtop = 'mxxxx'
     365           0 :          f_siflswutop = 'mxxxx'
     366           0 :          f_siflswdbot = 'mxxxx'
     367           0 :          f_sifllwdtop = 'mxxxx'
     368           0 :          f_sifllwutop = 'mxxxx'
     369           0 :          f_siflsenstop = 'mxxxx'
     370           0 :          f_siflsensupbot = 'mxxxx'
     371           0 :          f_sifllatstop = 'mxxxx'
     372           0 :          f_siflcondtop = 'mxxxx'
     373           0 :          f_siflcondbot = 'mxxxx'
     374           0 :          f_sipr = 'mxxxx'
     375           0 :          f_sifb = 'mxxxx'
     376           0 :          f_siflsaltbot = 'mxxxx'
     377           0 :          f_siflfwbot = 'mxxxx'
     378           0 :          f_siflfwdrain = 'mxxxx'
     379           0 :          f_siforcetiltx = 'mxxxx'
     380           0 :          f_siforcetilty = 'mxxxx'
     381           0 :          f_siforcecoriolx = 'mxxxx'
     382           0 :          f_siforcecorioly = 'mxxxx'
     383           0 :          f_siforceintstrx = 'mxxxx'
     384           0 :          f_siforceintstry = 'mxxxx'
     385           0 :          f_sidragtop = 'mxxxx'
     386           0 :          f_sistreave = 'mxxxx'
     387           0 :          f_sistremax = 'mxxxx'
     388           0 :          f_sirdgthick = 'mxxxx'
     389           0 :          f_siitdconc = 'mxxxx'
     390           0 :          f_siitdthick = 'mxxxx'
     391           0 :          f_siitdsnthick = 'mxxxx'
     392           0 :          f_aicen = 'mxxxx'
     393             :       endif
     394             : 
     395          37 :       if (f_CMIP(2:2) == 'd') then
     396           0 :          f_icepresent = f_CMIP
     397           0 :          f_aice = f_CMIP
     398           0 :          f_sithick = f_CMIP
     399           0 :          f_sisnthick = f_CMIP
     400           0 :          f_sitemptop = f_CMIP
     401           0 :          f_siu = f_CMIP
     402           0 :          f_siv = f_CMIP
     403           0 :          f_sispeed = f_CMIP
     404             :       endif
     405             : 
     406          37 :       if (grid_ice == 'CD' .or. grid_ice == 'C') then
     407           0 :          f_uvelE = f_uvel
     408           0 :          f_vvelE = f_vvel
     409           0 :          f_icespdE = f_icespd
     410           0 :          f_icedirE = f_icedir
     411           0 :          f_uvelN = f_uvel
     412           0 :          f_vvelN = f_vvel
     413           0 :          f_icespdN = f_icespd
     414           0 :          f_icedirN = f_icedir
     415           0 :          f_strairxN = f_strairx
     416           0 :          f_strairyN = f_strairy
     417           0 :          f_strairxE = f_strairx
     418           0 :          f_strairyE = f_strairy
     419           0 :          f_strocnxN = f_strocnx
     420           0 :          f_strocnyN = f_strocny
     421           0 :          f_strocnxE = f_strocnx
     422           0 :          f_strocnyE = f_strocny
     423           0 :          f_strcorxN = f_strcorx
     424           0 :          f_strcoryN = f_strcory
     425           0 :          f_strcorxE = f_strcorx
     426           0 :          f_strcoryE = f_strcory
     427           0 :          f_strintxN = f_strintx
     428           0 :          f_strintyN = f_strinty
     429           0 :          f_strintxE = f_strintx
     430           0 :          f_strintyE = f_strinty
     431           0 :          f_strtltxN = f_strtltx
     432           0 :          f_strtltyN = f_strtlty
     433           0 :          f_strtltxE = f_strtltx
     434           0 :          f_strtltyE = f_strtlty
     435           0 :          f_taubxN = f_taubx
     436           0 :          f_taubyN = f_tauby
     437           0 :          f_taubxE = f_taubx
     438           0 :          f_taubyE = f_tauby
     439             :       endif
     440             : 
     441             :       ! write dimensions for 3D or 4D history variables
     442             :       ! note: list of variables checked here is incomplete
     443             :       if (f_aicen(1:1) /= 'x' .or. f_vicen(1:1) /= 'x' .or. &
     444          37 :           f_Tinz (1:1) /= 'x' .or. f_Sinz (1:1) /= 'x') f_NCAT  = .true.
     445          37 :       if (f_Tinz (1:1) /= 'x' .or. f_Sinz (1:1) /= 'x') f_VGRDi = .true.
     446          37 :       if (f_Tsnz (1:1) /= 'x')                          f_VGRDs = .true.
     447          37 :       if (tr_fsd)                                       f_NFSD  = .true.
     448             : 
     449          37 :       call broadcast_scalar (f_tmask, master_task)
     450          37 :       call broadcast_scalar (f_umask, master_task)
     451          37 :       call broadcast_scalar (f_nmask, master_task)
     452          37 :       call broadcast_scalar (f_emask, master_task)
     453          37 :       call broadcast_scalar (f_blkmask, master_task)
     454          37 :       call broadcast_scalar (f_tarea, master_task)
     455          37 :       call broadcast_scalar (f_uarea, master_task)
     456          37 :       call broadcast_scalar (f_narea, master_task)
     457          37 :       call broadcast_scalar (f_earea, master_task)
     458          37 :       call broadcast_scalar (f_dxt, master_task)
     459          37 :       call broadcast_scalar (f_dyt, master_task)
     460          37 :       call broadcast_scalar (f_dxu, master_task)
     461          37 :       call broadcast_scalar (f_dyu, master_task)
     462          37 :       call broadcast_scalar (f_dxn, master_task)
     463          37 :       call broadcast_scalar (f_dyn, master_task)
     464          37 :       call broadcast_scalar (f_dxe, master_task)
     465          37 :       call broadcast_scalar (f_dye, master_task)
     466          37 :       call broadcast_scalar (f_HTN, master_task)
     467          37 :       call broadcast_scalar (f_HTE, master_task)
     468          37 :       call broadcast_scalar (f_ANGLE, master_task)
     469          37 :       call broadcast_scalar (f_ANGLET, master_task)
     470          37 :       call broadcast_scalar (f_bounds, master_task)
     471          37 :       call broadcast_scalar (f_NCAT, master_task)
     472          37 :       call broadcast_scalar (f_VGRDi, master_task)
     473          37 :       call broadcast_scalar (f_VGRDs, master_task)
     474          37 :       call broadcast_scalar (f_VGRDb, master_task)
     475          37 :       call broadcast_scalar (f_VGRDa, master_task)
     476          37 :       call broadcast_scalar (f_NFSD, master_task)
     477             : 
     478             : !     call broadcast_scalar (f_example, master_task)
     479          37 :       call broadcast_scalar (f_hi, master_task)
     480          37 :       call broadcast_scalar (f_hs, master_task)
     481          37 :       call broadcast_scalar (f_snowfrac, master_task)
     482          37 :       call broadcast_scalar (f_snowfracn, master_task)
     483          37 :       call broadcast_scalar (f_Tsfc, master_task)
     484          37 :       call broadcast_scalar (f_aice, master_task)
     485          37 :       call broadcast_scalar (f_uvel, master_task)
     486          37 :       call broadcast_scalar (f_vvel, master_task)
     487          37 :       call broadcast_scalar (f_icespd, master_task)
     488          37 :       call broadcast_scalar (f_icedir, master_task)
     489          37 :       call broadcast_scalar (f_uvelE, master_task)
     490          37 :       call broadcast_scalar (f_vvelE, master_task)
     491          37 :       call broadcast_scalar (f_icespdE, master_task)
     492          37 :       call broadcast_scalar (f_icedirE, master_task)
     493          37 :       call broadcast_scalar (f_uvelN, master_task)
     494          37 :       call broadcast_scalar (f_vvelN, master_task)
     495          37 :       call broadcast_scalar (f_icespdN, master_task)
     496          37 :       call broadcast_scalar (f_icedirN, master_task)
     497          37 :       call broadcast_scalar (f_uatm, master_task)
     498          37 :       call broadcast_scalar (f_vatm, master_task)
     499          37 :       call broadcast_scalar (f_atmspd, master_task)
     500          37 :       call broadcast_scalar (f_atmdir, master_task)
     501          37 :       call broadcast_scalar (f_sice, master_task)
     502          37 :       call broadcast_scalar (f_fswup, master_task)
     503          37 :       call broadcast_scalar (f_fswdn, master_task)
     504          37 :       call broadcast_scalar (f_flwdn, master_task)
     505          37 :       call broadcast_scalar (f_snow, master_task)
     506          37 :       call broadcast_scalar (f_snow_ai, master_task)
     507          37 :       call broadcast_scalar (f_rain, master_task)
     508          37 :       call broadcast_scalar (f_rain_ai, master_task)
     509          37 :       call broadcast_scalar (f_sst, master_task)
     510          37 :       call broadcast_scalar (f_sss, master_task)
     511          37 :       call broadcast_scalar (f_uocn, master_task)
     512          37 :       call broadcast_scalar (f_vocn, master_task)
     513          37 :       call broadcast_scalar (f_ocnspd, master_task)
     514          37 :       call broadcast_scalar (f_ocndir, master_task)
     515          37 :       call broadcast_scalar (f_frzmlt, master_task)
     516          37 :       call broadcast_scalar (f_fswfac, master_task)
     517          37 :       call broadcast_scalar (f_fswint_ai, master_task)
     518          37 :       call broadcast_scalar (f_fswabs, master_task)
     519          37 :       call broadcast_scalar (f_fswabs_ai, master_task)
     520          37 :       call broadcast_scalar (f_albsni, master_task)
     521          37 :       call broadcast_scalar (f_alvdr, master_task)
     522          37 :       call broadcast_scalar (f_alidr, master_task)
     523          37 :       call broadcast_scalar (f_alvdf, master_task)
     524          37 :       call broadcast_scalar (f_alidf, master_task)
     525          37 :       call broadcast_scalar (f_alvdr_ai, master_task)
     526          37 :       call broadcast_scalar (f_alidr_ai, master_task)
     527          37 :       call broadcast_scalar (f_alvdf_ai, master_task)
     528          37 :       call broadcast_scalar (f_alidf_ai, master_task)
     529          37 :       call broadcast_scalar (f_albice, master_task)
     530          37 :       call broadcast_scalar (f_albsno, master_task)
     531          37 :       call broadcast_scalar (f_albpnd, master_task)
     532          37 :       call broadcast_scalar (f_coszen, master_task)
     533          37 :       call broadcast_scalar (f_flat, master_task)
     534          37 :       call broadcast_scalar (f_flat_ai, master_task)
     535          37 :       call broadcast_scalar (f_fsens, master_task)
     536          37 :       call broadcast_scalar (f_fsens_ai, master_task)
     537          37 :       call broadcast_scalar (f_flwup, master_task)
     538          37 :       call broadcast_scalar (f_flwup_ai, master_task)
     539          37 :       call broadcast_scalar (f_evap, master_task)
     540          37 :       call broadcast_scalar (f_evap_ai, master_task)
     541          37 :       call broadcast_scalar (f_Tair, master_task)
     542          37 :       call broadcast_scalar (f_Tref, master_task)
     543          37 :       call broadcast_scalar (f_Qref, master_task)
     544          37 :       call broadcast_scalar (f_congel, master_task)
     545          37 :       call broadcast_scalar (f_frazil, master_task)
     546          37 :       call broadcast_scalar (f_snoice, master_task)
     547          37 :       call broadcast_scalar (f_dsnow, master_task)
     548          37 :       call broadcast_scalar (f_meltt, master_task)
     549          37 :       call broadcast_scalar (f_melts, master_task)
     550          37 :       call broadcast_scalar (f_meltb, master_task)
     551          37 :       call broadcast_scalar (f_meltl, master_task)
     552          37 :       call broadcast_scalar (f_fresh, master_task)
     553          37 :       call broadcast_scalar (f_fresh_ai, master_task)
     554          37 :       call broadcast_scalar (f_fsalt, master_task)
     555          37 :       call broadcast_scalar (f_fsalt_ai, master_task)
     556          37 :       call broadcast_scalar (f_fbot, master_task)
     557          37 :       call broadcast_scalar (f_fhocn, master_task)
     558          37 :       call broadcast_scalar (f_fhocn_ai, master_task)
     559          37 :       call broadcast_scalar (f_fswthru, master_task)
     560          37 :       call broadcast_scalar (f_fswthru_ai, master_task)
     561          37 :       call broadcast_scalar (f_strairx, master_task)
     562          37 :       call broadcast_scalar (f_strairy, master_task)
     563          37 :       call broadcast_scalar (f_strtltx, master_task)
     564          37 :       call broadcast_scalar (f_strtlty, master_task)
     565          37 :       call broadcast_scalar (f_strcorx, master_task)
     566          37 :       call broadcast_scalar (f_strcory, master_task)
     567          37 :       call broadcast_scalar (f_strocnx, master_task)
     568          37 :       call broadcast_scalar (f_strocny, master_task)
     569          37 :       call broadcast_scalar (f_strintx, master_task)
     570          37 :       call broadcast_scalar (f_strinty, master_task)
     571          37 :       call broadcast_scalar (f_taubx, master_task)
     572          37 :       call broadcast_scalar (f_tauby, master_task)
     573          37 :       call broadcast_scalar (f_strairxN, master_task)
     574          37 :       call broadcast_scalar (f_strairyN, master_task)
     575          37 :       call broadcast_scalar (f_strtltxN, master_task)
     576          37 :       call broadcast_scalar (f_strtltyN, master_task)
     577          37 :       call broadcast_scalar (f_strcorxN, master_task)
     578          37 :       call broadcast_scalar (f_strcoryN, master_task)
     579          37 :       call broadcast_scalar (f_strocnxN, master_task)
     580          37 :       call broadcast_scalar (f_strocnyN, master_task)
     581          37 :       call broadcast_scalar (f_strintxN, master_task)
     582          37 :       call broadcast_scalar (f_strintyN, master_task)
     583          37 :       call broadcast_scalar (f_taubxN, master_task)
     584          37 :       call broadcast_scalar (f_taubyN, master_task)
     585          37 :       call broadcast_scalar (f_strairxE, master_task)
     586          37 :       call broadcast_scalar (f_strairyE, master_task)
     587          37 :       call broadcast_scalar (f_strtltxE, master_task)
     588          37 :       call broadcast_scalar (f_strtltyE, master_task)
     589          37 :       call broadcast_scalar (f_strcorxE, master_task)
     590          37 :       call broadcast_scalar (f_strcoryE, master_task)
     591          37 :       call broadcast_scalar (f_strocnxE, master_task)
     592          37 :       call broadcast_scalar (f_strocnyE, master_task)
     593          37 :       call broadcast_scalar (f_strintxE, master_task)
     594          37 :       call broadcast_scalar (f_strintyE, master_task)
     595          37 :       call broadcast_scalar (f_taubxE, master_task)
     596          37 :       call broadcast_scalar (f_taubyE, master_task)
     597          37 :       call broadcast_scalar (f_strength, master_task)
     598          37 :       call broadcast_scalar (f_divu, master_task)
     599          37 :       call broadcast_scalar (f_shear, master_task)
     600          37 :       call broadcast_scalar (f_sig1, master_task)
     601          37 :       call broadcast_scalar (f_sig2, master_task)
     602          37 :       call broadcast_scalar (f_sigP, master_task)
     603          37 :       call broadcast_scalar (f_dvidtt, master_task)
     604          37 :       call broadcast_scalar (f_dvidtd, master_task)
     605          37 :       call broadcast_scalar (f_daidtt, master_task)
     606          37 :       call broadcast_scalar (f_daidtd, master_task)
     607          37 :       call broadcast_scalar (f_dagedtt, master_task)
     608          37 :       call broadcast_scalar (f_dagedtd, master_task)
     609          37 :       call broadcast_scalar (f_mlt_onset, master_task)
     610          37 :       call broadcast_scalar (f_frz_onset, master_task)
     611          37 :       call broadcast_scalar (f_aisnap, master_task)
     612          37 :       call broadcast_scalar (f_hisnap, master_task)
     613          37 :       call broadcast_scalar (f_sithick, master_task)
     614          37 :       call broadcast_scalar (f_siage, master_task)
     615          37 :       call broadcast_scalar (f_sisnthick, master_task)
     616          37 :       call broadcast_scalar (f_sitemptop, master_task)
     617          37 :       call broadcast_scalar (f_sitempsnic, master_task)
     618          37 :       call broadcast_scalar (f_sitempbot, master_task)
     619          37 :       call broadcast_scalar (f_siu, master_task)
     620          37 :       call broadcast_scalar (f_siv, master_task)
     621          37 :       call broadcast_scalar (f_sidmasstranx, master_task)
     622          37 :       call broadcast_scalar (f_sidmasstrany, master_task)
     623          37 :       call broadcast_scalar (f_sistrxdtop, master_task)
     624          37 :       call broadcast_scalar (f_sistrydtop, master_task)
     625          37 :       call broadcast_scalar (f_sistrxubot, master_task)
     626          37 :       call broadcast_scalar (f_sistryubot, master_task)
     627          37 :       call broadcast_scalar (f_sicompstren, master_task)
     628          37 :       call broadcast_scalar (f_sispeed, master_task)
     629          37 :       call broadcast_scalar (f_sidir, master_task)
     630          37 :       call broadcast_scalar (f_sialb, master_task)
     631          37 :       call broadcast_scalar (f_sihc, master_task)
     632          37 :       call broadcast_scalar (f_sisnhc, master_task)
     633          37 :       call broadcast_scalar (f_sidconcth, master_task)
     634          37 :       call broadcast_scalar (f_sidconcdyn, master_task)
     635          37 :       call broadcast_scalar (f_sidmassth, master_task)
     636          37 :       call broadcast_scalar (f_sidmassdyn, master_task)
     637          37 :       call broadcast_scalar (f_sidmassgrowthwat, master_task)
     638          37 :       call broadcast_scalar (f_sidmassgrowthbot, master_task)
     639          37 :       call broadcast_scalar (f_sidmasssi, master_task)
     640          37 :       call broadcast_scalar (f_sidmassevapsubl, master_task)
     641          37 :       call broadcast_scalar (f_sndmasssubl, master_task)
     642          37 :       call broadcast_scalar (f_sidmassmelttop, master_task)
     643          37 :       call broadcast_scalar (f_sidmassmeltbot, master_task)
     644          37 :       call broadcast_scalar (f_sidmasslat, master_task)
     645          37 :       call broadcast_scalar (f_sndmasssnf, master_task)
     646          37 :       call broadcast_scalar (f_sndmassmelt, master_task)
     647          37 :       call broadcast_scalar (f_siflswdtop, master_task)
     648          37 :       call broadcast_scalar (f_siflswutop, master_task)
     649          37 :       call broadcast_scalar (f_siflswdbot, master_task)
     650          37 :       call broadcast_scalar (f_sifllwdtop, master_task)
     651          37 :       call broadcast_scalar (f_sifllwutop, master_task)
     652          37 :       call broadcast_scalar (f_siflsenstop, master_task)
     653          37 :       call broadcast_scalar (f_siflsensupbot, master_task)
     654          37 :       call broadcast_scalar (f_sifllatstop, master_task)
     655          37 :       call broadcast_scalar (f_siflcondtop, master_task)
     656          37 :       call broadcast_scalar (f_siflcondbot, master_task)
     657          37 :       call broadcast_scalar (f_sipr, master_task)
     658          37 :       call broadcast_scalar (f_sifb, master_task)
     659          37 :       call broadcast_scalar (f_siflsaltbot, master_task)
     660          37 :       call broadcast_scalar (f_siflfwbot, master_task)
     661          37 :       call broadcast_scalar (f_siflfwdrain, master_task)
     662          37 :       call broadcast_scalar (f_siforcetiltx, master_task)
     663          37 :       call broadcast_scalar (f_siforcetilty, master_task)
     664          37 :       call broadcast_scalar (f_siforcecoriolx, master_task)
     665          37 :       call broadcast_scalar (f_siforcecorioly, master_task)
     666          37 :       call broadcast_scalar (f_siforceintstrx, master_task)
     667          37 :       call broadcast_scalar (f_siforceintstry, master_task)
     668          37 :       call broadcast_scalar (f_siitdconc, master_task)
     669          37 :       call broadcast_scalar (f_siitdthick, master_task)
     670          37 :       call broadcast_scalar (f_siitdsnthick, master_task)
     671          37 :       call broadcast_scalar (f_sidragtop, master_task)
     672          37 :       call broadcast_scalar (f_sistreave, master_task)
     673          37 :       call broadcast_scalar (f_sistremax, master_task)
     674          37 :       call broadcast_scalar (f_sirdgthick, master_task)
     675             : 
     676          37 :       call broadcast_scalar (f_aicen, master_task)
     677          37 :       call broadcast_scalar (f_vicen, master_task)
     678          37 :       call broadcast_scalar (f_vsnon, master_task)
     679          37 :       call broadcast_scalar (f_trsig, master_task)
     680          37 :       call broadcast_scalar (f_icepresent, master_task)
     681          37 :       call broadcast_scalar (f_fsurf_ai, master_task)
     682          37 :       call broadcast_scalar (f_fcondtop_ai, master_task)
     683          37 :       call broadcast_scalar (f_fmeltt_ai, master_task)
     684          37 :       call broadcast_scalar (f_fsurfn_ai, master_task)
     685          37 :       call broadcast_scalar (f_fcondtopn_ai, master_task)
     686          37 :       call broadcast_scalar (f_fmelttn_ai, master_task)
     687          37 :       call broadcast_scalar (f_flatn_ai, master_task)
     688          37 :       call broadcast_scalar (f_fsensn_ai, master_task)
     689             : 
     690             : !      call broadcast_scalar (f_field3dz, master_task)
     691          37 :       call broadcast_scalar (f_keffn_top, master_task)
     692          37 :       call broadcast_scalar (f_Tinz, master_task)
     693          37 :       call broadcast_scalar (f_Sinz, master_task)
     694          37 :       call broadcast_scalar (f_Tsnz, master_task)
     695             : 
     696          37 :       call broadcast_scalar (f_iage, master_task)
     697          37 :       call broadcast_scalar (f_FY, master_task)
     698             : 
     699          37 :       call broadcast_scalar (f_a11, master_task)
     700          37 :       call broadcast_scalar (f_a12, master_task)
     701          37 :       call broadcast_scalar (f_e11, master_task)
     702          37 :       call broadcast_scalar (f_e12, master_task)
     703          37 :       call broadcast_scalar (f_e22, master_task)
     704          37 :       call broadcast_scalar (f_s11, master_task)
     705          37 :       call broadcast_scalar (f_s12, master_task)
     706          37 :       call broadcast_scalar (f_s22, master_task)
     707          37 :       call broadcast_scalar (f_yieldstress11, master_task)
     708          37 :       call broadcast_scalar (f_yieldstress12, master_task)
     709          37 :       call broadcast_scalar (f_yieldstress22, master_task)
     710             : 
     711             :       ! 2D variables
     712          74 :       do ns1 = 1, nstreams
     713          74 :       if (histfreq(ns1) /= 'x') then
     714             : 
     715             : !!!!! begin example
     716             : !         call define_hist_field(n_example,"example","m",tstr2D, tcstr, &
     717             : !            "example: mean ice thickness",                           &   ! LCOV_EXCL_LINE
     718             : !            "ice volume per unit grid cell area", c1, c0,            &   ! LCOV_EXCL_LINE
     719             : !            ns1, f_example)
     720             : !!!!! end example
     721             : 
     722             :          call define_hist_field(n_hi,"hi","m",tstr2D, tcstr,        &
     723             :             "grid cell mean ice thickness",                       &   ! LCOV_EXCL_LINE
     724             :             "ice volume per unit grid cell area", c1, c0,         &   ! LCOV_EXCL_LINE
     725          37 :             ns1, f_hi)
     726             : 
     727             :          call define_hist_field(n_hs,"hs","m",tstr2D, tcstr,        &
     728             :              "grid cell mean snow thickness",                     &   ! LCOV_EXCL_LINE
     729             :              "snow volume per unit grid cell area", c1, c0,       &   ! LCOV_EXCL_LINE
     730          37 :              ns1, f_hs)
     731             : 
     732             :          call define_hist_field(n_snowfrac,"snowfrac","1",tstr2D, tcstr, &
     733             :              "grid cell mean snow fraction",                     &   ! LCOV_EXCL_LINE
     734             :              "snow fraction per unit grid cell area", c1, c0,       &   ! LCOV_EXCL_LINE
     735          37 :              ns1, f_snowfrac)
     736             : 
     737             :          call define_hist_field(n_Tsfc,"Tsfc","C",tstr2D, tcstr,    &
     738             :              "snow/ice surface temperature",                      &   ! LCOV_EXCL_LINE
     739             :              "averaged with Tf if no ice is present", c1, c0,     &   ! LCOV_EXCL_LINE
     740          37 :              ns1, f_Tsfc)
     741             : 
     742             :          call define_hist_field(n_aice,"aice","1",tstr2D, tcstr,    &
     743             :              "ice area  (aggregate)",                             &   ! LCOV_EXCL_LINE
     744             :              "none", c1, c0,                                      &   ! LCOV_EXCL_LINE
     745          37 :              ns1, f_aice)
     746             : 
     747             :          call define_hist_field(n_uvelE,"uvelE","m/s",estr2D, ecstr,  &
     748             :              "ice velocity (x)",                                  &   ! LCOV_EXCL_LINE
     749             :              "positive is x direction on E grid", c1, c0,         &   ! LCOV_EXCL_LINE
     750          37 :              ns1, f_uvelE)
     751             : 
     752             :           call define_hist_field(n_vvelE,"vvelE","m/s",estr2D, ecstr,  &
     753             :              "ice velocity (y)",                                  &   ! LCOV_EXCL_LINE
     754             :              "positive is y direction on E grid", c1, c0,         &   ! LCOV_EXCL_LINE
     755          37 :              ns1, f_vvelE)
     756             : 
     757             :          call define_hist_field(n_icespdE,"icespdE","m/s",estr2D, ecstr, &
     758             :              "sea ice speed",                                  &   ! LCOV_EXCL_LINE
     759             :              "vector magnitude on E grid", c1, c0,                       &   ! LCOV_EXCL_LINE
     760          37 :              ns1, f_icespdE)
     761             : 
     762             :          call define_hist_field(n_icedirE,"icedirE","deg",estr2D, ecstr, &
     763             :              "sea ice direction",                              &   ! LCOV_EXCL_LINE
     764             :              "vector direction - coming from on E grid", c1, c0,         &   ! LCOV_EXCL_LINE
     765          37 :              ns1, f_icedirE)
     766             : 
     767             :          call define_hist_field(n_uvelN,"uvelN","m/s",nstr2D, ncstr,  &
     768             :              "ice velocity (x)",                                  &   ! LCOV_EXCL_LINE
     769             :              "positive is x direction on N grid", c1, c0,         &   ! LCOV_EXCL_LINE
     770          37 :              ns1, f_uvelN)
     771             : 
     772             :          call define_hist_field(n_vvelN,"vvelN","m/s",nstr2D, ncstr,  &
     773             :              "ice velocity (y)",                                  &   ! LCOV_EXCL_LINE
     774             :              "positive is y direction on N grid", c1, c0,         &   ! LCOV_EXCL_LINE
     775          37 :              ns1, f_vvelN)
     776             : 
     777             :          call define_hist_field(n_icespdN,"icespdN","m/s",nstr2D, ncstr, &
     778             :              "sea ice speed",                                  &   ! LCOV_EXCL_LINE
     779             :              "vector magnitude on N grid", c1, c0,                       &   ! LCOV_EXCL_LINE
     780          37 :              ns1, f_icespdN)
     781             : 
     782             :          call define_hist_field(n_icedirN,"icedirN","deg",nstr2D, ncstr, &
     783             :              "sea ice direction",                              &   ! LCOV_EXCL_LINE
     784             :              "vector direction - coming from on N grid", c1, c0,         &   ! LCOV_EXCL_LINE
     785          37 :              ns1, f_icedirN)
     786             : 
     787             :          call define_hist_field(n_uvel,"uvel","m/s",ustr2D, ucstr,  &
     788             :              "ice velocity (x)",                                  &   ! LCOV_EXCL_LINE
     789             :              "positive is x direction on U grid", c1, c0,         &   ! LCOV_EXCL_LINE
     790          37 :              ns1, f_uvel)
     791             : 
     792             :          call define_hist_field(n_vvel,"vvel","m/s",ustr2D, ucstr,  &
     793             :              "ice velocity (y)",                                  &   ! LCOV_EXCL_LINE
     794             :              "positive is y direction on U grid", c1, c0,         &   ! LCOV_EXCL_LINE
     795          37 :              ns1, f_vvel)
     796             : 
     797             :          call define_hist_field(n_icespd,"icespd","m/s",ustr2D, ucstr, &
     798             :              "sea ice speed",                                  &   ! LCOV_EXCL_LINE
     799             :              "vector magnitude", c1, c0,                               &   ! LCOV_EXCL_LINE
     800          37 :              ns1, f_icespd)
     801             : 
     802             :          call define_hist_field(n_icedir,"icedir","deg",ustr2D, ucstr, &
     803             :              "sea ice direction",                              &   ! LCOV_EXCL_LINE
     804             :              "vector direction - coming from", c1, c0,                 &   ! LCOV_EXCL_LINE
     805          37 :              ns1, f_icedir)
     806             : 
     807             :          call define_hist_field(n_uatm,"uatm","m/s",str2D_gau, cstr_gau,  &
     808             :              "atm velocity (x)",                                  &   ! LCOV_EXCL_LINE
     809             :              "positive is x direction on U grid", c1, c0,         &   ! LCOV_EXCL_LINE
     810          37 :              ns1, f_uatm)
     811             : 
     812             :          call define_hist_field(n_vatm,"vatm","m/s",str2D_gav, cstr_gav,  &
     813             :              "atm velocity (y)",                                  &   ! LCOV_EXCL_LINE
     814             :              "positive is y direction on U grid", c1, c0,         &   ! LCOV_EXCL_LINE
     815          37 :              ns1, f_vatm)
     816             : 
     817             :          call define_hist_field(n_atmspd,"atmspd","m/s",str2D_gau, cstr_gau, &
     818             :              "atmosphere wind speed",                                  &   ! LCOV_EXCL_LINE
     819             :              "vector magnitude", c1, c0,                               &   ! LCOV_EXCL_LINE
     820          37 :              ns1, f_atmspd)
     821             : 
     822             :          call define_hist_field(n_atmdir,"atmdir","deg",str2D_gau, cstr_gau, &
     823             :              "atmosphere wind direction",                              &   ! LCOV_EXCL_LINE
     824             :              "vector direction - coming from", c1, c0,                 &   ! LCOV_EXCL_LINE
     825          37 :              ns1, f_atmdir)
     826             : 
     827             :          call define_hist_field(n_sice,"sice","ppt",tstr2D, tcstr,  &
     828             :              "bulk ice salinity",                                 &   ! LCOV_EXCL_LINE
     829             :              "none", c1, c0,                                      &   ! LCOV_EXCL_LINE
     830          37 :              ns1, f_sice)
     831             : 
     832             :          call define_hist_field(n_fswup,"fswup","W/m^2",tstr2D, tcstr, &
     833             :              "upward solar flux",                                      &   ! LCOV_EXCL_LINE
     834             :              "positive upward", c1, c0,                            &   ! LCOV_EXCL_LINE
     835          37 :              ns1, f_fswup)
     836             : 
     837             :          call define_hist_field(n_fswdn,"fswdn","W/m^2",tstr2D, tcstr, &
     838             :              "down solar flux",                                      &   ! LCOV_EXCL_LINE
     839             :              "positive downward", c1, c0,                            &   ! LCOV_EXCL_LINE
     840          37 :              ns1, f_fswdn)
     841             : 
     842             :          call define_hist_field(n_flwdn,"flwdn","W/m^2",tstr2D, tcstr, &
     843             :              "down longwave flux",                                   &   ! LCOV_EXCL_LINE
     844             :              "positive downward", c1, c0,                            &   ! LCOV_EXCL_LINE
     845          37 :              ns1, f_flwdn)
     846             : 
     847             :          call define_hist_field(n_snow,"snow","cm/day",tstr2D, tcstr, &
     848             :              "snowfall rate (cpl)",                                 &   ! LCOV_EXCL_LINE
     849             :              "none", mps_to_cmpdy/rhofresh, c0,                     &   ! LCOV_EXCL_LINE
     850          37 :              ns1, f_snow)
     851             : 
     852             :          call define_hist_field(n_snow_ai,"snow_ai","cm/day",tstr2D, tcstr, &
     853             :              "snowfall rate",                                             &   ! LCOV_EXCL_LINE
     854             :              "weighted by ice area", mps_to_cmpdy/rhofresh, c0,           &   ! LCOV_EXCL_LINE
     855          37 :              ns1, f_snow_ai)
     856             : 
     857             :          call define_hist_field(n_rain,"rain","cm/day",tstr2D, tcstr, &
     858             :              "rainfall rate (cpl)",                                 &   ! LCOV_EXCL_LINE
     859             :              "none", mps_to_cmpdy/rhofresh, c0,                     &   ! LCOV_EXCL_LINE
     860          37 :              ns1, f_rain)
     861             : 
     862             :          call define_hist_field(n_rain_ai,"rain_ai","cm/day",tstr2D, tcstr, &
     863             :              "rainfall rate",                                             &   ! LCOV_EXCL_LINE
     864             :              "weighted by ice area", mps_to_cmpdy/rhofresh, c0,           &   ! LCOV_EXCL_LINE
     865          37 :              ns1, f_rain_ai)
     866             : 
     867             :          call define_hist_field(n_sst,"sst","C",tstr2D, tcstr, &
     868             :              "sea surface temperature",                      &   ! LCOV_EXCL_LINE
     869             :              "none", c1, c0,                                 &   ! LCOV_EXCL_LINE
     870          37 :              ns1, f_sst)
     871             : 
     872             :          call define_hist_field(n_sss,"sss","ppt",tstr2D, tcstr, &
     873             :              "sea surface salinity",                           &   ! LCOV_EXCL_LINE
     874             :              "none", c1, c0,                                   &   ! LCOV_EXCL_LINE
     875          37 :              ns1, f_sss)
     876             : 
     877             :          call define_hist_field(n_uocn,"uocn","m/s",str2D_gou, cstr_gou, &
     878             :              "ocean current (x)",                                &   ! LCOV_EXCL_LINE
     879             :              "positive is x direction on U grid", c1, c0,        &   ! LCOV_EXCL_LINE
     880          37 :              ns1, f_uocn)
     881             : 
     882             :          call define_hist_field(n_vocn,"vocn","m/s",str2D_gov, cstr_gov, &
     883             :              "ocean current (y)",                                &   ! LCOV_EXCL_LINE
     884             :              "positive is y direction on U grid", c1, c0,        &   ! LCOV_EXCL_LINE
     885          37 :              ns1, f_vocn)
     886             : 
     887             :          call define_hist_field(n_ocnspd,"ocnspd","m/s",str2D_gou, cstr_gou, &
     888             :              "ocean current speed",                                    &   ! LCOV_EXCL_LINE
     889             :              "vector magnitude", c1, c0,                               &   ! LCOV_EXCL_LINE
     890          37 :              ns1, f_ocnspd)
     891             : 
     892             :          call define_hist_field(n_ocndir,"ocndir","deg",str2D_gou, cstr_gou, &
     893             :              "ocean current direction",                                &   ! LCOV_EXCL_LINE
     894             :              "vector direction - going to", c1, c0,                    &   ! LCOV_EXCL_LINE
     895          37 :              ns1, f_ocndir)
     896             : 
     897             :          call define_hist_field(n_frzmlt,"frzmlt","W/m^2",tstr2D, tcstr, &
     898             :              "freeze/melt potential",                                  &   ! LCOV_EXCL_LINE
     899             :              "if >0, new ice forms; if <0, ice melts", c1, c0,         &   ! LCOV_EXCL_LINE
     900          37 :              ns1, f_frzmlt)
     901             : 
     902             :          call define_hist_field(n_fswfac,"scale_factor","1",tstr2D, tcstr, &
     903             :              "shortwave scaling factor",                           &   ! LCOV_EXCL_LINE
     904             :              "ratio of netsw new:old", c1, c0,                     &   ! LCOV_EXCL_LINE
     905          37 :              ns1, f_fswfac)
     906             : 
     907             :          call define_hist_field(n_fswint_ai,"fswint_ai","W/m^2",tstr2D, tcstr, &
     908             :              "shortwave absorbed in ice interior",                             &   ! LCOV_EXCL_LINE
     909             :              "does not include surface", c1, c0,                               &   ! LCOV_EXCL_LINE
     910          37 :              ns1, f_fswint_ai)
     911             : 
     912             :          call define_hist_field(n_fswabs,"fswabs","W/m^2",tstr2D, tcstr, &
     913             :              "snow/ice/ocn absorbed solar flux (cpl)",                 &   ! LCOV_EXCL_LINE
     914             :              "positive downward", c1, c0,                              &   ! LCOV_EXCL_LINE
     915          37 :              ns1, f_fswabs)
     916             : 
     917             :          call define_hist_field(n_fswabs_ai,"fswabs_ai","W/m^2",tstr2D, tcstr, &
     918             :              "snow/ice/ocn absorbed solar flux",                             &   ! LCOV_EXCL_LINE
     919             :              "weighted by ice area", c1, c0,                                 &   ! LCOV_EXCL_LINE
     920          37 :              ns1, f_fswabs_ai)
     921             : 
     922             :          call define_hist_field(n_albsni,"albsni","%",tstr2D, tcstr, &
     923             :              "snow/ice broad band albedo",                         &   ! LCOV_EXCL_LINE
     924             :              "averaged for coszen>0, weighted by aice", c100, c0,  &   ! LCOV_EXCL_LINE
     925          37 :              ns1, f_albsni)
     926             : 
     927             :          call define_hist_field(n_alvdr,"alvdr","%",tstr2D, tcstr, &
     928             :              "visible direct albedo",                            &   ! LCOV_EXCL_LINE
     929             :              "scaled (divided) by aice", c100, c0,               &   ! LCOV_EXCL_LINE
     930          37 :              ns1, f_alvdr)
     931             : 
     932             :          call define_hist_field(n_alidr,"alidr","%",tstr2D, tcstr, &
     933             :              "near IR direct albedo",                            &   ! LCOV_EXCL_LINE
     934             :              "scaled (divided) by aice", c100, c0,               &   ! LCOV_EXCL_LINE
     935          37 :              ns1, f_alidr)
     936             : 
     937             :          call define_hist_field(n_alvdf,"alvdf","%",tstr2D, tcstr, &
     938             :              "visible diffuse albedo",                            &   ! LCOV_EXCL_LINE
     939             :              "scaled (divided) by aice", c100, c0,               &   ! LCOV_EXCL_LINE
     940          37 :              ns1, f_alvdf)
     941             : 
     942             :          call define_hist_field(n_alidf,"alidf","%",tstr2D, tcstr, &
     943             :              "near IR diffuse albedo",                            &   ! LCOV_EXCL_LINE
     944             :              "scaled (divided) by aice", c100, c0,               &   ! LCOV_EXCL_LINE
     945          37 :              ns1, f_alidf)
     946             : 
     947             :          call define_hist_field(n_alvdr_ai,"alvdr_ai","%",tstr2D, tcstr, &
     948             :              "visible direct albedo",                            &   ! LCOV_EXCL_LINE
     949             :              " ", c100, c0,               &   ! LCOV_EXCL_LINE
     950          37 :              ns1, f_alvdr_ai)
     951             : 
     952             :          call define_hist_field(n_alidr_ai,"alidr_ai","%",tstr2D, tcstr, &
     953             :              "near IR direct albedo",                            &   ! LCOV_EXCL_LINE
     954             :              " ", c100, c0,               &   ! LCOV_EXCL_LINE
     955          37 :              ns1, f_alidr_ai)
     956             : 
     957             :          call define_hist_field(n_alvdf_ai,"alvdf_ai","%",tstr2D, tcstr, &
     958             :              "visible diffuse albedo",                            &   ! LCOV_EXCL_LINE
     959             :              " ", c100, c0,               &   ! LCOV_EXCL_LINE
     960          37 :              ns1, f_alvdf_ai)
     961             : 
     962             :          call define_hist_field(n_alidf_ai,"alidf_ai","%",tstr2D, tcstr, &
     963             :              "near IR diffuse albedo",                            &   ! LCOV_EXCL_LINE
     964             :              " ", c100, c0,               &   ! LCOV_EXCL_LINE
     965          37 :              ns1, f_alidf_ai)
     966             : 
     967             :          call define_hist_field(n_albice,"albice","%",tstr2D, tcstr, &
     968             :              "bare ice albedo",                                    &   ! LCOV_EXCL_LINE
     969             :              "averaged for coszen>0, weighted by aice", c100, c0,  &   ! LCOV_EXCL_LINE
     970          37 :              ns1, f_albice)
     971             : 
     972             :          call define_hist_field(n_albsno,"albsno","%",tstr2D, tcstr, &
     973             :              "snow albedo",                                        &   ! LCOV_EXCL_LINE
     974             :              "averaged for coszen>0, weighted by aice", c100, c0,  &   ! LCOV_EXCL_LINE
     975          37 :              ns1, f_albsno)
     976             : 
     977             :          call define_hist_field(n_albpnd,"albpnd","%",tstr2D, tcstr, &
     978             :              "melt pond albedo",                                   &   ! LCOV_EXCL_LINE
     979             :              "averaged for coszen>0, weighted by aice", c100, c0,  &   ! LCOV_EXCL_LINE
     980          37 :              ns1, f_albpnd)
     981             : 
     982             :          call define_hist_field(n_coszen,"coszen","radian",tstr2D, tcstr, &
     983             :              "cosine of the zenith angle",                              &   ! LCOV_EXCL_LINE
     984             :              "negative below horizon", c1, c0,                          &   ! LCOV_EXCL_LINE
     985          37 :              ns1, f_coszen)
     986             : 
     987             :          call define_hist_field(n_flat,"flat","W/m^2",tstr2D, tcstr, &
     988             :              "latent heat flux (cpl)",                             &   ! LCOV_EXCL_LINE
     989             :              "positive downward", c1, c0,                          &   ! LCOV_EXCL_LINE
     990          37 :              ns1, f_flat)
     991             : 
     992             :          call define_hist_field(n_flat_ai,"flat_ai","W/m^2",tstr2D, tcstr, &
     993             :              "latent heat flux",                                         &   ! LCOV_EXCL_LINE
     994             :              "weighted by ice area", c1, c0,                             &   ! LCOV_EXCL_LINE
     995          37 :              ns1, f_flat_ai)
     996             : 
     997             :          call define_hist_field(n_fsens,"fsens","W/m^2",tstr2D, tcstr, &
     998             :              "sensible heat flux (cpl)",                             &   ! LCOV_EXCL_LINE
     999             :              "positive downward", c1, c0,                            &   ! LCOV_EXCL_LINE
    1000          37 :              ns1, f_fsens)
    1001             : 
    1002             :          call define_hist_field(n_fsens_ai,"fsens_ai","W/m^2",tstr2D, tcstr, &
    1003             :              "sensible heat flux",                                         &   ! LCOV_EXCL_LINE
    1004             :              "weighted by ice area", c1, c0,                               &   ! LCOV_EXCL_LINE
    1005          37 :              ns1, f_fsens_ai)
    1006             : 
    1007             :          call define_hist_field(n_flwup,"flwup","W/m^2",tstr2D, tcstr, &
    1008             :              "upward longwave flux (cpl)",                           &   ! LCOV_EXCL_LINE
    1009             :              "positive downward", c1, c0,                            &   ! LCOV_EXCL_LINE
    1010          37 :              ns1, f_flwup)
    1011             : 
    1012             :          call define_hist_field(n_flwup_ai,"flwup_ai","W/m^2",tstr2D, tcstr, &
    1013             :              "upward longwave flux",                                       &   ! LCOV_EXCL_LINE
    1014             :              "weighted by ice area", c1, c0,                               &   ! LCOV_EXCL_LINE
    1015          37 :              ns1, f_flwup_ai)
    1016             : 
    1017             :          call define_hist_field(n_evap,"evap","cm/day",tstr2D, tcstr, &
    1018             :              "evaporative water flux (cpl)",                        &   ! LCOV_EXCL_LINE
    1019             :              "none", mps_to_cmpdy/rhofresh, c0,                     &   ! LCOV_EXCL_LINE
    1020          37 :              ns1, f_evap)
    1021             : 
    1022             :          call define_hist_field(n_evap_ai,"evap_ai","cm/day",tstr2D, tcstr, &
    1023             :              "evaporative water flux",                                    &   ! LCOV_EXCL_LINE
    1024             :              "weighted by ice area", mps_to_cmpdy/rhofresh, c0,           &   ! LCOV_EXCL_LINE
    1025          37 :              ns1, f_evap_ai)
    1026             : 
    1027             :          call define_hist_field(n_Tair,"Tair","C",tstr2D, tcstr, &
    1028             :              "air temperature",                                &   ! LCOV_EXCL_LINE
    1029             :              "none", c1, -Tffresh,                             &   ! LCOV_EXCL_LINE
    1030          37 :              ns1, f_Tair)
    1031             : 
    1032             :          call define_hist_field(n_Tref,"Tref","C",tstr2D, tcstr, &
    1033             :              "2m reference temperature",                       &   ! LCOV_EXCL_LINE
    1034             :              "none", c1, -Tffresh,                             &   ! LCOV_EXCL_LINE
    1035          37 :              ns1, f_Tref)
    1036             : 
    1037             :          call define_hist_field(n_Qref,"Qref","g/kg",tstr2D, tcstr, &
    1038             :              "2m reference specific humidity",                    &   ! LCOV_EXCL_LINE
    1039             :              "none", kg_to_g, c0,                                 &   ! LCOV_EXCL_LINE
    1040          37 :              ns1, f_Qref)
    1041             : 
    1042             :          call define_hist_field(n_congel,"congel","cm/day",tstr2D, tcstr, &
    1043             :              "congelation ice growth",                                  &   ! LCOV_EXCL_LINE
    1044             :              "none", mps_to_cmpdy/dt, c0,                               &   ! LCOV_EXCL_LINE
    1045          37 :              ns1, f_congel)
    1046             : 
    1047             :          call define_hist_field(n_frazil,"frazil","cm/day",tstr2D, tcstr, &
    1048             :              "frazil ice growth",                                       &   ! LCOV_EXCL_LINE
    1049             :              "none", mps_to_cmpdy/dt, c0,                               &   ! LCOV_EXCL_LINE
    1050          37 :              ns1, f_frazil)
    1051             : 
    1052             :          call define_hist_field(n_snoice,"snoice","cm/day",tstr2D, tcstr, &
    1053             :              "snow-ice formation",                                      &   ! LCOV_EXCL_LINE
    1054             :              "none", mps_to_cmpdy/dt, c0,                               &   ! LCOV_EXCL_LINE
    1055          37 :              ns1, f_snoice)
    1056             : 
    1057             :          call define_hist_field(n_dsnow,"dsnow","cm/day",tstr2D, tcstr, &
    1058             :              "snow formation",                                      &   ! LCOV_EXCL_LINE
    1059             :              "none", mps_to_cmpdy/dt, c0,                               &   ! LCOV_EXCL_LINE
    1060          37 :              ns1, f_dsnow)
    1061             : 
    1062             :          call define_hist_field(n_meltt,"meltt","cm/day",tstr2D, tcstr, &
    1063             :              "top ice melt",                                          &   ! LCOV_EXCL_LINE
    1064             :              "none", mps_to_cmpdy/dt, c0,                             &   ! LCOV_EXCL_LINE
    1065          37 :              ns1, f_meltt)
    1066             : 
    1067             :          call define_hist_field(n_melts,"melts","cm/day",tstr2D, tcstr, &
    1068             :              "top snow melt",                                          &   ! LCOV_EXCL_LINE
    1069             :              "none", mps_to_cmpdy/dt, c0,                             &   ! LCOV_EXCL_LINE
    1070          37 :              ns1, f_melts)
    1071             : 
    1072             :          call define_hist_field(n_meltb,"meltb","cm/day",tstr2D, tcstr, &
    1073             :              "basal ice melt",                                        &   ! LCOV_EXCL_LINE
    1074             :              "none", mps_to_cmpdy/dt, c0,                             &   ! LCOV_EXCL_LINE
    1075          37 :              ns1, f_meltb)
    1076             : 
    1077             :          call define_hist_field(n_meltl,"meltl","cm/day",tstr2D, tcstr, &
    1078             :              "lateral ice melt",                                      &   ! LCOV_EXCL_LINE
    1079             :              "none", mps_to_cmpdy/dt, c0,                             &   ! LCOV_EXCL_LINE
    1080          37 :              ns1, f_meltl)
    1081             : 
    1082             :          call define_hist_field(n_fresh,"fresh","cm/day",tstr2D, tcstr,   &
    1083             :              "freshwtr flx ice to ocn (cpl)",                           &   ! LCOV_EXCL_LINE
    1084             :              "if positive, ocean gains fresh water",                    &   ! LCOV_EXCL_LINE
    1085             :              mps_to_cmpdy/rhofresh, c0,                                 &   ! LCOV_EXCL_LINE
    1086          37 :              ns1, f_fresh)
    1087             : 
    1088             :          call define_hist_field(n_fresh_ai,"fresh_ai","cm/day",tstr2D, tcstr, &
    1089             :              "freshwtr flx ice to ocn",                                     &   ! LCOV_EXCL_LINE
    1090             :              "weighted by ice area", mps_to_cmpdy/rhofresh, c0,             &   ! LCOV_EXCL_LINE
    1091          37 :              ns1, f_fresh_ai)
    1092             : 
    1093             :          call define_hist_field(n_fsalt,"fsalt","kg/m^2/s",tstr2D, tcstr, &
    1094             :              "salt flux ice to ocn (cpl)",                              &   ! LCOV_EXCL_LINE
    1095             :              "if positive, ocean gains salt", c1, c0,                   &   ! LCOV_EXCL_LINE
    1096          37 :              ns1, f_fsalt)
    1097             : 
    1098             :          call define_hist_field(n_fsalt_ai,"fsalt_ai","kg/m^2/s",tstr2D, tcstr, &
    1099             :              "salt flux ice to ocean",                                        &   ! LCOV_EXCL_LINE
    1100             :              "weighted by ice area", c1, c0,                                  &   ! LCOV_EXCL_LINE
    1101          37 :              ns1, f_fsalt_ai)
    1102             : 
    1103             :          call define_hist_field(n_fbot,"fbot","W/m^2",tstr2D, tcstr, &
    1104             :              "heat flux ice to ocean (fbot)",                        &   ! LCOV_EXCL_LINE
    1105             :              "if positive, ocean gains heat", c1, c0,                &   ! LCOV_EXCL_LINE
    1106          37 :              ns1, f_fbot)
    1107             : 
    1108             :          call define_hist_field(n_fhocn,"fhocn","W/m^2",tstr2D, tcstr, &
    1109             :              "heat flux ice to ocn (cpl)",                           &   ! LCOV_EXCL_LINE
    1110             :              "if positive, ocean gains heat", c1, c0,                &   ! LCOV_EXCL_LINE
    1111          37 :              ns1, f_fhocn)
    1112             : 
    1113             :          call define_hist_field(n_fhocn_ai,"fhocn_ai","W/m^2",tstr2D, tcstr, &
    1114             :              "heat flux ice to ocean (fhocn_ai)",                          &   ! LCOV_EXCL_LINE
    1115             :              "weighted by ice area", c1, c0,                               &   ! LCOV_EXCL_LINE
    1116          37 :              ns1, f_fhocn_ai)
    1117             : 
    1118             :          call define_hist_field(n_fswthru,"fswthru","W/m^2",tstr2D, tcstr, &
    1119             :              "SW thru ice to ocean (cpl)",                               &   ! LCOV_EXCL_LINE
    1120             :              "if positive, ocean gains heat", c1, c0,                    &   ! LCOV_EXCL_LINE
    1121          37 :              ns1, f_fswthru)
    1122             : 
    1123             :          call define_hist_field(n_fswthru_ai,"fswthru_ai","W/m^2",tstr2D, tcstr,&
    1124             :              "SW flux thru ice to ocean",                                     &   ! LCOV_EXCL_LINE
    1125             :              "weighted by ice area", c1, c0,                                  &   ! LCOV_EXCL_LINE
    1126          37 :              ns1, f_fswthru_ai)
    1127             : 
    1128             :          call define_hist_field(n_strairx,"strairx","N/m^2",ustr2D, ucstr, &
    1129             :              "atm/ice stress (x)",                                       &   ! LCOV_EXCL_LINE
    1130             :              "positive is x direction on U grid", c1, c0,                &   ! LCOV_EXCL_LINE
    1131          37 :              ns1, f_strairx)
    1132             : 
    1133             :          call define_hist_field(n_strairy,"strairy","N/m^2",ustr2D, ucstr, &
    1134             :              "atm/ice stress (y)",                                       &   ! LCOV_EXCL_LINE
    1135             :              "positive is y direction on U grid", c1, c0,                &   ! LCOV_EXCL_LINE
    1136          37 :              ns1, f_strairy)
    1137             : 
    1138             :          call define_hist_field(n_strtltx,"strtltx","N/m^2",ustr2D, ucstr, &
    1139             :              "sea sfc tilt stress (x)",                                  &   ! LCOV_EXCL_LINE
    1140             :              "none", c1, c0,                                             &   ! LCOV_EXCL_LINE
    1141          37 :              ns1, f_strtltx)
    1142             : 
    1143             :          call define_hist_field(n_strtlty,"strtlty","N/m^2",ustr2D, ucstr, &
    1144             :              "sea sfc tilt stress (y)",                                  &   ! LCOV_EXCL_LINE
    1145             :              "none", c1, c0,                                             &   ! LCOV_EXCL_LINE
    1146          37 :              ns1, f_strtlty)
    1147             : 
    1148             :          call define_hist_field(n_strcorx,"strcorx","N/m^2",ustr2D, ucstr, &
    1149             :              "coriolis stress (x)",                                      &   ! LCOV_EXCL_LINE
    1150             :              "positive is x direction on U grid", c1, c0,                &   ! LCOV_EXCL_LINE
    1151          37 :              ns1, f_strcorx)
    1152             : 
    1153             :          call define_hist_field(n_strcory,"strcory","N/m^2",ustr2D, ucstr, &
    1154             :              "coriolis stress (y)",                                      &   ! LCOV_EXCL_LINE
    1155             :              "positive is y direction on U grid", c1, c0,                &   ! LCOV_EXCL_LINE
    1156          37 :              ns1, f_strcory)
    1157             : 
    1158             :          call define_hist_field(n_strocnx,"strocnx","N/m^2",ustr2D, ucstr, &
    1159             :              "ocean/ice stress (x)",                                     &   ! LCOV_EXCL_LINE
    1160             :              "positive is x direction on U grid", c1, c0,                &   ! LCOV_EXCL_LINE
    1161          37 :              ns1, f_strocnx)
    1162             : 
    1163             :          call define_hist_field(n_strocny,"strocny","N/m^2",ustr2D, ucstr, &
    1164             :              "ocean/ice stress (y)",                                     &   ! LCOV_EXCL_LINE
    1165             :              "positive is y direction on U grid", c1, c0,                &   ! LCOV_EXCL_LINE
    1166          37 :              ns1, f_strocny)
    1167             : 
    1168             :          call define_hist_field(n_strintx,"strintx","N/m^2",ustr2D, ucstr, &
    1169             :              "internal ice stress (x)",                                  &   ! LCOV_EXCL_LINE
    1170             :              "positive is x direction on U grid", c1, c0,                &   ! LCOV_EXCL_LINE
    1171          37 :              ns1, f_strintx)
    1172             : 
    1173             :          call define_hist_field(n_strinty,"strinty","N/m^2",ustr2D, ucstr, &
    1174             :              "internal ice stress (y)",                                  &   ! LCOV_EXCL_LINE
    1175             :              "positive is y direction on U grid", c1, c0,                &   ! LCOV_EXCL_LINE
    1176          37 :              ns1, f_strinty)
    1177             : 
    1178             :          call define_hist_field(n_taubx,"taubx","N/m^2",ustr2D, ucstr,   &
    1179             :              "seabed (basal) stress (x)",                                &   ! LCOV_EXCL_LINE
    1180             :              "positive is x direction on U grid", c1, c0,                &   ! LCOV_EXCL_LINE
    1181          37 :              ns1, f_taubx)
    1182             : 
    1183             :          call define_hist_field(n_tauby,"tauby","N/m^2",ustr2D, ucstr,   &
    1184             :              "seabed (basal) stress (y)",                                &   ! LCOV_EXCL_LINE
    1185             :              "positive is y direction on U grid", c1, c0,                &   ! LCOV_EXCL_LINE
    1186          37 :              ns1, f_tauby)
    1187             : 
    1188             :          call define_hist_field(n_strairxN,"strairxN","N/m^2",nstr2D, ncstr, &
    1189             :              "atm/ice stress (x)",                                       &   ! LCOV_EXCL_LINE
    1190             :              "positive is x direction on N grid", c1, c0,                &   ! LCOV_EXCL_LINE
    1191          37 :              ns1, f_strairxN)
    1192             : 
    1193             :          call define_hist_field(n_strairyN,"strairyN","N/m^2",nstr2D, ncstr, &
    1194             :              "atm/ice stress (y)",                                       &   ! LCOV_EXCL_LINE
    1195             :              "positive is y direction on N grid", c1, c0,                &   ! LCOV_EXCL_LINE
    1196          37 :              ns1, f_strairyN)
    1197             : 
    1198             :          call define_hist_field(n_strairxE,"strairxE","N/m^2",estr2D, ecstr, &
    1199             :              "atm/ice stress (x)",                                       &   ! LCOV_EXCL_LINE
    1200             :              "positive is x direction on E grid", c1, c0,                &   ! LCOV_EXCL_LINE
    1201          37 :              ns1, f_strairxE)
    1202             : 
    1203             :          call define_hist_field(n_strairyE,"strairyE","N/m^2",estr2D, ecstr, &
    1204             :              "atm/ice stress (y)",                                       &   ! LCOV_EXCL_LINE
    1205             :              "positive is y direction on E grid", c1, c0,                &   ! LCOV_EXCL_LINE
    1206          37 :              ns1, f_strairyE)
    1207             : 
    1208             :          call define_hist_field(n_strtltxN,"strtltxN","N/m^2",nstr2D, ncstr, &
    1209             :              "sea sfc tilt stress (x)",                                  &   ! LCOV_EXCL_LINE
    1210             :              "positive is x direction on N grid", c1, c0,                &   ! LCOV_EXCL_LINE
    1211          37 :              ns1, f_strtltxN)
    1212             : 
    1213             :          call define_hist_field(n_strtltyN,"strtltyN","N/m^2",nstr2D, ncstr, &
    1214             :              "sea sfc tilt stress (y)",                                  &   ! LCOV_EXCL_LINE
    1215             :              "positive is y direction on N grid", c1, c0,                &   ! LCOV_EXCL_LINE
    1216          37 :              ns1, f_strtltyN)
    1217             : 
    1218             :          call define_hist_field(n_strtltxE,"strtltxE","N/m^2",estr2D, ecstr, &
    1219             :              "sea sfc tilt stress (x)",                                  &   ! LCOV_EXCL_LINE
    1220             :              "positive is x direction on E grid", c1, c0,                &   ! LCOV_EXCL_LINE
    1221          37 :              ns1, f_strtltxE)
    1222             : 
    1223             :          call define_hist_field(n_strtltyE,"strtltyE","N/m^2",estr2D, ecstr, &
    1224             :              "sea sfc tilt stress (y)",                                  &   ! LCOV_EXCL_LINE
    1225             :              "positive is y direction on E grid", c1, c0,                &   ! LCOV_EXCL_LINE
    1226          37 :              ns1, f_strtltyE)
    1227             : 
    1228             :          call define_hist_field(n_strcorxN,"strcorxN","N/m^2",nstr2D, ncstr, &
    1229             :              "coriolis stress (x)",                                      &   ! LCOV_EXCL_LINE
    1230             :              "positive is x direction on N grid", c1, c0,                &   ! LCOV_EXCL_LINE
    1231          37 :              ns1, f_strcorxN)
    1232             : 
    1233             :          call define_hist_field(n_strcoryN,"strcoryN","N/m^2",nstr2D, ncstr, &
    1234             :              "coriolis stress (y)",                                      &   ! LCOV_EXCL_LINE
    1235             :              "positive is y direction on N grid", c1, c0,                &   ! LCOV_EXCL_LINE
    1236          37 :              ns1, f_strcoryN)
    1237             : 
    1238             :          call define_hist_field(n_strcorxE,"strcorxE","N/m^2",estr2D, ecstr, &
    1239             :              "coriolis stress (x)",                                      &   ! LCOV_EXCL_LINE
    1240             :              "positive is x direction on E grid", c1, c0,                &   ! LCOV_EXCL_LINE
    1241          37 :              ns1, f_strcorxE)
    1242             : 
    1243             :          call define_hist_field(n_strcoryE,"strcoryE","N/m^2",estr2D, ecstr, &
    1244             :              "coriolis stress (y)",                                      &   ! LCOV_EXCL_LINE
    1245             :              "positive is y direction on E grid", c1, c0,                &   ! LCOV_EXCL_LINE
    1246          37 :              ns1, f_strcoryE)
    1247             : 
    1248             :          call define_hist_field(n_strocnxN,"strocnxN","N/m^2",nstr2D, ncstr, &
    1249             :              "ocean/ice stress (x)",                                     &   ! LCOV_EXCL_LINE
    1250             :              "positive is x direction on N grid", c1, c0,                &   ! LCOV_EXCL_LINE
    1251          37 :              ns1, f_strocnxN)
    1252             : 
    1253             :          call define_hist_field(n_strocnyN,"strocnyN","N/m^2",nstr2D, ncstr, &
    1254             :              "ocean/ice stress (y)",                                     &   ! LCOV_EXCL_LINE
    1255             :              "positive is y direction on N grid", c1, c0,                &   ! LCOV_EXCL_LINE
    1256          37 :              ns1, f_strocnyN)
    1257             : 
    1258             :          call define_hist_field(n_strocnxE,"strocnxE","N/m^2",estr2D, ecstr, &
    1259             :              "ocean/ice stress (x)",                                     &   ! LCOV_EXCL_LINE
    1260             :              "positive is x direction on E grid", c1, c0,                &   ! LCOV_EXCL_LINE
    1261          37 :              ns1, f_strocnxE)
    1262             : 
    1263             :          call define_hist_field(n_strocnyE,"strocnyE","N/m^2",estr2D, ecstr, &
    1264             :              "ocean/ice stress (y)",                                     &   ! LCOV_EXCL_LINE
    1265             :              "positive is y direction on E grid", c1, c0,                &   ! LCOV_EXCL_LINE
    1266          37 :              ns1, f_strocnyE)
    1267             : 
    1268             :          call define_hist_field(n_strintxN,"strintxN","N/m^2",nstr2D, ncstr, &
    1269             :              "internal ice stress (x)",                                  &   ! LCOV_EXCL_LINE
    1270             :              "positive is x direction on N grid", c1, c0,                &   ! LCOV_EXCL_LINE
    1271          37 :              ns1, f_strintxN)
    1272             : 
    1273             :          call define_hist_field(n_strintyN,"strintyN","N/m^2",nstr2D, ncstr, &
    1274             :              "internal ice stress (y)",                                  &   ! LCOV_EXCL_LINE
    1275             :              "positive is y direction on N grid", c1, c0,                &   ! LCOV_EXCL_LINE
    1276          37 :              ns1, f_strintyN)
    1277             : 
    1278             :          call define_hist_field(n_strintxE,"strintxE","N/m^2",estr2D, ecstr, &
    1279             :              "internal ice stress (x)",                                  &   ! LCOV_EXCL_LINE
    1280             :              "positive is x direction on E grid", c1, c0,                &   ! LCOV_EXCL_LINE
    1281          37 :              ns1, f_strintxE)
    1282             : 
    1283             :          call define_hist_field(n_strintyE,"strintyE","N/m^2",estr2D, ecstr, &
    1284             :              "internal ice stress (y)",                                  &   ! LCOV_EXCL_LINE
    1285             :              "positive is y direction on E grid", c1, c0,                &   ! LCOV_EXCL_LINE
    1286          37 :              ns1, f_strintyE)
    1287             : 
    1288             :          call define_hist_field(n_taubxN,"taubxN","N/m^2",nstr2D, ncstr,   &
    1289             :              "seabed (basal) stress (x)",                                &   ! LCOV_EXCL_LINE
    1290             :              "positive is x direction on N grid", c1, c0,                &   ! LCOV_EXCL_LINE
    1291          37 :              ns1, f_taubxN)
    1292             : 
    1293             :          call define_hist_field(n_taubyN,"taubyN","N/m^2",nstr2D, ncstr,   &
    1294             :              "seabed (basal) stress (y)",                                &   ! LCOV_EXCL_LINE
    1295             :              "positive is y direction on N grid", c1, c0,                &   ! LCOV_EXCL_LINE
    1296          37 :              ns1, f_taubyN)
    1297             : 
    1298             :          call define_hist_field(n_taubxE,"taubxE","N/m^2",estr2D, ecstr,   &
    1299             :              "seabed (basal) stress (x)",                                &   ! LCOV_EXCL_LINE
    1300             :              "positive is x direction on E grid", c1, c0,                &   ! LCOV_EXCL_LINE
    1301          37 :              ns1, f_taubxE)
    1302             : 
    1303             :          call define_hist_field(n_taubyE,"taubyE","N/m^2",estr2D, ecstr,   &
    1304             :              "seabed (basal) stress (y)",                                &   ! LCOV_EXCL_LINE
    1305             :              "positive is y direction on E grid", c1, c0,                &   ! LCOV_EXCL_LINE
    1306          37 :              ns1, f_taubyE)
    1307             : 
    1308             :          call define_hist_field(n_strength,"strength","N/m",tstr2D, tcstr, &
    1309             :              "compressive ice strength",                                 &   ! LCOV_EXCL_LINE
    1310             :              "none", c1, c0,                                             &   ! LCOV_EXCL_LINE
    1311          37 :              ns1, f_strength)
    1312             : 
    1313             :          call define_hist_field(n_divu,"divu","%/day",tstr2D, tcstr, &
    1314             :              "strain rate (divergence)",                           &   ! LCOV_EXCL_LINE
    1315             :              "none", secday*c100, c0,                              &   ! LCOV_EXCL_LINE
    1316          37 :              ns1, f_divu)
    1317             : 
    1318             :          call define_hist_field(n_shear,"shear","%/day",tstr2D, tcstr, &
    1319             :              "strain rate (shear)",                                  &   ! LCOV_EXCL_LINE
    1320             :              "none", secday*c100, c0,                                &   ! LCOV_EXCL_LINE
    1321          37 :              ns1, f_shear)
    1322             : 
    1323          37 :          select case (grid_ice)
    1324             :          case('B')
    1325          37 :             description = ", on U grid  (NE corner values)"
    1326          37 :             gridstr2d = trim(ustr2D)
    1327          37 :             gridstr   = trim(ucstr)
    1328             :          case ('CD','C')
    1329           0 :             description = ", on T grid"
    1330           0 :             gridstr2d = trim(tstr2D)
    1331          37 :             gridstr   = trim(tcstr)
    1332             :          end select
    1333             : 
    1334             :          call define_hist_field(n_sig1,"sig1","1",gridstr2d, gridstr, &
    1335             :              "norm. principal stress 1",                       &   ! LCOV_EXCL_LINE
    1336             :              "sig1 is instantaneous" // trim(description), c1, c0, &   ! LCOV_EXCL_LINE
    1337          37 :              ns1, f_sig1)
    1338             : 
    1339             :          call define_hist_field(n_sig2,"sig2","1",gridstr2d, gridstr, &
    1340             :              "norm. principal stress 2",                       &   ! LCOV_EXCL_LINE
    1341             :              "sig2 is instantaneous" // trim(description), c1, c0, &   ! LCOV_EXCL_LINE
    1342          37 :              ns1, f_sig2)
    1343             : 
    1344             :          call define_hist_field(n_sigP,"sigP","N/m",gridstr2d, gridstr, &
    1345             :              "ice pressure",                       &   ! LCOV_EXCL_LINE
    1346             :              "sigP is instantaneous" // trim(description), c1, c0, &   ! LCOV_EXCL_LINE
    1347          37 :              ns1, f_sigP)
    1348             : 
    1349             :          call define_hist_field(n_dvidtt,"dvidtt","cm/day",tstr2D, tcstr, &
    1350             :              "volume tendency thermo",                                  &   ! LCOV_EXCL_LINE
    1351             :              "none", mps_to_cmpdy, c0,                                  &   ! LCOV_EXCL_LINE
    1352          37 :              ns1, f_dvidtt)
    1353             : 
    1354             :          call define_hist_field(n_dvidtd,"dvidtd","cm/day",tstr2D, tcstr, &
    1355             :              "volume tendency dynamics",                                &   ! LCOV_EXCL_LINE
    1356             :              "none", mps_to_cmpdy, c0,                                  &   ! LCOV_EXCL_LINE
    1357          37 :              ns1, f_dvidtd)
    1358             : 
    1359             :          call define_hist_field(n_daidtt,"daidtt","%/day",tstr2D, tcstr, &
    1360             :              "area tendency thermo",                                   &   ! LCOV_EXCL_LINE
    1361             :              "none", secday*c100, c0,                                  &   ! LCOV_EXCL_LINE
    1362          37 :              ns1, f_daidtt)
    1363             : 
    1364             :          call define_hist_field(n_daidtd,"daidtd","%/day",tstr2D, tcstr, &
    1365             :              "area tendency dynamics",                                 &   ! LCOV_EXCL_LINE
    1366             :              "none", secday*c100, c0,                                  &   ! LCOV_EXCL_LINE
    1367          37 :              ns1, f_daidtd)
    1368             : 
    1369             :          call define_hist_field(n_dagedtt,"dagedtt","day/day",tstr2D, tcstr, &
    1370             :              "age tendency thermo",                                   &   ! LCOV_EXCL_LINE
    1371             :              "excludes time step increment", c1, c0,                  &   ! LCOV_EXCL_LINE
    1372          37 :              ns1, f_dagedtt)
    1373             : 
    1374             :          call define_hist_field(n_dagedtd,"dagedtd","day/day",tstr2D, tcstr, &
    1375             :              "age tendency dynamics",                                 &   ! LCOV_EXCL_LINE
    1376             :              "excludes time step increment", c1, c0,                  &   ! LCOV_EXCL_LINE
    1377          37 :              ns1, f_dagedtd)
    1378             : 
    1379             :          call define_hist_field(n_mlt_onset,"mlt_onset","day of year", &
    1380             :              tstr2D, tcstr,"melt onset date",                            &   ! LCOV_EXCL_LINE
    1381             :              "midyear restart gives erroneous dates", c1, c0,          &   ! LCOV_EXCL_LINE
    1382          37 :              ns1, f_mlt_onset)
    1383             : 
    1384             :          call define_hist_field(n_frz_onset,"frz_onset","day of year", &
    1385             :              tstr2D, tcstr,"freeze onset date",                          &   ! LCOV_EXCL_LINE
    1386             :              "midyear restart gives erroneous dates", c1, c0,          &   ! LCOV_EXCL_LINE
    1387          37 :              ns1, f_frz_onset)
    1388             : 
    1389             :          call define_hist_field(n_hisnap,"hisnap","m",tstr2D, tcstr, &
    1390             :              "ice volume snapshot",                                &   ! LCOV_EXCL_LINE
    1391             :              "none", c1, c0,                              &   ! LCOV_EXCL_LINE
    1392          37 :              ns1, f_hisnap)
    1393             : 
    1394             :          call define_hist_field(n_aisnap,"aisnap","1",tstr2D, tcstr, &
    1395             :              "ice area snapshot",                                  &   ! LCOV_EXCL_LINE
    1396             :              "none", c1, c0,                              &   ! LCOV_EXCL_LINE
    1397          37 :              ns1, f_aisnap)
    1398             : 
    1399             :          call define_hist_field(n_trsig,"trsig","N/m",tstr2D, tcstr, &
    1400             :              "internal stress tensor trace",                         &   ! LCOV_EXCL_LINE
    1401             :              "ice strength approximation", c1, c0,                   &   ! LCOV_EXCL_LINE
    1402          37 :              ns1, f_trsig)
    1403             : 
    1404             :          call define_hist_field(n_icepresent,"ice_present","1",tstr2D, tcstr, &
    1405             :              "fraction of time-avg interval that ice is present",           &   ! LCOV_EXCL_LINE
    1406             :              "ice extent flag", c1, c0,                                     &   ! LCOV_EXCL_LINE
    1407          37 :              ns1, f_icepresent)
    1408             : 
    1409             :          call define_hist_field(n_fsurf_ai,"fsurf_ai","W/m^2",tstr2D, tcstr, &
    1410             :              "net surface heat flux",                                      &   ! LCOV_EXCL_LINE
    1411             :              "positive downward, excludes conductive flux, weighted by ice area", &   ! LCOV_EXCL_LINE
    1412             :              c1, c0, &   ! LCOV_EXCL_LINE
    1413          37 :              ns1, f_fsurf_ai)
    1414             : 
    1415             :          call define_hist_field(n_fcondtop_ai,"fcondtop_ai","W/m^2", &
    1416             :              tstr2D, tcstr,"top surface conductive heat flux",         &   ! LCOV_EXCL_LINE
    1417             :              "positive downward, weighted by ice area", c1, c0,      &   ! LCOV_EXCL_LINE
    1418          37 :              ns1, f_fcondtop_ai)
    1419             : 
    1420             :          call define_hist_field(n_fmeltt_ai,"fmeltt_ai","W/m^2",tstr2D, tcstr, &
    1421             :              "net surface heat flux causing melt",                           &   ! LCOV_EXCL_LINE
    1422             :              "always >= 0, weighted by ice area", c1, c0,                    &   ! LCOV_EXCL_LINE
    1423          37 :              ns1, f_fmeltt_ai)
    1424             : 
    1425             :          call define_hist_field(n_a11,"a11"," ",tstr2D, tcstr, &
    1426             :             "a11: component a11 of the structure tensor",      &   ! LCOV_EXCL_LINE
    1427             :             "none", c1, c0,            &   ! LCOV_EXCL_LINE
    1428          37 :             ns1, f_a11)
    1429             : 
    1430             :          call define_hist_field(n_a12,"a12"," ",tstr2D, tcstr, &
    1431             :             "a12: component a12 of the structure tensor",      &   ! LCOV_EXCL_LINE
    1432             :             "none", c1, c0,            &   ! LCOV_EXCL_LINE
    1433          37 :             ns1, f_a12)
    1434             : 
    1435             :          call define_hist_field(n_e11,"e11","1/s",tstr2D, tcstr, &
    1436             :             "e11: component e11 of the strain rate tensor",      &   ! LCOV_EXCL_LINE
    1437             :             "none", c1, c0,            &   ! LCOV_EXCL_LINE
    1438          37 :             ns1, f_e11)
    1439             : 
    1440             :          call define_hist_field(n_e12,"e12","1/s",tstr2D, tcstr, &
    1441             :             "e12: component e12 of the strain rate tensor",      &   ! LCOV_EXCL_LINE
    1442             :             "none", c1, c0,            &   ! LCOV_EXCL_LINE
    1443          37 :             ns1, f_e12)
    1444             : 
    1445             :          call define_hist_field(n_e22,"e22","1/s",tstr2D, tcstr, &
    1446             :             "e22: component e22 of the strain rate tensor",      &   ! LCOV_EXCL_LINE
    1447             :             "none", c1, c0,            &   ! LCOV_EXCL_LINE
    1448          37 :             ns1, f_e22)
    1449             : 
    1450             :          call define_hist_field(n_s11,"s11","kg/s^2",tstr2D, tcstr, &
    1451             :             "s11: component s11 of the stress tensor",              &   ! LCOV_EXCL_LINE
    1452             :             "none", c1, c0,            &   ! LCOV_EXCL_LINE
    1453          37 :             ns1, f_s11)
    1454             : 
    1455             :          call define_hist_field(n_s12,"s12","kg/s^2",tstr2D, tcstr, &
    1456             :             "s12: component s12 of the stress tensor",              &   ! LCOV_EXCL_LINE
    1457             :             "none", c1, c0,            &   ! LCOV_EXCL_LINE
    1458          37 :             ns1, f_s12)
    1459             : 
    1460             :          call define_hist_field(n_s22,"s22","kg/s^2",tstr2D, tcstr, &
    1461             :             "s22: component s12 of the stress tensor",              &   ! LCOV_EXCL_LINE
    1462             :             "none", c1, c0,            &   ! LCOV_EXCL_LINE
    1463          37 :             ns1, f_s22)
    1464             : 
    1465             :          call define_hist_field(n_yieldstress11,"yieldstress11","kg/s^2",tstr2D, tcstr, &
    1466             :             "yieldstress11: component 11 of the yieldstress tensor",                    &   ! LCOV_EXCL_LINE
    1467             :             "none", c1, c0,            &   ! LCOV_EXCL_LINE
    1468          37 :             ns1, f_yieldstress11)
    1469             : 
    1470             :          call define_hist_field(n_yieldstress12,"yieldstress12","kg/s^2",tstr2D, tcstr, &
    1471             :             "yieldstress12: component 12 of the yieldstress tensor",                    &   ! LCOV_EXCL_LINE
    1472             :             "none", c1, c0,            &   ! LCOV_EXCL_LINE
    1473          37 :             ns1, f_yieldstress12)
    1474             : 
    1475             :          call define_hist_field(n_yieldstress22,"yieldstress22","kg/s^2",tstr2D, tcstr, &
    1476             :             "yieldstress22: component 12 of the yieldstress tensor",                    &   ! LCOV_EXCL_LINE
    1477             :             "none", c1, c0,            &   ! LCOV_EXCL_LINE
    1478          37 :             ns1, f_yieldstress22)
    1479             : 
    1480             :       ! Tracers
    1481             : 
    1482             :       ! Ice Age
    1483             :          call define_hist_field(n_iage,"iage","years",tstr2D, tcstr, &
    1484             :              "sea ice age",                                        &   ! LCOV_EXCL_LINE
    1485             :              "none", c1/(secday*days_per_year), c0,                &   ! LCOV_EXCL_LINE
    1486          37 :              ns1, f_iage)
    1487             : 
    1488             :       ! First Year Ice Area
    1489             :          call define_hist_field(n_FY,"FYarea"," ",tstr2D, tcstr, &
    1490             :              "first-year ice area",                            &   ! LCOV_EXCL_LINE
    1491             :              "weighted by ice area", c1, c0,                   &   ! LCOV_EXCL_LINE
    1492          37 :               ns1, f_FY)
    1493             : 
    1494             :       ! CMIP 2D variables
    1495             : 
    1496             :          call define_hist_field(n_sithick,"sithick","m",tstr2D, tcstr, &
    1497             :              "sea ice thickness",                             &   ! LCOV_EXCL_LINE
    1498             :              "volume divided by area", c1, c0, &   ! LCOV_EXCL_LINE
    1499          37 :              ns1, f_sithick)
    1500             : 
    1501             :          call define_hist_field(n_siage,"siage","s",tstr2D, tcstr,    &
    1502             :              "sea ice age",                             &   ! LCOV_EXCL_LINE
    1503             :              "none", c1, c0,                                      &   ! LCOV_EXCL_LINE
    1504          37 :              ns1, f_siage)
    1505             : 
    1506             :          call define_hist_field(n_sisnthick,"sisnthick","m",tstr2D, tcstr,    &
    1507             :              "sea ice snow thickness",                             &   ! LCOV_EXCL_LINE
    1508             :              "snow volume divided by area", c1, c0, &   ! LCOV_EXCL_LINE
    1509          37 :              ns1, f_sisnthick)
    1510             : 
    1511             :          call define_hist_field(n_sitemptop,"sitemptop","K",tstr2D, tcstr,    &
    1512             :              "sea ice surface temperature", &   ! LCOV_EXCL_LINE
    1513             :              "none", c1, c0,           &   ! LCOV_EXCL_LINE
    1514          37 :              ns1, f_sitemptop)
    1515             : 
    1516             :          call define_hist_field(n_sitempsnic,"sitempsnic","K",tstr2D, tcstr,    &
    1517             :              "snow ice interface temperature", &   ! LCOV_EXCL_LINE
    1518             :              "surface temperature when no snow present", c1, c0, &   ! LCOV_EXCL_LINE
    1519          37 :              ns1, f_sitempsnic)
    1520             : 
    1521             :          call define_hist_field(n_sitempbot,"sitempbot","K",tstr2D, tcstr,    &
    1522             :              "sea ice bottom temperature",                             &   ! LCOV_EXCL_LINE
    1523             :              "none", c1, c0,           &   ! LCOV_EXCL_LINE
    1524          37 :              ns1, f_sitempbot)
    1525             : 
    1526             :          call define_hist_field(n_siu,"siu","m/s",ustr2D, ucstr,  &
    1527             :              "ice x velocity component", &   ! LCOV_EXCL_LINE
    1528             :              "none", c1, c0,         &   ! LCOV_EXCL_LINE
    1529          37 :              ns1, f_siu)
    1530             : 
    1531             :          call define_hist_field(n_siv,"siv","m/s",ustr2D, ucstr,  &
    1532             :              "ice y velocity component", &   ! LCOV_EXCL_LINE
    1533             :              "none", c1, c0,         &   ! LCOV_EXCL_LINE
    1534          37 :              ns1, f_siv)
    1535             : 
    1536             :          call define_hist_field(n_sidmasstranx,"sidmasstranx","kg/s",ustr2D, ucstr,  &
    1537             :              "x component of snow and sea ice mass transport", &   ! LCOV_EXCL_LINE
    1538             :              "none", c1, c0,         &   ! LCOV_EXCL_LINE
    1539          37 :              ns1, f_sidmasstranx)
    1540             : 
    1541             :          call define_hist_field(n_sidmasstrany,"sidmasstrany","kg/s",ustr2D, ucstr,  &
    1542             :              "y component of snow and sea ice mass transport", &   ! LCOV_EXCL_LINE
    1543             :              "none", c1, c0,         &   ! LCOV_EXCL_LINE
    1544          37 :              ns1, f_sidmasstrany)
    1545             : 
    1546             :          call define_hist_field(n_sistrxdtop,"sistrxdtop","N m-2",ustr2D, ucstr,  &
    1547             :              "x component of atmospheric stress on sea ice", &   ! LCOV_EXCL_LINE
    1548             :              "none", c1, c0,         &   ! LCOV_EXCL_LINE
    1549          37 :              ns1, f_sistrxdtop)
    1550             : 
    1551             :          call define_hist_field(n_sistrydtop,"sistrydtop","N m-2",ustr2D, ucstr,  &
    1552             :              "y component of atmospheric stress on sea ice", &   ! LCOV_EXCL_LINE
    1553             :              "none", c1, c0,         &   ! LCOV_EXCL_LINE
    1554          37 :              ns1, f_sistrydtop)
    1555             : 
    1556             :          call define_hist_field(n_sistrxubot,"sistrxubot","N m-2",ustr2D, ucstr,  &
    1557             :              "x component of ocean stress on sea ice", &   ! LCOV_EXCL_LINE
    1558             :              "none", c1, c0,         &   ! LCOV_EXCL_LINE
    1559          37 :              ns1, f_sistrxubot)
    1560             : 
    1561             :          call define_hist_field(n_sistryubot,"sistryubot","N m-2",ustr2D, ucstr,  &
    1562             :              "y component of ocean stress on sea ice", &   ! LCOV_EXCL_LINE
    1563             :              "none", c1, c0,         &   ! LCOV_EXCL_LINE
    1564          37 :              ns1, f_sistryubot)
    1565             : 
    1566             :          call define_hist_field(n_sicompstren,"sicompstren","N m-1",tstr2D, tcstr,  &
    1567             :              "compressive sea ice strength",                      &   ! LCOV_EXCL_LINE
    1568             :              "none", c1, c0,         &   ! LCOV_EXCL_LINE
    1569          37 :              ns1, f_sicompstren)
    1570             : 
    1571             :          call define_hist_field(n_sispeed,"sispeed","m/s",ustr2D, ucstr, &
    1572             :              "ice speed",                                  &   ! LCOV_EXCL_LINE
    1573             :              "none", c1, c0,         &   ! LCOV_EXCL_LINE
    1574          37 :              ns1, f_sispeed)
    1575             : 
    1576             :          call define_hist_field(n_sidir,"sidir","deg",ustr2D, ucstr,  &
    1577             :              "ice direction",                                         &   ! LCOV_EXCL_LINE
    1578             :              "vector direction - going to", c1, c0,                   &   ! LCOV_EXCL_LINE
    1579          37 :              ns1, f_sidir)
    1580             : 
    1581             :          call define_hist_field(n_sialb,"sialb","1",tstr2D, tcstr,  &
    1582             :              "sea ice albedo",                                  &   ! LCOV_EXCL_LINE
    1583             :              "none", c1, c0,         &   ! LCOV_EXCL_LINE
    1584          37 :              ns1, f_sialb)
    1585             : 
    1586             :          call define_hist_field(n_sihc,"sihc","J m-2",tstr2D, tcstr,  &
    1587             :              "sea ice heat content",                                  &   ! LCOV_EXCL_LINE
    1588             :              "none", c1, c0,         &   ! LCOV_EXCL_LINE
    1589          37 :              ns1, f_sihc)
    1590             : 
    1591             :          call define_hist_field(n_sisnhc,"sisnhc","J m-2",tstr2D, tcstr, &
    1592             :              "snow heat content",                                  &   ! LCOV_EXCL_LINE
    1593             :              "none", c1, c0,         &   ! LCOV_EXCL_LINE
    1594          37 :              ns1, f_sisnhc)
    1595             : 
    1596             :          call define_hist_field(n_sidconcth,"sidconcth","1/s",tstr2D, tcstr,  &
    1597             :              "sea ice area change from thermodynamics",              &   ! LCOV_EXCL_LINE
    1598             :              "none", c1, c0,         &   ! LCOV_EXCL_LINE
    1599          37 :              ns1, f_sidconcth)
    1600             : 
    1601             :          call define_hist_field(n_sidconcdyn,"sidconcdyn","1/s",tstr2D, tcstr,  &
    1602             :              "sea ice area change from dynamics",                      &   ! LCOV_EXCL_LINE
    1603             :              "none", c1, c0,         &   ! LCOV_EXCL_LINE
    1604          37 :              ns1, f_sidconcdyn)
    1605             : 
    1606             :          call define_hist_field(n_sidmassth,"sidmassth","kg m-2 s-1",tstr2D, tcstr,  &
    1607             :              "sea ice mass change from thermodynamics",              &   ! LCOV_EXCL_LINE
    1608             :              "none", c1, c0,         &   ! LCOV_EXCL_LINE
    1609          37 :              ns1, f_sidmassth)
    1610             : 
    1611             :          call define_hist_field(n_sidmassdyn,"sidmassdyn","kg m-2 s-1",tstr2D, tcstr,  &
    1612             :              "sea ice mass change from dynamics",                      &   ! LCOV_EXCL_LINE
    1613             :              "none", c1, c0,         &   ! LCOV_EXCL_LINE
    1614          37 :              ns1, f_sidmassdyn)
    1615             : 
    1616             :          call define_hist_field(n_sidmassgrowthwat,"sidmassgrowthwat","kg m-2 s-1",tstr2D, tcstr,  &
    1617             :              "sea ice mass change from frazil",                      &   ! LCOV_EXCL_LINE
    1618             :              "none", c1, c0,         &   ! LCOV_EXCL_LINE
    1619          37 :              ns1, f_sidmassgrowthwat)
    1620             : 
    1621             :          call define_hist_field(n_sidmassgrowthbot,"sidmassgrowthbot","kg m-2 s-1",tstr2D, tcstr,  &
    1622             :              "sea ice mass change from basal growth", &   ! LCOV_EXCL_LINE
    1623             :              "none", c1, c0,         &   ! LCOV_EXCL_LINE
    1624          37 :              ns1, f_sidmassgrowthbot)
    1625             : 
    1626             :          call define_hist_field(n_sidmasssi,"sidmasssi","kg m-2 s-1",tstr2D, tcstr,  &
    1627             :              "sea ice mass change from snow-ice formation", &   ! LCOV_EXCL_LINE
    1628             :              "none", c1, c0,         &   ! LCOV_EXCL_LINE
    1629          37 :              ns1, f_sidmasssi)
    1630             : 
    1631             :          call define_hist_field(n_sidmassevapsubl,"sidmassevapsubl","kg m-2 s-1",tstr2D, tcstr,  &
    1632             :              "sea ice mass change from evaporation and sublimation", &   ! LCOV_EXCL_LINE
    1633             :              "none", c1, c0,         &   ! LCOV_EXCL_LINE
    1634          37 :              ns1, f_sidmassevapsubl)
    1635             : 
    1636             :          call define_hist_field(n_sndmasssubl,"sndmassubl","kg m-2 s-1",tstr2D, tcstr,  &
    1637             :              "snow mass change from evaporation and sublimation", &   ! LCOV_EXCL_LINE
    1638             :              "none", c1, c0,         &   ! LCOV_EXCL_LINE
    1639          37 :              ns1, f_sndmasssubl)
    1640             : 
    1641             :          call define_hist_field(n_sidmassmelttop,"sidmassmelttop","kg m-2 s-1",tstr2D, tcstr,  &
    1642             :              "sea ice mass change top melt",                      &   ! LCOV_EXCL_LINE
    1643             :              "none", c1, c0,         &   ! LCOV_EXCL_LINE
    1644          37 :              ns1, f_sidmassmelttop)
    1645             : 
    1646             :          call define_hist_field(n_sidmassmeltbot,"sidmassmeltbot","kg m-2 s-1",tstr2D, tcstr,  &
    1647             :              "sea ice mass change bottom melt",                      &   ! LCOV_EXCL_LINE
    1648             :              "none", c1, c0,         &   ! LCOV_EXCL_LINE
    1649          37 :              ns1, f_sidmassmeltbot)
    1650             : 
    1651             :          call define_hist_field(n_sidmasslat,"sidmasslat","kg m-2 s-1",tstr2D, tcstr,  &
    1652             :              "sea ice mass change lateral melt",                      &   ! LCOV_EXCL_LINE
    1653             :              "none", c1, c0,         &   ! LCOV_EXCL_LINE
    1654          37 :              ns1, f_sidmasslat)
    1655             : 
    1656             :         call define_hist_field(n_sndmasssnf,"sndmasssnf","kg m-2 s-1",tstr2D, tcstr,  &
    1657             :              "snow mass change from snow fall",                      &   ! LCOV_EXCL_LINE
    1658             :              "none", c1, c0,         &   ! LCOV_EXCL_LINE
    1659          37 :              ns1, f_sndmasssnf)
    1660             : 
    1661             :          call define_hist_field(n_sndmassmelt,"sndmassmelt","kg m-2 s-1",tstr2D, tcstr,  &
    1662             :              "snow mass change from snow melt",                      &   ! LCOV_EXCL_LINE
    1663             :              "none", c1, c0,         &   ! LCOV_EXCL_LINE
    1664          37 :              ns1, f_sndmassmelt)
    1665             : 
    1666             :          call define_hist_field(n_siflswdtop,"siflswdtop","W/m2",tstr2D, tcstr, &
    1667             :              "down shortwave flux over sea ice", &   ! LCOV_EXCL_LINE
    1668             :              "positive downward", c1, c0,                            &   ! LCOV_EXCL_LINE
    1669          37 :              ns1, f_siflswdtop)
    1670             : 
    1671             :          call define_hist_field(n_siflswutop,"siflswutop","W/m2",tstr2D, tcstr, &
    1672             :              "upward shortwave flux over sea ice", &   ! LCOV_EXCL_LINE
    1673             :              "positive downward", c1, c0,                            &   ! LCOV_EXCL_LINE
    1674          37 :              ns1, f_siflswutop)
    1675             : 
    1676             :          call define_hist_field(n_siflswdbot,"siflswdbot","W/m2",tstr2D, tcstr, &
    1677             :              "down shortwave flux at bottom of ice", &   ! LCOV_EXCL_LINE
    1678             :              "positive downward", c1, c0,                            &   ! LCOV_EXCL_LINE
    1679          37 :              ns1, f_siflswdbot)
    1680             : 
    1681             :          call define_hist_field(n_sifllwdtop,"sifllwdtop","W/m2",tstr2D, tcstr, &
    1682             :              "down longwave flux over sea ice", &   ! LCOV_EXCL_LINE
    1683             :              "positive downward", c1, c0,                            &   ! LCOV_EXCL_LINE
    1684          37 :              ns1, f_sifllwdtop)
    1685             : 
    1686             :          call define_hist_field(n_sifllwutop,"sifllwutop","W/m2",tstr2D, tcstr, &
    1687             :              "upward longwave flux over sea ice", &   ! LCOV_EXCL_LINE
    1688             :              "positive downward", c1, c0,                            &   ! LCOV_EXCL_LINE
    1689          37 :              ns1, f_sifllwutop)
    1690             : 
    1691             :          call define_hist_field(n_siflsenstop,"siflsenstop","W/m2",tstr2D, tcstr, &
    1692             :              "sensible heat flux over sea ice", &   ! LCOV_EXCL_LINE
    1693             :              "positive downward", c1, c0,                            &   ! LCOV_EXCL_LINE
    1694          37 :              ns1, f_siflsenstop)
    1695             : 
    1696             :          call define_hist_field(n_siflsensupbot,"siflsensupbot","W/m2",tstr2D, tcstr, &
    1697             :              "sensible heat flux at bottom of sea ice", &   ! LCOV_EXCL_LINE
    1698             :              "positive downward", c1, c0,                            &   ! LCOV_EXCL_LINE
    1699          37 :              ns1, f_siflsensupbot)
    1700             : 
    1701             :          call define_hist_field(n_sifllatstop,"sifllatstop","W/m2",tstr2D, tcstr, &
    1702             :              "latent heat flux over sea ice", &   ! LCOV_EXCL_LINE
    1703             :              "positive downward", c1, c0,                            &   ! LCOV_EXCL_LINE
    1704          37 :              ns1, f_sifllatstop)
    1705             : 
    1706             :          call define_hist_field(n_siflcondtop,"siflcondtop","W/m2",tstr2D, tcstr, &
    1707             :              "conductive heat flux at top of sea ice", &   ! LCOV_EXCL_LINE
    1708             :              "positive downward", c1, c0,                            &   ! LCOV_EXCL_LINE
    1709          37 :              ns1, f_siflcondtop)
    1710             : 
    1711             :          call define_hist_field(n_siflcondbot,"siflcondbot","W/m2",tstr2D, tcstr, &
    1712             :              "conductive heat flux at bottom of sea ice", &   ! LCOV_EXCL_LINE
    1713             :              "positive downward", c1, c0,                            &   ! LCOV_EXCL_LINE
    1714          37 :              ns1, f_siflcondbot)
    1715             : 
    1716             :          call define_hist_field(n_sipr,"sipr","kg m-2 s-1",tstr2D, tcstr, &
    1717             :              "rainfall over sea ice", &   ! LCOV_EXCL_LINE
    1718             :              "none", c1, c0,                            &   ! LCOV_EXCL_LINE
    1719          37 :              ns1, f_sipr)
    1720             : 
    1721             :          call define_hist_field(n_sifb,"sifb","m",tstr2D, tcstr, &
    1722             :              "sea ice freeboard above sea level",                &   ! LCOV_EXCL_LINE
    1723             :              "none", c1, c0,                            &   ! LCOV_EXCL_LINE
    1724          37 :              ns1, f_sifb)
    1725             : 
    1726             :          call define_hist_field(n_siflsaltbot,"siflsaltbot","kg m-2 s-1",tstr2D, tcstr, &
    1727             :              "salt flux from sea ice", &   ! LCOV_EXCL_LINE
    1728             :              "positive downward", c1, c0,                            &   ! LCOV_EXCL_LINE
    1729          37 :              ns1, f_siflsaltbot)
    1730             : 
    1731             :          call define_hist_field(n_siflfwbot,"siflfwbot","kg m-2 s-1",tstr2D, tcstr, &
    1732             :              "fresh water flux from sea ice", &   ! LCOV_EXCL_LINE
    1733             :              "positive downward", c1, c0,                            &   ! LCOV_EXCL_LINE
    1734          37 :              ns1, f_siflfwbot)
    1735             : 
    1736             :          call define_hist_field(n_siflfwdrain,"siflfwdrain","kg m-2 s-1",tstr2D, tcstr, &
    1737             :              "fresh water drainage through sea ice", &   ! LCOV_EXCL_LINE
    1738             :              "positive downward", c1, c0,                            &   ! LCOV_EXCL_LINE
    1739          37 :              ns1, f_siflfwdrain)
    1740             : 
    1741             :          call define_hist_field(n_sidragtop,"sidragtop","1",tstr2D, tcstr, &
    1742             :              "atmospheric drag over sea ice", &   ! LCOV_EXCL_LINE
    1743             :              "none", c1, c0,                            &   ! LCOV_EXCL_LINE
    1744          37 :              ns1, f_sidragtop)
    1745             : 
    1746             :          call define_hist_field(n_sirdgthick,"sirdgthick","m",tstr2D, tcstr, &
    1747             :              "sea ice ridge thickness", &   ! LCOV_EXCL_LINE
    1748             :              "vrdg divided by ardg", c1, c0, &   ! LCOV_EXCL_LINE
    1749          37 :              ns1, f_sirdgthick)
    1750             : 
    1751             :          call define_hist_field(n_siforcetiltx,"siforcetiltx","N m-2",tstr2D, tcstr, &
    1752             :              "sea surface tilt term", &   ! LCOV_EXCL_LINE
    1753             :              "none", c1, c0,                            &   ! LCOV_EXCL_LINE
    1754          37 :              ns1, f_siforcetiltx)
    1755             : 
    1756             :          call define_hist_field(n_siforcetilty,"siforcetilty","N m-2",tstr2D, tcstr, &
    1757             :              "sea surface tile term", &   ! LCOV_EXCL_LINE
    1758             :              "none", c1, c0,                            &   ! LCOV_EXCL_LINE
    1759          37 :              ns1, f_siforcetilty)
    1760             : 
    1761             :          call define_hist_field(n_siforcecoriolx,"siforcecoriolx","N m-2",tstr2D, tcstr, &
    1762             :              "coriolis term",                                      &   ! LCOV_EXCL_LINE
    1763             :              "none", c1, c0,                            &   ! LCOV_EXCL_LINE
    1764          37 :              ns1, f_siforcecoriolx)
    1765             : 
    1766             :          call define_hist_field(n_siforcecorioly,"siforcecorioly","N m-2",tstr2D, tcstr, &
    1767             :              "coriolis term",                                      &   ! LCOV_EXCL_LINE
    1768             :              "none", c1, c0,                            &   ! LCOV_EXCL_LINE
    1769          37 :              ns1, f_siforcecorioly)
    1770             : 
    1771             :          call define_hist_field(n_siforceintstrx,"siforceintstrx","N m-2",tstr2D, tcstr, &
    1772             :              "internal stress term", &   ! LCOV_EXCL_LINE
    1773             :              "none", c1, c0,                            &   ! LCOV_EXCL_LINE
    1774          37 :              ns1, f_siforceintstrx)
    1775             : 
    1776             :          call define_hist_field(n_siforceintstry,"siforceintstry","N m-2",tstr2D, tcstr, &
    1777             :              "internal stress term", &   ! LCOV_EXCL_LINE
    1778             :              "none", c1, c0,                            &   ! LCOV_EXCL_LINE
    1779          37 :              ns1, f_siforceintstry)
    1780             : 
    1781             :          call define_hist_field(n_sistreave,"sistreave","N m-1",ustr2D, ucstr, &
    1782             :              "average normal stress",                       &   ! LCOV_EXCL_LINE
    1783             :              "sistreave is instantaneous", c1, c0,                  &   ! LCOV_EXCL_LINE
    1784          37 :              ns1, f_sistreave)
    1785             : 
    1786             :          call define_hist_field(n_sistremax,"sistremax","N m-1",ustr2D, ucstr, &
    1787             :              "maximum shear stress",                       &   ! LCOV_EXCL_LINE
    1788             :              "sistremax is instantaneous", c1, c0,                  &   ! LCOV_EXCL_LINE
    1789          37 :              ns1, f_sistremax)
    1790             : 
    1791             :       endif ! if (histfreq(ns1) /= 'x') then
    1792             :       enddo ! ns1
    1793             : 
    1794             :       ! other 2D history variables
    1795             : 
    1796             :       ! mechanical redistribution
    1797          37 :       call init_hist_mechred_2D
    1798             : 
    1799             :       ! melt ponds
    1800          37 :       call init_hist_pond_2D
    1801             : 
    1802             :       ! biogeochemistry
    1803          37 :       call init_hist_bgc_2D
    1804             : 
    1805             :       ! form drag
    1806          37 :       call init_hist_drag_2D
    1807             : 
    1808             :       ! floe size distribution
    1809          37 :       call init_hist_fsd_2D
    1810             : 
    1811             :       ! advanced snow physics
    1812          37 :       call init_hist_snow_2D (dt)
    1813             : 
    1814             :       !-----------------------------------------------------------------
    1815             :       ! 3D (category) variables looped separately for ordering
    1816             :       !-----------------------------------------------------------------
    1817          74 :       do ns1 = 1, nstreams
    1818          74 :       if (histfreq(ns1) /= 'x') then
    1819             : 
    1820             :            call define_hist_field(n_aicen,"aicen","1",tstr3Dc, tcstr, &
    1821             :               "ice area, categories","none", c1, c0,                  &   ! LCOV_EXCL_LINE
    1822          37 :               ns1, f_aicen)
    1823             : 
    1824             :            call define_hist_field(n_vicen,"vicen","m",tstr3Dc, tcstr, &
    1825             :               "ice volume, categories","none", c1, c0,                &   ! LCOV_EXCL_LINE
    1826          37 :               ns1, f_vicen)
    1827             : 
    1828             :            call define_hist_field(n_vsnon,"vsnon","m",tstr3Dc, tcstr, &
    1829             :               "snow depth on ice, categories","volume per unit area of snow", c1, c0, &   ! LCOV_EXCL_LINE
    1830          37 :               ns1, f_vsnon)
    1831             : 
    1832             :            call define_hist_field(n_snowfracn,"snowfracn","1",tstr3Dc, tcstr, &
    1833             :              "category mean snow fraction",                     &   ! LCOV_EXCL_LINE
    1834             :              "snow fraction per unit grid cell area", c1, c0,       &   ! LCOV_EXCL_LINE
    1835          37 :               ns1, f_snowfracn)
    1836             : 
    1837             :            call define_hist_field(n_fsurfn_ai,"fsurfn_ai","W/m^2",tstr3Dc, tcstr, &
    1838             :               "net surface heat flux, categories","weighted by ice area", c1, c0, &   ! LCOV_EXCL_LINE
    1839          37 :               ns1, f_fsurfn_ai)
    1840             : 
    1841             :            call define_hist_field(n_fcondtopn_ai,"fcondtopn_ai","W/m^2",tstr3Dc, tcstr, &
    1842             :               "top sfc conductive heat flux, cat","weighted by ice area", c1, c0,       &   ! LCOV_EXCL_LINE
    1843          37 :               ns1, f_fcondtopn_ai)
    1844             : 
    1845             :            call define_hist_field(n_fmelttn_ai,"fmelttn_ai","W/m^2",tstr3Dc, tcstr, &
    1846             :               "net sfc heat flux causing melt, cat","weighted by ice area", c1, c0, &   ! LCOV_EXCL_LINE
    1847          37 :               ns1, f_fmelttn_ai)
    1848             : 
    1849             :            call define_hist_field(n_flatn_ai,"flatn_ai","W/m^2",tstr3Dc, tcstr, &
    1850             :               "latent heat flux, category","weighted by ice area", c1, c0,      &   ! LCOV_EXCL_LINE
    1851          37 :               ns1, f_flatn_ai)
    1852             : 
    1853             :            call define_hist_field(n_fsensn_ai,"fsensn_ai","W/m^2",tstr3Dc, tcstr, &
    1854             :               "sensible heat flux, category","weighted by ice area", c1, c0,      &   ! LCOV_EXCL_LINE
    1855          37 :               ns1, f_fsensn_ai)
    1856             : 
    1857             :            call define_hist_field(n_keffn_top,"keffn_top","W/m^2/K",tstr3Dc, tcstr, &
    1858             :               "effective thermal conductivity of the top ice layer, categories", &   ! LCOV_EXCL_LINE
    1859             :               "multilayer scheme", c1, c0,      &   ! LCOV_EXCL_LINE
    1860          37 :               ns1, f_keffn_top)
    1861             : 
    1862             :            ! CMIP 3D
    1863             :            call define_hist_field(n_siitdconc,"siitdconc","1",tstr3Dc, tcstr, &
    1864             :               "ice area, categories","none", c1, c0,                  &   ! LCOV_EXCL_LINE
    1865          37 :               ns1, f_siitdconc)
    1866             : 
    1867             :            call define_hist_field(n_siitdthick,"siitdthick","m",tstr3Dc, tcstr, &
    1868             :               "ice thickness, categories","none", c1, c0, &   ! LCOV_EXCL_LINE
    1869          37 :               ns1, f_siitdthick)
    1870             : 
    1871             :            call define_hist_field(n_siitdsnthick,"siitdsnthick","m",tstr3Dc, tcstr, &
    1872             :               "snow thickness, categories","none", c1, c0, &   ! LCOV_EXCL_LINE
    1873          37 :               ns1, f_siitdsnthick)
    1874             : 
    1875             :       endif ! if (histfreq(ns1) /= 'x') then
    1876             :       enddo ! ns1
    1877             : 
    1878             :       ! other 3D (category) history variables
    1879             : 
    1880             :       ! mechanical redistribution
    1881          37 :       call init_hist_mechred_3Dc
    1882             : 
    1883             :       ! melt ponds
    1884          37 :       call init_hist_pond_3Dc
    1885             : 
    1886             :       ! biogeochemistry
    1887          37 :       call init_hist_bgc_3Dc
    1888             : 
    1889             :       ! advanced snow physics
    1890          37 :       call init_hist_snow_3Dc
    1891             : 
    1892             :       !-----------------------------------------------------------------
    1893             :       ! 3D (vertical) variables must be looped separately
    1894             :       !-----------------------------------------------------------------
    1895             : 
    1896             : !      do ns1 = 1, nstreams
    1897             : !      if (histfreq(ns1) /= 'x') then
    1898             : 
    1899             : !         call define_hist_field(n_field3dz,"field3dz","1",tstr3Dz, tcstr, &
    1900             : !            "example 3dz field",                    &   ! LCOV_EXCL_LINE
    1901             : !            "vertical profile", c1, c0,                  &   ! LCOV_EXCL_LINE
    1902             : !            ns1, f_field3dz)
    1903             : 
    1904             : !      endif ! if (histfreq(ns1) /= 'x') then
    1905             : !      enddo ! ns1
    1906             : 
    1907             :       ! biogeochemistry
    1908          37 :       call init_hist_bgc_3Db
    1909          37 :       call init_hist_bgc_3Da
    1910             : 
    1911             :       !-----------------------------------------------------------------
    1912             :       ! 3D (floe size) variables must be looped separately
    1913             :       !-----------------------------------------------------------------
    1914             : 
    1915             :       ! floe size distribution
    1916          37 :       call init_hist_fsd_3Df
    1917             : 
    1918             :       !-----------------------------------------------------------------
    1919             :       ! 4D (categories, vertical) variables must be looped separately
    1920             :       !-----------------------------------------------------------------
    1921             : 
    1922          74 :       do ns1 = 1, nstreams
    1923          74 :       if (histfreq(ns1) /= 'x') then
    1924             : 
    1925             :          call define_hist_field(n_Tinz,"Tinz","C",tstr4Di, tcstr, &
    1926             :             "ice internal temperatures on CICE grid",          &   ! LCOV_EXCL_LINE
    1927             :             "vertical profile", c1, c0,                    &   ! LCOV_EXCL_LINE
    1928          37 :             ns1, f_Tinz)
    1929             : 
    1930             :          call define_hist_field(n_Sinz,"Sinz","ppt",tstr4Di, tcstr, &
    1931             :             "ice internal bulk salinity",          &   ! LCOV_EXCL_LINE
    1932             :             "vertical profile", c1, c0,                    &   ! LCOV_EXCL_LINE
    1933          37 :             ns1, f_Sinz)
    1934             : 
    1935             :       endif ! if (histfreq(ns1) /= 'x') then
    1936             :       enddo ! ns1
    1937             : 
    1938          74 :       do ns1 = 1, nstreams
    1939          74 :       if (histfreq(ns1) /= 'x') then
    1940             : 
    1941             :          call define_hist_field(n_Tsnz,"Tsnz","C",tstr4Ds, tcstr, &
    1942             :             "snow internal temperatures",          &   ! LCOV_EXCL_LINE
    1943             :             "vertical profile", c1, c0,                    &   ! LCOV_EXCL_LINE
    1944          37 :             ns1, f_Tsnz)
    1945             : 
    1946             :       endif ! if (histfreq(ns1) /= 'x') then
    1947             :       enddo
    1948             : 
    1949          37 :        if (f_Tinz   (1:1) /= 'x') then
    1950           0 :             if (allocated(Tinz4d)) deallocate(Tinz4d)
    1951           0 :             allocate(Tinz4d(nx_block,ny_block,nzilyr,ncat_hist))
    1952             :        endif
    1953          37 :        if (f_Sinz   (1:1) /= 'x')  then
    1954           0 :             if (allocated(Sinz4d)) deallocate(Sinz4d)
    1955           0 :             allocate(Sinz4d(nx_block,ny_block,nzilyr,ncat_hist))
    1956             :        endif
    1957          37 :        if (f_Tsnz   (1:1) /= 'x') then
    1958           0 :             if (allocated(Tsnz4d)) deallocate(Tsnz4d)
    1959           0 :             allocate(Tsnz4d(nx_block,ny_block,nzslyr,ncat_hist))
    1960             :        endif
    1961             : 
    1962             :       !-----------------------------------------------------------------
    1963             :       ! 4D (floe size, thickness categories) variables looped separately
    1964             :       !-----------------------------------------------------------------
    1965             : 
    1966             :       ! floe size distribution
    1967          37 :        call init_hist_fsd_4Df
    1968             : 
    1969             :       !-----------------------------------------------------------------
    1970             :       ! fill igrd array with namelist values
    1971             :       !-----------------------------------------------------------------
    1972             : 
    1973         814 :       igrd=.true.
    1974             : 
    1975          37 :       igrd(n_tmask     ) = f_tmask
    1976          37 :       igrd(n_umask     ) = f_umask
    1977          37 :       igrd(n_nmask     ) = f_nmask
    1978          37 :       igrd(n_emask     ) = f_emask
    1979          37 :       igrd(n_blkmask   ) = f_blkmask
    1980          37 :       igrd(n_tarea     ) = f_tarea
    1981          37 :       igrd(n_uarea     ) = f_uarea
    1982          37 :       igrd(n_narea     ) = f_narea
    1983          37 :       igrd(n_earea     ) = f_earea
    1984          37 :       igrd(n_dxt       ) = f_dxt
    1985          37 :       igrd(n_dyt       ) = f_dyt
    1986          37 :       igrd(n_dxu       ) = f_dxu
    1987          37 :       igrd(n_dyu       ) = f_dyu
    1988          37 :       igrd(n_dxn       ) = f_dxn
    1989          37 :       igrd(n_dyn       ) = f_dyn
    1990          37 :       igrd(n_dxe       ) = f_dxe
    1991          37 :       igrd(n_dye       ) = f_dye
    1992          37 :       igrd(n_HTN       ) = f_HTN
    1993          37 :       igrd(n_HTE       ) = f_HTE
    1994          37 :       igrd(n_ANGLE     ) = f_ANGLE
    1995          37 :       igrd(n_ANGLET    ) = f_ANGLET
    1996             : 
    1997         259 :       igrdz=.true.
    1998          37 :       igrdz(n_NCAT     ) = f_NCAT
    1999          37 :       igrdz(n_VGRDi    ) = f_VGRDi
    2000          37 :       igrdz(n_VGRDs    ) = f_VGRDs
    2001          37 :       igrdz(n_VGRDb    ) = f_VGRDb
    2002          37 :       igrdz(n_VGRDa    ) = f_VGRDa
    2003          37 :       igrdz(n_NFSD     ) = f_NFSD
    2004             : 
    2005             :       !-----------------------------------------------------------------
    2006             :       ! diagnostic output
    2007             :       !-----------------------------------------------------------------
    2008             : 
    2009          37 :       ntmp(:) = 0
    2010          37 :       if (my_task == master_task) then
    2011           7 :         write(nu_diag,*) ' '
    2012           7 :         write(nu_diag,*) 'total number of history fields = ',num_avail_hist_fields_tot
    2013           7 :         write(nu_diag,*) 'max number of history fields   = ',max_avail_hist_fields
    2014           7 :         write(nu_diag,*) 'The following variables will be ', &
    2015          14 :                          'written to the history tape: '
    2016           7 :         write(nu_diag,101) 'description','units','variable','frequency','x'
    2017           7 :         if (num_avail_hist_fields_tot == 0) &
    2018           0 :            write(nu_diag,*) '*** WARNING: NO HISTORY FIELDS WILL BE WRITTEN ***'
    2019         314 :         do n=1,num_avail_hist_fields_tot
    2020         307 :            if (avail_hist_fields(n)%vhistfreq_n /= 0) &
    2021             :            write(nu_diag,100) avail_hist_fields(n)%vdesc, &   ! LCOV_EXCL_LINE
    2022             :               avail_hist_fields(n)%vunit, avail_hist_fields(n)%vname, &   ! LCOV_EXCL_LINE
    2023         614 :               avail_hist_fields(n)%vhistfreq,avail_hist_fields(n)%vhistfreq_n
    2024         621 :            do ns = 1, nstreams
    2025         307 :               if (avail_hist_fields(n)%vhistfreq == histfreq(ns)) &
    2026         614 :                  ntmp(ns)=ntmp(ns)+1
    2027             :            enddo
    2028             :         enddo ! num_avail_hist_fields_tot
    2029           7 :         write(nu_diag,*) ' '
    2030             :       endif
    2031             :   100 format (1x,a40,2x,a16,2x,a12,1x,a1,2x,i6)
    2032             :   101 format (2x,a19,10x,a16,9x,a12,2x,a,3x,a1)
    2033             : 
    2034          37 :       call broadcast_array(ntmp, master_task)
    2035          74 :       do ns = 1, nstreams
    2036          74 :          if (ntmp(ns)==0) histfreq_n(ns) = 0
    2037             :       enddo
    2038             : 
    2039             :       !-----------------------------------------------------------------
    2040             :       ! initialize the history arrays
    2041             :       !-----------------------------------------------------------------
    2042             : 
    2043          37 :       if (allocated(a2D)) deallocate(a2D)
    2044          37 :       if (num_avail_hist_fields_2D > 0) &
    2045          37 :       allocate(a2D(nx_block,ny_block,num_avail_hist_fields_2D,max_blocks))
    2046             : 
    2047          37 :       if (allocated(a3Dc)) deallocate(a3Dc)
    2048          37 :       if (num_avail_hist_fields_3Dc > 0) &
    2049           0 :       allocate(a3Dc(nx_block,ny_block,ncat_hist,num_avail_hist_fields_3Dc,max_blocks))
    2050             : 
    2051          37 :       if (allocated(a3Dz)) deallocate(a3Dz)
    2052          37 :       if (num_avail_hist_fields_3Dz > 0) &
    2053           0 :       allocate(a3Dz(nx_block,ny_block,nzilyr,num_avail_hist_fields_3Dz,max_blocks))
    2054             : 
    2055          37 :       if (allocated(a3Db)) deallocate(a3Db)
    2056          37 :       if (num_avail_hist_fields_3Db > 0) &
    2057           0 :       allocate(a3Db(nx_block,ny_block,nzblyr,num_avail_hist_fields_3Db,max_blocks))
    2058             : 
    2059          37 :       if (allocated(a3Da)) deallocate(a3Da)
    2060          37 :       if (num_avail_hist_fields_3Da > 0) &
    2061           0 :       allocate(a3Da(nx_block,ny_block,nzalyr,num_avail_hist_fields_3Da,max_blocks))
    2062             : 
    2063          37 :       if (allocated(a3Df)) deallocate(a3Df)
    2064          37 :       if (num_avail_hist_fields_3Df > 0) &
    2065           0 :       allocate(a3Df(nx_block,ny_block,nfsd_hist,num_avail_hist_fields_3Df,max_blocks))
    2066             : 
    2067          37 :       if (allocated(a4Di)) deallocate(a4Di)
    2068          37 :       if (num_avail_hist_fields_4Di > 0) &
    2069           0 :       allocate(a4Di(nx_block,ny_block,nzilyr,ncat_hist,num_avail_hist_fields_4Di,max_blocks))
    2070             : 
    2071          37 :       if (allocated(a4Ds)) deallocate(a4Ds)
    2072          37 :       if (num_avail_hist_fields_4Ds > 0) &
    2073           0 :       allocate(a4Ds(nx_block,ny_block,nzslyr,ncat_hist,num_avail_hist_fields_4Ds,max_blocks))
    2074             : 
    2075          37 :       if (allocated(a4Df)) deallocate(a4Df)
    2076          37 :       if (num_avail_hist_fields_4Df > 0) &
    2077           0 :       allocate(a4Df(nx_block,ny_block,nfsd_hist,ncat_hist,num_avail_hist_fields_4Df,max_blocks))
    2078             : 
    2079     5056097 :       if (allocated(a2D))  a2D (:,:,:,:)     = c0
    2080          37 :       if (allocated(a3Dc)) a3Dc(:,:,:,:,:)   = c0
    2081          37 :       if (allocated(a3Dz)) a3Dz(:,:,:,:,:)   = c0
    2082          37 :       if (allocated(a3Db)) a3Db(:,:,:,:,:)   = c0
    2083          37 :       if (allocated(a3Da)) a3Da(:,:,:,:,:)   = c0
    2084          37 :       if (allocated(a3Df)) a3Df(:,:,:,:,:)   = c0
    2085          37 :       if (allocated(a4Di)) a4Di(:,:,:,:,:,:) = c0
    2086          37 :       if (allocated(a4Ds)) a4Ds(:,:,:,:,:,:) = c0
    2087          37 :       if (allocated(a4Df)) a4Df(:,:,:,:,:,:) = c0
    2088          37 :       avgct(:) = c0
    2089      559717 :       albcnt(:,:,:,:) = c0
    2090      559717 :       snwcnt(:,:,:,:) = c0
    2091             : 
    2092          37 :       if (restart .and. yday >= c2) then
    2093             : ! restarting midyear gives erroneous onset dates
    2094           0 :          mlt_onset = 999._dbl_kind
    2095           0 :          frz_onset = 999._dbl_kind
    2096             :       else
    2097      111936 :          mlt_onset = c0
    2098      111936 :          frz_onset = c0
    2099             :       endif
    2100             : 
    2101          37 :       end subroutine init_hist
    2102             : 
    2103             : !=======================================================================
    2104             : 
    2105             : ! accumulate average ice quantities or snapshots
    2106             : !
    2107             : ! author:   Elizabeth C. Hunke, LANL
    2108             : 
    2109        5821 :       subroutine accum_hist (dt)
    2110             : 
    2111             :       use ice_blocks, only: block, get_block, nx_block, ny_block
    2112             :       use ice_domain, only: blocks_ice, nblocks
    2113             :       use ice_domain_size, only: nfsd
    2114             :       use ice_grid, only: tmask, lmask_n, lmask_s, dxU, dyU, grid_ice
    2115             :       use ice_calendar, only: new_year, write_history, &
    2116             :                               write_ic, timesecs, histfreq, nstreams, mmonth, &   ! LCOV_EXCL_LINE
    2117             :                               new_month
    2118             :       use ice_dyn_eap, only: a11, a12, e11, e12, e22, s11, s12, s22, &
    2119             :           yieldstress11, yieldstress12, yieldstress22
    2120             :       use ice_dyn_shared, only: kdyn, principal_stress
    2121             :       use ice_flux, only: fsw, flw, fsnow, frain, sst, sss, uocn, vocn, &
    2122             :           frzmlt_init, scale_factor, fswabs, fswthru, alvdr, alvdf, alidr, alidf, &   ! LCOV_EXCL_LINE
    2123             :           albice, albsno, albpnd, coszen, flat, fsens, flwout, evap, evaps, evapi, &   ! LCOV_EXCL_LINE
    2124             :           Tair, Tref, Qref, congel, frazil, frazil_diag, snoice, dsnow, &   ! LCOV_EXCL_LINE
    2125             :           melts, meltb, meltt, meltl, fresh, fsalt, fresh_ai, fsalt_ai, &   ! LCOV_EXCL_LINE
    2126             :           fhocn, fhocn_ai, uatm, vatm, fbot, Tbot, Tsnice, fswthru_ai, &   ! LCOV_EXCL_LINE
    2127             :           strairxU, strairyU, strtltxU, strtltyU, strintxU, strintyU, &   ! LCOV_EXCL_LINE
    2128             :           taubxU, taubyU, strocnxU, strocnyU, &   ! LCOV_EXCL_LINE
    2129             :           strairxN, strairyN, strtltxN, strtltyN, strintxN, strintyN, &   ! LCOV_EXCL_LINE
    2130             :           taubxN, taubyN, strocnxN, strocnyN, &   ! LCOV_EXCL_LINE
    2131             :           strairxE, strairyE, strtltxE, strtltyE, strintxE, strintyE, &   ! LCOV_EXCL_LINE
    2132             :           taubxE, taubyE, strocnxE, strocnyE, &   ! LCOV_EXCL_LINE
    2133             :           fmU, fmN, fmE, daidtt, dvidtt, daidtd, dvidtd, fsurf, &   ! LCOV_EXCL_LINE
    2134             :           fcondtop, fcondbot, fsurfn, fcondtopn, flatn, fsensn, albcnt, snwcnt, &   ! LCOV_EXCL_LINE
    2135             :           stressp_1, stressm_1, stress12_1, &   ! LCOV_EXCL_LINE
    2136             :           stresspT, stressmT, stress12T, &   ! LCOV_EXCL_LINE
    2137             :           stressp_2, stressp_3, stressp_4, sig1, sig2, sigP, &   ! LCOV_EXCL_LINE
    2138             :           mlt_onset, frz_onset, dagedtt, dagedtd, fswint_ai, keffn_top, &   ! LCOV_EXCL_LINE
    2139             :           snowfrac, alvdr_ai, alvdf_ai, alidr_ai, alidf_ai, update_ocn_f, &   ! LCOV_EXCL_LINE
    2140             :           cpl_frazil
    2141             :       use ice_arrays_column, only: snowfracn, Cdn_atm
    2142             :       use ice_history_shared ! almost everything
    2143             :       use ice_history_write, only: ice_write_hist
    2144             :       use ice_history_bgc, only: accum_hist_bgc
    2145             :       use ice_history_mechred, only: accum_hist_mechred
    2146             :       use ice_history_pond, only: accum_hist_pond
    2147             :       use ice_history_snow, only: accum_hist_snow, &
    2148             :           f_rhos_cmp, f_rhos_cnt, n_rhos_cmp, n_rhos_cnt
    2149             :       use ice_history_drag, only: accum_hist_drag
    2150             :       use icepack_intfc, only: icepack_mushy_density_brine, icepack_mushy_liquid_fraction
    2151             :       use icepack_intfc, only: icepack_mushy_temperature_mush
    2152             :       use ice_history_fsd, only: accum_hist_fsd
    2153             :       use ice_state ! almost everything
    2154             :       use ice_timers, only: ice_timer_start, ice_timer_stop, timer_readwrite
    2155             : 
    2156             :       real (kind=dbl_kind), intent(in) :: &
    2157             :          dt      ! time step
    2158             : 
    2159             :       ! local variables
    2160             : 
    2161             :       integer (kind=int_kind) :: &
    2162             :            i,j,k,ic,n,ns,nn, &   ! LCOV_EXCL_LINE
    2163             :            iblk             , & ! block index   ! LCOV_EXCL_LINE
    2164             :            ilo,ihi,jlo,jhi  , & ! beginning and end of physical domain   ! LCOV_EXCL_LINE
    2165             :            nstrm                ! nstreams (1 if writing initial condition)
    2166             : 
    2167             :       real (kind=dbl_kind) :: &
    2168             :            timedbl          , & ! temporary dbl for time bounds   ! LCOV_EXCL_LINE
    2169             :            ravgct           , & ! 1/avgct   ! LCOV_EXCL_LINE
    2170        1448 :            ravgctz              ! 1/avgct
    2171             : 
    2172             :       real (kind=dbl_kind) :: &
    2173             :            qn                , & ! temporary variable for enthalpy   ! LCOV_EXCL_LINE
    2174        1448 :            sn                    ! temporary variable for salinity
    2175             : 
    2176             :       real (kind=dbl_kind), dimension (nx_block,ny_block) :: &
    2177     3783682 :          worka, workb, ravgip
    2178             : 
    2179             :       real (kind=dbl_kind), dimension (nx_block,ny_block,ncat_hist) :: &
    2180    12596210 :          ravgipn, worka3
    2181             : 
    2182        2896 :       real (kind=dbl_kind) :: awtvdr, awtidr, awtvdf, awtidf, puny, secday, rad_to_deg
    2183        2896 :       real (kind=dbl_kind) :: Tffresh, rhoi, rhos, rhow, ice_ref_salinity
    2184        1448 :       real (kind=dbl_kind) :: rho_ice, rho_ocn, Tice, Sbr, phi, rhob, dfresh, dfsalt, sicen
    2185             :       logical (kind=log_kind) :: formdrag, skl_bgc
    2186             :       logical (kind=log_kind) :: tr_pond, tr_aero, tr_brine, tr_snow
    2187             :       integer (kind=int_kind) :: ktherm
    2188             :       integer (kind=int_kind) :: nt_sice, nt_qice, nt_qsno, nt_iage, nt_FY, nt_Tsfc, &
    2189             :                                  nt_alvl, nt_vlvl
    2190             :       character (len=char_len) :: saltflux_option
    2191             : 
    2192             :       type (block) :: &
    2193             :          this_block           ! block information for current block
    2194             :       character(len=*), parameter :: subname = '(accum_hist)'
    2195             : 
    2196             :       call icepack_query_parameters(awtvdr_out=awtvdr, awtidr_out=awtidr, &
    2197             :            awtvdf_out=awtvdf, awtidf_out=awtidf, puny_out=puny, secday_out=secday, &   ! LCOV_EXCL_LINE
    2198        5821 :            rad_to_deg_out=rad_to_deg)
    2199             :       call icepack_query_parameters(Tffresh_out=Tffresh, rhoi_out=rhoi, rhos_out=rhos, &
    2200        5821 :            rhow_out=rhow, ice_ref_salinity_out=ice_ref_salinity)
    2201        5821 :       call icepack_query_parameters(formdrag_out=formdrag, skl_bgc_out=skl_bgc, ktherm_out=ktherm)
    2202        5821 :       call icepack_query_parameters(saltflux_option_out=saltflux_option)
    2203             :       call icepack_query_tracer_flags(tr_pond_out=tr_pond, tr_aero_out=tr_aero, &
    2204        5821 :            tr_brine_out=tr_brine, tr_snow_out=tr_snow)
    2205             :       call icepack_query_tracer_indices(nt_sice_out=nt_sice, nt_qice_out=nt_qice, &
    2206             :            nt_qsno_out=nt_qsno, nt_iage_out=nt_iage, nt_FY_out=nt_FY, nt_Tsfc_out=nt_Tsfc, &   ! LCOV_EXCL_LINE
    2207        5821 :            nt_alvl_out=nt_alvl, nt_vlvl_out=nt_vlvl)
    2208        5821 :       call icepack_warnings_flush(nu_diag)
    2209        5821 :       if (icepack_warnings_aborted()) call abort_ice(error_message=subname, &
    2210           0 :          file=__FILE__, line=__LINE__)
    2211             : 
    2212             :       !---------------------------------------------------------------
    2213             :       ! increment step counter
    2214             :       !---------------------------------------------------------------
    2215             : 
    2216        5821 :       n2D     = num_avail_hist_fields_2D
    2217        5821 :       n3Dccum = n2D     + num_avail_hist_fields_3Dc
    2218        5821 :       n3Dzcum = n3Dccum + num_avail_hist_fields_3Dz
    2219        5821 :       n3Dbcum = n3Dzcum + num_avail_hist_fields_3Db
    2220        5821 :       n3Dacum = n3Dbcum + num_avail_hist_fields_3Da
    2221        5821 :       n3Dfcum = n3Dacum + num_avail_hist_fields_3Df
    2222        5821 :       n4Dicum = n3Dfcum + num_avail_hist_fields_4Di
    2223        5821 :       n4Dscum = n4Dicum + num_avail_hist_fields_4Ds
    2224        5821 :       n4Dfcum = n4Dscum + num_avail_hist_fields_4Df ! should equal num_avail_hist_fields_tot
    2225             : 
    2226       11642 :       do ns = 1,nstreams
    2227        5821 :          if (.not. hist_avg(ns)) then  ! write snapshots
    2228           0 :            do n = 1,n2D
    2229           0 :               if (avail_hist_fields(n)%vhistfreq == histfreq(ns)) &
    2230           0 :                   a2D(:,:,n,:) = c0
    2231             :            enddo
    2232           0 :            do n = n2D + 1, n3Dccum
    2233           0 :               nn = n - n2D
    2234           0 :               if (avail_hist_fields(n)%vhistfreq == histfreq(ns)) &
    2235           0 :                   a3Dc(:,:,:,nn,:) = c0
    2236             :            enddo
    2237           0 :            do n = n3Dccum + 1, n3Dzcum
    2238           0 :               nn = n - n3Dccum
    2239           0 :               if (avail_hist_fields(n)%vhistfreq == histfreq(ns)) &
    2240           0 :                   a3Dz(:,:,:,nn,:) = c0
    2241             :            enddo
    2242           0 :            do n = n3Dzcum + 1, n3Dbcum
    2243           0 :               nn = n - n3Dzcum
    2244           0 :               if (avail_hist_fields(n)%vhistfreq == histfreq(ns)) &
    2245           0 :                   a3Db(:,:,:,nn,:) = c0
    2246             :            enddo
    2247           0 :            do n = n3Dbcum + 1, n3Dacum
    2248           0 :               nn = n - n3Dbcum
    2249           0 :               if (avail_hist_fields(n)%vhistfreq == histfreq(ns)) &
    2250           0 :                   a3Da(:,:,:,nn,:) = c0
    2251             :            enddo
    2252           0 :            do n = n3Dacum + 1, n3Dfcum
    2253           0 :               nn = n - n3Dacum
    2254           0 :               if (avail_hist_fields(n)%vhistfreq == histfreq(ns)) &
    2255           0 :                   a3Df(:,:,:,nn,:) = c0
    2256             :            enddo
    2257           0 :            do n = n3Dfcum + 1, n4Dicum
    2258           0 :               nn = n - n3Dfcum
    2259           0 :               if (avail_hist_fields(n)%vhistfreq == histfreq(ns)) &
    2260           0 :                   a4Di(:,:,:,:,nn,:) = c0
    2261             :            enddo
    2262           0 :            do n = n4Dicum + 1, n4Dscum
    2263           0 :               nn = n - n4Dicum
    2264           0 :               if (avail_hist_fields(n)%vhistfreq == histfreq(ns)) &
    2265           0 :                   a4Ds(:,:,:,:,nn,:) = c0
    2266             :            enddo
    2267           0 :            do n = n4Dscum + 1, n4Dfcum
    2268           0 :               nn = n - n4Dscum
    2269           0 :               if (avail_hist_fields(n)%vhistfreq == histfreq(ns)) &
    2270           0 :                   a4Df(:,:,:,:,nn,:) = c0
    2271             :            enddo
    2272           0 :            avgct(ns) = c1
    2273             :          else                      ! write averages over time histfreq
    2274        5821 :            avgct(ns) = avgct(ns) + c1
    2275             :          endif
    2276       11642 :          if (avgct(ns) == c1) then
    2277         122 :             timedbl = (timesecs-dt)/(secday)
    2278         122 :             time_beg(ns) = real(timedbl,kind=real_kind)
    2279             :          endif
    2280             :       enddo
    2281             : 
    2282             :       !---------------------------------------------------------------
    2283             :       ! increment field
    2284             :       !---------------------------------------------------------------
    2285             : 
    2286             :       !$OMP PARALLEL DO PRIVATE(iblk,i,j,ilo,ihi,jlo,jhi,this_block, &
    2287             :       !$OMP             k,n,qn,ns,sn,rho_ocn,rho_ice,Tice,Sbr,phi,rhob,dfresh,dfsalt,sicen, &   ! LCOV_EXCL_LINE
    2288        2900 :       !$OMP             worka,workb,worka3,Tinz4d,Sinz4d,Tsnz4d)
    2289             : 
    2290        8738 :       do iblk = 1, nblocks
    2291        5817 :          this_block = get_block(blocks_ice(iblk),iblk)
    2292        5817 :          ilo = this_block%ilo
    2293        5817 :          ihi = this_block%ihi
    2294        5817 :          jlo = this_block%jlo
    2295        5817 :          jhi = this_block%jhi
    2296             : 
    2297        5817 :          if (allocated(a2D)) then
    2298             : 
    2299     7202147 :          workb(:,:) = aice_init(:,:,iblk)
    2300             : 
    2301             : !        if (f_example(1:1) /= 'x') &
    2302             : !            call accum_hist_field(n_example,iblk, vice(:,:,iblk), a2D)
    2303        5817 :          if (f_hi     (1:1) /= 'x') &
    2304        5817 :              call accum_hist_field(n_hi,     iblk, vice(:,:,iblk), a2D)
    2305        5817 :          if (f_hs     (1:1) /= 'x') &
    2306        5817 :              call accum_hist_field(n_hs,     iblk, vsno(:,:,iblk), a2D)
    2307        5817 :          if (f_snowfrac(1:1) /= 'x') &
    2308           0 :              call accum_hist_field(n_snowfrac, iblk, snowfrac(:,:,iblk), a2D)
    2309        5817 :          if (f_Tsfc   (1:1) /= 'x') &
    2310        5817 :              call accum_hist_field(n_Tsfc,   iblk, trcr(:,:,nt_Tsfc,iblk), a2D)
    2311        5817 :          if (f_aice   (1:1) /= 'x') &
    2312        5817 :              call accum_hist_field(n_aice,   iblk, aice(:,:,iblk), a2D)
    2313        5817 :          if (f_uvel   (1:1) /= 'x') &
    2314        5817 :              call accum_hist_field(n_uvel,   iblk, uvel(:,:,iblk), a2D)
    2315        5817 :          if (f_vvel   (1:1) /= 'x') &
    2316        5817 :              call accum_hist_field(n_vvel,   iblk, vvel(:,:,iblk), a2D)
    2317        5817 :          if (f_icespd   (1:1) /= 'x') &
    2318             :              call accum_hist_field(n_icespd,   iblk, sqrt( &   ! LCOV_EXCL_LINE
    2319             :                                   (uvel(:,:,iblk)*uvel(:,:,iblk)) + &   ! LCOV_EXCL_LINE
    2320     7202147 :                                   (vvel(:,:,iblk)*vvel(:,:,iblk))), a2D)
    2321        5817 :          if (f_icedir(1:1) /= 'x') then
    2322     7202147 :            worka(:,:) = c0
    2323      194061 :            do j = jlo, jhi
    2324     6415069 :            do i = ilo, ihi
    2325     6221008 :               if (abs(uvel(i,j,iblk)) > puny .or. abs(vvel(i,j,iblk)) > puny) &
    2326     5682038 :                  worka(i,j) = atan2(uvel(i,j,iblk),vvel(i,j,iblk))*rad_to_deg
    2327     6409252 :                  worka(i,j) = worka(i,j) + c180
    2328             :            enddo
    2329             :            enddo
    2330        5817 :            call accum_hist_field(n_icedir, iblk, worka(:,:), a2D)
    2331             :          endif
    2332        5817 :          if (f_uvelN   (1:1) /= 'x') &
    2333           0 :              call accum_hist_field(n_uvelN,  iblk, uvelN(:,:,iblk), a2D)
    2334        5817 :          if (f_vvelN   (1:1) /= 'x') &
    2335           0 :              call accum_hist_field(n_vvelN,  iblk, vvelN(:,:,iblk), a2D)
    2336        5817 :          if (f_icespdN  (1:1) /= 'x') &
    2337             :              call accum_hist_field(n_icespdN,   iblk, sqrt( &   ! LCOV_EXCL_LINE
    2338             :                                   (uvelN(:,:,iblk)*uvelN(:,:,iblk)) + &   ! LCOV_EXCL_LINE
    2339           0 :                                   (vvelN(:,:,iblk)*vvelN(:,:,iblk))), a2D)
    2340        5817 :          if (f_icedirN(1:1) /= 'x') then
    2341           0 :            worka(:,:) = c0
    2342           0 :            do j = jlo, jhi
    2343           0 :            do i = ilo, ihi
    2344           0 :               if (abs(uvelN(i,j,iblk)) > puny .or. abs(vvelN(i,j,iblk)) > puny) &
    2345           0 :                  worka(i,j) = atan2(uvelN(i,j,iblk),vvelN(i,j,iblk))*rad_to_deg
    2346           0 :                  worka(i,j) = worka(i,j) + c180
    2347             :            enddo
    2348             :            enddo
    2349           0 :            call accum_hist_field(n_icedirN, iblk, worka(:,:), a2D)
    2350             :          endif
    2351        5817 :          if (f_uvelE   (1:1) /= 'x') &
    2352           0 :              call accum_hist_field(n_uvelE,  iblk, uvelE(:,:,iblk), a2D)
    2353        5817 :          if (f_vvelE   (1:1) /= 'x') &
    2354           0 :              call accum_hist_field(n_vvelE,  iblk, vvelE(:,:,iblk), a2D)
    2355        5817 :          if (f_icespdE  (1:1) /= 'x') &
    2356             :              call accum_hist_field(n_icespdE,   iblk, sqrt( &   ! LCOV_EXCL_LINE
    2357             :                                   (uvelE(:,:,iblk)*uvelE(:,:,iblk)) + &   ! LCOV_EXCL_LINE
    2358           0 :                                   (vvelE(:,:,iblk)*vvelE(:,:,iblk))), a2D)
    2359        5817 :          if (f_icedirE(1:1) /= 'x') then
    2360           0 :            worka(:,:) = c0
    2361           0 :            do j = jlo, jhi
    2362           0 :            do i = ilo, ihi
    2363           0 :               if (abs(uvelE(i,j,iblk)) > puny .or. abs(vvelE(i,j,iblk)) > puny) &
    2364           0 :                  worka(i,j) = atan2(uvelE(i,j,iblk),vvelE(i,j,iblk))*rad_to_deg
    2365           0 :                  worka(i,j) = worka(i,j) + c180
    2366             :            enddo
    2367             :            enddo
    2368           0 :            call accum_hist_field(n_icedirE, iblk, worka(:,:), a2D)
    2369             :          endif
    2370        5817 :          if (f_uatm   (1:1) /= 'x') &
    2371        5817 :              call accum_hist_field(n_uatm,   iblk, uatm(:,:,iblk), a2D)
    2372        5817 :          if (f_vatm   (1:1) /= 'x') &
    2373        5817 :              call accum_hist_field(n_vatm,   iblk, vatm(:,:,iblk), a2D)
    2374        5817 :          if (f_atmspd   (1:1) /= 'x') &
    2375             :              call accum_hist_field(n_atmspd,   iblk, sqrt( &   ! LCOV_EXCL_LINE
    2376             :                                   (uatm(:,:,iblk)*uatm(:,:,iblk)) + &   ! LCOV_EXCL_LINE
    2377     7202147 :                                   (vatm(:,:,iblk)*vatm(:,:,iblk))), a2D)
    2378        5817 :          if (f_atmdir(1:1) /= 'x') then
    2379     7202147 :            worka(:,:) = c0
    2380      194061 :            do j = jlo, jhi
    2381     6415069 :            do i = ilo, ihi
    2382     6221008 :               if (abs(uatm(i,j,iblk)) > puny .or. abs(vatm(i,j,iblk)) > puny) &
    2383     6134752 :                  worka(i,j) = atan2(uatm(i,j,iblk),vatm(i,j,iblk))*rad_to_deg
    2384     6409252 :                  worka(i,j) = worka(i,j) + c180
    2385             :            enddo
    2386             :            enddo
    2387        5817 :            call accum_hist_field(n_atmdir, iblk, worka(:,:), a2D)
    2388             :          endif
    2389        5817 :          if (f_sice   (1:1) /= 'x') then
    2390      194061 :              do j = jlo, jhi
    2391     6415069 :              do i = ilo, ihi
    2392     6221008 :                 worka(i,j) = c0
    2393    49768064 :                 do k = 1, nzilyr
    2394    49768064 :                    worka(i,j) = worka(i,j) + trcr(i,j,nt_sice+k-1,iblk)
    2395             :                 enddo
    2396     6409252 :                 worka(i,j) = worka(i,j) / nzilyr
    2397             :              enddo
    2398             :              enddo
    2399        5817 :              call accum_hist_field(n_sice,   iblk, worka(:,:), a2D)
    2400             :          endif
    2401             : 
    2402        5817 :          if (f_fswup(1:1) /= 'x') &
    2403             :             call accum_hist_field(n_fswup, iblk, &   ! LCOV_EXCL_LINE
    2404           0 :                  (fsw(:,:,iblk)-fswabs(:,:,iblk)*workb(:,:)), a2D)
    2405        5817 :          if (f_fswdn  (1:1) /= 'x') &
    2406        5817 :              call accum_hist_field(n_fswdn,  iblk, fsw(:,:,iblk), a2D)
    2407        5817 :          if (f_flwdn  (1:1) /= 'x') &
    2408        5817 :              call accum_hist_field(n_flwdn,  iblk, flw(:,:,iblk), a2D)
    2409        5817 :          if (f_snow   (1:1) /= 'x') &
    2410           0 :              call accum_hist_field(n_snow,   iblk, fsnow(:,:,iblk), a2D)
    2411        5817 :          if (f_snow_ai(1:1) /= 'x') &
    2412     7202147 :              call accum_hist_field(n_snow_ai,iblk, fsnow(:,:,iblk)*workb(:,:), a2D)
    2413        5817 :          if (f_rain   (1:1) /= 'x') &
    2414           0 :              call accum_hist_field(n_rain,   iblk, frain(:,:,iblk), a2D)
    2415        5817 :          if (f_rain_ai(1:1) /= 'x') &
    2416     7202147 :              call accum_hist_field(n_rain_ai,iblk, frain(:,:,iblk)*workb(:,:), a2D)
    2417             : 
    2418        5817 :          if (f_sst    (1:1) /= 'x') &
    2419        5817 :              call accum_hist_field(n_sst,    iblk, sst(:,:,iblk), a2D)
    2420        5817 :          if (f_sss    (1:1) /= 'x') &
    2421        5817 :              call accum_hist_field(n_sss,    iblk, sss(:,:,iblk), a2D)
    2422        5817 :          if (f_uocn   (1:1) /= 'x') &
    2423        5817 :              call accum_hist_field(n_uocn,   iblk, uocn(:,:,iblk), a2D)
    2424        5817 :          if (f_vocn   (1:1) /= 'x') &
    2425        5817 :              call accum_hist_field(n_vocn,   iblk, vocn(:,:,iblk), a2D)
    2426        5817 :          if (f_ocnspd   (1:1) /= 'x') &
    2427             :              call accum_hist_field(n_ocnspd,   iblk, sqrt( &   ! LCOV_EXCL_LINE
    2428             :                                   (uocn(:,:,iblk)*uocn(:,:,iblk)) + &   ! LCOV_EXCL_LINE
    2429     7202147 :                                   (vocn(:,:,iblk)*vocn(:,:,iblk))), a2D)
    2430        5817 :          if (f_ocndir(1:1) /= 'x') then
    2431     7202147 :            worka(:,:) = c0
    2432      194061 :            do j = jlo, jhi
    2433     6415069 :            do i = ilo, ihi
    2434     6221008 :               if (abs(uocn(i,j,iblk)) > puny .or. abs(vocn(i,j,iblk)) > puny) &
    2435     5664576 :                  worka(i,j) = atan2(uocn(i,j,iblk),vocn(i,j,iblk))*rad_to_deg
    2436     6409252 :               if (worka(i,j) < 0.0 ) then
    2437     2809482 :                  worka(i,j) = worka(i,j) + c360
    2438             :               else
    2439     3411526 :                  worka(i,j) = worka(i,j) * c1
    2440             :               endif
    2441             :            enddo
    2442             :            enddo
    2443        5817 :            call accum_hist_field(n_ocndir, iblk, worka(:,:), a2D)
    2444             :          endif
    2445        5817 :          if (f_frzmlt (1:1) /= 'x') &
    2446        5817 :              call accum_hist_field(n_frzmlt, iblk, frzmlt_init(:,:,iblk), a2D)
    2447             : 
    2448        5817 :          if (f_fswfac (1:1) /= 'x') &
    2449        5817 :              call accum_hist_field(n_fswfac, iblk, scale_factor(:,:,iblk), a2D)
    2450        5817 :          if (f_fswabs (1:1) /= 'x') &
    2451           0 :              call accum_hist_field(n_fswabs, iblk, fswabs(:,:,iblk), a2D)
    2452             : 
    2453        5817 :          if (f_fswint_ai (1:1) /= 'x') &
    2454        5817 :              call accum_hist_field(n_fswint_ai, iblk, fswint_ai(:,:,iblk), a2D)
    2455             : 
    2456        5817 :          if (f_fswabs_ai(1:1)/= 'x') &
    2457     7202147 :              call accum_hist_field(n_fswabs_ai, iblk, fswabs(:,:,iblk)*workb(:,:), a2D)
    2458             : 
    2459        5817 :          if (f_albsni (1:1) /= 'x') &
    2460             :              call accum_hist_field(n_albsni, iblk, &   ! LCOV_EXCL_LINE
    2461             :                                   (awtvdr*alvdr(:,:,iblk) &   ! LCOV_EXCL_LINE
    2462             :                                  + awtidr*alidr(:,:,iblk) &   ! LCOV_EXCL_LINE
    2463             :                                  + awtvdf*alvdf(:,:,iblk) &   ! LCOV_EXCL_LINE
    2464     7202147 :                                  + awtidf*alidf(:,:,iblk))*workb(:,:), a2D)
    2465        5817 :          if (f_alvdr  (1:1) /= 'x') &
    2466           0 :              call accum_hist_field(n_alvdr,  iblk, alvdr(:,:,iblk), a2D)
    2467        5817 :          if (f_alidr  (1:1) /= 'x') &
    2468           0 :              call accum_hist_field(n_alidr,  iblk, alidr(:,:,iblk), a2D)
    2469        5817 :          if (f_alvdf  (1:1) /= 'x') &
    2470           0 :              call accum_hist_field(n_alvdf,  iblk, alvdf(:,:,iblk), a2D)
    2471        5817 :          if (f_alidf  (1:1) /= 'x') &
    2472           0 :              call accum_hist_field(n_alidf,  iblk, alidf(:,:,iblk), a2D)
    2473        5817 :          if (f_alvdr_ai  (1:1) /= 'x') &
    2474           0 :              call accum_hist_field(n_alvdr_ai,  iblk, alvdr_ai(:,:,iblk), a2D)
    2475        5817 :          if (f_alidr_ai  (1:1) /= 'x') &
    2476           0 :              call accum_hist_field(n_alidr_ai,  iblk, alidr_ai(:,:,iblk), a2D)
    2477        5817 :          if (f_alvdf_ai  (1:1) /= 'x') &
    2478           0 :              call accum_hist_field(n_alvdf_ai,  iblk, alvdf_ai(:,:,iblk), a2D)
    2479        5817 :          if (f_alidf_ai  (1:1) /= 'x') &
    2480           0 :              call accum_hist_field(n_alidf_ai,  iblk, alidf_ai(:,:,iblk), a2D)
    2481             : 
    2482        5817 :          if (f_albice (1:1) /= 'x') &
    2483           0 :              call accum_hist_field(n_albice, iblk, albice(:,:,iblk), a2D)
    2484        5817 :          if (f_albsno (1:1) /= 'x') &
    2485           0 :              call accum_hist_field(n_albsno, iblk, albsno(:,:,iblk), a2D)
    2486        5817 :          if (f_albpnd (1:1) /= 'x') &
    2487           0 :              call accum_hist_field(n_albpnd, iblk, albpnd(:,:,iblk), a2D)
    2488        5817 :          if (f_coszen (1:1) /= 'x') &
    2489           0 :              call accum_hist_field(n_coszen, iblk, coszen(:,:,iblk), a2D)
    2490             : 
    2491        5817 :          if (f_flat   (1:1) /= 'x') &
    2492           0 :              call accum_hist_field(n_flat,   iblk, flat(:,:,iblk), a2D)
    2493        5817 :          if (f_flat_ai(1:1) /= 'x') &
    2494     7202147 :              call accum_hist_field(n_flat_ai,iblk, flat(:,:,iblk)*workb(:,:), a2D)
    2495        5817 :          if (f_fsens  (1:1) /= 'x') &
    2496           0 :              call accum_hist_field(n_fsens,   iblk, fsens(:,:,iblk), a2D)
    2497        5817 :          if (f_fsens_ai(1:1)/= 'x') &
    2498     7202147 :              call accum_hist_field(n_fsens_ai,iblk, fsens(:,:,iblk)*workb(:,:), a2D)
    2499        5817 :          if (f_flwup  (1:1) /= 'x') &
    2500           0 :              call accum_hist_field(n_flwup,   iblk, flwout(:,:,iblk), a2D)
    2501        5817 :          if (f_flwup_ai(1:1)/= 'x') &
    2502     7202147 :              call accum_hist_field(n_flwup_ai,iblk, flwout(:,:,iblk)*workb(:,:), a2D)
    2503        5817 :          if (f_evap   (1:1) /= 'x') &
    2504           0 :              call accum_hist_field(n_evap,   iblk, evap(:,:,iblk), a2D)
    2505        5817 :          if (f_evap_ai(1:1) /= 'x') &
    2506     7202147 :              call accum_hist_field(n_evap_ai,iblk, evap(:,:,iblk)*workb(:,:), a2D)
    2507             : 
    2508        5817 :          if (f_Tair   (1:1) /= 'x') &
    2509        5817 :              call accum_hist_field(n_Tair,   iblk, Tair(:,:,iblk), a2D)
    2510        5817 :          if (f_Tref   (1:1) /= 'x') &
    2511           0 :              call accum_hist_field(n_Tref,   iblk, Tref(:,:,iblk), a2D)
    2512        5817 :          if (f_Qref   (1:1) /= 'x') &
    2513           0 :              call accum_hist_field(n_Qref,   iblk, Qref(:,:,iblk), a2D)
    2514        5817 :          if (f_congel (1:1) /= 'x') &
    2515        5817 :              call accum_hist_field(n_congel, iblk, congel(:,:,iblk), a2D)
    2516        5817 :          if (f_frazil (1:1) /= 'x') &
    2517        5817 :              call accum_hist_field(n_frazil, iblk, frazil(:,:,iblk), a2D)
    2518        5817 :          if (f_snoice (1:1) /= 'x') &
    2519        5817 :              call accum_hist_field(n_snoice, iblk, snoice(:,:,iblk), a2D)
    2520        5817 :          if (f_dsnow (1:1) /= 'x') &
    2521           0 :              call accum_hist_field(n_dsnow, iblk, dsnow(:,:,iblk), a2D)
    2522        5817 :          if (f_meltt  (1:1) /= 'x') &
    2523        5817 :              call accum_hist_field(n_meltt,  iblk, meltt(:,:,iblk), a2D)
    2524        5817 :          if (f_melts  (1:1) /= 'x') &
    2525        5817 :               call accum_hist_field(n_melts,  iblk, melts(:,:,iblk), a2D)
    2526        5817 :          if (f_meltb  (1:1) /= 'x') &
    2527        5817 :              call accum_hist_field(n_meltb,  iblk, meltb(:,:,iblk), a2D)
    2528        5817 :          if (f_meltl  (1:1) /= 'x') &
    2529        5817 :              call accum_hist_field(n_meltl,  iblk, meltl(:,:,iblk), a2D)
    2530             : 
    2531        5817 :          if (f_fresh  (1:1) /= 'x') &
    2532           0 :              call accum_hist_field(n_fresh,   iblk, fresh(:,:,iblk), a2D)
    2533        5817 :          if (f_fresh_ai(1:1)/= 'x') &
    2534        5817 :              call accum_hist_field(n_fresh_ai,iblk, fresh_ai(:,:,iblk), a2D)
    2535        5817 :          if (f_fsalt  (1:1) /= 'x') &
    2536           0 :              call accum_hist_field(n_fsalt,   iblk, fsalt(:,:,iblk), a2D)
    2537        5817 :          if (f_fsalt_ai(1:1)/= 'x') &
    2538        5817 :              call accum_hist_field(n_fsalt_ai,iblk, fsalt_ai(:,:,iblk), a2D)
    2539             : 
    2540        5817 :          if (f_fbot(1:1)/= 'x') &
    2541        5817 :              call accum_hist_field(n_fbot,iblk, fbot(:,:,iblk), a2D)
    2542        5817 :          if (f_fhocn  (1:1) /= 'x') &
    2543           0 :              call accum_hist_field(n_fhocn,   iblk, fhocn(:,:,iblk), a2D)
    2544        5817 :          if (f_fhocn_ai(1:1)/= 'x') &
    2545        5817 :              call accum_hist_field(n_fhocn_ai,iblk, fhocn_ai(:,:,iblk), a2D)
    2546        5817 :          if (f_fswthru(1:1) /= 'x') &
    2547           0 :              call accum_hist_field(n_fswthru, iblk, fswthru(:,:,iblk), a2D)
    2548        5817 :          if (f_fswthru_ai(1:1)/= 'x') &
    2549        5817 :              call accum_hist_field(n_fswthru_ai,iblk, fswthru_ai(:,:,iblk), a2D)
    2550             : 
    2551        5817 :          if (f_strairx(1:1) /= 'x') &
    2552        5817 :              call accum_hist_field(n_strairx, iblk, strairxU(:,:,iblk), a2D)
    2553        5817 :          if (f_strairy(1:1) /= 'x') &
    2554        5817 :              call accum_hist_field(n_strairy, iblk, strairyU(:,:,iblk), a2D)
    2555        5817 :          if (f_strtltx(1:1) /= 'x') &
    2556           0 :              call accum_hist_field(n_strtltx, iblk, strtltxU(:,:,iblk), a2D)
    2557        5817 :          if (f_strtlty(1:1) /= 'x') &
    2558           0 :              call accum_hist_field(n_strtlty, iblk, strtltyU(:,:,iblk), a2D)
    2559        5817 :          if (f_strcorx(1:1) /= 'x') &
    2560           0 :              call accum_hist_field(n_strcorx, iblk, fmU(:,:,iblk)*vvel(:,:,iblk), a2D)
    2561        5817 :          if (f_strcory(1:1) /= 'x') &
    2562           0 :              call accum_hist_field(n_strcory, iblk,-fmU(:,:,iblk)*uvel(:,:,iblk), a2D)
    2563        5817 :          if (f_strocnx(1:1) /= 'x') &
    2564           0 :              call accum_hist_field(n_strocnx, iblk, strocnxU(:,:,iblk), a2D)
    2565        5817 :          if (f_strocny(1:1) /= 'x') &
    2566           0 :              call accum_hist_field(n_strocny, iblk, strocnyU(:,:,iblk), a2D)
    2567        5817 :          if (f_strintx(1:1) /= 'x') &
    2568           0 :              call accum_hist_field(n_strintx, iblk, strintxU(:,:,iblk), a2D)
    2569        5817 :          if (f_strinty(1:1) /= 'x') &
    2570           0 :              call accum_hist_field(n_strinty, iblk, strintyU(:,:,iblk), a2D)
    2571        5817 :          if (f_taubx(1:1) /= 'x') &
    2572           0 :              call accum_hist_field(n_taubx, iblk, taubxU(:,:,iblk), a2D)
    2573        5817 :          if (f_tauby(1:1) /= 'x') &
    2574           0 :              call accum_hist_field(n_tauby, iblk, taubyU(:,:,iblk), a2D)
    2575        5817 :          if (f_strairxN(1:1) /= 'x') &
    2576           0 :              call accum_hist_field(n_strairxN, iblk, strairxN(:,:,iblk), a2D)
    2577        5817 :          if (f_strairyN(1:1) /= 'x') &
    2578           0 :              call accum_hist_field(n_strairyN, iblk, strairyN(:,:,iblk), a2D)
    2579        5817 :          if (f_strairxE(1:1) /= 'x') &
    2580           0 :              call accum_hist_field(n_strairxE, iblk, strairxE(:,:,iblk), a2D)
    2581        5817 :          if (f_strairyE(1:1) /= 'x') &
    2582           0 :              call accum_hist_field(n_strairyE, iblk, strairyE(:,:,iblk), a2D)
    2583        5817 :          if (f_strtltxN(1:1) /= 'x') &
    2584           0 :              call accum_hist_field(n_strtltxN, iblk, strtltxN(:,:,iblk), a2D)
    2585        5817 :          if (f_strtltyN(1:1) /= 'x') &
    2586           0 :              call accum_hist_field(n_strtltyN, iblk, strtltyN(:,:,iblk), a2D)
    2587        5817 :          if (f_strtltxE(1:1) /= 'x') &
    2588           0 :              call accum_hist_field(n_strtltxE, iblk, strtltxE(:,:,iblk), a2D)
    2589        5817 :          if (f_strtltyE(1:1) /= 'x') &
    2590           0 :              call accum_hist_field(n_strtltyE, iblk, strtltyE(:,:,iblk), a2D)
    2591        5817 :          if (f_strcorxN(1:1) /= 'x') &
    2592           0 :              call accum_hist_field(n_strcorxN, iblk, fmN(:,:,iblk)*vvelN(:,:,iblk), a2D)
    2593        5817 :          if (f_strcoryN(1:1) /= 'x') &
    2594           0 :              call accum_hist_field(n_strcoryN, iblk,-fmN(:,:,iblk)*uvelN(:,:,iblk), a2D)
    2595        5817 :          if (f_strcorxE(1:1) /= 'x') &
    2596           0 :              call accum_hist_field(n_strcorxE, iblk, fmE(:,:,iblk)*vvelE(:,:,iblk), a2D)
    2597        5817 :          if (f_strcoryE(1:1) /= 'x') &
    2598           0 :              call accum_hist_field(n_strcoryE, iblk,-fmE(:,:,iblk)*uvelE(:,:,iblk), a2D)
    2599        5817 :          if (f_strocnxN(1:1) /= 'x') &
    2600           0 :              call accum_hist_field(n_strocnxN, iblk, strocnxN(:,:,iblk), a2D)
    2601        5817 :          if (f_strocnyN(1:1) /= 'x') &
    2602           0 :              call accum_hist_field(n_strocnyN, iblk, strocnyN(:,:,iblk), a2D)
    2603        5817 :          if (f_strocnxE(1:1) /= 'x') &
    2604           0 :              call accum_hist_field(n_strocnxE, iblk, strocnxE(:,:,iblk), a2D)
    2605        5817 :          if (f_strocnyE(1:1) /= 'x') &
    2606           0 :              call accum_hist_field(n_strocnyE, iblk, strocnyE(:,:,iblk), a2D)
    2607        5817 :          if (f_strintxN(1:1) /= 'x') &
    2608           0 :              call accum_hist_field(n_strintxN, iblk, strintxN(:,:,iblk), a2D)
    2609        5817 :          if (f_strintyN(1:1) /= 'x') &
    2610           0 :              call accum_hist_field(n_strintyN, iblk, strintyN(:,:,iblk), a2D)
    2611        5817 :          if (f_strintxE(1:1) /= 'x') &
    2612           0 :              call accum_hist_field(n_strintxE, iblk, strintxE(:,:,iblk), a2D)
    2613        5817 :          if (f_strintyE(1:1) /= 'x') &
    2614           0 :              call accum_hist_field(n_strintyE, iblk, strintyE(:,:,iblk), a2D)
    2615        5817 :          if (f_taubxN(1:1) /= 'x') &
    2616           0 :              call accum_hist_field(n_taubxN, iblk, taubxN(:,:,iblk), a2D)
    2617        5817 :          if (f_taubyN(1:1) /= 'x') &
    2618           0 :              call accum_hist_field(n_taubyN, iblk, taubyN(:,:,iblk), a2D)
    2619        5817 :          if (f_taubxE(1:1) /= 'x') &
    2620           0 :              call accum_hist_field(n_taubxE, iblk, taubxE(:,:,iblk), a2D)
    2621        5817 :          if (f_taubyE(1:1) /= 'x') &
    2622           0 :              call accum_hist_field(n_taubyE, iblk, taubyE(:,:,iblk), a2D)
    2623        5817 :          if (f_strength(1:1)/= 'x') &
    2624        5817 :              call accum_hist_field(n_strength,iblk, strength(:,:,iblk), a2D)
    2625             : 
    2626             : ! The following fields (divu, shear, sig1, and sig2) will be smeared
    2627             : !  if averaged over more than a few days.
    2628             : ! Snapshots may be more useful (see below).
    2629             : 
    2630             : !        if (f_divu   (1:1) /= 'x') &
    2631             : !             call accum_hist_field(n_divu,    iblk, divu(:,:,iblk), a2D)
    2632             : !        if (f_shear  (1:1) /= 'x') &
    2633             : !             call accum_hist_field(n_shear,   iblk, shear(:,:,iblk), a2D)
    2634             : !        if (f_sig1   (1:1) /= 'x') &
    2635             : !             call accum_hist_field(n_sig1,    iblk, sig1(:,:,iblk), a2D)
    2636             : !        if (f_sig2   (1:1) /= 'x') &
    2637             : !             call accum_hist_field(n_sig2,    iblk, sig2(:,:,iblk), a2D)
    2638             : !        if (f_trsig  (1:1) /= 'x') &
    2639             : !             call accum_hist_field(n_trsig,   iblk, trsig(:,:,iblk), a2D)
    2640             : 
    2641        5817 :          if (f_dvidtt (1:1) /= 'x') &
    2642        5817 :              call accum_hist_field(n_dvidtt,  iblk, dvidtt(:,:,iblk), a2D)
    2643        5817 :          if (f_dvidtd (1:1) /= 'x') &
    2644        5817 :              call accum_hist_field(n_dvidtd,  iblk, dvidtd(:,:,iblk), a2D)
    2645        5817 :          if (f_daidtt (1:1) /= 'x') &
    2646        5817 :              call accum_hist_field(n_daidtt,  iblk, daidtt(:,:,iblk), a2D)
    2647        5817 :          if (f_daidtd (1:1) /= 'x') &
    2648        5817 :              call accum_hist_field(n_daidtd,  iblk, daidtd(:,:,iblk), a2D)
    2649        5817 :          if (f_dagedtt (1:1) /= 'x') &
    2650        5817 :              call accum_hist_field(n_dagedtt, iblk, dagedtt(:,:,iblk), a2D)
    2651        5817 :          if (f_dagedtd (1:1) /= 'x') &
    2652        5817 :              call accum_hist_field(n_dagedtd, iblk, dagedtd(:,:,iblk), a2D)
    2653             : 
    2654        5817 :          if (f_fsurf_ai(1:1)/= 'x') &
    2655           0 :              call accum_hist_field(n_fsurf_ai,iblk, fsurf(:,:,iblk)*workb(:,:), a2D)
    2656        5817 :          if (f_fcondtop_ai(1:1)/= 'x') &
    2657             :              call accum_hist_field(n_fcondtop_ai, iblk, &   ! LCOV_EXCL_LINE
    2658           0 :                                                  fcondtop(:,:,iblk)*workb(:,:), a2D)
    2659             : 
    2660        5817 :          if (f_icepresent(1:1) /= 'x') then
    2661     7202147 :            worka(:,:) = c0
    2662      194061 :            do j = jlo, jhi
    2663     6415069 :            do i = ilo, ihi
    2664     6409252 :               if (aice(i,j,iblk) > puny) worka(i,j) = c1
    2665             :            enddo
    2666             :            enddo
    2667        5817 :            call accum_hist_field(n_icepresent, iblk, worka(:,:), a2D)
    2668             :          endif
    2669             : 
    2670             :          ! 2D CMIP fields
    2671             : 
    2672        5817 :          if (f_sithick(1:1) /= 'x') then
    2673           0 :            worka(:,:) = c0
    2674           0 :            do j = jlo, jhi
    2675           0 :            do i = ilo, ihi
    2676           0 :               if (aice(i,j,iblk) > puny) worka(i,j) = vice(i,j,iblk)
    2677             :            enddo
    2678             :            enddo
    2679           0 :            call accum_hist_field(n_sithick, iblk, worka(:,:), a2D)
    2680             :          endif
    2681             : 
    2682        5817 :          if (f_siage(1:1) /= 'x') then
    2683           0 :            worka(:,:) = c0
    2684           0 :            do j = jlo, jhi
    2685           0 :            do i = ilo, ihi
    2686           0 :               if (aice(i,j,iblk) > puny) worka(i,j) = aice(i,j,iblk)*trcr(i,j,nt_iage,iblk)
    2687             :            enddo
    2688             :            enddo
    2689           0 :            call accum_hist_field(n_siage, iblk, worka(:,:), a2D)
    2690             :          endif
    2691             : 
    2692        5817 :          if (f_sisnthick(1:1) /= 'x') then
    2693           0 :            worka(:,:) = c0
    2694           0 :            do j = jlo, jhi
    2695           0 :            do i = ilo, ihi
    2696           0 :               if (vsno(i,j,iblk) > puny) &
    2697           0 :                  worka(i,j) = vsno(i,j,iblk)
    2698             :            enddo
    2699             :            enddo
    2700           0 :            call accum_hist_field(n_sisnthick, iblk, worka(:,:), a2D)
    2701             :          endif
    2702             : 
    2703        5817 :          if (f_sitemptop(1:1) /= 'x') then
    2704           0 :            worka(:,:) = c0
    2705           0 :            do j = jlo, jhi
    2706           0 :            do i = ilo, ihi
    2707           0 :               if (aice(i,j,iblk) > puny) &
    2708           0 :               worka(i,j) = aice(i,j,iblk)*(trcr(i,j,nt_Tsfc,iblk)+Tffresh)
    2709             :            enddo
    2710             :            enddo
    2711           0 :            call accum_hist_field(n_sitemptop, iblk, worka(:,:), a2D)
    2712             :          endif
    2713             : 
    2714        5817 :          if (f_sitempsnic(1:1) /= 'x') then
    2715           0 :            worka(:,:) = c0
    2716           0 :            do j = jlo, jhi
    2717           0 :            do i = ilo, ihi
    2718           0 :               if (vsno(i,j,iblk) > puny .and. aice_init(i,j,iblk) > puny) then
    2719           0 :                  worka(i,j) = aice(i,j,iblk)*(Tsnice(i,j,iblk)/aice_init(i,j,iblk)+Tffresh)
    2720             :               else
    2721           0 :                  worka(i,j) = aice(i,j,iblk)*(trcr(i,j,nt_Tsfc,iblk)+Tffresh)
    2722             :               endif
    2723             :            enddo
    2724             :            enddo
    2725           0 :            call accum_hist_field(n_sitempsnic, iblk, worka(:,:), a2D)
    2726             :          endif
    2727             : 
    2728        5817 :          if (f_sitempbot(1:1) /= 'x') then
    2729           0 :            worka(:,:) = c0
    2730           0 :            do j = jlo, jhi
    2731           0 :            do i = ilo, ihi
    2732           0 :               if (aice_init(i,j,iblk) > puny) &
    2733           0 :                  worka(i,j) = aice(i,j,iblk)*(Tbot(i,j,iblk)/aice_init(i,j,iblk)+Tffresh)
    2734             :            enddo
    2735             :            enddo
    2736           0 :            call accum_hist_field(n_sitempbot, iblk, worka(:,:), a2D)
    2737             :          endif
    2738             : 
    2739        5817 :          if (f_siu(1:1) /= 'x') then
    2740           0 :            worka(:,:) = c0
    2741           0 :            do j = jlo, jhi
    2742           0 :            do i = ilo, ihi
    2743           0 :               if (aice(i,j,iblk) > puny) worka(i,j) = aice(i,j,iblk)*uvel(i,j,iblk)
    2744             :            enddo
    2745             :            enddo
    2746           0 :            call accum_hist_field(n_siu, iblk, worka(:,:), a2D)
    2747             :          endif
    2748             : 
    2749        5817 :          if (f_siv(1:1) /= 'x') then
    2750           0 :            worka(:,:) = c0
    2751           0 :            do j = jlo, jhi
    2752           0 :            do i = ilo, ihi
    2753           0 :               if (aice(i,j,iblk) > puny) worka(i,j) = aice(i,j,iblk)*vvel(i,j,iblk)
    2754             :            enddo
    2755             :            enddo
    2756           0 :            call accum_hist_field(n_siv, iblk, worka(:,:), a2D)
    2757             :          endif
    2758             : 
    2759        5817 :          if (f_sispeed(1:1) /= 'x') then
    2760           0 :            worka(:,:) = c0
    2761           0 :            do j = jlo, jhi
    2762           0 :            do i = ilo, ihi
    2763           0 :               if (aice(i,j,iblk) > puny) worka(i,j) = aice(i,j,iblk) &
    2764           0 :                  * sqrt(uvel(i,j,iblk)*uvel(i,j,iblk)+vvel(i,j,iblk)*vvel(i,j,iblk))
    2765             :            enddo
    2766             :            enddo
    2767           0 :            call accum_hist_field(n_sispeed, iblk, worka(:,:), a2D)
    2768             :          endif
    2769        5817 :          if (f_sidir(1:1) /= 'x') then
    2770           0 :            worka(:,:) = c0
    2771           0 :            do j = jlo, jhi
    2772           0 :            do i = ilo, ihi
    2773           0 :               if (abs(uvel(i,j,iblk)) > puny .or. abs(vvel(i,j,iblk)) > puny) &
    2774           0 :                  worka(i,j) = atan2(uvel(i,j,iblk),vvel(i,j,iblk))*rad_to_deg
    2775           0 :               if (worka(i,j) < 0.0 ) then
    2776           0 :                  worka(i,j) = worka(i,j) + c360
    2777             :               else
    2778           0 :                  worka(i,j) = worka(i,j) * c1
    2779             :               endif
    2780             :            enddo
    2781             :            enddo
    2782           0 :            call accum_hist_field(n_sidir, iblk, worka(:,:), a2D)
    2783             :          endif
    2784        5817 :          if (f_sidmasstranx(1:1) /= 'x') then
    2785           0 :            worka(:,:) = c0
    2786           0 :            do j = jlo, jhi
    2787           0 :            do i = ilo, ihi
    2788           0 :               if (aice(i,j,iblk) > puny) &
    2789             :                  worka(i,j) = (rhoi*p5*(vice(i+1,j,iblk)+vice(i,j,iblk))*dyU(i,j,iblk) &   ! LCOV_EXCL_LINE
    2790             :                             + rhos*p5*(vsno(i+1,j,iblk)+vsno(i,j,iblk))*dyU(i,j,iblk)) &   ! LCOV_EXCL_LINE
    2791           0 :                             *  p5*(uvel(i,j-1,iblk)+uvel(i,j,iblk))
    2792             :            enddo
    2793             :            enddo
    2794           0 :            call accum_hist_field(n_sidmasstranx, iblk, worka(:,:), a2D)
    2795             :          endif
    2796             : 
    2797        5817 :          if (f_sidmasstrany(1:1) /= 'x') then
    2798           0 :            worka(:,:) = c0
    2799           0 :            do j = jlo, jhi
    2800           0 :            do i = ilo, ihi
    2801           0 :               if (aice(i,j,iblk) > puny) &
    2802             :                  worka(i,j) = (rhoi*p5*(vice(i,j+1,iblk)+vice(i,j,iblk))*dxU(i,j,iblk) &   ! LCOV_EXCL_LINE
    2803             :                             + rhos*p5*(vsno(i,j+1,iblk)+vsno(i,j,iblk))*dxU(i,j,iblk)) &   ! LCOV_EXCL_LINE
    2804           0 :                             *  p5*(vvel(i-1,j,iblk)+vvel(i,j,iblk))
    2805             :            enddo
    2806             :            enddo
    2807           0 :            call accum_hist_field(n_sidmasstrany, iblk, worka(:,:), a2D)
    2808             :          endif
    2809             : 
    2810        5817 :          if (f_sistrxdtop(1:1) /= 'x') then
    2811           0 :            worka(:,:) = c0
    2812           0 :            do j = jlo, jhi
    2813           0 :            do i = ilo, ihi
    2814           0 :               if (aice_init(i,j,iblk) > puny) &
    2815           0 :                  worka(i,j) = aice(i,j,iblk)*(aice(i,j,iblk)*strairxU(i,j,iblk)/aice_init(i,j,iblk))
    2816             :            enddo
    2817             :            enddo
    2818           0 :            call accum_hist_field(n_sistrxdtop, iblk, worka(:,:), a2D)
    2819             :          endif
    2820             : 
    2821        5817 :          if (f_sistrydtop(1:1) /= 'x') then
    2822           0 :            worka(:,:) = c0
    2823           0 :            do j = jlo, jhi
    2824           0 :            do i = ilo, ihi
    2825           0 :               if (aice_init(i,j,iblk) > puny) &
    2826           0 :                  worka(i,j) = aice(i,j,iblk)*(aice(i,j,iblk)*strairyU(i,j,iblk)/aice_init(i,j,iblk))
    2827             :            enddo
    2828             :            enddo
    2829           0 :            call accum_hist_field(n_sistrydtop, iblk, worka(:,:), a2D)
    2830             :          endif
    2831             : 
    2832        5817 :          if (f_sistrxubot(1:1) /= 'x') then
    2833           0 :            worka(:,:) = c0
    2834           0 :            do j = jlo, jhi
    2835           0 :            do i = ilo, ihi
    2836           0 :               if (aice(i,j,iblk) > puny) &
    2837           0 :                  worka(i,j) = aice(i,j,iblk)*strocnxU(i,j,iblk)
    2838             :            enddo
    2839             :            enddo
    2840           0 :            call accum_hist_field(n_sistrxubot, iblk, worka(:,:), a2D)
    2841             :          endif
    2842             : 
    2843        5817 :          if (f_sistryubot(1:1) /= 'x') then
    2844           0 :            worka(:,:) = c0
    2845           0 :            do j = jlo, jhi
    2846           0 :            do i = ilo, ihi
    2847           0 :               if (aice(i,j,iblk) > puny) &
    2848           0 :                  worka(i,j) = aice(i,j,iblk)*strocnyU(i,j,iblk)
    2849             :            enddo
    2850             :            enddo
    2851           0 :            call accum_hist_field(n_sistryubot, iblk, worka(:,:), a2D)
    2852             :          endif
    2853             : 
    2854        5817 :          if (f_sicompstren(1:1) /= 'x') then
    2855           0 :            worka(:,:) = c0
    2856           0 :            do j = jlo, jhi
    2857           0 :            do i = ilo, ihi
    2858           0 :               if (aice(i,j,iblk) > puny) &
    2859           0 :                  worka(i,j) = aice(i,j,iblk)*strength(i,j,iblk)
    2860             :            enddo
    2861             :            enddo
    2862           0 :            call accum_hist_field(n_sicompstren, iblk, worka(:,:), a2D)
    2863             :          endif
    2864             : 
    2865        5817 :          if (f_sialb(1:1) /= 'x') then
    2866           0 :            worka(:,:) = c0
    2867           0 :            do j = jlo, jhi
    2868           0 :            do i = ilo, ihi
    2869           0 :               if (fsw(i,j,iblk) > puny .and. aice_init(i,j,iblk) > puny) then
    2870             :                  worka(i,j) = aice(i,j,iblk)*(fsw(i,j,iblk)-fswabs(i,j,iblk) &
    2871           0 :                             * aice(i,j,iblk)/aice_init(i,j,iblk)) / fsw(i,j,iblk)
    2872             :               endif
    2873             :            enddo
    2874             :            enddo
    2875           0 :            call accum_hist_field(n_sialb, iblk, worka(:,:), a2D)
    2876             :          endif
    2877             : 
    2878        5817 :          if (f_sihc(1:1) /= 'x') then
    2879           0 :            worka(:,:) = c0
    2880           0 :            do k = 1,nzilyr
    2881           0 :            do j = jlo, jhi
    2882           0 :            do i = ilo, ihi
    2883           0 :               worka(i,j) = worka(i,j) + trcr(i,j,nt_qice+k-1,iblk)*vice(i,j,iblk)/real(nzilyr,kind=dbl_kind)
    2884             :            enddo
    2885             :            enddo
    2886             :            enddo
    2887           0 :            call accum_hist_field(n_sihc, iblk, worka(:,:), a2D)
    2888             :          endif
    2889             : 
    2890        5817 :          if (f_sisnhc(1:1) /= 'x') then
    2891           0 :            worka(:,:) = c0
    2892           0 :            do k = 1,nzslyr
    2893           0 :            do j = jlo, jhi
    2894           0 :            do i = ilo, ihi
    2895           0 :               worka(i,j) = worka(i,j) + trcr(i,j,nt_qsno+k-1,iblk)*vsno(i,j,iblk)/real(nzslyr,kind=dbl_kind)
    2896             :            enddo
    2897             :            enddo
    2898             :            enddo
    2899           0 :            call accum_hist_field(n_sisnhc, iblk, worka(:,:), a2D)
    2900             :          endif
    2901             : 
    2902        5817 :          if (f_sidconcth(1:1) /= 'x') then
    2903           0 :            worka(:,:) = c0
    2904           0 :            do j = jlo, jhi
    2905           0 :            do i = ilo, ihi
    2906           0 :               if (aice(i,j,iblk) > puny) then
    2907           0 :                  worka(i,j) = daidtt(i,j,iblk)
    2908             :               endif
    2909             :            enddo
    2910             :            enddo
    2911           0 :            call accum_hist_field(n_sidconcth, iblk, worka(:,:), a2D)
    2912             :          endif
    2913             : 
    2914        5817 :          if (f_sidconcdyn(1:1) /= 'x') then
    2915           0 :            worka(:,:) = c0
    2916           0 :            do j = jlo, jhi
    2917           0 :            do i = ilo, ihi
    2918           0 :               if (aice(i,j,iblk) > puny) then
    2919           0 :                  worka(i,j) = daidtd(i,j,iblk)
    2920             :               endif
    2921             :            enddo
    2922             :            enddo
    2923           0 :            call accum_hist_field(n_sidconcdyn, iblk, worka(:,:), a2D)
    2924             :          endif
    2925             : 
    2926        5817 :          if (f_sidmassth(1:1) /= 'x') then
    2927           0 :            worka(:,:) = c0
    2928           0 :            do j = jlo, jhi
    2929           0 :            do i = ilo, ihi
    2930           0 :               if (aice(i,j,iblk) > puny) then
    2931           0 :                  worka(i,j) = dvidtt(i,j,iblk) * rhoi
    2932             :               endif
    2933             :            enddo
    2934             :            enddo
    2935           0 :            call accum_hist_field(n_sidmassth, iblk, worka(:,:), a2D)
    2936             :          endif
    2937             : 
    2938        5817 :          if (f_sidmassdyn(1:1) /= 'x') then
    2939           0 :            worka(:,:) = c0
    2940           0 :            do j = jlo, jhi
    2941           0 :            do i = ilo, ihi
    2942           0 :               if (aice(i,j,iblk) > puny) then
    2943           0 :                  worka(i,j) = dvidtd(i,j,iblk) * rhoi
    2944             :               endif
    2945             :            enddo
    2946             :            enddo
    2947           0 :            call accum_hist_field(n_sidmassdyn, iblk, worka(:,:), a2D)
    2948             :          endif
    2949             : 
    2950        5817 :          if (f_sidmassgrowthwat(1:1) /= 'x') then
    2951           0 :            worka(:,:) = c0
    2952           0 :            do j = jlo, jhi
    2953           0 :            do i = ilo, ihi
    2954           0 :               if (aice_init(i,j,iblk) > puny) then
    2955           0 :                  worka(i,j) = frazil(i,j,iblk)*rhoi/dt
    2956             :               endif
    2957             :            enddo
    2958             :            enddo
    2959           0 :            call accum_hist_field(n_sidmassgrowthwat, iblk, worka(:,:), a2D)
    2960             :          endif
    2961             : 
    2962        5817 :          if (f_sidmassgrowthbot(1:1) /= 'x') then
    2963           0 :            worka(:,:) = c0
    2964           0 :            do j = jlo, jhi
    2965           0 :            do i = ilo, ihi
    2966           0 :               if (aice(i,j,iblk) > puny) then
    2967           0 :                  worka(i,j) = congel(i,j,iblk)*rhoi/dt
    2968             :               endif
    2969             :            enddo
    2970             :            enddo
    2971           0 :            call accum_hist_field(n_sidmassgrowthbot, iblk, worka(:,:), a2D)
    2972             :          endif
    2973             : 
    2974        5817 :          if (f_sidmasssi(1:1) /= 'x') then
    2975           0 :            worka(:,:) = c0
    2976           0 :            do j = jlo, jhi
    2977           0 :            do i = ilo, ihi
    2978           0 :               if (aice(i,j,iblk) > puny) then
    2979           0 :                  worka(i,j) = snoice(i,j,iblk)*rhoi/dt
    2980             :               endif
    2981             :            enddo
    2982             :            enddo
    2983           0 :            call accum_hist_field(n_sidmasssi, iblk, worka(:,:), a2D)
    2984             :          endif
    2985             : 
    2986        5817 :          if (f_sidmassevapsubl(1:1) /= 'x') then
    2987           0 :            worka(:,:) = c0
    2988           0 :            do j = jlo, jhi
    2989           0 :            do i = ilo, ihi
    2990           0 :               if (aice(i,j,iblk) > puny) then
    2991           0 :                  worka(i,j) = evapi(i,j,iblk)*rhoi
    2992             :               endif
    2993             :            enddo
    2994             :            enddo
    2995           0 :            call accum_hist_field(n_sidmassevapsubl, iblk, worka(:,:), a2D)
    2996             :          endif
    2997             : 
    2998        5817 :          if (f_sidmassmelttop(1:1) /= 'x') then
    2999           0 :            worka(:,:) = c0
    3000           0 :            do j = jlo, jhi
    3001           0 :            do i = ilo, ihi
    3002           0 :               if (aice(i,j,iblk) > puny) then
    3003           0 :                  worka(i,j) = meltt(i,j,iblk)*rhoi/dt
    3004             :               endif
    3005             :            enddo
    3006             :            enddo
    3007           0 :            call accum_hist_field(n_sidmassmelttop, iblk, worka(:,:), a2D)
    3008             :          endif
    3009             : 
    3010        5817 :          if (f_sidmassmeltbot(1:1) /= 'x') then
    3011           0 :            worka(:,:) = c0
    3012           0 :            do j = jlo, jhi
    3013           0 :            do i = ilo, ihi
    3014           0 :               if (aice(i,j,iblk) > puny) then
    3015           0 :                  worka(i,j) = meltb(i,j,iblk)*rhoi/dt
    3016             :               endif
    3017             :            enddo
    3018             :            enddo
    3019           0 :            call accum_hist_field(n_sidmassmeltbot, iblk, worka(:,:), a2D)
    3020             :          endif
    3021             : 
    3022        5817 :          if (f_sidmasslat(1:1) /= 'x') then
    3023           0 :            worka(:,:) = c0
    3024           0 :            do j = jlo, jhi
    3025           0 :            do i = ilo, ihi
    3026           0 :               if (aice(i,j,iblk) > puny) then
    3027           0 :                  worka(i,j) = meltl(i,j,iblk)*rhoi/dt
    3028             :               endif
    3029             :            enddo
    3030             :            enddo
    3031           0 :            call accum_hist_field(n_sidmasslat, iblk, worka(:,:), a2D)
    3032             :          endif
    3033             : 
    3034        5817 :          if (f_sndmasssubl(1:1) /= 'x') then
    3035           0 :            worka(:,:) = c0
    3036           0 :            do j = jlo, jhi
    3037           0 :            do i = ilo, ihi
    3038           0 :               if (aice(i,j,iblk) > puny) then
    3039           0 :                  worka(i,j) = evaps(i,j,iblk)*rhos
    3040             :               endif
    3041             :            enddo
    3042             :            enddo
    3043           0 :            call accum_hist_field(n_sndmasssubl, iblk, worka(:,:), a2D)
    3044             :          endif
    3045             : 
    3046        5817 :          if (f_sndmasssnf(1:1) /= 'x') then
    3047           0 :            worka(:,:) = c0
    3048           0 :            do j = jlo, jhi
    3049           0 :            do i = ilo, ihi
    3050           0 :               if (aice(i,j,iblk) > puny) then
    3051           0 :                  worka(i,j) = aice(i,j,iblk)*fsnow(i,j,iblk)*rhos
    3052             :               endif
    3053             :            enddo
    3054             :            enddo
    3055           0 :            call accum_hist_field(n_sndmasssnf, iblk, worka(:,:), a2D)
    3056             :          endif
    3057             : 
    3058        5817 :          if (f_sndmassmelt(1:1) /= 'x') then
    3059           0 :            worka(:,:) = c0
    3060           0 :            do j = jlo, jhi
    3061           0 :            do i = ilo, ihi
    3062           0 :               if (aice(i,j,iblk) > puny) then
    3063           0 :                  worka(i,j) = melts(i,j,iblk)*rhos/dt
    3064             :               endif
    3065             :            enddo
    3066             :            enddo
    3067           0 :            call accum_hist_field(n_sndmassmelt, iblk, worka(:,:), a2D)
    3068             :          endif
    3069             : 
    3070        5817 :          if (f_siflswdtop(1:1) /= 'x') then
    3071           0 :            worka(:,:) = c0
    3072           0 :            do j = jlo, jhi
    3073           0 :            do i = ilo, ihi
    3074           0 :               if (fsw(i,j,iblk) > puny .and. aice(i,j,iblk) > puny) then
    3075           0 :                  worka(i,j) = aice(i,j,iblk)*fsw(i,j,iblk)
    3076             :               endif
    3077             :            enddo
    3078             :            enddo
    3079           0 :            call accum_hist_field(n_siflswdtop, iblk, worka(:,:), a2D)
    3080             :          endif
    3081             : 
    3082        5817 :          if (f_siflswutop(1:1) /= 'x') then
    3083           0 :            worka(:,:) = c0
    3084           0 :            do j = jlo, jhi
    3085           0 :            do i = ilo, ihi
    3086           0 :               if (fsw(i,j,iblk) > puny .and. aice_init(i,j,iblk) > puny) then
    3087             :                  worka(i,j) = aice(i,j,iblk)*(fsw(i,j,iblk)-fswabs(i,j,iblk) &
    3088           0 :                             * aice(i,j,iblk)/aice_init(i,j,iblk))
    3089             :               endif
    3090             :            enddo
    3091             :            enddo
    3092           0 :            call accum_hist_field(n_siflswutop, iblk, worka(:,:), a2D)
    3093             :          endif
    3094             : 
    3095        5817 :          if (f_siflswdbot(1:1) /= 'x') then
    3096           0 :            worka(:,:) = c0
    3097           0 :            do j = jlo, jhi
    3098           0 :            do i = ilo, ihi
    3099           0 :               if (aice(i,j,iblk) > puny) then
    3100           0 :                  worka(i,j) = aice(i,j,iblk)*fswthru(i,j,iblk)
    3101             :               endif
    3102             :            enddo
    3103             :            enddo
    3104           0 :            call accum_hist_field(n_siflswdbot, iblk, worka(:,:), a2D)
    3105             :          endif
    3106             : 
    3107        5817 :          if (f_sifllwdtop(1:1) /= 'x') then
    3108           0 :            worka(:,:) = c0
    3109           0 :            do j = jlo, jhi
    3110           0 :            do i = ilo, ihi
    3111           0 :               if (aice(i,j,iblk) > puny) then
    3112           0 :                  worka(i,j) = aice(i,j,iblk)*flw(i,j,iblk)
    3113             :               endif
    3114             :            enddo
    3115             :            enddo
    3116           0 :            call accum_hist_field(n_sifllwdtop, iblk, worka(:,:), a2D)
    3117             :          endif
    3118             : 
    3119        5817 :          if (f_sifllwutop(1:1) /= 'x') then
    3120           0 :            worka(:,:) = c0
    3121           0 :            do j = jlo, jhi
    3122           0 :            do i = ilo, ihi
    3123           0 :               if (aice(i,j,iblk) > puny) then
    3124           0 :                  worka(i,j) = aice(i,j,iblk)*flwout(i,j,iblk)
    3125             :               endif
    3126             :            enddo
    3127             :            enddo
    3128           0 :            call accum_hist_field(n_sifllwutop, iblk, worka(:,:), a2D)
    3129             :          endif
    3130             : 
    3131        5817 :          if (f_siflsenstop(1:1) /= 'x') then
    3132           0 :            worka(:,:) = c0
    3133           0 :            do j = jlo, jhi
    3134           0 :            do i = ilo, ihi
    3135           0 :               if (aice(i,j,iblk) > puny) then
    3136           0 :                  worka(i,j) = aice(i,j,iblk)*fsens(i,j,iblk)
    3137             :               endif
    3138             :            enddo
    3139             :            enddo
    3140           0 :            call accum_hist_field(n_siflsenstop, iblk, worka(:,:), a2D)
    3141             :          endif
    3142             : 
    3143        5817 :          if (f_siflsensupbot(1:1) /= 'x') then
    3144           0 :            worka(:,:) = c0
    3145           0 :            do j = jlo, jhi
    3146           0 :            do i = ilo, ihi
    3147           0 :               if (aice(i,j,iblk) > puny) then
    3148           0 :                  worka(i,j) = aice(i,j,iblk)*fhocn(i,j,iblk)
    3149             :               endif
    3150             :            enddo
    3151             :            enddo
    3152           0 :            call accum_hist_field(n_siflsensupbot, iblk, worka(:,:), a2D)
    3153             :          endif
    3154             : 
    3155        5817 :          if (f_sifllatstop(1:1) /= 'x') then
    3156           0 :            worka(:,:) = c0
    3157           0 :            do j = jlo, jhi
    3158           0 :            do i = ilo, ihi
    3159           0 :               if (aice(i,j,iblk) > puny) then
    3160           0 :                  worka(i,j) = aice(i,j,iblk)*flat(i,j,iblk)
    3161             :               endif
    3162             :            enddo
    3163             :            enddo
    3164           0 :            call accum_hist_field(n_sifllatstop, iblk, worka(:,:), a2D)
    3165             :          endif
    3166             : 
    3167        5817 :          if (f_siflcondtop(1:1) /= 'x') then
    3168           0 :            worka(:,:) = c0
    3169           0 :            do j = jlo, jhi
    3170           0 :            do i = ilo, ihi
    3171           0 :               if (aice(i,j,iblk) > puny) then
    3172           0 :                  worka(i,j) = aice(i,j,iblk)*fcondtop(i,j,iblk)
    3173             :               endif
    3174             :            enddo
    3175             :            enddo
    3176           0 :            call accum_hist_field(n_siflcondtop, iblk, worka(:,:), a2D)
    3177             :          endif
    3178             : 
    3179        5817 :          if (f_siflcondbot(1:1) /= 'x') then
    3180           0 :            worka(:,:) = c0
    3181           0 :            do j = jlo, jhi
    3182           0 :            do i = ilo, ihi
    3183           0 :               if (aice_init(i,j,iblk) > puny) then
    3184           0 :                  worka(i,j) = aice(i,j,iblk)*fcondbot(i,j,iblk)/aice_init(i,j,iblk)
    3185             :               endif
    3186             :            enddo
    3187             :            enddo
    3188           0 :            call accum_hist_field(n_siflcondbot, iblk, worka(:,:), a2D)
    3189             :          endif
    3190             : 
    3191        5817 :          if (f_sipr(1:1) /= 'x') then
    3192           0 :            worka(:,:) = c0
    3193           0 :            do j = jlo, jhi
    3194           0 :            do i = ilo, ihi
    3195           0 :               if (aice(i,j,iblk) > puny) then
    3196           0 :                  worka(i,j) = aice(i,j,iblk)*frain(i,j,iblk)
    3197             :               endif
    3198             :            enddo
    3199             :            enddo
    3200           0 :            call accum_hist_field(n_sipr, iblk, worka(:,:), a2D)
    3201             :          endif
    3202             : 
    3203        5817 :          if (f_sifb(1:1) /= 'x') then
    3204           0 :            worka(:,:) = c0
    3205           0 :            rho_ice = rhoi
    3206           0 :            rho_ocn = rhow
    3207           0 :            do j = jlo, jhi
    3208           0 :            do i = ilo, ihi
    3209           0 :               if (aice(i,j,iblk) > puny) then
    3210           0 :                  if (ktherm == 2) then
    3211           0 :                     rho_ocn = icepack_mushy_density_brine(sss(i,j,iblk))
    3212           0 :                     rho_ice = c0
    3213           0 :                     do k = 1, nzilyr
    3214           0 :                        Tice = icepack_mushy_temperature_mush(trcr(i,j,nt_qice+k-1,iblk),trcr(i,j,nt_sice+k-1,iblk))
    3215           0 :                        Sbr = trcr(i,j,nt_sice+k-1,iblk)
    3216           0 :                        phi = icepack_mushy_liquid_fraction(Tice,Sbr)
    3217           0 :                        rhob = icepack_mushy_density_brine(Sbr)
    3218           0 :                        rho_ice = rho_ice + min(phi*rhob+(c1-phi)*rhoi,rho_ocn)
    3219             :                     enddo
    3220           0 :                     rho_ice = rho_ice / real(nzilyr,kind=dbl_kind)
    3221             :                  endif
    3222           0 :                  worka(i,j) = ((rho_ocn-rho_ice)*vice(i,j,iblk) - rhos*vsno(i,j,iblk))/rho_ocn
    3223             : !                if (worka(i,j) < c0) then
    3224             : !                   write(nu_diag,*) 'negative fb',rho_ocn,rho_ice,rhos
    3225             : !                   write(nu_diag,*) vice(i,j,iblk),vsno(i,j,iblk)
    3226             : !                endif
    3227             :               endif
    3228             :            enddo
    3229             :            enddo
    3230           0 :            call accum_hist_field(n_sifb, iblk, worka(:,:), a2D)
    3231             :          endif
    3232             : 
    3233        5817 :          if (f_siflsaltbot(1:1) /= 'x') then
    3234           0 :            worka(:,:) = c0
    3235           0 :            do j = jlo, jhi
    3236           0 :            do i = ilo, ihi
    3237           0 :               if (aice(i,j,iblk) > puny) then
    3238             : !                Add in frazil flux
    3239           0 :                  if (.not. update_ocn_f) then
    3240           0 :                     if ( ktherm == 2 .and. cpl_frazil == 'fresh_ice_correction') then
    3241           0 :                        dfresh = -rhoi*(frazil(i,j,iblk)-frazil_diag(i,j,iblk))/dt
    3242             :                     else
    3243           0 :                        dfresh = -rhoi*frazil(i,j,iblk)/dt
    3244             :                     endif
    3245             :                  endif
    3246           0 :                  if (saltflux_option == 'prognostic') then
    3247           0 :                     sicen = c0
    3248           0 :                     do k = 1, nzilyr
    3249             :                        sicen = sicen + trcr(i,j,nt_sice+k-1,iblk)*vice(i,j,iblk) &
    3250           0 :                                      / real(nzilyr,kind=dbl_kind)
    3251             :                     enddo
    3252           0 :                     dfsalt = sicen*p001*dfresh
    3253             :                  else
    3254           0 :                     dfsalt = ice_ref_salinity*p001*dfresh
    3255             :                  endif
    3256           0 :                  worka(i,j) = aice(i,j,iblk)*(fsalt(i,j,iblk)+dfsalt)
    3257             :               endif
    3258             :            enddo
    3259             :            enddo
    3260           0 :            call accum_hist_field(n_siflsaltbot, iblk, worka(:,:), a2D)
    3261             :          endif
    3262             : 
    3263        5817 :          if (f_siflfwbot(1:1) /= 'x') then
    3264           0 :            worka(:,:) = c0
    3265           0 :            do j = jlo, jhi
    3266           0 :            do i = ilo, ihi
    3267           0 :               if (aice(i,j,iblk) > puny) then
    3268             : !                Add in frazil flux
    3269           0 :                  if (.not. update_ocn_f) then
    3270           0 :                     if ( ktherm == 2 .and. cpl_frazil == 'fresh_ice_correction') then
    3271           0 :                        dfresh = -rhoi*(frazil(i,j,iblk)-frazil_diag(i,j,iblk))/dt
    3272             :                     else
    3273           0 :                        dfresh = -rhoi*frazil(i,j,iblk)/dt
    3274             :                     endif
    3275             :                  endif
    3276           0 :                  worka(i,j) = aice(i,j,iblk)*(fresh(i,j,iblk)+dfresh)
    3277             :               endif
    3278             :            enddo
    3279             :            enddo
    3280           0 :            call accum_hist_field(n_siflfwbot, iblk, worka(:,:), a2D)
    3281             :          endif
    3282             : 
    3283        5817 :          if (f_siflfwdrain(1:1) /= 'x') then
    3284           0 :            worka(:,:) = c0
    3285           0 :            do j = jlo, jhi
    3286           0 :            do i = ilo, ihi
    3287           0 :               if (aice(i,j,iblk) > puny) then
    3288           0 :                  worka(i,j) = aice(i,j,iblk)*(frain(i,j,iblk)+melts(i,j,iblk)+meltt(i,j,iblk))
    3289             :               endif
    3290             :            enddo
    3291             :            enddo
    3292           0 :            call accum_hist_field(n_siflfwdrain, iblk, worka(:,:), a2D)
    3293             :          endif
    3294             : 
    3295        5817 :          if (f_sidragtop(1:1) /= 'x') then
    3296           0 :            worka(:,:) = c0
    3297           0 :            do j = jlo, jhi
    3298           0 :            do i = ilo, ihi
    3299           0 :               if (aice(i,j,iblk) > puny) then
    3300           0 :                  worka(i,j) = aice(i,j,iblk)*Cdn_atm(i,j,iblk)
    3301             :               endif
    3302             :            enddo
    3303             :            enddo
    3304           0 :            call accum_hist_field(n_sidragtop, iblk, worka(:,:), a2D)
    3305             :          endif
    3306             : 
    3307        5817 :          if (f_sirdgthick(1:1) /= 'x') then
    3308           0 :            worka(:,:) = c0
    3309           0 :            do j = jlo, jhi
    3310           0 :            do i = ilo, ihi
    3311           0 :               if (aice(i,j,iblk)*(c1 - trcr(i,j,nt_alvl,iblk)) > puny) then
    3312             :                  worka(i,j) = vice(i,j,iblk) * (c1 - trcr(i,j,nt_vlvl,iblk)) &
    3313           0 :                            / (aice(i,j,iblk) * (c1 - trcr(i,j,nt_alvl,iblk)))
    3314             :               endif
    3315             :            enddo
    3316             :            enddo
    3317           0 :            call accum_hist_field(n_sirdgthick, iblk, worka(:,:), a2D)
    3318             :          endif
    3319             : 
    3320        5817 :          if (f_siforcetiltx(1:1) /= 'x') then
    3321           0 :            worka(:,:) = c0
    3322           0 :            do j = jlo, jhi
    3323           0 :            do i = ilo, ihi
    3324           0 :               if (aice(i,j,iblk) > puny) then
    3325           0 :                  worka(i,j) = aice(i,j,iblk)*strtltxU(i,j,iblk)
    3326             :               endif
    3327             :            enddo
    3328             :            enddo
    3329           0 :            call accum_hist_field(n_siforcetiltx, iblk, worka(:,:), a2D)
    3330             :          endif
    3331             : 
    3332        5817 :          if (f_siforcetilty(1:1) /= 'x') then
    3333           0 :            worka(:,:) = c0
    3334           0 :            do j = jlo, jhi
    3335           0 :            do i = ilo, ihi
    3336           0 :               if (aice(i,j,iblk) > puny) then
    3337           0 :                  worka(i,j) = aice(i,j,iblk)*strtltyU(i,j,iblk)
    3338             :               endif
    3339             :            enddo
    3340             :            enddo
    3341           0 :            call accum_hist_field(n_siforcetilty, iblk, worka(:,:), a2D)
    3342             :          endif
    3343             : 
    3344        5817 :          if (f_siforcecoriolx(1:1) /= 'x') then
    3345           0 :            worka(:,:) = c0
    3346           0 :            do j = jlo, jhi
    3347           0 :            do i = ilo, ihi
    3348           0 :               if (aice(i,j,iblk) > puny) then
    3349           0 :                  worka(i,j) = aice(i,j,iblk)*fmU(i,j,iblk)*vvel(i,j,iblk)
    3350             :               endif
    3351             :            enddo
    3352             :            enddo
    3353           0 :            call accum_hist_field(n_siforcecoriolx, iblk, worka(:,:), a2D)
    3354             :          endif
    3355             : 
    3356        5817 :          if (f_siforcecorioly(1:1) /= 'x') then
    3357           0 :            worka(:,:) = c0
    3358           0 :            do j = jlo, jhi
    3359           0 :            do i = ilo, ihi
    3360           0 :               if (aice(i,j,iblk) > puny) then
    3361           0 :                  worka(i,j) = -aice(i,j,iblk)*fmU(i,j,iblk)*uvel(i,j,iblk)
    3362             :               endif
    3363             :            enddo
    3364             :            enddo
    3365           0 :            call accum_hist_field(n_siforcecorioly, iblk, worka(:,:), a2D)
    3366             :          endif
    3367             : 
    3368        5817 :          if (f_siforceintstrx(1:1) /= 'x') then
    3369           0 :            worka(:,:) = c0
    3370           0 :            do j = jlo, jhi
    3371           0 :            do i = ilo, ihi
    3372           0 :               if (aice(i,j,iblk) > puny) then
    3373           0 :                  worka(i,j) = aice(i,j,iblk)*strintxU(i,j,iblk)
    3374             :               endif
    3375             :            enddo
    3376             :            enddo
    3377           0 :            call accum_hist_field(n_siforceintstrx, iblk, worka(:,:), a2D)
    3378             :          endif
    3379             : 
    3380        5817 :          if (f_siforceintstry(1:1) /= 'x') then
    3381           0 :            worka(:,:) = c0
    3382           0 :            do j = jlo, jhi
    3383           0 :            do i = ilo, ihi
    3384           0 :               if (aice(i,j,iblk) > puny) then
    3385           0 :                  worka(i,j) = aice(i,j,iblk)*strintyU(i,j,iblk)
    3386             :               endif
    3387             :            enddo
    3388             :            enddo
    3389           0 :            call accum_hist_field(n_siforceintstry, iblk, worka(:,:), a2D)
    3390             :          endif
    3391             : 
    3392             :          endif ! if (allocated(a2D))
    3393             : 
    3394        5817 :          if (allocated(a3Dc)) then
    3395             : 
    3396             :          ! 3D category fields
    3397           0 :          if (f_aicen   (1:1) /= 'x') &
    3398             :              call accum_hist_field(n_aicen-n2D, iblk, ncat_hist, &   ! LCOV_EXCL_LINE
    3399           0 :                                    aicen(:,:,1:ncat_hist,iblk), a3Dc)
    3400           0 :          if (f_vicen   (1:1) /= 'x') &
    3401             :              call accum_hist_field(n_vicen-n2D, iblk, ncat_hist, &   ! LCOV_EXCL_LINE
    3402           0 :                                    vicen(:,:,1:ncat_hist,iblk), a3Dc)
    3403           0 :          if (f_vsnon   (1:1) /= 'x') &
    3404             :              call accum_hist_field(n_vsnon-n2D, iblk, ncat_hist, &   ! LCOV_EXCL_LINE
    3405           0 :                                    vsnon(:,:,1:ncat_hist,iblk), a3Dc)
    3406           0 :          if (f_snowfracn(1:1) /= 'x') &
    3407             :              call accum_hist_field(n_snowfracn-n2D, iblk, ncat_hist, &   ! LCOV_EXCL_LINE
    3408           0 :                                    snowfracn(:,:,1:ncat_hist,iblk), a3Dc)
    3409           0 :          if (f_snowfracn(1:1) /= 'x') &
    3410             :              call accum_hist_field(n_snowfracn-n2D, iblk, ncat_hist, &   ! LCOV_EXCL_LINE
    3411           0 :                                    snowfracn(:,:,1:ncat_hist,iblk), a3Dc)
    3412           0 :          if (f_keffn_top (1:1) /= 'x') &
    3413             :              call accum_hist_field(n_keffn_top-n2D, iblk, ncat_hist, &   ! LCOV_EXCL_LINE
    3414           0 :                                    keffn_top(:,:,1:ncat_hist,iblk), a3Dc)
    3415           0 :          if (f_fsurfn_ai   (1:1) /= 'x') &
    3416             :              call accum_hist_field(n_fsurfn_ai-n2D, iblk, ncat_hist, &   ! LCOV_EXCL_LINE
    3417           0 :                   fsurfn(:,:,1:ncat_hist,iblk)*aicen_init(:,:,1:ncat_hist,iblk), a3Dc)
    3418           0 :          if (f_fcondtopn_ai   (1:1) /= 'x') &
    3419             :              call accum_hist_field(n_fcondtopn_ai-n2D, iblk, ncat_hist, &   ! LCOV_EXCL_LINE
    3420           0 :                   fcondtopn(:,:,1:ncat_hist,iblk)*aicen_init(:,:,1:ncat_hist,iblk), a3Dc)
    3421           0 :          if (f_flatn_ai   (1:1) /= 'x') &
    3422             :              call accum_hist_field(n_flatn_ai-n2D, iblk, ncat_hist, &   ! LCOV_EXCL_LINE
    3423           0 :                   flatn(:,:,1:ncat_hist,iblk)*aicen_init(:,:,1:ncat_hist,iblk), a3Dc)
    3424           0 :          if (f_fsensn_ai   (1:1) /= 'x') &
    3425             :              call accum_hist_field(n_fsensn_ai-n2D, iblk, ncat_hist, &   ! LCOV_EXCL_LINE
    3426           0 :                   fsensn(:,:,1:ncat_hist,iblk)*aicen_init(:,:,1:ncat_hist,iblk), a3Dc)
    3427             :          ! Calculate surface heat flux that causes melt (calculated by the
    3428             :          ! atmos in HadGEM3 so needed for checking purposes)
    3429           0 :          if (f_fmelttn_ai   (1:1) /= 'x') &
    3430             :              call accum_hist_field(n_fmelttn_ai-n2D, iblk, ncat_hist, &   ! LCOV_EXCL_LINE
    3431             :                   max(fsurfn(:,:,1:ncat_hist,iblk) - fcondtopn(:,:,1:ncat_hist,iblk),c0) &   ! LCOV_EXCL_LINE
    3432           0 :                       *aicen_init(:,:,1:ncat_hist,iblk), a3Dc)
    3433             : 
    3434           0 :          if (f_siitdconc   (1:1) /= 'x') then
    3435           0 :            worka3(:,:,:) = c0
    3436           0 :            do n = 1,ncat_hist
    3437           0 :            do j = jlo, jhi
    3438           0 :            do i = ilo, ihi
    3439           0 :               if (aicen(i,j,n,iblk) > puny) then
    3440           0 :                  worka3(i,j,n) = aicen(i,j,n,iblk)
    3441             :               endif
    3442             :            enddo
    3443             :            enddo
    3444             :            enddo
    3445           0 :            call accum_hist_field(n_siitdconc-n2D, iblk, ncat_hist, worka3(:,:,:), a3Dc)
    3446             :          endif
    3447             : 
    3448           0 :          if (f_siitdthick   (1:1) /= 'x') then
    3449           0 :            worka3(:,:,:) = c0
    3450           0 :            do n = 1,ncat_hist
    3451           0 :            do j = jlo, jhi
    3452           0 :            do i = ilo, ihi
    3453           0 :               if (aicen(i,j,n,iblk) > puny) then
    3454           0 :                  worka3(i,j,n) = vicen(i,j,n,iblk)
    3455             :               endif
    3456             :            enddo
    3457             :            enddo
    3458             :            enddo
    3459           0 :            call accum_hist_field(n_siitdthick-n2D, iblk, ncat_hist, worka3(:,:,:), a3Dc)
    3460             :          endif
    3461             : 
    3462           0 :          if (f_siitdsnthick   (1:1) /= 'x') then
    3463           0 :            worka3(:,:,:) = c0
    3464           0 :            do n = 1,ncat_hist
    3465           0 :            do j = jlo, jhi
    3466           0 :            do i = ilo, ihi
    3467           0 :               if (aicen(i,j,n,iblk) > puny) then
    3468           0 :                  worka3(i,j,n) = vsnon(i,j,n,iblk)
    3469             :               endif
    3470             :            enddo
    3471             :            enddo
    3472             :            enddo
    3473           0 :            call accum_hist_field(n_siitdsnthick-n2D, iblk, ncat_hist, worka3(:,:,:), a3Dc)
    3474             :          endif
    3475             : 
    3476             :          endif ! if (allocated(a3Dc))
    3477             : 
    3478        5817 :          if (allocated(a4Di)) then
    3479             : 
    3480             : ! example for 3D field (x,y,z)
    3481             : !         if (f_field3dz   (1:1) /= 'x') &
    3482             : !             call accum_hist_field(n_field3dz-n3Dccum, iblk, nzilyr, &   ! LCOV_EXCL_LINE
    3483             : !                                   field3dz(:,:,1:nzilyr,iblk), a3Dz)
    3484             : 
    3485             :          ! 4D category fields
    3486           0 :          if (f_Tinz   (1:1) /= 'x') then
    3487           0 :             Tinz4d(:,:,:,:) = c0
    3488           0 :             do n = 1, ncat_hist
    3489           0 :                do j = jlo, jhi
    3490           0 :                do i = ilo, ihi
    3491           0 :                   do k = 1, nzilyr
    3492           0 :                      qn = trcrn(i,j,nt_qice+k-1,n,iblk)
    3493           0 :                      sn = trcrn(i,j,nt_sice+k-1,n,iblk)
    3494           0 :                      Tinz4d(i,j,k,n) = icepack_ice_temperature(qn,sn)
    3495             :                   enddo
    3496             :                enddo
    3497             :                enddo
    3498             :             enddo
    3499             :             call accum_hist_field(n_Tinz-n3Dfcum, iblk, nzilyr, ncat_hist, &
    3500           0 :                                   Tinz4d(:,:,1:nzilyr,1:ncat_hist), a4Di)
    3501             :          endif
    3502           0 :          if (f_Sinz   (1:1) /= 'x') then
    3503           0 :             Sinz4d(:,:,:,:) = c0
    3504           0 :             do n = 1, ncat_hist
    3505           0 :                do j = jlo, jhi
    3506           0 :                do i = ilo, ihi
    3507           0 :                   if (vicen(i,j,n,iblk) > puny) then
    3508           0 :                      Sinz4d(i,j,1:nzilyr,n) = trcrn(i,j,nt_sice:nt_sice+nzilyr-1,n,iblk)
    3509             :                   endif
    3510             :                enddo
    3511             :                enddo
    3512             :             enddo
    3513             :             call accum_hist_field(n_Sinz-n3Dfcum, iblk, nzilyr, ncat_hist, &
    3514           0 :                                   Sinz4d(:,:,1:nzilyr,1:ncat_hist), a4Di)
    3515             :          endif
    3516             : 
    3517             :          endif ! if (allocated(a3Dc))
    3518             : 
    3519        5817 :          if (allocated(a4Ds)) then
    3520             : 
    3521           0 :          if (f_Tsnz   (1:1) /= 'x') then
    3522           0 :             Tsnz4d(:,:,:,:) = c0
    3523           0 :             do n = 1, ncat_hist
    3524           0 :                do j = jlo, jhi
    3525           0 :                do i = ilo, ihi
    3526           0 :                   do k = 1, nzslyr
    3527           0 :                      qn = trcrn(i,j,nt_qsno+k-1,n,iblk)
    3528           0 :                      Tsnz4d(i,j,k,n) = icepack_snow_temperature(qn)
    3529             :                   enddo
    3530             :                enddo
    3531             :                enddo
    3532             :             enddo
    3533             :             call accum_hist_field(n_Tsnz-n4Dicum, iblk, nzslyr, ncat_hist, &
    3534           0 :                                   Tsnz4d(:,:,1:nzslyr,1:ncat_hist), a4Ds)
    3535             :          endif
    3536             : 
    3537             :          endif ! if (allocated(a4Ds))
    3538             : 
    3539        5817 :          if (allocated(a3Dc) .and. allocated(a2D)) then
    3540             : 
    3541             :          ! Calculate aggregate surface melt flux by summing category values
    3542           0 :          if (f_fmeltt_ai(1:1) /= 'x') then
    3543           0 :           do ns = 1, nstreams
    3544           0 :             if (n_fmeltt_ai(ns) /= 0) then
    3545           0 :                worka(:,:) = c0
    3546           0 :                do j = jlo, jhi
    3547           0 :                do i = ilo, ihi
    3548           0 :                 if (tmask(i,j,iblk)) then
    3549           0 :                   do n=1,ncat_hist
    3550           0 :                      worka(i,j)  = worka(i,j) + a3Dc(i,j,n,n_fmelttn_ai(ns)-n2D,iblk)
    3551             :                   enddo            ! n
    3552             :                 endif              ! tmask
    3553             :                enddo                ! i
    3554             :                enddo                ! j
    3555           0 :                a2D(:,:,n_fmeltt_ai(ns),iblk) = worka(:,:)
    3556             :             endif
    3557             :           enddo
    3558             :          endif
    3559             : 
    3560             :          endif
    3561             :       !---------------------------------------------------------------
    3562             :       ! accumulate other history output
    3563             :       !---------------------------------------------------------------
    3564             : 
    3565             :          ! mechanical redistribution
    3566        5817 :          call accum_hist_mechred (iblk)
    3567             : 
    3568             :          ! melt ponds
    3569        5817 :          call accum_hist_pond (iblk)
    3570             : 
    3571             :          ! biogeochemistry
    3572        5817 :          call accum_hist_bgc (iblk)
    3573             : 
    3574             :          ! form drag
    3575        5817 :          call accum_hist_drag (iblk)
    3576             : 
    3577             :          ! floe size distribution
    3578        5817 :          call accum_hist_fsd (dt, iblk)
    3579             : 
    3580             :          ! advanced snow physics
    3581       11638 :          call accum_hist_snow (iblk)
    3582             : 
    3583             :       enddo                     ! iblk
    3584             :       !$OMP END PARALLEL DO
    3585             : 
    3586        5821 :       call icepack_warnings_flush(nu_diag)
    3587        5821 :       if (icepack_warnings_aborted()) call abort_ice(error_message=subname, &
    3588           0 :          file=__FILE__, line=__LINE__)
    3589             : 
    3590             :       !---------------------------------------------------------------
    3591             :       ! Write output files at prescribed intervals
    3592             :       !---------------------------------------------------------------
    3593             : 
    3594        5821 :       nstrm = nstreams
    3595        5821 :       if (write_ic) nstrm = 1
    3596             : 
    3597       11642 :       do ns = 1, nstrm
    3598       11642 :       if (write_history(ns) .or. write_ic) then
    3599             : 
    3600             :       !---------------------------------------------------------------
    3601             :       ! Mask out land points and convert units
    3602             :       !---------------------------------------------------------------
    3603             : 
    3604          98 :         ravgct = c1/avgct(ns)
    3605             :         !$OMP PARALLEL DO PRIVATE(iblk,i,j,ilo,ihi,jlo,jhi,this_block, &
    3606          80 :         !$OMP                     n,nn,ravgctz,ravgip,ravgipn)
    3607          52 :         do iblk = 1, nblocks
    3608          34 :            this_block = get_block(blocks_ice(iblk),iblk)
    3609          34 :            ilo = this_block%ilo
    3610          34 :            ihi = this_block%ihi
    3611          34 :            jlo = this_block%jlo
    3612          34 :            jhi = this_block%jhi
    3613             : 
    3614             :            ! Ice fraction really needs to be on one of the history
    3615             :            ! streams, but in case it is not.
    3616             : 
    3617          34 :            if (n_aice(ns) > 0) then
    3618        1290 :            do j = jlo, jhi
    3619       57258 :            do i = ilo, ihi
    3620       57224 :               if (a2D(i,j,n_aice(ns),iblk) > puny) then
    3621       35301 :                  ravgip(i,j) = c1/(a2D(i,j,n_aice(ns),iblk))
    3622             :               else
    3623       20667 :                  ravgip(i,j) = c0
    3624             :               endif
    3625             :            enddo             ! i
    3626             :            enddo             ! j
    3627             :            endif
    3628          34 :            if (n_aicen(ns) > n2D) then
    3629           0 :            do k=1,ncat_hist
    3630           0 :            do j = jlo, jhi
    3631           0 :            do i = ilo, ihi
    3632           0 :               if (a3Dc(i,j,k,n_aicen(ns)-n2D,iblk) > puny) then
    3633           0 :                  ravgipn(i,j,k) = c1/(a3Dc(i,j,k,n_aicen(ns)-n2D,iblk))
    3634             :               else
    3635           0 :                  ravgipn(i,j,k) = c0
    3636             :               endif
    3637             :            enddo             ! i
    3638             :            enddo             ! j
    3639             :            enddo             ! k
    3640             :            endif
    3641             : 
    3642        2468 :            do n = 1, num_avail_hist_fields_2D
    3643        2468 :               if (avail_hist_fields(n)%vhistfreq == histfreq(ns)) then
    3644             : 
    3645       80490 :               do j = jlo, jhi
    3646     2594058 :               do i = ilo, ihi
    3647     2591624 :                  if (.not. tmask(i,j,iblk)) then ! mask out land points
    3648       80756 :                     a2D(i,j,n,iblk) = spval_dbl
    3649             :                  else                            ! convert units
    3650             :                     a2D(i,j,n,iblk) = avail_hist_fields(n)%cona*a2D(i,j,n,iblk) &
    3651     2432812 :                                    * ravgct + avail_hist_fields(n)%conb
    3652             :                  endif
    3653             :               enddo             ! i
    3654             :               enddo             ! j
    3655             : 
    3656             :               ! Only average for timesteps when ice present
    3657        2434 :               if (index(avail_hist_fields(n)%vname,'sithick') /= 0) then
    3658           0 :                  if (f_sithick(1:1) /= 'x' .and. n_sithick(ns) /= 0) then
    3659           0 :                     do j = jlo, jhi
    3660           0 :                     do i = ilo, ihi
    3661           0 :                        if (tmask(i,j,iblk)) then
    3662             :                              a2D(i,j,n_sithick(ns),iblk) = &
    3663           0 :                              a2D(i,j,n_sithick(ns),iblk)*avgct(ns)*ravgip(i,j)
    3664             :                        endif
    3665           0 :                        if (ravgip(i,j) == c0) a2D(i,j,n_sithick(ns),iblk) = spval_dbl
    3666             :                     enddo             ! i
    3667             :                     enddo             ! j
    3668             :                  endif
    3669             :               endif
    3670        2434 :               if (index(avail_hist_fields(n)%vname,'siage') /= 0) then
    3671           0 :                  if (f_siage(1:1) /= 'x' .and. n_siage(ns) /= 0) then
    3672           0 :                     do j = jlo, jhi
    3673           0 :                     do i = ilo, ihi
    3674           0 :                        if (tmask(i,j,iblk)) then
    3675             :                              a2D(i,j,n_siage(ns),iblk) = &
    3676           0 :                              a2D(i,j,n_siage(ns),iblk)*avgct(ns)*ravgip(i,j)
    3677             :                        endif
    3678           0 :                        if (ravgip(i,j) == c0) a2D(i,j,n_siage(ns),iblk) = spval_dbl
    3679             :                     enddo             ! i
    3680             :                     enddo             ! j
    3681             :                  endif
    3682             :               endif
    3683        2434 :               if (index(avail_hist_fields(n)%vname,'sisnthick') /= 0) then
    3684           0 :                  if (f_sisnthick(1:1) /= 'x' .and. n_sisnthick(ns) /= 0) then
    3685           0 :                     do j = jlo, jhi
    3686           0 :                     do i = ilo, ihi
    3687           0 :                        if (tmask(i,j,iblk)) then
    3688             :                              a2D(i,j,n_sisnthick(ns),iblk) = &
    3689           0 :                              a2D(i,j,n_sisnthick(ns),iblk)*avgct(ns)*ravgip(i,j)
    3690             :                        endif
    3691           0 :                        if (ravgip(i,j) == c0) a2D(i,j,n_sisnthick(ns),iblk) = spval_dbl
    3692             :                     enddo             ! i
    3693             :                     enddo             ! j
    3694             :                  endif
    3695             :               endif
    3696        2434 :               if (index(avail_hist_fields(n)%vname,'sitemptop') /= 0) then
    3697           0 :                  if (f_sitemptop(1:1) /= 'x' .and. n_sitemptop(ns) /= 0) then
    3698           0 :                     do j = jlo, jhi
    3699           0 :                     do i = ilo, ihi
    3700           0 :                        if (tmask(i,j,iblk)) then
    3701             :                              a2D(i,j,n_sitemptop(ns),iblk) = &
    3702           0 :                              a2D(i,j,n_sitemptop(ns),iblk)*avgct(ns)*ravgip(i,j)
    3703             :                        endif
    3704           0 :                        if (ravgip(i,j) == c0) a2D(i,j,n_sitemptop(ns),iblk) = spval_dbl
    3705             :                     enddo             ! i
    3706             :                     enddo             ! j
    3707             :                  endif
    3708             :               endif
    3709        2434 :               if (index(avail_hist_fields(n)%vname,'sitempsnic') /= 0) then
    3710           0 :                  if (f_sitempsnic(1:1) /= 'x' .and. n_sitempsnic(ns) /= 0) then
    3711           0 :                     do j = jlo, jhi
    3712           0 :                     do i = ilo, ihi
    3713           0 :                        if (tmask(i,j,iblk)) then
    3714             :                              a2D(i,j,n_sitempsnic(ns),iblk) = &
    3715           0 :                              a2D(i,j,n_sitempsnic(ns),iblk)*avgct(ns)*ravgip(i,j)
    3716             :                        endif
    3717           0 :                        if (ravgip(i,j) == c0) a2D(i,j,n_sitempsnic(ns),iblk) = spval_dbl
    3718             :                     enddo             ! i
    3719             :                     enddo             ! j
    3720             :                  endif
    3721             :               endif
    3722        2434 :               if (index(avail_hist_fields(n)%vname,'sitempbot') /= 0) then
    3723           0 :                  if (f_sitempbot(1:1) /= 'x' .and. n_sitempbot(ns) /= 0) then
    3724           0 :                     do j = jlo, jhi
    3725           0 :                     do i = ilo, ihi
    3726           0 :                        if (tmask(i,j,iblk)) then
    3727             :                              a2D(i,j,n_sitempbot(ns),iblk) = &
    3728           0 :                              a2D(i,j,n_sitempbot(ns),iblk)*avgct(ns)*ravgip(i,j)
    3729             :                        endif
    3730           0 :                        if (ravgip(i,j) == c0) a2D(i,j,n_sitempbot(ns),iblk) = spval_dbl
    3731             :                     enddo             ! i
    3732             :                     enddo             ! j
    3733             :                  endif
    3734             :               endif
    3735        2434 :               if (index(avail_hist_fields(n)%vname,'siu') /= 0) then
    3736           0 :                  if (f_siu(1:1) /= 'x' .and. n_siu(ns) /= 0) then
    3737           0 :                     do j = jlo, jhi
    3738           0 :                     do i = ilo, ihi
    3739           0 :                        if (tmask(i,j,iblk)) then
    3740             :                              a2D(i,j,n_siu(ns),iblk) = &
    3741           0 :                              a2D(i,j,n_siu(ns),iblk)*avgct(ns)*ravgip(i,j)
    3742             :                        endif
    3743           0 :                        if (ravgip(i,j) == c0) a2D(i,j,n_siu(ns),iblk) = spval_dbl
    3744             :                     enddo             ! i
    3745             :                     enddo             ! j
    3746             :                  endif
    3747             :               endif
    3748        2434 :               if (index(avail_hist_fields(n)%vname,'siv') /= 0) then
    3749           0 :                  if (f_siv(1:1) /= 'x' .and. n_siv(ns) /= 0) then
    3750           0 :                     do j = jlo, jhi
    3751           0 :                     do i = ilo, ihi
    3752           0 :                        if (tmask(i,j,iblk)) then
    3753             :                              a2D(i,j,n_siv(ns),iblk) = &
    3754           0 :                              a2D(i,j,n_siv(ns),iblk)*avgct(ns)*ravgip(i,j)
    3755             :                        endif
    3756           0 :                        if (ravgip(i,j) == c0) a2D(i,j,n_siv(ns),iblk) = spval_dbl
    3757             :                     enddo             ! i
    3758             :                     enddo             ! j
    3759             :                  endif
    3760             :               endif
    3761        2434 :               if (index(avail_hist_fields(n)%vname,'sistrxdtop') /= 0) then
    3762           0 :                  if (f_sistrxdtop(1:1) /= 'x' .and. n_sistrxdtop(ns) /= 0) then
    3763           0 :                     do j = jlo, jhi
    3764           0 :                     do i = ilo, ihi
    3765           0 :                        if (tmask(i,j,iblk)) then
    3766             :                              a2D(i,j,n_sistrxdtop(ns),iblk) = &
    3767           0 :                              a2D(i,j,n_sistrxdtop(ns),iblk)*avgct(ns)*ravgip(i,j)
    3768             :                        endif
    3769           0 :                        if (ravgip(i,j) == c0) a2D(i,j,n_sistrxdtop(ns),iblk) = spval_dbl
    3770             :                     enddo             ! i
    3771             :                     enddo             ! j
    3772             :                  endif
    3773             :               endif
    3774        2434 :               if (index(avail_hist_fields(n)%vname,'sistrydtop') /= 0) then
    3775           0 :                  if (f_sistrydtop(1:1) /= 'x' .and. n_sistrydtop(ns) /= 0) then
    3776           0 :                     do j = jlo, jhi
    3777           0 :                     do i = ilo, ihi
    3778           0 :                        if (tmask(i,j,iblk)) then
    3779             :                              a2D(i,j,n_sistrydtop(ns),iblk) = &
    3780           0 :                              a2D(i,j,n_sistrydtop(ns),iblk)*avgct(ns)*ravgip(i,j)
    3781             :                        endif
    3782           0 :                        if (ravgip(i,j) == c0) a2D(i,j,n_sistrydtop(ns),iblk) = spval_dbl
    3783             :                     enddo             ! i
    3784             :                     enddo             ! j
    3785             :                  endif
    3786             :               endif
    3787        2434 :               if (index(avail_hist_fields(n)%vname,'sistrxubot') /= 0) then
    3788           0 :                  if (f_sistrxubot(1:1) /= 'x' .and. n_sistrxubot(ns) /= 0) then
    3789           0 :                     do j = jlo, jhi
    3790           0 :                     do i = ilo, ihi
    3791           0 :                        if (tmask(i,j,iblk)) then
    3792             :                              a2D(i,j,n_sistrxubot(ns),iblk) = &
    3793           0 :                              a2D(i,j,n_sistrxubot(ns),iblk)*avgct(ns)*ravgip(i,j)
    3794             :                        endif
    3795           0 :                        if (ravgip(i,j) == c0) a2D(i,j,n_sistrxubot(ns),iblk) = spval_dbl
    3796             :                     enddo             ! i
    3797             :                     enddo             ! j
    3798             :                  endif
    3799             :               endif
    3800        2434 :               if (index(avail_hist_fields(n)%vname,'sistryubot') /= 0) then
    3801           0 :                  if (f_sistryubot(1:1) /= 'x' .and. n_sistryubot(ns) /= 0) then
    3802           0 :                     do j = jlo, jhi
    3803           0 :                     do i = ilo, ihi
    3804           0 :                        if (tmask(i,j,iblk)) then
    3805             :                              a2D(i,j,n_sistryubot(ns),iblk) = &
    3806           0 :                              a2D(i,j,n_sistryubot(ns),iblk)*avgct(ns)*ravgip(i,j)
    3807             :                        endif
    3808           0 :                        if (ravgip(i,j) == c0) a2D(i,j,n_sistryubot(ns),iblk) = spval_dbl
    3809             :                     enddo             ! i
    3810             :                     enddo             ! j
    3811             :                  endif
    3812             :               endif
    3813        2434 :               if (index(avail_hist_fields(n)%vname,'sicompstren') /= 0) then
    3814           0 :                  if (f_sicompstren(1:1) /= 'x' .and. n_sicompstren(ns) /= 0) then
    3815           0 :                     do j = jlo, jhi
    3816           0 :                     do i = ilo, ihi
    3817           0 :                        if (tmask(i,j,iblk)) then
    3818             :                              a2D(i,j,n_sicompstren(ns),iblk) = &
    3819           0 :                              a2D(i,j,n_sicompstren(ns),iblk)*avgct(ns)*ravgip(i,j)
    3820             :                        endif
    3821           0 :                        if (ravgip(i,j) == c0) a2D(i,j,n_sicompstren(ns),iblk) = spval_dbl
    3822             :                     enddo             ! i
    3823             :                     enddo             ! j
    3824             :                  endif
    3825             :               endif
    3826        2434 :               if (index(avail_hist_fields(n)%vname,'sispeed') /= 0) then
    3827           0 :                  if (f_sispeed(1:1) /= 'x' .and. n_sispeed(ns) /= 0) then
    3828           0 :                     do j = jlo, jhi
    3829           0 :                     do i = ilo, ihi
    3830           0 :                        if (tmask(i,j,iblk)) then
    3831             :                              a2D(i,j,n_sispeed(ns),iblk) = &
    3832           0 :                              a2D(i,j,n_sispeed(ns),iblk)*avgct(ns)*ravgip(i,j)
    3833             :                        endif
    3834           0 :                        if (ravgip(i,j) == c0) a2D(i,j,n_sispeed(ns),iblk) = spval_dbl
    3835             :                     enddo             ! i
    3836             :                     enddo             ! j
    3837             :                  endif
    3838             :               endif
    3839        2434 :               if (index(avail_hist_fields(n)%vname,'sialb') /= 0) then
    3840           0 :                  if (f_sialb(1:1) /= 'x' .and. n_sialb(ns) /= 0) then
    3841           0 :                     do j = jlo, jhi
    3842           0 :                     do i = ilo, ihi
    3843           0 :                        if (tmask(i,j,iblk)) then
    3844             :                              a2D(i,j,n_sialb(ns),iblk) = &
    3845           0 :                              a2D(i,j,n_sialb(ns),iblk)*avgct(ns)*ravgip(i,j)
    3846             :                        endif
    3847           0 :                        if (ravgip(i,j) == c0) a2D(i,j,n_sialb(ns),iblk) = spval_dbl
    3848           0 :                        if (albcnt(i,j,iblk,ns) <= puny) a2D(i,j,n_sialb(ns),iblk) = spval_dbl
    3849             :                     enddo             ! i
    3850             :                     enddo             ! j
    3851             :                  endif
    3852             :               endif
    3853        2434 :               if (index(avail_hist_fields(n)%vname,'siflswdtop') /= 0) then
    3854           0 :                  if (f_siflswdtop(1:1) /= 'x' .and. n_siflswdtop(ns) /= 0) then
    3855           0 :                     do j = jlo, jhi
    3856           0 :                     do i = ilo, ihi
    3857           0 :                        if (tmask(i,j,iblk)) then
    3858             :                              a2D(i,j,n_siflswdtop(ns),iblk) = &
    3859           0 :                              a2D(i,j,n_siflswdtop(ns),iblk)*avgct(ns)*ravgip(i,j)
    3860             :                        endif
    3861           0 :                        if (ravgip(i,j) == c0) a2D(i,j,n_siflswdtop(ns),iblk) = spval_dbl
    3862             :                     enddo             ! i
    3863             :                     enddo             ! j
    3864             :                  endif
    3865             :               endif
    3866        2434 :               if (index(avail_hist_fields(n)%vname,'siflswutop') /= 0) then
    3867           0 :                  if (f_siflswutop(1:1) /= 'x' .and. n_siflswutop(ns) /= 0) then
    3868           0 :                     do j = jlo, jhi
    3869           0 :                     do i = ilo, ihi
    3870           0 :                        if (tmask(i,j,iblk)) then
    3871             :                              a2D(i,j,n_siflswutop(ns),iblk) = &
    3872           0 :                              a2D(i,j,n_siflswutop(ns),iblk)*avgct(ns)*ravgip(i,j)
    3873             :                        endif
    3874           0 :                        if (ravgip(i,j) == c0) a2D(i,j,n_siflswutop(ns),iblk) = spval_dbl
    3875             :                     enddo             ! i
    3876             :                     enddo             ! j
    3877             :                  endif
    3878             :               endif
    3879        2434 :               if (index(avail_hist_fields(n)%vname,'siflswdbot') /= 0) then
    3880           0 :                  if (f_siflswdbot(1:1) /= 'x' .and. n_siflswdbot(ns) /= 0) then
    3881           0 :                     do j = jlo, jhi
    3882           0 :                     do i = ilo, ihi
    3883           0 :                        if (tmask(i,j,iblk)) then
    3884             :                              a2D(i,j,n_siflswdbot(ns),iblk) = &
    3885           0 :                              a2D(i,j,n_siflswdbot(ns),iblk)*avgct(ns)*ravgip(i,j)
    3886             :                        endif
    3887           0 :                        if (ravgip(i,j) == c0) a2D(i,j,n_siflswdbot(ns),iblk) = spval_dbl
    3888             :                     enddo             ! i
    3889             :                     enddo             ! j
    3890             :                  endif
    3891             :               endif
    3892        2434 :               if (index(avail_hist_fields(n)%vname,'sifllwdtop') /= 0) then
    3893           0 :                  if (f_sifllwdtop(1:1) /= 'x' .and. n_sifllwdtop(ns) /= 0) then
    3894           0 :                     do j = jlo, jhi
    3895           0 :                     do i = ilo, ihi
    3896           0 :                        if (tmask(i,j,iblk)) then
    3897             :                              a2D(i,j,n_sifllwdtop(ns),iblk) = &
    3898           0 :                              a2D(i,j,n_sifllwdtop(ns),iblk)*avgct(ns)*ravgip(i,j)
    3899             :                        endif
    3900           0 :                        if (ravgip(i,j) == c0) a2D(i,j,n_sifllwdtop(ns),iblk) = spval_dbl
    3901             :                     enddo             ! i
    3902             :                     enddo             ! j
    3903             :                  endif
    3904             :               endif
    3905        2434 :               if (index(avail_hist_fields(n)%vname,'sifllwutop') /= 0) then
    3906           0 :                  if (f_sifllwutop(1:1) /= 'x' .and. n_sifllwutop(ns) /= 0) then
    3907           0 :                     do j = jlo, jhi
    3908           0 :                     do i = ilo, ihi
    3909           0 :                        if (tmask(i,j,iblk)) then
    3910             :                              a2D(i,j,n_sifllwutop(ns),iblk) = &
    3911           0 :                              a2D(i,j,n_sifllwutop(ns),iblk)*avgct(ns)*ravgip(i,j)
    3912             :                        endif
    3913           0 :                        if (ravgip(i,j) == c0) a2D(i,j,n_sifllwutop(ns),iblk) = spval_dbl
    3914             :                     enddo             ! i
    3915             :                     enddo             ! j
    3916             :                  endif
    3917             :               endif
    3918        2434 :               if (index(avail_hist_fields(n)%vname,'siflsenstop') /= 0) then
    3919           0 :                  if (f_siflsenstop(1:1) /= 'x' .and. n_siflsenstop(ns) /= 0) then
    3920           0 :                     do j = jlo, jhi
    3921           0 :                     do i = ilo, ihi
    3922           0 :                        if (tmask(i,j,iblk)) then
    3923             :                              a2D(i,j,n_siflsenstop(ns),iblk) = &
    3924           0 :                              a2D(i,j,n_siflsenstop(ns),iblk)*avgct(ns)*ravgip(i,j)
    3925             :                        endif
    3926           0 :                        if (ravgip(i,j) == c0) a2D(i,j,n_siflsenstop(ns),iblk) = spval_dbl
    3927             :                     enddo             ! i
    3928             :                     enddo             ! j
    3929             :                  endif
    3930             :               endif
    3931        2434 :               if (index(avail_hist_fields(n)%vname,'siflsensupbot') /= 0) then
    3932           0 :                  if (f_siflsensupbot(1:1) /= 'x' .and.  n_siflsensupbot(ns) /= 0) then
    3933           0 :                     do j = jlo, jhi
    3934           0 :                     do i = ilo, ihi
    3935           0 :                        if (tmask(i,j,iblk)) then
    3936             :                              a2D(i,j,n_siflsensupbot(ns),iblk) = &
    3937           0 :                              a2D(i,j,n_siflsensupbot(ns),iblk)*avgct(ns)*ravgip(i,j)
    3938             :                        endif
    3939           0 :                        if (ravgip(i,j) == c0) a2D(i,j,n_siflsensupbot(ns),iblk) = spval_dbl
    3940             :                     enddo             ! i
    3941             :                     enddo             ! j
    3942             :                  endif
    3943             :               endif
    3944        2434 :               if (index(avail_hist_fields(n)%vname,'sifllatstop') /= 0) then
    3945           0 :                  if (f_sifllatstop(1:1) /= 'x' .and. n_sifllatstop(ns) /= 0) then
    3946           0 :                     do j = jlo, jhi
    3947           0 :                     do i = ilo, ihi
    3948           0 :                        if (tmask(i,j,iblk)) then
    3949             :                              a2D(i,j,n_sifllatstop(ns),iblk) = &
    3950           0 :                              a2D(i,j,n_sifllatstop(ns),iblk)*avgct(ns)*ravgip(i,j)
    3951             :                        endif
    3952           0 :                        if (ravgip(i,j) == c0) a2D(i,j,n_sifllatstop(ns),iblk) = spval_dbl
    3953             :                     enddo             ! i
    3954             :                     enddo             ! j
    3955             :                  endif
    3956             :               endif
    3957        2434 :               if (index(avail_hist_fields(n)%vname,'sipr') /= 0) then
    3958           0 :                  if (f_sipr(1:1) /= 'x' .and. n_sipr(ns) /= 0) then
    3959           0 :                     do j = jlo, jhi
    3960           0 :                     do i = ilo, ihi
    3961           0 :                        if (tmask(i,j,iblk)) then
    3962             :                              a2D(i,j,n_sipr(ns),iblk) = &
    3963           0 :                              a2D(i,j,n_sipr(ns),iblk)*avgct(ns)*ravgip(i,j)
    3964             :                        endif
    3965           0 :                        if (ravgip(i,j) == c0) a2D(i,j,n_sipr(ns),iblk) = spval_dbl
    3966             :                     enddo             ! i
    3967             :                     enddo             ! j
    3968             :                  endif
    3969             :               endif
    3970        2434 :               if (index(avail_hist_fields(n)%vname,'sifb') /= 0) then
    3971           0 :                  if (f_sifb(1:1) /= 'x' .and. n_sifb(ns) /= 0) then
    3972           0 :                     do j = jlo, jhi
    3973           0 :                     do i = ilo, ihi
    3974           0 :                        if (tmask(i,j,iblk)) then
    3975             :                              a2D(i,j,n_sifb(ns),iblk) = &
    3976           0 :                              a2D(i,j,n_sifb(ns),iblk)*avgct(ns)*ravgip(i,j)
    3977             :                        endif
    3978           0 :                        if (ravgip(i,j) == c0) a2D(i,j,n_sifb(ns),iblk) = spval_dbl
    3979             :                     enddo             ! i
    3980             :                     enddo             ! j
    3981             :                  endif
    3982             :               endif
    3983        2434 :               if (index(avail_hist_fields(n)%vname,'siflcondtop') /= 0) then
    3984           0 :                  if (f_siflcondtop(1:1) /= 'x' .and. n_siflcondtop(ns) /= 0) then
    3985           0 :                     do j = jlo, jhi
    3986           0 :                     do i = ilo, ihi
    3987           0 :                        if (tmask(i,j,iblk)) then
    3988             :                              a2D(i,j,n_siflcondtop(ns),iblk) = &
    3989           0 :                              a2D(i,j,n_siflcondtop(ns),iblk)*avgct(ns)*ravgip(i,j)
    3990             :                        endif
    3991           0 :                        if (ravgip(i,j) == c0) a2D(i,j,n_siflcondtop(ns),iblk) = spval_dbl
    3992             :                     enddo             ! i
    3993             :                     enddo             ! j
    3994             :                  endif
    3995             :               endif
    3996        2434 :               if (index(avail_hist_fields(n)%vname,'siflcondbot') /= 0) then
    3997           0 :                  if (f_siflcondbot(1:1) /= 'x' .and. n_siflcondbot(ns) /= 0) then
    3998           0 :                     do j = jlo, jhi
    3999           0 :                     do i = ilo, ihi
    4000           0 :                        if (tmask(i,j,iblk)) then
    4001             :                              a2D(i,j,n_siflcondbot(ns),iblk) = &
    4002           0 :                              a2D(i,j,n_siflcondbot(ns),iblk)*avgct(ns)*ravgip(i,j)
    4003             :                        endif
    4004           0 :                        if (ravgip(i,j) == c0) a2D(i,j,n_siflcondbot(ns),iblk) = spval_dbl
    4005             :                     enddo             ! i
    4006             :                     enddo             ! j
    4007             :                  endif
    4008             :               endif
    4009        2434 :               if (index(avail_hist_fields(n)%vname,'siflsaltbot') /= 0) then
    4010           0 :                  if (f_siflsaltbot(1:1) /= 'x' .and. n_siflsaltbot(ns) /= 0) then
    4011           0 :                     do j = jlo, jhi
    4012           0 :                     do i = ilo, ihi
    4013           0 :                        if (tmask(i,j,iblk)) then
    4014             :                              a2D(i,j,n_siflsaltbot(ns),iblk) = &
    4015           0 :                              a2D(i,j,n_siflsaltbot(ns),iblk)*avgct(ns)*ravgip(i,j)
    4016             :                        endif
    4017           0 :                        if (ravgip(i,j) == c0) a2D(i,j,n_siflsaltbot(ns),iblk) = spval_dbl
    4018             :                     enddo             ! i
    4019             :                     enddo             ! j
    4020             :                  endif
    4021             :               endif
    4022        2434 :               if (index(avail_hist_fields(n)%vname,'siflfwbot') /= 0) then
    4023           0 :                  if (f_siflfwbot(1:1) /= 'x' .and. n_siflfwbot(ns) /= 0) then
    4024           0 :                     do j = jlo, jhi
    4025           0 :                     do i = ilo, ihi
    4026           0 :                        if (tmask(i,j,iblk)) then
    4027             :                              a2D(i,j,n_siflfwbot(ns),iblk) = &
    4028           0 :                              a2D(i,j,n_siflfwbot(ns),iblk)*avgct(ns)*ravgip(i,j)
    4029             :                        endif
    4030           0 :                        if (ravgip(i,j) == c0) a2D(i,j,n_siflfwbot(ns),iblk) = spval_dbl
    4031             :                     enddo             ! i
    4032             :                     enddo             ! j
    4033             :                  endif
    4034             :               endif
    4035        2434 :               if (index(avail_hist_fields(n)%vname,'siflfwdrain') /= 0) then
    4036           0 :                  if (f_siflfwdrain(1:1) /= 'x' .and. n_siflfwdrain(ns) /= 0) then
    4037           0 :                     do j = jlo, jhi
    4038           0 :                     do i = ilo, ihi
    4039           0 :                        if (tmask(i,j,iblk)) then
    4040             :                              a2D(i,j,n_siflfwdrain(ns),iblk) = &
    4041           0 :                              a2D(i,j,n_siflfwdrain(ns),iblk)*avgct(ns)*ravgip(i,j)
    4042             :                        endif
    4043           0 :                        if (ravgip(i,j) == c0) a2D(i,j,n_siflfwdrain(ns),iblk) = spval_dbl
    4044             :                     enddo             ! i
    4045             :                     enddo             ! j
    4046             :                  endif
    4047             :               endif
    4048        2434 :              if (index(avail_hist_fields(n)%vname,'sidragtop') /= 0) then
    4049           0 :                  if (f_sidragtop(1:1) /= 'x' .and. n_sidragtop(ns) /= 0) then
    4050           0 :                     do j = jlo, jhi
    4051           0 :                     do i = ilo, ihi
    4052           0 :                        if (tmask(i,j,iblk)) then
    4053             :                              a2D(i,j,n_sidragtop(ns),iblk) = &
    4054           0 :                              a2D(i,j,n_sidragtop(ns),iblk)*avgct(ns)*ravgip(i,j)
    4055             :                        endif
    4056           0 :                        if (ravgip(i,j) == c0) a2D(i,j,n_sidragtop(ns),iblk) = spval_dbl
    4057             :                     enddo             ! i
    4058             :                     enddo             ! j
    4059             :                  endif
    4060             :               endif
    4061        2434 :               if (index(avail_hist_fields(n)%vname,'sirdgthick') /= 0) then
    4062           0 :                  if (f_sirdgthick(1:1) /= 'x' .and. n_sirdgthick(ns) /= 0) then
    4063           0 :                     do j = jlo, jhi
    4064           0 :                     do i = ilo, ihi
    4065           0 :                        if (tmask(i,j,iblk)) then
    4066             :                              a2D(i,j,n_sirdgthick(ns),iblk) = &
    4067           0 :                              a2D(i,j,n_sirdgthick(ns),iblk)*avgct(ns)*ravgip(i,j)
    4068             :                        endif
    4069           0 :                        if (ravgip(i,j) == c0) a2D(i,j,n_sirdgthick(ns),iblk) = spval_dbl
    4070             :                     enddo             ! i
    4071             :                     enddo             ! j
    4072             :                  endif
    4073             :               endif
    4074        2434 :               if (index(avail_hist_fields(n)%vname,'siforcetiltx') /= 0) then
    4075           0 :                  if (f_siforcetiltx(1:1) /= 'x' .and. n_siforcetiltx(ns) /= 0) then
    4076           0 :                     do j = jlo, jhi
    4077           0 :                     do i = ilo, ihi
    4078           0 :                        if (tmask(i,j,iblk)) then
    4079             :                              a2D(i,j,n_siforcetiltx(ns),iblk) = &
    4080           0 :                              a2D(i,j,n_siforcetiltx(ns),iblk)*avgct(ns)*ravgip(i,j)
    4081             :                        endif
    4082           0 :                        if (ravgip(i,j) == c0) a2D(i,j,n_siforcetiltx(ns),iblk) = spval_dbl
    4083             :                     enddo             ! i
    4084             :                     enddo             ! j
    4085             :                  endif
    4086             :               endif
    4087        2434 :               if (index(avail_hist_fields(n)%vname,'siforcetilty') /= 0) then
    4088           0 :                  if (f_siforcetilty(1:1) /= 'x' .and. n_siforcetilty(ns) /= 0) then
    4089           0 :                     do j = jlo, jhi
    4090           0 :                     do i = ilo, ihi
    4091           0 :                        if (tmask(i,j,iblk)) then
    4092             :                              a2D(i,j,n_siforcetilty(ns),iblk) = &
    4093           0 :                              a2D(i,j,n_siforcetilty(ns),iblk)*avgct(ns)*ravgip(i,j)
    4094             :                        endif
    4095           0 :                        if (ravgip(i,j) == c0) a2D(i,j,n_siforcetilty(ns),iblk) = spval_dbl
    4096             :                     enddo             ! i
    4097             :                     enddo             ! j
    4098             :                  endif
    4099             :               endif
    4100        2434 :               if (index(avail_hist_fields(n)%vname,'siforcecoriolx') /= 0) then
    4101           0 :                  if (f_siforcecoriolx(1:1) /= 'x' .and.  n_siforcecoriolx(ns) /= 0) then
    4102           0 :                     do j = jlo, jhi
    4103           0 :                     do i = ilo, ihi
    4104           0 :                        if (tmask(i,j,iblk)) then
    4105             :                              a2D(i,j,n_siforcecoriolx(ns),iblk) = &
    4106           0 :                              a2D(i,j,n_siforcecoriolx(ns),iblk)*avgct(ns)*ravgip(i,j)
    4107             :                        endif
    4108           0 :                        if (ravgip(i,j) == c0) a2D(i,j,n_siforcecoriolx(ns),iblk) = spval_dbl
    4109             :                     enddo             ! i
    4110             :                     enddo             ! j
    4111             :                  endif
    4112             :               endif
    4113        2434 :               if (index(avail_hist_fields(n)%vname,'siforcecorioly') /= 0) then
    4114           0 :                  if (f_siforcecorioly(1:1) /= 'x' .and.  n_siforcecorioly(ns) /= 0) then
    4115           0 :                     do j = jlo, jhi
    4116           0 :                     do i = ilo, ihi
    4117           0 :                        if (tmask(i,j,iblk)) then
    4118             :                              a2D(i,j,n_siforcecorioly(ns),iblk) = &
    4119           0 :                              a2D(i,j,n_siforcecorioly(ns),iblk)*avgct(ns)*ravgip(i,j)
    4120             :                        endif
    4121           0 :                        if (ravgip(i,j) == c0) a2D(i,j,n_siforcecorioly(ns),iblk) = spval_dbl
    4122             :                     enddo             ! i
    4123             :                     enddo             ! j
    4124             :                  endif
    4125             :               endif
    4126        2434 :               if (index(avail_hist_fields(n)%vname,'siforceintstrx') /= 0) then
    4127           0 :                  if (f_siforceintstrx(1:1) /= 'x' .and.  n_siforceintstrx(ns) /= 0) then
    4128           0 :                     do j = jlo, jhi
    4129           0 :                     do i = ilo, ihi
    4130           0 :                        if (tmask(i,j,iblk)) then
    4131             :                              a2D(i,j,n_siforceintstrx(ns),iblk) = &
    4132           0 :                              a2D(i,j,n_siforceintstrx(ns),iblk)*avgct(ns)*ravgip(i,j)
    4133             :                        endif
    4134           0 :                        if (ravgip(i,j) == c0) a2D(i,j,n_siforceintstrx(ns),iblk) = spval_dbl
    4135             :                     enddo             ! i
    4136             :                     enddo             ! j
    4137             :                  endif
    4138             :               endif
    4139        2434 :               if (index(avail_hist_fields(n)%vname,'siforceintstry') /= 0) then
    4140           0 :                  if (f_siforceintstry(1:1) /= 'x' .and.  n_siforceintstry(ns) /= 0) then
    4141           0 :                     do j = jlo, jhi
    4142           0 :                     do i = ilo, ihi
    4143           0 :                        if (tmask(i,j,iblk)) then
    4144             :                              a2D(i,j,n_siforceintstry(ns),iblk) = &
    4145           0 :                              a2D(i,j,n_siforceintstry(ns),iblk)*avgct(ns)*ravgip(i,j)
    4146             :                        endif
    4147           0 :                        if (ravgip(i,j) == c0) a2D(i,j,n_siforceintstry(ns),iblk) = spval_dbl
    4148             :                     enddo             ! i
    4149             :                     enddo             ! j
    4150             :                  endif
    4151             :               endif
    4152             : 
    4153             :               ! back out albedo/zenith angle dependence
    4154        2434 :               if (avail_hist_fields(n)%vname(1:6) == 'albice') then
    4155           0 :               do j = jlo, jhi
    4156           0 :               do i = ilo, ihi
    4157           0 :                  if (tmask(i,j,iblk)) then
    4158           0 :                     ravgctz = c0
    4159           0 :                     if (albcnt(i,j,iblk,ns) > puny) &
    4160           0 :                         ravgctz = c1/albcnt(i,j,iblk,ns)
    4161           0 :                     if (f_albice (1:1) /= 'x' .and. n_albice(ns) /= 0) &
    4162             :                        a2D(i,j,n_albice(ns),iblk) = &   ! LCOV_EXCL_LINE
    4163           0 :                        a2D(i,j,n_albice(ns),iblk)*avgct(ns)*ravgctz
    4164           0 :                     if (f_albsno (1:1) /= 'x' .and. n_albsno(ns) /= 0) &
    4165             :                        a2D(i,j,n_albsno(ns),iblk) = &   ! LCOV_EXCL_LINE
    4166           0 :                        a2D(i,j,n_albsno(ns),iblk)*avgct(ns)*ravgctz
    4167           0 :                     if (f_albpnd (1:1) /= 'x' .and. n_albpnd(ns) /= 0) &
    4168             :                        a2D(i,j,n_albpnd(ns),iblk) = &   ! LCOV_EXCL_LINE
    4169           0 :                        a2D(i,j,n_albpnd(ns),iblk)*avgct(ns)*ravgctz
    4170             :                  endif
    4171             :               enddo             ! i
    4172             :               enddo             ! j
    4173             :               endif
    4174        2434 :               if (avail_hist_fields(n)%vname(1:6) == 'albsni') then
    4175        1056 :               do j = jlo, jhi
    4176       33824 :               do i = ilo, ihi
    4177       33792 :                  if (tmask(i,j,iblk)) then
    4178       31800 :                     ravgctz = c0
    4179       31800 :                     if (albcnt(i,j,iblk,ns) > puny) &
    4180           0 :                         ravgctz = c1/albcnt(i,j,iblk,ns)
    4181       31800 :                     if (f_albsni (1:1) /= 'x' .and. n_albsni(ns) /= 0) &
    4182             :                        a2D(i,j,n_albsni(ns),iblk) = &   ! LCOV_EXCL_LINE
    4183       31800 :                        a2D(i,j,n_albsni(ns),iblk)*avgct(ns)*ravgctz
    4184             :                  endif
    4185             :               enddo             ! i
    4186             :               enddo             ! j
    4187             :               endif
    4188        2434 :               if (avail_hist_fields(n)%vname(1:8) == 'alvdr_ai') then
    4189           0 :               do j = jlo, jhi
    4190           0 :               do i = ilo, ihi
    4191           0 :                  if (tmask(i,j,iblk)) then
    4192           0 :                     ravgctz = c0
    4193           0 :                     if (albcnt(i,j,iblk,ns) > puny) &
    4194           0 :                         ravgctz = c1/albcnt(i,j,iblk,ns)
    4195           0 :                     if (f_alvdr_ai (1:1) /= 'x' .and. n_alvdr_ai(ns) /= 0) &
    4196             :                        a2D(i,j,n_alvdr_ai(ns),iblk) = &   ! LCOV_EXCL_LINE
    4197           0 :                        a2D(i,j,n_alvdr_ai(ns),iblk)*avgct(ns)*ravgctz
    4198           0 :                     if (f_alvdf_ai (1:1) /= 'x' .and. n_alvdf_ai(ns) /= 0) &
    4199             :                        a2D(i,j,n_alvdf_ai(ns),iblk) = &   ! LCOV_EXCL_LINE
    4200           0 :                        a2D(i,j,n_alvdf_ai(ns),iblk)*avgct(ns)*ravgctz
    4201           0 :                     if (f_alidr_ai (1:1) /= 'x' .and. n_alidr_ai(ns) /= 0) &
    4202             :                        a2D(i,j,n_alidr_ai(ns),iblk) = &   ! LCOV_EXCL_LINE
    4203           0 :                        a2D(i,j,n_alidr_ai(ns),iblk)*avgct(ns)*ravgctz
    4204           0 :                     if (f_alidf_ai (1:1) /= 'x' .and. n_alidf_ai(ns) /= 0) &
    4205             :                        a2D(i,j,n_alidf_ai(ns),iblk) = &   ! LCOV_EXCL_LINE
    4206           0 :                        a2D(i,j,n_alidf_ai(ns),iblk)*avgct(ns)*ravgctz
    4207             :                  endif
    4208             :               enddo             ! i
    4209             :               enddo             ! j
    4210             :               endif
    4211             : 
    4212             : ! snwcnt averaging is not working correctly
    4213             : ! for now, these history fields will have zeroes includes in the averages
    4214             : !              if (avail_hist_fields(n)%vname(1:8) == 'rhos_cmp') then
    4215             : !              do j = jlo, jhi
    4216             : !              do i = ilo, ihi
    4217             : !                 if (tmask(i,j,iblk)) then
    4218             : !                    ravgctz = c0
    4219             : !                    if (snwcnt(i,j,iblk,ns) > puny) &
    4220             : !                        ravgctz = c1/snwcnt(i,j,iblk,ns)
    4221             : !                    if (f_rhos_cmp (1:1) /= 'x' .and. n_rhos_cmp(ns) /= 0) &
    4222             : !                       a2D(i,j,n_rhos_cmp(ns),iblk) = &   ! LCOV_EXCL_LINE
    4223             : !                       a2D(i,j,n_rhos_cmp(ns),iblk)*avgct(ns)*ravgctz
    4224             : !                 endif
    4225             : !              enddo             ! i
    4226             : !              enddo             ! j
    4227             : !              endif
    4228             : !              if (avail_hist_fields(n)%vname(1:8) == 'rhos_cnt') then
    4229             : !              do j = jlo, jhi
    4230             : !              do i = ilo, ihi
    4231             : !                 if (tmask(i,j,iblk)) then
    4232             : !                    ravgctz = c0
    4233             : !                    if (snwcnt(i,j,iblk,ns) > puny) &
    4234             : !                        ravgctz = c1/snwcnt(i,j,iblk,ns)
    4235             : !                    if (f_rhos_cnt (1:1) /= 'x' .and. n_rhos_cnt(ns) /= 0) &
    4236             : !                       a2D(i,j,n_rhos_cnt(ns),iblk) = &   ! LCOV_EXCL_LINE
    4237             : !                       a2D(i,j,n_rhos_cnt(ns),iblk)*avgct(ns)*ravgctz
    4238             : !                 endif
    4239             : !              enddo             ! i
    4240             : !              enddo             ! j
    4241             : !              endif
    4242             : 
    4243             :               endif             ! avail_hist_fields(n)%vhistfreq == histfreq(ns)
    4244             :            enddo                ! n
    4245             : 
    4246          34 :            do n = 1, num_avail_hist_fields_3Dc
    4247           0 :               nn = n2D + n
    4248          34 :               if (avail_hist_fields(nn)%vhistfreq == histfreq(ns)) then
    4249             : 
    4250           0 :               do k = 1, ncat_hist
    4251           0 :               do j = jlo, jhi
    4252           0 :               do i = ilo, ihi
    4253           0 :                  if (.not. tmask(i,j,iblk)) then ! mask out land points
    4254           0 :                     a3Dc(i,j,k,n,iblk) = spval_dbl
    4255             :                  else                            ! convert units
    4256             :                     a3Dc(i,j,k,n,iblk) = avail_hist_fields(nn)%cona*a3Dc(i,j,k,n,iblk) &
    4257           0 :                                    * ravgct + avail_hist_fields(nn)%conb
    4258             :                  endif
    4259             :               enddo             ! i
    4260             :               enddo             ! j
    4261             :               enddo             ! k
    4262           0 :               if (index(avail_hist_fields(nn)%vname,'siitdthick') /= 0) then
    4263           0 :                  if (f_siitdthick(1:1) /= 'x' .and. n_siitdthick(ns)-n2D /= 0) then
    4264           0 :                     do k = 1, ncat_hist
    4265           0 :                     do j = jlo, jhi
    4266           0 :                     do i = ilo, ihi
    4267           0 :                        if (tmask(i,j,iblk)) then
    4268             :                              a3Dc(i,j,k,n_siitdthick(ns)-n2D,iblk) = &
    4269           0 :                              a3Dc(i,j,k,n_siitdthick(ns)-n2D,iblk)*avgct(ns)*ravgipn(i,j,k)
    4270             :                        endif
    4271             :                     enddo             ! i
    4272             :                     enddo             ! j
    4273             :                     enddo             ! k
    4274             :                  endif
    4275             :               endif
    4276           0 :               if (index(avail_hist_fields(nn)%vname,'siitdsnthick') /= 0) then
    4277           0 :                  if (f_siitdsnthick(1:1) /= 'x' .and.  n_siitdsnthick(ns)-n2D /= 0) then
    4278           0 :                     do k = 1, ncat_hist
    4279           0 :                     do j = jlo, jhi
    4280           0 :                     do i = ilo, ihi
    4281           0 :                        if (tmask(i,j,iblk)) then
    4282             :                              a3Dc(i,j,k,n_siitdsnthick(ns)-n2D,iblk) = &
    4283           0 :                              a3Dc(i,j,k,n_siitdsnthick(ns)-n2D,iblk)*avgct(ns)*ravgipn(i,j,k)
    4284             :                        endif
    4285             :                     enddo             ! i
    4286             :                     enddo             ! j
    4287             :                     enddo             ! k
    4288             :                  endif
    4289             :               endif
    4290             : 
    4291             :               endif
    4292             : 
    4293             :            enddo                ! n
    4294             : 
    4295          34 :            do n = 1, num_avail_hist_fields_3Dz
    4296           0 :               nn = n3Dccum + n
    4297          34 :               if (avail_hist_fields(nn)%vhistfreq == histfreq(ns)) then
    4298             : 
    4299           0 :               do k = 1, nzilyr
    4300           0 :               do j = jlo, jhi
    4301           0 :               do i = ilo, ihi
    4302           0 :                  if (.not. tmask(i,j,iblk)) then ! mask out land points
    4303           0 :                     a3Dz(i,j,k,n,iblk) = spval_dbl
    4304             :                  else                            ! convert units
    4305             :                     a3Dz(i,j,k,n,iblk) = avail_hist_fields(nn)%cona*a3Dz(i,j,k,n,iblk) &
    4306           0 :                                    * ravgct + avail_hist_fields(nn)%conb
    4307             :                  endif
    4308             :               enddo             ! i
    4309             :               enddo             ! j
    4310             :               enddo             ! k
    4311             :               endif
    4312             :            enddo                ! n
    4313          34 :            do n = 1, num_avail_hist_fields_3Db
    4314           0 :               nn = n3Dzcum + n
    4315          34 :               if (avail_hist_fields(nn)%vhistfreq == histfreq(ns)) then
    4316           0 :               do k = 1, nzblyr
    4317           0 :               do j = jlo, jhi
    4318           0 :               do i = ilo, ihi
    4319           0 :                  if (.not. tmask(i,j,iblk)) then ! mask out land points
    4320           0 :                     a3Db(i,j,k,n,iblk) = spval_dbl
    4321             :                  else                            ! convert units
    4322             :                     a3Db(i,j,k,n,iblk) = avail_hist_fields(nn)%cona*a3Db(i,j,k,n,iblk) &
    4323           0 :                                    * ravgct + avail_hist_fields(nn)%conb
    4324             :                  endif
    4325             :               enddo             ! i
    4326             :               enddo             ! j
    4327             :               enddo             ! k
    4328             :               endif
    4329             :            enddo                ! n
    4330             : 
    4331          34 :            do n = 1, num_avail_hist_fields_3Da
    4332           0 :               nn = n3Dbcum + n
    4333          34 :               if (avail_hist_fields(nn)%vhistfreq == histfreq(ns)) then
    4334           0 :               do k = 1, nzalyr
    4335           0 :               do j = jlo, jhi
    4336           0 :               do i = ilo, ihi
    4337           0 :                  if (.not. tmask(i,j,iblk)) then ! mask out land points
    4338           0 :                     a3Da(i,j,k,n,iblk) = spval_dbl
    4339             :                  else                            ! convert units
    4340             :                     a3Da(i,j,k,n,iblk) = avail_hist_fields(nn)%cona*a3Da(i,j,k,n,iblk) &
    4341           0 :                                    * ravgct + avail_hist_fields(nn)%conb
    4342             :                  endif
    4343             :               enddo             ! i
    4344             :               enddo             ! j
    4345             :               enddo             ! k
    4346             :               endif
    4347             :            enddo                ! n
    4348             : 
    4349          34 :            do n = 1, num_avail_hist_fields_3Df
    4350           0 :               nn = n3Dacum + n
    4351          34 :               if (avail_hist_fields(nn)%vhistfreq == histfreq(ns)) then
    4352           0 :               do k = 1, nfsd
    4353           0 :               do j = jlo, jhi
    4354           0 :               do i = ilo, ihi
    4355           0 :                  if (.not. tmask(i,j,iblk)) then ! mask out land points
    4356           0 :                     a3Df(i,j,k,n,iblk) = spval_dbl
    4357             :                  else                            ! convert units
    4358             :                     a3Df(i,j,k,n,iblk) = avail_hist_fields(nn)%cona*a3Df(i,j,k,n,iblk) &
    4359           0 :                                    * ravgct + avail_hist_fields(nn)%conb
    4360             :                  endif
    4361             :               enddo             ! i
    4362             :               enddo             ! j
    4363             :               enddo             ! k
    4364             :               endif
    4365             :            enddo                ! n
    4366             : 
    4367          34 :            do n = 1, num_avail_hist_fields_4Di
    4368           0 :               nn = n3Dfcum + n
    4369          34 :               if (avail_hist_fields(nn)%vhistfreq == histfreq(ns)) then
    4370           0 :               do k = 1, nzilyr
    4371           0 :               do ic = 1, ncat_hist
    4372           0 :               do j = jlo, jhi
    4373           0 :               do i = ilo, ihi
    4374           0 :                  if (.not. tmask(i,j,iblk)) then ! mask out land points
    4375           0 :                     a4Di(i,j,k,ic,n,iblk) = spval_dbl
    4376             :                  else                            ! convert units
    4377             :                     a4Di(i,j,k,ic,n,iblk) = avail_hist_fields(nn)%cona*a4Di(i,j,k,ic,n,iblk) &
    4378           0 :                                    * ravgct + avail_hist_fields(nn)%conb
    4379             :                  endif
    4380             :               enddo             ! i
    4381             :               enddo             ! j
    4382             :               enddo             ! ic
    4383             :               enddo             ! k
    4384             :               endif
    4385             :            enddo                ! n
    4386             : 
    4387          34 :            do n = 1, num_avail_hist_fields_4Ds
    4388           0 :               nn = n4Dicum + n
    4389          34 :               if (avail_hist_fields(nn)%vhistfreq == histfreq(ns)) then
    4390           0 :               do k = 1, nzslyr
    4391           0 :               do ic = 1, ncat_hist
    4392           0 :               do j = jlo, jhi
    4393           0 :               do i = ilo, ihi
    4394           0 :                  if (.not. tmask(i,j,iblk)) then ! mask out land points
    4395           0 :                     a4Ds(i,j,k,ic,n,iblk) = spval_dbl
    4396             :                  else                            ! convert units
    4397             :                     a4Ds(i,j,k,ic,n,iblk) = avail_hist_fields(nn)%cona*a4Ds(i,j,k,ic,n,iblk) &
    4398           0 :                                    * ravgct + avail_hist_fields(nn)%conb
    4399             :                  endif
    4400             :               enddo             ! i
    4401             :               enddo             ! j
    4402             :               enddo             ! ic
    4403             :               enddo             ! k
    4404             :               endif
    4405             :            enddo                ! n
    4406             : 
    4407          34 :            do n = 1, num_avail_hist_fields_4Df
    4408           0 :               nn = n4Dscum + n
    4409          34 :               if (avail_hist_fields(nn)%vhistfreq == histfreq(ns)) then
    4410           0 :               do k = 1, nfsd
    4411           0 :               do ic = 1, ncat_hist
    4412           0 :               do j = jlo, jhi
    4413           0 :               do i = ilo, ihi
    4414           0 :                  if (.not. tmask(i,j,iblk)) then ! mask out land points
    4415           0 :                     a4Df(i,j,k,ic,n,iblk) = spval_dbl
    4416             :                  else                            ! convert units
    4417             :                     a4Df(i,j,k,ic,n,iblk) = avail_hist_fields(nn)%cona*a4Df(i,j,k,ic,n,iblk) &
    4418           0 :                                    * ravgct + avail_hist_fields(nn)%conb
    4419             :                  endif
    4420             :               enddo             ! i
    4421             :               enddo             ! j
    4422             :               enddo             ! ic
    4423             :               enddo             ! k
    4424             :               endif
    4425             :            enddo                ! n
    4426             : 
    4427             :       !---------------------------------------------------------------
    4428             :       ! snapshots
    4429             :       !---------------------------------------------------------------
    4430             : 
    4431             :             ! compute sig1 and sig2
    4432          34 :             select case (grid_ice)
    4433             :             case('B')
    4434             :                call principal_stress (nx_block,  ny_block,  &
    4435             :                                       stressp_1 (:,:,iblk), &   ! LCOV_EXCL_LINE
    4436             :                                       stressm_1 (:,:,iblk), &   ! LCOV_EXCL_LINE
    4437             :                                       stress12_1(:,:,iblk), &   ! LCOV_EXCL_LINE
    4438             :                                       strength  (:,:,iblk), &   ! LCOV_EXCL_LINE
    4439             :                                       sig1      (:,:,iblk), &   ! LCOV_EXCL_LINE
    4440             :                                       sig2      (:,:,iblk), &   ! LCOV_EXCL_LINE
    4441          34 :                                       sigP      (:,:,iblk))
    4442             :             case('CD','C')
    4443             :                call principal_stress (nx_block,  ny_block,  &
    4444             :                                       stresspT  (:,:,iblk), &   ! LCOV_EXCL_LINE
    4445             :                                       stressmT  (:,:,iblk), &   ! LCOV_EXCL_LINE
    4446             :                                       stress12T (:,:,iblk), &   ! LCOV_EXCL_LINE
    4447             :                                       strength  (:,:,iblk), &   ! LCOV_EXCL_LINE
    4448             :                                       sig1      (:,:,iblk), &   ! LCOV_EXCL_LINE
    4449             :                                       sig2      (:,:,iblk), &   ! LCOV_EXCL_LINE
    4450          34 :                                       sigP      (:,:,iblk))
    4451             :             end select
    4452             : 
    4453        1388 :            do j = jlo, jhi
    4454       57258 :            do i = ilo, ihi
    4455       57224 :               if (.not. tmask(i,j,iblk)) then ! mask out land points
    4456        8156 :                  if (n_divu     (ns) /= 0) a2D(i,j,n_divu(ns),     iblk) = spval_dbl
    4457        8156 :                  if (n_shear    (ns) /= 0) a2D(i,j,n_shear(ns),    iblk) = spval_dbl
    4458        8156 :                  if (n_sig1     (ns) /= 0) a2D(i,j,n_sig1(ns),     iblk) = spval_dbl
    4459        8156 :                  if (n_sig2     (ns) /= 0) a2D(i,j,n_sig2(ns),     iblk) = spval_dbl
    4460        8156 :                  if (n_sigP     (ns) /= 0) a2D(i,j,n_sigP(ns),     iblk) = spval_dbl
    4461        8156 :                  if (n_sistreave(ns) /= 0) a2D(i,j,n_sistreave(ns),iblk) = spval_dbl
    4462        8156 :                  if (n_sistremax(ns) /= 0) a2D(i,j,n_sistremax(ns),iblk) = spval_dbl
    4463        8156 :                  if (n_mlt_onset(ns) /= 0) a2D(i,j,n_mlt_onset(ns),iblk) = spval_dbl
    4464        8156 :                  if (n_frz_onset(ns) /= 0) a2D(i,j,n_frz_onset(ns),iblk) = spval_dbl
    4465        8156 :                  if (n_hisnap   (ns) /= 0) a2D(i,j,n_hisnap(ns),   iblk) = spval_dbl
    4466        8156 :                  if (n_aisnap   (ns) /= 0) a2D(i,j,n_aisnap(ns),   iblk) = spval_dbl
    4467        8156 :                  if (n_trsig    (ns) /= 0) a2D(i,j,n_trsig(ns),    iblk) = spval_dbl
    4468        8156 :                  if (n_iage     (ns) /= 0) a2D(i,j,n_iage(ns),     iblk) = spval_dbl
    4469        8156 :                  if (n_FY       (ns) /= 0) a2D(i,j,n_FY(ns),       iblk) = spval_dbl
    4470             : 
    4471        8156 :                  if (n_a11      (ns) /= 0) a2D(i,j,n_a11(ns),      iblk) = spval_dbl
    4472        8156 :                  if (n_a12      (ns) /= 0) a2D(i,j,n_a12(ns),      iblk) = spval_dbl
    4473        8156 :                  if (n_e11      (ns) /= 0) a2D(i,j,n_e11(ns),      iblk) = spval_dbl
    4474        8156 :                  if (n_e12      (ns) /= 0) a2D(i,j,n_e12(ns),      iblk) = spval_dbl
    4475        8156 :                  if (n_e22      (ns) /= 0) a2D(i,j,n_e22(ns),      iblk) = spval_dbl
    4476        8156 :                  if (n_s11      (ns) /= 0) a2D(i,j,n_s11(ns),      iblk) = spval_dbl
    4477        8156 :                  if (n_s12      (ns) /= 0) a2D(i,j,n_s12(ns),      iblk) = spval_dbl
    4478        8156 :                  if (n_s22      (ns) /= 0) a2D(i,j,n_s22(ns),      iblk) = spval_dbl
    4479        8156 :                  if (n_yieldstress11 (ns) /= 0) a2D(i,j,n_yieldstress11(ns),iblk) = spval_dbl
    4480        8156 :                  if (n_yieldstress12 (ns) /= 0) a2D(i,j,n_yieldstress12(ns),iblk) = spval_dbl
    4481        8156 :                  if (n_yieldstress22 (ns) /= 0) a2D(i,j,n_yieldstress22(ns),iblk) = spval_dbl
    4482             :               else
    4483       47812 :                  if (n_divu     (ns) /= 0) a2D(i,j,n_divu(ns),iblk)      = &
    4484       31800 :                        divu (i,j,iblk)*avail_hist_fields(n_divu(ns))%cona
    4485       47812 :                  if (n_shear    (ns) /= 0) a2D(i,j,n_shear(ns),iblk)     = &
    4486       31800 :                        shear(i,j,iblk)*avail_hist_fields(n_shear(ns))%cona
    4487       47812 :                  if (n_sig1     (ns) /= 0) a2D(i,j,n_sig1(ns),iblk)      = &
    4488       31800 :                        sig1 (i,j,iblk)*avail_hist_fields(n_sig1(ns))%cona
    4489       47812 :                  if (n_sig2     (ns) /= 0) a2D(i,j,n_sig2(ns),iblk)      = &
    4490       31800 :                        sig2 (i,j,iblk)*avail_hist_fields(n_sig2(ns))%cona
    4491       47812 :                  if (n_sigP     (ns) /= 0) a2D(i,j,n_sigP(ns),iblk)      = &
    4492       31800 :                        sigP (i,j,iblk)*avail_hist_fields(n_sigP(ns))%cona
    4493       47812 :                  if (n_sistreave(ns) /= 0) a2D(i,j,n_sistreave(ns),iblk) = &
    4494           0 :                        p5*(sig1(i,j,iblk)+sig2(i,j,iblk))*avail_hist_fields(n_sistreave(ns))%cona
    4495       47812 :                  if (n_sistremax(ns) /= 0) a2D(i,j,n_sistremax(ns),iblk) = &
    4496           0 :                        p5*(sig1(i,j,iblk)-sig2(i,j,iblk))*avail_hist_fields(n_sistremax(ns))%cona
    4497       47812 :                  if (n_mlt_onset(ns) /= 0) a2D(i,j,n_mlt_onset(ns),iblk) = &
    4498       31800 :                        mlt_onset(i,j,iblk)
    4499       47812 :                  if (n_frz_onset(ns) /= 0) a2D(i,j,n_frz_onset(ns),iblk) = &
    4500       31800 :                        frz_onset(i,j,iblk)
    4501       47812 :                  if (n_hisnap   (ns) /= 0) a2D(i,j,n_hisnap(ns),iblk)    = &
    4502           0 :                        vice(i,j,iblk)
    4503       47812 :                  if (n_aisnap   (ns) /= 0) a2D(i,j,n_aisnap(ns),iblk)    = &
    4504           0 :                        aice(i,j,iblk)
    4505             : 
    4506       47812 :                  if (kdyn == 2) then  ! for EAP dynamics different time of output
    4507           0 :                     if (n_trsig    (ns) /= 0) a2D(i,j,n_trsig(ns),iblk ) = &
    4508           0 :                                         strength(i,j,iblk)
    4509             :                  else
    4510       47812 :                     if (n_trsig    (ns) /= 0) a2D(i,j,n_trsig(ns),iblk ) = &
    4511             :                                        p25*(stressp_1(i,j,iblk) &   ! LCOV_EXCL_LINE
    4512             :                                           + stressp_2(i,j,iblk) &   ! LCOV_EXCL_LINE
    4513             :                                           + stressp_3(i,j,iblk) &   ! LCOV_EXCL_LINE
    4514       31800 :                                           + stressp_4(i,j,iblk))
    4515             :                  endif
    4516             : 
    4517       47812 :                  if (n_iage     (ns) /= 0) a2D(i,j,n_iage(ns),iblk)  = &
    4518       31800 :                        trcr(i,j,nt_iage,iblk)*avail_hist_fields(n_iage(ns))%cona
    4519       47812 :                  if (n_FY       (ns) /= 0) a2D(i,j,n_FY(ns),iblk)  = &
    4520           0 :                        trcr(i,j,nt_FY,iblk)*avail_hist_fields(n_FY(ns))%cona
    4521             : 
    4522       47812 :                  if (n_a11     (ns) /= 0) a2D(i,j,n_a11(ns),iblk)      = &
    4523           0 :                        a11 (i,j,iblk)*avail_hist_fields(n_a11(ns))%cona
    4524       47812 :                  if (n_a12     (ns) /= 0) a2D(i,j,n_a12(ns),iblk)      = &
    4525           0 :                        a12 (i,j,iblk)*avail_hist_fields(n_a12(ns))%cona
    4526       47812 :                  if (n_e11     (ns) /= 0) a2D(i,j,n_e11(ns),iblk)      = &
    4527           0 :                        e11 (i,j,iblk)*avail_hist_fields(n_e11(ns))%cona
    4528       47812 :                  if (n_e12     (ns) /= 0) a2D(i,j,n_e12(ns),iblk)      = &
    4529           0 :                        e12 (i,j,iblk)*avail_hist_fields(n_e12(ns))%cona
    4530       47812 :                  if (n_e22     (ns) /= 0) a2D(i,j,n_e22(ns),iblk)      = &
    4531           0 :                        e22 (i,j,iblk)*avail_hist_fields(n_e22(ns))%cona
    4532       47812 :                  if (n_s11     (ns) /= 0) a2D(i,j,n_s11(ns),iblk)      = &
    4533           0 :                        s11 (i,j,iblk)*avail_hist_fields(n_s11(ns))%cona
    4534       47812 :                  if (n_s12     (ns) /= 0) a2D(i,j,n_s12(ns),iblk)      = &
    4535           0 :                        s12 (i,j,iblk)*avail_hist_fields(n_s12(ns))%cona
    4536       47812 :                  if (n_s22     (ns) /= 0) a2D(i,j,n_s22(ns),iblk)      = &
    4537           0 :                        s22 (i,j,iblk)*avail_hist_fields(n_s22(ns))%cona
    4538       47812 :                  if (n_yieldstress11     (ns) /= 0) a2D(i,j,n_yieldstress11(ns),iblk)      = &
    4539           0 :                        yieldstress11 (i,j,iblk)*avail_hist_fields(n_yieldstress11(ns))%cona
    4540       47812 :                  if (n_yieldstress12     (ns) /= 0) a2D(i,j,n_yieldstress12(ns),iblk)      = &
    4541           0 :                        yieldstress12 (i,j,iblk)*avail_hist_fields(n_yieldstress12(ns))%cona
    4542       47812 :                  if (n_yieldstress22     (ns) /= 0) a2D(i,j,n_yieldstress22(ns),iblk)      = &
    4543           0 :                        yieldstress22 (i,j,iblk)*avail_hist_fields(n_yieldstress22(ns))%cona
    4544             :               endif
    4545             :            enddo                ! i
    4546             :            enddo                ! j
    4547             : 
    4548             :         enddo                   ! iblk
    4549             :         !$OMP END PARALLEL DO
    4550             : 
    4551          98 :         timedbl = timesecs/secday
    4552          98 :         time_end(ns) = real(timedbl,kind=real_kind)
    4553             : 
    4554             :       !---------------------------------------------------------------
    4555             :       ! write file
    4556             :       !---------------------------------------------------------------
    4557             : 
    4558          98 :         call ice_timer_start(timer_readwrite)  ! reading/writing
    4559          98 :         call ice_write_hist (ns)
    4560          98 :         call ice_timer_stop(timer_readwrite)  ! reading/writing
    4561             : 
    4562             :       !---------------------------------------------------------------
    4563             :       ! reset to zero
    4564             :       !------------------------------------------------------------
    4565          98 :         if (write_ic) then
    4566     5056097 :            if (allocated(a2D))  a2D (:,:,:,:)     = c0
    4567          37 :            if (allocated(a3Dc)) a3Dc(:,:,:,:,:)   = c0
    4568          37 :            if (allocated(a3Dz)) a3Dz(:,:,:,:,:)   = c0
    4569          37 :            if (allocated(a3Db)) a3Db(:,:,:,:,:)   = c0
    4570          37 :            if (allocated(a3Da)) a3Da(:,:,:,:,:)   = c0
    4571          37 :            if (allocated(a3Df)) a3Df(:,:,:,:,:)   = c0
    4572          37 :            if (allocated(a4Di)) a4Di(:,:,:,:,:,:) = c0
    4573          37 :            if (allocated(a4Ds)) a4Ds(:,:,:,:,:,:) = c0
    4574          37 :            if (allocated(a4Df)) a4Df(:,:,:,:,:,:) = c0
    4575          37 :            avgct(:) = c0
    4576      559717 :            albcnt(:,:,:,:) = c0
    4577      559717 :            snwcnt(:,:,:,:) = c0
    4578          37 :            write_ic = .false.        ! write initial condition once at most
    4579             :         else
    4580          61 :            avgct(ns) = c0
    4581      181336 :            albcnt(:,:,:,ns) = c0
    4582      181336 :            snwcnt(:,:,:,ns) = c0
    4583             :         endif
    4584             : !        if (write_history(ns)) albcnt(:,:,:,ns) = c0
    4585             : 
    4586        1996 :         do n = 1,n2D
    4587     5239170 :            if (avail_hist_fields(n)%vhistfreq == histfreq(ns)) a2D(:,:,n,:) = c0
    4588             :         enddo
    4589          98 :         do n = n2D + 1, n3Dccum
    4590           0 :            nn = n - n2D
    4591          98 :            if (avail_hist_fields(n)%vhistfreq == histfreq(ns)) a3Dc(:,:,:,nn,:) = c0
    4592             :         enddo
    4593          98 :         do n = n3Dccum + 1, n3Dzcum
    4594           0 :            nn = n - n3Dccum
    4595          98 :            if (avail_hist_fields(n)%vhistfreq == histfreq(ns)) a3Dz(:,:,:,nn,:) = c0
    4596             :         enddo
    4597          98 :         do n = n3Dzcum + 1, n3Dbcum
    4598           0 :            nn = n - n3Dzcum
    4599          98 :            if (avail_hist_fields(n)%vhistfreq == histfreq(ns)) a3Db(:,:,:,nn,:) = c0
    4600             :         enddo
    4601          98 :         do n = n3Dbcum + 1, n3Dacum
    4602           0 :            nn = n - n3Dbcum
    4603          98 :            if (avail_hist_fields(n)%vhistfreq == histfreq(ns)) a3Da(:,:,:,nn,:) = c0
    4604             :         enddo
    4605          98 :         do n = n3Dacum + 1, n3Dfcum
    4606           0 :            nn = n - n3Dacum
    4607          98 :            if (avail_hist_fields(n)%vhistfreq == histfreq(ns)) a3Df(:,:,:,nn,:) = c0
    4608             :         enddo
    4609          98 :         do n = n3Dfcum + 1, n4Dicum
    4610           0 :            nn = n - n3Dfcum
    4611          98 :            if (avail_hist_fields(n)%vhistfreq == histfreq(ns)) a4Di(:,:,:,:,nn,:) = c0
    4612             :         enddo
    4613          98 :         do n = n4Dicum + 1, n4Dscum
    4614           0 :            nn = n - n4Dicum
    4615          98 :            if (avail_hist_fields(n)%vhistfreq == histfreq(ns)) a4Ds(:,:,:,:,nn,:) = c0
    4616             :         enddo
    4617          98 :         do n = n4Dscum + 1, n4Dfcum
    4618           0 :            nn = n - n4Dscum
    4619          98 :            if (avail_hist_fields(n)%vhistfreq == histfreq(ns)) a4Df(:,:,:,:,nn,:) = c0
    4620             :         enddo
    4621             : 
    4622             :       endif  ! write_history or write_ic
    4623             :       enddo  ! nstreams
    4624             : 
    4625        2900 :       !$OMP PARALLEL DO PRIVATE(iblk,i,j,ilo,ihi,jlo,jhi,this_block)
    4626        8738 :       do iblk = 1, nblocks
    4627        5817 :          this_block = get_block(blocks_ice(iblk),iblk)
    4628        5817 :          ilo = this_block%ilo
    4629        5817 :          ihi = this_block%ihi
    4630        5817 :          jlo = this_block%jlo
    4631        5817 :          jhi = this_block%jhi
    4632             : 
    4633        5817 :          if (new_year) then
    4634           0 :             do j=jlo,jhi
    4635           0 :             do i=ilo,ihi
    4636             :                ! reset NH Jan 1
    4637           0 :                if (lmask_n(i,j,iblk)) mlt_onset(i,j,iblk) = c0
    4638             :                ! reset SH Jan 1
    4639           0 :                if (lmask_s(i,j,iblk)) frz_onset(i,j,iblk) = c0
    4640             :             enddo
    4641             :             enddo
    4642             :          endif                  ! new_year
    4643             : 
    4644       11638 :          if ( (mmonth .eq. 7) .and. new_month ) then
    4645           0 :             do j=jlo,jhi
    4646           0 :             do i=ilo,ihi
    4647             :                ! reset SH Jul 1
    4648           0 :                if (lmask_s(i,j,iblk)) mlt_onset(i,j,iblk) = c0
    4649             :                ! reset NH Jul 1
    4650           0 :                if (lmask_n(i,j,iblk)) frz_onset(i,j,iblk) = c0
    4651             :             enddo
    4652             :             enddo
    4653             :          endif                  ! 1st of July
    4654             :       enddo                     ! iblk
    4655             :       !$OMP END PARALLEL DO
    4656             : 
    4657        5821 :       end subroutine accum_hist
    4658             : 
    4659             : !=======================================================================
    4660             : 
    4661             :       end module ice_history
    4662             : 
    4663             : !=======================================================================

Generated by: LCOV version 1.14-6-g40580cd