/***************************************************************************** * Copyright by The HDF Group. * * Copyright by the Board of Trustees of the University of Illinois. * * All rights reserved. * * * * This file is part of the HDF Java Products distribution. * * The full copyright notice, including terms governing use, modification, * * and redistribution, is contained in the files COPYING and Copyright.html. * * COPYING can be found at the root of the source code distribution tree. * * Or, see http://hdfgroup.org/products/hdf-java/doc/Copyright.html. * * If you do not have access to either file, you may request a copy from * * help@hdfgroup.org. * ****************************************************************************/ package javaExample; import ncsa.hdf.object.*; // the common object package import ncsa.hdf.object.h4.*; // the HDF4 implementation /** *
Title: HDF Object Package (Java) Example
*Description: this example shows how to retrieve HDF file structure using the * "HDF Object Package (Java)". The example created the group structure * and datasets, and print out the file structure: *
* "/" (root) * integer arrays * 2D 32-bit integer 20x10 * 3D unsigned 8-bit integer 20x10x5 * float arrays * 2D 64-bit double 20x10 * 3D 32-bit float 20x10x5 ** * * @author Peter X. Cao * @version 2.4 */ public class H4FileStructure { private static String fname = "H4FileStructure.hdf"; private static long[] dims2D = {20, 10}; private static long[] dims3D = {20, 10, 5}; public static void main( String args[] ) throws Exception { // create the file and add groups ans dataset into the file createFile(); // retrieve an instance of H4File FileFormat fileFormat = FileFormat.getFileFormat(FileFormat.FILE_TYPE_HDF4); if (fileFormat == null) { System.err.println("Cannot find HDF4 FileFormat."); return; } // open the file with read-only access FileFormat testFile = fileFormat.open(fname, FileFormat.READ); if (testFile == null) { System.err.println("Failed to open file: "+fname); return; } // open the file and retrieve the file structure testFile.open(); Group root = (Group)((javax.swing.tree.DefaultMutableTreeNode)testFile.getRootNode()).getUserObject(); printGroup(root, ""); // close file resource testFile.close(); } /** * Recursively print a group and its members. * @throws Exception */ private static void printGroup(Group g, String indent) throws Exception { if (g == null) return; java.util.List members = g.getMemberList(); int n = members.size(); indent += " "; HObject obj = null; for (int i=0; i