/[MITgcm]/MITgcm_contrib/gael/matlab_class/gcmfaces_calc/gcmfaces_bindata.m
ViewVC logotype

Annotation of /MITgcm_contrib/gael/matlab_class/gcmfaces_calc/gcmfaces_bindata.m

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


Revision 1.3 - (hide annotations) (download)
Tue Jun 21 21:54:33 2011 UTC (14 years, 1 month ago) by gforget
Branch: MAIN
Changes since 1.2: +3 -3 lines
- bring convert2array calls up to date.

1 gforget 1.1 function [varargout]=gcmfaces_bindata(varargin);
2    
3 gforget 1.2 warning('off','MATLAB:dsearch:DeprecatedFunction');
4    
5 gforget 1.1 global mygrid mytri;
6    
7     if nargin==0;
8     %generate delaunay triangulation:
9     XC=convert2array(mygrid.XC);
10     YC=convert2array(mygrid.YC);
11     %needed so that we do not loose data
12     XC(isnan(XC))=270;
13     YC(isnan(YC))=180;
14     %
15     TRI=delaunay(XC,YC); nxy = prod(size(XC));
16     Stri=sparse(TRI(:,[1 1 2 2 3 3]),TRI(:,[2 3 1 3 1 2]),1,nxy,nxy);
17     %
18     mytri.XC=XC; mytri.YC=YC; mytri.TRI=TRI; mytri.Stri=Stri;
19     %usage: ik=dsearch(mytri.XC,mytri.YC,mytri.TRI,lon,lat,mytri.Stri);
20     % where lon and lat are vector of position
21    
22     elseif nargin==2;
23     %compute grid point vector associated with lon/lat vectors
24     lon=varargin{1}; lat=varargin{2};
25     ik=dsearch(mytri.XC,mytri.YC,mytri.TRI,lon,lat,mytri.Stri);
26     if nargout==1;
27     varargout={ik};
28     elseif nargout==2;
29     jj=ceil(ik/size(mytri.XC,1));
30     ii=ik-(jj-1)*size(mytri.XC,1);
31     varargout={ii}; varargout(2)={jj};
32     else;
33     error('wrong output choice');
34     end;
35     elseif nargin==3;
36     %do the bin average (if nargout==1) or the bin sum+count (if nargout==2)
37     lon=varargin{1}; lat=varargin{2}; obs=varargin{3};
38     ii=find(~isnan(obs)); lon=lon(ii); lat=lat(ii); obs=obs(ii);
39     ik=dsearch(mytri.XC,mytri.YC,mytri.TRI,lon,lat,mytri.Stri);
40    
41     OBS=0*mytri.XC; NOBS=OBS;
42     for k=1:length(ik)
43     NOBS(ik(k))=NOBS(ik(k))+1;
44     OBS(ik(k))=OBS(ik(k))+obs(k);
45     end % k=1:length(ik)
46    
47     if nargout==1;%output bin average
48     in=find(NOBS); OBS(in)=OBS(in)./NOBS(in);
49     in=find(~NOBS); OBS(in)=NaN; NOBS(in)=NaN;
50 gforget 1.3 varargout={convert2array(OBS)};
51 gforget 1.1 elseif nargout==2;%output bin sum+count
52 gforget 1.3 OBS=convert2array(OBS);
53     NOBS=convert2array(NOBS);
54 gforget 1.1 varargout={OBS}; varargout(2)={NOBS};
55     else;
56     error('wrong output choice');
57     end;
58    
59     else;
60     error('wrong input choice');
61     end;
62    
63 gforget 1.2 warning('on','MATLAB:dsearch:DeprecatedFunction');
64 gforget 1.1
65    
66    

  ViewVC Help
Powered by ViewVC 1.1.22