Skip to content

Commit e69c6e2

Browse files
Tara Drwenskihaileyajohnson
authored andcommitted
When subsetting a coverage axis, use original values instead of midpoints; these coords are used to find a record
1 parent 49d9528 commit e69c6e2

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

cdm/core/src/main/java/ucar/nc2/ft2/coverage/CoordAxisHelper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,8 +496,7 @@ CoverageCoordAxisBuilder subsetByIndex(Range range) throws InvalidRangeException
496496

497497
// subset(int ncoords, double start, double end, double[] values)
498498
CoverageCoordAxisBuilder builder = new CoverageCoordAxisBuilder(axis);
499-
builder.subset(ncoords, axis.getCoordMidpoint(range.first()), axis.getCoordMidpoint(range.last()), resolution,
500-
subsetValues);
499+
builder.subset(ncoords, axis.getCoord(range.first()), axis.getCoord(range.last()), resolution, subsetValues);
501500
builder.setRange(range);
502501
return builder;
503502
}

cdm/core/src/main/java/ucar/nc2/ft2/coverage/CoverageCoordAxis1D.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,25 @@ public boolean isAscending() {
114114
throw new IllegalStateException("unknown spacing" + spacing);
115115
}
116116

117+
public double getCoord(int index) {
118+
if (index < 0 || index >= getNcoords()) {
119+
throw new IllegalArgumentException("Index out of range=" + index);
120+
}
121+
loadValuesIfNeeded();
122+
123+
switch (spacing) {
124+
case regularPoint:
125+
case regularInterval:
126+
return startValue + index * getResolution();
127+
128+
case irregularPoint:
129+
case contiguousInterval:
130+
case discontiguousInterval:
131+
return values[index];
132+
}
133+
throw new IllegalStateException("Unknown spacing=" + spacing);
134+
}
135+
117136
public double getCoordMidpoint(int index) {
118137
if (index < 0 || index >= getNcoords())
119138
throw new IllegalArgumentException("Index out of range=" + index);

0 commit comments

Comments
 (0)