当前位置: 首页>>代码示例>>Python>>正文


Python cwrap.CWrapper类代码示例

本文整理汇总了Python中cwrap.CWrapper的典型用法代码示例。如果您正苦于以下问题:Python CWrapper类的具体用法?Python CWrapper怎么用?Python CWrapper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了CWrapper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

    def __init__(self, ert, function_name, argument_types, argument_count):
        super(FunctionErtScript, self).__init__(ert)

        lib = ert_module.load(None)
        wrapper = CWrapper(lib)

        parsed_argument_types = []

        if ert is not None:
            self.__function = wrapper.prototype("c_void_p %s(c_void_p, stringlist)" % function_name)

        else:
            for arg in argument_types:
                if arg is bool:
                    parsed_argument_types.append("bool")
                elif arg is str:
                    parsed_argument_types.append("char*")
                elif arg is int:
                    parsed_argument_types.append("int")
                elif arg is float:
                    parsed_argument_types.append("float")
                else:
                    raise TypeError("Unknown type: %s" % arg)

            self.__function = wrapper.prototype("c_void_p %s(%s)" % (function_name, ", ".join(parsed_argument_types[:argument_count])))
开发者ID:agchitu,项目名称:ert,代码行数:25,代码来源:function_ert_script.py

示例2: test_method_type

    def test_method_type(self):
        wrapper =  CWrapper(test_lib)
        def stringObj(c_ptr):
            char_ptr = ctypes.c_char_p( c_ptr )
            python_string = char_ptr.value
            test_lib.free(c_ptr)
            return python_string

        wrapper.registerType("string_obj", stringObj)

        dateStamp  = wrapper.prototype("string_obj util_alloc_date_stamp_utc()")
        date_stamp = dateStamp()
        self.assertIsInstance(date_stamp, str)
开发者ID:agchitu,项目名称:ert,代码行数:13,代码来源:test_cwrap.py

示例3: isinstance

        assert isinstance(mini_step, LocalMinistep)
        assert isinstance(update_step, LocalUpdateStep)
        LocalConfig.cNamespace().attach_ministep(update_step, mini_step)
        

    def writeSummaryFile(self, filename):                                                                                                                          
        """                                                                                                                                                    
        Writes a summary of the local config object                                                                                                            
        The summary contains the Obsset with their respective                                                                                                  
        number of observations and the Datasets with the number of active indices                                                                              
        """                                                                                                                                                    
        assert isinstance(filename, str)                                                                                                                       
        LocalConfig.cNamespace().write_local_config_summary_file(self, filename)                    
        

cwrapper = CWrapper(ENKF_LIB)
cwrapper.registerObjectType("local_config", LocalConfig)

LocalConfig.cNamespace().free                            = cwrapper.prototype("void local_config_free( local_config )")
LocalConfig.cNamespace().clear                           = cwrapper.prototype("void local_config_clear( local_config )")
LocalConfig.cNamespace().get_updatestep                  = cwrapper.prototype("local_updatestep_ref local_config_get_updatestep( local_config )")
LocalConfig.cNamespace().get_ministep                    = cwrapper.prototype("local_ministep_ref local_config_get_ministep( local_config, char*)")
LocalConfig.cNamespace().create_ministep                 = cwrapper.prototype("void local_config_alloc_ministep( local_config, char*, analysis_module)")
LocalConfig.cNamespace().attach_ministep                 = cwrapper.prototype("void local_updatestep_add_ministep( local_updatestep, local_ministep)")
LocalConfig.cNamespace().get_obsdata                     = cwrapper.prototype("local_obsdata_ref local_config_get_obsdata( local_config, char*)")
LocalConfig.cNamespace().create_obsdata                  = cwrapper.prototype("void local_config_alloc_obsdata( local_config, char*)")
LocalConfig.cNamespace().copy_obsdata                    = cwrapper.prototype("local_obsdata_ref local_config_alloc_obsdata_copy( local_config, char*, char*)")
LocalConfig.cNamespace().has_obsdata                     = cwrapper.prototype("bool local_config_has_obsdata( local_config, char*)")
LocalConfig.cNamespace().get_dataset                     = cwrapper.prototype("local_dataset_ref local_config_get_dataset( local_config, char*)")
LocalConfig.cNamespace().create_dataset                  = cwrapper.prototype("void local_config_alloc_dataset( local_config, char*)")
LocalConfig.cNamespace().copy_dataset                    = cwrapper.prototype("local_dataset_ref local_config_alloc_dataset_copy( local_config, char*, char*)")
开发者ID:agchitu,项目名称:ert,代码行数:31,代码来源:local_config.py

示例4: load

        """ @rtype: str """
        return EnkfNode.cNamespace().get_name(self)

    def load(self, fs, node_id):
        if not self.tryLoad(fs, node_id):
            raise Exception("Could not load node: %s iens: %d report: %d" % (self.name(), node_id.iens, node_id.report_step))

    def save(self, fs, node_id):
        assert isinstance(fs, EnkfFs)
        assert isinstance(node_id, NodeId)
        
        return EnkfNode.cNamespace().store(self, fs, False, node_id)

    def free(self):
        EnkfNode.cNamespace().free(self)


cwrapper = CWrapper(ENKF_LIB)
cwrapper.registerObjectType("enkf_node", EnkfNode)

EnkfNode.cNamespace().free = cwrapper.prototype("void enkf_node_free(enkf_node)")
EnkfNode.cNamespace().alloc = cwrapper.prototype("void* enkf_node_alloc(enkf_config_node)")
EnkfNode.cNamespace().alloc_private = cwrapper.prototype("void* enkf_node_alloc_private_container(enkf_config_node)")
EnkfNode.cNamespace().get_name = cwrapper.prototype("char* enkf_node_get_key(enkf_node)")

EnkfNode.cNamespace().value_ptr = cwrapper.prototype("void* enkf_node_value_ptr(enkf_node)")

EnkfNode.cNamespace().try_load = cwrapper.prototype("bool enkf_node_try_load(enkf_node, enkf_fs, node_id)")
EnkfNode.cNamespace().get_impl_type = cwrapper.prototype("ert_impl_type_enum enkf_node_get_impl_type(enkf_node)")
EnkfNode.cNamespace().store = cwrapper.prototype("bool enkf_node_store(enkf_node, enkf_fs, bool, node_id)")
开发者ID:agchitu,项目名称:ert,代码行数:30,代码来源:enkf_node.py

示例5: Copyright

#  Copyright (C) 2012  Statoil ASA, Norway. 
#   
#  The file 'field_config.py' is part of ERT - Ensemble based Reservoir Tool. 
#   
#  ERT is free software: you can redistribute it and/or modify 
#  it under the terms of the GNU General Public License as published by 
#  the Free Software Foundation, either version 3 of the License, or 
#  (at your option) any later version. 
#   
#  ERT is distributed in the hope that it will be useful, but WITHOUT ANY 
#  WARRANTY; without even the implied warranty of MERCHANTABILITY or 
#  FITNESS FOR A PARTICULAR PURPOSE.   
#   
#  See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html> 
#  for more details.
from cwrap import BaseCClass, CWrapper
from ert.enkf import ENKF_LIB


class SummaryConfig(BaseCClass):
    def __init__(self):
        raise NotImplementedError("Class can not be instantiated directly!")


cwrapper = CWrapper(ENKF_LIB)
cwrapper.registerType("summary_config", SummaryConfig)
cwrapper.registerType("summary_config", SummaryConfig.createPythonObject)
cwrapper.registerType("summary_config", SummaryConfig.createCReference)

开发者ID:agchitu,项目名称:ert,代码行数:28,代码来源:summary_config.py

示例6: __eq__

    def __eq__(self, other):
        return WellConnection.cNamespace().equal(self, other)

    def __ne__(self, other):
        return not self == other

    def free(self):
        pass

    def isMultiSegmentWell(self):
        """ @rtype: bool """
        return WellConnection.cNamespace().is_msw(self)


CWrapper.registerObjectType("well_connection", WellConnection)
cwrapper = CWrapper(ECL_WELL_LIB)


WellConnection.cNamespace().i = cwrapper.prototype("int well_conn_get_i(well_connection)")
WellConnection.cNamespace().j = cwrapper.prototype("int well_conn_get_j(well_connection)")
WellConnection.cNamespace().k = cwrapper.prototype("int well_conn_get_k(well_connection)")
WellConnection.cNamespace().get_dir = cwrapper.prototype("well_connection_dir_enum well_conn_get_dir(well_connection)")

WellConnection.cNamespace().segment_id = cwrapper.prototype("int well_conn_get_segment_id(well_connection)")
WellConnection.cNamespace().is_open = cwrapper.prototype("bool well_conn_open(well_connection)")
WellConnection.cNamespace().is_msw = cwrapper.prototype("bool well_conn_MSW(well_connection)")
WellConnection.cNamespace().fracture_connection = cwrapper.prototype("bool well_conn_fracture_connection(well_connection)")
WellConnection.cNamespace().matrix_connection = cwrapper.prototype("bool well_conn_matrix_connection(well_connection)")
WellConnection.cNamespace().connection_factor = cwrapper.prototype("double well_conn_get_connection_factor(well_connection)")
开发者ID:agchitu,项目名称:ert,代码行数:29,代码来源:well_connection.py

示例7: keys

    def keys(self):
        """ @rtype: StringList """
        return SummaryKeySet.cNamespace().keys(self)

    def isReadOnly(self):
        """ @rtype: bool """
        return SummaryKeySet.cNamespace().is_read_only(self)


    def writeToFile(self, filename):
        assert isinstance(filename, str)
        SummaryKeySet.cNamespace().fwrite(self, filename)

    def free(self):
        SummaryKeySet.cNamespace().free(self)


cwrapper = CWrapper(ENKF_LIB)
cwrapper.registerObjectType("summary_key_set", SummaryKeySet)

SummaryKeySet.cNamespace().alloc  = cwrapper.prototype("c_void_p summary_key_set_alloc()")
SummaryKeySet.cNamespace().alloc_from_file  = cwrapper.prototype("c_void_p summary_key_set_alloc_from_file(char*, bool)")
SummaryKeySet.cNamespace().free  = cwrapper.prototype("void summary_key_set_free(summary_key_set)")
SummaryKeySet.cNamespace().size  = cwrapper.prototype("int summary_key_set_get_size(summary_key_set)")
SummaryKeySet.cNamespace().add_key  = cwrapper.prototype("bool summary_key_set_add_summary_key(summary_key_set, char*)")
SummaryKeySet.cNamespace().has_key  = cwrapper.prototype("bool summary_key_set_has_summary_key(summary_key_set, char*)")
SummaryKeySet.cNamespace().keys  = cwrapper.prototype("stringlist_obj summary_key_set_alloc_keys(summary_key_set)")
SummaryKeySet.cNamespace().is_read_only  = cwrapper.prototype("bool summary_key_set_is_read_only(summary_key_set)")
SummaryKeySet.cNamespace().fwrite  = cwrapper.prototype("void summary_key_set_fwrite(summary_key_set, char*)")
开发者ID:agchitu,项目名称:ert,代码行数:29,代码来源:summary_key_set.py

示例8: CWrapper

from os import path, symlink, remove

import ert
from cwrap import CWrapper
from ert.test import ExtendedTestCase, TestAreaContext,ErtTestContext
from ert.enkf import RunpathList, RunpathNode
from ert.util import BoolVector

test_lib  = ert.load("libenkf") # create a local namespace
cwrapper =  CWrapper(test_lib)

runpath_list_alloc = cwrapper.prototype("runpath_list_obj runpath_list_alloc(char*)")

class RunpathListTest(ExtendedTestCase):

    def test_runpath_list(self):
        runpath_list = runpath_list_alloc("")
        """ @type runpath_list: RunpathList """

        self.assertEqual(len(runpath_list), 0)

        test_runpath_nodes = [RunpathNode(0, 0, "runpath0", "basename0"), RunpathNode(1, 0, "runpath1", "basename0")]

        runpath_node = test_runpath_nodes[0]
        runpath_list.add(runpath_node.realization, runpath_node.iteration, runpath_node.runpath, runpath_node.basename)

        self.assertEqual(len(runpath_list), 1)
        self.assertEqual(runpath_list[0], test_runpath_nodes[0])

        runpath_node = test_runpath_nodes[1]
        runpath_list.add(runpath_node.realization, runpath_node.iteration, runpath_node.runpath, runpath_node.basename)
开发者ID:agchitu,项目名称:ert,代码行数:31,代码来源:test_runpath_list.py

示例9: convertDefinition

    @classmethod
    def convertDefinition(cls, definition):
        """ @rtype: IntegerHash """
        type_hash = IntegerHash()

        for key, value_type in definition.iteritems():
            if value_type == float:
                value_type = 1
            else:
                value_type = 0 #str
            type_hash[key] = value_type
        return type_hash



cwrapper = CWrapper(ENKF_LIB)
cwrapper.registerObjectType("custom_kw_config", CustomKWConfig)

CustomKWConfig.cNamespace().free = cwrapper.prototype("void custom_kw_config_free(custom_kw_config)")
CustomKWConfig.cNamespace().alloc_empty = cwrapper.prototype("void* custom_kw_config_alloc_empty(char*, char*, char*)")
CustomKWConfig.cNamespace().alloc_with_definition = cwrapper.prototype("void* custom_kw_config_alloc_with_definition(char*, integer_hash)")
CustomKWConfig.cNamespace().get_name = cwrapper.prototype("char* custom_kw_config_get_name(custom_kw_config)")
CustomKWConfig.cNamespace().get_result_file = cwrapper.prototype("char* custom_kw_config_get_result_file(custom_kw_config)")
CustomKWConfig.cNamespace().get_output_file = cwrapper.prototype("char* custom_kw_config_get_output_file(custom_kw_config)")
CustomKWConfig.cNamespace().parse_result_file = cwrapper.prototype("bool custom_kw_config_parse_result_file(custom_kw_config, char*, stringlist)")
CustomKWConfig.cNamespace().has_key = cwrapper.prototype("bool custom_kw_config_has_key(custom_kw_config, char*)")
CustomKWConfig.cNamespace().key_is_double = cwrapper.prototype("bool custom_kw_config_key_is_double(custom_kw_config, char*)")
CustomKWConfig.cNamespace().index_of_key = cwrapper.prototype("int custom_kw_config_index_of_key(custom_kw_config, char*)")
CustomKWConfig.cNamespace().size = cwrapper.prototype("int custom_kw_config_size(custom_kw_config)")
CustomKWConfig.cNamespace().keys = cwrapper.prototype("stringlist_obj custom_kw_config_get_keys(custom_kw_config)")
开发者ID:agchitu,项目名称:ert,代码行数:30,代码来源:custom_kw_config.py

示例10: GeoPolygon

#  See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html> 
#  for more details. 
"""
Create a polygon
"""
from cwrap import CClass, CWrapper, CWrapperNameSpace
from ert.geo import ERT_GEOMETRY_LIB


class GeoPolygon(CClass):
    def __init__(self, points):
        c_ptr = cfunc.alloc_new()
        self.init_cobj(c_ptr, cfunc.free)
        for (xc, yc) in points:
            self.add_point(xc, yc)


    def add_point( self, xc, yc ):
        cfunc.add_point(self, xc, yc)


#################################################################

cwrapper = CWrapper(ERT_GEOMETRY_LIB)
cwrapper.registerType("geo_polygon", GeoPolygon)

cfunc           = CWrapperNameSpace("geo_polygon")
cfunc.alloc_new = cwrapper.prototype("c_void_p geo_polygon_alloc( )")
cfunc.add_point = cwrapper.prototype("void     geo_polygon_add_point( geo_polygon , double , double )")
cfunc.free      = cwrapper.prototype("void     geo_polygon_free( geo_polygon )")
开发者ID:agchitu,项目名称:ert,代码行数:30,代码来源:geo_polygon.py

示例11: __exit__


    def __exit__(self, exc_type, exc_val, exc_tb):
        del self.__test_context
        return False


    def getErt(self):
        return self.__test_context.getErt()


    def getCwd(self):
        """
        Returns the current working directory of this context.
        @rtype: string
        """
        return self.__test_context.getCwd()




cwrapper = CWrapper(ENKF_LIB)
cwrapper.registerObjectType("ert_test", ErtTest)

ErtTest.cNamespace().alloc = cwrapper.prototype("c_void_p ert_test_context_alloc_python( char* , char*)")
ErtTest.cNamespace().set_store = cwrapper.prototype("c_void_p ert_test_context_set_store( ert_test , bool)")
ErtTest.cNamespace().free = cwrapper.prototype("void ert_test_context_free( ert_test )")
ErtTest.cNamespace().get_enkf_main = cwrapper.prototype("enkf_main_ref ert_test_context_get_main( ert_test )")
ErtTest.cNamespace().get_cwd = cwrapper.prototype("char* ert_test_context_get_cwd( ert_test )")

开发者ID:agchitu,项目名称:ert,代码行数:27,代码来源:ert_test_context.py

示例12: TypeError

        else:
            raise TypeError("Index should be integer type")


    def getLayer(self , k):
        """
        @rtype: FaultBlockLayer
        """
        return self[k]

    def free(self):
        self.cNamespace().free(self)


    def scanKeyword(self , fault_block_kw):
        ok = self.cNamespace().scan_keyword( self , fault_block_kw )
        if not ok:
            raise ValueError("The fault block keyword had wrong type/size")

    

cwrapper = CWrapper(ECL_LIB)
CWrapper.registerObjectType("fault_block_collection", FaultBlockCollection)


FaultBlockCollection.cNamespace().alloc      = cwrapper.prototype("c_void_p         fault_block_collection_alloc(ecl_grid )")
FaultBlockCollection.cNamespace().free       = cwrapper.prototype("void             fault_block_collection_free(fault_block_collection)")
FaultBlockCollection.cNamespace().num_layers = cwrapper.prototype("int              fault_block_collection_num_layers(fault_block_collection)")
FaultBlockCollection.cNamespace().get_layer  = cwrapper.prototype("fault_block_layer_ref  fault_block_collection_get_layer(fault_block_collection, int)")
FaultBlockCollection.cNamespace().scan_keyword  = cwrapper.prototype("bool          fault_block_collection_scan_kw(fault_block_collection, ecl_kw)")
开发者ID:agchitu,项目名称:ert,代码行数:30,代码来源:fault_block_collection.py

示例13: free

    def free(self):
        LocalObsdataNode.cNamespace().free(self)

    def tstepActive(self , tstep):
        return LocalObsdataNode.cNamespace().tstep_active( self , tstep)


    def getActiveList(self):
        return LocalObsdataNode.cNamespace().get_active_list( self )

    def allTimeStepActive(self):
        return LocalObsdataNode.cNamespace().all_timestep_active( self )

    def setAllTimeStepActive(self, flag):
        return LocalObsdataNode.cNamespace().set_all_timestep_active( self, flag )

cwrapper = CWrapper(ENKF_LIB)
cwrapper.registerObjectType("local_obsdata_node", LocalObsdataNode)

LocalObsdataNode.cNamespace().alloc            = cwrapper.prototype("c_void_p local_obsdata_node_alloc(char* , bool)")
LocalObsdataNode.cNamespace().free             = cwrapper.prototype("void local_obsdata_node_free(local_obsdata_node)")
LocalObsdataNode.cNamespace().get_key          = cwrapper.prototype("char* local_obsdata_node_get_key(local_obsdata_node)")
LocalObsdataNode.cNamespace().add_range        = cwrapper.prototype("void local_obsdata_node_add_range(local_obsdata_node, int, int)")
LocalObsdataNode.cNamespace().add_step         = cwrapper.prototype("void local_obsdata_node_add_tstep(local_obsdata_node, int)")
LocalObsdataNode.cNamespace().tstep_active     = cwrapper.prototype("bool local_obsdata_node_tstep_active(local_obsdata_node, int)")
LocalObsdataNode.cNamespace().get_active_list  = cwrapper.prototype("active_list_ref local_obsdata_node_get_active_list(local_obsdata_node)")
LocalObsdataNode.cNamespace().all_timestep_active  = cwrapper.prototype("bool local_obsdata_node_all_timestep_active(local_obsdata_node)")
LocalObsdataNode.cNamespace().set_all_timestep_active  = cwrapper.prototype("void local_obsdata_node_set_all_timestep_active(local_obsdata_node, bool)")


开发者ID:agchitu,项目名称:ert,代码行数:28,代码来源:local_obsdata_node.py

示例14: getNumReportStep

        return GenDataConfig.cNamespace().has_report_step(self, report_step)

    def getNumReportStep(self):
        """ @rtype: int """
        return GenDataConfig.cNamespace().get_num_report_step(self)

    def getReportStep(self, index):
        """ @rtype: int """
        return GenDataConfig.cNamespace().iget_report_step(self, index)

    def getReportSteps(self):
        """ @rtype: list of int """
        return [self.getReportStep(index) for index in range(self.getNumReportStep())]


cwrapper = CWrapper(ENKF_LIB)
cwrapper.registerObjectType("gen_data_config", GenDataConfig)


GenDataConfig.cNamespace().alloc = cwrapper.prototype("c_void_p gen_data_config_alloc_GEN_DATA_result( char* , gen_data_file_format_type)")
GenDataConfig.cNamespace().free  = cwrapper.prototype("void gen_data_config_free( gen_data_config )")
GenDataConfig.cNamespace().get_output_format = cwrapper.prototype("gen_data_file_format_type gen_data_config_get_output_format(gen_data_config)")
GenDataConfig.cNamespace().get_input_format = cwrapper.prototype("gen_data_file_format_type gen_data_config_get_input_format(gen_data_config)")
GenDataConfig.cNamespace().get_template_file = cwrapper.prototype("char* gen_data_config_get_template_file(gen_data_config)")
GenDataConfig.cNamespace().get_template_key = cwrapper.prototype("char* gen_data_config_get_template_key(gen_data_config)")
GenDataConfig.cNamespace().get_initial_size = cwrapper.prototype("int gen_data_config_get_initial_size(gen_data_config)")
GenDataConfig.cNamespace().has_report_step = cwrapper.prototype("bool gen_data_config_has_report_step(gen_data_config, int)")
GenDataConfig.cNamespace().get_data_size    = cwrapper.prototype("int gen_data_config_get_data_size__(gen_data_config , int)")
GenDataConfig.cNamespace().get_key          = cwrapper.prototype("char* gen_data_config_get_key(gen_data_config)")
GenDataConfig.cNamespace().get_active_mask  = cwrapper.prototype("bool_vector_ref gen_data_config_get_active_mask(gen_data_config)")
开发者ID:agchitu,项目名称:ert,代码行数:30,代码来源:gen_data_config.py

示例15: isinstance

        Will add a key -> value pair which can be used for search replace
        operations in the data file. Observe that the key will be
        surrounded by \'<\' and \'>\'.
        """
        doc_string = None
        if isinstance(value , str):
            EnKFState.cNamespace().add_subst_kw( self , key , value , doc_string )
        else:
            raise TypeError("The value argument must be a string")

    def getDataKW(self):
        """
        Will return the substitution map for this realisation.
        """
        return EnKFState.cNamespace().get_subst_list( self )


        

cwrapper = CWrapper(ENKF_LIB)
cwrapper.registerType("enkf_state", EnKFState)
cwrapper.registerType("enkf_state_obj", EnKFState.createPythonObject)
cwrapper.registerType("enkf_state_ref", EnKFState.createCReference)


EnKFState.cNamespace().free     = cwrapper.prototype("void enkf_state_free( enkf_state )")
EnKFState.cNamespace().has_key  = cwrapper.prototype("bool enkf_state_has_node( enkf_state , char* )")
EnKFState.cNamespace().get_node = cwrapper.prototype("enkf_node_ref enkf_state_get_node( enkf_state , char* )")
EnKFState.cNamespace().add_subst_kw = cwrapper.prototype("void enkf_state_add_subst_kw( enkf_state , char* , char* , char*)")
EnKFState.cNamespace().get_subst_list  = cwrapper.prototype("subst_list_ref enkf_state_get_subst_list( enkf_state )")
开发者ID:agchitu,项目名称:ert,代码行数:30,代码来源:enkf_state.py


注:本文中的cwrap.CWrapper类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。