Esempio n. 1
0
//'@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;
}
Esempio n. 2
0
//'@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;
}