-
Notifications
You must be signed in to change notification settings - Fork 1
/
station2hypo71.py
executable file
·46 lines (40 loc) · 1.23 KB
/
station2hypo71.py
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
#!/usr/bin/env python
"""
Convert a space-delimited station file to HYPO71 input format
Input format: Network, station, lat, long, elevation (m).
(allows 5-character station names for seisan hyp package).
Usage: station2hypo71.py <infile> <outfile>
"""
import sys
import math
try:
infile = sys.argv[1]
outfile = sys.argv[2]
except IndexError:
sys.exit("Did not specify input and/or output file.\n"
"Usage: station2hypo71.py <infile> <outfile>")
output = open(outfile, 'w')
# Read in input file
for line in open(infile, 'r'):
sta = line.split()[1]
lat = float(line.split()[2])
lon = float(line.split()[3])
ele = float(line.split()[4])
# Determine hemispheres
if lat < 0:
lat_side = 'S'
else:
lat_side = 'N'
if lon < 0:
lon_side = 'W'
else:
lon_side = 'E'
# Format and write to file
output.write(" {:>5s}{:02g}{:05.2f}{:1s}{:03.0f}{:05.2f}{:1s}{:4.0f}\n"
.format(sta,
abs(math.modf(lat)[1]),
60*abs(math.modf(lat)[0]), lat_side,
abs(math.modf(lon)[1]),
60*abs(math.modf(lon)[0]), lon_side,
ele))
output.close()