GPLIB++
SeismicStationList.cpp
Go to the documentation of this file.
1 #include "SeismicStationList.h"
2 #include "StationParser.h"
3 #include <fstream>
4 #include <iomanip>
5 using namespace std;
6 
7 namespace gplib
8  {
9  SeismicStationList::SeismicStationList()
10  {
11  }
12 
13  SeismicStationList::~SeismicStationList()
14  {
15  }
16 
17  void SeismicStationList::ReadList(const std::string filename)
18  {
19  ifstream infile(filename.c_str());
20  //we open file, check whether it opened OK
21  if (infile)
22  {
23  StationParser parser;
24  parser.ParseFile(infile);
25  for (unsigned int i = 0; i < parser.Stationnames.size(); ++i)
26  {
27  //show information about each file
28  cout << "Working on file " << parser.Stationnames.at(i) << endl;
29  //create a shared pointer object
30  boost::shared_ptr<SeismicDataComp> CurrentStation(
31  new SeismicDataComp);
32  //and read in the data from the specified file
33  CurrentStation->ReadData(parser.Stationnames.at(i));
34  //we can optionally specify latitude and longitude information
35  if (parser.HasLatLong.at(i))
36  {
37  //this overrides the information in the file
38  CurrentStation->SetStLo(parser.Longitudes.at(i));
39  CurrentStation->SetStLa(parser.Latitudes.at(i));
40  }
41  StationList.push_back(CurrentStation);
42  }
43  }
44  else
45  {
46  throw("File not found: " + filename);
47  }
48  }
49 
50  void SeismicStationList::WriteList(const std::string filename)
51  {
52  ofstream outfile(filename.c_str());
53  //go through the vector of seismic component objects
54  for (tseiscompvector::iterator CurrentStation = StationList.begin(); CurrentStation
55  != StationList.end(); CurrentStation++)
56  {
57  //write out name, longitude and latitude with some formatting
58  outfile << CurrentStation->get()->GetName();
59  outfile << setfill(' ') << setw(15) << resetiosflags(ios::fixed);
60  outfile << CurrentStation->get()->GetStLo() << " ";
61  outfile << setfill(' ') << setw(15) << resetiosflags(ios::fixed);
62  outfile << CurrentStation->get()->GetStLa();
63  outfile << endl;
64  }
65  }
66 
67  void SeismicStationList::WriteAllData()
68  {
69  //go through the vector of seismic components
70  //and write each one in the format it was read in
71  for (tseiscompvector::iterator CurrentStation = StationList.begin(); CurrentStation
72  != StationList.end(); CurrentStation++)
73  CurrentStation->get()->WriteBack();
74  }
75  }