-
Notifications
You must be signed in to change notification settings - Fork 0
/
NWK_reader.py
110 lines (80 loc) · 2.36 KB
/
NWK_reader.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
109
110
# -*- coding: utf-8 -*-
from NWK_reader_classes import *
def line_to_list(line):
name = line.split()[0]
line2 = line.replace(" =", ",")
line2 = line2.replace("'", "")
line2 = line2.replace("\n", "")
string_list = line2.split(", ")
return string_list, name
file = open("przykladowy_NWK", 'r')
readline = file.readlines()
nwk = NwkFile()
i = 0
# zaczytywanie początku pliku
while i < len(readline) and "POINTS" not in readline[i]:
nwk.add_start(readline[i])
i += 1
i += 1
# zaczytywanie punktów do klasy nwkFile
while i < len(readline) and "EndSect // POINTS" not in readline[i]:
line = readline[i]
stringList, name = line_to_list(line)
nwk.add_point(stringList, name)
i += 1
# przejście do pierwszego "brancha"
while "[branch]" not in readline[i]:
i += 1
# zaczytywanie poszczególnych klas
while i < len(readline):
line = readline[i]
if not line.split():
i += 1
continue
stringList, name = line_to_list(line)
if "[branch]" in line:
nwk.branchList.append(Branch())
cl = nwk.branchList[-1]
elif "[linkchannel]" in line:
cl.linkChannel = LinkChannel(cl)
cl = cl.linkChannel
elif "[Cross_Section]" in line:
cl.crossSection = CrossSection(cl)
cl = cl.crossSection
elif "[weir_data]" in line:
nwk.weirList.append(Weir())
cl = nwk.weirList[-1]
wr = True
elif "[ReservoirData]" in line:
cl.reservoir = ReservoirData(cl)
cl = cl.reservoir
elif "[Elevation]" in line:
cl.elevation = Elevation(cl)
cl = cl.elevation
elif "[Geometry]" in line:
cl.geometry = Geometry(cl)
cl = cl.geometry
elif "[Level_Width]" in line:
cl.levelWidth = LevelWidth(cl)
cl = cl.levelWidth
elif "[culvert_data]" in line:
nwk.culvertList.append(Culvert())
cl = nwk.culvertList[-1]
cr = True
elif "[Irregular]" in line:
cl.irregular = Irregular(cl)
cl = cl.irregular
elif cl.end in line and cl.parent is None:
i += 1
continue
elif cl.end in line:
cl = cl.parent
else:
cl.add_paramaters(stringList, name, line)
i += 1
print("zaczytano dane")
# Przetwarzanie typow danych
change_type(nwk)
print("All done")
print(nwk.branchList[8].linkChannel.crossSection.data)
print("All done")