From ffb03159b02854c497bfcb61c7b83a4fe655c91a Mon Sep 17 00:00:00 2001 From: David Minton Date: Wed, 23 Feb 2022 12:58:58 -0500 Subject: [PATCH] Fixed some problems related to directory structure generation and accidentally deleting ctem.dat after generating it --- python/ctem/ctem/driver.py | 19 +++++++++---------- python/ctem/ctem/io.py | 2 +- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/python/ctem/ctem/driver.py b/python/ctem/ctem/driver.py index c09cf20a..9bda0aa8 100644 --- a/python/ctem/ctem/driver.py +++ b/python/ctem/ctem/driver.py @@ -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, @@ -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 @@ -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): diff --git a/python/ctem/ctem/io.py b/python/ctem/ctem/io.py index 92f5dc7a..4088c7ea 100644 --- a/python/ctem/ctem/io.py +++ b/python/ctem/ctem/io.py @@ -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)