m_strings Module

String utilities

To use the routines in this module the user needs to add the statement use m_strings to the top of the program. These routines were developed primarily to aid in the reading and manipulation of input data from an ASCII text file. The routines are described below.


Uses

  • module~~m_strings~~UsesGraph module~m_strings m_strings module~m_precision m_precision module~m_strings->module~m_precision iso_fortran_env iso_fortran_env module~m_precision->iso_fortran_env

Used by

  • module~~m_strings~~UsedByGraph module~m_strings m_strings module~m_config_io m_config_io module~m_config_io->module~m_strings module~m_control_io m_control_io module~m_control_io->module~m_strings module~m_mc_solver m_mc_solver module~m_mc_solver->module~m_strings module~m_mc_solver->module~m_config_io module~m_stats_io m_stats_io module~m_mc_solver->module~m_stats_io module~m_stats_io->module~m_strings program~main main program~main->module~m_strings program~main->module~m_control_io program~main->module~m_mc_solver module~m_setup m_setup program~main->module~m_setup module~m_setup->module~m_config_io module~m_setup->module~m_mc_solver module~m_setup->module~m_stats_io

Interfaces

public interface str_from_num

Generic interface for writing a number to a string. The calling syntax is str_from_num(num, frmt) where number is a real number or an integer, format is the format desired, e.g., e15.6, i5, etc.

  • private pure function str_from_inum(num, frmt) result(str)

    Arguments

    Type IntentOptional Attributes Name
    integer, intent(in) :: num
    character(len=*), intent(in), optional :: frmt

    Return Value character(len=:), allocatable

  • private pure function str_from_ilnum(num, frmt) result(str)

    Arguments

    Type IntentOptional Attributes Name
    integer(kind=ip_long), intent(in) :: num
    character(len=*), intent(in), optional :: frmt

    Return Value character(len=:), allocatable

  • private pure function str_from_dnum(num, frmt) result(str)

    Arguments

    Type IntentOptional Attributes Name
    real(kind=rp), intent(in) :: num
    character(len=*), intent(in), optional :: frmt

    Return Value character(len=:), allocatable


Functions

public pure function str_is_letter(str) result(res)

Returns .true. if str contains only letters (a--z or A--Z) and .false. otherwise.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: str

Return Value logical

public pure function str_is_digit(str) result(res)

Returns .true. if str contains only digits (0,1,...,9) and .false. otherwise.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: str

Return Value logical

public pure function str_is_empty(str) result(res)

Returns .true. if str is empty and .false. otherwise.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: str

Return Value logical

public pure function str_is_space(str) result(res)

Returns .true. if str is non-empty and contains only whitespace characters (tab or blankspace). Otherwise .false. is returned.

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: str

Return Value logical

public pure function str_is_comment(line, comment_str) result(res)

Returns .true. if line is a comment, .false. other wise.

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: line

Input string

character(len=*), intent(in) :: comment_str

String indicating beginning of a comment.

Return Value logical

public pure function str_compact(str) result(ostr)

Returns a copy of str with multiple spaces and tabs converted to single spaces, control characters deleted, and leading and trailing spaces removed.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: str

Return Value character(len=:), allocatable

public pure function str_remove_stcc(str) result(ostr)

Returns a copy of the string str with spaces, tabs, and control characters removed.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: str

Return Value character(len=:), allocatable

public pure function str_to_upper(str) result(ucstr)

This function returns a string that is like the string str with all characters that are not between a pair of quotes ("..." or '...') converted to uppercase.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: str

Return Value character(len=len)

public pure function str_to_lower(str) result(lcstr)

This function returns a string that is like the string str with all characters that are not between a pair of quotes ("..." or '...') converted to lowercase.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: str

Return Value character(len=len)

public pure function str_trimzero(str) result(res)

Deletes nonsignificant trailing zeroes from number string str. If number string ends in a decimal point, one trailing zero is added.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: str

Return Value character(len=:), allocatable

public pure function str_to_d(str) result(res)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: str

Return Value real(kind=rp)

public pure function str_to_i(str) result(res)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: str

Return Value integer

public pure function str_strip(str, chars, ends) result(ostr)

Returns a copy of string str with the leading and trailing characters removed. The chars argument is a string specifying the set of characters to be removed. The chars argument is not a prefix or suffix; rather, all combinations of its values are stripped. If ends = 'l', only leading characters are removed, if ends = 'r', only trailing characters are removed, and if ends = 'b' both leading and trailing characters are removed.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: str
character(len=*), intent(in) :: chars
character(len=1), intent(in) :: ends

{'l', 'r', 'b'}

Return Value character(len=:), allocatable

public pure function str_startswith(str, prefix, start, finish) result(res)

Returns .true. if the string str starts with prefix, otherwise returns .false.. With optional start, test beginning at that position. With optional finish, stop comparing beyond that position.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: str
character(len=*), intent(in) :: prefix
integer, intent(in), optional :: start
integer, intent(in), optional :: finish

Return Value logical

public pure function str_endswith(str, suffix, start, finish) result(res)

Returns .true. if the string str ends with suffix, otherwise return .false.. With optional start, test beginning at that position. With optional finish, stop comparing beyond that position.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: str
character(len=*), intent(in) :: suffix
integer, intent(in), optional :: start
integer, intent(in), optional :: finish

Return Value logical


Subroutines

public subroutine str_shift(str, n)

Shifts characters in str by n positions (positive values denote a right shift and negative values denote a left shift). Characters that are shifted off the end are lost. Positions opened up by the shift are replaced by spaces.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(inout) :: str
integer, intent(in) :: n

public subroutine str_insert(str, substr, loc)

Inserts the string substr into the string str at position loc. Characters in str starting at position loc are shifted right to make room for the inserted string. Trailing spaces of substr are removed prior to insertion.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(inout) :: str
character(len=*), intent(in) :: substr
integer, intent(in) :: loc

public subroutine str_del(str, substr, n)

Deletes first n occurrences of substring substr from string str and shifts characters left to fill hole. If n < 0, all occurances are deleted. If n is not explicitly provided, it defaults to removing the first occurance. Trailing spaces or blanks are not considered part of substr.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(inout) :: str
character(len=*), intent(in) :: substr
integer, intent(in), optional :: n

public subroutine str_strip_comment(str, comment_str)

Strips trailing comment from a string.

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(inout) :: str

Input string

character(len=*), intent(in) :: comment_str

String indicating beginning of a comment.

public subroutine str_get_keyval(str, key, val, delimiter)

Split a string str into two strings, key and val based on space delimiter.

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: str
character(len=:), intent(out), allocatable :: key
character(len=:), intent(out), allocatable :: val
character(len=*), intent(in), optional :: delimiter

public subroutine str_match(str, ipos, imatch)

This routine finds the delimiter in string str that matches the delimiter in position ipos of str. The argument imatch contains the position of the matching delimiter. Allowable delimiters are (), [], {}, <>.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: str
integer, intent(in) :: ipos
integer, intent(out) :: imatch

public subroutine compact_real_string(str)

Author
Izaak Beekman
Date
02/24/2015
License
MIT

Compact a string representing a real number, so that the same value is displayed with fewer characters.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(inout) :: str

string representation of a real number.

public subroutine str_split(str, delimiter, before)

Routine finds the first instance of a character from delims in the the string str. The characters before the found delimiter are output in before. The characters after the found delimiter are output in str. Repeated applications of this routine can be used to parse a string into its component parts. Multiple whitespaces of str are compacted into a single whitespace before splitting begins. If either str or delimiter is empty, an empty string is retured in before and str remains unchanged.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(inout) :: str
character(len=*), intent(in) :: delimiter
character(len=:), intent(out), allocatable :: before

public subroutine str_append(dest, source, sep)

Appends a copy of the source string to the dest string, with optional string sep in between. It is assumed that dest is long enough to hold the result, otherwise an error will be generated.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(inout) :: dest
character(len=*), intent(in) :: source
character(len=*), intent(in), optional :: sep

public subroutine readline(nunitr, line, comment_str, ios)

Reads a line from unit=nunitr, ignoring blank lines and deleting comments

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: nunitr
character(len=*), intent(inout) :: line
character(len=*), intent(in) :: comment_str
integer, intent(out) :: ios