NetCDF allows multiple sets of measurement grids in a single file. One single set of measurements, such as salinity or temperature,
constitutes a variable.
By default, the TLcdNetCDFModelDecoder
decodes all variables, creating an ILcdModel
for each variable.
You can retrieve the list of variables of a particular dataset by calling the decoder’s discoverDataSources
method. To decode only a subset of the file, pass one of the returned data sources to the decoder’s decode
method again.
The discoverDataSources
method returns a list of TLcdNetCDFDataSource
and TLcdNetCDFMultiBandDataSource
instances.
To identify the type of data that is represented by a TLcdNetCDFDataSource
, you can retrieve the full name of the NetCDf variable using the TLcdNetCDFDataSource.getName()
method.
To identify the type of data that is represented by a TLcdNetCDFMultiBandDataSource
, you can retrieve the TLcdNetCDFDataSource
sources that are part of the multi-band source by using the TLcdNetCDFMultiBandDataSource.getDataSources()
method.
TLcdNetCDFModelDecoder decoder = new TLcdNetCDFModelDecoder();
String source = "Data/NetCDF/wind_u.nc";
List<ILcdDataSource> allDataSources = decoder.discoverDataSources(source);
//Filter the available data sources
List<TLcdNetCDFDataSource> filteredDataSources =
allDataSources.stream()
.filter(dataSource -> dataSource instanceof TLcdNetCDFDataSource)
.map(dataSource -> (TLcdNetCDFDataSource) dataSource)
.filter(dataSource -> dataSource.getName().toLowerCase().contains("u-component"))
.collect(Collectors.toList());
//Only pass the data sources in which we are interested to the model decoder
ILcdModel model = decoder.decodeSource(new TLcdNetCDFMultiBandDataSource(filteredDataSources));