/[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.6 - (hide annotations) (download)
Tue Feb 4 22:15:35 2014 UTC (11 years, 5 months ago) by gforget
Branch: MAIN
Changes since 1.5: +32 -0 lines
- add switch for binaries / nctiles input format.

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     if isempty(dir(dirMat)); eval(['!mkdir ' dirMat ';']); end;
59    
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     eval(['!\rm ' dirMat 'lock_mygrid']);
77     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     eval(['!mkdir ' dirMat 'profiles/;']);
103     eval(['!ln -s /net/nares/raid11/ecco-shared/ecco-version-4/input/input_insitu ' dirMat 'profiles/input']);
104     eval(['!mkdir ' dirMat 'profiles/output']);
105     if dirModel(1)~='/'; dirModelFull=[pwd '/' dirModel]; else; dirModelFull=dirModel; end;
106     eval(['!ln -s ' dirModelFull 'profiles/*equi.data ' dirMat 'profiles/.']);
107 gforget 1.4 listModel={'argo_feb2013_1992_to_2007*','argo_feb2013_2008_to_2010*',...
108 gforget 1.3 'argo_feb2013_2011_to_2012*','ctd_feb2013*','itp_feb2013*',...
109     'seals_feb2013*','xbt_feb2013*','climode_feb2013*'};
110 gforget 1.1 MITprof_gcm2nc([dirMat 'profiles/'],listModel);
111     eval(['!\rm ' dirMat 'lock_profiles']);
112     test1=1;
113     fprintf(['pre-processing : completed for profiles \n\n']);
114     end;
115    
116     while ~test1&doProfiles;%this process will wait for pre-processing to complete
117     fprintf(['waiting 30s for removal of ' dirMat 'lock_profiles \n']);
118 gforget 1.2 fprintf(['- That should happen automatically after pre-processing is complete \n']);
119     fprintf(['- But if a previous session was interupted, you may need to stop this one, \n ']);
120     fprintf([' remove ' dirMat 'lock_profiles manually, and start over. \n\n']);
121 gforget 1.1 test1=isempty(dir([dirMat 'lock_profiles']));
122     pause(30);
123     end;
124    
125     %3) budget pre-processing
126     test0=isempty(dir([dirMat 'BUDG/']));
127     test1=isempty(dir([dirMat 'lock_budg']));%this aims at having only one process do the
128    
129     if (test0&test1&doBudget);
130     fprintf(['pre-processing : started for budget \n']);
131     write2file([dirMat 'lock_budg'],1);
132     eval(['!mkdir ' dirMat 'BUDG/;']);
133     %compute time derivatives between snwpshots that will be
134     %compared in budgets with the time mean flux terms
135 gforget 1.5 diags_diff_snapshots(dirModel,dirMat,'budg2d_snap_set1');
136     diags_diff_snapshots(dirModel,dirMat,'budg2d_snap_set2');
137     diags_diff_snapshots(dirModel,dirMat,'budg2d_snap_set3');
138     %diags_diff_snapshots(dirModel,dirMat,'budg3d_snap_set1');
139 gforget 1.1 budget_list=1;
140     for kk=1:length(mygrid.RC);
141     tmp1=sprintf('%s/diags/BUDG/budg2d_snap_set3_%02i*',dirModel,kk);
142     tmp2=~isempty(dir(tmp1));
143     if tmp2;
144     budget_list=[budget_list kk];
145     tmp1=sprintf('budg2d_snap_set3_%02i',kk);
146 gforget 1.5 diags_diff_snapshots(dirModel,dirMat,tmp1);
147 gforget 1.1 end;
148     end;
149     eval(['save ' dirMat 'diags_select_budget_list.mat budget_list;']);
150     eval(['!\rm ' dirMat 'lock_budg']);
151     test1=1;
152     fprintf(['pre-processing : completed for budget \n\n']);
153     end;
154    
155     while ~test1&doBudget;%this process will wait for pre-processing to complete
156     fprintf(['waiting 30s more for removal of ' dirMat 'lock_budg \n']);
157 gforget 1.2 fprintf(['- That should happen automatically after pre-processing is complete \n']);
158     fprintf(['- But if a previous session was interupted, you may need to stop this one, \n ']);
159     fprintf([' remove ' dirMat 'lock_budg manually, and start over. \n\n']);
160 gforget 1.1 test1=isempty(dir([dirMat 'lock_budg']));
161     pause(30);
162     end;
163    

  ViewVC Help
Powered by ViewVC 1.1.22