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