CAMP 1.0.0
Chemistry Across Multiple Phases
Data Types | Modules | Functions/Subroutines | Variables
util.F90 File Reference

The camp_util module. More...

Go to the source code of this file.

Data Types

interface  camp_util::to_string
 Interface for to_string functions. More...
 
interface  camp_util::string_t
 String type for building arrays of string of various size. More...
 

Modules

module  camp_util
 Common utility subroutines.
 

Functions/Subroutines

type(string_t) function, pointer camp_util::string_t_constructor (val)
 Constructor for string_t.
 
elemental subroutine camp_util::string_t_finalize (this)
 Finalize a string.
 
subroutine camp_util::warn_msg (code, warning_msg, already_warned)
 Prints a warning message.
 
subroutine camp_util::warn_assert_msg (code, condition_ok, warning_msg)
 Prints a warning message if condition_ok is false.
 
subroutine camp_util::assert_msg (code, condition_ok, error_msg)
 Errors unless condition_ok is true.
 
subroutine camp_util::assert (code, condition_ok)
 Errors unless condition_ok is true.
 
subroutine camp_util::die (code)
 Error immediately.
 
subroutine camp_util::die_msg (code, error_msg)
 Error immediately.
 
integer function camp_util::get_unit ()
 Returns an available unit number. This should be freed by free_unit().
 
subroutine camp_util::free_unit (unit)
 Frees a unit number returned by get_unit().
 
subroutine camp_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().
 
subroutine camp_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().
 
subroutine camp_util::close_file (unit)
 Close a file and de-assign the unit.
 
real(kind=dp) elemental function camp_util::sphere_vol2rad (v)
 Convert mass-equivalent volume \(V\) (m^3) to geometric radius \(R_{\rm geo}\) (m) for spherical particles.
 
real(kind=dp) elemental function camp_util::rad2diam (r)
 Convert radius (m) to diameter (m).
 
real(kind=dp) elemental function camp_util::sphere_rad2vol (r)
 Convert geometric radius \(R_{\rm geo}\) (m) to mass-equivalent volume \(V\) (m^3) for spherical particles.
 
real(kind=dp) elemental function camp_util::diam2rad (d)
 Convert diameter (m) to radius (m).
 
real(kind=dp) function camp_util::air_mean_free_path (temp, pressure)
 Calculate air molecular mean free path \(l\) (m).
 
logical function camp_util::almost_equal (d1, d2, rel_tol, abs_tol)
 Tests whether two real numbers are almost equal using only a relative tolerance.
 
logical function camp_util::almost_equal_abs (d1, d2, abs_tol)
 Tests whether two real numbers are almost equal using an absolute and relative tolerance.
 
subroutine camp_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.
 
subroutine camp_util::check_event (time, timestep, interval, last_time, do_event)
 Computes whether an event is scheduled to take place.
 
real(kind=dp) function, dimension(:), allocatable camp_util::linspace (min_x, max_x, n)
 Makes a linearly spaced array from min to max.
 
real(kind=dp) function, dimension(:), allocatable camp_util::logspace (min_x, max_x, n)
 Makes a logarithmically spaced array of length n from min to max.
 
integer function camp_util::linspace_find (min_x, max_x, n, x)
 Find the position of a real number in a 1D linear array.
 
integer function camp_util::logspace_find (min_x, max_x, n, x)
 Find the position of a real number in a 1D logarithmic array.
 
integer function camp_util::find_1d (n, x_vals, x)
 Find the position of a real number in an arbitrary 1D array.
 
real(kind=dp) function camp_util::interp_1d (x_vals, y_vals, x)
 1D linear interpolation.
 
real(kind=dp) function camp_util::interp_linear_disc (x_1, x_n, n, i)
 Linear interpolation over discrete indices.
 
integer function camp_util::string_to_integer (string)
 Convert a string to an integer.
 
real(kind=dp) function camp_util::string_to_real (string)
 Convert a string to a real.
 
logical function camp_util::string_to_logical (string)
 Convert a string to a logical.
 
character(len=camp_util_convert_string_len) function camp_util::integer_to_string (val)
 Convert an integer to a string format.
 
character(len=camp_util_convert_string_len) function camp_util::real_dp_to_string (val)
 Convert a double precision real to a string format.
 
character(len=camp_util_convert_string_len) function camp_util::real_sp_to_string (val)
 Convert a single precision real to a string format.
 
character(len=camp_util_convert_string_len) function camp_util::logical_to_string (val)
 Convert a logical to a string format.
 
character(len=camp_util_convert_string_len) function camp_util::complex_to_string (val)
 Convert a complex to a string format.
 
character(len=camp_util_convert_string_len) function camp_util::integer_to_string_max_len (val, max_len)
 Convert an integer to a string format of maximum length.
 
character(len=camp_util_convert_string_len) function camp_util::real_to_string_max_len (val, max_len)
 Convert a real to a string format of maximum length.
 
character(len=camp_util_convert_string_len) function camp_util::time_to_string_max_len (time, max_len)
 Convert a time to a string format of maximum length.
 
type(string_t) function, dimension(:), allocatable camp_util::split_char (this, splitter, compress)
 Splits a string on a substring.
 
type(string_t) function, dimension(:), allocatable camp_util::split_string (this, splitter, compress)
 Splits a string on a substring.
 
subroutine camp_util::vec_cts_to_disc (n, vec_cts, n_samp, vec_disc)
 Convert a real-valued vector into an integer-valued vector.
 
subroutine camp_util::average_integer (int_vec, int_avg)
 Computes the average of an array of integer numbers.
 
subroutine camp_util::average_real (real_vec, real_avg)
 Computes the average of an array of real numbers.
 
integer function camp_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.
 
subroutine camp_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.
 
subroutine camp_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.
 
subroutine camp_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.
 
subroutine camp_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.
 
subroutine camp_util::ensure_string_array_size (x, n)
 Allocate or reallocate the given array to ensure it is of the given size, without preserving data.
 
subroutine camp_util::get_basename (filename, basename)
 Strip the extension to find the basename.
 
subroutine camp_util::iso8601_date_and_time (date_time)
 Current date and time in ISO 8601 format.
 
real(kind=dp) function camp_util::deg2rad (deg)
 Convert degrees to radians.
 
real(kind=dp) function camp_util::rad2deg (rad)
 Convert radians to degrees.
 
subroutine camp_util::integer_sort (data, perm)
 Sort the given data array and return the permutation defining the sort.
 
subroutine camp_util::loadtxt (filename, data)
 Load a real array from a text file.
 
subroutine camp_util::savetxt_1d (filename, data)
 Write a real 1D array to a text file.
 
subroutine camp_util::savetxt_2d (filename, data)
 Write a real 2D array to a text file.
 
subroutine camp_util::reallocate_real_array2d (data, rows, cols)
 Reallocate a 2D real array to the given size, preserving the contents.
 
subroutine camp_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.
 
subroutine camp_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.
 
logical function camp_util::starts_with (string, start_string)
 Checks whether a string starts with a given other string.
 
elemental real(kind=dp) function camp_util::harmonic_mean (x1, x2)
 Compute the harmonic mean of two numbers.
 
elemental real(kind=dp) function camp_util::nplogp (p)
 Compute \( - p \ln p\) for computing entropy.
 
real(kind=dp) function camp_util::entropy (p)
 Compute the entropy of a probability mass function (non necessarily normalized).
 
integer function camp_util::pow2_above (n)
 Return the least power-of-2 that is at least equal to n.
 

Variables

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

Detailed Description

The camp_util module.

Definition in file util.F90.