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.
References extract_word().
Referenced by mom_regridding::initialize_regridding(), and string_functions_unit_tests().
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.
References extract_word().
Referenced by mom_regridding::initialize_regridding(), and string_functions_unit_tests().
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.
Referenced by extract_integer(), extract_real(), extractword(), mom_open_boundary::parse_segment_data_str(), mom_open_boundary::parse_segment_str(), and string_functions_unit_tests().
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.
References extract_word().
Referenced by mom_diag_remap::diag_remap_init(), mom_regridding::initialize_regridding(), and string_functions_unit_tests().
|
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.
Referenced by left_real().
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.
Referenced by left_ints(), left_reals(), and string_functions_unit_tests().
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.
References left_int().
Referenced by string_functions_unit_tests().
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.
References isformattedfloatequalto().
Referenced by left_reals(), and string_functions_unit_tests().
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.
References left_int(), and left_real().
Referenced by string_functions_unit_tests().
|
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.
Referenced by string_functions_unit_tests().
|
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.
Referenced by string_functions_unit_tests().
|
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.
Referenced by string_functions_unit_tests().
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.
Referenced by mom_io::cmor_long_std(), mom_diag_remap::diag_remap_configure_axes(), mom_oda_driver_mod::init_oda(), mom_state_initialization::mom_initialize_state(), mom_io::num_timelevels(), mom_tracer_registry::register_tracer_diagnostics(), mom_restart::restore_state(), mom_tidal_mixing::tidal_mixing_init(), and mom_tracer_registry::tracer_name_lookup().
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.
Referenced by mom_open_boundary::open_boundary_config(), and string_functions_unit_tests().
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.
Referenced by mom_domains::mom_domains_init().
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.
References extract_integer(), extract_real(), extract_word(), extractword(), left_int(), left_ints(), left_real(), left_reals(), localtesti(), localtestr(), localtests(), and remove_spaces().
Referenced by mom_unit_tests::unit_tests().
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.
Referenced by mom_continuity::continuity_init(), regrid_consts::coordinatemode(), mom_coriolisadv::coriolisadv_init(), mom_energetic_pbl::energetic_pbl_init(), mom_eos::eos_init(), regrid_interp::interpolation_scheme(), mom_main(), mom_ocean_model_mct::ocean_model_init(), mom_ocean_model_nuopc::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_remapping::setreconstructiontype(), mom_surface_forcing_nuopc::surface_forcing_init(), mom_surface_forcing_mct::surface_forcing_init(), mom_tidal_mixing::tidal_mixing_init(), and mom_surface_forcing::wind_forcing_from_file().