/[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.4 - (hide annotations) (download)
Fri Jun 24 01:55:42 2011 UTC (14 years, 1 month ago) by gforget
Branch: MAIN
Changes since 1.3: +10 -0 lines
- added headers

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

  ViewVC Help
Powered by ViewVC 1.1.22