From b1e4d96fb7d17113921c9c657a650df7c707927b Mon Sep 17 00:00:00 2001 From: archerC Date: Thu, 30 Aug 2018 15:40:36 +0800 Subject: [PATCH] add a input file command #output_dir to specify the directory of output files other than the directory of the input files. --- docs/source/input.rst | 12 ++++++++++++ gprMax/grid.py | 1 + gprMax/input_cmds_file.py | 2 +- gprMax/input_cmds_singleuse.py | 6 ++++++ gprMax/model_build_run.py | 18 ++++++++++++++++-- 5 files changed, 36 insertions(+), 3 deletions(-) diff --git a/docs/source/input.rst b/docs/source/input.rst index 0101ddbf..65edcb96 100644 --- a/docs/source/input.rst +++ b/docs/source/input.rst @@ -153,6 +153,18 @@ Allows you to control the amount of information displayed on screen when gprMax where ``c1`` can be either y (yes) or n (no) which turns on or off the messages on the screen. The default value is y. When messages are on, gprMax will display on the screen information the translation of space and time values to cell coordinates, iteration number, material parameters etc... This information can be useful for error checking. +#output_dir: +---------- + +Allows you to control the directory of output files. The syntax of the command is: + +.. code-block:: none + + #output_dir: str1 + +where ``str1`` can be either the absolute path of the output directory or relative to the directory of the input files. The default value is the same as the directory of the input files. + + #num_threads: ----------------- diff --git a/gprMax/grid.py b/gprMax/grid.py index 83e93b8e..b025b728 100644 --- a/gprMax/grid.py +++ b/gprMax/grid.py @@ -86,6 +86,7 @@ class FDTDGrid(Grid): def __init__(self): self.inputfilename = '' self.inputdirectory = '' + self.outputdirectory = '' self.title = '' self.messages = True self.tqdmdisable = False diff --git a/gprMax/input_cmds_file.py b/gprMax/input_cmds_file.py index 7f36668a..39b6baa3 100644 --- a/gprMax/input_cmds_file.py +++ b/gprMax/input_cmds_file.py @@ -192,7 +192,7 @@ def check_cmd_names(processedlines, checkessential=True): essentialcmds = ['#domain', '#dx_dy_dz', '#time_window'] # Commands that there should only be one instance of in a model - singlecmds = dict.fromkeys(['#domain', '#dx_dy_dz', '#time_window', '#title', '#messages', '#num_threads', '#time_step_stability_factor', '#pml_cells', '#excitation_file', '#src_steps', '#rx_steps', '#taguchi', '#end_taguchi'], None) + singlecmds = dict.fromkeys(['#domain', '#dx_dy_dz', '#time_window', '#title', '#messages', '#num_threads', '#time_step_stability_factor', '#pml_cells', '#excitation_file', '#src_steps', '#rx_steps', '#taguchi', '#end_taguchi', '#output_dir'], None) # Commands that there can be multiple instances of in a model - these will be lists within the dictionary multiplecmds = {key: [] for key in ['#geometry_view', '#geometry_objects_write', '#material', '#soil_peplinski', '#add_dispersion_debye', '#add_dispersion_lorentz', '#add_dispersion_drude', '#waveform', '#voltage_source', '#hertzian_dipole', '#magnetic_dipole', '#transmission_line', '#rx', '#rx_array', '#snapshot', '#pml_cfs', '#include_file']} diff --git a/gprMax/input_cmds_singleuse.py b/gprMax/input_cmds_singleuse.py index 21828b2b..afe809b5 100644 --- a/gprMax/input_cmds_singleuse.py +++ b/gprMax/input_cmds_singleuse.py @@ -312,3 +312,9 @@ def process_singlecmds(singlecmds, G): print('User waveform {} created using {} and, if required, interpolation parameters (kind: {}, fill value: {}).'.format(w.ID, timestr, kwargs['kind'], kwargs['fill_value'])) G.waveforms.append(w) + + # set output dir + cmd = '#output_dir' + if singlecmds[cmd] is not None: + output_dir = singlecmds[cmd] + G.outputdirectory = output_dir \ No newline at end of file diff --git a/gprMax/model_build_run.py b/gprMax/model_build_run.py index d6442faf..d46eccb5 100644 --- a/gprMax/model_build_run.py +++ b/gprMax/model_build_run.py @@ -332,8 +332,22 @@ def run_model(args, currentmodelrun, modelend, numbermodelruns, inputfile, usern # Run simulation else: # Output filename - inputfileparts = os.path.splitext(os.path.join(G.inputdirectory, G.inputfilename)) - outputfile = inputfileparts[0] + appendmodelnumber + '.out' + inputdirectory, inputfilename = os.path.split(os.path.join(G.inputdirectory, G.inputfilename)) + if G.outputdirectory is None: + output_dir = inputdirectory + else: + output_dir = G.outputdirectory + # save current directory + curdir = os.getcwd() + os.chdir(inputdirectory) + output_dir = os.path.abspath(output_dir) + if not os.path.isdir(output_dir): + os.mkdir(output_dir) + print('\nmaking outputdirectory: {}'.format(output_dir)) + # restore current directory + os.chdir(curdir) + basename, ext = os.path.splitext(inputfilename) + outputfile = os.path.join(output_dir, basename + appendmodelnumber + '.out') print('\nOutput file: {}\n'.format(outputfile)) # Main FDTD solving functions for either CPU or GPU