forked from pwcazenave/dhi-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_coordinates.sh
executable file
·51 lines (46 loc) · 1.7 KB
/
get_coordinates.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
#!/bin/bash
# Extract coordinates for the current meters (which only have names like "Site 1").
for d in *; do
if [ ! -d $d ]; then
continue
fi
cd $d
for i in *.m21fm; do
# Do a more sophisticated version which cuts all the time series
# outputs I specified.
# OUTPUT_2 = BODC tides
# OUTPUT_3 = Current meters
# OUTPUT_4 = North Sea Tides
names=("tide" "points" "north_sea_points")
outputs=("OUTPUT_2" "OUTPUT_3" "OUTPUT_4")
for ((n=0; n<${#names[@]}; n++)); do
awk '/\['${outputs[n]}'\]/{flag=1;next}/EndSect \/\/ '${outputs[n]}'/{flag=0}flag' $i | \
tr -d '\015' | \
grep --group-separator="" -A4 POINT | \
grep . | \
grep -v POINT | \
sed '/\[LINE\]/,$d' | \
cut -f2 -d= | \
sed 's/Site /Site_/g' | \
xargs -n4 | \
tr " " "," > "${i%.*}_${names[n]}.txt"
if [ $(grep . "${i%.*}_${names[n]}.txt" | wc -l) -eq 0 ]; then
rm "${i%.*}_${names[n]}.txt"
fi
done
done
#echo "name,lon,lat,depth" > "${i%.*}_current_meter_sites.txt"
## Holy horrible pipeline Batman!
#grep --group-separator="" Site\ .* -A3 "$i" | \
# tr -d '\015' | \
# sed 's/Site /Site_/g' | \
# grep . | \
# cut -f2 -d= | \
# xargs -n4 | \
# tr " " "," >> "${i%.*}_current_meter_sites.txt"
#if [ $(grep . "${i%.*}_current_meter_sites.txt" | wc -l) -eq 1 ]; then
# rm "${i%.*}_current_meter_sites.txt"
#fi
#done
cd ~-
done