diff options
author | Allen Byrne <50328838+byrnHDF@users.noreply.github.com> | 2022-01-08 14:19:52 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-08 14:19:52 (GMT) |
commit | 03217eca811fde93dd3fbc2a941641cc9ccc1c1e (patch) | |
tree | b56a4a91fa4e6308ba8a739f3c99169d2c4386a7 /java/examples/datatypes/H5Ex_T_ObjectReference.java | |
parent | 8430e3d661cdcf91ed60626e87be936a6f15afe8 (diff) | |
download | hdf5-03217eca811fde93dd3fbc2a941641cc9ccc1c1e.zip hdf5-03217eca811fde93dd3fbc2a941641cc9ccc1c1e.tar.gz hdf5-03217eca811fde93dd3fbc2a941641cc9ccc1c1e.tar.bz2 |
Add tests for H5Ocopy of new object refs (#1338)
* Add tests for H5Ocopy of new object refs
* Correct class name
* Skip test because of issue with debug assertions
* Update reference file
* Fix object examples for new refs
Diffstat (limited to 'java/examples/datatypes/H5Ex_T_ObjectReference.java')
-rw-r--r-- | java/examples/datatypes/H5Ex_T_ObjectReference.java | 124 |
1 files changed, 55 insertions, 69 deletions
diff --git a/java/examples/datatypes/H5Ex_T_ObjectReference.java b/java/examples/datatypes/H5Ex_T_ObjectReference.java index 38536b8..98a11df 100644 --- a/java/examples/datatypes/H5Ex_T_ObjectReference.java +++ b/java/examples/datatypes/H5Ex_T_ObjectReference.java @@ -70,7 +70,7 @@ public class H5Ex_T_ObjectReference { long group_id = HDF5Constants.H5I_INVALID_HID; long dataset_id = HDF5Constants.H5I_INVALID_HID; long[] dims = { DIM0 }; - byte[][] dset_data = new byte[DIM0][8]; + byte[][] dset_data = new byte[DIM0][HDF5Constants.H5R_REF_BUF_SIZE]; // Create a new file using default properties. try { @@ -111,50 +111,58 @@ public class H5Ex_T_ObjectReference { e.printStackTrace(); } - // Create references to the previously created objects. Passing -1 - // as space_id causes this parameter to be ignored. Other values - // besides valid dataspaces result in an error. try { if (file_id >= 0) { - byte rbuf0[] = H5.H5Rcreate(file_id, GROUPNAME, HDF5Constants.H5R_OBJECT, -1); - byte rbuf1[] = H5.H5Rcreate(file_id, DATASETNAME2, HDF5Constants.H5R_OBJECT, -1); - for (int indx = 0; indx < 8; indx++) { - dset_data[0][indx] = rbuf0[indx]; - dset_data[1][indx] = rbuf1[indx]; + try { + dset_data[0] = H5.H5Rcreate_object(file_id, GROUPNAME, HDF5Constants.H5P_DEFAULT); + } + catch (Throwable err) { + err.printStackTrace(); + } + + try { + dset_data[1] = H5.H5Rcreate_object(file_id, DATASETNAME2, HDF5Constants.H5P_DEFAULT); + } + catch (Throwable err) { + err.printStackTrace(); } } + + // Create dataspace. Setting maximum size to NULL sets the maximum + // size to be the current size. + try { + filespace_id = H5.H5Screate_simple(RANK, dims, null); + } + catch (Exception e) { + e.printStackTrace(); + } + + // Create the dataset. + try { + if ((file_id >= 0) && (filespace_id >= 0)) + dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_REF, filespace_id, + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); + } + catch (Exception e) { + e.printStackTrace(); + } + + // Write the object references to it. + try { + if (dataset_id >= 0) + H5.H5Dwrite(dataset_id, HDF5Constants.H5T_STD_REF, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, + HDF5Constants.H5P_DEFAULT, dset_data); + } + catch (Exception e) { + e.printStackTrace(); + } } - catch (Exception e) { - e.printStackTrace(); - } - - // Create dataspace. Setting maximum size to NULL sets the maximum - // size to be the current size. - try { - filespace_id = H5.H5Screate_simple(RANK, dims, null); - } - catch (Exception e) { - e.printStackTrace(); - } - - // Create the dataset. - try { - if ((file_id >= 0) && (filespace_id >= 0)) - dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_REF_OBJ, filespace_id, - HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); - } - catch (Exception e) { - e.printStackTrace(); - } - - // Write the object references to it. - try { - if (dataset_id >= 0) - H5.H5Dwrite(dataset_id, HDF5Constants.H5T_STD_REF_OBJ, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, dset_data); + catch (Exception ex) { + ex.printStackTrace(); } - catch (Exception e) { - e.printStackTrace(); + finally { + try {H5.H5Rdestroy(dset_data[1]);} catch (Exception ex) {} + try {H5.H5Rdestroy(dset_data[0]);} catch (Exception ex) {} } // End access to the dataset and release resources used by it. @@ -192,7 +200,7 @@ public class H5Ex_T_ObjectReference { int object_type = -1; long object_id = HDF5Constants.H5I_INVALID_HID; long[] dims = { DIM0 }; - byte[][] dset_data; + byte[][] dset_data = new byte[DIM0][HDF5Constants.H5R_REF_BUF_SIZE]; // Open an existing file. try { @@ -228,14 +236,10 @@ public class H5Ex_T_ObjectReference { e.printStackTrace(); } - // Allocate array of pointers to two-dimensional arrays (the - // elements of the dataset. - dset_data = new byte[(int)dims[0]][8]; - - // Read the data using the default properties. + // Read data. try { if (dataset_id >= 0) { - H5.H5Dread(dataset_id, HDF5Constants.H5T_STD_REF_OBJ, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, + H5.H5Dread(dataset_id, HDF5Constants.H5T_STD_REF, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, dset_data); } } @@ -250,45 +254,24 @@ public class H5Ex_T_ObjectReference { // Open the referenced object, get its name and type. try { if (dataset_id >= 0) { - object_id = H5.H5Rdereference(dataset_id, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5R_OBJECT, dset_data[indx]); + object_id = H5.H5Ropen_object(dset_data[indx], HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); object_type = H5.H5Rget_obj_type(dataset_id, HDF5Constants.H5R_OBJECT, dset_data[indx]); } String obj_name = null; if (object_type >= 0) { - // Get the length of the name and retrieve the name. + // Get the name. obj_name = H5.H5Iget_name(object_id); } if ((object_id >= 0) && (object_type >= -1)) { switch (H5G_obj.get(object_type)) { case H5G_GROUP: System.out.print("H5G_GROUP"); - try { - if (object_id >= 0) - H5.H5Gclose(object_id); - } - catch (Exception e) { - e.printStackTrace(); - } break; case H5G_DATASET: System.out.print("H5G_DATASET"); - try { - if (object_id >= 0) - H5.H5Dclose(object_id); - } - catch (Exception e) { - e.printStackTrace(); - } break; case H5G_TYPE: System.out.print("H5G_TYPE"); - try { - if (object_id >= 0) - H5.H5Tclose(object_id); - } - catch (Exception e) { - e.printStackTrace(); - } break; default: System.out.print("UNHANDLED"); @@ -300,6 +283,9 @@ public class H5Ex_T_ObjectReference { catch (Exception e) { e.printStackTrace(); } + finally { + try {H5.H5Oclose(object_id);} catch (Exception ex) {} + } } // End access to the dataset and release resources used by it. |