diff --git a/srcbmi/mf6bmi.f90 b/srcbmi/mf6bmi.f90 index 35c4ffda775..4f1ba11d200 100644 --- a/srcbmi/mf6bmi.f90 +++ b/srcbmi/mf6bmi.f90 @@ -46,9 +46,8 @@ function bmi_get_component_name(name) result(bmi_status) & ! -- dummy variables character(kind=c_char), intent(out) :: name(BMI_LENCOMPONENTNAME) integer(kind=c_int) :: bmi_status !< BMI status code - ! -- local variables - name = string_to_char_array('MODFLOW 6', 9) + name = string_to_char_array('MODFLOW 6') bmi_status = BMI_SUCCESS end function bmi_get_component_name @@ -612,7 +611,7 @@ function get_value_string(c_var_address, c_arr_ptr) result(bmi_status) & call mem_setptr(srcstr, var_name, mem_path) call get_mem_elem_size(var_name, mem_path, ilen) call c_f_pointer(c_arr_ptr, tgtstr, shape=[ilen + 1]) - tgtstr(1:len(srcstr) + 1) = string_to_char_array(srcstr, len(srcstr)) + tgtstr(1:len(srcstr) + 1) = string_to_char_array(trim(srcstr)) else if (rank == 1) then ! an array of strings @@ -634,7 +633,7 @@ function get_value_string(c_var_address, c_arr_ptr) result(bmi_status) & allocate (character(ilen) :: tempstr) do i = 1, isize tempstr = srccharstr1d(i) - tgtstr1d(1:ilen + 1, i) = string_to_char_array(tempstr, ilen) + tgtstr1d(1:ilen + 1, i) = string_to_char_array(trim(tempstr)) end do deallocate (tempstr) else @@ -1172,7 +1171,7 @@ function get_var_type(c_var_address, c_var_type) result(bmi_status) & call get_mem_type(var_name, mem_path, mem_type) c_var_type(1:len(trim(mem_type)) + 1) = & - string_to_char_array(trim(mem_type), len(trim(mem_type))) + string_to_char_array(trim(mem_type)) if (mem_type == 'UNKNOWN') then write (bmi_last_error, fmt_general_err) 'unknown memory type' diff --git a/srcbmi/mf6bmiGrid.f90 b/srcbmi/mf6bmiGrid.f90 index 4af4d122e28..8dc6a766bc2 100644 --- a/srcbmi/mf6bmiGrid.f90 +++ b/srcbmi/mf6bmiGrid.f90 @@ -81,7 +81,7 @@ function get_grid_type(grid_id, grid_type) result(bmi_status) & else return end if - grid_type = string_to_char_array(trim(grid_type_f), len_trim(grid_type_f)) + grid_type = string_to_char_array(trim(grid_type_f)) bmi_status = BMI_SUCCESS end function get_grid_type diff --git a/srcbmi/mf6bmiUtil.f90 b/srcbmi/mf6bmiUtil.f90 index b0ff1770aef..b6420ee613e 100644 --- a/srcbmi/mf6bmiUtil.f90 +++ b/srcbmi/mf6bmiUtil.f90 @@ -145,18 +145,12 @@ end function char_array_to_string !> @brief Convert Fortran string to C-style character string !< - pure function string_to_char_array(string, length) result(c_array) + pure function string_to_char_array(string) result(c_array) ! -- dummy variables - integer(c_int), intent(in) :: length !< Fortran string length - character(len=length), intent(in) :: string !< string to convert - character(kind=c_char, len=1) :: c_array(length + 1) !< C-style character string - ! -- local variables - integer(I4B) :: i + character(len=*), intent(in) :: string !< string to convert + character(kind=c_char, len=1) :: c_array(len(string) + 1) !< C-style character string - do i = 1, length - c_array(i) = string(i:i) - end do - c_array(length + 1) = C_NULL_CHAR + c_array = trim(string)//c_null_char end function string_to_char_array diff --git a/srcbmi/mf6xmi.F90 b/srcbmi/mf6xmi.F90 index 9c476236054..f1048715ce7 100644 --- a/srcbmi/mf6xmi.F90 +++ b/srcbmi/mf6xmi.F90 @@ -357,7 +357,7 @@ function xmi_get_version(mf_version) result(bmi_status) & else vstr = VERSIONNUMBER end if - mf_version = string_to_char_array(vstr, len_trim(vstr)) + mf_version = string_to_char_array(trim(vstr)) bmi_status = BMI_SUCCESS end function xmi_get_version @@ -412,7 +412,7 @@ function get_var_address(c_component_name, c_subcomponent_name, & ! convert to c string: c_var_address(1:len(trim(mem_address)) + 1) = & - string_to_char_array(trim(mem_address), len(trim(mem_address))) + string_to_char_array(trim(mem_address)) bmi_status = BMI_SUCCESS