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();
}
}
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;
}
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);
}
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;
}
Aggregations