Search in sources :

Example 1 with H5File

use of ncsa.hdf.object.h5.H5File in project vcell by virtualcell.

the class H5FileStructure method createFile.

/**
 * create the file and add groups and dataset into the file, which is the
 * same as javaExample.H5DatasetCreate
 *
 * @see javaExample.HDF5DatasetCreate
 * @throws Exception
 */
private static void createFile() throws Exception {
    // retrieve an instance of H5File
    FileFormat fileFormat = FileFormat.getFileFormat(FileFormat.FILE_TYPE_HDF5);
    if (fileFormat == null) {
        System.err.println("Cannot find HDF5 FileFormat.");
        return;
    }
    // create a new file with a given file name.
    H5File testFile = (H5File) fileFormat.createFile(fname, FileFormat.FILE_CREATE_DELETE);
    if (testFile == null) {
        System.err.println("Failed to create file:" + fname);
        return;
    }
    // open the file and retrieve the root group
    testFile.open();
    Group root = (Group) ((javax.swing.tree.DefaultMutableTreeNode) testFile.getRootNode()).getUserObject();
    // create groups at the root
    Group g1 = testFile.createGroup("integer arrays", root);
    Group g2 = testFile.createGroup("float arrays", root);
    // create 2D 32-bit (4 bytes) integer dataset of 20 by 10
    Datatype dtype = testFile.createDatatype(Datatype.CLASS_INTEGER, 4, Datatype.NATIVE, Datatype.NATIVE);
    Dataset dataset = testFile.createScalarDS("2D 32-bit integer 20x10", g1, dtype, dims2D, null, null, 0, null);
    // create 3D 8-bit (1 byte) unsigned integer dataset of 20 by 10 by 5
    dtype = testFile.createDatatype(Datatype.CLASS_INTEGER, 1, Datatype.NATIVE, Datatype.SIGN_NONE);
    dataset = testFile.createScalarDS("3D 8-bit unsigned integer 20x10x5", g1, dtype, dims3D, null, null, 0, null);
    // create 2D 64-bit (8 bytes) double dataset of 20 by 10
    dtype = testFile.createDatatype(Datatype.CLASS_FLOAT, 8, Datatype.NATIVE, -1);
    dataset = testFile.createScalarDS("2D 64-bit double 20x10", g2, dtype, dims2D, null, null, 0, null);
    // create 3D 32-bit (4 bytes) float dataset of 20 by 10 by 5
    dtype = testFile.createDatatype(Datatype.CLASS_FLOAT, 4, Datatype.NATIVE, -1);
    dataset = testFile.createScalarDS("3D 32-bit float  20x10x5", g2, dtype, dims3D, null, null, 0, null);
    // close file resource
    testFile.close();
}
Also used : H5File(ncsa.hdf.object.h5.H5File) Group(ncsa.hdf.object.Group) Dataset(ncsa.hdf.object.Dataset) FileFormat(ncsa.hdf.object.FileFormat) Datatype(ncsa.hdf.object.Datatype)

Aggregations

Dataset (ncsa.hdf.object.Dataset)1 Datatype (ncsa.hdf.object.Datatype)1 FileFormat (ncsa.hdf.object.FileFormat)1 Group (ncsa.hdf.object.Group)1 H5File (ncsa.hdf.object.h5.H5File)1