-
Notifications
You must be signed in to change notification settings - Fork 7
/
post.bash
executable file
·106 lines (82 loc) · 2.97 KB
/
post.bash
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
#!/bin/bash
# ------------------------------------------------------------------------------
# WRFOTRON
# ------------------------------------------------------------------------------
#$ -cwd -V
#$ -l h_rt=48:00:00
#$ -pe smp __nprocPost__
#$ -l h_vmem=12G
module purge
module load licenses sge intel/19.0.4 nco/4.6.0 wrfchemconda/3.7 netcdf/4.6.3
export OMP_NUM_THREADS=__nprocPost__
. __CONFIGDIR__config.bash
cd ${stagingDir}
msg "Postprocessing of WRF/Chem output"
mkdir -p ${archiveDir}
# Postprocessing funtion (same as before just removed from for loop)
postpoc(){
# hour is passed in as a local variable
local hour=$1
# Tags and files are local vars so each core works on only one thing
local dateTag=$(date -u --date="__inpYear__-__inpMonth__-__inpDay__ __inpHour__:00:00 ${hour} hours" "+%Y%m%d%H%M%S")
local curDate=$(date -u --date="__inpYear__-__inpMonth__-__inpDay__ __inpHour__:00:00 ${hour} hours" "+%Y-%m-%d_%H")
echo "PP'ing ${dateTag}"
for domain in $(seq -f "0%g" 1 ${max_dom})
do
local inFile=wrfout_d${domain}_${curDate}:00:00
if [ ! -f ${inFile} ]
then
echo "${inFile} missing, skipped!"
continue
fi
if [ -f ${archiveDir}/${inFile} ]
then
echo "${archiveDir}/${inFile} already exists, skipped!"
continue
fi
# --------------------- per file postprocessing ----------------------------
local outFile=${inFile}.nc
cp -p $inFile $outFile
echo 'deleting tmp_'${outFile}
rm -f tmp_${outFile}
# create new variables
python ${pyPpScript} ${inFile} tmp_${outFile} $WRFdir
# temporary workaround for WRFChem4 due to NCO bug (fxm TODO nco1089) need to convert netcdf4 back to netcdf3, remove when fixed
if [ "$(printf '%s\n' "4.0.0" "${WRFdir} | grep -Eo '[0-9]+([.][0-9]+)?([.][0-9]+)?' | tail -1" | sort -V | head -n1)" = 4.0.0 ]; then
ncks -3 -O tmp_${outFile} tmp_${outFile}
ncks -3 -O ${outFile} ${outFile}
fi
# append all other variables
ncks -A tmp_${outFile} ${outFile}
#. $ppBashScript $inFile $outFile $domain $dateTag
# outFile=$inFile
# do whatever you want to do in postprocessing, just create a final NetCDF
# file with its name in the variable "outFile".
# This will be archived.
# --------------------- per file postprocessing ----------------------------
# apply compression and save to archive, use input filename
# k3 --> NetCDF-4 format
# d9 --> max compression level
# s --> shuffling (can improve compression)
nccopy -k3 -d9 -s $outFile ${archiveDir}/${inFile}
# remove output file only from staging area
rm -f $outFile
done
}
# parallel for loop runs post proc in background in chunks of number of avaible
# cores, i.e. core requested
N=$(nproc)
for hour in $(seq -w 0 __fcstTime__)
do
((i=i%N)); ((i++==0)) && wait
postpoc $hour &
done
# remove the run directory
if __REMOVERUNDIR__
then
echo $(du -sh ${runDir})
rm -rf ${runDir}
fi
msg "PP ended"
date
echo "-----------------------------"