@@ -219,68 +219,83 @@ public void doCalculation(Instrument instrument, Measurement measurement,
219219 measurementRuntime .doubleValue ());
220220
221221 if (null != interpZeroS2Beam ) {
222- BigDecimal bdZeroS2Beam = new BigDecimal (interpZeroS2Beam );
223222
224- BigDecimal sDC = bdMeasurementS2Beam . divide ( bdZeroS2Beam ,
225- RoundingMode . HALF_UP );
223+ try {
224+ BigDecimal bdZeroS2Beam = new BigDecimal ( interpZeroS2Beam );
226225
227- BigDecimal bdSProc = F .multiply (new BigDecimal (1D ).subtract (sDC ));
226+ BigDecimal sDC = bdMeasurementS2Beam .divide (bdZeroS2Beam ,
227+ RoundingMode .HALF_UP );
228228
229- BigDecimal runtimeSincePre = measurementRuntime
230- .subtract (runTimePrior .getBigDecimalValue ());
229+ BigDecimal bdSProc = F .multiply (new BigDecimal (1D ).subtract (sDC ));
231230
232- BigDecimal k1Interp = k1Prior .getBigDecimalValue ()
233- .add (k1Step .multiply (runtimeSincePre ));
234- BigDecimal k2Interp = k2Prior .getBigDecimalValue ()
235- .add (k2Step .multiply (runtimeSincePre ));
236- BigDecimal k3Interp = k3Prior .getBigDecimalValue ()
237- .add (k3Step .multiply (runtimeSincePre ));
231+ BigDecimal runtimeSincePre = measurementRuntime
232+ .subtract (runTimePrior .getBigDecimalValue ());
238233
239- BigDecimal sProcCubed = bdSProc .pow (3 );
240- BigDecimal sProcSquared = bdSProc .pow (2 );
234+ BigDecimal k1Interp = k1Prior .getBigDecimalValue ()
235+ .add (k1Step .multiply (runtimeSincePre ));
236+ BigDecimal k2Interp = k2Prior .getBigDecimalValue ()
237+ .add (k2Step .multiply (runtimeSincePre ));
238+ BigDecimal k3Interp = k3Prior .getBigDecimalValue ()
239+ .add (k3Step .multiply (runtimeSincePre ));
241240
242- BigDecimal k3Part = k3Interp .multiply (sProcCubed );
243- BigDecimal k2Part = k2Interp .multiply (sProcSquared );
244- BigDecimal k1Part = k1Interp .multiply (bdSProc );
241+ BigDecimal sProcCubed = bdSProc .pow (3 );
242+ BigDecimal sProcSquared = bdSProc .pow (2 );
245243
246- BigDecimal xco2ProcPart = k3Part .add (k2Part ).add (k1Part );
244+ BigDecimal k3Part = k3Interp .multiply (sProcCubed );
245+ BigDecimal k2Part = k2Interp .multiply (sProcSquared );
246+ BigDecimal k1Part = k1Interp .multiply (bdSProc );
247247
248- // Gas temperature in Kelvin
249- BigDecimal gasTemperature = new BigDecimal (measurement
250- .getMeasurementValue ("Gas Stream Temperature" ).getCalculatedValue ())
251- .add (T0 );
248+ BigDecimal xco2ProcPart = k3Part .add (k2Part ).add (k1Part );
252249
253- BigDecimal gasPressure = new BigDecimal (measurement
254- .getMeasurementValue ("Gas Stream Pressure" ).getCalculatedValue ());
250+ // Gas temperature in Kelvin
251+ BigDecimal gasTemperature = new BigDecimal (
252+ measurement .getMeasurementValue ("Gas Stream Temperature" )
253+ .getCalculatedValue ())
254+ .add (T0 );
255255
256- BigDecimal membranePressure = new BigDecimal (measurement
257- .getMeasurementValue ("Membrane Pressure" ).getCalculatedValue ());
256+ BigDecimal gasPressure = new BigDecimal (measurement
257+ .getMeasurementValue ("Gas Stream Pressure" ).getCalculatedValue ());
258258
259- BigDecimal pressureTimesTemp = P0 .multiply (gasTemperature );
259+ BigDecimal membranePressure = new BigDecimal (measurement
260+ .getMeasurementValue ("Membrane Pressure" ).getCalculatedValue ());
260261
261- BigDecimal tempTimesPressure = T0 .multiply (gasPressure );
262+ BigDecimal pressureTimesTemp = P0 .multiply (gasTemperature );
262263
263- BigDecimal xcoPresTempPart = pressureTimesTemp
264- .divide (tempTimesPressure , 50 , RoundingMode .HALF_UP );
264+ BigDecimal tempTimesPressure = T0 .multiply (gasPressure );
265265
266- BigDecimal bdXCO2 = xco2ProcPart .multiply (xcoPresTempPart );
266+ BigDecimal xcoPresTempPart = pressureTimesTemp
267+ .divide (tempTimesPressure , 50 , RoundingMode .HALF_UP );
267268
268- BigDecimal pco2PressurePart = membranePressure .divide (P0 , 50 ,
269- RoundingMode .HALF_UP );
269+ BigDecimal bdXCO2 = xco2ProcPart .multiply (xcoPresTempPart );
270270
271- BigDecimal bdPCO2SST = bdXCO2 .multiply (pco2PressurePart );
271+ BigDecimal pco2PressurePart = membranePressure .divide (P0 , 50 ,
272+ RoundingMode .HALF_UP );
272273
273- Double waterTemp = measurement
274- .getMeasurementValue ("Water Temperature" ).getCalculatedValue ();
274+ BigDecimal bdPCO2SST = bdXCO2 .multiply (pco2PressurePart );
275275
276- fCO2 = Calculators . calcfCO2 ( bdPCO2SST . doubleValue (),
277- bdXCO2 . doubleValue (), membranePressure . doubleValue (), waterTemp );
276+ Double waterTemp = measurement
277+ . getMeasurementValue ( "Water Temperature" ). getCalculatedValue ( );
278278
279- // Make Double values for data reduction record
280- zeroS2Beam = bdZeroS2Beam .doubleValue ();
281- sProc = bdSProc .doubleValue ();
282- xco2 = bdXCO2 .doubleValue ();
283- pCO2SST = bdPCO2SST .doubleValue ();
279+ fCO2 = Calculators .calcfCO2 (bdPCO2SST .doubleValue (),
280+ bdXCO2 .doubleValue (), membranePressure .doubleValue (), waterTemp );
281+
282+ // Make Double values for data reduction record
283+ zeroS2Beam = bdZeroS2Beam .doubleValue ();
284+ sProc = bdSProc .doubleValue ();
285+ xco2 = bdXCO2 .doubleValue ();
286+ pCO2SST = bdPCO2SST .doubleValue ();
287+ } catch (NumberFormatException e ) {
288+ /*
289+ * This will happen if any of the found measurement values are NaN.
290+ * As long as the CONTROS file isn't messed with, this shouldn't
291+ * happen.
292+ */
293+ zeroS2Beam = Double .NaN ;
294+ sProc = Double .NaN ;
295+ xco2 = Double .NaN ;
296+ pCO2SST = Double .NaN ;
297+ fCO2 = Double .NaN ;
298+ }
284299 } else {
285300 zeroS2Beam = Double .NaN ;
286301 sProc = Double .NaN ;
0 commit comments