/[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.1 - (hide annotations) (download)
Sat Dec 29 17:55:18 2012 UTC (12 years, 6 months ago) by gforget
Branch: MAIN
- add display components to gcmfaces_diags :
    diags_display.m : display a set of diagnostics
    diags_driver_tex.m : build tex file from a set of diagnostics

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     %in case mygrid.memoryLimit=1, load the stuff that was not saved to diags_grid_parms.mat
73     if mygrid.memoryLimit==1;
74     list0={'hFacS','hFacW'};
75     for iFld=1:length(list0);
76     eval(['mygrid.' list0{iFld} '=rdmds2gcmfaces([mygrid.dirGrid ''' list0{iFld} '*'']);']);
77     end;
78     %
79     mygrid.hFacCsurf=mygrid.hFacC;
80     for ff=1:mygrid.hFacC.nFaces; mygrid.hFacCsurf{ff}=mygrid.hFacC{ff}(:,:,1); end;
81     %
82     mskC=mygrid.hFacC; mskC(mskC==0)=NaN; mskC(mskC>0)=1; mygrid.mskC=mskC;
83     mskW=mygrid.hFacW; mskW(mskW==0)=NaN; mskW(mskW>0)=1; mygrid.mskW=mskW;
84     mskS=mygrid.hFacS; mskS(mskS==0)=NaN; mskS(mskS>0)=1; mygrid.mskS=mskS;
85     %
86     gcmfaces_lines_zonal;
87     mygrid.LATS=[mygrid.LATS_MASKS.lat]';
88     [lonPairs,latPairs,names]=line_greatC_TUV_MASKS_v4;
89     gcmfaces_lines_transp(lonPairs,latPairs,names);
90     end;
91    
92     %%%%%%%%%%%%%%
93     %define diags:
94     %%%%%%%%%%%%%%
95    
96     if strcmp(nameGrid,'diags_grid_parms.mat');
97     %load listDiags and get fileMat (if applies)
98     userStep=1;
99     if ~isempty(which(['diags_set_' setDiags]));
100     eval(['diags_set_' setDiags]);
101     else;
102     diags_set_user;
103     end;
104    
105     %reformat listDiags to cell array:
106     jj=strfind(listDiags,' '); jj=[0 jj length(listDiags)+1];
107     for ii=1:length(jj)-1;
108     tmp1=listDiags(jj(ii)+1:jj(ii+1)-1);
109     if ii==1; listDiags2={tmp1}; else; listDiags2{ii}=tmp1; end;
110     end;
111     listDiags=listDiags2; clear listDiags2;
112     end;
113    
114     %set fileMat to default name if needed
115     if isempty(who('fileMat')); fileMat=[suffDiag setDiags]; end;
116    
117     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
118     %are there results to display?
119     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
120    
121     test1=isempty(dir([dirMat '/' fileMat '_*.mat']));
122     tmp1=[dirMat '/' fileMat '_*.mat']; tmp2=strfind(tmp1,'_'); tmp1(tmp2)=' ';
123     if test1&addToTex;
124     eval(['load ' dirTex '/myPlots.mat;']);
125     write2tex(fileTex,3,{'[ ',mySection,' ]'},1);
126     write2tex(fileTex,3,{'abort : did not find any'},1);
127     write2tex(fileTex,3,{tmp1},1);
128     write2tex(fileTex,3,{'results files to display'},1);
129     return;
130     elseif test1;
131     fprintf(['\n abort : did not find any \n ' tmp1 '\n results files to display\n\n']);
132     return;
133     end;
134    
135    
136     %%%%%%%%%%%%%%%%%%%%%%%%%
137     %load pre-computed diags:
138     %%%%%%%%%%%%%%%%%%%%%%%%%
139    
140     tic;
141    
142     diagsWereLoaded=0;
143    
144     %specific load sequence (if any, diagsWereLoaded will be set to 1)
145     if strcmp(nameGrid,'diags_grid_parms.mat');
146     userStep=0;
147     if ~isempty(which(['diags_set_' setDiags]));
148     eval(['diags_set_' setDiags]);
149     else;
150     diags_set_user;
151     end;
152     end;
153    
154     %generic load (if no specific one, or )
155     if ~diagsWereLoaded;
156     alldiag=alldiag_load(dirMat,[fileMat '_*.mat']);
157     end;
158    
159     toc;
160    
161     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
162     %load ref and compute anomalies:
163     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
164    
165     if doAnomalies;
166     % scaleAnom=10;
167     scaleAnom=1;
168    
169     %store:
170     dirMatBak=dirMat; dirMat=dirMatRef; alldiagBak=alldiag;
171    
172     %load reference solution:
173     diagsWereLoaded=0;
174    
175     %specific load sequence (if any, diagsWereLoaded will be set to 1)
176     if strcmp(nameGrid,'diags_grid_parms.mat');
177     userStep=0;
178     if ~isempty(which(['diags_set_' setDiags]));
179     eval(['diags_set_' setDiags]);
180     else;
181     diags_set_user;
182     end;
183     end;
184    
185     %generic load (if no specific one, or )
186     if ~diagsWereLoaded;
187     alldiag=alldiag_load(dirMat,[fileMat '_*.mat']);
188     end;
189    
190     %restore:
191     dirMat=dirMatBak; alldiagRef=alldiag; alldiag=alldiagBak;
192    
193     %compute anomalies:
194     for ii=1:length(alldiag.listDiags);
195     tmp0=alldiag.listDiags{ii};
196     if isfield(alldiagRef,tmp0);%compute difference
197     tmp1=getfield(alldiag,tmp0)-getfield(alldiagRef,tmp0);
198     alldiag=setfield(alldiag,tmp0,tmp1);
199     else;%cannot compute diff -> set to NaN
200     tmp1=NaN*getfield(alldiag,tmp0);
201     alldiag=setfield(alldiag,tmp0,tmp1);
202     end;
203     end;
204     end;
205    
206    
207     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
208     %determine time parameters for plots
209     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
210    
211     %number of months for runmean
212     if myparms.diagsAreMonthly;
213     myNmean=12; myNmeanTxt=[' -- ' num2str(myNmean*2) ' months low pass filtered'];
214     else;
215     myNmean=0; myNmeanTxt='';
216     end;
217    
218     %first and last year of time average
219     myYmean=myparms.yearInAve;
220     if myYmean(1)==myYmean(2); myYmeanTxt=[num2str(myYmean(1)) ' '];
221     else; myYmeanTxt=[num2str(myYmean(1)) '-' num2str(myYmean(2)) ' '];
222     end;
223    
224     %to compute time mean/std on the fly
225     tt=[myparms.recInAve(1):min(myparms.recInAve(2),length(alldiag.listTimes))];
226     TT=alldiag.listTimes(tt);
227     nt=length(TT);
228    
229     %if only one record, swicth off time series and variance plots
230     multiTimes=1*(myparms.recInAve(2)>myparms.recInAve(1));
231    
232     %if llc90 we can plot overturn etc per basin
233     multiBasins=(sum([90 1170]~=mygrid.ioSize)==0);
234    
235     %%%%%%%%%%%%%%%
236     %display diags:
237     %%%%%%%%%%%%%%%
238    
239     userStep=-1;
240     if ~isempty(which(['diags_set_' setDiags]));
241     eval(['diags_set_' setDiags]);
242     else;
243     diags_set_user;
244     end;
245    
246    

  ViewVC Help
Powered by ViewVC 1.1.22