Close netcdf files on errors