Error using netcdflib, error in netcdf.open

163 views (last 30 days)
Barbara Bentz
Barbara Bentz on 3 May 2021
Commented: chao wei on 7 Mar 2022
My code to open and download files from a OPeNDAP URL is no longer working. It was working great, then all of a sudden I get errors. I am using Matlab R2020a. Thanks for the help. Barbara
*******
The NetCDF library encountered an error during execution of 'open' function - 'Malformed or inaccessible DAP DDS
(NC_EDDS)'. If the data source was an OPeNDAP URL, see the OPeNDAP Troubleshooting section in the Users Guide.
Error in netcdf.open (line 67)
[varargout{:}] = netcdflib ( 'open', filename, varargin{1} );
Error in internal.matlab.imagesci.nc/openToRead (line 1278)
this.ncRootid = netcdf.open(this.Filename,'NOWRITE');
Error in internal.matlab.imagesci.nc (line 121)
this.openToRead();
Error in ncread (line 61)
ncObj = internal.matlab.imagesci.nc(ncFile);
********
Code:
myVar = 'tmin';
myURL = ['http://thredds.northwestknowledge.net:8080/thredds/dodsC/agg_terraclimate_',myVar,'_1958_CurrentYear_GLOBE.nc'];
latList=[41 44 45 41]; %list of north latitudes for each point location
lonList=[-110 -100 -101 -95]; %list of East longitudes for each point location
NUM_POINTS = length(latList');
year_start = 1980;
month_start=1;
year_end = 2019;
month_end=12;
%===================================================
timebounds_start =datenum(year_start,month_start,1)-datenum(1900,1,1);
timebounds_end = datenum(year_end,month_end,1)-datenum(1900,1,1);
timebounds = [timebounds_start timebounds_end];
lat=ncread(myURL,'lat');
lon=ncread(myURL,'lon');
time=ncread(myURL,'time');
[Y,M,D]=datevec(time+datenum(1900,1,1));
ftimei=find(time>=timebounds(1) & time<=timebounds(2));
time = time(ftimei);
NUM_TIME= length(time);
myData = NaN(NUM_POINTS,NUM_TIME);
myLat = NaN(NUM_POINTS,1);
myLon = NaN(NUM_POINTS,1);
for i= 1:NUM_POINTS;
[dist,flati]=min(abs(lat-latList(i)));
[dist,floni]=min(abs(lon-lonList(i)));
myLat(i)=lat(flati);
myLon(i)=lon(floni);
myData(i,:)=ncread(myURL,myVar,[floni(1) flati(1) ftimei(1)],[length(floni) length(flati) length(ftimei)],[1 1 1]);
end;

Answers (1)

Prabhan Purwar
Prabhan Purwar on 11 May 2021
Hi Barbara,
This is a known issue with the NetCDF library in R2020a and is now fixed in R2020b and further releases.
The easiest workaround is to upgrade to R2020b or R2021a.
Please let me know if you are still having any concerns.
Thanks
  2 Comments
chao wei
chao wei on 7 Mar 2022
Pleat try this with full path filename

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