/[escript]/branches/diaplayground/ripley/src/Brick.cpp
ViewVC logotype

Diff of /branches/diaplayground/ripley/src/Brick.cpp

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

revision 4482 by caltinay, Tue Jun 25 05:20:01 2013 UTC revision 4495 by caltinay, Fri Jul 5 02:19:47 2013 UTC
# Line 378  void Brick::readNcGrid(escript::Data& ou Line 378  void Brick::readNcGrid(escript::Data& ou
378  void Brick::readBinaryGrid(escript::Data& out, string filename,  void Brick::readBinaryGrid(escript::Data& out, string filename,
379                             const vector<int>& first,                             const vector<int>& first,
380                             const vector<int>& numValues,                             const vector<int>& numValues,
381                             const vector<int>& multiplier) const                             const std::vector<int>& multiplier,
382                               int byteOrder, int dataType) const
383  {  {
384        // the mapping is not universally correct but should work on our
385        // supported platforms
386        switch (dataType) {
387            case DATATYPE_INT32:
388                readBinaryGridImpl<int>(out, filename, first, numValues,
389                                        multiplier, byteOrder);
390                break;
391            case DATATYPE_FLOAT32:
392                readBinaryGridImpl<float>(out, filename, first, numValues,
393                                          multiplier, byteOrder);
394                break;
395            case DATATYPE_FLOAT64:
396                readBinaryGridImpl<double>(out, filename, first, numValues,
397                                           multiplier, byteOrder);
398                break;
399            default:
400                throw RipleyException("readBinaryGrid(): invalid or unsupported datatype");
401        }
402    }
403    
404    template<typename ValueType>
405    void Brick::readBinaryGridImpl(escript::Data& out, const string& filename,
406                                   const vector<int>& first,
407                                   const vector<int>& numValues,
408                                   const vector<int>& multiplier,
409                                   int byteOrder) const
410    {
411        if (byteOrder != BYTEORDER_NATIVE)
412            throw RipleyException("readBinaryGrid(): only native byte order supported at the moment.");
413    
414      // check destination function space      // check destination function space
415      int myN0, myN1, myN2;      int myN0, myN1, myN2;
416      if (out.getFunctionSpace().getTypeCode() == Nodes) {      if (out.getFunctionSpace().getTypeCode() == Nodes) {
# Line 414  void Brick::readBinaryGrid(escript::Data Line 445  void Brick::readBinaryGrid(escript::Data
445      f.seekg(0, ios::end);      f.seekg(0, ios::end);
446      const int numComp = out.getDataPointSize();      const int numComp = out.getDataPointSize();
447      const int filesize = f.tellg();      const int filesize = f.tellg();
448      const int reqsize = numValues[0]*numValues[1]*numValues[2]*numComp*sizeof(float);      const int reqsize = numValues[0]*numValues[1]*numValues[2]*numComp*sizeof(ValueType);
449      if (filesize < reqsize) {      if (filesize < reqsize) {
450          f.close();          f.close();
451          throw RipleyException("readBinaryGrid(): not enough data in file");          throw RipleyException("readBinaryGrid(): not enough data in file");
# Line 444  void Brick::readBinaryGrid(escript::Data Line 475  void Brick::readBinaryGrid(escript::Data
475      const int num2 = min(numValues[2]-idx2, myN2-first2);      const int num2 = min(numValues[2]-idx2, myN2-first2);
476    
477      out.requireWrite();      out.requireWrite();
478      vector<float> values(num0*numComp);      vector<ValueType> values(num0*numComp);
479      const int dpp = out.getNumDataPointsPerSample();      const int dpp = out.getNumDataPointsPerSample();
480    
481      for (index_t z=0; z<num2; z++) {      for (index_t z=0; z<num2; z++) {
482          for (index_t y=0; y<num1; y++) {          for (index_t y=0; y<num1; y++) {
483              const int fileofs = numComp*(idx0+(idx1+y)*numValues[0]+(idx2+z)*numValues[0]*numValues[1]);              const int fileofs = numComp*(idx0+(idx1+y)*numValues[0]+(idx2+z)*numValues[0]*numValues[1]);
484              f.seekg(fileofs*sizeof(float));              f.seekg(fileofs*sizeof(ValueType));
485              f.read((char*)&values[0], num0*numComp*sizeof(float));              f.read((char*)&values[0], num0*numComp*sizeof(ValueType));
486    
487              for (index_t x=0; x<num0; x++) {              for (index_t x=0; x<num0; x++) {
488                  const int baseIndex = first0+x*multiplier[0]                  const int baseIndex = first0+x*multiplier[0]

Legend:
Removed from v.4482  
changed lines
  Added in v.4495

  ViewVC Help
Powered by ViewVC 1.1.26