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

조회 수: 12 (최근 30일)
Hello,
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\LC08_L1TP_001017_20140508_20200911_02_T1_redo_polymer.nc')
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 internal.matlab.imagesci.nc/read (line 644)
data = netcdf.getVar(gid, varid);
Error in ncread (line 74)
vardata = ncObj.read(varName, varargin{:});
Error in ReadingPolymerNetCDFs (line 6)
lon = ncread(ncfile,'longitude') ;
Any help is greatly appreciated!
Sydney

채택된 답변

Vatsal
Vatsal 2023년 9월 26일
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
Sydney Baratta
Sydney Baratta 2023년 9월 28일
Hello,
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!
Sydney

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 NetCDF에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by