FrontISTR  5.9.0
Large-scale structural analysis program with finit element method
hecmw_api_common.f90
Go to the documentation of this file.
1 !-------------------------------------------------------------------------------
2 ! Copyright (c) 2026 FrontISTR Commons
3 ! This software is released under the MIT License, see LICENSE.txt
4 !-------------------------------------------------------------------------------
5 
7  use iso_c_binding
8  implicit none
9 
10 contains
11 
12  ! hecmw_lib_fc.c の HECMW_strcpy_f2c と同等だがメモリ確保していることを前提
13  ! c_str は c_len の大きさで呼び出し側で確保済み
14  subroutine f_c_str_copy(f_str, c_str, c_len)
15  implicit none
16  character(len=*), intent(in) :: f_str
17  character(kind=c_char), intent(inout) :: c_str(*)
18  integer(c_int), value, intent(in) :: c_len
19  integer :: f_len, i
20 
21  f_len = len_trim(f_str)
22  if (f_len>=c_len) then
23  f_len = c_len-1
24  end if
25 
26  do i = 1, f_len
27  c_str(i) = f_str(i:i)
28  end do
29  c_str(f_len+1) = c_null_char
30  end subroutine
31 
32  ! hecmw_lib_fc.c の HECMW_strcpy_c2f と同等
33  ! f_str は f_len の大きさで呼び出し側で確保済み
34  subroutine c_f_str_copy(c_str, f_str, f_len)
35  implicit none
36  character(kind=c_char), intent(in) :: c_str(*)
37  character(len=*), intent(inout) :: f_str
38  integer(c_int), value, intent(in) :: f_len
39 
40  integer :: c_len, i
41 
42  c_len = 0
43  do while (c_str(c_len + 1) /= c_null_char)
44  c_len = c_len + 1
45  end do
46 
47  if (c_len > f_len) then
48  c_len = f_len
49  end if
50 
51  do i = 1, c_len
52  f_str(i:i) = c_str(i)
53  end do
54 
55  if (c_len < f_len) then
56  f_str(c_len + 1 : f_len) = ' '
57  end if
58  end subroutine c_f_str_copy
59 
60 end module
subroutine f_c_str_copy(f_str, c_str, c_len)
subroutine c_f_str_copy(c_str, f_str, f_len)