Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Remove C interoperability code from sample implementation #4

Open
mdpiper opened this issue Sep 28, 2018 · 1 comment
Open

Remove C interoperability code from sample implementation #4

mdpiper opened this issue Sep 28, 2018 · 1 comment
Labels

Comments

@mdpiper
Copy link
Member

mdpiper commented Sep 28, 2018

The Fortran 2003 intrinsic module iso_c_binding is used in the sample implementation bmi_heat.f90 to flatten arrays. Although there's nothing wrong with this, I think it's unnecessary; the arrays can be flattened using pure Fortran pointers. I may be wrong about this, but it would be nice to remove this dependency since it adds an additional layer of complexity for a model developer trying to implement this BMI.

@mdpiper
Copy link
Member Author

mdpiper commented Oct 3, 2018

It's possible to do this in pure Fortran, but only with 2008 features.

In heat.f90, make the temperature arrays contiguous:

real, pointer, contiguous :: temperature(:,:)
real, pointer, contiguous :: temperature_tmp(:,:)

In the heat_get_ref procedure in bmi_heat.f90, use bounds remapping:

case ("plate_surface__temperature")
    ! src = c_loc (self%model%temperature(1,1))
    n_elements = self%model%n_y * self%model%n_x
    ! call c_f_pointer(src, dest, [n_elements])
    dest(1:n_elements) => self%model%temperature
    bmi_status = BMI_SUCCESS

I'll mark this as pending, since I've advertised our BMI as only needing 2003, not 2008. OTOH, it's quite clean, and it removes the iso_c_binding dependency.

cc @sc0tts, @mcflugen

@mdpiper mdpiper transferred this issue from csdms/bmi-fortran Aug 29, 2019
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant