0.6.2-dev0
FORCES
FORtran lib for Comp. Env. Sys.
Loading...
Searching...
No Matches
mo_string_utils Module Reference

String utilities. More...

Data Types

interface  num2str
 Convert to string. More...
 
interface  numarray2str
 Convert to string. More...
 

Functions/Subroutines

pure logical function, public is_blank (c)
 Check for blank characters.
 
character(len(whitespaces)) function, public compress (whitespaces, n)
 Remove white spaces.
 
character(len(s)+100) function, public replace_text (s, text, rep)
 
character(len(s)+100) function, public replace_word (s, word, rep, check_negative_number_arg)
 replaces words in a string
 
integer function, public index_word (s, text, check_negative_number_arg)
 find index in word
 
subroutine, public divide_string (string, delim, strarr)
 Divide string in substrings.
 
logical function, public equalstrings (string1, string2)
 Checks if two string are equal.
 
logical function, public nonull (str)
 Checks if string was already used.
 
character(len=256) function, dimension(:), allocatable, public splitstring (string, delim)
 split string at delimiter
 
logical function, public startswith (string, start, strip)
 Checks if string starts with character(s)
 
logical function, public endswith (string, suffix, strip)
 Checks if (maybe trimmed) string ends with given character(s)
 
character(len=len_trim(upper)) function, public tolower (upper)
 Convert to lower case.
 
character(len=len_trim(lower)) function, public toupper (lower)
 Convert to upper case.
 
pure character(len=10) function i42str (nn, form)
 
pure character(len=20) function i82str (nn, form)
 
pure character(len=32) function sp2str (rr, form)
 
pure character(len=32) function dp2str (rr, form)
 
pure character(len=10) function log2str (ll, form)
 
character(len=size(arr)) function i4array2str (arr)
 
integer(i4) function, dimension(:), allocatable, public str2num (string)
 Converts string into an array of its numerical representation.
 

Variables

character(len= *), parameter, public separator = repeat('-', 70)
 separator string (line)
 

Detailed Description

String utilities.

This module provides string conversion and checking utilities.

Authors
Matthias Cuntz, Matthias Zink, Giovanni Dalmasso, David Schaefer
Date
Dec 2011

Function/Subroutine Documentation

◆ compress()

character(len(whitespaces)) function, public mo_string_utils::compress ( character(len=*), intent(in)  whitespaces,
integer(i4), intent(out), optional  n 
)

Remove white spaces.

Return a copy of an input string with all whitespace (spaces and tabs) removed

Example

Returns 'Hallo'

nospaces = whitespaces = compress('H a l l o')
Parameters
[in]character(len=*) :: whiteSpacesString
[out]integer(i4), optional :: nInteger
Return values
character(len = len(whiteSpaces)) :: compressString where all all whitespace (spaces and tabs) are removed
Author
Giovanni Dalmasso
Date
Jan 2013
  • modified from Paul van Delst, CIMSS/SSEC 18-Oct-1999

Definition at line 156 of file mo_string_utils.f90.

References compress(), and mo_kind::i4.

Referenced by compress(), mo_sce::sce(), and mo_utils::special_value::special_value_sp().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ divide_string()

subroutine, public mo_string_utils::divide_string ( character(len=*), intent(in)  string,
character(len=*), intent(in)  delim,
character(len=*), dimension(:), intent(out), allocatable  strarr 
)

Divide string in substrings.

Divides a string in several substrings (array of strings) with the help of a user specified delimiter.

Example

Divide string into 'I', 'want', 'to', ...

divide_string('I want to test this routine!', ' ', strarr(:))
Parameters
[in]CHARACTER(len=*), INTENT(IN) :: string- string to be divided
[in]CHARACTER(len=*), INTENT(IN) :: delim- delimiter specifying places for division
[out]CHARACTER(len=*), DIMENSION(:), ALLOCATABLE, INTENT(OUT) :: strArrArray of substrings, has to be allocateable and is handed to the routine unallocated
Note
only character types allowed.
output array should be allocateable array, which is unallocated handed to the subroutine. allocation is done in in devide_string.
Author
Matthias Zink
Date
Oct 2012

Definition at line 325 of file mo_string_utils.f90.

Referenced by mo_datetime::d_from_string(), mo_datetime::dt_from_cf(), mo_datetime::dt_from_string(), and mo_datetime::t_from_string().

Here is the caller graph for this function:

◆ dp2str()

pure character(len=32) function mo_string_utils::dp2str ( real(dp), intent(in)  rr,
character(len=*), intent(in), optional  form 
)
private

Definition at line 692 of file mo_string_utils.f90.

◆ endswith()

logical function, public mo_string_utils::endswith ( character(len=*), intent(in)  string,
character(len=*), intent(in)  suffix,
logical, intent(in), optional  strip 
)

Checks if (maybe trimmed) string ends with given character(s)

Return values
endswithif string ends with given end
Author
Sebastian Müller
Date
Mar 2023
Parameters
[in]stringstring to check
[in]suffixending string
[in]stripwhether to strip trailing white-spaces (.true. by default)

Definition at line 527 of file mo_string_utils.f90.

References endswith().

Referenced by endswith(), mo_os::path_join_char(), mo_os::path_join::path_join_char_opt(), and mo_os::path_splitext().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ equalstrings()

logical function, public mo_string_utils::equalstrings ( character(len=*), intent(in)  string1,
character(len=*), intent(in)  string2 
)

Checks if two string are equal.

Returns true if the given string arguments are equal

Example

isequal = equalstring(string1,string2)
Parameters
[in]character(len=*) :: string1String
[in]character(len=*) :: string2String
Return values
logical :: eqLogical value if string equal
Author
David Schaefer
Date
Mar 2015

Definition at line 389 of file mo_string_utils.f90.

References equalstrings(), and str2num().

Referenced by equalstrings().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ i42str()

pure character(len=10) function mo_string_utils::i42str ( integer(i4), intent(in)  nn,
character(len=*), intent(in), optional  form 
)
private

Definition at line 641 of file mo_string_utils.f90.

◆ i4array2str()

character(len=size(arr)) function mo_string_utils::i4array2str ( integer(i4), dimension(:), intent(in)  arr)
private

Definition at line 725 of file mo_string_utils.f90.

◆ i82str()

pure character(len=20) function mo_string_utils::i82str ( integer(i8), intent(in)  nn,
character(len=*), intent(in), optional  form 
)
private

Definition at line 658 of file mo_string_utils.f90.

◆ index_word()

integer function, public mo_string_utils::index_word ( character(*)  s,
character(*)  text,
logical, optional  check_negative_number_arg 
)

find index in word

Author
Robert Schweppe
Date
Nov 2018

Definition at line 236 of file mo_string_utils.f90.

Referenced by replace_word().

Here is the caller graph for this function:

◆ is_blank()

pure logical function, public mo_string_utils::is_blank ( character(len=1), intent(in)  c)

Check for blank characters.

Checks whether or not c is a blank character, namely a space and tab character.

Returns
Truth value if c is a blank.
Parameters
[in]cThe character to test.

Definition at line 125 of file mo_string_utils.f90.

References is_blank().

Referenced by is_blank(), and mo_io::number_of_columns().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ log2str()

pure character(len=10) function mo_string_utils::log2str ( logical, intent(in)  ll,
character(len=*), intent(in), optional  form 
)
private

Definition at line 709 of file mo_string_utils.f90.

◆ nonull()

logical function, public mo_string_utils::nonull ( character(len=*), intent(in)  str)

Checks if string was already used.

Checks if string was already used, i.e. does not contain NULL character anymore.

Example

Trim if string is used.

if (nonull(str)) write(*,*) trim(str)
Parameters
[in]character(len=*) :: strString
Return values
logical :: used.true.: string was already set; .false.: string still in initialised state
Author
Matthias Cuntz
Date
Jan 2012

Definition at line 432 of file mo_string_utils.f90.

References nonull().

Referenced by mo_ncwrite::create_netcdf(), and nonull().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ replace_text()

character(len(s)+100) function, public mo_string_utils::replace_text ( character(*)  s,
character(*)  text,
character(*)  rep 
)

Definition at line 201 of file mo_string_utils.f90.

◆ replace_word()

character(len(s)+100) function, public mo_string_utils::replace_word ( character(*)  s,
character(*)  word,
character(*)  rep,
logical, optional  check_negative_number_arg 
)

replaces words in a string

replaces proper words only, e.g. replace_word('our hour', 'our', 'their') --> 'their hour'

Author
Robert Schweppe
Date
Nov 2018

Definition at line 218 of file mo_string_utils.f90.

References index_word().

Here is the call graph for this function:

◆ sp2str()

pure character(len=32) function mo_string_utils::sp2str ( real(sp), intent(in)  rr,
character(len=*), intent(in), optional  form 
)
private

Definition at line 675 of file mo_string_utils.f90.

◆ splitstring()

character(len=256) function, dimension(:), allocatable, public mo_string_utils::splitstring ( character(len=*), intent(in)  string,
character(len=*), intent(in)  delim 
)

split string at delimiter

Split string at delimiter an return an array of strings

Example

string_parts = splitstring(string,delim)
Parameters
[in]character(len=*) :: stringString
[in]character(len=*) :: delimString
Return values
character(len=245) :: out(:)Array of splitted strings
Author
David Schaefer
Date
Mar 2015

Definition at line 466 of file mo_string_utils.f90.

References str2num().

Here is the call graph for this function:

◆ startswith()

logical function, public mo_string_utils::startswith ( character(len=*), intent(in)  string,
character(len=*), intent(in)  start,
logical, intent(in), optional  strip 
)

Checks if string starts with character(s)

Returns true if string starts with given characters, flase otherwise

Author
David Schaefer
Date
Mar 2015
Parameters
[in]stringstring to check
[in]startstarting string
[in]stripwhether to strip trailing white-spaces (.false. by default)

Definition at line 497 of file mo_string_utils.f90.

References startswith().

Referenced by mo_os::path_isabs(), mo_os::path_isroot(), and startswith().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ str2num()

integer(i4) function, dimension(:), allocatable, public mo_string_utils::str2num ( character(len=*), intent(in)  string)

Converts string into an array of its numerical representation.

Converts string into an integer array of the numerical values of the letters

Example

Convert is string into numerical array of the letters

num = str2num(string)
Parameters
[in]character(len=*) :: stringString
Return values
integer :: out(:)Numerical array of letters
Author
David Schaefer
Date
Mar 2015

Definition at line 757 of file mo_string_utils.f90.

Referenced by equalstrings(), and splitstring().

Here is the caller graph for this function:

◆ tolower()

character(len=len_trim(upper)) function, public mo_string_utils::tolower ( character(len=*), intent(in)  upper)

Convert to lower case.

Convert all upper case letters in string to lower case letters.

Example

Returns 'hallo'

low = tolower('Hallo')
Parameters
[in]character(len=*) :: upperString
Return values
character(len=len_trim(upper)) :: lowString where all uppercase in input is converted to lowercase
Author
Matthias Cuntz
Date
Dec 2011
  • modified from Echam5, (C) MPI-MET, Hamburg, Germany

Definition at line 573 of file mo_string_utils.f90.

References tolower().

Referenced by mo_nml::position_nml(), and tolower().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toupper()

character(len=len_trim(lower)) function, public mo_string_utils::toupper ( character(len=*), intent(in)  lower)

Convert to upper case.

Convert all lower case letters in string to upper case letters.

Example

Returns 'HALLO'

up = toupper('Hallo')
Parameters
[in]character(len=*) :: lowerString
Return values
character(len=len_trim(lower)) :: upString where all lowercase in input is converted to uppercase
Author
Matthias Cuntz
Date
Dec 2011
  • modified from Echam5, (C) MPI-MET, Hamburg, Germany

Definition at line 614 of file mo_string_utils.f90.

References toupper().

Referenced by toupper().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ separator

character(len=*), parameter, public mo_string_utils::separator = repeat('-', 70)

separator string (line)

Definition at line 116 of file mo_string_utils.f90.