/[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.5 - (hide annotations) (download)
Wed May 23 15:33:13 2012 UTC (13 years, 2 months ago) by gforget
Branch: MAIN
Changes since 1.4: +54 -50 lines
 - cosmetic changes.

1 gforget 1.1 function [varargout]=gcmfaces_bindata(varargin);
2 gforget 1.4 %object: compute delaunay triangulation, then bin averaging
3     %inputs: are all optional, triggering different sections of the code
4     % if none then generate the very triangulation (myTri)
5     % if lon,lat vectors, then compute closest neighbor index(ices)
6     % if lon,lat,obs vectors, then further do the bin average
7     %outputs: are all optional, triggering different sections of the code
8     % if OBS then return the bin aberage
9     % if OBS,NOBS then return the bin sum and count
10     %
11     %note: should mytri become part of mygrid ?
12 gforget 1.1
13 gforget 1.2 warning('off','MATLAB:dsearch:DeprecatedFunction');
14    
15 gforget 1.1 global mygrid mytri;
16    
17     if nargin==0;
18 gforget 1.5 %generate delaunay triangulation:
19     XC=convert2array(mygrid.XC);
20     YC=convert2array(mygrid.YC);
21     mytri=[];
22     %needed so that we do not loose data
23     XC(isnan(XC))=270;
24     YC(isnan(YC))=180;
25     %
26     TRI=delaunay(XC,YC); nxy = prod(size(XC));
27     Stri=sparse(TRI(:,[1 1 2 2 3 3]),TRI(:,[2 3 1 3 1 2]),1,nxy,nxy);
28     %
29     mytri.XC=XC; mytri.YC=YC; mytri.TRI=TRI; mytri.Stri=Stri;
30     %
31     tmp1=XC; tmp1(:)=1; mytri.kk=find(tmp1);
32     [mytri.ii,mytri.jj]=find(tmp1);
33     %usage: kk=dsearch(mytri.XC,mytri.YC,mytri.TRI,lon,lat,mytri.Stri);
34     % where lon and lat are vector of position
35 gforget 1.1 elseif nargin==2;
36 gforget 1.5 %compute grid point vector associated with lon/lat vectors
37     lon=varargin{1}; lat=varargin{2};
38     kk=dsearch(mytri.XC,mytri.YC,mytri.TRI,lon,lat,mytri.Stri);
39     if nargout==1;
40     varargout={mytri.kk(kk)};
41     elseif nargout==2;
42     ii=mytri.ii(kk); jj=mytri.jj(kk);
43     varargout={ii}; varargout(2)={jj};
44     else;
45     error('wrong output choice');
46     end;
47 gforget 1.1 elseif nargin==3;
48 gforget 1.5 %do the bin average (if nargout==1) or the bin sum+count (if nargout==2)
49     lon=varargin{1}; lat=varargin{2}; obs=varargin{3};
50     ii=find(~isnan(obs)); lon=lon(ii); lat=lat(ii); obs=obs(ii);
51     kk=dsearch(mytri.XC,mytri.YC,mytri.TRI,lon,lat,mytri.Stri);
52     kk=mytri.kk(kk);
53    
54     OBS=convert2array(mygrid.XC);
55     OBS(:)=0; NOBS=OBS;
56     for k=1:length(kk)
57     NOBS(kk(k))=NOBS(kk(k))+1;
58     OBS(kk(k))=OBS(kk(k))+obs(k);
59     end % k=1:length(kk)
60    
61     if nargout==1;%output bin average
62     in=find(NOBS); OBS(in)=OBS(in)./NOBS(in);
63     in=find(~NOBS); OBS(in)=NaN; NOBS(in)=NaN;
64     varargout={convert2array(OBS)};
65     elseif nargout==2;%output bin sum+count
66     OBS=convert2array(OBS);
67     NOBS=convert2array(NOBS);
68     varargout={OBS}; varargout(2)={NOBS};
69     else;
70     error('wrong output choice');
71     end;
72    
73 gforget 1.1 else;
74 gforget 1.5 error('wrong input choice');
75 gforget 1.1 end;
76    
77 gforget 1.2 warning('on','MATLAB:dsearch:DeprecatedFunction');
78 gforget 1.1
79    
80    

  ViewVC Help
Powered by ViewVC 1.1.22