GPLIB++
ParkSurfaceWaveData.cpp
Go to the documentation of this file.
1 #include "ParkSurfaceWaveData.h"
2 #include <fstream>
3 #include <iostream>
4 #include <iterator>
5 #include "FatalException.h"
6 #include <cassert>
7 
8 namespace gplib
9  {
10  void ParkSurfaceWaveData::ReadAscii(const std::string &filename)
11  {
12  std::ifstream infile(filename.c_str());
13  double currfreq, currphase;
14  SetPeriods().clear();
15  SetPhaseVelocities().clear();
16  if (!infile.good())
17  {
18  throw FatalException("Cannot open file " + filename);
19  }
20  while (infile.good())
21  {
22  infile >> currfreq >> currphase;
23  if (infile.good())
24  {
25  SetPeriods().push_back(1.0 / currfreq);
26  SetPhaseVelocities().push_back(currphase);
27  }
28  }
29  if (GetPeriods().empty() || GetPhaseVelocities().empty())
30  throw FatalException("Cannot read phase velocities from file: "
31  + filename);
32  }
33 
34  void ParkSurfaceWaveData::WriteAscii(const std::string &filename) const
35  {
36  std::ofstream outfile(filename.c_str());
37  assert(GetPeriods().size() == GetPhaseVelocities().size());
38  const unsigned int nelements = GetPeriods().size();
39  for (unsigned int i = 0; i < nelements; ++i)
40  {
41  outfile << 1.0 / GetPeriods().at(i);
42  outfile << " " << GetPhaseVelocities().at(i);
43  outfile << std::endl;
44  }
45  if (!outfile.good())
46  throw FatalException("Cannot write to file: " + filename);
47  }
48 
50  {
51  }
52 
54  {
55  }
56  }
const trealdata & GetPeriods() const
Read-only access to the vector of periods for the phase velocities.
virtual void WriteAscii(const std::string &filename) const
Write the data in simple ascii format.
const trealdata & GetPhaseVelocities() const
Read-only access to the vector of phase velocities.
trealdata & SetPeriods()
Read-write access to periods, the format might be changed in the future.
virtual void ReadAscii(const std::string &filename)
Read a file in general ascii format, i.e lines with period velocity each.
const int size
Definition: perftest.cpp:14
trealdata & SetPhaseVelocities()
Read-write access to phase velocities, the format might be changed in the future. ...
The basic exception class for all errors that arise in gplib.