Skip to content
This repository has been archived by the owner on Sep 1, 2022. It is now read-only.

Enable NCSS returns when variable has _ChunkSizes attribute #1332

Merged
merged 1 commit into from
Aug 12, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions cdm/src/main/java/ucar/nc2/dt/grid/CFGridWriter2.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ private long writeOrTestSize(ucar.nc2.dt.GridDataset gds, List<String> gridList,
boolean addLatLon, boolean testSizeOnly,
NetcdfFileWriter writer) throws IOException, InvalidRangeException {

boolean isSubset = false;

NetcdfDataset ncd = (NetcdfDataset) gds.getNetcdfFile();

List<Variable> varList = new ArrayList<>(); // could make these Sets
Expand Down Expand Up @@ -175,9 +177,8 @@ private long writeOrTestSize(ucar.nc2.dt.GridDataset gds, List<String> gridList,
if (projRect != null) {
makeHorizRange(gcsOrg, projRect, horizStride, yxRanges);
gridWant = gridOrg.makeSubset(null, null, timeRange, zRangeUse, yxRanges.get(0), yxRanges.get(1));

isSubset = true;
} else {

if (llbb == null) {
yxRanges.add(null);
yxRanges.add(null);
Expand All @@ -187,6 +188,7 @@ private long writeOrTestSize(ucar.nc2.dt.GridDataset gds, List<String> gridList,

if ((null != timeRange) || (zRangeUse != null) || (llbb != null) || (horizStride > 1)) {
gridWant = gridOrg.makeSubset(timeRange, zRangeUse, llbb, 1, horizStride, horizStride);
isSubset = true;
} else
gridWant = gridOrg;
}
Expand Down Expand Up @@ -235,8 +237,17 @@ private long writeOrTestSize(ucar.nc2.dt.GridDataset gds, List<String> gridList,

// use fileWriter to copy the variables
FileWriter2 fileWriter = new FileWriter2(writer);
for (Variable v : varList)
for (Variable v : varList) {
if (isSubset && fileWriter.getNetcdfFileWriter().getVersion().isNetdf4format()) {
// if we have subset a dataset, and we are writing to netCDF-4 files, then we need to
// make sure that no variables come through with the _ChunkSizes attribute
// This has been properly fixed in netCDF-Java 5, and in this case is meant to be a
// quick and dirty, lite-touch hack to allow for writing in this case. If we don't do
// this, we get "Bad chunk sizes"
v.removeAttributeIgnoreCase(CDM.CHUNK_SIZES);
}
fileWriter.addVariable(v);
}

addCFAnnotations(writer, gds, gridList, ncd, axisList, addLatLon);

Expand Down