Search in sources :

Example 51 with ODESolverResultSet

use of cbit.vcell.solver.ode.ODESolverResultSet in project vcell by virtualcell.

the class ODEDataInterfaceImpl method extractColumnMin.

@Override
public double[] extractColumnMin(String columnName) throws ExpressionException, ObjectNotFoundException {
    FileFormat hdf5FileFormat = null;
    File to = null;
    try {
        ODESolverResultSet osrs = getOdeSolverResultSet();
        if (osrs instanceof ODESimData) {
            byte[] hdf5FileBytes = ((ODESimData) getOdeSolverResultSet()).getHdf5FileBytes();
            if (hdf5FileBytes != null) {
                to = File.createTempFile("odeStats_" + simulationModelInfo.getSimulationName(), ".hdf5");
                Files.write(hdf5FileBytes, to);
                FileFormat fileFormat = FileFormat.getFileFormat(FileFormat.FILE_TYPE_HDF5);
                if (fileFormat == null) {
                    throw new Exception("Cannot find HDF5 FileFormat.");
                }
                // open the file with read-only access
                hdf5FileFormat = fileFormat.createInstance(to.getAbsolutePath(), FileFormat.READ);
                // open the file and retrieve the file structure
                hdf5FileFormat.open();
                Group root = (Group) ((javax.swing.tree.DefaultMutableTreeNode) hdf5FileFormat.getRootNode()).getUserObject();
                List<HObject> postProcessMembers = ((Group) root).getMemberList();
                for (HObject nextHObject : postProcessMembers) {
                    System.out.println(nextHObject.getName() + "   " + nextHObject.getClass().getName());
                    H5ScalarDS h5ScalarDS = (H5ScalarDS) nextHObject;
                    h5ScalarDS.init();
                    try {
                        long[] dims = h5ScalarDS.getDims();
                        System.out.println("---" + nextHObject.getName() + " " + nextHObject.getClass().getName() + " Dimensions=" + Arrays.toString(dims));
                        Object obj = h5ScalarDS.read();
                        if (dims.length == 2) {
                            double[] columns = new double[(int) dims[1]];
                            for (int row = 0; row < dims[0]; row++) {
                                System.arraycopy(obj, row * columns.length, columns, 0, columns.length);
                                System.out.println(Arrays.toString(columns));
                            }
                            return null;
                        // return columns;
                        } else {
                            return null;
                        }
                    } catch (Exception e) {
                        return null;
                    }
                }
            }
        }
    } catch (Exception e) {
    } finally {
        if (hdf5FileFormat != null) {
            try {
                hdf5FileFormat.close();
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
        if (to != null) {
            try {
                to.delete();
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
    }
    return null;
}
Also used : Group(ncsa.hdf.object.Group) HObject(ncsa.hdf.object.HObject) ODESimData(cbit.vcell.solver.ode.ODESimData) H5ScalarDS(ncsa.hdf.object.h5.H5ScalarDS) FileFormat(ncsa.hdf.object.FileFormat) ExpressionException(cbit.vcell.parser.ExpressionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet) HObject(ncsa.hdf.object.HObject) File(java.io.File)

Aggregations

ODESolverResultSet (cbit.vcell.solver.ode.ODESolverResultSet)51 ODESolverResultSetColumnDescription (cbit.vcell.math.ODESolverResultSetColumnDescription)18 FunctionColumnDescription (cbit.vcell.math.FunctionColumnDescription)11 Expression (cbit.vcell.parser.Expression)11 Simulation (cbit.vcell.solver.Simulation)11 IOException (java.io.IOException)11 File (java.io.File)10 SimulationTask (cbit.vcell.messaging.server.SimulationTask)9 DataSource (cbit.vcell.modelopt.DataSource)9 ExpressionException (cbit.vcell.parser.ExpressionException)9 ReferenceData (cbit.vcell.opt.ReferenceData)8 BioModel (cbit.vcell.biomodel.BioModel)7 SolverException (cbit.vcell.solver.SolverException)7 SBMLImportException (org.vcell.sbml.vcell.SBMLImportException)7 SimulationJob (cbit.vcell.solver.SimulationJob)6 SimulationSymbolTable (cbit.vcell.solver.SimulationSymbolTable)6 Executable (org.vcell.util.exe.Executable)6 SbmlException (org.vcell.sbml.SbmlException)5 VCLogger (cbit.util.xml.VCLogger)4 MathDescription (cbit.vcell.math.MathDescription)4