csdms / babelizer

Transform BMI-wrapped models into Python packages
https://babelizer.readthedocs.io
MIT License
4 stars 3 forks source link

Implement BMI get_value_ptr method in C++ template #59

Open mdpiper opened 3 years ago

mdpiper commented 3 years ago

This is a request to implement the BMI get_value_ptr method in the C++ cookiecutter template.

mdpiper commented 3 years ago

Here's a possible way to do it:

cpdef get_value_ptr(self, name):
    cdef int gid = self.get_var_grid(name)
    cdef int size = self.get_grid_size(gid)
    cdef void* ptr
    ptr = self._bmi.GetValuePtr(<char*>name)
    return np.asarray(<np.float_t[:size]>ptr)

This is C-like, though; I'm not sure if there's a cleaner C++ way to do this.