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