/[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.4 - (hide annotations) (download)
Thu Apr 14 23:35:42 2011 UTC (14 years, 3 months ago) by roquet
Branch: MAIN
CVS Tags: checkpoint65r, checkpoint65p, checkpoint65q
Changes since 1.3: +6 -4 lines
bug fix for old netcdf toolbox + new function to get a variable.

1 gforget 1.1 function []=ncputvar(nc,VARname,VARvalue,varargin);
2 roquet 1.3 % []=ncputvar(ncid,varid,data,[start,count])
3     % write data to MITprof netcdf file
4 gforget 1.1
5     global useNativeMatlabNetcdf; if isempty(useNativeMatlabNetcdf); useNativeMatlabNetcdf = ~isempty(which('netcdf.open')); end;
6    
7 roquet 1.2 if useNativeMatlabNetcdf
8 gforget 1.1
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 roquet 1.4
29 gforget 1.1
30     else;%try to use old mex stuff
31 roquet 1.2
32 roquet 1.4 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 gforget 1.1 else;
37 roquet 1.4 eval(['nc{''' VARname '''}(:)=VARvalue;']);
38 gforget 1.1 end;
39 roquet 1.2
40 gforget 1.1 end;

  ViewVC Help
Powered by ViewVC 1.1.22