diff --git a/build.xml b/build.xml index 4ff03935..9f43b3ce 100644 --- a/build.xml +++ b/build.xml @@ -831,11 +831,11 @@ - + (Short.MAX_VALUE * 2) + 1) - throw new NumberFormatException("Value out of range. Value:\"" + newValue + "\""); + if (intValue > (Short.MAX_VALUE * 2) + 1) + throw new NumberFormatException("Value out of range. Value:\"" + newValue + + "\""); + } + else { + Short.parseShort((String)newValue); + } } else { - Short.parseShort((String)newValue); + /* Floating-point type */ + Float.parseFloat((String)newValue); } break; diff --git a/src/org.hdfgroup.hdfview/hdf/view/dialog/NewCompoundAttributeDialog.java b/src/org.hdfgroup.hdfview/hdf/view/dialog/NewCompoundAttributeDialog.java index d08d1577..87ab28c3 100644 --- a/src/org.hdfgroup.hdfview/hdf/view/dialog/NewCompoundAttributeDialog.java +++ b/src/org.hdfgroup.hdfview/hdf/view/dialog/NewCompoundAttributeDialog.java @@ -78,11 +78,13 @@ public class NewCompoundAttributeDialog extends NewDataObjectDialog { "unsigned short (16-bit)", // 4 "unsigned int (32-bit)", // 5 "long (64-bit)", // 6 - "float", // 7 - "double", // 8 + "float (32-bit)", // 7 + "double (64-bit)", // 8 "string", // 9 "enum", // 10 - "unsigned long (64-bit)" // 11 + "unsigned long (64-bit)", // 11 + "float16 (16-bit)", // 12 + "long double (128-bit)" // 13 }; private Combo nFieldBox, templateChoice; @@ -465,6 +467,14 @@ else if (DATATYPE_NAMES[11].equals(typeName)) { type = fileFormat.createDatatype(Datatype.CLASS_INTEGER, 8, Datatype.NATIVE, Datatype.SIGN_NONE); } + else if (DATATYPE_NAMES[12].equals(typeName)) { + type = + fileFormat.createDatatype(Datatype.CLASS_FLOAT, 2, Datatype.NATIVE, Datatype.NATIVE); + } + else if (DATATYPE_NAMES[13].equals(typeName)) { + type = + fileFormat.createDatatype(Datatype.CLASS_FLOAT, 16, Datatype.NATIVE, Datatype.NATIVE); + } else { throw new IllegalArgumentException("Invalid data type."); } diff --git a/src/org.hdfgroup.hdfview/hdf/view/dialog/NewCompoundDatasetDialog.java b/src/org.hdfgroup.hdfview/hdf/view/dialog/NewCompoundDatasetDialog.java index 05f16a35..d2f40d8f 100644 --- a/src/org.hdfgroup.hdfview/hdf/view/dialog/NewCompoundDatasetDialog.java +++ b/src/org.hdfgroup.hdfview/hdf/view/dialog/NewCompoundDatasetDialog.java @@ -78,11 +78,13 @@ public class NewCompoundDatasetDialog extends NewDataObjectDialog { "unsigned short (16-bit)", // 4 "unsigned int (32-bit)", // 5 "long (64-bit)", // 6 - "float", // 7 - "double", // 8 + "float (32-bit)", // 7 + "double (64-bit)", // 8 "string", // 9 "enum", // 10 - "unsigned long (64-bit)" // 11 + "unsigned long (64-bit)", // 11 + "float16 (16-bit)", // 12 + "long double (128-bit)" // 13 }; private Combo parentChoice, nFieldBox, templateChoice; @@ -808,59 +810,81 @@ private HObject createCompoundDS() throws Exception String typeName = (String)table.getItem(i).getData("MemberType"); log.trace("createCompoundDS type[{}] name = {}", i, typeName); Datatype type = null; - if (DATATYPE_NAMES[0].equals(typeName)) { - type = fileFormat.createDatatype(Datatype.CLASS_INTEGER, 1, Datatype.NATIVE, Datatype.NATIVE); - } - else if (DATATYPE_NAMES[1].equals(typeName)) { - type = fileFormat.createDatatype(Datatype.CLASS_INTEGER, 2, Datatype.NATIVE, Datatype.NATIVE); - } - else if (DATATYPE_NAMES[2].equals(typeName)) { - type = fileFormat.createDatatype(Datatype.CLASS_INTEGER, 4, Datatype.NATIVE, Datatype.NATIVE); - } - else if (DATATYPE_NAMES[3].equals(typeName)) { - type = - fileFormat.createDatatype(Datatype.CLASS_INTEGER, 1, Datatype.NATIVE, Datatype.SIGN_NONE); - } - else if (DATATYPE_NAMES[4].equals(typeName)) { - type = - fileFormat.createDatatype(Datatype.CLASS_INTEGER, 2, Datatype.NATIVE, Datatype.SIGN_NONE); - } - else if (DATATYPE_NAMES[5].equals(typeName)) { - type = - fileFormat.createDatatype(Datatype.CLASS_INTEGER, 4, Datatype.NATIVE, Datatype.SIGN_NONE); - } - else if (DATATYPE_NAMES[6].equals(typeName)) { - type = fileFormat.createDatatype(Datatype.CLASS_INTEGER, 8, Datatype.NATIVE, Datatype.NATIVE); - } - else if (DATATYPE_NAMES[7].equals(typeName)) { - type = fileFormat.createDatatype(Datatype.CLASS_FLOAT, 4, Datatype.NATIVE, Datatype.NATIVE); - } - else if (DATATYPE_NAMES[8].equals(typeName)) { - type = fileFormat.createDatatype(Datatype.CLASS_FLOAT, 8, Datatype.NATIVE, Datatype.NATIVE); - } - else if (DATATYPE_NAMES[9].equals(typeName)) { - type = - fileFormat.createDatatype(Datatype.CLASS_STRING, order, Datatype.NATIVE, Datatype.NATIVE); - } - else if (DATATYPE_NAMES[10].equals(typeName)) { // enum - type = fileFormat.createDatatype(Datatype.CLASS_ENUM, 4, Datatype.NATIVE, Datatype.NATIVE); - if ((orderStr == null) || (orderStr.length() < 1) || orderStr.endsWith("...")) { - shell.getDisplay().beep(); - Tools.showError(shell, "Create", "Invalid member values: " + orderStr); - return null; + try { + if (DATATYPE_NAMES[0].equals(typeName)) { + type = fileFormat.createDatatype(Datatype.CLASS_INTEGER, 1, Datatype.NATIVE, + Datatype.NATIVE); + } + else if (DATATYPE_NAMES[1].equals(typeName)) { + type = fileFormat.createDatatype(Datatype.CLASS_INTEGER, 2, Datatype.NATIVE, + Datatype.NATIVE); + } + else if (DATATYPE_NAMES[2].equals(typeName)) { + type = fileFormat.createDatatype(Datatype.CLASS_INTEGER, 4, Datatype.NATIVE, + Datatype.NATIVE); + } + else if (DATATYPE_NAMES[3].equals(typeName)) { + type = fileFormat.createDatatype(Datatype.CLASS_INTEGER, 1, Datatype.NATIVE, + Datatype.SIGN_NONE); + } + else if (DATATYPE_NAMES[4].equals(typeName)) { + type = fileFormat.createDatatype(Datatype.CLASS_INTEGER, 2, Datatype.NATIVE, + Datatype.SIGN_NONE); + } + else if (DATATYPE_NAMES[5].equals(typeName)) { + type = fileFormat.createDatatype(Datatype.CLASS_INTEGER, 4, Datatype.NATIVE, + Datatype.SIGN_NONE); + } + else if (DATATYPE_NAMES[6].equals(typeName)) { + type = fileFormat.createDatatype(Datatype.CLASS_INTEGER, 8, Datatype.NATIVE, + Datatype.NATIVE); + } + else if (DATATYPE_NAMES[7].equals(typeName)) { + type = + fileFormat.createDatatype(Datatype.CLASS_FLOAT, 4, Datatype.NATIVE, Datatype.NATIVE); + } + else if (DATATYPE_NAMES[8].equals(typeName)) { + type = + fileFormat.createDatatype(Datatype.CLASS_FLOAT, 8, Datatype.NATIVE, Datatype.NATIVE); + } + else if (DATATYPE_NAMES[9].equals(typeName)) { + type = fileFormat.createDatatype(Datatype.CLASS_STRING, order, Datatype.NATIVE, + Datatype.NATIVE); + } + else if (DATATYPE_NAMES[10].equals(typeName)) { // enum + type = + fileFormat.createDatatype(Datatype.CLASS_ENUM, 4, Datatype.NATIVE, Datatype.NATIVE); + if ((orderStr == null) || (orderStr.length() < 1) || orderStr.endsWith("...")) { + shell.getDisplay().beep(); + Tools.showError(shell, "Create", "Invalid member values: " + orderStr); + return null; + } + else { + type.setEnumMembers(orderStr); + } + } + else if (DATATYPE_NAMES[11].equals(typeName)) { + type = fileFormat.createDatatype(Datatype.CLASS_INTEGER, 8, Datatype.NATIVE, + Datatype.SIGN_NONE); + } + else if (DATATYPE_NAMES[12].equals(typeName)) { + type = + fileFormat.createDatatype(Datatype.CLASS_FLOAT, 2, Datatype.NATIVE, Datatype.NATIVE); + } + else if (DATATYPE_NAMES[13].equals(typeName)) { + type = + fileFormat.createDatatype(Datatype.CLASS_FLOAT, 16, Datatype.NATIVE, Datatype.NATIVE); } else { - type.setEnumMembers(orderStr); + throw new IllegalArgumentException("Invalid data type."); } + mDatatypes[i] = type; } - else if (DATATYPE_NAMES[11].equals(typeName)) { - type = - fileFormat.createDatatype(Datatype.CLASS_INTEGER, 8, Datatype.NATIVE, Datatype.SIGN_NONE); - } - else { - throw new IllegalArgumentException("Invalid data type."); + catch (Exception ex) { + Tools.showError(shell, "Create", ex.getMessage()); + log.debug("createAttribute(): ", ex); + return null; } - mDatatypes[i] = type; } // (int i=0; i 0 && strValue.length() > count) + // truncate the extra characters + // strValue = strValue.substring(0, count); + sb.append(strValue); + + for (int i = 1; i < count; i++) { + sb.append(delimiter); + value = Array.get(theData, i); + + if (value == null) + strValue = "null"; + else + strValue = Float.toString(Float.float16ToFloat((short)value)); + + if (count > 0 && strValue.length() > count) + // truncate the extra characters + strValue = strValue.substring(0, count); + sb.append(strValue); + } + } else if (theType.isUnsigned()) { String cname = valClass.getName(); char dname = cname.charAt(cname.lastIndexOf('[') + 1); diff --git a/src/org.hdfgroup.object/hdf/object/h5/H5Datatype.java b/src/org.hdfgroup.object/hdf/object/h5/H5Datatype.java index 96bb7c3b..42255ad2 100644 --- a/src/org.hdfgroup.object/hdf/object/h5/H5Datatype.java +++ b/src/org.hdfgroup.object/hdf/object/h5/H5Datatype.java @@ -1420,9 +1420,11 @@ else if (datatypeOrder == Datatype.ORDER_LE) { try { if (datatypeSize > 8) tid = H5.H5Tcopy(HDF5Constants.H5T_NATIVE_LDOUBLE); + else if (datatypeSize == 8) + tid = H5.H5Tcopy(HDF5Constants.H5T_NATIVE_DOUBLE); else - tid = H5.H5Tcopy((datatypeSize == 8) ? HDF5Constants.H5T_NATIVE_DOUBLE - : HDF5Constants.H5T_NATIVE_FLOAT); + tid = H5.H5Tcopy((datatypeSize == 4) ? HDF5Constants.H5T_NATIVE_FLOAT + : HDF5Constants.H5T_NATIVE_FLOAT16); if (datatypeOrder == Datatype.ORDER_BE) { H5.H5Tset_order(tid, HDF5Constants.H5T_ORDER_BE); @@ -1780,6 +1782,9 @@ else if (typeClass == HDF5Constants.H5T_FLOAT) { typeSize = H5.H5Tget_size(HDF5Constants.H5T_NATIVE_FLOAT); switch ((int)typeSize) { + case 2: + data = new short[numPoints]; + break; case 4: data = new float[numPoints]; break; diff --git a/src/org.hdfgroup.object/hdf/object/h5/H5ScalarDS.java b/src/org.hdfgroup.object/hdf/object/h5/H5ScalarDS.java index a900cc3b..66b2ea28 100644 --- a/src/org.hdfgroup.object/hdf/object/h5/H5ScalarDS.java +++ b/src/org.hdfgroup.object/hdf/object/h5/H5ScalarDS.java @@ -1052,7 +1052,7 @@ else if (dsDatatype.isArray() && dsDatatype.getDatatypeBase().isFloat() && } else if (dsDatatype.isRef() && (theData instanceof byte[])) { log.trace( - "AttributeCommonIO():read ioType isRef: converting byte array to List of bytes"); + "scalarDatasetCommonIO():read ioType isRef: converting byte array to List of bytes"); ArrayList theListData = new ArrayList<>((int)totalSelectedSpacePoints); for (int m = 0; m < (int)totalSelectedSpacePoints; m++) { byte[] curBytes = new byte[(int)dsDatatype.getDatatypeSize()]; @@ -1062,7 +1062,7 @@ else if (dsDatatype.isRef() && (theData instanceof byte[])) { theListData.add(curBytes); } catch (Exception err) { - log.trace("AttributeCommonIO(): arraycopy failure: ", err); + log.trace("scalarDatasetCommonIO(): arraycopy failure: ", err); } } theData = theListData; @@ -2386,8 +2386,10 @@ else if (datatypeSize == 8) data = valStr.getBytes(); else if (datatypeSize == 8) data = HDFNativeData.doubleToByte(valDbl); - else + else if (datatypeSize == 4) data = HDFNativeData.floatToByte((float)valDbl); + else + data = HDFNativeData.shortToByte((short)Float.floatToFloat16((float)valDbl)); break; case Datatype.CLASS_STRING: log.trace("parseFillValue(): class CLASS_STRING"); diff --git a/test/org.hdfgroup.hdfview.test/uitest/TestAll.java b/test/org.hdfgroup.hdfview.test/uitest/TestAll.java index 864c36ec..d7221617 100644 --- a/test/org.hdfgroup.hdfview.test/uitest/TestAll.java +++ b/test/org.hdfgroup.hdfview.test/uitest/TestAll.java @@ -9,7 +9,7 @@ TestHDFViewAttributes.class, TestHDFViewImageConversion.class, TestTreeViewFiles.class, TestTreeViewFilters.class, TestHDFViewIntConversions.class, TestTreeViewNewMenu.class, TestTreeViewExport.class, TestHDFViewTAttr2.class, TestTreeViewNewVLDatatypes.class, - TestHDFViewRefs.class}) + TestHDFViewRefs.class, TestHDFViewFloat16.class}) public class TestAll { } diff --git a/test/org.hdfgroup.hdfview.test/uitest/TestHDFViewFloat16.java b/test/org.hdfgroup.hdfview.test/uitest/TestHDFViewFloat16.java new file mode 100644 index 00000000..10ad8a63 --- /dev/null +++ b/test/org.hdfgroup.hdfview.test/uitest/TestHDFViewFloat16.java @@ -0,0 +1,346 @@ +package uitest; + +import static org.junit.Assert.fail; + +import java.io.File; + +import org.junit.Test; + +import org.eclipse.swtbot.nebula.nattable.finder.widgets.SWTBotNatTable; +import org.eclipse.swtbot.swt.finder.waits.Conditions; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree; + +import uitest.AbstractWindowTest.DataRetrieverFactory.TableDataRetriever; + +/* + * Tests the ability of HDFView to display integer values as Hexadecimal + * or Binary values. + * + * Note: Since the conversion of data values in the table to Hexadecimal + * or Binary is simply a display conversion, the underlying data doesn't + * change and calling something like table.getCellDataValueByPosition() + * will not return the converted value. The displayed text values of + * individual cells in the table also cannot be conveniently retrieved, + * so as a workaround, the text field above the table is checked for + * the correct value. So long as this text field is functioning properly, + * it is guaranteed that we are retrieving the correct converted data + * value. + */ +public class TestHDFViewFloat16 extends AbstractWindowTest { + @Test + public void checkHDF5DS16BITS() + { + String[][] expectedData = { + {"16.0", "0.5", "1.0", "1.5", "2.0", "2.5", "3.0", "3.5", "4.0", "4.5", "5.0", "5.5", "6.0", + "6.5", "7.0", "7.5"}, + {"15.0", "0.5625", "1.0625", "1.5625", "2.0625", "2.5625", "3.0625", "3.5625", "4.0625", "4.5625", + "5.0625", "5.5625", "6.0625", "6.5625", "7.0625", "7.5625"}, + {"14.0", "0.625", "1.125", "1.625", "2.125", "2.625", "3.125", "3.625", "4.125", "4.625", "5.125", + "5.625", "6.125", "6.625", "7.125", "7.625"}, + {"13.0", "0.6875", "1.1875", "1.6875", "2.1875", "2.6875", "3.1875", "3.6875", "4.1875", "4.6875", + "5.1875", "5.6875", "6.1875", "6.6875", "7.1875", "7.6875"}, + {"12.0", "0.75", "1.25", "1.75", "2.25", "2.75", "3.25", "3.75", "4.25", "4.75", "5.25", "5.75", + "6.25", "6.75", "7.25", "7.75"}, + {"11.0", "0.8125", "1.3125", "1.8125", "2.3125", "2.8125", "3.3125", "3.8125", "4.3125", "4.8125", + "5.3125", "5.8125", "6.3125", "6.8125", "7.3125", "7.8125"}, + {"10.0", "0.875", "1.375", "1.875", "2.375", "2.875", "3.375", "3.875", "4.375", "4.875", "5.375", + "5.875", "6.375", "6.875", "7.375", "7.875"}, + {"9.0", "0.9375", "1.4375", "1.9375", "2.4375", "2.9375", "3.4375", "3.9375", "4.4375", "4.9375", + "5.4375", "5.9375", "6.4375", "6.9375", "7.4375", "7.9375"}}; + String[][] expectedDataSci = { + {"1.6E1", "5.0E-1", "1.0E0", "1.5E0", "2.0E0", "2.5E0", "3.0E0", "3.5E0", "4.0E0", "4.5E0", + "5.0E0", "5.5E0", "6.0E0", "6.5E0", "7.0E0", "7.5E0"}, + {"1.5E1", "5.625E-1", "1.0625E0", "1.5625E0", "2.0625E0", "2.5625E0", "3.0625E0", "3.5625E0", + "4.0625E0", "4.5625E0", "5.0625E0", "5.5625E0", "6.0625E0", "6.5625E0", "7.0625E0", "7.5625E0"}, + {"1.4E1", "6.25E-1", "1.125E0", "1.625E0", "2.125E0", "2.625E0", "3.125E0", "3.625E0", "4.125E0", + "4.625E0", "5.125E0", "5.625E0", "6.125E0", "6.625E0", "7.125E0", "7.625E0"}, + {"1.3E1", "6.875E-1", "1.1875E0", "1.6875E0", "2.1875E0", "2.6875E0", "3.1875E0", "3.6875E0", + "4.1875E0", "4.6875E0", "5.1875E0", "5.6875E0", "6.1875E0", "6.6875E0", "7.1875E0", "7.6875E0"}, + {"1.2E1", "7.5E-1", "1.25E0", "1.75E0", "2.25E0", "2.75E0", "3.25E0", "3.75E0", "4.25E0", + "4.75E0", "5.25E0", "5.75E0", "6.25E0", "6.75E0", "7.25E0", "7.75E0"}, + {"1.1E1", "8.125E-1", "1.3125E0", "1.8125E0", "2.3125E0", "2.8125E0", "3.3125E0", "3.8125E0", + "4.3125E0", "4.8125E0", "5.3125E0", "5.8125E0", "6.3125E0", "6.8125E0", "7.3125E0", "7.8125E0"}, + {"1.0E1", "8.75E-1", "1.375E0", "1.875E0", "2.375E0", "2.875E0", "3.375E0", "3.875E0", "4.375E0", + "4.875E0", "5.375E0", "5.875E0", "6.375E0", "6.875E0", "7.375E0", "7.875E0"}, + {"9.0E0", "9.375E-1", "1.4375E0", "1.9375E0", "2.4375E0", "2.9375E0", "3.4375E0", "3.9375E0", + "4.4375E0", "4.9375E0", "5.4375E0", "5.9375E0", "6.4375E0", "6.9375E0", "7.4375E0", "7.9375E0"}}; + SWTBotShell tableShell = null; + final String filename = "tfloat16.h5"; + final String datasetName = "/DS16BITS"; + File hdf_file = openFile(filename, FILE_MODE.READ_ONLY); + + try { + SWTBotTree filetree = bot.tree(); + + checkFileTree(filetree, "checkHDF5DS16BITS()", 4, filename); + + // Open dataset 'DS08BITS' + tableShell = openTreeviewObject(filetree, filename, datasetName); + final SWTBotNatTable dataTable = getNatTable(tableShell); + + TableDataRetriever retriever = + DataRetrieverFactory.getTableDataRetriever(dataTable, "checkHDF5DS16BITS()", false); + + retriever.testAllTableLocations(expectedData); + + tableShell.bot().menu().menu("Data Display").menu("Show Scientific Notation").click(); + retriever.testAllTableLocations(expectedDataSci); + } + catch (Exception ex) { + ex.printStackTrace(); + fail(ex.getMessage()); + } + catch (AssertionError ae) { + ae.printStackTrace(); + fail(ae.getMessage()); + } + finally { + closeShell(tableShell); + + try { + closeFile(hdf_file, false); + } + catch (Exception ex) { + ex.printStackTrace(); + } + } + } + + @Test + public void checkHDF5AttrDS16BITS() + { + String[][] expectedAttrData = { + {"DS16BITS", "16-bit floating-point", "128", + "16.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0, 6.5, 7.0, 7.5, 15.0, 0.5625, 1.0625, 1.5625, 2.0625, 2.5625, 3.0625, 3.5625, 4.0625, 4.5625, 5.0625, 5.5625, 6.0625, 6.5625, 7.0625, 7.5625, 14.0, 0.625, 1.125, 1.625, 2.125, 2.625, 3.125, 3.625, 4.125, 4.625, 5.125, 5.625, 6.125, 6.625, 7.125, 7.625, 13.0, 0.6875"}}; + String[][] expectedData = { + {"16.0"}, {"0.5"}, {"1.0"}, {"1.5"}, {"2.0"}, {"2.5"}, {"3.0"}, {"3.5"}, + {"4.0"}, {"4.5"}, {"5.0"}, {"5.5"}, {"6.0"}, {"6.5"}, {"7.0"}, {"7.5"}, + {"15.0"}, {"0.5625"}, {"1.0625"}, {"1.5625"}, {"2.0625"}, {"2.5625"}, {"3.0625"}, {"3.5625"}, + {"4.0625"}, {"4.5625"}, {"5.0625"}, {"5.5625"}, {"6.0625"}, {"6.5625"}, {"7.0625"}, {"7.5625"}, + {"14.0"}, {"0.625"}, {"1.125"}, {"1.625"}, {"2.125"}, {"2.625"}, {"3.125"}, {"3.625"}, + {"4.125"}, {"4.625"}, {"5.125"}, {"5.625"}, {"6.125"}, {"6.625"}, {"7.125"}, {"7.625"}, + {"13.0"}, {"0.6875"}, {"1.1875"}, {"1.6875"}, {"2.1875"}, {"2.6875"}, {"3.1875"}, {"3.6875"}, + {"4.1875"}, {"4.6875"}, {"5.1875"}, {"5.6875"}, {"6.1875"}, {"6.6875"}, {"7.1875"}, {"7.6875"}, + {"12.0"}, {"0.75"}, {"1.25"}, {"1.75"}, {"2.25"}, {"2.75"}, {"3.25"}, {"3.75"}, + {"4.25"}, {"4.75"}, {"5.25"}, {"5.75"}, {"6.25"}, {"6.75"}, {"7.25"}, {"7.75"}, + {"11.0"}, {"0.8125"}, {"1.3125"}, {"1.8125"}, {"2.3125"}, {"2.8125"}, {"3.3125"}, {"3.8125"}, + {"4.3125"}, {"4.8125"}, {"5.3125"}, {"5.8125"}, {"6.3125"}, {"6.8125"}, {"7.3125"}, {"7.8125"}, + {"10.0"}, {"0.875"}, {"1.375"}, {"1.875"}, {"2.375"}, {"2.875"}, {"3.375"}, {"3.875"}, + {"4.375"}, {"4.875"}, {"5.375"}, {"5.875"}, {"6.375"}, {"6.875"}, {"7.375"}, {"7.875"}, + {"9.0"}, {"0.9375"}, {"1.4375"}, {"1.9375"}, {"2.4375"}, {"2.9375"}, {"3.4375"}, {"3.9375"}, + {"4.4375"}, {"4.9375"}, {"5.4375"}, {"5.9375"}, {"6.4375"}, {"6.9375"}, {"7.4375"}, {"7.9375"}}; + String[][] expectedDataSci = { + {"1.6E1"}, {"5.0E-1"}, {"1.0E0"}, {"1.5E0"}, {"2.0E0"}, {"2.5E0"}, {"3.0E0"}, + {"3.5E0"}, {"4.0E0"}, {"4.5E0"}, {"5.0E0"}, {"5.5E0"}, {"6.0E0"}, {"6.5E0"}, + {"7.0E0"}, {"7.5E0"}, {"1.5E1"}, {"5.625E-1"}, {"1.0625E0"}, {"1.5625E0"}, {"2.0625E0"}, + {"2.5625E0"}, {"3.0625E0"}, {"3.5625E0"}, {"4.0625E0"}, {"4.5625E0"}, {"5.0625E0"}, {"5.5625E0"}, + {"6.0625E0"}, {"6.5625E0"}, {"7.0625E0"}, {"7.5625E0"}, {"1.4E1"}, {"6.25E-1"}, {"1.125E0"}, + {"1.625E0"}, {"2.125E0"}, {"2.625E0"}, {"3.125E0"}, {"3.625E0"}, {"4.125E0"}, {"4.625E0"}, + {"5.125E0"}, {"5.625E0"}, {"6.125E0"}, {"6.625E0"}, {"7.125E0"}, {"7.625E0"}, {"1.3E1"}, + {"6.875E-1"}, {"1.1875E0"}, {"1.6875E0"}, {"2.1875E0"}, {"2.6875E0"}, {"3.1875E0"}, {"3.6875E0"}, + {"4.1875E0"}, {"4.6875E0"}, {"5.1875E0"}, {"5.6875E0"}, {"6.1875E0"}, {"6.6875E0"}, {"7.1875E0"}, + {"7.6875E0"}, {"1.2E1"}, {"7.5E-1"}, {"1.25E0"}, {"1.75E0"}, {"2.25E0"}, {"2.75E0"}, + {"3.25E0"}, {"3.75E0"}, {"4.25E0"}, {"4.75E0"}, {"5.25E0"}, {"5.75E0"}, {"6.25E0"}, + {"6.75E0"}, {"7.25E0"}, {"7.75E0"}, {"1.1E1"}, {"8.125E-1"}, {"1.3125E0"}, {"1.8125E0"}, + {"2.3125E0"}, {"2.8125E0"}, {"3.3125E0"}, {"3.8125E0"}, {"4.3125E0"}, {"4.8125E0"}, {"5.3125E0"}, + {"5.8125E0"}, {"6.3125E0"}, {"6.8125E0"}, {"7.3125E0"}, {"7.8125E0"}, {"1.0E1"}, {"8.75E-1"}, + {"1.375E0"}, {"1.875E0"}, {"2.375E0"}, {"2.875E0"}, {"3.375E0"}, {"3.875E0"}, {"4.375E0"}, + {"4.875E0"}, {"5.375E0"}, {"5.875E0"}, {"6.375E0"}, {"6.875E0"}, {"7.375E0"}, {"7.875E0"}, + {"9.0E0"}, {"9.375E-1"}, {"1.4375E0"}, {"1.9375E0"}, {"2.4375E0"}, {"2.9375E0"}, {"3.4375E0"}, + {"3.9375E0"}, {"4.4375E0"}, {"4.9375E0"}, {"5.4375E0"}, {"5.9375E0"}, {"6.4375E0"}, {"6.9375E0"}, + {"7.4375E0"}, {"7.9375E0"}}; + SWTBotShell tableShell = null; + String filename = "tfloat16.h5"; + String datasetName = "/DS16BITS"; + String attributeName = "DS16BITS"; + File hdf_file = openFile(filename, FILE_MODE.READ_ONLY); + + try { + SWTBotTree filetree = bot.tree(); + + checkFileTree(filetree, "checkHDF5AttrDS16BITS()", 4, filename); + + // Open dataset Attribute Table + SWTBotTable attrTable = openAttributeTable(filetree, filename, datasetName); + + TableDataRetriever retriever = + DataRetrieverFactory.getTableDataRetriever(attrTable, "checkHDF5AttrDS16BITS()", false); + + retriever.testAllTableLocations(expectedAttrData); + + // Open attribute 1D + tableShell = openAttributeObject(attrTable, attributeName, 0); + SWTBotNatTable dataTable = getNatTable(tableShell); + + retriever = + DataRetrieverFactory.getTableDataRetriever(dataTable, "checkHDF5AttrDS16BITS()", false); + + retriever.testAllTableLocations(expectedData); + + tableShell.bot().menu().menu("Data Display").menu("Show Scientific Notation").click(); + retriever.testAllTableLocations(expectedDataSci); + + tableShell.bot().menu().menu("Table").menu("Close").click(); + bot.waitUntil(Conditions.shellCloses(tableShell)); + } + catch (Exception ex) { + ex.printStackTrace(); + fail(ex.getMessage()); + } + catch (AssertionError ae) { + ae.printStackTrace(); + fail(ae.getMessage()); + } + finally { + closeShell(tableShell); + + try { + closeFile(hdf_file, false); + } + catch (Exception ex) { + ex.printStackTrace(); + } + } + } + + @Test + public void checkHDF5DS16Array() + { + String[][] expectedData = { + {"^\\[16.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0, .*\\]"}}; + String[][] expectedDataSci = { + {"^\\[1.6E1, 5.0E-1, 1.0E0, 1.5E0, 2.0E0, 2.5E0, 3.0E0, 3.5E0, 4.0E0, 4.5E0, .*\\]"}}; + SWTBotShell tableShell = null; + final String filename = "tfloat16.h5"; + final String datasetName = "/DS16BITS_array"; + File hdf_file = openFile(filename, FILE_MODE.READ_ONLY); + + try { + SWTBotTree filetree = bot.tree(); + + checkFileTree(filetree, "checkHDF5DS16Array()", 4, filename); + + // Open dataset 'DS08BITS' + tableShell = openTreeviewObject(filetree, filename, datasetName); + final SWTBotNatTable dataTable = getNatTable(tableShell); + + TableDataRetriever retriever = + DataRetrieverFactory.getTableDataRetriever(dataTable, "checkHDF5DS16Array()", false); + + retriever.testAllTableLocations(expectedData); + + /* + * TODO: not supported yet + */ + /* + * tableShell.bot().menu().menu("Data Display").menu("Show Scientific Notation").click(); + * retriever.testAllTableLocations(expectedDataSci); + */ + } + catch (Exception ex) { + ex.printStackTrace(); + fail(ex.getMessage()); + } + catch (AssertionError ae) { + ae.printStackTrace(); + fail(ae.getMessage()); + } + finally { + closeShell(tableShell); + + try { + closeFile(hdf_file, false); + } + catch (Exception ex) { + ex.printStackTrace(); + } + } + } + + @Test + public void checkHDF5DS16Compound() + { + String[][] expectedData = { + {"16.0", "0.5", "1.0", "1.5", "2.0", "2.5", "3.0", "3.5", "4.0", "4.5", "5.0", "5.5", "6.0", + "6.5", "7.0", "7.5"}, + {"15.0", "0.5625", "1.0625", "1.5625", "2.0625", "2.5625", "3.0625", "3.5625", "4.0625", "4.5625", + "5.0625", "5.5625", "6.0625", "6.5625", "7.0625", "7.5625"}, + {"14.0", "0.625", "1.125", "1.625", "2.125", "2.625", "3.125", "3.625", "4.125", "4.625", "5.125", + "5.625", "6.125", "6.625", "7.125", "7.625"}, + {"13.0", "0.6875", "1.1875", "1.6875", "2.1875", "2.6875", "3.1875", "3.6875", "4.1875", "4.6875", + "5.1875", "5.6875", "6.1875", "6.6875", "7.1875", "7.6875"}, + {"12.0", "0.75", "1.25", "1.75", "2.25", "2.75", "3.25", "3.75", "4.25", "4.75", "5.25", "5.75", + "6.25", "6.75", "7.25", "7.75"}, + {"11.0", "0.8125", "1.3125", "1.8125", "2.3125", "2.8125", "3.3125", "3.8125", "4.3125", "4.8125", + "5.3125", "5.8125", "6.3125", "6.8125", "7.3125", "7.8125"}, + {"10.0", "0.875", "1.375", "1.875", "2.375", "2.875", "3.375", "3.875", "4.375", "4.875", "5.375", + "5.875", "6.375", "6.875", "7.375", "7.875"}, + {"9.0", "0.9375", "1.4375", "1.9375", "2.4375", "2.9375", "3.4375", "3.9375", "4.4375", "4.9375", + "5.4375", "5.9375", "6.4375", "6.9375", "7.4375", "7.9375"}}; + String[][] expectedDataSci = { + {"1.6E1", "5.0E-1", "1.0E0", "1.5E0", "2.0E0", "2.5E0", "3.0E0", "3.5E0", "4.0E0", "4.5E0", + "5.0E0", "5.5E0", "6.0E0", "6.5E0", "7.0E0", "7.5E0"}, + {"1.5E1", "5.625E-1", "1.0625E0", "1.5625E0", "2.0625E0", "2.5625E0", "3.0625E0", "3.5625E0", + "4.0625E0", "4.5625E0", "5.0625E0", "5.5625E0", "6.0625E0", "6.5625E0", "7.0625E0", "7.5625E0"}, + {"1.4E1", "6.25E-1", "1.125E0", "1.625E0", "2.125E0", "2.625E0", "3.125E0", "3.625E0", "4.125E0", + "4.625E0", "5.125E0", "5.625E0", "6.125E0", "6.625E0", "7.125E0", "7.625E0"}, + {"1.3E1", "6.875E-1", "1.1875E0", "1.6875E0", "2.1875E0", "2.6875E0", "3.1875E0", "3.6875E0", + "4.1875E0", "4.6875E0", "5.1875E0", "5.6875E0", "6.1875E0", "6.6875E0", "7.1875E0", "7.6875E0"}, + {"1.2E1", "7.5E-1", "1.25E0", "1.75E0", "2.25E0", "2.75E0", "3.25E0", "3.75E0", "4.25E0", + "4.75E0", "5.25E0", "5.75E0", "6.25E0", "6.75E0", "7.25E0", "7.75E0"}, + {"1.1E1", "8.125E-1", "1.3125E0", "1.8125E0", "2.3125E0", "2.8125E0", "3.3125E0", "3.8125E0", + "4.3125E0", "4.8125E0", "5.3125E0", "5.8125E0", "6.3125E0", "6.8125E0", "7.3125E0", "7.8125E0"}, + {"1.0E1", "8.75E-1", "1.375E0", "1.875E0", "2.375E0", "2.875E0", "3.375E0", "3.875E0", "4.375E0", + "4.875E0", "5.375E0", "5.875E0", "6.375E0", "6.875E0", "7.375E0", "7.875E0"}, + {"9.0E0", "9.375E-1", "1.4375E0", "1.9375E0", "2.4375E0", "2.9375E0", "3.4375E0", "3.9375E0", + "4.4375E0", "4.9375E0", "5.4375E0", "5.9375E0", "6.4375E0", "6.9375E0", "7.4375E0", "7.9375E0"}}; + SWTBotShell tableShell = null; + final String filename = "tfloat16.h5"; + final String datasetName = "/DS16BITS_compound"; + File hdf_file = openFile(filename, FILE_MODE.READ_ONLY); + + try { + SWTBotTree filetree = bot.tree(); + + checkFileTree(filetree, "checkHDF5DS16Compound()", 4, filename); + + // Open dataset 'DS08BITS' + tableShell = openTreeviewObject(filetree, filename, datasetName); + final SWTBotNatTable dataTable = getNatTable(tableShell); + + TableDataRetriever retriever = + DataRetrieverFactory.getTableDataRetriever(dataTable, "checkHDF5DS16Compound()", false); + retriever.setContainerHeaderOffset(2, 0); + + retriever.testAllTableLocations(expectedData); + + /* + * TODO: not supported yet + */ + /* + * tableShell.bot().menu().menu("Data Display").menu("Show Scientific Notation").click(); + * retriever.testAllTableLocations(expectedDataSci); + */ + } + catch (Exception ex) { + ex.printStackTrace(); + fail(ex.getMessage()); + } + catch (AssertionError ae) { + ae.printStackTrace(); + fail(ae.getMessage()); + } + finally { + closeShell(tableShell); + + try { + closeFile(hdf_file, false); + } + catch (Exception ex) { + ex.printStackTrace(); + } + } + } +} diff --git a/test/org.hdfgroup.hdfview.test/uitest/tfloat16.h5 b/test/org.hdfgroup.hdfview.test/uitest/tfloat16.h5 new file mode 100644 index 00000000..a414806c Binary files /dev/null and b/test/org.hdfgroup.hdfview.test/uitest/tfloat16.h5 differ diff --git a/test/org.hdfgroup.object.test/misc/DebugHDF.java b/test/org.hdfgroup.object.test/misc/DebugHDF.java index 44c2697f..061300c1 100644 --- a/test/org.hdfgroup.object.test/misc/DebugHDF.java +++ b/test/org.hdfgroup.object.test/misc/DebugHDF.java @@ -1147,6 +1147,9 @@ private static final void createINF(String fname) throws Exception dtype = testFile.createDatatype(Datatype.CLASS_FLOAT, 8, Datatype.NATIVE, Datatype.NATIVE); testFile.createScalarDS("f64", root, dtype, dims2D, null, null, 0, data2); + // dtype = testFile.createDatatype(Datatype.CLASS_FLOAT, 2, Datatype.NATIVE, Datatype.NATIVE); + // testFile.createScalarDS("f16", root, dtype, dims2D, null, null, 0, data2); + testFile.close(); } @@ -3380,6 +3383,10 @@ private static void createDataset(final String fname) throws Exception dtype = testFile.createDatatype(Datatype.CLASS_FLOAT, 4, Datatype.NATIVE, Datatype.NATIVE); testFile.createScalarDS("3D float", g2, dtype, dims3D, null, null, 0, null); + // create 3D 16-bit (2 bytes) float16 dataset of 20 by 10 by 5 + // dtype = testFile.createDatatype(Datatype.CLASS_FLOAT, 2, Datatype.NATIVE, Datatype.NATIVE); + // testFile.createScalarDS("3D float16", g2, dtype, dims3Dh, null, null, 0, null); + // close file resource testFile.close(); } @@ -3435,6 +3442,11 @@ private static void createStrDataset(final String fname) throws Exception dtype = testFile.createDatatype(Datatype.CLASS_FLOAT, 4, Datatype.NATIVE, Datatype.NATIVE); testFile.createScalarDS("3D 32-bit float 20x10x5", g2, dtype, dims3D, null, null, 0, null); + // Create 3D 16-bit (2 bytes) float dataset of 20 by 10 by 5 + // dtype = testFile.createDatatype(Datatype.CLASS_FLOAT, 2, Datatype.NATIVE, Datatype.NATIVE); + // testFile.createScalarDS("3D 16-bit float16 20x10x5", g2, dtype, dims3Dh, null, null, 0, + // null); + // Create String dataset System.out.println("Just before call for STRINGS"); try {