use of ncsa.hdf.object.Dataset in project vcell by virtualcell.
the class DataSet method readHdf5VariableSolution.
static double[] readHdf5VariableSolution(File zipfile, String fileName, String varName) throws Exception {
File tempFile = null;
FileFormat solFile = null;
try {
tempFile = createTempHdf5File(zipfile, fileName);
FileFormat fileFormat = FileFormat.getFileFormat(FileFormat.FILE_TYPE_HDF5);
solFile = fileFormat.createInstance(tempFile.getAbsolutePath(), FileFormat.READ);
solFile.open();
if (varName != null) {
String varPath = Hdf5Utils.getVarSolutionPath(varName);
HObject solObj = FileFormat.findObject(solFile, varPath);
if (solObj instanceof Dataset) {
Dataset dataset = (Dataset) solObj;
return (double[]) dataset.read();
}
}
} 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
}
}
return null;
}
use of ncsa.hdf.object.Dataset in project vcell by virtualcell.
the class DataSet method readChomboExtrapolatedValues.
static double[] readChomboExtrapolatedValues(String varName, FileFormat solFile) throws Exception {
double[] data = null;
if (varName != null) {
String varPath = Hdf5Utils.getVolVarExtrapolatedValuesPath(varName);
HObject solObj = FileFormat.findObject(solFile, varPath);
if (solObj == null) {
throw new IOException("Extrapolated values for variable '" + varName + "' does not exist in the results.");
}
if (solObj instanceof Dataset) {
Dataset dataset = (Dataset) solObj;
return (double[]) dataset.read();
}
}
return data;
}
use of ncsa.hdf.object.Dataset in project vcell by virtualcell.
the class CartesianMeshChombo method readMeshFile.
public static CartesianMeshChombo readMeshFile(File chomboMeshFile) throws Exception {
CartesianMeshChombo chomboMesh = new CartesianMeshChombo();
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 = null;
try {
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();
MeshAttribute mattr = null;
try {
mattr = MeshAttribute.valueOf(attrName);
} catch (IllegalArgumentException ex) {
}
if (mattr == null) {
// if not found, then we don't care about this attribute
logger.debug("mesh attribute " + attrName + " is not defined in Java");
continue;
}
Object value = attr.getValue();
switch(mattr) {
case dimension:
chomboMesh.dimension = ((int[]) value)[0];
break;
case numLevels:
chomboMesh.numLevels = ((int[]) value)[0];
break;
case viewLevel:
chomboMesh.viewLevel = ((int[]) value)[0];
break;
case refineRatios:
chomboMesh.refineRatios = (int[]) value;
break;
case Dx:
case extent:
case Nx:
case origin:
// these 4 has format of {};
String[] valueStrArray = (String[]) value;
String value0 = valueStrArray[0];
StringTokenizer st = new StringTokenizer(value0, "{,} ");
int numTokens = st.countTokens();
// we need 3 for 3d
double[] values = new double[Math.max(3, numTokens)];
for (int i = 0; i < Math.min(3, numTokens); ++i) {
String token = st.nextToken();
values[i] = Double.parseDouble(token);
}
switch(mattr) {
case Dx:
chomboMesh.dx = new double[3];
System.arraycopy(values, 0, chomboMesh.dx, 0, values.length);
break;
case extent:
chomboMesh.extent = new Extent(values[0], values[1], values[2] == 0 ? 1 : values[2]);
break;
case Nx:
chomboMesh.size = new ISize((int) values[0], (int) values[1], values[2] == 0 ? 1 : (int) values[2]);
break;
case origin:
chomboMesh.origin = new Origin(values[0], values[1], values[2]);
break;
}
break;
}
}
List<HObject> memberList = meshGroup.getMemberList();
for (HObject member : memberList) {
if (!(member instanceof Dataset)) {
continue;
}
Dataset dataset = (Dataset) member;
Vector vectValues = (Vector) dataset.read();
String name = dataset.getName();
MeshDataSet mdataset = null;
try {
mdataset = MeshDataSet.valueOfName(name);
} catch (IllegalArgumentException ex) {
logger.debug("mesh dataset " + name + " is not defined in Java");
}
if (mdataset == null) {
// if not found, then we don't care about this dataset
continue;
}
switch(mdataset) {
case vertices:
collectVertices(chomboMesh, vectValues);
break;
case segments:
collect2dSegments(chomboMesh, vectValues);
break;
case structures:
collectStructures(chomboMesh, vectValues);
break;
case featurephasevols:
collectFeaturePhaseVols(chomboMesh, vectValues);
break;
case membraneids:
collectMembraneIds(chomboMesh, vectValues);
break;
case membrane_elements:
case membrane_elements_old:
collectMembraneElements(chomboMesh, vectValues);
break;
case surface_triangles:
collect3dSurfaceTriangles(chomboMesh, vectValues);
break;
case slice_view:
collect3dSliceView(chomboMesh, vectValues);
break;
}
}
} finally {
if (meshFile != null) {
meshFile.close();
}
}
// set neighbors to membrane elements
if (chomboMesh.dimension == 2 && chomboMesh.membraneElements != null) {
for (int i = 0; i < chomboMesh.membraneElements.length; ++i) {
MembraneElement me = chomboMesh.membraneElements[i];
me.setConnectivity(chomboMesh.segments[i].prevNeigbhor, chomboMesh.segments[i].nextNeigbhor, -1, -1);
}
}
return chomboMesh;
}
use of ncsa.hdf.object.Dataset in project vcell by virtualcell.
the class DataSet method readHdf5SolutionMetaData.
private void readHdf5SolutionMetaData(InputStream is) throws Exception {
File tempFile = null;
FileFormat solFile = null;
try {
tempFile = createTempHdf5File(is);
FileFormat fileFormat = FileFormat.getFileFormat(FileFormat.FILE_TYPE_HDF5);
solFile = fileFormat.createInstance(tempFile.getAbsolutePath(), FileFormat.READ);
solFile.open();
DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) solFile.getRootNode();
Group rootGroup = (Group) rootNode.getUserObject();
List<HObject> solGroups = rootGroup.getMemberList();
for (HObject memberGroup : solGroups) {
if (memberGroup instanceof Group && memberGroup.getName().equals("solution")) {
Group solGroup = (Group) memberGroup;
List<HObject> memberList = solGroup.getMemberList();
for (HObject member : memberList) {
if (!(member instanceof Dataset)) {
continue;
}
Dataset dataset = (Dataset) member;
String dsname = dataset.getName();
int vt = -1;
String domain = null;
List<Attribute> solAttrList = dataset.getMetadata();
for (Attribute attr : solAttrList) {
String attrName = attr.getName();
if (attrName.equals("variable type")) {
Object obj = attr.getValue();
vt = ((int[]) obj)[0];
} else if (attrName.equals("domain")) {
Object obj = attr.getValue();
domain = ((String[]) obj)[0];
}
}
long[] dims = dataset.getDims();
String varName = domain == null ? dsname : domain + Variable.COMBINED_IDENTIFIER_SEPARATOR + dsname;
dataBlockList.addElement(DataBlock.createDataBlock(varName, vt, (int) dims[0], 0));
}
break;
}
}
} finally {
try {
if (solFile != null) {
solFile.close();
}
if (tempFile != null) {
if (!tempFile.delete()) {
System.err.println("couldn't delete temp file " + tempFile);
}
}
} catch (Exception e) {
// ignore
}
}
}
use of ncsa.hdf.object.Dataset in project vcell by virtualcell.
the class DataSet method readMBSDataMetadata.
private void readMBSDataMetadata() throws Exception {
FileFormat fileFormat = FileFormat.getFileFormat(FileFormat.FILE_TYPE_HDF5);
FileFormat solFile = null;
try {
solFile = fileFormat.createInstance(fileName, FileFormat.READ);
solFile.open();
DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) solFile.getRootNode();
Group rootGroup = (Group) rootNode.getUserObject();
Group solutionGroup = null;
for (Object member : rootGroup.getMemberList()) {
String memberName = ((HObject) member).getName();
if (member instanceof Group) {
MBSDataGroup group = MBSDataGroup.valueOf(memberName);
if (group == MBSDataGroup.Solution) {
solutionGroup = (Group) member;
break;
}
}
}
if (solutionGroup == null) {
throw new Exception("Group " + MBSDataGroup.Solution + " not found");
}
// find any timeGroup
Group timeGroup = null;
for (Object member : solutionGroup.getMemberList()) {
String memberName = ((HObject) member).getName();
if (member instanceof Group && memberName.startsWith("time")) {
timeGroup = (Group) member;
break;
}
}
if (timeGroup == null) {
throw new Exception("No time group found");
}
// find all the datasets in that time group
for (Object member : timeGroup.getMemberList()) {
if (member instanceof Dataset) {
List<Attribute> solAttrList = ((Dataset) member).getMetadata();
int size = 0;
String varName = null;
VariableType varType = null;
for (Attribute attr : solAttrList) {
String attrName = attr.getName();
Object attrValue = attr.getValue();
if (attrName.equals(MSBDataAttribute.name.name())) {
varName = ((String[]) attrValue)[0];
} else if (attrName.equals(MSBDataAttribute.size.name())) {
size = ((int[]) attrValue)[0];
} else if (attrName.equals(MSBDataAttribute.type.name())) {
String vt = ((String[]) attrValue)[0];
if (vt.equals(MSBDataAttributeValue.Point.name())) {
varType = VariableType.POINT_VARIABLE;
} else if (vt.equals(MSBDataAttributeValue.Volume.name())) {
varType = VariableType.VOLUME;
} else if (vt.equals(MSBDataAttributeValue.PointSubDomain.name())) {
// Position for PointSubdomain
}
}
}
if (varType == VariableType.VOLUME) {
// only display volume
dataBlockList.addElement(DataBlock.createDataBlock(varName, varType.getType(), size, 0));
}
if (varType == VariableType.POINT_VARIABLE) {
// only display volume
dataBlockList.addElement(DataBlock.createDataBlock(varName, varType.getType(), size, 0));
}
}
}
} finally {
if (solFile != null) {
try {
solFile.close();
} catch (Exception e) {
// ignore
}
}
}
}
Aggregations