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

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

  ViewVC Help
Powered by ViewVC 1.1.22