/[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 4949 by caltinay, Mon May 19 05:54:58 2014 UTC revision 4988 by caltinay, Wed Jun 4 01:15:10 2014 UTC
# Line 452  void Brick::readBinaryGridImpl(escript:: Line 452  void Brick::readBinaryGridImpl(escript::
452      for (size_t i=0; i<params.multiplier.size(); i++)      for (size_t i=0; i<params.multiplier.size(); i++)
453          if (params.multiplier[i]<1)          if (params.multiplier[i]<1)
454              throw RipleyException("readBinaryGrid(): all multipliers must be positive");              throw RipleyException("readBinaryGrid(): all multipliers must be positive");
455        if (params.reverse[0] != 0 || params.reverse[1] != 0)
456            throw RipleyException("readBinaryGrid(): reversing only supported in Z-direction currently");
457    
458      // check file existence and size      // check file existence and size
459      ifstream f(filename.c_str(), ifstream::binary);      ifstream f(filename.c_str(), ifstream::binary);
# Line 484  void Brick::readBinaryGridImpl(escript:: Line 486  void Brick::readBinaryGridImpl(escript::
486      const int first0 = max(0, params.first[0]-m_offset[0]);      const int first0 = max(0, params.first[0]-m_offset[0]);
487      const int first1 = max(0, params.first[1]-m_offset[1]);      const int first1 = max(0, params.first[1]-m_offset[1]);
488      const int first2 = max(0, params.first[2]-m_offset[2]);      const int first2 = max(0, params.first[2]-m_offset[2]);
489      // indices to first value in file      // indices to first value in file (not accounting for reverse yet)
490      const int idx0 = max(0, m_offset[0]-params.first[0]);      int idx0 = max(0, m_offset[0]-params.first[0]);
491      const int idx1 = max(0, m_offset[1]-params.first[1]);      int idx1 = max(0, m_offset[1]-params.first[1]);
492      const int idx2 = max(0, m_offset[2]-params.first[2]);      int idx2 = max(0, m_offset[2]-params.first[2]);
493      // number of values to read      // number of values to read
494      const int num0 = min(params.numValues[0]-idx0, myN0-first0);      const int num0 = min(params.numValues[0]-idx0, myN0-first0);
495      const int num1 = min(params.numValues[1]-idx1, myN1-first1);      const int num1 = min(params.numValues[1]-idx1, myN1-first1);
496      const int num2 = min(params.numValues[2]-idx2, myN2-first2);      const int num2 = min(params.numValues[2]-idx2, myN2-first2);
497    
498        // make sure we read the right block if going backwards through file
499        if (params.reverse[2])
500            idx2 = params.numValues[2]-idx2-1;
501    
502        // helpers for reversing
503        const int z_mult = (params.reverse[2] ? -1 : 1);
504    
505      out.requireWrite();      out.requireWrite();
506      vector<ValueType> values(num0*numComp);      vector<ValueType> values(num0*numComp);
507      const int dpp = out.getNumDataPointsPerSample();      const int dpp = out.getNumDataPointsPerSample();
508    
509      for (int z=0; z<num2; z++) {      for (int z=0; z<num2; z++) {
510          for (int y=0; y<num1; y++) {          for (int y=0; y<num1; y++) {
511              const int fileofs = numComp*(idx0+(idx1+y)*params.numValues[0]              const int fileofs = numComp*(idx0 +
512                               +(idx2+z)*params.numValues[0]*params.numValues[1]);                                  (idx1+y)*params.numValues[0] +
513                                    (idx2+z_mult*z)*params.numValues[0]*params.numValues[1]);
514              f.seekg(fileofs*sizeof(ValueType));              f.seekg(fileofs*sizeof(ValueType));
515              f.read((char*)&values[0], num0*numComp*sizeof(ValueType));              f.read((char*)&values[0], num0*numComp*sizeof(ValueType));
516    

Legend:
Removed from v.4949  
changed lines
  Added in v.4988

  ViewVC Help
Powered by ViewVC 1.1.26