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 |
|
|
test0=isdir([dirModel 'diags']); |
21 |
gforget |
1.11 |
test1=~isempty(dir([dirModel 'nctiles*'])); |
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.12 |
if doInteractive&~myenv.nctiles;%only works with binaries |
33 |
|
|
doBudget=~isempty(dir([dirModel 'diags' filesep 'BUDG' filesep])) |
34 |
gforget |
1.10 |
doBudget=doBudget&~myenv.nctiles; |
35 |
gforget |
1.12 |
doCost=~isempty(dir([dirModel 'barfiles' filesep])) |
36 |
|
|
doCtrl=~isempty(dir([dirModel 'ADXXfiles' filesep])) |
37 |
gforget |
1.8 |
else; |
38 |
gforget |
1.10 |
doBudget=0; |
39 |
|
|
doCost=0; |
40 |
|
|
doCtrl=0; |
41 |
gforget |
1.8 |
end; |
42 |
|
|
|
43 |
gforget |
1.12 |
doProfiles=~isempty(dir([dirModel 'MITprof' filesep])); |
44 |
gforget |
1.8 |
preprocessProfiles=0; |
45 |
gforget |
1.12 |
myenv.profiles=fullfile(pwd,filesep,dirModel,'MITprof',filesep); |
46 |
gforget |
1.8 |
if ~doProfiles; |
47 |
gforget |
1.12 |
doProfiles=~isempty(dir([dirModel 'profiles' filesep])); |
48 |
gforget |
1.10 |
preprocessProfiles=1; |
49 |
gforget |
1.12 |
myenv.profiles=fullfile(pwd,filesep,dirMat,'profiles',filesep,'output',filesep); |
50 |
gforget |
1.8 |
end; |
51 |
gforget |
1.1 |
|
52 |
|
|
%output switches |
53 |
|
|
myswitch.doBudget=doBudget; |
54 |
|
|
myswitch.doProfiles=doProfiles; |
55 |
|
|
myswitch.doCost=doCost; |
56 |
|
|
myswitch.doCtrl=doCtrl; |
57 |
|
|
|
58 |
gforget |
1.6 |
%set the list of diags directories and files |
59 |
|
|
if myenv.nctiles; |
60 |
gforget |
1.12 |
if isdir(fullfile(pwd,dirModel,'nctiles',filesep)); |
61 |
|
|
listSubdirs={fullfile(pwd,dirModel,'nctiles',filesep)}; |
62 |
|
|
elseif isdir(fullfile(pwd,dirModel,'nctiles_climatology',filesep)); |
63 |
|
|
listSubdirs={fullfile(pwd,dirModel,'nctiles_climatology',filesep)}; |
64 |
gforget |
1.11 |
end; |
65 |
|
|
|
66 |
gforget |
1.6 |
listFiles=dir(listSubdirs{1}); listFiles={listFiles(:).name}; |
67 |
|
|
%remove irrelevant files/dirs |
68 |
|
|
test1=ones(size(listFiles)); |
69 |
|
|
for kk=1:length(listFiles); |
70 |
gforget |
1.12 |
tmp1=fullfile(listSubdirs{1},listFiles{kk},[listFiles{kk} '*.nc']); |
71 |
gforget |
1.10 |
test1(kk)=~isempty(dir(tmp1)); |
72 |
gforget |
1.6 |
end; |
73 |
|
|
listFiles={listFiles{find(test1)}}; |
74 |
|
|
%store in myparms for later use |
75 |
|
|
myenv.nctilesdir=listSubdirs{1}; |
76 |
|
|
myenv.nctileslist=listFiles; |
77 |
gforget |
1.12 |
% |
78 |
|
|
myenv.diagsdir=''; |
79 |
|
|
else; |
80 |
|
|
myenv.diagsdir=fullfile(pwd,dirModel,['diags' filesep]); |
81 |
|
|
% |
82 |
|
|
myenv.nctilesdir=''; |
83 |
|
|
myenv.nctileslist={}; |
84 |
gforget |
1.6 |
end; |
85 |
gforget |
1.12 |
myenv.matdir=fullfile(pwd,dirMat); |
86 |
gforget |
1.6 |
|
87 |
gforget |
1.1 |
%0) create dirMat if needed: |
88 |
gforget |
1.7 |
if isempty(dir(dirMat)); mkdir(dirMat); end; |
89 |
gforget |
1.1 |
|
90 |
|
|
%1) pre-processing diags_grid_parms.mat |
91 |
|
|
test0=isempty(dir([dirMat 'diags_grid_parms.mat'])); |
92 |
|
|
test1=isempty(dir([dirMat 'lock_mygrid'])); |
93 |
|
|
|
94 |
|
|
if test0&test1;%this process will do the pre-processing |
95 |
gforget |
1.8 |
fprintf(['pre-processing : started for mygrid, myparms \n']); |
96 |
gforget |
1.1 |
write2file([dirMat 'lock_mygrid'],1); |
97 |
|
|
%set the list of diags times |
98 |
gforget |
1.10 |
[listTimes]=diags_list_times; |
99 |
gforget |
1.1 |
%set grid and model parameters: |
100 |
gforget |
1.8 |
diags_grid_parms(listTimes,doInteractive); |
101 |
gforget |
1.1 |
%save to disk: |
102 |
gforget |
1.10 |
%if doInteractive; |
103 |
|
|
eval(['save ' dirMat 'diags_grid_parms.mat mygrid myparms;']); |
104 |
|
|
%end; |
105 |
gforget |
1.7 |
delete([dirMat 'lock_mygrid']); |
106 |
gforget |
1.1 |
test1=1; |
107 |
gforget |
1.8 |
fprintf(['pre-processing : completed for mygrid, myparms \n\n']); |
108 |
gforget |
1.1 |
end; |
109 |
|
|
|
110 |
gforget |
1.6 |
%here I should test that files are indeed found (may have been moved) |
111 |
|
|
|
112 |
gforget |
1.1 |
while ~test1;%this process will wait for pre-processing to complete |
113 |
|
|
fprintf(['waiting 30s for removal of ' dirMat 'lock_mygrid \n']); |
114 |
gforget |
1.2 |
fprintf(['- That should happen automatically after pre-processing is complete \n']); |
115 |
|
|
fprintf(['- But if a previous session was interupted, you may need to stop this one, \n ']); |
116 |
|
|
fprintf([' remove ' dirMat 'lock_grid manually, and start over. \n\n']); |
117 |
gforget |
1.1 |
test1=isempty(dir([dirMat 'lock_mygrid'])); |
118 |
|
|
pause(30); |
119 |
|
|
end; |
120 |
|
|
|
121 |
|
|
%here we always reload the grid from dirMat to make sure the same one is used throughout |
122 |
gforget |
1.10 |
eval(['load ' dirMat 'diags_grid_parms.mat;']); |
123 |
gforget |
1.1 |
|
124 |
|
|
%2) pre-processing profiles |
125 |
|
|
test0=isempty(dir([dirMat 'profiles/'])); |
126 |
|
|
test1=isempty(dir([dirMat 'lock_profiles'])); |
127 |
|
|
|
128 |
gforget |
1.8 |
if test0&test1&doProfiles&preprocessProfiles;%this process will do the pre-processing |
129 |
gforget |
1.1 |
fprintf(['pre-processing : started for profiles \n']); |
130 |
|
|
write2file([dirMat 'lock_profiles'],1); |
131 |
gforget |
1.7 |
mkdir([dirMat 'profiles/']); |
132 |
gforget |
1.10 |
% NOTE: if on DOS system change ln to mklink |
133 |
gforget |
1.7 |
system(['ln -s /net/nares/raid11/ecco-shared/ecco-version-4/input/input_insitu ' dirMat 'profiles/input']); |
134 |
|
|
mkdir([dirMat 'profiles/output/']); |
135 |
gforget |
1.1 |
if dirModel(1)~='/'; dirModelFull=[pwd '/' dirModel]; else; dirModelFull=dirModel; end; |
136 |
gforget |
1.10 |
% NOTE: if on DOS system change ln to mklink |
137 |
gforget |
1.7 |
system(['ln -s ' dirModelFull 'profiles/*equi.data ' dirMat 'profiles/.']); |
138 |
gforget |
1.4 |
listModel={'argo_feb2013_1992_to_2007*','argo_feb2013_2008_to_2010*',... |
139 |
gforget |
1.3 |
'argo_feb2013_2011_to_2012*','ctd_feb2013*','itp_feb2013*',... |
140 |
|
|
'seals_feb2013*','xbt_feb2013*','climode_feb2013*'}; |
141 |
gforget |
1.1 |
MITprof_gcm2nc([dirMat 'profiles/'],listModel); |
142 |
gforget |
1.7 |
delete([dirMat 'lock_profiles']); |
143 |
gforget |
1.1 |
test1=1; |
144 |
|
|
fprintf(['pre-processing : completed for profiles \n\n']); |
145 |
|
|
end; |
146 |
|
|
|
147 |
|
|
while ~test1&doProfiles;%this process will wait for pre-processing to complete |
148 |
|
|
fprintf(['waiting 30s for removal of ' dirMat 'lock_profiles \n']); |
149 |
gforget |
1.2 |
fprintf(['- That should happen automatically after pre-processing is complete \n']); |
150 |
|
|
fprintf(['- But if a previous session was interupted, you may need to stop this one, \n ']); |
151 |
|
|
fprintf([' remove ' dirMat 'lock_profiles manually, and start over. \n\n']); |
152 |
gforget |
1.1 |
test1=isempty(dir([dirMat 'lock_profiles'])); |
153 |
|
|
pause(30); |
154 |
|
|
end; |
155 |
|
|
|
156 |
|
|
%3) budget pre-processing |
157 |
gforget |
1.12 |
test0=isempty(dir([dirMat 'BUDG'])); |
158 |
gforget |
1.1 |
test1=isempty(dir([dirMat 'lock_budg']));%this aims at having only one process do the |
159 |
|
|
|
160 |
|
|
if (test0&test1&doBudget); |
161 |
|
|
fprintf(['pre-processing : started for budget \n']); |
162 |
|
|
write2file([dirMat 'lock_budg'],1); |
163 |
gforget |
1.12 |
mkdir([dirMat 'BUDG']); |
164 |
gforget |
1.1 |
%compute time derivatives between snwpshots that will be |
165 |
|
|
%compared in budgets with the time mean flux terms |
166 |
gforget |
1.5 |
diags_diff_snapshots(dirModel,dirMat,'budg2d_snap_set1'); |
167 |
|
|
diags_diff_snapshots(dirModel,dirMat,'budg2d_snap_set2'); |
168 |
|
|
diags_diff_snapshots(dirModel,dirMat,'budg2d_snap_set3'); |
169 |
|
|
%diags_diff_snapshots(dirModel,dirMat,'budg3d_snap_set1'); |
170 |
gforget |
1.1 |
budget_list=1; |
171 |
|
|
for kk=1:length(mygrid.RC); |
172 |
|
|
tmp1=sprintf('%s/diags/BUDG/budg2d_snap_set3_%02i*',dirModel,kk); |
173 |
|
|
tmp2=~isempty(dir(tmp1)); |
174 |
|
|
if tmp2; |
175 |
|
|
budget_list=[budget_list kk]; |
176 |
|
|
tmp1=sprintf('budg2d_snap_set3_%02i',kk); |
177 |
gforget |
1.5 |
diags_diff_snapshots(dirModel,dirMat,tmp1); |
178 |
gforget |
1.1 |
end; |
179 |
|
|
end; |
180 |
|
|
eval(['save ' dirMat 'diags_select_budget_list.mat budget_list;']); |
181 |
gforget |
1.7 |
delete([dirMat 'lock_budg']); |
182 |
gforget |
1.1 |
test1=1; |
183 |
|
|
fprintf(['pre-processing : completed for budget \n\n']); |
184 |
|
|
end; |
185 |
|
|
|
186 |
|
|
while ~test1&doBudget;%this process will wait for pre-processing to complete |
187 |
|
|
fprintf(['waiting 30s more for removal of ' dirMat 'lock_budg \n']); |
188 |
gforget |
1.2 |
fprintf(['- That should happen automatically after pre-processing is complete \n']); |
189 |
|
|
fprintf(['- But if a previous session was interupted, you may need to stop this one, \n ']); |
190 |
|
|
fprintf([' remove ' dirMat 'lock_budg manually, and start over. \n\n']); |
191 |
gforget |
1.1 |
test1=isempty(dir([dirMat 'lock_budg'])); |
192 |
|
|
pause(30); |
193 |
|
|
end; |
194 |
|
|
|
195 |
gforget |
1.10 |
%set budget list |
196 |
|
|
myparms.budgetList=1; |
197 |
|
|
if ~isempty(dir([dirMat 'diags_select_budget_list.mat'])); |
198 |
|
|
eval(['load ' dirMat 'diags_select_budget_list.mat;']); |
199 |
|
|
myparms.budgetList=budget_list; |
200 |
|
|
end; |