LCOV - code coverage report
Current view: top level - configuration/driver - icedrv_init.F90 (source / functions) Coverage Total Hit
Test: 250117-002718:9f4b99afd9:4:base,io,travis,quick Lines: 83.99 % 731 614
Test Date: 2025-01-16 18:02:43 Functions: 100.00 % 5 5

            Line data    Source code
       1              : !=======================================================================
       2              : 
       3              : ! parameter and variable initializations
       4              : !
       5              : ! authors Elizabeth C. Hunke, LANL
       6              : 
       7              :       module icedrv_init
       8              : 
       9              :       use icedrv_kinds
      10              :       use icedrv_constants, only: nu_diag, ice_stdout, nu_diag_out, nu_nml
      11              :       use icedrv_constants, only: c0, c1, c2, c3, p2, p5
      12              :       use icedrv_domain_size, only: nx
      13              :       use icepack_intfc, only: icepack_init_parameters
      14              :       use icepack_intfc, only: icepack_init_fsd
      15              :       use icepack_intfc, only: icepack_init_tracer_flags
      16              :       use icepack_intfc, only: icepack_init_tracer_sizes
      17              :       use icepack_intfc, only: icepack_init_tracer_indices
      18              :       use icepack_intfc, only: icepack_init_enthalpy
      19              :       use icepack_intfc, only: icepack_query_parameters
      20              :       use icepack_intfc, only: icepack_query_tracer_flags
      21              :       use icepack_intfc, only: icepack_query_tracer_sizes
      22              :       use icepack_intfc, only: icepack_query_tracer_indices
      23              :       use icepack_intfc, only: icepack_warnings_flush, icepack_warnings_aborted
      24              :       use icedrv_system, only: icedrv_system_abort, icedrv_system_flush
      25              : 
      26              :       implicit none
      27              :       private
      28              :       public :: input_data, init_grid2, init_state, init_fsd
      29              : 
      30              :       character(len=char_len_long), public :: &
      31              :          ice_ic      ! method of ice cover initialization
      32              :                      ! 'default' or 'none' => conditions specified in code
      33              :                      ! restart = .true. overwrites default initial
      34              :                      !    condition using filename given by ice_ic
      35              : 
      36              :       real (kind=dbl_kind), dimension (nx), public :: &
      37              :          TLON   , & ! longitude of temp pts (radians)
      38              :          TLAT       ! latitude of temp pts (radians)
      39              : 
      40              :       logical (kind=log_kind), &
      41              :          dimension (nx), public :: &
      42              :          tmask  , & ! land/boundary mask, thickness (T-cell)
      43              :          lmask_n, & ! northern hemisphere mask
      44              :          lmask_s    ! southern hemisphere mask
      45              : 
      46              : !=======================================================================
      47              : 
      48              :       contains
      49              : 
      50              : !=======================================================================
      51              : 
      52              : ! Namelist variables, set to default values; may be altered
      53              : ! at run time
      54              : !
      55              : ! author Elizabeth C. Hunke, LANL
      56              : 
      57           83 :       subroutine input_data
      58              : 
      59              :       use icedrv_diagnostics, only: diag_file, nx_names
      60              :       use icedrv_domain_size, only: nilyr, nslyr, nblyr, max_ntrcr, ncat
      61              :       use icedrv_domain_size, only: n_iso, n_aero, nfsd
      62              :       use icedrv_calendar, only: year_init, istep0
      63              :       use icedrv_calendar, only: dumpfreq, diagfreq, dump_last
      64              :       use icedrv_calendar, only: npt, dt, ndtd, days_per_year, use_leap_years
      65              :       use icedrv_history, only: history_format
      66              :       use icedrv_restart_shared, only: restart, restart_dir, restart_file, restart_format
      67              :       use icedrv_flux, only: l_mpond_fresh, cpl_bgc
      68              :       use icedrv_flux, only: default_season
      69              :       use icedrv_forcing, only: precip_units,    fyear_init,      ycycle
      70              :       use icedrv_forcing, only: atm_data_type,   ocn_data_type,   bgc_data_type
      71              :       use icedrv_forcing, only: atm_data_file,   ocn_data_file,   bgc_data_file
      72              :       use icedrv_forcing, only: ice_data_file
      73              :       use icedrv_forcing, only: atm_data_format, ocn_data_format, bgc_data_format
      74              :       use icedrv_forcing, only: data_dir
      75              :       use icedrv_forcing, only: oceanmixed_ice, restore_ocn, trestore
      76              :       use icedrv_forcing, only: snw_ssp_table, lateral_flux_type
      77              : 
      78              :       ! local variables
      79              : 
      80              :       character (32) :: &
      81              :          nml_filename = 'icepack_in' ! namelist input file name
      82              : 
      83              :       integer (kind=int_kind) :: &
      84              :          nml_error, & ! namelist i/o error flag
      85              :          n            ! loop index
      86              : 
      87              :       character (len=char_len) :: diag_file_names
      88              :       character (len=char_len), dimension(4) :: nx_names_default
      89              : 
      90              :       real (kind=dbl_kind) :: ustar_min, albicev, albicei, albsnowv, albsnowi, &
      91              :          ahmax, R_ice, R_pnd, R_snw, dT_mlt, rsnw_mlt, ksno, hi_min, Tliquidus_max, &
      92              :          mu_rdg, hs0, dpscale, rfracmin, rfracmax, pndaspect, hs1, hp1, &
      93              :          a_rapid_mode, Rac_rapid_mode, aspect_rapid_mode, dSdt_slow_mode, &
      94              :          phi_c_slow_mode, phi_i_mushy, kalg, emissivity, floediam, hfrazilmin, &
      95              :          rsnw_fall, rsnw_tmax, rhosnew, rhosmin, rhosmax, &
      96              :          windmin, drhosdwind, snwlvlfac
      97              : 
      98              :       integer (kind=int_kind) :: ktherm, kstrength, krdg_partic, krdg_redist, &
      99              :          natmiter, kitd, kcatbound
     100              : 
     101              :       character (len=char_len) :: shortwave, albedo_type, conduct, fbot_xfer_type, &
     102              :          cpl_frazil, congel_freeze, tfrz_option, saltflux_option, &
     103              :          frzpnd, atmbndy, wave_spec_type, snwredist, snw_aging_table
     104              : 
     105              :       logical (kind=log_kind) :: sw_redist, use_smliq_pnd, snwgrain, update_ocn_f
     106              :       real (kind=dbl_kind)    :: sw_frac, sw_dtemp
     107              : 
     108              :       ! Flux convergence tolerance
     109              :       real (kind=dbl_kind) :: atmiter_conv
     110              : 
     111              :       ! Ice reference salinity for fluxes
     112              :       real (kind=dbl_kind) :: ice_ref_salinity
     113              : 
     114              :       logical (kind=log_kind) :: calc_Tsfc, formdrag, highfreq, calc_strair, calc_dragio
     115              :       logical (kind=log_kind) :: conserv_check
     116              : 
     117              :       integer (kind=int_kind) :: ntrcr
     118              :       logical (kind=log_kind) :: tr_iage, tr_FY, tr_lvl, tr_pond, tr_snow
     119              :       logical (kind=log_kind) :: tr_iso, tr_aero, tr_fsd
     120              :       logical (kind=log_kind) :: tr_pond_lvl, tr_pond_topo, wave_spec
     121              :       integer (kind=int_kind) :: nt_Tsfc, nt_sice, nt_qice, nt_qsno, nt_iage, nt_FY
     122              :       integer (kind=int_kind) :: nt_alvl, nt_vlvl, nt_apnd, nt_hpnd, nt_ipnd, &
     123              :                                  nt_smice, nt_smliq, nt_rhos, nt_rsnw, &
     124              :                                  nt_aero, nt_fsd, nt_isosno, nt_isoice
     125              : 
     126              :       real (kind=real_kind) :: rplvl, rptopo
     127              :       real (kind=dbl_kind) :: Cf, puny
     128              : 
     129              :       character(len=*), parameter :: subname='(input_data)'
     130              : 
     131              :       !-----------------------------------------------------------------
     132              :       ! Namelist variables
     133              :       !-----------------------------------------------------------------
     134              : 
     135              :       namelist /setup_nml/ &
     136              :         days_per_year,  use_leap_years, year_init,       istep0,        &
     137              :         dt,             npt,            ndtd,            dump_last,     &
     138              :         ice_ic,         restart,        restart_dir,     restart_file,  &
     139              :         restart_format, &
     140              :         dumpfreq,       diagfreq,       diag_file,       cpl_bgc,       &
     141              :         conserv_check,  history_format
     142              : 
     143              :       namelist /grid_nml/ &
     144              :         kcatbound
     145              : 
     146              :       namelist /thermo_nml/ &
     147              :         kitd,           ktherm,          ksno,     conduct,             &
     148              :         a_rapid_mode,   Rac_rapid_mode,  aspect_rapid_mode,             &
     149              :         dSdt_slow_mode, phi_c_slow_mode, phi_i_mushy,                   &
     150              :         floediam,       hfrazilmin,      Tliquidus_max,    hi_min
     151              : 
     152              :       namelist /dynamics_nml/ &
     153              :         kstrength,      krdg_partic,    krdg_redist,    mu_rdg,         &
     154              :         Cf
     155              : 
     156              :       namelist /shortwave_nml/ &
     157              :         shortwave,      albedo_type,                                    &
     158              :         albicev,        albicei,         albsnowv,      albsnowi,       &
     159              :         ahmax,          R_ice,           R_pnd,         R_snw,          &
     160              :         sw_redist,      sw_frac,         sw_dtemp,                      &
     161              :         dT_mlt,         rsnw_mlt,        kalg,          snw_ssp_table
     162              : 
     163              :       namelist /ponds_nml/ &
     164              :         hs0,            dpscale,         frzpnd,                        &
     165              :         rfracmin,       rfracmax,        pndaspect,     hs1,            &
     166              :         hp1
     167              :       namelist /snow_nml/ &
     168              :         snwredist,      snwgrain,       rsnw_fall,     rsnw_tmax,      &
     169              :         rhosnew,        rhosmin,        rhosmax,       snwlvlfac,      &
     170              :         windmin,        drhosdwind,     use_smliq_pnd, snw_aging_table
     171              : 
     172              :       namelist /forcing_nml/ &
     173              :         atmbndy,         calc_strair,     calc_Tsfc,       &
     174              :         update_ocn_f,    l_mpond_fresh,   ustar_min,       &
     175              :         fbot_xfer_type,  oceanmixed_ice,  emissivity,      &
     176              :         formdrag,        highfreq,        natmiter,        &
     177              :         atmiter_conv,    calc_dragio,     congel_freeze,   &
     178              :         tfrz_option,     saltflux_option, ice_ref_salinity, &
     179              :         default_season,  wave_spec_type,  cpl_frazil,      &
     180              :         precip_units,    fyear_init,      ycycle,          &
     181              :         atm_data_type,   ocn_data_type,   bgc_data_type,   &
     182              :         lateral_flux_type,                                 &
     183              :         atm_data_file,   ocn_data_file,   bgc_data_file,   &
     184              :         ice_data_file,                                     &
     185              :         atm_data_format, ocn_data_format, bgc_data_format, &
     186              :         data_dir,        trestore,        restore_ocn
     187              : 
     188              :       namelist /tracer_nml/   &
     189              :         tr_iage,      &
     190              :         tr_FY,        &
     191              :         tr_lvl,       &
     192              :         tr_pond_lvl,  &
     193              :         tr_pond_topo, &
     194              :         tr_snow,      &
     195              :         tr_aero,      &
     196              :         tr_fsd,       &
     197              :         tr_iso
     198              : 
     199              :       !-----------------------------------------------------------------
     200              :       ! query Icepack values
     201              :       !-----------------------------------------------------------------
     202              : 
     203              :       call icepack_query_parameters(ustar_min_out=ustar_min, Cf_out=Cf, &
     204              :            albicev_out=albicev, albicei_out=albicei, ksno_out = ksno,   &
     205              :            albsnowv_out=albsnowv, albsnowi_out=albsnowi, hi_min_out=hi_min, &
     206              :            natmiter_out=natmiter, ahmax_out=ahmax, shortwave_out=shortwave, &
     207              :            atmiter_conv_out = atmiter_conv, calc_dragio_out=calc_dragio, &
     208              :            albedo_type_out=albedo_type, R_ice_out=R_ice, R_pnd_out=R_pnd, &
     209              :            R_snw_out=R_snw, dT_mlt_out=dT_mlt, rsnw_mlt_out=rsnw_mlt, &
     210              :            kstrength_out=kstrength, krdg_partic_out=krdg_partic, &
     211              :            krdg_redist_out=krdg_redist, mu_rdg_out=mu_rdg, &
     212              :            atmbndy_out=atmbndy, calc_strair_out=calc_strair, &
     213              :            formdrag_out=formdrag, highfreq_out=highfreq, &
     214              :            emissivity_out=emissivity, &
     215              :            kitd_out=kitd, kcatbound_out=kcatbound, hs0_out=hs0, &
     216              :            dpscale_out=dpscale, frzpnd_out=frzpnd, &
     217              :            rfracmin_out=rfracmin, rfracmax_out=rfracmax, &
     218              :            pndaspect_out=pndaspect, hs1_out=hs1, hp1_out=hp1, &
     219              :            ktherm_out=ktherm, calc_Tsfc_out=calc_Tsfc, &
     220              :            floediam_out=floediam, hfrazilmin_out=hfrazilmin, &
     221              :            update_ocn_f_out = update_ocn_f, cpl_frazil_out = cpl_frazil, &
     222              :            conduct_out=conduct, a_rapid_mode_out=a_rapid_mode, &
     223              :            Rac_rapid_mode_out=Rac_rapid_mode, &
     224              :            aspect_rapid_mode_out=aspect_rapid_mode, &
     225              :            dSdt_slow_mode_out=dSdt_slow_mode, &
     226              :            phi_c_slow_mode_out=phi_c_slow_mode, Tliquidus_max_out=Tliquidus_max, &
     227              :            phi_i_mushy_out=phi_i_mushy, conserv_check_out=conserv_check, &
     228              :            congel_freeze_out=congel_freeze, &
     229              :            tfrz_option_out=tfrz_option, saltflux_option_out=saltflux_option, &
     230              :            ice_ref_salinity_out=ice_ref_salinity, kalg_out=kalg, &
     231              :            fbot_xfer_type_out=fbot_xfer_type, puny_out=puny, &
     232              :            wave_spec_type_out=wave_spec_type, &
     233              :            sw_redist_out=sw_redist, sw_frac_out=sw_frac, sw_dtemp_out=sw_dtemp, &
     234              :            snwredist_out=snwredist, use_smliq_pnd_out=use_smliq_pnd, &
     235              :            snwgrain_out=snwgrain, rsnw_fall_out=rsnw_fall, rsnw_tmax_out=rsnw_tmax, &
     236              :            rhosnew_out=rhosnew, rhosmin_out = rhosmin, rhosmax_out=rhosmax, &
     237              :            windmin_out=windmin, drhosdwind_out=drhosdwind, snwlvlfac_out=snwlvlfac, &
     238           83 :            snw_aging_table_out=snw_aging_table)
     239              : 
     240           83 :       call icepack_warnings_flush(nu_diag)
     241           83 :       if (icepack_warnings_aborted()) call icedrv_system_abort(string=subname, &
     242            0 :           file=__FILE__, line=__LINE__)
     243              : 
     244              :       !-----------------------------------------------------------------
     245              :       ! default values
     246              :       !-----------------------------------------------------------------
     247              : 
     248           83 :       days_per_year = 365    ! number of days in a year
     249           83 :       use_leap_years= .false.! if true, use leap years (Feb 29)
     250           83 :       year_init = 0          ! initial year
     251           83 :       istep0 = 0             ! no. of steps taken in previous integrations,
     252              :                              ! real (dumped) or imagined (to set calendar)
     253           83 :       dt = 3600.0_dbl_kind   ! time step, s
     254           83 :       npt = 99999            ! total number of time steps (dt)
     255           83 :       diagfreq = 24          ! how often diag output is written
     256           83 :       diag_file = 'ice_diag' ! history file name prefix
     257           83 :       cpl_bgc = .false.      !
     258           83 :       dumpfreq='y'           ! restart frequency option
     259           83 :       dump_last=.false.      ! restart at end of run
     260           83 :       restart = .false.      ! if true, read restart files for initialization
     261           83 :       restart_dir  = './'    ! write to executable dir for default
     262           83 :       restart_file = 'iced'  ! restart file name prefix
     263           83 :       restart_format = 'bin' ! default restart format is binary, other option 'nc'
     264           83 :       history_format = 'none'     ! if 'nc', write history files. Otherwise do nothing
     265           83 :       ice_ic       = 'default'    ! initial conditions are specified in the code
     266              :                                   ! otherwise, the filename for reading restarts
     267           83 :       ndtd = 1               ! dynamic time steps per thermodynamic time step
     268           83 :       l_mpond_fresh = .false.     ! logical switch for including meltpond freshwater
     269              :                                   ! flux feedback to ocean model
     270           83 :       default_season  = 'winter'  ! default forcing data, if data is not read in
     271           83 :       fyear_init      = 1998      ! initial forcing year
     272           83 :       ycycle          = 1         ! number of years in forcing cycle
     273           83 :       atm_data_format = 'bin'     ! file format ('bin'=binary or 'nc'=netcdf)
     274           83 :       atm_data_type   = 'default' ! source of atmospheric forcing data
     275           83 :       atm_data_file   = ' '       ! atmospheric forcing data file
     276           83 :       precip_units    = 'mks'     ! 'mm_per_month' or
     277              :                                   ! 'mm_per_sec' = 'mks' = kg/m^2 s
     278           83 :       oceanmixed_ice  = .false.   ! if true, use internal ocean mixed layer
     279           83 :       wave_spec_type  = 'none'    ! type of wave spectrum forcing
     280           83 :       ocn_data_format = 'bin'     ! file format ('bin'=binary or 'nc'=netcdf)
     281           83 :       ocn_data_type   = 'default' ! source of ocean forcing data
     282           83 :       ocn_data_file   = ' '       ! ocean forcing data file
     283           83 :       ice_data_file   = ' '       ! ice forcing data file (opening, closing)
     284           83 :       lateral_flux_type   = 'uniform_ice' ! if 'uniform_ice' assume closing
     285              :                                            ! fluxes in uniform ice
     286           83 :       bgc_data_format = 'bin'     ! file format ('bin'=binary or 'nc'=netcdf)
     287           83 :       bgc_data_type   = 'default' ! source of BGC forcing data
     288           83 :       bgc_data_file   = ' '       ! biogeochemistry forcing data file
     289           83 :       data_dir    = ' '           ! root location of data files
     290           83 :       restore_ocn     = .false.   ! restore sst if true
     291           83 :       trestore        = 90        ! restoring timescale, days (0 instantaneous)
     292           83 :       snw_ssp_table   = 'test'    ! snow table type, test or snicar
     293              : 
     294              :       ! extra tracers
     295           83 :       tr_iage      = .false. ! ice age
     296           83 :       tr_FY        = .false. ! ice age
     297           83 :       tr_lvl       = .false. ! level ice
     298           83 :       tr_pond_lvl  = .false. ! level-ice melt ponds
     299           83 :       tr_pond_topo = .false. ! topographic melt ponds
     300           83 :       tr_snow      = .false. ! snow tracers (wind redistribution, metamorphosis)
     301           83 :       tr_aero      = .false. ! aerosols
     302           83 :       tr_fsd       = .false. ! floe size distribution
     303           83 :       tr_iso       = .false. ! isotopes
     304              : 
     305              :       !-----------------------------------------------------------------
     306              :       ! read from input file
     307              :       !-----------------------------------------------------------------
     308              : 
     309           83 :       open (nu_nml, file=trim(nml_filename), status='old',iostat=nml_error)
     310           83 :       if (nml_error /= 0) then
     311              :          call icedrv_system_abort(string=subname//'ERROR: open file '// &
     312              :             trim(nml_filename), &
     313            0 :             file=__FILE__, line=__LINE__)
     314              :       endif
     315              : 
     316           83 :       write(nu_diag,*) subname,' Reading setup_nml'
     317           83 :       rewind(unit=nu_nml, iostat=nml_error)
     318           83 :       if (nml_error /= 0) then
     319              :          call icedrv_system_abort(string=subname//'ERROR: setup_nml rewind ', &
     320            0 :             file=__FILE__, line=__LINE__)
     321              :       endif
     322           83 :       nml_error =  1
     323          166 :       do while (nml_error > 0)
     324           83 :          read(nu_nml, nml=setup_nml,iostat=nml_error)
     325              :       end do
     326           83 :       if (nml_error /= 0) then
     327              :          call icedrv_system_abort(string=subname//'ERROR: setup_nml reading ', &
     328            0 :             file=__FILE__, line=__LINE__)
     329              :       endif
     330              : 
     331           83 :       write(nu_diag,*) subname,' Reading grid_nml'
     332           83 :       rewind(unit=nu_nml, iostat=nml_error)
     333           83 :       if (nml_error /= 0) then
     334              :          call icedrv_system_abort(string=subname//'ERROR: grid_nml rewind ', &
     335            0 :             file=__FILE__, line=__LINE__)
     336              :       endif
     337           83 :       nml_error =  1
     338          166 :       do while (nml_error > 0)
     339           83 :          read(nu_nml, nml=grid_nml,iostat=nml_error)
     340              :       end do
     341           83 :       if (nml_error /= 0) then
     342              :          call icedrv_system_abort(string=subname//'ERROR: grid_nml reading ', &
     343            0 :             file=__FILE__, line=__LINE__)
     344              :       endif
     345              : 
     346           83 :       write(nu_diag,*) subname,' Reading thermo_nml'
     347           83 :       rewind(unit=nu_nml, iostat=nml_error)
     348           83 :       if (nml_error /= 0) then
     349              :          call icedrv_system_abort(string=subname//'ERROR: thermo_nml rewind ', &
     350            0 :             file=__FILE__, line=__LINE__)
     351              :       endif
     352           83 :       nml_error =  1
     353          166 :       do while (nml_error > 0)
     354           83 :          read(nu_nml, nml=thermo_nml,iostat=nml_error)
     355              :       end do
     356           83 :       if (nml_error /= 0) then
     357              :          call icedrv_system_abort(string=subname//'ERROR: thermo_nml reading ', &
     358            0 :             file=__FILE__, line=__LINE__)
     359              :       endif
     360              : 
     361           83 :       write(nu_diag,*) subname,' Reading tracer_nml'
     362           83 :       rewind(unit=nu_nml, iostat=nml_error)
     363           83 :       if (nml_error /= 0) then
     364              :          call icedrv_system_abort(string=subname//'ERROR: tracer_nml rewind ', &
     365            0 :             file=__FILE__, line=__LINE__)
     366              :       endif
     367           83 :       nml_error =  1
     368          166 :       do while (nml_error > 0)
     369           83 :          read(nu_nml, nml=tracer_nml,iostat=nml_error)
     370              :       end do
     371           83 :       if (nml_error /= 0) then
     372              :          call icedrv_system_abort(string=subname//'ERROR: tracer_nml reading ', &
     373            0 :             file=__FILE__, line=__LINE__)
     374              :       endif
     375              : 
     376           83 :       write(nu_diag,*) subname,' Reading shortwave_nml'
     377           83 :       rewind(unit=nu_nml, iostat=nml_error)
     378           83 :       if (nml_error /= 0) then
     379              :          call icedrv_system_abort(string=subname//'ERROR: shortwave_nml rewind ', &
     380            0 :             file=__FILE__, line=__LINE__)
     381              :       endif
     382           83 :       nml_error =  1
     383          166 :       do while (nml_error > 0)
     384           83 :          read(nu_nml, nml=shortwave_nml,iostat=nml_error)
     385              :       end do
     386           83 :       if (nml_error /= 0) then
     387              :          call icedrv_system_abort(string=subname//'ERROR: shortwave_nml reading ', &
     388            0 :             file=__FILE__, line=__LINE__)
     389              :       endif
     390              : 
     391           83 :       write(nu_diag,*) subname,' Reading ponds_nml'
     392           83 :       rewind(unit=nu_nml, iostat=nml_error)
     393           83 :       if (nml_error /= 0) then
     394              :          call icedrv_system_abort(string=subname//'ERROR: ponds_nml rewind ', &
     395            0 :             file=__FILE__, line=__LINE__)
     396              :       endif
     397           83 :       nml_error =  1
     398          166 :       do while (nml_error > 0)
     399           83 :          read(nu_nml, nml=ponds_nml,iostat=nml_error)
     400              :       end do
     401           83 :       if (nml_error /= 0) then
     402              :          call icedrv_system_abort(string=subname//'ERROR: ponds_nml reading ', &
     403            0 :             file=__FILE__, line=__LINE__)
     404              :       endif
     405              : 
     406           83 :       write(nu_diag,*) subname,' Reading snow_nml'
     407           83 :       rewind(unit=nu_nml, iostat=nml_error)
     408           83 :       if (nml_error /= 0) then
     409              :          call icedrv_system_abort(string=subname//'ERROR: snow_nml rewind ', &
     410            0 :             file=__FILE__, line=__LINE__)
     411              :       endif
     412           83 :       nml_error =  1
     413          166 :       do while (nml_error > 0)
     414           83 :          read(nu_nml, nml=snow_nml,iostat=nml_error)
     415              :       end do
     416           83 :       if (nml_error /= 0) then
     417              :          call icedrv_system_abort(string=subname//'ERROR: snow_nml reading ', &
     418            0 :             file=__FILE__, line=__LINE__)
     419              :       endif
     420              : 
     421           83 :       write(nu_diag,*) subname,' Reading forcing_nml'
     422           83 :       rewind(unit=nu_nml, iostat=nml_error)
     423           83 :       if (nml_error /= 0) then
     424              :          call icedrv_system_abort(string=subname//'ERROR: forcing_nml rewind ', &
     425            0 :             file=__FILE__, line=__LINE__)
     426              :       endif
     427           83 :       nml_error =  1
     428          166 :       do while (nml_error > 0)
     429           83 :          read(nu_nml, nml=forcing_nml,iostat=nml_error)
     430              :       end do
     431           83 :       if (nml_error /= 0) then
     432              :          call icedrv_system_abort(string=subname//'ERROR: forcing_nml reading ', &
     433            0 :             file=__FILE__, line=__LINE__)
     434              :       endif
     435              : 
     436           83 :       close(nu_nml)
     437              : 
     438              :       !-----------------------------------------------------------------
     439              :       ! set up diagnostics output and resolve conflicts
     440              :       !-----------------------------------------------------------------
     441              : 
     442           83 :       write(ice_stdout,*) 'Diagnostic output will be in files '
     443           83 :       write(ice_stdout,*)'    ','icepack.runlog.timestamp'
     444              : 
     445          415 :       do n = 1,nx
     446          415 :          write(nx_names(n),'(a,i2.2)') 'point_',n
     447              :       enddo
     448           83 :       nx_names_default(1) = 'icefree'
     449           83 :       nx_names_default(2) = 'slab'
     450           83 :       nx_names_default(3) = 'full_ITD'
     451           83 :       nx_names_default(4) = 'land'
     452          415 :       do n = 1,nx
     453          415 :          nx_names(n) = nx_names_default(n)
     454              :       enddo
     455              : 
     456          415 :       do n = 1,nx
     457          332 :          diag_file_names=' '
     458          332 :          write(diag_file_names,'(a,a,a)') trim(diag_file),'.',trim(nx_names(n))
     459          332 :          write(ice_stdout,*)'    ',trim(diag_file_names)
     460          415 :          open(nu_diag_out+n-1, file=diag_file_names, status='unknown')
     461              :       end do
     462              : 
     463           83 :       write(nu_diag,*) '-----------------------------------'
     464           83 :       write(nu_diag,*) '  ICEPACK model diagnostic output  '
     465           83 :       write(nu_diag,*) '-----------------------------------'
     466           83 :       write(nu_diag,*) ' '
     467              : 
     468            3 :       if (ncat == 1 .and. kitd == 1) then
     469            0 :          write (nu_diag,*) 'Remapping the ITD is not allowed for ncat=1.'
     470            0 :          write (nu_diag,*) 'Use kitd = 0 (delta function ITD) with kcatbound = 0'
     471            0 :          write (nu_diag,*) 'or for column configurations use kcatbound = -1'
     472            0 :          call icedrv_system_abort(file=__FILE__,line=__LINE__)
     473              :       endif
     474              : 
     475           80 :       if (ncat /= 1 .and. kcatbound == -1) then
     476            0 :          write (nu_diag,*) 'WARNING: ITD required for ncat > 1'
     477            0 :          write (nu_diag,*) 'WARNING: Setting kitd and kcatbound to default values'
     478            0 :          kitd = 1
     479            0 :          kcatbound = 0
     480              :       endif
     481              : 
     482           83 :       rplvl  = c0
     483           83 :       rptopo = c0
     484           83 :       if (tr_pond_lvl ) rplvl  = c1
     485           83 :       if (tr_pond_topo) rptopo = c1
     486              : 
     487           83 :       tr_pond = .false. ! explicit melt ponds
     488           83 :       if (rplvl + rptopo > puny) tr_pond = .true.
     489              : 
     490           83 :       if (rplvl + rptopo > c1 + puny) then
     491            0 :          write (nu_diag,*) 'WARNING: Must use only one melt pond scheme'
     492            0 :          call icedrv_system_abort(file=__FILE__,line=__LINE__)
     493              :       endif
     494              : 
     495           83 :       if (tr_pond_lvl .and. .not. tr_lvl) then
     496            0 :          write (nu_diag,*) 'WARNING: tr_pond_lvl=T but tr_lvl=F'
     497            0 :          write (nu_diag,*) 'WARNING: Setting tr_lvl=T'
     498            0 :          tr_lvl = .true.
     499              :       endif
     500              : 
     501           83 :       if (tr_pond_lvl .and. abs(hs0) > puny) then
     502            0 :          write (nu_diag,*) 'WARNING: tr_pond_lvl=T and hs0/=0'
     503            0 :          write (nu_diag,*) 'WARNING: Setting hs0=0'
     504            0 :          hs0 = c0
     505              :       endif
     506              : 
     507           83 :       if (trim(shortwave(1:4)) /= 'dEdd' .and. tr_pond .and. calc_tsfc) then
     508            0 :          write (nu_diag,*) 'WARNING: Must use dEdd shortwave'
     509            0 :          write (nu_diag,*) 'WARNING: with tr_pond and calc_tsfc=T.'
     510            0 :          write (nu_diag,*) 'WARNING: Setting shortwave = dEdd'
     511            0 :          shortwave = 'dEdd'
     512              :       endif
     513              : 
     514           83 :       if (snwredist(1:3) == 'ITD' .and. .not. tr_snow) then
     515            0 :          write (nu_diag,*) 'WARNING: snwredist on but tr_snow=F'
     516            0 :          call icedrv_system_abort(file=__FILE__,line=__LINE__)
     517              :       endif
     518           83 :       if (snwredist(1:4) == 'bulk' .and. .not. tr_lvl) then
     519            0 :          write (nu_diag,*) 'WARNING: snwredist=bulk but tr_lvl=F'
     520            0 :          call icedrv_system_abort(file=__FILE__,line=__LINE__)
     521              :       endif
     522           83 :       if (snwredist(1:6) == 'ITDrdg' .and. .not. tr_lvl) then
     523            0 :          write (nu_diag,*) 'WARNING: snwredist=ITDrdg but tr_lvl=F'
     524            0 :          call icedrv_system_abort(file=__FILE__,line=__LINE__)
     525              :       endif
     526           83 :       if (use_smliq_pnd .and. .not. snwgrain) then
     527            0 :          write (nu_diag,*) 'WARNING: use_smliq_pnd = T but'
     528            0 :          write (nu_diag,*) 'WARNING: snow metamorphosis not used'
     529            0 :          call icedrv_system_abort(file=__FILE__,line=__LINE__)
     530              :       endif
     531           83 :       if (use_smliq_pnd .and. .not. tr_snow) then
     532            0 :          write (nu_diag,*) 'WARNING: use_smliq_pnd = T but'
     533            0 :          write (nu_diag,*) 'WARNING: snow tracers are not active'
     534            0 :          call icedrv_system_abort(file=__FILE__,line=__LINE__)
     535              :       endif
     536           83 :       if (snwgrain .and. .not. tr_snow) then
     537            0 :          write (nu_diag,*) 'WARNING: snwgrain=T but tr_snow=F'
     538            0 :          call icedrv_system_abort(file=__FILE__,line=__LINE__)
     539              :       endif
     540           83 :       if (trim(snw_aging_table) /= 'test') then
     541            0 :          write (nu_diag,*) 'WARNING: snw_aging_table /= test'
     542            0 :          write (nu_diag,*) 'WARNING: netcdf not available'
     543            0 :          call icedrv_system_abort(file=__FILE__,line=__LINE__)
     544              :       endif
     545              : 
     546           81 :       if (tr_iso .and. n_iso==0) then
     547            0 :          write (nu_diag,*) 'WARNING: isotopes activated but'
     548            0 :          write (nu_diag,*) 'WARNING: not allocated in tracer array.'
     549            0 :          write (nu_diag,*) 'WARNING: Activate in compilation script.'
     550            0 :          call icedrv_system_abort(file=__FILE__,line=__LINE__)
     551              :       endif
     552              : 
     553            3 :       if (tr_aero .and. n_aero==0) then
     554            0 :          write (nu_diag,*) 'WARNING: aerosols activated but'
     555            0 :          write (nu_diag,*) 'WARNING: not allocated in tracer array.'
     556            0 :          write (nu_diag,*) 'WARNING: Activate in compilation script.'
     557            0 :          call icedrv_system_abort(file=__FILE__,line=__LINE__)
     558              :       endif
     559              : 
     560           83 :       if (restart_format /= 'bin' .and. restart_format /= 'nc') then
     561            0 :          write (nu_diag,*) 'WARNING: restart_format value unknown '//trim(restart_format)
     562            0 :          call icedrv_system_abort(file=__FILE__,line=__LINE__)
     563              :       endif
     564              : 
     565           83 :       if (history_format /= 'none' .and. history_format /= 'nc') then
     566            0 :          write (nu_diag,*) 'WARNING: history_format value unknown '//trim(history_format)
     567            0 :          call icedrv_system_abort(file=__FILE__,line=__LINE__)
     568              :       endif
     569              : 
     570           83 :       if (tr_aero .and. trim(shortwave(1:4)) /= 'dEdd') then
     571            0 :          write (nu_diag,*) 'WARNING: aerosols activated but dEdd'
     572            0 :          write (nu_diag,*) 'WARNING: shortwave is not.'
     573            0 :          write (nu_diag,*) 'WARNING: Setting shortwave = dEdd'
     574            0 :          shortwave = 'dEdd'
     575              :       endif
     576              : 
     577           83 :       if (snwgrain .and. trim(shortwave(1:4)) /= 'dEdd') then
     578            0 :          write (nu_diag,*) 'WARNING: snow grain radius activated but'
     579            0 :          write (nu_diag,*) 'WARNING: dEdd shortwave is not.'
     580              :       endif
     581              : 
     582           83 :       if (snwredist(1:4) /= 'none' .and. trim(shortwave(1:4)) /= 'dEdd') then
     583            0 :          write (nu_diag,*) 'WARNING: snow redistribution activated but'
     584            0 :          write (nu_diag,*) 'WARNING: dEdd shortwave is not.'
     585              :       endif
     586              : 
     587           83 :       rfracmin = min(max(rfracmin,c0),c1)
     588           83 :       rfracmax = min(max(rfracmax,c0),c1)
     589              : 
     590           83 :       if (ktherm == 2 .and. .not. calc_Tsfc) then
     591            0 :          write (nu_diag,*) 'WARNING: ktherm = 2 and calc_Tsfc = F'
     592            0 :          write (nu_diag,*) 'WARNING: Setting calc_Tsfc = T'
     593            0 :          calc_Tsfc = .true.
     594              :       endif
     595              : 
     596           83 :       if (ktherm == 1 .and. trim(tfrz_option) /= 'linear_salt') then
     597              :          write (nu_diag,*) &
     598            6 :          'WARNING: ktherm = 1 and tfrz_option = ',trim(tfrz_option)
     599              :          write (nu_diag,*) &
     600            6 :          'WARNING: For consistency, set tfrz_option = linear_salt'
     601              :       endif
     602           83 :       if (ktherm == 2 .and. trim(tfrz_option) /= 'mushy') then
     603              :          write (nu_diag,*) &
     604            0 :          'WARNING: ktherm = 2 and tfrz_option = ',trim(tfrz_option)
     605              :          write (nu_diag,*) &
     606            0 :          'WARNING: For consistency, set tfrz_option = mushy'
     607              :       endif
     608              : 
     609           83 :       if (ktherm == 1 .and. trim(saltflux_option) /= 'constant') then
     610              :          write (nu_diag,*) &
     611            0 :          'WARNING: ktherm = 1 and saltflux_option = ',trim(saltflux_option)
     612              :          write (nu_diag,*) &
     613            0 :          'WARNING: For consistency, set saltflux_option = constant'
     614              :       endif
     615              : 
     616           83 :       if (ktherm == 0) then
     617            0 :          write (nu_diag,*) 'WARNING: ktherm = 0 zero-layer thermodynamics'
     618            0 :          write (nu_diag,*) 'WARNING: has been deprecated'
     619            0 :          call icedrv_system_abort(file=__FILE__,line=__LINE__)
     620              :       endif
     621              : 
     622           83 :       if (formdrag) then
     623            3 :       if (trim(atmbndy) == 'constant') then
     624            0 :          write (nu_diag,*) 'WARNING: atmbndy = constant not allowed with formdrag'
     625            0 :          write (nu_diag,*) 'WARNING: Setting atmbndy = similarity'
     626            0 :          atmbndy = 'similarity'
     627              :       endif
     628              : 
     629            3 :       if (.not. calc_strair) then
     630            0 :          write (nu_diag,*) 'WARNING: formdrag=T but calc_strair=F'
     631            0 :          write (nu_diag,*) 'WARNING: Setting calc_strair=T'
     632            0 :          calc_strair = .true.
     633              :       endif
     634              : 
     635            3 :       if (.not. tr_lvl) then
     636            3 :          write (nu_diag,*) 'WARNING: formdrag=T but tr_lvl=F'
     637            3 :          write (nu_diag,*) 'WARNING: Setting tr_lvl=T'
     638            3 :          tr_lvl = .true.
     639              :       endif
     640              :       endif
     641              : 
     642           83 :       if (trim(fbot_xfer_type) == 'Cdn_ocn' .and. .not. formdrag)  then
     643            0 :          write (nu_diag,*) 'WARNING: formdrag=F but fbot_xfer_type=Cdn_ocn'
     644            0 :          write (nu_diag,*) 'WARNING: Setting fbot_xfer_type = constant'
     645            0 :          fbot_xfer_type = 'constant'
     646              :       endif
     647              : 
     648           83 :       wave_spec = .false.
     649           83 :       if (tr_fsd .and. (trim(wave_spec_type) /= 'none')) wave_spec = .true.
     650           83 :       if (tr_fsd .and. (trim(wave_spec_type) == 'none')) then
     651            1 :          write (nu_diag,*) 'WARNING: tr_fsd=T but wave_spec=F - not recommended'
     652              :       end if
     653              : 
     654              :       !-----------------------------------------------------------------
     655              :       ! spew
     656              :       !-----------------------------------------------------------------
     657              : 
     658           83 :          write(nu_diag,*) ' Document ice_in namelist parameters:'
     659           83 :          write(nu_diag,*) ' ==================================== '
     660           83 :          write(nu_diag,*) ' '
     661           83 :          write(nu_diag,1020) ' days_per_year             = ', days_per_year
     662           83 :          write(nu_diag,1010) ' use_leap_years            = ', use_leap_years
     663           83 :          write(nu_diag,1020) ' year_init                 = ', year_init
     664           83 :          write(nu_diag,1020) ' istep0                    = ', istep0
     665           83 :          write(nu_diag,1000) ' dt                        = ', dt
     666           83 :          write(nu_diag,1020) ' npt                       = ', npt
     667           83 :          write(nu_diag,1020) ' diagfreq                  = ', diagfreq
     668           83 :          write(nu_diag,1030) ' dumpfreq                  = ', trim(dumpfreq)
     669           83 :          write(nu_diag,1010) ' dump_last                 = ', dump_last
     670           83 :          write(nu_diag,1010) ' restart                   = ', restart
     671           83 :          write(nu_diag,1030) ' restart_dir               = ', trim(restart_dir)
     672           83 :          write(nu_diag,1030) ' restart_file              = ', trim(restart_file)
     673           83 :          write(nu_diag,1030) ' restart_format            = ', trim(restart_format)
     674           83 :          write(nu_diag,1030) ' history_format            = ', trim(history_format)
     675           83 :          write(nu_diag,1030) ' ice_ic                    = ', trim(ice_ic)
     676           83 :          write(nu_diag,1010) ' conserv_check             = ', conserv_check
     677           83 :          write(nu_diag,1020) ' kitd                      = ', kitd
     678           83 :          write(nu_diag,1020) ' kcatbound                 = ', kcatbound
     679           83 :          write(nu_diag,1020) ' ndtd                      = ', ndtd
     680           83 :          write(nu_diag,1020) ' kstrength                 = ', kstrength
     681           83 :          write(nu_diag,1020) ' krdg_partic               = ', krdg_partic
     682           83 :          write(nu_diag,1020) ' krdg_redist               = ', krdg_redist
     683           83 :          if (krdg_redist == 1) &
     684           83 :          write(nu_diag,1000) ' mu_rdg                    = ', mu_rdg
     685           83 :          if (kstrength == 1) &
     686           83 :          write(nu_diag,1000) ' Cf                        = ', Cf
     687           83 :          write(nu_diag,1000) ' ksno                      = ', ksno
     688           83 :          write(nu_diag,1030) ' shortwave                 = ', trim(shortwave)
     689           83 :          if (cpl_bgc) then
     690            0 :              write(nu_diag,1000) ' BGC coupling is switched ON'
     691              :          else
     692           83 :              write(nu_diag,1000) ' BGC coupling is switched OFF'
     693              :          endif
     694              : 
     695           83 :          if (trim(shortwave(1:4)) == 'dEdd') then
     696           77 :          write(nu_diag,1000) ' R_ice                     = ', R_ice
     697           77 :          write(nu_diag,1000) ' R_pnd                     = ', R_pnd
     698           77 :          write(nu_diag,1000) ' R_snw                     = ', R_snw
     699           77 :          write(nu_diag,1000) ' dT_mlt                    = ', dT_mlt
     700           77 :          write(nu_diag,1000) ' rsnw_mlt                  = ', rsnw_mlt
     701           77 :          write(nu_diag,1000) ' kalg                      = ', kalg
     702           77 :          write(nu_diag,1000) ' hp1                       = ', hp1
     703           77 :          write(nu_diag,1000) ' hs0                       = ', hs0
     704              :          else
     705            6 :          write(nu_diag,1030) ' albedo_type               = ', trim(albedo_type)
     706            6 :          write(nu_diag,1000) ' albicev                   = ', albicev
     707            6 :          write(nu_diag,1000) ' albicei                   = ', albicei
     708            6 :          write(nu_diag,1000) ' albsnowv                  = ', albsnowv
     709            6 :          write(nu_diag,1000) ' albsnowi                  = ', albsnowi
     710            6 :          write(nu_diag,1000) ' ahmax                     = ', ahmax
     711              :          endif
     712              : 
     713           83 :          if (trim(shortwave) == 'dEdd_snicar_ad') then
     714            6 :          write(nu_diag,1030) ' snw_ssp_table             = ', trim(snw_ssp_table)
     715              :          endif
     716              : 
     717           83 :          write(nu_diag,1010) ' sw_redist                 = ', sw_redist
     718           83 :          write(nu_diag,1005) ' sw_frac                   = ', sw_frac
     719           83 :          write(nu_diag,1005) ' sw_dtemp                  = ', sw_dtemp
     720              : 
     721           83 :          write(nu_diag,1000) ' rfracmin                  = ', rfracmin
     722           83 :          write(nu_diag,1000) ' rfracmax                  = ', rfracmax
     723           83 :          if (tr_pond_lvl) then
     724           69 :          write(nu_diag,1000) ' hs1                       = ', hs1
     725           69 :          write(nu_diag,1000) ' dpscale                   = ', dpscale
     726           69 :          write(nu_diag,1030) ' frzpnd                    = ', trim(frzpnd)
     727              :          endif
     728           83 :          if (tr_pond .and. .not. tr_pond_lvl) &
     729            5 :          write(nu_diag,1000) ' pndaspect                 = ', pndaspect
     730              : 
     731           83 :          if (tr_snow) then
     732           12 :          write(nu_diag,1030) ' snwredist                 = ', trim(snwredist)
     733           12 :          write(nu_diag,1010) ' snwgrain                  = ', snwgrain
     734           12 :          write(nu_diag,1010) ' use_smliq_pnd             = ', use_smliq_pnd
     735           12 :          write(nu_diag,1030) ' snw_aging_table           = ', trim(snw_aging_table)
     736           12 :          write(nu_diag,1000) ' rsnw_fall                 = ', rsnw_fall
     737           12 :          write(nu_diag,1000) ' rsnw_tmax                 = ', rsnw_tmax
     738           12 :          write(nu_diag,1000) ' rhosnew                   = ', rhosnew
     739           12 :          write(nu_diag,1000) ' rhosmin                   = ', rhosmin
     740           12 :          write(nu_diag,1000) ' rhosmax                   = ', rhosmax
     741           12 :          write(nu_diag,1000) ' windmin                   = ', windmin
     742           12 :          write(nu_diag,1000) ' drhosdwind                = ', drhosdwind
     743           12 :          write(nu_diag,1000) ' snwlvlfac                 = ', snwlvlfac
     744              :          endif
     745              : 
     746           83 :          write(nu_diag,1020) ' ktherm                    = ', ktherm
     747           83 :          if (ktherm == 1) &
     748           18 :          write(nu_diag,1030) ' conduct                   = ', trim(conduct)
     749           83 :          write(nu_diag,1005) ' emissivity                = ', emissivity
     750           83 :          if (ktherm == 2) then
     751           65 :          write(nu_diag,1005) ' a_rapid_mode              = ', a_rapid_mode
     752           65 :          write(nu_diag,1005) ' Rac_rapid_mode            = ', Rac_rapid_mode
     753           65 :          write(nu_diag,1005) ' aspect_rapid_mode         = ', aspect_rapid_mode
     754           65 :          write(nu_diag,1005) ' dSdt_slow_mode            = ', dSdt_slow_mode
     755           65 :          write(nu_diag,1005) ' phi_c_slow_mode           = ', phi_c_slow_mode
     756           65 :          write(nu_diag,1005) ' phi_i_mushy               = ', phi_i_mushy
     757           65 :          write(nu_diag,1005) ' Tliquidus_max             = ', Tliquidus_max
     758              :          endif
     759              : 
     760           83 :          write(nu_diag,1030) ' atmbndy                   = ', trim(atmbndy)
     761           83 :          write(nu_diag,1010) ' formdrag                  = ', formdrag
     762           83 :          write(nu_diag,1010) ' highfreq                  = ', highfreq
     763           83 :          write(nu_diag,1020) ' natmiter                  = ', natmiter
     764           83 :          write(nu_diag,1005) ' atmiter_conv              = ', atmiter_conv
     765           83 :          write(nu_diag,1010) ' calc_strair               = ', calc_strair
     766           83 :          write(nu_diag,1010) ' calc_Tsfc                 = ', calc_Tsfc
     767           83 :          write(nu_diag,1010) ' calc_dragio               = ', calc_dragio
     768           83 :          write(nu_diag,1005) ' floediam                  = ', floediam
     769           83 :          write(nu_diag,1005) ' hfrazilmin                = ', hfrazilmin
     770              : 
     771           83 :          write(nu_diag,1030) ' atm_data_type             = ', trim(atm_data_type)
     772           83 :          write(nu_diag,1030) ' ocn_data_type             = ', trim(ocn_data_type)
     773           83 :          write(nu_diag,1030) ' bgc_data_type             = ', trim(bgc_data_type)
     774              : 
     775           83 :          write(nu_diag,*)    '  lateral_flux_type        = ', trim(lateral_flux_type)
     776              : 
     777           83 :          write(nu_diag,1030) ' atm_data_file             = ', trim(atm_data_file)
     778           83 :          write(nu_diag,1030) ' ocn_data_file             = ', trim(ocn_data_file)
     779           83 :          write(nu_diag,1030) ' bgc_data_file             = ', trim(bgc_data_file)
     780           83 :          write(nu_diag,1030) ' ice_data_file             = ', trim(ice_data_file)
     781              : 
     782           83 :          if (trim(atm_data_type)=='default') &
     783            9 :          write(nu_diag,1030) ' default_season            = ', trim(default_season)
     784              : 
     785           83 :          write(nu_diag,1030) ' cpl_frazil                = ', trim(cpl_frazil)
     786           83 :          write(nu_diag,1010) ' update_ocn_f              = ', update_ocn_f
     787           83 :          write(nu_diag,1010) ' wave_spec                 = ', wave_spec
     788           83 :          if (wave_spec) &
     789            3 :          write(nu_diag,1030) ' wave_spec_type            = ', trim(wave_spec_type)
     790           83 :          write(nu_diag,1010) ' l_mpond_fresh             = ', l_mpond_fresh
     791           83 :          write(nu_diag,1005) ' ustar_min                 = ', ustar_min
     792           83 :          write(nu_diag,1005) ' hi_min                    = ', hi_min
     793           83 :          write(nu_diag,1030) ' fbot_xfer_type            = ', trim(fbot_xfer_type)
     794           83 :          write(nu_diag,1010) ' oceanmixed_ice            = ', oceanmixed_ice
     795           83 :          write(nu_diag,1030) ' congel_freeze             = ', trim(congel_freeze)
     796           83 :          write(nu_diag,1030) ' tfrz_option               = ', trim(tfrz_option)
     797           83 :          write(nu_diag,*)    ' saltflux_option           = ', &
     798          166 :                                trim(saltflux_option)
     799           83 :          if (trim(saltflux_option) == 'constant') then
     800           81 :             write(nu_diag,1005)    ' ice_ref_salinity          = ', ice_ref_salinity
     801              :          endif
     802           83 :          write(nu_diag,1010) ' restore_ocn               = ', restore_ocn
     803           83 :          if (restore_ocn) &
     804           12 :          write(nu_diag,1005) ' trestore                  = ', trestore
     805              : 
     806              :          ! tracers
     807           83 :          write(nu_diag,1010) ' tr_iage                   = ', tr_iage
     808           83 :          write(nu_diag,1010) ' tr_FY                     = ', tr_FY
     809           83 :          write(nu_diag,1010) ' tr_lvl                    = ', tr_lvl
     810           83 :          write(nu_diag,1010) ' tr_pond_lvl               = ', tr_pond_lvl
     811           83 :          write(nu_diag,1010) ' tr_pond_topo              = ', tr_pond_topo
     812           83 :          write(nu_diag,1010) ' tr_snow                   = ', tr_snow
     813           83 :          write(nu_diag,1010) ' tr_aero                   = ', tr_aero
     814           83 :          write(nu_diag,1010) ' tr_fsd                    = ', tr_fsd
     815              : 
     816           83 :          nt_Tsfc = 1           ! index tracers, starting with Tsfc = 1
     817           83 :          ntrcr = 1             ! count tracers, starting with Tsfc = 1
     818              : 
     819           83 :          nt_qice = ntrcr + 1
     820           83 :          ntrcr = ntrcr + nilyr ! qice in nilyr layers
     821              : 
     822           83 :          nt_qsno = ntrcr + 1
     823           83 :          ntrcr = ntrcr + nslyr ! qsno in nslyr layers
     824              : 
     825           83 :          nt_sice = ntrcr + 1
     826           83 :          ntrcr = ntrcr + nilyr ! sice in nilyr layers
     827              : 
     828           83 :          nt_iage = max_ntrcr
     829           83 :          if (tr_iage) then
     830            2 :              ntrcr = ntrcr + 1
     831            2 :              nt_iage = ntrcr   ! chronological ice age
     832              :          endif
     833              : 
     834           83 :          nt_FY = max_ntrcr
     835           83 :          if (tr_FY) then
     836            8 :              ntrcr = ntrcr + 1
     837            8 :              nt_FY = ntrcr     ! area of first year ice
     838              :          endif
     839              : 
     840           83 :          nt_alvl = max_ntrcr
     841           83 :          nt_vlvl = max_ntrcr
     842           83 :          if (tr_lvl) then
     843           81 :              ntrcr = ntrcr + 1
     844           81 :              nt_alvl = ntrcr   ! area of level ice
     845           81 :              ntrcr = ntrcr + 1
     846           81 :              nt_vlvl = ntrcr   ! volume of level ice
     847              :          endif
     848              : 
     849           83 :          nt_apnd = max_ntrcr
     850           83 :          nt_hpnd = max_ntrcr
     851           83 :          nt_ipnd = max_ntrcr
     852           83 :          if (tr_pond) then            ! all explicit melt pond schemes
     853           74 :              ntrcr = ntrcr + 1
     854           74 :              nt_apnd = ntrcr
     855           74 :              ntrcr = ntrcr + 1
     856           74 :              nt_hpnd = ntrcr
     857           74 :              if (tr_pond_lvl) then
     858           69 :                  ntrcr = ntrcr + 1    ! refrozen pond ice lid thickness
     859           69 :                  nt_ipnd = ntrcr      ! on level-ice ponds (if frzpnd='hlid')
     860              :              endif
     861           74 :              if (tr_pond_topo) then
     862            5 :                  ntrcr = ntrcr + 1    !
     863            5 :                  nt_ipnd = ntrcr      ! refrozen pond ice lid thickness
     864              :              endif
     865              :          endif
     866              : 
     867           83 :          nt_smice = max_ntrcr
     868           83 :          nt_smliq = max_ntrcr
     869           83 :          nt_rhos  = max_ntrcr
     870           83 :          nt_rsnw  = max_ntrcr
     871           83 :          if (tr_snow) then
     872           12 :             nt_smice = ntrcr + 1
     873           12 :             ntrcr = ntrcr + nslyr     ! mass of ice in nslyr snow layers
     874           12 :             nt_smliq = ntrcr + 1
     875           12 :             ntrcr = ntrcr + nslyr     ! mass of liquid in nslyr snow layers
     876           12 :             nt_rhos = ntrcr + 1
     877           12 :             ntrcr = ntrcr + nslyr     ! snow density in nslyr layers
     878           12 :             nt_rsnw = ntrcr + 1
     879           12 :             ntrcr = ntrcr + nslyr     ! snow grain radius in nslyr layers
     880              :          endif
     881              : 
     882           83 :          nt_fsd = max_ntrcr
     883           83 :          if (tr_fsd) then
     884            4 :              nt_fsd = ntrcr + 1       ! floe size distribution
     885            4 :              ntrcr = ntrcr + nfsd
     886              :          end if
     887              : 
     888           83 :          nt_isosno = max_ntrcr
     889           83 :          nt_isoice = max_ntrcr
     890           83 :          if (tr_iso) then             ! isotopes
     891            2 :              nt_isosno = ntrcr + 1
     892            2 :              ntrcr = ntrcr + n_iso    ! n_iso species in snow
     893            2 :              nt_isoice = ntrcr + 1
     894            2 :              ntrcr = ntrcr + n_iso    ! n_iso species in ice
     895              :          end if
     896              : 
     897           83 :          nt_aero = max_ntrcr - 4*n_aero
     898           83 :          if (tr_aero) then
     899            3 :              nt_aero = ntrcr + 1
     900            3 :              ntrcr = ntrcr + 4*n_aero ! 4 dEdd layers, n_aero species
     901              :          endif
     902              : 
     903           83 :          if (ntrcr > max_ntrcr-1) then
     904            0 :             write(nu_diag,*) 'max_ntrcr-1 < number of namelist tracers'
     905            0 :             write(nu_diag,*) 'max_ntrcr-1 = ',max_ntrcr-1,' ntrcr = ',ntrcr
     906            0 :             call icedrv_system_abort(file=__FILE__,line=__LINE__)
     907              :          endif
     908              : 
     909           83 :          write(nu_diag,*) ' '
     910           83 :          write(nu_diag,1020) 'max_ntrcr = ', max_ntrcr
     911           83 :          write(nu_diag,1020) 'ntrcr = ', ntrcr
     912           83 :          write(nu_diag,*) ' '
     913           83 :          write(nu_diag,1020) 'nt_sice = ', nt_sice
     914           83 :          write(nu_diag,1020) 'nt_qice = ', nt_qice
     915           83 :          write(nu_diag,1020) 'nt_qsno = ', nt_qsno
     916           83 :          write(nu_diag,*)' '
     917           83 :          write(nu_diag,1020) 'ncat    = ', ncat
     918           83 :          write(nu_diag,1020) 'nilyr   = ', nilyr
     919           83 :          write(nu_diag,1020) 'nslyr   = ', nslyr
     920           83 :          write(nu_diag,1020) 'nblyr   = ', nblyr
     921           83 :          write(nu_diag,1020) 'nfsd    = ', nfsd
     922           83 :          write(nu_diag,1020) 'n_iso   = ', n_iso
     923           83 :          write(nu_diag,1020) 'n_aero  = ', n_aero
     924           83 :          write(nu_diag,*)' '
     925           83 :          write(nu_diag,1020) 'nx      = ', nx
     926           83 :          write(nu_diag,*)' '
     927              : 
     928           83 :          call icedrv_system_flush(nu_diag)
     929              : 
     930              :  1000    format (a30,2x,f9.2)  ! a30 to align formatted, unformatted statements
     931              :  1005    format (a30,2x,f10.6) ! float
     932              :  1010    format (a30,2x,l6)    ! logical
     933              :  1020    format (a30,2x,i6)    ! integer
     934              :  1030    format (a30,    a)    ! character
     935              :  1040    format (a30,2x,6i6)   ! integer
     936              :  1050    format (a30,2x,6a6)   ! character
     937              : 
     938           83 :       if (formdrag) then
     939            3 :          if (nt_apnd==0) then
     940            0 :             write(nu_diag,*)'ERROR: nt_apnd:',nt_apnd
     941            0 :             call icedrv_system_abort(file=__FILE__,line=__LINE__)
     942            3 :          elseif (nt_hpnd==0) then
     943            0 :             write(nu_diag,*)'ERROR: nt_hpnd:',nt_hpnd
     944            0 :             call icedrv_system_abort(file=__FILE__,line=__LINE__)
     945            3 :          elseif (nt_ipnd==0) then
     946            0 :             write(nu_diag,*)'ERROR: nt_ipnd:',nt_ipnd
     947            0 :             call icedrv_system_abort(file=__FILE__,line=__LINE__)
     948            3 :          elseif (nt_alvl==0) then
     949            0 :             write(nu_diag,*)'ERROR: nt_alvl:',nt_alvl
     950            0 :             call icedrv_system_abort(file=__FILE__,line=__LINE__)
     951            3 :          elseif (nt_vlvl==0) then
     952            0 :             write(nu_diag,*)'ERROR: nt_vlvl:',nt_vlvl
     953            0 :             call icedrv_system_abort(file=__FILE__,line=__LINE__)
     954              :          endif
     955              :       endif
     956              : 
     957              :       !-----------------------------------------------------------------
     958              :       ! set Icepack values
     959              :       !-----------------------------------------------------------------
     960              : 
     961              :       call icepack_init_parameters(ustar_min_in=ustar_min, Cf_in=Cf, &
     962              :            albicev_in=albicev, albicei_in=albicei, ksno_in=ksno, &
     963              :            albsnowv_in=albsnowv, albsnowi_in=albsnowi, hi_min_in=hi_min, &
     964              :            natmiter_in=natmiter, ahmax_in=ahmax, shortwave_in=shortwave, &
     965              :            atmiter_conv_in = atmiter_conv, calc_dragio_in=calc_dragio, &
     966              :            albedo_type_in=albedo_type, R_ice_in=R_ice, R_pnd_in=R_pnd, &
     967              :            R_snw_in=R_snw, dT_mlt_in=dT_mlt, rsnw_mlt_in=rsnw_mlt, &
     968              :            kstrength_in=kstrength, krdg_partic_in=krdg_partic, &
     969              :            krdg_redist_in=krdg_redist, mu_rdg_in=mu_rdg, &
     970              :            atmbndy_in=atmbndy, calc_strair_in=calc_strair, &
     971              :            formdrag_in=formdrag, highfreq_in=highfreq, &
     972              :            emissivity_in=emissivity, &
     973              :            kitd_in=kitd, kcatbound_in=kcatbound, hs0_in=hs0, &
     974              :            dpscale_in=dpscale, frzpnd_in=frzpnd, &
     975              :            rfracmin_in=rfracmin, rfracmax_in=rfracmax, &
     976              :            pndaspect_in=pndaspect, hs1_in=hs1, hp1_in=hp1, &
     977              :            floediam_in=floediam, hfrazilmin_in=hfrazilmin, &
     978              :            ktherm_in=ktherm, calc_Tsfc_in=calc_Tsfc, &
     979              :            conduct_in=conduct, a_rapid_mode_in=a_rapid_mode, &
     980              :            update_ocn_f_in=update_ocn_f, cpl_frazil_in=cpl_frazil, &
     981              :            Rac_rapid_mode_in=Rac_rapid_mode, &
     982              :            aspect_rapid_mode_in=aspect_rapid_mode, &
     983              :            dSdt_slow_mode_in=dSdt_slow_mode, &
     984              :            phi_c_slow_mode_in=phi_c_slow_mode, Tliquidus_max_in=Tliquidus_max, &
     985              :            phi_i_mushy_in=phi_i_mushy, conserv_check_in=conserv_check, &
     986              :            congel_freeze_in=congel_freeze, &
     987              :            tfrz_option_in=tfrz_option, saltflux_option_in=saltflux_option, &
     988              :            ice_ref_salinity_in=ice_ref_salinity, kalg_in=kalg, &
     989              :            fbot_xfer_type_in=fbot_xfer_type, &
     990              :            wave_spec_type_in=wave_spec_type, wave_spec_in=wave_spec, &
     991              :            sw_redist_in=sw_redist, sw_frac_in=sw_frac, sw_dtemp_in=sw_dtemp, &
     992              :            snwredist_in=snwredist, use_smliq_pnd_in=use_smliq_pnd, &
     993              :            snw_aging_table_in=snw_aging_table, &
     994              :            snwgrain_in=snwgrain, rsnw_fall_in=rsnw_fall, rsnw_tmax_in=rsnw_tmax, &
     995              :            rhosnew_in=rhosnew, rhosmin_in=rhosmin, rhosmax_in=rhosmax, &
     996           83 :            windmin_in=windmin, drhosdwind_in=drhosdwind, snwlvlfac_in=snwlvlfac)
     997              :       call icepack_init_tracer_sizes(ntrcr_in=ntrcr, &
     998              :            ncat_in=ncat, nilyr_in=nilyr, nslyr_in=nslyr, nblyr_in=nblyr, &
     999           83 :            nfsd_in=nfsd, n_iso_in=n_iso, n_aero_in=n_aero)
    1000              :       call icepack_init_tracer_flags(tr_iage_in=tr_iage, &
    1001              :            tr_FY_in=tr_FY, tr_lvl_in=tr_lvl, tr_aero_in=tr_aero, &
    1002              :            tr_iso_in=tr_iso, tr_snow_in=tr_snow, &
    1003              :            tr_pond_in=tr_pond, &
    1004              :            tr_pond_lvl_in=tr_pond_lvl, &
    1005           83 :            tr_pond_topo_in=tr_pond_topo, tr_fsd_in=tr_fsd)
    1006              :       call icepack_init_tracer_indices(nt_Tsfc_in=nt_Tsfc, &
    1007              :            nt_sice_in=nt_sice, nt_qice_in=nt_qice, &
    1008              :            nt_qsno_in=nt_qsno, nt_iage_in=nt_iage, &
    1009              :            nt_fy_in=nt_fy, nt_alvl_in=nt_alvl, nt_vlvl_in=nt_vlvl, &
    1010              :            nt_apnd_in=nt_apnd, nt_hpnd_in=nt_hpnd, nt_ipnd_in=nt_ipnd, &
    1011              :            nt_smice_in=nt_smice, nt_smliq_in=nt_smliq, &
    1012              :            nt_rhos_in=nt_rhos, nt_rsnw_in=nt_rsnw, &
    1013              :            nt_aero_in=nt_aero, nt_fsd_in=nt_fsd, &
    1014           83 :            nt_isosno_in=nt_isosno, nt_isoice_in=nt_isoice)
    1015              : 
    1016           83 :       call icepack_warnings_flush(nu_diag)
    1017           83 :       if (icepack_warnings_aborted()) call icedrv_system_abort(string=subname, &
    1018            0 :           file=__FILE__,line= __LINE__)
    1019              : 
    1020           83 :       end subroutine input_data
    1021              : 
    1022              : !=======================================================================
    1023              : 
    1024              : ! Horizontal grid initialization:
    1025              : !
    1026              : ! author: Elizabeth C. Hunke, LANL
    1027              : 
    1028           83 :       subroutine init_grid2
    1029              : 
    1030              :       integer :: i
    1031              :       real (kind=dbl_kind) :: pi, puny
    1032              :       character(len=*), parameter :: subname='(init_grid2)'
    1033              : 
    1034              :       !-----------------------------------------------------------------
    1035              :       ! query Icepack values
    1036              :       !-----------------------------------------------------------------
    1037              : 
    1038           83 :       call icepack_query_parameters(pi_out=pi,puny_out=puny)
    1039           83 :       call icepack_warnings_flush(nu_diag)
    1040           83 :       if (icepack_warnings_aborted()) call icedrv_system_abort(string=subname, &
    1041            0 :           file=__FILE__, line=__LINE__)
    1042              : 
    1043              :       !-----------------------------------------------------------------
    1044              :       ! lat, lon, cell widths, angle, land mask
    1045              :       !-----------------------------------------------------------------
    1046              : 
    1047          415 :       TLAT(:) = p5*pi  ! pi/2, North pole
    1048           83 :       TLON(:) = c0
    1049              : 
    1050          332 :       do i = 2, nx
    1051          332 :          TLAT(i) = TLAT(i-1) - p5*pi/180._dbl_kind ! half-deg increments
    1052              :       enddo
    1053              : 
    1054          415 :       tmask(:) = .true.
    1055              : 
    1056              :       !-----------------------------------------------------------------
    1057              :       ! create hemisphere masks
    1058              :       !-----------------------------------------------------------------
    1059              : 
    1060           83 :       lmask_n(:) = .false.
    1061           83 :       lmask_s(:) = .false.
    1062              : 
    1063          415 :       do i = 1, nx
    1064          332 :          if (TLAT(i) >= -puny) lmask_n(i) = .true. ! N. Hem.
    1065          415 :          if (TLAT(i) <  -puny) lmask_s(i) = .true. ! S. Hem.
    1066              :       enddo
    1067              : 
    1068           83 :       end subroutine init_grid2
    1069              : 
    1070              : !=======================================================================
    1071              : 
    1072              : ! Initialize state for the itd model
    1073              : !
    1074              : ! authors: C. M. Bitz, UW
    1075              : !          William H. Lipscomb, LANL
    1076              : 
    1077          249 :       subroutine init_state
    1078              : 
    1079              :       use icepack_intfc, only: icepack_aggregate
    1080              :       use icedrv_domain_size, only: ncat, nilyr, nslyr, nblyr, max_ntrcr
    1081              :       use icedrv_domain_size, only: n_iso, n_aero, nfsd
    1082              :       use icedrv_flux, only: sst, Tf, Tair, salinz, Tmltz
    1083              :       use icedrv_state, only: trcr_depend, aicen, trcrn, vicen, vsnon
    1084              :       use icedrv_state, only: aice0, aice, vice, vsno, trcr, aice_init
    1085              :       use icedrv_state, only: n_trcr_strata, nt_strata, trcr_base
    1086              : 
    1087              :       integer (kind=int_kind) :: &
    1088              :          i           , & ! horizontal indes
    1089              :          k           , & ! vertical index
    1090              :          it              ! tracer index
    1091              : 
    1092              :       integer (kind=int_kind) :: ntrcr
    1093              :       logical (kind=log_kind) :: tr_iage, tr_FY, tr_lvl, tr_aero, tr_fsd, tr_iso
    1094              :       logical (kind=log_kind) :: tr_pond_lvl, tr_pond_topo, tr_snow
    1095              :       integer (kind=int_kind) :: nt_Tsfc, nt_sice, nt_qice, nt_qsno, nt_iage, nt_fy
    1096              :       integer (kind=int_kind) :: nt_alvl, nt_vlvl, nt_apnd, nt_hpnd, nt_ipnd, &
    1097              :                                  nt_smice, nt_smliq, nt_rhos, nt_rsnw, &
    1098              :                                  nt_aero, nt_fsd, nt_isosno, nt_isoice
    1099              : 
    1100              :       character(len=*), parameter :: subname='(init_state)'
    1101              : 
    1102              :       !-----------------------------------------------------------------
    1103              :       ! query Icepack values
    1104              :       !-----------------------------------------------------------------
    1105              : 
    1106           83 :          call icepack_query_tracer_sizes(ntrcr_out=ntrcr)
    1107              :          call icepack_query_tracer_flags(tr_iage_out=tr_iage, &
    1108              :               tr_FY_out=tr_FY, tr_lvl_out=tr_lvl, tr_aero_out=tr_aero, &
    1109              :               tr_iso_out=tr_iso, tr_snow_out=tr_snow, &
    1110              :               tr_pond_lvl_out=tr_pond_lvl, &
    1111           83 :               tr_pond_topo_out=tr_pond_topo, tr_fsd_out=tr_fsd)
    1112              :          call icepack_query_tracer_indices(nt_Tsfc_out=nt_Tsfc, &
    1113              :               nt_sice_out=nt_sice, nt_qice_out=nt_qice, &
    1114              :               nt_qsno_out=nt_qsno, nt_iage_out=nt_iage, nt_fy_out=nt_fy, &
    1115              :               nt_alvl_out=nt_alvl, nt_vlvl_out=nt_vlvl, &
    1116              :               nt_apnd_out=nt_apnd, nt_hpnd_out=nt_hpnd, &
    1117              :               nt_ipnd_out=nt_ipnd, &
    1118              :               nt_smice_out=nt_smice, nt_smliq_out=nt_smliq, &
    1119              :               nt_rhos_out=nt_rhos, nt_rsnw_out=nt_rsnw, &
    1120              :               nt_isosno_out=nt_isosno, nt_isoice_out=nt_isoice, &
    1121           83 :               nt_aero_out=nt_aero, nt_fsd_out=nt_fsd)
    1122           83 :          call icepack_warnings_flush(nu_diag)
    1123           83 :          if (icepack_warnings_aborted()) call icedrv_system_abort(string=subname, &
    1124            0 :              file=__FILE__,line= __LINE__)
    1125              : 
    1126              :       !-----------------------------------------------------------------
    1127              :       ! Check number of layers in ice and snow.
    1128              :       !-----------------------------------------------------------------
    1129              :          if (nilyr < 1) then
    1130              :             write (nu_diag,*) 'nilyr =', nilyr
    1131              :             write (nu_diag,*) 'Must have at least one ice layer'
    1132              :             call icedrv_system_abort(file=__FILE__,line=__LINE__)
    1133              :          endif
    1134              : 
    1135              :          if (nslyr < 1) then
    1136              :             write (nu_diag,*) 'nslyr =', nslyr
    1137              :             write (nu_diag,*) 'Must have at least one snow layer'
    1138              :             call icedrv_system_abort(file=__FILE__,line=__LINE__)
    1139              :          endif
    1140              : 
    1141              :       !-----------------------------------------------------------------
    1142              :       ! Set tracer types
    1143              :       !-----------------------------------------------------------------
    1144              : 
    1145           83 :       trcr_depend(nt_Tsfc) = 0 ! ice/snow surface temperature
    1146          628 :       do k = 1, nilyr
    1147          545 :          trcr_depend(nt_sice + k - 1) = 1 ! volume-weighted ice salinity
    1148          628 :          trcr_depend(nt_qice + k - 1) = 1 ! volume-weighted ice enthalpy
    1149              :       enddo
    1150          226 :       do k = 1, nslyr
    1151          226 :          trcr_depend(nt_qsno + k - 1) = 2 ! volume-weighted snow enthalpy
    1152              :       enddo
    1153           83 :       if (tr_iage) trcr_depend(nt_iage)  = 1   ! volume-weighted ice age
    1154           83 :       if (tr_FY)   trcr_depend(nt_FY)    = 0   ! area-weighted first-year ice area
    1155           83 :       if (tr_lvl)  trcr_depend(nt_alvl)  = 0   ! level ice area
    1156           83 :       if (tr_lvl)  trcr_depend(nt_vlvl)  = 1   ! level ice volume
    1157           83 :       if (tr_pond_lvl) then
    1158           69 :                    trcr_depend(nt_apnd)  = 2+nt_alvl   ! melt pond area
    1159           69 :                    trcr_depend(nt_hpnd)  = 2+nt_apnd   ! melt pond depth
    1160           69 :                    trcr_depend(nt_ipnd)  = 2+nt_apnd   ! refrozen pond lid
    1161              :       endif
    1162           83 :       if (tr_pond_topo) then
    1163            5 :                    trcr_depend(nt_apnd)  = 0           ! melt pond area
    1164            5 :                    trcr_depend(nt_hpnd)  = 2+nt_apnd   ! melt pond depth
    1165            5 :                    trcr_depend(nt_ipnd)  = 2+nt_apnd   ! refrozen pond lid
    1166              :       endif
    1167           83 :       if (tr_snow) then
    1168           72 :          do k = 1, nslyr
    1169           60 :             trcr_depend(nt_smice + k - 1) = 2          ! ice mass in snow
    1170           60 :             trcr_depend(nt_smliq + k - 1) = 2          ! liquid mass in snow
    1171           60 :             trcr_depend(nt_rhos  + k - 1) = 2          ! effective snow density
    1172           72 :             trcr_depend(nt_rsnw  + k - 1) = 2          ! snow radius
    1173              :          enddo
    1174              :       endif
    1175           83 :       if (tr_fsd) then
    1176           41 :          do it = 1, nfsd
    1177           41 :             trcr_depend(nt_fsd + it - 1) = 0    ! area-weighted floe size distribution
    1178              :          enddo
    1179              :       endif
    1180           83 :       if (tr_iso) then  ! isotopes
    1181            8 :          do it = 1, n_iso
    1182            6 :             trcr_depend(nt_isosno) = 2          ! snow
    1183            8 :             trcr_depend(nt_isoice) = 1          ! ice
    1184              :          enddo
    1185              :       endif
    1186           83 :       if (tr_aero) then ! volume-weighted aerosols
    1187            6 :          do it = 1, n_aero
    1188            3 :             trcr_depend(nt_aero+(it-1)*4  ) = 2 ! snow
    1189            3 :             trcr_depend(nt_aero+(it-1)*4+1) = 2 ! snow
    1190            3 :             trcr_depend(nt_aero+(it-1)*4+2) = 1 ! ice
    1191            6 :             trcr_depend(nt_aero+(it-1)*4+3) = 1 ! ice
    1192              :          enddo
    1193              :       endif
    1194              : 
    1195         3621 :       do it = 1, ntrcr
    1196              :          ! mask for base quantity on which tracers are carried
    1197         3538 :          if (trcr_depend(it) == 0) then      ! area
    1198          222 :             trcr_base(it,1) = c1
    1199         3316 :          elseif (trcr_depend(it) == 1) then  ! ice volume
    1200         1190 :             trcr_base(it,2) = c1
    1201         2126 :          elseif (trcr_depend(it) == 2) then  ! snow volume
    1202          667 :             trcr_base(it,3) = c1
    1203              :          else
    1204         1459 :             trcr_base(it,1) = c1    ! default: ice area
    1205         1459 :             trcr_base(it,2) = c0
    1206         1459 :             trcr_base(it,3) = c0
    1207              :          endif
    1208              : 
    1209              :          ! initialize number of underlying tracer layers
    1210         3538 :          n_trcr_strata(it) = 0
    1211              :          ! default indices of underlying tracer layers
    1212         3538 :          nt_strata   (it,1) = 0
    1213         3621 :          nt_strata   (it,2) = 0
    1214              :       enddo
    1215              : 
    1216           83 :       if (tr_pond_lvl) then
    1217           69 :          n_trcr_strata(nt_apnd)   = 1       ! melt pond area
    1218           69 :          nt_strata    (nt_apnd,1) = nt_alvl ! on level ice area
    1219           69 :          n_trcr_strata(nt_hpnd)   = 2       ! melt pond depth
    1220           69 :          nt_strata    (nt_hpnd,2) = nt_apnd ! on melt pond area
    1221           69 :          nt_strata    (nt_hpnd,1) = nt_alvl ! on level ice area
    1222           69 :          n_trcr_strata(nt_ipnd)   = 2       ! refrozen pond lid
    1223           69 :          nt_strata    (nt_ipnd,2) = nt_apnd ! on melt pond area
    1224           69 :          nt_strata    (nt_ipnd,1) = nt_alvl ! on level ice area
    1225              :       endif
    1226           83 :       if (tr_pond_topo) then
    1227            5 :          n_trcr_strata(nt_hpnd)   = 1       ! melt pond depth
    1228            5 :          nt_strata    (nt_hpnd,1) = nt_apnd ! on melt pond area
    1229            5 :          n_trcr_strata(nt_ipnd)   = 1       ! refrozen pond lid
    1230            5 :          nt_strata    (nt_ipnd,1) = nt_apnd ! on melt pond area
    1231              :       endif
    1232              : 
    1233              :       !-----------------------------------------------------------------
    1234              :       ! Set state variables
    1235              :       !-----------------------------------------------------------------
    1236              : 
    1237              :       call set_state_var (nx, &
    1238              :           Tair  (:),   sst  (:),     &
    1239              :           Tf    (:),                 &
    1240              :           salinz(:,:), Tmltz(:,:),   &
    1241              :           aicen (:,:), trcrn(:,:,:), &
    1242           83 :           vicen (:,:), vsnon(:,:))
    1243              : 
    1244              :       !-----------------------------------------------------------------
    1245              :       ! compute aggregate ice state and open water area
    1246              :       !-----------------------------------------------------------------
    1247              : 
    1248              :       !$OMP PARALLEL DO PRIVATE(i)
    1249          415 :       do i = 1, nx
    1250          332 :          aice(i) = c0
    1251          332 :          vice(i) = c0
    1252          332 :          vsno(i) = c0
    1253        18720 :          do it = 1, max_ntrcr
    1254        18720 :             trcr(i,it) = c0
    1255              :          enddo
    1256              : 
    1257          332 :          if (tmask(i)) &
    1258              :          call icepack_aggregate(trcrn=trcrn(i,1:ntrcr,:),     &
    1259              :                                 aicen=aicen(i,:),             &
    1260              :                                 vicen=vicen(i,:),             &
    1261              :                                 vsnon=vsnon(i,:),             &
    1262              :                                 trcr=trcr (i,1:ntrcr),        &
    1263              :                                 aice=aice (i),                &
    1264              :                                 vice=vice (i),                &
    1265              :                                 vsno=vsno (i),                &
    1266              :                                 aice0=aice0(i),               &
    1267              :                                 trcr_depend=trcr_depend(1:ntrcr),     &
    1268              :                                 trcr_base=trcr_base    (1:ntrcr,:),   &
    1269              :                                 n_trcr_strata=n_trcr_strata(1:ntrcr), &
    1270              :                                 nt_strata=nt_strata    (1:ntrcr,:), &
    1271          249 :                                 Tf = Tf(i))
    1272              : 
    1273          415 :          aice_init(i) = aice(i)
    1274              : 
    1275              :       enddo
    1276              :       !$OMP END PARALLEL DO
    1277              : 
    1278           83 :       call icepack_warnings_flush(nu_diag)
    1279           83 :       if (icepack_warnings_aborted()) call icedrv_system_abort(string=subname, &
    1280            0 :           file=__FILE__, line=__LINE__)
    1281              : 
    1282           83 :       end subroutine init_state
    1283              : 
    1284              : !=======================================================================
    1285              : 
    1286              : ! Initialize state in each ice thickness category
    1287              : !
    1288              : ! authors: Elizabeth Hunke, LANL
    1289              : 
    1290          332 :       subroutine set_state_var (nx, &
    1291            0 :                                 Tair,     sst,    &
    1292            0 :                                 Tf,               &
    1293          166 :                                 salinz,   Tmltz,  &
    1294          166 :                                 aicen,    trcrn,  &
    1295           83 :                                 vicen,    vsnon)
    1296              : 
    1297              :       use icedrv_arrays_column, only: hin_max
    1298              :       use icedrv_domain_size, only: nilyr, nslyr, max_ntrcr, ncat, nfsd
    1299              : 
    1300              :       integer (kind=int_kind), intent(in) :: &
    1301              :          nx          ! number of grid cells
    1302              : 
    1303              :       real (kind=dbl_kind), dimension (:), intent(in) :: &
    1304              :          Tair       ! air temperature  (K)
    1305              : 
    1306              :       ! ocean values may be redefined here, unlike in CICE
    1307              :       real (kind=dbl_kind), dimension (:), intent(inout) :: &
    1308              :          Tf     , & ! freezing temperature (C)
    1309              :          sst        ! sea surface temperature (C)
    1310              : 
    1311              :       real (kind=dbl_kind), dimension (:,:), intent(in) :: &
    1312              :          salinz , & ! initial salinity profile
    1313              :          Tmltz      ! initial melting temperature profile
    1314              : 
    1315              :       real (kind=dbl_kind), dimension (:,:), intent(out) :: &
    1316              :          aicen , & ! concentration of ice
    1317              :          vicen , & ! volume per unit area of ice          (m)
    1318              :          vsnon     ! volume per unit area of snow         (m)
    1319              : 
    1320              :       real (kind=dbl_kind), dimension (:,:,:), intent(out) :: &
    1321              :          trcrn     ! ice tracers
    1322              :                    ! 1: surface temperature of ice/snow (C)
    1323              : 
    1324              :       ! local variables
    1325              : 
    1326              :       integer (kind=int_kind) :: &
    1327              :          i     , & ! horizontal indices
    1328              :          k     , & ! ice layer index
    1329              :          n     , & ! thickness category index
    1330              :          it        ! tracer index
    1331              : 
    1332              :       real (kind=dbl_kind) :: &
    1333              :          Tsfc, sum, hbar, &
    1334              :          rhos, Lfresh, puny, rsnw_fall
    1335              : 
    1336              :       real (kind=dbl_kind), dimension(ncat) :: &
    1337              :          ainit, hinit    ! initial area, thickness
    1338              : 
    1339              :       real (kind=dbl_kind), dimension(nilyr) :: &
    1340              :          qin             ! ice enthalpy (J/m3)
    1341              : 
    1342              :       real (kind=dbl_kind), dimension(nslyr) :: &
    1343              :          qsn             ! snow enthalpy (J/m3)
    1344              : 
    1345              :       real (kind=dbl_kind), parameter :: &
    1346              :          hsno_init = 0.25_dbl_kind   ! initial snow thickness (m)
    1347              : 
    1348              :       logical (kind=log_kind) :: tr_brine, tr_lvl, tr_fsd, tr_snow
    1349              :       integer (kind=int_kind) :: nt_Tsfc, nt_qice, nt_qsno, nt_sice, nt_fsd
    1350              :       integer (kind=int_kind) :: nt_fbri, nt_alvl, nt_vlvl
    1351              :       integer (kind=int_kind) :: nt_rhos, nt_rsnw, nt_smice, nt_smliq
    1352              : 
    1353              :       character(len=*), parameter :: subname='(set_state_var)'
    1354              : 
    1355              :       !-----------------------------------------------------------------
    1356              :       ! query Icepack values
    1357              :       !-----------------------------------------------------------------
    1358              : 
    1359              :       call icepack_query_tracer_flags(tr_brine_out=tr_brine, tr_lvl_out=tr_lvl, &
    1360           83 :            tr_fsd_out=tr_fsd, tr_snow_out=tr_snow)
    1361              :       call icepack_query_tracer_indices(nt_Tsfc_out=nt_Tsfc, nt_qice_out=nt_qice, &
    1362              :            nt_qsno_out=nt_qsno, nt_sice_out=nt_sice, nt_fsd_out=nt_fsd, &
    1363              :            nt_fbri_out=nt_fbri, nt_alvl_out=nt_alvl, nt_vlvl_out=nt_vlvl, &
    1364              :            nt_rsnw_out=nt_rsnw, nt_rhos_out=nt_rhos, &
    1365           83 :            nt_smice_out=nt_smice, nt_smliq_out=nt_smliq)
    1366              :       call icepack_query_parameters(rhos_out=rhos, Lfresh_out=Lfresh, puny_out=puny, &
    1367           83 :            rsnw_fall_out=rsnw_fall)
    1368           83 :       call icepack_warnings_flush(nu_diag)
    1369           83 :       if (icepack_warnings_aborted()) call icedrv_system_abort(string=subname, &
    1370            0 :          file=__FILE__,line= __LINE__)
    1371              : 
    1372              :       !-----------------------------------------------------------------
    1373              :       ! Initialize state variables.
    1374              :       ! If restarting, these values are overwritten.
    1375              :       !-----------------------------------------------------------------
    1376              : 
    1377          486 :       do n = 1, ncat
    1378         2015 :          do i = 1, nx
    1379         1612 :             aicen(i,n) = c0
    1380         1612 :             vicen(i,n) = c0
    1381         1612 :             vsnon(i,n) = c0
    1382         1612 :             trcrn(i,nt_Tsfc,n) = Tf(i)  ! surface temperature
    1383              :             if (max_ntrcr >= 2) then
    1384        91124 :                do it = 2, max_ntrcr
    1385        91124 :                   trcrn(i,it,n) = c0
    1386              :                enddo
    1387              :             endif
    1388         1612 :             if (tr_lvl)   trcrn(i,nt_alvl,n) = c1
    1389         1612 :             if (tr_lvl)   trcrn(i,nt_vlvl,n) = c1
    1390         1612 :             if (tr_brine) trcrn(i,nt_fbri,n) = c1
    1391        12464 :             do k = 1, nilyr
    1392        12464 :                trcrn(i,nt_sice+k-1,n) = salinz(i,k)
    1393              :             enddo
    1394         4827 :             do k = 1, nslyr
    1395         4424 :                trcrn(i,nt_qsno+k-1,n) = -rhos * Lfresh
    1396              :             enddo
    1397              :          enddo
    1398          403 :          ainit(n) = c0
    1399          486 :          hinit(n) = c0
    1400              :       enddo
    1401              : 
    1402              :       !-----------------------------------------------------------------
    1403              :       ! For Icepack testing, the grid vector is populated with several
    1404              :       ! different ice distributions, including ice-free, a single-
    1405              :       ! thickness slab, a full thickness distribution (as in CICE),
    1406              :       ! and land
    1407              :       !-----------------------------------------------------------------
    1408              : 
    1409           83 :       i = 1  ! ice-free
    1410              :              ! already initialized above
    1411              : 
    1412              :       !-----------------------------------------------------------------
    1413              : 
    1414           83 :       i = 2  ! 2-m slab, no snow
    1415           83 :       if (i <= nx) then
    1416              :       if (3 <= ncat) then
    1417           80 :          n = 3
    1418           80 :          ainit(n) = c1  ! assumes we are using the default ITD boundaries
    1419           80 :          hinit(n) = c2
    1420              :       else
    1421            3 :          ainit(ncat) = c1
    1422            3 :          hinit(ncat) = c2
    1423              :       endif
    1424          486 :       do n = 1, ncat
    1425              :          ! ice volume, snow volume
    1426          403 :          aicen(i,n) = ainit(n)
    1427          403 :          vicen(i,n) = hinit(n) * ainit(n) ! m
    1428          403 :          vsnon(i,n) = c0
    1429              :          ! tracers
    1430              :          call icepack_init_enthalpy(Tair = Tair(i),     &
    1431              :                                 Tf       = Tf(i),       &
    1432              :                                 Sprofile = salinz(i,:), &
    1433              :                                 Tprofile = Tmltz(i,:),  &
    1434              :                                 Tsfc     = Tsfc,        &
    1435          403 :                                 qin=qin(:), qsn=qsn(:))
    1436              : 
    1437              :          ! floe size distribution
    1438          403 :          if (tr_fsd) call icepack_init_fsd(ice_ic=ice_ic, &
    1439           20 :                                   afsd=trcrn(i,nt_fsd:nt_fsd+nfsd-1,n))
    1440              :          ! surface temperature
    1441          403 :          trcrn(i,nt_Tsfc,n) = Tsfc ! deg C
    1442              :          ! ice enthalpy, salinity
    1443         3116 :          do k = 1, nilyr
    1444         2713 :             trcrn(i,nt_qice+k-1,n) = qin(k)
    1445         3116 :             trcrn(i,nt_sice+k-1,n) = salinz(i,k)
    1446              :          enddo
    1447              :          ! snow enthalpy
    1448         1106 :          do k = 1, nslyr
    1449         1106 :             trcrn(i,nt_qsno+k-1,n) = qsn(k)
    1450              :          enddo               ! nslyr
    1451              :          ! brine fraction
    1452          403 :          if (tr_brine) trcrn(i,nt_fbri,n) = c1
    1453              :          ! snow radius, effective density, ice and liquid mass content
    1454          486 :          if (tr_snow) then
    1455          360 :             do k = 1, nslyr
    1456          300 :                trcrn(i,nt_rsnw +k-1,n) = rsnw_fall
    1457          300 :                trcrn(i,nt_rhos +k-1,n) = rhos
    1458          300 :                trcrn(i,nt_smice+k-1,n) = rhos
    1459          360 :                trcrn(i,nt_smliq+k-1,n) = c0
    1460              :             enddo               ! nslyr
    1461              :          endif
    1462              :       enddo                  ! ncat
    1463           83 :       call icepack_warnings_flush(nu_diag)
    1464           83 :       if (icepack_warnings_aborted()) call icedrv_system_abort(string=subname, &
    1465            0 :           file=__FILE__, line=__LINE__)
    1466              : 
    1467              :       endif  ! (i <= nx)
    1468              :       !-----------------------------------------------------------------
    1469              : 
    1470           83 :       i = 3  ! full thickness distribution
    1471           83 :       if (i <= nx) then
    1472              :       ! initial category areas in cells with ice
    1473           83 :       hbar = c3  ! initial ice thickness with greatest area
    1474              :       ! Note: the resulting average ice thickness
    1475              :       ! tends to be less than hbar due to the
    1476              :       ! nonlinear distribution of ice thicknesses
    1477              : 
    1478           83 :       sum = c0
    1479          486 :       do n = 1, ncat
    1480          403 :          if (n < ncat) then
    1481          320 :             hinit(n) = p5*(hin_max(n-1) + hin_max(n)) ! m
    1482              :          else                ! n=ncat
    1483           83 :             hinit(n) = (hin_max(n-1) + c1) ! m
    1484              :          endif
    1485              :          ! parabola, max at h=hbar, zero at h=0, 2*hbar
    1486          403 :          ainit(n) = max(c0, (c2*hbar*hinit(n) - hinit(n)**2))
    1487          486 :          sum = sum + ainit(n)
    1488              :       enddo
    1489          486 :       do n = 1, ncat
    1490          486 :          ainit(n) = ainit(n) / (sum + puny/ncat) ! normalize
    1491              :       enddo
    1492              : 
    1493          486 :       do n = 1, ncat
    1494              :          ! ice volume, snow volume
    1495          403 :          aicen(i,n) = ainit(n)
    1496          403 :          vicen(i,n) = hinit(n) * ainit(n) ! m
    1497          403 :          vsnon(i,n) = min(aicen(i,n)*hsno_init,p2*vicen(i,n))
    1498              :          ! tracers
    1499              :          call icepack_init_enthalpy(Tair = Tair(i),     &
    1500              :                                 Tf       = Tf(i),       &
    1501              :                                 Sprofile = salinz(i,:), &
    1502              :                                 Tprofile = Tmltz(i,:),  &
    1503              :                                 Tsfc     = Tsfc,        &
    1504          403 :                                 qin=qin(:), qsn=qsn(:))
    1505              :          ! floe size distribution
    1506          403 :          if (tr_fsd) call icepack_init_fsd(ice_ic=ice_ic, &
    1507           20 :                                   afsd=trcrn(i,nt_fsd:nt_fsd+nfsd-1,n))
    1508              : 
    1509              :          ! surface temperature
    1510          403 :          trcrn(i,nt_Tsfc,n) = Tsfc ! deg C
    1511              :          ! ice enthalpy, salinity
    1512         3116 :          do k = 1, nilyr
    1513         2713 :             trcrn(i,nt_qice+k-1,n) = qin(k)
    1514         3116 :             trcrn(i,nt_sice+k-1,n) = salinz(i,k)
    1515              :          enddo
    1516              :          ! snow enthalpy
    1517         1106 :          do k = 1, nslyr
    1518         1106 :             trcrn(i,nt_qsno+k-1,n) = qsn(k)
    1519              :          enddo               ! nslyr
    1520              :          ! brine fraction
    1521          403 :          if (tr_brine) trcrn(i,nt_fbri,n) = c1
    1522              :          ! snow radius, effective density, ice and liquid mass content
    1523          486 :          if (tr_snow) then
    1524          360 :             do k = 1, nslyr
    1525          300 :                trcrn(i,nt_rsnw +k-1,n) = rsnw_fall
    1526          300 :                trcrn(i,nt_rhos +k-1,n) = rhos
    1527          300 :                trcrn(i,nt_smice+k-1,n) = rhos
    1528          360 :                trcrn(i,nt_smliq+k-1,n) = c0
    1529              :             enddo               ! nslyr
    1530              :          endif
    1531              :       enddo                  ! ncat
    1532           83 :       call icepack_warnings_flush(nu_diag)
    1533           83 :       if (icepack_warnings_aborted()) call icedrv_system_abort(string=subname, &
    1534            0 :           file=__FILE__, line=__LINE__)
    1535              : 
    1536              :       endif  ! (i <= nx)
    1537              : 
    1538              :       !-----------------------------------------------------------------
    1539              : 
    1540              :       ! land
    1541              :       ! already initialized above (tmask = 0)
    1542           83 :       i = 4
    1543           83 :       if (i <= nx) then
    1544           83 :          tmask(i) = .false.
    1545           83 :          sst(i) = c0
    1546           83 :          Tf(i) = c0
    1547              :       endif
    1548              : 
    1549           83 :       end subroutine set_state_var
    1550              : 
    1551              : !=======================================================================
    1552              : 
    1553              : !  Initialize floe size distribution tracer (call prior to reading restart data)
    1554              : 
    1555           83 :       subroutine init_fsd
    1556              : 
    1557              :       use icedrv_arrays_column, only: wavefreq, dwavefreq, wave_sig_ht, &
    1558              :          wave_spectrum, d_afsd_newi, d_afsd_latg, d_afsd_latm, &
    1559              :          d_afsd_wave, d_afsd_weld
    1560              : 
    1561           83 :       wavefreq       (:)   = c0
    1562           83 :       dwavefreq      (:)   = c0
    1563           83 :       wave_sig_ht    (:)   = c0
    1564           83 :       wave_spectrum  (:,:) = c0
    1565           83 :       d_afsd_newi    (:,:) = c0
    1566           83 :       d_afsd_latg    (:,:) = c0
    1567           83 :       d_afsd_latm    (:,:) = c0
    1568           83 :       d_afsd_wave    (:,:) = c0
    1569           83 :       d_afsd_weld    (:,:) = c0
    1570              : 
    1571           83 :       end subroutine init_fsd
    1572              : 
    1573              : !=======================================================================
    1574              : 
    1575              :   end module icedrv_init
    1576              : 
    1577              : !=======================================================================
        

Generated by: LCOV version 2.0-1