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