1 |
gforget |
1.1 |
function [myswitch]=diags_pre_process(dirModel,dirMat); |
2 |
|
|
%object : pre-processing for grid, model parameters, budgets, |
3 |
|
|
% profiles, cost and control, etc. |
4 |
|
|
% To be called at the the start of diags_driver |
5 |
|
|
%inputs : dirModel is the model run directory name |
6 |
|
|
% dirMat is the directory where diagnozed .mat files will be saved |
7 |
|
|
% -> set it to '' to use the default [dirModel 'mat/'] |
8 |
|
|
%output : myswitch is the set of switches (doBudget, doProfiles, doCost, doCtrl) |
9 |
|
|
% that are set here depending on the model output available |
10 |
|
|
|
11 |
|
|
gcmfaces_global; global myparms; |
12 |
|
|
|
13 |
|
|
dirModel=[dirModel '/']; |
14 |
|
|
if isempty(dirMat); dirMat=[dirModel 'mat/']; else; dirMat=[dirMat '/']; end; |
15 |
|
|
|
16 |
gforget |
1.6 |
%detect which types of files are avaiable |
17 |
|
|
test0=isdir([dirModel 'diags']); |
18 |
|
|
test1=isdir([dirModel 'nctiles']); |
19 |
|
|
if test0&test1; |
20 |
|
|
myenv.nctiles=input('select to use binaries (0) or nctiles (1) files\n'); |
21 |
|
|
elseif test0; |
22 |
|
|
myenv.nctiles=0; |
23 |
|
|
elseif test1; |
24 |
|
|
myenv.nctiles=1; |
25 |
|
|
else; |
26 |
|
|
error('no files (diags/ or nctiles/) were found\n'); |
27 |
|
|
end |
28 |
|
|
|
29 |
gforget |
1.1 |
doBudget=~isempty(dir([dirModel 'diags/BUDG/'])) |
30 |
gforget |
1.6 |
doBudget=doBudget&~myenv.nctiles; |
31 |
gforget |
1.1 |
doProfiles=~isempty(dir([dirModel 'profiles/'])) |
32 |
|
|
doCost=~isempty(dir([dirModel 'barfiles/'])) |
33 |
|
|
doCtrl=~isempty(dir([dirModel 'ADXXfiles/'])) |
34 |
|
|
|
35 |
|
|
%output switches |
36 |
|
|
myswitch.doBudget=doBudget; |
37 |
|
|
myswitch.doProfiles=doProfiles; |
38 |
|
|
myswitch.doCost=doCost; |
39 |
|
|
myswitch.doCtrl=doCtrl; |
40 |
|
|
|
41 |
gforget |
1.6 |
%set the list of diags directories and files |
42 |
|
|
if myenv.nctiles; |
43 |
|
|
listSubdirs={[pwd '/' dirModel 'nctiles/']}; |
44 |
|
|
listFiles=dir(listSubdirs{1}); listFiles={listFiles(:).name}; |
45 |
|
|
%remove irrelevant files/dirs |
46 |
|
|
test1=ones(size(listFiles)); |
47 |
|
|
for kk=1:length(listFiles); |
48 |
|
|
tmp1=[listSubdirs{1} listFiles{kk} '/' listFiles{kk} '*.nc']; |
49 |
|
|
test1(kk)=~isempty(dir(tmp1)); |
50 |
|
|
end; |
51 |
|
|
listFiles={listFiles{find(test1)}}; |
52 |
|
|
%store in myparms for later use |
53 |
|
|
myenv.nctilesdir=listSubdirs{1}; |
54 |
|
|
myenv.nctileslist=listFiles; |
55 |
|
|
end; |
56 |
|
|
|
57 |
gforget |
1.1 |
%0) create dirMat if needed: |
58 |
gforget |
1.7 |
if isempty(dir(dirMat)); mkdir(dirMat); end; |
59 |
gforget |
1.1 |
|
60 |
|
|
%1) pre-processing diags_grid_parms.mat |
61 |
|
|
test0=isempty(dir([dirMat 'diags_grid_parms.mat'])); |
62 |
|
|
test1=isempty(dir([dirMat 'lock_mygrid'])); |
63 |
|
|
|
64 |
|
|
if test0&test1;%this process will do the pre-processing |
65 |
|
|
fprintf(['pre-processing : started for mygrid \n']); |
66 |
|
|
write2file([dirMat 'lock_mygrid'],1); |
67 |
|
|
%set the list of diags times |
68 |
|
|
listSubdirs={[dirMat 'BUDG/' ],[dirModel 'diags/BUDG/' ],[dirModel 'diags/OTHER/' ],... |
69 |
|
|
[dirModel 'diags/STATE/' ],[dirModel 'diags/TRSP/'],[dirModel 'diags/' ]}; |
70 |
|
|
listFiles={'state_2d_set1','diags_2d_set1','monthly_2d_set1'}; |
71 |
|
|
[listTimes]=diags_list_times(listSubdirs,listFiles); |
72 |
|
|
%set grid and model parameters: |
73 |
|
|
diags_grid_parms(listTimes); |
74 |
|
|
%save to disk: |
75 |
|
|
eval(['save ' dirMat 'diags_grid_parms.mat mygrid myparms;']); |
76 |
gforget |
1.7 |
delete([dirMat 'lock_mygrid']); |
77 |
gforget |
1.1 |
test1=1; |
78 |
|
|
fprintf(['pre-processing : completed for mygrid \n\n']); |
79 |
|
|
end; |
80 |
|
|
|
81 |
gforget |
1.6 |
%here I should test that files are indeed found (may have been moved) |
82 |
|
|
|
83 |
gforget |
1.1 |
while ~test1;%this process will wait for pre-processing to complete |
84 |
|
|
fprintf(['waiting 30s for removal of ' dirMat 'lock_mygrid \n']); |
85 |
gforget |
1.2 |
fprintf(['- That should happen automatically after pre-processing is complete \n']); |
86 |
|
|
fprintf(['- But if a previous session was interupted, you may need to stop this one, \n ']); |
87 |
|
|
fprintf([' remove ' dirMat 'lock_grid manually, and start over. \n\n']); |
88 |
gforget |
1.1 |
test1=isempty(dir([dirMat 'lock_mygrid'])); |
89 |
|
|
pause(30); |
90 |
|
|
end; |
91 |
|
|
|
92 |
|
|
%here we always reload the grid from dirMat to make sure the same one is used throughout |
93 |
|
|
eval(['load ' dirMat 'diags_grid_parms.mat;']); |
94 |
|
|
|
95 |
|
|
%2) pre-processing profiles |
96 |
|
|
test0=isempty(dir([dirMat 'profiles/'])); |
97 |
|
|
test1=isempty(dir([dirMat 'lock_profiles'])); |
98 |
|
|
|
99 |
|
|
if test0&test1&doProfiles;%this process will do the pre-processing |
100 |
|
|
fprintf(['pre-processing : started for profiles \n']); |
101 |
|
|
write2file([dirMat 'lock_profiles'],1); |
102 |
gforget |
1.7 |
mkdir([dirMat 'profiles/']); |
103 |
|
|
% NOTE: if on DOS system change ln to mklink |
104 |
|
|
system(['ln -s /net/nares/raid11/ecco-shared/ecco-version-4/input/input_insitu ' dirMat 'profiles/input']); |
105 |
|
|
mkdir([dirMat 'profiles/output/']); |
106 |
gforget |
1.1 |
if dirModel(1)~='/'; dirModelFull=[pwd '/' dirModel]; else; dirModelFull=dirModel; end; |
107 |
gforget |
1.7 |
% NOTE: if on DOS system change ln to mklink |
108 |
|
|
system(['ln -s ' dirModelFull 'profiles/*equi.data ' dirMat 'profiles/.']); |
109 |
gforget |
1.4 |
listModel={'argo_feb2013_1992_to_2007*','argo_feb2013_2008_to_2010*',... |
110 |
gforget |
1.3 |
'argo_feb2013_2011_to_2012*','ctd_feb2013*','itp_feb2013*',... |
111 |
|
|
'seals_feb2013*','xbt_feb2013*','climode_feb2013*'}; |
112 |
gforget |
1.1 |
MITprof_gcm2nc([dirMat 'profiles/'],listModel); |
113 |
gforget |
1.7 |
delete([dirMat 'lock_profiles']); |
114 |
gforget |
1.1 |
test1=1; |
115 |
|
|
fprintf(['pre-processing : completed for profiles \n\n']); |
116 |
|
|
end; |
117 |
|
|
|
118 |
|
|
while ~test1&doProfiles;%this process will wait for pre-processing to complete |
119 |
|
|
fprintf(['waiting 30s for removal of ' dirMat 'lock_profiles \n']); |
120 |
gforget |
1.2 |
fprintf(['- That should happen automatically after pre-processing is complete \n']); |
121 |
|
|
fprintf(['- But if a previous session was interupted, you may need to stop this one, \n ']); |
122 |
|
|
fprintf([' remove ' dirMat 'lock_profiles manually, and start over. \n\n']); |
123 |
gforget |
1.1 |
test1=isempty(dir([dirMat 'lock_profiles'])); |
124 |
|
|
pause(30); |
125 |
|
|
end; |
126 |
|
|
|
127 |
|
|
%3) budget pre-processing |
128 |
|
|
test0=isempty(dir([dirMat 'BUDG/'])); |
129 |
|
|
test1=isempty(dir([dirMat 'lock_budg']));%this aims at having only one process do the |
130 |
|
|
|
131 |
|
|
if (test0&test1&doBudget); |
132 |
|
|
fprintf(['pre-processing : started for budget \n']); |
133 |
|
|
write2file([dirMat 'lock_budg'],1); |
134 |
gforget |
1.7 |
mkdir([dirMat 'BUDG/']); |
135 |
gforget |
1.1 |
%compute time derivatives between snwpshots that will be |
136 |
|
|
%compared in budgets with the time mean flux terms |
137 |
gforget |
1.5 |
diags_diff_snapshots(dirModel,dirMat,'budg2d_snap_set1'); |
138 |
|
|
diags_diff_snapshots(dirModel,dirMat,'budg2d_snap_set2'); |
139 |
|
|
diags_diff_snapshots(dirModel,dirMat,'budg2d_snap_set3'); |
140 |
|
|
%diags_diff_snapshots(dirModel,dirMat,'budg3d_snap_set1'); |
141 |
gforget |
1.1 |
budget_list=1; |
142 |
|
|
for kk=1:length(mygrid.RC); |
143 |
|
|
tmp1=sprintf('%s/diags/BUDG/budg2d_snap_set3_%02i*',dirModel,kk); |
144 |
|
|
tmp2=~isempty(dir(tmp1)); |
145 |
|
|
if tmp2; |
146 |
|
|
budget_list=[budget_list kk]; |
147 |
|
|
tmp1=sprintf('budg2d_snap_set3_%02i',kk); |
148 |
gforget |
1.5 |
diags_diff_snapshots(dirModel,dirMat,tmp1); |
149 |
gforget |
1.1 |
end; |
150 |
|
|
end; |
151 |
|
|
eval(['save ' dirMat 'diags_select_budget_list.mat budget_list;']); |
152 |
gforget |
1.7 |
delete([dirMat 'lock_budg']); |
153 |
gforget |
1.1 |
test1=1; |
154 |
|
|
fprintf(['pre-processing : completed for budget \n\n']); |
155 |
|
|
end; |
156 |
|
|
|
157 |
|
|
while ~test1&doBudget;%this process will wait for pre-processing to complete |
158 |
|
|
fprintf(['waiting 30s more for removal of ' dirMat 'lock_budg \n']); |
159 |
gforget |
1.2 |
fprintf(['- That should happen automatically after pre-processing is complete \n']); |
160 |
|
|
fprintf(['- But if a previous session was interupted, you may need to stop this one, \n ']); |
161 |
|
|
fprintf([' remove ' dirMat 'lock_budg manually, and start over. \n\n']); |
162 |
gforget |
1.1 |
test1=isempty(dir([dirMat 'lock_budg'])); |
163 |
|
|
pause(30); |
164 |
|
|
end; |
165 |
|
|
|