| title | Runtime loading |
|---|---|
| last_updated | 2025-08-12 |
| sidebar | netcdfJavaTutorial_sidebar |
| permalink | runtime_loading.html |
| toc | false |
These are the various classes that can be plugged in at runtime:
- The recommended way is to use the Service Provider{:target="_blank"}
mechanism and include your IOSP in a JAR on the classpath, where it is dynamically loaded at runtime. In your
JAR, include a file named
META-INF/services/ucar.nc2.iosp.IOServiceProvidercontaining the name(s) of your implementations, eg:
ucar.nc2.iosp.fysat.Fysatiosp
ucar.nc2.iosp.gini.Giniiosp
- Alternatively, from your code, register your IOSP by calling:
{% capture rmd %} {% includecodeblock netcdf-java&docs/src/test/java/examples/runtime/runtimeloadingTutorial.java®isterIOSP %} {% endcapture %} {{ rmd | markdownify }}
In both cases, your class must implement ucar.nc2.iosp.IOServiceProvider.
When NetcdfFiles.open() is called, we call getIosp() and loop through the IOServiceProvider classes calling isValidFile() on each until one returns true. This method is fast and accurate to insure efficient registration.
From your code, register your CoordSystemBuilder by calling:
{% capture rmd %} {% includecodeblock netcdf-java&docs/src/test/java/examples/runtime/runtimeloadingTutorial.java®isterCoordSystemBuilder %} {% endcapture %} {{ rmd | markdownify }}
The registered class must implement ucar.nc2.dataset.CoordSystemFactory. The NetcdfDataset is checked if it has a Convention attribute, and if so,
it is matched by conventionName. If not, loop through the CoordSystemFactory classes and call findConventionByIsMine() on each, until one returns true.
If none are found, use the default _Coordinate convention.
{% capture rmd %} {% includecodeblock netcdf-java&docs/src/test/java/examples/runtime/runtimeloadingTutorial.java®isterCoordTransBuilder %} {% endcapture %} {{ rmd | markdownify }}
The registered class must implement ucar.nc2.internal.dataset.CoordTransformFactory. The Coordinate Transform Variable must have the transform name as one of its parameters.
{% capture rmd %} {% includecodeblock netcdf-java&docs/src/test/java/examples/runtime/runtimeloadingTutorial.java®isterFeatureDatasetFactory %} {% endcapture %} {{ rmd | markdownify }}
The registered class must implement ucar.nc2.ft.FeatureDatasetFactory.
{% capture rmd %} {% includecodeblock netcdf-java&docs/src/test/java/examples/runtime/runtimeloadingTutorial.java®isterGRIBTable %} {% endcapture %} {{ rmd | markdownify }}
This registers a single table for the given center/subcenter/version. See GribTables for more information about parameter tables. Note: GRIB2 table handling is still being developed.
{% capture rmd %} {% includecodeblock netcdf-java&docs/src/test/java/examples/runtime/runtimeloadingTutorial.java®isterGRIBLookupTable %} {% endcapture %} {{ rmd | markdownify }}
This registers one or more tables for different center/subcenter/versions. See GribTables for more information about lookup tables. Note: GRIB2 table handling is still being developed.
{% capture rmd %} {% includecodeblock netcdf-java&docs/src/test/java/examples/runtime/runtimeloadingTutorial.java®isterBUFRTable %} {% endcapture %} {{ rmd | markdownify }}
The file must be a BUFR table lookup file.
Users-supplied filters must be provided using the Service Provider{:target="_blank"}
mechanism and included in a JAR on the classpath, where it is dynamically loaded at runtime.
In your JAR, include a file named META-INF/services/ucar.nc2.filter.FilterProvider containing the name(s) of your implementations, eg:
ucar.nc2.filter.BloscFilter
ucar.nc2.filter.GZipFilter
Your FilterProvider classes must implement the ucar.nc2.filter.FilterProvider interface.
See here for details on implementing user-supplied filters.
Instead of calling the above routines in your code, you can pass the CDM library an XML configuration file.
Note that your application must call ucar.nc2.util.xml.RuntimeConfigParser.read().
The configuration file looks like this:
<?xml version='1.0' encoding='UTF-8'?>
<runtimeConfig>
1) <ioServiceProvider class='edu.univ.ny.stuff.FooFiles'/>
2) <coordSystemBuilderFactory convention='foo' class='test.Foo'/>
3) <coordTransformFactory name='atmos_ln_sigma_coordinates' type='vertical' class='my.stuff.atmosSigmaLog'/>
4) <featureDatasetFactory featureType='Point' class='gov.noaa.obscure.file.Flabulate'/>
5) <gribParameterTable edition='1' center='58' subcenter='-1' version='128'>C:/grib/tables/ons288.xml</gribParameterTable>
6) <gribParameterTableLookup edition='1'>C:/grib/tables/ncepLookup.txt</gribParameterTableLookup>
7) <bufrtable filename='C:/my/files/lookup.txt' />
8) <grib1Table strict='false'/>
9) <Netcdf4Clibrary>
<libraryPath>/usr/local/lib</libraryPath>
<libraryName>netcdf</libraryName>
<useForReading>false</useForReading>
</Netcdf4Clibrary>
</runtimeConfig>- Loads an
IOServiceProviderwith the given class name - Loads a
CoordSysBuilderIFwith the given class name, which looks for the givenConventionattribute value. - Loads a
CoordTransformFactorywith the given class name, which looks for the giventransformNamein the dataset. The type must be vertical or projection. - Loads a
FeatureDatasetFactorywith the given class name which openFeatureDatasetsof the givenfeatureType. - Load a GRIB-1 parameter table (as of version 4.3)
- Load a GRIB-1 parameter table lookup (as of version 4.3)
- Load a BUFR table lookup file.
- Turn strict GRIB1 table handling off.
- Configure how the NetCDF-4 C library is discovered and used.
libraryPath: The directory in which the native library is installed.libraryName: The name of the native library. This will be used to locate the proper.DLL,.SO, or.DYLIBfile within thelibraryPathdirectory.useForReading: By default, the native library is only used for writing NetCDF-4 files; a pure-Java layer is responsible for reading them. However, if this property is set totrue, then it will be used for reading NetCDF-4 (and HDF5) files as well.
There are several ways pass the Runtime Configuration XML to the CDM library. From your application, you can pass a java.io.InputStream (or JDOM element) to
ucar.nc2.util.xml.RuntimeConfigParser, as in the following examples:
{% capture rmd %} {% includecodeblock netcdf-java&docs/src/test/java/examples/runtime/runtimeloadingTutorial.java&passConfigurationToCDM %} {% endcapture %} {{ rmd | markdownify }}
For example, the ToolsUI application allows you to specify this file on the command line with the -nj22Config parameter:
{% capture rmd %} {% includecodeblock netcdf-java&docs/src/test/java/examples/runtime/runtimeloadingTutorial.java&passConfigurationToolsUI %} {% endcapture %} {{ rmd | markdownify }}
If none is specified on the command line, it will look for the XML document in $USER_HOME/.unidata/nj22Config.xml.