1 |
gforget |
1.1 |
function []=diags_display(dirMat,setDiags,dirTex,nameTex); |
2 |
|
|
%object: display a set of diagnostics |
3 |
|
|
%input: dirMat is the directory where diagnozed .mat files are. |
4 |
|
|
% dirMat is usually specified as a chararcter string, but |
5 |
|
|
% user can also specify dirMat as {dirMat,dirMatRef} |
6 |
|
|
% in order to plot the dirMat-dirMatRef anlomalies. |
7 |
|
|
% setDiags is the choice of diagnostics set |
8 |
|
|
% 'A') trasnports |
9 |
|
|
% 'B') air-sea fluxes |
10 |
|
|
% 'C') state variables |
11 |
|
|
% 'D') global and regional budgets |
12 |
|
|
%optional: dirTex is the directory where tex and figures files are created |
13 |
|
|
% (if not specified then display all results to screen instead) |
14 |
|
|
% nameTex is the tex file name (default : 'myPlots') |
15 |
|
|
%note: specifying dirTex / nameTex requires that the tex file has been |
16 |
|
|
% initialized (see e.g. diags_driver_tex.m). Each figure will then |
17 |
|
|
% be save as an eps file, added to the tex file, and closed. |
18 |
|
|
|
19 |
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
20 |
|
|
%determine input/output params: |
21 |
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
22 |
|
|
|
23 |
|
|
%directory names: |
24 |
|
|
if iscell(dirMat); dirMatRef=dirMat{2}; dirMat=dirMat{1}; end; |
25 |
|
|
dirMat=[dirMat '/']; |
26 |
|
|
if isempty(who('dirMatRef')); dirMatRef=''; |
27 |
|
|
elseif ~isempty(dirMatRef); dirMatRef=[dirMatRef '/']; |
28 |
|
|
end; |
29 |
|
|
if isempty(who('dirTex')); dirTex=''; else; dirTex=[dirTex '/']; end; |
30 |
|
|
if isempty(who('nameTex')); nameTex='myPlots'; end; |
31 |
|
|
|
32 |
|
|
%determine if and where to create tex and figures files |
33 |
|
|
if ~ischar(dirTex); error('mis-specified dirTex'); end; |
34 |
|
|
if isempty(dirTex); |
35 |
|
|
addToTex=0; |
36 |
|
|
else; |
37 |
|
|
addToTex=1; fileTex=[dirTex nameTex '.tex']; |
38 |
|
|
end; |
39 |
|
|
|
40 |
|
|
%determined where to display anomalies between runs |
41 |
|
|
doAnomalies=~isempty(dirMatRef); |
42 |
|
|
|
43 |
|
|
%more params |
44 |
|
|
setDiagsParams=[]; |
45 |
|
|
if iscell(setDiags); |
46 |
|
|
setDiagsParams={setDiags{2:end}}; |
47 |
|
|
setDiags=setDiags{1}; |
48 |
|
|
end; |
49 |
|
|
|
50 |
|
|
%%%%%%%%%%%%%%%%%%%%%% |
51 |
|
|
%load grid and params: |
52 |
|
|
%%%%%%%%%%%%%%%%%%%%%% |
53 |
|
|
|
54 |
|
|
gcmfaces_global; global myparms; |
55 |
|
|
test1=~isempty(dir([dirMat 'basic_diags_ecco_mygrid.mat'])); |
56 |
|
|
test2=~isempty(dir([dirMat 'diags_grid_parms.mat'])); |
57 |
|
|
if ~test1&~test2; |
58 |
|
|
error('missing diags_grid_parms.mat') |
59 |
|
|
elseif test2; |
60 |
|
|
nameGrid='diags_grid_parms.mat'; |
61 |
|
|
suffDiag='diags_set_'; |
62 |
|
|
budgetList='diags_select_budget_list.mat'; |
63 |
|
|
else; |
64 |
|
|
nameGrid='basic_diags_ecco_mygrid.mat'; |
65 |
|
|
suffDiag='basic_diags_ecco_'; |
66 |
|
|
budgetList='basic_diags_ecco_budget_list.mat'; |
67 |
|
|
end; |
68 |
|
|
|
69 |
|
|
%here we always reload the grid from dirMat to make sure the same one is used throughout |
70 |
|
|
eval(['load ' dirMat nameGrid ';']); |
71 |
|
|
|
72 |
gforget |
1.2 |
%backward compatibility: |
73 |
|
|
if ~isfield(mygrid,'memoryLimit'); mygrid.memoryLimit=0; end; |
74 |
|
|
if ~isfield(mygrid,'ioSize'); mygrid.ioSize=0; end; |
75 |
|
|
|
76 |
gforget |
1.1 |
%in case mygrid.memoryLimit=1, load the stuff that was not saved to diags_grid_parms.mat |
77 |
|
|
if mygrid.memoryLimit==1; |
78 |
|
|
list0={'hFacS','hFacW'}; |
79 |
|
|
for iFld=1:length(list0); |
80 |
|
|
eval(['mygrid.' list0{iFld} '=rdmds2gcmfaces([mygrid.dirGrid ''' list0{iFld} '*'']);']); |
81 |
|
|
end; |
82 |
|
|
% |
83 |
|
|
mygrid.hFacCsurf=mygrid.hFacC; |
84 |
|
|
for ff=1:mygrid.hFacC.nFaces; mygrid.hFacCsurf{ff}=mygrid.hFacC{ff}(:,:,1); end; |
85 |
|
|
% |
86 |
|
|
mskC=mygrid.hFacC; mskC(mskC==0)=NaN; mskC(mskC>0)=1; mygrid.mskC=mskC; |
87 |
|
|
mskW=mygrid.hFacW; mskW(mskW==0)=NaN; mskW(mskW>0)=1; mygrid.mskW=mskW; |
88 |
|
|
mskS=mygrid.hFacS; mskS(mskS==0)=NaN; mskS(mskS>0)=1; mygrid.mskS=mskS; |
89 |
|
|
% |
90 |
|
|
gcmfaces_lines_zonal; |
91 |
|
|
mygrid.LATS=[mygrid.LATS_MASKS.lat]'; |
92 |
|
|
[lonPairs,latPairs,names]=line_greatC_TUV_MASKS_v4; |
93 |
|
|
gcmfaces_lines_transp(lonPairs,latPairs,names); |
94 |
|
|
end; |
95 |
|
|
|
96 |
|
|
%%%%%%%%%%%%%% |
97 |
|
|
%define diags: |
98 |
|
|
%%%%%%%%%%%%%% |
99 |
|
|
|
100 |
gforget |
1.4 |
%test for results organization |
101 |
|
|
if isdir([dirMat 'diags_set_' setDiags]); |
102 |
|
|
dirMat=[dirMat 'diags_set_' setDiags '/']; |
103 |
|
|
end; |
104 |
|
|
if isdir([dirMatRef 'diags_set_' setDiags]); |
105 |
|
|
dirMatRef=[dirMatRef 'diags_set_' setDiags '/']; |
106 |
|
|
end; |
107 |
|
|
|
108 |
gforget |
1.1 |
if strcmp(nameGrid,'diags_grid_parms.mat'); |
109 |
|
|
%load listDiags and get fileMat (if applies) |
110 |
|
|
userStep=1; |
111 |
|
|
if ~isempty(which(['diags_set_' setDiags])); |
112 |
|
|
eval(['diags_set_' setDiags]); |
113 |
|
|
else; |
114 |
|
|
diags_set_user; |
115 |
|
|
end; |
116 |
|
|
|
117 |
|
|
%reformat listDiags to cell array: |
118 |
|
|
jj=strfind(listDiags,' '); jj=[0 jj length(listDiags)+1]; |
119 |
|
|
for ii=1:length(jj)-1; |
120 |
|
|
tmp1=listDiags(jj(ii)+1:jj(ii+1)-1); |
121 |
|
|
if ii==1; listDiags2={tmp1}; else; listDiags2{ii}=tmp1; end; |
122 |
|
|
end; |
123 |
|
|
listDiags=listDiags2; clear listDiags2; |
124 |
|
|
end; |
125 |
|
|
|
126 |
|
|
%set fileMat to default name if needed |
127 |
|
|
if isempty(who('fileMat')); fileMat=[suffDiag setDiags]; end; |
128 |
|
|
|
129 |
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
130 |
|
|
%are there results to display? |
131 |
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
132 |
|
|
|
133 |
|
|
test1=isempty(dir([dirMat '/' fileMat '_*.mat'])); |
134 |
|
|
tmp1=[dirMat '/' fileMat '_*.mat']; tmp2=strfind(tmp1,'_'); tmp1(tmp2)=' '; |
135 |
|
|
if test1&addToTex; |
136 |
gforget |
1.7 |
eval(['load ' dirTex nameTex '.mat;']); |
137 |
gforget |
1.1 |
write2tex(fileTex,3,{'[ ',mySection,' ]'},1); |
138 |
|
|
write2tex(fileTex,3,{'abort : did not find any'},1); |
139 |
|
|
write2tex(fileTex,3,{tmp1},1); |
140 |
|
|
write2tex(fileTex,3,{'results files to display'},1); |
141 |
|
|
return; |
142 |
|
|
elseif test1; |
143 |
|
|
fprintf(['\n abort : did not find any \n ' tmp1 '\n results files to display\n\n']); |
144 |
|
|
return; |
145 |
|
|
end; |
146 |
|
|
|
147 |
|
|
|
148 |
|
|
%%%%%%%%%%%%%%%%%%%%%%%%% |
149 |
|
|
%load pre-computed diags: |
150 |
|
|
%%%%%%%%%%%%%%%%%%%%%%%%% |
151 |
|
|
|
152 |
|
|
tic; |
153 |
|
|
|
154 |
|
|
diagsWereLoaded=0; |
155 |
|
|
|
156 |
|
|
%specific load sequence (if any, diagsWereLoaded will be set to 1) |
157 |
|
|
if strcmp(nameGrid,'diags_grid_parms.mat'); |
158 |
|
|
userStep=0; |
159 |
|
|
if ~isempty(which(['diags_set_' setDiags])); |
160 |
|
|
eval(['diags_set_' setDiags]); |
161 |
|
|
else; |
162 |
|
|
diags_set_user; |
163 |
|
|
end; |
164 |
|
|
end; |
165 |
|
|
|
166 |
|
|
%generic load (if no specific one, or ) |
167 |
|
|
if ~diagsWereLoaded; |
168 |
gforget |
1.6 |
alldiag=diags_read_from_mat(dirMat,[fileMat '_*.mat']); |
169 |
gforget |
1.1 |
end; |
170 |
|
|
|
171 |
|
|
toc; |
172 |
|
|
|
173 |
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
174 |
|
|
%load ref and compute anomalies: |
175 |
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
176 |
|
|
|
177 |
|
|
if doAnomalies; |
178 |
|
|
% scaleAnom=10; |
179 |
|
|
scaleAnom=1; |
180 |
|
|
|
181 |
|
|
%store: |
182 |
|
|
dirMatBak=dirMat; dirMat=dirMatRef; alldiagBak=alldiag; |
183 |
|
|
|
184 |
|
|
%load reference solution: |
185 |
|
|
diagsWereLoaded=0; |
186 |
|
|
|
187 |
|
|
%specific load sequence (if any, diagsWereLoaded will be set to 1) |
188 |
|
|
if strcmp(nameGrid,'diags_grid_parms.mat'); |
189 |
|
|
userStep=0; |
190 |
|
|
if ~isempty(which(['diags_set_' setDiags])); |
191 |
|
|
eval(['diags_set_' setDiags]); |
192 |
|
|
else; |
193 |
|
|
diags_set_user; |
194 |
|
|
end; |
195 |
|
|
end; |
196 |
|
|
|
197 |
|
|
%generic load (if no specific one, or ) |
198 |
|
|
if ~diagsWereLoaded; |
199 |
gforget |
1.6 |
alldiag=diags_read_from_mat(dirMat,[fileMat '_*.mat']); |
200 |
gforget |
1.1 |
end; |
201 |
|
|
|
202 |
|
|
%restore: |
203 |
|
|
dirMat=dirMatBak; alldiagRef=alldiag; alldiag=alldiagBak; |
204 |
|
|
|
205 |
|
|
%compute anomalies: |
206 |
|
|
for ii=1:length(alldiag.listDiags); |
207 |
|
|
tmp0=alldiag.listDiags{ii}; |
208 |
gforget |
1.2 |
if ~strcmp(tmp0,'listTimes')&~strcmp(tmp0,'listSteps') |
209 |
gforget |
1.1 |
if isfield(alldiagRef,tmp0);%compute difference |
210 |
|
|
tmp1=getfield(alldiag,tmp0)-getfield(alldiagRef,tmp0); |
211 |
|
|
alldiag=setfield(alldiag,tmp0,tmp1); |
212 |
|
|
else;%cannot compute diff -> set to NaN |
213 |
|
|
tmp1=NaN*getfield(alldiag,tmp0); |
214 |
|
|
alldiag=setfield(alldiag,tmp0,tmp1); |
215 |
|
|
end; |
216 |
gforget |
1.2 |
end; |
217 |
gforget |
1.1 |
end; |
218 |
|
|
end; |
219 |
|
|
|
220 |
|
|
|
221 |
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
222 |
|
|
%determine time parameters for plots |
223 |
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
224 |
|
|
|
225 |
|
|
%number of months for runmean |
226 |
gforget |
1.5 |
if myparms.diagsAreMonthly&myparms.diagsNbRec>12; |
227 |
gforget |
1.3 |
myNmean=6; %half window |
228 |
|
|
myNmeanTxt=[' -- ' num2str(myNmean*2) ' months low pass filtered']; |
229 |
gforget |
1.1 |
else; |
230 |
|
|
myNmean=0; myNmeanTxt=''; |
231 |
|
|
end; |
232 |
|
|
|
233 |
|
|
%first and last year of time average |
234 |
|
|
myYmean=myparms.yearInAve; |
235 |
|
|
if myYmean(1)==myYmean(2); myYmeanTxt=[num2str(myYmean(1)) ' ']; |
236 |
|
|
else; myYmeanTxt=[num2str(myYmean(1)) '-' num2str(myYmean(2)) ' ']; |
237 |
|
|
end; |
238 |
|
|
|
239 |
|
|
%to compute time mean/std on the fly |
240 |
gforget |
1.8 |
if length(alldiag.listTimes)>diff(myparms.recInAve)+1; |
241 |
|
|
tt=[myparms.recInAve(1):min(myparms.recInAve(2),length(alldiag.listTimes))]; |
242 |
|
|
TT=alldiag.listTimes(tt); |
243 |
|
|
else; |
244 |
|
|
tt=[1:length(alldiag.listTimes)]; |
245 |
|
|
TT=alldiag.listTimes; |
246 |
|
|
end; |
247 |
gforget |
1.1 |
nt=length(TT); |
248 |
|
|
|
249 |
|
|
%if only one record, swicth off time series and variance plots |
250 |
|
|
multiTimes=1*(myparms.recInAve(2)>myparms.recInAve(1)); |
251 |
|
|
|
252 |
|
|
%if llc90 we can plot overturn etc per basin |
253 |
|
|
multiBasins=(sum([90 1170]~=mygrid.ioSize)==0); |
254 |
|
|
|
255 |
|
|
%%%%%%%%%%%%%%% |
256 |
|
|
%display diags: |
257 |
|
|
%%%%%%%%%%%%%%% |
258 |
|
|
|
259 |
|
|
userStep=-1; |
260 |
|
|
if ~isempty(which(['diags_set_' setDiags])); |
261 |
|
|
eval(['diags_set_' setDiags]); |
262 |
|
|
else; |
263 |
|
|
diags_set_user; |
264 |
|
|
end; |
265 |
|
|
|
266 |
|
|
|