17 const MPI_Comm* comm,
bool multifile,
const StdString& timeCounterName)
20 , useClassicFormat(useClassicFormat)
21 , useCFConvention(useCFConvention)
23 this->
initialize(filename, append, useClassicFormat, useCFConvention, comm, multifile, timeCounterName);
35 const MPI_Comm* comm,
bool multifile,
const StdString& timeCounterName)
40 int mode = useClassicFormat ? 0 : NC_NETCDF4;
46 MPI_Comm_size(*comm, &commSize);
50 wmpi = comm && !multifile;
53 mode |= useClassicFormat ? NC_PNETCDF : NC_MPIIO;
56 if (!append || !std::ifstream(filename.c_str()))
119 int retvalue = this->
ncidp;
121 CONetCDF4Path::const_iterator it = path.begin(), end = path.end();
123 for (; it != end; it++)
177 std::vector<StdSize> retvalue;
180 int nbdim = 0, *dimid = NULL;
183 dimid =
new int[nbdim]();
186 for (
int i = 0; i < nbdim; i++)
189 if (size == NC_UNLIMITED)
191 retvalue.push_back(size);
200 int nbdim = 0, *dimid = NULL;
202 int varid = (_varname != NULL) ? this->
getVariable(*_varname) : NC_GLOBAL;
203 std::vector<std::string> retvalue;
205 if (_varname != NULL)
208 dimid =
new int[nbdim]();
214 dimid =
new int[nbdim]();
218 for (
int i = 0; i < nbdim; i++)
222 retvalue.push_back(dimname);
236 std::vector<StdSize> start(2),
count(2);
239 int ncUnlimitedDimId;
245 timeAxisBounds.
resize(count[1], count[0]);
247 if (this->
wmpi && collective)
249 if (this->
wmpi && !collective)
260 std::vector<StdSize> start(2),
count(2);
266 timeAxisBounds.
resize(2, 1);
268 if (this->
wmpi && collective)
270 if (this->
wmpi && !collective)
279 {
return this->
path; }
282 { this->path =
path; }
310 const std::vector<StdString>& dim,
int compressionLevel)
313 std::vector<int> dimids;
314 std::vector<StdSize> dimsizes;
315 int dimSize = dim.size();
319 StdSize maxSize = 1024 * 1024 * 256;
323 std::vector<StdString>::const_iterator it = dim.begin(), end = dim.end();
325 for (
int idx = 0; it != end; it++, ++idx)
330 if (size == NC_UNLIMITED) size = 1;
331 dimsizes.push_back(size);
342 for (vector<StdSize>::reverse_iterator it = dimsizes.rbegin(); it != dimsizes.rend(); ++it)
345 if (totalSize >= maxSize) *it = 1;
347 int storageType = (0 == dimSize) ? NC_CONTIGUOUS : NC_CHUNKED;
361 if (compressionLevel < 0 || compressionLevel > 9)
362 ERROR(
"void CONetCDF4::setCompressionLevel(const StdString& varname, int compressionLevel)",
363 "Invalid compression level for variable \"" << varname <<
"\", the value should range between 0 and 9.");
364 if (compressionLevel &&
wmpi)
365 ERROR(
"void CONetCDF4::setCompressionLevel(const StdString& varname, int compressionLevel)",
366 "Impossible to use compression for variable \"" << varname <<
"\" when using parallel mode.");
379 int varid = (varname == NULL) ? NC_GLOBAL : this->
getVariable(*varname);
389 int varid = (varname == NULL) ? NC_GLOBAL : this->
getVariable(*varname);
397 int varid = (varname == NULL) ? NC_GLOBAL : this->
getVariable(*varname);
406 int varid = (varname == NULL) ? NC_GLOBAL : this->
getVariable(*varname);
414 int varid = (varname == NULL) ? NC_GLOBAL : this->
getVariable(*varname);
424 int varid = (varname == NULL) ? NC_GLOBAL : this->
getVariable(*varname);
432 int varid = (varname == NULL) ? NC_GLOBAL : this->
getVariable(*varname);
440 int varid = (varname == NULL) ? NC_GLOBAL : this->
getVariable(*varname);
448 int varid = (varname == NULL) ? NC_GLOBAL : this->
getVariable(*varname);
456 int varid = (varname == NULL) ? NC_GLOBAL : this->
getVariable(*varname);
464 int varid = (varname == NULL) ? NC_GLOBAL : this->
getVariable(*varname);
471 std::vector<StdSize>& sstart,
472 std::vector<StdSize>& scount,
473 const std::vector<StdSize>* start,
474 const std::vector<StdSize>*
count)
486 std::vector<std::size_t>::const_iterator
487 it = sizes.begin(), end = sizes.end();
492 sstart.push_back(record);
494 if ((start == NULL) &&
495 (count == NULL)) i++;
499 for (;it != end; it++)
501 if ((start != NULL) && (count != NULL))
503 sstart.push_back((*start)[i]);
504 scount.push_back((*count)[i]);
505 array_size *= (*count)[i];
511 scount.push_back(sizes[i]);
512 array_size *= sizes[i];
523 const std::vector<StdSize>& sstart,
524 const std::vector<StdSize>& scount,
const double* data)
533 const std::vector<StdSize>& sstart,
534 const std::vector<StdSize>& scount,
char* data)
542 const std::vector<StdSize>& sstart,
543 const std::vector<StdSize>& scount,
const int* data)
551 const std::vector<StdSize>& sstart,
552 const std::vector<StdSize>& scount,
const float* data)
564 std::vector<StdSize> sstart, scount;
568 this->
writeData_(grpid, varid, sstart, scount, data.dataFirst());
573 bool collective,
StdSize record,
bool isRoot)
578 map<int,size_t>::iterator it=
timeAxis.find(varid);
582 if (it->second >= record)
return;
583 else it->second =record;
587 std::vector<StdSize> sstart, scount;
589 if (this->
wmpi && collective)
591 if (this->
wmpi && !collective)
595 this->
writeData_(grpid, varid, sstart, scount, data.dataFirst());
599 bool collective,
StdSize record,
bool isRoot)
604 map<int,size_t>::iterator it=
timeAxis.find(varid);
608 if (it->second >= record)
return;
609 else it->second =record;
613 std::vector<StdSize> sstart, scount;
615 if (this->
wmpi && collective)
617 if (this->
wmpi && !collective)
621 this->
writeData_(grpid, varid, sstart, scount, data.dataFirst());
static int defVarChunking(int ncid, int varId, int storage, StdSize chunkSize[])
Define variable chunking size.
const CONetCDF4Path & getCurrentPath(void) const
Accesseur ///.
bool dimExist(const StdString &dimname)
static int putAttType(int ncid, int varid, const StdString &attrName, StdSize numVal, const T *data)
Set an attribute.
static int reDef(int ncId)
Put netcdf file into define mode.
static int setFill(int ncid, bool fill)
Set or unset the fill mode.
static int openPar(const StdString &path, int cmode, MPI_Comm comm, MPI_Info info, int &ncId)
Open a netcdf file.
std::vector< StdString > CONetCDF4Path
Définition de type ///.
static int endDef(int ncId)
End define mode of a netcdf file.
static int inqDimId(int ncid, const StdString &dimName, int &dimId)
Query identity of a named dimension.
int getVariable(const StdString &varname)
Wrapper of netcdf functions.
map< int, size_t > timeAxis
std::vector< StdSize > getDimensions(const StdString &varname)
virtual ~CONetCDF4(void)
Destructeur ///.
static int close(int ncId)
Close a netcdf file.
static int inqUnLimDim(int ncid, int &dimId)
Query identity of unlimited dimension.
CONetCDF4Path path
Propriétés privées ///.
bool useCFConvention
If true data is written in the CF convention otherwise in UGRID.
static int putVaraType(int ncid, int varid, const StdSize *start, const StdSize *count, const T *data)
Set data for a variable.
void getTimeAxisBounds(CArray< double, 2 > &timeAxisBounds, const StdString &name, bool collective)
int getCurrentGroup(void)
Accesseurs ///.
void addAttribute(const StdString &name, const T &value, const StdString *varname=NULL)
void writeTimeAxisData(const CArray< double, 1 > &data, const StdString &name, bool collective, StdSize record, bool Isroot)
static int defVar(int ncid, const StdString &varName, nc_type xtype, int nDims, const int dimIds[], int &varId)
Define a variable.
static int open(const StdString &path, int oMode, int &ncId)
Open a netcdf file.
void initialize(const StdString &filename, bool append, bool useClassicFormat, bool useCFConvention, const MPI_Comm *comm, bool multifile, const StdString &timeCounterName)
Initialisation ///.
std::vector< StdString > getDimensionsIdList(const StdString *varname)
static int inqVarNDims(int ncid, int varId, int &nDims)
Query number of dimension of a variable with its id.
void writeTimeAxisDataBounds(const CArray< double, 1 > &data, const StdString &name, bool collective, StdSize record, bool Isroot)
static bool isDimExisted(int ncId, const StdString &dimName)
int addDimension(const StdString &name, const StdSize size=(size_t)(-1))
static int createPar(const StdString &path, int cmode, MPI_Comm comm, MPI_Info info, int &ncId)
Create a netcdf file on a parallel file system.
void writeData(const CArray< T, ndim > &data, const StdString &name, bool collective, StdSize record, const std::vector< StdSize > *start=NULL, const std::vector< StdSize > *count=NULL)
Ecriture des données ///.
void getWriteDataInfos(const StdString &name, StdSize record, StdSize &array_size, std::vector< StdSize > &sstart, std::vector< StdSize > &scount, const std::vector< StdSize > *start, const std::vector< StdSize > *count)
static int varParAccess(int ncid, int varid, int access)
Change access type of a variable.
static int defVarFill(int ncid, int varId, int noFill, void *fillValue)
Define variable fill parameters.
CATCH CScalarAlgorithmReduceScalar::CScalarAlgorithmReduceScalar(CScalar *scalarDestination, CScalar *scalarSource, CReduceScalarToScalar *algo ERROR)("CScalarAlgorithmReduceScalar::CScalarAlgorithmReduceScalar(CScalar* scalarDestination, CScalar* scalarSource, CReduceScalarToScalar* algo)",<< "Operation must be defined."<< "Scalar source "<< scalarSource->getId()<< std::endl<< "Scalar destination "<< scalarDestination->getId())
bool appendMode
If true, we are appending data to an existing file.
static int inqDimName(int ncid, int dimId, StdString &dimName)
Query name of a dimension with its id.
static int getVaraType(int ncid, int varid, const StdSize *start, const StdSize *count, T *data)
Get data for a variable.
int getDimension(const StdString &dimname)
bool useClassicFormat
If true, NetCDF4 will use the classic NetCDF3 format.
void setCurrentPath(const CONetCDF4Path &path)
Mutateurs ///.
static int inqVarDimId(int, int, int *)
Query list of dimension of a variable with its id.
void writeData_(int grpid, int varid, const std::vector< StdSize > &sstart, const std::vector< StdSize > &scount, T *data)
static int create(const StdString &path, int cmode, int &ncId)
Create a netcdf file.
bool varExist(const StdString &varname)
StdString getUnlimitedDimensionName(void)
int getGroup(const CONetCDF4Path &path)
static int sync(int ncId)
Sync the file.
#define UNLIMITED_DIM
XIOS headers ///.
static int defGrp(int parentNcid, const StdString &grpName, int &grpId)
Define a group.
static CTimer & get(std::string name)
int addVariable(const StdString &name, nc_type type, const std::vector< StdString > &dim, int compressionLevel=0)
static int defVarDeflate(int ncid, int varId, int compressionLevel)
Define variable compression level.
void setCompressionLevel(const StdString &varname, int compressionLevel)
static int inqVarId(int ncid, const StdString &varName, int &varId)
Query identity of a named variable.
static int defDim(int ncid, const StdString &dimName, StdSize dimLen, int &dimId)
Define a dimension.
StdString timeCounterName
CONetCDF4(const StdString &filename, bool append, bool useClassicFormat=false, bool useCFConvention=true, const MPI_Comm *comm=NULL, bool multifile=true, const StdString &timeCounterName="time_counter")
Constructeurs ///.
static int inqNcId(int ncid, const StdString &grpName, int &grpId)
Query identity of a named group.
static int inqDimIds(int ncid, int &nDims, int *dimIds, int includeParents)
Query dimensions of a group.
int getUnlimitedDimension(void)
void definition_start(void)
static bool isVarExisted(int ncId, const StdString &varName)
Query the existence of a variable.
void definition_end(void)
Test if the file was opened in append mode.
static int inqDimLen(int ncid, int dimId, StdSize &dimLen)
Query length of dimension with its id.
int addGroup(const StdString &name)