error using netcdf.getVar

31 Ansichten (letzte 30 Tage)
Damiano Pasetto
Damiano Pasetto am 6 Mär. 2017
Kommentiert: BN am 9 Nov. 2022
Hi all, I am trying to access the following file using netcdf in matlab:
url='http://nomads.ncdc.noaa.gov/thredds/dodsC/modeldata/cfsv2_forecast_ts_9mon/2016/201609/20160901/2016090100/prate.01.2016090100.daily.grb2’
and the with the codes
ncid=netcdf.open(url)
prate = netcdf.getVar(ncid, 5, [0,0,0],[1,2,3])
However I receive the following error message
syntax error, unexpected WORD_STRING, expecting WORD_WORD
context: Error { code = 2; message = "The variable `Precipitation%5frate' was not found in the dataset."^;};
Error using netcdflib
The NetCDF library encountered an error during execution of
'getVaraFloat' function - 'Access failure (-77)'.
Error in netcdf.getVar (line 136)
data = netcdflib(funcstr,ncid,varid,varargin{:});
The same code was working without errors the last December, and now I have no idea on how to access the file from matlab. Any idea on how I should proceed?
Thank you,
Damiano
  1 Kommentar
mv2195
mv2195 am 2 Mai 2017
I am having what seems to be a similar issue. The URL is http (not https) and the file has four variables: Latitude, Longitude, Time, and Precipitation. I can successfully ncread the Lat, Lon and Time variables, but neither ncread nor netcdf.getVar are successful for the Precipitation variable. Following are the error messages.
For netcdf.getVar:
Error using netcdflib
The NetCDF library encountered an error during execution of
'getVarFloat' function - 'Access failure (-77)'.
Error in netcdf.getVar (line 136)
data = netcdflib(funcstr,ncid,varid,varargin{:});
With the addition of the following for ncread:
Error in internal.matlab.imagesci.nc/read (line 605)
data = netcdf.getVar(gid, varid);
Error in ncread (line 58)
vardata = ncObj.read(varName, varargin{:});
The only difference I see among the variables based on the info from ncdisp is that Lat, Lon,and Time have one dimension each, while Precipitation has three (Lat,Lon,Time).
Is there something simple I'm missing or is this a more complicated issue?

Melden Sie sich an, um zu kommentieren.

Antworten (4)

KSSV
KSSV am 6 Mär. 2017
Bearbeitet: KSSV am 6 Mär. 2017
There are other easy commands like ncdisp, ncinfo, ncread. I advise you to use these easy functions to read nc files.
  5 Kommentare
KSSV
KSSV am 7 Mär. 2017
When ncdisp and ncinfo working, you shall get this too. Check are you calling the variable in right manner.
BN
BN am 9 Nov. 2022
I have a same issue,
Error using matlab.internal.imagesci.netcdflib
The NetCDF library encountered an error during execution of
'getVarsDouble' function - 'Access failure (-77)'.
Error in netcdf.getVar (line 182)
data =
matlab.internal.imagesci.netcdflib(funcstr,ncid,varid,varargin{:});
Error in internal.matlab.imagesci.nc/read (line 637)
data = netcdf.getVar(gid, varid, ...
Error in ncread (line 66)
vardata = ncObj.read(varName, varargin{:});
I hope one of you could solve it and told me now. please help with this error.

Melden Sie sich an, um zu kommentieren.


Matt
Matt am 21 Mär. 2017
I'm getting the exact same error when trying to get data from a netcdf file in R2016b:
url = 'http://data.nodc.noaa.gov/thredds/dodsC/testdata/mbiddle/veg_test_his_compressed.nc';
ncid = netcdf.open(url);
varid = netcdf.inqVarID(ncid,'Hwave')
data = netcdf.getVar(ncid,varid)
varid =
142
syntax error, unexpected WORD_STRING, expecting WORD_WORD
context: Error { code = 2; message = "The variable `nl%5fvisc2' was not found in the dataset."^;};
Error using netcdflib
The NetCDF library encountered an error during execution of 'getVarFloat' function - 'Access failure (-77)'.
Error in netcdf.getVar (line 136)
data = netcdflib(funcstr,ncid,varid,varargin{:});
Error in coawst_import (line 25)
data = netcdf.getVar(ncid,varid)
All of the other netCDF tools work fine, ncdisp, ncinfo, ncread. Its only an issue when trying to get the data...
  4 Kommentare
Matt
Matt am 24 Mär. 2017
FWIW, I did see this thread https://www.mathworks.com/matlabcentral/answers/248192-problem-with-netcdf-file-downloaded-from-an-opendap-source#answer_195740 talking about https, the file I was trying to open is on https, I just changed the url to http. Maybe that is part of the problem?
Matt
Matt am 24 Mär. 2017
And one more conversation https://www.mathworks.com/matlabcentral/answers/223837-problem-to-access-opendap-data-behind-https-urls, maybe this bugfix will help https://www.mathworks.com/support/bugreports/1072120 unless you are using R2017...

Melden Sie sich an, um zu kommentieren.


fuchang wang
fuchang wang am 30 Jun. 2020
version: R2018a
When ncread('A.nc', 'VAR'), it shows the same Error.
For my case, it is due to the data is not properly downloaded. Redownload it, solving the issue.
Though A.nc can be read by other tools, and new A.nc owes the same file size as the old A.nc. Maybe tiny difference exists.

lucksoftware
lucksoftware am 6 Aug. 2020
I meet exactly the same problem when I am reading a variable from a link via OpenDAP. It turned out that the variable is too larege. Reading the variable part by part solves the problem in my case.

Community Treasure Hunt

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

Start Hunting!

Translated by