Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed some problems related to directory structure generation and accidentally deleting ctem.dat after generating it
  • Loading branch information
daminton committed Feb 23, 2022
1 parent 7557f79 commit ffb0315
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
19 changes: 9 additions & 10 deletions python/ctem/ctem/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Simulation:
it in from a file (default name is ctem.in). It also creates the directory structure needed to store simulation
files if necessary.
"""
def __init__(self, param_file="ctem.in"):
def __init__(self, param_file="ctem.in", isnew=True):
currentdir = os.getcwd()
self.user = {
'restart': None,
Expand Down Expand Up @@ -78,14 +78,19 @@ def __init__(self, param_file="ctem.in"):
sfdfile = os.path.join(self.user['workingdir'], self.user['sfdcompare'])
self.ph1 = io.read_formatted_ascii(sfdfile, skip_lines=0)

# Scale the production function to the simulation domain
self.scale_production()

# Starting new or old run?
if (self.user['restart'].upper() == 'F'):
if (self.user['restart'].upper() == 'F' and isnew):
print('Starting a new run')

io.create_dir_structure(self.user)
# Delete any old output files
for k, v in self.output_filenames.items():
if os.path.isfile(v):
os.remove(v)

# Scale the production function to the simulation domain
self.scale_production()

if (self.user['runtype'].upper() == 'STATISTICAL'):
self.user['ncount'] = 1
Expand All @@ -94,16 +99,10 @@ def __init__(self, param_file="ctem.in"):
io.write_datfile(self.user, self.output_filenames['dat'], self.seedarr)
else:
self.user['ncount'] = 0

# Delete any old output files
for k, v in self.output_filenames.items():
if os.path.isfile(v):
os.remove(v)
else:
print('Continuing a previous run')
self.process_interval(isnew=False)


return

def scale_production(self):
Expand Down
2 changes: 1 addition & 1 deletion python/ctem/ctem/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def create_dir_structure(user):
directories = ['dist', 'misc', 'rego', 'rplot', 'surf', 'shaded']

for directory in directories:
dir_test = user['workingdir'] + directory
dir_test = os.path.join(user['workingdir'], directory)
if not os.path.isdir(dir_test):
os.makedirs(dir_test)

Expand Down

0 comments on commit ffb0315

Please sign in to comment.