From a4b0e70400bb2da7f9e682aef7756345f385fac1 Mon Sep 17 00:00:00 2001 From: Craig Warren Date: Tue, 19 Jan 2016 16:27:01 +0000 Subject: [PATCH] Implemented searching for available outputs. --- tools/outputfiles_merge.py | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/tools/outputfiles_merge.py b/tools/outputfiles_merge.py index 750e5ad3..f941e14b 100644 --- a/tools/outputfiles_merge.py +++ b/tools/outputfiles_merge.py @@ -30,40 +30,34 @@ args = parser.parse_args() basefilename = args.basefilename modelruns = args.modelruns -outputfile = basefilename + '_all.out' +outputfile = basefilename + '_merge.out' path = '/rxs/rx1' # Combined output file fout = h5py.File(outputfile, 'w') # Add positional data for rxs -for rx in range(modelruns): - fin = h5py.File(basefilename + str(rx + 1) + '.out', 'r') - if rx == 0: +for model in range(modelruns): + fin = h5py.File(basefilename + str(model + 1) + '.out', 'r') + availableoutputs = list(fin[path].keys()) + if model == 0: fout.attrs['Iterations'] = fin.attrs['Iterations'] fout.attrs['dt'] = fin.attrs['dt'] fields = fout.create_group(path) - fields['Ex'] = np.zeros((fout.attrs['Iterations'], modelruns), dtype=fin[path + '/Ex'].dtype) - fields['Ey'] = np.zeros((fout.attrs['Iterations'], modelruns), dtype=fin[path + '/Ex'].dtype) - fields['Ez'] = np.zeros((fout.attrs['Iterations'], modelruns), dtype=fin[path + '/Ex'].dtype) - fields['Hx'] = np.zeros((fout.attrs['Iterations'], modelruns), dtype=fin[path + '/Ex'].dtype) - fields['Hy'] = np.zeros((fout.attrs['Iterations'], modelruns), dtype=fin[path + '/Ex'].dtype) - fields['Hz'] = np.zeros((fout.attrs['Iterations'], modelruns), dtype=fin[path + '/Ex'].dtype) - - fields[path + '/Ex'][:,rx] = fin[path + '/Ex'][:] - fields[path + '/Ey'][:,rx] = fin[path + '/Ey'][:] - fields[path + '/Ez'][:,rx] = fin[path + '/Ez'][:] - fields[path + '/Hx'][:,rx] = fin[path + '/Hx'][:] - fields[path + '/Hy'][:,rx] = fin[path + '/Hy'][:] - fields[path + '/Hz'][:,rx] = fin[path + '/Hz'][:] + for output in availableoutputs: + fields[output] = np.zeros((fout.attrs['Iterations'], modelruns), dtype=fin[path + '/' + output].dtype) + + for output in availableoutputs: + fields[path + '/' + output][:,model] = fin[path + '/' + output][:] + fin.close() fout.close() check = input('Do you want to remove the multiple individual output files? [y] or n:') if not check or check == 'y': - for rx in range(modelruns): - file = basefilename + str(rx + 1) + '.out' + for model in range(modelruns): + file = basefilename + str(model + 1) + '.out' os.remove(file)