MATLAB Answers

error using netcdf.getVar

75 views (last 30 days)
Damiano Pasetto
Damiano Pasetto on 6 Mar 2017
Answered: lucksoftware on 6 Aug 2020
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 Comment

mv2195
mv2195 on 2 May 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?

Sign in to comment.

Answers (4)

KSSV
KSSV on 6 Mar 2017
Edited: KSSV on 6 Mar 2017
There are other easy commands like ncdisp, ncinfo, ncread. I advise you to use these easy functions to read nc files.

  4 Comments

Show 1 older comment
KSSV
KSSV on 6 Mar 2017
You are accessing the file via link or it is present in your folder?
Damiano Pasetto
Damiano Pasetto on 6 Mar 2017
via link. The other netcdf commands (as ncdisp, ncinfo) are working well. Should I download the whole file? How?
KSSV
KSSV on 7 Mar 2017
When ncdisp and ncinfo working, you shall get this too. Check are you calling the variable in right manner.

Sign in to comment.


Matt
Matt on 21 Mar 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 Comments

Show 1 older comment
Damiano Pasetto
Damiano Pasetto on 22 Mar 2017
So, it is a common problem! I was told to try to download the data from different sites, but I still have to try. Hope to solve this soon.
Matt
Matt on 24 Mar 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 on 24 Mar 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...

Sign in to comment.


fuchang wang
fuchang wang on 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.

  0 Comments

Sign in to comment.


lucksoftware
lucksoftware on 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.

  0 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by