1 10 Fix java data export functions (#450)

* HDFFV-10865 - merge from dev, HDFArray perf fix.

* Remove duplicate setting

* Whitespace changes after clang format

* Undo version 11 clang format changes

* Merge CMake changes from develop

* test testing script merge from develop

* Update supported platforms

* PR#3 merge from develop

* Merge gcc 10 diagnostics option from develop

* Merge #318 OSX changes from develop

* Merge small changes from develop

* Minor non-space formatting changes

* #386 copyright corrections for java folder

* Merges from develop

#358 patches from vtk
#361 fix header guard spelling

* Merge updates

#358 patches from vtk
#361 fix header guard spelling

* format fix

* Fix missing underscore and make H5public.h closer to dev

* Merges from develop

#340 clang -Wformat-security warnings
#360 Fixed uninitialized warnings
header guard underscore cleanup
JNI cleanup

* format alignment

* Add missing test ref file

* Merge #380 from develop

* Finish java merges from develop

* Fix java issues with tests and javadoc

* Correct use of attribute access plist

* Remove debug code

* Remove unused variable

* Change file access to read only for java tests

* Split clang format operations.

* More javadoc comments

* Remove pre-split setting

* format source
This commit is contained in:
Allen Byrne
2021-03-10 07:41:14 -06:00
committed by GitHub
parent 2524ad19c0
commit dd5b8a8747
98 changed files with 1339 additions and 1041 deletions

View File

@@ -31,6 +31,7 @@ import java.io.StreamTokenizer;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
import hdf.hdf5lib.exceptions.HDF5Exception;
import hdf.hdf5lib.exceptions.HDF5LibraryException;
import org.junit.After;
@@ -46,22 +47,21 @@ import org.junit.rules.TestName;
*/
public class TestH5 {
@Rule public TestName testname = new TestName();
@Before
public void showTestName() {
System.out.print(testname.getMethodName());
}
@After
public void nextTestName() {
System.out.println();
}
private static final String H5_FILE = "testData.h5";
private static final String EXPORT_FILE = "testExport.txt";
private static final String H5_DREG_FILE = "trefer_reg.h5";
private static final String EXPORT_DREG_FILE = "testExportReg.txt";
private static final String H5_AREG_FILE = "tattrreg.h5";
private static final String EXPORT_AREG_FILE = "testExportAReg.txt";
private static final int DIM_X = 4;
private static final int DIM_Y = 6;
private static final int DIM_BLKS = 36;
private static final int DIM_PNTS = 10;
private static final int DIM_ATTR = 12;
private static final int RANK = 2;
long H5fid = -1;
long H5dsid = -1;
long H5did = -1;
long H5fid = HDF5Constants.H5I_INVALID_HID;
long H5dsid = HDF5Constants.H5I_INVALID_HID;
long H5did = HDF5Constants.H5I_INVALID_HID;
long[] H5dims = { DIM_X, DIM_Y };
private final void _deleteFile(String filename) {
@@ -77,7 +77,7 @@ public class TestH5 {
}
private final long _createDataset(long fid, long dsid, String name, long dapl) {
long did = -1;
long did = HDF5Constants.H5I_INVALID_HID;
try {
did = H5.H5Dcreate(fid, name, HDF5Constants.H5T_STD_I32LE, dsid,
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, dapl);
@@ -114,22 +114,64 @@ public class TestH5 {
}
}
public final void _closeH5File() throws HDF5LibraryException {
private final void _closeH5File() {
if (H5did >= 0)
try {H5.H5Dclose(H5did);} catch (Exception ex) {}
if (H5dsid > 0)
try {H5.H5Sclose(H5dsid);} catch (Exception ex) {}
if (H5fid > 0)
try {H5.H5Fclose(H5fid);} catch (Exception ex) {}
H5fid = -1;
H5dsid = -1;
H5did = -1;
H5fid = HDF5Constants.H5I_INVALID_HID;
H5dsid = HDF5Constants.H5I_INVALID_HID;
H5did = HDF5Constants.H5I_INVALID_HID;
}
public void _openH5File(String filename, String dsetname) {
try {
H5fid = H5.H5Fopen(filename,
HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
}
catch (Throwable err) {
err.printStackTrace();
fail("TestH5._openH5file: " + err);
}
assertTrue("TestH5._openH5file: H5.H5Fopen: ", H5fid >= 0);
try {
H5did = H5.H5Dopen(H5fid, dsetname, HDF5Constants.H5P_DEFAULT);
}
catch (Throwable err) {
err.printStackTrace();
fail("TestH5._openH5file: " + err);
}
assertTrue("TestH5._openH5file: H5.H5Dopen: ", H5did >= 0);
try {
H5dsid = H5.H5Dget_space(H5did);
}
catch (Throwable err) {
err.printStackTrace();
fail("TestH5._openH5file: " + err);
}
assertTrue("TestH5._openH5file: H5.H5Screate_simple: ",H5dsid > 0);
}
public final void _deleteH5file() {
_closeH5File();
_deleteFile(H5_FILE);
}
@After
public void closeH5File() throws HDF5LibraryException {
_closeH5File();
System.out.println();
}
@Before
public void verifyCount()
throws NullPointerException, HDF5Exception {
assertTrue("H5 open ids is 0", H5.getOpenIDCount()==0);
System.out.print(testname.getMethodName());
}
/**
* Test method for {@link hdf.hdf5lib.H5#J2C(int)}.
* NOTE:
@@ -373,8 +415,10 @@ public class TestH5 {
_closeH5File();
_openH5File(H5_FILE, "/dset");
try {
H5.H5export_dataset(EXPORT_FILE, H5_FILE, "/dset", 99);
H5.H5export_dataset(EXPORT_FILE, H5fid, "/dset", 99);
}
catch (HDF5LibraryException err) {
err.printStackTrace();
@@ -410,4 +454,88 @@ public class TestH5 {
}
_deleteH5file();
}
@Test
public void testH5export_regdataset() {
int[] dset_data_expect = {66, 69, 72, 75, 78, 81, 96, 99, 102, 105, 108,
111, 126, 129, 132, 135, 138, 141, 156, 159, 162, 165, 168, 171,
186, 189, 192, 195, 198, 201, 216, 219, 222, 225, 228, 231,
207, 66, 252, 48, 84, 96, 12, 14, 213, 99};
int[] dset_indata = new int[DIM_BLKS+DIM_PNTS];
String objName = "/Dataset1";
_openH5File(H5_DREG_FILE, objName);
try {
H5.H5export_dataset(EXPORT_DREG_FILE, H5fid, objName, 99);
}
catch (HDF5LibraryException err) {
err.printStackTrace();
fail("H5export_dataset failed: " + err);
}
File file = new File(EXPORT_DREG_FILE);
try {
Reader reader = new FileReader(EXPORT_DREG_FILE);
StreamTokenizer streamTokenizer = new StreamTokenizer(reader);
int indx = 0;
while(streamTokenizer.nextToken() != StreamTokenizer.TT_EOF){
if(streamTokenizer.ttype == StreamTokenizer.TT_NUMBER) {
dset_indata[indx] = (int)streamTokenizer.nval;
indx++;
}
}
reader.close();
}
catch (IOException err) {
err.printStackTrace();
fail("read file failed: " + err);
}
for(int row = 0; row < DIM_X; row++)
assertTrue("testH5export_regdataset: <"+row+">"+dset_indata[row], dset_indata[row]==dset_data_expect[row]);
}
@Test
public void testH5export_attrdataset() {
int[] dset_data_expect = {66, 69, 72, 75, 78, 81, 96, 99, 102, 105, 108,
111, 126, 129, 132, 135, 138, 141, 156, 159, 162, 165, 168, 171,
186, 189, 192, 195, 198, 201, 216, 219, 222, 225, 228, 231,
207, 66, 252, 48, 84, 96, 12, 14, 213, 99};
int[] dset_indata = new int[DIM_BLKS+DIM_PNTS];
String dsetName = "/Dataset1";
String objName = "Attribute1";
_openH5File(H5_AREG_FILE, dsetName);
try {
H5.H5export_attribute(EXPORT_AREG_FILE, H5did, objName, 99);
}
catch (HDF5LibraryException err) {
err.printStackTrace();
fail("H5export_attribute failed: " + err);
}
File file = new File(EXPORT_AREG_FILE);
try {
Reader reader = new FileReader(EXPORT_AREG_FILE);
StreamTokenizer streamTokenizer = new StreamTokenizer(reader);
int indx = 0;
int jndx = 0;
while(streamTokenizer.nextToken() != StreamTokenizer.TT_EOF){
if(streamTokenizer.ttype == StreamTokenizer.TT_NUMBER) {
dset_indata[indx] = (int)streamTokenizer.nval;
indx++;
}
}
reader.close();
}
catch (IOException err) {
err.printStackTrace();
fail("read file failed: " + err);
}
for(int row = 0; row < DIM_X; row++)
assertTrue("testH5export_attrdataset: <"+row+">"+dset_indata[row], dset_indata[row]==dset_data_expect[row]);
}
}