1 | %'aver_stat': calculate field average over a time series |
---|
2 | %------------------------------------------------------------------------ |
---|
3 | % function ParamOut=aver_stat(Param) |
---|
4 | % |
---|
5 | %%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
6 | % |
---|
7 | %OUTPUT |
---|
8 | % ParamOut: sets options in the GUI series.fig needed for the function |
---|
9 | % |
---|
10 | %INPUT: |
---|
11 | % In run mode, the input parameters are given as a Matlab structure Param copied from the GUI series. |
---|
12 | % In batch mode, Param is the name of the corresponding xml file containing the same information |
---|
13 | % when Param.Action.RUN=0 (as activated when the current Action is selected |
---|
14 | % in series), the function ouput paramOut set the activation of the needed GUI elements |
---|
15 | % |
---|
16 | % Param contains the elements:(use the menu bar command 'export/GUI config' in series to |
---|
17 | % see the current structure Param) |
---|
18 | % .InputTable: cell of input file names, (several lines for multiple input) |
---|
19 | % each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension} |
---|
20 | % .OutputSubDir: name of the subdirectory for data outputs |
---|
21 | % .OutputDirExt: directory extension for data outputs |
---|
22 | % .Action: .ActionName: name of the current activated function |
---|
23 | % .ActionPath: path of the current activated function |
---|
24 | % .ActionExt: fct extension ('.m', Matlab fct, '.sh', compiled Matlab fct |
---|
25 | % .RUN =0 for GUI input, =1 for function activation |
---|
26 | % .RunMode='local','background', 'cluster': type of function use |
---|
27 | % |
---|
28 | % .IndexRange: set the file or frame indices on which the action must be performed |
---|
29 | % .FieldTransform: .TransformName: name of the selected transform function |
---|
30 | % .TransformPath: path of the selected transform function |
---|
31 | % .InputFields: sub structure describing the input fields withfields |
---|
32 | % .FieldName: name(s) of the field |
---|
33 | % .VelType: velocity type |
---|
34 | % .FieldName_1: name of the second field in case of two input series |
---|
35 | % .VelType_1: velocity type of the second field in case of two input series |
---|
36 | % .Coord_y: name of y coordinate variable |
---|
37 | % .Coord_x: name of x coordinate variable |
---|
38 | % .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object) |
---|
39 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
40 | |
---|
41 | function ParamOut=aver_synchro(Param) |
---|
42 | |
---|
43 | %% set the input elements needed on the GUI series when the action is selected in the menu ActionName |
---|
44 | if isstruct(Param) && isequal(Param.Action.RUN,0) |
---|
45 | ParamOut.AllowInputSort='off';% allow alphabetic sorting of the list of input file SubDir (options 'off'/'on', 'off' by default) |
---|
46 | ParamOut.WholeIndexRange='off';% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default) |
---|
47 | ParamOut.NbSlice='on'; %nbre of slices ('off' by default) |
---|
48 | ParamOut.VelType='two';% menu for selecting the velocity type (options 'off'/'one'/'two', 'off' by default) |
---|
49 | ParamOut.FieldName='two';% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default) |
---|
50 | ParamOut.FieldTransform = 'on';%can use a transform function |
---|
51 | ParamOut.ProjObject='on';%can use projection object(option 'off'/'on', |
---|
52 | ParamOut.Mask='off';%can use mask option (option 'off'/'on', 'off' by default) |
---|
53 | ParamOut.OutputDirExt='.synchro';%set the output dir extension |
---|
54 | ParamOut.OutputFileMode='NbSlice';% '=NbInput': 1 output file per input file index, '=NbInput_i': 1 file per input file index i, '=NbSlice': 1 file per slice |
---|
55 | % filecell=get_file_series(Param);%check existence of the first input file |
---|
56 | % if ~exist(filecell{1,1},'file') |
---|
57 | % msgbox_uvmat('WARNING','the first input file does not exist') |
---|
58 | % end |
---|
59 | def={'26'}; |
---|
60 | if isfield (Param,'ActionInput')&& isfield(Param.ActionInput,'WavePeriod') |
---|
61 | def=Param.ActionInput.WavePeriod; |
---|
62 | |
---|
63 | def={num2str(def)}; |
---|
64 | end |
---|
65 | prompt={'wave period'}; |
---|
66 | dlgTitle='primary period'; |
---|
67 | lineNo=1; |
---|
68 | answer=inputdlg(prompt,dlgTitle,lineNo,def); |
---|
69 | ParamOut.ActionInput.WavePeriod=str2num(answer{1}); |
---|
70 | return |
---|
71 | end |
---|
72 | |
---|
73 | %%%%%%%%%%%% STANDARD PART %%%%%%%%%%%% |
---|
74 | ParamOut=[];%default output |
---|
75 | %% read input parameters from an xml file if input is a file name (batch mode) |
---|
76 | checkrun=1; |
---|
77 | if ischar(Param) |
---|
78 | Param=xml2struct(Param);% read Param as input file (batch case) |
---|
79 | checkrun=0; |
---|
80 | end |
---|
81 | hseries=findobj(allchild(0),'Tag','series'); |
---|
82 | RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series |
---|
83 | WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series |
---|
84 | |
---|
85 | %% define the directory for result file (with path=RootPath{1}) |
---|
86 | OutputDir=[Param.OutputSubDir Param.OutputDirExt]; |
---|
87 | |
---|
88 | %% root input file(s) name, type and index series |
---|
89 | RootPath=Param.InputTable(:,1); |
---|
90 | RootFile=Param.InputTable(:,3); |
---|
91 | SubDir=Param.InputTable(:,2); |
---|
92 | NomType=Param.InputTable(:,4); |
---|
93 | FileExt=Param.InputTable(:,5); |
---|
94 | [filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param); |
---|
95 | [FileType,FileInfo]=get_file_type(filecell{1,1}); |
---|
96 | %%%%%%%%%%%% |
---|
97 | % The cell array filecell is the list of input file names, while |
---|
98 | % filecell{iview,fileindex}: |
---|
99 | % iview: line in the table corresponding to a given file series |
---|
100 | % fileindex: file index within the file series, |
---|
101 | % i1_series(iview,ref_j,ref_i)... are the corresponding arrays of indices i1,i2,j1,j2, depending on the input line iview and the two reference indices ref_i,ref_j |
---|
102 | % i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices |
---|
103 | %%%%%%%%%%%% |
---|
104 | nbview=numel(i1_series);%number of input file series (lines in InputTable) |
---|
105 | nbfield_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices) |
---|
106 | nbfield_i=size(i1_series{1},2); %nb of fields for the i index |
---|
107 | nbfield=nbfield_j*nbfield_i; %total number of fields |
---|
108 | |
---|
109 | %% determine the input file type |
---|
110 | % if ~strcmp(FileType{1},'netcdf') |
---|
111 | % displ_uvmat('ERROR','netcdf file series with field projected on a regular mesh must be put as input') |
---|
112 | % return |
---|
113 | % end |
---|
114 | |
---|
115 | %% calibration data and timing: read the ImaDoc files |
---|
116 | [XmlData,NbSlice_calib,time,errormsg]=read_multimadoc(RootPath,SubDir,RootFile,FileExt,i1_series,i2_series,j1_series,j2_series); |
---|
117 | % if size(time,1)>1 |
---|
118 | % diff_time=max(max(diff(time))); |
---|
119 | % if diff_time>0 |
---|
120 | % msgbox_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time)]) |
---|
121 | % end |
---|
122 | % end |
---|
123 | |
---|
124 | %% coordinate transform or other user defined transform |
---|
125 | transform_fct='';%default |
---|
126 | if isfield(Param,'FieldTransform')&&~isempty(Param.FieldTransform.TransformName) |
---|
127 | addpath(Param.FieldTransform.TransformPath) |
---|
128 | transform_fct=str2func(Param.FieldTransform.TransformName); |
---|
129 | rmpath(Param.FieldTransform.TransformPath) |
---|
130 | end |
---|
131 | |
---|
132 | %% settings for the output file |
---|
133 | NomTypeOut=nomtype2pair(NomType{1});% determine the index nomenclature type for the output file |
---|
134 | first_i=i1_series{1}(1); |
---|
135 | last_i=i1_series{1}(end); |
---|
136 | if isempty(j1_series{1})% if there is no second index j |
---|
137 | first_j=1;last_j=1; |
---|
138 | else |
---|
139 | first_j=j1_series{1}(1); |
---|
140 | last_j=j1_series{1}(end); |
---|
141 | end |
---|
142 | |
---|
143 | %% Set field names and velocity types |
---|
144 | InputFields{1}=[];%default (case of images) |
---|
145 | if isfield(Param,'InputFields') |
---|
146 | InputFields{1}=Param.InputFields; |
---|
147 | end |
---|
148 | |
---|
149 | % for i_slice=1:NbSlice |
---|
150 | % index_slice=i_slice:NbSlice:nbfield;% select file indices of the slice |
---|
151 | nbfiles=0; |
---|
152 | nbmissing=0; |
---|
153 | MeanU=0; |
---|
154 | MeanV=0; |
---|
155 | MinU=0; |
---|
156 | MaxU=0; |
---|
157 | MinV=0; |
---|
158 | MaxV=0; |
---|
159 | vec_X=0; |
---|
160 | vec_Y=0; |
---|
161 | vec_U=0; %initiate the sum |
---|
162 | vec_V=0; |
---|
163 | cos1_U=0; |
---|
164 | cos1_V=0; |
---|
165 | sin1_U=0; |
---|
166 | sin1_V=0; |
---|
167 | cos2_U=0; |
---|
168 | cos2_V=0; |
---|
169 | sin2_U=0; |
---|
170 | sin2_V=0; |
---|
171 | cos3_U=0; |
---|
172 | cos3_V=0; |
---|
173 | sin3_U=0; |
---|
174 | sin3_V=0; |
---|
175 | cossub_U=0; |
---|
176 | cossub_V=0; |
---|
177 | sinsub_U=0; |
---|
178 | sigma1=2*pi/Param.ActionInput.WavePeriod;%primary wave frequency |
---|
179 | sigma2=4*pi/Param.ActionInput.WavePeriod;%harmonic 2 |
---|
180 | sigma3=6*pi/Param.ActionInput.WavePeriod;%harmonic 3 |
---|
181 | sigma_sub=pi/Param.ActionInput.WavePeriod;%subharmonic |
---|
182 | sinsub_V=0; |
---|
183 | vec_C=0; |
---|
184 | |
---|
185 | %%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%% |
---|
186 | for index=1:nbfield |
---|
187 | update_waitbar(WaitbarHandle,index/nbfield) |
---|
188 | if ~isempty(RUNHandle)&& ~strcmp(get(RUNHandle,'BusyAction'),'queue') |
---|
189 | disp('program stopped by user') |
---|
190 | break |
---|
191 | end |
---|
192 | |
---|
193 | % reading input file(s) |
---|
194 | [Data,tild,errormsg] = read_field(filecell{1,index},FileType,InputFields{1}); |
---|
195 | if ~isempty(errormsg) |
---|
196 | displ_uvmat('ERROR',['error of input reading: ' errormsg],checkrun); |
---|
197 | break |
---|
198 | end |
---|
199 | if ~isempty(NbSlice_calib) |
---|
200 | Data.ZIndex=mod(i1_series{1}(index)-1,NbSlice_calib{1})+1;%Zindex for phys transform |
---|
201 | end |
---|
202 | %update average |
---|
203 | MeanU=MeanU+Data.U; |
---|
204 | MeanV=MeanV+Data.V; |
---|
205 | MaxU=(MaxU>=Data.U).*MaxU+(MaxU<Data.U).*Data.U; |
---|
206 | MinU=(MinU<=Data.U).*MinU+(MinU>Data.U).*Data.U; |
---|
207 | MaxV=(MaxV>=Data.V).*MaxV+(MaxV<Data.V).*Data.V; |
---|
208 | MinV=(MinV<=Data.V).*MinV+(MinV>Data.V).*Data.V; |
---|
209 | cos1_U=cos1_U+Data.U*cos(Data.Time*sigma1); |
---|
210 | cos1_V=cos1_V+Data.V*cos(Data.Time*sigma1); |
---|
211 | sin1_U=sin1_U+Data.U*sin(Data.Time*sigma1); |
---|
212 | sin1_V=sin1_V+Data.V*sin(Data.Time*sigma1); |
---|
213 | cos2_U=cos2_U+Data.U*cos(Data.Time*sigma2); |
---|
214 | cos2_V=cos2_V+Data.V*cos(Data.Time*sigma2); |
---|
215 | sin2_U=sin2_U+Data.U*sin(Data.Time*sigma2); |
---|
216 | sin2_V=sin2_V+Data.V*sin(Data.Time*sigma2); |
---|
217 | cos3_U=cos3_U+Data.U*cos(Data.Time*sigma3); |
---|
218 | cos3_V=cos3_V+Data.V*cos(Data.Time*sigma3); |
---|
219 | sin3_U=sin3_U+Data.U*sin(Data.Time*sigma3); |
---|
220 | sin3_V=sin3_V+Data.V*sin(Data.Time*sigma3); |
---|
221 | cossub_U=cossub_U+Data.U*cos(Data.Time*sigma_sub); |
---|
222 | cossub_V=cossub_V+Data.V*cos(Data.Time*sigma_sub); |
---|
223 | sinsub_U=sinsub_U+Data.U*sin(Data.Time*sigma_sub); |
---|
224 | sinsub_V=sinsub_V+Data.V*sin(Data.Time*sigma_sub); |
---|
225 | |
---|
226 | |
---|
227 | end |
---|
228 | |
---|
229 | %%%%%%%%%%%%%%%%%%%%%%%% |
---|
230 | Data.ListVarName={'X','Y','MeanU','MeanV','cos1_U','cos1_V','a1_U','a1_V','a2_U','a2_V','a3_U','a3_V','asub_U','asub_V',... |
---|
231 | 'phase1_U','phase1_V','phase2_U','phase2_V','phase3_U','phase3_V'}; |
---|
232 | %Data.ListVarName=[{'coord_y','coord_x'} Data.ListVarName]; |
---|
233 | %Data.VarDimName={'coord_y', 'coord_x'}; |
---|
234 | for ilist=1:numel(Data.ListVarName) |
---|
235 | %Data.VarDimName{ilist+2}={'coord_y','coord_x'}; |
---|
236 | Data.VarDimName{ilist}='nb_vectors'; |
---|
237 | end |
---|
238 | Data.MeanU=MeanU/nbfield; |
---|
239 | Data.MeanV=MeanV/nbfield; |
---|
240 | Data.cos1_U=cos1_U/nbfield; |
---|
241 | Data.cos1_V=cos1_V/nbfield; |
---|
242 | sin1_U=sin1_U/nbfield; |
---|
243 | sin1_V=sin1_V/nbfield; |
---|
244 | cos2_U=cos2_U/nbfield; |
---|
245 | cos2_V=cos2_V/nbfield; |
---|
246 | sin2_U=sin2_U/nbfield; |
---|
247 | sin2_V=sin2_V/nbfield; |
---|
248 | cos3_U=cos3_U/nbfield; |
---|
249 | cos3_V=cos3_V/nbfield; |
---|
250 | sin3_U=sin3_U/nbfield; |
---|
251 | sin3_V=sin3_V/nbfield; |
---|
252 | cossub_U=cossub_U/nbfield; |
---|
253 | cossub_V=cossub_V/nbfield; |
---|
254 | sinsub_U=sinsub_U/nbfield; |
---|
255 | sinsub_V=sinsub_V/nbfield; |
---|
256 | Data.a1_U=sqrt(2)*sqrt(Data.cos1_U.*Data.cos1_U+sin1_U.*sin1_U); |
---|
257 | Data.a1_V=-sqrt(2)*sqrt(Data.cos1_V.*Data.cos1_V+sin1_V.*sin1_V); |
---|
258 | Data.a2_U=sqrt(2)*sqrt(cos2_U.*cos2_U+sin2_U.*sin2_U); |
---|
259 | Data.a2_V=-sqrt(2)*sqrt(cos2_V.*cos2_V+sin2_V.*sin2_V); |
---|
260 | Data.a3_U=sqrt(2)*sqrt(cos3_U.*cos3_U+sin3_U.*sin3_U); |
---|
261 | Data.a3_V=-sqrt(2)*sqrt(cos3_V.*cos3_V+sin3_V.*sin3_V); |
---|
262 | Data.asub_U=sqrt(2)*sqrt(cossub_U.*cossub_U+sinsub_U.*sinsub_U); |
---|
263 | Data.asub_V=-sqrt(2)*sqrt(cossub_V.*cossub_V+sinsub_V.*sinsub_V); |
---|
264 | clear i |
---|
265 | Data.phase1_U=(angle(cos1_U+i*sin1_U)); |
---|
266 | Data.phase1_V=angle(cos1_V+i*sin1_V); |
---|
267 | Data.phase2_U=(angle(cos2_U+i*sin2_U)); |
---|
268 | Data.phase2_V=(angle(cos2_V+i*sin2_V)); |
---|
269 | Data.phase3_U=(angle(cos3_U+i*sin3_U)); |
---|
270 | Data.phase3_V=(angle(cos3_V+i*sin3_V)); |
---|
271 | Data.phasesub_U=(angle(cossub_U+i*sinsub_U)); |
---|
272 | Data.phasesub_V=(angle(cossub_V+i*sinsub_V)); |
---|
273 | |
---|
274 | %% write the results |
---|
275 | OutputFile=fullfile_uvmat(RootPath{1},OutputDir,RootFile{1},'.nc','',1); |
---|
276 | errormsg=struct2nc(OutputFile,Data)% write the output file |
---|
277 | |
---|
278 | %% open the result file with uvmat (in RUN mode) |
---|
279 | % if checkrun |
---|
280 | % uvmat(OutputFile)% open the last result file with uvmat |
---|
281 | % end |
---|
282 | '#### THE END ####' |
---|