1 function ncreplace(filename,varname,value)
2 % ncreplace(filename,varname,value)
3 % replace variable value in netcdf file
4 % the number of entries in the variable must match
5 fprintf('ncreplace: open %s\n',filename)
6 ncid = netcdf.open(filename,'NC_WRITE');
7 fprintf('replacing variable %s\n',varname)
8 varid = netcdf.inqVarID(ncid,char(varname));
9 v=ncvarinfo(ncid,varid); % find out all about this variable
12 %v.dimlength=v.dimlength(v.ndims:-1:1);
13 %value=permute(value,[ndims(value):-1:1]);
15 [s,c]=getstartcount(v);
16 netcdf.putVar(ncid,varid,s,c,value);
18 nvalue=ncread(filename,varname);
19 err=big(abs(single(nvalue(:))-single(value(:)))./(abs(nvalue(:))+realmin));
20 v.var_value=value; % just to display the dimension
23 error('ncreplace','bad replaced value');