LIBRADDIR=$WORK/lib/libRadtran/

DATA=/project/meteo/work/Carolin.Klinger/ECMWF/Data/

function run_ex () {
  K=$1
  IDENT=$2

  WDIR=${K}.$IDENT
  if [[ -e $WDIR ]]; then
    echo "Skipping $WDIR because dir exists"
  else
    echo "Executing $WDIR"
    mkdir -p $WDIR

    cat > $WDIR/uvspec.inp << EOF
data_files_path $LIBRADDIR/data/
atmosphere_file $DATA/atmos_gem_pacific_${K}_shift.dat
source thermal

albedo 0

rte_solver mystic        # Radiative transfer equation solver
mc_photons 1.e9
mc_minphotons 10000

mol_abs_param FU          # Correlated-k by Fu and Liou [1992/93]
wavelength_index 6 18

output_process sum

mc_sample_grid 1 1 80 80 # Gitter festlegen

output_user zout edn eup
#output_user zout edn eup heat
#mc_forward_output heating K_per_day
#make_all_layers_3d

zout all_levels

no_scattering

mc_std
mc_bcond mirror

mixing_ratio O2 2095
mixing_ratio CO2 400

mol_file N2O $DATA/mol_n2o_gem_pacific_${K}.dat vmr
mol_file O3  $DATA/mol_o3_gem_pacific_${K}.dat vmr
mol_file CH4 $DATA/mol_ch4_gem_pacific_${K}.dat vmr

wc_file 3D $DATA/wcloud3D_gem_pacific_3D_${K}_homo_asEcRad2.nc
wc_file 3D $DATA/wcloud3D_gem_pacific_3D_${K}.nc
wc_properties hu interpolate
ic_file 3D $DATA/icloud3D_gem_pacific_3D_${K}_homo_asEcRad2.nc
ic_file 3D $DATA/icloud3D_gem_pacific_3D_${K}.nc
ic_properties yang2013 interpolate
quiet
EOF

    if [[ "$IDENT" == *"1D"* ]]; then
      echo "Adding mc_ipa"
      echo mc_ipa >> $WDIR/uvspec.inp
    fi

    if [[ ! -e $WDIR/mc.flx.spc ]]; then
      cd $WDIR
      date | tee timing
      $LIBRADDIR/bin/uvspec -f uvspec.inp &> >(tee -a out)
      date | tee -a timing
      cd -
    fi
  fi
}

run_ex 17 1D
run_ex 17 3D
