/[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.22 - (hide annotations) (download)
Sat Dec 10 20:14:01 2016 UTC (8 years, 7 months ago) by gforget
Branch: MAIN
Changes since 1.21: +5 -15 lines
- gcmfaces_diags/diags_grid.m (new): grid loading as done earlier in diags_grid_parms.m now done
  only if needed; grid parameters are now stored in myparms and the call to grid_load becomes
  grid_load(myparms.dirGrid,myparms.nF,myparms.frmt,myparms.memoryLimit);
- diags_grid_parms.m : move grid loading to  subroutine that can be called from diags_driver.m directly
- diags_driver.m : reload mygrid if needed via diags_grid.m
- diags_pre_process.m : omit linking of files to mat/profiles which was causing problems with recent
  matlab versions; instead call MITprof_gcm2nc with {dir_model,dir_out} as first input parameter.

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 doCtrl=~isempty(dir([dirModel 'ADXXfiles' filesep 'xx*.effective.*']));
46     doCtrl=doCtrl|~isempty(dir([dirModel 'xx*.effective.*']));
47 gforget 1.8 else;
48 gforget 1.15 dirSnap=fullfile(dirModel,'diags',filesep);
49 gforget 1.10 doBudget=0;
50     doCost=0;
51     doCtrl=0;
52 gforget 1.8 end;
53    
54 gforget 1.21 doCost=~isempty(dir([dirModel 'barfiles' filesep 'm_eta_day.*.data']));
55     doCost=doCost|~isempty(dir([dirModel 'm_eta_day.*.data']));
56     doCost=doCost|~isempty(dir([dirModel 'nctiles_remotesensing']));
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.21 doProfiles=~isempty(dir([dirModel 'profiles' filesep '*.nc']));
63     preprocessProfiles=0;
64     myenv.profiles=fullfile(dirModel,'profiles',filesep);
65     end;
66     if ~doProfiles;
67 gforget 1.12 doProfiles=~isempty(dir([dirModel 'profiles' filesep]));
68 gforget 1.10 preprocessProfiles=1;
69 gforget 1.14 myenv.profiles=fullfile(dirMat,'profiles',filesep,'output',filesep);
70 gforget 1.8 end;
71 gforget 1.1
72     %output switches
73     myswitch.doBudget=doBudget;
74     myswitch.doProfiles=doProfiles;
75     myswitch.doCost=doCost;
76     myswitch.doCtrl=doCtrl;
77    
78 gforget 1.22 fprintf('\n'); disp(myswitch);
79 gforget 1.15 if doInteractive;
80     test0=input('edit switches (1) or proceed (0)?\n');
81     while test0;
82     test0=input('type modification (e.g. as ''myswitch.doBudget=1;'') or hit return to stop editing.\n');
83     if ~isempty(test0); eval(test0); disp(myswitch); end;
84     end;
85     end;
86    
87    
88 gforget 1.6 %set the list of diags directories and files
89     if myenv.nctiles;
90 gforget 1.14 if isdir(fullfile(dirModel,'nctiles',filesep));
91     listSubdirs={fullfile(dirModel,'nctiles',filesep)};
92 gforget 1.20 elseif isdir(fullfile(dirModel,'nctiles_monthly',filesep));
93     listSubdirs={fullfile(dirModel,'nctiles_monthly',filesep)};
94 gforget 1.14 elseif isdir(fullfile(dirModel,'nctiles_climatology',filesep));
95     listSubdirs={fullfile(dirModel,'nctiles_climatology',filesep)};
96 gforget 1.11 end;
97    
98 gforget 1.6 listFiles=dir(listSubdirs{1}); listFiles={listFiles(:).name};
99     %remove irrelevant files/dirs
100     test1=ones(size(listFiles));
101     for kk=1:length(listFiles);
102 gforget 1.12 tmp1=fullfile(listSubdirs{1},listFiles{kk},[listFiles{kk} '*.nc']);
103 gforget 1.10 test1(kk)=~isempty(dir(tmp1));
104 gforget 1.6 end;
105     listFiles={listFiles{find(test1)}};
106     %store in myparms for later use
107     myenv.nctilesdir=listSubdirs{1};
108     myenv.nctileslist=listFiles;
109 gforget 1.12 %
110     myenv.diagsdir='';
111     else;
112 gforget 1.14 myenv.diagsdir=fullfile(dirModel,['diags' filesep]);
113 gforget 1.19 if isempty(dir([myenv.diagsdir '*.data']))&...
114     isempty(dir([myenv.diagsdir 'STATE' filesep '*.data']));
115     myenv.diagsdir=fullfile(dirModel);
116     end;
117 gforget 1.12 %
118     myenv.nctilesdir='';
119     myenv.nctileslist={};
120 gforget 1.6 end;
121 gforget 1.14 myenv.matdir=fullfile(dirMat);
122 gforget 1.6
123 gforget 1.1 %0) create dirMat if needed:
124 gforget 1.7 if isempty(dir(dirMat)); mkdir(dirMat); end;
125 gforget 1.1
126     %1) pre-processing diags_grid_parms.mat
127     test0=isempty(dir([dirMat 'diags_grid_parms.mat']));
128     test1=isempty(dir([dirMat 'lock_mygrid']));
129    
130     if test0&test1;%this process will do the pre-processing
131 gforget 1.8 fprintf(['pre-processing : started for mygrid, myparms \n']);
132 gforget 1.1 write2file([dirMat 'lock_mygrid'],1);
133     %set the list of diags times
134 gforget 1.10 [listTimes]=diags_list_times;
135 gforget 1.1 %set grid and model parameters:
136 gforget 1.21 diags_grid_parms(dirModel,listTimes,doInteractive);
137 gforget 1.1 %save to disk:
138 gforget 1.22 eval(['save ' dirMat 'diags_grid_parms.mat myparms;']);
139 gforget 1.7 delete([dirMat 'lock_mygrid']);
140 gforget 1.1 test1=1;
141 gforget 1.8 fprintf(['pre-processing : completed for mygrid, myparms \n\n']);
142 gforget 1.1 end;
143    
144 gforget 1.6 %here I should test that files are indeed found (may have been moved)
145    
146 gforget 1.1 while ~test1;%this process will wait for pre-processing to complete
147     fprintf(['waiting 30s for removal of ' dirMat 'lock_mygrid \n']);
148 gforget 1.2 fprintf(['- That should happen automatically after pre-processing is complete \n']);
149     fprintf(['- But if a previous session was interupted, you may need to stop this one, \n ']);
150 gforget 1.14 fprintf([' remove ' dirMat 'lock_mygrid manually, and start over. \n\n']);
151 gforget 1.1 test1=isempty(dir([dirMat 'lock_mygrid']));
152     pause(30);
153     end;
154    
155     %here we always reload the grid from dirMat to make sure the same one is used throughout
156 gforget 1.10 eval(['load ' dirMat 'diags_grid_parms.mat;']);
157 gforget 1.1
158     %2) pre-processing profiles
159     test0=isempty(dir([dirMat 'profiles/']));
160     test1=isempty(dir([dirMat 'lock_profiles']));
161    
162 gforget 1.8 if test0&test1&doProfiles&preprocessProfiles;%this process will do the pre-processing
163 gforget 1.1 fprintf(['pre-processing : started for profiles \n']);
164     write2file([dirMat 'lock_profiles'],1);
165 gforget 1.7 mkdir([dirMat 'profiles/']);
166 gforget 1.14 mkdir([dirMat 'profiles/output/']);
167 gforget 1.15
168 gforget 1.19 listModel=dir([dirModel '*.nc']);
169     listModel={listModel(:).name};
170 gforget 1.22 for ff=1:length(listModel); listModel{ff}=[listModel{ff}(1:end-3) '*']; end;
171 gforget 1.15
172 gforget 1.18 if ~isempty(listModel);
173 gforget 1.22 MITprof_gcm2nc({dirModel,[dirMat 'profiles/output/']},listModel);
174 gforget 1.18 else;
175     warning('no MITprof files wer found');
176     end;
177 gforget 1.22
178 gforget 1.7 delete([dirMat 'lock_profiles']);
179 gforget 1.1 test1=1;
180     fprintf(['pre-processing : completed for profiles \n\n']);
181     end;
182    
183     while ~test1&doProfiles;%this process will wait for pre-processing to complete
184     fprintf(['waiting 30s for removal of ' dirMat 'lock_profiles \n']);
185 gforget 1.2 fprintf(['- That should happen automatically after pre-processing is complete \n']);
186     fprintf(['- But if a previous session was interupted, you may need to stop this one, \n ']);
187     fprintf([' remove ' dirMat 'lock_profiles manually, and start over. \n\n']);
188 gforget 1.1 test1=isempty(dir([dirMat 'lock_profiles']));
189     pause(30);
190     end;
191    
192     %3) budget pre-processing
193 gforget 1.12 test0=isempty(dir([dirMat 'BUDG']));
194 gforget 1.1 test1=isempty(dir([dirMat 'lock_budg']));%this aims at having only one process do the
195    
196     if (test0&test1&doBudget);
197     fprintf(['pre-processing : started for budget \n']);
198     write2file([dirMat 'lock_budg'],1);
199 gforget 1.12 mkdir([dirMat 'BUDG']);
200 gforget 1.15 %compute time derivatives between snapshots that will be
201 gforget 1.1 %compared in budgets with the time mean flux terms
202 gforget 1.15 tmp1=fullfile(dirSnap,'budg3d_snap_set1*meta');
203     test3d=~isempty(dir(tmp1));
204     tmp1=fullfile(dirSnap,'budg3d_snap_set1*meta');
205     test3d=test3d|~isempty(dir(tmp1));
206 gforget 1.16 tmp1=fullfile(dirSnap,'geothermalFlux.bin');
207     testGeothermalFlux=~isempty(dir(tmp1));
208 gforget 1.15 diags_diff_snapshots(dirSnap,dirMat,'budg2d_snap_set1');
209 gforget 1.13 if ~test3d;
210 gforget 1.15 diags_diff_snapshots(dirSnap,dirMat,'budg2d_snap_set2');
211 gforget 1.16 if testGeothermalFlux; diags_budg_geothermal(dirSnap,dirMat,'budg2d_snap_set2'); end;
212 gforget 1.13 else;
213 gforget 1.15 diags_diff_snapshots(dirSnap,dirMat,'budg3d_snap_set1');
214 gforget 1.16 if testGeothermalFlux; diags_budg_geothermal(dirSnap,dirMat,'budg3d_snap_set1'); end;
215 gforget 1.13 end;
216 gforget 1.1 budget_list=1;
217     for kk=1:length(mygrid.RC);
218 gforget 1.15 tmp1=sprintf('%s/budg2d_snap_set3_%02i*',dirSnap,kk);
219 gforget 1.1 tmp2=~isempty(dir(tmp1));
220     if tmp2;
221     budget_list=[budget_list kk];
222     tmp1=sprintf('budg2d_snap_set3_%02i',kk);
223 gforget 1.15 diags_diff_snapshots(dirSnap,dirMat,tmp1);
224 gforget 1.16 if testGeothermalFlux; diags_budg_geothermal(dirSnap,dirMat,tmp1); end;
225 gforget 1.1 end;
226     end;
227     eval(['save ' dirMat 'diags_select_budget_list.mat budget_list;']);
228 gforget 1.7 delete([dirMat 'lock_budg']);
229 gforget 1.1 test1=1;
230     fprintf(['pre-processing : completed for budget \n\n']);
231     end;
232    
233     while ~test1&doBudget;%this process will wait for pre-processing to complete
234     fprintf(['waiting 30s more for removal of ' dirMat 'lock_budg \n']);
235 gforget 1.2 fprintf(['- That should happen automatically after pre-processing is complete \n']);
236     fprintf(['- But if a previous session was interupted, you may need to stop this one, \n ']);
237     fprintf([' remove ' dirMat 'lock_budg manually, and start over. \n\n']);
238 gforget 1.1 test1=isempty(dir([dirMat 'lock_budg']));
239     pause(30);
240     end;
241    
242 gforget 1.10 %set budget list
243     myparms.budgetList=1;
244     if ~isempty(dir([dirMat 'diags_select_budget_list.mat']));
245     eval(['load ' dirMat 'diags_select_budget_list.mat;']);
246     myparms.budgetList=budget_list;
247     end;

  ViewVC Help
Powered by ViewVC 1.1.22