/[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.15 - (hide annotations) (download)
Mon Oct 5 16:51:44 2015 UTC (9 years, 9 months ago) by gforget
Branch: MAIN
CVS Tags: checkpoint65p
Changes since 1.14: +38 -17 lines
- improved treatment of directory names, switches, and driver.

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

  ViewVC Help
Powered by ViewVC 1.1.22