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

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

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


Revision 1.20 - (hide annotations) (download)
Mon May 2 17:43:10 2016 UTC (9 years, 2 months ago) by gforget
Branch: MAIN
Changes since 1.19: +5 -1 lines
- diags_pre_process.m: also search for nctiles_monthly
- diags_driver_tex.m: cosmetic changes

1 gforget 1.8 function [myswitch]=diags_pre_process(dirModel,dirMat,doInteractive);
2 gforget 1.10 %object : pre-processing for grid, model parameters, budgets,
3 gforget 1.8 % profiles, cost and control, etc if required
4     %input : dirModel is the directory containing 'diags/' or 'nctiles/'
5     % dirMat is the directory where diagnostics results will be saved
6     % if isempty(dirMat) then [dirModel 'mat/'] is used by default
7     %(optional) doInteractive=1 allows users to specify parameters interactively
8     % doInteractive = 0 (default) uses ECCO v4 parameters
9     % and omits budgets and model-data misfits analyses
10     %output : myswitch is the set of switches (doBudget, doProfiles, doCost, doCtrl)
11     % that are set here depending on the model output available
12 gforget 1.1
13     gcmfaces_global; global myparms;
14    
15 gforget 1.12 dirModel=fullfile(dirModel,filesep);
16     if isempty(dirMat); dirMat=fullfile(dirModel,'mat',filesep); else; dirMat=fullfile(dirMat,filesep); end;
17 gforget 1.8 if isempty(who('doInteractive')); doInteractive=0; end;
18 gforget 1.1
19 gforget 1.6 %detect which types of files are avaiable
20 gforget 1.19 test0=isdir([dirModel 'diags'])|~isempty(dir([dirModel 'state_2d_set1*']));
21 gforget 1.20 test1=~isempty(dir([dirModel 'nctiles']))|...
22     ~isempty(dir([dirModel 'nctiles_climatology']))|...
23     ~isempty(dir([dirModel 'nctiles_monthly']));
24 gforget 1.10 if test0&test1&doInteractive;
25     myenv.nctiles=input('select to use binaries (0) or nctiles (1) files\n');
26 gforget 1.8 elseif test1;
27 gforget 1.10 myenv.nctiles=1;
28 gforget 1.6 elseif test0;
29 gforget 1.10 myenv.nctiles=0;
30 gforget 1.6 else;
31 gforget 1.10 error('no files (diags/ or nctiles/) were found\n');
32 gforget 1.6 end
33    
34 gforget 1.15 if ~myenv.nctiles;%only works with binaries
35     dirSnap=fullfile(dirModel,'diags',filesep);
36     doBudget=~isempty(dir([dirSnap 'budg2d_snap_set1*']));
37     if ~doBudget;
38     dirSnap=fullfile(dirModel,'diags',filesep,'BUDG',filesep);
39     doBudget=~isempty(dir([dirSnap 'budg2d_snap_set1*']));
40     end;
41 gforget 1.19 if ~doBudget;
42     dirSnap=dirModel;
43     doBudget=~isempty(dir([dirSnap 'budg2d_snap_set1*']));
44     end;
45 gforget 1.15
46     doCost=~isempty(dir([dirModel 'barfiles' filesep 'm_eta_day.*.data']));
47     doCost=doCost|~isempty(dir([dirModel 'm_eta_day.*.data']));
48    
49     doCtrl=~isempty(dir([dirModel 'ADXXfiles' filesep 'xx*.effective.*']));
50     doCtrl=doCtrl|~isempty(dir([dirModel 'xx*.effective.*']));
51 gforget 1.8 else;
52 gforget 1.15 dirSnap=fullfile(dirModel,'diags',filesep);
53 gforget 1.10 doBudget=0;
54     doCost=0;
55     doCtrl=0;
56 gforget 1.8 end;
57    
58 gforget 1.12 doProfiles=~isempty(dir([dirModel 'MITprof' filesep]));
59 gforget 1.8 preprocessProfiles=0;
60 gforget 1.14 myenv.profiles=fullfile(dirModel,'MITprof',filesep);
61 gforget 1.8 if ~doProfiles;
62 gforget 1.12 doProfiles=~isempty(dir([dirModel 'profiles' filesep]));
63 gforget 1.10 preprocessProfiles=1;
64 gforget 1.14 myenv.profiles=fullfile(dirMat,'profiles',filesep,'output',filesep);
65 gforget 1.8 end;
66 gforget 1.1
67     %output switches
68     myswitch.doBudget=doBudget;
69     myswitch.doProfiles=doProfiles;
70     myswitch.doCost=doCost;
71     myswitch.doCtrl=doCtrl;
72    
73 gforget 1.15 disp(myswitch);
74     if doInteractive;
75     test0=input('edit switches (1) or proceed (0)?\n');
76     while test0;
77     test0=input('type modification (e.g. as ''myswitch.doBudget=1;'') or hit return to stop editing.\n');
78     if ~isempty(test0); eval(test0); disp(myswitch); end;
79     end;
80     end;
81    
82    
83 gforget 1.6 %set the list of diags directories and files
84     if myenv.nctiles;
85 gforget 1.14 if isdir(fullfile(dirModel,'nctiles',filesep));
86     listSubdirs={fullfile(dirModel,'nctiles',filesep)};
87 gforget 1.20 elseif isdir(fullfile(dirModel,'nctiles_monthly',filesep));
88     listSubdirs={fullfile(dirModel,'nctiles_monthly',filesep)};
89 gforget 1.14 elseif isdir(fullfile(dirModel,'nctiles_climatology',filesep));
90     listSubdirs={fullfile(dirModel,'nctiles_climatology',filesep)};
91 gforget 1.11 end;
92    
93 gforget 1.6 listFiles=dir(listSubdirs{1}); listFiles={listFiles(:).name};
94     %remove irrelevant files/dirs
95     test1=ones(size(listFiles));
96     for kk=1:length(listFiles);
97 gforget 1.12 tmp1=fullfile(listSubdirs{1},listFiles{kk},[listFiles{kk} '*.nc']);
98 gforget 1.10 test1(kk)=~isempty(dir(tmp1));
99 gforget 1.6 end;
100     listFiles={listFiles{find(test1)}};
101     %store in myparms for later use
102     myenv.nctilesdir=listSubdirs{1};
103     myenv.nctileslist=listFiles;
104 gforget 1.12 %
105     myenv.diagsdir='';
106     else;
107 gforget 1.14 myenv.diagsdir=fullfile(dirModel,['diags' filesep]);
108 gforget 1.19 if isempty(dir([myenv.diagsdir '*.data']))&...
109     isempty(dir([myenv.diagsdir 'STATE' filesep '*.data']));
110     myenv.diagsdir=fullfile(dirModel);
111     end;
112 gforget 1.12 %
113     myenv.nctilesdir='';
114     myenv.nctileslist={};
115 gforget 1.6 end;
116 gforget 1.14 myenv.matdir=fullfile(dirMat);
117 gforget 1.6
118 gforget 1.1 %0) create dirMat if needed:
119 gforget 1.7 if isempty(dir(dirMat)); mkdir(dirMat); end;
120 gforget 1.1
121     %1) pre-processing diags_grid_parms.mat
122     test0=isempty(dir([dirMat 'diags_grid_parms.mat']));
123     test1=isempty(dir([dirMat 'lock_mygrid']));
124    
125     if test0&test1;%this process will do the pre-processing
126 gforget 1.8 fprintf(['pre-processing : started for mygrid, myparms \n']);
127 gforget 1.1 write2file([dirMat 'lock_mygrid'],1);
128     %set the list of diags times
129 gforget 1.10 [listTimes]=diags_list_times;
130 gforget 1.1 %set grid and model parameters:
131 gforget 1.8 diags_grid_parms(listTimes,doInteractive);
132 gforget 1.1 %save to disk:
133 gforget 1.10 %if doInteractive;
134     eval(['save ' dirMat 'diags_grid_parms.mat mygrid myparms;']);
135     %end;
136 gforget 1.7 delete([dirMat 'lock_mygrid']);
137 gforget 1.1 test1=1;
138 gforget 1.8 fprintf(['pre-processing : completed for mygrid, myparms \n\n']);
139 gforget 1.1 end;
140    
141 gforget 1.6 %here I should test that files are indeed found (may have been moved)
142    
143 gforget 1.1 while ~test1;%this process will wait for pre-processing to complete
144     fprintf(['waiting 30s for removal of ' dirMat 'lock_mygrid \n']);
145 gforget 1.2 fprintf(['- That should happen automatically after pre-processing is complete \n']);
146     fprintf(['- But if a previous session was interupted, you may need to stop this one, \n ']);
147 gforget 1.14 fprintf([' remove ' dirMat 'lock_mygrid manually, and start over. \n\n']);
148 gforget 1.1 test1=isempty(dir([dirMat 'lock_mygrid']));
149     pause(30);
150     end;
151    
152     %here we always reload the grid from dirMat to make sure the same one is used throughout
153 gforget 1.10 eval(['load ' dirMat 'diags_grid_parms.mat;']);
154 gforget 1.1
155     %2) pre-processing profiles
156     test0=isempty(dir([dirMat 'profiles/']));
157     test1=isempty(dir([dirMat 'lock_profiles']));
158    
159 gforget 1.8 if test0&test1&doProfiles&preprocessProfiles;%this process will do the pre-processing
160 gforget 1.1 fprintf(['pre-processing : started for profiles \n']);
161     write2file([dirMat 'lock_profiles'],1);
162 gforget 1.7 mkdir([dirMat 'profiles/']);
163 gforget 1.14 mkdir([dirMat 'profiles/input/']);
164     mkdir([dirMat 'profiles/output/']);
165 gforget 1.15
166 gforget 1.19 listModel=dir([dirModel '*.nc']);
167     listModel={listModel(:).name};
168     for ff=1:length(listModel);
169     copyfile([dirModel listModel{ff}],[dirMat 'profiles/input/' listModel{ff}]);
170     end;
171 gforget 1.15
172 gforget 1.1 if dirModel(1)~='/'; dirModelFull=[pwd '/' dirModel]; else; dirModelFull=dirModel; end;
173 gforget 1.10 % NOTE: if on DOS system change ln to mklink
174 gforget 1.7 system(['ln -s ' dirModelFull 'profiles/*equi.data ' dirMat 'profiles/.']);
175 gforget 1.18 listModel=dir([dirMat 'profiles/input/*.nc'])
176     listModel={listModel(:).name};
177     for ff=1:length(listModel); listModel{ff}=[listModel{ff}(1:end-3) '*']; end;
178     if ~isempty(listModel);
179     MITprof_gcm2nc([dirMat 'profiles/'],listModel);
180     else;
181     warning('no MITprof files wer found');
182     end;
183 gforget 1.7 delete([dirMat 'lock_profiles']);
184 gforget 1.1 test1=1;
185     fprintf(['pre-processing : completed for profiles \n\n']);
186     end;
187    
188     while ~test1&doProfiles;%this process will wait for pre-processing to complete
189     fprintf(['waiting 30s for removal of ' dirMat 'lock_profiles \n']);
190 gforget 1.2 fprintf(['- That should happen automatically after pre-processing is complete \n']);
191     fprintf(['- But if a previous session was interupted, you may need to stop this one, \n ']);
192     fprintf([' remove ' dirMat 'lock_profiles manually, and start over. \n\n']);
193 gforget 1.1 test1=isempty(dir([dirMat 'lock_profiles']));
194     pause(30);
195     end;
196    
197     %3) budget pre-processing
198 gforget 1.12 test0=isempty(dir([dirMat 'BUDG']));
199 gforget 1.1 test1=isempty(dir([dirMat 'lock_budg']));%this aims at having only one process do the
200    
201     if (test0&test1&doBudget);
202     fprintf(['pre-processing : started for budget \n']);
203     write2file([dirMat 'lock_budg'],1);
204 gforget 1.12 mkdir([dirMat 'BUDG']);
205 gforget 1.15 %compute time derivatives between snapshots that will be
206 gforget 1.1 %compared in budgets with the time mean flux terms
207 gforget 1.15 tmp1=fullfile(dirSnap,'budg3d_snap_set1*meta');
208     test3d=~isempty(dir(tmp1));
209     tmp1=fullfile(dirSnap,'budg3d_snap_set1*meta');
210     test3d=test3d|~isempty(dir(tmp1));
211 gforget 1.16 tmp1=fullfile(dirSnap,'geothermalFlux.bin');
212     testGeothermalFlux=~isempty(dir(tmp1));
213 gforget 1.15 diags_diff_snapshots(dirSnap,dirMat,'budg2d_snap_set1');
214 gforget 1.13 if ~test3d;
215 gforget 1.15 diags_diff_snapshots(dirSnap,dirMat,'budg2d_snap_set2');
216 gforget 1.16 if testGeothermalFlux; diags_budg_geothermal(dirSnap,dirMat,'budg2d_snap_set2'); end;
217 gforget 1.13 else;
218 gforget 1.15 diags_diff_snapshots(dirSnap,dirMat,'budg3d_snap_set1');
219 gforget 1.16 if testGeothermalFlux; diags_budg_geothermal(dirSnap,dirMat,'budg3d_snap_set1'); end;
220 gforget 1.13 end;
221 gforget 1.1 budget_list=1;
222     for kk=1:length(mygrid.RC);
223 gforget 1.15 tmp1=sprintf('%s/budg2d_snap_set3_%02i*',dirSnap,kk);
224 gforget 1.1 tmp2=~isempty(dir(tmp1));
225     if tmp2;
226     budget_list=[budget_list kk];
227     tmp1=sprintf('budg2d_snap_set3_%02i',kk);
228 gforget 1.15 diags_diff_snapshots(dirSnap,dirMat,tmp1);
229 gforget 1.16 if testGeothermalFlux; diags_budg_geothermal(dirSnap,dirMat,tmp1); end;
230 gforget 1.1 end;
231     end;
232     eval(['save ' dirMat 'diags_select_budget_list.mat budget_list;']);
233 gforget 1.7 delete([dirMat 'lock_budg']);
234 gforget 1.1 test1=1;
235     fprintf(['pre-processing : completed for budget \n\n']);
236     end;
237    
238     while ~test1&doBudget;%this process will wait for pre-processing to complete
239     fprintf(['waiting 30s more for removal of ' dirMat 'lock_budg \n']);
240 gforget 1.2 fprintf(['- That should happen automatically after pre-processing is complete \n']);
241     fprintf(['- But if a previous session was interupted, you may need to stop this one, \n ']);
242     fprintf([' remove ' dirMat 'lock_budg manually, and start over. \n\n']);
243 gforget 1.1 test1=isempty(dir([dirMat 'lock_budg']));
244     pause(30);
245     end;
246    
247 gforget 1.10 %set budget list
248     myparms.budgetList=1;
249     if ~isempty(dir([dirMat 'diags_select_budget_list.mat']));
250     eval(['load ' dirMat 'diags_select_budget_list.mat;']);
251     myparms.budgetList=budget_list;
252     end;

  ViewVC Help
Powered by ViewVC 1.1.22