Search in sources :

Example 16 with HObject

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

the class SimDataReader method getNextDataAtCurrentTimeChombo.

private void getNextDataAtCurrentTimeChombo(double[][] returnValues) throws Exception {
    if (zipFilenNames == null || zipFilenNames[masterTimeIndex] == null) {
        return;
    }
    if (currentZipFile == null || !currentZipFileName.equals(zipFilenNames[masterTimeIndex])) {
        close();
        currentZipFile = new ZipFile(zipFilenNames[masterTimeIndex]);
        currentZipFileName = zipFilenNames[masterTimeIndex];
    }
    File tempFile = null;
    FileFormat solFile = null;
    try {
        tempFile = DataSet.createTempHdf5File(currentZipFile, simDataFileNames[masterTimeIndex]);
        FileFormat fileFormat = FileFormat.getFileFormat(FileFormat.FILE_TYPE_HDF5);
        solFile = fileFormat.createInstance(tempFile.getAbsolutePath(), FileFormat.READ);
        solFile.open();
        for (int k = 0; k < varNames.length; ++k) {
            try {
                boolean bExtrapolatedValue = false;
                String varName = varNames[k];
                if (varName.endsWith(InsideVariable.INSIDE_VARIABLE_SUFFIX)) {
                    bExtrapolatedValue = true;
                    varName = varName.substring(0, varName.lastIndexOf(InsideVariable.INSIDE_VARIABLE_SUFFIX));
                } else if (varName.endsWith(OutsideVariable.OUTSIDE_VARIABLE_SUFFIX)) {
                    bExtrapolatedValue = true;
                    varName = varName.substring(0, varName.lastIndexOf(OutsideVariable.OUTSIDE_VARIABLE_SUFFIX));
                }
                double[] sol = null;
                if (bExtrapolatedValue) {
                    sol = DataSet.readChomboExtrapolatedValues(varName, solFile);
                } else {
                    String varPath = Hdf5Utils.getVarSolutionPath(varNames[k]);
                    HObject solObj = FileFormat.findObject(solFile, varPath);
                    if (solObj instanceof Dataset) {
                        Dataset dataset = (Dataset) solObj;
                        sol = (double[]) dataset.read();
                    }
                }
                if (sol != null) {
                    for (int l = 0; l < varIndexes[k].length; ++l) {
                        int idx = varIndexes[k][l];
                        double val = sol[idx];
                        returnValues[k][l] = val;
                    }
                }
            } catch (Exception e) {
                e.printStackTrace(System.out);
                throw new DataAccessException(e.getMessage(), e);
            }
        }
    } finally {
        try {
            if (solFile != null) {
                solFile.close();
            }
            if (tempFile != null) {
                if (!tempFile.delete()) {
                    System.err.println("couldn't delete temp file " + tempFile.getAbsolutePath());
                }
            }
        } catch (Exception e) {
        // ignore
        }
    }
    ++masterTimeIndex;
    if (masterTimeIndex >= times.length) {
        close();
    }
}
Also used : HObject(ncsa.hdf.object.HObject) ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) Dataset(ncsa.hdf.object.Dataset) FileFormat(ncsa.hdf.object.FileFormat) ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) File(java.io.File) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) DataAccessException(org.vcell.util.DataAccessException)

Example 17 with HObject

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

the class SimulationDataSpatialHdf5 method retrieveSimDataSet.

public SimDataSet retrieveSimDataSet(double time, String varName) throws Exception {
    File tempFile = getTempSimHdf5File(time);
    FileFormat fileFormat = FileFormat.getFileFormat(FileFormat.FILE_TYPE_HDF5);
    FileFormat solFile = fileFormat.createInstance(tempFile.getAbsolutePath(), FileFormat.READ);
    solFile.open();
    DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) solFile.getRootNode();
    Group rootGroup = (Group) rootNode.getUserObject();
    Group solGroup = (Group) rootGroup.getMemberList().get(0);
    SimDataSet simDataSet = new SimDataSet();
    List<HObject> memberList = solGroup.getMemberList();
    for (HObject member : memberList) {
        if (!(member instanceof Dataset)) {
            continue;
        }
        Dataset dataset = (Dataset) member;
        String dsname = dataset.getName();
        if (!dsname.equals(varName)) {
            continue;
        }
        simDataSet.solValues = (double[]) dataset.read();
        List<Attribute> attrList = dataset.getMetadata();
        for (Attribute attr : attrList) {
            String attrName = attr.getName();
            Object val = attr.getValue();
            double dval = 0;
            if (val instanceof double[]) {
                dval = ((double[]) val)[0];
            }
            if (attrName.equals(SOLUTION_DATASET_ATTR_MAX_ERROR)) {
                simDataSet.maxError = dval;
            } else if (attrName.equals(SOLUTION_DATASET_ATTR_MEAN)) {
                simDataSet.mean = dval;
            } else if (attrName.equals(SOLUTION_DATASET_ATTR_RELATIVE_L2ERROR)) {
                simDataSet.l2Error = dval;
            } else if (attrName.equals(SOLUTION_DATASET_ATTR_SUM_VOLFRAC)) {
                simDataSet.sumVolFrac = dval;
            }
        }
        break;
    }
    return simDataSet;
}
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) FileFormat(ncsa.hdf.object.FileFormat) HObject(ncsa.hdf.object.HObject) ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) File(java.io.File)

Example 18 with HObject

use of ncsa.hdf.object.HObject 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)

Aggregations

HObject (ncsa.hdf.object.HObject)18 Dataset (ncsa.hdf.object.Dataset)13 Group (ncsa.hdf.object.Group)13 FileFormat (ncsa.hdf.object.FileFormat)11 IOException (java.io.IOException)10 Attribute (ncsa.hdf.object.Attribute)10 File (java.io.File)7 FileNotFoundException (java.io.FileNotFoundException)7 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)7 ZipFile (org.apache.commons.compress.archivers.zip.ZipFile)5 ArrayList (java.util.ArrayList)4 H5ScalarDS (ncsa.hdf.object.h5.H5ScalarDS)4 DataAccessException (org.vcell.util.DataAccessException)4 MBSDataGroup (cbit.vcell.solvers.CartesianMeshMovingBoundary.MBSDataGroup)3 MSBDataAttribute (cbit.vcell.solvers.CartesianMeshMovingBoundary.MSBDataAttribute)3 Vector (java.util.Vector)3 H5CompoundDS (ncsa.hdf.object.h5.H5CompoundDS)3 ExpressionException (cbit.vcell.parser.ExpressionException)2 ODESimData (cbit.vcell.solver.ode.ODESimData)2 ODESolverResultSet (cbit.vcell.solver.ode.ODESolverResultSet)2