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

Contents of /MITgcm_contrib/gael/matlab_class/gcmfaces_IO/ncgetvar.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 [VARvalue]=ncgetvar(nc,VARname,varargin)
2 % function [VARvalue]=ncgetvar(nc,VARname, [index_prof, index_depth] )
3 % get data to MITprof netcdf file
4
5 global useNativeMatlabNetcdf;
6 if isempty(useNativeMatlabNetcdf); useNativeMatlabNetcdf = ~isempty(which('netcdf.open')); end;
7
8 if useNativeMatlabNetcdf
9
10 %get variable id:
11 vv = netcdf.inqVarID(nc,VARname);
12 if nargin>2;
13 %get and flip position vectors:
14 VARpos=fliplr(varargin);
15 %convert VARpos to start,count:
16 start=[]; count=[];
17 for ii=1:length(VARpos);
18 start=[start VARpos{ii}(1)-1];
19 count=[count VARpos{ii}(end)-VARpos{ii}(1)+1];
20 end;
21 %write to file:
22 VARvalue=netcdf.getVar(nc,vv,start,count);
23 else;
24 %write to file:
25 VARvalue=netcdf.getVar(nc,vv);
26 end;
27 %flip order of dimensions:
28 bb=length(size(VARvalue)); VARvalue=permute(VARvalue,[bb:-1:1]);
29
30
31 else;%try to use old mex stuff
32
33 if nargin==3;
34 eval(['VARvalue=nc{''' VARname '''}([' num2str(varargin{1}) ']);']);
35 elseif nargin==4,
36 eval(['VARvalue=nc{''' VARname '''}([' num2str(varargin{1}) '],[' num2str(varargin{2}) ']);']);
37 else;
38 eval(['VARvalue=nc{''' VARname '''}(:);']);
39 end;
40
41 end;

  ViewVC Help
Powered by ViewVC 1.1.22