Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Epoch time #1287

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
242 changes: 123 additions & 119 deletions Source/IO/NCInterface.H
Original file line number Diff line number Diff line change
Expand Up @@ -58,120 +58,128 @@ struct NCVar
const int varid;

//! Name of this variable
[[nodiscard]] std::string name() const;
[[nodiscard]] std::string name () const;

//! Number of array dimensions for this variable
[[nodiscard]] int ndim() const;
[[nodiscard]] int ndim () const;

//! Shape of the array (size in each array dimension)
[[nodiscard]] std::vector<size_t> shape() const;
[[nodiscard]] std::vector<size_t> shape () const;

//! Write out the entire variable
void put(const double*) const;
void put(const float*) const;
void put(const int*) const;
void put (const double*) const;
void put (const float*) const;
void put (const int*) const;

//! Write out a slice of data
void
put(const double*,
const std::vector<size_t>&,
const std::vector<size_t>&) const;
put (const double*,
const std::vector<size_t>&,
const std::vector<size_t>&) const;

//! Write out a slice of data with with strides (see hyperslab definition in
//! NetCDF)
void
put(const double*,
const std::vector<size_t>&,
const std::vector<size_t>&,
const std::vector<ptrdiff_t>&) const;
put (const double*,
const std::vector<size_t>&,
const std::vector<size_t>&,
const std::vector<ptrdiff_t>&) const;
//! Write out a slice of data
void
put(const float*,
const std::vector<size_t>&,
const std::vector<size_t>&) const;
put (const float*,
const std::vector<size_t>&,
const std::vector<size_t>&) const;

//! Write out a slice of data with with strides (see hyperslab definition in
//! NetCDF)
void
put(const float*,
const std::vector<size_t>&,
const std::vector<size_t>&,
const std::vector<ptrdiff_t>&) const;
put (const float*,
const std::vector<size_t>&,
const std::vector<size_t>&,
const std::vector<ptrdiff_t>&) const;

void put (const int*, const std::vector<size_t>&, const std::vector<size_t>&) const;

void put(const int*, const std::vector<size_t>&, const std::vector<size_t>&) const;
void
put(const int*,
const std::vector<size_t>&,
const std::vector<size_t>&,
const std::vector<ptrdiff_t>&) const;
put (const int*,
const std::vector<size_t>&,
const std::vector<size_t>&,
const std::vector<ptrdiff_t>&) const;

void put (const char**, const std::vector<size_t>&, const std::vector<size_t>&) const;

void put(const char**, const std::vector<size_t>&, const std::vector<size_t>&) const;
void
put(
const char** dptr,
const std::vector<size_t>& start,
const std::vector<size_t>& count,
const std::vector<ptrdiff_t>& stride) const;
put (const char** dptr,
const std::vector<size_t>& start,
const std::vector<size_t>& count,
const std::vector<ptrdiff_t>& stride) const;

//! Read the entire variable from file
void get(double*) const;
void get(float*) const;
void get(int*) const;
void get (double*) const;
void get (float*) const;
void get (int*) const;

//! Read a chunk of data from the file
void
get(double*, const std::vector<size_t>&, const std::vector<size_t>&) const;
get (double*, const std::vector<size_t>&, const std::vector<size_t>&) const;

//! Read a chunk of data with strides
void
get(double*,
const std::vector<size_t>&,
const std::vector<size_t>&,
const std::vector<ptrdiff_t>&) const;
get (double*,
const std::vector<size_t>&,
const std::vector<size_t>&,
const std::vector<ptrdiff_t>&) const;

//! Read a chunk of data from the file
void
get(float*, const std::vector<size_t>&, const std::vector<size_t>&) const;
get (float*, const std::vector<size_t>&, const std::vector<size_t>&) const;

//! Read a chunk of data with strides
void
get(float*,
const std::vector<size_t>&,
const std::vector<size_t>&,
const std::vector<ptrdiff_t>&) const;
get (float*,
const std::vector<size_t>&,
const std::vector<size_t>&,
const std::vector<ptrdiff_t>&) const;

void
get(int*, const std::vector<size_t>&, const std::vector<size_t>&) const;
get (int*, const std::vector<size_t>&, const std::vector<size_t>&) const;

void
get(int*,
const std::vector<size_t>&,
const std::vector<size_t>&,
const std::vector<ptrdiff_t>&) const;
get (int*,
const std::vector<size_t>&,
const std::vector<size_t>&,
const std::vector<ptrdiff_t>&) const;

//! Read a chunk of data from the file
void
get(char*, const std::vector<size_t>&, const std::vector<size_t>&) const;
get (char*, const std::vector<size_t>&, const std::vector<size_t>&) const;

//! Read a chunk of data with strides
void
get(char*,
const std::vector<size_t>&,
const std::vector<size_t>&,
const std::vector<ptrdiff_t>&) const;
get (char*,
const std::vector<size_t>&,
const std::vector<size_t>&,
const std::vector<ptrdiff_t>&) const;

[[nodiscard]] bool has_attr (const std::string& name) const;

void put_attr (const std::string& name, const std::string& value) const;

[[nodiscard]] bool has_attr(const std::string& name) const;
void put_attr(const std::string& name, const std::string& value) const;
void
put_attr(const std::string& name, const std::vector<double>& value) const;
put_attr (const std::string& name, const std::vector<double>& value) const;

void
put_attr(const std::string& name, const std::vector<float>& value) const;
void put_attr(const std::string& name, const std::vector<int>& value) const;

[[nodiscard]] std::string get_attr(const std::string& name) const;
void get_attr(const std::string& name, std::vector<double>& value) const;
void get_attr(const std::string& name, std::vector<float>& value) const;
void get_attr(const std::string& name, std::vector<int>& value) const;
void par_access(int cmode) const; //Uncomment for parallel NetCDF
put_attr (const std::string& name, const std::vector<float>& value) const;

void put_attr (const std::string& name, const std::vector<int>& value) const;

[[nodiscard]] std::string get_attr (const std::string& name) const;

void get_attr (const std::string& name, std::vector<double>& value) const;
void get_attr (const std::string& name, std::vector<float>& value) const;
void get_attr (const std::string& name, std::vector<int>& value) const;

void par_access (int cmode) const; //Uncomment for parallel NetCDF
};

//! Representation of a NetCDF group
Expand All @@ -182,99 +190,97 @@ public:
const int ncid;

//! Name of this group
[[nodiscard]] std::string name() const;
[[nodiscard]] std::string name () const;

//! Full name for this group
[[nodiscard]] std::string full_name() const;
[[nodiscard]] std::string full_name () const;

//! Number of sub-groups within this group
[[nodiscard]] int num_groups() const;
[[nodiscard]] int num_groups () const;

//! Number of dimensions in this group
[[nodiscard]] int num_dimensions() const;
[[nodiscard]] int num_dimensions () const;

//! Number of variables within this group
[[nodiscard]] int num_variables() const;
[[nodiscard]] int num_variables () const;

//! Number of attributes within this group
[[nodiscard]] int num_attributes() const;
[[nodiscard]] int num_attributes () const;

//! Check if a group exists
[[nodiscard]] bool has_group(const std::string&) const;
[[nodiscard]] bool has_group (const std::string&) const;

//! Check if a dimension exists by name
[[nodiscard]] bool has_dim(const std::string&) const;
[[nodiscard]] bool has_dim (const std::string&) const;

//! Check if a variable exists by name
[[nodiscard]] bool has_var(const std::string&) const;
[[nodiscard]] bool has_var (const std::string&) const;

//! Check if an attribute exists
[[nodiscard]] bool has_attr(const std::string&) const;
[[nodiscard]] bool has_attr (const std::string&) const;

/** Get the group by name
*
* Throws error if the group doesn't exist, use `has_group` to check
*/
[[nodiscard]] NCGroup group(const std::string&) const;
[[nodiscard]] NCGroup group (const std::string&) const;

//! Get the dimension instance by name
[[nodiscard]] NCDim dim(const std::string&) const;
[[nodiscard]] NCDim dim (const std::string&) const;

//! Get the variable instance by name
[[nodiscard]] NCVar var(const std::string&) const;
[[nodiscard]] NCVar var (const std::string&) const;

//! Define new group
[[nodiscard]] NCGroup def_group(const std::string&) const;
[[nodiscard]] NCGroup def_group (const std::string&) const;

//! Define new dimension
[[nodiscard]] NCDim def_dim(const std::string&, size_t len) const;
[[nodiscard]] NCDim def_dim (const std::string&, size_t len) const;

//! Define a scalar variable, i.e., 0-dimensional array
[[nodiscard]] NCVar def_scalar(const std::string& name, nc_type dtype) const;
[[nodiscard]] NCVar def_scalar (const std::string& name, nc_type dtype) const;

//! Define an array
[[nodiscard]] NCVar def_array(
const std::string& name,
nc_type dtype,
const std::vector<std::string>&) const;
[[nodiscard]] NCVar def_array (const std::string& name,
nc_type dtype,
const std::vector<std::string>&) const;

//! Define a variable (wrapper for def_array)
[[nodiscard]] NCVar def_var(
const std::string& name,
const nc_type dtype,
const std::vector<std::string>& dnames) const
[[nodiscard]] NCVar def_var (const std::string& name,
const nc_type dtype,
const std::vector<std::string>& dnames) const
{
return def_array(name, dtype, dnames);
}

void put_attr(const std::string& name, const std::string& value) const;
void put_attr(const std::string& name, const std::vector<double>& value) const;
void put_attr(const std::string& name, const std::vector<float>& value) const;
void put_attr(const std::string& name, const std::vector<int>& value) const;
void put_attr (const std::string& name, const std::string& value) const;
void put_attr (const std::string& name, const std::vector<double>& value) const;
void put_attr (const std::string& name, const std::vector<float>& value) const;
void put_attr (const std::string& name, const std::vector<int>& value) const;

[[nodiscard]] std::string get_attr(const std::string& name) const;
void get_attr(const std::string& name, std::vector<double>& value) const;
void get_attr(const std::string& name, std::vector<float>& value) const;
void get_attr(const std::string& name, std::vector<int>& value) const;
[[nodiscard]] std::string get_attr (const std::string& name) const;
void get_attr (const std::string& name, std::vector<double>& value) const;
void get_attr (const std::string& name, std::vector<float>& value) const;
void get_attr (const std::string& name, std::vector<int>& value) const;

//! Return a list of all groups defined in this group
[[nodiscard]] std::vector<NCGroup> all_groups() const;
[[nodiscard]] std::vector<NCGroup> all_groups () const;

//! Return a list of all dimensions defined in this group
[[nodiscard]] std::vector<NCDim> all_dims() const;
[[nodiscard]] std::vector<NCDim> all_dims () const;

//! Return a list of all variables defined in this group
[[nodiscard]] std::vector<NCVar> all_vars() const;
[[nodiscard]] std::vector<NCVar> all_vars () const;

//! Enter definition mode (not needed for NetCDF4 format)
void enter_def_mode() const;
void enter_def_mode () const;

//! Exit definition mode
void exit_def_mode() const;
void exit_def_mode () const;

protected:
NCGroup(const int id) : ncid(id) {}
NCGroup(const int id, const NCGroup* /*par*/) : ncid(id) {}
NCGroup (const int id) : ncid(id) {}
NCGroup (const int id, const NCGroup* /*par*/) : ncid(id) {}
};

/** Representation of a NetCDF file
Expand All @@ -285,28 +291,26 @@ class NCFile : public NCGroup
{
public:
static NCFile
create(const std::string& name, const int cmode = NC_CLOBBER | NC_NETCDF4);
create (const std::string& name, const int cmode = NC_CLOBBER | NC_NETCDF4);

static NCFile open(const std::string& name, const int cmode = NC_NOWRITE);
static NCFile open (const std::string& name, const int cmode = NC_NOWRITE);

static NCFile create_par(
const std::string& name,
const int cmode = NC_CLOBBER | NC_NETCDF4 | NC_MPIIO,
MPI_Comm comm = MPI_COMM_WORLD,
MPI_Info info = MPI_INFO_NULL);
static NCFile create_par (const std::string& name,
const int cmode = NC_CLOBBER | NC_NETCDF4 | NC_MPIIO,
MPI_Comm comm = MPI_COMM_WORLD,
MPI_Info info = MPI_INFO_NULL);

static NCFile open_par(
const std::string& name,
const int cmode = NC_NOWRITE,
MPI_Comm comm = MPI_COMM_WORLD,
MPI_Info info = MPI_INFO_NULL);
static NCFile open_par (const std::string& name,
const int cmode = NC_NOWRITE,
MPI_Comm comm = MPI_COMM_WORLD,
MPI_Info info = MPI_INFO_NULL);

~NCFile();
~NCFile ();

void close();
void close ();

protected:
NCFile(const int id) : NCGroup(id), is_open{true} {}
NCFile (const int id) : NCGroup(id), is_open{true} {}

bool is_open{false};
};
Expand Down
Loading
Loading