Merge pull request #291 from smharper/zero_padded_statepoint

Batch number on statepoint files are zero-padded
This commit is contained in:
Paul Romano 2014-08-07 20:05:39 -04:00
commit b71f513320
13 changed files with 103 additions and 49 deletions

View file

@ -342,9 +342,9 @@ foreach(test ${TESTS})
# Handle restart tests separately
if(${test} MATCHES "test_statepoint_restart")
set(RESTART_FILE statepoint.7.h5)
set(RESTART_FILE statepoint.07.h5)
elseif(${test} MATCHES "test_sourcepoint_restart")
set(RESTART_FILE statepoint.7.h5 source.7.h5)
set(RESTART_FILE statepoint.07.h5 source.07.h5)
elseif(${test} MATCHES "test_particle_restart")
set(RESTART_FILE particle_12_192.h5)
else(${test} MATCHES "test_statepoint_restart")
@ -355,9 +355,9 @@ foreach(test ${TESTS})
# Handle restart tests separately
if(${test} MATCHES "test_statepoint_restart")
set(RESTART_FILE statepoint.7.binary)
set(RESTART_FILE statepoint.07.binary)
elseif(${test} MATCHES "test_sourcepoint_restart")
set(RESTART_FILE statepoint.7.binary source.7.binary)
set(RESTART_FILE statepoint.07.binary source.07.binary)
elseif(${test} MATCHES "test_particle_restart")
set(RESTART_FILE particle_12_192.binary)
else(${test} MATCHES "test_statepoint_restart")

View file

@ -16,7 +16,7 @@ module state_point
use error, only: fatal_error, warning
use global
use output, only: write_message, time_stamp
use string, only: to_str
use string, only: to_str, zero_padded, count_digits
use output_interface
use tally_header, only: TallyObject
@ -44,7 +44,7 @@ contains
! Set filename for state point
filename = trim(path_output) // 'statepoint.' // &
trim(to_str(current_batch))
& zero_padded(current_batch, count_digits(n_batches))
! Append appropriate extension
#ifdef HDF5
@ -305,7 +305,9 @@ contains
if (source_separate) then
! Set filename
filename = trim(path_output) // 'source.' // trim(to_str(current_batch))
filename = trim(path_output) // 'source.' // &
& zero_padded(current_batch, count_digits(n_batches))
#ifdef HDF5
filename = trim(filename) // '.h5'
#else
@ -326,7 +328,7 @@ contains
! Set filename for state point
filename = trim(path_output) // 'statepoint.' // &
trim(to_str(current_batch))
& zero_padded(current_batch, count_digits(n_batches))
#ifdef HDF5
filename = trim(filename) // '.h5'
#else

View file

@ -1,7 +1,7 @@
module string
use constants, only: MAX_WORDS, MAX_LINE_LEN, ERROR_INT, ERROR_REAL
use error, only: warning
use error, only: fatal_error, warning
use global, only: message
implicit none
@ -184,6 +184,39 @@ contains
end subroutine upper_case
!===============================================================================
! ZERO_PADDED returns a string of the input integer padded with zeros to the
! desired number of digits. Do not include the sign in n_digits for negative
! integers.
!===============================================================================
function zero_padded(num, n_digits) result(str)
integer, intent(in) :: num
integer, intent(in) :: n_digits
character(11) :: str
character(8) :: zp_form
! Make sure n_digits is reasonable. 10 digits is the maximum needed for the
! largest integer(4).
if (n_digits > 10) then
message = 'zero_padded called with an unreasonably large n_digits (>10)'
call fatal_error()
end if
! Write a format string of the form '(In.m)' where n is the max width and
! m is the min width. If a sign is present, then n must be one greater
! than m.
if (num < 0) then
write(zp_form, '("(I", I0, ".", I0, ")")') n_digits+1, n_digits
else
write(zp_form, '("(I", I0, ".", I0, ")")') n_digits, n_digits
end if
! Format the number.
write(str, zp_form) num
end function zero_padded
!===============================================================================
! IS_NUMBER determines whether a string of characters is all 0-9 characters
!===============================================================================
@ -268,6 +301,25 @@ contains
end function ends_with
!===============================================================================
! COUNT_DIGITS returns the number of digits needed to represent the input
! integer.
!===============================================================================
function count_digits(num) result(n_digits)
integer, intent(in) :: num
integer :: n_digits
n_digits = 1
do while (num / 10**(n_digits) /= 0 .and. abs(num / 10 **(n_digits-1)) /= 1&
&.and. n_digits /= 10)
! Note that 10 digits is the maximum needed to represent an integer(4) so
! the loop automatically exits when n_digits = 10.
n_digits = n_digits + 1
end do
end function count_digits
!===============================================================================
! INT4_TO_STR converts an integer(4) to a string.
!===============================================================================

View file

@ -10,7 +10,7 @@ import statepoint
if len(sys.argv) > 1:
sp = statepoint.StatePoint(sys.argv[1])
else:
sp = statepoint.StatePoint('statepoint.8.binary')
sp = statepoint.StatePoint('statepoint.08.binary')
sp.read_results()
sp.read_source()

View file

@ -30,7 +30,7 @@ def test_statepoint_exists():
'Statepoint file detected that is not binary or hdf5.'
def test_results():
statepoint = glob.glob(os.path.join(cwd, 'statepoint.8.*'))
statepoint = glob.glob(os.path.join(cwd, 'statepoint.08.*'))
call(['python', 'results.py', statepoint[0]])
compare = filecmp.cmp('results_test.dat', 'results_true.dat')
if not compare:

View file

@ -10,7 +10,7 @@ import statepoint
if len(sys.argv) > 1:
sp = statepoint.StatePoint(sys.argv[1])
else:
sp = statepoint.StatePoint('statepoint.8.binary')
sp = statepoint.StatePoint('statepoint.08.binary')
sp.read_results()
sp.read_source()

View file

@ -30,7 +30,7 @@ def test_statepoint_exists():
'Statepoint file detected that is not binary or hdf5.'
def test_results():
statepoint = glob.glob(os.path.join(cwd, 'statepoint.8.*'))
statepoint = glob.glob(os.path.join(cwd, 'statepoint.08.*'))
call(['python', 'results.py', statepoint[0]])
compare = filecmp.cmp('results_test.dat', 'results_true.dat')
if not compare:

View file

@ -28,7 +28,7 @@ def test_created_statepoint():
assert len(statepoint) == 2, '2 statepoint files must exist.'
assert statepoint[0].endswith('binary') or statepoint[0].endswith('h5'),\
'Statepoint file must either be binary or hdf5.'
sourcepoint = glob.glob(os.path.join(cwd, 'source.7.*'))
sourcepoint = glob.glob(os.path.join(cwd, 'source.07.*'))
assert len(sourcepoint) == 1, 'Either multiple or no source files found.'
assert sourcepoint[0].endswith('binary') or sourcepoint[0].endswith('h5'),\
'Source file must either be binary or hdf5.'
@ -43,8 +43,8 @@ def test_results():
os.remove(statepoint[0])
def test_restart_form1():
statepoint = glob.glob(os.path.join(cwd, 'statepoint.7.*'))
sourcepoint = glob.glob(os.path.join(cwd, 'source.7.*'))
statepoint = glob.glob(os.path.join(cwd, 'statepoint.07.*'))
sourcepoint = glob.glob(os.path.join(cwd, 'source.07.*'))
if opts.mpi_exec != '':
proc = Popen([opts.mpi_exec, '-np', opts.mpi_np, opts.exe,
'-r', statepoint[0], sourcepoint[0], cwd], stderr=STDOUT, stdout=PIPE)
@ -70,8 +70,8 @@ def test_results_form1():
os.remove(statepoint[0])
def test_restart_form2():
statepoint = glob.glob(os.path.join(cwd, 'statepoint.7.*'))
sourcepoint = glob.glob(os.path.join(cwd, 'source.7.*'))
statepoint = glob.glob(os.path.join(cwd, 'statepoint.07.*'))
sourcepoint = glob.glob(os.path.join(cwd, 'source.07.*'))
if opts.mpi_exec != '':
proc = Popen([opts.mpi_exec, '-np', opts.mpi_np, opts.exe,
'--restart', statepoint[0], sourcepoint[0], cwd], stderr=STDOUT, stdout=PIPE)
@ -97,8 +97,8 @@ def test_results_form2():
os.remove(statepoint[0])
def test_restart_serial():
statepoint = glob.glob(os.path.join(cwd, 'statepoint.7.*'))
sourcepoint = glob.glob(os.path.join(cwd, 'source.7.*'))
statepoint = glob.glob(os.path.join(cwd, 'statepoint.07.*'))
sourcepoint = glob.glob(os.path.join(cwd, 'source.07.*'))
proc = Popen([opts.exe, '--restart', statepoint[0], sourcepoint[0], cwd], stderr=STDOUT, stdout=PIPE)
print(proc.communicate()[0])
returncode = proc.returncode

View file

@ -10,7 +10,7 @@ import statepoint
if len(sys.argv) > 1:
sp = statepoint.StatePoint(sys.argv[1])
else:
sp = statepoint.StatePoint('statepoint.9.binary')
sp = statepoint.StatePoint('statepoint.09.binary')
sp.read_results()
# set up output string

View file

@ -24,21 +24,21 @@ def test_run():
assert returncode == 0, 'OpenMC did not exit successfully.'
def test_statepoints_exist():
statepoint = glob.glob(os.path.join(cwd, 'statepoint.3.*'))
assert len(statepoint) == 1, 'Either multiple or no statepoint.3 files exist.'
statepoint = glob.glob(os.path.join(cwd, 'statepoint.03.*'))
assert len(statepoint) == 1, 'Either multiple or no statepoint.03 files exist.'
assert statepoint[0].endswith('binary') or statepoint[0].endswith('h5'),\
'Statepoint.3 file is not a binary or hdf5 file.'
statepoint = glob.glob(os.path.join(cwd, 'statepoint.6.*'))
assert len(statepoint) == 1, 'Either multiple or no statepoint.6 files exist.'
statepoint = glob.glob(os.path.join(cwd, 'statepoint.06.*'))
assert len(statepoint) == 1, 'Either multiple or no statepoint.06 files exist.'
assert statepoint[0].endswith('binary') or statepoint[0].endswith('h5'),\
'Statepoint.6 file is not a binary or hdf5 file.'
statepoint = glob.glob(os.path.join(cwd, 'statepoint.9.*'))
assert len(statepoint) == 1, 'Either multiple or no statepoint.9 files exist.'
statepoint = glob.glob(os.path.join(cwd, 'statepoint.09.*'))
assert len(statepoint) == 1, 'Either multiple or no statepoint.09 files exist.'
assert statepoint[0].endswith('binary') or statepoint[0].endswith('h5'),\
'Statepoint.9 file is not a binary or hdf5 file.'
def test_results():
statepoint = glob.glob(os.path.join(cwd, 'statepoint.9.*'))
statepoint = glob.glob(os.path.join(cwd, 'statepoint.09.*'))
call(['python', 'results.py', statepoint[0]])
compare = filecmp.cmp('results_test.dat', 'results_true.dat')
if not compare:

View file

@ -25,20 +25,20 @@ def test_run():
assert returncode == 0, 'OpenMC did not exit successfully.'
def test_statepoints_exist():
statepoint = glob.glob(os.path.join(cwd, 'statepoint.2.*'))
assert len(statepoint) == 1, 'Either multiple or no statepoint.2 files exist.'
statepoint = glob.glob(os.path.join(cwd, 'statepoint.02.*'))
assert len(statepoint) == 1, 'Either multiple or no statepoint.02 files exist.'
assert statepoint[0].endswith('binary') or statepoint[0].endswith('h5'),\
'Statepoint.2 file is not a binary or hdf5 file.'
statepoint = glob.glob(os.path.join(cwd, 'statepoint.4.*'))
assert len(statepoint) == 1, 'Either multiple or no statepoint.4 files exist.'
statepoint = glob.glob(os.path.join(cwd, 'statepoint.04.*'))
assert len(statepoint) == 1, 'Either multiple or no statepoint.04 files exist.'
assert statepoint[0].endswith('binary') or statepoint[0].endswith('h5'),\
'Statepoint.4 file is not a binary or hdf5 file.'
statepoint = glob.glob(os.path.join(cwd, 'statepoint.6.*'))
assert len(statepoint) == 1, 'Either multiple or no statepoint.6 files exist.'
statepoint = glob.glob(os.path.join(cwd, 'statepoint.06.*'))
assert len(statepoint) == 1, 'Either multiple or no statepoint.06 files exist.'
assert statepoint[0].endswith('binary') or statepoint[0].endswith('h5'),\
'Statepoint.6 file is not a binary or hdf5 file.'
statepoint = glob.glob(os.path.join(cwd, 'statepoint.8.*'))
assert len(statepoint) == 1, 'Either multiple or no statepoint.8 files exist.'
statepoint = glob.glob(os.path.join(cwd, 'statepoint.08.*'))
assert len(statepoint) == 1, 'Either multiple or no statepoint.08 files exist.'
assert statepoint[0].endswith('binary') or statepoint[0].endswith('h5'),\
'Statepoint.8 file is not a binary or hdf5 file.'
statepoint = glob.glob(os.path.join(cwd, 'statepoint.10.*'))

View file

@ -11,7 +11,7 @@ import statepoint
if len(sys.argv) > 1:
sp = statepoint.StatePoint(sys.argv[1])
else:
sp = statepoint.StatePoint('statepoint.7.binary')
sp = statepoint.StatePoint('statepoint.07.binary')
sp.read_results()
# extract tally results and convert to vector

View file

@ -24,13 +24,13 @@ def test_run():
assert returncode == 0, 'OpenMC did not exit successfully.'
def test_created_statepoint():
statepoint = glob.glob(os.path.join(cwd, 'statepoint.7.*'))
statepoint = glob.glob(os.path.join(cwd, 'statepoint.07.*'))
assert len(statepoint) == 1, 'Either multiple or no statepoint files exist.'
assert statepoint[0].endswith('binary') or statepoint[0].endswith('h5'),\
'Statepoint file is not a binary or hdf5 file.'
def test_results():
statepoint = glob.glob(os.path.join(cwd, 'statepoint.7.*'))
statepoint = glob.glob(os.path.join(cwd, 'statepoint.07.*'))
call(['python', 'results.py', statepoint[0]])
compare = filecmp.cmp('results_test.dat', 'results_true.dat')
if not compare:
@ -38,7 +38,7 @@ def test_results():
assert compare, 'Initial test results do not agree.'
def test_restart_form1():
statepoint = glob.glob(os.path.join(cwd, 'statepoint.7.*'))
statepoint = glob.glob(os.path.join(cwd, 'statepoint.07.*'))
if opts.mpi_exec != '':
proc = Popen([opts.mpi_exec, '-np', opts.mpi_np, opts.exe,
'-r', statepoint[0], cwd], stderr=STDOUT, stdout=PIPE)
@ -49,13 +49,13 @@ def test_restart_form1():
assert returncode == 0, 'OpenMC restart 1 did not exit successfully.'
def test_created_statepoint_form1():
statepoint = glob.glob(os.path.join(cwd, 'statepoint.7.*'))
statepoint = glob.glob(os.path.join(cwd, 'statepoint.07.*'))
assert len(statepoint) == 1, 'Either multiple or no statepoint files exist.'
assert statepoint[0].endswith('binary') or statepoint[0].endswith('h5'),\
'Statepoint file is not a binary or hdf5 file.'
def test_results_form1():
statepoint = glob.glob(os.path.join(cwd, 'statepoint.7.*'))
statepoint = glob.glob(os.path.join(cwd, 'statepoint.07.*'))
call(['python', 'results.py', statepoint[0]])
compare = filecmp.cmp('results_test.dat', 'results_true.dat')
if not compare:
@ -63,7 +63,7 @@ def test_results_form1():
assert compare, 'Restart 1 test results do not agree.'
def test_restart_form2():
statepoint = glob.glob(os.path.join(cwd, 'statepoint.7.*'))
statepoint = glob.glob(os.path.join(cwd, 'statepoint.07.*'))
if opts.mpi_exec != '':
proc = Popen([opts.mpi_exec, '-np', opts.mpi_np, opts.exe,
'--restart', statepoint[0], cwd], stderr=STDOUT, stdout=PIPE)
@ -74,13 +74,13 @@ def test_restart_form2():
assert returncode == 0, 'OpenMC restart 2 did not exit successfully.'
def test_created_statepoint_form2():
statepoint = glob.glob(os.path.join(cwd, 'statepoint.7.*'))
statepoint = glob.glob(os.path.join(cwd, 'statepoint.07.*'))
assert len(statepoint) == 1, 'Either multiple or no statepoint files exist.'
assert statepoint[0].endswith('binary') or statepoint[0].endswith('h5'),\
'Statepoint file is not a binary or hdf5 file.'
def test_results_form2():
statepoint = glob.glob(os.path.join(cwd, 'statepoint.7.*'))
statepoint = glob.glob(os.path.join(cwd, 'statepoint.07.*'))
call(['python', 'results.py', statepoint[0]])
compare = filecmp.cmp('results_test.dat', 'results_true.dat')
if not compare:
@ -88,20 +88,20 @@ def test_results_form2():
assert compare, 'Restart 2 test results do not agree.'
def test_restart_serial():
statepoint = glob.glob(os.path.join(cwd, 'statepoint.7.*'))
statepoint = glob.glob(os.path.join(cwd, 'statepoint.07.*'))
proc = Popen([opts.exe, '--restart', statepoint[0], cwd], stderr=STDOUT, stdout=PIPE)
print(proc.communicate()[0])
returncode = proc.returncode
assert returncode == 0, 'OpenMC restart serial did not exit successfully.'
def test_created_statepoint_serial():
statepoint = glob.glob(os.path.join(cwd, 'statepoint.7.*'))
statepoint = glob.glob(os.path.join(cwd, 'statepoint.07.*'))
assert len(statepoint) == 1, 'Either multiple or no statepoint files exist.'
assert statepoint[0].endswith('binary') or statepoint[0].endswith('h5'),\
'Statepoint file is not a binary or hdf5 file.'
def test_results_serial():
statepoint = glob.glob(os.path.join(cwd, 'statepoint.7.*'))
statepoint = glob.glob(os.path.join(cwd, 'statepoint.07.*'))
call(['python', 'results.py', statepoint[0]])
compare = filecmp.cmp('results_test.dat', 'results_true.dat')
if not compare:
@ -109,7 +109,7 @@ def test_results_serial():
assert compare, 'Restart serial test results do not agree.'
def teardown():
output = glob.glob(os.path.join(cwd, 'statepoint.7.*'))
output = glob.glob(os.path.join(cwd, 'statepoint.07.*'))
output.append(os.path.join(cwd, 'results_test.dat'))
for f in output:
if os.path.exists(f):