size_t PolyRegions::read(const std::string& location) { fs::path directory; try { directory = SC_FS_PATH(location); } catch ( ... ) { SEISCOMP_ERROR("Invalid path '%s'", location.c_str()); return 0; } if ( !fs::exists(directory) ) return regionCount(); fs::directory_iterator end_itr; std::vector<std::string> files; try { for ( fs::directory_iterator itr(directory); itr != end_itr; ++itr ) { if ( fs::is_directory(*itr) ) continue; if ( boost::regex_match(SC_FS_IT_LEAF(itr), boost::regex(".*\\.(?:fep)")) ) files.push_back(SC_FS_IT_STR(itr)); } } catch ( const std::exception &ex ) { SEISCOMP_ERROR("Reading regions: %s", ex.what()); return regionCount(); } std::sort(files.begin(), files.end()); for ( size_t i = 0; i < files.size(); ++i ) { if ( !readFepBoundaries(files[i]) ) SEISCOMP_ERROR("Error reading file: %s", files[i].c_str()); } info(); // Sort the features according to their rank std::sort(_regions.begin(), _regions.end(), compareByRank); // store directory path the data was read from _dataDir = directory.string(); return regionCount(); }
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> bool SC3GF1DArchive::setSource(std::string source) { fs::path directory; try { directory = SC_FS_PATH(source); } catch ( ... ) { SEISCOMP_ERROR("Unable to open directory: %s", source.c_str()); return false; } _baseDirectory = source; fs::directory_iterator end_itr; try { for ( fs::directory_iterator itr(directory); itr != end_itr; ++itr ) { if ( !fs::is_directory(*itr) ) continue; std::string name = SC_FS_IT_LEAF(itr); /* size_t pos = name.rfind("_efl"); if ( pos == std::string::npos ) continue; */ std::string model = name/*.substr(0, pos)*/; std::ifstream ifDesc; int depthFrom = -1, depthTo = -1, depthSpacing = -1; int distanceFrom = -1, distanceTo = -1, distanceSpacing = -1; std::string line; ifDesc.open((_baseDirectory + "/" + name + ".desc").c_str()); if ( !ifDesc.is_open() ) { SEISCOMP_WARNING("Unable to find model description, skipping directory: %s", name.c_str()); continue; } bool validModel = true; DoubleList &depths = _models[model].depths; DoubleList &dists = _models[model].distances; while ( getline(ifDesc, line) ) { Core::trim(line); if ( line.empty() ) continue; if ( line[0] == '#' ) continue; std::stringstream ss(line); ss >> line; if ( line == "depth" ) { ss >> depthFrom >> depthTo >> depthSpacing; if ( (depthSpacing < 0) || (depthFrom > depthTo) ) { SEISCOMP_WARNING("Invalid description format, skipping directory: %s", name.c_str()); validModel = false; break; } if ( depthSpacing == 0 ) depths.insert(depthFrom); else { for ( int i = depthFrom; i <= depthTo; i += depthSpacing ) depths.insert(i); } } else if ( line == "distance" ) { ss >> distanceFrom >> distanceTo >> distanceSpacing; if ( (distanceSpacing < 0) || (distanceFrom > distanceTo) ) { SEISCOMP_WARNING("Invalid description format, skipping directory: %s", name.c_str()); validModel = false; break; } if ( distanceSpacing == 0 ) dists.insert(distanceFrom); else { for ( int i = distanceFrom; i <= distanceTo; i += distanceSpacing ) dists.insert(i); } } }