|
| 1 | +#!/bin/bash -f |
| 2 | +#SBATCH --job-name=run-MDTF.sh |
| 3 | +#SBATCH --time=4:00:00 |
| 4 | +#set -x |
| 5 | + |
| 6 | +# dir references |
| 7 | +run_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) |
| 8 | +mdtf_dir=/home/oar.gfdl.mdtf/mdtf/MDTF-diagnostics |
| 9 | +#mdtf_dir=/home/Jacob.Mims/mdtf/MDTF-diagnostics |
| 10 | +activate=/home/oar.gfdl.mdtf/miniconda3/bin/activate |
| 11 | + |
| 12 | +#TEST: /archive/jpk/fre/FMS2024.02_OM5_20240819/CM4.5v01_om5b06_piC_noBLING_xrefine_test4/gfdl.ncrc5-intel23-prod-openmp/pp/ starts 0001 |
| 13 | + |
| 14 | +#TEST 2: /archive/djp/am5/am5f7b12r1/c96L65_am5f7b12r1_amip/gfdl.ncrc5-intel23-classic-prod-openmp/pp/ starts 1990 |
| 15 | + |
| 16 | +usage() { |
| 17 | + echo "USAGE: run-mdtf.sh -i /path/to/pp/dir/pp -o out_dir/mdtf -s startyr -e endyr" |
| 18 | + echo "ADDITONAL OPTS:" |
| 19 | + echo "-l: custom config file for pods (default: config/pod_config.json) this can be used to set which PODs you would like to run and define the realm to grab vars from" |
| 20 | +} |
| 21 | + |
| 22 | +# handle arguments |
| 23 | +tempdir="" |
| 24 | +pod_config="" |
| 25 | +declare -a pods=() |
| 26 | +while getopts "hi:o:s:e:p:t:l:" arg; do |
| 27 | + case "${arg}" in |
| 28 | + h) |
| 29 | + usage |
| 30 | + exit |
| 31 | + ;; |
| 32 | + i) |
| 33 | + if [ -d $OPTARG ]; then |
| 34 | + ppdir="${OPTARG}" |
| 35 | + else |
| 36 | + echo "ERROR: $1 is not a directory" |
| 37 | + usage |
| 38 | + exit |
| 39 | + fi |
| 40 | + ;; |
| 41 | + o) |
| 42 | + if [ -d "${OPTARG}" ]; then |
| 43 | + outdir="${OPTARG}" |
| 44 | + else |
| 45 | + mkdir -p "${OPTARG}" |
| 46 | + outdir="${OPTARG}" |
| 47 | + fi |
| 48 | + ;; |
| 49 | + s) |
| 50 | + startyr="${OPTARG}" |
| 51 | + ;; |
| 52 | + e) |
| 53 | + endyr="${OPTARG}" |
| 54 | + ;; |
| 55 | + p) |
| 56 | + pods+=("$OPTARG") |
| 57 | + ;; |
| 58 | + t) |
| 59 | + tempdir="${OPTARG}" |
| 60 | + ;; |
| 61 | + l) |
| 62 | + pod_config="${OPTARG}" |
| 63 | + esac |
| 64 | +done |
| 65 | +shift $((OPTIND-1)) |
| 66 | +if ! [ -d $outdir/config ]; then |
| 67 | + mkdir -p $outdir/config |
| 68 | +fi |
| 69 | +if [ -z $tempdir ]; then |
| 70 | + wkdir=$outdir |
| 71 | +else |
| 72 | + wkdir=$tempdir |
| 73 | +fi |
| 74 | +if [ -z $pod_config ]; then |
| 75 | + pod_config="$run_dir/config/pod_config.json" |
| 76 | +fi |
| 77 | + |
| 78 | +# check to see if catalog exists |
| 79 | +# ^..^ |
| 80 | +# /o o\ |
| 81 | +# oo--oo~~~ |
| 82 | +echo "looking for catalog in $ppdir" |
| 83 | +cat=$(grep -s -H "esmcat_version" $ppdir/*.json | cut -d: -f1) |
| 84 | +if [[ "$cat" == "" ]]; then |
| 85 | + env=/nbhome/fms/conda/envs/fre-2025.01 |
| 86 | + source $activate $env |
| 87 | + fre catalog builder --overwrite $ppdir $outdir/catalog |
| 88 | + cat=$outdir/catalog.json |
| 89 | + echo "new catalog generated: $cat" |
| 90 | +else |
| 91 | + echo "found catalog: $cat" |
| 92 | +fi |
| 93 | + |
| 94 | +# edit template config file |
| 95 | +cp $run_dir/config/template_config.jsonc $outdir |
| 96 | +f=$outdir/template_config.jsonc |
| 97 | +if [ ! -f $f ]; then |
| 98 | + echo "ERROR: failed to find $f" |
| 99 | + exit 0 |
| 100 | +fi |
| 101 | +config='"DATA_CATALOG": "",' |
| 102 | +config_edit='"DATA_CATALOG": "'"${cat}"'",' |
| 103 | +sed -i "s|$config|$config_edit|ig" $f |
| 104 | +config='"WORK_DIR": "",' |
| 105 | +config_edit='"WORK_DIR": "'"${wkdir}"'",' |
| 106 | +sed -i "s|$config|$config_edit|ig" $f |
| 107 | +config='"OUTPUT_DIR": "",' |
| 108 | +config_edit='"OUTPUT_DIR": "'"${outdir}"'",' |
| 109 | +sed -i "s|$config|$config_edit|ig" $f |
| 110 | +config='"startdate": "",' |
| 111 | +config_edit='"startdate": "'"${startyr}"'",' |
| 112 | +sed -i "s|$config|$config_edit|ig" $f |
| 113 | +config='"enddate": ""' |
| 114 | +config_edit='"enddate": "'"${endyr}"'"' |
| 115 | +sed -i "s|$config|$config_edit|ig" $f |
| 116 | +echo "edited file $f" |
| 117 | + |
| 118 | +# load mdtf base conda env |
| 119 | +env=/home/oar.gfdl.mdtf/miniconda3/envs/_MDTF_base |
| 120 | +source $activate $env |
| 121 | +#generate config files |
| 122 | +python $run_dir/scripts/gen_config.py $outdir/ $pod_config |
| 123 | + |
| 124 | +# launch the mdtf with the config files |
| 125 | +for f in $(ls ${outdir}/config) ; do |
| 126 | + echo "launching MDTF with $f" |
| 127 | + "$mdtf_dir"/mdtf -f $outdir/config/$f |
| 128 | +done |
| 129 | + |
| 130 | +# consolidate outputs into index |
| 131 | +cp $run_dir/scripts/index.html $outdir/ |
| 132 | +cp $run_dir/scripts/mdtf_diag_banner.png $outdir/ |
| 133 | +python $run_dir/scripts/gen_index.py $outdir/ $pod_config |
| 134 | + |
| 135 | +exit 0 |
0 commit comments