#!/bin/bash

set -e

set=HIPPO_set_1420_1

case ${set} in
   HIPPO_set_1400*) fyear=1400; lyear=1850 ;;
   HIPPO_set_1420*) fyear=1420; lyear=1780; refrun=HIPPO_r002i1420p1f1102 ;;
   HIPPO_set_1780*) fyear=1780; lyear=1850 ;;
esac # set

cd /mnt/climstor/ERC_PALAEO/${set}

for run in HIPPO_r*i*p*f*; do

   cd ${run}/means

   for year in $(seq ${fyear} ${lyear}); do

      for file in 6h.special.grb mon.special.nc day.toasurf.grb mon.stdlevs.nc mon.alllevs.nc mon.toasurf.nc mon.meridional.nc ; do

         if [ ! -e ${run}_${year}_${file} ]; then

            cdo -s -setrtomiss,-9e33,9e33 -setmissval,-9e33 /mnt/climstor/ERC_PALAEO/${set}/${refrun}/means/${refrun}_${year}_${file} dummy_${run}_${year}_${file}

            echo "created dummy file dummy_${run}_${year}_${file}."

         fi # file exists?
      
      done # file

   done # year

   cd /mnt/climstor/ERC_PALAEO/${set}

done # run


exit 0
