diff --git a/grib/src/main/java/ucar/nc2/grib/collection/Grib1Collection.java b/grib/src/main/java/ucar/nc2/grib/collection/Grib1Collection.java index a17aeddadb..4b53f9984f 100644 --- a/grib/src/main/java/ucar/nc2/grib/collection/Grib1Collection.java +++ b/grib/src/main/java/ucar/nc2/grib/collection/Grib1Collection.java @@ -6,7 +6,6 @@ package ucar.nc2.grib.collection; import javax.annotation.Nullable; -import ucar.nc2.dataset.NetcdfDatasets; import ucar.nc2.grib.coord.CoordinateTimeAbstract; import ucar.nc2.*; import ucar.nc2.constants.DataFormatType; @@ -23,7 +22,6 @@ import ucar.nc2.grib.grib1.tables.Grib1Customizer; import java.io.IOException; import java.util.Formatter; -import ucar.unidata.io.RandomAccessFile; /** * Grib1-specific subclass of GribCollection. @@ -43,9 +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()); - RandomAccessFile raf = (RandomAccessFile) iosp.sendIospMessage(NetcdfFile.IOSP_MESSAGE_RANDOM_ACCESS_FILE); - NetcdfFile ncfile = NetcdfFiles.build(iosp, raf, getLocation(), null); - return NetcdfDatasets.enhance(ncfile, NetcdfDataset.getDefaultEnhanceMode(), null); + return buildNetcdfDataset(iosp, getLocation()); } else { MFile wantFile = findMFileByName(filename); @@ -56,9 +52,7 @@ public ucar.nc2.dataset.NetcdfDataset getNetcdfDataset(Dataset ds, GroupGC group return null; Grib1Iosp iosp = new Grib1Iosp(gc); - RandomAccessFile raf = (RandomAccessFile) iosp.sendIospMessage(NetcdfFile.IOSP_MESSAGE_RANDOM_ACCESS_FILE); - NetcdfFile ncfile = NetcdfFiles.build(iosp, raf, getLocation(), null); - return NetcdfDatasets.enhance(ncfile, NetcdfDataset.getDefaultEnhanceMode(), null); + return buildNetcdfDataset(iosp, getLocation()); } return null; } @@ -70,9 +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()); - RandomAccessFile raf = (RandomAccessFile) iosp.sendIospMessage(NetcdfFile.IOSP_MESSAGE_RANDOM_ACCESS_FILE); - NetcdfFile ncfile = NetcdfFiles.build(iosp, raf, getLocation() + "#" + group.getId(), null); - NetcdfDataset ncd = NetcdfDatasets.enhance(ncfile, NetcdfDataset.getDefaultEnhanceMode(), null); + NetcdfDataset ncd = buildNetcdfDataset(iosp, getLocation() + "#" + group.getId()); return new ucar.nc2.dt.grid.GridDataset(ncd); // LOOK - replace with custom GridDataset?? } else { @@ -84,9 +76,7 @@ public ucar.nc2.dt.grid.GridDataset getGridDataset(Dataset ds, GroupGC group, St return null; Grib1Iosp iosp = new Grib1Iosp(gc); - RandomAccessFile raf = (RandomAccessFile) iosp.sendIospMessage(NetcdfFile.IOSP_MESSAGE_RANDOM_ACCESS_FILE); - NetcdfFile ncfile = NetcdfFiles.build(iosp, raf, getLocation(), null); - NetcdfDataset ncd = NetcdfDatasets.enhance(ncfile, NetcdfDataset.getDefaultEnhanceMode(), null); + NetcdfDataset ncd = buildNetcdfDataset(iosp, getLocation()); return new ucar.nc2.dt.grid.GridDataset(ncd); // LOOK - replace with custom GridDataset?? } return null; diff --git a/grib/src/main/java/ucar/nc2/grib/collection/Grib1Partition.java b/grib/src/main/java/ucar/nc2/grib/collection/Grib1Partition.java index ddd548a313..61481d8cb0 100644 --- a/grib/src/main/java/ucar/nc2/grib/collection/Grib1Partition.java +++ b/grib/src/main/java/ucar/nc2/grib/collection/Grib1Partition.java @@ -10,13 +10,11 @@ import thredds.featurecollection.FeatureCollectionConfig; import ucar.nc2.constants.CDM; import ucar.nc2.dataset.NetcdfDataset; -import ucar.nc2.dataset.NetcdfDatasets; import ucar.nc2.ft2.coverage.CoverageCollection; import ucar.nc2.grib.GribUtils; import ucar.nc2.grib.coverage.GribCoverageDataset; import java.io.IOException; import java.util.Formatter; -import ucar.unidata.io.RandomAccessFile; /** * PartitionCollection for Grib1. @@ -35,9 +33,7 @@ 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()); - RandomAccessFile raf = (RandomAccessFile) iosp.sendIospMessage(NetcdfFile.IOSP_MESSAGE_RANDOM_ACCESS_FILE); - NetcdfFile ncfile = NetcdfFiles.build(iosp, raf, getLocation(), null); - return NetcdfDatasets.enhance(ncfile, NetcdfDataset.getDefaultEnhanceMode(), null); + return buildNetcdfDataset(iosp, getLocation()); } @Override @@ -45,9 +41,7 @@ public ucar.nc2.dt.grid.GridDataset getGridDataset(Dataset ds, GroupGC group, St 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()); - RandomAccessFile raf = (RandomAccessFile) iosp.sendIospMessage(NetcdfFile.IOSP_MESSAGE_RANDOM_ACCESS_FILE); - NetcdfFile ncfile = NetcdfFiles.build(iosp, raf, getLocation(), null); - NetcdfDataset ncd = NetcdfDatasets.enhance(ncfile, NetcdfDataset.getDefaultEnhanceMode(), null); + NetcdfDataset ncd = buildNetcdfDataset(iosp, getLocation()); return new ucar.nc2.dt.grid.GridDataset(ncd); } diff --git a/grib/src/main/java/ucar/nc2/grib/collection/Grib2Collection.java b/grib/src/main/java/ucar/nc2/grib/collection/Grib2Collection.java index 2d17f4f42e..0430891b54 100644 --- a/grib/src/main/java/ucar/nc2/grib/collection/Grib2Collection.java +++ b/grib/src/main/java/ucar/nc2/grib/collection/Grib2Collection.java @@ -6,7 +6,6 @@ package ucar.nc2.grib.collection; import javax.annotation.Nullable; -import ucar.nc2.dataset.NetcdfDatasets; import ucar.nc2.grib.coord.CoordinateTimeAbstract; import ucar.ma2.Array; import ucar.nc2.*; @@ -21,7 +20,6 @@ import ucar.nc2.grib.GribTables; import ucar.nc2.grib.coverage.GribCoverageDataset; import ucar.nc2.grib.grib2.table.Grib2Tables; -import ucar.unidata.io.RandomAccessFile; import ucar.unidata.util.StringUtil2; import java.io.IOException; import java.util.Formatter; @@ -45,9 +43,7 @@ public ucar.nc2.dataset.NetcdfDataset getNetcdfDataset(Dataset ds, GroupGC group if (filename == null) { Grib2Iosp iosp = new Grib2Iosp(group, ds.getType()); - RandomAccessFile raf = (RandomAccessFile) iosp.sendIospMessage(NetcdfFile.IOSP_MESSAGE_RANDOM_ACCESS_FILE); - NetcdfFile ncfile = NetcdfFiles.build(iosp, raf, getLocation(), null); - return NetcdfDatasets.enhance(ncfile, NetcdfDataset.getDefaultEnhanceMode(), null); + return buildNetcdfDataset(iosp, getLocation()); } else { MFile wantFile = findMFileByName(filename); @@ -58,9 +54,7 @@ public ucar.nc2.dataset.NetcdfDataset getNetcdfDataset(Dataset ds, GroupGC group return null; Grib2Iosp iosp = new Grib2Iosp(gc); - RandomAccessFile raf = (RandomAccessFile) iosp.sendIospMessage(NetcdfFile.IOSP_MESSAGE_RANDOM_ACCESS_FILE); - NetcdfFile ncfile = NetcdfFiles.build(iosp, raf, getLocation(), null); - return NetcdfDatasets.enhance(ncfile, NetcdfDataset.getDefaultEnhanceMode(), null); + return buildNetcdfDataset(iosp, getLocation()); } return null; } @@ -73,9 +67,7 @@ public ucar.nc2.dt.grid.GridDataset getGridDataset(Dataset ds, GroupGC group, St if (filename == null) { Grib2Iosp iosp = new Grib2Iosp(group, ds.getType()); - RandomAccessFile raf = (RandomAccessFile) iosp.sendIospMessage(NetcdfFile.IOSP_MESSAGE_RANDOM_ACCESS_FILE); - NetcdfFile ncfile = NetcdfFiles.build(iosp, raf, getLocation() + "#" + group.getId(), null); - NetcdfDataset ncd = NetcdfDatasets.enhance(ncfile, NetcdfDataset.getDefaultEnhanceMode(), null); + NetcdfDataset ncd = buildNetcdfDataset(iosp, getLocation() + "#" + group.getId()); return new ucar.nc2.dt.grid.GridDataset(ncd); // LOOK - replace with custom GridDataset?? } else { @@ -87,9 +79,7 @@ public ucar.nc2.dt.grid.GridDataset getGridDataset(Dataset ds, GroupGC group, St return null; Grib2Iosp iosp = new Grib2Iosp(gc); - RandomAccessFile raf = (RandomAccessFile) iosp.sendIospMessage(NetcdfFile.IOSP_MESSAGE_RANDOM_ACCESS_FILE); - NetcdfFile ncfile = NetcdfFiles.build(iosp, raf, getLocation(), null); - NetcdfDataset ncd = NetcdfDatasets.enhance(ncfile, NetcdfDataset.getDefaultEnhanceMode(), null); + NetcdfDataset ncd = buildNetcdfDataset(iosp, getLocation()); return new ucar.nc2.dt.grid.GridDataset(ncd); // LOOK - replace with custom GridDataset?? } return null; diff --git a/grib/src/main/java/ucar/nc2/grib/collection/Grib2Partition.java b/grib/src/main/java/ucar/nc2/grib/collection/Grib2Partition.java index 1f7073b59a..6ab3716d76 100644 --- a/grib/src/main/java/ucar/nc2/grib/collection/Grib2Partition.java +++ b/grib/src/main/java/ucar/nc2/grib/collection/Grib2Partition.java @@ -11,15 +11,11 @@ import thredds.featurecollection.FeatureCollectionConfig; import ucar.nc2.Attribute; import ucar.nc2.AttributeContainer; -import ucar.nc2.NetcdfFile; -import ucar.nc2.NetcdfFiles; import ucar.nc2.constants.CDM; import ucar.nc2.constants.DataFormatType; import ucar.nc2.dataset.NetcdfDataset; -import ucar.nc2.dataset.NetcdfDatasets; import ucar.nc2.ft2.coverage.CoverageCollection; import ucar.nc2.grib.coverage.GribCoverageDataset; -import ucar.unidata.io.RandomAccessFile; /** * PartitionCollection for Grib2. @@ -38,9 +34,7 @@ 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()); - RandomAccessFile raf = (RandomAccessFile) iosp.sendIospMessage(NetcdfFile.IOSP_MESSAGE_RANDOM_ACCESS_FILE); - NetcdfFile ncfile = NetcdfFiles.build(iosp, raf, getLocation(), null); - return NetcdfDatasets.enhance(ncfile, NetcdfDataset.getDefaultEnhanceMode(), null); + return buildNetcdfDataset(iosp, getLocation()); } @Override @@ -48,9 +42,7 @@ public ucar.nc2.dt.grid.GridDataset getGridDataset(Dataset ds, GroupGC group, St 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()); - RandomAccessFile raf = (RandomAccessFile) iosp.sendIospMessage(NetcdfFile.IOSP_MESSAGE_RANDOM_ACCESS_FILE); - NetcdfFile ncfile = NetcdfFiles.build(iosp, raf, getLocation(), null); - NetcdfDataset ncd = NetcdfDatasets.enhance(ncfile, NetcdfDataset.getDefaultEnhanceMode(), null); + NetcdfDataset ncd = buildNetcdfDataset(iosp, getLocation()); return new ucar.nc2.dt.grid.GridDataset(ncd); } diff --git a/grib/src/main/java/ucar/nc2/grib/collection/GribCollectionImmutable.java b/grib/src/main/java/ucar/nc2/grib/collection/GribCollectionImmutable.java index f1790e43cd..53dc60f9b5 100644 --- a/grib/src/main/java/ucar/nc2/grib/collection/GribCollectionImmutable.java +++ b/grib/src/main/java/ucar/nc2/grib/collection/GribCollectionImmutable.java @@ -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.*; @@ -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; @@ -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