Esempio n. 1
0
//'@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;
}
Esempio n. 2
0
/*-------------------------------------------------------------------------
 * Function:	test_types
 *
 * Purpose:	Test various types - should be moved to dtypes.cpp
 *
 * Return:	Success:	0
 *
 *		Failure:	-1
 *
 * Programmer:  Binh-Minh Ribler (using C version)
 *		February 17, 2001
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static herr_t
test_types(H5File& file)
{
    SUBTEST("Various datatypes");

    size_t		i;
    DataSet* dset = NULL;
    try {

	// Create a group in the file that was passed in from the caller
	Group grp = file.createGroup ("typetests");

	/* bitfield_1 */
	unsigned char	buf[32];
	hsize_t nelmts = sizeof(buf);
	DataType type;
	try { // block of bitfield_1
	    // test copying a predefined type
	    type.copy (PredType::STD_B8LE);

	    // Test copying a user-defined type using DataType::copy
	    DataType copied_type;
	    copied_type.copy(type);

	    // Test copying a user-defined type using DataType::operator=
	    DataType another_copied_type;
	    another_copied_type = type;

	    // Test copying a user-defined int type using DataType::operator=
	    IntType orig_int(PredType::STD_B8LE);
	    DataType generic_type;
	    generic_type = orig_int;

	    // Test copying an integer predefined type
	    IntType new_int_type(PredType::STD_B8LE);

	    // Test copying an int predefined type using DataType::operator=
	    IntType another_int_type;
	    another_int_type = new_int_type;

	    DataSpace space (1, &nelmts);
	    dset = new DataSet(grp.createDataSet("bitfield_1", type, space));

	    // Fill buffer
	    for (i=0; i<sizeof buf; i++)
	    	buf[i] = (unsigned char)0xff ^ (unsigned char)i;

	    // Write data from buf using all default dataspaces and property list
	    dset->write (buf, type);

	    // no failure in bitfield_1, close this dataset
	    delete dset;
	} // end try block of bitfield_1

	// catch exceptions thrown in try block of bitfield_1
	catch (Exception E)
	{
	    cerr << " FAILED" << endl;
	    cerr << "    <<<  " << "bitfield_1: " << E.getFuncName()
		 << " - " << E.getDetailMsg() << "  >>>" << endl << endl;
	    if (dset != NULL)
		delete dset;
	    return -1;
	}

	/* bitfield_2 */
	nelmts = sizeof(buf)/2;
	try { // bitfield_2 block
	    type.copy (PredType::STD_B16LE);
	    DataSpace space (1, &nelmts);
	    dset = new DataSet(grp.createDataSet("bitfield_2", type, space));

	    // Fill buffer
	    for (i=0; i<sizeof(buf); i++)
		buf[i] = (unsigned char)0xff ^ (unsigned char)i;

	    // Write data from buf using all default dataspaces and property
	    // list; if writing fails, deallocate dset and return.
	    dset->write (buf, type);

	    // no failure in bitfield_2, close this dataset and reset for
	    // variable reuse
	    delete dset;
	    dset = NULL;
	} // end try block of bitfield_2

	// catch exceptions thrown in try block of bitfield_2
	catch (Exception E) {
	    cerr << " FAILED" << endl;
	    cerr << "    <<<  " << "bitfield_2: " << E.getFuncName()
		 << " - " << E.getDetailMsg() << "  >>>" << endl << endl;
	    if (dset != NULL)
		delete dset;
	    throw E; // propagate the exception
	}

	/* opaque_1 */
	DataType* optype = NULL;
	try { // opaque_1 block
	    optype = new DataType(H5T_OPAQUE, 1);
	    nelmts = sizeof(buf);
	    DataSpace space (1, &nelmts);
	    optype->setTag ("testing 1-byte opaque type");
	    dset = new DataSet(grp.createDataSet("opaque_1", *optype, space));

	    // Fill buffer
	    for (i=0; i<sizeof buf; i++)
		buf[i] = (unsigned char)0xff ^ (unsigned char)i;

	    // Write data from buf using all default dataspaces and property
	    // list; if writing fails, deallocate dset and return.
	    dset->write (buf, *optype);

	    // no failure in opaque_1
	    delete dset; dset = NULL;
	    delete optype; optype = NULL;
	} // end try block of opaque_1

	// catch exceptions thrown in try block of opaque_1
	catch (Exception E) {
	    cerr << " FAILED" << endl;
	    cerr << "    <<<  " << "opaque_1: " << E.getFuncName()
		 << " - " << E.getDetailMsg() << "  >>>" << endl << endl;
	    if (dset != NULL)
		delete dset;
	    if (optype != NULL)
		delete optype;
	    throw E; // propagate the exception
	}

	/* opaque_2 */
	try { // block opaque_2
	    nelmts = sizeof(buf)/4;
	    DataSpace space (1, &nelmts);
	    optype = new DataType(H5T_OPAQUE, 4);
	    optype->setTag ("testing 4-byte opaque type");
	    dset = new DataSet(grp.createDataSet("opaque_2", *optype, space));

	    // Fill buffer
	    for (i=0; i<sizeof(buf); i++)
		buf[i] = (unsigned char)0xff ^ (unsigned char)i;

	    // Write data from buf using all default dataspaces and property
	    // list; if writing fails, deallocate dset and return.
	    dset->write (buf, *optype);

	    // no failure in opaque_1
	    delete dset; dset = NULL;
	    delete optype; optype = NULL;
	} //end try block of opaque_2

	// catch exceptions thrown in try block of opaque_2
	catch (Exception E) {
	    cerr << " FAILED" << endl;
	    cerr << "    <<<  " << "opaque_2: " << E.getFuncName()
		 << " - " << E.getDetailMsg() << "  >>>" << endl << endl;
	    if (dset != NULL)
		delete dset;
	    if (optype != NULL)
		delete optype;
	    throw E; // propagate the exception
	}

	PASSED();
	return 0;
    } // end top try block

    catch (Exception E)
    {
	return -1;
    }
}   // test_types