Skip to content

Commit 9bd56e6

Browse files
committed
Remove C null characters from strings read by PIO
The PIO2 library fills in unused characters of a string variable with C null characters, and replaces C null characters with spaces when reading strings. However, the PIO1 library does not perform these conversions. Consequently, if a file written by the PIO2 library is read by the PIO1 library, C null characters may be present in the resulting Fortran string. Under the assumption that C null characters will generally not be expected or handled in MPAS (e.g., in timestamp strings), this commit makes calls to MPAS_sanitize_string to convert any C null characters in strings read by PIO into spaces.
1 parent 756f03e commit 9bd56e6

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/framework/mpas_io.F

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2187,6 +2187,8 @@ end subroutine MPAS_io_get_var_real5d
21872187

21882188
subroutine MPAS_io_get_var_char0d(handle, fieldname, val, ierr)
21892189

2190+
use mpas_c_interfacing, only : MPAS_sanitize_string
2191+
21902192
implicit none
21912193

21922194
type (MPAS_IO_Handle_type), intent(inout) :: handle
@@ -2198,23 +2200,31 @@ subroutine MPAS_io_get_var_char0d(handle, fieldname, val, ierr)
21982200
if (present(ierr)) ierr = MPAS_IO_NOERR
21992201

22002202
call MPAS_io_get_var_generic(handle, fieldname, charVal=val, ierr=ierr)
2203+
call MPAS_sanitize_string(val)
22012204

22022205
end subroutine MPAS_io_get_var_char0d
22032206

22042207

22052208
subroutine MPAS_io_get_var_char1d(handle, fieldname, val, ierr)
22062209

2210+
use mpas_c_interfacing, only : MPAS_sanitize_string
2211+
22072212
implicit none
22082213

22092214
type (MPAS_IO_Handle_type), intent(inout) :: handle
22102215
character (len=*), intent(in) :: fieldname
22112216
character (len=*), dimension(:), intent(out) :: val
22122217
integer, intent(out), optional :: ierr
22132218

2219+
integer :: i
2220+
22142221
! call mpas_log_write('Called MPAS_io_get_var_char1d()')
22152222
if (present(ierr)) ierr = MPAS_IO_NOERR
22162223

22172224
call MPAS_io_get_var_generic(handle, fieldname, charArray1d=val, ierr=ierr)
2225+
do i=1,size(val)
2226+
call MPAS_sanitize_string(val(i))
2227+
end do
22182228

22192229
end subroutine MPAS_io_get_var_char1d
22202230

0 commit comments

Comments
 (0)