/[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.21 - (hide annotations) (download)
Tue May 10 21:55:43 2016 UTC (9 years, 2 months ago) by gforget
Branch: MAIN
CVS Tags: checkpoint65x, checkpoint65w, checkpoint66a
Changes since 1.20: +10 -5 lines
- diags_driver.m: comment out cost_altimeter and issue print statement (to avoid
  overloading user's memory).
- diags_driver_tex.m: test whether cost_altimeter has generated output; remove
  call to cost_bp that remains a work in progress.
- diags_grid_parms.m: add dirModel to input argument list; search also for
  files in e.g. release2/nctiles_grid.
- diags_pre_process.m: pass dirModel as input to diags_grid_parms; also
  look for intput files in nctiles_remotesensing etc.

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.15 disp(myswitch);
79     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.10 %if doInteractive;
139     eval(['save ' dirMat 'diags_grid_parms.mat mygrid myparms;']);
140     %end;
141 gforget 1.7 delete([dirMat 'lock_mygrid']);
142 gforget 1.1 test1=1;
143 gforget 1.8 fprintf(['pre-processing : completed for mygrid, myparms \n\n']);
144 gforget 1.1 end;
145    
146 gforget 1.6 %here I should test that files are indeed found (may have been moved)
147    
148 gforget 1.1 while ~test1;%this process will wait for pre-processing to complete
149     fprintf(['waiting 30s for removal of ' dirMat 'lock_mygrid \n']);
150 gforget 1.2 fprintf(['- That should happen automatically after pre-processing is complete \n']);
151     fprintf(['- But if a previous session was interupted, you may need to stop this one, \n ']);
152 gforget 1.14 fprintf([' remove ' dirMat 'lock_mygrid manually, and start over. \n\n']);
153 gforget 1.1 test1=isempty(dir([dirMat 'lock_mygrid']));
154     pause(30);
155     end;
156    
157     %here we always reload the grid from dirMat to make sure the same one is used throughout
158 gforget 1.10 eval(['load ' dirMat 'diags_grid_parms.mat;']);
159 gforget 1.1
160     %2) pre-processing profiles
161     test0=isempty(dir([dirMat 'profiles/']));
162     test1=isempty(dir([dirMat 'lock_profiles']));
163    
164 gforget 1.8 if test0&test1&doProfiles&preprocessProfiles;%this process will do the pre-processing
165 gforget 1.1 fprintf(['pre-processing : started for profiles \n']);
166     write2file([dirMat 'lock_profiles'],1);
167 gforget 1.7 mkdir([dirMat 'profiles/']);
168 gforget 1.14 mkdir([dirMat 'profiles/input/']);
169     mkdir([dirMat 'profiles/output/']);
170 gforget 1.15
171 gforget 1.19 listModel=dir([dirModel '*.nc']);
172     listModel={listModel(:).name};
173     for ff=1:length(listModel);
174     copyfile([dirModel listModel{ff}],[dirMat 'profiles/input/' listModel{ff}]);
175     end;
176 gforget 1.15
177 gforget 1.1 if dirModel(1)~='/'; dirModelFull=[pwd '/' dirModel]; else; dirModelFull=dirModel; end;
178 gforget 1.10 % NOTE: if on DOS system change ln to mklink
179 gforget 1.7 system(['ln -s ' dirModelFull 'profiles/*equi.data ' dirMat 'profiles/.']);
180 gforget 1.18 listModel=dir([dirMat 'profiles/input/*.nc'])
181     listModel={listModel(:).name};
182     for ff=1:length(listModel); listModel{ff}=[listModel{ff}(1:end-3) '*']; end;
183     if ~isempty(listModel);
184     MITprof_gcm2nc([dirMat 'profiles/'],listModel);
185     else;
186     warning('no MITprof files wer found');
187     end;
188 gforget 1.7 delete([dirMat 'lock_profiles']);
189 gforget 1.1 test1=1;
190     fprintf(['pre-processing : completed for profiles \n\n']);
191     end;
192    
193     while ~test1&doProfiles;%this process will wait for pre-processing to complete
194     fprintf(['waiting 30s for removal of ' dirMat 'lock_profiles \n']);
195 gforget 1.2 fprintf(['- That should happen automatically after pre-processing is complete \n']);
196     fprintf(['- But if a previous session was interupted, you may need to stop this one, \n ']);
197     fprintf([' remove ' dirMat 'lock_profiles manually, and start over. \n\n']);
198 gforget 1.1 test1=isempty(dir([dirMat 'lock_profiles']));
199     pause(30);
200     end;
201    
202     %3) budget pre-processing
203 gforget 1.12 test0=isempty(dir([dirMat 'BUDG']));
204 gforget 1.1 test1=isempty(dir([dirMat 'lock_budg']));%this aims at having only one process do the
205    
206     if (test0&test1&doBudget);
207     fprintf(['pre-processing : started for budget \n']);
208     write2file([dirMat 'lock_budg'],1);
209 gforget 1.12 mkdir([dirMat 'BUDG']);
210 gforget 1.15 %compute time derivatives between snapshots that will be
211 gforget 1.1 %compared in budgets with the time mean flux terms
212 gforget 1.15 tmp1=fullfile(dirSnap,'budg3d_snap_set1*meta');
213     test3d=~isempty(dir(tmp1));
214     tmp1=fullfile(dirSnap,'budg3d_snap_set1*meta');
215     test3d=test3d|~isempty(dir(tmp1));
216 gforget 1.16 tmp1=fullfile(dirSnap,'geothermalFlux.bin');
217     testGeothermalFlux=~isempty(dir(tmp1));
218 gforget 1.15 diags_diff_snapshots(dirSnap,dirMat,'budg2d_snap_set1');
219 gforget 1.13 if ~test3d;
220 gforget 1.15 diags_diff_snapshots(dirSnap,dirMat,'budg2d_snap_set2');
221 gforget 1.16 if testGeothermalFlux; diags_budg_geothermal(dirSnap,dirMat,'budg2d_snap_set2'); end;
222 gforget 1.13 else;
223 gforget 1.15 diags_diff_snapshots(dirSnap,dirMat,'budg3d_snap_set1');
224 gforget 1.16 if testGeothermalFlux; diags_budg_geothermal(dirSnap,dirMat,'budg3d_snap_set1'); end;
225 gforget 1.13 end;
226 gforget 1.1 budget_list=1;
227     for kk=1:length(mygrid.RC);
228 gforget 1.15 tmp1=sprintf('%s/budg2d_snap_set3_%02i*',dirSnap,kk);
229 gforget 1.1 tmp2=~isempty(dir(tmp1));
230     if tmp2;
231     budget_list=[budget_list kk];
232     tmp1=sprintf('budg2d_snap_set3_%02i',kk);
233 gforget 1.15 diags_diff_snapshots(dirSnap,dirMat,tmp1);
234 gforget 1.16 if testGeothermalFlux; diags_budg_geothermal(dirSnap,dirMat,tmp1); end;
235 gforget 1.1 end;
236     end;
237     eval(['save ' dirMat 'diags_select_budget_list.mat budget_list;']);
238 gforget 1.7 delete([dirMat 'lock_budg']);
239 gforget 1.1 test1=1;
240     fprintf(['pre-processing : completed for budget \n\n']);
241     end;
242    
243     while ~test1&doBudget;%this process will wait for pre-processing to complete
244     fprintf(['waiting 30s more for removal of ' dirMat 'lock_budg \n']);
245 gforget 1.2 fprintf(['- That should happen automatically after pre-processing is complete \n']);
246     fprintf(['- But if a previous session was interupted, you may need to stop this one, \n ']);
247     fprintf([' remove ' dirMat 'lock_budg manually, and start over. \n\n']);
248 gforget 1.1 test1=isempty(dir([dirMat 'lock_budg']));
249     pause(30);
250     end;
251    
252 gforget 1.10 %set budget list
253     myparms.budgetList=1;
254     if ~isempty(dir([dirMat 'diags_select_budget_list.mat']));
255     eval(['load ' dirMat 'diags_select_budget_list.mat;']);
256     myparms.budgetList=budget_list;
257     end;

  ViewVC Help
Powered by ViewVC 1.1.22