Exemple #1
0
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
int Inventory::getAllStations(StationList& stationList,
                              const Core::Time& t) {
	if ( _inventory == NULL )
		return 0;

	std::set<std::string> networkMap;

	for ( size_t i = 0; i < _inventory->networkCount(); ++i ) {
		DataModel::Network* network = _inventory->network(i);

		if ( networkMap.find(network->code()) != networkMap.end() ) continue;
		try {
			if ( network->end() < t ) continue;
		}
		catch (...) {}

		if ( network->start() > t ) continue;

		networkMap.insert(network->code());

		std::set<std::string> stationMap;

		for ( size_t j = 0; j < network->stationCount(); ++j ) {
			DataModel::Station* station = network->station(j);

			if ( stationMap.find(station->code()) != stationMap.end() ) continue;

			try {
				if ( station->end() < t ) continue;
			}
			catch (...) {}

			if ( station->start() > t ) continue;

			stationList.push_back(station);
			stationMap.insert(station->code());
		}
	}

	return stationList.size();
}
Exemple #2
0
		bool syncRCFiles(DataModel::Inventory *inv) {
			if ( !Util::pathExists(_rcdir) ) {
				if ( !Util::createPath(_rcdir) ) {
					cerr << "ERROR: Unable to create rc output path "
					     << _rcdir << endl;
					return false;
				}
			}

			typedef pair<Core::Time, string> Item;
			typedef map<string, Item> DescMap;
			DescMap descs;

			for ( size_t n = 0; n < inv->networkCount(); ++n ) {
				DataModel::Network *net = inv->network(n);
				for ( size_t s = 0; s < net->stationCount(); ++s ) {
					DataModel::Station *sta = net->station(s);
					string id = net->code() + "_" + sta->code();
					Core::Time endTime;

					try { endTime = sta->end(); }
					catch ( ... ) {}

					DescMap::iterator it = descs.find(id);
					if ( it == descs.end() )
						descs[id] = Item(endTime, sta->description());
					else {
						if ( (it->second.first.valid() && it->second.first < endTime) ||
						     !endTime.valid() )
							it->second.second = sta->description();
					}
				}
			}

			// Collect all station files
			vector<string> oldFiles;
			try {
				fs::path directory = SC_FS_PATH(_rcdir);
				fs::directory_iterator it(directory);
				fs::directory_iterator dirEnd;

				for ( ; it != dirEnd; ++it ) {
					if ( fs::is_directory(*it) ) continue;
					string name = SC_FS_IT_LEAF(it);
					if ( name.compare(0, 8, "station_") == 0 )
						oldFiles.push_back(SC_FS_IT_STR(it));
				}
			}
			catch ( ... ) {}

			// Delete them
			for ( size_t i = 0; i < oldFiles.size(); ++i )
				unlink(oldFiles[i].c_str());

			for ( DescMap::iterator it = descs.begin(); it != descs.end(); ++it ) {
				fs::path fp = SC_FS_PATH(_rcdir) / SC_FS_PATH((string("station_") + it->first));
				Config::Config cfg;
				cfg.setString("description", it->second.second);
				if (! cfg.writeConfig(fp.string()) ) {
					cerr << "ERROR: " << fp.string() << ": unable to write file" << endl;
					return false;
				}
			}

			return true;
		}