use of ncsa.hdf.object.Attribute 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;
}
use of ncsa.hdf.object.Attribute in project vcell by virtualcell.
the class SimulationDataSpatialHdf5 method retriveVariableNames.
private void retriveVariableNames() throws Exception {
// read variables only when I have never read the file since variables don't change
if (dataSetIdentifierList.size() > 0) {
return;
}
File tempFile = getTempSimHdf5File(0.0);
FileFormat fileFormat = FileFormat.getFileFormat(FileFormat.FILE_TYPE_HDF5);
FileFormat meshFile = fileFormat.createInstance(tempFile.getAbsolutePath(), FileFormat.READ);
meshFile.open();
DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) meshFile.getRootNode();
Group rootGroup = (Group) rootNode.getUserObject();
Group solGroup = (Group) rootGroup.getMemberList().get(0);
List<Attribute> solAttrList = solGroup.getMetadata();
String[] varNames = null;
int[] varTypes = null;
for (Attribute attr : solAttrList) {
String attrName = attr.getName();
Object value = attr.getValue();
if (attrName.equals(SOLUTION_ATTR_VARIABLES)) {
varNames = (String[]) value;
} else if (attrName.equals(SOLUTION_ATTR_VARIABLE_TYPES)) {
varTypes = (int[]) value;
}
}
for (int i = 0; i < varNames.length; i++) {
VariableType varType = VariableType.getVariableTypeFromInteger(varTypes[i]);
Domain domain = Variable.getDomainFromCombinedIdentifier(varNames[i]);
String varName = Variable.getNameFromCombinedIdentifier(varNames[i]);
dataSetIdentifierList.add(new DataSetIdentifier(varName, varType, domain));
}
}
Aggregations