SeismicStationList.cpp

Go to the documentation of this file.
00001 #include "SeismicStationList.h"
00002 #include "StationParser.h"
00003 #include <fstream>
00004 #include <iomanip>
00005 using namespace std;
00006 
00007 namespace gplib
00008   {
00009     SeismicStationList::SeismicStationList()
00010       {
00011       }
00012 
00013     SeismicStationList::~SeismicStationList()
00014       {
00015       }
00016 
00017     void SeismicStationList::ReadList(const std::string filename)
00018       {
00019         ifstream infile(filename.c_str());
00020         //we open file, check whether it opened OK
00021         if (infile)
00022           {
00023             StationParser parser;
00024             parser.ParseFile(infile);
00025             for (unsigned int i = 0; i < parser.Stationnames.size(); ++i)
00026               {
00027                 //show information about each file
00028                 cout << "Working on file " << parser.Stationnames.at(i) << endl;
00029                 //create a shared pointer object
00030                 boost::shared_ptr<SeismicDataComp> CurrentStation(
00031                     new SeismicDataComp);
00032                 //and read in the data from the specified file
00033                 CurrentStation->ReadData(parser.Stationnames.at(i));
00034                 //we can optionally specify latitude and longitude information
00035                 if (parser.HasLatLong.at(i))
00036                   {
00037                     //this overrides the information in the file
00038                     CurrentStation->SetStLo(parser.Longitudes.at(i));
00039                     CurrentStation->SetStLa(parser.Latitudes.at(i));
00040                   }
00041                 StationList.push_back(CurrentStation);
00042               }
00043           }
00044         else
00045           {
00046             throw("File not found: " + filename);
00047           }
00048       }
00049 
00050     void SeismicStationList::WriteList(const std::string filename)
00051       {
00052         ofstream outfile(filename.c_str());
00053         //go through the vector of seismic component objects
00054         for (tseiscompvector::iterator CurrentStation = StationList.begin(); CurrentStation
00055             != StationList.end(); CurrentStation++)
00056           {
00057             //write out name, longitude and latitude with some formatting
00058             outfile << CurrentStation->get()->GetName();
00059             outfile << setfill(' ') << setw(15) << resetiosflags(ios::fixed);
00060             outfile << CurrentStation->get()->GetStLo() << " ";
00061             outfile << setfill(' ') << setw(15) << resetiosflags(ios::fixed);
00062             outfile << CurrentStation->get()->GetStLa();
00063             outfile << endl;
00064           }
00065       }
00066 
00067     void SeismicStationList::WriteAllData()
00068       {
00069         //go through the vector of seismic components
00070         //and write each one in the format it was read in
00071         for (tseiscompvector::iterator CurrentStation = StationList.begin(); CurrentStation
00072             != StationList.end(); CurrentStation++)
00073           CurrentStation->get()->WriteBack();
00074       }
00075   }

Generated on Tue May 4 16:52:15 2010 for GPLIB++ by  doxygen 1.5.8