#!/bin/bash
#
#################################################
# batch settings for INT2LM run on mistral at DKRZ
#################################################
#SBATCH --job-name=sp_int2lm
#SBATCH --partition=compute
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=1
#SBATCH --time=01:00:00
#SBATCH --exclusive
#SBATCH --output=sp_int2lm.o%j
#SBATCH --error=sp_int2lm.o%j
#SBATCH --account=bb0105

# ulimit: the setting of the stack size instead of using "ulimit -s unlimited",
#         together with the --propagate=STACK in the "srun" command (see below),
#         speeds up the job considerably; in my test cases between 10% and 15%;
#         the value 102400 is the default maximum stack size on MISTRAL
#
#ulimit -s 102400
ulimit -s unlimited

#
export FORT_BUFFERED=true
export decfort_dump_flag=true
#
export MXM_LOG_LEVEL=ERROR

set -e

#### !!!! Adopt this directory !!!!
SPDIR=/work/bb0105/fkelemen

cd ${SPDIR}/2014_Pentecost/log_int2lm

# clean the directory
rm -rf I* O* Y*

NPX=1
NPY=1
NPIO=0
NP1=`expr $NPX \* $NPY`
NP=`expr $NP1 + $NPIO`

#################################################
# cat together the INPUT*-files
#################################################

cat > INPUT <<**
 &CONTRL
  ydate_ini = '2014060900',
  hstart = 0.0,
  hstop = 0.,
  hincbound = 6,
  yinput_model ='CM',   
  itype_albedo=2,
  itype_calendar = 0,
  itype_rootdp = 4,
  itype_t_cl = 1, 
  itype_w_so_rel = 1,
  l_cressman = .FALSE., 
  lbdclim = .TRUE.,  
  lboundaries =.TRUE., 
  lfilter_oro = .TRUE.,
  eps_filter = 10.,
  lforest = .TRUE.,
  linitial =.TRUE.,
  lmulti_layer_in = .TRUE., 
  lmulti_layer_lm = .TRUE.,
  lprog_qi = .TRUE.,
  lt_cl_corr=.TRUE.,
  lreorder = .TRUE.,
  luvcor=.TRUE.,
  lsso = .TRUE.,
  ltime_mean = .TRUE., 
  luse_t_skin = .TRUE.,
  nincwait = 5, nmaxwait = 20, 
  nprocx = ${NPX}, nprocy = ${NPY},
  idbg_level = 2,
/END
 &GRID_IN
  pcontrol_fi = 30000., 
  ie_in_tot = 269,
  je_in_tot = 268,
  ke_in_tot = 137,
  startlat_in_tot = 34.95,
  startlon_in_tot = -20.1,
  endlat_in_tot = 75,
  endlon_in_tot = 20.1,
  dlat_in = 0.15,
  dlon_in = 0.15,
  pollat_in = 90.0,
  pollon_in = 180.0,
  ke_soil_in = 3,   
  czml_soil_in = 0.035, 0.175, 0.64, 1.775,
 /END
 &LMGRID
  ivctype = 2,
  ielm_tot = 100, 
  jelm_tot = 80,
  kelm_tot = 40,
  pollat = 39.0,
  pollon = -173.0, 
  polgam = 0.0,
  dlon = 0.0625,
  dlat = 0.0625, 
  startlat_tot = -6.8125,
  startlon_tot = -7.8125,
  irefatm = 2,
  delta_t = 75.0,
  h_scal = 10000.0,
/END
 &DATABASE
 /
 &DATA
  yinput_type = 'analysis',
  ytunit_in = 'd',
  ytunit_out = 'd',
  ylmext_form_read = 'ncdf',
  yinext_form_read = 'ncdf',
  yin_form_read = 'ncdf',
  ylm_form_write = 'ncdf',
  ie_ext = 250, je_ext = 200,
  ylmext_lfn = 'domain_00625.nc',
  ylmext_cat = '${SPDIR}/2014_Pentecost/data/ext/',
  yinext_lfn = 'cas2014060900.nc',
  yinext_cat = '${SPDIR}/2014_Pentecost/data/ecmwf/v1_015',
  yin_cat = '${SPDIR}/2014_Pentecost/data/ecmwf/v1_015',
  ylm_cat = '${SPDIR}/2014_Pentecost/data/int2lm_output/small',
  nprocess_ini = 131, nprocess_bd = 132, 
 /END
 &PRICTR
  igp_tot = 36,
  jgp_tot = 30,
  lchkin=.TRUE., lchkout=.TRUE.,
 /END
**


#################################################
# run the program
#################################################

# you have to adapt the way how to invoke the binary
echo ----- start INT2CLM
srun -l --propagate=STACK --cpu_bind=verbose,cores --distribution=block:cyclic  /pf/b/b380174/CCLM/bin/int2lm.exe
echo ----- INT2CLM finished

