# ICON
#
# ------------------------------------------
# Copyright (C) 2004-2026, DWD, MPI-M, DKRZ, KIT, ETH, MeteoSwiss
# Contact information: icon-model.org
# See AUTHORS.TXT for a list of authors
# See LICENSES/ for license information
# SPDX-License-Identifier: BSD-3-Clause
# ------------------------------------------

# --------------------------------------------------------------------
# CASE_SETUP
# --------------------------------------------------------------------
#
# Purpose of this document:
#   This file contains the experiment parameters of the
#   ICON test case
#
# Corresponding author:
#   Florian Prill, DWD, mailto:florian.prill@dwd.de
#
# Document version:
#   $LastChangedDate: 2012-04-11 11:18:42 +0000 (Wed, 11 Apr 2012) $
#   $Rev: 8630 $ -- $Author: florian.prill $
#
# --------------------------------------------------------------------


# output directory
EXPDIR=${outbasedir}/${INITIME}
# grid directory
GRIDDIR=${inputdir}/grids
# external parameter directory
EXTPARDIR=${inputdir}/extpar
# IFS2ICON data directory
IFS2ICONDIR=${ifsdir}
# path to files needed for radiation
RADDIR=${inputdir}/radiation
# path to files needed for ECRAD radiation
ecRad_data_path=${sccodedir}/externals/ecrad/data

# --------------------------------------------------------------------


# the directory for the experiment will be created, if not already there
if [ ! -d $EXPDIR ]; then
    mkdir -p $EXPDIR
fi
cd $EXPDIR

# grid parameters
atmo_dyn_grids=icon_grid_${res}_G.nc
atmo_dyn_ginfo=icon_grid_${res}_G-grfinfo.nc
atmo_rad_grids=icon_grid_${resrad}_R.nc
atmo_rad_ginfo=icon_grid_${resrad}_R-grfinfo.nc
extpar_filename=icon_extpar_${res}_G.nc
ifs2icon_filename=icon2icon_${res}_DOM01.grb

ln -sf $GRIDDIR/icon_grid_*_${res}_G.nc             ${atmo_dyn_grids}
ln -sf $GRIDDIR/icon_grid_*_${res}_G-grfinfo.nc     ${atmo_dyn_ginfo}
ln -sf $GRIDDIR/icon_grid_*_${resrad}_R.nc          ${atmo_rad_grids}
ln -sf $GRIDDIR/icon_grid_*_${resrad}_R-grfinfo.nc  ${atmo_rad_ginfo}
ln -sf $EXTPARDIR/icon_extpar_*_${res}_G.nc         ${extpar_filename}
ln -sf $IFS2ICONDIR/${ifs2icon_filename}            ${ifs2icon_filename}

# global timing
start_date=`echo $INITIME | awk '{print substr($0,1,4)"-"substr($0,5,2)"-"substr($0,7,2)"T"substr($0,9,2)":00:00Z"}'`
ndays_restart=60
dt_restart=`expr ${ndays_restart} \* 86400`

# model timing
dtime=${dtime}  # advect, phys   R2B4:600  R2B5:450  R2B6:360  R2B7:180  R3B7:120  R2B8:90
dtconv=600      # conv, SSO, GWD R2B4:600  R2B5:900  R2B6:720  R2B7:360  R3B7:600  R2B8:360
dtrad=1800      # rad            R2B4:3600 R2B5:3600 R2B6:3600 R2B7:1800 R3B7:1800 R2B8:1800
dtsso=600
dtgwd=600
ninc_mtgrm=30   # output interval 3600s             (25)
ndays=${ndays}  # number of days to run
#nsteps=`expr ${ndays} \* 86400 / ${dtime}`
nsteps=$(( round(ndays * 86400 / dtime) ))       # will be rounded

# model parameters
atmo_namelist=NAMELIST_${basename}
model_equations=3      #  3=non-hydrost. atm.,


# ----------------------------------------------------------------------------
# create ICON master namelist
# ----------------------------------------------------------------------------

cat > icon_master.namelist << EOF

&master_nml
 lrestart                     = .FALSE.
/
&time_nml
 ini_datetime_string          = "$start_date"
 dt_restart                   = $dt_restart
/
&master_model_nml
  model_type                  = 1
  model_name                  = "ATMO"
  model_namelist_filename     = "$atmo_namelist"
  model_min_rank              = 1
  model_max_rank              = 65536
  model_inc_rank              = 1
/
EOF

# ----------------------------------------------------------------------------
# model namelists
# ----------------------------------------------------------------------------

# reconstrcuct the grid parameters in namelist form
dynamics_grid_filename=""
for gridfile in ${atmo_dyn_grids}; do
  dynamics_grid_filename="${dynamics_grid_filename} '${gridfile}',"
done
radiation_grid_filename=""
for gridfile in ${atmo_rad_grids}; do
  radiation_grid_filename="${radiation_grid_filename} '${gridfile}',"
done


#-----------------------------------------------------------------------------
# output variables

ml_varlist="'temp','u','v','w','pres','pres_sfc', 'pres_msl',
'qv','qc','qi','qr','qs','o3','clc','tot_qv_dia','tot_qc_dia','tot_qi_dia',
'clct','clch','clcm','clcl', 'tqv_dia', 'tqc_dia', 'tqi_dia', 'tqv', 'tqc', 'tqi', 'tqr', 'tqs',
'tot_prec','rain_gsp','rain_con','snow_gsp','snow_con',
'u_10m','v_10m','sp_10m', 't_2m', 'td_2m', 'qv_2m',
'accshfl_s','acclhfl_s',  'accthb_s','accthb_t','accsob_s','accsob_t',
'ddt_temp_dyn', 'ddt_temp_radsw', 'ddt_temp_radlw',  'ddt_temp_turb', 'ddt_temp_drag', 'ddt_temp_pconv',
'ddt_u_turb', 'ddt_u_sso', 'ddt_u_gwd', 'ddt_u_pconv', 'ddt_v_turb', 'ddt_v_sso',
'ddt_v_gwd', 'ddt_v_pconv', 'ddt_qv_turb', 'ddt_qv_conv',
'ddt_temp_gscp','ddt_qv_gscp','ddt_qc_gscp','ddt_qi_gscp',
't_g', 't_ice','h_ice', 't_so', 'w_so', 'fr_seaice', 't_seasfc', 'cape',
'snowfrac', 'w_snow', 'h_snow'"
#'dzh_snow', 't_snow_mult', 'rho_snow_mult'
#'t_so_t_1', 'w_so_t_1', 'w_snow_t_1'"

#ml_varlist="'extra_3d1', 'extra_3d2', 'extra_3d3', 'extra_3d4'"
pl_varlist="'u','v','temp','geopot','clc','tot_qv_dia','tot_qc_dia','tot_qi_dia','qv','qc','qi'"
hl_varlist="'u','v','temp','pres',  'clc','tot_qv_dia','tot_qc_dia','tot_qi_dia','qv','qc','qi'"

# ---

cat > ${atmo_namelist} << EOF
&parallel_nml
 nproma                       = ${nproma}     ! 4
 p_test_run                   = .FALSE.
 l_test_openmp                = .FALSE.
 l_log_checks                 = .FALSE.
 num_io_procs                 = 16
 iorder_sendrecv              = 3
/
&grid_nml
 dynamics_grid_filename       = ${dynamics_grid_filename}
 radiation_grid_filename      = ${radiation_grid_filename}
 dynamics_parent_grid_id      = 0
 lredgrid_phys                = .TRUE.
 lfeedback                    = .TRUE.
 ifeedback_type               = 2
/
&initicon_nml
 init_mode                    = 1           ! initialization mode (2 for IFS ana, 1 for DWD ana)
 zpbl1                        = 500.
 zpbl2                        = 1000.
 dwdfg_filename               = '${ifs2icon_filename}'
 lread_ana                    = .false.
 ana_varnames_map_file        = '${sccodedir}/run/ana_varnames_map_file.txt'
 filetype                     = 2
 ltile_coldstart              =.true.
/
&run_nml
 num_lev                      = 90
 lvert_nest                   = .TRUE.
 nsteps                       = ${nsteps}
 dtime                        = ${dtime}    ! timestep in seconds
 ldynamics                    = .TRUE.      ! dynamics
 ltransport                   = .TRUE.
 ntracer                      = 5
 iforcing                     = 3           ! NWP forcing
 ltestcase                    = .FALSE.     ! false: run with real data
 msg_level                    = 5           ! default: 5, much more: 20
 ltimer                       = .FALSE.
 timers_level                 = 4
 activate_sync_timers         = .FALSE.
 output                       = "nml"
/
&io_nml
 lflux_avg                    = .FALSE.     ! false: accumulated fluxes
 itype_pres_msl               = 5           ! 3: new IFS T and pressure calculation below ground
                                            ! 4: IFS method with bug fix for self-consistency between SLP and geopotential
 itype_rh                     = 1           ! RH w.r.t. water
!inextra_2d                   = 2           ! 2D extra variables
!inextra_3d                   = 4           ! 3D extra variables
/
! OUTPUT: Regular grid, model levels, all domains
&output_nml
 filetype                     =  2                        ! output format: 2=GRIB2, 4=NETCDFv2
 dom                          = -1                        ! write all domains
 output_time_unit             =  1                        ! 1: seconds
 output_bounds                =  0., 10000000., 43200.    ! start, end, increment
 steps_per_file               =  40
 mode                         =  1  ! 1: forecast mode (relative t-axis), 2: climate mode (absolute t-axis)
 taxis_tunit                  =  3  ! output time unit, 3: hours, 2:min, 1:sec
 include_last                 = .TRUE.
 output_filename              = '${basename}'             ! file name base
 ml_varlist                   = ${ml_varlist}
 pl_varlist                   = ${pl_varlist}
 !hl_varlist                  = ${hl_varlist}
 p_levels                     = 100,200,300,500,700,1000,2000,3000,5000,7000,10000,15000,20000,25000,
                                30000,40000,50000,60000,70000,80000,85000,90000,92500,95000,100000
 !h_levels                    = 50000,45000,40000,35000,30000,25000,20000,18000,16000,14000,12000,
 !                              10000,8000,6000,5000,4000,3000,2000,1000,800,600,400,200,100,10
 output_grid                  = .FALSE.
 remap                        = 1                         ! 1: latlon,  0: native grid
 reg_lon_def                  =  0., 1.0, 359.
 reg_lat_def                  = 90.,-1.0, -90.
!namespace                    = "ECMWF"                   ! may give problems with metview - leave default ecmwf
/
&gribout_nml
 generatingCenter             = 98                        ! ECMWF
 generatingSubcenter          = 0                         ! ECMWF
!generatingCenter             = 78                        ! DWD
!generatingSubcenter          = 255                       ! DWD
/
&meteogram_output_nml
 lmeteogram_enabled= .TRUE.
 n0_mtgrm          = 0              ! meteogram initial time step (0 is first step!)
 ninc_mtgrm        = ${ninc_mtgrm}  ! meteogram output interval
 max_time_stamps   = 5000
 ldistributed      = .false.        ! Lat,Lon
 stationlist_tot   =  50.16,   8.75, 'Offenbach',
                      52.17,  14.12, 'Lindenberg',
                      51.97,   4.93, 'Cabauw',
                     -10.08, -61.93, 'LBA_Rondonia',
                      13.50,   2.5 , 'Niamey',
                      36.61, -97.49, 'ARM_Southern_Great_Plains',
                      71.32, 156.62, 'ARM_North_Slope_of_Alaska_Barrow',
                      -2.06, 147.43, 'ARM_Tropical_W_Pacific_Manus',
                     -12.43, 130.89, 'ARM_Tropical_W_Pacific_Darwin',
                     -20.00,-120.00, 'Tropical Ocean cumumulus',
                     -20.00, -85.00, 'Tropical Ocean IMET strcu',
                      60.00,  80.00, 'Snow Test Russia',
                      46.81,   6.94, 'Payerne',
                      67.36,  26.64, 'Sodankyla',
                      54.015,  6.588,'FINO1',
                      55.007, 13.154,'FINO2',
                      55.195,  7.158,'FINO3'
/
&nwp_phy_nml
 inwp_gscp                    = 1
 inwp_convection              = 1
 inwp_radiation               = 4
 inwp_cldcover                = 1   ! 0: no cld, 1: new diagnostic, 3: COSMO, 5: grid scale
 inwp_turb                    = 1   ! 1/10: Raschendorfer, 2: GME
 inwp_satad                   = 1
 inwp_sso                     = 1
 inwp_gwd                     = 1
 inwp_surface                 = 1
 latm_above_top               = .true.
 itype_z0                     = 2   ! 1: default, 2: turn off SSO part of z0
 dt_conv                      = ${dtconv}
 dt_sso                       = ${dtsso}
 dt_gwd                       = ${dtgwd}
 dt_rad                       = ${dtrad}
 efdt_min_raylfric            = 3600.
 icapdcycl                    = 3
 icpl_aero_conv               = 1
 icpl_aero_gscp               = 1
 icpl_o3_tp                   = 1
!lsgs_cond                    = .false. !! ! SGS cloud condensation
!lcalculate_fsd               = .true.  ! FSD: true
 ldetrain_conv_prec           = .false.
 mu_rain                      = 0.5
 rain_n0_factor               = 0.1
/
&nwp_tuning_nml
 itune_albedo                 = 0       ! somewhat reduced albedo (w.r.t. MODIS data) over Sahara in order to reduce cold bias
 tune_zceff_min               = 0.01    ! ** default value to be used for R3B7; use 0.025 for R2B6 in order to get similar temperature biases in upper troposphere **
 tune_gkdrag                  = 0.075   ! R2B6: 0.075, R3B7: 0.08
 tune_gkdrag_enh              = 0.16
 tune_gkwake                  = 1.5     ! R2B6: 1.5,   R3B7: 0.65
 tune_gfluxlaun               = 0.00375
 tune_gfrcrit                 = 0.425   ! R2B6: 0.425, R3B7: 0.35
 tune_grcrit                  = 0.5
 tune_grcrit_enh              = 0.65
 tune_dust_abs                = 1.
 tune_zvz0i                   = 0.90
 tune_box_liq_asy             = 3.25    ! oper global: 3.0 , oper D2: 3.25, default: 2.5
!tune_box_liq                 = 0.05
 tune_rcucov                  = 0.075
 tune_rhebc_land              = 0.825
 tune_gust_factor             = 7.0
 tune_gustsso_lim             = 20.0
 tune_minsso                  = 1.0
 tune_eiscrit                 = 7.0     ! estimated inversion strength to turn off shallow cumulus
 tune_sc_eis                  = 7.0
 icpl_turb_clc                = 1
 max_calibfac_clcl            = 4       ! eps: 1.5  det: 4.0
 lcalib_clcov                 = .false. ! turn off TCC, HCC, MCC, LCC tuning
 ! SSO with MERIT data
 itune_gust_diag              = 2
 tune_blockred                = 1.5
 tune_minsso                  = 1.
 tune_minsso_gwd              = 40.
 tune_capethresh              = 2000.
/
&turbdiff_nml
 a_hshr                       = 1.25
 alpha0                       = 0.0123
 alpha0_max                   = 0.0335
 alpha1                       = 0.125
 c_diff                       = 0.2
 frcsmot                      = 0       ! these 2 switches together apply vertical smoothing of the TKE source terms
!imode_frcsmot                = 2       ! in the tropics (only), which reduces the moist bias in the tropical lower troposphere
 icldm_turb                   = 1       ! 2: Gauss clouds for turbulence    1: grid scale clouds
!icldm_tran                   = 2       ! 2: Gauss clouds for surface layer 1: grid scale clouds
 imode_charpar                = 3
 imode_snowsmot               = 2
! use horizontal shear production terms with 1/SQRT(Ri) scaling to prevent unwanted side effects:
 itype_sher                   = 3       ! use horizontal shear production terms with 1/SQRT(Ri) scaling to prevent unwanted side effects
 ltkesso                      = .true.  ! SSO dissipation energy used in TKE equation
 ltkeshs                      = .true.
 pat_len                      = 750.
 rat_sea                      = 0.875
 rlam_heat                    = 10.0
 tkhmin                       = 0.6
 tkhmin_strat                 = 1.0
 tkmmin                       = 0.75
 tkmmin_strat                 = 4
/
&lnd_nml
 ntiles                       = 3
 nlev_snow                    = 3       ! 2 for multi-level snow
 lmulti_snow                  = .false. ! true: multi-level snow, false:single-level snow
 itype_heatcond               = 3       ! 1: fixed heatcond, 2: moisture dependent heatcond
 idiag_snowfrac               = 20
 lsnowtile                    = .true.  ! true: allow separate snow and snow-free tiles
 lseaice                      = .true.
 llake                        = .true.
 lprog_albsi                  = .true.
 itype_canopy                 = 2       ! Peter Schulz skin temperature
 itype_lndtbl                 = 4       ! 2: tuned stomata resistance rsmin
 itype_root                   = 2       ! 2: exponetial root distribution, 1: roots at level 3
 itype_evsl                   = 4
 itype_trvg                   = 3
 cwimax_ml                    = 5.e-4
 c_soil                       = 1.25
 c_soil_urb                   = 0.5
 sstice_mode                  = 2
 lbottom_hflux                = .true.
 itype_snowevap               = 2
 itype_oskin_warm             = 1
/
&radiation_nml
 irad_o3                      = 79          ! 6: GME, 7: GEMS, 9: MACC, 97: oper (mix)
 irad_aero                    = 6
 izenith                      = 4           ! 4: NWP default, 3: no annual cycle
 albedo_type                  = 2           ! 2: Modis albedo
!direct_albedo                = 4
 direct_albedo_water          = 3
 albedo_whitecap              = 1
 vmr_cfc11                    = 220.e-12
 vmr_cfc12                    = 490.e-12
 vmr_ch4                      = 1900.e-09
 vmr_co2                      = 425.e-06   ! values representative for 2023
 vmr_n2o                      = 334.0e-09
 vmr_o2                       = 0.20946
!ecRad_isolver                = 3           ! 0: McICA, 1: Tripleclouds, 3: Spartacus
!ecRad_llw_cloud_scat         = .true.
!ecrad_igas_model             = 1           ! 0: RRTM gas model, 1: ecckd gas model
!llw_cloud_scat               = .true.
!iliquid_scat                 = 1           ! 0: SOCRATES liquid optics, 1: Slingo
!iice_scat                    = 1           ! 0: Fu ice optics, 1: Buran
!icld_overlap                 = 1           ! 1: max/random, 2: generalized (default)
!fsd_default                  = 0.75
 ecRad_data_path              = '${ecRad_data_path}'
/
&nonhydrostatic_nml
 iadv_rhotheta                = 2
 ivctype                      = 2
 itime_scheme                 = 4
 exner_expol                  = 0.6
 vwind_offctr                 = 0.2         ! 0.2 for R2B6 and higher resolution, 0.3 for lower resolution
 damp_height                  = 43500
 rayleigh_coeff               = 1
 divdamp_order                = 24          ! 2 ass, 24 fc
 divdamp_type                 = 32          ! optional: 2 assimilation cycle, 32 forecast
 divdamp_fac                  = 0.004       ! 0.004 for R2B6; recommendation for R3B7: 0.003
 divdamp_trans_start          = 12500
 divdamp_trans_end            = 17500
 igradp_method                = 3
 l_zdiffu_t                   = .true.
 thslp_zdiffu                 = 0.02
 thhgtd_zdiffu                = 125.
 htop_moist_proc              = 22500.
 hbot_qvsubstep               = 16000.
 vcfl_threshold               = 1.00
 nlev_hcfl                    = 10
/
&sleve_nml
 min_lay_thckn                = 20.         ! lowest level thickness (between half-levels)
 max_lay_thckn                = 400.        ! maximum layer thickness below htop_thcknlimit
 htop_thcknlimit              = 14000.
 top_height                   = 75000.
 stretch_fac                  = 0.9
 decay_scale_1                = 4000.
 decay_scale_2                = 2500.
 decay_exp                    = 1.2
 flat_height                  = 16000.
/
&dynamics_nml
 divavg_cntrwgt               = 0.50
 lcoriolis                    = .true.
 lmoist_thdyn                 = .true.
/
&transport_nml
 ctracer_list                 = '12345'
 ivadv_tracer                 = 3,3,3,3,3
 itype_hlimit                 = 3,4,4,4,4
 ihadv_tracer                 = 52,2,2,2,2
 llsq_svd                     = .true.
/
&diffusion_nml
 hdiff_order                  = 5
 itype_vn_diffu               = 1
 itype_t_diffu                = 2
 hdiff_efdt_ratio             = 24.0   ! for R2B6: 24.0;  recommendation for R3B7: 30.0
 hdiff_smag_fac               = 0.025  ! for R2B6: 0.025; recommendation for R3B7: 0.02
 lhdiff_vn                    = .true.
 lhdiff_temp                  = .true.
/
&interpol_nml
 nudge_zone_width             = 8
 lsq_high_ord                 = 3
 l_intp_c2l                   = .true.
 l_mono_c2l                   = .true.
!support_baryctr_intp         = .true.
/
&extpar_nml
 itopo                        = 1
 itype_lwemiss                = 2           ! requires new extpar file
 itype_vegetation_cycle       = 3
 n_iter_smooth_topo           = 1,1
 heightdiff_threshold         = 3000.
 hgtdiff_max_smooth_topo      = 750.,750.,
 extpar_filename              = '${extpar_filename}'
 read_nc_via_cdi              = .true.
 ! SSO with MERIT data
 !!pp_sso                     = 2
/
EOF


#-----------------------------------------------------------------------------
