1 | %'time_series': extract a time series after projection on an object (points , line..) |
---|
2 | % this function can be used as a template for applying a global operation on a series of input fields |
---|
3 | %------------------------------------------------------------------------ |
---|
4 | % function GUI_input=time_series(Param) |
---|
5 | % |
---|
6 | %%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
7 | % |
---|
8 | %OUTPUT |
---|
9 | % ParamOut: sets options in the GUI series.fig needed for the function |
---|
10 | % |
---|
11 | %INPUT: |
---|
12 | % In run mode, the input parameters are given as a Matlab structure Param copied from the GUI series. |
---|
13 | % In batch mode, Param is the name of the corresponding xml file containing the same information |
---|
14 | % when Param.Action.RUN=0 (as activated when the current Action is selected |
---|
15 | % in series), the function ouput paramOut set the activation of the needed GUI elements |
---|
16 | % |
---|
17 | % Param contains the elements:(use the menu bar command 'export/GUI config' in series to |
---|
18 | % see the current structure Param) |
---|
19 | % .InputTable: cell of input file names, (several lines for multiple input) |
---|
20 | % each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension} |
---|
21 | % .OutputSubDir: name of the subdirectory for data outputs |
---|
22 | % .OutputDirExt: directory extension for data outputs |
---|
23 | % .Action: .ActionName: name of the current activated function |
---|
24 | % .ActionPath: path of the current activated function |
---|
25 | % .ActionExt: fct extension ('.m', Matlab fct, '.sh', compiled Matlab fct |
---|
26 | % .RUN =0 for GUI input, =1 for function activation |
---|
27 | % .RunMode='local','background', 'cluster': type of function use |
---|
28 | % |
---|
29 | % .IndexRange: set the file or frame indices on which the action must be performed |
---|
30 | % .FieldTransform: .TransformName: name of the selected transform function |
---|
31 | % .TransformPath: path of the selected transform function |
---|
32 | % .InputFields: sub structure describing the input fields withfields |
---|
33 | % .FieldName: name(s) of the field |
---|
34 | % .VelType: velocity type |
---|
35 | % .FieldName_1: name of the second field in case of two input series |
---|
36 | % .VelType_1: velocity type of the second field in case of two input series |
---|
37 | % .Coord_y: name of y coordinate variable |
---|
38 | % .Coord_x: name of x coordinate variable |
---|
39 | % .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object) |
---|
40 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
41 | |
---|
42 | %======================================================================= |
---|
43 | % Copyright 2008-2022, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France |
---|
44 | % http://www.legi.grenoble-inp.fr |
---|
45 | % Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr |
---|
46 | % |
---|
47 | % This file is part of the toolbox UVMAT. |
---|
48 | % |
---|
49 | % UVMAT is free software; you can redistribute it and/or modify |
---|
50 | % it under the terms of the GNU General Public License as published |
---|
51 | % by the Free Software Foundation; either version 2 of the license, |
---|
52 | % or (at your option) any later version. |
---|
53 | % |
---|
54 | % UVMAT is distributed in the hope that it will be useful, |
---|
55 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
56 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
57 | % GNU General Public License (see LICENSE.txt) for more details. |
---|
58 | %======================================================================= |
---|
59 | |
---|
60 | function ParamOut=time_series(Param) |
---|
61 | |
---|
62 | %% set the input elements needed on the GUI series when the action is selected in the menu ActionName or InputTable refreshed |
---|
63 | if isstruct(Param) && isequal(Param.Action.RUN,0)% function activated from the GUI series but not RUN |
---|
64 | ParamOut.AllowInputSort='off';% allow alphabetic sorting of the list of input file SubDir (options 'off'/'on', 'off' by default) |
---|
65 | ParamOut.WholeIndexRange='off';% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default) |
---|
66 | ParamOut.NbSlice='on'; %nbre of slices ('off' by default) |
---|
67 | ParamOut.VelType='two';% menu for selecting the velocity type (options 'off'/'one'/'two', 'off' by default) |
---|
68 | ParamOut.FieldName='two';% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default) |
---|
69 | ParamOut.FieldTransform = {'phys','phys_polar'};%can use a transform function, proposed list (needed for compilation) |
---|
70 | ParamOut.TransformPath=fullfile(fileparts(which('uvmat')),'transform_field');% path to transform functions (needed for compilation only) |
---|
71 | if 1==2 % loop used to enforce compilation of transform fct, never entered. |
---|
72 | phys |
---|
73 | phys_polar |
---|
74 | end |
---|
75 | ParamOut.ProjObject='on';%can use projection object(option 'off'/'on', |
---|
76 | ParamOut.Mask='off';%can use mask option (option 'off'/'on', 'off' by default) |
---|
77 | ParamOut.OutputDirExt='.tseries';%set the output dir extension |
---|
78 | 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 |
---|
79 | % check for selection of a projection object |
---|
80 | hseries=findobj(allchild(0),'Tag','series');% handles of the GUI series |
---|
81 | hhseries=guidata(hseries); |
---|
82 | if ~isfield(Param,'ProjObject') |
---|
83 | msgbox_uvmat('WARNING','you may need to introduce a projection object for the time_series'); |
---|
84 | end |
---|
85 | |
---|
86 | % introduce bin size for histograms |
---|
87 | if isfield(Param,'CheckObject') &&Param.CheckObject |
---|
88 | SeriesData=get(hseries,'UserData'); |
---|
89 | if ismember(SeriesData.ProjObject.ProjMode,{'inside','outside'}) |
---|
90 | answer=msgbox_uvmat('INPUT_TXT','set bin size for histograms (or keep ''auto'' by default)?','auto'); |
---|
91 | ParamOut.ActionInput.VarMesh=str2num(answer); |
---|
92 | end |
---|
93 | end |
---|
94 | |
---|
95 | % test for subtraction |
---|
96 | if size(Param.InputTable,1)>2 |
---|
97 | msgbox_uvmat('WARNING','''time_series'' uses only one or two input lines (two for substraction). To concatene fields first use ''merge_proj'''); |
---|
98 | end |
---|
99 | if size(Param.InputTable,1)>=2 |
---|
100 | answer=msgbox_uvmat('INPUT_Y-N','substract the two input file series?'); |
---|
101 | if strcmp(answer,'Yes') |
---|
102 | if isempty(Param.FieldTransform.TransformName) |
---|
103 | set(hhseries.TransformName,'value',2) %select sub_field |
---|
104 | end |
---|
105 | else |
---|
106 | set(hhseries.InputTable,'Data',Param.InputTable(1,:)) |
---|
107 | end |
---|
108 | end |
---|
109 | |
---|
110 | % check the existence of the first and last file in the series |
---|
111 | first_j=[]; |
---|
112 | if isfield(Param.IndexRange,'first_j'); first_j=Param.IndexRange.first_j; end |
---|
113 | last_j=[]; |
---|
114 | if isfield(Param.IndexRange,'last_j'); last_j=Param.IndexRange.last_j; end |
---|
115 | PairString=''; |
---|
116 | if isfield(Param.IndexRange,'PairString'); PairString=Param.IndexRange.PairString; end |
---|
117 | [i1,i2,j1,j2] = get_file_index(Param.IndexRange.first_i,first_j,PairString); |
---|
118 | FirstFileName=fullfile_uvmat(Param.InputTable{1,1},Param.InputTable{1,2},Param.InputTable{1,3},... |
---|
119 | Param.InputTable{1,5},Param.InputTable{1,4},i1,i2,j1,j2); |
---|
120 | if ~exist(FirstFileName,'file') |
---|
121 | msgbox_uvmat('WARNING',['the first input file ' FirstFileName ' does not exist']) |
---|
122 | else |
---|
123 | [i1,i2,j1,j2] = get_file_index(Param.IndexRange.last_i,last_j,PairString); |
---|
124 | LastFileName=fullfile_uvmat(Param.InputTable{1,1},Param.InputTable{1,2},Param.InputTable{1,3},... |
---|
125 | Param.InputTable{1,5},Param.InputTable{1,4},i1,i2,j1,j2); |
---|
126 | if ~exist(LastFileName,'file') |
---|
127 | msgbox_uvmat('WARNING',['the last input file ' LastFileName ' does not exist']) |
---|
128 | end |
---|
129 | end |
---|
130 | return |
---|
131 | end |
---|
132 | |
---|
133 | %%%%%%%%%%%% STANDARD PART %%%%%%%%%%%% |
---|
134 | ParamOut=[]; %default output |
---|
135 | %% read input parameters from an xml file if input is a file name (batch mode) |
---|
136 | checkrun=1; |
---|
137 | if ischar(Param) |
---|
138 | Param=xml2struct(Param);% read Param as input file (batch case) |
---|
139 | checkrun=0; |
---|
140 | end |
---|
141 | hseries=findobj(allchild(0),'Tag','series'); |
---|
142 | RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series |
---|
143 | WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series |
---|
144 | |
---|
145 | %% define the directory for result file (with path=RootPath{1}) |
---|
146 | OutputDir=[Param.OutputSubDir Param.OutputDirExt]; |
---|
147 | |
---|
148 | %% root input file(s) name, type and index series |
---|
149 | RootPath=Param.InputTable(:,1); |
---|
150 | RootFile=Param.InputTable(:,3); |
---|
151 | SubDir=Param.InputTable(:,2); |
---|
152 | NomType=Param.InputTable(:,4); |
---|
153 | FileExt=Param.InputTable(:,5); |
---|
154 | |
---|
155 | hdisp=disp_uvmat('WAITING...','checking the file series',checkrun); |
---|
156 | % gives the series of input file names and indices set by the input parameters: |
---|
157 | [filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param); |
---|
158 | % filecell{iview,fileindex}: |
---|
159 | % iview: line in the table corresponding to a given file series |
---|
160 | % fileindex: file index with i and j reshaped as a 1D array |
---|
161 | % 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 |
---|
162 | % i1_series(iview,fileindex) expresses the same indices as a 1D array in file indices |
---|
163 | if ~isempty(hdisp),delete(hdisp),end;%end the waiting display |
---|
164 | |
---|
165 | NbView=numel(i1_series);%number of input file series (lines in InputTable) |
---|
166 | NbField_j=size(i1_series{1},1); %nb of fields for the j index (bursts or volume slices) |
---|
167 | NbField_i=size(i1_series{1},2); %nb of fields for the i index |
---|
168 | NbField=NbField_j*NbField_i; %total number of fields |
---|
169 | |
---|
170 | %% determine the file type on each line from the first input file |
---|
171 | ImageTypeOptions={'image','multimage','mmreader','video','cine_phantom'}; |
---|
172 | NcTypeOptions={'netcdf','civx','civdata'}; |
---|
173 | FileType=cell(1,NbView); |
---|
174 | FileInfo=cell(1,NbView); |
---|
175 | MovieObject=cell(1,NbView); |
---|
176 | CheckImage=cell(1,NbView); |
---|
177 | CheckNc=cell(1,NbView); |
---|
178 | frame_index=cell(1,NbView); |
---|
179 | |
---|
180 | for iview=1:NbView |
---|
181 | if ~exist(filecell{iview,1}','file') |
---|
182 | disp_uvmat('ERROR',['the first input file ' filecell{iview,1} ' does not exist'],checkrun) |
---|
183 | return |
---|
184 | end |
---|
185 | [FileInfo{iview},MovieObject{iview}]=get_file_info(filecell{iview,1}); |
---|
186 | FileType{iview}=FileInfo{iview}.FileType; |
---|
187 | if strcmp(FileType{iview},'civdata')||strcmp(FileType{iview},'civx') |
---|
188 | if ~isfield(Param.InputFields,'VelType') |
---|
189 | FileType{iview}='netcdf';% civ data read as usual netcdf files |
---|
190 | end |
---|
191 | end |
---|
192 | CheckImage{iview}=~isempty(find(strcmp(FileType{iview},ImageTypeOptions)));% =1 for images |
---|
193 | CheckNc{iview}=~isempty(find(strcmp(FileType{iview},NcTypeOptions)));% =1 for netcdf files |
---|
194 | if isempty(j1_series{iview}) |
---|
195 | frame_index{iview}=i1_series{iview}; |
---|
196 | else |
---|
197 | frame_index{iview}=j1_series{iview}; |
---|
198 | end |
---|
199 | end |
---|
200 | |
---|
201 | %% calibration data and timing: read the ImaDoc files |
---|
202 | [XmlData,NbSlice_calib,time,errormsg]=read_multimadoc(RootPath,SubDir,RootFile,FileExt,i1_series,i2_series,j1_series,j2_series); |
---|
203 | if ~isempty(errormsg) |
---|
204 | disp_uvmat('ERROR',['error in reading xmlfile: ' errormsg],checkrun) |
---|
205 | return |
---|
206 | end |
---|
207 | if size(time,1)>1 |
---|
208 | diff_time=max(max(diff(time))); |
---|
209 | if diff_time>0 |
---|
210 | disp_uvmat('WARNING',['times of series differ by (max) ' num2str(diff_time)],checkrun) |
---|
211 | end |
---|
212 | time=time(1,:);% choose the time data from the first sequence |
---|
213 | end |
---|
214 | |
---|
215 | %% coordinate transform or other user defined transform |
---|
216 | transform_fct=[];%default |
---|
217 | if isfield(Param,'FieldTransform')&&~isempty(Param.FieldTransform.TransformName) |
---|
218 | %addpath(Param.FieldTransform.TransformPath) |
---|
219 | transform_fct=str2func(Param.FieldTransform.TransformName); |
---|
220 | %rmpath(Param.FieldTransform.TransformPath) |
---|
221 | if isfield(Param,'TransformInput') |
---|
222 | XmlData{1}.TransformInput=Param.TransformInput; |
---|
223 | end |
---|
224 | end |
---|
225 | |
---|
226 | %%%%%%%%%%%% END STANDARD PART %%%%%%%%%%%% |
---|
227 | % EDIT FROM HERE |
---|
228 | |
---|
229 | %% check the validity of the input file types |
---|
230 | if ~CheckImage{1}&&~CheckNc{1} |
---|
231 | disp_uvmat('ERROR',['invalid file type input ' FileType{1}],checkrun) |
---|
232 | return |
---|
233 | end |
---|
234 | if NbView==2 && ~isequal(CheckImage{1},CheckImage{2}) |
---|
235 | disp_uvmat('ERROR','input must be two image series or two netcdf file series',checkrun) |
---|
236 | return |
---|
237 | end |
---|
238 | |
---|
239 | %% settings for the output file |
---|
240 | FileExtOut='.nc';% write result as .nc files for netcdf inputs |
---|
241 | NomTypeOut=nomtype2pair(NomType{1});% determine the index nomenclature type for the output file |
---|
242 | first_i=i1_series{1}(1); |
---|
243 | last_i=i1_series{1}(end); |
---|
244 | if isempty(j1_series{1})% if there is no second index j |
---|
245 | first_j=1;last_j=1; |
---|
246 | else |
---|
247 | first_j=j1_series{1}(1); |
---|
248 | last_j=j1_series{1}(end); |
---|
249 | end |
---|
250 | OutputPath=fullfile(Param.OutputPath,Param.Experiment,Param.Device) |
---|
251 | |
---|
252 | %% Set field names and velocity types |
---|
253 | InputFields{1}=[];%default (case of images) |
---|
254 | if NbView==2 |
---|
255 | InputFields{2}=[];%default (case of images) |
---|
256 | end |
---|
257 | if isfield(Param,'InputFields') |
---|
258 | InputFields{1}=Param.InputFields; |
---|
259 | if NbView==2 |
---|
260 | InputFields{2}=Param.InputFields;%default |
---|
261 | if isfield(Param.InputFields,'FieldName_1') |
---|
262 | InputFields{2}.FieldName=Param.InputFields.FieldName_1; |
---|
263 | if isfield(Param.InputFields,'VelType_1') |
---|
264 | InputFields{2}.VelType=Param.InputFields.VelType_1; |
---|
265 | end |
---|
266 | end |
---|
267 | end |
---|
268 | end |
---|
269 | |
---|
270 | %% Initiate output fields |
---|
271 | %initiate the output structure as a copy of the first input one (reproduce fields) |
---|
272 | [DataOut,tild,errormsg] = read_field(filecell{1,1},FileType{1},InputFields{1},1); |
---|
273 | if ~isempty(errormsg) |
---|
274 | disp_uvmat('ERROR',['error reading ' filecell{1,1} ': ' errormsg],checkrun) |
---|
275 | return |
---|
276 | end |
---|
277 | time_1=[]; |
---|
278 | if isfield(DataOut,'Time') |
---|
279 | time_1=DataOut.Time(1); |
---|
280 | end |
---|
281 | if CheckNc{iview} |
---|
282 | if isempty(strcmp('Conventions',DataOut.ListGlobalAttribute)) |
---|
283 | DataOut.ListGlobalAttribute=['Conventions' DataOut.ListGlobalAttribute]; |
---|
284 | end |
---|
285 | DataOut.Conventions='uvmat'; |
---|
286 | DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {Param.Action}]; |
---|
287 | ActionKey='Action'; |
---|
288 | while isfield(DataOut,ActionKey) |
---|
289 | ActionKey=[ActionKey '_1']; |
---|
290 | end |
---|
291 | DataOut.(ActionKey)=Param.Action; |
---|
292 | DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {ActionKey}]; |
---|
293 | if isfield(DataOut,'Time') |
---|
294 | DataOut.ListGlobalAttribute=[DataOut.ListGlobalAttribute {'Time','Time_end'}]; |
---|
295 | end |
---|
296 | end |
---|
297 | |
---|
298 | nbfile=0;% not used , to check |
---|
299 | nbmissing=0; |
---|
300 | VarMesh=[]; |
---|
301 | checkhisto=0; |
---|
302 | checkline=0; |
---|
303 | if isfield(Param,'ProjObject') |
---|
304 | if ismember(Param.ProjObject.ProjMode,{'inside','outside'}) |
---|
305 | checkhisto=1; |
---|
306 | if isfield(Param,'ActionInput') && isfield(Param.ActionInput,'VarMesh')%case of histograms |
---|
307 | VarMesh=Param.ActionInput.VarMesh; |
---|
308 | elseif isequal(Param.IndexRange.NbSlice,1) |
---|
309 | VarMesh=[]; |
---|
310 | disp_uvmat('WARNING','automatic bin size for histograms, select time_series again to set the value',checkrun) |
---|
311 | end |
---|
312 | elseif ismember(Param.ProjObject.Type,{'line'}) |
---|
313 | checkline=1; |
---|
314 | end |
---|
315 | end |
---|
316 | |
---|
317 | %%%%%%%%%%%%%%%% loop on field indices %%%%%%%%%%%%%%%% |
---|
318 | for index=1:NbField |
---|
319 | update_waitbar(WaitbarHandle,index/NbField) |
---|
320 | if ~isempty(RUNHandle) && ~strcmp(get(RUNHandle,'BusyAction'),'queue') |
---|
321 | disp('program stopped by user') |
---|
322 | break % leave the loop if stop is ordered |
---|
323 | end |
---|
324 | Data=cell(1,NbView);%initiate the set Data; |
---|
325 | nbtime=0; |
---|
326 | dt=[]; |
---|
327 | %%%%%%%%%%%%%%%% loop on views (input lines) %%%%%%%%%%%%%%%% |
---|
328 | for iview=1:NbView |
---|
329 | % reading input file(s) |
---|
330 | [Data{iview},tild,errormsg] = read_field(filecell{iview,index},FileType{iview},InputFields{iview},frame_index{iview}(index)); |
---|
331 | if ~isempty(errormsg) |
---|
332 | errormsg=['time_series / read_field / ' errormsg]; |
---|
333 | disp(errormsg) |
---|
334 | break% exit the loop on iview |
---|
335 | end |
---|
336 | if ~isempty(NbSlice_calib) |
---|
337 | Data{iview}.ZIndex=mod(i1_series{iview}(index)-1,NbSlice_calib{iview})+1;%Zindex for phys transform |
---|
338 | end |
---|
339 | end |
---|
340 | if ~isempty(errormsg) |
---|
341 | continue %in case of input error skip the current input field, go to next index |
---|
342 | end |
---|
343 | Field=Data{1}; % default input field structure |
---|
344 | % coordinate transform (or other user defined transform) |
---|
345 | if ~isempty(transform_fct) |
---|
346 | switch nargin(transform_fct) |
---|
347 | case 4 |
---|
348 | if length(Data)==2 |
---|
349 | Field=transform_fct(Data{1},XmlData{1},Data{2},XmlData{2}); |
---|
350 | else |
---|
351 | Field=transform_fct(Data{1},XmlData{1}); |
---|
352 | end |
---|
353 | case 3 |
---|
354 | if length(Data)==2 |
---|
355 | Field=transform_fct(Data{1},XmlData{1},Data{2}); |
---|
356 | else |
---|
357 | Field=transform_fct(Data{1},XmlData{1}); |
---|
358 | end |
---|
359 | case 2 |
---|
360 | Field=transform_fct(Data{1},XmlData{1}); |
---|
361 | case 1 |
---|
362 | Field=transform_fct(Data{1}); |
---|
363 | end |
---|
364 | end |
---|
365 | |
---|
366 | %field projection on an object |
---|
367 | if Param.CheckObject |
---|
368 | % calculate tps coefficients if needed |
---|
369 | if isfield(Param.ProjObject,'ProjMode')&& strcmp(Param.ProjObject.ProjMode,'interp_tps') |
---|
370 | Field=tps_coeff_field(Field,check_proj_tps); |
---|
371 | end |
---|
372 | [Field,errormsg]=proj_field(Field,Param.ProjObject,VarMesh); |
---|
373 | if ~isempty(errormsg) |
---|
374 | disp_uvmat('ERROR',['time_series / proj_field / ' errormsg],checkrun) |
---|
375 | return |
---|
376 | end |
---|
377 | end |
---|
378 | % nbfile=nbfile+1; |
---|
379 | |
---|
380 | % initiate the time series at the first iteration |
---|
381 | if index==1 |
---|
382 | % stop program if the first field reading is in error |
---|
383 | if ~isempty(errormsg) |
---|
384 | disp_uvmat('ERROR',['time_series / sub_field / ' errormsg],checkrun) |
---|
385 | return |
---|
386 | end |
---|
387 | if ~isfield(Field,'ListVarName') |
---|
388 | disp_uvmat('ERROR','no variable in the projected field',checkrun) |
---|
389 | return |
---|
390 | end |
---|
391 | DataOut=Field;%output reproduced the first projected field by default |
---|
392 | nbvar=length(Field.ListVarName); |
---|
393 | if nbvar==0 |
---|
394 | disp_uvmat('ERROR','no input variable selected',checkrun) |
---|
395 | return |
---|
396 | end |
---|
397 | if checkhisto%case of histograms |
---|
398 | testsum=zeros(1,nbvar);%initiate flag for action on each variable |
---|
399 | for ivar=1:numel(Field.ListVarName)% list of variable names before projection (histogram) |
---|
400 | VarName=Field.ListVarName{ivar}; |
---|
401 | if isfield(Data{1},VarName) |
---|
402 | DataOut.ListVarName=[DataOut.ListVarName {[VarName 'Histo']}]; |
---|
403 | DataOut.VarDimName=[DataOut.VarDimName {{'Time',VarName}}]; |
---|
404 | StatName=pdf2stat;% get the names of statistical quantities to calcuilate at each time |
---|
405 | for istat=1:numel(StatName) |
---|
406 | DataOut.ListVarName=[DataOut.ListVarName {[VarName StatName{istat}]}]; |
---|
407 | DataOut.VarDimName=[DataOut.VarDimName {'Time'}]; |
---|
408 | end |
---|
409 | testsum(ivar)=1; |
---|
410 | DataOut.(VarName)=Field.(VarName); |
---|
411 | DataOut.([VarName 'Histo'])=zeros([NbField numel(DataOut.(VarName))]); |
---|
412 | VarMesh=Field.(VarName)(2)-Field.(VarName)(1); |
---|
413 | end |
---|
414 | end |
---|
415 | disp(['mesh for histogram = ' num2str(VarMesh)]) |
---|
416 | else |
---|
417 | testsum=2*ones(1,nbvar);%initiate flag for action on each variable |
---|
418 | if isfield(Field,'VarAttribute') % look for coordinate and flag variables |
---|
419 | for ivar=1:nbvar |
---|
420 | if length(Field.VarAttribute)>=ivar && isfield(Field.VarAttribute{ivar},'Role') |
---|
421 | var_role=Field.VarAttribute{ivar}.Role;%'role' of the variable |
---|
422 | if isequal(var_role,'errorflag') |
---|
423 | disp_uvmat('ERROR','do not handle error flags in time series',checkrun) |
---|
424 | return |
---|
425 | end |
---|
426 | if isequal(var_role,'warnflag') |
---|
427 | testsum(ivar)=0; % not recorded variable |
---|
428 | eval(['DataOut=rmfield(DataOut,''' Field.ListVarName{ivar} ''');']);%remove variable |
---|
429 | end |
---|
430 | if strcmp(var_role,'coord_x')||strcmp(var_role,'coord_z')||strcmp(var_role,'coord') |
---|
431 | testsum(ivar)=1; %constant coordinates, record without time evolution |
---|
432 | end |
---|
433 | if strcmp(var_role,'coord_y')&& ~checkline |
---|
434 | testsum(ivar)=1; |
---|
435 | end |
---|
436 | end |
---|
437 | % check whether the variable ivar is a dimension variable |
---|
438 | DimCell=Field.VarDimName{ivar}; |
---|
439 | if ischar(DimCell) |
---|
440 | DimCell={DimCell}; |
---|
441 | end |
---|
442 | if numel(DimCell)==1 && isequal(Field.ListVarName{ivar},DimCell{1})%detect dimension variables |
---|
443 | testsum(ivar)=1; |
---|
444 | end |
---|
445 | end |
---|
446 | end |
---|
447 | for ivar=1:nbvar |
---|
448 | if testsum(ivar)==2 |
---|
449 | VarName=Field.ListVarName{ivar}; |
---|
450 | siz=size(Field.(VarName)); |
---|
451 | DataOut.(VarName)=zeros([NbField siz]); |
---|
452 | end |
---|
453 | end |
---|
454 | end |
---|
455 | DataOut.ListVarName=[{'Time'} DataOut.ListVarName]; |
---|
456 | end |
---|
457 | % end initialisation for index==1 |
---|
458 | |
---|
459 | % append data from the current field |
---|
460 | |
---|
461 | if checkhisto % case of histogram (projection mode=inside or outside) |
---|
462 | for ivar=1:length(Field.ListVarName) |
---|
463 | VarName=Field.ListVarName{ivar}; |
---|
464 | if isfield(Data{1},VarName) |
---|
465 | MaxValue=max(DataOut.(VarName));% current max of histogram absissa |
---|
466 | MinValue=min(DataOut.(VarName));% current min of histogram absissa |
---|
467 | MaxIndex=round(MaxValue/VarMesh); |
---|
468 | MinIndex=round(MinValue/VarMesh); |
---|
469 | MaxIndex_new=round(max(Field.(VarName)/VarMesh));% max of the current field |
---|
470 | MinIndex_new=round(min(Field.(VarName)/VarMesh)); |
---|
471 | if MaxIndex_new>MaxIndex% the variable max for the current field exceeds the previous one |
---|
472 | DataOut.(VarName)=[DataOut.(VarName) VarMesh*(MaxIndex+1:MaxIndex_new)];% append the new variable values |
---|
473 | DataOut.([VarName 'Histo'])=[DataOut.([VarName 'Histo']) zeros(NbField,MaxIndex_new-MaxIndex)]; % append the new histo values |
---|
474 | end |
---|
475 | if MinIndex_new <= MinIndex-1 |
---|
476 | DataOut.(VarName)=[VarMesh*(MinIndex_new:MinIndex-1) DataOut.(VarName)];% insert the new variable values |
---|
477 | DataOut.([VarName 'Histo'])=[zeros(NbField,MinIndex-MinIndex_new) DataOut.([VarName 'Histo'])];% insert the new histo values |
---|
478 | ind_start=1; |
---|
479 | else |
---|
480 | ind_start=MinIndex_new-MinIndex+1; |
---|
481 | end |
---|
482 | DataOut.([VarName 'Histo'])(index,ind_start:ind_start+MaxIndex_new-MinIndex_new)=... |
---|
483 | DataOut.([VarName 'Histo'])(index,ind_start:ind_start+MaxIndex_new-MinIndex_new)+Field.([VarName 'Histo']); |
---|
484 | VarVal=pdf2stat((Field.(VarName))',(Field.([VarName 'Histo']))');% max of the current field |
---|
485 | for istat=1:numel(VarVal) |
---|
486 | DataOut.([VarName StatName{istat}])(index)=VarVal(istat); |
---|
487 | end |
---|
488 | end |
---|
489 | end |
---|
490 | else % not histogram |
---|
491 | for ivar=1:length(Field.ListVarName) |
---|
492 | VarName=Field.ListVarName{ivar}; |
---|
493 | VarVal=Field.(VarName); |
---|
494 | if testsum(ivar)==2% test for recorded variable |
---|
495 | if isempty(errormsg) |
---|
496 | VarVal=shiftdim(VarVal,-1); %shift dimension |
---|
497 | DataOut.(VarName)(index,:,:)=VarVal;%concanete the current field to the time series |
---|
498 | end |
---|
499 | elseif testsum(ivar)==1% variable representing fixed coordinates |
---|
500 | VarInit=DataOut.(VarName); |
---|
501 | if isempty(errormsg) && ~isequal(VarVal,VarInit) |
---|
502 | disp_uvmat('ERROR',['time series requires constant coordinates ' VarName ': use projection mode interp'],checkrun) |
---|
503 | return |
---|
504 | end |
---|
505 | end |
---|
506 | end |
---|
507 | end |
---|
508 | |
---|
509 | % record the time: |
---|
510 | if isempty(errormsg) |
---|
511 | if isempty(time)% time not set by xml filer(s) |
---|
512 | if isfield(Data{1},'Time') |
---|
513 | DataOut.Time(index,1)=Field.Time; |
---|
514 | else |
---|
515 | DataOut.Time(index,1)=index;%default |
---|
516 | end |
---|
517 | else % time from ImaDoc prevails TODO: correct |
---|
518 | DataOut.Time(index,1)=time(index);% |
---|
519 | end |
---|
520 | end |
---|
521 | index |
---|
522 | % record the number of missing input fields |
---|
523 | if ~isempty(errormsg) |
---|
524 | nbmissing=nbmissing+1; |
---|
525 | display(['index=' num2str(index) ':' errormsg]) |
---|
526 | end |
---|
527 | end |
---|
528 | |
---|
529 | %%%%%%% END OF LOOP WITHIN A SLICE |
---|
530 | |
---|
531 | %remove time for global attributes if exists |
---|
532 | Time_index=find(strcmp('Time',DataOut.ListGlobalAttribute)); |
---|
533 | if ~isempty(Time_index) |
---|
534 | DataOut.ListGlobalAttribute(Time_index)=[]; |
---|
535 | end |
---|
536 | DataOut.Conventions='uvmat'; |
---|
537 | for ivar=1:numel(DataOut.ListVarName) |
---|
538 | VarName=DataOut.ListVarName{ivar}; |
---|
539 | eval(['DataOut.' VarName '=squeeze(DataOut.' VarName ');']) %remove singletons |
---|
540 | end |
---|
541 | |
---|
542 | % add time dimension |
---|
543 | for ivar=1:length(Field.ListVarName) |
---|
544 | DimCell=Field.VarDimName{ivar}; |
---|
545 | if ischar(DimCell),DimCell={DimCell};end |
---|
546 | if testsum(ivar)==2% variable for which time series is calculated |
---|
547 | DataOut.VarDimName{ivar}=[{'Time'} DimCell]; |
---|
548 | elseif testsum(ivar)==1 % variable represneting a fixed coordinate |
---|
549 | DataOut.VarDimName{ivar}=DimCell; |
---|
550 | end |
---|
551 | end |
---|
552 | indexremove=find(~testsum); |
---|
553 | if ~isempty(indexremove) |
---|
554 | DataOut.ListVarName(1+indexremove)=[]; |
---|
555 | DataOut.VarDimName(indexremove)=[]; |
---|
556 | if isfield(DataOut,'Role') && ~isempty(DataOut.Role{1})%generaliser aus autres attributs |
---|
557 | DataOut.Role(1+indexremove)=[]; |
---|
558 | end |
---|
559 | end |
---|
560 | |
---|
561 | %shift variable attributes |
---|
562 | if isfield(DataOut,'VarAttribute') |
---|
563 | DataOut.VarAttribute=[{[]} DataOut.VarAttribute]; |
---|
564 | end |
---|
565 | DataOut.VarDimName=[{'Time'} DataOut.VarDimName]; |
---|
566 | DataOut.Action=Param.Action;%name of the processing programme |
---|
567 | test_time=diff(DataOut.Time)>0;% test that the readed time is increasing (not constant) |
---|
568 | if ~test_time |
---|
569 | DataOut.Time=1:NbField; |
---|
570 | end |
---|
571 | |
---|
572 | if ~isequal(nbmissing,0) |
---|
573 | disp_uvmat('WARNING',[num2str(nbmissing) ' files skipped: missing files or bad input, see command window display'],checkrun) |
---|
574 | end |
---|
575 | |
---|
576 | %% name of result file |
---|
577 | OutputFile=fullfile_uvmat(OutputPath,OutputDir,RootFile{1},FileExtOut,NomTypeOut,first_i,last_i,first_j,last_j); |
---|
578 | errormsg=struct2nc(OutputFile,DataOut); %save result file |
---|
579 | if isempty(errormsg) |
---|
580 | display([OutputFile ' written']) |
---|
581 | else |
---|
582 | disp_uvmat('ERROR',['error in Series/struct2nc: ' errormsg],checkrun) |
---|
583 | end |
---|
584 | |
---|
585 | %% plot the time series for (the last one in case of multislices) |
---|
586 | if checkrun && isequal(Param.IndexRange.NbSlice,1)%&& isfield(Param,'ProjObject') && strcmp(Param.ProjObject.Type,'points') |
---|
587 | %% open the result file with uvmat (in RUN mode) |
---|
588 | uvmat(OutputFile)% open the last result file with uvmat |
---|
589 | end |
---|
590 | |
---|
591 | |
---|
592 | |
---|