1 |
function ncaddVar(ncid,varname,xtype,dimlist); |
function ncaddVar(ncid,varname,xtype,dimlist); |
2 |
% add a variable in an existing netcdf file. |
% function ncaddVar(ncid,varname,xtype,dimlist); |
3 |
|
% add a variable in an existing netcdf file. |
4 |
|
|
5 |
global useNativeMatlabNetcdf; |
global useNativeMatlabNetcdf; |
6 |
if isempty(useNativeMatlabNetcdf); useNativeMatlabNetcdf = ~isempty(which('netcdf.open')); end; |
if isempty(useNativeMatlabNetcdf); useNativeMatlabNetcdf = ~isempty(which('netcdf.open')); end; |
7 |
|
|
8 |
if useNativeMatlabNetcdf; |
if useNativeMatlabNetcdf; |
9 |
if isempty(dimlist), error('nddefVar error: no dimensions allocated'); end |
if isempty(dimlist), error('ncaddVar error: no dimension allocated'); end |
10 |
iDim=[]; |
iDim=[]; |
11 |
for ii=1:length(dimlist), |
for ii=1:length(dimlist), |
12 |
iDim(ii)=netcdf.inqDimID(ncid,dimlist{ii}); |
iDim(ii)=netcdf.inqDimID(ncid,dimlist{ii}); |
25 |
case 3, |
case 3, |
26 |
sprintf('ncid{''%s''}=nc%s(''%s'',''%s'',''%s'');',varname,xtype,dimlist{1},dimlist{2},dimlist{3}); |
sprintf('ncid{''%s''}=nc%s(''%s'',''%s'',''%s'');',varname,xtype,dimlist{1},dimlist{2},dimlist{3}); |
27 |
otherwise |
otherwise |
28 |
error('ncdefVar: number of dimension > 3'); |
error('ncaddVar: number of dimension > 3'); |
29 |
end |
end |
30 |
end; |
end; |
31 |
|
|