adding drawfire
[wrf-fire-matlab.git] / netcdf / ncreplace.m
blobddd141772fe669b3a9acc93b52467a8354143abb
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
10 % transpose
11 % if ndims(value)>1,
12     %v.dimlength=v.dimlength(v.ndims:-1:1);
13         %value=permute(value,[ndims(value):-1:1]);
14 % end
15 [s,c]=getstartcount(v);
16 netcdf.putVar(ncid,varid,s,c,value);
17 netcdf.close(ncid);
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
21 dispvarinfo(v);
22 if(err>1e-6),
23     error('ncreplace','bad replaced value');
24 end
25 end