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

Contents 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.6 - (show annotations) (download)
Sat Nov 19 15:22:40 2016 UTC (8 years, 8 months ago) by gforget
Branch: MAIN
CVS Tags: checkpoint66f, checkpoint66e, checkpoint66d, checkpoint66c, checkpoint66b, checkpoint66a, checkpoint66o, HEAD
Changes since 1.5: +8 -1 lines
- grid_load.m: remove call to gcmfaces_lines_zonal and gcmfaces_lines_transp
- calc_MeridionalTransport.m, calc_mermean_T.m, calc_overturn.m, calc_zonmean_T.m,
  calc_zonmedian_T.m, gcmfaces_section.m, diags_display.m, diags_grid_parms.m, figureL.m,
  example_transports_disp.m: call gcmfaces_lines_zonal and / or gcmfaces_lines_transp to
  initialize LATS_MASKS, LONS_MASKS, or LINES_MASKS if needed.

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

  ViewVC Help
Powered by ViewVC 1.1.22