/[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 4276 by jfenwick, Mon Feb 25 03:16:14 2013 UTC revision 4277 by caltinay, Wed Mar 6 01:30:41 2013 UTC
# Line 28  using namespace boost::python; Line 28  using namespace boost::python;
28  namespace ripley {  namespace ripley {
29    
30  escript::Data readBinaryGrid(std::string filename, escript::FunctionSpace fs,  escript::Data readBinaryGrid(std::string filename, escript::FunctionSpace fs,
31          const object& pyFirst, const object& pyNum, const object& pyShape,          const object& pyFirst, const object& pyNum, const object& pyMultiplier,
32          double fill=0.)          const object& pyShape, double fill=0.)
33  {  {
34      int dim=fs.getDim();      int dim=fs.getDim();
35      std::vector<int> first(dim), numValues(dim), shape;      std::vector<int> first(dim), numValues(dim), multiplier(dim), shape;
36    
37      if (extract<tuple>(pyFirst).check() || extract<list>(pyFirst).check()) {      if (extract<tuple>(pyFirst).check() || extract<list>(pyFirst).check()) {
38          if (len(pyFirst)==dim) {          if (len(pyFirst)==dim) {
# Line 61  escript::Data readBinaryGrid(std::string Line 61  escript::Data readBinaryGrid(std::string
61      } else      } else
62          throw RipleyException("Argument 'shape' must be a tuple or list");          throw RipleyException("Argument 'shape' must be a tuple or list");
63    
64        if (extract<tuple>(pyMultiplier).check() || extract<list>(pyMultiplier).check()) {
65            if (len(pyMultiplier)==dim) {
66                for (int i=0; i<dim; i++) {
67                    multiplier[i]=extract<int>(pyMultiplier[i]);
68                }
69            } else
70                throw RipleyException("Argument 'multiplier' has wrong length");
71        } else
72            throw RipleyException("Argument 'multiplier' must be a tuple or list");
73    
74      const RipleyDomain* dom=dynamic_cast<const RipleyDomain*>(fs.getDomain().get());      const RipleyDomain* dom=dynamic_cast<const RipleyDomain*>(fs.getDomain().get());
75      if (!dom)      if (!dom)
76          throw RipleyException("Function space must be on a ripley domain");          throw RipleyException("Function space must be on a ripley domain");
# Line 68  escript::Data readBinaryGrid(std::string Line 78  escript::Data readBinaryGrid(std::string
78    
79      escript::Data res(fill, shape, fs, true);      escript::Data res(fill, shape, fs, true);
80    
81      dom->readBinaryGrid(res, filename, first, numValues);      dom->readBinaryGrid(res, filename, first, numValues, multiplier);
82      return res;      return res;
83  }  }
84    
85  escript::Data readNcGrid(std::string filename, std::string varname,  escript::Data readNcGrid(std::string filename, std::string varname,
86          escript::FunctionSpace fs, const object& pyFirst, const object& pyNum,          escript::FunctionSpace fs, const object& pyFirst, const object& pyNum,
87          const object& pyShape, double fill=0.)          const object& pyMultiplier, const object& pyShape, double fill=0.)
88  {  {
89      int dim=fs.getDim();      int dim=fs.getDim();
90      std::vector<int> first(dim), numValues(dim), shape;      std::vector<int> first(dim), numValues(dim), multiplier(dim), shape;
91    
92      if (extract<tuple>(pyFirst).check() || extract<list>(pyFirst).check()) {      if (extract<tuple>(pyFirst).check() || extract<list>(pyFirst).check()) {
93          if (len(pyFirst)==dim) {          if (len(pyFirst)==dim) {
# Line 99  escript::Data readNcGrid(std::string fil Line 109  escript::Data readNcGrid(std::string fil
109      } else      } else
110          throw RipleyException("Argument 'numValues' must be a tuple or list");          throw RipleyException("Argument 'numValues' must be a tuple or list");
111    
112        if (extract<tuple>(pyMultiplier).check() || extract<list>(pyMultiplier).check()) {
113            if (len(pyMultiplier)==dim) {
114                for (int i=0; i<dim; i++) {
115                    multiplier[i]=extract<int>(pyMultiplier[i]);
116                }
117            } else
118                throw RipleyException("Argument 'multiplier' has wrong length");
119        } else
120            throw RipleyException("Argument 'multiplier' must be a tuple or list");
121    
122      if (extract<tuple>(pyShape).check() || extract<list>(pyShape).check()) {      if (extract<tuple>(pyShape).check() || extract<list>(pyShape).check()) {
123          for (int i=0; i<len(pyShape); i++) {          for (int i=0; i<len(pyShape); i++) {
124              shape.push_back(extract<int>(pyShape[i]));              shape.push_back(extract<int>(pyShape[i]));
# Line 113  escript::Data readNcGrid(std::string fil Line 133  escript::Data readNcGrid(std::string fil
133    
134      escript::Data res(fill, shape, fs, true);      escript::Data res(fill, shape, fs, true);
135    
136      dom->readNcGrid(res, filename, varname, first, numValues);      dom->readNcGrid(res, filename, varname, first, numValues, multiplier);
137      return res;      return res;
138  }  }
139    
# Line 243  BOOST_PYTHON_MODULE(ripleycpp) Line 263  BOOST_PYTHON_MODULE(ripleycpp)
263              "Reads a ripley domain from a file created by write().\n\n"              "Reads a ripley domain from a file created by write().\n\n"
264              ":rtype: `RipleyDomain`\n:param filename:\n:type filename: ``string``\n");              ":rtype: `RipleyDomain`\n:param filename:\n:type filename: ``string``\n");
265    
266      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("multiplier"), arg("shape"), arg("fill")=0.));
267    
268      def("_readNcGrid", &ripley::readNcGrid, (arg("filename"), arg("varname"), arg("functionspace"), arg("first"), arg("numValues"), arg("shape"), arg("fill")=0.));      def("_readNcGrid", &ripley::readNcGrid, (arg("filename"), arg("varname"), arg("functionspace"), arg("first"), arg("numValues"), arg("multiplier"), arg("shape"), arg("fill")=0.));
269    
270      class_<ripley::RipleyDomain, bases<escript::AbstractContinuousDomain>, boost::noncopyable >      class_<ripley::RipleyDomain, bases<escript::AbstractContinuousDomain>, boost::noncopyable >
271          ("RipleyDomain", "", no_init)          ("RipleyDomain", "", no_init)

Legend:
Removed from v.4276  
changed lines
  Added in v.4277

  ViewVC Help
Powered by ViewVC 1.1.26