namespace mom_string_functions

Overview

Handy functions for manipulating strings. More…

namespace mom_string_functions {

// global functions

character(len=len(input_string)) function, public lowercase(input_string input_string);
character(len=len(input_string)) function, public uppercase(input_string input_string);
character(len=19) function, public left_int(i i);
character(len=1320) function, public left_ints(i i);
character(len=32) function, public left_real(val val);
character(len=1320) function, public left_reals(r r, sep sep);
character(len=120) function, public extractword(string string, n n);
character(len=120) function, public extract_word(string string, separators separators, n n);

integer function, public extract_integer(
    string string,
    separators separators,
    n n,
    missing_value missing_value
    );

real function, public extract_real(
    string string,
    separators separators,
    n n,
    missing_value missing_value
    );

character(len=120) function, public remove_spaces(string string);
logical function, public string_functions_unit_tests(verbose verbose);
character(len=len(dir)+2) function, public slasher(dir dir);

} // namespace mom_string_functions

Detailed Documentation

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.

Global Functions

character(len=len(input_string)) function, public lowercase(input_string input_string)

Return a string in which all uppercase letters have been replaced by their lowercase counterparts.

Parameters:

input_string

The string to modify

Returns:

The modified output string

character(len=len(input_string)) function, public uppercase(input_string input_string)

Return a string in which all uppercase letters have been replaced by their lowercase counterparts.

Parameters:

input_string

The string to modify

Returns:

The modified output string

character(len=19) function, public left_int(i i)

Returns a character string of a left-formatted integer e.g. “123 ” (assumes 19 digit maximum)

Parameters:

i

The integer to convert to a string

Returns:

The output string

character(len=1320) function, public left_ints(i i)

Returns a character string of a comma-separated, compact formatted, integers e.g. “1, 2, 3, 4”.

Parameters:

i

The array of integers to convert to a string

Returns:

The output string

character(len=32) function, public left_real(val val)

Returns a left-justified string with a real formatted like ‘(G)’.

Parameters:

val

The real variable to convert to a string

Returns:

The output string

character(len=1320) function, public left_reals(r r, sep sep)

Returns a character string of a comma-separated, compact formatted, reals e.g. “1., 2., 5*3., 5.E2”.

Parameters:

r

The array of real variables to convert to a string

sep

The separator between successive values, by default it is ‘, ‘.

Returns:

The output string

character(len=120) function, public extractword(string string, n 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.

Parameters:

string

The string to scan

n

Number of word to extract

character(len=120) function, public extract_word(
    string string,
    separators separators,
    n 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.

Parameters:

string

String to scan

separators

Characters to use for delineation

n

Number of word to extract

integer function, public extract_integer(
    string string,
    separators separators,
    n n,
    missing_value missing_value
    )

Returns the integer corresponding to the nth word in the argument.

Parameters:

string

String to scan

separators

Characters to use for delineation

n

Number of word to extract

missing_value

Value to assign if word is missing

real function, public extract_real(
    string string,
    separators separators,
    n n,
    missing_value missing_value
    )

Returns the real corresponding to the nth word in the argument.

Parameters:

string

String to scan

separators

Characters to use for delineation

n

Number of word to extract

missing_value

Value to assign if word is missing

character(len=120) function, public remove_spaces(string string)

Returns string with all spaces removed.

Parameters:

string

String to scan

logical function, public string_functions_unit_tests(verbose verbose)

Returns true if a unit test of string_functions fails.

Parameters:

verbose

If true, write results to stdout

character(len=len(dir)+2) function, public slasher(dir dir)

Returns a directory name that is terminated with a “/” or “./” if the argument is an empty string.

Parameters:

dir

A directory to be terminated with a “/” or changed to “./” if it is blank.