LCOV - code coverage report
Current view: top level - columnphysics - icepack_tracers.F90 (source / functions) Coverage Total Hit
Test: 250117-002718:9f4b99afd9:4:base,io,travis,quick Lines: 91.67 % 504 462
Test Date: 2025-01-16 18:02:43 Functions: 100.00 % 10 10

            Line data    Source code
       1              : !=======================================================================
       2              : ! Indices and flags associated with the tracer infrastructure.
       3              : ! Grid-dependent and max_trcr-dependent arrays are declared in ice_state.F90.
       4              : !
       5              : ! author Elizabeth C. Hunke, LANL
       6              : 
       7              :       module icepack_tracers
       8              : 
       9              :       use icepack_kinds
      10              :       use icepack_parameters, only: c0, c1, puny, rhos, rsnw_fall, rhosnew
      11              :       use icepack_parameters, only: snwredist, snwgrain
      12              :       use icepack_warnings, only: warnstr, icepack_warnings_add
      13              :       use icepack_warnings, only: icepack_warnings_setabort, icepack_warnings_aborted
      14              : 
      15              :       implicit none
      16              : 
      17              :       private
      18              :       public :: icepack_compute_tracers
      19              :       public :: icepack_init_tracer_flags
      20              :       public :: icepack_query_tracer_flags
      21              :       public :: icepack_write_tracer_flags
      22              :       public :: icepack_init_tracer_indices
      23              :       public :: icepack_query_tracer_indices
      24              :       public :: icepack_write_tracer_indices
      25              :       public :: icepack_init_tracer_sizes
      26              :       public :: icepack_query_tracer_sizes
      27              :       public :: icepack_write_tracer_sizes
      28              : 
      29              :       !-----------------------------------------------------------------
      30              :       ! dimensions
      31              :       !-----------------------------------------------------------------
      32              :       integer (kind=int_kind), parameter, public :: &
      33              :          max_iso    =   3       , & ! maximum number of isotopes
      34              :          nmodal1    =   10      , & ! dimension for modal aerosol radiation parameters
      35              :          nmodal2    =   8       , & ! dimension for modal aerosol radiation parameters
      36              :          max_algae  =   3       , & ! maximum number of algal types
      37              :          max_dic    =   1       , & ! maximum number of dissolved inorganic carbon types
      38              :          max_doc    =   3       , & ! maximum number of dissolved organic carbon types
      39              :          max_don    =   1       , & ! maximum number of dissolved organic nitrogen types
      40              :          max_fe     =   2       , & ! maximum number of iron types
      41              :          max_aero   =   6       , & ! maximum number of aerosols
      42              :          max_nbtrcr = max_algae*2 & ! algal nitrogen and chlorophyll
      43              :                     + max_dic     & ! dissolved inorganic carbon
      44              :                     + max_doc     & ! dissolved organic carbon
      45              :                     + max_don     & ! dissolved organic nitrogen
      46              :                     + 5           & ! nitrate, ammonium, silicate, PON, and humics
      47              :                     + 3           & ! DMSPp, DMSPd, DMS
      48              :                     + max_fe*2    & ! dissolved Fe and  particulate Fe
      49              :                     + max_aero      ! aerosols
      50              : 
      51              :       integer (kind=int_kind), public :: &
      52              :          ntrcr        = 0, & ! number of tracers in use
      53              :          ntrcr_o      = 0, & ! number of non-bio tracers in use
      54              :          ncat         = 0, & ! number of ice categories in use
      55              :          nilyr        = 0, & ! number of ice layers per category
      56              :          nslyr        = 0, & ! number of snow layers per category
      57              :          nblyr        = 0, & ! number of bio/brine layers per category
      58              :          nfsd         = 0, & ! number of fsd layers
      59              :          n_iso        = 0, & ! number of isotopes in use
      60              :          n_aero       = 0, & ! number of aerosols in use
      61              :          n_zaero      = 0, & ! number of z aerosols in use
      62              :          n_algae      = 0, & ! number of algae in use
      63              :          n_doc        = 0, & ! number of DOC pools in use
      64              :          n_dic        = 0, & ! number of DIC pools in use
      65              :          n_don        = 0, & ! number of DON pools in use
      66              :          n_fed        = 0, & ! number of Fe  pools in use dissolved Fe
      67              :          n_fep        = 0    ! number of Fe  pools in use particulate Fe
      68              : 
      69              :       integer (kind=int_kind), public :: &
      70              :          nt_Tsfc      = 0, & ! ice/snow temperature
      71              :          nt_qice      = 0, & ! volume-weighted ice enthalpy (in layers)
      72              :          nt_qsno      = 0, & ! volume-weighted snow enthalpy (in layers)
      73              :          nt_sice      = 0, & ! volume-weighted ice bulk salinity (CICE grid layers)
      74              :          nt_fbri      = 0, & ! volume fraction of ice with dynamic salt (hinS/vicen*aicen)
      75              :          nt_iage      = 0, & ! volume-weighted ice age
      76              :          nt_FY        = 0, & ! area-weighted first-year ice area
      77              :          nt_alvl      = 0, & ! level ice area fraction
      78              :          nt_vlvl      = 0, & ! level ice volume fraction
      79              :          nt_apnd      = 0, & ! melt pond area fraction
      80              :          nt_hpnd      = 0, & ! melt pond depth
      81              :          nt_ipnd      = 0, & ! melt pond refrozen lid thickness
      82              :          nt_fsd       = 0, & ! floe size distribution
      83              :          nt_smice     = 0, & ! mass of ice in snow
      84              :          nt_smliq     = 0, & ! mass of liquid water in snow
      85              :          nt_rhos      = 0, & ! snow density
      86              :          nt_rsnw      = 0, & ! snow grain radius
      87              :          nt_isosno    = 0, & ! starting index for isotopes in snow
      88              :          nt_isoice    = 0, & ! starting index for isotopes in ice
      89              :          nt_aero      = 0, & ! starting index for aerosols in ice
      90              :          nt_bgc_Nit   = 0, & ! nutrients
      91              :          nt_bgc_Am    = 0, & !
      92              :          nt_bgc_Sil   = 0, & !
      93              :          nt_bgc_DMSPp = 0, & ! trace gases (skeletal layer)
      94              :          nt_bgc_DMSPd = 0, & !
      95              :          nt_bgc_DMS   = 0, & !
      96              :          nt_bgc_PON   = 0, & ! zooplankton and detritus
      97              :          nt_bgc_hum   = 0, & ! humic material
      98              :          nt_zbgc_frac = 0, & ! fraction of tracer in the mobile phase
      99              :          nt_bgc_S     = 0    ! Bulk salinity in fraction ice with dynamic salinity (Bio grid) (deprecated)
     100              : 
     101              :       logical (kind=log_kind), public :: &
     102              :          tr_iage      = .false., & ! if .true., use age tracer
     103              :          tr_FY        = .false., & ! if .true., use first-year area tracer
     104              :          tr_lvl       = .false., & ! if .true., use level ice tracer
     105              :          tr_pond      = .false., & ! if .true., use melt pond tracer
     106              :          tr_pond_lvl  = .false., & ! if .true., use level-ice pond tracer
     107              :          tr_pond_topo = .false., & ! if .true., use explicit topography-based ponds
     108              :          tr_snow      = .false., & ! if .true., use snow redistribution or metamorphosis tracers
     109              :          tr_iso       = .false., & ! if .true., use isotope tracers
     110              :          tr_aero      = .false., & ! if .true., use aerosol tracers
     111              :          tr_brine     = .false., & ! if .true., brine height differs from ice thickness
     112              :          tr_fsd       = .false.    ! if .true., use floe size distribution
     113              : 
     114              :       !-----------------------------------------------------------------
     115              :       !  biogeochemistry
     116              :       !-----------------------------------------------------------------
     117              : 
     118              :       logical (kind=log_kind), public :: &
     119              :          tr_zaero     = .false., & ! if .true., black carbon as tracers  (n_zaero)
     120              :          tr_bgc_Nit   = .false., & ! if .true. Nitrate tracer in ice
     121              :          tr_bgc_N     = .false., & ! if .true., algal nitrogen tracers  (n_algae)
     122              :          tr_bgc_DON   = .false., & ! if .true., DON pools are tracers  (n_don)
     123              :          tr_bgc_C     = .false., & ! if .true., algal carbon tracers + DOC and DIC
     124              :          tr_bgc_chl   = .false., & ! if .true., algal chlorophyll tracers
     125              :          tr_bgc_Am    = .false., & ! if .true., ammonia/um as nutrient tracer
     126              :          tr_bgc_Sil   = .false., & ! if .true., silicon as nutrient tracer
     127              :          tr_bgc_DMS   = .false., & ! if .true., DMS as tracer
     128              :          tr_bgc_Fe    = .false., & ! if .true., Fe as  tracer
     129              :          tr_bgc_PON   = .false., & ! if .true., PON as tracer
     130              :          tr_bgc_hum   = .false.    ! if .true., humic material as tracer
     131              : 
     132              :       integer (kind=int_kind), public :: &
     133              :          nbtrcr       = 0, & ! number of bgc tracers in use
     134              :          nbtrcr_sw    = 0, & ! number of bgc tracers which impact shortwave
     135              :          nlt_chl_sw   = 0    ! points to total chla in trcrn_sw
     136              : 
     137              :       integer (kind=int_kind), dimension(max_aero), public :: &
     138              :          nlt_zaero_sw = 0    ! points to aerosol in trcrn_sw
     139              : 
     140              :       integer (kind=int_kind), dimension(max_algae), public :: &
     141              :          nlt_bgc_N    = 0, & ! algae
     142              :          nlt_bgc_C    = 0, & !
     143              :          nlt_bgc_chl  = 0    !
     144              : 
     145              :       integer (kind=int_kind), dimension(max_doc), public :: &
     146              :          nlt_bgc_DOC  = 0    ! disolved organic carbon
     147              : 
     148              :       integer (kind=int_kind), dimension(max_don), public :: &
     149              :          nlt_bgc_DON  = 0    !
     150              : 
     151              :       integer (kind=int_kind), dimension(max_dic), public :: &
     152              :          nlt_bgc_DIC  = 0    ! disolved inorganic carbon
     153              : 
     154              :       integer (kind=int_kind), dimension(max_fe), public :: &
     155              :          nlt_bgc_Fed  = 0, & !
     156              :          nlt_bgc_Fep  = 0    !
     157              : 
     158              :       integer (kind=int_kind), dimension(max_aero), public :: &
     159              :          nlt_zaero    = 0    ! non-reacting layer aerosols
     160              : 
     161              :       integer (kind=int_kind), public :: &
     162              :          nlt_bgc_Nit  = 0, & ! nutrients
     163              :          nlt_bgc_Am   = 0, & !
     164              :          nlt_bgc_Sil  = 0, & !
     165              :          nlt_bgc_DMSPp= 0, & ! trace gases (skeletal layer)
     166              :          nlt_bgc_DMSPd= 0, & !
     167              :          nlt_bgc_DMS  = 0, & !
     168              :          nlt_bgc_PON  = 0, & ! zooplankton and detritus
     169              :          nlt_bgc_hum  = 0    ! humic material
     170              : 
     171              :       integer (kind=int_kind), dimension(max_algae), public :: &
     172              :          nt_bgc_N     = 0, & ! diatoms, phaeocystis, pico/small
     173              :          nt_bgc_C     = 0, & ! diatoms, phaeocystis, pico/small
     174              :          nt_bgc_chl   = 0    ! diatoms, phaeocystis, pico/small
     175              : 
     176              :       integer (kind=int_kind), dimension(max_doc), public :: &
     177              :          nt_bgc_DOC   = 0    !  dissolved organic carbon
     178              : 
     179              :       integer (kind=int_kind), dimension(max_don), public :: &
     180              :          nt_bgc_DON   = 0    !  dissolved organic nitrogen
     181              : 
     182              :       integer (kind=int_kind), dimension(max_dic), public :: &
     183              :          nt_bgc_DIC   = 0    !  dissolved inorganic carbon
     184              : 
     185              :       integer (kind=int_kind), dimension(max_fe), public :: &
     186              :          nt_bgc_Fed   = 0, & !  dissolved iron
     187              :          nt_bgc_Fep   = 0    !  particulate iron
     188              : 
     189              :       integer (kind=int_kind), dimension(max_aero), public :: &
     190              :          nt_zaero     = 0    !  black carbon and other aerosols
     191              : 
     192              :       integer (kind=int_kind), dimension(max_nbtrcr), public :: &
     193              :          bio_index_o  = 0    ! relates nlt_bgc_NO to ocean concentration index
     194              :                              ! see ocean_bio_all
     195              : 
     196              :       integer (kind=int_kind), dimension(max_nbtrcr), public :: &
     197              :          bio_index    = 0    ! relates bio indices, ie.  nlt_bgc_N to nt_bgc_N
     198              : 
     199              : !=======================================================================
     200              : 
     201              :       contains
     202              : 
     203              : !=======================================================================
     204              : !autodocument_start icepack_init_tracer_flags
     205              : ! set tracer active flags
     206              : 
     207          166 :       subroutine icepack_init_tracer_flags(&
     208              :            tr_iage_in, tr_FY_in, tr_lvl_in, tr_snow_in, &
     209              :            tr_pond_in, tr_pond_lvl_in, tr_pond_topo_in, &
     210              :            tr_fsd_in, tr_aero_in, tr_iso_in, tr_brine_in, tr_zaero_in, &
     211              :            tr_bgc_Nit_in, tr_bgc_N_in, tr_bgc_DON_in, tr_bgc_C_in, tr_bgc_chl_in, &
     212              :            tr_bgc_Am_in, tr_bgc_Sil_in, tr_bgc_DMS_in, tr_bgc_Fe_in, tr_bgc_hum_in, &
     213              :            tr_bgc_PON_in)
     214              : 
     215              :         logical, intent(in), optional :: &
     216              :              tr_iage_in      , & ! if .true., use age tracer
     217              :              tr_FY_in        , & ! if .true., use first-year area tracer
     218              :              tr_lvl_in       , & ! if .true., use level ice tracer
     219              :              tr_pond_in      , & ! if .true., use melt pond tracer
     220              :              tr_pond_lvl_in  , & ! if .true., use level-ice pond tracer
     221              :              tr_pond_topo_in , & ! if .true., use explicit topography-based ponds
     222              :              tr_snow_in      , & ! if .true., use snow redistribution or metamorphosis tracers
     223              :              tr_fsd_in       , & ! if .true., use floe size distribution tracers
     224              :              tr_iso_in       , & ! if .true., use isotope tracers
     225              :              tr_aero_in      , & ! if .true., use aerosol tracers
     226              :              tr_brine_in     , & ! if .true., brine height differs from ice thickness
     227              :              tr_zaero_in     , & ! if .true., black carbon is tracers  (n_zaero)
     228              :              tr_bgc_Nit_in   , & ! if .true., Nitrate tracer in ice
     229              :              tr_bgc_N_in     , & ! if .true., algal nitrogen tracers  (n_algae)
     230              :              tr_bgc_DON_in   , & ! if .true., DON pools are tracers  (n_don)
     231              :              tr_bgc_C_in     , & ! if .true., algal carbon tracers + DOC and DIC
     232              :              tr_bgc_chl_in   , & ! if .true., algal chlorophyll tracers
     233              :              tr_bgc_Am_in    , & ! if .true., ammonia/um as nutrient tracer
     234              :              tr_bgc_Sil_in   , & ! if .true., silicon as nutrient tracer
     235              :              tr_bgc_DMS_in   , & ! if .true., DMS as product tracer
     236              :              tr_bgc_Fe_in    , & ! if .true., Fe as product tracer
     237              :              tr_bgc_hum_in   , & ! if .true., hum as product tracer
     238              :              tr_bgc_PON_in       ! if .true., PON as product tracer
     239              : 
     240              : !autodocument_end
     241              : 
     242              :         character(len=*),parameter :: subname='(icepack_init_tracer_flags)'
     243              : 
     244          166 :         if (present(tr_iage_in)) tr_iage = tr_iage_in
     245          166 :         if (present(tr_FY_in)  ) tr_FY   = tr_FY_in
     246          166 :         if (present(tr_lvl_in) ) tr_lvl  = tr_lvl_in
     247          166 :         if (present(tr_pond_in)) tr_pond = tr_pond_in
     248          166 :         if (present(tr_pond_lvl_in) ) tr_pond_lvl  = tr_pond_lvl_in
     249          166 :         if (present(tr_pond_topo_in)) tr_pond_topo = tr_pond_topo_in
     250          166 :         if (present(tr_snow_in)   ) tr_snow    = tr_snow_in
     251          166 :         if (present(tr_fsd_in)    ) tr_fsd     = tr_fsd_in
     252          166 :         if (present(tr_iso_in)    ) tr_iso     = tr_iso_in
     253          166 :         if (present(tr_aero_in)   ) tr_aero    = tr_aero_in
     254          166 :         if (present(tr_brine_in)  ) tr_brine   = tr_brine_in
     255          166 :         if (present(tr_zaero_in)  ) tr_zaero   = tr_zaero_in
     256          166 :         if (present(tr_bgc_Nit_in)) tr_bgc_Nit = tr_bgc_Nit_in
     257          166 :         if (present(tr_bgc_N_in)  ) tr_bgc_N   = tr_bgc_N_in
     258          166 :         if (present(tr_bgc_DON_in)) tr_bgc_DON = tr_bgc_DON_in
     259          166 :         if (present(tr_bgc_C_in)  ) tr_bgc_C   = tr_bgc_C_in
     260          166 :         if (present(tr_bgc_chl_in)) tr_bgc_chl = tr_bgc_chl_in
     261          166 :         if (present(tr_bgc_Am_in) ) tr_bgc_Am  = tr_bgc_Am_in
     262          166 :         if (present(tr_bgc_Sil_in)) tr_bgc_Sil = tr_bgc_Sil_in
     263          166 :         if (present(tr_bgc_DMS_in)) tr_bgc_DMS = tr_bgc_DMS_in
     264          166 :         if (present(tr_bgc_Fe_in )) tr_bgc_Fe  = tr_bgc_Fe_in
     265          166 :         if (present(tr_bgc_hum_in)) tr_bgc_hum = tr_bgc_hum_in
     266          166 :         if (present(tr_bgc_PON_in)) tr_bgc_PON = tr_bgc_PON_in
     267              : 
     268          166 :       end subroutine icepack_init_tracer_flags
     269              : 
     270              : !=======================================================================
     271              : !autodocument_start icepack_query_tracer_flags
     272              : ! query tracer active flags
     273              : 
     274      6292641 :       subroutine icepack_query_tracer_flags(&
     275              :            tr_iage_out, tr_FY_out, tr_lvl_out, tr_snow_out, &
     276              :            tr_pond_out, tr_pond_lvl_out, tr_pond_topo_out, &
     277              :            tr_fsd_out, tr_aero_out, tr_iso_out, tr_brine_out, tr_zaero_out, &
     278              :            tr_bgc_Nit_out, tr_bgc_N_out, tr_bgc_DON_out, tr_bgc_C_out, tr_bgc_chl_out, &
     279              :            tr_bgc_Am_out, tr_bgc_Sil_out, tr_bgc_DMS_out, tr_bgc_Fe_out, tr_bgc_hum_out, &
     280              :            tr_bgc_PON_out)
     281              : 
     282              :         logical, intent(out), optional :: &
     283              :              tr_iage_out      , & ! if .true., use age tracer
     284              :              tr_FY_out        , & ! if .true., use first-year area tracer
     285              :              tr_lvl_out       , & ! if .true., use level ice tracer
     286              :              tr_pond_out      , & ! if .true., use melt pond tracer
     287              :              tr_pond_lvl_out  , & ! if .true., use level-ice pond tracer
     288              :              tr_pond_topo_out , & ! if .true., use explicit topography-based ponds
     289              :              tr_snow_out      , & ! if .true., use snow redistribution or metamorphosis tracers
     290              :              tr_fsd_out       , & ! if .true., use floe size distribution
     291              :              tr_iso_out       , & ! if .true., use isotope tracers
     292              :              tr_aero_out      , & ! if .true., use aerosol tracers
     293              :              tr_brine_out     , & ! if .true., brine height differs from ice thickness
     294              :              tr_zaero_out     , & ! if .true., black carbon is tracers  (n_zaero)
     295              :              tr_bgc_Nit_out   , & ! if .true., Nitrate tracer in ice
     296              :              tr_bgc_N_out     , & ! if .true., algal nitrogen tracers  (n_algae)
     297              :              tr_bgc_DON_out   , & ! if .true., DON pools are tracers  (n_don)
     298              :              tr_bgc_C_out     , & ! if .true., algal carbon tracers + DOC and DIC
     299              :              tr_bgc_chl_out   , & ! if .true., algal chlorophyll tracers
     300              :              tr_bgc_Am_out    , & ! if .true., ammonia/um as nutrient tracer
     301              :              tr_bgc_Sil_out   , & ! if .true., silicon as nutrient tracer
     302              :              tr_bgc_DMS_out   , & ! if .true., DMS as product tracer
     303              :              tr_bgc_Fe_out    , & ! if .true., Fe as product tracer
     304              :              tr_bgc_hum_out   , & ! if .true., hum as product tracer
     305              :              tr_bgc_PON_out       ! if .true., PON as product tracer
     306              : 
     307              : !autodocument_end
     308              : 
     309              :         character(len=*),parameter :: subname='(icepack_query_tracer_flags)'
     310              : 
     311      6292641 :         if (present(tr_iage_out)) tr_iage_out = tr_iage
     312      6292641 :         if (present(tr_FY_out)  ) tr_FY_out   = tr_FY
     313      6292641 :         if (present(tr_lvl_out) ) tr_lvl_out  = tr_lvl
     314      6292641 :         if (present(tr_pond_out)) tr_pond_out = tr_pond
     315      6292641 :         if (present(tr_pond_lvl_out) ) tr_pond_lvl_out  = tr_pond_lvl
     316      6292641 :         if (present(tr_pond_topo_out)) tr_pond_topo_out = tr_pond_topo
     317      6292641 :         if (present(tr_snow_out)   ) tr_snow_out    = tr_snow
     318      6292641 :         if (present(tr_fsd_out)    ) tr_fsd_out     = tr_fsd
     319      6292641 :         if (present(tr_iso_out)    ) tr_iso_out     = tr_iso
     320      6292641 :         if (present(tr_aero_out)   ) tr_aero_out    = tr_aero
     321      6292641 :         if (present(tr_brine_out)  ) tr_brine_out   = tr_brine
     322      6292641 :         if (present(tr_zaero_out)  ) tr_zaero_out   = tr_zaero
     323      6292641 :         if (present(tr_bgc_Nit_out)) tr_bgc_Nit_out = tr_bgc_Nit
     324      6292641 :         if (present(tr_bgc_N_out)  ) tr_bgc_N_out   = tr_bgc_N
     325      6292641 :         if (present(tr_bgc_DON_out)) tr_bgc_DON_out = tr_bgc_DON
     326      6292641 :         if (present(tr_bgc_C_out)  ) tr_bgc_C_out   = tr_bgc_C
     327      6292641 :         if (present(tr_bgc_chl_out)) tr_bgc_chl_out = tr_bgc_chl
     328      6292641 :         if (present(tr_bgc_Am_out) ) tr_bgc_Am_out  = tr_bgc_Am
     329      6292641 :         if (present(tr_bgc_Sil_out)) tr_bgc_Sil_out = tr_bgc_Sil
     330      6292641 :         if (present(tr_bgc_DMS_out)) tr_bgc_DMS_out = tr_bgc_DMS
     331      6292641 :         if (present(tr_bgc_Fe_out )) tr_bgc_Fe_out  = tr_bgc_Fe
     332      6292641 :         if (present(tr_bgc_hum_out)) tr_bgc_hum_out = tr_bgc_hum
     333      6292641 :         if (present(tr_bgc_PON_out)) tr_bgc_PON_out = tr_bgc_PON
     334              : 
     335      6292641 :       end subroutine icepack_query_tracer_flags
     336              : 
     337              : !=======================================================================
     338              : !autodocument_start icepack_write_tracer_flags
     339              : ! write tracer active flags
     340              : 
     341           83 :       subroutine icepack_write_tracer_flags(iounit)
     342              : 
     343              :         integer, intent(in) :: iounit
     344              : 
     345              : !autodocument_end
     346              : 
     347              :         character(len=*),parameter :: subname='(icepack_write_tracer_flags)'
     348              : 
     349           83 :         write(iounit,*) subname//":"
     350           83 :         write(iounit,*) "  tr_iage = ",tr_iage
     351           83 :         write(iounit,*) "  tr_FY   = ",tr_FY
     352           83 :         write(iounit,*) "  tr_lvl  = ",tr_lvl
     353           83 :         write(iounit,*) "  tr_pond = ",tr_pond
     354           83 :         write(iounit,*) "  tr_pond_lvl  = ",tr_pond_lvl
     355           83 :         write(iounit,*) "  tr_pond_topo = ",tr_pond_topo
     356           83 :         write(iounit,*) "  tr_snow    = ",tr_snow
     357           83 :         write(iounit,*) "  tr_fsd     = ",tr_fsd
     358           83 :         write(iounit,*) "  tr_iso     = ",tr_iso
     359           83 :         write(iounit,*) "  tr_aero    = ",tr_aero
     360           83 :         write(iounit,*) "  tr_brine   = ",tr_brine
     361           83 :         write(iounit,*) "  tr_zaero   = ",tr_zaero
     362           83 :         write(iounit,*) "  tr_bgc_Nit = ",tr_bgc_Nit
     363           83 :         write(iounit,*) "  tr_bgc_N   = ",tr_bgc_N
     364           83 :         write(iounit,*) "  tr_bgc_DON = ",tr_bgc_DON
     365           83 :         write(iounit,*) "  tr_bgc_C   = ",tr_bgc_C
     366           83 :         write(iounit,*) "  tr_bgc_chl = ",tr_bgc_chl
     367           83 :         write(iounit,*) "  tr_bgc_Am  = ",tr_bgc_Am
     368           83 :         write(iounit,*) "  tr_bgc_Sil = ",tr_bgc_Sil
     369           83 :         write(iounit,*) "  tr_bgc_DMS = ",tr_bgc_DMS
     370           83 :         write(iounit,*) "  tr_bgc_Fe  = ",tr_bgc_Fe
     371           83 :         write(iounit,*) "  tr_bgc_hum = ",tr_bgc_hum
     372           83 :         write(iounit,*) "  tr_bgc_PON = ",tr_bgc_PON
     373              : 
     374           83 :       end subroutine icepack_write_tracer_flags
     375              : 
     376              : !=======================================================================
     377              : !autodocument_start icepack_init_tracer_indices
     378              : ! set the number of column tracer indices
     379              : 
     380          166 :       subroutine icepack_init_tracer_indices(&
     381              :            nt_Tsfc_in, nt_qice_in, nt_qsno_in, nt_sice_in, &
     382              :            nt_fbri_in, nt_iage_in, nt_FY_in, &
     383              :            nt_alvl_in, nt_vlvl_in, nt_apnd_in, nt_hpnd_in, nt_ipnd_in, &
     384              :            nt_smice_in, nt_smliq_in, nt_rhos_in, nt_rsnw_in, &
     385              :            nt_fsd_in, nt_isosno_in, nt_isoice_in, &
     386          332 :            nt_aero_in, nt_zaero_in, nt_bgc_C_in, &
     387          664 :            nt_bgc_N_in, nt_bgc_chl_in, nt_bgc_DOC_in, nt_bgc_DON_in, &
     388          498 :            nt_bgc_DIC_in, nt_bgc_Fed_in, nt_bgc_Fep_in, nt_bgc_Nit_in, nt_bgc_Am_in, &
     389              :            nt_bgc_Sil_in, nt_bgc_DMSPp_in, nt_bgc_DMSPd_in, nt_bgc_DMS_in, nt_bgc_hum_in, &
     390          664 :            nt_bgc_PON_in, nlt_zaero_in, nlt_bgc_C_in, nlt_bgc_N_in, nlt_bgc_chl_in, &
     391          664 :            nlt_bgc_DOC_in, nlt_bgc_DON_in, nlt_bgc_DIC_in, nlt_bgc_Fed_in, &
     392          166 :            nlt_bgc_Fep_in, nlt_bgc_Nit_in, nlt_bgc_Am_in, nlt_bgc_Sil_in, &
     393              :            nlt_bgc_DMSPp_in, nlt_bgc_DMSPd_in, nlt_bgc_DMS_in, nlt_bgc_hum_in, &
     394              :            nlt_bgc_PON_in, nt_zbgc_frac_in, nt_bgc_S_in, nlt_chl_sw_in, &
     395          166 :            nlt_zaero_sw_in, &
     396          166 :            bio_index_o_in, bio_index_in)
     397              : 
     398              :         integer, intent(in), optional :: &
     399              :              nt_Tsfc_in, & ! ice/snow temperature
     400              :              nt_qice_in, & ! volume-weighted ice enthalpy (in layers)
     401              :              nt_qsno_in, & ! volume-weighted snow enthalpy (in layers)
     402              :              nt_sice_in, & ! volume-weighted ice bulk salinity (CICE grid layers)
     403              :              nt_fbri_in, & ! volume fraction of ice with dynamic salt (hinS/vicen*aicen)
     404              :              nt_iage_in, & ! volume-weighted ice age
     405              :              nt_FY_in,   & ! area-weighted first-year ice area
     406              :              nt_alvl_in, & ! level ice area fraction
     407              :              nt_vlvl_in, & ! level ice volume fraction
     408              :              nt_apnd_in, & ! melt pond area fraction
     409              :              nt_hpnd_in, & ! melt pond depth
     410              :              nt_ipnd_in, & ! melt pond refrozen lid thickness
     411              :              nt_smice_in,& ! mass of ice in snow
     412              :              nt_smliq_in,& ! mass of liquid water in snow
     413              :              nt_rhos_in, & ! snow density
     414              :              nt_rsnw_in, & ! snow grain radius
     415              :              nt_fsd_in,  & ! floe size distribution
     416              :              nt_isosno_in,  & ! starting index for isotopes in snow
     417              :              nt_isoice_in,  & ! starting index for isotopes in ice
     418              :              nt_aero_in,    & ! starting index for aerosols in ice
     419              :              nt_bgc_Nit_in, & ! nutrients
     420              :              nt_bgc_Am_in,  & !
     421              :              nt_bgc_Sil_in, & !
     422              :              nt_bgc_DMSPp_in,&! trace gases (skeletal layer)
     423              :              nt_bgc_DMSPd_in,&!
     424              :              nt_bgc_DMS_in, & !
     425              :              nt_bgc_hum_in, & !
     426              :              nt_bgc_PON_in, & ! zooplankton and detritus
     427              :              nlt_bgc_Nit_in,& ! nutrients
     428              :              nlt_bgc_Am_in, & !
     429              :              nlt_bgc_Sil_in,& !
     430              :              nlt_bgc_DMSPp_in,&! trace gases (skeletal layer)
     431              :              nlt_bgc_DMSPd_in,&!
     432              :              nlt_bgc_DMS_in,& !
     433              :              nlt_bgc_hum_in,& !
     434              :              nlt_bgc_PON_in,& ! zooplankton and detritus
     435              :              nt_zbgc_frac_in,&! fraction of tracer in the mobile phase
     436              :              nt_bgc_S_in,   & ! (deprecated, was related to zsalinity)
     437              :              nlt_chl_sw_in    ! points to total chla in trcrn_sw
     438              : 
     439              :         integer (kind=int_kind), dimension(:), intent(in), optional :: &
     440              :              bio_index_o_in, &
     441              :              bio_index_in
     442              : 
     443              :         integer (kind=int_kind), dimension(:), intent(in), optional :: &
     444              :              nt_bgc_N_in ,  & ! diatoms, phaeocystis, pico/small
     445              :              nt_bgc_C_in ,  & ! diatoms, phaeocystis, pico/small
     446              :              nt_bgc_chl_in, & ! diatoms, phaeocystis, pico/small
     447              :              nlt_bgc_N_in , & ! diatoms, phaeocystis, pico/small
     448              :              nlt_bgc_C_in , & ! diatoms, phaeocystis, pico/small
     449              :              nlt_bgc_chl_in   ! diatoms, phaeocystis, pico/small
     450              : 
     451              :         integer (kind=int_kind), dimension(:), intent(in), optional :: &
     452              :              nt_bgc_DOC_in, & !  dissolved organic carbon
     453              :              nlt_bgc_DOC_in   !  dissolved organic carbon
     454              : 
     455              :         integer (kind=int_kind), dimension(:), intent(in), optional :: &
     456              :              nt_bgc_DON_in, & !  dissolved organic nitrogen
     457              :              nlt_bgc_DON_in   !  dissolved organic nitrogen
     458              : 
     459              :         integer (kind=int_kind), dimension(:), intent(in), optional :: &
     460              :              nt_bgc_DIC_in, & ! dissolved inorganic carbon
     461              :              nlt_bgc_DIC_in   !  dissolved inorganic carbon
     462              : 
     463              :         integer (kind=int_kind), dimension(:), intent(in), optional :: &
     464              :              nt_bgc_Fed_in, & !  dissolved iron
     465              :              nt_bgc_Fep_in, & !  particulate iron
     466              :              nlt_bgc_Fed_in,& !  dissolved iron
     467              :              nlt_bgc_Fep_in   !  particulate iron
     468              : 
     469              :         integer (kind=int_kind), dimension(:), intent(in), optional :: &
     470              :              nt_zaero_in,   & !  black carbon and other aerosols
     471              :              nlt_zaero_in,  & !  black carbon and other aerosols
     472              :              nlt_zaero_sw_in  ! black carbon and dust in trcrn_sw
     473              : 
     474              : !autodocument_end
     475              : 
     476              :         ! local
     477              :         integer (kind=int_kind) :: nsiz
     478              :         character(len=*),parameter :: subname='(icepack_init_tracer_indices)'
     479              : 
     480          166 :         if (present(nt_Tsfc_in)) nt_Tsfc = nt_Tsfc_in
     481          166 :         if (present(nt_qice_in)) nt_qice = nt_qice_in
     482          166 :         if (present(nt_qsno_in)) nt_qsno = nt_qsno_in
     483          166 :         if (present(nt_sice_in)) nt_sice = nt_sice_in
     484          166 :         if (present(nt_fbri_in)) nt_fbri = nt_fbri_in
     485          166 :         if (present(nt_iage_in)) nt_iage = nt_iage_in
     486          166 :         if (present(nt_FY_in)  ) nt_FY   = nt_FY_in
     487          166 :         if (present(nt_alvl_in)) nt_alvl = nt_alvl_in
     488          166 :         if (present(nt_vlvl_in)) nt_vlvl = nt_vlvl_in
     489          166 :         if (present(nt_apnd_in)) nt_apnd = nt_apnd_in
     490          166 :         if (present(nt_hpnd_in)) nt_hpnd = nt_hpnd_in
     491          166 :         if (present(nt_ipnd_in)) nt_ipnd = nt_ipnd_in
     492          166 :         if (present(nt_fsd_in) ) nt_fsd  = nt_fsd_in
     493          166 :         if (present(nt_smice_in)     ) nt_smice      = nt_smice_in
     494          166 :         if (present(nt_smliq_in)     ) nt_smliq      = nt_smliq_in
     495          166 :         if (present(nt_rhos_in)      ) nt_rhos       = nt_rhos_in
     496          166 :         if (present(nt_rsnw_in)      ) nt_rsnw       = nt_rsnw_in
     497          166 :         if (present(nt_isosno_in)    ) nt_isosno     = nt_isosno_in
     498          166 :         if (present(nt_isoice_in)    ) nt_isoice     = nt_isoice_in
     499          166 :         if (present(nt_aero_in)      ) nt_aero       = nt_aero_in
     500          166 :         if (present(nt_bgc_Nit_in)   ) nt_bgc_Nit    = nt_bgc_Nit_in
     501          166 :         if (present(nt_bgc_Am_in)    ) nt_bgc_Am     = nt_bgc_Am_in
     502          166 :         if (present(nt_bgc_Sil_in)   ) nt_bgc_Sil    = nt_bgc_Sil_in
     503          166 :         if (present(nt_bgc_DMSPp_in) ) nt_bgc_DMSPp  = nt_bgc_DMSPp_in
     504          166 :         if (present(nt_bgc_DMSPd_in) ) nt_bgc_DMSPd  = nt_bgc_DMSPd_in
     505          166 :         if (present(nt_bgc_DMS_in)   ) nt_bgc_DMS    = nt_bgc_DMS_in
     506          166 :         if (present(nt_bgc_hum_in)   ) nt_bgc_hum    = nt_bgc_hum_in
     507          166 :         if (present(nt_bgc_PON_in)   ) nt_bgc_PON    = nt_bgc_PON_in
     508          166 :         if (present(nlt_bgc_Nit_in)  ) nlt_bgc_Nit   = nlt_bgc_Nit_in
     509          166 :         if (present(nlt_bgc_Am_in)   ) nlt_bgc_Am    = nlt_bgc_Am_in
     510          166 :         if (present(nlt_bgc_Sil_in)  ) nlt_bgc_Sil   = nlt_bgc_Sil_in
     511          166 :         if (present(nlt_bgc_DMSPp_in)) nlt_bgc_DMSPp = nlt_bgc_DMSPp_in
     512          166 :         if (present(nlt_bgc_DMSPd_in)) nlt_bgc_DMSPd = nlt_bgc_DMSPd_in
     513          166 :         if (present(nlt_bgc_DMS_in)  ) nlt_bgc_DMS   = nlt_bgc_DMS_in
     514          166 :         if (present(nlt_bgc_hum_in)  ) nlt_bgc_hum   = nlt_bgc_hum_in
     515          166 :         if (present(nlt_bgc_PON_in)  ) nlt_bgc_PON   = nlt_bgc_PON_in
     516          166 :         if (present(nlt_chl_sw_in)   ) nlt_chl_sw    = nlt_chl_sw_in
     517          166 :         if (present(nt_zbgc_frac_in) ) nt_zbgc_frac  = nt_zbgc_frac_in
     518          166 :         if (present(nt_bgc_S_in)     ) nt_bgc_S      = nt_bgc_S_in
     519              : 
     520          166 :         if (present(bio_index_in)) then
     521           83 :            nsiz = size(bio_index_in)
     522           83 :            if (size(bio_index) < nsiz) then
     523            0 :               call icepack_warnings_add(subname//'error in bio_index size')
     524            0 :               call icepack_warnings_setabort(.true.,__FILE__,__LINE__)
     525              :            else
     526         2490 :               bio_index(1:nsiz) = bio_index_in(1:nsiz)
     527              :            endif
     528              :         endif
     529              : 
     530          166 :         if (present(bio_index_o_in)) then
     531           83 :            nsiz = size(bio_index_o_in)
     532           83 :            if (size(bio_index_o) < nsiz) then
     533            0 :               call icepack_warnings_add(subname//'error in bio_index_o size')
     534            0 :               call icepack_warnings_setabort(.true.,__FILE__,__LINE__)
     535              :            else
     536         2490 :               bio_index_o(1:nsiz) = bio_index_o_in(1:nsiz)
     537              :            endif
     538              :         endif
     539              : 
     540          166 :         if (present(nt_bgc_N_in)) then
     541           83 :            nsiz = size(nt_bgc_N_in)
     542           83 :            if (size(nt_bgc_N) < nsiz) then
     543            0 :               call icepack_warnings_add(subname//'error in nt_bgc_N size')
     544            0 :               call icepack_warnings_setabort(.true.,__FILE__,__LINE__)
     545              :            else
     546          332 :               nt_bgc_N(1:nsiz) = nt_bgc_N_in(1:nsiz)
     547              :            endif
     548              :         endif
     549              : 
     550          166 :         if (present(nlt_bgc_N_in)) then
     551           83 :            nsiz = size(nlt_bgc_N_in)
     552           83 :            if (size(nlt_bgc_N) < nsiz) then
     553            0 :               call icepack_warnings_add(subname//'error in nlt_bgc_N size')
     554            0 :               call icepack_warnings_setabort(.true.,__FILE__,__LINE__)
     555              :            else
     556          332 :               nlt_bgc_N(1:nsiz) = nlt_bgc_N_in(1:nsiz)
     557              :            endif
     558              :         endif
     559              : 
     560          166 :         if (present(nt_bgc_chl_in)) then
     561           83 :            nsiz = size(nt_bgc_chl_in)
     562           83 :            if (size(nt_bgc_chl) < nsiz) then
     563            0 :               call icepack_warnings_add(subname//'error in nt_bgc_chl size')
     564            0 :               call icepack_warnings_setabort(.true.,__FILE__,__LINE__)
     565              :            else
     566          332 :               nt_bgc_chl(1:nsiz) = nt_bgc_chl_in(1:nsiz)
     567              :            endif
     568              :         endif
     569              : 
     570          166 :         if (present(nlt_bgc_chl_in)) then
     571           83 :            nsiz = size(nlt_bgc_chl_in)
     572           83 :            if (size(nlt_bgc_chl) < nsiz) then
     573            0 :               call icepack_warnings_add(subname//'error in nlt_bgc_chl size')
     574            0 :               call icepack_warnings_setabort(.true.,__FILE__,__LINE__)
     575              :            else
     576          332 :               nlt_bgc_chl(1:nsiz) = nlt_bgc_chl_in(1:nsiz)
     577              :            endif
     578              :         endif
     579              : 
     580              : ! algal C is not yet distinct from algal N
     581          166 :         if (present(nt_bgc_C_in) .or. present(nlt_bgc_C_in)) then
     582            0 :            call icepack_warnings_add(subname//'error bgc_C not supported')
     583            0 :            call icepack_warnings_setabort(.true.,__FILE__,__LINE__)
     584              :         endif
     585              : 
     586              : !        if (present(nt_bgc_C_in)) then
     587              : !           nsiz = size(nt_bgc_C_in)
     588              : !           if (size(nt_bgc_C) < nsiz) then
     589              : !              call icepack_warnings_add(subname//'error in nt_bgc_C size')
     590              : !              call icepack_warnings_setabort(.true.,__FILE__,__LINE__)
     591              : !           else
     592              : !              nt_bgc_C(1:nsiz) = nt_bgc_C_in(1:nsiz)
     593              : !           endif
     594              : !        endif
     595              : 
     596              : !        if (present(nlt_bgc_C_in)) then
     597              : !           nsiz = size(nlt_bgc_C_in)
     598              : !           if (size(nlt_bgc_C) < nsiz) then
     599              : !              call icepack_warnings_add(subname//'error in nlt_bgc_C size')
     600              : !              call icepack_warnings_setabort(.true.,__FILE__,__LINE__)
     601              : !           else
     602              : !              nlt_bgc_C(1:nsiz) = nlt_bgc_C_in(1:nsiz)
     603              : !           endif
     604              : !        endif
     605              : 
     606          166 :         if (present(nt_bgc_DOC_in)) then
     607           83 :            nsiz = size(nt_bgc_DOC_in)
     608           83 :            if (size(nt_bgc_DOC) < nsiz) then
     609            0 :               call icepack_warnings_add(subname//'error in nt_bgc_DOC size')
     610            0 :               call icepack_warnings_setabort(.true.,__FILE__,__LINE__)
     611              :            else
     612          332 :               nt_bgc_DOC(1:nsiz) = nt_bgc_DOC_in(1:nsiz)
     613              :            endif
     614              :         endif
     615              : 
     616          166 :         if (present(nlt_bgc_DOC_in)) then
     617           83 :            nsiz = size(nlt_bgc_DOC_in)
     618           83 :            if (size(nlt_bgc_DOC) < nsiz) then
     619            0 :               call icepack_warnings_add(subname//'error in nlt_bgc_DOC size')
     620            0 :               call icepack_warnings_setabort(.true.,__FILE__,__LINE__)
     621              :            else
     622          332 :               nlt_bgc_DOC(1:nsiz) = nlt_bgc_DOC_in(1:nsiz)
     623              :            endif
     624              :         endif
     625              : 
     626          166 :         if (present(nt_bgc_DON_in)) then
     627           83 :            nsiz = size(nt_bgc_DON_in)
     628           83 :            if (size(nt_bgc_DON) < nsiz) then
     629            0 :               call icepack_warnings_add(subname//'error in nt_bgc_DON size')
     630            0 :               call icepack_warnings_setabort(.true.,__FILE__,__LINE__)
     631              :            else
     632          166 :               nt_bgc_DON(1:nsiz) = nt_bgc_DON_in(1:nsiz)
     633              :            endif
     634              :         endif
     635              : 
     636          166 :         if (present(nlt_bgc_DON_in)) then
     637           83 :            nsiz = size(nlt_bgc_DON_in)
     638           83 :            if (size(nlt_bgc_DON) < nsiz) then
     639            0 :               call icepack_warnings_add(subname//'error in nlt_bgc_DON size')
     640            0 :               call icepack_warnings_setabort(.true.,__FILE__,__LINE__)
     641              :            else
     642          166 :               nlt_bgc_DON(1:nsiz) = nlt_bgc_DON_in(1:nsiz)
     643              :            endif
     644              :         endif
     645              : 
     646          166 :         if (present(nt_bgc_DIC_in)) then
     647           83 :            nsiz = size(nt_bgc_DIC_in)
     648           83 :            if (size(nt_bgc_DIC) < nsiz) then
     649            0 :               call icepack_warnings_add(subname//'error in nt_bgc_DIC size')
     650            0 :               call icepack_warnings_setabort(.true.,__FILE__,__LINE__)
     651              :            else
     652          166 :               nt_bgc_DIC(1:nsiz) = nt_bgc_DIC_in(1:nsiz)
     653              :            endif
     654              :         endif
     655              : 
     656          166 :         if (present(nlt_bgc_DIC_in)) then
     657           83 :            nsiz = size(nlt_bgc_DIC_in)
     658           83 :            if (size(nlt_bgc_DIC) < nsiz) then
     659            0 :               call icepack_warnings_add(subname//'error in nlt_bgc_DIC size')
     660            0 :               call icepack_warnings_setabort(.true.,__FILE__,__LINE__)
     661              :            else
     662          166 :               nlt_bgc_DIC(1:nsiz) = nlt_bgc_DIC_in(1:nsiz)
     663              :            endif
     664              :         endif
     665              : 
     666          166 :         if (present(nt_bgc_Fed_in)) then
     667           83 :            nsiz = size(nt_bgc_Fed_in)
     668           83 :            if (size(nt_bgc_Fed) < nsiz) then
     669            0 :               call icepack_warnings_add(subname//'error in nt_bgc_Fed size')
     670            0 :               call icepack_warnings_setabort(.true.,__FILE__,__LINE__)
     671              :            else
     672          249 :               nt_bgc_Fed(1:nsiz) = nt_bgc_Fed_in(1:nsiz)
     673              :            endif
     674              :         endif
     675              : 
     676          166 :         if (present(nlt_bgc_Fed_in)) then
     677           83 :            nsiz = size(nlt_bgc_Fed_in)
     678           83 :            if (size(nlt_bgc_Fed) < nsiz) then
     679            0 :               call icepack_warnings_add(subname//'error in nlt_bgc_Fed size')
     680            0 :               call icepack_warnings_setabort(.true.,__FILE__,__LINE__)
     681              :            else
     682          249 :               nlt_bgc_Fed(1:nsiz) = nlt_bgc_Fed_in(1:nsiz)
     683              :            endif
     684              :         endif
     685              : 
     686          166 :         if (present(nt_bgc_Fep_in)) then
     687           83 :            nsiz = size(nt_bgc_Fep_in)
     688           83 :            if (size(nt_bgc_Fep) < nsiz) then
     689            0 :               call icepack_warnings_add(subname//'error in nt_bgc_Fep size')
     690            0 :               call icepack_warnings_setabort(.true.,__FILE__,__LINE__)
     691              :            else
     692          249 :               nt_bgc_Fep(1:nsiz) = nt_bgc_Fep_in(1:nsiz)
     693              :            endif
     694              :         endif
     695              : 
     696          166 :         if (present(nlt_bgc_Fep_in)) then
     697           83 :            nsiz = size(nlt_bgc_Fep_in)
     698           83 :            if (size(nlt_bgc_Fep) < nsiz) then
     699            0 :               call icepack_warnings_add(subname//'error in nlt_bgc_Fep size')
     700            0 :               call icepack_warnings_setabort(.true.,__FILE__,__LINE__)
     701              :            else
     702          249 :               nlt_bgc_Fep(1:nsiz) = nlt_bgc_Fep_in(1:nsiz)
     703              :            endif
     704              :         endif
     705              : 
     706          166 :         if (present(nt_zaero_in)) then
     707           83 :            nsiz = size(nt_zaero_in)
     708           83 :            if (size(nt_zaero) < nsiz) then
     709            0 :               call icepack_warnings_add(subname//'error in nt_zaero size')
     710            0 :               call icepack_warnings_setabort(.true.,__FILE__,__LINE__)
     711              :            else
     712          581 :               nt_zaero(1:nsiz) = nt_zaero_in(1:nsiz)
     713              :            endif
     714              :         endif
     715              : 
     716          166 :         if (present(nlt_zaero_in)) then
     717           83 :            nsiz = size(nlt_zaero_in)
     718           83 :            if (size(nlt_zaero) < nsiz) then
     719            0 :               call icepack_warnings_add(subname//'error in nlt_zaero size')
     720            0 :               call icepack_warnings_setabort(.true.,__FILE__,__LINE__)
     721              :            else
     722          581 :               nlt_zaero(1:nsiz) = nlt_zaero_in(1:nsiz)
     723              :            endif
     724              :         endif
     725              : 
     726          166 :         if (present(nlt_zaero_sw_in)) then
     727           83 :            nsiz = size(nlt_zaero_sw_in)
     728           83 :            if (size(nlt_zaero_sw) < nsiz) then
     729            0 :               call icepack_warnings_add(subname//'error in nlt_zaero_sw size')
     730            0 :               call icepack_warnings_setabort(.true.,__FILE__,__LINE__)
     731              :            else
     732          581 :               nlt_zaero_sw(1:nsiz) = nlt_zaero_sw_in(1:nsiz)
     733              :            endif
     734              :         endif
     735              : 
     736          166 :       end subroutine icepack_init_tracer_indices
     737              : 
     738              : !=======================================================================
     739              : !autodocument_start icepack_query_tracer_indices
     740              : ! query the number of column tracer indices
     741              : 
     742      6502016 :       subroutine icepack_query_tracer_indices(&
     743              :            nt_Tsfc_out, nt_qice_out, nt_qsno_out, nt_sice_out, &
     744              :            nt_fbri_out, nt_iage_out, nt_FY_out, &
     745              :            nt_alvl_out, nt_vlvl_out, nt_apnd_out, nt_hpnd_out, nt_ipnd_out, &
     746              :            nt_smice_out, nt_smliq_out, nt_rhos_out, nt_rsnw_out, &
     747              :            nt_fsd_out, nt_isosno_out, nt_isoice_out, &
     748     13004032 :            nt_aero_out, nt_zaero_out, nt_bgc_C_out, &
     749     26008064 :            nt_bgc_N_out, nt_bgc_chl_out, nt_bgc_DOC_out, nt_bgc_DON_out, &
     750     19506048 :            nt_bgc_DIC_out, nt_bgc_Fed_out, nt_bgc_Fep_out, nt_bgc_Nit_out, nt_bgc_Am_out, &
     751              :            nt_bgc_Sil_out, nt_bgc_DMSPp_out, nt_bgc_DMSPd_out, nt_bgc_DMS_out, nt_bgc_hum_out, &
     752     26008064 :            nt_bgc_PON_out, nlt_zaero_out, nlt_bgc_C_out, nlt_bgc_N_out, nlt_bgc_chl_out, &
     753     26008064 :            nlt_bgc_DOC_out, nlt_bgc_DON_out, nlt_bgc_DIC_out, nlt_bgc_Fed_out, &
     754      6502016 :            nlt_bgc_Fep_out, nlt_bgc_Nit_out, nlt_bgc_Am_out, nlt_bgc_Sil_out, &
     755              :            nlt_bgc_DMSPp_out, nlt_bgc_DMSPd_out, nlt_bgc_DMS_out, nlt_bgc_hum_out, &
     756              :            nlt_bgc_PON_out, nt_zbgc_frac_out, nt_bgc_S_out, nlt_chl_sw_out, &
     757      6502016 :            nlt_zaero_sw_out, &
     758      6502016 :            bio_index_o_out, bio_index_out)
     759              : 
     760              :         integer, intent(out), optional :: &
     761              :              nt_Tsfc_out, & ! ice/snow temperature
     762              :              nt_qice_out, & ! volume-weighted ice enthalpy (in layers)
     763              :              nt_qsno_out, & ! volume-weighted snow enthalpy (in layers)
     764              :              nt_sice_out, & ! volume-weighted ice bulk salinity (CICE grid layers)
     765              :              nt_fbri_out, & ! volume fraction of ice with dynamic salt (hinS/vicen*aicen)
     766              :              nt_iage_out, & ! volume-weighted ice age
     767              :              nt_FY_out, & ! area-weighted first-year ice area
     768              :              nt_alvl_out, & ! level ice area fraction
     769              :              nt_vlvl_out, & ! level ice volume fraction
     770              :              nt_apnd_out, & ! melt pond area fraction
     771              :              nt_hpnd_out, & ! melt pond depth
     772              :              nt_ipnd_out, & ! melt pond refrozen lid thickness
     773              :              nt_smice_out,& ! mass of ice in snow
     774              :              nt_smliq_out,& ! mass of liquid water in snow
     775              :              nt_rhos_out, & ! snow density
     776              :              nt_rsnw_out, & ! snow grain radius
     777              :              nt_fsd_out,  & ! floe size distribution
     778              :              nt_isosno_out,  & ! starting index for isotopes in snow
     779              :              nt_isoice_out,  & ! starting index for isotopes in ice
     780              :              nt_aero_out,    & ! starting index for aerosols in ice
     781              :              nt_bgc_Nit_out, & ! nutrients
     782              :              nt_bgc_Am_out,  & !
     783              :              nt_bgc_Sil_out, & !
     784              :              nt_bgc_DMSPp_out,&! trace gases (skeletal layer)
     785              :              nt_bgc_DMSPd_out,&!
     786              :              nt_bgc_DMS_out, & !
     787              :              nt_bgc_hum_out, & !
     788              :              nt_bgc_PON_out, & ! zooplankton and detritus
     789              :              nlt_bgc_Nit_out,& ! nutrients
     790              :              nlt_bgc_Am_out, & !
     791              :              nlt_bgc_Sil_out,& !
     792              :              nlt_bgc_DMSPp_out,&! trace gases (skeletal layer)
     793              :              nlt_bgc_DMSPd_out,&!
     794              :              nlt_bgc_DMS_out,& !
     795              :              nlt_bgc_hum_out,& !
     796              :              nlt_bgc_PON_out,& ! zooplankton and detritus
     797              :              nt_zbgc_frac_out,&! fraction of tracer in the mobile phase
     798              :              nt_bgc_S_out,   & ! (deprecated, was related to zsalinity)
     799              :              nlt_chl_sw_out    ! points to total chla in trcrn_sw
     800              : 
     801              :         integer (kind=int_kind), dimension(:), intent(out), optional :: &
     802              :              bio_index_o_out, &
     803              :              bio_index_out
     804              : 
     805              :         integer (kind=int_kind), dimension(:), intent(out), optional :: &
     806              :              nt_bgc_N_out ,  & ! diatoms, phaeocystis, pico/small
     807              :              nt_bgc_C_out ,  & ! diatoms, phaeocystis, pico/small
     808              :              nt_bgc_chl_out, & ! diatoms, phaeocystis, pico/small
     809              :              nlt_bgc_N_out , & ! diatoms, phaeocystis, pico/small
     810              :              nlt_bgc_C_out , & ! diatoms, phaeocystis, pico/small
     811              :              nlt_bgc_chl_out   ! diatoms, phaeocystis, pico/small
     812              : 
     813              :         integer (kind=int_kind), dimension(:), intent(out), optional :: &
     814              :              nt_bgc_DOC_out, & !  dissolved organic carbon
     815              :              nlt_bgc_DOC_out   !  dissolved organic carbon
     816              : 
     817              :         integer (kind=int_kind), dimension(:), intent(out), optional :: &
     818              :              nt_bgc_DON_out, & !  dissolved organic nitrogen
     819              :              nlt_bgc_DON_out   !  dissolved organic nitrogen
     820              : 
     821              :         integer (kind=int_kind), dimension(:), intent(out), optional :: &
     822              :              nt_bgc_DIC_out, & ! dissolved inorganic carbon
     823              :              nlt_bgc_DIC_out   !  dissolved inorganic carbon
     824              : 
     825              :         integer (kind=int_kind), dimension(:), intent(out), optional :: &
     826              :              nt_bgc_Fed_out, & !  dissolved iron
     827              :              nt_bgc_Fep_out, & !  particulate iron
     828              :              nlt_bgc_Fed_out,& !  dissolved iron
     829              :              nlt_bgc_Fep_out   !  particulate iron
     830              : 
     831              :         integer (kind=int_kind), dimension(:), intent(out), optional :: &
     832              :              nt_zaero_out,   & !  black carbon and other aerosols
     833              :              nlt_zaero_out,  & !  black carbon and other aerosols
     834              :              nlt_zaero_sw_out  ! black carbon and dust in trcrn_sw
     835              : 
     836              : !autodocument_end
     837              : 
     838              :         character(len=*),parameter :: subname='(icepack_query_tracer_indices)'
     839              : 
     840      6502016 :         if (present(nt_Tsfc_out)) nt_Tsfc_out = nt_Tsfc
     841      6502016 :         if (present(nt_qice_out)) nt_qice_out = nt_qice
     842      6502016 :         if (present(nt_qsno_out)) nt_qsno_out = nt_qsno
     843      6502016 :         if (present(nt_sice_out)) nt_sice_out = nt_sice
     844      6502016 :         if (present(nt_fbri_out)) nt_fbri_out = nt_fbri
     845      6502016 :         if (present(nt_iage_out)) nt_iage_out = nt_iage
     846      6502016 :         if (present(nt_FY_out)  ) nt_FY_out   = nt_FY
     847      6502016 :         if (present(nt_alvl_out)) nt_alvl_out = nt_alvl
     848      6502016 :         if (present(nt_vlvl_out)) nt_vlvl_out = nt_vlvl
     849      6502016 :         if (present(nt_apnd_out)) nt_apnd_out = nt_apnd
     850      6502016 :         if (present(nt_hpnd_out)) nt_hpnd_out = nt_hpnd
     851      6502016 :         if (present(nt_ipnd_out)) nt_ipnd_out = nt_ipnd
     852      6502016 :         if (present(nt_fsd_out) ) nt_fsd_out  = nt_fsd
     853      6502016 :         if (present(nt_smice_out)     ) nt_smice_out      = nt_smice
     854      6502016 :         if (present(nt_smliq_out)     ) nt_smliq_out      = nt_smliq
     855      6502016 :         if (present(nt_rhos_out)      ) nt_rhos_out       = nt_rhos
     856      6502016 :         if (present(nt_rsnw_out)      ) nt_rsnw_out       = nt_rsnw
     857      6502016 :         if (present(nt_isosno_out)    ) nt_isosno_out     = nt_isosno
     858      6502016 :         if (present(nt_isoice_out)    ) nt_isoice_out     = nt_isoice
     859      6502016 :         if (present(nt_aero_out)      ) nt_aero_out       = nt_aero
     860      6502016 :         if (present(nt_bgc_Nit_out)   ) nt_bgc_Nit_out    = nt_bgc_Nit
     861      6502016 :         if (present(nt_bgc_Am_out)    ) nt_bgc_Am_out     = nt_bgc_Am
     862      6502016 :         if (present(nt_bgc_Sil_out)   ) nt_bgc_Sil_out    = nt_bgc_Sil
     863      6502016 :         if (present(nt_bgc_DMSPp_out) ) nt_bgc_DMSPp_out  = nt_bgc_DMSPp
     864      6502016 :         if (present(nt_bgc_DMSPd_out) ) nt_bgc_DMSPd_out  = nt_bgc_DMSPd
     865      6502016 :         if (present(nt_bgc_DMS_out)   ) nt_bgc_DMS_out    = nt_bgc_DMS
     866      6502016 :         if (present(nt_bgc_hum_out)   ) nt_bgc_hum_out    = nt_bgc_hum
     867      6502016 :         if (present(nt_bgc_PON_out)   ) nt_bgc_PON_out    = nt_bgc_PON
     868      6502016 :         if (present(nlt_bgc_Nit_out)  ) nlt_bgc_Nit_out   = nlt_bgc_Nit
     869      6502016 :         if (present(nlt_bgc_Am_out)   ) nlt_bgc_Am_out    = nlt_bgc_Am
     870      6502016 :         if (present(nlt_bgc_Sil_out)  ) nlt_bgc_Sil_out   = nlt_bgc_Sil
     871      6502016 :         if (present(nlt_bgc_DMSPp_out)) nlt_bgc_DMSPp_out = nlt_bgc_DMSPp
     872      6502016 :         if (present(nlt_bgc_DMSPd_out)) nlt_bgc_DMSPd_out = nlt_bgc_DMSPd
     873      6502016 :         if (present(nlt_bgc_DMS_out)  ) nlt_bgc_DMS_out   = nlt_bgc_DMS
     874      6502016 :         if (present(nlt_bgc_hum_out)  ) nlt_bgc_hum_out   = nlt_bgc_hum
     875      6502016 :         if (present(nlt_bgc_PON_out)  ) nlt_bgc_PON_out   = nlt_bgc_PON
     876      6502016 :         if (present(nlt_chl_sw_out)   ) nlt_chl_sw_out    = nlt_chl_sw
     877      6502016 :         if (present(nt_zbgc_frac_out) ) nt_zbgc_frac_out  = nt_zbgc_frac
     878      6502016 :         if (present(nt_bgc_S_out)     ) nt_bgc_S_out      = nt_bgc_S
     879              : 
     880      8261852 :         if (present(bio_index_o_out) ) bio_index_o_out  = bio_index_o
     881      6502016 :         if (present(bio_index_out)   ) bio_index_out    = bio_index
     882      8482172 :         if (present(nt_bgc_N_out)    ) nt_bgc_N_out     = nt_bgc_N
     883      6509597 :         if (present(nlt_bgc_N_out)   ) nlt_bgc_N_out    = nlt_bgc_N
     884      6502226 :         if (present(nt_bgc_C_out)    ) nt_bgc_C_out     = nt_bgc_C
     885      6502016 :         if (present(nlt_bgc_C_out)   ) nlt_bgc_C_out    = nlt_bgc_C
     886      6502226 :         if (present(nt_bgc_chl_out)  ) nt_bgc_chl_out   = nt_bgc_chl
     887      6502016 :         if (present(nlt_bgc_chl_out) ) nlt_bgc_chl_out  = nlt_bgc_chl
     888      6509807 :         if (present(nt_bgc_DOC_out)  ) nt_bgc_DOC_out   = nt_bgc_DOC
     889      6509597 :         if (present(nlt_bgc_DOC_out) ) nlt_bgc_DOC_out  = nlt_bgc_DOC
     890      6504613 :         if (present(nt_bgc_DON_out)  ) nt_bgc_DON_out   = nt_bgc_DON
     891      6504543 :         if (present(nlt_bgc_DON_out) ) nlt_bgc_DON_out  = nlt_bgc_DON
     892      6502086 :         if (present(nt_bgc_DIC_out)  ) nt_bgc_DIC_out   = nt_bgc_DIC
     893      6502016 :         if (present(nlt_bgc_DIC_out) ) nlt_bgc_DIC_out  = nlt_bgc_DIC
     894      6507210 :         if (present(nt_bgc_Fed_out)  ) nt_bgc_Fed_out   = nt_bgc_Fed
     895      6507070 :         if (present(nlt_bgc_Fed_out) ) nlt_bgc_Fed_out  = nlt_bgc_Fed
     896      6507210 :         if (present(nt_bgc_Fep_out)  ) nt_bgc_Fep_out   = nt_bgc_Fep
     897      6507070 :         if (present(nlt_bgc_Fep_out) ) nlt_bgc_Fep_out  = nlt_bgc_Fep
     898     10462328 :         if (present(nt_zaero_out)    ) nt_zaero_out     = nt_zaero
     899      6881282 :         if (present(nlt_zaero_out)   ) nlt_zaero_out    = nlt_zaero
     900     10461908 :         if (present(nlt_zaero_sw_out)) nlt_zaero_sw_out = nlt_zaero_sw
     901              : 
     902      6502016 :       end subroutine icepack_query_tracer_indices
     903              : 
     904              : !=======================================================================
     905              : !autodocument_start icepack_write_tracer_indices
     906              : ! write the number of column tracer indices
     907              : 
     908           83 :       subroutine icepack_write_tracer_indices(iounit)
     909              : 
     910              :         integer, intent(in) :: iounit
     911              : 
     912              : !autodocument_end
     913              : 
     914              :         ! local
     915              :         integer (kind=int_kind) :: k
     916              :         character(len=*),parameter :: subname='(icepack_write_tracer_indices)'
     917              : 
     918           83 :         write(iounit,*) subname//":"
     919           83 :         write(iounit,*) "  nt_Tsfc = ",nt_Tsfc
     920           83 :         write(iounit,*) "  nt_qice = ",nt_qice
     921           83 :         write(iounit,*) "  nt_qsno = ",nt_qsno
     922           83 :         write(iounit,*) "  nt_sice = ",nt_sice
     923           83 :         write(iounit,*) "  nt_fbri = ",nt_fbri
     924           83 :         write(iounit,*) "  nt_iage = ",nt_iage
     925           83 :         write(iounit,*) "  nt_FY   = ",nt_FY
     926           83 :         write(iounit,*) "  nt_alvl = ",nt_alvl
     927           83 :         write(iounit,*) "  nt_vlvl = ",nt_vlvl
     928           83 :         write(iounit,*) "  nt_apnd = ",nt_apnd
     929           83 :         write(iounit,*) "  nt_hpnd = ",nt_hpnd
     930           83 :         write(iounit,*) "  nt_ipnd = ",nt_ipnd
     931           83 :         write(iounit,*) "  nt_fsd  = ",nt_fsd
     932           83 :         write(iounit,*) "  nt_smice      = ",nt_smice
     933           83 :         write(iounit,*) "  nt_smliq      = ",nt_smliq
     934           83 :         write(iounit,*) "  nt_rhos       = ",nt_rhos
     935           83 :         write(iounit,*) "  nt_rsnw       = ",nt_rsnw
     936           83 :         write(iounit,*) "  nt_isosno     = ",nt_isosno
     937           83 :         write(iounit,*) "  nt_isoice     = ",nt_isoice
     938           83 :         write(iounit,*) "  nt_aero       = ",nt_aero
     939           83 :         write(iounit,*) "  nt_bgc_Nit    = ",nt_bgc_Nit
     940           83 :         write(iounit,*) "  nt_bgc_Am     = ",nt_bgc_Am
     941           83 :         write(iounit,*) "  nt_bgc_Sil    = ",nt_bgc_Sil
     942           83 :         write(iounit,*) "  nt_bgc_DMSPp  = ",nt_bgc_DMSPp
     943           83 :         write(iounit,*) "  nt_bgc_DMSPd  = ",nt_bgc_DMSPd
     944           83 :         write(iounit,*) "  nt_bgc_DMS    = ",nt_bgc_DMS
     945           83 :         write(iounit,*) "  nt_bgc_hum    = ",nt_bgc_hum
     946           83 :         write(iounit,*) "  nt_bgc_PON    = ",nt_bgc_PON
     947           83 :         write(iounit,*) "  nlt_bgc_Nit   = ",nlt_bgc_Nit
     948           83 :         write(iounit,*) "  nlt_bgc_Am    = ",nlt_bgc_Am
     949           83 :         write(iounit,*) "  nlt_bgc_Sil   = ",nlt_bgc_Sil
     950           83 :         write(iounit,*) "  nlt_bgc_DMSPp = ",nlt_bgc_DMSPp
     951           83 :         write(iounit,*) "  nlt_bgc_DMSPd = ",nlt_bgc_DMSPd
     952           83 :         write(iounit,*) "  nlt_bgc_DMS   = ",nlt_bgc_DMS
     953           83 :         write(iounit,*) "  nlt_bgc_hum   = ",nlt_bgc_hum
     954           83 :         write(iounit,*) "  nlt_bgc_PON   = ",nlt_bgc_PON
     955           83 :         write(iounit,*) "  nlt_chl_sw    = ",nlt_chl_sw
     956           83 :         write(iounit,*) "  nt_zbgc_frac  = ",nt_zbgc_frac
     957           83 :         write(iounit,*) "  nt_bgc_S      = ",nt_bgc_S," (deprecated)"
     958              : 
     959           83 :         write(iounit,*) "  max_nbtrcr = ",max_nbtrcr
     960         2490 :         do k = 1, max_nbtrcr
     961         2407 :            write(iounit,*) "  bio_index_o(k) = ",k,bio_index_o(k)
     962         2490 :            write(iounit,*) "  bio_index(k)   = ",k,bio_index(k)
     963              :         enddo
     964              : 
     965           83 :         write(iounit,*) "  max_algae = ",max_algae
     966          332 :         do k = 1, max_algae
     967          249 :            write(iounit,*) "  nt_bgc_N(k)  = ",k,nt_bgc_N(k)
     968          249 :            write(iounit,*) "  nlt_bgc_N(k) = ",k,nlt_bgc_N(k)
     969          249 :            write(iounit,*) "  nt_bgc_C(k)  = ",k,nt_bgc_C(k)
     970          249 :            write(iounit,*) "  nlt_bgc_C(k) = ",k,nlt_bgc_C(k)
     971          249 :            write(iounit,*) "  nt_bgc_chl(k)  = ",k,nt_bgc_chl(k)
     972          332 :            write(iounit,*) "  nlt_bgc_chl(k) = ",k,nlt_bgc_chl(k)
     973              :         enddo
     974              : 
     975           83 :         write(iounit,*) "  max_DOC = ",max_DOC
     976          332 :         do k = 1, max_DOC
     977          249 :            write(iounit,*) "  nt_bgc_DOC(k)  = ",k,nt_bgc_DOC(k)
     978          332 :            write(iounit,*) "  nlt_bgc_DOC(k) = ",k,nlt_bgc_DOC(k)
     979              :         enddo
     980              : 
     981           83 :         write(iounit,*) "  max_DON = ",max_DON
     982          166 :         do k = 1, max_DON
     983           83 :            write(iounit,*) "  nt_bgc_DON(k)  = ",k,nt_bgc_DON(k)
     984          166 :            write(iounit,*) "  nlt_bgc_DON(k) = ",k,nlt_bgc_DON(k)
     985              :         enddo
     986              : 
     987           83 :         write(iounit,*) "  max_DIC = ",max_DIC
     988          166 :         do k = 1, max_DIC
     989           83 :            write(iounit,*) "  nt_bgc_DIC(k)  = ",k,nt_bgc_DIC(k)
     990          166 :            write(iounit,*) "  nlt_bgc_DIC(k) = ",k,nlt_bgc_DIC(k)
     991              :         enddo
     992              : 
     993           83 :         write(iounit,*) "  max_fe = ",max_fe
     994          249 :         do k = 1, max_fe
     995          166 :            write(iounit,*) "  nt_bgc_Fed(k)  = ",k,nt_bgc_Fed(k)
     996          166 :            write(iounit,*) "  nlt_bgc_Fed(k) = ",k,nlt_bgc_Fed(k)
     997          166 :            write(iounit,*) "  nt_bgc_Fep(k)  = ",k,nt_bgc_Fep(k)
     998          249 :            write(iounit,*) "  nlt_bgc_Fep(k) = ",k,nlt_bgc_Fep(k)
     999              :         enddo
    1000              : 
    1001           83 :         write(iounit,*) "  max_aero = ",max_aero
    1002          581 :         do k = 1, max_aero
    1003          498 :            write(iounit,*) "  nt_zaero(k)     = ",k,nt_zaero(k)
    1004          498 :            write(iounit,*) "  nlt_zaero(k)    = ",k,nlt_zaero(k)
    1005          581 :            write(iounit,*) "  nlt_zaero_sw(k) = ",k,nlt_zaero_sw(k)
    1006              :         enddo
    1007              : 
    1008           83 :       end subroutine icepack_write_tracer_indices
    1009              : 
    1010              : !=======================================================================
    1011              : !autodocument_start icepack_init_tracer_sizes
    1012              : ! set the number of column tracers
    1013              : 
    1014          166 :       subroutine icepack_init_tracer_sizes(&
    1015              :          ncat_in, nilyr_in, nslyr_in, nblyr_in, nfsd_in  , &
    1016              :          n_algae_in, n_DOC_in, n_aero_in, n_iso_in, &
    1017              :          n_DON_in, n_DIC_in, n_fed_in, n_fep_in, n_zaero_in, &
    1018              :          ntrcr_in, ntrcr_o_in, nbtrcr_in, nbtrcr_sw_in)
    1019              : 
    1020              :       integer (kind=int_kind), intent(in), optional :: &
    1021              :          ncat_in   , & ! Categories
    1022              :          nfsd_in   , & !
    1023              :          nilyr_in  , & ! Layers
    1024              :          nslyr_in  , & !
    1025              :          nblyr_in  , & !
    1026              :          n_algae_in, & ! Dimensions
    1027              :          n_DOC_in  , & !
    1028              :          n_DON_in  , & !
    1029              :          n_DIC_in  , & !
    1030              :          n_fed_in  , & !
    1031              :          n_fep_in  , & !
    1032              :          n_zaero_in, & !
    1033              :          n_iso_in  , & !
    1034              :          n_aero_in , & !
    1035              :          ntrcr_in  , & ! number of tracers in use
    1036              :          ntrcr_o_in, & ! number of non-bio tracers in use
    1037              :          nbtrcr_in , & ! number of bio tracers in use
    1038              :          nbtrcr_sw_in  ! number of shortwave bio tracers in use
    1039              : 
    1040              : !autodocument_end
    1041              : 
    1042              :         character(len=*),parameter :: subname='(icepack_init_tracer_sizes)'
    1043              : 
    1044          166 :         if (present(ncat_in)     ) ncat      = ncat_in
    1045          166 :         if (present(nilyr_in)    ) nilyr     = nilyr_in
    1046          166 :         if (present(nslyr_in)    ) nslyr     = nslyr_in
    1047          166 :         if (present(nblyr_in)    ) nblyr     = nblyr_in
    1048          166 :         if (present(nfsd_in)     ) nfsd      = nfsd_in
    1049              : 
    1050          166 :         if (present(n_algae_in)  ) n_algae   = n_algae_in
    1051          166 :         if (present(n_DOC_in)    ) n_DOC     = n_DOC_in
    1052          166 :         if (present(n_DON_in)    ) n_DON     = n_DON_in
    1053          166 :         if (present(n_DIC_in)    ) n_DIC     = n_DIC_in
    1054          166 :         if (present(n_fed_in)    ) n_fed     = n_fed_in
    1055          166 :         if (present(n_fep_in)    ) n_fep     = n_fep_in
    1056          166 :         if (present(n_zaero_in)  ) n_zaero   = n_zaero_in
    1057          166 :         if (present(n_iso_in)    ) n_iso     = n_iso_in
    1058          166 :         if (present(n_aero_in)   ) n_aero    = n_aero_in
    1059              : 
    1060          166 :         if (present(ntrcr_in)    ) ntrcr     = ntrcr_in
    1061          166 :         if (present(ntrcr_o_in)  ) ntrcr_o   = ntrcr_o_in
    1062          166 :         if (present(nbtrcr_in)   ) nbtrcr    = nbtrcr_in
    1063          166 :         if (present(nbtrcr_sw_in)) nbtrcr_sw = nbtrcr_sw_in
    1064              : 
    1065          166 :       end subroutine icepack_init_tracer_sizes
    1066              : 
    1067              : !=======================================================================
    1068              : !autodocument_start icepack_query_tracer_sizes
    1069              : ! query the number of column tracers
    1070              : 
    1071      5579655 :       subroutine icepack_query_tracer_sizes(&
    1072              :          max_algae_out  , max_dic_out    , max_doc_out      , &
    1073              :          max_don_out    , max_fe_out     , nmodal1_out      , &
    1074              :          nmodal2_out    , max_aero_out   , max_nbtrcr_out   , &
    1075              :          ncat_out, nilyr_out, nslyr_out, nblyr_out, nfsd_out, &
    1076              :          n_algae_out, n_DOC_out, n_aero_out, n_iso_out, &
    1077              :          n_DON_out, n_DIC_out, n_fed_out, n_fep_out, n_zaero_out, &
    1078              :          ntrcr_out, ntrcr_o_out, nbtrcr_out, nbtrcr_sw_out)
    1079              : 
    1080              :       integer (kind=int_kind), intent(out), optional :: &
    1081              :          max_algae_out  , & ! maximum number of algal types
    1082              :          max_dic_out    , & ! maximum number of dissolved inorganic carbon types
    1083              :          max_doc_out    , & ! maximum number of dissolved organic carbon types
    1084              :          max_don_out    , & ! maximum number of dissolved organic nitrogen types
    1085              :          max_fe_out     , & ! maximum number of iron types
    1086              :          nmodal1_out    , & ! dimension for modal aerosol radiation parameters
    1087              :          nmodal2_out    , & ! dimension for modal aerosol radiation parameters
    1088              :          max_aero_out   , & ! maximum number of aerosols
    1089              :          max_nbtrcr_out     ! algal nitrogen and chlorophyll
    1090              : 
    1091              :       integer (kind=int_kind), intent(out), optional :: &
    1092              :          ncat_out   , & ! Categories
    1093              :          nfsd_out   , & !
    1094              :          nilyr_out  , & ! Layers
    1095              :          nslyr_out  , & !
    1096              :          nblyr_out  , & !
    1097              :          n_algae_out, & ! Dimensions
    1098              :          n_DOC_out  , & !
    1099              :          n_DON_out  , & !
    1100              :          n_DIC_out  , & !
    1101              :          n_fed_out  , & !
    1102              :          n_fep_out  , & !
    1103              :          n_zaero_out, & !
    1104              :          n_iso_out  , & !
    1105              :          n_aero_out , & !
    1106              :          ntrcr_out  , & ! number of tracers in use
    1107              :          ntrcr_o_out, & ! number of non-bio tracers in use
    1108              :          nbtrcr_out , & ! number of bio tracers in use
    1109              :          nbtrcr_sw_out  ! number of shortwave bio tracers in use
    1110              : 
    1111              : !autodocument_end
    1112              : 
    1113              :         character(len=*),parameter :: subname='(icepack_query_tracer_sizes)'
    1114              : 
    1115      5579655 :         if (present(max_algae_out))  max_algae_out = max_algae
    1116      5579655 :         if (present(max_dic_out))    max_dic_out   = max_dic
    1117      5579655 :         if (present(max_doc_out))    max_doc_out   = max_doc
    1118      5579655 :         if (present(max_don_out))    max_don_out   = max_don
    1119      5579655 :         if (present(max_fe_out))     max_fe_out    = max_fe
    1120      5579655 :         if (present(nmodal1_out))    nmodal1_out   = nmodal1
    1121      5579655 :         if (present(nmodal2_out))    nmodal2_out   = nmodal2
    1122      5579655 :         if (present(max_aero_out))   max_aero_out  = max_aero
    1123      5579655 :         if (present(max_nbtrcr_out)) max_nbtrcr_out= max_nbtrcr
    1124              : 
    1125      5579655 :         if (present(ncat_out)     ) ncat_out      = ncat
    1126      5579655 :         if (present(nilyr_out)    ) nilyr_out     = nilyr
    1127      5579655 :         if (present(nslyr_out)    ) nslyr_out     = nslyr
    1128      5579655 :         if (present(nblyr_out)    ) nblyr_out     = nblyr
    1129      5579655 :         if (present(nfsd_out)     ) nfsd_out      = nfsd
    1130              : 
    1131      5579655 :         if (present(n_algae_out)  ) n_algae_out   = n_algae
    1132      5579655 :         if (present(n_DOC_out)    ) n_DOC_out     = n_DOC
    1133      5579655 :         if (present(n_DON_out)    ) n_DON_out     = n_DON
    1134      5579655 :         if (present(n_DIC_out)    ) n_DIC_out     = n_DIC
    1135      5579655 :         if (present(n_fed_out)    ) n_fed_out     = n_fed
    1136      5579655 :         if (present(n_fep_out)    ) n_fep_out     = n_fep
    1137      5579655 :         if (present(n_zaero_out)  ) n_zaero_out   = n_zaero
    1138      5579655 :         if (present(n_aero_out)   ) n_aero_out    = n_aero
    1139      5579655 :         if (present(n_iso_out)    ) n_iso_out     = n_iso
    1140              : 
    1141      5579655 :         if (present(ntrcr_out)    ) ntrcr_out     = ntrcr
    1142      5579655 :         if (present(ntrcr_o_out)  ) ntrcr_o_out   = ntrcr_o
    1143      5579655 :         if (present(nbtrcr_out)   ) nbtrcr_out    = nbtrcr
    1144      5579655 :         if (present(nbtrcr_sw_out)) nbtrcr_sw_out = nbtrcr_sw
    1145              : 
    1146      5579655 :       end subroutine icepack_query_tracer_sizes
    1147              : 
    1148              : !=======================================================================
    1149              : !autodocument_start icepack_write_tracer_sizes
    1150              : ! write the number of column tracers
    1151              : 
    1152           83 :       subroutine icepack_write_tracer_sizes(iounit)
    1153              : 
    1154              :       integer (kind=int_kind), intent(in) :: iounit
    1155              : 
    1156              : !autodocument_end
    1157              : 
    1158              :         character(len=*),parameter :: subname='(icepack_write_tracer_sizes)'
    1159              : 
    1160           83 :         write(iounit,*) subname//":"
    1161           83 :         write(iounit,*) "  fixed parameters: "
    1162           83 :         write(iounit,*) "  max_algae_out =", max_algae
    1163           83 :         write(iounit,*) "  max_dic_out   =", max_dic
    1164           83 :         write(iounit,*) "  max_doc_out   =", max_doc
    1165           83 :         write(iounit,*) "  max_don_out   =", max_don
    1166           83 :         write(iounit,*) "  max_fe_out    =", max_fe
    1167           83 :         write(iounit,*) "  nmodal1_out   =", nmodal1
    1168           83 :         write(iounit,*) "  nmodal2_out   =", nmodal2
    1169           83 :         write(iounit,*) "  max_iso_out   =", max_iso
    1170           83 :         write(iounit,*) "  max_aero_out  =", max_aero
    1171           83 :         write(iounit,*) "  max_nbtrcr_out=", max_nbtrcr
    1172              : 
    1173           83 :         write(iounit,*) "  model defined parameters: "
    1174           83 :         write(iounit,*) "  ncat      = ",ncat
    1175           83 :         write(iounit,*) "  nilyr     = ",nilyr
    1176           83 :         write(iounit,*) "  nslyr     = ",nslyr
    1177           83 :         write(iounit,*) "  nblyr     = ",nblyr
    1178           83 :         write(iounit,*) "  nfsd      = ",nfsd
    1179           83 :         write(iounit,*) "  n_algae   = ",n_algae
    1180           83 :         write(iounit,*) "  n_DOC     = ",n_DOC
    1181           83 :         write(iounit,*) "  n_DON     = ",n_DON
    1182           83 :         write(iounit,*) "  n_DIC     = ",n_DIC
    1183           83 :         write(iounit,*) "  n_fed     = ",n_fed
    1184           83 :         write(iounit,*) "  n_fep     = ",n_fep
    1185           83 :         write(iounit,*) "  n_zaero   = ",n_zaero
    1186           83 :         write(iounit,*) "  n_aero    = ",n_aero
    1187           83 :         write(iounit,*) "  n_iso     = ",n_iso
    1188           83 :         write(iounit,*) "  ntrcr     = ",ntrcr
    1189           83 :         write(iounit,*) "  ntrcr_o   = ",ntrcr_o
    1190           83 :         write(iounit,*) "  nbtrcr    = ",nbtrcr
    1191           83 :         write(iounit,*) "  nbtrcr_sw = ",nbtrcr_sw
    1192              : 
    1193           83 :       end subroutine icepack_write_tracer_sizes
    1194              : 
    1195              : !=======================================================================
    1196              : !autodocument_start icepack_compute_tracers
    1197              : ! Compute tracer fields.
    1198              : ! Given atrcrn = aicen*trcrn (or vicen*trcrn, vsnon*trcrn), compute trcrn.
    1199              : 
    1200            0 :       subroutine icepack_compute_tracers (trcr_depend,               &
    1201            0 :                                           atrcrn,    aicen,          &
    1202              :                                           vicen,     vsnon,          &
    1203     47306542 :                                           trcr_base, n_trcr_strata,  &
    1204     47306542 :                                           nt_strata, trcrn, Tf)
    1205              : 
    1206              :       integer (kind=int_kind), dimension (:), intent(in) :: &
    1207              :          trcr_depend, & ! = 0 for aicen tracers, 1 for vicen, 2 for vsnon
    1208              :          n_trcr_strata  ! number of underlying tracer layers
    1209              : 
    1210              :       real (kind=dbl_kind), dimension (:,:), intent(in) :: &
    1211              :          trcr_base      ! = 0 or 1 depending on tracer dependency
    1212              :                         ! argument 2:  (1) aice, (2) vice, (3) vsno
    1213              : 
    1214              :       integer (kind=int_kind), dimension (:,:), intent(in) :: &
    1215              :          nt_strata      ! indices of underlying tracer layers
    1216              : 
    1217              :       real (kind=dbl_kind), dimension (:), intent(in) :: &
    1218              :          atrcrn    ! aicen*trcrn or vicen*trcrn or vsnon*trcrn
    1219              : 
    1220              :       real (kind=dbl_kind), intent(in) :: &
    1221              :          aicen , & ! concentration of ice
    1222              :          vicen , & ! volume per unit area of ice          (m)
    1223              :          vsnon     ! volume per unit area of snow         (m)
    1224              : 
    1225              :       real (kind=dbl_kind), dimension (:), intent(out) :: &
    1226              :          trcrn     ! ice tracers
    1227              : 
    1228              :       real (kind=dbl_kind), intent(in) :: &
    1229              :          Tf        ! Freezing point
    1230              : 
    1231              : !autodocument_end
    1232              : 
    1233              :       ! local variables
    1234              : 
    1235              :       integer (kind=int_kind) :: &
    1236              :          it,     & ! tracer index
    1237              :          itl,    & ! tracer index
    1238              :          ntr,    & ! tracer index
    1239              :          k         ! loop index
    1240              : 
    1241              :       real (kind=dbl_kind), dimension(3) :: &
    1242              :          divisor   ! base quantity on which tracers are carried
    1243              : 
    1244              :       real (kind=dbl_kind) :: &
    1245              :          work      ! temporary scalar
    1246              : 
    1247              :       character(len=*),parameter :: subname='(icepack_compute_tracers)'
    1248              : 
    1249              :       !-----------------------------------------------------------------
    1250              :       ! Compute new tracers
    1251              :       !-----------------------------------------------------------------
    1252              : 
    1253    961276778 :       do it = 1, ntrcr
    1254    937623507 :          divisor(1) = trcr_base(it,1)*aicen
    1255    937623507 :          divisor(2) = trcr_base(it,2)*vicen
    1256    937623507 :          divisor(3) = trcr_base(it,3)*vsnon
    1257              : 
    1258    961276778 :          if (trcr_depend(it) == 0) then ! ice area tracers
    1259     62931622 :             if (aicen > puny) then
    1260     59048527 :                trcrn(it) = atrcrn(it) / aicen
    1261              :             else
    1262      3883095 :                trcrn(it) = c0
    1263      3883095 :                if (it == nt_Tsfc) then
    1264      1463212 :                   trcrn(it) = Tf  ! surface temperature
    1265              :                endif
    1266              :             endif
    1267              : 
    1268              :          else
    1269              : 
    1270    874691885 :             work = c0
    1271   3498767540 :             do k = 1, 3
    1272   3498767540 :                if (divisor(k) > c0) then
    1273    724109005 :                   work = atrcrn(it) / divisor(k)
    1274              :                endif
    1275              :             enddo
    1276    874691885 :             trcrn(it) = work                ! save it
    1277    874691885 :             if (n_trcr_strata(it) > 0) then          ! additional tracer layers
    1278    168382568 :                do itl = 1, n_trcr_strata(it)
    1279    104588360 :                   ntr = nt_strata(it,itl)
    1280    168382568 :                   if (trcrn(ntr) > c0) then
    1281     77954125 :                       trcrn(it) = trcrn(it) / trcrn(ntr)
    1282              :                   else
    1283     26634235 :                       trcrn(it) = c0
    1284              :                   endif
    1285              :                enddo
    1286              :             endif
    1287              : 
    1288              :          endif ! trcr_depend=0
    1289              : 
    1290              :       enddo
    1291              : 
    1292     23653271 :       if (vicen <= c0 .and. tr_brine) trcrn(nt_fbri) = c1
    1293     23653271 :       if (vsnon <= c0) then
    1294      2879431 :          if (snwredist(1:3) == 'ITD') then
    1295      3354516 :             trcrn(nt_rhos :nt_rhos +nslyr-1) = rhosnew
    1296              :          endif
    1297      2879431 :          if (snwgrain) then
    1298      3330282 :             trcrn(nt_rsnw :nt_rsnw +nslyr-1) = rsnw_fall
    1299      3330282 :             trcrn(nt_smice:nt_smice+nslyr-1) = rhos
    1300              :          endif
    1301              :       endif ! vsnon <= 0
    1302              : 
    1303     23653271 :       end subroutine icepack_compute_tracers
    1304              : 
    1305              : !=======================================================================
    1306              : 
    1307              :       end module icepack_tracers
    1308              : 
    1309              : !=======================================================================
        

Generated by: LCOV version 2.0-1