Search in sources :

Example 1 with DataFormat

use of ncsa.hdf.object.DataFormat in project vcell by virtualcell.

the class VH5Path method walk.

/**
 * find next object in sequence
 * @param hobj previous element in sequence
 * @param steps name of each step
 * @param index current step
 * @return next object path, if present
 * @throws HDF5Exception
 */
private static Object walk(Object hobj, String[] steps, int index) throws Exception {
    final boolean isLastIndex = lastIndex(index, steps);
    final String finding = steps[index];
    Group g = BeanUtils.downcast(Group.class, hobj);
    if (g != null) {
        List<HObject> ml = g.getMemberList();
        for (HObject sub : ml) {
            // String full = sub.getFullName();
            if (finding.equals(sub.getName())) {
                if (isLastIndex) {
                    return sub;
                }
                return walk(sub, steps, index + 1);
            }
        }
    }
    H5CompoundDS cds = BeanUtils.downcast(H5CompoundDS.class, hobj);
    if (cds != null) {
        cds.read();
        String[] mn = cds.getMemberNames();
        for (int i = 0; i < mn.length; i++) {
            if (finding.equals(mn[i])) {
                Object c = cds.read();
                Vector<?> vec = BeanUtils.downcast(Vector.class, c);
                if (vec != null) {
                    VCAssert.assertTrue(i < vec.size(), "Disconnect between H5CompoundDS.getMemberNames( )  and returned Vector");
                    Object child = vec.get(i);
                    if (isLastIndex) {
                        return child;
                    }
                } else {
                    throw new UnsupportedOperationException("Unsupported H5CompoundDS subtype " + className(c));
                }
            }
        }
    }
    if (isLastIndex) {
        DataFormat df = BeanUtils.downcast(DataFormat.class, hobj);
        if (df != null && df.hasAttribute()) {
            try {
                @SuppressWarnings("unchecked") List<Object> meta = df.getMetadata();
                for (Object o : meta) {
                    Attribute a = BeanUtils.downcast(Attribute.class, o);
                    if (a != null) {
                        if (finding.equals(a.getName())) {
                            return a.getValue();
                        }
                    } else {
                        lg.warn(concat(steps, finding) + " fetching metadata unexpected type " + className(o));
                    }
                }
            } catch (Exception e) {
                throw new RuntimeException(concat(steps, finding) + " fetching metadata", e);
            }
        }
    }
    return null;
}
Also used : Group(ncsa.hdf.object.Group) HObject(ncsa.hdf.object.HObject) Attribute(ncsa.hdf.object.Attribute) HDF5Exception(ncsa.hdf.hdf5lib.exceptions.HDF5Exception) DataFormat(ncsa.hdf.object.DataFormat) HObject(ncsa.hdf.object.HObject) H5CompoundDS(ncsa.hdf.object.h5.H5CompoundDS)

Aggregations

HDF5Exception (ncsa.hdf.hdf5lib.exceptions.HDF5Exception)1 Attribute (ncsa.hdf.object.Attribute)1 DataFormat (ncsa.hdf.object.DataFormat)1 Group (ncsa.hdf.object.Group)1 HObject (ncsa.hdf.object.HObject)1 H5CompoundDS (ncsa.hdf.object.h5.H5CompoundDS)1