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

Contents of /MITgcm_contrib/gael/matlab_class/gcmfaces_IO/ncdefVar.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 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

  ViewVC Help
Powered by ViewVC 1.1.22