csdms / babelizer

Transform BMI-wrapped models into Python packages

Home Page:https://babelizer.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Implement BMI get_value_ptr method in C++ template

mdpiper opened this issue · comments

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

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.