Skip to content

Commit 11acdce

Browse files
committed
Refactor parameter file handling
Signed-off-by: Prasanna <iprasannamb@gmail.com>
1 parent 4ef989f commit 11acdce

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

concore.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,15 @@ def safe_literal_eval(filename, defaultValue):
125125
inpath = "./in" #must be rel path for local
126126
outpath = "./out"
127127
simtime = 0
128+
concore_params_file = os.path.join(inpath, "1", "concore.params")
129+
concore_maxtime_file = os.path.join(inpath, "1", "concore.maxtime")
128130

129131
#9/21/22
130132
# ===================================================================
131133
# Parameter Parsing
132134
# ===================================================================
133135
try:
134-
sparams_path = os.path.join(inpath, "1", "concore.params")
136+
sparams_path = concore_params_file
135137
if os.path.exists(sparams_path):
136138
with open(sparams_path, "r") as f:
137139
sparams = f.read()
@@ -171,8 +173,7 @@ def tryparam(n, i):
171173
def default_maxtime(default):
172174
"""Read maximum simulation time from file or use default."""
173175
global maxtime
174-
maxtime_path = os.path.join(inpath, "1", "concore.maxtime")
175-
maxtime = safe_literal_eval(maxtime_path, default)
176+
maxtime = safe_literal_eval(concore_maxtime_file, default)
176177

177178
default_maxtime(100)
178179

@@ -283,14 +284,12 @@ def write(port_identifier, name, val, delta=0):
283284
print(f"ZMQ write error on port {port_identifier} (name: {name}): {e}")
284285
except Exception as e:
285286
print(f"Unexpected error during ZMQ write on port {port_identifier} (name: {name}): {e}")
287+
return
286288

287289
# Case 2: File-based port
288290
try:
289-
if isinstance(port_identifier, str) and port_identifier in zmq_ports:
290-
file_path = os.path.join("..", port_identifier, name)
291-
else:
292-
file_port_num = int(port_identifier)
293-
file_path = os.path.join(outpath, str(file_port_num), name)
291+
file_port_num = int(port_identifier)
292+
file_path = os.path.join(outpath, str(file_port_num), name)
294293
except ValueError:
295294
print(f"Error: Invalid port identifier '{port_identifier}' for file operation. Must be integer or ZMQ name.")
296295
return

0 commit comments

Comments
 (0)