#!/bin/ksh
#################################################
# batch commandos
#################################################
# for Cray XC30
#PBS -q xc_norm_h
#PBS -l select=1
#PBS -l place=pack
#PBS -j oe
#PBS -N eu2de

cd /e/uhome/sbrienen/CLM_community/WG_CRCS/CECPC5.0/int2lm_run

#################################################
# cat together the INPUT-file
#################################################

cat > INPUT << end_input
 &CONTRL
  ydate_bd='2008010100', ydate_ini='2008010100',
  linitial=.TRUE., lboundaries=.TRUE.,
  hstart=0.0, hstop=3.0, hincbound=1.0,
  nprocx=4, nprocy=6, nprocio=0,
  yinput_model='COSMO',
  lfilter_oro=.true., lfilter_pp=.true., lbalance_pp=.true.,
  eps_filter=0.1, norder_filter=5,
  ilow_pass_oro=4, ilow_pass_xso=5,
  lasync_io=.false., lreorder=.false., lroutine=.false., ltime_mean=.true.,
  lmulti_layer_in=.true., lmulti_layer_lm=.true.,
  lprog_qi=.true., lprog_qr_qs=.TRUE., lprog_rho_snow=.false.,
  lforest=.true., lt_cl_corr=.false., luvcor=.true.,
  lvertwind_ini=.true., lvertwind_bd=.true.,
  rxso_mask=625.0,
  itype_albedo=3, idbg_level=2,
 lprintdeb_all=.true.,
 /
 &GRID_IN
 startlat_in_tot=-20.0, startlon_in_tot=-18.0,
!  startlat_in_tot=-5.0,  startlon_in_tot=-5.0,
  pollat_in=40.0,        pollon_in=-170.0,
  dlat_in=0.0625,        dlon_in=0.0625,
 ie_in_tot=665, je_in_tot=657, ke_in_tot=40,
!  ie_in_tot=101, je_in_tot=109, ke_in_tot=40,
 /
 &LMGRID
 startlat_tot=-5.0, startlon_tot=-5.0,
!  startlat_tot=-2.0, startlon_tot=-2.0,
  pollat=40.0, pollon=-170.0,
  dlon=0.025, dlat=0.025,
 ielm_tot=421, jelm_tot=461, kelm_tot=50,
!  ielm_tot=101, jelm_tot=121, kelm_tot=50,
  ivctype=2, vcflat=11357.0,
  lanalyt_calc_t0p0=.TRUE.,
  vcoord_d=22000.00,21000.00,20028.57,19085.36,18170.00,17282.14,
           16421.43,15587.50,14780.00,13998.57,13242.86,12512.50,
           11807.14,11126.43,10470.00, 9837.50, 9228.57, 8642.86,
            8080.00, 7539.64, 7021.43, 6525.00, 6050.00, 5596.07,5162.86,
            4750.00, 4357.14, 3983.93, 3630.00, 3295.00, 2978.57,2680.36,
            2400.00, 2137.14, 1891.43, 1662.50, 1450.00, 1253.57,1072.86,
             907.50,  757.14,  621.43,  500.00,  392.50,  298.57, 217.86,
             150.00,   94.64,   51.43,   20.00,    0.00,
  lnewVGrid=.FALSE.,
 /
 &DATABASE
 /
 &DATA
  ie_ext=645, je_ext=645,
  yinput_type='analysis',
! ylmext_lfn='lm_d0_02800_1605x1605.mol.g1',
  ylmext_lfn='lm_02800_645x645_glcv_V1_6.mol.albproz1_9_18.g1',
  ylmext_cat='/e/rhome/routfor/routfox/lm/const',
  ylm_hhl='COSMO_DE_HHL_002_051_001.g2',
  ylmext_form_read='grb1',
  yinext_lfn='laf2008010100',
  yin_hhl='lfff00000000c',
  yinext_form_read='grb1',
  yinext_cat='/e/uwork/sbrienen/COSMO-EU-ANA/rundir/COSMO_EU_output',
  yin_form_read='grb1',
  yin_cat='/e/uwork/sbrienen/COSMO-EU-ANA/rundir/COSMO_EU_output',
  ytunit_in='d',
  ylm_cat='/e/uwork/sbrienen/COSMO-EU-ANA/rundir/COSMO_DE_input',
  ylm_form_write='ncdf',
  ytunit_out='d',
  nprocess_ini = 137, nprocess_bd = 138, 
  nl_soil_in=2, nl_soil_lm=2,
  l_ke_in_gds=.TRUE.,
 /
 &PRICTR
  igp_tot = 36, 40, 48, 44, 48, 85, 77,
  jgp_tot = 30, 94, 38, 26, 26, 96, 12,
  lchkin=.TRUE., lchkout=.TRUE.,
  lprps=.FALSE.,
 /
end_input

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

rm -f YUCHKDAT YUTIMING YUDEBUG OUTPUT
rm -f /e/uwork/sbrienen/COSMO-EU-ANA/rundir/COSMO_DE_input/l*
rm -f ftrace.* gmon.*

#################################

## machine specific for Cray
export OMP_NUM_THREADS="1"
export ATP_ENABLED="1"
export ATP_MAX_CORES="0"
export RLIMIT_CORE="0"
##export MPICH_RANK_REORDER_DISPLAY="1"
##export MPICH_ENV_DISPLAY="1"
#export MPICH_VERSION_DISPLAY="1"

#export GRIB_DEFINITION_PATH=/usr/local/pkg/grib_api/definitions/release/1.11.0/definitions.edzw:/usr/local/pkg/grib_api/definitions/release/1.11.0/definitions
#export GRIB_SAMPLES_PATH=/usr/local/pkg/grib_api/definitions/release/1.11.0/samples/

#aprun -n 24 -N 24 -j 1 -d 1 -m 1500m /e/uhome/sbrienen/CLM_community/WG_CRCS/CECPC5.0/code/bin/int2lm_2.0_clm4_grb1.exe
aprun -n 24 -N 24 -j 1 -d 1 -m 1500m /e/uhome/sbrienen/INT2LM/int2lm_131101_2.00_clm4/tstint2lm
#aprun -n 24 -N 20 -j 1 -d 1 -m 1500m tstint2lm

#################################################
# cleanup
#################################################

rm INPUT

