diff --git a/cdm/src/main/java/ucar/nc2/iosp/netcdf3/N3iosp.java b/cdm/src/main/java/ucar/nc2/iosp/netcdf3/N3iosp.java index e39e6d9..e6159f6 100644 --- a/cdm/src/main/java/ucar/nc2/iosp/netcdf3/N3iosp.java +++ b/cdm/src/main/java/ucar/nc2/iosp/netcdf3/N3iosp.java @@ -410,6 +410,23 @@ public String NC_check_name(String name) { this.fill = fill; } + /** + * Returns a Layout object for use by an N3iosp object + * + * @param v2 the variable to get the layout information for + * @param section the record range to read + * @return a Layout corresponding to the Section requested + * @throws IOException on error + */ + private Layout getLayout(Variable v2, Section section) throws InvalidRangeException { + N3header.Vinfo vinfo = (N3header.Vinfo) v2.getSPobject(); + + Layout layout = (!v2.isUnlimited()) ? new LayoutRegular(vinfo.begin, v2.getElementSize(), v2.getShape(), section) + : new LayoutRegularSegmented(vinfo.begin, v2.getElementSize(), header.recsize, v2.getShape(), section); + + return layout; + } + ///////////////////////////////////////////////////////////////////////////// // data reading @@ -417,11 +434,8 @@ public String NC_check_name(String name) { if (v2 instanceof Structure) return readRecordData((Structure) v2, section); - N3header.Vinfo vinfo = (N3header.Vinfo) v2.getSPobject(); DataType dataType = v2.getDataType(); - - Layout layout = (!v2.isUnlimited()) ? new LayoutRegular(vinfo.begin, v2.getElementSize(), v2.getShape(), section) : - new LayoutRegularSegmented(vinfo.begin, v2.getElementSize(), header.recsize, v2.getShape(), section); + Layout layout = getLayout(v2, section); if (layout.getTotalNelems() == 0) { return Array.factory(dataType.getPrimitiveClassType(), section.getShape()); @@ -563,11 +577,8 @@ public String NC_check_name(String name) { if (v2 instanceof Structure) return readRecordData((Structure) v2, section, channel); - N3header.Vinfo vinfo = (N3header.Vinfo) v2.getSPobject(); DataType dataType = v2.getDataType(); - - Layout layout = (!v2.isUnlimited()) ? new LayoutRegular(vinfo.begin, v2.getElementSize(), v2.getShape(), section) : - new LayoutRegularSegmented(vinfo.begin, v2.getElementSize(), header.recsize, v2.getShape(), section); + Layout layout = getLayout(v2, section); return readData(layout, dataType, channel); } @@ -662,7 +673,6 @@ public String NC_check_name(String name) { public void writeData(Variable v2, Section section, Array values) throws java.io.IOException, InvalidRangeException { - N3header.Vinfo vinfo = (N3header.Vinfo) v2.getSPobject(); DataType dataType = v2.getDataType(); if (v2.isUnlimited()) { @@ -674,8 +684,7 @@ public String NC_check_name(String name) { writeRecordData((Structure) v2, section, values); } else { - Layout layout = (!v2.isUnlimited()) ? new LayoutRegular(vinfo.begin, v2.getElementSize(), v2.getShape(), section) : - new LayoutRegularSegmented(vinfo.begin, v2.getElementSize(), header.recsize, v2.getShape(), section); + Layout layout = getLayout(v2, section); writeData(values, layout, dataType); } }