/[MITgcm]/MITgcm_contrib/gael/profilesMatlabProcessing/profiles_misc/ncputvar.m
ViewVC logotype

Annotation of /MITgcm_contrib/gael/profilesMatlabProcessing/profiles_misc/ncputvar.m

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


Revision 1.1 - (hide annotations) (download)
Fri Nov 5 21:41:02 2010 UTC (14 years, 8 months ago) by gforget
Branch: MAIN
- make this work both with the legacy mexnc stuff (as before)
  and with the modern matlab native netcdf implementation.

1 gforget 1.1 function []=ncputvar(nc,VARname,VARvalue,varargin);
2    
3     global useNativeMatlabNetcdf; if isempty(useNativeMatlabNetcdf); useNativeMatlabNetcdf = ~isempty(which('netcdf.open')); end;
4    
5     if (useNativeMatlabNetcdf);
6    
7     %get variable id:
8     vv = netcdf.inqVarID(nc,VARname);
9     %flip order of dimensions:
10     bb=length(size(VARvalue)); VARvalue=permute(VARvalue,[bb:-1:1]);
11     if nargin>3;
12     %get and flip position vectors:
13     VARpos=fliplr(varargin);
14     %convert VARpos to start,count:
15     start=[]; count=[];
16     for ii=1:length(VARpos);
17     start=[start VARpos{ii}(1)-1];
18     count=[count VARpos{ii}(end)-VARpos{ii}(1)+1];
19     end;
20     %write to file:
21     netcdf.putVar(nc,vv,start,count,VARvalue);
22     else;
23     %write to file:
24     netcdf.putVar(nc,vv,VARvalue);
25     end;
26    
27    
28     else;%try to use old mex stuff
29     if nargin>3;
30     nc{VARname}(varargin{:})=VARvalue;
31     else;
32     nc{VARname}(:)=VARvalue;
33     end;
34     end;

  ViewVC Help
Powered by ViewVC 1.1.22