/[MITgcm]/MITgcm_contrib/gael/matlab_class/gcmfaces_IO/ncaddVar.m
ViewVC logotype

Contents of /MITgcm_contrib/gael/matlab_class/gcmfaces_IO/ncaddVar.m

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download)
Sun Jan 24 17:05:13 2016 UTC (9 years, 5 months ago) by gforget
Branch: MAIN
CVS Tags: checkpoint65x, checkpoint65v, checkpoint65w, checkpoint65t, checkpoint65u, checkpoint66f, checkpoint66e, checkpoint66d, checkpoint66c, checkpoint66b, checkpoint66a, checkpoint66o, HEAD
- move routines from MITprof/profiles_misc/ to gcmfaces/gcmfaces_IO/
  to allow for nctiles IO without having to rely on MITprof
- these wrapper routines were originally provided by F. Roquet
  that work both with the native implememtation of ncetcf in recent
  Matlab versions and the third party mex codes used earlier

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

  ViewVC Help
Powered by ViewVC 1.1.22