/[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.19 - (hide annotations) (download)
Tue Feb 16 02:33:25 2016 UTC (9 years, 5 months ago) by gforget
Branch: MAIN
CVS Tags: checkpoint65v, checkpoint65u
Changes since 1.18: +14 -4 lines
- revise handling of files (use copyfile rather than cp; myenv.diagsdir).

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

  ViewVC Help
Powered by ViewVC 1.1.22