Skip to content

Commit

Permalink
Merge pull request #1260 from tdrwenski/dont-use-deprecated-code
Browse files Browse the repository at this point in the history
Don't use deprecated code in grib collections
  • Loading branch information
haileyajohnson authored Nov 15, 2023
2 parents dc397a3 + fec51d0 commit 5c0de38
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 27 deletions.
2 changes: 2 additions & 0 deletions cdm/core/src/main/java/ucar/nc2/NetcdfFileSubclass.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
*
* @author caron
* @since 10/29/2014
* @deprecated Use NetcdfFile.builder(). Remove in v6
*/
@Deprecated
public class NetcdfFileSubclass extends NetcdfFile {

public NetcdfFileSubclass() {}
Expand Down
2 changes: 1 addition & 1 deletion cdm/core/src/main/java/ucar/nc2/NetcdfFiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ private static IOServiceProvider getIosp(ucar.unidata.io.RandomAccessFile raf) t
return null;
}

private static NetcdfFile build(IOServiceProvider spi, ucar.unidata.io.RandomAccessFile raf, String location,
public static NetcdfFile build(IOServiceProvider spi, ucar.unidata.io.RandomAccessFile raf, String location,
ucar.nc2.util.CancelTask cancelTask) throws IOException {

NetcdfFile.Builder builder = NetcdfFile.builder().setIosp((AbstractIOServiceProvider) spi).setLocation(location);
Expand Down
12 changes: 4 additions & 8 deletions grib/src/main/java/ucar/nc2/grib/collection/Grib1Collection.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ public ucar.nc2.dataset.NetcdfDataset getNetcdfDataset(Dataset ds, GroupGC group
FeatureCollectionConfig gribConfig, Formatter errlog, org.slf4j.Logger logger) throws IOException {
if (filename == null) {
Grib1Iosp iosp = new Grib1Iosp(group, ds.getType());
NetcdfFile ncfile = new NetcdfFileSubclass(iosp, null, getLocation(), null);
return new NetcdfDataset(ncfile);
return buildNetcdfDataset(iosp, getLocation());

} else {
MFile wantFile = findMFileByName(filename);
Expand All @@ -53,8 +52,7 @@ public ucar.nc2.dataset.NetcdfDataset getNetcdfDataset(Dataset ds, GroupGC group
return null;

Grib1Iosp iosp = new Grib1Iosp(gc);
NetcdfFile ncfile = new NetcdfFileSubclass(iosp, null, getLocation(), null);
return new NetcdfDataset(ncfile);
return buildNetcdfDataset(iosp, getLocation());
}
return null;
}
Expand All @@ -66,8 +64,7 @@ public ucar.nc2.dt.grid.GridDataset getGridDataset(Dataset ds, GroupGC group, St
FeatureCollectionConfig gribConfig, Formatter errlog, org.slf4j.Logger logger) throws IOException {
if (filename == null) {
Grib1Iosp iosp = new Grib1Iosp(group, ds.getType());
NetcdfFile ncfile = new NetcdfFileSubclass(iosp, null, getLocation() + "#" + group.getId(), null);
NetcdfDataset ncd = new NetcdfDataset(ncfile);
NetcdfDataset ncd = buildNetcdfDataset(iosp, getLocation() + "#" + group.getId());
return new ucar.nc2.dt.grid.GridDataset(ncd); // LOOK - replace with custom GridDataset??

} else {
Expand All @@ -79,8 +76,7 @@ public ucar.nc2.dt.grid.GridDataset getGridDataset(Dataset ds, GroupGC group, St
return null;

Grib1Iosp iosp = new Grib1Iosp(gc);
NetcdfFile ncfile = new NetcdfFileSubclass(iosp, null, getLocation(), null);
NetcdfDataset ncd = new NetcdfDataset(ncfile);
NetcdfDataset ncd = buildNetcdfDataset(iosp, getLocation());
return new ucar.nc2.dt.grid.GridDataset(ncd); // LOOK - replace with custom GridDataset??
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,15 @@ public ucar.nc2.dataset.NetcdfDataset getNetcdfDataset(Dataset ds, GroupGC group
FeatureCollectionConfig config, Formatter errlog, org.slf4j.Logger logger) throws IOException {

ucar.nc2.grib.collection.Grib1Iosp iosp = new ucar.nc2.grib.collection.Grib1Iosp(group, ds.getType());
NetcdfFile ncfile = new NetcdfFileSubclass(iosp, null, getLocation(), null);
return new NetcdfDataset(ncfile);
return buildNetcdfDataset(iosp, getLocation());
}

@Override
public ucar.nc2.dt.grid.GridDataset getGridDataset(Dataset ds, GroupGC group, String filename,
FeatureCollectionConfig config, Formatter errlog, org.slf4j.Logger logger) throws IOException {

ucar.nc2.grib.collection.Grib1Iosp iosp = new ucar.nc2.grib.collection.Grib1Iosp(group, ds.getType());
NetcdfFile ncfile = new NetcdfFileSubclass(iosp, null, getLocation(), null);
NetcdfDataset ncd = new NetcdfDataset(ncfile);
NetcdfDataset ncd = buildNetcdfDataset(iosp, getLocation());
return new ucar.nc2.dt.grid.GridDataset(ncd);
}

Expand Down
12 changes: 4 additions & 8 deletions grib/src/main/java/ucar/nc2/grib/collection/Grib2Collection.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ public ucar.nc2.dataset.NetcdfDataset getNetcdfDataset(Dataset ds, GroupGC group

if (filename == null) {
Grib2Iosp iosp = new Grib2Iosp(group, ds.getType());
NetcdfFile ncfile = new NetcdfFileSubclass(iosp, null, getLocation(), null);
return new NetcdfDataset(ncfile);
return buildNetcdfDataset(iosp, getLocation());

} else {
MFile wantFile = findMFileByName(filename);
Expand All @@ -55,8 +54,7 @@ public ucar.nc2.dataset.NetcdfDataset getNetcdfDataset(Dataset ds, GroupGC group
return null;

Grib2Iosp iosp = new Grib2Iosp(gc);
NetcdfFile ncfile = new NetcdfFileSubclass(iosp, null, getLocation(), null);
return new NetcdfDataset(ncfile);
return buildNetcdfDataset(iosp, getLocation());
}
return null;
}
Expand All @@ -69,8 +67,7 @@ public ucar.nc2.dt.grid.GridDataset getGridDataset(Dataset ds, GroupGC group, St

if (filename == null) {
Grib2Iosp iosp = new Grib2Iosp(group, ds.getType());
NetcdfFile ncfile = new NetcdfFileSubclass(iosp, null, getLocation() + "#" + group.getId(), null);
NetcdfDataset ncd = new NetcdfDataset(ncfile);
NetcdfDataset ncd = buildNetcdfDataset(iosp, getLocation() + "#" + group.getId());
return new ucar.nc2.dt.grid.GridDataset(ncd); // LOOK - replace with custom GridDataset??

} else {
Expand All @@ -82,8 +79,7 @@ public ucar.nc2.dt.grid.GridDataset getGridDataset(Dataset ds, GroupGC group, St
return null;

Grib2Iosp iosp = new Grib2Iosp(gc);
NetcdfFile ncfile = new NetcdfFileSubclass(iosp, null, getLocation(), null);
NetcdfDataset ncd = new NetcdfDataset(ncfile);
NetcdfDataset ncd = buildNetcdfDataset(iosp, getLocation());
return new ucar.nc2.dt.grid.GridDataset(ncd); // LOOK - replace with custom GridDataset??
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import thredds.featurecollection.FeatureCollectionConfig;
import ucar.nc2.Attribute;
import ucar.nc2.AttributeContainer;
import ucar.nc2.NetcdfFile;
import ucar.nc2.NetcdfFileSubclass;
import ucar.nc2.constants.CDM;
import ucar.nc2.constants.DataFormatType;
import ucar.nc2.dataset.NetcdfDataset;
Expand All @@ -36,17 +34,15 @@ public ucar.nc2.dataset.NetcdfDataset getNetcdfDataset(Dataset ds, GroupGC group
FeatureCollectionConfig config, Formatter errlog, org.slf4j.Logger logger) throws IOException {

ucar.nc2.grib.collection.Grib2Iosp iosp = new ucar.nc2.grib.collection.Grib2Iosp(group, ds.getType());
NetcdfFile ncfile = new NetcdfFileSubclass(iosp, null, getLocation(), null);
return new NetcdfDataset(ncfile);
return buildNetcdfDataset(iosp, getLocation());
}

@Override
public ucar.nc2.dt.grid.GridDataset getGridDataset(Dataset ds, GroupGC group, String filename,
FeatureCollectionConfig config, Formatter errlog, org.slf4j.Logger logger) throws IOException {

ucar.nc2.grib.collection.Grib2Iosp iosp = new ucar.nc2.grib.collection.Grib2Iosp(group, ds.getType());
NetcdfFile ncfile = new NetcdfFileSubclass(iosp, null, getLocation(), null);
NetcdfDataset ncd = new NetcdfDataset(ncfile);
NetcdfDataset ncd = buildNetcdfDataset(iosp, getLocation());
return new ucar.nc2.dt.grid.GridDataset(ncd);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@
import ucar.nc2.Attribute;
import ucar.nc2.AttributeContainer;
import ucar.nc2.AttributeContainerMutable;
import ucar.nc2.NetcdfFile;
import ucar.nc2.NetcdfFiles;
import ucar.nc2.constants.CDM;
import ucar.nc2.constants.CF;
import ucar.nc2.constants.FeatureType;
import ucar.nc2.dataset.NetcdfDataset;
import ucar.nc2.dataset.NetcdfDatasets;
import ucar.nc2.ft2.coverage.CoverageCollection;
import ucar.nc2.ft2.coverage.SubsetParams;
import ucar.nc2.grib.*;
Expand All @@ -31,6 +35,7 @@
import ucar.nc2.grib.grib1.Grib1Variable;
import ucar.nc2.grib.grib1.tables.Grib1Customizer;
import ucar.nc2.grib.grib2.table.Grib2Tables;
import ucar.nc2.iosp.AbstractIOServiceProvider;
import ucar.nc2.time.CalendarDate;
import ucar.nc2.time.CalendarDateRange;
import ucar.nc2.util.cache.FileCacheIF;
Expand Down Expand Up @@ -1113,6 +1118,13 @@ String getDataRafFilename(int fileno) {
return mfile.getPath();
}

protected static NetcdfDataset buildNetcdfDataset(AbstractIOServiceProvider iosp, String location)
throws IOException {
RandomAccessFile raf = (RandomAccessFile) iosp.sendIospMessage(NetcdfFile.IOSP_MESSAGE_RANDOM_ACCESS_FILE);
NetcdfFile ncfile = NetcdfFiles.build(iosp, raf, location, null);
return NetcdfDatasets.enhance(ncfile, NetcdfDataset.getDefaultEnhanceMode(), null);
}

///////////////////////

// stuff needed by InvDatasetFcGrib
Expand Down

0 comments on commit 5c0de38

Please sign in to comment.