FMS  2024.03
Flexible Modeling System
fms_string_utils_mod

Routines to use for string manipulation. More...

Functions/Subroutines

character(len=:) function, allocatable cpointer_fortran_conversion (cstring)
 Converts a C-string returned from a TYPE(C_PTR) function to a fortran string with type character. More...
 
character(len=:) function, allocatable cstring_fortran_conversion (cstring)
 Converts a C-string to a pointer and then to a Fortran string. More...
 
type(c_ptr) function, dimension(:), allocatable, public fms_array_to_pointer (my_array)
 Converts a character array to an array of c pointers! More...
 
subroutine, public fms_f2c_string (dest, str_in)
 Copies a Fortran string into a C string and puts c_null_char in any trailing spaces. More...
 
integer function, dimension(:), allocatable, public fms_find_my_string (my_pointer, narray, string_to_find)
 Searches through a SORTED array of pointers for a string. More...
 
character(len=:) function, dimension(:), allocatable, public fms_pointer_to_array (my_pointer, narray)
 Convert an array of c pointers back to a character array. More...
 
character(:) function, allocatable, public string (v, fmt)
 Converts a number or a Boolean value to a string. More...
 
subroutine, public string_copy (dest, source, check_for_null)
 Safely copy a string from one buffer to another. More...
 

Detailed Description

Routines to use for string manipulation.

Function/Subroutine Documentation

◆ cpointer_fortran_conversion()

character(len=:) function, allocatable fms_string_utils_mod::cpointer_fortran_conversion ( type (c_ptr), intent(in)  cstring)
private

Converts a C-string returned from a TYPE(C_PTR) function to a fortran string with type character.

Parameters
[in]cstringInput C-pointer
Returns
The fortran string returned

Set the length of fstring

Definition at line 208 of file fms_string_utils.F90.

◆ cstring_fortran_conversion()

character(len=:) function, allocatable fms_string_utils_mod::cstring_fortran_conversion ( character (kind=c_char), dimension (*), intent(in)  cstring)
private

Converts a C-string to a pointer and then to a Fortran string.

Parameters
[in]cstringInput C-string
Returns
The fortran string returned

Definition at line 200 of file fms_string_utils.F90.

◆ fms_array_to_pointer()

type(c_ptr) function, dimension(:), allocatable, public fms_string_utils_mod::fms_array_to_pointer ( character(len=*), dimension(:), target  my_array)

Converts a character array to an array of c pointers!

Returns
An array of c pointers

Definition at line 131 of file fms_string_utils.F90.

◆ fms_f2c_string()

subroutine, public fms_string_utils_mod::fms_f2c_string ( character (c_char), dimension (:), intent(out)  dest,
character (len=*), intent(in)  str_in 
)

Copies a Fortran string into a C string and puts c_null_char in any trailing spaces.

Parameters
[out]destC String to be copied into
[in]str_inFortran string to copy to C string

Drop an error if the C string is not large enough to hold the input and the c_null_char at the end.

Copy c_null_char into each spot in dest

Loop though and put each character of the Fortran string into the C string array

Definition at line 228 of file fms_string_utils.F90.

◆ fms_find_my_string()

integer function, dimension(:), allocatable, public fms_string_utils_mod::fms_find_my_string ( type(c_ptr), dimension(*), intent(in)  my_pointer,
integer, intent(in)  narray,
character(len=*), intent(in)  string_to_find 
)

Searches through a SORTED array of pointers for a string.

Returns
the indices where the array was found If the string was not found, indices will be indices(1) = -999
Example usage: my_pointer = fms_array_to_pointer(my_array) call fms_sort_this(my_pointer, n_array, indices) ifind = fms_find_my_string(my_pointer, n_array, string_to_find)
Parameters
[in]my_pointerArray of c pointer
[in]narrayLength of the array
[in]string_to_findstring to find

Definition at line 173 of file fms_string_utils.F90.

◆ fms_pointer_to_array()

character(len=:) function, dimension(:), allocatable, public fms_string_utils_mod::fms_pointer_to_array ( type(c_ptr), dimension(*), intent(in)  my_pointer,
integer, intent(in)  narray 
)

Convert an array of c pointers back to a character array.

Returns
A character array
Parameters
[in]my_pointerArray of c pointer
[in]narrayLength of the array

Definition at line 149 of file fms_string_utils.F90.

◆ string()

character(:) function, allocatable, public fms_string_utils_mod::string ( class(*), intent(in)  v,
character(*), intent(in), optional  fmt 
)

Converts a number or a Boolean value to a string.

Returns
The argument as a string
Parameters
[in]vValue to be converted to a string
[in]fmtOptional format string for a real or integral argument

Definition at line 245 of file fms_string_utils.F90.

◆ string_copy()

subroutine, public fms_string_utils_mod::string_copy ( character(len=*), intent(inout)  dest,
character(len=*), intent(in)  source,
logical, intent(in), optional  check_for_null 
)

Safely copy a string from one buffer to another.

Parameters
[in,out]destDestination string.
[in]sourceSource string.
[in]check_for_nullFlag indicating to test for null character

Definition at line 304 of file fms_string_utils.F90.