|
7 | 7 | import cbit.vcell.math.Variable; |
8 | 8 | import cbit.vcell.math.VariableType; |
9 | 9 | import cbit.vcell.messaging.server.SimulationTask; |
| 10 | +import cbit.vcell.parser.DivideByZeroException; |
10 | 11 | import cbit.vcell.parser.Expression; |
11 | 12 | import cbit.vcell.parser.ExpressionException; |
| 13 | +import cbit.vcell.simdata.DataSet; |
12 | 14 | import cbit.vcell.simdata.SimDataBlock; |
13 | 15 | import cbit.vcell.simdata.SimulationData; |
14 | 16 | import cbit.vcell.simdata.VCData; |
@@ -66,15 +68,7 @@ protected void writeFieldData() throws ExpressionException, DataAccessException |
66 | 68 | ); |
67 | 69 | uniqueFieldDataIDSpecs.add(fieldDataIDSpec); |
68 | 70 | VariableType varType = fieldDataIDSpec.getFieldFuncArgs().getVariableType(); |
69 | | - final VariableType dataVarType; |
70 | | - try { |
71 | | - File ext_data_dir = new File(workingDirectory.getParentFile(), ffa.getFieldName()); |
72 | | - VCData vcData = new SimulationData(fieldDataIDSpec.getExternalDataIdentifier(), ext_data_dir, ext_data_dir, null); |
73 | | - SimDataBlock simDataBlock = vcData.getSimDataBlock(null, ffa.getVariableName(), ffa.getTime().evaluateConstant()); |
74 | | - dataVarType = simDataBlock.getVariableType(); |
75 | | - } catch (IOException e) { |
76 | | - throw new DataAccessException("Error reading field data file: " + e.getMessage()); |
77 | | - } |
| 71 | + final VariableType dataVarType = getVariableTypeFromFieldDataFiles(fieldDataIDSpec, ffa); |
78 | 72 | if (varType.equals(VariableType.UNKNOWN)) { |
79 | 73 | varType = dataVarType; |
80 | 74 | } else if (!varType.equals(dataVarType)) { |
@@ -104,4 +98,34 @@ protected void writeFieldData() throws ExpressionException, DataAccessException |
104 | 98 | printWriter.println(); |
105 | 99 | } |
106 | 100 |
|
| 101 | + private VariableType getVariableTypeFromFieldDataFiles(FieldDataIdentifierSpec fieldDataIDSpec, FieldFunctionArguments ffa) throws DataAccessException { |
| 102 | + |
| 103 | + try { |
| 104 | + final VariableType dataVarType; |
| 105 | + // |
| 106 | + // First, look to see if the processed field data file already exists, if so, use it to determine the variable type |
| 107 | + // |
| 108 | + DataSet dataSet = new DataSet(); |
| 109 | + File existingFieldDataFile = new File(workingDirectory, SimulationData.createCanonicalResampleFileName(fieldDataIDSpec.getExternalDataIdentifier(), ffa)); |
| 110 | + if (existingFieldDataFile.exists()) { |
| 111 | + // field data file may already exist |
| 112 | + // 1. from pyvcell writing the field data file directly into this directory for an image-based field data |
| 113 | + dataSet.read(existingFieldDataFile, null); |
| 114 | + int varTypeInteger = dataSet.getVariableTypeInteger(fieldDataIDSpec.getFieldFuncArgs().getVariableName()); |
| 115 | + dataVarType = VariableType.getVariableTypeFromInteger(varTypeInteger); |
| 116 | + }else { |
| 117 | + // |
| 118 | + // Else, read the unprocessed simulation results referenced in the FieldDataIdentifierSpec and extract the VariableType |
| 119 | + // |
| 120 | + File ext_data_dir = new File(workingDirectory.getParentFile(), ffa.getFieldName()); |
| 121 | + VCData vcData = new SimulationData(fieldDataIDSpec.getExternalDataIdentifier(), ext_data_dir, ext_data_dir, null); |
| 122 | + SimDataBlock simDataBlock = vcData.getSimDataBlock(null, ffa.getVariableName(), ffa.getTime().evaluateConstant()); |
| 123 | + dataVarType = simDataBlock.getVariableType(); |
| 124 | + } |
| 125 | + return dataVarType; |
| 126 | + } catch (IOException | ExpressionException | DataAccessException e) { |
| 127 | + throw new DataAccessException("Error reading field data file: " + e.getMessage()); |
| 128 | + } |
| 129 | + } |
| 130 | + |
107 | 131 | } |
0 commit comments