-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsidship
More file actions
executable file
·334 lines (287 loc) · 5.21 KB
/
sidship
File metadata and controls
executable file
·334 lines (287 loc) · 5.21 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
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
#!/bin/sh
#
# This script is used to convert our daily channel files into the format
# used by the Stanford SuperSid folks
#
isanumber ()
{
valid=`echo $input|awk '
/./ {if ($0 ~ /^[0-9][0-9]*$/)
{
print "yes"
}
else
{
print "no"
}
}'`
if [ $valid = "no" ]
then
echo Invalid input: $input
fi
}
islatlong ()
{
valid=`echo $input|awk '
/./ {if ($0 ~ /^-*[0-9][0-9]*[.][0-9][0-9]*$/)
{
print "yes"
}
else
{
print "no"
}
}'`
if [ $valid = "no" ]
then
echo Invalid input: $input
fi
}
isemail ()
{
valid=`echo $input|awk '
/./ {if ($0 ~ /^[-a-zA-Z_.0-9][-a-zA-Z_.0-9]*@[-a-zA-Z.0-9][-a-zA-Z.0-9]*$/)
{
print "yes"
}
else
{
print "no"
}
}'`
if [ $valid = "no" ]
then
echo Invalid input: $input
fi
}
if [ -e $HOME/.sidshipinfo ]
then
. $HOME/.sidshipinfo
else
echo You do not appear to have SID data shipping information configured
echo Setting up that information now
echo -n "SITE: "
read SITE
valid=no
while [ $valid != "yes" ]
do
echo -n "LONGITUDE: "
read input
islatlong
done
LONGITUDE="$input"
valid=no
while [ $valid != "yes" ]
do
echo -n "LATITUDE: "
read input
islatlong
done
LATITUDE="$input"
valid=no
while [ $valid != "yes" ]
do
echo -n "UTC OFFSET: "
read input
islatlong
done
UTC_OFFSET="$input"
echo -n "TIMEZONE: "
read TIMEZONE
valid=no
while [ $valid != "yes" ]
do
echo -n "MONITORID: "
read input
isanumber
done
MONITORID="$input"
valid=no
while [ $valid != "yes" ]
do
echo -n "EMAIL: "
read input
isemail
done
EMAIL="$input"
echo "SITE=\"$SITE\"" >$HOME/.sidshipinfo
echo "LONGITUDE=\"$LONGITUDE\"" >>$HOME/.sidshipinfo
echo "LATITUDE=\"$LATITUDE\"" >>$HOME/.sidshipinfo
echo "UTC_OFFSET=\"$UTC_OFFSET\"" >>$HOME/.sidshipinfo
echo "TIMEZONE=\"$TIMEZONE\"" >>$HOME/.sidshipinfo
echo "MONITORID=\"$MONITORID\"" >>$HOME/.sidshipinfo
echo "EMAIL=\"$EMAIL\"" >>$HOME/.sidshipinfo
. $HOME/.sidshipinfo
fi
#
# Probably don't need to change these
#
FTPSERVER=sid-ftp.stanford.edu
FTPUSER=anonymous
PASS=$EMAIL
DIRECTORY=incoming/SuperSID/NEW
PATH=$PATH:$HOME/bin
export PATH
freq=24000
station=""
chan=""
DATE="NONE"
while [ "@@" != "@$1@" ]; do
case "$1" in
-f|-freq|-frequency)
freq=$2
shift 2
;;
-s|-station|-sname|-name)
station=$2
shift 2
;;
-c|-chan|-ch)
chan=$2
shift 2
;;
-d|-date)
DATE=$2
shift 2
;;
-help|-h)
shift
cat <<!EOF!
Usage: sidship options:
-f|-freq|-frequency frequency, in Hz
-s|-station|-sname|-name station name: e.g.: NAA
-c|-chan|-ch channel number 1-4
-d|-date|-date date: YYYY-MM-DD
!EOF!
exit
;;
-*)
echo "Unknown option" $1
exit
;;
*)
echo "Unknown parameter" $1
exit
;;
esac
done
if [ $DATE != "NONE" ]
then
case $DATE in
[2][0][123][0-9]-[01][0-9]-[0-9][0-9])
;;
*)
echo Invalid date: $DATE
echo format is: YYYY-MM-DD
exit
;;
esac
YEAR=`echo $DATE|sed -e 's/-.*$//'`
MONTH=`echo $DATE|sed -e 's/^....-//'|sed -e 's/-.*$//'`
DAY=`echo $DATE|sed -e 's/^....-..-//'`
fi
if [ @@ = "@$chan@" -o @@ = "$freq" ]
then
echo You must specify at least channel and frequency
cat <<!EOF!
Usage: sidship options:
-f|-freq|-frequency frequency, in Hz
-s|-station|-sname|-name station name: e.g.: NAA
-c|-chan|-ch channel number 1-4
-d|-date|-date date: YYYY-MM-DD
!EOF!
exit
fi
freq=`echo $freq|awk '/./ {printf ("%d", 0+$1)}'`
if [ $freq -le 0 ]
then
echo Frequency parameter is invalid--must be a number
exit
fi
if [ $freq -le 12000 -o $freq -gt 45000 ]
then
echo Frequency $freq likely invalid for VLF station
exit
fi
cat >tbl$$ <<"!EOF!"
40000 JJY
24000 NAA
25200 NML
24800 NLK
19800 NWK
19400 NPX
21400 NPM
40750 NAU
23400 DHO
26700 TBB
19600 GQD
21370 GYA
37500 TFK
15100 HWU
19700 UGE
14600 UVA
30300 UGKZ
18100 UFQE
15000 UIK
!EOF!
station=`grep $freq tbl$$|sed -e 's/.* //'`
rm -f tbl$$
if [ @$station@ = "@@" -a @$3@ = "@@" ]
then
echo Cant find $freq in frequency list and station name not supplied
exit
fi
if [ @$station@ = "@@" ]
then
station=$3
fi
cwd=`pwd`
cd $HOME/sid_data
TZ=UTC0
export TZ
if [ $DATE = "NONE" ]
then
fname=`date +%Y%m%d`
siddate=`date +%Y-%m-%d`
else
fname="${YEAR}${MONTH}${DAY}"
siddate="${YEAR}-${MONTH}-${DAY}"
fi
sidfname=`echo ${SITE}_${station}_${siddate}.csv`
sidconvert <chan${chan}-$fname.dat >tmp$$
max=`grep MAXIMUM tmp$$|sed -e 's/MAXIMUM *//'`
min=`grep MINIMUM tmp$$|sed -e 's/MINIMUM *//'`
grep -v IMUM tmp$$ >chan${chan}-$fname.tmp
first=`head -1 chan${chan}-$fname.tmp|sed -e 's/,.*$//'`
last=`tail -1 chan${chan}-$fname.tmp|sed -e 's/,.*$//'`
rm -f tmp$$
cat >$cwd/$sidfname <<!EOF!
# Site = $SITE
# Longitude = $LONGITUDE
# Latitude = $LATITUDE
#
# UTC_Offset = $UTC_OFFSET
# TimeZone = $TIMEZONE
#
# UTC_StartTime = $first
# StationID = $station
# Frequency = $freq
# MonitorID = $MONITORID
# SampleRate = 5
# Contact $EMAIL
# UTC_EndTime = $last
# DataMin=$min
# DataMax=$max
!EOF!
cat chan${chan}-$fname.tmp >>$cwd/$sidfname
rm -f chan${chan}-$fname.tmp
cd $cwd
echo -n Shipping $sidfname to $FTPSERVER ...
ftp -n $FTPSERVER <<END_SCRIPT
quote USER $FTPUSER
quote PASS $PASS
cd $DIRECTORY
put $sidfname
quit
END_SCRIPT
echo Done