diff options
author | Allen Byrne <50328838+byrnHDF@users.noreply.github.com> | 2022-01-18 20:02:53 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-18 20:02:53 (GMT) |
commit | 8dc72928b8c2f0390659d14011b34983cf9b1171 (patch) | |
tree | cbaea8d84759aab14b2c16cbb2c0983736659029 /java/examples | |
parent | 2f34c433dc26811909673922838e4a97d7c98b9c (diff) | |
download | hdf5-8dc72928b8c2f0390659d14011b34983cf9b1171.zip hdf5-8dc72928b8c2f0390659d14011b34983cf9b1171.tar.gz hdf5-8dc72928b8c2f0390659d14011b34983cf9b1171.tar.bz2 |
Develop java newrefs fixes for obj ref datasets (#1354)
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Dana Robinson <43805+derobins@users.noreply.github.com>
Diffstat (limited to 'java/examples')
-rw-r--r-- | java/examples/datatypes/H5Ex_T_ObjectReference.java | 165 | ||||
-rw-r--r-- | java/examples/datatypes/H5Ex_T_ObjectReferenceAttribute.java | 194 |
2 files changed, 149 insertions, 210 deletions
diff --git a/java/examples/datatypes/H5Ex_T_ObjectReference.java b/java/examples/datatypes/H5Ex_T_ObjectReference.java index 98a11df..b0f98de 100644 --- a/java/examples/datatypes/H5Ex_T_ObjectReference.java +++ b/java/examples/datatypes/H5Ex_T_ObjectReference.java @@ -205,113 +205,86 @@ public class H5Ex_T_ObjectReference { // Open an existing file. try { file_id = H5.H5Fopen(FILENAME, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT); - } - catch (Exception e) { - e.printStackTrace(); - } - - // Open an existing dataset. - try { - if (file_id >= 0) - dataset_id = H5.H5Dopen(file_id, DATASETNAME, HDF5Constants.H5P_DEFAULT); - } - catch (Exception e) { - e.printStackTrace(); - } - - // Get dataspace and allocate memory for read buffer. - try { - if (dataset_id >= 0) - dataspace_id = H5.H5Dget_space(dataset_id); - } - catch (Exception e) { - e.printStackTrace(); - } - - try { - if (dataspace_id >= 0) - H5.H5Sget_simple_extent_dims(dataspace_id, dims, null); - } - catch (Exception e) { - e.printStackTrace(); - } - - // Read data. - try { - if (dataset_id >= 0) { - H5.H5Dread(dataset_id, HDF5Constants.H5T_STD_REF, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, dset_data); - } - } - catch (Exception e) { - e.printStackTrace(); - } - // Output the data to the screen. - for (int indx = 0; indx < dims[0]; indx++) { - System.out.println(DATASETNAME + "[" + indx + "]:"); - System.out.print(" ->"); - // Open the referenced object, get its name and type. + // Open an existing dataset. try { - if (dataset_id >= 0) { - 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]); + dataset_id = H5.H5Dopen(file_id, DATASETNAME, HDF5Constants.H5P_DEFAULT); + + try { + // Get dataspace and allocate memory for read buffer. + dataspace_id = H5.H5Dget_space(dataset_id); + H5.H5Sget_simple_extent_dims(dataspace_id, dims, null); + + // Read data. + H5.H5Dread(dataset_id, HDF5Constants.H5T_STD_REF, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, + HDF5Constants.H5P_DEFAULT, dset_data); + + // Output the data to the screen. + for (int indx = 0; indx < dims[0]; indx++) { + System.out.println(DATASETNAME + "[" + indx + "]:"); + System.out.print(" ->"); + // Open the referenced object, get its name and type. + try { + object_id = H5.H5Ropen_object(dset_data[indx], HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); + try { + object_type = H5.H5Rget_obj_type3(dset_data[indx], HDF5Constants.H5R_OBJECT); + String obj_name = null; + if (object_type >= 0) { + // 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"); + break; + case H5G_DATASET: + System.out.print("H5G_DATASET"); + break; + case H5G_TYPE: + System.out.print("H5G_TYPE"); + break; + default: + System.out.print("UNHANDLED"); + } + } + // Print the name. + System.out.println(": " + obj_name); + } + catch (Exception e) { + e.printStackTrace(); + } + finally { + try {H5.H5Oclose(object_id);} catch (Exception e) {} + } + } + catch (Exception e4) { + e4.printStackTrace(); + } + finally { + try {H5.H5Rdestroy(dset_data[indx]);} catch (Exception e4) {} + } + } // end for } - String obj_name = null; - if (object_type >= 0) { - // Get the name. - obj_name = H5.H5Iget_name(object_id); + catch (Exception e3) { + e3.printStackTrace(); } - if ((object_id >= 0) && (object_type >= -1)) { - switch (H5G_obj.get(object_type)) { - case H5G_GROUP: - System.out.print("H5G_GROUP"); - break; - case H5G_DATASET: - System.out.print("H5G_DATASET"); - break; - case H5G_TYPE: - System.out.print("H5G_TYPE"); - break; - default: - System.out.print("UNHANDLED"); - } + finally { + try {H5.H5Sclose(dataspace_id);} catch (Exception e3) {} } - // Print the name. - System.out.println(": " + obj_name); } - catch (Exception e) { - e.printStackTrace(); + catch (Exception e2) { + e2.printStackTrace(); } finally { - try {H5.H5Oclose(object_id);} catch (Exception ex) {} + try {H5.H5Dclose(dataset_id);} catch (Exception e2) {} } } - - // End access to the dataset and release resources used by it. - try { - if (dataspace_id >= 0) - H5.H5Sclose(dataspace_id); - } - catch (Exception e) { - e.printStackTrace(); + catch (Exception e1) { + e1.printStackTrace(); } - - try { - if (dataset_id >= 0) - H5.H5Dclose(dataset_id); - } - catch (Exception e) { - e.printStackTrace(); - } - - // Close the file. - try { - if (file_id >= 0) - H5.H5Fclose(file_id); - } - catch (Exception e) { - e.printStackTrace(); + finally { + try {H5.H5Fclose(file_id);} catch (Exception e1) {} } } diff --git a/java/examples/datatypes/H5Ex_T_ObjectReferenceAttribute.java b/java/examples/datatypes/H5Ex_T_ObjectReferenceAttribute.java index 885b1da..f61ae0d 100644 --- a/java/examples/datatypes/H5Ex_T_ObjectReferenceAttribute.java +++ b/java/examples/datatypes/H5Ex_T_ObjectReferenceAttribute.java @@ -85,7 +85,7 @@ public class H5Ex_T_ObjectReferenceAttribute { // Create dataset with a scalar dataspace. try { dataspace_id = H5.H5Screate(HDF5Constants.H5S_SCALAR); - if (dataspace_id >= 0) { + if ((file_id >= 0) && (dataspace_id >= 0)) { dataset_id = H5.H5Dcreate(file_id, DATASETNAME2, HDF5Constants.H5T_STD_I32LE, dataspace_id, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); if (dataset_id >= 0) @@ -197,7 +197,6 @@ public class H5Ex_T_ObjectReferenceAttribute { e.printStackTrace(); } - // Terminate access to the data space. try { if (dataspace_id >= 0) H5.H5Sclose(dataspace_id); @@ -229,129 +228,96 @@ public class H5Ex_T_ObjectReferenceAttribute { // Open an existing file. try { file_id = H5.H5Fopen(FILENAME, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT); - } - catch (Exception e) { - e.printStackTrace(); - } - - // Open an existing dataset. - try { - if (file_id >= 0) - dataset_id = H5.H5Dopen(file_id, DATASETNAME, HDF5Constants.H5P_DEFAULT); - } - catch (Exception e) { - e.printStackTrace(); - } - try { - if (dataset_id >= 0) - attribute_id = H5.H5Aopen_by_name(dataset_id, ".", ATTRIBUTENAME, HDF5Constants.H5P_DEFAULT, - HDF5Constants.H5P_DEFAULT); - } - catch (Exception e) { - e.printStackTrace(); - } - - // Get dataspace and allocate memory for read buffer. - try { - if (attribute_id >= 0) - dataspace_id = H5.H5Aget_space(attribute_id); - } - catch (Exception e) { - e.printStackTrace(); - } - - try { - if (dataspace_id >= 0) - H5.H5Sget_simple_extent_dims(dataspace_id, dims, null); - } - catch (Exception e) { - e.printStackTrace(); - } - - // Read data. - try { - if (attribute_id >= 0) - H5.H5Aread(attribute_id, HDF5Constants.H5T_STD_REF, dset_data); - } - catch (Exception e) { - e.printStackTrace(); - } - - // Output the data to the screen. - for (int indx = 0; indx < dims[0]; indx++) { - System.out.println(ATTRIBUTENAME + "[" + indx + "]:"); - System.out.print(" ->"); - // Open the referenced object, get its name and type. + // Open an existing dataset. try { - if (dataset_id >= 0) { - 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]); + dataset_id = H5.H5Dopen(file_id, DATASETNAME, HDF5Constants.H5P_DEFAULT); + + try { + attribute_id = H5.H5Aopen_by_name(dataset_id, ".", ATTRIBUTENAME, HDF5Constants.H5P_DEFAULT, + HDF5Constants.H5P_DEFAULT); + + // Get dataspace and allocate memory for read buffer. + try { + dataspace_id = H5.H5Aget_space(attribute_id); + H5.H5Sget_simple_extent_dims(dataspace_id, dims, null); + + // Read data. + H5.H5Aread(attribute_id, HDF5Constants.H5T_STD_REF, dset_data); + + // Output the data to the screen. + for (int indx = 0; indx < dims[0]; indx++) { + System.out.println(ATTRIBUTENAME + "[" + indx + "]:"); + System.out.print(" ->"); + // Open the referenced object, get its name and type. + try { + object_id = H5.H5Ropen_object(dset_data[indx], HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); + try { + object_type = H5.H5Rget_obj_type3(dset_data[indx], HDF5Constants.H5R_OBJECT); + String obj_name = null; + if (object_type >= 0) { + // 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"); + break; + case H5G_DATASET: + System.out.print("H5G_DATASET"); + break; + case H5G_TYPE: + System.out.print("H5G_TYPE"); + break; + default: + System.out.print("UNHANDLED"); + } + } + // Print the name. + System.out.println(": " + obj_name); + } + catch (Exception e) { + e.printStackTrace(); + } + finally { + try {H5.H5Oclose(object_id);} catch (Exception e) {} + } + } + catch (Exception e5) { + e5.printStackTrace(); + } + finally { + try {H5.H5Rdestroy(dset_data[indx]);} catch (Exception e5) {} + } + } // end for + } + catch (Exception e4) { + e4.printStackTrace(); + } + finally { + try {H5.H5Sclose(dataspace_id);} catch (Exception e3) {} + } } - String obj_name = null; - if (object_type >= 0) { - // Get the name. - obj_name = H5.H5Iget_name(object_id); + catch (Exception e3) { + e3.printStackTrace(); } - if ((object_id >= 0) && (object_type >= -1)) { - switch (H5G_obj.get(object_type)) { - case H5G_GROUP: - System.out.print("H5G_GROUP"); - break; - case H5G_DATASET: - System.out.print("H5G_DATASET"); - break; - case H5G_TYPE: - System.out.print("H5G_TYPE"); - break; - default: - System.out.print("UNHANDLED"); - } + finally { + try {H5.H5Aclose(attribute_id);} catch (Exception e4) {} } - // Print the name. - System.out.println(": " + obj_name); } - catch (Exception e) { - e.printStackTrace(); + catch (Exception e2) { + e2.printStackTrace(); } finally { - try {H5.H5Oclose(object_id);} catch (Exception ex) {} + try {H5.H5Dclose(dataset_id);} catch (Exception e2) {} } } - - // End access to the dataset and release resources used by it. - try { - if (attribute_id >= 0) - H5.H5Aclose(attribute_id); - } - catch (Exception e) { - e.printStackTrace(); + catch (Exception e1) { + e1.printStackTrace(); } - - try { - if (dataset_id >= 0) - H5.H5Dclose(dataset_id); - } - catch (Exception e) { - e.printStackTrace(); - } - - // Terminate access to the data space. - try { - if (dataspace_id >= 0) - H5.H5Sclose(dataspace_id); - } - catch (Exception e) { - e.printStackTrace(); - } - - // Close the file. - try { - if (file_id >= 0) - H5.H5Fclose(file_id); - } - catch (Exception e) { - e.printStackTrace(); + finally { + try {H5.H5Fclose(file_id);} catch (Exception e1) {} } } |