Skip to content
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
24 changes: 19 additions & 5 deletions tds/src/main/java/thredds/server/config/TdsInit.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
import thredds.server.ncss.format.SupportedFormat;
import thredds.server.notebook.JupyterNotebookServiceCache;
import ucar.nc2.NetcdfFile;
import ucar.nc2.NetcdfFiles;
import ucar.nc2.dataset.NetcdfDataset;
import ucar.nc2.dataset.NetcdfDatasets;
import ucar.nc2.ffi.netcdf.NetcdfClibrary;
import ucar.nc2.grib.GribIndexCache;
import ucar.nc2.grib.collection.GribCdmIndex;
import ucar.nc2.jni.netcdf.Nc4Iosp;
Expand Down Expand Up @@ -161,7 +163,6 @@ private void setDebugFlags(DebugFlags debugFlags) {
ucar.nc2.ncml.NcMLReader.setDebugFlags(debugFlags);
ucar.nc2.dods.DODSNetcdfFile.setDebugFlags(debugFlags);
CdmRemote.setDebugFlags(debugFlags);
Nc4Iosp.setDebugFlags(debugFlags);
DataFactory.setDebugFlags(debugFlags);

ucar.nc2.FileWriter2.setDebugFlags(debugFlags);
Expand Down Expand Up @@ -276,16 +277,28 @@ private void readThreddsConfig() {
String libraryPath = ThreddsConfig.get("Netcdf4Clibrary.libraryPath", null);
String libraryName = ThreddsConfig.get("Netcdf4Clibrary.libraryName", null);
if (libraryPath != null || libraryName != null) {
Nc4Iosp.setLibraryAndPath(libraryPath, libraryName);
// must be called before any calls to Nc4Iosp
NetcdfClibrary.setLibraryNameAndPath(libraryPath, libraryName);
}

Boolean useForReading = ThreddsConfig.getBoolean("Netcdf4Clibrary.useForReading", false);
// needed to delay setting Nc4Iosp debug flags, in case threddsConfig was
// used to set library name and path
if (NetcdfClibrary.isLibraryPresent()) {
String tdsDebugFlags = tdsContext.getTdsDebugFlags();
if (!tdsDebugFlags.isEmpty()) {
startupLog.info("TdsInit: setting Nc4Iosp debug flags");
Nc4Iosp.setDebugFlags(new DebugFlagsImpl(tdsDebugFlags));
}
}

boolean useForReading = ThreddsConfig.getBoolean("Netcdf4Clibrary.useForReading", false);
if (useForReading) {
if (Nc4Iosp.isClibraryPresent()) {
if (NetcdfClibrary.isLibraryPresent()) {
try {
// Registers Nc4Iosp in front of all the other IOSPs already registered in NetcdfFile.<clinit>().
// Crucially, this means that we'll try to open a file with Nc4Iosp before we try it with H5iosp.
NetcdfFile.registerIOProvider(Nc4Iosp.class);
NetcdfFiles.registerIOProvider(Nc4Iosp.class);
} catch (IllegalAccessException | InstantiationException e) {
startupLog.error("TdsInit: Unable to register IOSP: " + Nc4Iosp.class.getCanonicalName(), e);
}
Expand All @@ -295,7 +308,8 @@ private void readThreddsConfig() {
}
}

if (Nc4Iosp.isClibraryPresent()) { // NetCDF-4 lib could be set as an environment variable or as a JVM parameter.
if (NetcdfClibrary.isLibraryPresent()) { // NetCDF-4 lib could be set as an environment variable or as a JVM
// parameter.
FormatsAvailabilityService.setFormatAvailability(SupportedFormat.NETCDF4, true);
FormatsAvailabilityService.setFormatAvailability(SupportedFormat.NETCDF4EXT, true);
}
Expand Down