/[MITgcm]/MITgcm_contrib/gael/matlab_class/gcmfaces_diags/diags_select.m
ViewVC logotype

Annotation of /MITgcm_contrib/gael/matlab_class/gcmfaces_diags/diags_select.m

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (hide annotations) (download)
Thu Nov 1 19:07:16 2012 UTC (12 years, 8 months ago) by gforget
Branch: MAIN
- more modular, and suposedly more user-friendly, version
  of ecco_v4/comp_driver.m and basic_diags_ecco.m

1 gforget 1.1 function []=basic_diags_ecco(dirModel,dirMat,setDiags,lChunk,iChunk,varargin);
2     %object: compute a set of basic diagnostics
3     %input: dirModel is the model run directory
4     % dirMat is the directory where diagnozed .mat files will be saved
5     % -> set it to '' to use the default [dirModel 'mat/']
6     % setDiags is the choice of diagnostics
7     % 'A') trasnports (see diags_set_A.m)
8     % 'B') air-sea fluxes
9     % 'C') state variables
10     % 'D') global and regional budgets
11     % 'LAYERS') T/S/RHO coordinate overturns
12     % 'user') is a placeholder for user diags additions
13     % lChunk states how many records are computed at once
14     % iChunk states which part of the records should be
15     % computed (i0+1:i0+lChunk where i0~lTot/lChunk)
16    
17     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18     %create dirModel/mat if needed:
19     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20    
21     dirModel=[dirModel '/'];
22    
23     if isempty(dirMat); dirMat=[dirModel 'mat/']; end;
24     if isempty(dir(dirMat)); eval(['!mkdir ' dirMat ';']); end;
25    
26     %list of subdirectories where to scan for output
27     listSubdirs={[dirMat 'BUDG/' ],[dirModel 'diags/BUDG/' ],[dirModel 'diags/OTHER/' ],...
28     [dirModel 'diags/STATE/' ],[dirModel 'diags/TRSP/'],[dirModel 'diags/' ]};
29    
30     setDiagsParams=[];
31     if iscell(setDiags);
32     setDiagsParams={setDiags{2:end}};
33     setDiags=setDiags{1};
34     end;
35    
36     %%%%%%%%%%%%%%%%%%%%%%
37     %load grid and params:
38     %%%%%%%%%%%%%%%%%%%%%%
39    
40     gcmfaces_global; global myparms;
41     test0=~isempty(dir([dirMat 'diags_grid_parms.mat']));
42     test1=~isempty(dir([dirMat 'basic_diags_ecco_mygrid.mat']));
43     if test0;%load mygrid and myparms from file
44     eval(['load ' dirMat 'diags_grid_parms.mat;']);
45     elseif test1;%for backward compatibility
46     eval(['load ' dirMat 'basic_diags_ecco_mygrid.mat;']);
47     else;
48     error('could not find diags_grid_parms.mat');
49     end;
50    
51     %%%%%%%%%%%%%%
52     %define diags:
53     %%%%%%%%%%%%%%
54    
55     userStep=1;
56     if ~isempty(which(['diags_set_' setDiags]));
57     eval(['diags_set_' setDiags]);
58     else;
59     diags_set_user;
60     end;
61    
62     %reformat listDiags to cell array:
63     jj=strfind(listDiags,' '); jj=[0 jj length(listDiags)+1];
64     for ii=1:length(jj)-1;
65     tmp1=listDiags(jj(ii)+1:jj(ii+1)-1);
66     if ii==1; listDiags2={tmp1}; else; listDiags2{ii}=tmp1; end;
67     end;
68     listDiags=listDiags2; clear listDiags2;
69    
70     %%%%%%%%%%%%%%
71     %detect files:
72     %%%%%%%%%%%%%%
73    
74     userStep=2;
75     if ~isempty(which(['diags_set_' setDiags]));
76     eval(['diags_set_' setDiags]);
77     else;
78     diags_set_user;
79     end;
80    
81     %remove blanks in pkg/diagnostics flds name
82     listFlds=deblank(listFlds);
83     listFldsNames=deblank(listFldsNames);
84    
85     %set the list of diags times
86     [listTimes]=diags_list_times(listSubdirs,listFiles);
87    
88     %then scan directories (listSubdirs) for files (listFiles)
89     for ii=1:length(listFiles);
90     tmp0='';
91     for jj=1:length(listSubdirs);
92     tmp1=listFiles{ii}; tmp2=listSubdirs{jj};
93     if ~isempty(dir([tmp2 '/' tmp1 '*meta']));
94     tmp0=[tmp2 '/' tmp1]; listFiles{ii}=tmp0;
95     end;
96     end;
97     if isempty(tmp0); fprintf([' not found: ' tmp1 '\n']); listFiles{ii}=''; end;
98     end;
99    
100     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
101     %load records for computation:
102     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
103    
104     lTot=length(listTimes);
105     i0=min(lChunk*(iChunk-1),lTot);
106     i1=min(i0+lChunk,lTot);
107    
108     tic;
109     tt=listTimes([i0+1:i1])';
110     for iFile=1:length(listFiles);
111     fileFld=listFiles{iFile};
112     if ~isempty(fileFld);
113     rdmds2workspace_list(fileFld,tt,listFlds);
114     for ii=1:length(meta.fldList);
115     tmp1=deblank(meta.fldList{ii});
116     jj=find(strcmp(tmp1,listFlds));
117     if ~isempty(jj); eval(['all_' listFldsNames{jj} '=' tmp1 ';']); end;
118     eval(['clear ' tmp1]);
119     end;
120     end;
121     end;
122     fprintf([num2str(i1-i0) ' records loaded in ' num2str(toc) '\n']);
123    
124     %check that all fields were found, and otherwise reduce listFlds
125     listFldsIsPresent=zeros(1,length(listFldsNames));
126     for iFld=1:length(listFldsNames);
127     fldName=['all_' listFldsNames{iFld}];
128     if isempty(who(fldName));
129     fprintf([fldName ' is missing \n']);
130     else;
131     listFldsIsPresent(iFld)=1;
132     % fprintf([fldName ' was found \n']);
133     end;
134     end;
135     listFldsNames={listFldsNames{find(listFldsIsPresent)}};
136     listFlds={listFlds{find(listFldsIsPresent)}};
137    
138     %%%%%%%%%%%%%%%%%%%%
139     %do the computation:
140     %%%%%%%%%%%%%%%%%%%%
141     for ii=i0+1:i1;
142    
143     tic;
144     tt=listTimes(ii);
145    
146     %get data from buffer
147     for jj=1:length(listFldsNames);
148     if lChunk==1|length(listTimes)==1;
149     eval([listFldsNames{jj} '=all_' listFldsNames{jj} ';']);
150     else;
151     eval(['tmp1=size(all_' listFldsNames{jj} '{1});']);
152     if length(tmp1)==4; eval([listFldsNames{jj} '=all_' listFldsNames{jj} '(:,:,:,ii-i0);']);
153     else; eval([listFldsNames{jj} '=all_' listFldsNames{jj} '(:,:,ii-i0);']);
154     end;
155     end;
156     end;
157     fprintf([num2str(ii-i0) '/' num2str(i1-i0) ' started \n']);
158    
159     %generic output file name (that will potentially be overriden)
160     tmp1=setDiags;
161     fileMat=['diags_set_' tmp1 '_' num2str(tt) '.mat'];
162    
163     %the actual computations
164     userStep=3;
165     if ~isempty(which(['diags_set_' setDiags]));
166     eval(['diags_set_' setDiags]);
167     else;
168     diags_set_user;
169     end;
170    
171     %package results
172     onediag=[];
173     onediag.listTimes=myparms.yearFirst(1)+tt*myparms.timeStep/86400/365.25;
174     onediag.listSteps=tt;
175     for jj=1:length(listDiags);
176     eval(['onediag.' listDiags{jj} '=' listDiags{jj} ';']);
177     end;
178    
179     %write to disk
180     diags_store_to_mat(dirMat,fileMat,onediag);
181    
182     fprintf([num2str(ii) '/' num2str(length(listTimes)) ' done in ' num2str(toc) '\n']);
183    
184     end;
185    
186    

  ViewVC Help
Powered by ViewVC 1.1.22