diff --git a/src/ace.F90 b/src/ace.F90 index 57564f0b91..45b58a8d54 100644 --- a/src/ace.F90 +++ b/src/ace.F90 @@ -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 diff --git a/src/cmfd_data.F90 b/src/cmfd_data.F90 index b624e839d7..347351e318 100644 --- a/src/cmfd_data.F90 +++ b/src/cmfd_data.F90 @@ -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 diff --git a/src/cmfd_execute.F90 b/src/cmfd_execute.F90 index af6991e47d..b7d0cc3879 100644 --- a/src/cmfd_execute.F90 +++ b/src/cmfd_execute.F90 @@ -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 diff --git a/src/cmfd_input.F90 b/src/cmfd_input.F90 index 5e22d38559..2d9df4182c 100644 --- a/src/cmfd_input.F90 +++ b/src/cmfd_input.F90 @@ -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 diff --git a/src/distribution_univariate.F90 b/src/distribution_univariate.F90 index 274c6b1155..0ec2959c3b 100644 --- a/src/distribution_univariate.F90 +++ b/src/distribution_univariate.F90 @@ -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 diff --git a/src/eigenvalue.F90 b/src/eigenvalue.F90 index 7ed6c34f01..e735bc8d8a 100644 --- a/src/eigenvalue.F90 +++ b/src/eigenvalue.F90 @@ -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 diff --git a/src/endf.F90 b/src/endf.F90 index 0539e8b9d2..64f26539a9 100644 --- a/src/endf.F90 +++ b/src/endf.F90 @@ -1,7 +1,7 @@ module endf use constants - use simple_string, only: to_str + use string, only: to_str implicit none diff --git a/src/geometry.F90 b/src/geometry.F90 index 53e2f29fc2..8a38f982b5 100644 --- a/src/geometry.F90 +++ b/src/geometry.F90 @@ -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 diff --git a/src/initialize.F90 b/src/initialize.F90 index 00e5bab443..74bba03e72 100644 --- a/src/initialize.F90 +++ b/src/initialize.F90 @@ -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 diff --git a/src/input_xml.F90 b/src/input_xml.F90 index fde77f498e..e726b6f403 100644 --- a/src/input_xml.F90 +++ b/src/input_xml.F90 @@ -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 diff --git a/src/interpolation.F90 b/src/interpolation.F90 index 49d3de7fe8..5f87870677 100644 --- a/src/interpolation.F90 +++ b/src/interpolation.F90 @@ -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 diff --git a/src/mgxs_data.F90 b/src/mgxs_data.F90 index f48238afa9..880764edad 100644 --- a/src/mgxs_data.F90 +++ b/src/mgxs_data.F90 @@ -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 diff --git a/src/nuclide_header.F90 b/src/nuclide_header.F90 index 72e1a4dc66..398e91eb20 100644 --- a/src/nuclide_header.F90 +++ b/src/nuclide_header.F90 @@ -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 diff --git a/src/output.F90 b/src/output.F90 index 5379555ff0..29844076e6 100644 --- a/src/output.F90 +++ b/src/output.F90 @@ -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 diff --git a/src/particle_restart_write.F90 b/src/particle_restart_write.F90 index 324e96bc7a..e1a280e9fa 100644 --- a/src/particle_restart_write.F90 +++ b/src/particle_restart_write.F90 @@ -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 diff --git a/src/physics.F90 b/src/physics.F90 index 2212269209..cb216467cd 100644 --- a/src/physics.F90 +++ b/src/physics.F90 @@ -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 diff --git a/src/physics_mg.F90 b/src/physics_mg.F90 index a5272e1f47..a8a9084171 100644 --- a/src/physics_mg.F90 +++ b/src/physics_mg.F90 @@ -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 diff --git a/src/plot.F90 b/src/plot.F90 index cdddc6d706..796cce6afa 100644 --- a/src/plot.F90 +++ b/src/plot.F90 @@ -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 diff --git a/src/sab_header.F90 b/src/sab_header.F90 index a2d70d4f21..56617dd01d 100644 --- a/src/sab_header.F90 +++ b/src/sab_header.F90 @@ -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 diff --git a/src/simple_string.F90 b/src/simple_string.F90 deleted file mode 100644 index 65eb58ac0b..0000000000 --- a/src/simple_string.F90 +++ /dev/null @@ -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 \ No newline at end of file diff --git a/src/simulation.F90 b/src/simulation.F90 index d1b96d8b08..4a419df906 100644 --- a/src/simulation.F90 +++ b/src/simulation.F90 @@ -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 diff --git a/src/source.F90 b/src/source.F90 index 7f56b240b7..601232192a 100644 --- a/src/source.F90 +++ b/src/source.F90 @@ -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 diff --git a/src/state_point.F90 b/src/state_point.F90 index a46450fc5a..2249e3d45e 100644 --- a/src/state_point.F90 +++ b/src/state_point.F90 @@ -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 diff --git a/src/string.F90 b/src/string.F90 index e5f09a50d4..b51763a611 100644 --- a/src/string.F90 +++ b/src/string.F90 @@ -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 diff --git a/src/summary.F90 b/src/summary.F90 index 2f255a4fc5..e662aa473b 100644 --- a/src/summary.F90 +++ b/src/summary.F90 @@ -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 diff --git a/src/tally.F90 b/src/tally.F90 index 842b7644ea..bbe099c3e4 100644 --- a/src/tally.F90 +++ b/src/tally.F90 @@ -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 diff --git a/src/track_output.F90 b/src/track_output.F90 index 87dbfbfa44..1411738622 100644 --- a/src/track_output.F90 +++ b/src/track_output.F90 @@ -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 diff --git a/src/tracking.F90 b/src/tracking.F90 index 992cc2ca95..0b2719ef5d 100644 --- a/src/tracking.F90 +++ b/src/tracking.F90 @@ -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, & diff --git a/src/trigger.F90 b/src/trigger.F90 index 967d74b14e..ed362154b4 100644 --- a/src/trigger.F90 +++ b/src/trigger.F90 @@ -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