Skip to content

Commit

Permalink
Added debugging feature
Browse files Browse the repository at this point in the history
  • Loading branch information
ajulik1997 authored Aug 31, 2017
1 parent fb4fc44 commit 048d6fb
Showing 1 changed file with 33 additions and 6 deletions.
39 changes: 33 additions & 6 deletions SWINE.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,18 @@

print("==================================================")
while True:
print(Fore.MAGENTA + "Would like to load a previous plot (L) or run a simulation (S)? [L/S] ", end='')
print(Fore.MAGENTA + "Would like to run a simulation (S), simulate with debug mode (D), or load a previous plot (L)? [S/D/L] ", end='')
load_or_sim = str(input()).upper()
if load_or_sim == 'L' or load_or_sim == 'S':
if load_or_sim == 'L' or load_or_sim == 'S' or load_or_sim == 'D':
if load_or_sim == 'L':
unpickle = True
debug = False
if load_or_sim == 'S':
unpickle = False
debug = False
if load_or_sim == 'D':
unpickle = False
debug = True
break
else:
print(Fore.YELLOW + "That is not a recongnised option!")
Expand All @@ -134,6 +139,15 @@
print("Exitting...")
sys.exit()

############################################################
# Opens file for debugging, all external output will be
# piped here
############################################################

if debug == True:
debugfile = open('debug.log', 'a')
debugfile.write("==================================================\n")

############################################################
# Ask user whether to use the default OffSpec-based .instr
# file for this simulation or use their own
Expand Down Expand Up @@ -239,7 +253,10 @@
INSTRtoC = mcstas, '-I', ' -I '.join(mclib), '-t', os.path.split(instr)[1]
try:
os.chdir(os.path.split(instr)[0])
check_call(' '.join(INSTRtoC), creationflags=CREATE_NEW_CONSOLE)
if debug == False:
check_call(' '.join(INSTRtoC), creationflags=CREATE_NEW_CONSOLE)
if debug == True:
check_call(' '.join(INSTRtoC), stdout=debugfile, stderr=debugfile)
os.chdir(cwd)
except:
print(Fore.RED + "An unknown error has occured while compiling to C...")
Expand Down Expand Up @@ -268,7 +285,10 @@
sys.exit()

try:
check_call('gcc_temp.bat', creationflags=CREATE_NEW_CONSOLE)
if debug == False:
check_call('gcc_temp.bat', creationflags=CREATE_NEW_CONSOLE)
if debug == True:
check_call('gcc_temp.bat', stdout=debugfile, stderr=debugfile)
except:
print(Fore.RED + "An unknown error has occured while compiling to binary...")
print(Fore.RED + "Exitting...")
Expand Down Expand Up @@ -490,7 +510,10 @@
'| PU:',format(float(debug1[calls1_done][2]), '03.2f'),
'| Res:',format(float(debug1[calls1_done][3]), '03.2f'), '|')

sim = Popen(calls1[calls1_done], creationflags=CREATE_NEW_CONSOLE)
if debug == False:
sim = Popen(calls1[calls1_done], creationflags=CREATE_NEW_CONSOLE)
if debug == True:
sim = Popen(calls1[calls1_done], stdout=debugfile, stderr=debugfile)
running_calls.append(sim)
calls1_done = calls1_done + 1

Expand Down Expand Up @@ -519,7 +542,10 @@
'| S1W:',format(debug2[calls2_done][1], '03.2f'),
'| S2W:',format(debug2[calls2_done][2], '03.2f'), '|')

sim = Popen(calls2[calls2_done], creationflags=CREATE_NEW_CONSOLE)
if debug == False:
sim = Popen(calls2[calls2_done], creationflags=CREATE_NEW_CONSOLE)
if debug == True:
sim = Popen(calls2[calls2_done], stdout=debugfile, stderr=debugfile)
running_calls.append(sim)
calls2_done = calls2_done + 1

Expand All @@ -541,6 +567,7 @@

print("Collecting data...")
os.chdir(swinedir)
time.sleep(1)
for folder in os.listdir():
dim1 = str(folder).split('][')[0][2:]
dim2 = str(folder).split('][')[1][:-1]
Expand Down

0 comments on commit 048d6fb

Please sign in to comment.