You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This issue (and I'm not convinced it is an issue) arises from a specific case, but the fix may still be general.
In the bmi_initialize method in bmi_interoperability.f90, the input config file path has an exact length; e.g., "gipl.cfg" has n=8 characters. When this string is passed to the underlying Fortran model (GIPL), it's input as a character*164 instead of a character (len=*). The problem is, when going from C to Fortran through the interoperability layer, the remaining 164-8=156 characters are filled out with garbage. I think this is unfortunate coding in GIPL, but I don't have the right to change it.
Instead, if we pad the config file name in bmi_initialize with spaces to BMI_MAX_VAR_NAME, when converting from C to Fortran, the string is truncated. It's still 164 characters in GIPL, but instead of garbage, there are spaces, which the model accepts.
Here's my change:
integer (c_int), intent(in), value :: n
character (len=1, kind=c_char), intent(in) :: config_file(n)
integer (c_int) :: i, status
- character (len=n, kind=c_char) :: config_file_
+ character (len=BMI_MAX_VAR_NAME, kind=c_char) :: config_file_
! Convert `config_file` from rank-1 array to scalar.
do i = 1, n
config_file_(i:i) = config_file(i)
enddo
+ ! Pad with spaces to max size.
+ do i = n+1, BMI_MAX_VAR_NAME
+ config_file_(i:i) = ' '
+ enddo
+
status = model_array(model_index)%initialize(config_file_)
I'm not sure this is a general solution, but I wanted to record it in case it's needed later.
The text was updated successfully, but these errors were encountered:
By adding spaces to the config file name in the *bmi_initialize*
in the interoperability layer, the file name is read correctly
in GIPL, without junk appended.
Background on this commit is described in https://github.com/csdms/cookiecutter-bmi-wrap/issues/17.
mdpiper
transferred this issue from csdms/cookiecutter-bmi-wrap
Jul 30, 2020
This issue (and I'm not convinced it is an issue) arises from a specific case, but the fix may still be general.
In the bmi_initialize method in bmi_interoperability.f90, the input config file path has an exact length; e.g., "gipl.cfg" has n=8 characters. When this string is passed to the underlying Fortran model (GIPL), it's input as a
character*164
instead of acharacter (len=*)
. The problem is, when going from C to Fortran through the interoperability layer, the remaining 164-8=156 characters are filled out with garbage. I think this is unfortunate coding in GIPL, but I don't have the right to change it.Instead, if we pad the config file name in bmi_initialize with spaces to BMI_MAX_VAR_NAME, when converting from C to Fortran, the string is truncated. It's still 164 characters in GIPL, but instead of garbage, there are spaces, which the model accepts.
Here's my change:
I'm not sure this is a general solution, but I wanted to record it in case it's needed later.
The text was updated successfully, but these errors were encountered: