QDFUtils¶
This page describes the module QDFUtils
The module QDFUtils
contain functions to simplify interactions with QDF files.
It als contains string constants for the names of HDF datasets and groups used in QDF files.
- Code:
Constants¶
Public Methods¶
Handling files¶
qdf_createFile
¶
hid_t qdf_createFile(const std::string sFileName, int fStep, float fStartTime, const std::string sInfoString);
sFileName
Name of file to be created.
fStep
Current step of simulation.
fStartTime
Start time of simulation.
sInfoString
String containing additional info.
qdf_openFile
¶
hid_t qdf_openFile(const std::string sFileName, bool bRW=false);
sFileName
Name of file to be opened.
bRW
File opening mode:
true
-> Read/Write,false
-> read only
qdf_opencreateFile
¶
hid_t qdf_opencreateFile(const std::string sFileName, int fStep, float fStartTime, const std::string sInfoString);
sFileName
Name of file to be created.
fStep
Current step of simulation.
fStartTime
Start time of simulation.
sInfoString
String containing additional info.
qdf_closeFile
¶
void qdf_closeFile(hid_t hFile);
hFile
HDF handle to an opened file.
Closes the HDF file resource.
Handling groups¶
Below hGroup
stands for a handle to a file or a handle to a group.
qdf_createGroup
¶
hid_t qdf_createGroup(hid_t hGroup, const std::string sGroupName);
hGroup
Handle to group (or file) in which to create a group.
sGroupName
Name of group to be created.
qdf_openGroup
¶
hid_t qdf_openGroup(hid_t hGroup, const std::string sGroupName, bool bForceCheck=true);
hGroup
Handle to group (or file) in which to open a group.
sGroupName
Name of group to be opened.
bForceCheck
If true, existence of group is checked.
hGroup
.qdf_opencreateGroup
¶
hid_t qdf_opencreateGroup(hid_t hGroup, const std::string sGroupName, bool bForceCheck=true);
hGroup
Handle to group (or file) in which to open or create a group.
sGroupName
Name of group to be opened or created.
bForceCheck
If true, existence of group is checked.
hGroup
, or creates it if it doesn’t exist.qdf_closeGroup
¶
void qdf_closeGroup(hid_t hGroup);
hGroup
Handle to group to be closed.
Closes the opened group.
qdf_deleteGroup
¶
int qdf_deleteGroup(hid_t hGroup, std::string sSubName);
hGroup
Handle to group in which to delete a sub group.
sSubName
Name of subgroup to delete.
hGroup
.Handling Data Sets¶
qdf_openDataSet
¶
hid_t qdf_openDataSet(hid_t hGroup, const std::string sDataSetName, bool bForceCheck=true);
hGroup
Handle to group (or file) in which to open a dataset.
sDataSetName
Name of data set to be opened.
bForceCheck
If true, existence of group is checked.
qdf_closeDataSet
¶
void qdf_closeDataSet(hid_t hDataSet);
hDataSet
Handle to data set to be closed.
Closes the specified data set.
qdf_closeDataSpace
¶
void qdf_closeDataSpace(hid_t hDataSpace);
hDataSet
Handle to data space to be closed.
Closes the specified data space.
qdf_closeDataType
¶
void qdf_closeDataType(hid_t hDataType);
hDataType
Handle to data type to be closed.
Closes the specified data type.
qdf_closeAttribute
¶
void qdf_closeAttribute(hid_t hDataSpace);
hDataSet
Handle to data space to be closed.
Closes the specified data space.
Link Existence¶
qdf_link_exists
¶
bool qdf_link_exists(hid_t hGroup, const std::string sName);
Returns true if the specified group contains a link (group, dataset) with the specified name.
qdf_attr_exists
¶
bool qdf_attr_exists(hid_t hGroup, const std::string sName);
Returns true if the specified group contains an attribute with the specified name.
Handling String Attributes¶
hLoc
HDF handle to object (group, file, dataset) to add the string to.
sName
Name of string attribute to create.
sValue
The string to write.
pValue
The C-string to write.
tValue
A value (it will be copnverte to a string before writing)
Writes the specified string to an attribute with given name in the specified location.
The last version accepts any value that can be converted to string with std::stringstream::operator<<()
.
std::string qdf_extractSAttribute(hid_t hLoc, const std::string sName);
int qdf_extractSAttribute(hid_t hLoc, const std::string sName, std::string &sValue);
hLoc
HDF handle to object (group, file, dataset) to extract the string attribute from.
sName
Name of string attribute to extract.
sValue
The string into which tp place th extracted string.
sValue
and returns 0 on success, -1 on failure.Handling Numeric Atributes¶
qdf_insertAttribute
¶
int qdf_insertAttribute(hid_t hLoc, const std::string sName, const uint iNum, void *vValue, const hid_t hType);
template<typename T>
int qdf_insertAttribute(hid_t hLoc, const std::string sName, const uint iNum, T *tValue);
hLoc
HDF handle to object (group, file, dataset) to write the numeric attribute to.
sName
Name of numeric attribute to write.
iNum
Number of elements in the attriute.
pValue
Pointer to the numeric values to be written to the attribute with the specified name at the specified location.
hType
Handle to HDF type of the numeric values.
tValue
Pointer to a numeric value.
int qdf_extractAttribute(hid_t hLoc, const std::string sName, const uint iNum, void *vValue, const hid_t hType);
template<typename T>
int qdf_extractAttribute(hid_t hLoc, const std::string sName, const uint iNum, T *tValue);
hLoc
HDF handle to object (group, file, dataset) to extract the numeric attribute from.
sName
Name of numeric attribute to write.
iNum
Number of elements in the attriute.
pValue
Pointer to the numeric values to be written to the attribute with the specified name at the specified location.
hType
Handle to HDF type of the numeric values.
tValue
Pointer to aarray numeric values.
Handling Arrays in Data Sets¶
qdf_readArray
¶
int qdf_readArray(hid_t hGroup, const std::string sName, const uint iNum, void *vData, const hid_t hType);
template<typename T>
int qdf_readArray(hid_t hGroup, const std::string sName, const uint iNum, T *pData);
hGroup
Group in which to read the dataset.
sName
Name of dataset to read.
iNum
Number of elements in array
vData
Pointer to an array with size at least
iNum
. The contents will be written to the data set.hType
Handle to HDF type of the numeric values.
pData
Pointer to an array with size at least
iNum
. The contents will be written to the data set.
qdf_replaceArray
¶
int qdf_replaceArray(hid_t hGroup, const std::string sName, const uint iNum, void *vData, const hid_t hType);
template<typename T>
int qdf_replaceArray(hid_t hGroup, const std::string sName, const uint iNum, T *pData);
hGroup
Group in which to replace the dataset.
sName
Name of dataset to replaced.
iNum
Number of elements in array.
vData
Pointer to an array with size at least
iNum
. The contents will replace the current array in the data set.hType
Handle to HDF type of the numeric values.
pData
Pointer to an array with size at least
iNum
. The contents will replace the current array in the data set.
qdf_writeArray
¶
int qdf_writeArray(hid_t hGroup, const std::string sName, const uint iNum, void *vData, const hid_t hType);
template<typename T>
int qdf_writeArray(hid_t hGroup, const std::string sName, const uint iNum, T *pData);
hGroup
Group in which to write the dataset.
sName
Name of dataset to be written to.
iNum
Number of elements in array.
vData
Pointer to an array with size at least
iNum
. The contents will be written to the data set.hType
Handle to HDF type of the numeric values.
pData
Pointer to an array with size at least
iNum
. The contents will e written to the data set.
qdf_readArrays
¶
int qdf_readArrays(hid_t hGroup, const std::string sName, const uint iNumArr, const uint iSize, double **pData);
hGroup
Group in which to write the dataset.
sName
Name of dataset to be written to.
iNumArr
Number of arrays.
iSize
Number of elements in array.
pData
Pointer to an array of
iNumArr
arrays with size at leastiSize
. The contents will be read from the data set.
qdf_writeArrays
¶
int qdf_writeArrays(hid_t hGroup, const std::string sName, const uint iNumArr, const uint iSize, const double **pData);
hGroup
Group in which to read the dataset.
sName
Name of dataset to be read from.
iNumArr
Number of arrays.
iSize
Number of elements in array.
pData
Pointer to an array of
iNumArr
arrays with size at leastiSize
. The contents will be writtten to the data set.
Various¶
qdf_listGroupContents
¶
int qdf_listGroupContents(hid_t loc_id, const std::string sName, char *pIndent);
loc_id
Location in which to list a group or file.
sName
Name of the group to b listed.
pIndent
Indentation to be prefixed to output.
Writes the list of contents of the group to stdout.
. —————————————————————————–
qdf_getDataType
¶
int qdf_getDataType(hid_t hDataSet);
hDataSet
Handle to the data set to get the data type of.
Returns an integer representing a data type:
DS_TYPE_NONE |
0 |
unknown type |
DS_TYPE_CHAR |
1 |
char |
DS_TYPE_SHORT |
2 |
short |
DS_TYPE_INT |
3 |
int |
DS_TYPE_LONG |
4 |
long |
DS_TYPE_LLONG |
5 |
long long |
DS_TYPE_UCHAR |
6 |
unsigned char |
DS_TYPE_USHORT |
7 |
unsigned short |
DS_TYPE_UINT |
8 |
unsigned int |
DS_TYPE_ULONG |
9 |
unsigned long |
DS_TYPE_ULLONG |
10 |
unsigned long long |
DS_TYPE_FLOAT |
11 |
float |
DS_TYPE_DOUBLE |
12 |
double |
DS_TYPE_LDOUBLE |
13 |
long double |
. —————————————————————————–
qdf_getDataExtents
¶
int qdf_getDataExtents(hid_t hGroup, const std::string sName, std::vector<hsize_t> &vSizes);
hGroup
Handle to group containing the data set to be analysed.
sName
Name of data set.
vSizes
String vector to write th sizes into.
qdf_getFirstPopulation
¶
const std::string qdf_getFirstPopulation(const std::string sPopQDF);
sPopQDF
Name of a QDF file containing populations.
Returns the name of the first population in the qdf file.
qdf_checkForPop
¶
const std::string qdf_checkForPop(const std::string sPopQDF, const std::string sSpeciesName);
sPopQDF
Name of a QDF file containing populations.
sSpeciesName
Name of a species.
Returns the name if the species exists, or an empty string if it doesn’t.
qdf_hasGeo
¶
bool qdf_hasGeo(const std::string sQDF);
sQDF
Name of a QDF file.
Returns true
if the file contains a geo group.
qdf_createPolyLine
¶
PolyLine *qdf_createPolyLine(hid_t hSpeciesGroup, const std::string sPLParName);
hSpeciesGroup
Handle to a species group.
sPLParName
Name of a poly line entry.
Gets the data for the poly line and creates it.
qdf_writePolyLine
¶
int qdf_writePolyLine(hid_t hSpeciesGroup, PolyLine *pPL, const std::string sPLParName);
hSpeciesGroup
Handle to a species group.
sPLParName
Name of a poly line entry.
Writes the poly line data to a data set named as specieified.
compareDataTypes
¶
int qdf_compareDataTypes(hid_t t1, hid_t t2);
t1
Handle to a HDF data type.
t2
Handle to a HDF data type.
-2 |
different number of members |
-3 |
different offsets |
-4 |
different class |
-5 |
different type |
-6 |
different name |
qdf_checkPathExists
¶
int qdf_checkPathExists(const std::string sQDF, const std::string sPath);
sQDF
Name of a qdf file.
sPath
A HDF path.
If the given path exists in the QDF file, o is returned. Otherwise -1.