Index: /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh/TriMesh.cpp.bak =================================================================== --- /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh/TriMesh.cpp.bak (revision 0) +++ /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh/TriMesh.cpp.bak (revision 11850) @@ -0,0 +1,53 @@ +#include +using namespace std; + +void meshx(double* index,int n) { + int i; + for(i=0;i +#include +#include +using namespace boost::python; + +void FetchData(double** array,int* N,boost::python::list pythonlist){/*{{{*/ + + /*Get list size*/ + int n = boost::python::extract(pythonlist.attr("__len__")()); + + /*Assign double array and populate*/ + double* clist = new double[n]; + for (int i=0;i(pythonlist[i]); + + /*Assign output pointers*/ + *array = clist; + if(N) *N = n; +}/*}}}*/ + +boost::python::list void mesh(boost::python::list INDEX){ + + boost::python::list output; + + double *index=NULL; + int n; + + FetchData(&index,&n,INDEX); + + /*Call x layer*/ + meshx(index,n); + + /*Clean up*/ + delete index; +} + + +#include +#include +using namespace boost::python; + +BOOST_PYTHON_MODULE(TriMesh_ext){ + def("mesh",mesh); +} Index: /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh/Code.cpp =================================================================== --- /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh/Code.cpp (revision 0) +++ /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh/Code.cpp (revision 11850) @@ -0,0 +1,53 @@ +/*Copyright 2006 Phil Austin (http:www.eos.ubc.ca/personal/paustin) + Distributed under the Boost Software License, Version 1.0. (See + accompanying file LICENSE_1_0.txt or copy at +http:www.boost.org/LICENSE_1_0.txt) +*/ + +#define PY_ARRAY_UNIQUE_SYMBOL PyArrayHandle +#include "num_util.h" +#include + +namespace { const char* rcsid = "$Id: simpletest.cpp,v 1.4 2006/07/05 22:55:16 phil Exp $"; } + +//send a dictionary with two arrays back to python +boost::python::dict testToPython(void){ + double ia[6] = {1,2,3,4,5,6}; + int ib[3] = {88,99,100}; + //construct two numpy arrays + boost::python::numeric::array pyDoubles=num_util::makeNum(ia,6); + boost::python::numeric::array pyInts=num_util::makeNum(ib,3); + //pack them in a dictionary and return to python + boost::python::dict retvals; + retvals["myDoubles"]=pyDoubles; + retvals["myInts"]=pyInts; + return retvals; +} + +//get an array from python +void testFromPython(boost::python::numeric::array inValue){ + num_util::check_type(inValue, PyArray_DOUBLE); + num_util::check_rank(inValue, 2); + double* dataPtr = (double*) num_util::data(inValue); + int theSize= num_util::size(inValue); + std::cout << std::endl << "data values on c++ side: " << std::endl; + for(int i=0;i < theSize;++i){ + std::cout << *(dataPtr + i) << std::endl; + } +} + +BOOST_PYTHON_MODULE(simple_ext) +{ + import_array(); + boost::python::numeric::array::set_module_and_type("numpy", "ArrayType"); + //global doc string + boost::python::scope().attr("RCSID") = rcsid; + std::string str1; + str1="docstring for module\n"; + boost::python::scope().attr("__doc__") = str1.c_str(); + str1 = "Doc string for testToPython\n"; + def("testToPython", testToPython,str1.c_str()); + str1 = "Doc string for testFromPython\n"; + def("testFromPython", testFromPython,str1.c_str()); +} + Index: /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh/TriMesh.cpp =================================================================== --- /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh/TriMesh.cpp (revision 0) +++ /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh/TriMesh.cpp (revision 11850) @@ -0,0 +1,58 @@ +#include +using namespace std; + +void meshx(double* index,int n) { + int i; + for(i=0;i +#include +#include +using namespace boost::python; + +void FetchData(double** array,int* N,boost::python::list pythonlist){/*{{{*/ + + /*Get list size*/ + int n = boost::python::extract(pythonlist.attr("__len__")()); + + /*Assign double array and populate*/ + double* clist = new double[n]; + for (int i=0;i(pythonlist[i]); + + /*Assign output pointers*/ + *array = clist; + if(N) *N = n; +}/*}}}*/ + +boost::python::list mesh(boost::python::list INDEX){ + + int i; + + boost::python::list output; + + double *index=NULL; + int n; + + FetchData(&index,&n,INDEX); + + for(i=0;i +#include +using namespace boost::python; + +BOOST_PYTHON_MODULE(TriMesh){ + def("mesh",mesh); +} Index: /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh/Makefile =================================================================== --- /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh/Makefile (revision 11849) +++ /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh/Makefile (revision 11850) @@ -1,12 +1,11 @@ -all: ice +all: TriMesh.so -ice: - g++ -bundle -bind \ - -I$(ISSM_TIER)/externalpackages/boost/install/include \ - -I/Library/Frameworks/Python.framework/Versions/3.2/include/python3.2m\ - -L$(ISSM_TIER)/externalpackages/boost/install/lib -lboost_python \ - -L/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/config-3.2m/ -lpython3.2 \ - TriMeshmodule.cpp -o TriMesh.so +TriMesh.o: TriMesh.cpp + g++ -I$(ISSM_TIER)/externalpackages/boost/install/include -I$(ISSM_TIER)/externalpackages/python/install/Python.framework/Versions/3.2/include/python3.2 -c -o TriMesh.o TriMesh.cpp + +TriMesh.so: TriMesh.o + g++ -dynamiclib -o TriMesh.so TriMesh.o -L$(ISSM_TIER)/externalpackages/boost/install/lib -lboost_python -L$(ISSM_TIER)/externalpackages/python/install/Python.framework/Versions/3.2/lib -L$(ISSM_TIER)/externalpackages/python/install/Python.framework/Versions/3.2/lib/python3.2/config -lpython3.2 + clean: - rm TriMesh.so + rm TriMesh.so TriMesh.o Index: /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh2/test.py =================================================================== --- /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh2/test.py (revision 0) +++ /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh2/test.py (revision 11850) @@ -0,0 +1,5 @@ +from TriMesh import * +from numpy import * +a=array([1.0,2.0]); + +mesh(a) Index: /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh2/TriMesh.cpp.bak =================================================================== --- /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh2/TriMesh.cpp.bak (revision 0) +++ /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh2/TriMesh.cpp.bak (revision 11850) @@ -0,0 +1,53 @@ +#include +using namespace std; + +void meshx(double* index,int n) { + int i; + for(i=0;i +#include +#include +using namespace boost::python; + +void FetchData(double** array,int* N,boost::python::list pythonlist){/*{{{*/ + + /*Get list size*/ + int n = boost::python::extract(pythonlist.attr("__len__")()); + + /*Assign double array and populate*/ + double* clist = new double[n]; + for (int i=0;i(pythonlist[i]); + + /*Assign output pointers*/ + *array = clist; + if(N) *N = n; +}/*}}}*/ + +boost::python::list void mesh(boost::python::list INDEX){ + + boost::python::list output; + + double *index=NULL; + int n; + + FetchData(&index,&n,INDEX); + + /*Call x layer*/ + meshx(index,n); + + /*Clean up*/ + delete index; +} + + +#include +#include +using namespace boost::python; + +BOOST_PYTHON_MODULE(TriMesh_ext){ + def("mesh",mesh); +} Index: /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh2/TriMesh.cpp.bak2 =================================================================== --- /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh2/TriMesh.cpp.bak2 (revision 0) +++ /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh2/TriMesh.cpp.bak2 (revision 11850) @@ -0,0 +1,33 @@ +#include +using namespace std; + +#include +#include +#include +//#include "num_util.h" + +using namespace boost::python; + +void mesh(boost::python::numeric::array array){ + + int n; + double a; + + n = boost::python::extract(array.attr("__len__")()); + + for(int i=0;i < n;++i){ + a=extract(array[i]); + printf("%g\n",a); + } + +} + + +#include +#include +using namespace boost::python; + +BOOST_PYTHON_MODULE(TriMesh){ + boost::python::numeric::array::set_module_and_type( "numpy", "ndarray"); + def("mesh",mesh); +} Index: /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh2/Code.cpp =================================================================== --- /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh2/Code.cpp (revision 0) +++ /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh2/Code.cpp (revision 11850) @@ -0,0 +1,53 @@ +/*Copyright 2006 Phil Austin (http:www.eos.ubc.ca/personal/paustin) + Distributed under the Boost Software License, Version 1.0. (See + accompanying file LICENSE_1_0.txt or copy at +http:www.boost.org/LICENSE_1_0.txt) +*/ + +#define PY_ARRAY_UNIQUE_SYMBOL PyArrayHandle +#include "num_util.h" +#include + +namespace { const char* rcsid = "$Id: simpletest.cpp,v 1.4 2006/07/05 22:55:16 phil Exp $"; } + +//send a dictionary with two arrays back to python +boost::python::dict testToPython(void){ + double ia[6] = {1,2,3,4,5,6}; + int ib[3] = {88,99,100}; + //construct two numpy arrays + boost::python::numeric::array pyDoubles=num_util::makeNum(ia,6); + boost::python::numeric::array pyInts=num_util::makeNum(ib,3); + //pack them in a dictionary and return to python + boost::python::dict retvals; + retvals["myDoubles"]=pyDoubles; + retvals["myInts"]=pyInts; + return retvals; +} + +//get an array from python +void testFromPython(boost::python::numeric::array inValue){ + num_util::check_type(inValue, PyArray_DOUBLE); + num_util::check_rank(inValue, 2); + double* dataPtr = (double*) num_util::data(inValue); + int theSize= num_util::size(inValue); + std::cout << std::endl << "data values on c++ side: " << std::endl; + for(int i=0;i < theSize;++i){ + std::cout << *(dataPtr + i) << std::endl; + } +} + +BOOST_PYTHON_MODULE(simple_ext) +{ + import_array(); + boost::python::numeric::array::set_module_and_type("numpy", "ArrayType"); + //global doc string + boost::python::scope().attr("RCSID") = rcsid; + std::string str1; + str1="docstring for module\n"; + boost::python::scope().attr("__doc__") = str1.c_str(); + str1 = "Doc string for testToPython\n"; + def("testToPython", testToPython,str1.c_str()); + str1 = "Doc string for testFromPython\n"; + def("testFromPython", testFromPython,str1.c_str()); +} + Index: /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh2/TriMesh.cpp =================================================================== --- /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh2/TriMesh.cpp (revision 0) +++ /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh2/TriMesh.cpp (revision 11850) @@ -0,0 +1,41 @@ +#include +using namespace std; + +#include +#include +#include +#include + +using namespace boost::python; + +void mesh(boost::python::numeric::array array){ +//void mesh(boost::python::object array){ + + int i; + double* b=NULL; + int nd,M,N; + int* dims=NULL; + PyArrayObject* a = (PyArrayObject*)array.ptr(); + b=(double*)PyArray_DATA(a); + nd=PyArray_NDIM(a); + dims=(int*)PyArray_DIMS(a); + M=dims[0]; + + printf("nd: %i M: %i\n",nd,M); + for(i=0;i +#include +using namespace boost::python; + +BOOST_PYTHON_MODULE(TriMesh){ + boost::python::numeric::array::set_module_and_type( "numpy", "ndarray"); + //boost::python::numeric::array::set_module_and_type( "numpy", "array"); + def("mesh",mesh); +} Index: /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh2/Makefile =================================================================== --- /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh2/Makefile (revision 0) +++ /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh2/Makefile (revision 11850) @@ -0,0 +1,15 @@ +all: TriMesh.so + + +TriMesh.o: TriMesh.cpp + g++ -DNPY_NO_DEPRECATED_API -c -o TriMesh.o TriMesh.cpp \ + -I$(ISSM_TIER)/externalpackages/boost/install/include \ + -I$(ISSM_TIER)/externalpackages/python/install/include \ + -I$(ISSM_TIER)/externalpackages/python/install/Python.framework/Versions/3.2/lib/python3.2/site-packages/numpy/core/include + + +TriMesh.so: TriMesh.o + g++ -dynamiclib -o TriMesh.so TriMesh.o -L$(ISSM_TIER)/externalpackages/boost/install/lib -lboost_python -L$(ISSM_TIER)/externalpackages/python/install/lib -lpython3.2 + +clean: + rm TriMesh.so TriMesh.o Property changes on: /proj/ice/larour/issm-uci-clean/trunk-jpl/src/py/modules/TriMesh2/Makefile ___________________________________________________________________ Added: svn:executable + *