Clear Filters
Clear Filters

problem with netcdf lib

19 views (last 30 days)
Patrick on 20 Jul 2012
Edited: Walter Roberson on 21 Nov 2015
Here is my function to write a netcdf file. The data I want to write is a matrix (VARI33) of dim (87x81x366). The first part of this function cares about the date and determines a1, which is used as third dimension lateron.
I call the function e.g. as create_ncfile('Tmax',1960,1960,1,1,1,31,1,1,1,VARLIST,lon2,lat2,annual_file_VARI1)
The error warning is :
Error using netcdflib
The NetCDF library encountered an error during execution of 'putVaraDouble' function - 'Start+count
exceeds dimension bound (NC_EEDGE)'.
Error in netcdf.putVar (line 87)
Error in (line 815)
netcdf.putVar(gid, varid,start, count, varData);
Error in ncwrite (line 76)
ncObj.write(varName, varData, start, stride);
Error in create_ncfile (line 37)
ncwrite(path,'Tmax', VARI33);
Here is the code:
function create_ncfile(pat h,Y1,Y2,M1,M2,D1,D2,H1,H2,res,VARILIST,lon1,lat1,VARI33)
n1 = datenum(Y1, M1, D1, H1, 0, 0);
n2 = datenum(Y2, M2, D2, H2, 0, 0);
if res==1;
elseif res==2;
[Y, M, D, H] = datevec(n3);
% for i=1:length(VARILIST);
% nccreate(path,VARILIST(i,1:size(VARILIST,2)),'Dimensions',{'lon' 87 'lat' 81 'time' a1},'Format','classic');
% ncwrite(path,VARILIST(i,1:size(VARILIST,2)),VARI33);
% end
nccreate(path,'Tmax','Dimensions',{'lat' 87 'lon' 81 'time' a1},'Format','classic');
ncwrite(path,'Tmax', VARI33);
nccreate(path,'lon','Dimensions',{'lon' 87},'Format','classic');
ncwrite(path,'lon', lon);
nccreate(path,'lat','Dimensions',{'lat' 81},'Format','classic');
ncwrite(path,'lat', lat);
nccreate(path,'Year','Dimensions',{'d1' a1}, 'Format','classic');
ncwrite(path,'Year', Year);
nccreate(path,'Month','Dimensions',{'d1' a1}, 'Format','classic');
ncwrite(path,'Month', Month);
nccreate(path,'Day','Dimensions',{'d1' a1}, 'Format','classic');
ncwrite(path,'Day', Day);
end %EOF
  1 Comment
Ashish Uthama
Ashish Uthama on 20 Jul 2012
I would suggest putting a breakpoint at line 37, and ensuring that your VARI33 variable has the dimensions 87x81x(value of a1).

Sign in to comment.

Answers (1)

Stephen Po-Chedley
Stephen Po-Chedley on 21 Nov 2015
I recently had a similar problem on a Mac with Matlab R2015b (I don't have this issue with linux). I had the variable dimensions correct (I was reading a file, modifying the content and writing to the same variable). I had to flip the variable ordering. So if my variable was V(time,lat,lon) I had to ensure it was flipped to V(lon,lat,time) via:
V=permute(V,[3 2 1]);
You might need to do the same with VARI33. Or maybe the dimensions aren't exactly right.


Community Treasure Hunt

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

Start Hunting!