summaryrefslogtreecommitdiffstats
path: root/java/examples/datatypes/H5Ex_T_String.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/examples/datatypes/H5Ex_T_String.java')
-rw-r--r--java/examples/datatypes/H5Ex_T_String.java71
1 files changed, 36 insertions, 35 deletions
diff --git a/java/examples/datatypes/H5Ex_T_String.java b/java/examples/datatypes/H5Ex_T_String.java
index e497bd8..a69a70b 100644
--- a/java/examples/datatypes/H5Ex_T_String.java
+++ b/java/examples/datatypes/H5Ex_T_String.java
@@ -24,27 +24,28 @@ import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
public class H5Ex_T_String {
- private static String FILENAME = "H5Ex_T_String.h5";
+ private static String FILENAME = "H5Ex_T_String.h5";
private static String DATASETNAME = "DS1";
- private static final int DIM0 = 4;
- private static final int SDIM = 8;
- private static final int RANK = 1;
-
- private static void CreateDataset() {
- long file_id = HDF5Constants.H5I_INVALID_HID;
- long memtype_id = HDF5Constants.H5I_INVALID_HID;
- long filetype_id = HDF5Constants.H5I_INVALID_HID;
- long dataspace_id = HDF5Constants.H5I_INVALID_HID;
- long dataset_id = HDF5Constants.H5I_INVALID_HID;
- long[] dims = { DIM0 };
- byte[][] dset_data = new byte[DIM0][SDIM];
- StringBuffer[] str_data = { new StringBuffer("Parting"), new StringBuffer("is such"),
- new StringBuffer("sweet"), new StringBuffer("sorrow.") };
+ private static final int DIM0 = 4;
+ private static final int SDIM = 8;
+ private static final int RANK = 1;
+
+ private static void CreateDataset()
+ {
+ long file_id = HDF5Constants.H5I_INVALID_HID;
+ long memtype_id = HDF5Constants.H5I_INVALID_HID;
+ long filetype_id = HDF5Constants.H5I_INVALID_HID;
+ long dataspace_id = HDF5Constants.H5I_INVALID_HID;
+ long dataset_id = HDF5Constants.H5I_INVALID_HID;
+ long[] dims = {DIM0};
+ byte[][] dset_data = new byte[DIM0][SDIM];
+ StringBuffer[] str_data = {new StringBuffer("Parting"), new StringBuffer("is such"),
+ new StringBuffer("sweet"), new StringBuffer("sorrow.")};
// 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();
@@ -82,8 +83,9 @@ public class H5Ex_T_String {
// Create the dataset and write the string data to it.
try {
if ((file_id >= 0) && (filetype_id >= 0) && (dataspace_id >= 0))
- dataset_id = H5.H5Dcreate(file_id, DATASETNAME, filetype_id, dataspace_id, HDF5Constants.H5P_DEFAULT,
- HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ dataset_id =
+ H5.H5Dcreate(file_id, DATASETNAME, filetype_id, dataspace_id, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
@@ -94,14 +96,14 @@ public class H5Ex_T_String {
for (int indx = 0; indx < DIM0; indx++) {
for (int jndx = 0; jndx < SDIM; jndx++) {
if (jndx < str_data[indx].length())
- dset_data[indx][jndx] = (byte) str_data[indx].charAt(jndx);
+ dset_data[indx][jndx] = (byte)str_data[indx].charAt(jndx);
else
dset_data[indx][jndx] = 0;
}
}
if ((dataset_id >= 0) && (memtype_id >= 0))
H5.H5Dwrite(dataset_id, memtype_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
- HDF5Constants.H5P_DEFAULT, dset_data);
+ HDF5Constants.H5P_DEFAULT, dset_data);
}
catch (Exception e) {
e.printStackTrace();
@@ -151,17 +153,17 @@ public class H5Ex_T_String {
catch (Exception e) {
e.printStackTrace();
}
-
}
- private static void ReadDataset() {
- long file_id = HDF5Constants.H5I_INVALID_HID;
- long filetype_id = HDF5Constants.H5I_INVALID_HID;
- long memtype_id = HDF5Constants.H5I_INVALID_HID;
+ private static void ReadDataset()
+ {
+ long file_id = HDF5Constants.H5I_INVALID_HID;
+ long filetype_id = HDF5Constants.H5I_INVALID_HID;
+ long memtype_id = HDF5Constants.H5I_INVALID_HID;
long dataspace_id = HDF5Constants.H5I_INVALID_HID;
- long dataset_id = HDF5Constants.H5I_INVALID_HID;
- long sdim = 0;
- long[] dims = { DIM0 };
+ long dataset_id = HDF5Constants.H5I_INVALID_HID;
+ long sdim = 0;
+ long[] dims = {DIM0};
byte[][] dset_data;
StringBuffer[] str_data;
@@ -213,8 +215,8 @@ public class H5Ex_T_String {
}
// Allocate space for data.
- dset_data = new byte[(int) dims[0]][(int)sdim];
- str_data = new StringBuffer[(int) dims[0]];
+ dset_data = new byte[(int)dims[0]][(int)sdim];
+ str_data = new StringBuffer[(int)dims[0]];
// Create the memory datatype.
try {
@@ -230,9 +232,9 @@ public class H5Ex_T_String {
try {
if ((dataset_id >= 0) && (memtype_id >= 0))
H5.H5Dread(dataset_id, memtype_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
- HDF5Constants.H5P_DEFAULT, dset_data);
+ HDF5Constants.H5P_DEFAULT, dset_data);
byte[] tempbuf = new byte[(int)sdim];
- for (int indx = 0; indx < (int) dims[0]; indx++) {
+ for (int indx = 0; indx < (int)dims[0]; indx++) {
for (int jndx = 0; jndx < sdim; jndx++) {
tempbuf[jndx] = dset_data[indx][jndx];
}
@@ -293,10 +295,10 @@ public class H5Ex_T_String {
catch (Exception e) {
e.printStackTrace();
}
-
}
- public static void main(String[] args) {
+ public static void main(String[] args)
+ {
H5Ex_T_String.CreateDataset();
// Now we begin the read section of this example. Here we assume
// the dataset and array have the same name and rank, but can have
@@ -304,5 +306,4 @@ public class H5Ex_T_String {
// data using malloc().
H5Ex_T_String.ReadDataset();
}
-
}