mom_string_functions module reference

Handy functions for manipulating strings.

More…

Functions/Subroutines

lowercase()

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

uppercase()

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

left_int()

Returns a character string of a left-formatted integer e.g.

left_ints()

Returns a character string of a comma-separated, compact formatted, integers e.g.

left_real()

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

left_reals()

Returns a character string of a comma-separated, compact formatted, reals e.g.

isformattedfloatequalto()

Returns True if the string can be read/parsed to give the exact value of "val".

extractword()

Returns the string corresponding to the nth word in the argument or "" if the string is not long enough.

extract_word()

Returns the string corresponding to the nth word in the argument or "" if the string is not long enough.

extract_integer()

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

extract_real()

Returns the real corresponding to the nth word in the argument, in arbitrary units [A].

remove_spaces()

Returns string with all spaces removed.

string_functions_unit_tests()

Returns true if a unit test of string_functions fails.

localtests()

True if str1 does not match str2.

localtesti()

True if i1 is not equal to i2.

localtestr()

True if r1 is not equal to r2.

slasher()

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

trim_trailing_commas()

Returns a left-adjusted string with trailing blanks and commas removed.

ints_to_string()

Convert the first n elements (3 by default) of an integer array into an underscore delimited string.

Detailed Description

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.

Function/Subroutine Documentation

function  mom_string_functions/lowercase(input_string)

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

Parameters:

input_string :: input_string [in] The string to modify

Return:

undefined :: The modified output string

Called from:

basin_builder::basin_builder_topography mom_io::cmor_long_std mom_io::create_mom_file mom_diag_remap::diag_remap_configure_axes mom_io::get_varid mom_oda_driver_mod::init_oda mom_meke::meke_init mom_state_initialization::mom_initialize_obcs mom_tracer_registry::register_tracer mom_tracer_registry::register_tracer_diagnostics mom_restart::restore_state mom_self_attr_load::sal_init mom_tidal_mixing::tidal_mixing_init mom_tracer_registry::tracer_name_lookup

[source]

function  mom_string_functions/uppercase(input_string)

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

Parameters:

input_string :: input_string [in] The string to modify

Return:

undefined :: The modified output string

Called from:

regrid_consts::coordinatemode mom_coriolisadv::coriolisadv_init mom_energetic_pbl::energetic_pbl_init mom_internal_tides::internal_tides_init regrid_interp::interpolation_scheme mom6 mom_is_diag_mediator::mom_is_diag_mediator_init ocean_model_mod::ocean_model_init mom_opacity::opacity_init mom_shared_initialization::read_face_length_list mom_tidal_mixing::read_tidal_energy mom_shared_initialization::reset_face_lengths_list mom_open_boundary::scale_factor_from_name mom_remapping::setreconstructiontype mom_surface_forcing_gfdl::surface_forcing_init mom_tidal_mixing::tidal_mixing_init mom_surface_forcing::wind_forcing_from_file

[source]

function  mom_string_functions/left_int(i)

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

Parameters:

i :: i [in] The integer to convert to a string

Return:

undefined :: The output string

Called from:

left_ints left_reals string_functions_unit_tests

[source]

function  mom_string_functions/left_ints(i)

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

Parameters:

i :: i [in] The array of integers to convert to a string

Return:

undefined :: The output string

Call to:

left_int

Called from:

string_functions_unit_tests

[source]

function  mom_string_functions/left_real(val)

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

Parameters:

val :: val [in] The real variable to convert to a string, in arbitrary units [A]

Return:

undefined :: The output string

Call to:

isformattedfloatequalto

Called from:

left_reals string_functions_unit_tests

[source]

function  mom_string_functions/left_reals(r, sep)

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

Parameters:
  • r :: r [in] The array of real variables to convert to a string, in arbitrary units [A]

  • sep :: sep [in] The separator between successive values, by default it is ‘, ‘.

Return:

undefined :: The output string

Call to:

left_int left_real

Called from:

string_functions_unit_tests

[source]

function  mom_string_functions/isformattedfloatequalto(str, val)

Returns True if the string can be read/parsed to give the exact value of “val”.

Parameters:
  • str :: str [in] The string to parse

  • val :: val [in] The real value to compare with, in arbitrary units [A]

Called from:

left_real

[source]

function  mom_string_functions/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.

Parameters:
  • string :: string [in] The string to scan

  • n :: n [in] Number of word to extract

Call to:

extract_word

Called from:

mom_diag_remap::diag_remap_init mom_regridding::initialize_regridding mom_int_tide_input::int_tide_input_init string_functions_unit_tests

[source]

function  mom_string_functions/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.

Parameters:
  • string :: string [in] String to scan

  • separators :: separators [in] Characters to use for delineation

  • n :: n [in] Number of word to extract

Called from:

extract_integer extract_real extractword mom_open_boundary::parse_segment_data_str mom_open_boundary::parse_segment_manifest_str mom_open_boundary::parse_segment_str string_functions_unit_tests

[source]

function  mom_string_functions/extract_integer(string, separators, n, missing_value)

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

Parameters:
  • string :: string [in] String to scan

  • separators :: separators [in] Characters to use for delineation

  • n :: n [in] Number of word to extract

  • missing_value :: missing_value [in] Value to assign if word is missing

Call to:

extract_word

Called from:

mom_regridding::initialize_regridding string_functions_unit_tests

[source]

function  mom_string_functions/extract_real(string, separators, n, missing_value)

Returns the real corresponding to the nth word in the argument, in arbitrary units [A].

Parameters:
  • string :: string [in] String to scan

  • separators :: separators [in] Characters to use for delineation

  • n :: n [in] Number of word to extract

  • missing_value :: missing_value [in] Value to assign if word is missing, in arbitrary units [A]

Call to:

extract_word

Called from:

mom_regridding::initialize_regridding mom_internal_tides::internal_tides_init string_functions_unit_tests

[source]

function  mom_string_functions/remove_spaces(string)

Returns string with all spaces removed.

Parameters:

string :: string [in] String to scan

Called from:

mom_open_boundary::open_boundary_config string_functions_unit_tests

[source]

function  mom_string_functions/string_functions_unit_tests(verbose)

Returns true if a unit test of string_functions fails.

Parameters:

verbose :: verbose [in] If true, write results to stdout

Call to:

extract_integer extract_real extract_word extractword ints_to_string left_int left_ints left_real left_reals localtesti localtestr localtests remove_spaces trim_trailing_commas

Called from:

mom_unit_tests::unit_tests

[source]

function  mom_string_functions/localtests(verbose, str1, str2)

True if str1 does not match str2. False otherwise.

Parameters:
  • verbose :: verbose [in] If true, write results to stdout

  • str1 :: str1 [in] String

  • str2 :: str2 [in] String

Called from:

string_functions_unit_tests

[source]

function  mom_string_functions/localtesti(verbose, i1, i2)

True if i1 is not equal to i2. False otherwise.

Parameters:
  • verbose :: verbose [in] If true, write results to stdout

  • i1 :: i1 [in] Integer

  • i2 :: i2 [in] Integer

Called from:

string_functions_unit_tests

[source]

function  mom_string_functions/localtestr(verbose, r1, r2)

True if r1 is not equal to r2. False otherwise.

Parameters:
  • verbose :: verbose [in] If true, write results to stdout

  • r1 :: r1 [in] The first value to compare, in arbitrary units [A]

  • r2 :: r2 [in] The first value to compare, in arbitrary units [A]

Called from:

string_functions_unit_tests

[source]

function  mom_string_functions/slasher(dir)

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

Parameters:

dir :: dir [in] A directory to be terminated with a “/” or changed to “./” if it is blank.

Called from:

mom_diag_mediator::diag_mediator_init mom_hybgen_regrid::init_hybgen_regrid mom_domains::mom_domains_init mom_is_diag_mediator::mom_is_diag_mediator_init mom_coord_initialization::set_coord_from_file mom_coord_initialization::set_coord_from_ts_profile

[source]

function  mom_string_functions/trim_trailing_commas(in_str)

Returns a left-adjusted string with trailing blanks and commas removed.

Parameters:

in_str :: in_str [in] A string that is to be left adjusted and have its trailing commas and white space removed.

Return:

undefined :: A left-adjusted version of in_str with trailing commas and white space removed

Called from:

mom_diag_mediator::register_diag_field mom_is_diag_mediator::register_mom_is_diag_field mom_is_diag_mediator::register_mom_is_static_field mom_diag_mediator::register_static_field string_functions_unit_tests

[source]

function  mom_string_functions/ints_to_string(a, n)

Convert the first n elements (3 by default) of an integer array into an underscore delimited string.

Parameters:
  • a :: a [in] The array of integers to translate

  • n :: n [in] The number of elements to translate, by default the lesser of 3 or all of the integers

Return:

undefined :: The returned underscore delimited string of integers

Called from:

mom_diag_mediator::define_axes_group mom_is_diag_mediator::define_axes_group mom_diag_mediator::define_axes_group_dsamp string_functions_unit_tests

[source]

[source]