3#include "ncException.h"
25 cerr << e.what() << endl;
32 ncCheck(nc_close(myId),__FILE__,__LINE__);
46 open(filePath, fMode);
52 open(filePath, ncFileFlags);
61void NcFile::open(
const string& filePath,
int ncFileFlags) {
65 ncCheck(nc_open(filePath.c_str(), ncFileFlags, &myId),__FILE__,__LINE__);
72void NcFile::open(
const string& filePath,
const FileMode fMode)
82 ncCheck(nc_open(filePath.c_str(), NC_WRITE, &myId),__FILE__,__LINE__);
85 ncCheck(nc_open(filePath.c_str(), NC_NOWRITE, &myId),__FILE__,__LINE__);
88 ncCheck(nc_create(filePath.c_str(), NC_NETCDF4 | NC_NOCLOBBER, &myId),__FILE__,__LINE__);
91 ncCheck(nc_create(filePath.c_str(), NC_NETCDF4 | NC_CLOBBER, &myId),__FILE__,__LINE__);
100NcFile::NcFile(
const string& filePath,
const FileMode fMode,
const FileFormat fFormat )
102 open(filePath, fMode, fFormat);
114 ncCheck(nc_create(filePath.c_str(),ncFileFlags,&myId),__FILE__,__LINE__);
120void NcFile::open(
const string& filePath,
const FileMode fMode,
const FileFormat fFormat )
132 format = NC_64BIT_OFFSET;
138 format = NC_NETCDF4 | NC_CLASSIC_MODEL;
144 ncCheck(nc_open(filePath.c_str(), format | NC_WRITE, &myId),__FILE__,__LINE__);
147 ncCheck(nc_open(filePath.c_str(), format | NC_NOWRITE, &myId),__FILE__,__LINE__);
150 ncCheck(nc_create(filePath.c_str(), format | NC_NOCLOBBER, &myId),__FILE__,__LINE__);
153 ncCheck(nc_create(filePath.c_str(), format | NC_CLOBBER, &myId),__FILE__,__LINE__);
162 ncCheck(nc_sync(myId),__FILE__,__LINE__);
166 ncCheck(nc_set_fill(myId, fillmode, old_modep),__FILE__,__LINE__);
172 ncCheck(nc_redef(myId),__FILE__,__LINE__);
177 ncCheck(nc_enddef(myId),__FILE__,__LINE__);
180string NcFile::getPath()
const
183 ncCheck(nc_inq_path(myId, &pathLength, NULL),__FILE__,__LINE__);
185 vector<char> pathCString(pathLength + 1);
186 ncCheck(nc_inq_path(myId, NULL, pathCString.data()),__FILE__,__LINE__);
188 return string(pathCString.data());
NcFile()
Constructor generates a null object.
void sync()
Synchronize an open netcdf dataset to disk.
void enddef()
Leave define mode, used for classic model.
void set_Fill(int fillmode, int *old_modep)
Elect a fill parameter different that the one currently being used.
void create(const std::string &filePath, const int ncFileFlags)
Create a netCDF file.
@ newFile
Create new file, fail if already exists.
@ read
File exists, open read-only.
@ write
File exists, open for writing.
@ replace
Create new file, even if already exists.
void open(const std::string &filePath, int ncFileFlags)
Opens a netCDF file.
void close()
Close a file before destructor call.
virtual ~NcFile()
destructor
void redef()
Redefine variable.
@ classic
Classic format, classic data model.
@ classic64
64-bit offset format, classic data model
@ nc4
(default) netCDF-4/HDF5 format, enhanced data model
@ nc4classic
netCDF-4/HDF5 format, classic data model
NcGroup()
Constructor generates a null object.
bool nullObject
assignment operator
Base object is thrown if a netCDF exception is encountered.
void ncCheck(int retCode, const char *file, int line)
Function checks error code and if necessary throws an exception.