Beispiel #1
0
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())
Beispiel #2
0
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)
Beispiel #3
0
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())
Beispiel #4
0
 def test_c_prototype_empty(self):
     return_arg = pyf.Argument(name="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)
     eq_(empty_func_wrapper.c_prototype(), (
         'void empty_func_c(fwi_integer_t *, fwi_integer_t *, fw_character_t *);'
     ))
     empty_subr = pyf.Subroutine(name='empty_subr', args=())
     empty_subr_wrapper = fc_wrap.SubroutineWrapper(wrapped=empty_subr)
     eq_(empty_subr_wrapper.c_prototype(),
         'void empty_subr_c(fwi_integer_t *, fw_character_t *);')
Beispiel #5
0
 def setup(self):
     int_arg_inout = pyf.Argument("int_arg_inout", pyf.default_integer,
                                  'inout')
     int_arg = pyf.Argument("int_arg", pyf.default_integer)
     int_array = pyf.Argument("int_array",
                              pyf.default_integer,
                              intent="out",
                              dimension=[':', ':'])
     return_arg = pyf.Argument(name="dstring_func",
                               dtype=pyf.default_integer)
     func = pyf.Function(name="dstring_func",
                         args=[int_arg_inout, int_arg, int_array],
                         return_arg=return_arg)
     fcw = fc_wrap.FunctionWrapper(wrapped=func)
     self.cyw = cy_wrap.ProcWrapper(wrapped=fcw)
Beispiel #6
0
    def setup(self):
        int_arg_in = pyf.Argument("int_arg_in", pyf.default_integer, 'in')
        int_arg_inout = pyf.Argument("int_arg_inout", pyf.default_integer,
                                     'inout')
        int_arg_out = pyf.Argument("int_arg_out", pyf.default_integer, 'out')
        real_arg = pyf.Argument("real_arg", pyf.default_real)
        all_args = [int_arg_in, int_arg_inout, int_arg_out, real_arg]

        return_arg = pyf.Argument(name="fort_func", dtype=pyf.default_integer)
        pyf_func = pyf.Function(name="fort_func",
                                args=all_args,
                                return_arg=return_arg)
        func_wrapper = fc_wrap.FunctionWrapper(wrapped=pyf_func)
        self.cy_func_wrapper = cy_wrap.ProcWrapper(wrapped=func_wrapper)

        pyf_subr = pyf.Subroutine(name="fort_subr", args=all_args)
        subr_wrapper = fc_wrap.SubroutineWrapper(wrapped=pyf_subr)
        self.cy_subr_wrapper = cy_wrap.ProcWrapper(wrapped=subr_wrapper)
Beispiel #7
0
 def test_c_prototype_args(self):
     args = [
         pyf.Argument(name='int_arg',
                      dtype=pyf.default_integer,
                      intent='in'),
         pyf.Argument(name='array',
                      dtype=pyf.default_real,
                      dimension=(':', ) * 3,
                      intent='out')
     ]
     return_arg = pyf.Argument(name="func", dtype=pyf.default_integer)
     func = pyf.Function(name='func', args=args, return_arg=return_arg)
     func_wrapper = fc_wrap.FunctionWrapper(wrapped=func)
     eq_(
         func_wrapper.c_prototype(), "void func_c"
         "(fwi_integer_t *, "
         "fwi_integer_t *, "
         "fwi_npy_intp_t *, "
         "fwi_npy_intp_t *, "
         "fwi_npy_intp_t *, "
         "fwr_real_t *, "
         "fwi_integer_t *, "
         "fw_character_t *);")