1 |
gforget |
1.1 |
function varid = ncdefVar(ncid,varname,xtype,dimlist); |
2 |
|
|
% add a variable in a netcdf file. |
3 |
|
|
|
4 |
|
|
global useNativeMatlabNetcdf; |
5 |
|
|
if isempty(useNativeMatlabNetcdf); useNativeMatlabNetcdf = ~isempty(which('netcdf.open')); end; |
6 |
|
|
|
7 |
|
|
if useNativeMatlabNetcdf; |
8 |
|
|
if isempty(dimlist), error('ncdefVar error: no dimension allocated'); end |
9 |
|
|
iDim=[]; |
10 |
|
|
for ii=1:length(dimlist), |
11 |
|
|
iDim(ii)=netcdf.inqDimID(ncid,dimlist{ii}); |
12 |
|
|
end |
13 |
|
|
netcdf.defVar(ncid,varname,xtype,iDim); |
14 |
|
|
else;%try to use old mex stuff |
15 |
|
|
% inverse the order of list dimensions |
16 |
|
|
dimlist=fliplr(dimlist); |
17 |
|
|
switch length(dimlist) |
18 |
|
|
case 1, |
19 |
|
|
eval(sprintf('ncid{''%s''}=nc%s(''%s'');',varname,xtype,dimlist{1})); |
20 |
|
|
case 2, |
21 |
|
|
eval(sprintf('ncid{''%s''}=nc%s(''%s'',''%s'');',varname,xtype,dimlist{1},dimlist{2})); |
22 |
|
|
case 3, |
23 |
|
|
eval(sprintf('ncid{''%s''}=nc%s(''%s'',''%s'',''%s'');',varname,xtype,dimlist{1},dimlist{2},dimlist{3})); |
24 |
|
|
otherwise |
25 |
|
|
error('ncdefVar: number of dimension > 3'); |
26 |
|
|
end |
27 |
|
|
end; |
28 |
|
|
|
29 |
|
|
|