File dataformat.hxx

Generic interface for file formats e.g. netCDF.

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

Author

B.Dudson

Date

April 2009

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/.

Functions

std::unique_ptr<DataFormat> data_format(const char *filename = nullptr)
class DataFormat

Subclassed by PncFormat

Public Functions

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

Sets a string attribute

Inputs

Parameters
  • varname[in] 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[in] Attribute name

  • text[in] A string attribute to attach to the variable

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

Sets an integer attribute

Inputs

Parameters
  • varname[in] 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[in] Attribute name

  • value[in] An int attribute to attach to the variable

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

Sets a BoutReal attribute

Inputs

Parameters
  • varname[in] 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[in] Attribute name

  • value[in] A BoutReal attribute to attach to the variable

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

Gets a string attribute

Inputs

Returns

text A string attribute of the variable

Parameters
  • varname[in] 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[in] Attribute name

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

Gets an integer attribute

Inputs

Returns

value An int attribute of the variable

Parameters
  • varname[in] 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[in] Attribute name

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

Gets a BoutReal attribute

Inputs

Returns

value A BoutReal attribute of the variable

Parameters
  • varname[in] 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[in] Attribute name

void writeFieldAttributes(const std::string &name, const Field &f, bool shiftOutput = false)

Write out the meta-data of a field as attributes of the variable.

void writeFieldAttributes(const std::string &name, const FieldPerp &f, bool shiftOutput)

Overload for FieldPerp so we can also write ‘yindex’.

void readFieldAttributes(const std::string &name, Field &f)

Read the attributes of a field.

void readFieldAttributes(const std::string &name, FieldPerp &f)

Overload for FieldPerp so we can also read ‘yindex’.

Protected Attributes

Mesh *mesh