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)
~Datafile()
Datafile &operator=(Datafile &&rhs)
Datafile &operator=(const Datafile &rhs)
bool openr(const char *filename, ...)
bool openw(const char *filename, ...)
bool opena(const char *filename, ...)
bool isValid()
void close()
void setLowPrecision()

Only output floats.

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

Read data into added variables.

bool write()

Write added variables.

bool write(const char *filename, ...) const

Opens, writes, closes file.

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_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
size_t filenamelen
char *filename
bool writable = {false}
bool appending = {false}
bool first_time = {true}
std::vector<VarStr<int>> int_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

Private Static Attributes

const size_t FILENAMELEN = 512
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.