strings_m Module

Many of these routines were originally written by George Benthien, some have been written by Sarit Dutta or gathered/modified from other authors (appropriately credited).

These routines were developed primarily to aid in the reading and manipulation of input data from an ASCII text file. Accordingly, it is assumed that all characters to be processed are ASCII characters.


Uses

  • module~~strings_m~~UsesGraph module~strings_m strings_m module~constants_m constants_m module~strings_m->module~constants_m iso_fortran_env iso_fortran_env module~constants_m->iso_fortran_env

Used by

  • module~~strings_m~~UsedByGraph module~strings_m strings_m module~ia_bond_m ia_bond_m module~ia_bond_m->module~strings_m program~main main program~main->module~strings_m module~setup_m setup_m program~main->module~setup_m module~control_m control_m program~main->module~control_m module~aabbtree_m aabbtree_m module~aabbtree_m->module~strings_m module~aabb_m aabb_m module~aabbtree_m->module~aabb_m module~setup_m->module~strings_m module~config_io_m config_io_m module~setup_m->module~config_io_m module~stats_m stats_m module~setup_m->module~stats_m module~setup_m->module~control_m module~bd_solver_m bd_solver_m module~setup_m->module~bd_solver_m module~interaction_m interaction_m module~setup_m->module~interaction_m module~brown_m brown_m module~brown_m->module~strings_m module~config_io_m->module~strings_m module~stats_m->module~strings_m module~stats_m->module~control_m module~control_m->module~strings_m module~aabb_m->module~strings_m module~aabbtree_sm aabbtree_sm module~aabbtree_sm->module~aabbtree_m module~bd_solver_m->module~brown_m module~bd_solver_m->module~config_io_m module~bd_solver_m->module~stats_m module~bd_solver_m->module~control_m module~bd_solver_m->module~interaction_m module~pairtab_m pairtab_m module~pairtab_m->module~aabbtree_m module~interaction_m->module~ia_bond_m module~interaction_m->module~stats_m module~interaction_m->module~control_m module~interaction_m->module~pairtab_m

Contents


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 AttributesName
    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 AttributesName
    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 AttributesName
    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 AttributesName
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 AttributesName
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 AttributesName
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 AttributesName
character(len=*), intent(in) :: line

Input string

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

String marking the 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 AttributesName
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 AttributesName
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 AttributesName
character(len=*), intent(in) :: str

Return Value character(len=len(str))

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 AttributesName
character(len=*), intent(in) :: str

Return Value character(len=len(str))

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

Arguments

Type IntentOptional AttributesName
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 AttributesName
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 AttributesName
real(kind=rp), intent(in) :: num
character(len=*), intent(in), optional :: frmt

Return Value character(len=:), allocatable

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 AttributesName
character(len=*), intent(in) :: str

Return Value character(len=:), allocatable

public pure function str_to_d(str) result(res)

Arguments

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

Return Value real(kind=rp)

public pure function str_to_i(str) result(res)

Arguments

Type IntentOptional AttributesName
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 AttributesName
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 AttributesName
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 AttributesName
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 AttributesName
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 AttributesName
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 occurrence. Trailing spaces or blanks are not considered part of substr.

Arguments

Type IntentOptional AttributesName
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 AttributesName
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 AttributesName
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 AttributesName
character(len=*), intent(in) :: str
integer, intent(in) :: ipos
integer, intent(out) :: imatch

public subroutine str_compact_rlstr(str)

Author
Izaak Beekman
Date
02/24/2015

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

Arguments

Type IntentOptional AttributesName
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 AttributesName
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 AttributesName
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 AttributesName
integer, intent(in) :: nunitr
character(len=*), intent(inout) :: line
character(len=*), intent(in) :: comment_str
integer, intent(out) :: ios