1 |
gforget |
1.1 |
function []=ncputvar(nc,VARname,VARvalue,varargin); |
2 |
|
|
|
3 |
|
|
global useNativeMatlabNetcdf; if isempty(useNativeMatlabNetcdf); useNativeMatlabNetcdf = ~isempty(which('netcdf.open')); end; |
4 |
|
|
|
5 |
roquet |
1.2 |
if useNativeMatlabNetcdf |
6 |
gforget |
1.1 |
|
7 |
|
|
%get variable id: |
8 |
|
|
vv = netcdf.inqVarID(nc,VARname); |
9 |
|
|
%flip order of dimensions: |
10 |
|
|
bb=length(size(VARvalue)); VARvalue=permute(VARvalue,[bb:-1:1]); |
11 |
|
|
if nargin>3; |
12 |
|
|
%get and flip position vectors: |
13 |
|
|
VARpos=fliplr(varargin); |
14 |
|
|
%convert VARpos to start,count: |
15 |
|
|
start=[]; count=[]; |
16 |
|
|
for ii=1:length(VARpos); |
17 |
|
|
start=[start VARpos{ii}(1)-1]; |
18 |
|
|
count=[count VARpos{ii}(end)-VARpos{ii}(1)+1]; |
19 |
|
|
end; |
20 |
|
|
%write to file: |
21 |
|
|
netcdf.putVar(nc,vv,start,count,VARvalue); |
22 |
|
|
else; |
23 |
|
|
%write to file: |
24 |
|
|
netcdf.putVar(nc,vv,VARvalue); |
25 |
|
|
end; |
26 |
|
|
|
27 |
|
|
|
28 |
|
|
else;%try to use old mex stuff |
29 |
roquet |
1.2 |
|
30 |
|
|
if nargin>3; |
31 |
|
|
nc{VARname}(varargin{:})=VARvalue; |
32 |
gforget |
1.1 |
else; |
33 |
roquet |
1.2 |
nc{VARname}(:)=VARvalue; |
34 |
gforget |
1.1 |
end; |
35 |
roquet |
1.2 |
|
36 |
gforget |
1.1 |
end; |