/[MITgcm]/MITgcm_contrib/gael/matlab_class/gcmfaces_diags/diags_display.m
ViewVC logotype

Annotation of /MITgcm_contrib/gael/matlab_class/gcmfaces_diags/diags_display.m

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


Revision 1.12 - (hide annotations) (download)
Mon Mar 14 15:56:47 2016 UTC (9 years, 4 months ago) by gforget
Branch: MAIN
CVS Tags: checkpoint65x, checkpoint65v, checkpoint65w, checkpoint65u
Changes since 1.11: +1 -1 lines
- diags_display.m: set addToTex=1 but fileTex='' to go through write2tex
  but simply to add figure captions (when using diags_display directly).
- write2tex.m: add call to gcmfaces_caption (also when fileTex='') and
  save figures (atfter print to eps and activation of caption).
- gcmfaces_caption.m: output captionHandle; include 'Children' in
  visibility switch; rename temporary variables as gfCapTmp and gfCapTmppp;
  revise uipanel aspect and position.

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

  ViewVC Help
Powered by ViewVC 1.1.22