!/bin/bash

ages=('190' '195' '200' '205' '210' '215' '220' '225' '230')
sol_consts=('1339.8' '1339.2' '1338.7' '1338.1' '1337.6' '1337.0' '1336.5' '1336.' '1335.4')

pCO2s=('750' '1500' '3000')

### loop over timeslices
for tt in 0 1 2 3 4 5 6 7 8; #
do

age=${ages[${tt}]};
sol_const=${sol_consts[${tt}]};

### loop over CO2 concentrations
for cc in 0 1 2; do # 
pCO2=${pCO2s[${cc}]};
pCO2_str=$(printf "%04d" ${pCO2})

orb_forcing_scenarios_sel=('ecc-obl-per')
length=${#orb_forcing_scenarios_sel[@]}

### loop over orbital forcing scenarios
for ((ff = 0; ff < length; ++ff)); do

forcing=${orb_forcing_scenarios_sel[${ff}]};
forcing_file="input/MesoOrb-Newark_forcing_${forcing}.nc"

echo $tt, $orb_forcing_scenarios_sel, $length, $ff, $forcing

if [[ "$cc" == "1" ]] && [[ "$forcing" == "ecc-obl-per" ]]; then 
    topog_recons_sel=('Marcilly2021' 'Cao201718');
else
    topog_recons_sel=('Marcilly2021'); 
fi
length_gg=${#topog_recons_sel[@]}

### loop over paleogeographic reconstructions
for ((gg = 0; gg < length_gg; ++gg)); do
topog_recon=${topog_recons_sel[${gg}]};
topog_file="input/topog_${age}Ma_${topog_recon}_climberX.nc"

sed -i "s/job-name=.*/job-name=cX_${age}_${pCO2}_${forcing}_${topog_recon}/g" ./job_climber;
./job_climber -s -f -o ../climberx_output_MesoOrb-Newark/${age}Ma_${pCO2_str}ppm_${forcing}_${topog_recon} -c long -w 400 -j parallel -n 8 \&control="nyears=250000 year_ini=0 sol_const=${sol_const} n_accel=5 iorbit=2 orbit_file=${forcing_file} fake_geo_const_file=${topog_file} fake_ice_const_file=${topog_file} co2_const=${pCO2} nyout_cmn=1000 nyout_atm=1000 nyout_lnd=1000 nyout_ocn=1000 nyout_sic=1000 atm_restart=F lnd_restart=F ocn_restart=F sic_restart=F bgc_restart=F n_year_geo=250000 i_write_restart=1 n_year_write_restart=50000" geo_par="l_close_panama=F geo_ref_file=${topog_file} i_q_geo=1 n_coast_cells=8 z_bed_rel_file=${topog_file} f_crit=0.25" ocn_par="i_init=1 l_isl_auto=T l_dist_run_lnd=T smooth_fac=2" atm_par="nstep_fast=32"; 

done;
done;
done;
done;


