当前位置: 首页>>代码示例>>C++>>正文


C++ H5File类代码示例

本文整理汇总了C++中H5File的典型用法代码示例。如果您正苦于以下问题:C++ H5File类的具体用法?C++ H5File怎么用?C++ H5File使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了H5File类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: 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;
}
开发者ID:ActiveAnalytics,项目名称:activeH5,代码行数:61,代码来源:activeH5.cpp

示例2: sprintf

void BkgParamH5::InitBeads_BestRegion( H5File &h5_local_ref, int nBeads_live, const Region *region)
{
    char buff[80];
    //cout << "BkgParamH5::InitBeads_BestRegion... bestRegion=" << bestRegion.first << "," << bestRegion.second << endl << flush;
	// only once (the first flow, not all flows) 
    beads_bestRegion_timeframe.InitBasicCube (h5_local_ref,1,max_frames,1,"/bestRegion/timeframe", "Time Frame", "frameNumber");
    beads_bestRegion_location.InitBasicCube (h5_local_ref,nBeads_live,2,1,"/bestRegion/location", "y(row),x(col) for each bead", "row,col" );
    beads_bestRegion_gainSens.InitBasicCube(h5_local_ref,nBeads_live,1,1,"/bestRegion/gainSens","gain*sens","");
    beads_bestRegion_kmult.InitBasicCube(h5_local_ref,nBeads_live,1,1,"/bestRegion/kmult","kMult","");
    beads_bestRegion_dmult.InitBasicCube(h5_local_ref,nBeads_live,1,1,"/bestRegion/dmult","dMult","");
    beads_bestRegion_SP.InitBasicCube(h5_local_ref,nBeads_live,1,1,"/bestRegion/SP","SP: copies*copy_multiplier","");
    beads_bestRegion_R.InitBasicCube(h5_local_ref,nBeads_live,1,1,"/bestRegion/R","R: ratio of bead buffering to empty buffering","");
	// all flows 
    beads_bestRegion_predicted.InitBasicCube(h5_local_ref,nBeads_live,max_frames,datacube_numflows,"/bestRegion/predicted","predicted trace","");
    beads_bestRegion_corrected.InitBasicCube(h5_local_ref,nBeads_live,max_frames,datacube_numflows,"/bestRegion/corrected","background-adjusted trace","");
    beads_bestRegion_amplitude.InitBasicCube(h5_local_ref,nBeads_live,1,datacube_numflows,"/bestRegion/amplitude","amplititude","");
    beads_bestRegion_residual.InitBasicCube(h5_local_ref,nBeads_live,1,datacube_numflows,"/bestRegion/residual","residual error","");
    beads_bestRegion_fittype.InitBasicCube(h5_local_ref,nBeads_live,1,datacube_numflows,"/bestRegion/fittype","fittype","");
    beads_bestRegion_taub.InitBasicCube(h5_local_ref,nBeads_live,1,datacube_numflows,"/bestRegion/taub","taub","");
    sprintf(buff,"%d",nBeads_live);
    h5_local_ref.CreateAttribute(beads_bestRegion_location.h5_set->getDataSetId(),"nBeads_live",buff);
    sprintf(buff,"%d",region->h);
    h5_local_ref.CreateAttribute(beads_bestRegion_location.h5_set->getDataSetId(),"region_h",buff);
    sprintf(buff,"%d",region->w);
    h5_local_ref.CreateAttribute(beads_bestRegion_location.h5_set->getDataSetId(),"region_w",buff);
    sprintf(buff,"%d",region->row);
    h5_local_ref.CreateAttribute(beads_bestRegion_location.h5_set->getDataSetId(),"region_y(row)",buff);
    sprintf(buff,"%d",region->col);
    h5_local_ref.CreateAttribute(beads_bestRegion_location.h5_set->getDataSetId(),"region_x(col)",buff);
}
开发者ID:Lingrui,项目名称:TS,代码行数:30,代码来源:BkgModelHdf5.cpp

示例3: 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;
}
开发者ID:ActiveAnalytics,项目名称:activeH5,代码行数:35,代码来源:activeH5.cpp

示例4: 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;
}
开发者ID:ActiveAnalytics,项目名称:activeH5,代码行数:33,代码来源:activeH5.cpp

示例5: TestCompress

int TestCompress()
{

	unsigned int flags = 0;
    unsigned int config = 0;
    size_t cd_nelemts = 0;

    TESTING("compression")
#ifdef H5_HAVE_FILTER_DEFLATE
    try {
        /* Create packet table with compression. */
        FL_PacketTable wrapper(fileID, "/compressTest", H5T_NATIVE_CHAR, 100, 8);

        /* Create an HDF5 C++ file object */
        H5File file;
        file.setId(fileID);

        /* Make sure that the deflate filter is set by opening the packet table
         * as a dataset and getting its creation property list */
        DataSet dsetID = file.openDataSet("/compressTest");

        DSetCreatPropList dcplID = dsetID.getCreatePlist();

        dcplID.getFilterById(H5Z_FILTER_DEFLATE, flags, cd_nelemts, NULL, 0, NULL, config);
    } catch (Exception e) {
      H5_FAILED();
      return 1;
    }
    PASSED();
#else
    SKIPPED();
    puts("    deflate filter not enabled");
#endif /* H5_HAVE_FILTER_DEFLATE */
    return 0;
}
开发者ID:ArielleBassanelli,项目名称:gempak,代码行数:35,代码来源:ptableTest.cpp

示例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;
}
开发者ID:ActiveAnalytics,项目名称:activeH5,代码行数:37,代码来源:activeH5.cpp

示例7: H5File

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);
  
}
开发者ID:nanjiye123,项目名称:tracking,代码行数:30,代码来源:wrapper_i_hdf.cpp

示例8: 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;
}
开发者ID:ActiveAnalytics,项目名称:activeH5,代码行数:37,代码来源:activeH5.cpp

示例9: 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;
}
开发者ID:ActiveAnalytics,项目名称:activeH5,代码行数:33,代码来源:activeH5.cpp

示例10: get_feature_names

vector<string> get_feature_names(H5File h5f)
{
    vector<string> out;
    int num_features;
    for (int i = 0; i < h5f.getNumObjs(); i++)
        out.push_back(h5f.getObjnameByIdx(i));
    return out;
}
开发者ID:Rhoana,项目名称:feature-computation,代码行数:8,代码来源:opencv_hdf5.cpp

示例11: 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);
}
开发者ID:ActiveAnalytics,项目名称:activeH5,代码行数:65,代码来源:activeH5.cpp

示例12: TEST

TEST(H5Handle_Test, WriteReadTest) {
  float data[12];
  for (size_t i = 0; i < ArraySize(data); i++) {
    data[i] = i;
  }
  {
    H5File file;
    file.SetFile("tmp.h5");
    file.Open(true);
    hsize_t dims[] = {3,4};
    hsize_t chunking[] = {3,4};
    H5DataSet *ds =  file.CreateDataSet("/tmp/here/testdata", 2, dims, chunking, 2, H5T_NATIVE_FLOAT);

    size_t starts[] = {0,0};
    size_t ends[] = {3,4};
    //ds->WriteRangeData(starts, ends, ArraySize(data), data);
	ds->WriteRangeData(starts, ends, data);
    ds->Close();
  }
  { 
    H5File file;
    file.SetFile("tmp.h5");
    file.Open();
    H5DataSet *ds = file.OpenDataSet("/tmp/here/testdata");
    float query[12];
    size_t starts[] = {0,0};
    size_t ends[] = {3,4};
    ds->ReadRangeData(starts, ends, ArraySize(query), query);
    for (size_t i = 0; i < ArraySize(data); i++) {
      if (data[i] != query[i]) {
        EXPECT_EQ(query[i], data[i]);
      }
    }
    
    {
      float update[4];
      size_t starts[] = {1,2};
      size_t ends[] = {3,4};
      size_t count = 0;
      for (size_t i = 11; i >= 8; i--) {
        update[count++] = i;
      }
      //ds->WriteRangeData(starts, ends, ArraySize(update), update);
	  ds->WriteRangeData(starts, ends, update);
      float query[12];
      size_t rstarts[] = {0,0};
      size_t rends[] = {3,4};
      float gold[12] = {0,1,2,3,4,5,11,10,8,9,9,8};
      ds->ReadRangeData(rstarts, rends, ArraySize(query), query);
      for (size_t i = 0; i < 1; i++) {
        EXPECT_EQ(gold[i], query[i]);
      }

    }
    //    ds->Close();
    ds = file.OpenDataSet("shouldbenull");
    EXPECT_EQ(NULL,ds);

  }
}
开发者ID:alecw,项目名称:TS,代码行数:60,代码来源:H5File_Test.cpp

示例13: 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);
}
开发者ID:ActiveAnalytics,项目名称:activeH5,代码行数:62,代码来源:activeH5.cpp

示例14:

void BkgParamH5::ConstructOneFile ( H5File &h5_local_ref, string &hgLocalFile, string &local_results, const char *my_name )
{
  hgLocalFile = local_results;

  if ( hgLocalFile[hgLocalFile.length()-1] != '/' )
    hgLocalFile += '/';
  hgLocalFile += my_name;
  cout << "H5File for params:" << hgLocalFile << endl;

  h5_local_ref.Init();
  h5_local_ref.SetFile ( hgLocalFile );
  h5_local_ref.Open ( true );
}
开发者ID:biocyberman,项目名称:TS,代码行数:13,代码来源:BkgModelHdf5.cpp

示例15: ReadInfo

void TraceChunkSerializer::ReadInfo(H5File &h5, SynchDat &sdat) {
  sdat.mInfo.Clear();
  vector<string> keys;
  vector<string> values;
  h5.ReadStringVector(INFO_KEYS, keys);
  h5.ReadStringVector(INFO_VALUES, values);
  if (keys.size() != values.size()) { ION_ABORT("Keys and Values don't match in size."); }
    
  for (size_t i = 0; i < keys.size(); i++) {
    if (!sdat.mInfo.SetValue(keys[i], values[i])) { 
      ION_ABORT("Error: Could not set key: " + keys[i] + " with value: " + values[i]); 
    }
  }
}
开发者ID:Brainiarc7,项目名称:TS,代码行数:14,代码来源:SynchDatSerialize.cpp


注:本文中的H5File类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。