1 | %'time_series': extract a time series, used with series.fig |
---|
2 | %------------------------------------------------------------------------ |
---|
3 | % function GUI_input=time_series(Param) |
---|
4 | % |
---|
5 | %OUTPUT |
---|
6 | % GUI_input=list of options in the GUI series.fig needed for the function |
---|
7 | % |
---|
8 | %INPUT: |
---|
9 | %num_i1: series of first indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ) |
---|
10 | %i2_series: series of second indices i (given from the series interface as first_i:incr_i:last_i, mode and list_pair_civ) |
---|
11 | %num_j1: series of first indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ ) |
---|
12 | %num_j2: series of second indices j (given from the series interface as first_j:incr_j:last_j, mode and list_pair_civ) |
---|
13 | %Series: Matlab structure containing information set by the series interface |
---|
14 | % |
---|
15 | function GUI_input=time_series(Param) |
---|
16 | |
---|
17 | %% requests for the visibility of input windows in the GUI series (activated directly by the selection in the menu ACTION) |
---|
18 | if ~exist('Param','var') |
---|
19 | GUI_input={'RootPath';'two';...%nbre of possible input series (options 'on'/'two'/'many', default:'one') |
---|
20 | 'SubDir';'on';... % subdirectory of derived files (PIV fields), ('on' by default) |
---|
21 | 'RootFile';'on';... %root input file name ('on' by default) |
---|
22 | 'FileExt';'on';... %input file extension ('on' by default) |
---|
23 | 'NomType';'on';...%type of file indexing ('on' by default) |
---|
24 | 'NbSlice';'on'; ...%nbre of slices ('off' by default) |
---|
25 | 'VelTypeMenu';'two';...% menu for selecting the velocity type (civ1,..) options 'off'/'one'/'two', 'off' by default) |
---|
26 | 'FieldMenu';'two';...% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default) |
---|
27 | 'CoordType';'on';...%can use a transform function 'off' by default |
---|
28 | 'GetObject';'on';...%can use projection object ,'off' by default |
---|
29 | 'OutputDirExt';'.series'... |
---|
30 | %'GetMask';'on'...%can use mask option ,'off' by default |
---|
31 | %'PARAMETER'; options: name of the user defined parameter',repeat a line for each parameter |
---|
32 | ''}; |
---|
33 | return %exit the function |
---|
34 | end |
---|
35 | |
---|
36 | %% input parameters |
---|
37 | % read the xml file for batch case |
---|
38 | if ischar(Param) && ~isempty(find(regexp('Param','.xml$'))) |
---|
39 | Param=xml2struct(Param); |
---|
40 | checkrun=0; |
---|
41 | else % RUN case: parameters introduced as the input structure Param |
---|
42 | hseries=guidata(Param.hseries);%handles of the GUI series |
---|
43 | WaitbarPos=get(hseries.waitbar_frame,'Position'); |
---|
44 | checkrun=1; |
---|
45 | end |
---|
46 | [filecell,i1_series,i2_series,j1_series,j2_series]=get_file_series(Param); |
---|
47 | |
---|
48 | %% coordinate transform or other user defined transform |
---|
49 | transform_fct='';%default |
---|
50 | if isfield(Param,'FieldTransform')&&isfield(Param.FieldTransform,'fct_handle') |
---|
51 | transform_fct=Param.FieldTransform.fct_handle; |
---|
52 | end |
---|
53 | |
---|
54 | %% projection object |
---|
55 | test_object=get(hseries.GetObject,'Value'); |
---|
56 | if test_object |
---|
57 | hset_object=findobj(allchild(0),'tag','set_object'); |
---|
58 | ProjObject=read_GUI(hset_object); |
---|
59 | answeryes=msgbox_uvmat('INPUT_Y-N',['field series projected on ' ProjObject.Type]); |
---|
60 | if ~isequal(answeryes,'Yes') |
---|
61 | return |
---|
62 | end |
---|
63 | else |
---|
64 | msgbox_uvmat('ERROR','a projection object is needed'); |
---|
65 | return |
---|
66 | end |
---|
67 | |
---|
68 | %% features of the input fields |
---|
69 | RootPath=Param.InputTable(:,1); |
---|
70 | RootFile=Param.InputTable(:,3); |
---|
71 | % SubDir=Param.InputTable(:,2); |
---|
72 | NomType=Param.InputTable(:,4); |
---|
73 | FileExt=Param.InputTable(:,5); |
---|
74 | % ext=FileExt{1}; |
---|
75 | % form=imformats(ext(2:end));%test valid Matlab image formats |
---|
76 | nbfield=size(i1_series{1},1)*size(i1_series{1},2); %number of fields in the time series |
---|
77 | |
---|
78 | %% determine image type |
---|
79 | hhh=which('mmreader'); |
---|
80 | testnetcdf=0; |
---|
81 | nbview=length(RootPath);%Number of input series: this function accepts only one or two input file series (sub_field is used in the latter case) |
---|
82 | for iview=1:nbview |
---|
83 | if isequal(FileExt{iview},'.nc')||isequal(FileExt{iview},'.cdf') |
---|
84 | FileType{iview}='netcdf'; |
---|
85 | testnetcdf=1; |
---|
86 | elseif isequal(lower(FileExt{iview}),'.avi') |
---|
87 | if ~isequal(hhh,'')%&& mmreader.isPlatformSupported() |
---|
88 | MovieObject{iview}=mmreader(fullfile(RootPath{iview},[RootFile{iview} FileExt{iview}])); |
---|
89 | FileType{iview}='movie'; |
---|
90 | else |
---|
91 | FileType{iview}='avi'; |
---|
92 | end |
---|
93 | elseif isequal(lower(FileExt{iview}),'.vol') |
---|
94 | FileType{iview}='vol'; |
---|
95 | else |
---|
96 | form=imformats(FileExt{iview}(2:end)); |
---|
97 | if ~isempty(form)% if the extension corresponds to an image format recognized by Matlab |
---|
98 | if isequal(NomType{iview},'*'); |
---|
99 | FileType{iview}='multimage'; |
---|
100 | else |
---|
101 | FileType{iview}='image'; |
---|
102 | end |
---|
103 | end |
---|
104 | end |
---|
105 | end |
---|
106 | filebase{1}=fullfile(RootPath{1},RootFile{1}); |
---|
107 | |
---|
108 | %% number of slices |
---|
109 | NbSlice=Param.NbSlice; |
---|
110 | |
---|
111 | %% Field and velocity type (the same for the two views) |
---|
112 | FieldName={''}; |
---|
113 | |
---|
114 | if isfield(Param,'InputFields')&&isfield(Param.InputFields,'FieldMenu') |
---|
115 | FieldName=Param.InputFields.FieldMenu;%the same set of fields for all views |
---|
116 | VelType{1}=Param.InputFields.VelTypeMenu; |
---|
117 | end |
---|
118 | if isempty(FieldName) && testnetcdf |
---|
119 | msgbox_uvmat('ERROR','A field must be defined as input') |
---|
120 | return |
---|
121 | end |
---|
122 | if isequal(FieldName,'get_field...') |
---|
123 | hget_field=findobj(allchild(0),'name','get_field');%find the get_field... GUI |
---|
124 | if numel(hget_field)>1 |
---|
125 | delete(hget_field(2:end)) % delete multiple occurerence of the GUI get_fioeld |
---|
126 | elseif isempty(hget_field) |
---|
127 | filename=filecell{1,1}; |
---|
128 | % filename=name_generator(filebase{1},i1_series{1}(1),j1_series{1}(1),FileExt{1},NomType{1},1,i2_series{1}(1),num_j2{1}(1),SubDir{1}); |
---|
129 | idetect(iview)=exist(filename,'file'); |
---|
130 | hget_field=get_field(filename); |
---|
131 | return |
---|
132 | end |
---|
133 | SubField=read_get_field(hget_field); %read the names of the variables to plot in the get_field GUI |
---|
134 | if isempty(SubField) |
---|
135 | delete(hget_field) |
---|
136 | filename=filecell{1,1}; |
---|
137 | %filename=name_generator(filebase{1},i1_series{1}(1),j1_series{1}(1),FileExt{1},NomType{1},1,i2_series{1}(1),j2_series{1}(1),SubDir{1}); |
---|
138 | hget_field=get_field(filename); |
---|
139 | SubField=read_get_field(hget_field); %read the names of the variables to plot in the get_field GUI |
---|
140 | end |
---|
141 | end |
---|
142 | |
---|
143 | %% detect whether the two files are 'images' or 'netcdf' |
---|
144 | testcivx=0; |
---|
145 | % FileExt=get(hseries.FileExt,'String'); |
---|
146 | if ~isequal(FieldName,{'get_field...'}) |
---|
147 | testcivx=isequal(FileType{1},'netcdf'); |
---|
148 | end |
---|
149 | % VelType_str=get(hseries.VelTypeMenu,'String'); |
---|
150 | % VelType_val=get(hseries.VelTypeMenu,'Value'); |
---|
151 | % VelType{1}=VelType_str{VelType_val}; |
---|
152 | % if nbview==2 |
---|
153 | % VelType_str=get(hseries.VelTypeMenu_1,'String'); |
---|
154 | % VelType_val=get(hseries.VelTypeMenu_1,'Value'); |
---|
155 | % VelType{2}=VelType_str{VelType_val}; |
---|
156 | % end |
---|
157 | |
---|
158 | %% Calibration data and timing: read the ImaDoc files |
---|
159 | % mode=''; %default |
---|
160 | timecell={}; |
---|
161 | XmlData={}; |
---|
162 | itime=0; |
---|
163 | NbSlice_calib={}; |
---|
164 | for iview=1:nbview%Loop on views |
---|
165 | XmlData{iview}=[];%default |
---|
166 | filebase{iview}=fullfile(RootPath{iview},RootFile{iview}); |
---|
167 | if exist([filebase{iview} '.xml'],'file') |
---|
168 | [XmlData{iview},error]=imadoc2struct([filebase{iview} '.xml']); |
---|
169 | if isfield(XmlData{iview},'Time') |
---|
170 | itime=itime+1; |
---|
171 | timecell{itime}=XmlData{iview}.Time; |
---|
172 | end |
---|
173 | if isfield(XmlData{iview},'GeometryCalib') && isfield(XmlData{iview}.GeometryCalib,'SliceCoord') |
---|
174 | NbSlice_calib{iview}=size(XmlData{iview}.GeometryCalib.SliceCoord,1);%nbre of slices for Zindex in phys transform |
---|
175 | if ~isequal(NbSlice_calib{iview},NbSlice_calib{1}) |
---|
176 | msgbox_uvmat('WARNING','inconsistent number of Z indices for the field series'); |
---|
177 | end |
---|
178 | end |
---|
179 | elseif exist([filebase{iview} '.civ'],'file')%old convention .civ text file |
---|
180 | [error,time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([filebase{iview} '.civ']); |
---|
181 | itime=itime+1; |
---|
182 | timecell{itime}=time; |
---|
183 | XmlData{iview}.Time=time; |
---|
184 | GeometryCalib.R=[pxcmx 0 0; 0 pxcmy 0;0 0 0]; |
---|
185 | GeometryCalib.Tx=0; |
---|
186 | GeometryCalib.Ty=0; |
---|
187 | GeometryCalib.Tz=1; |
---|
188 | GeometryCalib.dpx=1; |
---|
189 | GeometryCalib.dpy=1; |
---|
190 | GeometryCalib.sx=1; |
---|
191 | GeometryCalib.Cx=0; |
---|
192 | GeometryCalib.Cy=0; |
---|
193 | GeometryCalib.f=1; |
---|
194 | GeometryCalib.kappa1=0; |
---|
195 | GeometryCalib.CoordUnit='cm'; |
---|
196 | XmlData{iview}.GeometryCalib=GeometryCalib; |
---|
197 | if error==1 |
---|
198 | msgbox_uvmat('WARNING','inconsistent number of fields in the .civ file'); |
---|
199 | end |
---|
200 | end |
---|
201 | end |
---|
202 | time=[];%default |
---|
203 | if ~isempty(timecell) |
---|
204 | if numel(timecell{1})<nbfield |
---|
205 | msgbox_uvmat('WARNING','time array from ImaDoc to short') |
---|
206 | else |
---|
207 | time=timecell{1}; %time defined from ImaDoc file (image series) |
---|
208 | end |
---|
209 | end |
---|
210 | |
---|
211 | %% check coincidence in time |
---|
212 | if length(timecell)>1 |
---|
213 | for icell=2:length(timecell) |
---|
214 | if isequal(size(timecell{icell}),size(time)) |
---|
215 | diff_time=max(abs(timecell{icell}-time)); |
---|
216 | if diff_time>0 |
---|
217 | msgbox_uvmat('WARNING',['times of series differ by more than ' num2str(diff_time)]) |
---|
218 | break |
---|
219 | end |
---|
220 | else |
---|
221 | msgbox_uvmat('WARNING','inconsistent time array dimensions in ImaDoc fields, the time for the first series is used') |
---|
222 | break |
---|
223 | end |
---|
224 | end |
---|
225 | end |
---|
226 | if ~isempty(time) |
---|
227 | display(['time is read from ' filebase{iview} '.xml']) |
---|
228 | end |
---|
229 | |
---|
230 | %% Root name of output files (TO GENERALISE FOR TWO INPUT SERIES) |
---|
231 | subdir_result='time_series'; |
---|
232 | pathdir=fullfile(RootPath{1},subdir_result); |
---|
233 | while exist(pathdir,'dir') |
---|
234 | subdir_result=[subdir_result '.0']; |
---|
235 | pathdir=fullfile(RootPath{1},subdir_result); |
---|
236 | end |
---|
237 | [m1,m2,m3]=mkdir(pathdir); |
---|
238 | if ~isequal(m2,'') |
---|
239 | msgbox_uvmat('CONFIRMATION',m2);%error message for directory creation |
---|
240 | end |
---|
241 | [xx,msg2] = fileattrib(pathdir,'+w','g'); %yield writing access (+w) to user group (g) |
---|
242 | if ~strcmp(msg2,'') |
---|
243 | msgbox_uvmat('ERROR',['pb of permission for ' pathdir ': ' msg2])%error message for directory creation |
---|
244 | return |
---|
245 | end |
---|
246 | filebase_out=filebase{1}; |
---|
247 | i21=i1_series{end}(end); |
---|
248 | if ~isempty(i2_series{end}) |
---|
249 | i21=i2_series{end}(end)-i1_series{1}(1); |
---|
250 | end |
---|
251 | j21=1; |
---|
252 | if ~isempty(j1_series{1}) |
---|
253 | j21=j1_series{end}(end); |
---|
254 | if ~isempty(j2_series{end}) |
---|
255 | j21=j2_series{end}(end)-j21; |
---|
256 | end |
---|
257 | end |
---|
258 | NomTypeOut=nomtype2pair(NomType{1},i21,j21); |
---|
259 | |
---|
260 | |
---|
261 | %% velocity type |
---|
262 | VelType_str=get(hseries.VelTypeMenu,'String'); |
---|
263 | VelType_val=get(hseries.VelTypeMenu,'Value'); |
---|
264 | VelType{1}=VelType_str{VelType_val}; |
---|
265 | if nbview==2 |
---|
266 | VelType_str=get(hseries.VelTypeMenu_1,'String'); |
---|
267 | VelType_val=get(hseries.VelTypeMenu_1,'Value'); |
---|
268 | VelType{2}=VelType_str{VelType_val}; |
---|
269 | end |
---|
270 | |
---|
271 | %% LOOP ON SLICES |
---|
272 | nbmissing=0; %number of undetected files |
---|
273 | for i_slice=1:NbSlice |
---|
274 | dt=[]; |
---|
275 | %%%%%%%%%%%%%%%%%%%%%%%%%%%% LOOP ON FIELDS WITHIN A SLICE |
---|
276 | filecounter=0; |
---|
277 | for ifile=i_slice:NbSlice:nbfield |
---|
278 | if checkrun |
---|
279 | update_waitbar(hseries.waitbar_frame,WaitbarPos,ifile/nbfield) |
---|
280 | stopstate=get(hseries.RUN,'BusyAction'); |
---|
281 | else |
---|
282 | stopstate='queue'; |
---|
283 | end |
---|
284 | errormsg=''; |
---|
285 | if isequal(stopstate,'queue')% enable STOP command |
---|
286 | % loop on views (in case of multiple input series) |
---|
287 | for iview=1:nbview |
---|
288 | filename=filecell{iview,ifile}; |
---|
289 | % filename=name_generator(filebase{iview},... |
---|
290 | % i1_series{iview}(ifile),j1_series{iview}(ifile),FileExt{iview},NomType{iview},1,i2_series{iview}(ifile),j2_series{iview}(ifile),SubDir{iview}); |
---|
291 | if exist(filename,'file') |
---|
292 | try |
---|
293 | Data{iview}=[]; %default |
---|
294 | if ~isequal(FileType{iview},'netcdf') |
---|
295 | Data{iview}.ListVarName={'A'}; |
---|
296 | Data{iview}.AName='image'; |
---|
297 | switch FileType{iview} |
---|
298 | case 'movie' |
---|
299 | A=read(MovieObject{iview},i1_series{iview}(ifile)); |
---|
300 | case 'avi' |
---|
301 | mov=aviread(filename,i1_series{iview}(ifile)); |
---|
302 | A=frame2im(mov(1)); |
---|
303 | case 'vol' |
---|
304 | A=imread(filename); |
---|
305 | case 'multimage' |
---|
306 | A=imread(filename,i1_series{iview}(ifile)); |
---|
307 | case 'image' |
---|
308 | A=imread(filename); |
---|
309 | end |
---|
310 | Data{iview}.ListVarName={'AY','AX','A'}; % |
---|
311 | npy=size(A,1); |
---|
312 | npx=size(A,2); |
---|
313 | nbcolor=size(A,3); |
---|
314 | if nbcolor==3 |
---|
315 | Data{iview}.VarDimName={'AY','AX',{'AY','AX','rgb'}}; |
---|
316 | else |
---|
317 | Data{iview}.VarDimName={'AY','AX',{'AY','AX'}}; |
---|
318 | end |
---|
319 | Data{iview}.AY=[npy-0.5 0.5]; |
---|
320 | Data{iview}.AX=[0.5 npx-0.5]; |
---|
321 | Data{iview}.A=double(A); |
---|
322 | Data{iview}.CoordUnit='pixel'; |
---|
323 | elseif testcivx |
---|
324 | [Data{iview},VelTypeOut]=read_civxdata(filename,FieldName,VelType); |
---|
325 | if ~isequal(FieldName,{''}) |
---|
326 | Data{iview}=calc_field(FieldName,Data{iview});%calculate field (vort..) |
---|
327 | end |
---|
328 | else |
---|
329 | [Data{iview},var_detect]=nc2struct(filename,SubField.ListVarName); %read the corresponding input data |
---|
330 | Data{iview}.VarAttribute=SubField.VarAttribute; |
---|
331 | end |
---|
332 | if ~isempty(NbSlice_calib) % z index |
---|
333 | Data{iview}.ZIndex=mod(i1_series{iview}(ifile)-1,NbSlice_calib{1})+1; |
---|
334 | end |
---|
335 | catch ME |
---|
336 | errormsg=ME.message; |
---|
337 | end |
---|
338 | else |
---|
339 | errormsg=[filename ' is missing']; |
---|
340 | end |
---|
341 | if isempty(errormsg) |
---|
342 | % coordinate transform (or other user defined transform) |
---|
343 | if ~isempty(transform_fct) |
---|
344 | if nbview==2 |
---|
345 | [Data{1},Data{2}]=transform_fct(Data{1},XmlData{1},Data{2},XmlData{2}); |
---|
346 | if isempty(Data{2}) |
---|
347 | Data(2)=[]; |
---|
348 | end |
---|
349 | else |
---|
350 | Data{1}=transform_fct(Data{1},XmlData{1}); |
---|
351 | end |
---|
352 | end |
---|
353 | if length(Data)==2 |
---|
354 | [Field,errormsg]=sub_field(Data{1},Data{2}); %substract the two fields |
---|
355 | else |
---|
356 | Field=Data{1}; |
---|
357 | end |
---|
358 | if test_object |
---|
359 | [Field,errormsg]=proj_field(Field,ProjObject); |
---|
360 | end |
---|
361 | end |
---|
362 | filecounter=filecounter+1; |
---|
363 | |
---|
364 | % initiate the time series at the first iteration |
---|
365 | if filecounter==1 |
---|
366 | % stop program if the first field reading is in error |
---|
367 | if ~isempty(errormsg) |
---|
368 | msgbox_uvmat('ERROR',['error in time_series/sub_field:' errormsg]) |
---|
369 | return |
---|
370 | end |
---|
371 | RecordData=Field;%default |
---|
372 | RecordData.NbDim=Field.NbDim+1; %add the time dimension for plots |
---|
373 | nbvar=length(Field.ListVarName); |
---|
374 | if nbvar==0 |
---|
375 | msgbox_uvmat('ERROR','no input variable selected in get_field') |
---|
376 | return |
---|
377 | end |
---|
378 | testsum=2*ones(1,nbvar);%initiate flag for action on each variable |
---|
379 | if isfield(Field,'VarAttribute') % look for coordinate and flag variables |
---|
380 | for ivar=1:nbvar |
---|
381 | if length(Field.VarAttribute)>=ivar && isfield(Field.VarAttribute{ivar},'Role') |
---|
382 | var_role=Field.VarAttribute{ivar}.Role;%'role' of the variable |
---|
383 | if isequal(var_role,'errorflag') |
---|
384 | msgbox_uvmat('ERROR','do not handle error flags in time series') |
---|
385 | return |
---|
386 | end |
---|
387 | if isequal(var_role,'warnflag') |
---|
388 | testsum(ivar)=0; % not recorded variable |
---|
389 | eval(['RecordData=rmfield(RecordData,''' Field.ListVarName{ivar} ''');']);%remove variable |
---|
390 | end |
---|
391 | if isequal(var_role,'coord_x')| isequal(var_role,'coord_y')|... |
---|
392 | isequal(var_role,'coord_z')|isequal(var_role,'coord') |
---|
393 | testsum(ivar)=1; %constant coordinates, record without time evolution |
---|
394 | end |
---|
395 | end |
---|
396 | % check whether the variable ivar is a dimension variable |
---|
397 | DimCell=Field.VarDimName{ivar}; |
---|
398 | if ischar(DimCell) |
---|
399 | DimCell={DimCell}; |
---|
400 | end |
---|
401 | if numel(DimCell)==1 && isequal(Field.ListVarName{ivar},DimCell{1})%detect dimension variables |
---|
402 | testsum(ivar)=1; |
---|
403 | end |
---|
404 | end |
---|
405 | end |
---|
406 | for ivar=1:nbvar |
---|
407 | if testsum(ivar)==2 |
---|
408 | eval(['RecordData.' Field.ListVarName{ivar} '=[];']) |
---|
409 | end |
---|
410 | end |
---|
411 | RecordData.ListVarName=[{'Time'} RecordData.ListVarName]; |
---|
412 | end |
---|
413 | |
---|
414 | % add data to the current field |
---|
415 | for ivar=1:length(Field.ListVarName) |
---|
416 | VarName=Field.ListVarName{ivar}; |
---|
417 | VarVal=Field.(VarName); |
---|
418 | if testsum(ivar)==2% test for recorded variable |
---|
419 | if isempty(errormsg) |
---|
420 | if isequal(ProjObject.ProjMode,'inside')% take the average in the domain for 'inside' mode |
---|
421 | if isempty(VarVal) |
---|
422 | msgbox_uvmat('ERROR',['empty result at frame index ' num2str(i1_series{iview}(ifile))]) |
---|
423 | return |
---|
424 | end |
---|
425 | VarVal=mean(VarVal,1); |
---|
426 | end |
---|
427 | VarVal=shiftdim(VarVal,-1); %shift dimension |
---|
428 | RecordData.(VarName)=cat(1,RecordData.(VarName),VarVal);%concanete the current field to the time series |
---|
429 | else |
---|
430 | RecordData.(VarName)=cat(1,RecordData.(VarName),0);% put each variable to 0 in case of input reading error |
---|
431 | end |
---|
432 | elseif testsum(ivar)==1% variable representing fixed coordinates |
---|
433 | eval(['VarInit=RecordData.' VarName ';']); |
---|
434 | if isempty(errormsg) && ~isequal(VarVal,VarInit) |
---|
435 | msgbox_uvmat('ERROR',['time series requires constant coordinates ' VarName]) |
---|
436 | return |
---|
437 | end |
---|
438 | end |
---|
439 | end |
---|
440 | |
---|
441 | % record the time: |
---|
442 | if isempty(time)% time read in ncfiles |
---|
443 | if isfield(Field,'Time') |
---|
444 | RecordData.Time(filecounter,1)=Field.Time; |
---|
445 | else |
---|
446 | RecordData.Time(filecounter,1)=ifile;%default |
---|
447 | end |
---|
448 | else % time from ImaDoc prevails TODO: correct |
---|
449 | % RecordData.Time(filecounter,1)=time{1}(i1_series{1})(ifile),j1_series{1}(ifile))+time(end,i2_series{end}(ifile),j2_series{end}(ifile)))/2; |
---|
450 | RecordData.Time(filecounter,1)=i1_series{1}(ifile);% TODO : generalise |
---|
451 | end |
---|
452 | |
---|
453 | % record the number of missing input fields |
---|
454 | if ~isempty(errormsg) |
---|
455 | nbmissing=nbmissing+1; |
---|
456 | display(['ifile=' num2str(ifile) ':' errormsg]) |
---|
457 | end |
---|
458 | end |
---|
459 | end |
---|
460 | end |
---|
461 | %%%%%%% END OF LOOP WITHIN A SLICE |
---|
462 | |
---|
463 | %remove time for global attributes if exists |
---|
464 | Time_index=find(strcmp('Time',RecordData.ListGlobalAttribute)); |
---|
465 | if ~isempty(Time_index) |
---|
466 | RecordData.ListGlobalAttribute(Time_index)=[]; |
---|
467 | end |
---|
468 | RecordData.Conventions='uvmat'; |
---|
469 | for ivar=1:numel(RecordData.ListVarName) |
---|
470 | VarName=RecordData.ListVarName{ivar}; |
---|
471 | eval(['RecordData.' VarName '=squeeze(RecordData.' VarName ');']) %remove singletons |
---|
472 | end |
---|
473 | |
---|
474 | % add time dimension |
---|
475 | for ivar=1:length(Field.ListVarName) |
---|
476 | DimCell=Field.VarDimName(ivar); |
---|
477 | if testsum(ivar)==2%variable used as time series |
---|
478 | RecordData.VarDimName{ivar}=[{'Time'} DimCell]; |
---|
479 | elseif testsum(ivar)==1 |
---|
480 | RecordData.VarDimName{ivar}=DimCell; |
---|
481 | end |
---|
482 | end |
---|
483 | indexremove=find(~testsum); |
---|
484 | if ~isempty(indexremove) |
---|
485 | RecordData.ListVarName(1+indexremove)=[]; |
---|
486 | RecordData.VarDimName(indexremove)=[]; |
---|
487 | if isfield(RecordData,'Role') && ~isempty(RecordData.Role{1})%generaliser aus autres attributs |
---|
488 | RecordData.Role(1+indexremove)=[]; |
---|
489 | end |
---|
490 | end |
---|
491 | |
---|
492 | %shift variable attributes |
---|
493 | if isfield(RecordData,'VarAttribute') |
---|
494 | RecordData.VarAttribute=[{[]} RecordData.VarAttribute]; |
---|
495 | end |
---|
496 | RecordData.VarDimName=[{'Time'} RecordData.VarDimName]; |
---|
497 | RecordData.Action=Param.Action;%name of the processing programme |
---|
498 | test_time=diff(RecordData.Time)>0;% test that the readed time is increasing (not constant) |
---|
499 | if ~test_time |
---|
500 | RecordData.Time=[1:filecounter]; |
---|
501 | end |
---|
502 | |
---|
503 | % display nbmissing |
---|
504 | if ~isequal(nbmissing,0) |
---|
505 | msgbox_uvmat('WARNING',[num2str(nbmissing) ' files skipped: missing files or bad input, see command window display']) |
---|
506 | end |
---|
507 | |
---|
508 | %name of result file |
---|
509 | % [filemean]=... |
---|
510 | % name_generator(filebase_out,i1_series{1}(i_slice),j1_series{1}(i_slice),'.nc','_i1-i2_j1-j2',1,i2_series{end}(ifile),j2_series{end}(ifile),subdir_result); |
---|
511 | filemean=fullfile_uvmat(RootPath{1},subdir_result,RootFile{1},'.nc','_1',i1_series{1}(i_slice)); |
---|
512 | errormsg=struct2nc(filemean,RecordData); %save result file |
---|
513 | if isempty(errormsg) |
---|
514 | display([filemean ' written']) |
---|
515 | else |
---|
516 | msgbox_uvmat('ERROR',['error in Series/struct2nc: ' errormsg]) |
---|
517 | end |
---|
518 | end |
---|
519 | |
---|
520 | %% plot the time series (the last one in case of multislices) |
---|
521 | figure |
---|
522 | haxes=axes; |
---|
523 | plot_field(RecordData,haxes) |
---|
524 | |
---|
525 | %% display the result file using the GUI get_field |
---|
526 | hget_field=findobj(allchild(0),'name','get_field'); |
---|
527 | if ~isempty(hget_field) |
---|
528 | delete(hget_field) |
---|
529 | end |
---|
530 | get_field(filemean,RecordData) |
---|
531 | |
---|
532 | %------------------------------------------------------------------------ |
---|
533 | % --- Executes on selection change in CoordType. |
---|
534 | function CoordType_Callback(hObject, eventdata, handles) |
---|
535 | %------------------------------------------------------------------------ |
---|
536 | menu_str=get(handles.CoordType,'String'); |
---|
537 | ind_coord=get(handles.CoordType,'Value'); |
---|
538 | coord_option=menu_str{ind_coord}; |
---|
539 | if isequal(coord_option,'more...'); |
---|
540 | fct_name=''; |
---|
541 | if exist('./TMP/current_usr_fct.mat','file')% if a file is found |
---|
542 | h=load('./TMP/current_usr_fct.mat'); |
---|
543 | if isfield(h,'fct_name'); |
---|
544 | fct_name=h.fct_name; |
---|
545 | end |
---|
546 | end |
---|
547 | prompt = {'Enter the name of the transform function'}; |
---|
548 | dlg_title = 'user defined transform'; |
---|
549 | num_lines= 1; |
---|
550 | [FileName, PathName, filterindex] = uigetfile( ... |
---|
551 | {'*.m', ' (*.m)'; |
---|
552 | '*.m', '.m files '; ... |
---|
553 | '*.*', 'All Files (*.*)'}, ... |
---|
554 | 'Pick a file', fct_name); |
---|
555 | fct_name=fullfile(PathName,FileName); |
---|
556 | addpath(PathName);%add the path to the selected fct |
---|
557 | [errormsg,date_str]=check_functions;%check whether new functions can oversed the uvmat package A UTILISER |
---|
558 | if ~exist(fct_name,'file') |
---|
559 | warndlg(['image procesing fct ' fct_name ' not found']) |
---|
560 | else |
---|
561 | transform=FileName(1:end-2);% |
---|
562 | update_menu(handles.CoordType,transform)%add the selected fct to the menu |
---|
563 | % set(handles.mouse_coord,'String',menu([1:end-1])')%update the mouse coord menu |
---|
564 | %save ('./TMP/current_usr_fct.mat','fct_name'); |
---|
565 | end |
---|
566 | end |
---|
567 | ind_coord=get(handles.CoordType,'Value'); |
---|
568 | |
---|
569 | %--------------------------------------------------------------------- |
---|
570 | % % --- Executes on selection change in ProjObject. |
---|
571 | % function ProjObject_Callback(hObject, eventdata, handles) |
---|
572 | % |
---|
573 | % list_object=get(handles.ProjObject,'String'); |
---|
574 | % index=get(handles.ProjObject,'Value'); |
---|
575 | % hseries=get(handles.ProjObject,'Parent'); |
---|
576 | % SeriesData=get(hseries,'UserData'); |
---|
577 | % Obj=SeriesData.ProjObject{index}; |
---|
578 | % [SeriesData.hset_object,SeriesData.sethandles]=set_object(SeriesData.ProjObject{index}); |
---|
579 | % set(hseries,'UserData',SeriesData); |
---|
580 | |
---|