summaryrefslogtreecommitdiffstats
path: root/fortran/src/H5fortkit.F90
diff options
context:
space:
mode:
Diffstat (limited to 'fortran/src/H5fortkit.F90')
-rw-r--r--fortran/src/H5fortkit.F9027
1 files changed, 18 insertions, 9 deletions
diff --git a/fortran/src/H5fortkit.F90 b/fortran/src/H5fortkit.F90
index b745c22..70d7087 100644
--- a/fortran/src/H5fortkit.F90
+++ b/fortran/src/H5fortkit.F90
@@ -25,6 +25,8 @@
!*****
MODULE H5fortkit
+ USE H5FORTRAN_TYPES, ONLY : SIZE_T
+
CONTAINS
!****if* H5fortkit/HD5c2fstring
@@ -32,28 +34,35 @@ CONTAINS
! HD5c2fstring
! INPUTS
! cstring - C string stored as a string array of size 'len' of string size LEN=1
-! len - length of Fortran string
+! f_len - length of Fortran string
+! c_len - length of C array
! OUTPUT
-! fstring - Fortran string array of LEN=1
+! fstring - Fortran string LEN=1
! PURPOSE
-! Copies a Fortran array of strings having a length of one to a fortran string and removes the C Null
+! Copies a C array of strings having a length of one to a fortran string and removes the C Null
! terminator. The Null terminator is returned from C when calling the C APIs directly.
!
! The fortran standard does not allow C_LOC to be used on a character string of
! length greater than one, which is why we use the array of characters instead.
!
! SOURCE
- SUBROUTINE HD5c2fstring(fstring,cstring,len)
+ SUBROUTINE HD5c2fstring(fstring,cstring,f_len,c_len)
!*****
IMPLICIT NONE
- INTEGER :: i
- INTEGER :: len
- CHARACTER(LEN=len) :: fstring
- CHARACTER(LEN=1), DIMENSION(1:len) :: cstring
+ INTEGER(SIZE_T) :: i
+ INTEGER(SIZE_T) :: f_len
+ INTEGER(SIZE_T) :: c_len
+ CHARACTER(*) :: fstring
+ CHARACTER(LEN=1), DIMENSION(1:c_len) :: cstring
+
+ INTEGER(SIZE_T) :: f_len_max
fstring = ''
- DO i = 1, len
+ f_len_max = LEN(fstring, KIND=SIZE_T)
+ DO i = 1, c_len
+ IF (i .GT. f_len_max) EXIT
+ IF (i .GT. f_len) EXIT
IF (cstring(i)(1:1)==CHAR(0)) EXIT
fstring(i:i) = cstring(i)(1:1)
END DO