Error reading NetCDF file: 'getVarDouble' function - 'HDF error (NC_EHDFERR)'

23 visualizzazioni (ultimi 30 giorni)
I am trying to read in different variables from a netCDF with 'ncread', but am encountering an error when trying to call in latitude and logitude (but not with any other variables)
My code:
ncfile =('D:\sydneysDrive\imagery\POLYMER\POLYMER_output\')
chl = ncread(ncfile,'logchl') ;
red = ncread(ncfile,'Rw655') ;
nir = ncread(ncfile,'Rw865') ;
lon = ncread(ncfile,'longitude') ;
lat = ncread(ncfile,'latitude') ;
My error:
Error using matlab.internal.imagesci.netcdflib
The NetCDF library encountered an error during execution of 'getVarDouble' function - 'HDF error (NC_EHDFERR)'.
Error in netcdf.getVar (line 205)
data = matlab.internal.imagesci.netcdflib(funcstr,ncid,varid,varargin{:});
Error in (line 644)
data = netcdf.getVar(gid, varid);
Error in ncread (line 74)
vardata =, varargin{:});
Error in ReadingPolymerNetCDFs (line 6)
lon = ncread(ncfile,'longitude') ;
Any help is greatly appreciated!

Risposta accettata

Vatsal il 26 Set 2023
Hi @Sydney Baratta,
I understand that you are getting the “NC_EHDFERR” error while reading variables ‘latitude’ and ‘longitude’.
Based on the error message you received ('HDF error (NC_EHDFERR)'), it is likely that the netCDF file you are working with is corrupted. To investigate further, it would be helpful to determine if the error is specific to MATLAB or if it persists when using other tools.
I recommend using third-party tools, such as the Python netcdf4 package, to read the netCDF file. This will allow you to verify if the error persists and help identify any potential issues with the file itself. You can find a tutorial on reading netCDF data using Python in the following article:
Please try using the Python netcdf4 package to read the file and observe if the same error occurs. This will provide valuable information for troubleshooting the issue further.
  1 Commento
Sydney Baratta
Sydney Baratta il 28 Set 2023
Thank you. It does look like the files were corrupted (not a MATLAB issue), but rerunning through the program I was working in solved it.
Thank you!

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by