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