Skip to content

Class mgrid::NcWriter

ClassList > mgrid > NcWriter

Incremental writer for a gridded solution file (netCDF-4). More...

  • #include <netcdf_writer.hpp>

Public Functions

Type Name
NcWriter (const std::string & path, int nx, int nz, double hx, double hz)
Opens path (replacing any existing file) and writes thex /z axis coordinate variables.
NcWriter (const NcWriter &) = delete
void add_attribute (const std::string & name, double value)
Adds a scalar double global attribute.
void add_variable (const std::string & name, const Field2D & field)
Adds a 2-D double variable over (x ,z ) and writes it.
NcWriter & operator= (const NcWriter &) = delete
~NcWriter ()
Flushes and closes the file.

Detailed Description

Construction opens the target path (replacing any existing file), defines the x/z dimensions and fills the 1-D axis coordinate variables. Callers then add 2-D field variables with add_variable() and scalar globals with add_attribute(); the file is flushed and closed when the writer is destroyed.

Public Functions Documentation

function NcWriter [1/2]

Opens path (replacing any existing file) and writes thex /z axis coordinate variables.

mgrid::NcWriter::NcWriter (
    const std::string & path,
    int nx,
    int nz,
    double hx,
    double hz
) 

Parameters:

  • path full output path (the caller has already appended .nc).
  • nx number of grid points in x (rows); becomes dim x.
  • nz number of grid points in z (columns); becomes dim z.
  • hx grid spacing in x; axis var "x" is filled with i * hx.
  • hz grid spacing in z; axis var "z" is filled with j * hz.

Exception:

  • propagates the underlying netCDF-C++ exception (a std::exception) on any failure.

function NcWriter [2/2]

mgrid::NcWriter::NcWriter (
    const NcWriter &
) = delete

function add_attribute

Adds a scalar double global attribute.

void mgrid::NcWriter::add_attribute (
    const std::string & name,
    double value
) 

Parameters:

  • name attribute name.
  • value attribute value.

Exception:

  • propagates the underlying netCDF-C++ exception on failure.

function add_variable

Adds a 2-D double variable over (x ,z ) and writes it.

void mgrid::NcWriter::add_variable (
    const std::string & name,
    const Field2D & field
) 

Parameters:

  • name variable name.
  • field values, row-major; field.data() is written verbatim.

Exception:

  • propagates the underlying netCDF-C++ exception on failure.

function operator=

NcWriter & mgrid::NcWriter::operator= (
    const NcWriter &
) = delete

function ~NcWriter

Flushes and closes the file.

mgrid::NcWriter::~NcWriter () 



The documentation for this class was generated from the following file include/multigrid/netcdf_writer.hpp