def test_logical_wrapper(): args = [ pyf.Argument(name='lgcl', dtype=pyf.LogicalType(fw_ktp='lgcl_ktp'), intent="inout") ] lgcl_arg = pyf.Subroutine(name='lgcl_arg', args=args) lgcl_arg_wrapped = fc_wrap.SubroutineWrapper(wrapped=lgcl_arg) buf = CodeBuffer() lgcl_arg_wrapped.generate_wrapper(buf) fort_file = '''\ subroutine lgcl_arg_c(lgcl, fw_iserr__, fw_errstr__) bind(c, name="lgcl_arg_c") use fwrap_ktp_mod implicit none type(c_ptr), value :: lgcl integer(kind=fwi_integer_t), intent(out) :: fw_iserr__ character(kind=fw_character_t, len=1), dimension(fw_errstr_len) :: fw_errstr__ interface subroutine lgcl_arg(lgcl) use fwrap_ktp_mod implicit none logical(kind=fwl_lgcl_ktp_t), intent(inout) :: lgcl end subroutine lgcl_arg end interface logical(kind=fwl_lgcl_ktp_t), pointer :: fw_lgcl fw_iserr__ = FW_INIT_ERR__ call c_f_pointer(lgcl, fw_lgcl) call lgcl_arg(fw_lgcl) fw_iserr__ = FW_NO_ERR__ end subroutine lgcl_arg_c ''' compare(fort_file, buf.getvalue())
def test_logical_function(): return_arg = pyf.Argument('lgcl_fun', dtype=pyf.LogicalType(fw_ktp='lgcl')) lgcl_fun = pyf.Function(name='lgcl_fun', args=[], return_arg=return_arg) lgcl_fun_wrapped = fc_wrap.FunctionWrapper(wrapped=lgcl_fun) buf = CodeBuffer() lgcl_fun_wrapped.generate_wrapper(buf) fort_file = '''\ subroutine lgcl_fun_c(fw_ret_arg, fw_iserr__, fw_errstr__) bind(c, name="lgcl_fun_c") use fwrap_ktp_mod implicit none type(c_ptr), value :: fw_ret_arg integer(kind=fwi_integer_t), intent(out) :: fw_iserr__ character(kind=fw_character_t, len=1), dimension(fw_errstr_len) :: fw_errstr__ interface function lgcl_fun() use fwrap_ktp_mod implicit none logical(kind=fwl_lgcl_t) :: lgcl_fun end function lgcl_fun end interface logical(kind=fwl_lgcl_t), pointer :: fw_fw_ret_arg fw_iserr__ = FW_INIT_ERR__ call c_f_pointer(fw_ret_arg, fw_fw_ret_arg) fw_fw_ret_arg = lgcl_fun() fw_iserr__ = FW_NO_ERR__ end subroutine lgcl_fun_c ''' compare(fort_file, buf.getvalue())
def test_intent_hide(): hide_arg_subr = pyf.Subroutine('hide_subr', args=[ pyf.HiddenArgument( 'hide_arg', dtype=pyf.default_integer, intent='hide', value='10') ]) wppr = fc_wrap.SubroutineWrapper(wrapped=hide_arg_subr) buf = CodeBuffer() wppr.generate_wrapper(buf) check = '''\ subroutine hide_subr_c(fw_iserr__, fw_errstr__) bind(c, name="hide_subr_c") use fwrap_ktp_mod implicit none integer(kind=fwi_integer_t), intent(out) :: fw_iserr__ character(kind=fw_character_t, len=1), dimension(fw_errstr_len) :: fw_errstr__ interface subroutine hide_subr(hide_arg) use fwrap_ktp_mod implicit none integer(kind=fwi_integer_t) :: hide_arg end subroutine hide_subr end interface integer(kind=fwi_integer_t) :: hide_arg fw_iserr__ = FW_INIT_ERR__ hide_arg = (10) call hide_subr(hide_arg) fw_iserr__ = FW_NO_ERR__ end subroutine hide_subr_c ''' compare(check, buf.getvalue())
def test_generate_fc_h(): return_arg = pyf.Argument(name="two_arg", dtype=pyf.default_real) two_arg_func = pyf.Function(name='two_arg', args=[ pyf.Argument(name='a', dtype=pyf.default_integer, intent='in'), pyf.Argument(name='b', dtype=pyf.default_integer, intent='in'), pyf.Argument(name='c', dtype=pyf.default_integer, intent='in'), pyf.Argument(name='d', dtype=pyf.default_integer, intent='in'), ], return_arg=return_arg) ta_wrp = fc_wrap.FunctionWrapper(wrapped=two_arg_func) ast = [ta_wrp] buf = CodeBuffer() header_name = 'foobar' fc_wrap.generate_fc_h(ast, header_name, buf) code = '''\ #include "foobar" void two_arg_c(fwr_real_t *, fwi_integer_t *, fwi_integer_t *, fwi_integer_t *, fwi_integer_t *, fwi_integer_t *, fw_character_t *); ''' compare(buf.getvalue(), code)
def test_assumed_shape_int_array(): arr_arg = pyf.Subroutine(name='arr_arg', args=[ pyf.Argument(name='arr', dtype=pyf.default_integer, dimension=(':', ':'), intent="inout") ]) arr_arg_wrapped = fc_wrap.SubroutineWrapper(wrapped=arr_arg) buf = CodeBuffer() arr_arg_wrapped.generate_wrapper(buf) fort_file = '''\ subroutine arr_arg_c(arr_d1, arr_d2, arr, fw_iserr__, fw_errstr__) bind(c, name="arr_arg_c") use fwrap_ktp_mod implicit none integer(kind=fwi_npy_intp_t), intent(in) :: arr_d1 integer(kind=fwi_npy_intp_t), intent(in) :: arr_d2 integer(kind=fwi_integer_t), dimension(arr_d1, arr_d2), intent(inout) :: arr integer(kind=fwi_integer_t), intent(out) :: fw_iserr__ character(kind=fw_character_t, len=1), dimension(fw_errstr_len) :: fw_errstr__ interface subroutine arr_arg(arr) use fwrap_ktp_mod implicit none integer(kind=fwi_integer_t), dimension(:, :), intent(inout) :: arr end subroutine arr_arg end interface fw_iserr__ = FW_INIT_ERR__ call arr_arg(arr) fw_iserr__ = FW_NO_ERR__ end subroutine arr_arg_c ''' compare(fort_file, buf.getvalue())
def test_gen_empty_func_wrapper(): return_arg = pyf.Argument("empty_func", dtype=pyf.default_integer) empty_func = pyf.Function(name='empty_func', args=(), return_arg=return_arg) empty_func_wrapper = fc_wrap.FunctionWrapper(wrapped=empty_func) empty_func_wrapped = '''\ subroutine empty_func_c(fw_ret_arg, fw_iserr__, fw_errstr__) bind(c, name="empty_func_c") use fwrap_ktp_mod implicit none integer(kind=fwi_integer_t), intent(out) :: fw_ret_arg integer(kind=fwi_integer_t), intent(out) :: fw_iserr__ character(kind=fw_character_t, len=1), dimension(fw_errstr_len) :: fw_errstr__ interface function empty_func() use fwrap_ktp_mod implicit none integer(kind=fwi_integer_t) :: empty_func end function empty_func end interface fw_iserr__ = FW_INIT_ERR__ fw_ret_arg = empty_func() fw_iserr__ = FW_NO_ERR__ end subroutine empty_func_c ''' buf = CodeBuffer() empty_func_wrapper.generate_wrapper(buf) compare(empty_func_wrapped, buf.getvalue())
def test_logical_wrapper(): args=[pyf.Argument(name='lgcl', dtype=pyf.LogicalType(fw_ktp='lgcl_ktp'), intent="inout")] lgcl_arg = pyf.Subroutine(name='lgcl_arg', args=args) lgcl_arg_wrapped = fc_wrap.SubroutineWrapper(wrapped=lgcl_arg) buf = CodeBuffer() lgcl_arg_wrapped.generate_wrapper(buf) fort_file = '''\ subroutine lgcl_arg_c(lgcl, fw_iserr__, fw_errstr__) bind(c, name="lgcl_arg_c") use fwrap_ktp_mod implicit none type(c_ptr), value :: lgcl integer(kind=fwi_integer_t), intent(out) :: fw_iserr__ character(kind=fw_character_t, len=1), dimension(fw_errstr_len) :: fw_errstr__ interface subroutine lgcl_arg(lgcl) use fwrap_ktp_mod implicit none logical(kind=fwl_lgcl_ktp_t), intent(inout) :: lgcl end subroutine lgcl_arg end interface logical(kind=fwl_lgcl_ktp_t), pointer :: fw_lgcl fw_iserr__ = FW_INIT_ERR__ call c_f_pointer(lgcl, fw_lgcl) call lgcl_arg(fw_lgcl) fw_iserr__ = FW_NO_ERR__ end subroutine lgcl_arg_c ''' compare(fort_file, buf.getvalue())
def test_generate_fc_h(): return_arg = pyf.Argument(name="two_arg", dtype=pyf.default_real) two_arg_func = pyf.Function( name='two_arg', args=[pyf.Argument(name='a',dtype=pyf.default_integer, intent='in'), pyf.Argument(name='b', dtype=pyf.default_integer, intent='in'), pyf.Argument(name='c', dtype=pyf.default_integer, intent='in'), pyf.Argument(name='d', dtype=pyf.default_integer, intent='in'), ], return_arg=return_arg) ta_wrp = fc_wrap.FunctionWrapper(wrapped=two_arg_func) ast = [ta_wrp] buf = CodeBuffer() header_name = 'foobar' fc_wrap.generate_fc_h(ast, header_name, buf) code = '''\ #include "foobar" void two_arg_c(fwr_real_t *, fwi_integer_t *, fwi_integer_t *, fwi_integer_t *, fwi_integer_t *, fwi_integer_t *, fw_character_t *); ''' compare(buf.getvalue(), code)
def test_assumed_shape_int_array(): arr_arg = pyf.Subroutine(name='arr_arg', args=[pyf.Argument(name='arr', dtype=pyf.default_integer, dimension=(':',':'), intent="inout")]) arr_arg_wrapped = fc_wrap.SubroutineWrapper(wrapped=arr_arg) buf = CodeBuffer() arr_arg_wrapped.generate_wrapper(buf) fort_file = '''\ subroutine arr_arg_c(arr_d1, arr_d2, arr, fw_iserr__, fw_errstr__) bind(c, name="arr_arg_c") use fwrap_ktp_mod implicit none integer(kind=fwi_npy_intp_t), intent(in) :: arr_d1 integer(kind=fwi_npy_intp_t), intent(in) :: arr_d2 integer(kind=fwi_integer_t), dimension(arr_d1, arr_d2), intent(inout) :: arr integer(kind=fwi_integer_t), intent(out) :: fw_iserr__ character(kind=fw_character_t, len=1), dimension(fw_errstr_len) :: fw_errstr__ interface subroutine arr_arg(arr) use fwrap_ktp_mod implicit none integer(kind=fwi_integer_t), dimension(:, :), intent(inout) :: arr end subroutine arr_arg end interface fw_iserr__ = FW_INIT_ERR__ call arr_arg(arr) fw_iserr__ = FW_NO_ERR__ end subroutine arr_arg_c ''' compare(fort_file, buf.getvalue())
def test_gen_fortran_one_arg_func(): one_arg = pyf.Subroutine( name='one_arg', args=[pyf.Argument(name='a', dtype=pyf.default_integer, intent="in")]) one_arg_wrapped = fc_wrap.SubroutineWrapper(wrapped=one_arg) buf = CodeBuffer() one_arg_wrapped.generate_wrapper(buf) fort_file = '''\ subroutine one_arg_c(a, fw_iserr__, fw_errstr__) bind(c, name="one_arg_c") use fwrap_ktp_mod implicit none integer(kind=fwi_integer_t), intent(in) :: a integer(kind=fwi_integer_t), intent(out) :: fw_iserr__ character(kind=fw_character_t, len=1), dimension(fw_errstr_len) :: fw_errstr__ interface subroutine one_arg(a) use fwrap_ktp_mod implicit none integer(kind=fwi_integer_t), intent(in) :: a end subroutine one_arg end interface fw_iserr__ = FW_INIT_ERR__ call one_arg(a) fw_iserr__ = FW_NO_ERR__ end subroutine one_arg_c ''' compare(fort_file, buf.getvalue())
def test_generate_fc_f(self): fort_ast = fwrapper.parse(self.source_file_lst) c_ast = fc_wrap.wrap_pyf_iface(fort_ast) fname, buf = fwrapper.generate_fc_f(c_ast, self.name) fc = '''\ subroutine empty_func_c(fw_ret_arg, fw_iserr__, fw_errstr__) bind(c, name="em& &pty_func_c") use fwrap_ktp_mod implicit none integer(kind=fwi_integer_t), intent(out) :: fw_ret_arg integer(kind=fwi_integer_t), intent(out) :: fw_iserr__ character(kind=fw_character_t, len=1), dimension(fw_errstr_len) :: fw_err& &str__ interface function empty_func() use fwrap_ktp_mod implicit none integer(kind=fwi_integer_t) :: empty_func end function empty_func end interface fw_iserr__ = FW_INIT_ERR__ fw_ret_arg = empty_func() fw_iserr__ = FW_NO_ERR__ end subroutine empty_func_c ''' compare(fc, buf.getvalue())
def test_func_generate_wrapper(self): buf = CodeBuffer() self.cy_func_wrapper.generate_wrapper(buf) cy_wrapper = '''\ cpdef api object fort_func(fwi_integer_t int_arg_in, fwi_integer_t int_arg_inout, fwr_real_t real_arg): """ fort_func(int_arg_in, int_arg_inout, real_arg) -> (fw_ret_arg, int_arg_inout, int_arg_out, real_arg) Parameters ---------- int_arg_in : fwi_integer, intent in int_arg_inout : fwi_integer, intent inout real_arg : fwr_real Returns ------- fw_ret_arg : fwi_integer, intent out int_arg_inout : fwi_integer, intent inout int_arg_out : fwi_integer, intent out real_arg : fwr_real """ cdef fwi_integer_t fw_ret_arg cdef fwi_integer_t int_arg_out cdef fwi_integer_t fw_iserr__ cdef fw_character_t fw_errstr__[fw_errstr_len] fort_func_c(&fw_ret_arg, &int_arg_in, &int_arg_inout, &int_arg_out, &real_arg, &fw_iserr__, fw_errstr__) if fw_iserr__ != FW_NO_ERR__: raise RuntimeError("an error was encountered when calling the 'fort_func' wrapper.") return (fw_ret_arg, int_arg_inout, int_arg_out, real_arg,) ''' compare(cy_wrapper, buf.getvalue())
def test_subr_declarations(self): buf = CodeBuffer() self.cy_subr_wrapper.temp_declarations(buf) compare( buf.getvalue(), 'cdef fwi_integer_t int_arg_out\n' 'cdef fwi_integer_t fw_iserr__\n' 'cdef fw_character_t fw_errstr__[fw_errstr_len]')
def test_generate_fc_f(self): fort_ast = main.parse(self.source_file_lst) c_ast = fc_wrap.wrap_pyf_iface(fort_ast) fname, buf = main.generate_fc_f(c_ast, self.name) fc = '''\ subroutine empty_func_c(fw_ret_arg, fw_iserr__, fw_errstr__) bind(c, name="em& &pty_func_c") use fwrap_ktp_mod implicit none integer(kind=fwi_integer_t), intent(out) :: fw_ret_arg integer(kind=fwi_integer_t), intent(out) :: fw_iserr__ character(kind=fw_character_t, len=1), dimension(fw_errstr_len) :: fw_err& &str__ interface function empty_func() use fwrap_ktp_mod implicit none integer(kind=fwi_integer_t) :: empty_func end function empty_func end interface fw_iserr__ = FW_INIT_ERR__ fw_ret_arg = empty_func() fw_iserr__ = FW_NO_ERR__ end subroutine empty_func_c ''' compare(fc, buf.getvalue())
def test_intent_hide(): hide_arg_subr = pyf.Subroutine('hide_subr', args=[pyf.HiddenArgument('hide_arg', dtype=pyf.default_integer, intent='hide', value='10')]) wppr = fc_wrap.SubroutineWrapper(wrapped=hide_arg_subr) buf = CodeBuffer() wppr.generate_wrapper(buf) check = '''\ subroutine hide_subr_c(fw_iserr__, fw_errstr__) bind(c, name="hide_subr_c") use fwrap_ktp_mod implicit none integer(kind=fwi_integer_t), intent(out) :: fw_iserr__ character(kind=fw_character_t, len=1), dimension(fw_errstr_len) :: fw_errstr__ interface subroutine hide_subr(hide_arg) use fwrap_ktp_mod implicit none integer(kind=fwi_integer_t) :: hide_arg end subroutine hide_subr end interface integer(kind=fwi_integer_t) :: hide_arg fw_iserr__ = FW_INIT_ERR__ hide_arg = (10) call hide_subr(hide_arg) fw_iserr__ = FW_NO_ERR__ end subroutine hide_subr_c ''' compare(check, buf.getvalue())
def test_func_declarations(self): buf = CodeBuffer() self.cy_func_wrapper.temp_declarations(buf) decls = '''\ cdef fwi_integer_t fw_ret_arg cdef fwi_integer_t int_arg_out cdef fwi_integer_t fw_iserr__ cdef fw_character_t fw_errstr__[fw_errstr_len] ''' compare(buf.getvalue(), decls)
def test_generate_fc_pxd(self): fort_ast = fwrapper.parse(self.source_file_lst) c_ast = fc_wrap.wrap_pyf_iface(fort_ast) fname, buf = fwrapper.generate_fc_pxd(c_ast, self.name) header = '''\ from fwrap_ktp cimport * cdef extern from "test_fc.h": void empty_func_c(fwi_integer_t *, fwi_integer_t *, fw_character_t *) ''' compare(header, buf.getvalue())
def test_generate_fc_h(self): fort_ast = fwrapper.parse(self.source_file_lst) c_ast = fc_wrap.wrap_pyf_iface(fort_ast) fname, buf = fwrapper.generate_fc_h(c_ast, self.name) header = '''\ #include "fwrap_ktp_header.h" void empty_func_c(fwi_integer_t *, fwi_integer_t *, fw_character_t *); ''' compare(buf.getvalue(), header) eq_(fname, constants.FC_HDR_TMPL % self.name)
def test_generate_fc_h(self): fort_ast = main.parse(self.source_file_lst) c_ast = fc_wrap.wrap_pyf_iface(fort_ast) fname, buf = main.generate_fc_h(c_ast, self.name) header = '''\ #include "fwrap_ktp_header.h" void empty_func_c(fwi_integer_t *, fwi_integer_t *, fw_character_t *); ''' compare(buf.getvalue(), header) eq_(fname, constants.FC_HDR_TMPL % self.name)
def test_generate_fc_pxd(self): fort_ast = main.parse(self.source_file_lst) c_ast = fc_wrap.wrap_pyf_iface(fort_ast) fname, buf = main.generate_fc_pxd(c_ast, self.name) header = '''\ from fwrap_ktp cimport * cdef extern from "test_fc.h": void empty_func_c(fwi_integer_t *, fwi_integer_t *, fw_character_t *) ''' compare(header, buf.getvalue())
def test_generate_cy_pxd(self): fort_ast = fwrapper.parse(self.source_file_lst) c_ast = fc_wrap.wrap_pyf_iface(fort_ast) cython_ast = cy_wrap.wrap_fc(c_ast) fname, buf = fwrapper.generate_cy_pxd(cython_ast, self.name) pxd = '''\ cimport numpy as np from test_fc cimport * cpdef api object empty_func() ''' compare(pxd, buf.getvalue())
def test_generate_cy_pxd(self): fort_ast = main.parse(self.source_file_lst) c_ast = fc_wrap.wrap_pyf_iface(fort_ast) cython_ast = cy_wrap.wrap_fc(c_ast) fname, buf = main.generate_cy_pxd(cython_ast, self.name) pxd = '''\ cimport numpy as np from test_fc cimport * cpdef api object empty_func() ''' compare(pxd, buf.getvalue())
def test_empty_subr_dstring(self): subr = pyf.Subroutine("empty", args=()) fs = fc_wrap.SubroutineWrapper(subr) cs = cy_wrap.ProcWrapper(fs) eq_(cs.dstring_signature(), ["empty()"]) dstring = '''\ empty() Parameters ---------- None ''' compare("\n".join(cs.docstring()), dstring)
def test_generate_cy_pyx(self): from fwrap.version import get_version fort_ast = fwrapper.parse(self.source_file_lst) c_ast = fc_wrap.wrap_pyf_iface(fort_ast) cython_ast = cy_wrap.wrap_fc(c_ast) fname, buf = fwrapper.generate_cy_pyx(cython_ast, self.name) test_str = '''\ """ The test module was generated with Fwrap v%s. Below is a listing of functions and data types. For usage information see the function docstrings. Functions --------- empty_func(...) Data Types ---------- fw_character fwi_integer """ np.import_array() include 'fwrap_ktp.pxi' cdef extern from "string.h": void *memcpy(void *dest, void *src, size_t n) cpdef api object empty_func(): """ empty_func() -> fw_ret_arg Parameters ---------- None Returns ------- fw_ret_arg : fwi_integer, intent out """ cdef fwi_integer_t fw_ret_arg cdef fwi_integer_t fw_iserr__ cdef fw_character_t fw_errstr__[fw_errstr_len] empty_func_c(&fw_ret_arg, &fw_iserr__, fw_errstr__) if fw_iserr__ != FW_NO_ERR__: raise RuntimeError("an error was encountered when calling the 'empty_func' wrapper.") return fw_ret_arg ''' % get_version() compare(test_str, buf.getvalue())
def test_generate_cy_pyx(self): from fwrap.version import get_version fort_ast = main.parse(self.source_file_lst) c_ast = fc_wrap.wrap_pyf_iface(fort_ast) cython_ast = cy_wrap.wrap_fc(c_ast) fname, buf = main.generate_cy_pyx(cython_ast, self.name) test_str = '''\ """ The test module was generated with Fwrap v%s. Below is a listing of functions and data types. For usage information see the function docstrings. Functions --------- empty_func(...) Data Types ---------- fw_character fwi_integer """ np.import_array() include 'fwrap_ktp.pxi' cdef extern from "string.h": void *memcpy(void *dest, void *src, size_t n) cpdef api object empty_func(): """ empty_func() -> fw_ret_arg Parameters ---------- None Returns ------- fw_ret_arg : fwi_integer, intent out """ cdef fwi_integer_t fw_ret_arg cdef fwi_integer_t fw_iserr__ cdef fw_character_t fw_errstr__[fw_errstr_len] empty_func_c(&fw_ret_arg, &fw_iserr__, fw_errstr__) if fw_iserr__ != FW_NO_ERR__: raise RuntimeError("an error was encountered when calling the 'empty_func' wrapper.") return fw_ret_arg ''' % get_version() compare(test_str, buf.getvalue())
def test_explicit_shape_int_array(): args=[pyf.Argument(name='arr', dtype=pyf.default_integer, dimension=('d1', 'd2'), intent="inout"), pyf.Argument(name='d1', dtype=pyf.default_integer, intent='in'), pyf.Argument(name='d2', dtype=pyf.default_integer, intent='in') ] arr_arg = pyf.Subroutine(name='arr_arg', args=args) arr_arg_wrapped = fc_wrap.SubroutineWrapper(wrapped=arr_arg) buf = CodeBuffer() arr_arg_wrapped.generate_wrapper(buf) fort_file = '''\ subroutine arr_arg_c(arr_d1, arr_d2, arr, d1, d2, fw_iserr__, fw_errstr__) bind(c, name="arr_arg_c") use fwrap_ktp_mod implicit none integer(kind=fwi_npy_intp_t), intent(in) :: arr_d1 integer(kind=fwi_npy_intp_t), intent(in) :: arr_d2 integer(kind=fwi_integer_t), dimension(arr_d1, arr_d2), intent(inout) :: arr integer(kind=fwi_integer_t), intent(in) :: d1 integer(kind=fwi_integer_t), intent(in) :: d2 integer(kind=fwi_integer_t), intent(out) :: fw_iserr__ character(kind=fw_character_t, len=1), dimension(fw_errstr_len) :: fw_errstr__ interface subroutine arr_arg(arr, d1, d2) use fwrap_ktp_mod implicit none integer(kind=fwi_integer_t), intent(in) :: d1 integer(kind=fwi_integer_t), intent(in) :: d2 integer(kind=fwi_integer_t), dimension(d1, d2), intent(inout) :: arr end subroutine arr_arg end interface fw_iserr__ = FW_INIT_ERR__ if ((d1) .ne. (arr_d1) .or. (d2) .ne. (arr_d2)) then fw_iserr__ = FW_ARR_DIM__ fw_errstr__ = transfer("arr ", fw_errstr__) fw_errstr__(fw_errstr_len) = C_NULL_CHAR return endif call arr_arg(arr, d1, d2) fw_iserr__ = FW_NO_ERR__ end subroutine arr_arg_c ''' compare(fort_file, buf.getvalue())
def test_many_arrays(): args=[pyf.Argument('assumed_size', pyf.default_integer, "inout", dimension=('d1','*')), pyf.Argument('d1', pyf.default_integer, 'in'), pyf.Argument('assumed_shape', pyf.default_logical, 'out', dimension=(':', ':')), pyf.Argument('explicit_shape', pyf.default_complex, 'inout', ('c1', 'c2')), pyf.Argument('c1', pyf.default_integer, 'inout'), pyf.Argument('c2', pyf.default_integer) ] arr_args = pyf.Subroutine(name='arr_args', args=args) arr_args_wrapped = fc_wrap.SubroutineWrapper(wrapped=arr_args) buf = CodeBuffer() arr_args_wrapped.generate_wrapper(buf) compare(many_arrays_text, buf.getvalue())
def test_explicit_shape_int_array(): args = [ pyf.Argument(name='arr', dtype=pyf.default_integer, dimension=('d1', 'd2'), intent="inout"), pyf.Argument(name='d1', dtype=pyf.default_integer, intent='in'), pyf.Argument(name='d2', dtype=pyf.default_integer, intent='in') ] arr_arg = pyf.Subroutine(name='arr_arg', args=args) arr_arg_wrapped = fc_wrap.SubroutineWrapper(wrapped=arr_arg) buf = CodeBuffer() arr_arg_wrapped.generate_wrapper(buf) fort_file = '''\ subroutine arr_arg_c(arr_d1, arr_d2, arr, d1, d2, fw_iserr__, fw_errstr__) bind(c, name="arr_arg_c") use fwrap_ktp_mod implicit none integer(kind=fwi_npy_intp_t), intent(in) :: arr_d1 integer(kind=fwi_npy_intp_t), intent(in) :: arr_d2 integer(kind=fwi_integer_t), dimension(arr_d1, arr_d2), intent(inout) :: arr integer(kind=fwi_integer_t), intent(in) :: d1 integer(kind=fwi_integer_t), intent(in) :: d2 integer(kind=fwi_integer_t), intent(out) :: fw_iserr__ character(kind=fw_character_t, len=1), dimension(fw_errstr_len) :: fw_errstr__ interface subroutine arr_arg(arr, d1, d2) use fwrap_ktp_mod implicit none integer(kind=fwi_integer_t), intent(in) :: d1 integer(kind=fwi_integer_t), intent(in) :: d2 integer(kind=fwi_integer_t), dimension(d1, d2), intent(inout) :: arr end subroutine arr_arg end interface fw_iserr__ = FW_INIT_ERR__ if ((d1) .ne. (arr_d1) .or. (d2) .ne. (arr_d2)) then fw_iserr__ = FW_ARR_DIM__ fw_errstr__ = transfer("arr ", fw_errstr__) fw_errstr__(fw_errstr_len) = C_NULL_CHAR return endif call arr_arg(arr, d1, d2) fw_iserr__ = FW_NO_ERR__ end subroutine arr_arg_c ''' compare(fort_file, buf.getvalue())
def test_func_dstring(self): dstring = """\ dstring_func(int_arg_inout, int_arg, int_array) -> (fw_ret_arg, int_arg_inout, int_arg, int_array) Parameters ---------- int_arg_inout : fwi_integer, intent inout int_arg : fwi_integer int_array : fwi_integer, 2D array, dimension(:, :), intent out Returns ------- fw_ret_arg : fwi_integer, intent out int_arg_inout : fwi_integer, intent inout int_arg : fwi_integer int_array : fwi_integer, 2D array, dimension(:, :), intent out """ compare('\n'.join(self.cyw.docstring()), dstring)
def test_many_arrays(): args = [ pyf.Argument('assumed_size', pyf.default_integer, "inout", dimension=('d1', '*')), pyf.Argument('d1', pyf.default_integer, 'in'), pyf.Argument('assumed_shape', pyf.default_logical, 'out', dimension=(':', ':')), pyf.Argument('explicit_shape', pyf.default_complex, 'inout', ('c1', 'c2')), pyf.Argument('c1', pyf.default_integer, 'inout'), pyf.Argument('c2', pyf.default_integer) ] arr_args = pyf.Subroutine(name='arr_args', args=args) arr_args_wrapped = fc_wrap.SubroutineWrapper(wrapped=arr_args) buf = CodeBuffer() arr_args_wrapped.generate_wrapper(buf) compare(many_arrays_text, buf.getvalue())
def test_declaration_order(): args=[ pyf.Argument('explicit_shape', pyf.default_complex, 'out', dimension=('d1', 'd2')), pyf.Argument('d2', pyf.default_integer, 'in'), pyf.Argument('d1', pyf.default_integer, 'in'), ] arr_arg = pyf.Subroutine(name='arr_arg', args=args) iface = '''\ interface subroutine arr_arg(explicit_shape, d2, d1) use fwrap_ktp_mod implicit none integer(kind=fwi_integer_t), intent(in) :: d2 integer(kind=fwi_integer_t), intent(in) :: d1 complex(kind=fwc_complex_t), dimension(d1, d2), intent(out) :: explicit_shape end subroutine arr_arg end interface ''' buf = CodeBuffer() fc_wrap.generate_interface(arr_arg, buf) compare(iface, buf.getvalue())
def test_declaration_order(): args = [ pyf.Argument('explicit_shape', pyf.default_complex, 'out', dimension=('d1', 'd2')), pyf.Argument('d2', pyf.default_integer, 'in'), pyf.Argument('d1', pyf.default_integer, 'in'), ] arr_arg = pyf.Subroutine(name='arr_arg', args=args) iface = '''\ interface subroutine arr_arg(explicit_shape, d2, d1) use fwrap_ktp_mod implicit none integer(kind=fwi_integer_t), intent(in) :: d2 integer(kind=fwi_integer_t), intent(in) :: d1 complex(kind=fwc_complex_t), dimension(d1, d2), intent(out) :: explicit_shape end subroutine arr_arg end interface ''' buf = CodeBuffer() fc_wrap.generate_interface(arr_arg, buf) compare(iface, buf.getvalue())
def gen_iface_gen(ast, istr): buf = CodeBuffer() #ast.generate_interface(buf) fc_wrap.generate_interface(ast, buf) compare(istr, buf.getvalue())
def test_subr_declarations(self): buf = CodeBuffer() self.cy_subr_wrapper.temp_declarations(buf) compare(buf.getvalue(), 'cdef fwi_integer_t int_arg_out\n' 'cdef fwi_integer_t fw_iserr__\n' 'cdef fw_character_t fw_errstr__[fw_errstr_len]')