PartMC  2.6.1
Modules | Functions/Subroutines | Variables
util.F90 File Reference

The pmc_util module. More...

Go to the source code of this file.

Modules

module  pmc_util
 Common utility subroutines.
 

Functions/Subroutines

subroutine pmc_util::warn_msg (code, warning_msg, already_warned)
 Prints a warning message. More...
 
subroutine pmc_util::warn_assert_msg (code, condition_ok, warning_msg)
 Prints a warning message if condition_ok is false. More...
 
subroutine pmc_util::assert_msg (code, condition_ok, error_msg)
 Errors unless condition_ok is true. More...
 
subroutine pmc_util::assert (code, condition_ok)
 Errors unless condition_ok is true. More...
 
subroutine pmc_util::die (code)
 Error immediately. More...
 
subroutine pmc_util::die_msg (code, error_msg)
 Error immediately. More...
 
integer function pmc_util::get_unit ()
 Returns an available unit number. This should be freed by free_unit(). More...
 
subroutine pmc_util::free_unit (unit)
 Frees a unit number returned by get_unit(). More...
 
subroutine pmc_util::open_file_read (filename, unit)
 Open a file for reading with an automatically assigned unit and test that it succeeds. The file should be closed with close_file(). More...
 
subroutine pmc_util::open_file_write (filename, unit)
 Open a file for writing with an automatically assigned unit and test that it succeeds. The file should be closed with close_file(). More...
 
subroutine pmc_util::close_file (unit)
 Close a file and de-assign the unit. More...
 
real(kind=dp) elemental function pmc_util::sphere_vol2rad (v)
 Convert mass-equivalent volume $V$ (m^3) to geometric radius $R_{\rm geo}$ (m) for spherical particles. More...
 
real(kind=dp) elemental function pmc_util::rad2diam (r)
 Convert radius (m) to diameter (m). More...
 
real(kind=dp) elemental function pmc_util::sphere_rad2vol (r)
 Convert geometric radius $R_{\rm geo}$ (m) to mass-equivalent volume $V$ (m^3) for spherical particles. More...
 
real(kind=dp) elemental function pmc_util::diam2rad (d)
 Convert diameter (m) to radius (m). More...
 
real(kind=dp) function pmc_util::air_mean_free_path (temp, pressure)
 Calculate air molecular mean free path $l$ (m). More...
 
logical function pmc_util::almost_equal (d1, d2)
 Tests whether two real numbers are almost equal using only a relative tolerance. More...
 
logical function pmc_util::almost_equal_abs (d1, d2, abs_tol)
 Tests whether two real numbers are almost equal using an absolute and relative tolerance. More...
 
subroutine pmc_util::check_time_multiple (first_name, first_time, second_name, second_time)
 Check that the first time interval is close to an integer multiple of the second, and warn if it is not. More...
 
subroutine pmc_util::check_event (time, timestep, interval, last_time, do_event)
 Computes whether an event is scheduled to take place. More...
 
real(kind=dp) function, dimension(:), allocatable pmc_util::linspace (min_x, max_x, n)
 Makes a linearly spaced array from min to max. More...
 
real(kind=dp) function, dimension(:), allocatable pmc_util::logspace (min_x, max_x, n)
 Makes a logarithmically spaced array of length n from min to max. More...
 
integer function pmc_util::linspace_find (min_x, max_x, n, x)
 Find the position of a real number in a 1D linear array. More...
 
integer function pmc_util::logspace_find (min_x, max_x, n, x)
 Find the position of a real number in a 1D logarithmic array. More...
 
integer function pmc_util::find_1d (n, x_vals, x)
 Find the position of a real number in an arbitrary 1D array. More...
 
real(kind=dp) function pmc_util::interp_1d (x_vals, y_vals, x)
 1D linear interpolation. More...
 
real(kind=dp) function pmc_util::interp_linear_disc (x_1, x_n, n, i)
 Linear interpolation over discrete indices. More...
 
integer function pmc_util::string_to_integer (string)
 Convert a string to an integer. More...
 
real(kind=dp) function pmc_util::string_to_real (string)
 Convert a string to a real. More...
 
logical function pmc_util::string_to_logical (string)
 Convert a string to a logical. More...
 
character(len=pmc_util_convert_string_len) function pmc_util::integer_to_string (val)
 Convert an integer to a string format. More...
 
character(len=pmc_util_convert_string_len) function pmc_util::real_to_string (val)
 Convert a real to a string format. More...
 
character(len=pmc_util_convert_string_len) function pmc_util::logical_to_string (val)
 Convert a logical to a string format. More...
 
character(len=pmc_util_convert_string_len) function pmc_util::complex_to_string (val)
 Convert a complex to a string format. More...
 
character(len=pmc_util_convert_string_len) function pmc_util::integer_to_string_max_len (val, max_len)
 Convert an integer to a string format of maximum length. More...
 
character(len=pmc_util_convert_string_len) function pmc_util::real_to_string_max_len (val, max_len)
 Convert a real to a string format of maximum length. More...
 
character(len=pmc_util_convert_string_len) function pmc_util::time_to_string_max_len (time, max_len)
 Convert a time to a string format of maximum length. More...
 
subroutine pmc_util::vec_cts_to_disc (n, vec_cts, n_samp, vec_disc)
 Convert a real-valued vector into an integer-valued vector. More...
 
subroutine pmc_util::average_integer (int_vec, int_avg)
 Computes the average of an array of integer numbers. More...
 
subroutine pmc_util::average_real (real_vec, real_avg)
 Computes the average of an array of real numbers. More...
 
integer function pmc_util::string_array_find (array, val)
 Return the index of the first occurance of the given value in the array, or 0 if it is not present. More...
 
subroutine pmc_util::ensure_real_array_size (x, n, only_grow)
 Allocate or reallocate the given array to ensure it is of the given size, preserving any data and/or initializing to 0. More...
 
subroutine pmc_util::ensure_real_array_2d_size (x, n1, n2, only_grow)
 Allocate or reallocate the given array to ensure it is of the given size, preserving any data and/or initializing to 0. More...
 
subroutine pmc_util::ensure_integer_array_size (x, n, only_grow)
 Allocate or reallocate the given array to ensure it is of the given size, preserving any data and/or initializing to 0. More...
 
subroutine pmc_util::ensure_integer_array_2d_size (x, n1, n2, only_grow)
 Allocate or reallocate the given array to ensure it is of the given size, preserving any data and/or initializing to 0. More...
 
subroutine pmc_util::ensure_string_array_size (x, n)
 Allocate or reallocate the given array to ensure it is of the given size, without preserving data. More...
 
subroutine pmc_util::get_basename (filename, basename)
 Strip the extension to find the basename. More...
 
subroutine pmc_util::iso8601_date_and_time (date_time)
 Current date and time in ISO 8601 format. More...
 
real(kind=dp) function pmc_util::deg2rad (deg)
 Convert degrees to radians. More...
 
real(kind=dp) function pmc_util::rad2deg (rad)
 Convert radians to degrees. More...
 
subroutine pmc_util::integer_sort (data, perm)
 Sort the given data array and return the permutation defining the sort. More...
 
subroutine pmc_util::loadtxt (filename, data)
 Load a real array from a text file. More...
 
subroutine pmc_util::savetxt_1d (filename, data)
 Write a real 1D array to a text file. More...
 
subroutine pmc_util::savetxt_2d (filename, data)
 Write a real 2D array to a text file. More...
 
subroutine pmc_util::reallocate_real_array2d (data, rows, cols)
 Reallocate a 2D real array to the given size, preserving the contents. More...
 
subroutine pmc_util::read_char_raw (unit, char, eol, eof)
 Read a single character from a file, signaling if we have hit end-of-line (EOL) or end-of-file (EOF). If EOL or EOF are true then the character value should be ignored. More...
 
subroutine pmc_util::read_word_raw (unit, word, eol, eof)
 Read a white-space delimited word from a file, signaling if we have EOL or EOF. If EOL or EOF are true then the word will still be meaningful data. If there was no data to be read then len(word) will be 0. More...
 
logical function pmc_util::starts_with (string, start_string)
 Checks whether a string starts with a given other string. More...
 
elemental real(kind=dp) function pmc_util::harmonic_mean (x1, x2)
 Compute the harmonic mean of two numbers. More...
 
elemental real(kind=dp) function pmc_util::nplogp (p)
 Compute $ - p \ln p$ for computing entropy. More...
 
real(kind=dp) function pmc_util::entropy (p)
 Compute the entropy of a probability mass function (non necessarily normalized). More...
 
integer function pmc_util::pow2_above (n)
 Return the least power-of-2 that is at least equal to n. More...
 

Variables

integer, parameter pmc_util::max_units = 200
 Maximum number of IO units usable simultaneously. More...
 
integer, parameter pmc_util::unit_offset = 10
 Minimum unit number to allocate. More...
 
logical, dimension(max_units), save pmc_util::unit_used = .false.
 Table of unit numbers storing allocation status. More...
 
integer, parameter pmc_util::pmc_util_convert_string_len = 100
 Length of string for converting numbers. More...
 
integer, parameter pmc_util::pmc_max_filename_len = 300
 Maximum length of filenames. More...
 

Detailed Description

The pmc_util module.

Definition in file util.F90.