diff --git a/opm/parser/eclipse/Generator/KeywordLoader.hpp b/opm/parser/eclipse/Generator/KeywordLoader.hpp index 0a505a8d8..0ae48f29c 100644 --- a/opm/parser/eclipse/Generator/KeywordLoader.hpp +++ b/opm/parser/eclipse/Generator/KeywordLoader.hpp @@ -40,14 +40,9 @@ namespace Opm { bool hasKeyword(const std::string& keyword) const; std::shared_ptr getKeyword(const std::string& keyword) const; std::string getJsonFile(const std::string& keyword) const; - size_t loadKeywordDirectory(const std::string& pathname); - size_t loadKeywordDirectory(boost::filesystem::path& path); void loadKeyword(const std::string& filename); void loadKeyword(boost::filesystem::path& path); - static std::vector sortSubdirectories( const std::string& directory ); - size_t loadMultipleKeywordDirectories(const std::string& directory); - std::map >::const_iterator keyword_begin( ) const; std::map >::const_iterator keyword_end( ) const; private: diff --git a/src/opm/parser/eclipse/Generator/KeywordLoader.cpp b/src/opm/parser/eclipse/Generator/KeywordLoader.cpp index 6bb69efea..9dc121984 100644 --- a/src/opm/parser/eclipse/Generator/KeywordLoader.cpp +++ b/src/opm/parser/eclipse/Generator/KeywordLoader.cpp @@ -67,43 +67,6 @@ namespace Opm { } - size_t KeywordLoader::loadKeywordDirectory(boost::filesystem::path& path) { - size_t loadCount = 0; - if (boost::filesystem::is_directory( path )) { - boost::filesystem::directory_iterator end_iterator; - - for (boost::filesystem::directory_iterator iter(path); iter != end_iterator; ++iter) { - boost::filesystem::path iter_path = iter->path(); - - if (boost::filesystem::is_directory( iter_path )) { - loadCount += loadKeywordDirectory( iter_path ); - } else { - std::string internalName = iter_path.filename().string(); - if (ParserKeyword::validInternalName(internalName)) { - if (m_verbose) - std::cout << "Loading keyword " << internalName << " from file: " << iter_path << "...."; - loadKeyword( iter_path ); - if (m_verbose) - std::cout << std::endl; - loadCount += 1; - } else { - if (m_verbose) - std::cout << "Ignoring file " << iter_path << " - incorrectly formatted name." << std::endl; - } - } - } - - } else - throw std::invalid_argument("Input does not correspond to existing directory\n"); - - return loadCount; - } - - size_t KeywordLoader::loadKeywordDirectory(const std::string& directory) { - boost::filesystem::path path( directory ); - return loadKeywordDirectory( path ); - } - void KeywordLoader::loadKeyword(boost::filesystem::path& path) { std::shared_ptr jsonConfig = std::make_shared( path ); std::shared_ptr parserKeyword = std::make_shared(*jsonConfig); @@ -114,19 +77,10 @@ namespace Opm { } - size_t KeywordLoader::loadMultipleKeywordDirectories(const std::string& directory) { - std::vector directories = sortSubdirectories( directory ); - - size_t load_count = 0; - for (auto iter = directories.begin(); iter != directories.end(); ++iter) - load_count += loadKeywordDirectory(*iter); - - return load_count; - } - - void KeywordLoader::loadKeyword(const std::string& filename) { boost::filesystem::path path( filename ); + if (m_verbose) + std::cout << "Loading keyword from file: " << filename << std::endl; return loadKeyword( path ); } @@ -144,22 +98,6 @@ namespace Opm { } - std::vector KeywordLoader::sortSubdirectories( const std::string& root_path) { - boost::filesystem::path root(root_path); - if (boost::filesystem::is_directory( root )) { - std::vector paths_in_root; - boost::filesystem::directory_iterator end_iterator; - - for (boost::filesystem::directory_iterator iter(root); iter != end_iterator; ++iter) { - if (boost::filesystem::is_directory( iter->path() )) - paths_in_root.push_back(iter->path().string()); - } - - std::sort(paths_in_root.begin(), paths_in_root.end()); - return paths_in_root; - } else - throw std::invalid_argument("Input argument is not a directory"); - } std::map >::const_iterator KeywordLoader::keyword_begin( ) const { return m_keywords.begin( ); diff --git a/tests/parser/KeywordLoaderTests.cpp b/tests/parser/KeywordLoaderTests.cpp index a37912e33..2a3927c8c 100644 --- a/tests/parser/KeywordLoaderTests.cpp +++ b/tests/parser/KeywordLoaderTests.cpp @@ -64,46 +64,3 @@ BOOST_AUTO_TEST_CASE(LoadKeyword) { -BOOST_AUTO_TEST_CASE(LoadKeywordDirectory) { - Opm::KeywordLoader loader(false); - BOOST_CHECK_THROW( loader.loadKeywordDirectory("does/not/exists") , std::invalid_argument ); - BOOST_CHECK_THROW( loader.loadKeywordDirectory(prefix() + "invalid.json") , std::invalid_argument); - - BOOST_CHECK_EQUAL( 4 , loader.loadKeywordDirectory( prefix() + "loader/001_ECLIPSE100")); - BOOST_CHECK( loader.hasKeyword("ADDREG") ); - BOOST_CHECK( loader.hasKeyword("ACTNUM") ); - BOOST_CHECK( loader.hasKeyword("BOX") ); - BOOST_CHECK( loader.hasKeyword("BLOCK_PROBE") ); - { - auto kw = loader.getKeyword("ADDREG"); - auto record = kw->getRecord(0); - BOOST_CHECK( !record.hasItem("REGION_NUMBER") ); - } -} - - -BOOST_AUTO_TEST_CASE(DirectorySort) { - BOOST_CHECK_THROW( Opm::KeywordLoader::sortSubdirectories( prefix() + "loader/ZCORN") , std::invalid_argument ); - std::vector dir_list = Opm::KeywordLoader::sortSubdirectories( prefix() + "loader"); - - namespace fs = boost::filesystem; - - BOOST_CHECK_EQUAL( 2U , dir_list.size()); - BOOST_CHECK_EQUAL( fs::path( dir_list[0] ), fs::path( prefix() + "loader/001_ECLIPSE100" ) ); - BOOST_CHECK_EQUAL( fs::path( dir_list[1] ), fs::path( prefix() + "loader/002_ECLIPSE300" ) ); -} - - -BOOST_AUTO_TEST_CASE(BigLoad) { - Opm::KeywordLoader loader(false); - BOOST_CHECK_THROW( loader.loadMultipleKeywordDirectories("does/not/exists") , std::invalid_argument ); - BOOST_CHECK_THROW( loader.loadMultipleKeywordDirectories(prefix() + "invalid.json") , std::invalid_argument); - - loader.loadMultipleKeywordDirectories(prefix() + "loader"); - BOOST_CHECK( loader.hasKeyword("EQUIL")); - { - auto kw = loader.getKeyword("ADDREG"); - auto record = kw->getRecord(0); - BOOST_CHECK( record.hasItem("REGION_NUMBER")); - } -}