-
Notifications
You must be signed in to change notification settings - Fork 2
/
annualcycle.cgi
executable file
·76 lines (70 loc) · 2.08 KB
/
annualcycle.cgi
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
#!/bin/bash
. ./init.cgi
export PATH=$PATH:/usr/local/bin
# average an ensemble of fields
echo "Content-type: text/html"
echo
export DIR=`pwd`
. ./getargs.cgi
. ./queryfield.cgi
. ./myvinkhead.cgi "Annual cycle" "$kindname $climfield" "nofollow,index"
infile=$file
file=${infile%.nc}
file=${file%.ctl}_annualcycle.nc
file=data/`basename $file`
if [ ${infile%.ctl} != "$infile" ]; then
ncfile=data/`basename $infile .ctl`.nc
bin/grads2nc $infile $ncfile
infile=$ncfile
fi
iens=0
echo "$EMAIL ($REMOTE_ADDR) cdo ydaymean $infile $file" >> log/log
if [ -z "$ENSEMBLE" ]; then
if [ -s $file -a $file -nt $infile ]; then
echo "Using cached data<p>"
else
echo "Computing annual cycle using <a href="https://code.zmaw.de/projects/cdo">cdo</a> ...<p>"
cdo ydaymean $infile $file.$$
mv $file.$$ $file
fi
else
iens=0
ens=00
ensinfile=`echo $infile | sed -e "s:\+\+:$ens:g" -e "s:\%\%:$ens:g"`
ensfile=`echo $file | sed -e "s:\+\+:$ens:g" -e "s:\%\%:$ens:g"`
echo "Computing annual cycle using <a href=\"https://code.zmaw.de/projects/cdo\" target=_new>cdo</a> ...<p>"
while [ -s $ensinfile ]; do
if [ -s $ensfile -a $ensfile -nt $ensinfile ]; then
echo "Using cached data<p>"
else
echo "cdo ydaymean $ensinfile $ensfile"
cdo ydaymean $ensinfile $ensfile.$$
mv $ensfile.$$ $ensfile
if [ ! -s $ensfile ]; then
echo "Something went wrong in the averaging routine."
. ./myvinkfoot.cgi
exit
fi
fi
iens=$((iens+1))
if [ $iens -lt 10 ]; then
ens=0$iens
else
ens=$iens
fi
ensinfile=`echo $infile | sed -e "s:\+\+:$ens:g" -e "s:\%\%:$ens:g"`
ensfile=`echo $file | sed -e "s:\+\+:$ens:g" -e "s:\%\%:$ens:g"`
done
fi
eval `bin/getunits.sh $file`
ENSEMBLE=""
kindname="annual cycle $kindname"
FORM_field=data/`basename $file .nc`.$EMAIL.info
cat > $FORM_field <<EOF
$file
NPERYEAR=$NPERYEAR
UNITS=$UNITS
$kindname
$climfield
EOF
. ./select.cgi