Search in sources :

Example 11 with Attribute

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

the class SimulationDataSpatialHdf5 method readMeshFile.

public static ChomboMesh readMeshFile(File chomboMeshFile) throws Exception {
    // if (chomboMesh != null)
    // {
    // return;
    // }
    ChomboMesh chomboMesh = new ChomboMesh();
    // File mfile = new File(userDirectory, getMeshFileName());
    if (H5.H5open() < 0) {
        throw new Exception("H5.H5open() failed");
    }
    FileFormat fileFormat = FileFormat.getFileFormat(FileFormat.FILE_TYPE_HDF5);
    if (fileFormat == null) {
        throw new Exception("FileFormat.getFileFormat(FileFormat.FILE_TYPE_HDF5) failed, returned null.");
    }
    FileFormat meshFile = fileFormat.createInstance(chomboMeshFile.getAbsolutePath(), FileFormat.READ);
    meshFile.open();
    DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) meshFile.getRootNode();
    Group rootGroup = (Group) rootNode.getUserObject();
    Group meshGroup = (Group) rootGroup.getMemberList().get(0);
    List<Attribute> meshAttrList = meshGroup.getMetadata();
    for (Attribute attr : meshAttrList) {
        String attrName = attr.getName();
        Object value = attr.getValue();
        if (attrName.equals(MESH_ATTR_DIMENSION)) {
            chomboMesh.dimension = ((int[]) value)[0];
        } else {
            String[] valueStrArray = (String[]) value;
            String value0 = valueStrArray[0];
            StringTokenizer st = new StringTokenizer(value0, "{,} ");
            List<Double> valueList = new ArrayList<Double>();
            while (st.hasMoreTokens()) {
                String token = st.nextToken();
                valueList.add(Double.parseDouble(token));
            }
            if (attrName.equals(MESH_ATTR_DX)) {
                for (int i = 0; i < valueList.size(); ++i) {
                    chomboMesh.dx[i] = valueList.get(i);
                }
            } else if (attrName.equals(MESH_ATTR_EXTENT)) {
                for (int i = 0; i < valueList.size(); ++i) {
                    chomboMesh.extent[i] = valueList.get(i);
                }
            } else if (attrName.equals(MESH_ATTR_NX)) {
                for (int i = 0; i < valueList.size(); ++i) {
                    chomboMesh.nx[i] = valueList.get(i).intValue();
                }
            } else if (attrName.equals(MESH_ATTR_ORIGIN)) {
                for (int i = 0; i < valueList.size(); ++i) {
                    chomboMesh.origin[i] = valueList.get(i);
                }
            }
        }
    }
    List<HObject> memberList = meshGroup.getMemberList();
    for (HObject member : memberList) {
        if (member instanceof Dataset) {
            Dataset dataset = (Dataset) member;
            Vector vectValues = (Vector) dataset.read();
            String name = dataset.getName();
            if (name.equals(BOXES_DATASET)) {
            // not needed right now
            } else if (name.equals(METRICS_DATASET)) {
                H5CompoundDS compoundDataSet = (H5CompoundDS) dataset;
                chomboMesh.metricsColumnNames = compoundDataSet.getMemberNames();
                int c = -1;
                int[] index = (int[]) vectValues.get(++c);
                int[] i = (int[]) vectValues.get(++c);
                int[] j = (int[]) vectValues.get(++c);
                int[] k = null;
                if (chomboMesh.dimension == 3) {
                    k = (int[]) vectValues.get(++c);
                }
                double[] x = (double[]) vectValues.get(++c);
                double[] y = (double[]) vectValues.get(++c);
                double[] z = null;
                if (chomboMesh.dimension == 3) {
                    z = (double[]) vectValues.get(++c);
                }
                double[] normalx = (double[]) vectValues.get(++c);
                double[] normaly = (double[]) vectValues.get(++c);
                double[] normalz = null;
                if (chomboMesh.dimension == 3) {
                    normalz = (double[]) vectValues.get(++c);
                }
                double[] volFrac = (double[]) vectValues.get(++c);
                double[] areaFrac = (double[]) vectValues.get(++c);
                for (int n = 0; n < index.length; ++n) {
                    ChomboMeshMetricsEntry entry = new ChomboMeshMetricsEntry(index[n], i[n], j[n], k == null ? 0 : k[n], x[n], y[n], z == null ? 0 : z[n], normalx[n], normaly[n], normalz == null ? 0 : normalz[n], volFrac[n], areaFrac[n]);
                    chomboMesh.metrics.add(entry);
                }
            } else if (name.equals(SURFACE_DATASET)) {
            // not needed right now
            } else if (name.equals(SLICE_VIEW_DATASET)) {
            // not needed right now
            }
        }
    }
    return chomboMesh;
}
Also used : Group(ncsa.hdf.object.Group) HObject(ncsa.hdf.object.HObject) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Attribute(ncsa.hdf.object.Attribute) Dataset(ncsa.hdf.object.Dataset) ArrayList(java.util.ArrayList) FileFormat(ncsa.hdf.object.FileFormat) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) FileNotFoundException(java.io.FileNotFoundException) StringTokenizer(java.util.StringTokenizer) HObject(ncsa.hdf.object.HObject) H5CompoundDS(ncsa.hdf.object.h5.H5CompoundDS) Vector(java.util.Vector)

Example 12 with Attribute

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

the class SimulationDataSpatialHdf5 method retriveVariableNames.

private void retriveVariableNames() throws Exception {
    // read variables only when I have never read the file since variables don't change
    if (dataSetIdentifierList.size() > 0) {
        return;
    }
    File tempFile = getTempSimHdf5File(0.0);
    FileFormat fileFormat = FileFormat.getFileFormat(FileFormat.FILE_TYPE_HDF5);
    FileFormat meshFile = fileFormat.createInstance(tempFile.getAbsolutePath(), FileFormat.READ);
    meshFile.open();
    DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) meshFile.getRootNode();
    Group rootGroup = (Group) rootNode.getUserObject();
    Group solGroup = (Group) rootGroup.getMemberList().get(0);
    List<Attribute> solAttrList = solGroup.getMetadata();
    String[] varNames = null;
    int[] varTypes = null;
    for (Attribute attr : solAttrList) {
        String attrName = attr.getName();
        Object value = attr.getValue();
        if (attrName.equals(SOLUTION_ATTR_VARIABLES)) {
            varNames = (String[]) value;
        } else if (attrName.equals(SOLUTION_ATTR_VARIABLE_TYPES)) {
            varTypes = (int[]) value;
        }
    }
    for (int i = 0; i < varNames.length; i++) {
        VariableType varType = VariableType.getVariableTypeFromInteger(varTypes[i]);
        Domain domain = Variable.getDomainFromCombinedIdentifier(varNames[i]);
        String varName = Variable.getNameFromCombinedIdentifier(varNames[i]);
        dataSetIdentifierList.add(new DataSetIdentifier(varName, varType, domain));
    }
}
Also used : Group(ncsa.hdf.object.Group) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) VariableType(cbit.vcell.math.VariableType) Attribute(ncsa.hdf.object.Attribute) FileFormat(ncsa.hdf.object.FileFormat) HObject(ncsa.hdf.object.HObject) Domain(cbit.vcell.math.Variable.Domain) ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) File(java.io.File)

Aggregations

Attribute (ncsa.hdf.object.Attribute)12 HObject (ncsa.hdf.object.HObject)11 Group (ncsa.hdf.object.Group)10 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)8 Dataset (ncsa.hdf.object.Dataset)8 FileFormat (ncsa.hdf.object.FileFormat)8 IOException (java.io.IOException)6 FileNotFoundException (java.io.FileNotFoundException)5 File (java.io.File)4 ZipFile (org.apache.commons.compress.archivers.zip.ZipFile)4 MBSDataGroup (cbit.vcell.solvers.CartesianMeshMovingBoundary.MBSDataGroup)3 MSBDataAttribute (cbit.vcell.solvers.CartesianMeshMovingBoundary.MSBDataAttribute)3 VariableType (cbit.vcell.math.VariableType)2 ArrayList (java.util.ArrayList)2 StringTokenizer (java.util.StringTokenizer)2 Vector (java.util.Vector)2 H5CompoundDS (ncsa.hdf.object.h5.H5CompoundDS)2 MathFormatException (cbit.vcell.math.MathFormatException)1 Domain (cbit.vcell.math.Variable.Domain)1 HashMap (java.util.HashMap)1