diff options
author | Allen Byrne <50328838+byrnHDF@users.noreply.github.com> | 2022-04-22 15:24:27 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-22 15:24:27 (GMT) |
commit | 974aefb8416d78b0687a54e5f72f21d0ca72ae2d (patch) | |
tree | 0fe4e4327b95c38f362ceace220d59cb08aa88a3 /java/examples/datasets | |
parent | f5042fd4d3549e9e3453ab99d81bb46f1688b240 (diff) | |
download | hdf5-974aefb8416d78b0687a54e5f72f21d0ca72ae2d.zip hdf5-974aefb8416d78b0687a54e5f72f21d0ca72ae2d.tar.gz hdf5-974aefb8416d78b0687a54e5f72f21d0ca72ae2d.tar.bz2 |
Add java clang-format (#1672)
Diffstat (limited to 'java/examples/datasets')
19 files changed, 826 insertions, 769 deletions
diff --git a/java/examples/datasets/CMakeLists.txt b/java/examples/datasets/CMakeLists.txt index 8198135..e63ead0 100644 --- a/java/examples/datasets/CMakeLists.txt +++ b/java/examples/datasets/CMakeLists.txt @@ -62,6 +62,13 @@ foreach (example ${HDF_JAVA_EXAMPLES}) # install_jar (${example} ${HJAVA_INSTALL_DATA_DIR}/examples examples) get_target_property (${example}_CLASSPATH ${example} CLASSDIR) add_dependencies (${example} ${HDF5_JAVA_HDF5_LIB_TARGET}) + + #----------------------------------------------------------------------------- + # Add Target to clang-format + #----------------------------------------------------------------------------- + if (HDF5_ENABLE_FORMATTERS) + clang_format (HDF5_JAVA_${example}_SRC_FORMAT ${example}.java) + endif () endforeach () set (CMAKE_JAVA_INCLUDE_PATH "${HDF5_JAVA_JARS};${HDF5_JAVA_LOGGING_JAR};${HDF5_JAVA_LOGGING_NOP_JAR}") diff --git a/java/examples/datasets/H5Ex_D_Alloc.java b/java/examples/datasets/H5Ex_D_Alloc.java index 4e10c23..4853cc0 100644 --- a/java/examples/datasets/H5Ex_D_Alloc.java +++ b/java/examples/datasets/H5Ex_D_Alloc.java @@ -29,49 +29,47 @@ import hdf.hdf5lib.H5; import hdf.hdf5lib.HDF5Constants; public class H5Ex_D_Alloc { - private static String FILENAME = "H5Ex_D_Alloc.h5"; + private static String FILENAME = "H5Ex_D_Alloc.h5"; private static String DATASETNAME1 = "DS1"; private static String DATASETNAME2 = "DS2"; - private static final int DIM_X = 4; - private static final int DIM_Y = 7; - private static final int FILLVAL = 99; - private static final int RANK = 2; + private static final int DIM_X = 4; + private static final int DIM_Y = 7; + private static final int FILLVAL = 99; + private static final int RANK = 2; // Values for the status of space allocation enum H5D_space_status { - H5D_SPACE_STATUS_ERROR(-1), H5D_SPACE_STATUS_NOT_ALLOCATED(0), H5D_SPACE_STATUS_PART_ALLOCATED(1), H5D_SPACE_STATUS_ALLOCATED( - 2); + H5D_SPACE_STATUS_ERROR(-1), + H5D_SPACE_STATUS_NOT_ALLOCATED(0), + H5D_SPACE_STATUS_PART_ALLOCATED(1), + H5D_SPACE_STATUS_ALLOCATED(2); private static final Map<Integer, H5D_space_status> lookup = new HashMap<Integer, H5D_space_status>(); - static { + static + { for (H5D_space_status s : EnumSet.allOf(H5D_space_status.class)) lookup.put(s.getCode(), s); } private int code; - H5D_space_status(int space_status) { - this.code = space_status; - } + H5D_space_status(int space_status) { this.code = space_status; } - public int getCode() { - return this.code; - } + public int getCode() { return this.code; } - public static H5D_space_status get(int code) { - return lookup.get(code); - } + public static H5D_space_status get(int code) { return lookup.get(code); } } - private static void allocation() { - long file_id = HDF5Constants.H5I_INVALID_HID; + private static void allocation() + { + long file_id = HDF5Constants.H5I_INVALID_HID; long filespace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id1 = HDF5Constants.H5I_INVALID_HID; - long dataset_id2 = HDF5Constants.H5I_INVALID_HID; - long dcpl_id = HDF5Constants.H5I_INVALID_HID; - long[] dims = { DIM_X, DIM_Y }; + long dataset_id1 = HDF5Constants.H5I_INVALID_HID; + long dataset_id2 = HDF5Constants.H5I_INVALID_HID; + long dcpl_id = HDF5Constants.H5I_INVALID_HID; + long[] dims = {DIM_X, DIM_Y}; int[][] dset_data = new int[DIM_X][DIM_Y]; - int space_status = 0; + int space_status = 0; long storage_size = 0; // Initialize the dataset. @@ -82,7 +80,7 @@ public class H5Ex_D_Alloc { // Create a file using default properties. try { file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT, - HDF5Constants.H5P_DEFAULT); + HDF5Constants.H5P_DEFAULT); } catch (Exception e) { e.printStackTrace(); @@ -125,7 +123,8 @@ public class H5Ex_D_Alloc { try { if ((file_id >= 0) && (filespace_id >= 0)) dataset_id1 = H5.H5Dcreate(file_id, DATASETNAME1, HDF5Constants.H5T_NATIVE_INT, filespace_id, - HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, + HDF5Constants.H5P_DEFAULT); } catch (Exception e) { e.printStackTrace(); @@ -135,7 +134,7 @@ public class H5Ex_D_Alloc { try { if ((file_id >= 0) && (filespace_id >= 0) && (dcpl_id >= 0)) dataset_id2 = H5.H5Dcreate(file_id, DATASETNAME2, HDF5Constants.H5T_NATIVE_INT, filespace_id, - HDF5Constants.H5P_DEFAULT, dcpl_id, HDF5Constants.H5P_DEFAULT); + HDF5Constants.H5P_DEFAULT, dcpl_id, HDF5Constants.H5P_DEFAULT); } catch (Exception e) { e.printStackTrace(); @@ -190,16 +189,16 @@ public class H5Ex_D_Alloc { // Write the data to the datasets. try { if (dataset_id1 >= 0) - H5.H5Dwrite(dataset_id1, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, dset_data[0]); + H5.H5Dwrite(dataset_id1, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, + HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, dset_data[0]); } catch (Exception e) { e.printStackTrace(); } try { if (dataset_id2 >= 0) - H5.H5Dwrite(dataset_id2, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, dset_data[0]); + H5.H5Dwrite(dataset_id2, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, + HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, dset_data[0]); } catch (Exception e) { e.printStackTrace(); @@ -291,8 +290,5 @@ public class H5Ex_D_Alloc { } } - public static void main(String[] args) { - H5Ex_D_Alloc.allocation(); - } - + public static void main(String[] args) { H5Ex_D_Alloc.allocation(); } } diff --git a/java/examples/datasets/H5Ex_D_Checksum.java b/java/examples/datasets/H5Ex_D_Checksum.java index 781dd68..7b01176 100644 --- a/java/examples/datasets/H5Ex_D_Checksum.java +++ b/java/examples/datasets/H5Ex_D_Checksum.java @@ -30,42 +30,46 @@ import hdf.hdf5lib.H5; import hdf.hdf5lib.HDF5Constants; public class H5Ex_D_Checksum { - private static String FILENAME = "H5Ex_D_Checksum.h5"; + private static String FILENAME = "H5Ex_D_Checksum.h5"; private static String DATASETNAME = "DS1"; - private static final int DIM_X = 32; - private static final int DIM_Y = 64; - private static final int CHUNK_X = 4; - private static final int CHUNK_Y = 8; - private static final int RANK = 2; - private static final int NDIMS = 2; + private static final int DIM_X = 32; + private static final int DIM_Y = 64; + private static final int CHUNK_X = 4; + private static final int CHUNK_Y = 8; + private static final int RANK = 2; + private static final int NDIMS = 2; // Values for the status of space allocation enum H5Z_filter { - H5Z_FILTER_ERROR(-1), H5Z_FILTER_NONE(0), H5Z_FILTER_DEFLATE(1), H5Z_FILTER_SHUFFLE(2), H5Z_FILTER_FLETCHER32(3), H5Z_FILTER_SZIP( - 4), H5Z_FILTER_NBIT(5), H5Z_FILTER_SCALEOFFSET(6), H5Z_FILTER_RESERVED(256), H5Z_FILTER_MAX(65535); + H5Z_FILTER_ERROR(-1), + H5Z_FILTER_NONE(0), + H5Z_FILTER_DEFLATE(1), + H5Z_FILTER_SHUFFLE(2), + H5Z_FILTER_FLETCHER32(3), + H5Z_FILTER_SZIP(4), + H5Z_FILTER_NBIT(5), + H5Z_FILTER_SCALEOFFSET(6), + H5Z_FILTER_RESERVED(256), + H5Z_FILTER_MAX(65535); private static final Map<Integer, H5Z_filter> lookup = new HashMap<Integer, H5Z_filter>(); - static { + static + { for (H5Z_filter s : EnumSet.allOf(H5Z_filter.class)) lookup.put(s.getCode(), s); } private int code; - H5Z_filter(int layout_type) { - this.code = layout_type; - } + H5Z_filter(int layout_type) { this.code = layout_type; } - public int getCode() { - return this.code; - } + public int getCode() { return this.code; } - public static H5Z_filter get(int code) { - return lookup.get(code); - } + public static H5Z_filter get(int code) { return lookup.get(code); } } - private static boolean checkFletcher32Filter() { + private static boolean checkFletcher32Filter() + { try { int available = H5.H5Zfilter_avail(H5Z_filter.H5Z_FILTER_FLETCHER32.getCode()); if (available == 0) { @@ -79,8 +83,8 @@ public class H5Ex_D_Checksum { try { int filter_info = H5.H5Zget_filter_info(HDF5Constants.H5Z_FILTER_FLETCHER32); - if (((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_ENCODE_ENABLED) == 0) - || ((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_DECODE_ENABLED) == 0)) { + if (((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_ENCODE_ENABLED) == 0) || + ((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_DECODE_ENABLED) == 0)) { System.out.println("N-Bit filter not available for encoding and decoding."); return false; } @@ -91,13 +95,14 @@ public class H5Ex_D_Checksum { return true; } - private static void writeChecksum() { - long file_id = HDF5Constants.H5I_INVALID_HID; + private static void writeChecksum() + { + long file_id = HDF5Constants.H5I_INVALID_HID; long filespace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long dcpl_id = HDF5Constants.H5I_INVALID_HID; - long[] dims = { DIM_X, DIM_Y }; - long[] chunk_dims = { CHUNK_X, CHUNK_Y }; + long dataset_id = HDF5Constants.H5I_INVALID_HID; + long dcpl_id = HDF5Constants.H5I_INVALID_HID; + long[] dims = {DIM_X, DIM_Y}; + long[] chunk_dims = {CHUNK_X, CHUNK_Y}; int[][] dset_data = new int[DIM_X][DIM_Y]; // Initialize data. @@ -108,7 +113,7 @@ public class H5Ex_D_Checksum { // Create a new file using default properties. try { file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT, - HDF5Constants.H5P_DEFAULT); + HDF5Constants.H5P_DEFAULT); } catch (Exception e) { e.printStackTrace(); @@ -140,7 +145,7 @@ public class H5Ex_D_Checksum { try { if ((file_id >= 0) && (filespace_id >= 0) && (dcpl_id >= 0)) dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_I32LE, filespace_id, - HDF5Constants.H5P_DEFAULT, dcpl_id, HDF5Constants.H5P_DEFAULT); + HDF5Constants.H5P_DEFAULT, dcpl_id, HDF5Constants.H5P_DEFAULT); } catch (Exception e) { e.printStackTrace(); @@ -149,8 +154,8 @@ public class H5Ex_D_Checksum { // Write the data to the dataset. try { if (dataset_id >= 0) - H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, dset_data); + H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, + HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, dset_data); } catch (Exception e) { e.printStackTrace(); @@ -191,10 +196,11 @@ public class H5Ex_D_Checksum { } } - private static void readChecksum() { - long file_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long dcpl_id = HDF5Constants.H5I_INVALID_HID; + private static void readChecksum() + { + long file_id = HDF5Constants.H5I_INVALID_HID; + long dataset_id = HDF5Constants.H5I_INVALID_HID; + long dcpl_id = HDF5Constants.H5I_INVALID_HID; int[][] dset_data = new int[DIM_X][DIM_Y]; // Open an existing file. @@ -228,14 +234,14 @@ public class H5Ex_D_Checksum { try { if (dcpl_id >= 0) { // Java lib requires a valid filter_name object and cd_values - int[] flags = { 0 }; - long[] cd_nelmts = { 1 }; - int[] cd_values = { 0 }; - String[] filter_name = { "" }; - int[] filter_config = { 0 }; - int filter_type = -1; - filter_type = H5 - .H5Pget_filter(dcpl_id, 0, flags, cd_nelmts, cd_values, 120, filter_name, filter_config); + int[] flags = {0}; + long[] cd_nelmts = {1}; + int[] cd_values = {0}; + String[] filter_name = {""}; + int[] filter_config = {0}; + int filter_type = -1; + filter_type = H5.H5Pget_filter(dcpl_id, 0, flags, cd_nelmts, cd_values, 120, filter_name, + filter_config); System.out.print("Filter type is: "); switch (H5Z_filter.get(filter_type)) { case H5Z_FILTER_DEFLATE: @@ -264,7 +270,7 @@ public class H5Ex_D_Checksum { try { if (dataset_id >= 0) { int status = H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, - HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, dset_data); + HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, dset_data); // Check if the read was successful. Normally we do not perform // error checking in these examples for the sake of clarity, but in // this case we will make an exception because this is how the @@ -328,7 +334,8 @@ public class H5Ex_D_Checksum { } } - public static void main(String[] args) { + public static void main(String[] args) + { // Check if the Fletcher32 filter is available and can be used for // both encoding and decoding. Normally we do not perform error // checking in these examples for the sake of clarity, but in this @@ -340,5 +347,4 @@ public class H5Ex_D_Checksum { H5Ex_D_Checksum.readChecksum(); } } - } diff --git a/java/examples/datasets/H5Ex_D_Chunk.java b/java/examples/datasets/H5Ex_D_Chunk.java index 2ddf293..fbfc148 100644 --- a/java/examples/datasets/H5Ex_D_Chunk.java +++ b/java/examples/datasets/H5Ex_D_Chunk.java @@ -30,47 +30,48 @@ import hdf.hdf5lib.H5; import hdf.hdf5lib.HDF5Constants; public class H5Ex_D_Chunk { - private static String FILENAME = "H5Ex_D_Chunk.h5"; + private static String FILENAME = "H5Ex_D_Chunk.h5"; private static String DATASETNAME = "DS1"; - private static final int DIM_X = 6; - private static final int DIM_Y = 8; - private static final int CHUNK_X = 4; - private static final int CHUNK_Y = 4; - private static final int RANK = 2; - private static final int NDIMS = 2; + private static final int DIM_X = 6; + private static final int DIM_Y = 8; + private static final int CHUNK_X = 4; + private static final int CHUNK_Y = 4; + private static final int RANK = 2; + private static final int NDIMS = 2; // Values for the status of space allocation enum H5D_layout { - H5D_LAYOUT_ERROR(-1), H5D_COMPACT(0), H5D_CONTIGUOUS(1), H5D_CHUNKED(2), H5D_VIRTUAL(3), H5D_NLAYOUTS(4); + H5D_LAYOUT_ERROR(-1), + H5D_COMPACT(0), + H5D_CONTIGUOUS(1), + H5D_CHUNKED(2), + H5D_VIRTUAL(3), + H5D_NLAYOUTS(4); private static final Map<Integer, H5D_layout> lookup = new HashMap<Integer, H5D_layout>(); - static { + static + { for (H5D_layout s : EnumSet.allOf(H5D_layout.class)) lookup.put(s.getCode(), s); } private int code; - H5D_layout(int layout_type) { - this.code = layout_type; - } + H5D_layout(int layout_type) { this.code = layout_type; } - public int getCode() { - return this.code; - } + public int getCode() { return this.code; } - public static H5D_layout get(int code) { - return lookup.get(code); - } + public static H5D_layout get(int code) { return lookup.get(code); } } - private static void writeChunk() { - long file_id = HDF5Constants.H5I_INVALID_HID; + private static void writeChunk() + { + long file_id = HDF5Constants.H5I_INVALID_HID; long filespace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long dcpl_id = HDF5Constants.H5I_INVALID_HID; - long[] dims = { DIM_X, DIM_Y }; - long[] chunk_dims = { CHUNK_X, CHUNK_Y }; + long dataset_id = HDF5Constants.H5I_INVALID_HID; + long dcpl_id = HDF5Constants.H5I_INVALID_HID; + long[] dims = {DIM_X, DIM_Y}; + long[] chunk_dims = {CHUNK_X, CHUNK_Y}; int[][] dset_data = new int[DIM_X][DIM_Y]; // Initialize data to "1", to make it easier to see the selections. @@ -91,7 +92,7 @@ public class H5Ex_D_Chunk { // Create a new file using default properties. try { file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT, - HDF5Constants.H5P_DEFAULT); + HDF5Constants.H5P_DEFAULT); } catch (Exception e) { e.printStackTrace(); @@ -127,20 +128,21 @@ public class H5Ex_D_Chunk { try { if ((file_id >= 0) && (filespace_id >= 0) && (dcpl_id >= 0)) dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_I32LE, filespace_id, - HDF5Constants.H5P_DEFAULT, dcpl_id, HDF5Constants.H5P_DEFAULT); + HDF5Constants.H5P_DEFAULT, dcpl_id, HDF5Constants.H5P_DEFAULT); } catch (Exception e) { e.printStackTrace(); } // Define and select the first part of the hyperslab selection. - long[] start = { 0, 0 }; - long[] stride = { 3, 3 }; - long[] count = { 2, 3 }; - long[] block = { 2, 2 }; + long[] start = {0, 0}; + long[] stride = {3, 3}; + long[] count = {2, 3}; + long[] block = {2, 2}; try { if ((filespace_id >= 0)) - H5.H5Sselect_hyperslab(filespace_id, HDF5Constants.H5S_SELECT_SET, start, stride, count, block); + H5.H5Sselect_hyperslab(filespace_id, HDF5Constants.H5S_SELECT_SET, start, stride, count, + block); } catch (Exception e) { e.printStackTrace(); @@ -152,12 +154,13 @@ public class H5Ex_D_Chunk { block[1] = 1; try { if ((filespace_id >= 0)) { - H5.H5Sselect_hyperslab(filespace_id, HDF5Constants.H5S_SELECT_NOTB, start, stride, count, block); + H5.H5Sselect_hyperslab(filespace_id, HDF5Constants.H5S_SELECT_NOTB, start, stride, count, + block); // Write the data to the dataset. if (dataset_id >= 0) H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, filespace_id, - HDF5Constants.H5P_DEFAULT, dset_data); + HDF5Constants.H5P_DEFAULT, dset_data); } } catch (Exception e) { @@ -199,11 +202,12 @@ public class H5Ex_D_Chunk { } } - private static void readChunk() { - long file_id = HDF5Constants.H5I_INVALID_HID; + private static void readChunk() + { + long file_id = HDF5Constants.H5I_INVALID_HID; long filespace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long dcpl_id = HDF5Constants.H5I_INVALID_HID; + long dataset_id = HDF5Constants.H5I_INVALID_HID; + long dcpl_id = HDF5Constants.H5I_INVALID_HID; int[][] dset_data = new int[DIM_X][DIM_Y]; // Open an existing file. @@ -267,8 +271,8 @@ public class H5Ex_D_Chunk { // Read the data using the default properties. try { if (dataset_id >= 0) - H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, dset_data); + H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, + HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, dset_data); } catch (Exception e) { e.printStackTrace(); @@ -294,18 +298,19 @@ public class H5Ex_D_Chunk { if (dataset_id >= 0) { filespace_id = H5.H5Dget_space(dataset_id); - long[] start = { 0, 1 }; - long[] stride = { 4, 4 }; - long[] count = { 2, 2 }; - long[] block = { 2, 3 }; + long[] start = {0, 1}; + long[] stride = {4, 4}; + long[] count = {2, 2}; + long[] block = {2, 3}; if (filespace_id >= 0) { - H5.H5Sselect_hyperslab(filespace_id, HDF5Constants.H5S_SELECT_SET, start, stride, count, block); + H5.H5Sselect_hyperslab(filespace_id, HDF5Constants.H5S_SELECT_SET, start, stride, count, + block); // Read the data using the previously defined hyperslab. if ((dataset_id >= 0) && (filespace_id >= 0)) - H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, filespace_id, - HDF5Constants.H5P_DEFAULT, dset_data); + H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, + filespace_id, HDF5Constants.H5P_DEFAULT, dset_data); } } } @@ -358,9 +363,9 @@ public class H5Ex_D_Chunk { } } - public static void main(String[] args) { + public static void main(String[] args) + { H5Ex_D_Chunk.writeChunk(); H5Ex_D_Chunk.readChunk(); } - } diff --git a/java/examples/datasets/H5Ex_D_Compact.java b/java/examples/datasets/H5Ex_D_Compact.java index 0abf8da..3a60283 100644 --- a/java/examples/datasets/H5Ex_D_Compact.java +++ b/java/examples/datasets/H5Ex_D_Compact.java @@ -27,43 +27,44 @@ import hdf.hdf5lib.H5; import hdf.hdf5lib.HDF5Constants; public class H5Ex_D_Compact { - private static String FILENAME = "H5Ex_D_Compact.h5"; + private static String FILENAME = "H5Ex_D_Compact.h5"; private static String DATASETNAME = "DS1"; - private static final int DIM_X = 4; - private static final int DIM_Y = 7; - private static final int RANK = 2; + private static final int DIM_X = 4; + private static final int DIM_Y = 7; + private static final int RANK = 2; // Values for the status of space allocation enum H5D_layout { - H5D_LAYOUT_ERROR(-1), H5D_COMPACT(0), H5D_CONTIGUOUS(1), H5D_CHUNKED(2), H5D_VIRTUAL(3), H5D_NLAYOUTS(4); + H5D_LAYOUT_ERROR(-1), + H5D_COMPACT(0), + H5D_CONTIGUOUS(1), + H5D_CHUNKED(2), + H5D_VIRTUAL(3), + H5D_NLAYOUTS(4); private static final Map<Integer, H5D_layout> lookup = new HashMap<Integer, H5D_layout>(); - static { + static + { for (H5D_layout s : EnumSet.allOf(H5D_layout.class)) lookup.put(s.getCode(), s); } private int code; - H5D_layout(int layout_type) { - this.code = layout_type; - } + H5D_layout(int layout_type) { this.code = layout_type; } - public int getCode() { - return this.code; - } + public int getCode() { return this.code; } - public static H5D_layout get(int code) { - return lookup.get(code); - } + public static H5D_layout get(int code) { return lookup.get(code); } } - private static void writeCompact() { - long file_id = HDF5Constants.H5I_INVALID_HID; + private static void writeCompact() + { + long file_id = HDF5Constants.H5I_INVALID_HID; long filespace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long dcpl_id = HDF5Constants.H5I_INVALID_HID; - long[] dims = { DIM_X, DIM_Y }; + long dataset_id = HDF5Constants.H5I_INVALID_HID; + long dcpl_id = HDF5Constants.H5I_INVALID_HID; + long[] dims = {DIM_X, DIM_Y}; int[][] dset_data = new int[DIM_X][DIM_Y]; // Initialize data. @@ -74,7 +75,7 @@ public class H5Ex_D_Compact { // Create a new file using default properties. try { file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT, - HDF5Constants.H5P_DEFAULT); + HDF5Constants.H5P_DEFAULT); } catch (Exception e) { e.printStackTrace(); @@ -110,7 +111,7 @@ public class H5Ex_D_Compact { try { if ((file_id >= 0) && (filespace_id >= 0) && (dcpl_id >= 0)) dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_I32LE, filespace_id, - HDF5Constants.H5P_DEFAULT, dcpl_id, HDF5Constants.H5P_DEFAULT); + HDF5Constants.H5P_DEFAULT, dcpl_id, HDF5Constants.H5P_DEFAULT); } catch (Exception e) { e.printStackTrace(); @@ -119,8 +120,8 @@ public class H5Ex_D_Compact { // Write the data to the dataset. try { if (dataset_id >= 0) - H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, dset_data); + H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, + HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, dset_data); } catch (Exception e) { e.printStackTrace(); @@ -161,11 +162,12 @@ public class H5Ex_D_Compact { } } - private static void readCompact() { - long file_id = HDF5Constants.H5I_INVALID_HID; + private static void readCompact() + { + long file_id = HDF5Constants.H5I_INVALID_HID; long filespace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long dcpl_id = HDF5Constants.H5I_INVALID_HID; + long dataset_id = HDF5Constants.H5I_INVALID_HID; + long dcpl_id = HDF5Constants.H5I_INVALID_HID; int[][] dset_data = new int[DIM_X][DIM_Y]; // Open file and dataset using the default properties. @@ -229,8 +231,8 @@ public class H5Ex_D_Compact { // Read the data using the default properties. try { if (dataset_id >= 0) - H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, dset_data); + H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, + HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, dset_data); } catch (Exception e) { e.printStackTrace(); @@ -281,9 +283,9 @@ public class H5Ex_D_Compact { } } - public static void main(String[] args) { + public static void main(String[] args) + { H5Ex_D_Compact.writeCompact(); H5Ex_D_Compact.readCompact(); } - } diff --git a/java/examples/datasets/H5Ex_D_External.java b/java/examples/datasets/H5Ex_D_External.java index 9c3787f..d706fb7 100644 --- a/java/examples/datasets/H5Ex_D_External.java +++ b/java/examples/datasets/H5Ex_D_External.java @@ -24,20 +24,21 @@ import hdf.hdf5lib.H5; import hdf.hdf5lib.HDF5Constants; public class H5Ex_D_External { - private static String FILENAME = "H5Ex_D_External.h5"; - private static String EXTERNALNAME = "H5Ex_D_External.data"; - private static String DATASETNAME = "DS1"; - private static final int DIM_X = 4; - private static final int DIM_Y = 7; - private static final int RANK = 2; + private static String FILENAME = "H5Ex_D_External.h5"; + private static String EXTERNALNAME = "H5Ex_D_External.data"; + private static String DATASETNAME = "DS1"; + private static final int DIM_X = 4; + private static final int DIM_Y = 7; + private static final int RANK = 2; private static final int NAME_BUF_SIZE = 32; - private static void writeExternal() { - long file_id = HDF5Constants.H5I_INVALID_HID; - long dcpl_id = HDF5Constants.H5I_INVALID_HID; + private static void writeExternal() + { + long file_id = HDF5Constants.H5I_INVALID_HID; + long dcpl_id = HDF5Constants.H5I_INVALID_HID; long filespace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long[] dims = { DIM_X, DIM_Y }; + long dataset_id = HDF5Constants.H5I_INVALID_HID; + long[] dims = {DIM_X, DIM_Y}; int[][] dset_data = new int[DIM_X][DIM_Y]; // Initialize the dataset. @@ -48,7 +49,7 @@ public class H5Ex_D_External { // Create a new file using default properties. try { file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT, - HDF5Constants.H5P_DEFAULT); + HDF5Constants.H5P_DEFAULT); } catch (Exception e) { e.printStackTrace(); @@ -84,7 +85,7 @@ public class H5Ex_D_External { try { if ((file_id >= 0) && (filespace_id >= 0) && (dcpl_id >= 0)) dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_I32LE, filespace_id, - HDF5Constants.H5P_DEFAULT, dcpl_id, HDF5Constants.H5P_DEFAULT); + HDF5Constants.H5P_DEFAULT, dcpl_id, HDF5Constants.H5P_DEFAULT); } catch (Exception e) { e.printStackTrace(); @@ -92,8 +93,8 @@ public class H5Ex_D_External { // Write the dataset. try { - H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, dset_data); + H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, + HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, dset_data); } catch (Exception e) { e.printStackTrace(); @@ -133,15 +134,15 @@ public class H5Ex_D_External { catch (Exception e) { e.printStackTrace(); } - } - private static void readExternal() { - long file_id = HDF5Constants.H5I_INVALID_HID; - long dcpl_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; + private static void readExternal() + { + long file_id = HDF5Constants.H5I_INVALID_HID; + long dcpl_id = HDF5Constants.H5I_INVALID_HID; + long dataset_id = HDF5Constants.H5I_INVALID_HID; int[][] dset_data = new int[DIM_X][DIM_Y]; - String[] Xname = new String[1]; + String[] Xname = new String[1]; // Open file using the default properties. try { @@ -183,8 +184,8 @@ public class H5Ex_D_External { // Read the data using the default properties. try { if (dataset_id >= 0) - H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, dset_data); + H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, + HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, dset_data); } catch (Exception e) { e.printStackTrace(); @@ -227,9 +228,9 @@ public class H5Ex_D_External { } } - public static void main(String[] args) { + public static void main(String[] args) + { H5Ex_D_External.writeExternal(); H5Ex_D_External.readExternal(); } - } diff --git a/java/examples/datasets/H5Ex_D_FillValue.java b/java/examples/datasets/H5Ex_D_FillValue.java index 3526993..db4dff7 100644 --- a/java/examples/datasets/H5Ex_D_FillValue.java +++ b/java/examples/datasets/H5Ex_D_FillValue.java @@ -26,29 +26,30 @@ import hdf.hdf5lib.H5; import hdf.hdf5lib.HDF5Constants; public class H5Ex_D_FillValue { - private static String FILENAME = "H5Ex_D_FillValue.h5"; + private static String FILENAME = "H5Ex_D_FillValue.h5"; private static String DATASETNAME = "ExtendibleArray"; - private static final int DIM_X = 4; - private static final int DIM_Y = 7; - private static final int EDIM_X = 6; - private static final int EDIM_Y = 10; - private static final int CHUNK_X = 4; - private static final int CHUNK_Y = 4; - private static final int RANK = 2; - private static final int NDIMS = 2; - private static final int FILLVAL = 99; - - private static void fillValue() { - long file_id = HDF5Constants.H5I_INVALID_HID; - long dcpl_id = HDF5Constants.H5I_INVALID_HID; - long dataspace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long[] dims = { DIM_X, DIM_Y }; - long[] extdims = { EDIM_X, EDIM_Y }; - long[] chunk_dims = { CHUNK_X, CHUNK_Y }; - long[] maxdims = { HDF5Constants.H5S_UNLIMITED, HDF5Constants.H5S_UNLIMITED }; - int[][] write_dset_data = new int[DIM_X][DIM_Y]; - int[][] read_dset_data = new int[DIM_X][DIM_Y]; + private static final int DIM_X = 4; + private static final int DIM_Y = 7; + private static final int EDIM_X = 6; + private static final int EDIM_Y = 10; + private static final int CHUNK_X = 4; + private static final int CHUNK_Y = 4; + private static final int RANK = 2; + private static final int NDIMS = 2; + private static final int FILLVAL = 99; + + private static void fillValue() + { + long file_id = HDF5Constants.H5I_INVALID_HID; + long dcpl_id = HDF5Constants.H5I_INVALID_HID; + long dataspace_id = HDF5Constants.H5I_INVALID_HID; + long dataset_id = HDF5Constants.H5I_INVALID_HID; + long[] dims = {DIM_X, DIM_Y}; + long[] extdims = {EDIM_X, EDIM_Y}; + long[] chunk_dims = {CHUNK_X, CHUNK_Y}; + long[] maxdims = {HDF5Constants.H5S_UNLIMITED, HDF5Constants.H5S_UNLIMITED}; + int[][] write_dset_data = new int[DIM_X][DIM_Y]; + int[][] read_dset_data = new int[DIM_X][DIM_Y]; int[][] extend_dset_data = new int[EDIM_X][EDIM_Y]; // Initialize the dataset. @@ -59,7 +60,7 @@ public class H5Ex_D_FillValue { // Create a new file using default properties. try { file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT, - HDF5Constants.H5P_DEFAULT); + HDF5Constants.H5P_DEFAULT); } catch (Exception e) { e.printStackTrace(); @@ -92,7 +93,7 @@ public class H5Ex_D_FillValue { // Set the fill value for the dataset try { - int[] fill_value = { FILLVAL }; + int[] fill_value = {FILLVAL}; if (dcpl_id >= 0) H5.H5Pset_fill_value(dcpl_id, HDF5Constants.H5T_NATIVE_INT, fill_value); } @@ -115,7 +116,7 @@ public class H5Ex_D_FillValue { try { if ((file_id >= 0) && (dataspace_id >= 0) && (dcpl_id >= 0)) dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_I32LE, dataspace_id, - HDF5Constants.H5P_DEFAULT, dcpl_id, HDF5Constants.H5P_DEFAULT); + HDF5Constants.H5P_DEFAULT, dcpl_id, HDF5Constants.H5P_DEFAULT); } catch (Exception e) { e.printStackTrace(); @@ -124,8 +125,8 @@ public class H5Ex_D_FillValue { // Read values from the dataset, which has not been written to yet. try { if (dataset_id >= 0) - H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, read_dset_data); + H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, + HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, read_dset_data); } catch (Exception e) { e.printStackTrace(); @@ -144,8 +145,8 @@ public class H5Ex_D_FillValue { // Write the data to the dataset. try { if (dataset_id >= 0) - H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, write_dset_data); + H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, + HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, write_dset_data); } catch (Exception e) { e.printStackTrace(); @@ -154,8 +155,8 @@ public class H5Ex_D_FillValue { // Read the data back. try { if (dataset_id >= 0) - H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, read_dset_data); + H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, + HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, read_dset_data); } catch (Exception e) { e.printStackTrace(); @@ -183,8 +184,8 @@ public class H5Ex_D_FillValue { // Read from the extended dataset. try { if (dataset_id >= 0) - H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, extend_dset_data); + H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, + HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, extend_dset_data); } catch (Exception e) { e.printStackTrace(); @@ -233,11 +234,7 @@ public class H5Ex_D_FillValue { catch (Exception e) { e.printStackTrace(); } - - } - - public static void main(String[] args) { - H5Ex_D_FillValue.fillValue(); } + public static void main(String[] args) { H5Ex_D_FillValue.fillValue(); } } diff --git a/java/examples/datasets/H5Ex_D_Gzip.java b/java/examples/datasets/H5Ex_D_Gzip.java index 404ff05..0a94254 100644 --- a/java/examples/datasets/H5Ex_D_Gzip.java +++ b/java/examples/datasets/H5Ex_D_Gzip.java @@ -29,45 +29,46 @@ import hdf.hdf5lib.H5; import hdf.hdf5lib.HDF5Constants; public class H5Ex_D_Gzip { - private static String FILENAME = "H5Ex_D_Gzip.h5"; + private static String FILENAME = "H5Ex_D_Gzip.h5"; private static String DATASETNAME = "DS1"; - private static final int DIM_X = 32; - private static final int DIM_Y = 64; - private static final int CHUNK_X = 4; - private static final int CHUNK_Y = 8; - private static final int RANK = 2; - private static final int NDIMS = 2; + private static final int DIM_X = 32; + private static final int DIM_Y = 64; + private static final int CHUNK_X = 4; + private static final int CHUNK_Y = 8; + private static final int RANK = 2; + private static final int NDIMS = 2; // Values for the status of space allocation enum H5Z_filter { - H5Z_FILTER_ERROR(HDF5Constants.H5Z_FILTER_ERROR), H5Z_FILTER_NONE(HDF5Constants.H5Z_FILTER_NONE), H5Z_FILTER_DEFLATE( - HDF5Constants.H5Z_FILTER_DEFLATE), H5Z_FILTER_SHUFFLE(HDF5Constants.H5Z_FILTER_SHUFFLE), H5Z_FILTER_FLETCHER32( - HDF5Constants.H5Z_FILTER_FLETCHER32), H5Z_FILTER_SZIP(HDF5Constants.H5Z_FILTER_SZIP), H5Z_FILTER_NBIT( - HDF5Constants.H5Z_FILTER_NBIT), H5Z_FILTER_SCALEOFFSET(HDF5Constants.H5Z_FILTER_SCALEOFFSET), H5Z_FILTER_RESERVED( - HDF5Constants.H5Z_FILTER_RESERVED), H5Z_FILTER_MAX(HDF5Constants.H5Z_FILTER_MAX); + H5Z_FILTER_ERROR(HDF5Constants.H5Z_FILTER_ERROR), + H5Z_FILTER_NONE(HDF5Constants.H5Z_FILTER_NONE), + H5Z_FILTER_DEFLATE(HDF5Constants.H5Z_FILTER_DEFLATE), + H5Z_FILTER_SHUFFLE(HDF5Constants.H5Z_FILTER_SHUFFLE), + H5Z_FILTER_FLETCHER32(HDF5Constants.H5Z_FILTER_FLETCHER32), + H5Z_FILTER_SZIP(HDF5Constants.H5Z_FILTER_SZIP), + H5Z_FILTER_NBIT(HDF5Constants.H5Z_FILTER_NBIT), + H5Z_FILTER_SCALEOFFSET(HDF5Constants.H5Z_FILTER_SCALEOFFSET), + H5Z_FILTER_RESERVED(HDF5Constants.H5Z_FILTER_RESERVED), + H5Z_FILTER_MAX(HDF5Constants.H5Z_FILTER_MAX); private static final Map<Integer, H5Z_filter> lookup = new HashMap<Integer, H5Z_filter>(); - static { + static + { for (H5Z_filter s : EnumSet.allOf(H5Z_filter.class)) lookup.put(s.getCode(), s); } private int code; - H5Z_filter(int layout_type) { - this.code = layout_type; - } + H5Z_filter(int layout_type) { this.code = layout_type; } - public int getCode() { - return this.code; - } + public int getCode() { return this.code; } - public static H5Z_filter get(int code) { - return lookup.get(code); - } + public static H5Z_filter get(int code) { return lookup.get(code); } } - private static boolean checkGzipFilter() { + private static boolean checkGzipFilter() + { try { int available = H5.H5Zfilter_avail(HDF5Constants.H5Z_FILTER_DEFLATE); if (available == 0) { @@ -81,8 +82,8 @@ public class H5Ex_D_Gzip { try { int filter_info = H5.H5Zget_filter_info(HDF5Constants.H5Z_FILTER_DEFLATE); - if (((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_ENCODE_ENABLED) == 0) - || ((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_DECODE_ENABLED) == 0)) { + if (((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_ENCODE_ENABLED) == 0) || + ((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_DECODE_ENABLED) == 0)) { System.out.println("gzip filter not available for encoding and decoding."); return false; } @@ -93,13 +94,14 @@ public class H5Ex_D_Gzip { return true; } - private static void writeGzip() { - long file_id = HDF5Constants.H5I_INVALID_HID; + private static void writeGzip() + { + long file_id = HDF5Constants.H5I_INVALID_HID; long filespace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long dcpl_id = HDF5Constants.H5I_INVALID_HID; - long[] dims = { DIM_X, DIM_Y }; - long[] chunk_dims = { CHUNK_X, CHUNK_Y }; + long dataset_id = HDF5Constants.H5I_INVALID_HID; + long dcpl_id = HDF5Constants.H5I_INVALID_HID; + long[] dims = {DIM_X, DIM_Y}; + long[] chunk_dims = {CHUNK_X, CHUNK_Y}; int[][] dset_data = new int[DIM_X][DIM_Y]; // Initialize data. @@ -110,7 +112,7 @@ public class H5Ex_D_Gzip { // Create a new file using default properties. try { file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT, - HDF5Constants.H5P_DEFAULT); + HDF5Constants.H5P_DEFAULT); } catch (Exception e) { e.printStackTrace(); @@ -143,7 +145,7 @@ public class H5Ex_D_Gzip { try { if ((file_id >= 0) && (filespace_id >= 0) && (dcpl_id >= 0)) dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_I32LE, filespace_id, - HDF5Constants.H5P_DEFAULT, dcpl_id, HDF5Constants.H5P_DEFAULT); + HDF5Constants.H5P_DEFAULT, dcpl_id, HDF5Constants.H5P_DEFAULT); } catch (Exception e) { e.printStackTrace(); @@ -152,8 +154,8 @@ public class H5Ex_D_Gzip { // Write the data to the dataset. try { if (dataset_id >= 0) - H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, dset_data); + H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, + HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, dset_data); } catch (Exception e) { e.printStackTrace(); @@ -194,10 +196,11 @@ public class H5Ex_D_Gzip { } } - private static void readGzip() { - long file_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long dcpl_id = HDF5Constants.H5I_INVALID_HID; + private static void readGzip() + { + long file_id = HDF5Constants.H5I_INVALID_HID; + long dataset_id = HDF5Constants.H5I_INVALID_HID; + long dcpl_id = HDF5Constants.H5I_INVALID_HID; int[][] dset_data = new int[DIM_X][DIM_Y]; // Open an existing file. @@ -231,14 +234,14 @@ public class H5Ex_D_Gzip { try { if (dcpl_id >= 0) { // Java lib requires a valid filter_name object and cd_values - int[] flags = { 0 }; - long[] cd_nelmts = { 1 }; - int[] cd_values = { 0 }; - String[] filter_name = { "" }; - int[] filter_config = { 0 }; - int filter_type = -1; - filter_type = H5 - .H5Pget_filter(dcpl_id, 0, flags, cd_nelmts, cd_values, 120, filter_name, filter_config); + int[] flags = {0}; + long[] cd_nelmts = {1}; + int[] cd_values = {0}; + String[] filter_name = {""}; + int[] filter_config = {0}; + int filter_type = -1; + filter_type = H5.H5Pget_filter(dcpl_id, 0, flags, cd_nelmts, cd_values, 120, filter_name, + filter_config); System.out.print("Filter type is: "); switch (H5Z_filter.get(filter_type)) { case H5Z_FILTER_DEFLATE: @@ -272,8 +275,8 @@ public class H5Ex_D_Gzip { // Read the data using the default properties. try { if (dataset_id >= 0) { - H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, dset_data); + H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, + HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, dset_data); } } catch (Exception e) { @@ -318,7 +321,8 @@ public class H5Ex_D_Gzip { } } - public static void main(String[] args) { + public static void main(String[] args) + { // Check if gzip compression is available and can be used for both // compression and decompression. Normally we do not perform error // checking in these examples for the sake of clarity, but in this @@ -329,5 +333,4 @@ public class H5Ex_D_Gzip { H5Ex_D_Gzip.readGzip(); } } - } diff --git a/java/examples/datasets/H5Ex_D_Hyperslab.java b/java/examples/datasets/H5Ex_D_Hyperslab.java index fa3473f..0575d50 100644 --- a/java/examples/datasets/H5Ex_D_Hyperslab.java +++ b/java/examples/datasets/H5Ex_D_Hyperslab.java @@ -26,17 +26,18 @@ import hdf.hdf5lib.H5; import hdf.hdf5lib.HDF5Constants; public class H5Ex_D_Hyperslab { - private static String FILENAME = "H5Ex_D_Hyperslab.h5"; + private static String FILENAME = "H5Ex_D_Hyperslab.h5"; private static String DATASETNAME = "DS1"; - private static final int DIM_X = 6; - private static final int DIM_Y = 8; - private static final int RANK = 2; + private static final int DIM_X = 6; + private static final int DIM_Y = 8; + private static final int RANK = 2; - private static void writeHyperslab() { - long file_id = HDF5Constants.H5I_INVALID_HID; + private static void writeHyperslab() + { + long file_id = HDF5Constants.H5I_INVALID_HID; long filespace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long[] dims = { DIM_X, DIM_Y }; + long dataset_id = HDF5Constants.H5I_INVALID_HID; + long[] dims = {DIM_X, DIM_Y}; int[][] dset_data = new int[DIM_X][DIM_Y]; // Initialize data to "1", to make it easier to see the selections. @@ -57,7 +58,7 @@ public class H5Ex_D_Hyperslab { // Create a new file using default properties. try { file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT, - HDF5Constants.H5P_DEFAULT); + HDF5Constants.H5P_DEFAULT); } catch (Exception e) { e.printStackTrace(); @@ -76,20 +77,22 @@ public class H5Ex_D_Hyperslab { try { if ((file_id >= 0) && (filespace_id >= 0)) dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_I32LE, filespace_id, - HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, + HDF5Constants.H5P_DEFAULT); } catch (Exception e) { e.printStackTrace(); } // Define and select the first part of the hyperslab selection. - long[] start = { 0, 0 }; - long[] stride = { 3, 3 }; - long[] count = { 2, 3 }; - long[] block = { 2, 2 }; + long[] start = {0, 0}; + long[] stride = {3, 3}; + long[] count = {2, 3}; + long[] block = {2, 2}; try { if ((filespace_id >= 0)) - H5.H5Sselect_hyperslab(filespace_id, HDF5Constants.H5S_SELECT_SET, start, stride, count, block); + H5.H5Sselect_hyperslab(filespace_id, HDF5Constants.H5S_SELECT_SET, start, stride, count, + block); } catch (Exception e) { e.printStackTrace(); @@ -101,12 +104,13 @@ public class H5Ex_D_Hyperslab { block[1] = 1; try { if ((filespace_id >= 0)) { - H5.H5Sselect_hyperslab(filespace_id, HDF5Constants.H5S_SELECT_NOTB, start, stride, count, block); + H5.H5Sselect_hyperslab(filespace_id, HDF5Constants.H5S_SELECT_NOTB, start, stride, count, + block); // Write the data to the dataset. if (dataset_id >= 0) H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, filespace_id, - HDF5Constants.H5P_DEFAULT, dset_data); + HDF5Constants.H5P_DEFAULT, dset_data); } } catch (Exception e) { @@ -140,11 +144,12 @@ public class H5Ex_D_Hyperslab { } } - private static void readHyperslab() { - long file_id = HDF5Constants.H5I_INVALID_HID; + private static void readHyperslab() + { + long file_id = HDF5Constants.H5I_INVALID_HID; long filespace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long dcpl_id = HDF5Constants.H5I_INVALID_HID; + long dataset_id = HDF5Constants.H5I_INVALID_HID; + long dcpl_id = HDF5Constants.H5I_INVALID_HID; int[][] dset_data = new int[DIM_X][DIM_Y]; // Open an existing file. @@ -167,8 +172,8 @@ public class H5Ex_D_Hyperslab { // Read the data using the default properties. try { if (dataset_id >= 0) - H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, dset_data); + H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, + HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, dset_data); } catch (Exception e) { e.printStackTrace(); @@ -194,18 +199,19 @@ public class H5Ex_D_Hyperslab { if (dataset_id >= 0) { filespace_id = H5.H5Dget_space(dataset_id); - long[] start = { 0, 1 }; - long[] stride = { 4, 4 }; - long[] count = { 2, 2 }; - long[] block = { 2, 3 }; + long[] start = {0, 1}; + long[] stride = {4, 4}; + long[] count = {2, 2}; + long[] block = {2, 3}; if (filespace_id >= 0) { - H5.H5Sselect_hyperslab(filespace_id, HDF5Constants.H5S_SELECT_SET, start, stride, count, block); + H5.H5Sselect_hyperslab(filespace_id, HDF5Constants.H5S_SELECT_SET, start, stride, count, + block); // Read the data using the previously defined hyperslab. if ((dataset_id >= 0) && (filespace_id >= 0)) - H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, filespace_id, - HDF5Constants.H5P_DEFAULT, dset_data); + H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, + filespace_id, HDF5Constants.H5P_DEFAULT, dset_data); } } } @@ -258,9 +264,9 @@ public class H5Ex_D_Hyperslab { } } - public static void main(String[] args) { + public static void main(String[] args) + { H5Ex_D_Hyperslab.writeHyperslab(); H5Ex_D_Hyperslab.readHyperslab(); } - } diff --git a/java/examples/datasets/H5Ex_D_Nbit.java b/java/examples/datasets/H5Ex_D_Nbit.java index 35d23a9..d54ce21 100644 --- a/java/examples/datasets/H5Ex_D_Nbit.java +++ b/java/examples/datasets/H5Ex_D_Nbit.java @@ -29,45 +29,46 @@ import hdf.hdf5lib.H5; import hdf.hdf5lib.HDF5Constants; public class H5Ex_D_Nbit { - private static String FILENAME = "H5Ex_D_Nbit.h5"; + private static String FILENAME = "H5Ex_D_Nbit.h5"; private static String DATASETNAME = "DS1"; - private static final int DIM_X = 32; - private static final int DIM_Y = 64; - private static final int CHUNK_X = 4; - private static final int CHUNK_Y = 8; - private static final int RANK = 2; - private static final int NDIMS = 2; + private static final int DIM_X = 32; + private static final int DIM_Y = 64; + private static final int CHUNK_X = 4; + private static final int CHUNK_Y = 8; + private static final int RANK = 2; + private static final int NDIMS = 2; // Values for the status of space allocation enum H5Z_filter { - H5Z_FILTER_ERROR(HDF5Constants.H5Z_FILTER_ERROR), H5Z_FILTER_NONE(HDF5Constants.H5Z_FILTER_NONE), H5Z_FILTER_DEFLATE( - HDF5Constants.H5Z_FILTER_DEFLATE), H5Z_FILTER_SHUFFLE(HDF5Constants.H5Z_FILTER_SHUFFLE), H5Z_FILTER_FLETCHER32( - HDF5Constants.H5Z_FILTER_FLETCHER32), H5Z_FILTER_SZIP(HDF5Constants.H5Z_FILTER_SZIP), H5Z_FILTER_NBIT( - HDF5Constants.H5Z_FILTER_NBIT), H5Z_FILTER_SCALEOFFSET(HDF5Constants.H5Z_FILTER_SCALEOFFSET), H5Z_FILTER_RESERVED( - HDF5Constants.H5Z_FILTER_RESERVED), H5Z_FILTER_MAX(HDF5Constants.H5Z_FILTER_MAX); + H5Z_FILTER_ERROR(HDF5Constants.H5Z_FILTER_ERROR), + H5Z_FILTER_NONE(HDF5Constants.H5Z_FILTER_NONE), + H5Z_FILTER_DEFLATE(HDF5Constants.H5Z_FILTER_DEFLATE), + H5Z_FILTER_SHUFFLE(HDF5Constants.H5Z_FILTER_SHUFFLE), + H5Z_FILTER_FLETCHER32(HDF5Constants.H5Z_FILTER_FLETCHER32), + H5Z_FILTER_SZIP(HDF5Constants.H5Z_FILTER_SZIP), + H5Z_FILTER_NBIT(HDF5Constants.H5Z_FILTER_NBIT), + H5Z_FILTER_SCALEOFFSET(HDF5Constants.H5Z_FILTER_SCALEOFFSET), + H5Z_FILTER_RESERVED(HDF5Constants.H5Z_FILTER_RESERVED), + H5Z_FILTER_MAX(HDF5Constants.H5Z_FILTER_MAX); private static final Map<Integer, H5Z_filter> lookup = new HashMap<Integer, H5Z_filter>(); - static { + static + { for (H5Z_filter s : EnumSet.allOf(H5Z_filter.class)) lookup.put(s.getCode(), s); } private int code; - H5Z_filter(int layout_type) { - this.code = layout_type; - } + H5Z_filter(int layout_type) { this.code = layout_type; } - public int getCode() { - return this.code; - } + public int getCode() { return this.code; } - public static H5Z_filter get(int code) { - return lookup.get(code); - } + public static H5Z_filter get(int code) { return lookup.get(code); } } - private static boolean checkNbitFilter() { + private static boolean checkNbitFilter() + { try { // Check if N-Bit compression is available and can be used for both compression and decompression. int available = H5.H5Zfilter_avail(HDF5Constants.H5Z_FILTER_NBIT); @@ -82,8 +83,8 @@ public class H5Ex_D_Nbit { try { int filter_info = H5.H5Zget_filter_info(HDF5Constants.H5Z_FILTER_NBIT); - if (((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_ENCODE_ENABLED) == 0) - || ((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_DECODE_ENABLED) == 0)) { + if (((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_ENCODE_ENABLED) == 0) || + ((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_DECODE_ENABLED) == 0)) { System.out.println("N-Bit filter not available for encoding and decoding."); return false; } @@ -94,14 +95,15 @@ public class H5Ex_D_Nbit { return true; } - private static void writeData() throws Exception { - long file_id = HDF5Constants.H5I_INVALID_HID; + private static void writeData() throws Exception + { + long file_id = HDF5Constants.H5I_INVALID_HID; long filespace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long dtype_id = HDF5Constants.H5I_INVALID_HID; - long dcpl_id = HDF5Constants.H5I_INVALID_HID; - long[] dims = { DIM_X, DIM_Y }; - long[] chunk_dims = { CHUNK_X, CHUNK_Y }; + long dataset_id = HDF5Constants.H5I_INVALID_HID; + long dtype_id = HDF5Constants.H5I_INVALID_HID; + long dcpl_id = HDF5Constants.H5I_INVALID_HID; + long[] dims = {DIM_X, DIM_Y}; + long[] chunk_dims = {CHUNK_X, CHUNK_Y}; int[][] dset_data = new int[DIM_X][DIM_Y]; // Initialize data. @@ -112,7 +114,7 @@ public class H5Ex_D_Nbit { try { // Create a new file using the default properties. file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT, - HDF5Constants.H5P_DEFAULT); + HDF5Constants.H5P_DEFAULT); // Create dataspace. Setting maximum size to NULL sets the maximum // size to be the current size. @@ -130,12 +132,12 @@ public class H5Ex_D_Nbit { H5.H5Pset_chunk(dcpl_id, NDIMS, chunk_dims); // Create the dataset. - dataset_id = H5.H5Dcreate(file_id, DATASETNAME, dtype_id, filespace_id, HDF5Constants.H5P_DEFAULT, dcpl_id, - HDF5Constants.H5P_DEFAULT); + dataset_id = H5.H5Dcreate(file_id, DATASETNAME, dtype_id, filespace_id, HDF5Constants.H5P_DEFAULT, + dcpl_id, HDF5Constants.H5P_DEFAULT); // Write the data to the dataset. - H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, dset_data); + H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, + HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, dset_data); } catch (Exception e) { e.printStackTrace(); @@ -155,10 +157,11 @@ public class H5Ex_D_Nbit { } } - private static void readData() throws Exception { - long file_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long dcpl_id = HDF5Constants.H5I_INVALID_HID; + private static void readData() throws Exception + { + long file_id = HDF5Constants.H5I_INVALID_HID; + long dataset_id = HDF5Constants.H5I_INVALID_HID; + long dcpl_id = HDF5Constants.H5I_INVALID_HID; int[][] dset_data = new int[DIM_X][DIM_Y]; // Open an existing file. @@ -192,14 +195,14 @@ public class H5Ex_D_Nbit { try { if (dcpl_id >= 0) { // Java lib requires a valid filter_name object and cd_values - int[] flags = { 0 }; - long[] cd_nelmts = { 1 }; - int[] cd_values = { 0 }; - String[] filter_name = { "" }; - int[] filter_config = { 0 }; - int filter_type = -1; - filter_type = H5 - .H5Pget_filter(dcpl_id, 0, flags, cd_nelmts, cd_values, 120, filter_name, filter_config); + int[] flags = {0}; + long[] cd_nelmts = {1}; + int[] cd_values = {0}; + String[] filter_name = {""}; + int[] filter_config = {0}; + int filter_type = -1; + filter_type = H5.H5Pget_filter(dcpl_id, 0, flags, cd_nelmts, cd_values, 120, filter_name, + filter_config); System.out.print("Filter type is: "); switch (H5Z_filter.get(filter_type)) { case H5Z_FILTER_DEFLATE: @@ -234,7 +237,7 @@ public class H5Ex_D_Nbit { try { if (dataset_id >= 0) { int status = H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, - HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, dset_data); + HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, dset_data); // Check if the read was successful. if (status < 0) System.out.print("Dataset read failed!"); @@ -280,14 +283,14 @@ public class H5Ex_D_Nbit { catch (Exception e) { e.printStackTrace(); } - } - public static void main(String[] args) { + public static void main(String[] args) + { /* - * Check if N-Bit compression is available and can be used for both compression and decompression. Normally we - * do not perform error checking in these examples for the sake of clarity, but in this case we will make an - * exception because this filter is an optional part of the hdf5 library. + * Check if N-Bit compression is available and can be used for both compression and decompression. + * Normally we do not perform error checking in these examples for the sake of clarity, but in this + * case we will make an exception because this filter is an optional part of the hdf5 library. */ try { if (H5Ex_D_Nbit.checkNbitFilter()) { diff --git a/java/examples/datasets/H5Ex_D_ReadWrite.java b/java/examples/datasets/H5Ex_D_ReadWrite.java index db930d3..4b26a2c 100644 --- a/java/examples/datasets/H5Ex_D_ReadWrite.java +++ b/java/examples/datasets/H5Ex_D_ReadWrite.java @@ -24,17 +24,18 @@ import hdf.hdf5lib.H5; import hdf.hdf5lib.HDF5Constants; public class H5Ex_D_ReadWrite { - private static String FILENAME = "H5Ex_D_ReadWrite.h5"; + private static String FILENAME = "H5Ex_D_ReadWrite.h5"; private static String DATASETNAME = "DS1"; - private static final int DIM_X = 4; - private static final int DIM_Y = 7; - private static final int RANK = 2; + private static final int DIM_X = 4; + private static final int DIM_Y = 7; + private static final int RANK = 2; - private static void WriteDataset() { - long file_id = HDF5Constants.H5I_INVALID_HID; + private static void WriteDataset() + { + long file_id = HDF5Constants.H5I_INVALID_HID; long filespace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long[] dims = { DIM_X, DIM_Y }; + long dataset_id = HDF5Constants.H5I_INVALID_HID; + long[] dims = {DIM_X, DIM_Y}; int[][] dset_data = new int[DIM_X][DIM_Y]; // Initialize data. @@ -45,7 +46,7 @@ public class H5Ex_D_ReadWrite { // Create a new file using default properties. try { file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT, - HDF5Constants.H5P_DEFAULT); + HDF5Constants.H5P_DEFAULT); } catch (Exception e) { e.printStackTrace(); @@ -64,7 +65,8 @@ public class H5Ex_D_ReadWrite { try { if ((file_id >= 0) && (filespace_id >= 0)) dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_I32LE, filespace_id, - HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, + HDF5Constants.H5P_DEFAULT); } catch (Exception e) { e.printStackTrace(); @@ -73,8 +75,8 @@ public class H5Ex_D_ReadWrite { // Write the data to the dataset. try { if (dataset_id >= 0) - H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, dset_data); + H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, + HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, dset_data); } catch (Exception e) { e.printStackTrace(); @@ -107,9 +109,10 @@ public class H5Ex_D_ReadWrite { } } - private static void ReadDataset() { - long file_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; + private static void ReadDataset() + { + long file_id = HDF5Constants.H5I_INVALID_HID; + long dataset_id = HDF5Constants.H5I_INVALID_HID; int[][] dset_data = new int[DIM_X][DIM_Y]; // Open file using the default properties. @@ -132,8 +135,8 @@ public class H5Ex_D_ReadWrite { // Read the data using the default properties. try { if (dataset_id >= 0) - H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, dset_data); + H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, + HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, dset_data); } catch (Exception e) { e.printStackTrace(); @@ -168,9 +171,9 @@ public class H5Ex_D_ReadWrite { } } - public static void main(String[] args) { + public static void main(String[] args) + { H5Ex_D_ReadWrite.WriteDataset(); H5Ex_D_ReadWrite.ReadDataset(); } - } diff --git a/java/examples/datasets/H5Ex_D_Shuffle.java b/java/examples/datasets/H5Ex_D_Shuffle.java index 1dd7c6a..54a77c7 100644 --- a/java/examples/datasets/H5Ex_D_Shuffle.java +++ b/java/examples/datasets/H5Ex_D_Shuffle.java @@ -30,45 +30,46 @@ import hdf.hdf5lib.H5; import hdf.hdf5lib.HDF5Constants; public class H5Ex_D_Shuffle { - private static String FILENAME = "H5Ex_D_Shuffle.h5"; + private static String FILENAME = "H5Ex_D_Shuffle.h5"; private static String DATASETNAME = "DS1"; - private static final int DIM_X = 32; - private static final int DIM_Y = 64; - private static final int CHUNK_X = 4; - private static final int CHUNK_Y = 8; - private static final int RANK = 2; - private static final int NDIMS = 2; + private static final int DIM_X = 32; + private static final int DIM_Y = 64; + private static final int CHUNK_X = 4; + private static final int CHUNK_Y = 8; + private static final int RANK = 2; + private static final int NDIMS = 2; // Values for the status of space allocation enum H5Z_filter { - H5Z_FILTER_ERROR(HDF5Constants.H5Z_FILTER_ERROR), H5Z_FILTER_NONE(HDF5Constants.H5Z_FILTER_NONE), H5Z_FILTER_DEFLATE( - HDF5Constants.H5Z_FILTER_DEFLATE), H5Z_FILTER_SHUFFLE(HDF5Constants.H5Z_FILTER_SHUFFLE), H5Z_FILTER_FLETCHER32( - HDF5Constants.H5Z_FILTER_FLETCHER32), H5Z_FILTER_SZIP(HDF5Constants.H5Z_FILTER_SZIP), H5Z_FILTER_NBIT( - HDF5Constants.H5Z_FILTER_NBIT), H5Z_FILTER_SCALEOFFSET(HDF5Constants.H5Z_FILTER_SCALEOFFSET), H5Z_FILTER_RESERVED( - HDF5Constants.H5Z_FILTER_RESERVED), H5Z_FILTER_MAX(HDF5Constants.H5Z_FILTER_MAX); + H5Z_FILTER_ERROR(HDF5Constants.H5Z_FILTER_ERROR), + H5Z_FILTER_NONE(HDF5Constants.H5Z_FILTER_NONE), + H5Z_FILTER_DEFLATE(HDF5Constants.H5Z_FILTER_DEFLATE), + H5Z_FILTER_SHUFFLE(HDF5Constants.H5Z_FILTER_SHUFFLE), + H5Z_FILTER_FLETCHER32(HDF5Constants.H5Z_FILTER_FLETCHER32), + H5Z_FILTER_SZIP(HDF5Constants.H5Z_FILTER_SZIP), + H5Z_FILTER_NBIT(HDF5Constants.H5Z_FILTER_NBIT), + H5Z_FILTER_SCALEOFFSET(HDF5Constants.H5Z_FILTER_SCALEOFFSET), + H5Z_FILTER_RESERVED(HDF5Constants.H5Z_FILTER_RESERVED), + H5Z_FILTER_MAX(HDF5Constants.H5Z_FILTER_MAX); private static final Map<Integer, H5Z_filter> lookup = new HashMap<Integer, H5Z_filter>(); - static { + static + { for (H5Z_filter s : EnumSet.allOf(H5Z_filter.class)) lookup.put(s.getCode(), s); } private int code; - H5Z_filter(int layout_type) { - this.code = layout_type; - } + H5Z_filter(int layout_type) { this.code = layout_type; } - public int getCode() { - return this.code; - } + public int getCode() { return this.code; } - public static H5Z_filter get(int code) { - return lookup.get(code); - } + public static H5Z_filter get(int code) { return lookup.get(code); } } - private static boolean checkGzipFilter() { + private static boolean checkGzipFilter() + { try { int available = H5.H5Zfilter_avail(HDF5Constants.H5Z_FILTER_DEFLATE); if (available == 0) { @@ -82,8 +83,8 @@ public class H5Ex_D_Shuffle { try { int filter_info = H5.H5Zget_filter_info(HDF5Constants.H5Z_FILTER_DEFLATE); - if (((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_ENCODE_ENABLED) == 0) - || ((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_DECODE_ENABLED) == 0)) { + if (((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_ENCODE_ENABLED) == 0) || + ((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_DECODE_ENABLED) == 0)) { System.out.println("gzip filter not available for encoding and decoding."); return false; } @@ -94,7 +95,8 @@ public class H5Ex_D_Shuffle { return true; } - private static boolean checkShuffleFilter() { + private static boolean checkShuffleFilter() + { try { int available = H5.H5Zfilter_avail(HDF5Constants.H5Z_FILTER_SHUFFLE); if (available == 0) { @@ -108,8 +110,8 @@ public class H5Ex_D_Shuffle { try { int filter_info = H5.H5Zget_filter_info(HDF5Constants.H5Z_FILTER_SHUFFLE); - if (((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_ENCODE_ENABLED) == 0) - || ((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_DECODE_ENABLED) == 0)) { + if (((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_ENCODE_ENABLED) == 0) || + ((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_DECODE_ENABLED) == 0)) { System.out.println("Shuffle filter not available for encoding and decoding."); return false; } @@ -120,13 +122,14 @@ public class H5Ex_D_Shuffle { return true; } - private static void writeShuffle() { - long file_id = HDF5Constants.H5I_INVALID_HID; + private static void writeShuffle() + { + long file_id = HDF5Constants.H5I_INVALID_HID; long filespace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long dcpl_id = HDF5Constants.H5I_INVALID_HID; - long[] dims = { DIM_X, DIM_Y }; - long[] chunk_dims = { CHUNK_X, CHUNK_Y }; + long dataset_id = HDF5Constants.H5I_INVALID_HID; + long dcpl_id = HDF5Constants.H5I_INVALID_HID; + long[] dims = {DIM_X, DIM_Y}; + long[] chunk_dims = {CHUNK_X, CHUNK_Y}; int[][] dset_data = new int[DIM_X][DIM_Y]; // Initialize data. @@ -137,7 +140,7 @@ public class H5Ex_D_Shuffle { // Create a new file using default properties. try { file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT, - HDF5Constants.H5P_DEFAULT); + HDF5Constants.H5P_DEFAULT); } catch (Exception e) { e.printStackTrace(); @@ -176,7 +179,7 @@ public class H5Ex_D_Shuffle { try { if ((file_id >= 0) && (filespace_id >= 0) && (dcpl_id >= 0)) dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_I32LE, filespace_id, - HDF5Constants.H5P_DEFAULT, dcpl_id, HDF5Constants.H5P_DEFAULT); + HDF5Constants.H5P_DEFAULT, dcpl_id, HDF5Constants.H5P_DEFAULT); } catch (Exception e) { e.printStackTrace(); @@ -185,8 +188,8 @@ public class H5Ex_D_Shuffle { // Write the data to the dataset. try { if (dataset_id >= 0) - H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, dset_data); + H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, + HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, dset_data); } catch (Exception e) { e.printStackTrace(); @@ -227,10 +230,11 @@ public class H5Ex_D_Shuffle { } } - private static void readShuffle() { - long file_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long dcpl_id = HDF5Constants.H5I_INVALID_HID; + private static void readShuffle() + { + long file_id = HDF5Constants.H5I_INVALID_HID; + long dataset_id = HDF5Constants.H5I_INVALID_HID; + long dcpl_id = HDF5Constants.H5I_INVALID_HID; int[][] dset_data = new int[DIM_X][DIM_Y]; // Open an existing file. @@ -266,14 +270,14 @@ public class H5Ex_D_Shuffle { int nfilters = H5.H5Pget_nfilters(dcpl_id); for (int indx = 0; indx < nfilters; indx++) { // Java lib requires a valid filter_name object and cd_values - int[] flags = { 0 }; - long[] cd_nelmts = { 1 }; - int[] cd_values = { 0 }; - String[] filter_name = { "" }; - int[] filter_config = { 0 }; - int filter_type = -1; - filter_type = H5.H5Pget_filter(dcpl_id, indx, flags, cd_nelmts, cd_values, 120, filter_name, - filter_config); + int[] flags = {0}; + long[] cd_nelmts = {1}; + int[] cd_values = {0}; + String[] filter_name = {""}; + int[] filter_config = {0}; + int filter_type = -1; + filter_type = H5.H5Pget_filter(dcpl_id, indx, flags, cd_nelmts, cd_values, 120, + filter_name, filter_config); System.out.print("Filter " + indx + ": Type is: "); switch (H5Z_filter.get(filter_type)) { case H5Z_FILTER_DEFLATE: @@ -308,8 +312,8 @@ public class H5Ex_D_Shuffle { // Read the data using the default properties. try { if (dataset_id >= 0) { - H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, dset_data); + H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, + HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, dset_data); } } catch (Exception e) { @@ -354,7 +358,8 @@ public class H5Ex_D_Shuffle { } } - public static void main(String[] args) { + public static void main(String[] args) + { // Check if gzip compression is available and can be used for both // compression and decompression. Normally we do not perform error // checking in these examples for the sake of clarity, but in this @@ -366,5 +371,4 @@ public class H5Ex_D_Shuffle { H5Ex_D_Shuffle.readShuffle(); } } - } diff --git a/java/examples/datasets/H5Ex_D_Sofloat.java b/java/examples/datasets/H5Ex_D_Sofloat.java index 8edde09..a5f5cd8 100644 --- a/java/examples/datasets/H5Ex_D_Sofloat.java +++ b/java/examples/datasets/H5Ex_D_Sofloat.java @@ -23,9 +23,9 @@ package examples.datasets; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; -import java.util.Locale; import java.util.EnumSet; import java.util.HashMap; +import java.util.Locale; import java.util.Map; import hdf.hdf5lib.H5; @@ -33,45 +33,46 @@ import hdf.hdf5lib.HDF5Constants; public class H5Ex_D_Sofloat { - private static String FILENAME = "H5Ex_D_Sofloat.h5"; + private static String FILENAME = "H5Ex_D_Sofloat.h5"; private static String DATASETNAME = "DS1"; - private static final int DIM_X = 32; - private static final int DIM_Y = 64; - private static final int CHUNK_X = 4; - private static final int CHUNK_Y = 8; - private static final int RANK = 2; - private static final int NDIMS = 2; + private static final int DIM_X = 32; + private static final int DIM_Y = 64; + private static final int CHUNK_X = 4; + private static final int CHUNK_Y = 8; + private static final int RANK = 2; + private static final int NDIMS = 2; // Values for the status of space allocation enum H5Z_filter { - H5Z_FILTER_ERROR(HDF5Constants.H5Z_FILTER_ERROR), H5Z_FILTER_NONE(HDF5Constants.H5Z_FILTER_NONE), H5Z_FILTER_DEFLATE( - HDF5Constants.H5Z_FILTER_DEFLATE), H5Z_FILTER_SHUFFLE(HDF5Constants.H5Z_FILTER_SHUFFLE), H5Z_FILTER_FLETCHER32( - HDF5Constants.H5Z_FILTER_FLETCHER32), H5Z_FILTER_SZIP(HDF5Constants.H5Z_FILTER_SZIP), H5Z_FILTER_NBIT( - HDF5Constants.H5Z_FILTER_NBIT), H5Z_FILTER_SCALEOFFSET(HDF5Constants.H5Z_FILTER_SCALEOFFSET), H5Z_FILTER_RESERVED( - HDF5Constants.H5Z_FILTER_RESERVED), H5Z_FILTER_MAX(HDF5Constants.H5Z_FILTER_MAX); + H5Z_FILTER_ERROR(HDF5Constants.H5Z_FILTER_ERROR), + H5Z_FILTER_NONE(HDF5Constants.H5Z_FILTER_NONE), + H5Z_FILTER_DEFLATE(HDF5Constants.H5Z_FILTER_DEFLATE), + H5Z_FILTER_SHUFFLE(HDF5Constants.H5Z_FILTER_SHUFFLE), + H5Z_FILTER_FLETCHER32(HDF5Constants.H5Z_FILTER_FLETCHER32), + H5Z_FILTER_SZIP(HDF5Constants.H5Z_FILTER_SZIP), + H5Z_FILTER_NBIT(HDF5Constants.H5Z_FILTER_NBIT), + H5Z_FILTER_SCALEOFFSET(HDF5Constants.H5Z_FILTER_SCALEOFFSET), + H5Z_FILTER_RESERVED(HDF5Constants.H5Z_FILTER_RESERVED), + H5Z_FILTER_MAX(HDF5Constants.H5Z_FILTER_MAX); private static final Map<Integer, H5Z_filter> lookup = new HashMap<Integer, H5Z_filter>(); - static { + static + { for (H5Z_filter s : EnumSet.allOf(H5Z_filter.class)) lookup.put(s.getCode(), s); } private int code; - H5Z_filter(int layout_type) { - this.code = layout_type; - } + H5Z_filter(int layout_type) { this.code = layout_type; } - public int getCode() { - return this.code; - } + public int getCode() { return this.code; } - public static H5Z_filter get(int code) { - return lookup.get(code); - } + public static H5Z_filter get(int code) { return lookup.get(code); } } - private static boolean checkScaleoffsetFilter() { + private static boolean checkScaleoffsetFilter() + { try { int available = H5.H5Zfilter_avail(HDF5Constants.H5Z_FILTER_SCALEOFFSET); if (available == 0) { @@ -85,8 +86,8 @@ public class H5Ex_D_Sofloat { try { int filter_info = H5.H5Zget_filter_info(HDF5Constants.H5Z_FILTER_SCALEOFFSET); - if (((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_ENCODE_ENABLED) == 0) - || ((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_DECODE_ENABLED) == 0)) { + if (((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_ENCODE_ENABLED) == 0) || + ((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_DECODE_ENABLED) == 0)) { System.out.println("Scale-Offset filter not available for encoding and decoding."); return false; } @@ -97,20 +98,21 @@ public class H5Ex_D_Sofloat { return true; } - private static void writeData() { - long file_id = HDF5Constants.H5I_INVALID_HID; - long filespace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long dcpl_id = HDF5Constants.H5I_INVALID_HID; - long[] dims = { DIM_X, DIM_Y }; - long[] chunk_dims = { CHUNK_X, CHUNK_Y }; + private static void writeData() + { + long file_id = HDF5Constants.H5I_INVALID_HID; + long filespace_id = HDF5Constants.H5I_INVALID_HID; + long dataset_id = HDF5Constants.H5I_INVALID_HID; + long dcpl_id = HDF5Constants.H5I_INVALID_HID; + long[] dims = {DIM_X, DIM_Y}; + long[] chunk_dims = {CHUNK_X, CHUNK_Y}; double[][] dset_data = new double[DIM_X][DIM_Y]; // Initialize data. for (int indx = 0; indx < DIM_X; indx++) for (int jndx = 0; jndx < DIM_Y; jndx++) { - double x = indx; - double y = jndx; + double x = indx; + double y = jndx; dset_data[indx][jndx] = (x + 1) / (y + 0.3) + y; } @@ -133,7 +135,7 @@ public class H5Ex_D_Sofloat { // Create a new file using the default properties. try { file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT, - HDF5Constants.H5P_DEFAULT); + HDF5Constants.H5P_DEFAULT); } catch (Exception e) { e.printStackTrace(); @@ -164,7 +166,7 @@ public class H5Ex_D_Sofloat { try { if ((file_id >= 0) && (filespace_id >= 0) && (dcpl_id >= 0)) dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_IEEE_F64LE, filespace_id, - HDF5Constants.H5P_DEFAULT, dcpl_id, HDF5Constants.H5P_DEFAULT); + HDF5Constants.H5P_DEFAULT, dcpl_id, HDF5Constants.H5P_DEFAULT); } catch (Exception e) { e.printStackTrace(); @@ -173,8 +175,8 @@ public class H5Ex_D_Sofloat { // Write the data to the dataset. try { if (dataset_id >= 0) - H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_DOUBLE, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, dset_data); + H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_DOUBLE, HDF5Constants.H5S_ALL, + HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, dset_data); } catch (Exception e) { e.printStackTrace(); @@ -215,10 +217,11 @@ public class H5Ex_D_Sofloat { } } - private static void readData() { - long file_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long dcpl_id = HDF5Constants.H5I_INVALID_HID; + private static void readData() + { + long file_id = HDF5Constants.H5I_INVALID_HID; + long dataset_id = HDF5Constants.H5I_INVALID_HID; + long dcpl_id = HDF5Constants.H5I_INVALID_HID; double[][] dset_data = new double[DIM_X][DIM_Y]; // Open file using the default properties. @@ -251,15 +254,15 @@ public class H5Ex_D_Sofloat { try { if (dcpl_id >= 0) { // Java lib requires a valid filter_name object and cd_values - int[] flags = { 0 }; - long[] cd_nelmts = { 1 }; - int[] cd_values = { 0 }; - String[] filter_name = { "" }; - int[] filter_config = { 0 }; - int filter_type = -1; - - filter_type = H5 - .H5Pget_filter(dcpl_id, 0, flags, cd_nelmts, cd_values, 120, filter_name, filter_config); + int[] flags = {0}; + long[] cd_nelmts = {1}; + int[] cd_values = {0}; + String[] filter_name = {""}; + int[] filter_config = {0}; + int filter_type = -1; + + filter_type = H5.H5Pget_filter(dcpl_id, 0, flags, cd_nelmts, cd_values, 120, filter_name, + filter_config); System.out.print("Filter type is: "); switch (H5Z_filter.get(filter_type)) { case H5Z_FILTER_DEFLATE: @@ -293,8 +296,8 @@ public class H5Ex_D_Sofloat { // Read the data using the default properties. try { if (dataset_id >= 0) - H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_DOUBLE, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, dset_data); + H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_DOUBLE, HDF5Constants.H5S_ALL, + HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, dset_data); } catch (Exception e) { e.printStackTrace(); @@ -343,7 +346,8 @@ public class H5Ex_D_Sofloat { } } - public static void main(String[] args) { + public static void main(String[] args) + { // Check if Scale-Offset compression is available and can be used // for both compression and decompression. Normally we do not diff --git a/java/examples/datasets/H5Ex_D_Soint.java b/java/examples/datasets/H5Ex_D_Soint.java index dd7664f..3eb8e37 100644 --- a/java/examples/datasets/H5Ex_D_Soint.java +++ b/java/examples/datasets/H5Ex_D_Soint.java @@ -30,45 +30,46 @@ import hdf.hdf5lib.HDF5Constants; public class H5Ex_D_Soint { - private static String FILENAME = "H5Ex_D_Soint.h5"; + private static String FILENAME = "H5Ex_D_Soint.h5"; private static String DATASETNAME = "DS1"; - private static final int DIM_X = 32; - private static final int DIM_Y = 64; - private static final int CHUNK_X = 4; - private static final int CHUNK_Y = 8; - private static final int RANK = 2; - private static final int NDIMS = 2; + private static final int DIM_X = 32; + private static final int DIM_Y = 64; + private static final int CHUNK_X = 4; + private static final int CHUNK_Y = 8; + private static final int RANK = 2; + private static final int NDIMS = 2; // Values for the status of space allocation enum H5Z_filter { - H5Z_FILTER_ERROR(HDF5Constants.H5Z_FILTER_ERROR), H5Z_FILTER_NONE(HDF5Constants.H5Z_FILTER_NONE), H5Z_FILTER_DEFLATE( - HDF5Constants.H5Z_FILTER_DEFLATE), H5Z_FILTER_SHUFFLE(HDF5Constants.H5Z_FILTER_SHUFFLE), H5Z_FILTER_FLETCHER32( - HDF5Constants.H5Z_FILTER_FLETCHER32), H5Z_FILTER_SZIP(HDF5Constants.H5Z_FILTER_SZIP), H5Z_FILTER_NBIT( - HDF5Constants.H5Z_FILTER_NBIT), H5Z_FILTER_SCALEOFFSET(HDF5Constants.H5Z_FILTER_SCALEOFFSET), H5Z_FILTER_RESERVED( - HDF5Constants.H5Z_FILTER_RESERVED), H5Z_FILTER_MAX(HDF5Constants.H5Z_FILTER_MAX); + H5Z_FILTER_ERROR(HDF5Constants.H5Z_FILTER_ERROR), + H5Z_FILTER_NONE(HDF5Constants.H5Z_FILTER_NONE), + H5Z_FILTER_DEFLATE(HDF5Constants.H5Z_FILTER_DEFLATE), + H5Z_FILTER_SHUFFLE(HDF5Constants.H5Z_FILTER_SHUFFLE), + H5Z_FILTER_FLETCHER32(HDF5Constants.H5Z_FILTER_FLETCHER32), + H5Z_FILTER_SZIP(HDF5Constants.H5Z_FILTER_SZIP), + H5Z_FILTER_NBIT(HDF5Constants.H5Z_FILTER_NBIT), + H5Z_FILTER_SCALEOFFSET(HDF5Constants.H5Z_FILTER_SCALEOFFSET), + H5Z_FILTER_RESERVED(HDF5Constants.H5Z_FILTER_RESERVED), + H5Z_FILTER_MAX(HDF5Constants.H5Z_FILTER_MAX); private static final Map<Integer, H5Z_filter> lookup = new HashMap<Integer, H5Z_filter>(); - static { + static + { for (H5Z_filter s : EnumSet.allOf(H5Z_filter.class)) lookup.put(s.getCode(), s); } private int code; - H5Z_filter(int layout_type) { - this.code = layout_type; - } + H5Z_filter(int layout_type) { this.code = layout_type; } - public int getCode() { - return this.code; - } + public int getCode() { return this.code; } - public static H5Z_filter get(int code) { - return lookup.get(code); - } + public static H5Z_filter get(int code) { return lookup.get(code); } } - private static boolean checkScaleoffsetFilter() { + private static boolean checkScaleoffsetFilter() + { try { int available = H5.H5Zfilter_avail(HDF5Constants.H5Z_FILTER_SCALEOFFSET); if (available == 0) { @@ -82,8 +83,8 @@ public class H5Ex_D_Soint { try { int filter_info = H5.H5Zget_filter_info(HDF5Constants.H5Z_FILTER_SCALEOFFSET); - if (((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_ENCODE_ENABLED) == 0) - || ((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_DECODE_ENABLED) == 0)) { + if (((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_ENCODE_ENABLED) == 0) || + ((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_DECODE_ENABLED) == 0)) { System.out.println("Scale-Offset filter not available for encoding and decoding."); return false; } @@ -94,13 +95,14 @@ public class H5Ex_D_Soint { return true; } - private static void writeData() { - long file_id = HDF5Constants.H5I_INVALID_HID; + private static void writeData() + { + long file_id = HDF5Constants.H5I_INVALID_HID; long filespace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long dcpl_id = HDF5Constants.H5I_INVALID_HID; - long[] dims = { DIM_X, DIM_Y }; - long[] chunk_dims = { CHUNK_X, CHUNK_Y }; + long dataset_id = HDF5Constants.H5I_INVALID_HID; + long dcpl_id = HDF5Constants.H5I_INVALID_HID; + long[] dims = {DIM_X, DIM_Y}; + long[] chunk_dims = {CHUNK_X, CHUNK_Y}; int[][] dset_data = new int[DIM_X][DIM_Y]; // Initialize data. @@ -111,7 +113,7 @@ public class H5Ex_D_Soint { // Create a new file using the default properties. try { file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT, - HDF5Constants.H5P_DEFAULT); + HDF5Constants.H5P_DEFAULT); } catch (Exception e) { e.printStackTrace(); @@ -130,7 +132,8 @@ public class H5Ex_D_Soint { try { dcpl_id = H5.H5Pcreate(HDF5Constants.H5P_DATASET_CREATE); if (dcpl_id >= 0) { - H5.H5Pset_scaleoffset(dcpl_id, HDF5Constants.H5Z_SO_INT, HDF5Constants.H5Z_SO_INT_MINBITS_DEFAULT); + H5.H5Pset_scaleoffset(dcpl_id, HDF5Constants.H5Z_SO_INT, + HDF5Constants.H5Z_SO_INT_MINBITS_DEFAULT); H5.H5Pset_chunk(dcpl_id, NDIMS, chunk_dims); } } @@ -142,7 +145,7 @@ public class H5Ex_D_Soint { try { if ((file_id >= 0) && (filespace_id >= 0) && (dcpl_id >= 0)) dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_I32LE, filespace_id, - HDF5Constants.H5P_DEFAULT, dcpl_id, HDF5Constants.H5P_DEFAULT); + HDF5Constants.H5P_DEFAULT, dcpl_id, HDF5Constants.H5P_DEFAULT); } catch (Exception e) { e.printStackTrace(); @@ -151,8 +154,8 @@ public class H5Ex_D_Soint { // Write the data to the dataset. try { if (dataset_id >= 0) - H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, dset_data); + H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, + HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, dset_data); } catch (Exception e) { e.printStackTrace(); @@ -193,10 +196,11 @@ public class H5Ex_D_Soint { } } - private static void readData() { - long file_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long dcpl_id = HDF5Constants.H5I_INVALID_HID; + private static void readData() + { + long file_id = HDF5Constants.H5I_INVALID_HID; + long dataset_id = HDF5Constants.H5I_INVALID_HID; + long dcpl_id = HDF5Constants.H5I_INVALID_HID; int[][] dset_data = new int[DIM_X][DIM_Y]; // Open file using the default properties. @@ -229,15 +233,15 @@ public class H5Ex_D_Soint { try { if (dcpl_id >= 0) { // Java lib requires a valid filter_name object and cd_values - int[] flags = { 0 }; - long[] cd_nelmts = { 1 }; - int[] cd_values = { 0 }; - String[] filter_name = { "" }; - int[] filter_config = { 0 }; - int filter_type = -1; - - filter_type = H5 - .H5Pget_filter(dcpl_id, 0, flags, cd_nelmts, cd_values, 120, filter_name, filter_config); + int[] flags = {0}; + long[] cd_nelmts = {1}; + int[] cd_values = {0}; + String[] filter_name = {""}; + int[] filter_config = {0}; + int filter_type = -1; + + filter_type = H5.H5Pget_filter(dcpl_id, 0, flags, cd_nelmts, cd_values, 120, filter_name, + filter_config); System.out.print("Filter type is: "); switch (H5Z_filter.get(filter_type)) { case H5Z_FILTER_DEFLATE: @@ -271,8 +275,8 @@ public class H5Ex_D_Soint { // Read the data using the default properties. try { if (dataset_id >= 0) - H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, dset_data); + H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, + HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, dset_data); } catch (Exception e) { e.printStackTrace(); @@ -316,7 +320,8 @@ public class H5Ex_D_Soint { } } - public static void main(String[] args) { + public static void main(String[] args) + { // Check if Scale-Offset compression is available and can be used // for both compression and decompression. Normally we do not @@ -328,5 +333,4 @@ public class H5Ex_D_Soint { H5Ex_D_Soint.readData(); } } - } diff --git a/java/examples/datasets/H5Ex_D_Szip.java b/java/examples/datasets/H5Ex_D_Szip.java index 3fdc712..0426a87 100644 --- a/java/examples/datasets/H5Ex_D_Szip.java +++ b/java/examples/datasets/H5Ex_D_Szip.java @@ -29,45 +29,46 @@ import hdf.hdf5lib.H5; import hdf.hdf5lib.HDF5Constants; public class H5Ex_D_Szip { - private static String FILENAME = "H5Ex_D_Szip.h5"; + private static String FILENAME = "H5Ex_D_Szip.h5"; private static String DATASETNAME = "DS1"; - private static final int DIM_X = 32; - private static final int DIM_Y = 64; - private static final int CHUNK_X = 4; - private static final int CHUNK_Y = 8; - private static final int RANK = 2; - private static final int NDIMS = 2; + private static final int DIM_X = 32; + private static final int DIM_Y = 64; + private static final int CHUNK_X = 4; + private static final int CHUNK_Y = 8; + private static final int RANK = 2; + private static final int NDIMS = 2; // Values for the status of space allocation enum H5Z_filter { - H5Z_FILTER_ERROR(HDF5Constants.H5Z_FILTER_ERROR), H5Z_FILTER_NONE(HDF5Constants.H5Z_FILTER_NONE), H5Z_FILTER_DEFLATE( - HDF5Constants.H5Z_FILTER_DEFLATE), H5Z_FILTER_SHUFFLE(HDF5Constants.H5Z_FILTER_SHUFFLE), H5Z_FILTER_FLETCHER32( - HDF5Constants.H5Z_FILTER_FLETCHER32), H5Z_FILTER_SZIP(HDF5Constants.H5Z_FILTER_SZIP), H5Z_FILTER_NBIT( - HDF5Constants.H5Z_FILTER_NBIT), H5Z_FILTER_SCALEOFFSET(HDF5Constants.H5Z_FILTER_SCALEOFFSET), H5Z_FILTER_RESERVED( - HDF5Constants.H5Z_FILTER_RESERVED), H5Z_FILTER_MAX(HDF5Constants.H5Z_FILTER_MAX); + H5Z_FILTER_ERROR(HDF5Constants.H5Z_FILTER_ERROR), + H5Z_FILTER_NONE(HDF5Constants.H5Z_FILTER_NONE), + H5Z_FILTER_DEFLATE(HDF5Constants.H5Z_FILTER_DEFLATE), + H5Z_FILTER_SHUFFLE(HDF5Constants.H5Z_FILTER_SHUFFLE), + H5Z_FILTER_FLETCHER32(HDF5Constants.H5Z_FILTER_FLETCHER32), + H5Z_FILTER_SZIP(HDF5Constants.H5Z_FILTER_SZIP), + H5Z_FILTER_NBIT(HDF5Constants.H5Z_FILTER_NBIT), + H5Z_FILTER_SCALEOFFSET(HDF5Constants.H5Z_FILTER_SCALEOFFSET), + H5Z_FILTER_RESERVED(HDF5Constants.H5Z_FILTER_RESERVED), + H5Z_FILTER_MAX(HDF5Constants.H5Z_FILTER_MAX); private static final Map<Integer, H5Z_filter> lookup = new HashMap<Integer, H5Z_filter>(); - static { + static + { for (H5Z_filter s : EnumSet.allOf(H5Z_filter.class)) lookup.put(s.getCode(), s); } private int code; - H5Z_filter(int layout_type) { - this.code = layout_type; - } + H5Z_filter(int layout_type) { this.code = layout_type; } - public int getCode() { - return this.code; - } + public int getCode() { return this.code; } - public static H5Z_filter get(int code) { - return lookup.get(code); - } + public static H5Z_filter get(int code) { return lookup.get(code); } } - private static boolean checkSzipFilter() { + private static boolean checkSzipFilter() + { try { int available = H5.H5Zfilter_avail(HDF5Constants.H5Z_FILTER_SZIP); if (available == 0) { @@ -81,8 +82,8 @@ public class H5Ex_D_Szip { try { int filter_info = H5.H5Zget_filter_info(HDF5Constants.H5Z_FILTER_SZIP); - if (((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_ENCODE_ENABLED) == 0) - || ((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_DECODE_ENABLED) == 0)) { + if (((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_ENCODE_ENABLED) == 0) || + ((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_DECODE_ENABLED) == 0)) { System.out.println("szip filter not available for encoding and decoding."); return false; } @@ -93,13 +94,14 @@ public class H5Ex_D_Szip { return true; } - private static void writeSzip() { - long file_id = HDF5Constants.H5I_INVALID_HID; + private static void writeSzip() + { + long file_id = HDF5Constants.H5I_INVALID_HID; long filespace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long dcpl_id = HDF5Constants.H5I_INVALID_HID; - long[] dims = { DIM_X, DIM_Y }; - long[] chunk_dims = { CHUNK_X, CHUNK_Y }; + long dataset_id = HDF5Constants.H5I_INVALID_HID; + long dcpl_id = HDF5Constants.H5I_INVALID_HID; + long[] dims = {DIM_X, DIM_Y}; + long[] chunk_dims = {CHUNK_X, CHUNK_Y}; int[][] dset_data = new int[DIM_X][DIM_Y]; // Initialize data. @@ -110,7 +112,7 @@ public class H5Ex_D_Szip { // Create a new file using default properties. try { file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT, - HDF5Constants.H5P_DEFAULT); + HDF5Constants.H5P_DEFAULT); } catch (Exception e) { e.printStackTrace(); @@ -143,7 +145,7 @@ public class H5Ex_D_Szip { try { if ((file_id >= 0) && (filespace_id >= 0) && (dcpl_id >= 0)) dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_I32LE, filespace_id, - HDF5Constants.H5P_DEFAULT, dcpl_id, HDF5Constants.H5P_DEFAULT); + HDF5Constants.H5P_DEFAULT, dcpl_id, HDF5Constants.H5P_DEFAULT); } catch (Exception e) { e.printStackTrace(); @@ -152,8 +154,8 @@ public class H5Ex_D_Szip { // Write the data to the dataset. try { if (dataset_id >= 0) - H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, dset_data); + H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, + HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, dset_data); } catch (Exception e) { e.printStackTrace(); @@ -194,10 +196,11 @@ public class H5Ex_D_Szip { } } - private static void readSzip() { - long file_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long dcpl_id = HDF5Constants.H5I_INVALID_HID; + private static void readSzip() + { + long file_id = HDF5Constants.H5I_INVALID_HID; + long dataset_id = HDF5Constants.H5I_INVALID_HID; + long dcpl_id = HDF5Constants.H5I_INVALID_HID; int[][] dset_data = new int[DIM_X][DIM_Y]; // Open an existing file. @@ -231,15 +234,15 @@ public class H5Ex_D_Szip { try { if (dcpl_id >= 0) { // Java lib requires a valid filter_name object and cd_values - int[] flags = { 0 }; - long[] cd_nelmts = { 1 }; - int[] cd_values = { 0 }; - String[] filter_name = { "" }; - int[] filter_config = { 0 }; - int filter_type = -1; - - filter_type = H5 - .H5Pget_filter(dcpl_id, 0, flags, cd_nelmts, cd_values, 120, filter_name, filter_config); + int[] flags = {0}; + long[] cd_nelmts = {1}; + int[] cd_values = {0}; + String[] filter_name = {""}; + int[] filter_config = {0}; + int filter_type = -1; + + filter_type = H5.H5Pget_filter(dcpl_id, 0, flags, cd_nelmts, cd_values, 120, filter_name, + filter_config); System.out.print("Filter type is: "); switch (H5Z_filter.get(filter_type)) { case H5Z_FILTER_DEFLATE: @@ -273,8 +276,8 @@ public class H5Ex_D_Szip { // Read the data using the default properties. try { if (dataset_id >= 0) { - H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, dset_data); + H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, + HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, dset_data); } } catch (Exception e) { @@ -319,7 +322,8 @@ public class H5Ex_D_Szip { } } - public static void main(String[] args) { + public static void main(String[] args) + { // Check if gzip compression is available and can be used for both // compression and decompression. Normally we do not perform error // checking in these examples for the sake of clarity, but in this @@ -330,5 +334,4 @@ public class H5Ex_D_Szip { H5Ex_D_Szip.readSzip(); } } - } diff --git a/java/examples/datasets/H5Ex_D_Transform.java b/java/examples/datasets/H5Ex_D_Transform.java index 069e80b..16ab423 100644 --- a/java/examples/datasets/H5Ex_D_Transform.java +++ b/java/examples/datasets/H5Ex_D_Transform.java @@ -27,20 +27,21 @@ import hdf.hdf5lib.HDF5Constants; public class H5Ex_D_Transform { - private static String FILE = "H5Ex_D_Transform.h5"; - private static String DATASET = "DS1"; - private static final int DIM_X = 4; - private static final int DIM_Y = 7; - private static String TRANSFORM = "x+1"; + private static String FILE = "H5Ex_D_Transform.h5"; + private static String DATASET = "DS1"; + private static final int DIM_X = 4; + private static final int DIM_Y = 7; + private static String TRANSFORM = "x+1"; private static String RTRANSFORM = "x-1"; - private static void writeData() { - long file_id = HDF5Constants.H5I_INVALID_HID; + private static void writeData() + { + long file_id = HDF5Constants.H5I_INVALID_HID; long filespace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long dxpl_id = HDF5Constants.H5I_INVALID_HID; + long dataset_id = HDF5Constants.H5I_INVALID_HID; + long dxpl_id = HDF5Constants.H5I_INVALID_HID; - long[] dims = { DIM_X, DIM_Y }; + long[] dims = {DIM_X, DIM_Y}; int[][] dset_data = new int[DIM_X][DIM_Y]; // Initialize data. @@ -60,7 +61,7 @@ public class H5Ex_D_Transform { // Create a new file using the default properties. try { file_id = H5.H5Fcreate(FILE, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT, - HDF5Constants.H5P_DEFAULT); + HDF5Constants.H5P_DEFAULT); } catch (Exception e) { e.printStackTrace(); @@ -90,7 +91,8 @@ public class H5Ex_D_Transform { try { if ((file_id >= 0) && (filespace_id >= 0)) dataset_id = H5.H5Dcreate(file_id, DATASET, HDF5Constants.H5T_NATIVE_INT, filespace_id, - HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, + HDF5Constants.H5P_DEFAULT); } catch (Exception e) { e.printStackTrace(); @@ -99,8 +101,8 @@ public class H5Ex_D_Transform { // Write the data to the dataset using the dataset transfer property list. try { if ((dataset_id >= 0) && (dxpl_id >= 0)) - H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - dxpl_id, dset_data); + H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, + HDF5Constants.H5S_ALL, dxpl_id, dset_data); } catch (Exception e) { e.printStackTrace(); @@ -141,11 +143,12 @@ public class H5Ex_D_Transform { } } - private static void readData() { + private static void readData() + { - long file_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long dxpl_id = HDF5Constants.H5I_INVALID_HID; + long file_id = HDF5Constants.H5I_INVALID_HID; + long dataset_id = HDF5Constants.H5I_INVALID_HID; + long dxpl_id = HDF5Constants.H5I_INVALID_HID; int[][] dset_data = new int[DIM_X][DIM_Y]; // Open an existing file using the default properties. @@ -168,8 +171,8 @@ public class H5Ex_D_Transform { // Read the data using the default properties. try { if (dataset_id >= 0) - H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, dset_data); + H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, + HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, dset_data); } catch (Exception e) { e.printStackTrace(); @@ -197,8 +200,8 @@ public class H5Ex_D_Transform { // Read the data using the dataset transfer property list. try { if ((dataset_id >= 0) && (dxpl_id >= 0)) - H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - dxpl_id, dset_data); + H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, + HDF5Constants.H5S_ALL, dxpl_id, dset_data); } catch (Exception e) { e.printStackTrace(); @@ -206,8 +209,8 @@ public class H5Ex_D_Transform { // Output the data to the screen. - System.out.println("Data as written with transform '" + TRANSFORM + "' and read with transform '" - + RTRANSFORM + "'"); + System.out.println("Data as written with transform '" + TRANSFORM + "' and read with transform '" + + RTRANSFORM + "'"); for (int i = 0; i < DIM_X; i++) { System.out.print(" ["); for (int j = 0; j < DIM_Y; j++) @@ -239,9 +242,9 @@ public class H5Ex_D_Transform { } } - public static void main(String[] args) { + public static void main(String[] args) + { H5Ex_D_Transform.writeData(); H5Ex_D_Transform.readData(); } - } diff --git a/java/examples/datasets/H5Ex_D_UnlimitedAdd.java b/java/examples/datasets/H5Ex_D_UnlimitedAdd.java index c82b2d6..4154cf3 100644 --- a/java/examples/datasets/H5Ex_D_UnlimitedAdd.java +++ b/java/examples/datasets/H5Ex_D_UnlimitedAdd.java @@ -26,25 +26,26 @@ import hdf.hdf5lib.H5; import hdf.hdf5lib.HDF5Constants; public class H5Ex_D_UnlimitedAdd { - private static String FILENAME = "H5Ex_D_UnlimitedAdd.h5"; + private static String FILENAME = "H5Ex_D_UnlimitedAdd.h5"; private static String DATASETNAME = "DS1"; - private static final int DIM_X = 4; - private static final int DIM_Y = 7; - private static final int EDIM_X = 6; - private static final int EDIM_Y = 10; - private static final int CHUNK_X = 4; - private static final int CHUNK_Y = 4; - private static final int RANK = 2; - private static final int NDIMS = 2; - - private static void writeUnlimited() { - long file_id = HDF5Constants.H5I_INVALID_HID; - long dcpl_id = HDF5Constants.H5I_INVALID_HID; + private static final int DIM_X = 4; + private static final int DIM_Y = 7; + private static final int EDIM_X = 6; + private static final int EDIM_Y = 10; + private static final int CHUNK_X = 4; + private static final int CHUNK_Y = 4; + private static final int RANK = 2; + private static final int NDIMS = 2; + + private static void writeUnlimited() + { + long file_id = HDF5Constants.H5I_INVALID_HID; + long dcpl_id = HDF5Constants.H5I_INVALID_HID; long dataspace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long[] dims = { DIM_X, DIM_Y }; - long[] chunk_dims = { CHUNK_X, CHUNK_Y }; - long[] maxdims = { HDF5Constants.H5S_UNLIMITED, HDF5Constants.H5S_UNLIMITED }; + long dataset_id = HDF5Constants.H5I_INVALID_HID; + long[] dims = {DIM_X, DIM_Y}; + long[] chunk_dims = {CHUNK_X, CHUNK_Y}; + long[] maxdims = {HDF5Constants.H5S_UNLIMITED, HDF5Constants.H5S_UNLIMITED}; int[][] dset_data = new int[DIM_X][DIM_Y]; // Initialize the dataset. @@ -55,7 +56,7 @@ public class H5Ex_D_UnlimitedAdd { // Create a new file using default properties. try { file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT, - HDF5Constants.H5P_DEFAULT); + HDF5Constants.H5P_DEFAULT); } catch (Exception e) { e.printStackTrace(); @@ -90,7 +91,7 @@ public class H5Ex_D_UnlimitedAdd { try { if ((file_id >= 0) && (dataspace_id >= 0) && (dcpl_id >= 0)) dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_I32LE, dataspace_id, - HDF5Constants.H5P_DEFAULT, dcpl_id, HDF5Constants.H5P_DEFAULT); + HDF5Constants.H5P_DEFAULT, dcpl_id, HDF5Constants.H5P_DEFAULT); } catch (Exception e) { e.printStackTrace(); @@ -99,8 +100,8 @@ public class H5Ex_D_UnlimitedAdd { // Write the data to the dataset. try { if (dataset_id >= 0) - H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, dset_data); + H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, + HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, dset_data); } catch (Exception e) { e.printStackTrace(); @@ -141,14 +142,15 @@ public class H5Ex_D_UnlimitedAdd { } } - private static void extendUnlimited() { - long file_id = HDF5Constants.H5I_INVALID_HID; + private static void extendUnlimited() + { + long file_id = HDF5Constants.H5I_INVALID_HID; long dataspace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long[] dims = { DIM_X, DIM_Y }; - long[] extdims = { EDIM_X, EDIM_Y }; - long[] start = { 0, 0 }; - long[] count = new long[2]; + long dataset_id = HDF5Constants.H5I_INVALID_HID; + long[] dims = {DIM_X, DIM_Y}; + long[] extdims = {EDIM_X, EDIM_Y}; + long[] start = {0, 0}; + long[] count = new long[2]; int[][] dset_data; int[][] extend_dset_data = new int[EDIM_X][EDIM_Y]; @@ -189,13 +191,13 @@ public class H5Ex_D_UnlimitedAdd { } // Allocate array of pointers to rows. - dset_data = new int[(int) dims[0]][(int) dims[1]]; + dset_data = new int[(int)dims[0]][(int)dims[1]]; // Read the data using the default properties. try { if (dataset_id >= 0) - H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, dset_data); + H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, + HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, dset_data); } catch (Exception e) { e.printStackTrace(); @@ -257,7 +259,7 @@ public class H5Ex_D_UnlimitedAdd { // Write the data to the selected portion of the dataset. if (dataset_id >= 0) H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, dataspace_id, - HDF5Constants.H5P_DEFAULT, extend_dset_data); + HDF5Constants.H5P_DEFAULT, extend_dset_data); } } catch (Exception e) { @@ -291,11 +293,12 @@ public class H5Ex_D_UnlimitedAdd { } } - private static void readUnlimited() { - long file_id = HDF5Constants.H5I_INVALID_HID; + private static void readUnlimited() + { + long file_id = HDF5Constants.H5I_INVALID_HID; long dataspace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long[] dims = { DIM_X, DIM_Y }; + long dataset_id = HDF5Constants.H5I_INVALID_HID; + long[] dims = {DIM_X, DIM_Y}; int[][] dset_data; // Open an existing file. @@ -332,13 +335,13 @@ public class H5Ex_D_UnlimitedAdd { e.printStackTrace(); } // Allocate array of pointers to rows. - dset_data = new int[(int) dims[0]][(int) dims[1]]; + dset_data = new int[(int)dims[0]][(int)dims[1]]; // Read the data using the default properties. try { if (dataset_id >= 0) - H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, dset_data); + H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, + HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, dset_data); } catch (Exception e) { e.printStackTrace(); @@ -381,10 +384,10 @@ public class H5Ex_D_UnlimitedAdd { } } - public static void main(String[] args) { + public static void main(String[] args) + { H5Ex_D_UnlimitedAdd.writeUnlimited(); H5Ex_D_UnlimitedAdd.extendUnlimited(); H5Ex_D_UnlimitedAdd.readUnlimited(); } - } diff --git a/java/examples/datasets/H5Ex_D_UnlimitedGzip.java b/java/examples/datasets/H5Ex_D_UnlimitedGzip.java index 675b1ba..e084641 100644 --- a/java/examples/datasets/H5Ex_D_UnlimitedGzip.java +++ b/java/examples/datasets/H5Ex_D_UnlimitedGzip.java @@ -31,47 +31,48 @@ import hdf.hdf5lib.H5; import hdf.hdf5lib.HDF5Constants; public class H5Ex_D_UnlimitedGzip { - private static String FILENAME = "H5Ex_D_UnlimitedGzip.h5"; + private static String FILENAME = "H5Ex_D_UnlimitedGzip.h5"; private static String DATASETNAME = "DS1"; - private static final int DIM_X = 4; - private static final int DIM_Y = 7; - private static final int EDIM_X = 6; - private static final int EDIM_Y = 10; - private static final int CHUNK_X = 4; - private static final int CHUNK_Y = 4; - private static final int RANK = 2; - private static final int NDIMS = 2; + private static final int DIM_X = 4; + private static final int DIM_Y = 7; + private static final int EDIM_X = 6; + private static final int EDIM_Y = 10; + private static final int CHUNK_X = 4; + private static final int CHUNK_Y = 4; + private static final int RANK = 2; + private static final int NDIMS = 2; // Values for the status of space allocation enum H5Z_filter { - H5Z_FILTER_ERROR(HDF5Constants.H5Z_FILTER_ERROR), H5Z_FILTER_NONE(HDF5Constants.H5Z_FILTER_NONE), H5Z_FILTER_DEFLATE( - HDF5Constants.H5Z_FILTER_DEFLATE), H5Z_FILTER_SHUFFLE(HDF5Constants.H5Z_FILTER_SHUFFLE), H5Z_FILTER_FLETCHER32( - HDF5Constants.H5Z_FILTER_FLETCHER32), H5Z_FILTER_SZIP(HDF5Constants.H5Z_FILTER_SZIP), H5Z_FILTER_NBIT( - HDF5Constants.H5Z_FILTER_NBIT), H5Z_FILTER_SCALEOFFSET(HDF5Constants.H5Z_FILTER_SCALEOFFSET), H5Z_FILTER_RESERVED( - HDF5Constants.H5Z_FILTER_RESERVED), H5Z_FILTER_MAX(HDF5Constants.H5Z_FILTER_MAX); + H5Z_FILTER_ERROR(HDF5Constants.H5Z_FILTER_ERROR), + H5Z_FILTER_NONE(HDF5Constants.H5Z_FILTER_NONE), + H5Z_FILTER_DEFLATE(HDF5Constants.H5Z_FILTER_DEFLATE), + H5Z_FILTER_SHUFFLE(HDF5Constants.H5Z_FILTER_SHUFFLE), + H5Z_FILTER_FLETCHER32(HDF5Constants.H5Z_FILTER_FLETCHER32), + H5Z_FILTER_SZIP(HDF5Constants.H5Z_FILTER_SZIP), + H5Z_FILTER_NBIT(HDF5Constants.H5Z_FILTER_NBIT), + H5Z_FILTER_SCALEOFFSET(HDF5Constants.H5Z_FILTER_SCALEOFFSET), + H5Z_FILTER_RESERVED(HDF5Constants.H5Z_FILTER_RESERVED), + H5Z_FILTER_MAX(HDF5Constants.H5Z_FILTER_MAX); private static final Map<Integer, H5Z_filter> lookup = new HashMap<Integer, H5Z_filter>(); - static { + static + { for (H5Z_filter s : EnumSet.allOf(H5Z_filter.class)) lookup.put(s.getCode(), s); } private int code; - H5Z_filter(int layout_type) { - this.code = layout_type; - } + H5Z_filter(int layout_type) { this.code = layout_type; } - public int getCode() { - return this.code; - } + public int getCode() { return this.code; } - public static H5Z_filter get(int code) { - return lookup.get(code); - } + public static H5Z_filter get(int code) { return lookup.get(code); } } - private static boolean checkGzipFilter() { + private static boolean checkGzipFilter() + { try { int available = H5.H5Zfilter_avail(HDF5Constants.H5Z_FILTER_DEFLATE); if (available == 0) { @@ -85,8 +86,8 @@ public class H5Ex_D_UnlimitedGzip { try { int filter_info = H5.H5Zget_filter_info(HDF5Constants.H5Z_FILTER_DEFLATE); - if (((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_ENCODE_ENABLED) == 0) - || ((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_DECODE_ENABLED) == 0)) { + if (((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_ENCODE_ENABLED) == 0) || + ((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_DECODE_ENABLED) == 0)) { System.out.println("gzip filter not available for encoding and decoding."); return false; } @@ -97,14 +98,15 @@ public class H5Ex_D_UnlimitedGzip { return true; } - private static void writeUnlimited() { - long file_id = HDF5Constants.H5I_INVALID_HID; - long dcpl_id = HDF5Constants.H5I_INVALID_HID; + private static void writeUnlimited() + { + long file_id = HDF5Constants.H5I_INVALID_HID; + long dcpl_id = HDF5Constants.H5I_INVALID_HID; long dataspace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long[] dims = { DIM_X, DIM_Y }; - long[] chunk_dims = { CHUNK_X, CHUNK_Y }; - long[] maxdims = { HDF5Constants.H5S_UNLIMITED, HDF5Constants.H5S_UNLIMITED }; + long dataset_id = HDF5Constants.H5I_INVALID_HID; + long[] dims = {DIM_X, DIM_Y}; + long[] chunk_dims = {CHUNK_X, CHUNK_Y}; + long[] maxdims = {HDF5Constants.H5S_UNLIMITED, HDF5Constants.H5S_UNLIMITED}; int[][] dset_data = new int[DIM_X][DIM_Y]; // Initialize the dataset. @@ -115,7 +117,7 @@ public class H5Ex_D_UnlimitedGzip { // Create a new file using default properties. try { file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT, - HDF5Constants.H5P_DEFAULT); + HDF5Constants.H5P_DEFAULT); } catch (Exception e) { e.printStackTrace(); @@ -147,7 +149,7 @@ public class H5Ex_D_UnlimitedGzip { try { if ((file_id >= 0) && (dataspace_id >= 0) && (dcpl_id >= 0)) dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_I32LE, dataspace_id, - HDF5Constants.H5P_DEFAULT, dcpl_id, HDF5Constants.H5P_DEFAULT); + HDF5Constants.H5P_DEFAULT, dcpl_id, HDF5Constants.H5P_DEFAULT); } catch (Exception e) { e.printStackTrace(); @@ -156,8 +158,8 @@ public class H5Ex_D_UnlimitedGzip { // Write the data to the dataset. try { if (dataset_id >= 0) - H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, dset_data); + H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, + HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, dset_data); } catch (Exception e) { e.printStackTrace(); @@ -198,14 +200,15 @@ public class H5Ex_D_UnlimitedGzip { } } - private static void extendUnlimited() { - long file_id = HDF5Constants.H5I_INVALID_HID; + private static void extendUnlimited() + { + long file_id = HDF5Constants.H5I_INVALID_HID; long dataspace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long[] dims = { DIM_X, DIM_Y }; - long[] extdims = { EDIM_X, EDIM_Y }; - long[] start = { 0, 0 }; - long[] count = new long[2]; + long dataset_id = HDF5Constants.H5I_INVALID_HID; + long[] dims = {DIM_X, DIM_Y}; + long[] extdims = {EDIM_X, EDIM_Y}; + long[] start = {0, 0}; + long[] count = new long[2]; int[][] dset_data; int[][] extend_dset_data = new int[EDIM_X][EDIM_Y]; @@ -246,13 +249,13 @@ public class H5Ex_D_UnlimitedGzip { } // Allocate array of pointers to rows. - dset_data = new int[(int) dims[0]][(int) dims[1]]; + dset_data = new int[(int)dims[0]][(int)dims[1]]; // Read the data using the default properties. try { if (dataset_id >= 0) - H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, dset_data); + H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, + HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, dset_data); } catch (Exception e) { e.printStackTrace(); @@ -314,7 +317,7 @@ public class H5Ex_D_UnlimitedGzip { // Write the data to the selected portion of the dataset. if (dataset_id >= 0) H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, dataspace_id, - HDF5Constants.H5P_DEFAULT, extend_dset_data); + HDF5Constants.H5P_DEFAULT, extend_dset_data); } } catch (Exception e) { @@ -348,12 +351,13 @@ public class H5Ex_D_UnlimitedGzip { } } - private static void readUnlimited() { - long file_id = HDF5Constants.H5I_INVALID_HID; + private static void readUnlimited() + { + long file_id = HDF5Constants.H5I_INVALID_HID; long dataspace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long dcpl_id = HDF5Constants.H5I_INVALID_HID; - long[] dims = { DIM_X, DIM_Y }; + long dataset_id = HDF5Constants.H5I_INVALID_HID; + long dcpl_id = HDF5Constants.H5I_INVALID_HID; + long[] dims = {DIM_X, DIM_Y}; int[][] dset_data; // Open an existing file. @@ -387,14 +391,14 @@ public class H5Ex_D_UnlimitedGzip { try { if (dcpl_id >= 0) { // Java lib requires a valid filter_name object and cd_values - int[] flags = { 0 }; - long[] cd_nelmts = { 1 }; - int[] cd_values = { 0 }; - String[] filter_name = { "" }; - int[] filter_config = { 0 }; - int filter_type = -1; - filter_type = H5 - .H5Pget_filter(dcpl_id, 0, flags, cd_nelmts, cd_values, 120, filter_name, filter_config); + int[] flags = {0}; + long[] cd_nelmts = {1}; + int[] cd_values = {0}; + String[] filter_name = {""}; + int[] filter_config = {0}; + int filter_type = -1; + filter_type = H5.H5Pget_filter(dcpl_id, 0, flags, cd_nelmts, cd_values, 120, filter_name, + filter_config); System.out.print("Filter type is: "); switch (H5Z_filter.get(filter_type)) { case H5Z_FILTER_DEFLATE: @@ -436,13 +440,13 @@ public class H5Ex_D_UnlimitedGzip { e.printStackTrace(); } // Allocate array of pointers to rows. - dset_data = new int[(int) dims[0]][(int) dims[1]]; + dset_data = new int[(int)dims[0]][(int)dims[1]]; // Read the data using the default properties. try { if (dataset_id >= 0) - H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, dset_data); + H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, + HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, dset_data); } catch (Exception e) { e.printStackTrace(); @@ -485,7 +489,8 @@ public class H5Ex_D_UnlimitedGzip { } } - public static void main(String[] args) { + public static void main(String[] args) + { // Check if gzip compression is available and can be used for both // compression and decompression. Normally we do not perform error // checking in these examples for the sake of clarity, but in this @@ -497,5 +502,4 @@ public class H5Ex_D_UnlimitedGzip { H5Ex_D_UnlimitedGzip.readUnlimited(); } } - } diff --git a/java/examples/datasets/H5Ex_D_UnlimitedMod.java b/java/examples/datasets/H5Ex_D_UnlimitedMod.java index 0708898..ccabcdd 100644 --- a/java/examples/datasets/H5Ex_D_UnlimitedMod.java +++ b/java/examples/datasets/H5Ex_D_UnlimitedMod.java @@ -26,25 +26,26 @@ import hdf.hdf5lib.H5; import hdf.hdf5lib.HDF5Constants; public class H5Ex_D_UnlimitedMod { - private static String FILENAME = "H5Ex_D_UnlimitedMod.h5"; + private static String FILENAME = "H5Ex_D_UnlimitedMod.h5"; private static String DATASETNAME = "DS1"; - private static final int DIM_X = 4; - private static final int DIM_Y = 7; - private static final int EDIM_X = 6; - private static final int EDIM_Y = 10; - private static final int CHUNK_X = 4; - private static final int CHUNK_Y = 4; - private static final int RANK = 2; - private static final int NDIMS = 2; - - private static void writeUnlimited() { - long file_id = HDF5Constants.H5I_INVALID_HID; - long dcpl_id = HDF5Constants.H5I_INVALID_HID; + private static final int DIM_X = 4; + private static final int DIM_Y = 7; + private static final int EDIM_X = 6; + private static final int EDIM_Y = 10; + private static final int CHUNK_X = 4; + private static final int CHUNK_Y = 4; + private static final int RANK = 2; + private static final int NDIMS = 2; + + private static void writeUnlimited() + { + long file_id = HDF5Constants.H5I_INVALID_HID; + long dcpl_id = HDF5Constants.H5I_INVALID_HID; long dataspace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long[] dims = { DIM_X, DIM_Y }; - long[] chunk_dims = { CHUNK_X, CHUNK_Y }; - long[] maxdims = { HDF5Constants.H5S_UNLIMITED, HDF5Constants.H5S_UNLIMITED }; + long dataset_id = HDF5Constants.H5I_INVALID_HID; + long[] dims = {DIM_X, DIM_Y}; + long[] chunk_dims = {CHUNK_X, CHUNK_Y}; + long[] maxdims = {HDF5Constants.H5S_UNLIMITED, HDF5Constants.H5S_UNLIMITED}; int[][] dset_data = new int[DIM_X][DIM_Y]; // Initialize the dataset. @@ -55,7 +56,7 @@ public class H5Ex_D_UnlimitedMod { // Create a new file using default properties. try { file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT, - HDF5Constants.H5P_DEFAULT); + HDF5Constants.H5P_DEFAULT); } catch (Exception e) { e.printStackTrace(); @@ -90,7 +91,7 @@ public class H5Ex_D_UnlimitedMod { try { if ((file_id >= 0) && (dataspace_id >= 0) && (dcpl_id >= 0)) dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_I32LE, dataspace_id, - HDF5Constants.H5P_DEFAULT, dcpl_id, HDF5Constants.H5P_DEFAULT); + HDF5Constants.H5P_DEFAULT, dcpl_id, HDF5Constants.H5P_DEFAULT); } catch (Exception e) { e.printStackTrace(); @@ -99,8 +100,8 @@ public class H5Ex_D_UnlimitedMod { // Write the data to the dataset. try { if (dataset_id >= 0) - H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, dset_data); + H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, + HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, dset_data); } catch (Exception e) { e.printStackTrace(); @@ -141,12 +142,13 @@ public class H5Ex_D_UnlimitedMod { } } - private static void extendUnlimited() { - long file_id = HDF5Constants.H5I_INVALID_HID; + private static void extendUnlimited() + { + long file_id = HDF5Constants.H5I_INVALID_HID; long dataspace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long[] dims = { DIM_X, DIM_Y }; - long[] extdims = { EDIM_X, EDIM_Y }; + long dataset_id = HDF5Constants.H5I_INVALID_HID; + long[] dims = {DIM_X, DIM_Y}; + long[] extdims = {EDIM_X, EDIM_Y}; int[][] dset_data; int[][] extend_dset_data = new int[EDIM_X][EDIM_Y]; @@ -187,13 +189,13 @@ public class H5Ex_D_UnlimitedMod { } // Allocate array of pointers to rows. - dset_data = new int[(int) dims[0]][(int) dims[1]]; + dset_data = new int[(int)dims[0]][(int)dims[1]]; // Read the data using the default properties. try { if (dataset_id >= 0) - H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, dset_data); + H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, + HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, dset_data); } catch (Exception e) { e.printStackTrace(); @@ -244,7 +246,7 @@ public class H5Ex_D_UnlimitedMod { try { if ((dataspace_id >= 0) && (dataset_id >= 0)) H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, dataspace_id, - HDF5Constants.H5P_DEFAULT, extend_dset_data); + HDF5Constants.H5P_DEFAULT, extend_dset_data); } catch (Exception e) { e.printStackTrace(); @@ -277,11 +279,12 @@ public class H5Ex_D_UnlimitedMod { } } - private static void readUnlimited() { - long file_id = HDF5Constants.H5I_INVALID_HID; + private static void readUnlimited() + { + long file_id = HDF5Constants.H5I_INVALID_HID; long dataspace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long[] dims = { DIM_X, DIM_Y }; + long dataset_id = HDF5Constants.H5I_INVALID_HID; + long[] dims = {DIM_X, DIM_Y}; int[][] dset_data; // Open an existing file. @@ -318,13 +321,13 @@ public class H5Ex_D_UnlimitedMod { e.printStackTrace(); } // Allocate array of pointers to rows. - dset_data = new int[(int) dims[0]][(int) dims[1]]; + dset_data = new int[(int)dims[0]][(int)dims[1]]; // Read the data using the default properties. try { if (dataset_id >= 0) - H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, dset_data); + H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, + HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, dset_data); } catch (Exception e) { e.printStackTrace(); @@ -367,10 +370,10 @@ public class H5Ex_D_UnlimitedMod { } } - public static void main(String[] args) { + public static void main(String[] args) + { H5Ex_D_UnlimitedMod.writeUnlimited(); H5Ex_D_UnlimitedMod.extendUnlimited(); H5Ex_D_UnlimitedMod.readUnlimited(); } - } |