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.
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.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | num | |||
| character(len=*), | intent(in), | optional | :: | frmt |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer(kind=ip_long), | intent(in) | :: | num | |||
| character(len=*), | intent(in), | optional | :: | frmt |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=rp), | intent(in) | :: | num | |||
| character(len=*), | intent(in), | optional | :: | frmt |
Returns .true. if str contains only letters (a--z or A--Z) and
.false. otherwise.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | str |
Returns .true. if str contains only digits (0,1,...,9) and
.false. otherwise.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | str |
Returns .true. if str is non-empty and contains only whitespace
characters (tab or blankspace). Otherwise .false. is returned.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | str |
Returns .true. if line is a comment, .false. other wise.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | line | Input string |
||
| character(len=*), | intent(in) | :: | comment_str | String marking the beginning of a comment. |
Returns a copy of str with multiple spaces and tabs converted to
single spaces, control characters deleted, and leading and trailing
spaces removed.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | str |
Returns a copy of the string str with spaces, tabs, and
control characters removed.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | str |
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.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | str |
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.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | str |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | num | |||
| character(len=*), | intent(in), | optional | :: | frmt |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer(kind=ip_long), | intent(in) | :: | num | |||
| character(len=*), | intent(in), | optional | :: | frmt |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| real(kind=rp), | intent(in) | :: | num | |||
| character(len=*), | intent(in), | optional | :: | frmt |
Deletes nonsignificant trailing zeroes from number string str. If number string ends in a decimal point, one trailing zero is added.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | str |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | str |
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | str |
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.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | str | |||
| character(len=*), | intent(in) | :: | chars | |||
| character(len=1), | intent(in) | :: | ends | {'l', 'r', 'b'} |
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.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | str | |||
| character(len=*), | intent(in) | :: | prefix | |||
| integer, | intent(in), | optional | :: | start | ||
| integer, | intent(in), | optional | :: | finish |
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.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | str | |||
| character(len=*), | intent(in) | :: | suffix | |||
| integer, | intent(in), | optional | :: | start | ||
| integer, | intent(in), | optional | :: | finish |
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.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(inout) | :: | str | |||
| integer, | intent(in) | :: | n |
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.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(inout) | :: | str | |||
| character(len=*), | intent(in) | :: | substr | |||
| integer, | intent(in) | :: | loc |
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.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(inout) | :: | str | |||
| character(len=*), | intent(in) | :: | substr | |||
| integer, | intent(in), | optional | :: | n |
Strips trailing comment from a string.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(inout) | :: | str | Input string |
||
| character(len=*), | intent(in) | :: | comment_str | String indicating beginning of a comment. |
Split a string str into two strings, key and val based on space
delimiter.
| Type | Intent | Optional | 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 |
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 (), [], {}, <>.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | str | |||
| integer, | intent(in) | :: | ipos | |||
| integer, | intent(out) | :: | imatch |
Compact a string representing a real number, so that the same value is displayed with fewer characters.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(inout) | :: | str | string representation of a real number. |
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.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(inout) | :: | str | |||
| character(len=*), | intent(in) | :: | delimiter | |||
| character(len=:), | intent(out), | allocatable | :: | before |
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.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(inout) | :: | dest | |||
| character(len=*), | intent(in) | :: | source | |||
| character(len=*), | intent(in), | optional | :: | sep |
Reads a line from unit=nunitr, ignoring blank lines and deleting comments
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| integer, | intent(in) | :: | nunitr | |||
| character(len=*), | intent(inout) | :: | line | |||
| character(len=*), | intent(in) | :: | comment_str | |||
| integer, | intent(out) | :: | ios |