-
Notifications
You must be signed in to change notification settings - Fork 3
/
advtime
executable file
·163 lines (146 loc) · 3.14 KB
/
advtime
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/bin/sh
#########################################################################
# advtime.sh #
# #
# This script is used to advance forward or backward in date/time. #
# #
# Log: #
# K. Brill/HPC 9/01 Created from advtime in C shell #
# K. Brill/HPC 11/01 Trap 2-digit year invalid date #
#########################################################################
if [ $# -eq 0 ]; then
cat << EOF
This script goes forward or backward in time beginning at the
starting time.
Command line inputs are:
YYYYMMDDHH = starting year month day hour
DH = time increment in hours (- => backward)
NDH = number of increments
If NDH is negative, the first time is not output; otherwise,
there will be NDH + 1 output times.
Any fourth command line input triggers output times in GEMPAK
format, YYYYMMDD/HH; otherwise, the output format is the same
as the input format, YYYYMMDDHH.
EOF
exit
fi
ymdh=$1
cnt=`echo $ymdh | wc -c`
if [ $cnt -lt 10 ]; then
echo $ymdh is not valid for YYYYMMDDHH
exit 1
fi
dh=`expr $2 + 0`
ndh=`expr $3 + 0`
if [ $ndh -lt 0 ]; then
ndh=`expr -1 \* $ndh`
first=2
else
first=1
fi
monday="31 28 31 30 31 30 31 31 30 31 30 31"
yy=`echo $ymdh | cut -c1-4`
mm=`echo $ymdh | cut -c5-6`
dd=`echo $ymdh | cut -c7-8`
hh=`echo $ymdh | cut -c9-10`
times=${yy}${mm}${dd}/${hh}
ymdhs=${yy}${mm}${dd}${hh}
ddd=$dd
mmm=$mm
dd=`expr $dd + 0`
mm=`expr $mm + 0`
yy=`expr $yy + 0`
hr=`expr $hh + 0`
icnt=0
while [ $icnt -lt $ndh ]; do
icnt=`expr $icnt + 1`
hr=`expr $hr + $dh`
while [ $hr -lt 0 ]; do
hr=`expr $hr + 24`
dd=`expr $dd - 1`
if [ $dd -eq 0 ]; then
mm=`expr $mm - 1`
if [ $mm -eq 0 ]; then
yy=`expr $yy - 1`
mm=12
fi
mmm=$mm
if [ $mm -lt 10 ]; then
mmm=0$mm
fi
dd=`echo $monday | cut -d" " -f$mm`
leap=0
if [ `expr $yy % 400` -eq 0 ]; then
leap=1
elif [ `expr $yy % 4` -eq 0 -a `expr $yy % 100` -ne 0 ]; then
leap=1
fi
if [ $leap -eq 1 -a $mm -eq 2 ]; then
dd=`expr $dd + 1`
fi
fi
ddd=$dd
if [ $dd -lt 10 ]; then
ddd=0$dd
fi
done
while [ $hr -ge 24 ]; do
hr=`expr $hr - 24`
dd=`expr $dd + 1`
dtst=`echo $monday | cut -d" " -f$mm`
mm=$mm
yy=$yy
leap=0
if [ `expr $yy % 400` -eq 0 ]; then
leap=1
elif [ `expr $yy % 4` -eq 0 -a `expr $yy % 100` -ne 0 ]; then
leap=1
fi
if [ $leap -eq 1 -a $mm -eq 2 ]; then
dtst=`expr $dtst + 1`
fi
if [ $dd -gt $dtst ]; then
mm=`expr $mm + 1`
if [ $mm -eq 13 ]; then
yy=`expr $yy + 1`
mm=1
fi
mmm=$mm
if [ $mm -lt 10 ]; then
mmm=0$mm
fi
dd=1
fi
ddd=$dd
if [ $dd -lt 10 ]; then
ddd=0$dd
fi
done
hhh=$hr
if [ $hr -lt 10 ]; then
hhh=0$hr
fi
yyy=$yy
if [ $yy -lt 10 ]; then
yyy=0$yy
fi
times="$times ${yyy}${mmm}${ddd}/${hhh}"
ymdhs="$ymdhs ${yyy}${mmm}${ddd}${hhh}"
done
if [ $# -eq 4 ]; then
i=0
for t in $times; do
i=`expr $i + 1`
if [ $i -ge $first ]; then
echo $t
fi
done
else
i=0
for t in $ymdhs; do
i=`expr $i + 1`
if [ $i -ge $first ]; then
echo $t
fi
done
fi