Skip to content

Commit

Permalink
Reverse a minor change to NetCDF file reading, #130.
Browse files Browse the repository at this point in the history
  • Loading branch information
james-d-brown committed Jan 16, 2025
1 parent 1e3ba64 commit 4ed5962
Showing 1 changed file with 24 additions and 30 deletions.
54 changes: 24 additions & 30 deletions wres-reading/src/wres/reading/netcdf/nwm/NwmTimeSeries.java
Original file line number Diff line number Diff line change
Expand Up @@ -498,38 +498,32 @@ String readAttributeAsString( String variableName, String attributeName )
{
// Use the very first netcdf file, assume homogeneity.
Variable variableVariable;
try ( NetcdfFile netcdfFile = this.getNetcdfFiles()
.iterator()
.next() )
{
variableVariable = netcdfFile.findVariable( variableName );
NetcdfFile netcdfFile = this.getNetcdfFiles()
.iterator()
.next();
variableVariable = netcdfFile.findVariable( variableName );

if ( variableVariable == null )
{
Set<String> variables = netcdfFile.getVariables()
.stream()
.map( Variable::getFullName )
.collect( Collectors.toSet() );

// Remove the metadata variables
variables.remove( "time" );
variables.remove( "reference_time" );
variables.remove( "feature_id" );
variables.remove( "crs" );

throw new IllegalArgumentException( "There was no variable '"
+ variableName
+ "' in the netCDF blob at '"
+ netcdfFile.getLocation()
+ "'. The blob contained the following readable variables: "
+ variables
+ ". Please declare one of these case-sensitive variable names to "
+ "evaluate." );
}
}
catch ( IOException e )
if ( variableVariable == null )
{
throw new IllegalStateException( "Could not read the NetCDF data.", e );
Set<String> variables = netcdfFile.getVariables()
.stream()
.map( Variable::getFullName )
.collect( Collectors.toSet() );

// Remove the metadata variables
variables.remove( "time" );
variables.remove( "reference_time" );
variables.remove( "feature_id" );
variables.remove( "crs" );

throw new IllegalArgumentException( "There was no variable '"
+ variableName
+ "' in the netCDF blob at '"
+ netcdfFile.getLocation()
+ "'. The blob contained the following readable variables: "
+ variables
+ ". Please declare one of these case-sensitive variable names to "
+ "evaluate." );
}

return NwmTimeSeries.readAttributeAsString( variableVariable, attributeName );
Expand Down

0 comments on commit 4ed5962

Please sign in to comment.