function varid = ncdefVar(ncid,varname,xtype,dimlist); % add a variable in a netcdf file. global useNativeMatlabNetcdf; if isempty(useNativeMatlabNetcdf); useNativeMatlabNetcdf = ~isempty(which('netcdf.open')); end; if useNativeMatlabNetcdf; if isempty(dimlist), error('nddefVar error: no dimencions allocated'); end iDim=[]; for ii=1:length(dimlist), iDim(ii)=netcdf.inqDimID(ncid,dimlist{ii}); end netcdf.defVar(ncid,varname,xtype,iDim); else;%try to use old mex stuff % inverse the order of list dimensions dimlist=fliplr(dimlist); ncvar(varname,xtype,dimlist,ncid); end;