From 11538831520b5de29708b18f2d21164fbb85718f Mon Sep 17 00:00:00 2001 From: wpbonelli Date: Fri, 9 Aug 2024 14:42:59 -0400 Subject: [PATCH] keep string_to_char_array around just to avoid character truncation warning... is there a better way around this? --- srcbmi/mf6bmi.f90 | 3 +-- srcbmi/mf6bmiUtil.f90 | 11 +++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/srcbmi/mf6bmi.f90 b/srcbmi/mf6bmi.f90 index 62a396ddf3d..eb64b13be5e 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 = 'MODFLOW 6'//c_null_char + name = string_to_char_array('MODFLOW 6') bmi_status = BMI_SUCCESS end function bmi_get_component_name diff --git a/srcbmi/mf6bmiUtil.f90 b/srcbmi/mf6bmiUtil.f90 index 0ec6a243c7a..b6420ee613e 100644 --- a/srcbmi/mf6bmiUtil.f90 +++ b/srcbmi/mf6bmiUtil.f90 @@ -143,6 +143,17 @@ pure function char_array_to_string(char_array, length) result(f_string) end function char_array_to_string + !> @brief Convert Fortran string to C-style character string + !< + pure function string_to_char_array(string) result(c_array) + ! -- dummy variables + character(len=*), intent(in) :: string !< string to convert + character(kind=c_char, len=1) :: c_array(len(string) + 1) !< C-style character string + + c_array = trim(string)//c_null_char + + end function string_to_char_array + !> @brief Extract the model name from a memory address string !< function extract_model_name(var_address, success) result(model_name)