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

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

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


Revision 1.4 - (hide annotations) (download)
Sun Aug 3 20:29:49 2014 UTC (10 years, 11 months ago) by gforget
Branch: MAIN
Changes since 1.3: +29 -11 lines
- calc_zonmean_T : allow for position arrays X,Y as 2nd,3rd output argument
- gcmfaces_section : allow for position arrays X,Y as 4th,5th output argument

1 gforget 1.4 function [LO,LA,FLD,X,Y]=gcmfaces_section(lons,lats,fld,varargin);
2 gforget 1.1 %purpose: extract a great circle section (defined by two points) from a field
3 gforget 1.2 % or a latitude circle (defined by one latitude)
4 gforget 1.1 %
5     %inputs: lons/lats are the longitude/latitude vector
6     % fld is the gcmfaces field (can incl. depth/time dimensions)
7 gforget 1.2 %optional: sortByLon to sort point by longitude (default = 0 -> sort by latgitude)
8 gforget 1.4 %outputs: LO/LA is the vector of grid points longitude/latitude
9     % FLD is the vector/matrix of grid point values (from fld)
10 gforget 1.1
11 gforget 1.2 if nargin>3; sortByLon=varargin{1}; else; sortByLon=0; end;
12    
13 gforget 1.1 global mygrid;
14    
15 gforget 1.2 if length(lats)==2;
16     line_cur=gcmfaces_lines_transp(lons,lats,{'tmp'});
17     elseif length(lats)==1;
18     tmp1=abs(mygrid.LATS-lats);
19     tmp2=find(tmp1==min(tmp1));
20     tmp2=tmp2(1);
21     line_cur=mygrid.LATS_MASKS(tmp2);
22     else;
23     error('wrong specification of lons,lats');
24     end;
25     secP=find(line_cur.mskCedge==1);
26     secN=length(secP);
27 gforget 1.1
28     %lon/lat vectors:
29 gforget 1.4 LO=zeros(secN,1); LA=zeros(secN,1);
30 gforget 1.1 %sections:
31 gforget 1.4 n3=max(size(fld{1},3),1); n4=max(size(fld{1},4),1); FLD=zeros(secN,n3,n4);
32 gforget 1.1 %counter:
33     ii0=0;
34     for ff=1:secP.nFaces;
35     tmp0=secP{ff}; [tmpI,tmpJ]=ind2sub(size(mygrid.XC{ff}),tmp0);
36 gforget 1.4 tmp1=mygrid.XC{ff}; for ii=1:length(tmpI); LO(ii+ii0)=tmp1(tmpI(ii),tmpJ(ii)); end;
37     tmp1=mygrid.YC{ff}; for ii=1:length(tmpI); LA(ii+ii0)=tmp1(tmpI(ii),tmpJ(ii)); end;
38     tmp1=fld{ff}; for ii=1:length(tmpI); FLD(ii+ii0,:,:)=squeeze(tmp1(tmpI(ii),tmpJ(ii),:,:)); end;
39 gforget 1.1 ii0=ii0+length(tmpI);
40     end;
41    
42 gforget 1.2 %sort according to increasing latitude or longitude:
43     if sortByLon;
44 gforget 1.4 [tmp1,ii]=sort(LO); %sort according to increasing longitude
45 gforget 1.2 else;
46 gforget 1.4 [tmp1,ii]=sort(LA); %sort according to increasing latitude
47 gforget 1.2 end;
48 gforget 1.4 LO=LO(ii); LA=LA(ii); FLD=FLD(ii,:,:);
49 gforget 1.1
50 gforget 1.4 %output axes for ploting with pcolor
51     nr=length(mygrid.RC);
52     nx=length(LO);
53     X=[]; Y=[];
54     if size(FLD,2)==nr&sortByLon;
55     X=LO'*ones(1,nr);
56     Y=ones(nx,1)*mygrid.RC';
57     elseif size(FLD,2)==nr&~sortByLon;
58     X=LA'*ones(1,nr);
59     Y=ones(nx,1)*mygrid.RC';
60     elseif size(FLD,1)==nr&sortByLon;
61     X=LO';
62     Y=ones(nx,1);
63     elseif size(FLD,2)==1&~sortByLon;
64     X=LA';
65     Y=ones(nx,1);
66     end;
67    

  ViewVC Help
Powered by ViewVC 1.1.22