1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 2 * Copyright by The HDF Group. * 3 * Copyright by the Board of Trustees of the University of Illinois. * 4 * All rights reserved. * 5 * * 6 * This file is part of HDF5. The full HDF5 copyright notice, including * 7 * terms governing use, modification, and redistribution, is contained in * 8 * the COPYING file, which can be found at the root of the source code * 9 * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * 10 * If you do not have access to either file, you may request a copy from * 11 * help@hdfgroup.org. * 12 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 13 14 /************************************************************ 15 Creating and closing a group. 16 ************************************************************/ 17 18 package examples.intro; 19 20 import hdf.hdf5lib.H5; 21 import hdf.hdf5lib.HDF5Constants; 22 23 public class H5_CreateGroup { 24 private static String FILENAME = "H5_CreateGroup.h5"; 25 private static String GROUPNAME = "MyGroup"; 26 CreateGroup()27 private static void CreateGroup() { 28 long file_id = -1; 29 long group_id = -1; 30 31 // Create a new file using default properties. 32 try { 33 file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT, 34 HDF5Constants.H5P_DEFAULT); 35 } 36 catch (Exception e) { 37 e.printStackTrace(); 38 } 39 40 // Create a group in the file. 41 try { 42 if (file_id >= 0) 43 group_id = H5.H5Gcreate(file_id, "/" + GROUPNAME, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, 44 HDF5Constants.H5P_DEFAULT); 45 } 46 catch (Exception e) { 47 e.printStackTrace(); 48 } 49 50 // Close the group. 51 try { 52 if (group_id >= 0) 53 H5.H5Gclose(group_id); 54 } 55 catch (Exception e) { 56 e.printStackTrace(); 57 } 58 59 // Close the file. 60 try { 61 if (file_id >= 0) 62 H5.H5Fclose(file_id); 63 } 64 catch (Exception e) { 65 e.printStackTrace(); 66 } 67 68 } 69 main(String[] args)70 public static void main(String[] args) { 71 H5_CreateGroup.CreateGroup(); 72 } 73 74 } 75