#!/bin/ksh
###############################################################################
#                             RUN NEMO
###############################################################################
#
#!/bin/ksh --login
##PBS -N run_nemo-v3.2-orca1
#PBS -l mppwidth=36
#PBS -l mppnppn=24
#PBS -l walltime=00:30:00
#PBS -A hpx1enes
#

# General settings

date
set -xuv

NEMO=/work/e24/rzg35ene/$USER/tools/nemo/v3.2-orca1
TESTDATADIR=/work/e24/rzg35ene/$USER/tools/nemo/inidata
FORCING=${TESTDATADIR}/DFS4.1
WRITINGDIR=/work/e24/rzg35ene/$USER/scratch/test
RUN_dir=$WRITINGDIR/run_nemo-v3.2-orca1_$PBS_JOBID

NPROCNEMO=36
MPPNPPN=24
YEAR=1990

mkdir -p ${RUN_dir} || true
cd ${RUN_dir}

cp ${NEMO}/bin/opa opa.xx
chmod 770 opa.xx

cp ${NEMO}/setup/namelist.v3.2.default namelist
cp ${NEMO}/setup/namelist_ice.v3.2.default namelist_ice

cp ${TESTDATADIR}/EMPave_old.dat EMPave_old.dat
cp ${TESTDATADIR}/geothermal_heating_orca1.nc geothermal_heating.nc
cp ${TESTDATADIR}/coordinates_ukorca1.nc coordinates.nc
cp ${TESTDATADIR}/bathy_meter_050308_UKMO.nc bathy_meter.nc
cp ${TESTDATADIR}/basinmask_050308_UKMO.nc basinmasks.nc
cp ${TESTDATADIR}/runoff_1m_ORCA1.nc runoff_1m_nomask.nc
cp ${TESTDATADIR}/sst_1m_ORCA1.nc sst_1m.nc
cp ${TESTDATADIR}/sss_1m_ORCA1.nc sss_1m.nc
cp ${TESTDATADIR}/dust_1m_ORCA1.nc dust_1m.nc
cp ${TESTDATADIR}/ahmcoef ahmcoef

cp ${TESTDATADIR}/bathy_level42_050308_UKMO.nc bathy_level.nc
cp ${TESTDATADIR}/potemp05_1m_z42_nomask.nc data_1m_potential_temperature_nomask.nc
cp ${TESTDATADIR}/salin05_1m_z42_nomask.nc data_1m_salinity_nomask.nc

ln -s ${TESTDATADIR}/weights_grid02_bicubic_orca1.nc weights_grid02_bicubic_orca1.nc
ln -s ${TESTDATADIR}/weights_grid02_bilinear_orca1.nc weights_grid02_bilinear_orca1.nc
ln -s ${TESTDATADIR}/weights_grid03_bicubic_orca1.nc weights_grid03_bicubic_orca1.nc
ln -s ${TESTDATADIR}/weights_grid03_bilinear_orca1.nc weights_grid03_bilinear_orca1.nc

ln -s ${FORCING}/${YEAR}_1d_DFS4.1_lwdn.nc qlw_core_y${YEAR}.nc
ln -s ${FORCING}/${YEAR}_1d_DFS4.1_swdn.nc qsw_core_y${YEAR}.nc
ln -s ${FORCING}/${YEAR}_6hr_DFS4.1_q2m.nc q2_core_y${YEAR}.nc
ln -s ${FORCING}/${YEAR}_6hr_DFS4.1_t2m.nc t2_core_y${YEAR}.nc
ln -s ${FORCING}/${YEAR}_6hr_DFS4.1_u10.nc u10_core_y${YEAR}.nc
ln -s ${FORCING}/${YEAR}_6hr_DFS4.1_v10.nc v10_core_y${YEAR}.nc
ln -s ${FORCING}/${YEAR}_1m_DFS4.1_precip.nc precip_core_y${YEAR}.nc
ln -s ${FORCING}/${YEAR}_1m_DFS4.1_snow.nc snow_core_y${YEAR}.nc

for ((l=0; l<$NPROCNEMO; l++)); do
 ln -sf coordinates.nc coordinates_$(printf "%03d" $l).nc
 ln -sf geothermal_heating.nc geothermal_heating_$(printf "%03d" $l).nc
done

ls -alF

ulimit -s unlimited

aprun -n $NPROCNEMO -N $MPPNPPN opa.xx

date
