Removed need for simple string, merged back in with string

This commit is contained in:
Adam Nelson 2016-02-03 13:20:01 -05:00
parent 1aa80bbac8
commit 89910d71fd
29 changed files with 403 additions and 417 deletions

View file

@ -19,7 +19,7 @@ module ace
use secondary_correlated, only: CorrelatedAngleEnergy
use secondary_kalbach, only: KalbachMann
use secondary_uncorrelated, only: UncorrelatedAngleEnergy
use simple_string, only: to_str, to_lower
use string, only: to_str, to_lower
implicit none

View file

@ -49,17 +49,17 @@ contains
subroutine compute_xs()
use constants, only: FILTER_MESH, FILTER_ENERGYIN, FILTER_ENERGYOUT, &
FILTER_SURFACE, IN_RIGHT, OUT_RIGHT, IN_FRONT, &
OUT_FRONT, IN_TOP, OUT_TOP, CMFD_NOACCEL, ZERO, &
ONE, TINY_BIT
use error, only: fatal_error
use global, only: cmfd, n_cmfd_tallies, cmfd_tallies, meshes,&
matching_bins
use mesh, only: mesh_indices_to_bin
use mesh_header, only: RegularMesh
use simple_string, only: to_str
use tally_header, only: TallyObject
use constants, only: FILTER_MESH, FILTER_ENERGYIN, FILTER_ENERGYOUT, &
FILTER_SURFACE, IN_RIGHT, OUT_RIGHT, IN_FRONT, &
OUT_FRONT, IN_TOP, OUT_TOP, CMFD_NOACCEL, ZERO, &
ONE, TINY_BIT
use error, only: fatal_error
use global, only: cmfd, n_cmfd_tallies, cmfd_tallies, meshes,&
matching_bins
use mesh, only: mesh_indices_to_bin
use mesh_header, only: RegularMesh
use string, only: to_str
use tally_header, only: TallyObject
integer :: nx ! number of mesh cells in x direction
integer :: ny ! number of mesh cells in y direction
@ -625,10 +625,10 @@ contains
subroutine compute_dhat()
use constants, only: CMFD_NOACCEL, ZERO
use global, only: cmfd, cmfd_coremap, dhat_reset
use output, only: write_message
use simple_string, only: to_str
use constants, only: CMFD_NOACCEL, ZERO
use global, only: cmfd, cmfd_coremap, dhat_reset
use output, only: write_message
use string, only: to_str
integer :: nx ! maximum number of cells in x direction
integer :: ny ! maximum number of cells in y direction

View file

@ -89,9 +89,9 @@ contains
subroutine calc_fission_source()
use constants, only: CMFD_NOACCEL, ZERO, TWO
use global, only: cmfd, cmfd_coremap, master, entropy_on, current_batch
use simple_string, only: to_str
use constants, only: CMFD_NOACCEL, ZERO, TWO
use global, only: cmfd, cmfd_coremap, master, entropy_on, current_batch
use string, only: to_str
#ifdef MPI
use global, only: mpi_err
@ -213,14 +213,14 @@ contains
subroutine cmfd_reweight(new_weights)
use constants, only: ZERO, ONE
use error, only: warning, fatal_error
use global, only: meshes, source_bank, work, n_user_meshes, cmfd, &
master
use mesh_header, only: RegularMesh
use mesh, only: count_bank_sites, get_mesh_indices
use search, only: binary_search
use simple_string, only: to_str
use constants, only: ZERO, ONE
use error, only: warning, fatal_error
use global, only: meshes, source_bank, work, n_user_meshes, cmfd, &
master
use mesh_header, only: RegularMesh
use mesh, only: count_bank_sites, get_mesh_indices
use search, only: binary_search
use string, only: to_str
#ifdef MPI
use global, only: mpi_err

View file

@ -45,10 +45,10 @@ contains
subroutine read_cmfd_xml()
use constants, only: ZERO, ONE
use error, only: fatal_error, warning
use error, only: fatal_error, warning
use global
use output, only: write_message
use simple_string, only: to_lower
use output, only: write_message
use string, only: to_lower
use xml_interface
use, intrinsic :: ISO_FORTRAN_ENV

View file

@ -1,11 +1,11 @@
module distribution_univariate
use constants, only: ZERO, ONE, HALF, HISTOGRAM, LINEAR_LINEAR, &
use constants, only: ZERO, ONE, HALF, HISTOGRAM, LINEAR_LINEAR, &
MAX_LINE_LEN, MAX_WORD_LEN
use error, only: fatal_error
use random_lcg, only: prn
use spectra, only: maxwell_spectrum, watt_spectrum
use simple_string, only: to_lower
use error, only: fatal_error
use random_lcg, only: prn
use spectra, only: maxwell_spectrum, watt_spectrum
use string, only: to_lower
use xml_interface
implicit none

View file

@ -4,15 +4,15 @@ module eigenvalue
use message_passing
#endif
use constants, only: ZERO
use error, only: fatal_error, warning
use constants, only: ZERO
use error, only: fatal_error, warning
use global
use math, only: t_percentile
use mesh, only: count_bank_sites
use mesh_header, only: RegularMesh
use random_lcg, only: prn, set_particle_seed, prn_skip
use search, only: binary_search
use simple_string, only: to_str
use math, only: t_percentile
use mesh, only: count_bank_sites
use mesh_header, only: RegularMesh
use random_lcg, only: prn, set_particle_seed, prn_skip
use search, only: binary_search
use string, only: to_str
implicit none

View file

@ -1,7 +1,7 @@
module endf
use constants
use simple_string, only: to_str
use string, only: to_str
implicit none

View file

@ -10,7 +10,7 @@ module geometry
use particle_restart_write, only: write_particle_restart
use surface_header
use stl_vector, only: VectorInt
use simple_string, only: to_str
use string, only: to_str
use tally, only: score_surface_current
implicit none

View file

@ -1,32 +1,31 @@
module initialize
use ace, only: read_ace_xs, same_nuclide_list
use bank_header, only: Bank
use ace, only: read_ace_xs, same_nuclide_list
use bank_header, only: Bank
use constants
use dict_header, only: DictIntInt, ElemKeyValueII
use set_header, only: SetInt
use energy_grid, only: logarithmic_grid, grid_method, unionized_grid
use error, only: fatal_error, warning
use geometry, only: neighbor_lists, count_instance, calc_offsets, &
maximum_levels
use geometry_header, only: Cell, Universe, Lattice, RectLattice, HexLattice,&
&BASE_UNIVERSE
use dict_header, only: DictIntInt, ElemKeyValueII
use set_header, only: SetInt
use energy_grid, only: logarithmic_grid, grid_method, unionized_grid
use error, only: fatal_error, warning
use geometry, only: neighbor_lists, count_instance, calc_offsets, &
maximum_levels
use geometry_header, only: Cell, Universe, Lattice, RectLattice, HexLattice,&
&BASE_UNIVERSE
use global
use hdf5_interface, only: file_open, read_dataset, file_close, hdf5_bank_t,&
hdf5_tallyresult_t, hdf5_integer8_t
use input_xml, only: read_input_xml, cells_in_univ_dict, read_plots_xml
use material_header, only: Material
use mgxs_data, only: read_mgxs, same_nuclide_mg_list, create_macro_xs
use output, only: title, header, print_version, write_message, &
print_usage, write_xs_summary, print_plot
use random_lcg, only: initialize_prng
use state_point, only: load_state_point
use simple_string, only: to_str, starts_with, ends_with
use string, only: str_to_int
use summary, only: write_summary
use tally_header, only: TallyObject, TallyResult, TallyFilter
use tally_initialize, only: configure_tallies
use tally, only: init_tally_routines
use hdf5_interface, only: file_open, read_dataset, file_close, hdf5_bank_t,&
hdf5_tallyresult_t, hdf5_integer8_t
use input_xml, only: read_input_xml, cells_in_univ_dict, read_plots_xml
use material_header, only: Material
use mgxs_data, only: read_mgxs, same_nuclide_mg_list, create_macro_xs
use output, only: title, header, print_version, write_message, &
print_usage, write_xs_summary, print_plot
use random_lcg, only: initialize_prng
use state_point, only: load_state_point
use string, only: to_str, starts_with, ends_with, str_to_int
use summary, only: write_summary
use tally_header, only: TallyObject, TallyResult, TallyFilter
use tally_initialize,only: configure_tallies
use tally, only: init_tally_routines
#ifdef MPI
use message_passing

View file

@ -17,8 +17,8 @@ module input_xml
use random_lcg, only: prn, seed
use surface_header
use stl_vector, only: VectorInt
use simple_string, only: to_lower, to_str, starts_with, ends_with
use string, only: str_to_int, str_to_real, tokenize
use string, only: str_to_int, str_to_real, tokenize, &
to_lower, to_str, starts_with, ends_with
use tally_header, only: TallyObject, TallyFilter
use tally_initialize, only: add_tallies
use xml_interface

View file

@ -1,9 +1,9 @@
module interpolation
use constants
use endf_header, only: Tab1
use search, only: binary_search
use simple_string, only: to_str
use endf_header, only: Tab1
use search, only: binary_search
use string, only: to_str
implicit none

View file

@ -1,14 +1,14 @@
module mgxs_data
use constants
use error, only: fatal_error
use error, only: fatal_error
use global
use macroxs_header
use material_header, only: Material
use material_header, only: Material
use nuclide_header
use output, only: write_message
use set_header, only: SetChar
use simple_string, only: to_lower
use output, only: write_message
use set_header, only: SetChar
use string, only: to_lower
use xml_interface
implicit none

View file

@ -7,8 +7,7 @@ module nuclide_header
use endf, only: reaction_name
use list_header, only: ListInt
use math, only: evaluate_legendre
!use scattdata_header
use simple_string
use string
implicit none

View file

@ -16,7 +16,7 @@ module output
use particle_header, only: LocalCoord, Particle
use plot_header
use sab_header, only: SAlphaBeta
use simple_string, only: to_upper, to_str
use string, only: to_upper, to_str
use tally_header, only: TallyObject
implicit none

View file

@ -1,10 +1,10 @@
module particle_restart_write
use bank_header, only: Bank
use bank_header, only: Bank
use global
use hdf5_interface
use particle_header, only: Particle
use simple_string, only: to_str
use particle_header, only: Particle
use string, only: to_str
use hdf5

View file

@ -18,7 +18,7 @@ module physics
use random_lcg, only: prn
use search, only: binary_search
use secondary_uncorrelated, only: UncorrelatedAngleEnergy
use simple_string, only: to_str
use string, only: to_str
use spectra
implicit none

View file

@ -15,7 +15,7 @@ module physics_mg
use physics_common
use random_lcg, only: prn
use scattdata_header
use simple_string, only: to_str
use string, only: to_str
use spectra, only: rotate_angle
implicit none

View file

@ -14,7 +14,7 @@ module plot
use ppmlib, only: Image, init_image, allocate_image, &
deallocate_image, set_pixel
use progress_header, only: ProgressBar
use simple_string, only: to_str
use string, only: to_str
use hdf5

View file

@ -3,7 +3,7 @@ module sab_header
use, intrinsic :: ISO_FORTRAN_ENV
use constants
use simple_string, only: to_str
use string, only: to_str
implicit none

View file

@ -1,308 +0,0 @@
module simple_string
use constants, only: ERROR_REAL, ERROR_INT, MAX_LINE_LEN
implicit none
interface to_str
module procedure int4_to_str, int8_to_str, real_to_str
end interface
contains
!===============================================================================
! TO_LOWER converts a string to all lower case characters
!===============================================================================
pure function to_lower(word) result(word_lower)
character(*), intent(in) :: word
character(len=len(word)) :: word_lower
integer :: i
integer :: ic
do i = 1, len(word)
ic = ichar(word(i:i))
if (ic >= 65 .and. ic <= 90) then
word_lower(i:i) = char(ic+32)
else
word_lower(i:i) = word(i:i)
end if
end do
end function to_lower
!===============================================================================
! TO_UPPER converts a string to all upper case characters
!===============================================================================
pure function to_upper(word) result(word_upper)
character(*), intent(in) :: word
character(len=len(word)) :: word_upper
integer :: i
integer :: ic
do i = 1, len(word)
ic = ichar(word(i:i))
if (ic >= 97 .and. ic <= 122) then
word_upper(i:i) = char(ic-32)
else
word_upper(i:i) = word(i:i)
end if
end do
end function to_upper
!===============================================================================
! IS_NUMBER determines whether a string of characters is all 0-9 characters
!===============================================================================
pure function is_number(word) result(number)
character(*), intent(in) :: word
logical :: number
integer :: i
integer :: ic
number = .true.
do i = 1, len_trim(word)
ic = ichar(word(i:i))
if (ic < 48 .or. ic >= 58) number = .false.
end do
end function is_number
!===============================================================================
! STARTS_WITH determines whether a string starts with a certain
! sequence of characters
!===============================================================================
pure logical function starts_with(str, seq)
character(*), intent(in) :: str ! string to check
character(*), intent(in) :: seq ! sequence of characters
integer :: i
integer :: i_start
integer :: str_len
integer :: seq_len
str_len = len_trim(str)
seq_len = len_trim(seq)
! determine how many spaces are at beginning of string
i_start = 0
do i = 1, str_len
if (str(i:i) == ' ' .or. str(i:i) == achar(9)) cycle
i_start = i
exit
end do
! Check if string starts with sequence using INDEX intrinsic
if (index(str(1:str_len), seq(1:seq_len)) == i_start) then
starts_with = .true.
else
starts_with = .false.
end if
end function starts_with
!===============================================================================
! ENDS_WITH determines whether a string ends with a certain sequence
! of characters
!===============================================================================
pure logical function ends_with(str, seq)
character(*), intent(in) :: str ! string to check
character(*), intent(in) :: seq ! sequence of characters
integer :: i_start
integer :: str_len
integer :: seq_len
str_len = len_trim(str)
seq_len = len_trim(seq)
! determine how many spaces are at beginning of string
i_start = str_len - seq_len + 1
! Check if string starts with sequence using INDEX intrinsic
if (index(str(1:str_len), seq(1:seq_len), .true.) == i_start) then
ends_with = .true.
else
ends_with = .false.
end if
end function ends_with
!===============================================================================
! COUNT_DIGITS returns the number of digits needed to represent the input
! integer.
!===============================================================================
pure 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.
!===============================================================================
pure function int4_to_str(num) result(str)
integer, intent(in) :: num
character(11) :: str
write (str, '(I11)') num
str = adjustl(str)
end function int4_to_str
!===============================================================================
! INT8_TO_STR converts an integer(8) to a string.
!===============================================================================
pure function int8_to_str(num) result(str)
integer(8), intent(in) :: num
character(21) :: str
write (str, '(I21)') num
str = adjustl(str)
end function int8_to_str
!===============================================================================
! REAL_TO_STR converts a real(8) to a string based on how large the value is and
! how many significant digits are desired. By default, six significants digits
! are used.
!===============================================================================
pure function real_to_str(num, sig_digits) result(string)
real(8), intent(in) :: num ! number to convert
integer, optional, intent(in) :: sig_digits ! # of significant digits
character(15) :: string ! string returned
integer :: decimal ! number of places after decimal
integer :: width ! total field width
real(8) :: num2 ! absolute value of number
character(9) :: fmt ! format specifier for writing number
! set default field width
width = 15
! set number of places after decimal
if (present(sig_digits)) then
decimal = sig_digits
else
decimal = 6
end if
! Create format specifier for writing character
num2 = abs(num)
if (num2 == 0.0_8) then
write(fmt, '("(F",I2,".",I2,")")') width, 1
elseif (num2 < 1.0e-1_8) then
write(fmt, '("(ES",I2,".",I2,")")') width, decimal - 1
elseif (num2 >= 1.0e-1_8 .and. num2 < 1.0_8) then
write(fmt, '("(F",I2,".",I2,")")') width, decimal
elseif (num2 >= 1.0_8 .and. num2 < 10.0_8) then
write(fmt, '("(F",I2,".",I2,")")') width, max(decimal-1, 0)
elseif (num2 >= 10.0_8 .and. num2 < 100.0_8) then
write(fmt, '("(F",I2,".",I2,")")') width, max(decimal-2, 0)
elseif (num2 >= 100.0_8 .and. num2 < 1000.0_8) then
write(fmt, '("(F",I2,".",I2,")")') width, max(decimal-3, 0)
elseif (num2 >= 100.0_8 .and. num2 < 10000.0_8) then
write(fmt, '("(F",I2,".",I2,")")') width, max(decimal-4, 0)
elseif (num2 >= 10000.0_8 .and. num2 < 100000.0_8) then
write(fmt, '("(F",I2,".",I2,")")') width, max(decimal-5, 0)
else
write(fmt, '("(ES",I2,".",I2,")")') width, decimal - 1
end if
! Write string and left adjust
write(string, fmt) num
string = adjustl(string)
end function real_to_str
!===============================================================================
! STR_TO_INT converts a string to an integer.
!===============================================================================
pure function str_to_int(str) result(num)
character(*), intent(in) :: str
integer(8) :: num
character(5) :: fmt
integer :: w
integer :: ioError
! Determine width of string
w = len_trim(str)
! Create format specifier for reading string
write(UNIT=fmt, FMT='("(I",I2,")")') w
! read string into integer
read(UNIT=str, FMT=fmt, IOSTAT=ioError) num
if (ioError > 0) num = ERROR_INT
end function str_to_int
!===============================================================================
! STR_TO_REAL converts an arbitrary string to a real(8)
!===============================================================================
pure function str_to_real(string) result(num)
character(*), intent(in) :: string
real(8) :: num
integer :: ioError
! Read string
read(UNIT=string, FMT=*, IOSTAT=ioError) num
if (ioError > 0) num = ERROR_REAL
end function str_to_real
!===============================================================================
! CONCATENATE takes an array of words and concatenates them together in one
! string with a single space between words
!
! Arguments:
! words = array of words
! n_words = total number of words
! string = concatenated string
!===============================================================================
pure function concatenate(words, n_words) result(string)
integer, intent(in) :: n_words
character(*), intent(in) :: words(n_words)
character(MAX_LINE_LEN) :: string
integer :: i ! index
string = words(1)
if (n_words == 1) return
do i = 2, n_words
string = trim(string) // ' ' // words(i)
end do
end function concatenate
end module simple_string

View file

@ -19,7 +19,7 @@ module simulation
use random_lcg, only: set_particle_seed
use source, only: initialize_source
use state_point, only: write_state_point, write_source_point
use simple_string, only: to_str
use string, only: to_str
use tally, only: synchronize_tallies, setup_active_usertallies, &
reset_result
use trigger, only: check_triggers

View file

@ -13,7 +13,7 @@ module source
use particle_header, only: Particle
use random_lcg, only: prn, set_particle_seed, prn_set_stream
use search, only: binary_search
use simple_string, only: to_str
use string, only: to_str
use spectra
use state_point, only: read_source_bank, write_source_bank

View file

@ -18,8 +18,7 @@ module state_point
use global
use hdf5_interface
use output, only: write_message, time_stamp
use simple_string, only: to_str, count_digits
use string, only: zero_padded
use string, only: to_str, count_digits, zero_padded
use tally_header, only: TallyObject
use mesh_header, only: RegularMesh
use dict_header, only: ElemKeyValueII, ElemKeyValueCI

View file

@ -1,13 +1,16 @@
module string
use constants, only: MAX_WORDS, MAX_LINE_LEN, ERROR_INT, ERROR_REAL, &
use constants, only: MAX_WORDS, MAX_LINE_LEN, ERROR_INT, ERROR_REAL, &
OP_LEFT_PAREN, OP_RIGHT_PAREN, OP_COMPLEMENT, OP_INTERSECTION, OP_UNION
use error, only: fatal_error, warning
use simple_string, only: str_to_int, str_to_real
use stl_vector, only: VectorInt
use error, only: fatal_error, warning
use stl_vector, only: VectorInt
implicit none
interface to_str
module procedure int4_to_str, int8_to_str, real_to_str
end interface
contains
!===============================================================================
@ -151,6 +154,75 @@ contains
end if
end subroutine tokenize
!===============================================================================
! CONCATENATE takes an array of words and concatenates them together in one
! string with a single space between words
!
! Arguments:
! words = array of words
! n_words = total number of words
! string = concatenated string
!===============================================================================
pure function concatenate(words, n_words) result(string)
integer, intent(in) :: n_words
character(*), intent(in) :: words(n_words)
character(MAX_LINE_LEN) :: string
integer :: i ! index
string = words(1)
if (n_words == 1) return
do i = 2, n_words
string = trim(string) // ' ' // words(i)
end do
end function concatenate
!===============================================================================
! TO_LOWER converts a string to all lower case characters
!===============================================================================
pure function to_lower(word) result(word_lower)
character(*), intent(in) :: word
character(len=len(word)) :: word_lower
integer :: i
integer :: ic
do i = 1, len(word)
ic = ichar(word(i:i))
if (ic >= 65 .and. ic <= 90) then
word_lower(i:i) = char(ic+32)
else
word_lower(i:i) = word(i:i)
end if
end do
end function to_lower
!===============================================================================
! TO_UPPER converts a string to all upper case characters
!===============================================================================
pure function to_upper(word) result(word_upper)
character(*), intent(in) :: word
character(len=len(word)) :: word_upper
integer :: i
integer :: ic
do i = 1, len(word)
ic = ichar(word(i:i))
if (ic >= 97 .and. ic <= 122) then
word_upper(i:i) = char(ic-32)
else
word_upper(i:i) = word(i:i)
end if
end do
end function to_upper
!===============================================================================
! ZERO_PADDED returns a string of the input integer padded with zeros to the
@ -185,4 +257,229 @@ contains
write(str, zp_form) num
end function zero_padded
!===============================================================================
! IS_NUMBER determines whether a string of characters is all 0-9 characters
!===============================================================================
pure function is_number(word) result(number)
character(*), intent(in) :: word
logical :: number
integer :: i
integer :: ic
number = .true.
do i = 1, len_trim(word)
ic = ichar(word(i:i))
if (ic < 48 .or. ic >= 58) number = .false.
end do
end function is_number
!===============================================================================
! STARTS_WITH determines whether a string starts with a certain
! sequence of characters
!===============================================================================
pure logical function starts_with(str, seq)
character(*), intent(in) :: str ! string to check
character(*), intent(in) :: seq ! sequence of characters
integer :: i
integer :: i_start
integer :: str_len
integer :: seq_len
str_len = len_trim(str)
seq_len = len_trim(seq)
! determine how many spaces are at beginning of string
i_start = 0
do i = 1, str_len
if (str(i:i) == ' ' .or. str(i:i) == achar(9)) cycle
i_start = i
exit
end do
! Check if string starts with sequence using INDEX intrinsic
if (index(str(1:str_len), seq(1:seq_len)) == i_start) then
starts_with = .true.
else
starts_with = .false.
end if
end function starts_with
!===============================================================================
! ENDS_WITH determines whether a string ends with a certain sequence
! of characters
!===============================================================================
pure logical function ends_with(str, seq)
character(*), intent(in) :: str ! string to check
character(*), intent(in) :: seq ! sequence of characters
integer :: i_start
integer :: str_len
integer :: seq_len
str_len = len_trim(str)
seq_len = len_trim(seq)
! determine how many spaces are at beginning of string
i_start = str_len - seq_len + 1
! Check if string starts with sequence using INDEX intrinsic
if (index(str(1:str_len), seq(1:seq_len), .true.) == i_start) then
ends_with = .true.
else
ends_with = .false.
end if
end function ends_with
!===============================================================================
! COUNT_DIGITS returns the number of digits needed to represent the input
! integer.
!===============================================================================
pure 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.
!===============================================================================
pure function int4_to_str(num) result(str)
integer, intent(in) :: num
character(11) :: str
write (str, '(I11)') num
str = adjustl(str)
end function int4_to_str
!===============================================================================
! INT8_TO_STR converts an integer(8) to a string.
!===============================================================================
pure function int8_to_str(num) result(str)
integer(8), intent(in) :: num
character(21) :: str
write (str, '(I21)') num
str = adjustl(str)
end function int8_to_str
!===============================================================================
! STR_TO_INT converts a string to an integer.
!===============================================================================
pure function str_to_int(str) result(num)
character(*), intent(in) :: str
integer(8) :: num
character(5) :: fmt
integer :: w
integer :: ioError
! Determine width of string
w = len_trim(str)
! Create format specifier for reading string
write(UNIT=fmt, FMT='("(I",I2,")")') w
! read string into integer
read(UNIT=str, FMT=fmt, IOSTAT=ioError) num
if (ioError > 0) num = ERROR_INT
end function str_to_int
!===============================================================================
! STR_TO_REAL converts an arbitrary string to a real(8)
!===============================================================================
pure function str_to_real(string) result(num)
character(*), intent(in) :: string
real(8) :: num
integer :: ioError
! Read string
read(UNIT=string, FMT=*, IOSTAT=ioError) num
if (ioError > 0) num = ERROR_REAL
end function str_to_real
!===============================================================================
! REAL_TO_STR converts a real(8) to a string based on how large the value is and
! how many significant digits are desired. By default, six significants digits
! are used.
!===============================================================================
pure function real_to_str(num, sig_digits) result(string)
real(8), intent(in) :: num ! number to convert
integer, optional, intent(in) :: sig_digits ! # of significant digits
character(15) :: string ! string returned
integer :: decimal ! number of places after decimal
integer :: width ! total field width
real(8) :: num2 ! absolute value of number
character(9) :: fmt ! format specifier for writing number
! set default field width
width = 15
! set number of places after decimal
if (present(sig_digits)) then
decimal = sig_digits
else
decimal = 6
end if
! Create format specifier for writing character
num2 = abs(num)
if (num2 == 0.0_8) then
write(fmt, '("(F",I2,".",I2,")")') width, 1
elseif (num2 < 1.0e-1_8) then
write(fmt, '("(ES",I2,".",I2,")")') width, decimal - 1
elseif (num2 >= 1.0e-1_8 .and. num2 < 1.0_8) then
write(fmt, '("(F",I2,".",I2,")")') width, decimal
elseif (num2 >= 1.0_8 .and. num2 < 10.0_8) then
write(fmt, '("(F",I2,".",I2,")")') width, max(decimal-1, 0)
elseif (num2 >= 10.0_8 .and. num2 < 100.0_8) then
write(fmt, '("(F",I2,".",I2,")")') width, max(decimal-2, 0)
elseif (num2 >= 100.0_8 .and. num2 < 1000.0_8) then
write(fmt, '("(F",I2,".",I2,")")') width, max(decimal-3, 0)
elseif (num2 >= 100.0_8 .and. num2 < 10000.0_8) then
write(fmt, '("(F",I2,".",I2,")")') width, max(decimal-4, 0)
elseif (num2 >= 10000.0_8 .and. num2 < 100000.0_8) then
write(fmt, '("(F",I2,".",I2,")")') width, max(decimal-5, 0)
else
write(fmt, '("(ES",I2,".",I2,")")') width, decimal - 1
end if
! Write string and left adjust
write(string, fmt) num
string = adjustl(string)
end function real_to_str
end module string

View file

@ -12,7 +12,7 @@ module summary
use nuclide_header
use output, only: time_stamp
use surface_header
use simple_string, only: to_str
use string, only: to_str
use tally_header, only: TallyObject
use hdf5

View file

@ -13,7 +13,7 @@ module tally
use output, only: header
use particle_header, only: LocalCoord, Particle
use search, only: binary_search
use simple_string, only: to_str
use string, only: to_str
use tally_header, only: TallyResult, TallyMapItem, TallyMapElement
use fission, only: nu_total, nu_delayed, yield_delayed
use interpolation, only: interpolate_tab1

View file

@ -7,8 +7,8 @@ module track_output
use global
use hdf5_interface
use particle_header, only: Particle
use simple_string, only: to_str
use particle_header, only: Particle
use string, only: to_str
use hdf5

View file

@ -13,7 +13,7 @@ module tracking
use physics, only: collision
use physics_mg, only: collision_mg
use random_lcg, only: prn
use simple_string, only: to_str
use string, only: to_str
use tally, only: score_analog_tally, score_tracklength_tally, &
score_collision_tally, score_surface_current
use track_output, only: initialize_particle_track, write_particle_track, &

View file

@ -6,12 +6,12 @@ module trigger
use constants
use global
use simple_string, only: to_str
use output, only: warning, write_message
use mesh, only: mesh_indices_to_bin
use mesh_header, only: RegularMesh
use trigger_header, only: TriggerObject
use tally, only: TallyObject
use string, only: to_str
use output, only: warning, write_message
use mesh, only: mesh_indices_to_bin
use mesh_header, only: RegularMesh
use trigger_header, only: TriggerObject
use tally, only: TallyObject
implicit none