Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for complex types - basic implemented #348

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from
Draft
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ of HDF5 and HDF4. Previous releases of HDFView that were based on HDF5 1.8,
| 3.3.0 | 1.14.0 | 4.2.16 | HDF5 1.12 (new-style) references, Single-Writer/Multiple-Readers (SWMR) reads, bug fixes |
| 3.3.1 | 1.14.2 | 4.2.16-2 | Fixes a critical HDF4 + HDFView bug |
| 3.3.2 | 1.14.4 | 4.3.0 | Float16 support |
| 3.3.3 | 1.16.0 | 4.4.0 | Complex number support |
| 3.4.0 | 2.0.0 | 4.4.0 | Complex number support |


PREVIOUS RELEASES AND SOURCE CODE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ else if (dtype.isOpaque() || dtype.isBitField())
converter = new BitfieldDataDisplayConverter(dtype);
else if (dtype.isRef())
converter = new RefDataDisplayConverter(dtype);
else if (dtype.isComplex())
converter = new ComplexDataDisplayConverter(dtype);
}
catch (Exception ex) {
log.debug(
Expand Down Expand Up @@ -963,4 +965,141 @@ public Object canonicalToDisplayValue(Object value)
return buffer;
}
}

private static class ComplexDataDisplayConverter extends HDFDisplayConverter {
private static final Logger log = LoggerFactory.getLogger(ComplexDataDisplayConverter.class);

private final HDFDisplayConverter baseTypeConverter;
private final StringBuilder buffer;

ComplexDataDisplayConverter(final Datatype dtype) throws Exception
{
super(dtype);

if (!dtype.isComplex()) {
log.debug("exit: datatype is not a complex type");
throw new Exception("ComplexDataDisplayConverter: datatype is not a complex type");
}

Datatype baseType = dtype.getDatatypeBase();

if (baseType == null) {
log.debug("exit: base datatype is null");
throw new Exception("ComplexDataDisplayConverter: base datatype is null");
}

try {
baseTypeConverter = getDataDisplayConverter(baseType);

/*
* Make base datatype converter inherit the data conversion settings.
*/
baseTypeConverter.setShowAsHex(this.showAsHex);
baseTypeConverter.setShowAsBin(this.showAsBin);
baseTypeConverter.setNumberFormat(this.numberFormat);
baseTypeConverter.setConvertEnum(this.isEnumConverted);
}
catch (Exception ex) {
log.debug("exit: couldn't get DataDisplayConverter for base datatype: ", ex);
throw new Exception(
"ComplexDataDisplayConverter: couldn't get DataDisplayConverter for base datatype: " +
ex.getMessage());
}

buffer = new StringBuilder();
}

@Override
public Object canonicalToDisplayValue(ILayerCell cell, IConfigRegistry configRegistry, Object value)
{
cellRowIdx = cell.getRowIndex();
cellColIdx = cell.getColumnIndex();
log.trace("canonicalToDisplayValue({}): cellRowIdx={} cellRowIdx={}", value, cellRowIdx,
cellRowIdx);
return canonicalToDisplayValue(value);
}

@Override
public Object canonicalToDisplayValue(Object value)
{
log.trace("canonicalToDisplayValue({}): start", value);

if (value instanceof String)
return value;

if (value == null) {
log.debug("canonicalToDisplayValue({}): value is null", value);
return DataFactoryUtils.nullStr;
}

buffer.setLength(0); // clear the old string

/*
* Pass the cell's row and column index down in case there is a CompoundDataDisplayConverter at
* the bottom of the chain.
*/
baseTypeConverter.cellRowIdx = cellRowIdx;
baseTypeConverter.cellColIdx = cellColIdx;

try {
Object obj;
Object convertedValue;
int arrLen = Array.getLength(value);

log.trace("canonicalToDisplayValue({}): array length={}", value, arrLen);

for (int i = 0; i < arrLen; i++) {
if (i > 0)
buffer.append("+");

obj = Array.get(value, i);

convertedValue = baseTypeConverter.canonicalToDisplayValue(obj);

buffer.append(convertedValue);
}

buffer.append("i");
}
catch (Exception ex) {
log.debug("canonicalToDisplayValue({}): failure: ", value, ex);
buffer.setLength(0);
buffer.append(DataFactoryUtils.errStr);
}

return buffer;
}

@Override
public void setNumberFormat(NumberFormat format)
{
super.setNumberFormat(format);

baseTypeConverter.setNumberFormat(format);
}

@Override
public void setShowAsHex(boolean asHex)
{
super.setShowAsHex(asHex);

baseTypeConverter.setShowAsHex(asHex);
}

@Override
public void setShowAsBin(boolean asBin)
{
super.setShowAsBin(asBin);

baseTypeConverter.setShowAsBin(asBin);
}

@Override
public void setConvertEnum(boolean convert)
{
super.setConvertEnum(convert);

baseTypeConverter.setConvertEnum(convert);
}
}
}
Loading
Loading