44 lines
1.4 KiB
Python
44 lines
1.4 KiB
Python
import re
|
|
|
|
def parse_temp_file(temp_file):
|
|
node_temps = {}
|
|
with open(temp_file, 'r') as f:
|
|
for line in f:
|
|
match = re.match(r'^\s*(\d+)\s+([\d.]+)\s*$', line.strip())
|
|
if match:
|
|
node = int(match.group(1))
|
|
temp = float(match.group(2))
|
|
node_temps[node] = temp
|
|
return node_temps
|
|
|
|
def parse_node_file(node_file):
|
|
node_coords = {}
|
|
with open(node_file, 'r') as f:
|
|
for line in f:
|
|
match = re.match(r'^\s*(\d+)\s+([-\d.Ee]+)\s+([-\d.Ee]+)\s+([-\d.Ee]+)\s+[-\d.]+', line.strip())
|
|
if match:
|
|
node = int(match.group(1))
|
|
x = float(match.group(2))
|
|
y = float(match.group(3))
|
|
node_coords[node] = (x, y)
|
|
return node_coords
|
|
|
|
def process_files(temp_file, node_file, output_file):
|
|
node_temps = parse_temp_file(temp_file)
|
|
node_coords = parse_node_file(node_file)
|
|
|
|
with open(output_file, 'w') as f:
|
|
for node in node_temps:
|
|
if node in node_coords:
|
|
x, y = node_coords[node]
|
|
temp = node_temps[node]
|
|
f.write(f"100 {int(x)} {int(y)} {temp}\n")
|
|
else:
|
|
print(f"Warning: Node {node} not found in coordinate file")
|
|
|
|
temp_file = "temp_data.txt"
|
|
node_file = "node_data.txt"
|
|
output_file = "ansys.txt"
|
|
|
|
process_files(temp_file, node_file, output_file)
|
|
print(f"Output written to {output_file}") |