本文整理汇总了C++中H5File::close方法的典型用法代码示例。如果您正苦于以下问题:C++ H5File::close方法的具体用法?C++ H5File::close怎么用?C++ H5File::close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类H5File
的用法示例。
在下文中一共展示了H5File::close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: get_dims
Tuplef Wrapper_i_hdf::get_dims()const
{
Tuplef tmp;
H5File file = H5File( file_name_, H5F_ACC_RDONLY );
Group group = Group(file.openGroup("/"));
Attr_list_hdf attr_list(&group);
if(!attr_list.contains_attr("version"))
throw invalid_argument("input file does not have a version");
int file_version = 0;
if(attr_list.get_value("version",file_version) != 1)
throw invalid_argument("input file is not the right version");
if(attr_list.contains_attr("dims"))
{
attr_list.get_value("dims",tmp);
}
group.close();
file.close();
return Tuplef(tmp);
}
示例2: h5WriteDoubleMat
//'@title Function to write a matrix chunk to file
//'
//'@description Function is intended for internal use
//'
//'@param dset character denoting the meta data name of the data set
//'@param chunk matrix that will be written to h5file
//'@param dim numeric containing the dimension of the matrix that will be written to file
//'@param filePath character denoting the location of the h5 file
//'@return int 0
// [[Rcpp::export]]
int h5WriteDoubleMat (std::string dset, SEXP chunk, NumericVector dim, std::string filePath)
{
H5File *file = new H5File(filePath, H5F_ACC_RDWR);
// Data initialization.
int rank = 2;
hsize_t dims[rank]; // dataset dimensions
for(int k = 0; k < rank; k++)
dims[k] = dim(k);
const void *buf = REAL(chunk);
// Create the data space for the dataset.
DataSpace dataspace (rank, dims, NULL);
// Create the dataset.
H5std_string dsetName(dset);
DataSet dataset = file->createDataSet(dsetName, PredType::NATIVE_DOUBLE, dataspace);
// Write the data to the dataset using default memory space, file
// space, and transfer properties.
dataset.write(buf, PredType::NATIVE_DOUBLE);
dataset.close(); //nn
file->close();
return 0;
}
示例3: ch5ChunkSel
// Function to return a selected part of a data frame as a list
List ch5ChunkSel(string chunkName, CharacterVector selCols, string filePath)
{
// Open the file in Read/Write Mode, H5F_ACC_RDONLY
H5File *file = new H5File(filePath, H5F_ACC_RDONLY);
// Opening the data set
DataSet dataset = file->openDataSet((H5std_string)chunkName);
// Opening the data space
DataSpace dataspace = dataset.getSpace();
// Get the number of dimensions
int ndim = dataspace.getSimpleExtentNdims();
// Create a dimension object to be filled with the dimensions of the data set
hsize_t dims[ndim];
// Fill the dimension of the dataset
dataspace.getSimpleExtentDims(dims, NULL);
// Create the return data
// Filling the matrix with data form the dataspace
SEXP data;
// Allocating a matrix of the right size and dimension
data = PROTECT(Rf_allocMatrix(REALSXP, dims[0], dims[1]));
// Filling the matrix with data form the dataspace
dataset.read(REAL(data), PredType::NATIVE_DOUBLE, dataspace);
UNPROTECT(1);
// converting the R object to a numeric matrix
NumericMatrix M = as<NumericMatrix>(data);
CharacterVector colNames = ch5ReadCharVector("ColumnNames", filePath);
CharacterVector colClasses = ch5ReadCharVector("ColumnClasses", filePath);
// Create the output
List DF;
string colName;
string colClass;
NumericVector vec;
CharacterVector levels;
int n = selCols.size();
IntegerVector sel(n);
int selN;
// First we need to find which of the columns has been selected
sel = match(selCols, colNames);
for(int i = 0; i < n; i++)
{
colName = selCols[i];
selN = sel[i] - 1;
colClass = colClasses[selN];
if(colClass != "factor")
{
DF[colName] = M(_, selN);
}else{
vec = M(_, selN);
levels = (CharacterVector)ch5ReadFactor(colName, filePath);
DF[colName] = cCreateFactor(vec, levels);
}
}
dataset.close();
file->close();
return DF;
}
示例4: h5DummyRead
//'@title Function for dummy read
//'
//'@param chunkName the name of the chunk to be read back
//'@param filePath the path to the h5 file
//'@return int 0
// [[Rcpp::export]]
int h5DummyRead(std::string chunkName, std::string filePath)
{
// Open the file in Read/Write Mode, H5F_ACC_RDONLY
H5File *file = new H5File(filePath, H5F_ACC_RDONLY);
// Opening the data set
DataSet dataset = file->openDataSet((H5std_string)chunkName);
// Opening the data space
DataSpace dataspace = dataset.getSpace();
// Get the number of dimensions
int ndim = dataspace.getSimpleExtentNdims();
// Create a dimension object to be filled with the dimensions of the data set
hsize_t dims[ndim];
// Fill the dimension of the dataset
dataspace.getSimpleExtentDims(dims, NULL);
// Create the return data
SEXP data;
// Allocating a matrix of the right size and dimension
data = PROTECT(Rf_allocMatrix(REALSXP, dims[0], dims[1]));
// Filling the matrix with data form the dataspace
dataset.read(REAL(data), PredType::NATIVE_DOUBLE, dataspace);
UNPROTECT(1);
dataset.close();
file->close();
return 0;
}
示例5: ch5ReadFactor
CharacterVector ch5ReadFactor(string charName, string filePath)
{
H5File *file = new H5File(filePath, H5F_ACC_RDONLY);
// Group Meta Group
Group* metaGroup = new Group(file->openGroup("/MetaData/Factor"));
// Getting the data set from the file
DataSet dataset = metaGroup->openDataSet((H5std_string)charName);
// Getting the data space from the dataset
DataSpace dataspace = dataset.getSpace();
// We know that it is a char vector array so ndim = 1
hsize_t dims[1];
// Getting the length of strings
dataspace.getSimpleExtentDims(dims, NULL);
// for convenience
int dim = dims[0];
// String Type
StrType vlst(0, H5T_VARIABLE);
// Returning the data
char *strRet[dim];
dataset.read(strRet, vlst);
CharacterVector out(dim);
for(int i = 0; i < dim; i++)
{
out[i] = strRet[i];
}
dataset.close(); //nn
metaGroup->close();
file->close();
return out;
}
示例6: h5WriteInt
//'@title This function writes an integer meta data to file
//'
//'@description This function is inteded for internal use
//'
//'@param intName the name of the meta data item to be written
//'@param integer int that will be written to the meta data described by intName
//'@param filePath character path to the h5 file where data will be written
//'@param update int flag for whether item is new (0) or whether it will overwrite a previous item (1)
//'@return int 0
// [[Rcpp::export]]
int h5WriteInt(std::string intName, int integer, std::string filePath, int update)
{
H5File *file = new H5File(filePath, H5F_ACC_RDWR);
// Colclasses dim
hsize_t dim[1] = {1};
string meta = "/MetaData";
// Group Meta Group
Group* metaGroup = new Group(file->openGroup(meta));
// dataspace
DataSpace dataspace = DataSpace(1, dim);
DataSet dataset;
if(update == 1)
{
string slash = "/";
string groupName = meta + slash + intName;
file->unlink(groupName);
}
dataset = metaGroup->createDataSet(intName, PredType::NATIVE_INT, dataspace);
dataset.write(&integer, PredType::NATIVE_INT);
dataset.close(); //nn
metaGroup->close();
file->close();
return 0;
}
示例7: h5CreateMetaData
//'@title Function creates the groups for the meta data to be written to the h5 file
//'
//'@description Function to create the groups in the h5 file before it is populated.
//'This function is intended for internal use only
//'
//'@param filePath character path to the location where the h5 file will be written
//'@return int 0
// [[Rcpp::export]]
int h5CreateMetaData(std::string filePath)
{
H5File *file = new H5File(filePath, H5F_ACC_RDWR);
hsize_t dims[1] = {1};
// The variable length string type
StrType vlst(0, H5T_VARIABLE);
// Creating the meta data group
Group *metaGroup = new Group(file->createGroup("/MetaData"));
// File path
H5std_string fString("FilePath");
DataSpace fileDataSpace (1, dims, NULL);
DataSet fileDataSet;
// Create a dataset in the group
fileDataSet = metaGroup->createDataSet(fString, vlst, fileDataSpace);
fileDataSet.write(filePath, vlst);
// Create the factor group
Group *factorGroup = new Group(metaGroup->createGroup("/MetaData/Factor"));
fileDataSet.close(); //nn
factorGroup->close();
metaGroup->close();
file->close();
return 0;
}
示例8: h5ReadDoubleMat3
//'@title Legacy function to return a data frame chunk as a list
//'
//'@description Experimental function not intended for use at all
//'
//'@param chunkName the name of the chunk to be read
//'@param filePath the path to the h5 file
//'@return List of the data frame chunk
// [[Rcpp::export]]
SEXP h5ReadDoubleMat3(std::string chunkName, std::string filePath)
{
// Open the file in Read/Write Mode, H5F_ACC_RDONLY
H5File *file = new H5File(filePath, H5F_ACC_RDONLY);
// Opening the data set
DataSet dataset = file->openDataSet((H5std_string)chunkName);
// Opening the data space
DataSpace dataspace = dataset.getSpace();
// Get the number of dimensions
int ndim = dataspace.getSimpleExtentNdims();
// Create a dimension object to be filled with the dimensions of the data set
hsize_t dims[ndim];
// Fill the dimension of the dataset
dataspace.getSimpleExtentDims(dims, NULL);
// Create the return data
// Filling the matrix with data form the dataspace
//double (*buf)[dims[1]]*[dims[0]] = malloc(dims[1]]*[dims[0] * sizeof *buf);
//buf[dims[1]][dims[0]] = 0.0;
double **buf = (double**) calloc (dims[1]*dims[0], sizeof(double));
buf[dims[1]][dims[0]] = 0.0;
//double buf[dims[1]][dims[0]];
dataset.read(buf, PredType::NATIVE_DOUBLE, dataspace);
// Attempt tp append the contents to a list
List out;
NumericVector vec(dims[0]);
NumericMatrix M(dims[0], dims[1]);
CharacterVector colNames = ch5ReadCharVector("ColumnNames", filePath);
CharacterVector colClasses = ch5ReadCharVector("ColumnClasses", filePath);
string colName;
for(int i = 0; i < dims[1]; i++)
{
NumericVector vec(dims[0]);
for(int j = 0; j < dims[0]; j++)
{
M(j,i) = buf[i][j];
vec(j) = buf[i][j];
}
colName = colNames[i];
if(colClasses[i] == "factor")
{
CharacterVector levels;
levels = h5ReadFactor(colName, filePath);
IntegerVector fact(vec.size());
fact = cCreateFactor(vec, levels);
out[colName] = fact;
}else{
out[colName] = vec;
}
}
free(buf);
dataset.close(); //nn
file->close();
return wrap(out);
}
示例9: h5ReadDoubleMat2
//'@title Legacy function to return a data frame chunk as a list
//'
//'@description Experimental function not intended for use at all
//'
//'@param chunkName the name of the chunk to be read
//'@param filePath the path to the h5 file
//'@return List of the data frame chunk
// [[Rcpp::export]]
SEXP h5ReadDoubleMat2(std::string chunkName, std::string filePath)
{
// Open the file in Read/Write Mode, H5F_ACC_RDONLY
H5File *file = new H5File(filePath, H5F_ACC_RDONLY);
// Opening the data set
DataSet dataset = file->openDataSet((H5std_string)chunkName);
// Opening the data space
DataSpace dataspace = dataset.getSpace();
// Get the number of dimensions
int ndim = dataspace.getSimpleExtentNdims();
// Create a dimension object to be filled with the dimensions of the data set
hsize_t dims[ndim];
// Fill the dimension of the dataset
dataspace.getSimpleExtentDims(dims, NULL);
// Create the return data
// Filling the matrix with data form the dataspace
SEXP data;
// Allocating a matrix of the right size and dimension
data = PROTECT(Rf_allocMatrix(REALSXP, dims[0], dims[1]));
// Filling the matrix with data form the dataspace
dataset.read(REAL(data), PredType::NATIVE_DOUBLE, dataspace);
UNPROTECT(1);
// converting the R object to a numeric matrix
NumericMatrix M = as<NumericMatrix>(data);
List out;
NumericVector vec(dims[0]);
CharacterVector colNames = ch5ReadCharVector("ColumnNames", filePath);
CharacterVector colClasses = ch5ReadCharVector("ColumnClasses", filePath);
string colName;
for(int i = 0; i < dims[1]; i++)
{
NumericVector vec(dims[0]);
for(int j = 0; j < dims[0]; j++)
{
vec(j) = M(j,i);
}
colName = colNames[i];
if(colClasses[i] == "factor")
{
CharacterVector levels;
levels = ch5ReadFactor(colName, filePath);
IntegerVector fact(vec.size());
fact = cCreateFactor(vec, levels);
out[colName] = fact;
}else{
out[colName] = vec;
}
}
dataset.close(); //nn
file->close();
// Returning the data
return wrap(out);
}
示例10: main
int main(int argc, char ** argv)
{
if (argc < 3){
cout << "Usage:" << argv[0] << " <filename> <outputfilename> - display some statistics of specified synapse." << endl;
return 0;
}
const H5std_string FILE_NAME(argv[1]);
ofstream outfile;
outfile.open(argv[2]);
try{
H5File * file = new H5File(FILE_NAME, H5F_ACC_RDONLY);
Group * netgroup = new Group(file->openGroup("network"));
const DataSet * syndataset = new DataSet(netgroup->openDataSet("synapse"));
synstat(*syndataset, outfile);
file->close();
outfile.close();
}
catch( FileIException error )
{
error.printError();
return -1;
}
// catch failure caused by the DataSet operations
catch( DataSetIException error )
{
error.printError();
return -1;
}
// catch failure caused by the DataSpace operations
catch( DataSpaceIException error )
{
error.printError();
return -1;
}
// catch failure caused by the DataSpace operations
catch( DataTypeIException error )
{
error.printError();
return -1;
}
return 0;
}
示例11: h5CreateFile
//'@title Function to create file a h5 file
//'
//'@description Function to create a h5 file. It is intended for internal use only
//'
//'@param filePath a character denoting the path to the location where the h5 file will be written
//'@param overwrite integer 1 for overwrite and 0 for not overwrite. Will fail if overwrite is 0
//'@return int 0
// [[Rcpp::export]]
int h5CreateFile(std::string filePath, int overwrite)
{
H5File* file;
if(fileExists(filePath))
{
if(overwrite)
{
file = new H5File(filePath, H5F_ACC_TRUNC);
}else{
throw "Error: file exists and overwrite is set to 0.";
}
}else{
file = new H5File(filePath, H5F_ACC_TRUNC);
}
file->close();
return 0;
}
示例12: h5ReadInt
//'@title Function to read an integer item from meta data
//'
//'@param intName character for the name of the item to be read back
//'@param filePath character for the path to the h5 file
//'@return int iteger item defined by intName in the meta data
// [[Rcpp::export]]
int h5ReadInt(std::string intName, std::string filePath)
{
H5File *file = new H5File(filePath, H5F_ACC_RDONLY);
// Group Meta Group
Group* metaGroup = new Group(file->openGroup("/MetaData"));
// Getting the data set from the file
DataSet dataset = metaGroup->openDataSet((H5std_string)intName);
// Getting the data space from the dataset
DataSpace dataspace = dataset.getSpace();
// Returning the data
int intRet;
dataset.read(&intRet, PredType::NATIVE_INT);
dataset.close(); //nn
metaGroup->close();
file->close();
return intRet;
}
示例13: h5WriteCharVector
//'@title This function writes a character vector to the meta data
//'
//'@description This function writes a character vector to the meta data and is intended for internal use.
//'
//'@param charName the name that will be given to the meta data character vector
//'@param charVec the character vector to be written as meta data
//'@param filePath the path to the h5 file where the data will be written
//'@param update integer denoting whether the data item is new or whether it is an update
//'(which will overwrite any previous item)
//'@return int 0
// [[Rcpp::export]]
int h5WriteCharVector(std::string charName, SEXP charVec, std::string filePath, int update)
{
H5File *file = new H5File(filePath, H5F_ACC_RDWR);
int len = Rf_length(charVec);
hsize_t DIM1 = len;
int rank = 1;
//cout << "The length is ... " << len << endl;
// Create a datatype to refer to
StrType vlst(0, H5T_VARIABLE);
// This is the char array
char** arr = convertCharArray(charVec);
string meta = "/MetaData";
// Group Meta Group
Group* metaGroup = new Group(file->openGroup(meta));
// The dataset and dataspace
hsize_t dims[] = {DIM1};
//hsize_t maxdims[] = {H5S_UNLIMITED};
DataSet dataset;
if(update == 1)
{
string slash = "/";
string groupName = meta + slash + charName;
file->unlink(groupName);
}
DataSpace dataspace(rank, dims);
dataset = metaGroup->createDataSet(charName, vlst, dataspace);
dataset.write(arr, vlst);
dataset.close(); //nn
metaGroup->close();
file->close();
return 0;
}
示例14: priv_init
//.........这里部分代码省略.........
{
if(two_d_data_ && ((*it).first)==utilities::D_ZPOS)
continue;
// ***************
DataSet * dset = new DataSet(frame->openDataSet(format_dset_name((*it).first,(*it).second)));
// ***************
DataSpace dspace = dset-> getSpace();
dspace.selectAll();
int part_count = dspace.getSimpleExtentNpoints();
// if the first data set for this frame set the number of particles
if(frame_c_.size()==j)
frame_c_.push_back(part_count);
// if the part_count is less than a previous dataset, set the
// number of particles to be the smaller number. This
// shouldn't result in memory leaks as the bare arrays are
// never returned
else if(frame_c_.at(j) > part_count)
frame_c_.at(j) = part_count;
// if the current set has more than a previous set, keep the
// old value. these checks are a kludge, need to deal with
// this better at the level of writing out the data
else if(frame_c_.at(j) < part_count)
continue;
// if(frame_c_.at(j) != part_count)
// throw runtime_error("wrapper_i_hdf: data sets different sizes");
D_TYPE cur_type = (*it).first;
switch(v_type(cur_type))
{
case V_INT:
data_i_.at(d_mapi_(cur_type)).at(j) = new int [part_count];
dset->read(data_i_.at(d_mapi_(cur_type)).at(j),PredType::NATIVE_INT);
break;
case V_FLOAT:
data_f_.at(d_mapf_(cur_type)).at(j) = new float [part_count];
dset->read(data_f_.at(d_mapf_(cur_type)).at(j),PredType::NATIVE_FLOAT);
break;
case V_COMPLEX:
throw logic_error("not implemented yet");
break;
case V_STRING:
case V_BOOL:
case V_GUID:
case V_TIME:
case V_UINT:
case V_ERROR:
throw logic_error("wrapper_i_hdf: The data type should not have been " + VT2str_s(v_type(cur_type)));
}
// clean up hdf stuff
dset->close();
delete dset;
dset = NULL;
}
frame->close();
delete frame;
frame = NULL;
}
file->close();
delete file;
file = NULL;
// shift all of the z by the minimum to start at zero
if(two_d_data_)
{
float min = frame_zdata_[0];
for(unsigned int j = 0; j<frame_count_;++j)
if(frame_zdata_[j]<min)
min = frame_zdata_[j];
for(unsigned int j = 0; j<frame_count_;++j)
frame_zdata_[j] -= min ;
}
}
catch(Exception & e)
{
// clean up data if it died
e.printError();
throw runtime_error("wrapper_i_hdf: constructor error");
}
for(unsigned int j= 0; j<frame_count_;++j)
total_part_count_ += frame_c_.at(j);
return true;
}
示例15: h5ModelFrame
//.........这里部分代码省略.........
//' @param chunkName character name of the chunk to be read
//' @param selCols character vector of columns to select
//' @param filePath character path to file where chunk is to be read from
//' @return list representing a data frame with no NA values.
//[[Rcpp::export]]
SEXP h5ModelFrame(std::string chunkName, SEXP selCols_, std::string filePath)
{
// Quick conversion of the SEXP column selection to character vector
CharacterVector selCols(selCols_);
// Open the file in Read/Write Mode, H5F_ACC_RDONLY
H5File *file = new H5File(filePath, H5F_ACC_RDONLY);
// Opening the data set
DataSet dataset = file->openDataSet((H5std_string)chunkName);
// Opening the data space
DataSpace dataspace = dataset.getSpace();
// Get the number of dimensions
int ndim = dataspace.getSimpleExtentNdims();
// Create a dimension object to be filled with the dimensions of the data set
hsize_t dims[ndim];
// Fill the dimension of the dataset
dataspace.getSimpleExtentDims(dims, NULL);
// Create the return data
// Filling the matrix with data form the dataspace
SEXP data;
// Allocating a matrix of the right size and dimension
data = PROTECT(Rf_allocMatrix(REALSXP, dims[0], dims[1]));
// Filling the matrix with data form the dataspace
dataset.read(REAL(data), PredType::NATIVE_DOUBLE, dataspace);
UNPROTECT(1);
// Convert the R object to a numeric matrix
NumericMatrix M__(data);
CharacterVector colNames = ch5ReadCharVector("ColumnNames", filePath);
CharacterVector colClasses = ch5ReadCharVector("ColumnClasses", filePath);
// Create the output
List DF;
string colName;
string colClass;
NumericVector vect;
CharacterVector levels;
int n = selCols.size();
IntegerVector sel(n);
int selN;
NumericMatrix M_(M__.nrow(), n);
// Find which of the columns has been selected
sel = match(selCols, colNames);
// Copy the correct matrix columns
for(int i = 0; i < n; i++)
{
selN = sel[i] - 1;
M_(_, i) = M__(_, selN);
}
// Number of rows in the matrix
int nr = M_.nrow();
int goodRow;
NumericVector goodRows(nr);
int badRow;
for(int i = 0; i < nr; i++)
{
badRow = sum(is_na(M_(i, _)));
if(badRow >= 1)
{
goodRows[i] = 0;
}else{
goodRows[i] = 1;
}
}
//goodRows = goodRows*-1 + 1;
NumericMatrix M(sum(goodRows), n);
int j = 0;
// Remove NA rows
for(int i = 0; i < nr; i++)
{
goodRow = goodRows[i];
if(goodRow == 1)
{
M(j, _) = M_(i, _);
j++;
}
}
// Compile the list
for(int i = 0; i < n; i++)
{
colName = selCols[i];
selN = sel[i] - 1;
colClass = colClasses[selN];
if(colClass != "factor")
{
DF[colName] = M(_, i);
}else{
vect = M(_, i);
levels = (CharacterVector)ch5ReadFactor(colName, filePath);
DF[colName] = cCreateFactor(vect, levels);
}
}
dataset.close();
file->close();
return wrap(DF);
}