00001 #include "ParkSurfaceWaveData.h" 00002 #include <fstream> 00003 #include <iostream> 00004 #include <iterator> 00005 #include "FatalException.h" 00006 #include <cassert> 00007 00008 namespace gplib 00009 { 00010 void ParkSurfaceWaveData::ReadAscii(const std::string &filename) 00011 { 00012 std::ifstream infile(filename.c_str()); 00013 double currfreq, currphase; 00014 SetPeriods().clear(); 00015 SetPhaseVelocities().clear(); 00016 if (!infile.good()) 00017 { 00018 throw FatalException("Cannot open file " + filename); 00019 } 00020 while (infile.good()) 00021 { 00022 infile >> currfreq >> currphase; 00023 if (infile.good()) 00024 { 00025 SetPeriods().push_back(1.0 / currfreq); 00026 SetPhaseVelocities().push_back(currphase); 00027 } 00028 } 00029 if (GetPeriods().empty() || GetPhaseVelocities().empty()) 00030 throw FatalException("Cannot read phase velocities from file: " 00031 + filename); 00032 } 00033 00034 void ParkSurfaceWaveData::WriteAscii(const std::string &filename) const 00035 { 00036 std::ofstream outfile(filename.c_str()); 00037 assert(GetPeriods().size() == GetPhaseVelocities().size()); 00038 const unsigned int nelements = GetPeriods().size(); 00039 for (unsigned int i = 0; i < nelements; ++i) 00040 { 00041 outfile << 1.0 / GetPeriods().at(i); 00042 outfile << " " << GetPhaseVelocities().at(i); 00043 outfile << std::endl; 00044 } 00045 if (!outfile.good()) 00046 throw FatalException("Cannot write to file: " + filename); 00047 } 00048 00049 ParkSurfaceWaveData::ParkSurfaceWaveData() 00050 { 00051 } 00052 00053 ParkSurfaceWaveData::~ParkSurfaceWaveData() 00054 { 00055 } 00056 }
1.5.8