@@ -8,6 +8,7 @@ module OS
88 use , intrinsic :: ISO_fortran_env
99
1010 use prec
11+ use C_interfacing
1112
1213 implicit none (type,external )
1314 private
@@ -18,16 +19,10 @@ module OS
1819 OS_setCWD, &
1920 OS_getCWD, &
2021 OS_getHostName, &
21- OS_getUserName, &
22+ OS_getUserName
2223#ifdef OLD_STYLE_C_TO_FORTRAN_STRING
23- free_C, &
24+ public :: free_C
2425#endif
25- #if (defined(__INTEL_COMPILER) && __INTEL_COMPILER_BUILD_DATE < 20240000) \
26- || (defined(__GFORTRAN__) && __GNUC__ < 15 ) \
27- || defined(__flang__)
28- f_c_string, &
29- #endif
30- c_f_string
3126
3227 interface
3328
@@ -100,11 +95,6 @@ end subroutine free_C
10095
10196 end interface
10297
103- interface c_f_string
104- module procedure c_f_string_scalar
105- module procedure c_f_string_array
106- end interface
107-
10898contains
10999
110100
@@ -214,76 +204,6 @@ function OS_getUserName()
214204end function OS_getUserName
215205
216206
217- !- -------------------------------------------------------------------------------------------------
218- ! > @brief Convert C string to Fortran string.
219- ! > @details: C string is a fixed-size fortran array referencing a NULL terminated c string.
220- ! Due to the NULL-termination, C string has one more element than the Fortran string.
221- !- -------------------------------------------------------------------------------------------------
222- pure function c_f_string_scalar (c_string ) result(f_string)
223-
224- character (kind= C_CHAR,len=* ), intent (in ) :: c_string
225- character (len= :), allocatable :: f_string
226-
227- integer (pI64) :: i
228-
229-
230- allocate (character (len= len (c_string,kind= pI64)):: f_string)
231- do i= 1_pI64 ,len (f_string,pI64)
232- if (c_string(i:i) /= C_NULL_CHAR) then
233- f_string(i:i)= c_string(i:i)
234- else
235- f_string = f_string(:i-1_pI64 )
236- exit
237- end if
238- end do
239-
240- end function c_f_string_scalar
241-
242- !- -------------------------------------------------------------------------------------------------
243- ! > @brief Convert C string pointer to Fortran string.
244- ! > @details: C string is an assumed-size fortran array referencing a NULL terminated c string.
245- !- -------------------------------------------------------------------------------------------------
246- pure function c_f_string_array (c_string ) result(f_string)
247-
248- character (kind= C_CHAR), intent (in ), dimension (* ) :: c_string
249- character (len= :), allocatable :: f_string
250-
251- integer :: n, i
252-
253-
254- n = 0
255- do
256- if (c_string(n+1 ) == C_NULL_CHAR) exit
257- n = n + 1
258- end do
259-
260- allocate (character (len= n) :: f_string)
261- do i = 1 , n
262- f_string(i:i) = c_string(i)
263- end do
264-
265- end function c_f_string_array
266-
267-
268- #if (defined(__INTEL_COMPILER) && __INTEL_COMPILER_BUILD_DATE < 20240000) \
269- || (defined(__GFORTRAN__) && __GNUC__ < 15 ) \
270- || defined(__flang__)
271- !- -------------------------------------------------------------------------------------------------
272- ! > @brief Fortran 2023 "f_c_string" (without optional argument).
273- ! > @details: C string is NULL terminated and, hence, longer by one than the Fortran string.
274- !- -------------------------------------------------------------------------------------------------
275- pure function f_c_string (f_string ) result(c_string)
276-
277- character (len=* ), intent (in ) :: f_string
278- character (kind= C_CHAR,len= len_trim (f_string,pI64)+ 1_pI64 ) :: c_string
279-
280-
281- c_string = trim (f_string)// C_NULL_CHAR
282-
283- end function f_c_string
284- #endif
285-
286-
287207!- -------------------------------------------------------------------------------------------------
288208! > @brief Check correctness of some OS functions.
289209!- -------------------------------------------------------------------------------------------------
@@ -310,4 +230,3 @@ end subroutine OS_selfTest
310230
311231
312232end module OS
313-
0 commit comments