File h5_format.hxx

HDF5 data format interface.

Records: In netCDF, the time dimension for each dimension must be the same. Hence when a record is appended to a variable, the size of all variables is increased. To work out which record to write to, a map of variable names to record number is kept.

Author
John Omotani
Date
2015

Copyright 2010 B.D.Dudson, S.Farley, M.V.Umansky, X.Q.Xu

Contact: Ben Dudson, bd512@york.ac.uk

This file is part of BOUT++.

BOUT++ is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

BOUT++ 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 Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with BOUT++. If not, see http://www.gnu.org/licenses/.

class H5Format : public DataFormat

Public Functions

H5Format(bool parallel_in = false, Mesh *mesh_in = nullptr)
H5Format(const char *name, bool parallel_in = false, Mesh *mesh_in = nullptr)
H5Format(const std::string &name, bool parallel_in = false, Mesh *mesh_in = nullptr)
~H5Format()
bool openr(const char *name)
bool openw(const char *name, bool append = false)
bool is_valid()
void close()
void flush()
const char *filename()
const std::vector<int> getSize(const char *var)
const std::vector<int> getSize(const std::string &var)
bool setGlobalOrigin(int x = 0, int y = 0, int z = 0)
bool setLocalOrigin(int x = 0, int y = 0, int z = 0, int offset_x = 0, int offset_y = 0, int offset_z = 0)
bool setRecord(int t)
bool addVarInt(const std::string &name, bool repeat)
bool addVarBoutReal(const std::string &name, bool repeat)
bool addVarField2D(const std::string &name, bool repeat)
bool addVarField3D(const std::string &name, bool repeat)
bool addVarFieldPerp(const std::string &name, bool repeat)
bool read(int *var, const char *name, int lx = 1, int ly = 0, int lz = 0)
bool read(int *var, const std::string &name, int lx = 1, int ly = 0, int lz = 0)
bool read(BoutReal *var, const char *name, int lx = 1, int ly = 0, int lz = 0)
bool read(BoutReal *var, const std::string &name, int lx = 1, int ly = 0, int lz = 0)
bool read_perp(BoutReal *var, const std::string &name, int lx = 1, int lz = 0)
bool write(int *var, const char *name, int lx = 0, int ly = 0, int lz = 0)
bool write(int *var, const std::string &name, int lx = 0, int ly = 0, int lz = 0)
bool write(BoutReal *var, const char *name, int lx = 0, int ly = 0, int lz = 0)
bool write(BoutReal *var, const std::string &name, int lx = 0, int ly = 0, int lz = 0)
bool write_perp(BoutReal *var, const std::string &name, int lx = 0, int lz = 0)
bool read_rec(int *var, const char *name, int lx = 1, int ly = 0, int lz = 0)
bool read_rec(int *var, const std::string &name, int lx = 1, int ly = 0, int lz = 0)
bool read_rec(BoutReal *var, const char *name, int lx = 1, int ly = 0, int lz = 0)
bool read_rec(BoutReal *var, const std::string &name, int lx = 1, int ly = 0, int lz = 0)
bool read_rec_perp(BoutReal *var, const std::string &name, int lx = 1, int lz = 0)
bool write_rec(int *var, const char *name, int lx = 0, int ly = 0, int lz = 0)
bool write_rec(int *var, const std::string &name, int lx = 0, int ly = 0, int lz = 0)
bool write_rec(BoutReal *var, const char *name, int lx = 0, int ly = 0, int lz = 0)
bool write_rec(BoutReal *var, const std::string &name, int lx = 0, int ly = 0, int lz = 0)
bool write_rec_perp(BoutReal *var, const std::string &name, int lx = 0, int lz = 0)
void setLowPrecision()
void setAttribute(const std::string &varname, const std::string &attrname, const std::string &text)

Sets a string attribute

Inputs

Parameters
  • varname: Variable name. The variable must already exist. If varname is the empty string “” then the attribute will be added to the file instead of to a variable.
  • attrname: Attribute name
  • text: A string attribute to attach to the variable

void setAttribute(const std::string &varname, const std::string &attrname, int value)

Sets an integer attribute

Inputs

Parameters
  • varname: Variable name. The variable must already exist. If varname is the empty string “” then the attribute will be added to the file instead of to a variable.
  • attrname: Attribute name
  • value: An int attribute to attach to the variable

void setAttribute(const std::string &varname, const std::string &attrname, BoutReal value)

Sets a BoutReal attribute

Inputs

Parameters
  • varname: Variable name. The variable must already exist. If varname is the empty string “” then the attribute will be added to the file instead of to a variable.
  • attrname: Attribute name
  • value: A BoutReal attribute to attach to the variable

bool getAttribute(const std::string &varname, const std::string &attrname, std::string &text)

Gets a string attribute

Inputs

Returns

Parameters
  • varname: Variable name. The variable must already exist. If varname is the empty string “” then get the attribute from the top-level of the file instead of from a variable.
  • attrname: Attribute name

text A string attribute of the variable

bool getAttribute(const std::string &varname, const std::string &attrname, int &value)

Gets an integer attribute

Inputs

Returns

Parameters
  • varname: Variable name. The variable must already exist. If varname is the empty string “” then get the attribute from the top-level of the file instead of from a variable.
  • attrname: Attribute name

value An int attribute of the variable

bool getAttribute(const std::string &varname, const std::string &attrname, BoutReal &value)

Gets a BoutReal attribute

Inputs

Returns

Parameters
  • varname: Variable name. The variable must already exist. If varname is the empty string “” then get the attribute from the top-level of the file instead of from a variable.
  • attrname: Attribute name

value A BoutReal attribute of the variable

Private Functions

bool addVar(const std::string &name, bool repeat, hid_t write_hdf5_type, std::string datatype)
bool read(void *var, hid_t hdf5_type, const char *name, int lx = 1, int ly = 0, int lz = 0)
bool write(void *var, hid_t mem_hdf5_type, const char *name, int lx = 0, int ly = 0, int lz = 0)
bool read_rec(void *var, hid_t hdf5_type, const char *name, int lx = 1, int ly = 0, int lz = 0)
bool write_rec(void *var, hid_t mem_hdf5_type, const char *name, int lx = 0, int ly = 0, int lz = 0)
void setAttribute(const hid_t &dataSet, const std::string &attrname, const std::string &text)
void setAttribute(const hid_t &dataSet, const std::string &attrname, int value)
void setAttribute(const hid_t &dataSet, const std::string &attrname, BoutReal value)
bool getAttribute(const hid_t &dataSet, const std::string &attrname, std::string &text)
bool getAttribute(const hid_t &dataSet, const std::string &attrname, int &value)
bool getAttribute(const hid_t &dataSet, const std::string &attrname, BoutReal &value)

Private Members

char *fname

Current file name.

hid_t dataFile
hid_t dataFile_plist
hid_t dataSet_plist
bool lowPrecision

When writing, down-convert to floats.

bool parallel
int x0
int y0
int z0
int t0

Data origins for file access.

int x0_local
int y0_local
int z0_local

Data origins for memory access.

hsize_t chunk_length