#!/bin/bash
# Create cccmf cache files for selected model versions in both Victoria and Dorval
# These files are placed in a known location and made world readable
# The script cccmf will use one of these cache files when possible

# This script is intended to be run as a cron job on lxsrv

# Create cache files containing only common (ie not version dependent) source
cache_file_rpath="cccjob_dir/cccmake/lib/cache_cccmf_comm"
echo -e "\n### common lxwrk1 ###\n"
ssh -x lxwrk1 cccmf cache_only='$CCRNSRC'/$cache_file_rpath  &&
    ssh -x lxwrk1 chmod a+r '$CCRNSRC'/$cache_file_rpath

echo -e "\n### common joule ###\n"
ssh -x joule cccmf cache_only='$CCRNSRC'/$cache_file_rpath  &&
    ssh -x joule chmod a+r '$CCRNSRC'/$cache_file_rpath

# Create cache files containing version dependent source
modver_list="gcm13e gcm15i gcm16 gcm17 gcm18"
for modver in $modver_list; do

  # Output pathname for cache file (relative to CCRNSRC)
  cache_file_rpath="cccjob_dir/cccmake/lib/cache_cccmf_atm_$modver"

  echo -e "\n### modver=$modver lxwrk1 ###\n"
  ssh -x lxwrk1 cccmf modver=$modver cache_only='$CCRNSRC'/$cache_file_rpath  &&
      ssh -x lxwrk1 chmod a+r '$CCRNSRC'/$cache_file_rpath

  echo -e "\n### modver=$modver joule ###\n"
  ssh -x joule cccmf modver=$modver cache_only='$CCRNSRC'/$cache_file_rpath  &&
      ssh -x joule chmod a+r '$CCRNSRC'/$cache_file_rpath

done
