2 #include "StationParser.h"
5 #include "stringcompare.h"
11 #include <boost/bind.hpp>
16 MTStationList::MTStationList(
double freqtol):
27 ifstream infile(filename.c_str());
33 parser.ParseFile(infile);
35 for (
unsigned int i = 0; i < parser.Stationnames.size(); ++i)
37 cout <<
"Working on file " << parser.Stationnames.at(i) << endl;
41 CurrentStation.
GetData(parser.Stationnames.at(i));
44 if (parser.HasLatLong.at(i))
49 StationData.push_back(CurrentStation);
52 cerr << e.what() <<
" Skipping file !" << endl;
61 if (!StationData.empty())
69 return (StationData.at(loc));
74 ofstream outfile(filename.c_str());
75 for (vector<MTStation>::iterator CurrentStation = StationData.begin(); CurrentStation
76 != StationData.end(); CurrentStation++)
78 outfile << CurrentStation->GetName();
79 outfile << setfill(
' ') << setw(15) << resetiosflags(ios::fixed);
80 outfile << CurrentStation->GetLongitude() <<
" ";
81 outfile << setfill(
' ') << setw(15) << resetiosflags(ios::fixed);
82 outfile << CurrentStation->GetLatitude();
90 for (std::vector<MTStation>::iterator CurrentStation =
91 StationData.begin(); CurrentStation != StationData.end(); CurrentStation++)
92 CurrentStation->WriteBack();
95 void MTStationList::FindCommon(
void)
97 trealdata masterfrequencies(StationData.begin()->GetFrequencies());
99 commonfrequencies.clear();
100 for (
unsigned int i = 0; i < masterfrequencies.size(); ++i)
102 bool iscommon =
true;
103 for (
size_t j = 0; j < StationData.size(); ++j)
105 bool foundfrequency =
false;
107 while ((foundfrequency ==
false) && (k
108 < StationData.at(j).GetFrequencies().size()))
110 if (fcmp(masterfrequencies.at(i),
111 StationData.at(j).GetFrequencies().at(k), tolerance)
113 foundfrequency =
true;
117 iscommon = (iscommon && foundfrequency);
120 commonfrequencies.push_back(masterfrequencies.at(i));
122 tindexvector indices(commonfrequencies.size(), -1);
123 cfindices.assign(StationData.size(), indices);
124 for (
unsigned int i = 0; i < commonfrequencies.size(); ++i)
126 for (
unsigned int j = 0; j < StationData.size(); ++j)
128 double bestfit = 1e32;
129 for (
size_t k = 0; k < StationData.at(j).GetFrequencies().size(); ++k)
131 if ((fcmp(commonfrequencies.at(i),
132 StationData.at(j).GetFrequencies().at(k), tolerance)
133 == 0) && (abs(commonfrequencies.at(i) - StationData.at(
134 j).GetFrequencies().at(k)) < bestfit))
136 cfindices.at(j).at(i) = k;
137 bestfit = commonfrequencies.at(i)
138 - StationData.at(j).GetFrequencies().at(k);
148 class HasSameName:
public std::binary_function<MTStation, MTStation, bool>
163 std::vector<std::pair<MTStation*, MTStation*> > CorrespondingSites;
164 for (
size_t i = 0; i < MasterList.size(); ++i)
166 tStationList::iterator slaveit = find_if(SlaveList.begin(),
167 SlaveList.end(), boost::bind(
HasSameName(), MasterList.at(i),
169 if (slaveit != SlaveList.end())
170 CorrespondingSites.push_back(std::make_pair(&MasterList.at(i),
173 std::cerr <<
"Not found: " << MasterList.at(i).GetName()
176 return CorrespondingSites;
MTStation & at(int loc)
Get a reference to a site at a given index.
void WriteAllData()
Write the data of each station to an individual file.
void WriteList(const std::string filename="station.list")
Write the names of the sites in the current list to a file.
virtual void GetData(const std::string filename)
read in data from file, determines format by ending
The class MTStation is used to store the transfer functions and related information for a MT-site...
returns if station a and b have the same name
void SetLatitude(double lat)
void GetData(const std::string filename)
Read a list of filenames and the associated data in those files to fill the list. ...
void SetLongitude(double lon)
bool operator()(MTStation a, MTStation b)
The basic exception class for all errors that arise in gplib.