/*
Copyright 2019 Equinor ASA.
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see .
*/
#ifndef OPM_IO_ECLFILE_HPP
#define OPM_IO_ECLFILE_HPP
#include
#include
#include
#include
#include
#include
#include
#include
namespace Opm { namespace EclIO {
class EclFile
{
public:
explicit EclFile(const std::string& filename, bool preload = false);
bool formattedInput() { return formatted; }
void loadData(); // load all data
void loadData(const std::string& arrName); // load all arrays with array name equal to arrName
void loadData(int arrIndex); // load data based on array indices in vector arrIndex
void loadData(const std::vector& arrIndex); // load data based on array indices in vector arrIndex
void clearData()
{
inte_array.clear();
real_array.clear();
doub_array.clear();
logi_array.clear();
char_array.clear();
}
using EclEntry = std::tuple;
std::vector getList() const;
template
const std::vector& get(int arrIndex);
template
const std::vector& get(const std::string& name);
bool hasKey(const std::string &name) const;
std::size_t count(const std::string& name) const;
const std::vector& arrayNames() const { return array_name; }
std::size_t size() const;
protected:
bool formatted;
std::string inputFilename;
std::unordered_map> inte_array;
std::unordered_map> logi_array;
std::unordered_map> doub_array;
std::unordered_map> real_array;
std::unordered_map> char_array;
std::vector array_name;
std::vector array_type;
std::vector array_size;
std::vector ifStreamPos;
std::map array_index;
template
const std::vector& getImpl(int arrIndex, eclArrType type,
const std::unordered_map>& array,
const std::string& typeStr)
{
if (array_type[arrIndex] != type) {
std::string message = "Array with index " + std::to_string(arrIndex) + " is not of type " + typeStr;
OPM_THROW(std::runtime_error, message);
}
if (!arrayLoaded[arrIndex]) {
loadData(arrIndex);
}
return array.at(arrIndex);
}
std::streampos
seekPosition(const std::vector::size_type arrIndex) const;
private:
std::vector arrayLoaded;
void loadBinaryArray(std::fstream& fileH, std::size_t arrIndex);
void loadFormattedArray(const std::string& fileStr, std::size_t arrIndex, int64_t fromPos);
};
}} // namespace Opm::EclIO
#endif // OPM_IO_ECLFILE_HPP