Skip to content

Commit

Permalink
Account for no data in calculator
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Brauer committed Jan 26, 2023
1 parent f2839af commit db48178
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import mil.army.usace.hec.vortex.VortexGrid;

import java.util.Arrays;

public class Calculator {

private final VortexGrid inputGrid;
Expand Down Expand Up @@ -75,27 +77,31 @@ public VortexGrid calculate(){
int size = data.length;
float[] resultantData = new float[size];

float noDataValue = (float) inputGrid.noDataValue();

Arrays.fill(resultantData, noDataValue);

if (!Double.isNaN(multiplyValue)) {
for (int i = 0; i < size; i++) {
resultantData[i] = data[i] * multiplyValue;
resultantData[i] = data[i] != noDataValue ? data[i] * multiplyValue : noDataValue;
}
}

if (!Double.isNaN(divideValue)) {
for (int i = 0; i < size; i++) {
resultantData[i] = data[i] / divideValue;
resultantData[i] = data[i] != noDataValue ? data[i] / divideValue : noDataValue;
}
}

if (!Double.isNaN(addValue)) {
for (int i = 0; i < size; i++) {
resultantData[i] = data[i] + addValue;
resultantData[i] = data[i] != noDataValue ? data[i] + addValue : noDataValue;
}
}

if (!Double.isNaN(subtractValue)) {
for (int i = 0; i < size; i++) {
resultantData[i] = data[i] - subtractValue;
resultantData[i] = data[i] != noDataValue ? data[i] - subtractValue : noDataValue;
}
}

Expand Down

0 comments on commit db48178

Please sign in to comment.