Skip to content

Commit 8184ecf

Browse files
committed
correct srw format
1 parent c072853 commit 8184ecf

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/TField3D_Grid.cc

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -945,8 +945,9 @@ void TField3D_Grid::ReadFile_SRW (std::string const& InFileName, TVector3D const
945945
++fXDIM;
946946
}
947947

948-
// Reserve correct number of points in vector (slightly faster)
949-
fData.reserve(fNX * fNY * fNZ);
948+
// Resize the vector because we will need to insert values non-sequentially
949+
// ie can't use push_back
950+
fData.resize(fNX * fNY * fNZ);
950951

951952
// Temp variables for field
952953
double fx;
@@ -955,9 +956,9 @@ void TField3D_Grid::ReadFile_SRW (std::string const& InFileName, TVector3D const
955956

956957

957958
// Loop over all points
958-
for (int ix = 0; ix != NX; ++ix) {
959+
for (int iz = 0; iz != NZ; ++iz) {
959960
for (int iy = 0; iy != NY; ++iy) {
960-
for (int iz = 0; iz != NZ; ++iz) {
961+
for (int ix = 0; ix != NX; ++ix) {
961962

962963
// Grab a line from input file
963964
std::getline(fi, L);
@@ -977,7 +978,12 @@ void TField3D_Grid::ReadFile_SRW (std::string const& InFileName, TVector3D const
977978
// Push data to storage
978979
TVector3D F(fx, fy, fz);
979980
F.RotateSelfXYZ(Rotations);
980-
fData.push_back(F);
981+
982+
size_t const Index = this->GetIndex(ix, iy, iz);
983+
if (Index >= fData.size()) {
984+
throw;
985+
}
986+
fData[Index] = F;
981987
}
982988
}
983989
}

src/TFieldContainer.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,9 +371,9 @@ void TFieldContainer::WriteToFile (std::string const& OutFileName, std::string c
371371
of << std::scientific;
372372

373373
// Loop over all points and output
374-
for (int i = 0; i < NX; ++i) {
374+
for (int k = 0; k < NZ; ++k) {
375375
for (int j = 0; j < NY; ++j) {
376-
for (int k = 0; k < NZ; ++k) {
376+
for (int i = 0; i < NX; ++i) {
377377

378378
// Set current position
379379
X.SetXYZ(XLim[0] + XStep * i, YLim[0] + YStep * j, ZLim[0] + ZStep * k);

0 commit comments

Comments
 (0)