/[escript]/trunk/ripley/src/ripleycpp.cpp
ViewVC logotype

Diff of /trunk/ripley/src/ripleycpp.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3994 by jfenwick, Wed Sep 26 07:38:38 2012 UTC revision 4013 by caltinay, Thu Oct 4 03:13:27 2012 UTC
# Line 72  escript::Data readBinaryGrid(std::string Line 72  escript::Data readBinaryGrid(std::string
72      return res;      return res;
73  }  }
74    
75    escript::Data readNcGrid(std::string filename, std::string varname,
76            escript::FunctionSpace fs, const object& pyFirst, const object& pyNum,
77            const object& pyShape, double fill=0.)
78    {
79        int dim=fs.getDim();
80        std::vector<int> first(dim), numValues(dim), shape;
81    
82        if (extract<tuple>(pyFirst).check() || extract<list>(pyFirst).check()) {
83            if (len(pyFirst)==dim) {
84                for (int i=0; i<dim; i++) {
85                    first[i]=extract<int>(pyFirst[i]);
86                }
87            } else
88                throw RipleyException("Argument 'first' has wrong length");
89        } else
90            throw RipleyException("Argument 'first' must be a tuple or list");
91    
92        if (extract<tuple>(pyNum).check() || extract<list>(pyNum).check()) {
93            if (len(pyNum)==dim) {
94                for (int i=0; i<dim; i++) {
95                    numValues[i]=extract<int>(pyNum[i]);
96                }
97            } else
98                throw RipleyException("Argument 'numValues' has wrong length");
99        } else
100            throw RipleyException("Argument 'numValues' must be a tuple or list");
101    
102        if (extract<tuple>(pyShape).check() || extract<list>(pyShape).check()) {
103            for (int i=0; i<len(pyShape); i++) {
104                shape.push_back(extract<int>(pyShape[i]));
105            }
106        } else
107            throw RipleyException("Argument 'shape' must be a tuple or list");
108    
109        const RipleyDomain* dom=dynamic_cast<const RipleyDomain*>(fs.getDomain().get());
110        if (!dom)
111            throw RipleyException("Function space must be on a ripley domain");
112    
113    
114        escript::Data res(fill, shape, fs, true);
115    
116        dom->readNcGrid(res, filename, varname, first, numValues);
117        return res;
118    }
119    
120  // These wrappers are required to make the shared pointers work through the  // These wrappers are required to make the shared pointers work through the
121  // Python wrapper  // Python wrapper
122    
# Line 201  BOOST_PYTHON_MODULE(ripleycpp) Line 246  BOOST_PYTHON_MODULE(ripleycpp)
246    
247      def("_readBinaryGrid", &ripley::readBinaryGrid, (arg("filename"), arg("functionspace"), arg("first"), arg("numValues"), arg("shape"), arg("fill")=0.));      def("_readBinaryGrid", &ripley::readBinaryGrid, (arg("filename"), arg("functionspace"), arg("first"), arg("numValues"), arg("shape"), arg("fill")=0.));
248    
249        def("_readNcGrid", &ripley::readNcGrid, (arg("filename"), arg("varname"), arg("functionspace"), arg("first"), arg("numValues"), arg("shape"), arg("fill")=0.));
250    
251      class_<ripley::RipleyDomain, bases<escript::AbstractContinuousDomain> >      class_<ripley::RipleyDomain, bases<escript::AbstractContinuousDomain> >
252          ("RipleyDomain", "", no_init)          ("RipleyDomain", "", no_init)
253          .def("write", &ripley::RipleyDomain::write, args("filename"),          .def("write", &ripley::RipleyDomain::write, args("filename"),

Legend:
Removed from v.3994  
changed lines
  Added in v.4013

  ViewVC Help
Powered by ViewVC 1.1.26