MOM6
|
Handy functions for manipulating strings.
By Alistair Adcroft and Robert Hallberg, last updated Sept. 2013.
The functions here perform a set of useful manipulations of character strings. Although they are a part of MOM6, the do not require any other MOM software to be useful.
Functions/Subroutines | |
character(len=len(input_string)) function, public | lowercase (input_string) |
Return a string in which all uppercase letters have been replaced by their lowercase counterparts. More... | |
character(len=len(input_string)) function, public | uppercase (input_string) |
Return a string in which all uppercase letters have been replaced by their lowercase counterparts. More... | |
character(len=19) function, public | left_int (i) |
Returns a character string of a left-formatted integer e.g. "123 " (assumes 19 digit maximum) More... | |
character(len=1320) function, public | left_ints (i) |
Returns a character string of a comma-separated, compact formatted, integers e.g. "1, 2, 3, 4". More... | |
character(len=32) function, public | left_real (val) |
Returns a left-justified string with a real formatted like '(G)'. More... | |
character(len=1320) function, public | left_reals (r, sep) |
Returns a character string of a comma-separated, compact formatted, reals e.g. "1., 2., 5*3., 5.E2". More... | |
logical function | isformattedfloatequalto (str, val) |
Returns True if the string can be read/parsed to give the exact value of "val". More... | |
character(len=120) function, public | extractword (string, n) |
Returns the string corresponding to the nth word in the argument or "" if the string is not long enough. Both spaces and commas are interpreted as separators. More... | |
character(len=120) function, public | extract_word (string, separators, n) |
Returns the string corresponding to the nth word in the argument or "" if the string is not long enough. Words are delineated by the mandatory separators argument. More... | |
integer function, public | extract_integer (string, separators, n, missing_value) |
Returns the integer corresponding to the nth word in the argument. More... | |
real function, public | extract_real (string, separators, n, missing_value) |
Returns the real corresponding to the nth word in the argument. More... | |
character(len=120) function, public | remove_spaces (string) |
Returns string with all spaces removed. More... | |
logical function, public | string_functions_unit_tests (verbose) |
Returns true if a unit test of string_functions fails. More... | |
logical function | localtests (verbose, str1, str2) |
True if str1 does not match str2. False otherwise. More... | |
logical function | localtesti (verbose, i1, i2) |
True if i1 is not equal to i2. False otherwise. More... | |
logical function | localtestr (verbose, r1, r2) |
True if r1 is not equal to r2. False otherwise. More... | |
character(len=len(dir)+2) function, public | slasher (dir) |
Returns a directory name that is terminated with a "/" or "./" if the argument is an empty string. More... | |
integer function, public mom_string_functions::extract_integer | ( | character(len=*), intent(in) | string, |
character(len=*), intent(in) | separators, | ||
integer, intent(in) | n, | ||
integer, intent(in), optional | missing_value | ||
) |
Returns the integer corresponding to the nth word in the argument.
[in] | string | String to scan |
[in] | separators | Characters to use for delineation |
[in] | n | Number of word to extract |
[in] | missing_value | Value to assign if word is missing |
Definition at line 244 of file MOM_string_functions.F90.
real function, public mom_string_functions::extract_real | ( | character(len=*), intent(in) | string, |
character(len=*), intent(in) | separators, | ||
integer, intent(in) | n, | ||
real, intent(in), optional | missing_value | ||
) |
Returns the real corresponding to the nth word in the argument.
[in] | string | String to scan |
[in] | separators | Characters to use for delineation |
[in] | n | Number of word to extract |
[in] | missing_value | Value to assign if word is missing |
Definition at line 268 of file MOM_string_functions.F90.
character(len=120) function, public mom_string_functions::extract_word | ( | character(len=*), intent(in) | string, |
character(len=*), intent(in) | separators, | ||
integer, intent(in) | n | ||
) |
Returns the string corresponding to the nth word in the argument or "" if the string is not long enough. Words are delineated by the mandatory separators argument.
[in] | string | String to scan |
[in] | separators | Characters to use for delineation |
[in] | n | Number of word to extract |
Definition at line 207 of file MOM_string_functions.F90.
character(len=120) function, public mom_string_functions::extractword | ( | character(len=*), intent(in) | string, |
integer, intent(in) | n | ||
) |
Returns the string corresponding to the nth word in the argument or "" if the string is not long enough. Both spaces and commas are interpreted as separators.
[in] | string | The string to scan |
[in] | n | Number of word to extract |
Definition at line 196 of file MOM_string_functions.F90.
|
private |
Returns True if the string can be read/parsed to give the exact value of "val".
[in] | str | The string to parse |
[in] | val | The real value to compare with |
Definition at line 180 of file MOM_string_functions.F90.
character(len=19) function, public mom_string_functions::left_int | ( | integer, intent(in) | i | ) |
Returns a character string of a left-formatted integer e.g. "123 " (assumes 19 digit maximum)
[in] | i | The integer to convert to a string |
Definition at line 60 of file MOM_string_functions.F90.
character(len=1320) function, public mom_string_functions::left_ints | ( | integer, dimension(:), intent(in) | i | ) |
Returns a character string of a comma-separated, compact formatted, integers e.g. "1, 2, 3, 4".
[in] | i | The array of integers to convert to a string |
Definition at line 71 of file MOM_string_functions.F90.
character(len=32) function, public mom_string_functions::left_real | ( | real, intent(in) | val | ) |
Returns a left-justified string with a real formatted like '(G)'.
[in] | val | The real variable to convert to a string |
Definition at line 87 of file MOM_string_functions.F90.
character(len=1320) function, public mom_string_functions::left_reals | ( | real, dimension(:), intent(in) | r, |
character(len=*), intent(in), optional | sep | ||
) |
Returns a character string of a comma-separated, compact formatted, reals e.g. "1., 2., 5*3., 5.E2".
[in] | r | The array of real variables to convert to a string |
[in] | sep | The separator between successive values, by default it is ', '. |
Definition at line 140 of file MOM_string_functions.F90.
|
private |
True if i1 is not equal to i2. False otherwise.
[in] | verbose | If true, write results to stdout |
[in] | i1 | Integer |
[in] | i2 | Integer |
Definition at line 371 of file MOM_string_functions.F90.
|
private |
True if r1 is not equal to r2. False otherwise.
[in] | verbose | If true, write results to stdout |
[in] | r1 | Float |
[in] | r2 | Float |
Definition at line 384 of file MOM_string_functions.F90.
|
private |
True if str1 does not match str2. False otherwise.
[in] | verbose | If true, write results to stdout |
[in] | str1 | String |
[in] | str2 | String |
Definition at line 358 of file MOM_string_functions.F90.
character(len=len(input_string)) function, public mom_string_functions::lowercase | ( | character(len=*), intent(in) | input_string | ) |
Return a string in which all uppercase letters have been replaced by their lowercase counterparts.
[in] | input_string | The string to modify |
Definition at line 24 of file MOM_string_functions.F90.
character(len=120) function, public mom_string_functions::remove_spaces | ( | character(len=*), intent(in) | string | ) |
Returns string with all spaces removed.
[in] | string | String to scan |
Definition at line 292 of file MOM_string_functions.F90.
character(len=len(dir)+2) function, public mom_string_functions::slasher | ( | character(len=*), intent(in) | dir | ) |
Returns a directory name that is terminated with a "/" or "./" if the argument is an empty string.
[in] | dir | A directory to be terminated with a "/" or changed to "./" if it is blank. |
Definition at line 398 of file MOM_string_functions.F90.
logical function, public mom_string_functions::string_functions_unit_tests | ( | logical, intent(in) | verbose | ) |
Returns true if a unit test of string_functions fails.
[in] | verbose | If true, write results to stdout |
Definition at line 314 of file MOM_string_functions.F90.
character(len=len(input_string)) function, public mom_string_functions::uppercase | ( | character(len=*), intent(in) | input_string | ) |
Return a string in which all uppercase letters have been replaced by their lowercase counterparts.
[in] | input_string | The string to modify |
Definition at line 42 of file MOM_string_functions.F90.