File datafile.hxx

Data file handling object definition.

26th Sep 2009: Modified to use varargs

Author

B.Dudson

Date

April 2009

Defines

SAVE_ONCE1(var)

Write this variable once to the grid file.

SAVE_ONCE2(var1, var2)
SAVE_ONCE3(var1, var2, var3)
SAVE_ONCE4(var1, var2, var3, var4)
SAVE_ONCE5(var1, var2, var3, var4, var5)
SAVE_ONCE6(var1, var2, var3, var4, var5, var6)
SAVE_ONCE(...)
SAVE_REPEAT1(var)

Write this variable every timestep.

SAVE_REPEAT2(var1, var2)
SAVE_REPEAT3(var1, var2, var3)
SAVE_REPEAT4(var1, var2, var3, var4)
SAVE_REPEAT5(var1, var2, var3, var4, var5)
SAVE_REPEAT6(var1, var2, var3, var4, var5, var6)
SAVE_REPEAT(...)
class Datafile
#include <datafile.hxx>

Uses a generic interface to file formats (DataFormat) and provides an interface for reading/writing simulation data.

Public Functions

Datafile(Options *opt = nullptr, Mesh *mesh_in = nullptr)
Datafile(Datafile &&other) noexcept
~Datafile() = default
Datafile &operator=(Datafile &&rhs) noexcept
Datafile &operator=(const Datafile &rhs) = delete
bool openr(const std::string &filename)

Open read-only.

template<class S, class ...Args>
inline bool openr(const S &format, const Args&... args)
bool openw(const std::string &filename)

Overwrites existing file.

template<class S, class ...Args>
inline bool openw(const S &format, const Args&... args)
bool opena(const std::string &filename)

Appends if exists.

template<class S, class ...Args>
inline bool opena(const S &format, const Args&... args)
bool isValid()
void close()
void setLowPrecision()

Only output floats.

template<typename T>
inline void addRepeat(T &value, std::string name)
template<typename T>
inline void addOnce(T &value, std::string name)
void add(int &i, const char *name, bool save_repeat = false, const std::string &description = "")
void add(std::vector<int> &ivec, const char *name, bool save_repeat = false, const std::string &description = "")
void add(std::string &s, const char *name, bool save_repeat = false, const std::string &description = "")
void add(BoutReal &r, const char *name, bool save_repeat = false, const std::string &description = "")
void add(bool &b, const char *name, bool save_repeat = false, const std::string &description = "")
void add(Field2D &f, const char *name, bool save_repeat = false, const std::string &description = "")
void add(Field3D &f, const char *name, bool save_repeat = false, const std::string &description = "")
void add(FieldPerp &f, const char *name, bool save_repeat = false, const std::string &description = "")
void add(Vector2D &f, const char *name, bool save_repeat = false, const std::string &description = "")
void add(Vector3D &f, const char *name, bool save_repeat = false, const std::string &description = "")
bool read()

Read data into added variables.

bool write()

Write added variables.

bool write(const std::string &filename) const

Opens, writes, closes file.

template<typename S, typename ...Args>
inline bool write(const S &format, const Args&... args) const
void setAttribute(const std::string &varname, const std::string &attrname, const std::string &text)
void setAttribute(const std::string &varname, const std::string &attrname, int value)
void setAttribute(const std::string &varname, const std::string &attrname, BoutReal value)

Private Functions

Datafile(const Datafile &other)

Shallow copy, not including dataformat, therefore private.

bool read_f2d(const std::string &name, Field2D *f, bool save_repeat)
bool read_f3d(const std::string &name, Field3D *f, bool save_repeat)
bool read_fperp(const std::string &name, FieldPerp *f, bool save_repeat)
bool write_int(const std::string &name, int *f, bool save_repeat)
bool write_int_vec(const std::string &name, std::vector<int> *f, bool save_repeat)
bool write_string(const std::string &name, std::string *f, bool save_repeat)
bool write_real(const std::string &name, BoutReal *f, bool save_repeat)
bool write_f2d(const std::string &name, Field2D *f, bool save_repeat)
bool write_f3d(const std::string &name, Field3D *f, bool save_repeat)
bool write_fperp(const std::string &name, FieldPerp *f, bool save_repeat)
bool varAdded(const std::string &name)

Check if a variable has already been added.

void *varPtr(const std::string &name)

Get the pointer to the variable, nullptr if not added This is used to check if the same variable is being added

Private Members

Mesh *mesh
bool parallel = {false}
bool flush = {true}
bool guards = {true}
bool floats = {false}
bool openclose = {true}
int Lx
int Ly
int Lz
bool enabled = {true}
bool init_missing
bool shiftoutput = {false}
bool shiftinput = {false}
int flushFrequencyCounter = {0}
int flushfrequency = {1}
std::unique_ptr<DataFormat> file
std::string filename
bool writable = {false}
bool appending = {false}
bool first_time = {true}
std::vector<VarStr<int>> int_arr
std::vector<VarStr<std::vector<int>>> int_vec_arr
std::vector<VarStr<std::string>> string_arr
std::vector<VarStr<BoutReal>> BoutReal_arr
std::vector<VarStr<bool>> bool_arr
std::vector<VarStr<Field2D>> f2d_arr
std::vector<VarStr<Field3D>> f3d_arr
std::vector<VarStr<FieldPerp>> fperp_arr
std::vector<VarStr<Vector2D>> v2d_arr
std::vector<VarStr<Vector3D>> v3d_arr
template<class T>
struct VarStr

A structure to hold a pointer to a class, and associated name and flags.

Public Members

T *ptr

Pointer to the data. Note that this may be a user object, not a copy, so must not be destroyed

std::string name

Name as it appears in the output file.

bool save_repeat

If true, has a time dimension and is saved every time step.

bool covar

For vectors, true if a covariant vector, false if contravariant.

size_t size

Size of a stored vector or string, to check it does not change after being added.

std::string description = {""}

Documentation of what the variable is.