Skip to content

C++ Binout

PucklaJ edited this page Apr 12, 2023 · 1 revision

Binout - C++

Back to Home

dro::Binout

This class is used to open and read data from a binout file (or multiple files by globbing)

Constructor

Binout(const std::filesystem::path &file_name);

Open a binout file (or multiple files by globbing) and parse its records to be ready to read data.

  • file_name The path to the binout file or glob pattern

read

template <typename T> Array<T> read(const std::string &path_to_variable);

Read data from the file. The type id of the data has to match T. All string values inside a binout are usually INT8 (int8_t).

  • path_to_variable The path to the variable inside the binout (e.g. /nodout/metadata/ids)

read_timed

template <typename T> std::vector<Array<T>> read_timed(const std::string &variable);

Read a variable under the dxxxxxx folders as either float or double. The type id of the data has to match. This functions reads all timesteps of a variable at once. If the actual variable is something like /nodout/d00000/x_displacement then the variable has to be /nodout/x_displacement. The shape of the array is num_timesteps * num_values which means to get a value you need to index like [timestep][value].

  • variable The path to the timed variable in the binout (e.g. /nodout/x_displacement)

get_type_id

BinoutType get_type_id(const std::string &path_to_variable) const;

Returns the type id of the given variable. The type id is one of dro::BinoutType.

  • path_to_variable The path to the variable inside the binout (e.g. /nodout/metadata/ids)

variable_exists

bool variable_exists(const std::string &path_to_variable) const noexcept;

Returns whether a record with the given path and variable name exists.

  • path_to_variable The path to the variable inside the binout (e.g. /nodout/metadata/ids)

get_children

std::vector<String> get_children(const std::string &path) const;

Returns the entries under a given path.

  • path The path to a folder inside the binout (e.g. /nodout)

get_num_timesteps

size_t get_num_timesteps(const std::string &path) const;

Returns the number of dxxxxxx folders inside of a given path. Each folder inside a binout can have a different number of time steps. This method is used to get the time steps of one single folder (e.g. /nodout or /rcforc).

  • path The path to a folder inside the binout (e.g. /nodout or /rcforc)

get_handle

binout_file &get_handle() noexcept;
const binout_file &get_handle() const noexcept;

Returns the underlying C binout_file.

simple_path_to_real

std::string simple_path_to_real(const std::string &simple,
                                BinoutType &type_id, bool &timed) const;

This takes a path that without metadata or dxxxxxx in and converts it into a path which can be given to the read and read_timed functions. Returns the path that points to the correct file or throws an exception if the file does not exist or the path is invalid. timed will be set to false if it's a file of metadata and to true if it's a file of on of the dxxxxxx folders which means that the returned path should be given to the read_timed function. type_id will be set to the correct type id of the file.

  • simple The simple path without metadata or dxxxxxx in it
  • type_id Will be written with the type of the data
  • timed Will be set to false or true wether it is data that goes over multiple time steps

Back to Home

Clone this wiki locally