@@ -164,6 +164,7 @@ module fms_mod
164
164
use fms2_io_mod, only: fms2_io_init
165
165
use memutils_mod, only: print_memuse_stats, memutils_init
166
166
use grid2_mod, only: grid_init, grid_end
167
+ use fms_string_utils_mod, only: fms_c2f_string, fms_cstring2cpointer, string
167
168
168
169
use , intrinsic :: iso_c_binding
169
170
@@ -294,40 +295,6 @@ module fms_mod
294
295
295
296
! > @}
296
297
297
- ! > Converts a number to a string
298
- ! > @ingroup fms_mod
299
- interface string
300
- module procedure string_from_integer
301
- module procedure string_from_real
302
- end interface
303
- ! > Converts a C string to a Fortran string
304
- ! > @ingroup fms_mod
305
- interface fms_c2f_string
306
- module procedure cstring_fortran_conversion
307
- module procedure cpointer_fortran_conversion
308
- end interface
309
- ! > C functions
310
- interface
311
- ! > @brief converts a kind=c_char to type c_ptr
312
- pure function fms_cstring2cpointer (cs ) result (cp) bind(c, name= " cstring2cpointer" )
313
- import c_char, c_ptr
314
- character (kind= c_char), intent (in ) :: cs(* ) ! < C string input
315
- type (c_ptr) :: cp ! < C pointer
316
- end function fms_cstring2cpointer
317
-
318
- ! > @brief Finds the length of a C-string
319
- integer (c_size_t) pure function c_strlen(s) bind(c,name= " strlen" )
320
- import c_size_t, c_ptr
321
- type (c_ptr), intent (in ), value :: s ! < A C-string whose size is desired
322
- end function
323
-
324
- ! > @brief Frees a C pointer
325
- subroutine c_free (ptr ) bind(c,name= " free" )
326
- import c_ptr
327
- type (c_ptr), value :: ptr ! < A C-pointer to free
328
- end subroutine
329
- end interface
330
-
331
298
! > @addtogroup fms_mod
332
299
! > @{
333
300
contains
@@ -801,61 +768,6 @@ function monotonic_array ( array, direction )
801
768
802
769
end function monotonic_array
803
770
804
- ! ! Functions from the old fms_io
805
- ! > @brief Converts an integer to a string
806
- ! !
807
- ! > This has been updated from the fms_io function.
808
- function string_from_integer (i ) result (res)
809
- integer , intent (in ) :: i ! < Integer to be converted to a string
810
- character (:),allocatable :: res ! < String converted frominteger
811
- character (range (i)+ 2 ) :: tmp ! < Temp string that is set to correct size
812
- write (tmp,' (i0)' ) i
813
- res = trim (tmp)
814
- return
815
-
816
- end function string_from_integer
817
-
818
- ! #######################################################################
819
- ! > @brief Converts a real to a string
820
- function string_from_real (a )
821
- real , intent (in ) :: a
822
- character (len= 32 ) :: string_from_real
823
-
824
- write (string_from_real,* ) a
825
-
826
- return
827
-
828
- end function string_from_real
829
-
830
- ! > \brief Converts a C-string to a pointer and then to a Fortran string
831
- function cstring_fortran_conversion (cstring ) result(fstring)
832
- character (kind= c_char), intent (in ) :: cstring (* ) ! < Input C-string
833
- character (len= :), allocatable :: fstring ! < The fortran string returned
834
- fstring = cpointer_fortran_conversion(fms_cstring2cpointer(cstring))
835
- end function cstring_fortran_conversion
836
-
837
- ! > \brief Converts a C-string returned from a TYPE(C_PTR) function to
838
- ! ! a fortran string with type character.
839
- function cpointer_fortran_conversion (cstring ) result(fstring)
840
- type (c_ptr), intent (in ) :: cstring ! < Input C-pointer
841
- character (len= :), allocatable :: fstring ! < The fortran string returned
842
- character (len= :,kind= c_char), pointer :: string_buffer ! < A temporary pointer to between C and Fortran
843
- integer (c_size_t) :: length ! < The string length
844
-
845
- length = c_strlen(cstring)
846
- allocate (character (len= length, kind= c_char) :: string_buffer)
847
- block
848
- character (len= length,kind= c_char), pointer :: s
849
- call c_f_pointer(cstring,s) ! Recovers a view of the C string
850
- string_buffer = s ! Copies the string contents
851
- end block
852
-
853
- allocate (character (len= length) :: fstring) ! > Set the length of fstring
854
- fstring = string_buffer
855
- deallocate (string_buffer)
856
-
857
- end function cpointer_fortran_conversion
858
-
859
771
! #######################################################################
860
772
! > @brief Prints to the log file (or a specified unit) the version id string and
861
773
! ! tag name.
0 commit comments