From 4ed5962bddd74a92201220a8414f0ae1dc8b5b0d Mon Sep 17 00:00:00 2001 From: James Brown <64858662+james-d-brown@users.noreply.github.com> Date: Thu, 16 Jan 2025 18:25:18 +0000 Subject: [PATCH] Reverse a minor change to NetCDF file reading, #130. --- .../reading/netcdf/nwm/NwmTimeSeries.java | 54 +++++++++---------- 1 file changed, 24 insertions(+), 30 deletions(-) diff --git a/wres-reading/src/wres/reading/netcdf/nwm/NwmTimeSeries.java b/wres-reading/src/wres/reading/netcdf/nwm/NwmTimeSeries.java index c8ef10fcf..266424aa6 100644 --- a/wres-reading/src/wres/reading/netcdf/nwm/NwmTimeSeries.java +++ b/wres-reading/src/wres/reading/netcdf/nwm/NwmTimeSeries.java @@ -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 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 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 );