/[MITgcm]/MITgcm_contrib/enderton/Diagnostics/DiagSlice.m
ViewVC logotype

Contents of /MITgcm_contrib/enderton/Diagnostics/DiagSlice.m

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


Revision 1.6 - (show annotations) (download)
Wed Aug 10 20:17:17 2005 UTC (19 years, 11 months ago) by enderton
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +16 -16 lines
Changed to make more accomodating for different resolution grids.

1 function [data,xax,yax,pltslc] = ...
2 DiagSlice(data,fln,trl,dat,dad,grd,itr,tst,flu,ddf,gdf,...
3 avg,slc,pst,LoadGridData,GridSuffix,ZcordFile,Vector,FieldName);
4
5 % Function: DiagSlice
6 % Author: Daniel Enderton
7 %
8 % Input Fields:
9 %
10 % Field Type (Brief) Description
11 % -----------------------------------------------------------------------
12 % data array Field name
13 % fln string Field name
14 % dad string Data directory.
15 % grd string Grid data directory.
16 % avg string Averaging scheme ('Ann','DJF', 'JJA',...)
17 % slc string Slice type ('Zon','k=#',...)
18 % pst string Plot style ('Con','Sur',...)
19 % flu string Fluid ('A','O')
20 % dfm string Data format ('MDS' or 'MNC')
21 % LoadGridData 0/1 Optionally load grid data
22 %
23 % Output Fields:
24 %
25 % Field Type (Brief) Description
26 % -----------------------------------------------------------------------
27 % data array Sliced data.
28 %
29 % Descripton:
30 % This function slices the data according to SliceType 'slc'. Depending
31 % on the SliceType and PlotStyle, the data may be converted to a lat-lon
32 % grid. At the end there is also a range check. If the value is out of
33 % the user specified range given in 'DaigFieldParamA'.
34
35 % Load diagnostics parameters, grid data, mark data size
36 DiagGenParam;
37 DiagFieldParamA;
38 DiagFieldParamO;
39 DiagFieldParamC;
40 DiagFieldParamI;
41 [XC,XG,YC,YG,Ylat,ZC,ZG,RAC,drC,drF,HFacC,HFacW,HFacS,dxG,dyG,dxC,dyC] = ...
42 DiagLoadGridData(LoadGridData,grd,gdf,flu,GridSuffix,ZcordFile);
43 datasize = size(data);
44
45
46 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47 % Surface plot %
48 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
49
50 % All surface plots are direct cube sphere outputs, and therefore must have
51 % the dimensions of the cube grid data. If the 'pst' is 'Grd' or 'Int',
52 % everything is already all set since those handle the cubed sphere data.
53 % If the 'pst' is 'Con' or 'Cnf', convert data to a lat-lon grid so that it
54 % can easily be contoured.
55 if isequal(slc,'Sur')
56 if ismember(fln,{'TX','TY','USTR','VSTR'}) | ~isequal(Vector,0)
57 data = data'; xax = XL; yax = YL;
58 elseif ~isequal(datasize,size(XC))
59 error('Incorrect dimensions for slc: ',slc);
60 else
61 if ismember(pst,{'Grd','Int'})
62 if isequal(pst,'Grd'),
63 xax = XG;
64 yax = YG;
65 elseif isequal(pst,'Int'),
66 xax = XC;
67 yax = YC;
68 end
69 elseif ismember(pst,{'Con','Cnf'})
70 data = cube2latlon(XC,YC,data,XL,YL)';
71 xax = XL; yax = YL;
72 else
73 error(['slc = ''Sur'' can not use pst: ',pst]);
74 end
75 end
76 pltslc='lonlat';
77
78
79 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80 % Zonal average plot %
81 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82
83 % When computing a zonal average, there are many different options for the
84 % initial data. If the data is cube-sphere, it could be the shape of XC,
85 % possibly also with a vertical axis. In either case, 'calc_ZonAv_CS' (a
86 % nifty zonally averaging script from JMC) is called to compute the zonal
87 % average for raw cube sphere data. For horizontal velocities, the data
88 % could be of the size [length(XL),length(YL),z-axis length], in which case
89 % you just need to take the mean over the longitude axis (always 1).
90 elseif isequal(slc,'Zon')
91 if isequal(datasize(1:2),size(XC))
92 if isequal(flu,'O'), nBas = 0; end
93 if isequal(flu,'A'), nBas = 0; end
94 [data,dump1,dump2] = ...
95 calc_ZonAv_CS(data,kpr,kwr,nBas,XC,YC,XG,YG,RAC,dad,HFacC);
96 if isequal(avg,'Tse')
97 data=data(:,:,1); xax=years; yax=Ylat; pltslc='timlat';
98 elseif isequal(avg,'Tyr')
99 data=data(:,:,1); xax=[0:12]; yax=Ylat; pltslc='timlat';
100 elseif isequal(pst,'Lin')
101 data=data(:,:,1)'; xax=Ylat; yax=NaN; pltslc='latfld';
102 else
103 data=data(:,:,1)'; xax=Ylat; yax=ZC; pltslc='lathgt';
104 end
105 elseif isequal(datasize(1:2),[length(XL),length(YL)])
106 if ~isequal(pst,'Lin')
107 data = squeeze(mean(data,1))'; xax=YL; yax=ZC; pltslc='lathgt';
108 else
109 data = squeeze(mean(data,1))'; xax=YL; yax=NaN; pltslc='latfld';
110 end
111 else
112 error('Incorrect dimensions for slc = ''Zon''');
113 end
114
115
116 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
117 % i,j,k=# %
118 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
119
120 % These slicing settings just take a slice on one of the axes. If the
121 % slice option is 'i=' or 'j=' and the data is cube-sphere, it is converted
122 % to lat-lon first and indexed then (thus the index number should be based
123 % off of the XL and YL interpolated grids defined in 'DiagGenParam'. It
124 % would be nice to add functions that can slice by longitude, latitude, and
125 % height values directly. Note that there is transposing of all the data
126 % to prepare it for contour plots (harmless is line plots).
127 elseif isequal(slc(1:2),'i=')
128 ii = str2num(slc(3:end));
129 data = cube2latlon(XC,YC,data,XL,YL);
130 if ismember(fln,fields2D)
131 data=squeeze(data(ii,:));
132 xax=YL; yax=NaN; pltslc='latfld';
133 elseif ismember(fln,fields3D)
134 data=squeeze(data(ii,:,:))';
135 xax=YL; yax=ZC; pltslc='lathgt';
136 end
137
138 elseif isequal(slc(1:2),'j=')
139 jj = str2num(slc(3:end));
140 data = cube2latlon(XC,YC,data,XL,YL);
141 if ismember(fln,fields2D)
142 data = squeeze(data(:,jj));
143 xax=XL; yax=NaN; pltslc='lonfld';
144 elseif ismember(fln,fields3D)
145 data = squeeze(data(:,jj,:))';
146 xax=XL; yax=ZC; pltslc='lonhgt';
147 end
148
149 elseif isequal(slc(1:2),'k=')
150 kk = str2num(slc(3:end));
151 data = squeeze(data(:,:,kk));
152 if ismember(fln,{'U','V','uVel','vVel','fizhi_U','fizhi_V'})
153 data = data'; xax = XL; yax = YL;
154 elseif ismember(pst,{'Grd','Int'})
155 if isequal(pst,'Grd'),
156 xax = XG;
157 yax = YG;
158 elseif isequal(pst,'Int'),
159 xax = XC;
160 yax = YC;
161 end
162 elseif ismember(pst,{'Con','Cnf'})
163 data = cube2latlon(XC,YC,data,XL,YL)'; xax = XL; yax = YL;
164 end
165 pltslc='lonlat';
166
167 else
168 error(['Unrecognized SliceType: ',slc]);
169 end
170
171
172 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
173 % Check range %
174 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
175
176 % Load fixed and data ranges, throw a warning is data out of range.
177 datarange = [min(data(:)),max(data(:))];
178 try
179 eval(['fixedrange = ',fln,'range',flu,';']);
180 if datarange(1) < fixedrange(1) | ...
181 datarange(2) > fixedrange(2)
182 disp(['***Warning*** Value out of range for ',fln]);
183 disp([' Data range: ',mat2str(datarange)]);
184 disp([' Fixed range: ',mat2str(fixedrange)]);
185 end
186 catch
187 disp(['***Warning*** No range information found for ',fln]);
188 disp([' Data range: ',mat2str(datarange)]);
189 end

  ViewVC Help
Powered by ViewVC 1.1.22