Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
uvahotspot
GitHub Repository: uvahotspot/HotSpot
Path: blob/master/scripts/split_grid_steady.py
612 views
1
#!/usr/bin/python3
2
3
import subprocess
4
import sys
5
6
usage = """
7
usage: split_grid_steady.py <grid_steady_file> <layers> <rows> <cols>
8
9
Takes a single grid_steady_file and splits it into layer-specific temperature files.
10
11
<grid_steady_file> -- path to the grid steady file (eg: example.grid.steady)
12
<layers> -- no. of layers
13
<rows> -- no. of rows in the grid
14
<cols> -- no. of cols in the grid
15
"""
16
17
if len(sys.argv) != 5:
18
print(usage)
19
sys.exit(0)
20
21
grid_steady_file = sys.argv[1]
22
grid_steady_prefix = grid_steady_file.split('.')[0]
23
num_layers = int(sys.argv[2])
24
num_rows = int(sys.argv[3])
25
num_cols = int(sys.argv[4])
26
27
with open(grid_steady_file, "r") as ifp:
28
for i in range(num_layers):
29
line = ifp.readline()[:-1]
30
layer_num = line.split()[1][:-1]
31
32
split_file = f"{grid_steady_prefix}_layer{layer_num}.grid.steady"
33
with open(split_file, "w") as ofp:
34
for i in range(num_rows * num_cols):
35
line = ifp.readline().split()
36
ofp.write(f"{line[0]} {round(float(line[1]), 2)}\n")
37
38