-
Notifications
You must be signed in to change notification settings - Fork 0
/
SPSreformat.py
executable file
·108 lines (89 loc) · 3.08 KB
/
SPSreformat.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
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
#!/usr/bin/env python3
# Author: Andrei Voronin
# Year: 2019
# License: MIT
import sys
class Common:
def __init__(self):
self.table = {}
def parse(self, line):
parsed = {}
for k, v in self.table.items():
parsed[k] = line[v[0] - 1:v[1]]
return parsed
def format(self, parsed):
result = ""
for k, v in parsed.items():
size = self.table[k][1] - self.table[k][0] + 1
result += v[0:size].rjust(size)
return result
class RSstandard(Common):
def __init__(self):
super().__init__()
self.table["Record id"] = (1, 1)
self.table["Line name"] = (2, 17)
self.table["Point number"] = (18, 25)
self.table["Point index"] = (26, 26)
self.table["Point code"] = (27, 28)
self.table["Static correction"] = (29, 32)
self.table["Point depth"] = (33, 36)
self.table["Seismic datum"] = (37, 40)
self.table["Uphole time"] = (41, 42)
self.table["Water depth"] = (43, 46)
self.table["Easting"] = (47, 55)
self.table["Northing"] = (56, 65)
self.table["Elevation"] = (66, 71)
self.table["Day of year"] = (72, 74)
self.table["Time"] = (75, 80)
class Xstandard(Common):
def __init__(self):
super().__init__()
self.table["Record id"] = (1, 1)
self.table["Field tape number"] = (2, 7)
self.table["FFID"] = (8, 11)
self.table["FFID increment"] = (12, 12)
self.table["Istrument code"] = (13, 13)
self.table["Line name"] = (14, 29)
self.table["Point number"] = (30, 37)
self.table["Point index"] = (38, 38)
self.table["From channel"] = (39, 42)
self.table["To channel"] = (43, 46)
self.table["Channel increment"] = (47, 47)
self.table["Line name"] = (48, 63)
self.table["From receiver"] = (64, 71)
self.table["To receiver"] = (72, 79)
self.table["Receiver index"] = (80, 80)
class OverrideRS(RSstandard):
def override(self, name, tup):
if name in self.table:
self.table[name] = tup
else:
print("Name not found in RS table: {}".format(name))
exit()
class OverrideX(Xstandard):
def override(self, name, tup):
if name in self.table:
self.table[name] = tup
else:
print("Name not found in X table: {}".format(name))
exit()
RS = RSstandard()
X = Xstandard()
myRS = OverrideRS()
myRS.override("Static correction", (29, 33))
myRS.override("Point depth", (34, 37))
myRS.override("Seismic datum", (38, 40))
myX = OverrideX()
with open(sys.argv[1]) as file:
for line in file:
if line.startswith("H"):
print(line, end="")
elif line.startswith("R"):
print(RS.format(myRS.parse(line)))
elif line.startswith("S"):
print(RS.format(myRS.parse(line)))
elif line.startswith("X"):
print(X.format(myX.parse(line)))
else:
print("Unknown format. String starts with: {}".format(line[0]))
sys.exit()