Search in sources :

Example 41 with ZipFile

use of org.apache.commons.compress.archivers.zip.ZipFile 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 42 with ZipFile

use of org.apache.commons.compress.archivers.zip.ZipFile in project vcell by virtualcell.

the class SimulationData method getVCellSimFiles.

@Override
public VCellSimFiles getVCellSimFiles() throws FileNotFoundException, DataAccessException {
    File cartesianMeshFile = getMeshFile();
    File meshMetricsFile = getMembraneMeshMetricsFile();
    File subdomainFile = getSubdomainFile();
    File logFile = getLogFile();
    File postprocessingFile = getDataProcessingOutputSourceFileHDF5();
    if (!(vcDataId instanceof VCSimulationDataIdentifier)) {
        throw new RuntimeException("cannot process vtk, vcDataId not " + VCSimulationDataIdentifier.class.getSimpleName());
    }
    VCSimulationDataIdentifier vcSimDataID = (VCSimulationDataIdentifier) vcDataId;
    VCellSimFiles vcellSimFiles = new VCellSimFiles(vcSimDataID.getSimulationKey(), vcSimDataID.getJobIndex(), cartesianMeshFile, meshMetricsFile, subdomainFile, logFile, postprocessingFile);
    refreshLogFile();
    double[] times = getDataTimes();
    for (int i = 0; i < times.length; i++) {
        File pdeDataFile = getPDEDataFile(times[i]);
        File zipFile = getPDEDataZipFile(times[i]);
        vcellSimFiles.addDataFileEntry(zipFile, pdeDataFile, times[i]);
    }
    return vcellSimFiles;
}
Also used : VCellSimFiles(org.vcell.vis.io.VCellSimFiles) ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) File(java.io.File) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier)

Example 43 with ZipFile

use of org.apache.commons.compress.archivers.zip.ZipFile in project vcell by virtualcell.

the class SimulationData method getChomboExtrapolatedValues.

public synchronized SimDataBlock getChomboExtrapolatedValues(String varName, double time) throws DataAccessException, IOException {
    refreshLogFile();
    File pdeFile = getPDEDataFile(time);
    if (pdeFile == null) {
        return null;
    }
    DataSet dataSet = new DataSet();
    File zipFile = null;
    try {
        zipFile = getPDEDataZipFile(time);
    } catch (DataAccessException ex) {
        zipFile = null;
    }
    try {
        dataSet.read(pdeFile, zipFile);
    } catch (IOException ex) {
        ex.printStackTrace();
        throw new DataAccessException("data at time=" + time + " read error", ex);
    }
    long lastModified = getLastModified(pdeFile, zipFile);
    DataSetIdentifier dsi = getDataSetIdentifier(varName);
    if (dsi == null) {
        throw new DataAccessException("data not found for variable " + varName);
    }
    final String varNameInDataSet = dsi.getQualifiedName();
    double[] data = DataSet.readChomboExtrapolatedValues(varNameInDataSet, pdeFile, zipFile);
    VariableType variableType = VariableType.MEMBRANE;
    PDEDataInfo pdeDataInfo = new PDEDataInfo(vcDataId.getOwner(), vcDataId.getID(), varName, time, lastModified);
    return data == null ? null : new SimDataBlock(pdeDataInfo, data, variableType);
}
Also used : VariableType(cbit.vcell.math.VariableType) IOException(java.io.IOException) ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) File(java.io.File) DataAccessException(org.vcell.util.DataAccessException)

Example 44 with ZipFile

use of org.apache.commons.compress.archivers.zip.ZipFile in project vcell by virtualcell.

the class SimulationData method getPDEDataZipFile.

/**
 * This method was created by a SmartGuide.
 * @return java.lang.String
 * @param time double
 */
private synchronized File getPDEDataZipFile(double time) throws DataAccessException {
    // 
    if (bZipFormat1) {
        File zipFile = getZipFile(false, null);
        if (zipFile.exists()) {
            return zipFile;
        } else {
            return null;
        }
    }
    if (!bZipFormat2) {
        return null;
    }
    double[] times = getDataTimes();
    if (times == null) {
        return null;
    }
    if (zipFilenames == null || times.length != zipFilenames.length) {
        return null;
    }
    Integer index = pdeDataMap.get(time);
    if (index != null) {
        String zipFileName = FilenameUtils.getName(zipFilenames[index]);
        // new File(userDirectory,zipFileName);
        File zipFile = amplistorHelper.getFile(zipFileName);
        if (zipFile.exists()) {
            return zipFile;
        } else {
            return null;
        }
    }
    return null;
}
Also used : ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) File(java.io.File)

Aggregations

ZipFile (org.apache.commons.compress.archivers.zip.ZipFile)44 ZipArchiveEntry (org.apache.commons.compress.archivers.zip.ZipArchiveEntry)25 File (java.io.File)23 IOException (java.io.IOException)23 FileNotFoundException (java.io.FileNotFoundException)12 InputStream (java.io.InputStream)12 BufferedInputStream (java.io.BufferedInputStream)10 FileInputStream (java.io.FileInputStream)9 ZipEntry (java.util.zip.ZipEntry)8 Path (java.nio.file.Path)7 DataAccessException (org.vcell.util.DataAccessException)7 ZipInputStream (java.util.zip.ZipInputStream)6 DataInputStream (java.io.DataInputStream)5 FileOutputStream (java.io.FileOutputStream)5 ArrayList (java.util.ArrayList)5 ZipOutputStream (java.util.zip.ZipOutputStream)5 OutputStream (java.io.OutputStream)4 Test (org.junit.Test)4 MathException (cbit.vcell.math.MathException)2 VariableType (cbit.vcell.math.VariableType)2