-
Notifications
You must be signed in to change notification settings - Fork 5
/
upload_ncl.sh
executable file
·148 lines (131 loc) · 5.06 KB
/
upload_ncl.sh
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
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/bin/bash
###############################################################################
yearstr=2018
monthstr=06
daystr=05
cyclestr=00
cyclestrsec=00000
###############################################################################
nclweightfile=$1
runDir=$2
betacastPath=$3
path_to_ncl=${betacastPath}/plotting_ncl/
htmlFolder=${betacastPath}/html_for_upload/
echo "UPLOAD_NCL: SSHings..."
ssh [email protected] "mkdir -p /home/colinzar/www/www/current2/${yearstr}${monthstr}${daystr}${cyclestr} ; \
cd /home/colinzar/www/www/current2/ ; \
cp *cfg *html ${yearstr}${monthstr}${daystr}${cyclestr} ; \
rm ${yearstr}${monthstr}${daystr}${cyclestr}/index.html "
## UPDATE html page
cd ${htmlFolder}
if [ ! -f index.html ]; then
if [ ! -f index.HOLD ]; then
echo "UPLOAD_NCL: downloading index from server"
scp [email protected]:/home/colinzar/www/www/current2/index.html index.html
else
echo "UPLOAD_NCL: copying index from HOLD"
cp -v index.HOLD index.html
fi
echo "UPLOAD_NCL: sedding in this date"
sed '/<!--FORECASTHEAD-->/ r htmltemplate.html' index.html > _index1.html
sed -e "s/YYYYMMDDHH/${yearstr}${monthstr}${daystr}${cyclestr}/" _index1.html > _index3.html
mv _index3.html index.html
rm _index*.html
scp index.html [email protected]:/home/colinzar/www/www/current2
fi
filenames=`ls ${runDir}/*am.h0.*.nc`
numfiles=`ls ${runDir}/*am.h0.*.nc | wc -l`
echo $numfiles
VARS=PRECLav,PRECCav,PRECBSN,PRECBRA,PRECBIP,PRECBFZ
for i in `seq 1 ${numfiles}`; do
thisFile=`echo $filenames | cut -d" " -f${i}`
if [ "$i" -eq 1 ] ; then
ncks -v ${VARS} ${thisFile} ${runDir}/sum${i}.nc
ncks -A -v ${VARS} ${runDir}/sum${i}.nc ${thisFile}
rm ${runDir}/sum${i}.nc
else
iminus1=`expr $i - 1`
lastFile=`echo $filenames | cut -d" " -f${iminus1}`
ncrcat -v ${VARS} ${thisFile} ${lastFile} ${runDir}/tmpfile2.nc
ncra -h -O -y ttl ${runDir}/tmpfile2.nc ${runDir}/sum${i}.nc
ncap2 -A -s 'time=time+0.0625' ${runDir}/sum${i}.nc ${runDir}/sum${i}.nc
ncks -A -v ${VARS} ${runDir}/sum${i}.nc ${thisFile}
rm ${runDir}/sum${i}.nc ${runDir}/tmpfile2.nc
fi
done
sleep 5
echo "UPLOAD_NCL: Found at least one file"
echo $filenames
cd ${runDir}
for i in *h0*.nc; do mv $i _$i; done
cd ${htmlFolder}
newfiles=`ls ${runDir}/_*h0*-00000.nc ${runDir}/_*h0*-21600.nc ${runDir}/_*h0*-43200.nc ${runDir}/_*h0*-64800.nc`
for f in $newfiles; do
echo "UPLOAD_NCL: Processing $f"
(set -x; env PATH_TO_NCL=$path_to_ncl ncl ${path_to_ncl}/weatherplot.ncl inisec=$cyclestrsec \
iniday=$daystr \
inimon=$monthstr \
iniyear=$yearstr \
'filename="'${f}'"' \
'wgt_file="'${nclweightfile}'"' > ncl.output 2>&1 )
if grep -q "FileReadVar" ncl.output; then
sleep 5
echo "UPLOAD_NCL: Found an error, try again"
(set -x; env PATH_TO_NCL=$path_to_ncl ncl ${path_to_ncl}/weatherplot.ncl inisec=$cyclestrsec \
iniday=$daystr \
inimon=$monthstr \
iniyear=$yearstr \
'filename="'${f}'"' \
'wgt_file="'${nclweightfile}'"' )
fi
#rm ncl.output
done
## Trim whitespace around pngs
genpngs=`ls *png`
for g in $genpngs; do
convert -trim +repage $g -colors 255 $g
done
## Get file list in txt file for FLANIS viewer
#basins=(natl epac)
basins=(natl epac float1)
#outflds=(wind tmq flut prect sumprect 500vort shear850250)
outflds=(wind tmq flut prect sumprect 500vort sumsnow ts tsanom ptype)
# Loop over items in outflds
for basin in ${basins[*]}
do
for item in ${outflds[*]}
do
#printf " %s\n" $item
if [ ! -f ${item}_${basin}_files.txt ]; then
echo "UPLOAD_NCL: File not found!"
ls -1 ${item}_${basin}*png > ${item}_${basin}_files_nopath.txt
else
mv -v ${item}_${basin}_files_nopath.txt orig_${item}_${basin}_files.txt
ls -1 ${item}_${basin}*png > tocat_${item}_${basin}_files.txt
cat orig_${item}_${basin}_files.txt tocat_${item}_${basin}_files.txt > ${item}_${basin}_files_nopath.txt
rm -v tocat_${item}_${basin}_files.txt orig_${item}_${basin}_files.txt
fi
cp -v ${item}_${basin}_files_nopath.txt ${item}_${basin}_files.txt
#sed -i.bak 's/^/##/' ${item}files.txt
done
done
# Copy tracker data over if around...
mv -v ${betacastPath}/cyclone-tracking/trajs.*.png .
cp -v ${betacastPath}/cyclone-tracking/fin-atcf/atcf.tempest.${yearstr}${monthstr}${daystr}${cyclestr} .
## Move files to server
## Google create remote directory if not existant
## use rysnc?
echo "UPLOAD_NCL: Moving files to remote server"
scp *.png *.txt atcf.tempest* [email protected]:/home/colinzar/www/www/current2/${yearstr}${monthstr}${daystr}${cyclestr}
#mv $newfiles $procdir
mkdir ${yearstr}${monthstr}${daystr}${cyclestr}
mv -v *.png *.txt atcf.tempest* ${yearstr}${monthstr}${daystr}${cyclestr}
rm -rf ${yearstr}${monthstr}${daystr}${cyclestr}
### Finish uploading index.html
printtime=`date -u`
sed -e 's/\"red/\"green/' index.html > _index4.html
sed -e "s/CURRENTLY UPDATING/COMPLETED AT $printtime/" _index4.html > _index5.html
mv _index5.html index.html
rm _index*html
scp index.html [email protected]:/home/colinzar/www/www/current2
mv -v index.html index.HOLD