/[MITgcm]/MITgcm_contrib/gael/matlab_class/sample_analysis/plot_one_field.m
ViewVC logotype

Annotation of /MITgcm_contrib/gael/matlab_class/sample_analysis/plot_one_field.m

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


Revision 1.14 - (hide annotations) (download)
Wed Dec 3 00:16:12 2014 UTC (11 years, 11 months ago) by gforget
Branch: MAIN
Changes since 1.13: +23 -6 lines
- update to use official files instead of sample_input.tar,
  add gcmfaces_sphere, retire basic_diags_compute_v3_or_v4

1 gforget 1.9 function []=plot_one_field(choiceV3orV4,plotMethod);
2     %object: illustrate several methods to plot fields within gcmfaces.
3     %inputs: choiceV3orV4 ('v3' or 'v4') selects the sample GRID
4     % plotMethod selects the plotting method
5     % 0) all, one after the other
6     % 1) plot a gcmfaces object face by face
7     % 2) use convert2array then plot in array coordinates.
8     % 3) use convert2pcol then plot in lat-lon coordinates.
9     % 4) use the gcmfaces front end to m_map.
10    
11     input_list_check('plot_one_field',nargin);
12 gforget 1.1
13 gforget 1.13 gcmfaces_global;
14     if myenv.verbose>0;
15     gcmfaces_msg('===============================================');
16     gcmfaces_msg(['*** entering plot_one_field that displays ' ...
17     'a gridded field of ocean depth, first ' ...
18     'in gcmfaces and array formats. Then in geographic coordinates ' ...
19     'using pcolor and in various projections using m_map (if avail. in path). '],'');
20     end;
21    
22 gforget 1.1 %%%%%%%%%%%%%%%%%
23     %load parameters:
24     %%%%%%%%%%%%%%%%%
25 gforget 1.14
26     gcmfaces_global;
27 gforget 1.12 dir0=[myenv.gcmfaces_dir '/sample_input/'];
28 gforget 1.14 if strcmp(choiceV3orV4,'v4');
29     nF=5;
30     fileFormat='compact';
31     dirGrid=[dir0 '../../GRID/'];
32     else;
33     error('files are missing');
34     nF=1;
35     fileFormat='straight';
36     dirGrid=[dir0 '/GRID' choiceV3orV4 '/'];
37     end;
38    
39     mygrid=[]; grid_load(dirGrid,nF,fileFormat,1);
40 gforget 1.1
41     %%%%%%%%%%%
42     %get field:
43     %%%%%%%%%%%
44 gforget 1.14
45     fld=mygrid.Depth; fld(fld==0)=NaN;
46     cc=[[0:0.05:0.5] [0.6 0.75 1 1.25]]*1e4; myCmap='gray';
47 gforget 1.9
48 gforget 1.1 %%%%%%%%%%%%
49     %plot field:
50     %%%%%%%%%%%%
51 gforget 1.9
52     if plotMethod==0|plotMethod==1;
53 gforget 1.13 if myenv.verbose>0; gcmfaces_msg('* gcmfaces format display -- face by face.'); end;
54 gforget 1.9 if nF==1;
55 gforget 1.12 figure; imagescnan(fld{1}','nancolor',[1 1 1]*0.8); axis xy; cb=gcmfaces_cmap_cbar(cc,{'myCmap',myCmap}); delete(cb);
56 gforget 1.9 elseif nF==5;
57     figure;
58 gforget 1.12 subplot(3,3,7); imagescnan(fld{1}','nancolor',[1 1 1]*0.8); axis xy; cb=gcmfaces_cmap_cbar(cc,{'myCmap',myCmap}); delete(cb);
59     tmp1=axis; tmp2=text(tmp1(2)/2,tmp1(4)/2,'1','FontSize',32,'Color','r','Rotation',0);
60     subplot(3,3,8); imagescnan(fld{2}','nancolor',[1 1 1]*0.8); axis xy; cb=gcmfaces_cmap_cbar(cc,{'myCmap',myCmap}); delete(cb);
61     tmp1=axis; tmp2=text(tmp1(2)/2,tmp1(4)/2,'2','FontSize',32,'Color','r','Rotation',0);
62     subplot(3,3,5); imagescnan(fld{3}','nancolor',[1 1 1]*0.8); axis xy; cb=gcmfaces_cmap_cbar(cc,{'myCmap',myCmap}); delete(cb);
63     tmp1=axis; tmp2=text(tmp1(2)/2,tmp1(4)/2,'3','FontSize',32,'Color','r','Rotation',0);
64     subplot(3,3,6); imagescnan(fld{4}','nancolor',[1 1 1]*0.8); axis xy; cb=gcmfaces_cmap_cbar(cc,{'myCmap',myCmap}); delete(cb);
65     tmp1=axis; tmp2=text(tmp1(2)/2,tmp1(4)/2,'4','FontSize',32,'Color','r','Rotation',0);
66     subplot(3,3,3); imagescnan(fld{5}','nancolor',[1 1 1]*0.8); axis xy; cb=gcmfaces_cmap_cbar(cc,{'myCmap',myCmap}); delete(cb);
67     tmp1=axis; tmp2=text(tmp1(2)/2,tmp1(4)/2,'5','FontSize',32,'Color','r','Rotation',0);
68 gforget 1.9 elseif nF==6;
69     error('face by face plot for cude : not yet implemented');
70     end;
71     end;
72    
73     if plotMethod==0|plotMethod==2;
74 gforget 1.13 if myenv.verbose>0; gcmfaces_msg('* array format display -- all faces concatenated somehow.'); end;
75 gforget 1.9 figure;
76     FLD=convert2array(fld);
77 gforget 1.12 imagescnan(FLD','nancolor',[1 1 1]*0.8); axis xy; cb=gcmfaces_cmap_cbar(cc,{'myCmap',myCmap}); %delete(cb);
78     for ff=1:mygrid.nFaces;
79     tmp0=0*mygrid.XC;
80     tmp1=round(size(tmp0{ff})/2);
81     tmp0{ff}(tmp1(1),tmp1(2))=1;
82     tmp0=convert2array(tmp0); [ii,jj]=find(tmp0==1);
83     if ff==3; ang=90; elseif ff>3; ang=-90; else; ang=0; end;
84     hold on; text(ii,jj,num2str(ff),'FontSize',32,'Color','r','Rotation',ang);
85     end;
86 gforget 1.9 end;
87    
88     if plotMethod==0|plotMethod==3;
89 gforget 1.13 if myenv.verbose>0; gcmfaces_msg('* geographical display -- using pcolor.'); end;
90 gforget 1.9 figure;
91     [X,Y,FLD]=convert2pcol(mygrid.XC,mygrid.YC,fld); pcolor(X,Y,FLD);
92     if ~isempty(find(X>359)); axis([0 360 -90 90]); else; axis([-180 180 -90 90]); end;
93 gforget 1.12 shading flat; cb=gcmfaces_cmap_cbar(cc,{'myCmap',myCmap}); delete(cb); xlabel('longitude'); ylabel('latitude');
94 gforget 1.2 end;
95 gforget 1.1
96 gforget 1.9 if plotMethod==0|plotMethod==4;
97 gforget 1.13 if myenv.verbose>0; gcmfaces_msg('* geographical display -- using m_map.'); end;
98 gforget 1.9 if ~isempty(which('m_proj'));
99 gforget 1.12 figure; m_map_gcmfaces(fld,0,{'myCaxis',cc},{'myCmap',myCmap});
100     elseif myenv.verbose;
101 gforget 1.9 fprintf('if you want to use m_map_gcmfaces, you will need to have m_map in your path\n');
102     end;
103     end;
104    
105 gforget 1.14 if plotMethod==0|plotMethod==5;
106     if myenv.verbose>0; gcmfaces_msg('* geographical display -- on a sphere.'); end;
107     gcmfaces_sphere(fld,cc,[],'N',3);
108     end;
109    
110 gforget 1.11 %test case for depthStretchPlot:
111 gforget 1.14 if plotMethod==0|plotMethod==6;
112 gforget 1.13 if myenv.verbose>0; gcmfaces_msg('* section display -- using strecthed vertical coord.'); end;
113 gforget 1.12 x=ones(length(mygrid.RC),1)*[1:200]; z=mygrid.RC*ones(1,200); c=sin(z/2000*pi).*cos(x/50*pi);
114 gforget 1.11 figure;
115     subplot(1,2,1); pcolor(x,z,c); shading flat; title('standard depth display');
116     subplot(1,2,2); depthStretchPlot('pcolor',{x,z,c}); shading flat; title('stretched depth display');
117     % subplot(1,2,1); plot(c(:,1),z(:,1)); title('standard depth display');
118     % subplot(1,2,2); depthStretchPlot('plot',{c(:,1),z(:,1)}); title('stretched depth display');
119     end;
120    
121 gforget 1.13 if myenv.verbose>0;
122     gcmfaces_msg('*** leaving plot_one_field');
123     gcmfaces_msg('===============================================');
124     end;
125 gforget 1.9

  ViewVC Help
Powered by ViewVC 1.1.22