Skip to content

Commit 756f03e

Browse files
committed
Add new MPAS_sanitize_string routine to mpas_c_interfacing
The MPAS_sanitize_string routine converts C null characters in a Fortran string to spaces.
1 parent ece5f71 commit 756f03e

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/framework/mpas_c_interfacing.F

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,37 @@ module mpas_c_interfacing
44
contains
55

66

7+
!-----------------------------------------------------------------------
8+
! routine mpas_sanitize_string
9+
!
10+
!> \brief Converts C null characters in a Fortran string to spaces
11+
!> \author Michael Duda
12+
!> \date 19 February 2019
13+
!> \details
14+
!> Converts all C null characters in a Fortran string to spaces.
15+
!> This may be useful for strings that were provided by C code through other
16+
!> Fortran code external to MPAS.
17+
!
18+
!-----------------------------------------------------------------------
19+
subroutine mpas_sanitize_string(str)
20+
21+
use iso_c_binding, only : c_null_char
22+
23+
implicit none
24+
25+
character(len=*), intent(inout) :: str
26+
27+
integer :: i
28+
29+
do i=1,len(str)
30+
if (str(i:i) == c_null_char) then
31+
str(i:i) = ' '
32+
end if
33+
end do
34+
35+
end subroutine mpas_sanitize_string
36+
37+
738
!-----------------------------------------------------------------------
839
! routine mpas_c_to_f_string
940
!

0 commit comments

Comments
 (0)