| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | module mod_string | ||
| 2 | |||
| 3 | use, intrinsic :: iso_c_binding, only: c_char, c_null_char | ||
| 4 | |||
| 5 | public :: string_c2f | ||
| 6 | public :: string_f2c | ||
| 7 | |||
| 8 | contains | ||
| 9 | |||
| 10 | ✗ | subroutine string_c2f(c_string, f_string) | |
| 11 | implicit none | ||
| 12 | character(kind=c_char), intent(in) :: c_string(:) | ||
| 13 | character(len=*), intent(out) :: f_string | ||
| 14 | |||
| 15 | integer :: size_c_string, len_c_string, len_f_string, i | ||
| 16 | |||
| 17 | ✗ | size_c_string = size(c_string) | |
| 18 | |||
| 19 | ✗ | i = 1 | |
| 20 | ✗ | do while (i <= size_c_string .and. c_string(i) /= c_null_char) | |
| 21 | ✗ | f_string(i:i) = c_string(i) | |
| 22 | ✗ | i = i + 1 | |
| 23 | end do | ||
| 24 | |||
| 25 | ! Fill the rest of f_string with spaces | ||
| 26 | ✗ | len_c_string = i | |
| 27 | ✗ | len_f_string = len(f_string) | |
| 28 | ✗ | if (len_c_string < len_f_string) then | |
| 29 | ✗ | f_string(len_c_string:len_f_string) = ' ' | |
| 30 | end if | ||
| 31 | |||
| 32 | ✗ | end subroutine string_c2f | |
| 33 | |||
| 34 | 6 | subroutine string_f2c(f_string, c_string) | |
| 35 | implicit none | ||
| 36 | character(len=*), intent(in) :: f_string | ||
| 37 | character(kind=c_char), intent(out) :: c_string(:) | ||
| 38 | |||
| 39 | integer :: start_idx, end_idx, i, j | ||
| 40 | |||
| 41 | ! MPI Info object requires stripping leading and trailing spaces | ||
| 42 | 6 | start_idx = 1 | |
| 43 | 6 | end_idx = len_trim(f_string) | |
| 44 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | do while (start_idx <= end_idx .and. f_string(start_idx:start_idx) == ' ') |
| 45 | ✗ | start_idx = start_idx + 1 | |
| 46 | end do | ||
| 47 | |||
| 48 | 6 | j = 1 | |
| 49 |
2/2✓ Branch 0 taken 46 times.
✓ Branch 1 taken 6 times.
|
52 | do i = start_idx, end_idx |
| 50 | 46 | c_string(j) = f_string(i:i) | |
| 51 | 52 | j = j + 1 | |
| 52 | end do | ||
| 53 | |||
| 54 | 6 | c_string(j) = c_null_char | |
| 55 | |||
| 56 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | end subroutine string_f2c |
| 57 | |||
| 58 | end module mod_string | ||
| 59 |