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
instances. To identify the type of data that is represented by this data source, you can retrieve the full name of the NetCDf
variable using the TLcdNetCDFDataSource.getName()
method.
TLcdNetCDFModelDecoder decoder = new TLcdNetCDFModelDecoder();
String source = "Data/NetCDF/wind_u.nc";
List<TLcdNetCDFDataSource> allDataSources = decoder.discoverDataSources(source);
//Filter the available data sources
List<TLcdNetCDFDataSource> filteredDataSources =
allDataSources.stream()
.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));