#!/bin/bash
#
# Rewrites C-LAMP Experiment 1 model output for distribution on the Earth
# System Grid (ESG).
#
ESGROOT=/u3/forrest/ESG/c-lamp
#
echo "`date` -- Rewriting C-LAMP model output for distribution on ESG"
for model in clm3_casa clm3_cn; do
   for exp in exp1_2 exp1_3 exp1_4 exp1_6 exp1_7; do
      for run in run1; do
         for stat in monthly_mean; do
            rm -rf ${ESGROOT}/${model}/${exp}/${run}/${stat}
            mkdir -p ${ESGROOT}/${model}/${exp}/${run}/${stat}
            chmod 755 ${ESGROOT}/${model}/${exp}/${run}/${stat}
            cp -p namelist.${model}.${exp}.${run}.${stat} namelist
            echo "`date` -- Rewriting output for ${model}.${exp}.${run}.${stat}"
            time ./c-lamp_rewrite >& c-lamp_rewrite.${model}.${exp}.${run}.${stat}.log
            echo "`date` -- Computing SHA1 checksums for ${model}.${exp}.${run}.${stat}"
            (cd ${ESGROOT}/${model}/${exp}/${run}/${stat} ; time sha1sum *.nc > SHA1SUM; chmod 644 *)
         done
      done
   done
done
echo "`date` -- Done"
