source: trunk/src/series.m @ 471

Last change on this file since 471 was 471, checked in by sommeria, 9 years ago

a few bugs repaired

File size: 90.3 KB
Line 
1%'series': master function associated to the GUI series.m for analysis field series 
2%------------------------------------------------------------------------
3% function varargout = series(varargin)
4% associated with the GUI series.fig
5%
6%INPUT
7% param: structure with input parameters (link with the GUI uvmat)
8%      .menu_coord_str: string for the TransformName (menu for coordinate transforms)
9%      .menu_coord_val: value for TransformName (menu for coordinate transforms)
10%      .FileName: input file name
11%      .FileName_1: second input file name
12%      .list_field: menu of input fields
13%      .index_fields: chosen index
14%      .civ1=0 or 1, .interp1,  ... : input civ field type
15%
16%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
17%  Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
18%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
19%     This file is part of the toolbox UVMAT.
20%
21%     UVMAT is free software; you can redistribute it and/or modify
22%     it under the terms of the GNU General Public License as published by
23%     the Free Software Foundation; either version 2 of the License, or
24%     (at your option) any later version.
25%
26%     UVMAT is distributed in the hope that it will be useful,
27%     but WITHOUT ANY WARRANTY; without even the implied warranty of
28%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29%     GNU General Public License (file UVMAT/COPYING.txt) for more details.
30%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
31
32%------------------------------------------------------------------------
33%------------------------------------------------------------------------
34%  I - MAIN FUNCTION series
35%------------------------------------------------------------------------
36%------------------------------------------------------------------------
37function varargout = series(varargin)
38
39% Begin initialization code - DO NOT EDIT
40gui_Singleton = 1;
41gui_State = struct('gui_Name',       mfilename, ...
42                   'gui_Singleton',  gui_Singleton, ...
43                   'gui_OpeningFcn', @series_OpeningFcn, ...
44                   'gui_OutputFcn',  @series_OutputFcn, ...
45                   'gui_LayoutFcn',  [] , ...
46                   'gui_Callback',   []);
47if nargin && ischar(varargin{1})
48    gui_State.gui_Callback = str2func(varargin{1});
49end
50
51if nargout
52    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
53else
54    gui_mainfcn(gui_State, varargin{:});
55end
56% End initialization code - DO NOT EDIT
57
58%--------------------------------------------------------------------------
59% --- Executes just before series is made visible.
60%--------------------------------------------------------------------------
61function series_OpeningFcn(hObject, eventdata, handles,param)
62global nb_builtin_ACTION nb_builtin_transform
63% Choose default command line output for series
64handles.output = hObject;
65% Update handles structure
66guidata(hObject, handles);
67%default initial parameters
68drawnow
69set(hObject,'Units','pixels')
70set(handles.PairString,'ColumnEditable',logical(0))
71set(handles.PairString,'ColumnFormat',{'char'})
72set(handles.PairString,'ColumnWidth',{60})
73set(handles.PairString,'Data',{''})
74set(hObject,'WindowButtonDownFcn',{'mouse_down'})%allows mouse action with right button (zoom for uicontrol display)
75dir_perso=prefdir;
76test_profil_perso=0;
77profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
78if exist(profil_perso,'file')
79     h=load (profil_perso);
80     if isfield(h,'MenuFile')
81          for ifile=1:min(length(h.MenuFile),5)
82              eval(['set(handles.MenuFile_' num2str(ifile) ',''Label'',h.MenuFile{ifile});'])
83%               eval(['set(handles.MenuFile_' num2str(ifile) '_1,''Label'',h.MenuFile{ifile});'])
84          end
85     end
86%      if isfield(h,'MenuFile')
87%           for ifile=1:min(length(h.MenuFile),5)
88%               eval(['set(handles.MenuFile_' num2str(ifile) ',''Label'',h.MenuFile{ifile});'])
89%                eval(['set(handles.MenuFile_' num2str(ifile) '_1,''Label'',h.MenuFile{ifile});'])
90%           end
91%       end
92     
93     test_profil_perso=1;
94%      if isfield(h,'MenuFile_1') && exist(h.MenuFile_1,'file')
95%           set(handles.MenuFile_1,'Label',h.MenuFile_1);
96%           set(handles.MenuFile_insert_1,'Label',h.MenuFile_1);
97%      end
98%      if isfield(h,'MenuFile_2')&& exist(h.MenuFile_2,'file')
99%           set(handles.MenuFile_2,'Label',h.MenuFile_2);
100%           set(handles.MenuFile_insert_2,'Label',h.MenuFile_2);
101%      end
102%      if isfield(h,'MenuFile_3')&& exist(h.MenuFile_3,'file')
103%           set(handles.MenuFile_3,'Label',h.MenuFile_3);
104%           set(handles.MenuFile_insert_3,'Label',h.MenuFile_3);
105%      end
106%      if isfield(h,'MenuFile_4')&& exist(h.MenuFile_4,'file')
107%           set(handles.MenuFile_4,'Label',h.MenuFile_4);
108%           set(handles.MenuFile_insert_4,'Label',h.MenuFile_4);
109%      end
110%      if isfield(h,'MenuFile_5')&& exist(h.MenuFile_5,'file')
111%           set(handles.MenuFile_5,'Label',h.MenuFile_5);
112%           set(handles.MenuFile_insert_5,'Label',h.MenuFile_5);
113%      end
114end
115
116%check default input data
117if ~exist('param','var')
118    param=[]; %default
119end
120
121%% file name and browser initialisation
122if isfield(param,'menu_coord_str')
123    set(handles.TransformName,'String',param.menu_coord_str)
124end
125if isfield(param,'menu_coord_val')
126    set(handles.TransformName,'Value',param.menu_coord_val);
127else
128     set(handles.TransformName,'Value',1);%default
129end
130if isfield(param,'FileName')
131    if isfield(param,'FileName_1')
132        display_file_name(handles,param.FileName_1,0)
133        display_file_name(handles,param.FileName,1)
134    else
135        display_file_name(handles,param.FileName,0)
136    end
137end 
138
139%% fields input initialisation
140if isfield(param,'list_fields')&& isfield(param,'index_fields') &&~isempty(param.list_fields) &&~isempty(param.index_fields)
141    set(handles.FieldName,'String',param.list_fields);% list menu fields
142    set(handles.FieldName,'Value',param.index_fields);% selected string index
143    FieldCell{1}=param.list_fields{param.index_fields};
144end
145
146%loads the information stored in prefdir to initiate  the list of ActionName functions
147fct_menu={'check_data_files';'aver_stat';'time_series';'merge_proj';'clean_civ_cmx'};
148transform_menu={'';'phys';'px';'phys_polar'};
149nb_builtin_ACTION=numel(fct_menu); %number of functions
150nb_transform=numel(transform_menu);
151[path_series,name,ext]=fileparts(which('series'));
152path_series=fullfile(path_series,'series');%path of the function 'series'
153addpath (path_series) ; %add the path to UVMAT, (useful in case of change of working directory after civ has been s opened in the working directory)
154path_transform=fullfile(path_series,'transform_field');%path to the field transform functions
155for ilist=1:length(fct_menu)
156    fct_path{ilist,1}=path_series;%paths of the fuctions buil-in in 'series.m'
157end
158
159%% TRANSFORM menu: loads the information stored in prefdir to initiate  the list of field transform functions
160menu_str={'';'phys';'px';'phys_polar'};
161nb_builtin_transform=numel(menu_str); %number of functions
162[path_uvmat,name,ext]=fileparts(which('uvmat'));
163addpath(fullfile(path_uvmat,'transform_field'))
164fct_handle{1,1}=[];
165testexist(1)=1;
166for ilist=2:length(menu_str)
167    if exist(menu_str{ilist},'file')
168        fct_handle{ilist,1}=str2func(menu_str{ilist});
169        testexist(ilist)=1;
170    else
171        testexist(ilist)=0;
172    end
173end
174rmpath(fullfile(path_uvmat,'transform_field'))
175
176%% read the list of functions stored in the personal file 'uvmat_perso.mat' in prefdir
177if test_profil_perso
178    if isfield(h,'series_fct') && iscell(h.series_fct)
179         for ilist=1:length(h.series_fct)
180             [path,file]=fileparts(h.series_fct{ilist});
181             fct_path=[fct_path; {path}];%concatene the list of paths
182             fct_menu=[fct_menu; {file}];
183         end
184    end
185    if isfield(h,'transform_fct') && iscell(h.transform_fct)
186        for ilist=1:length(h.transform_fct);
187             [path,file]=fileparts(h.transform_fct{ilist});
188             addpath(path)
189             if exist(file,'file')
190                h_func=str2func(file);
191                testexist=[testexist 1];
192             else
193                h_func=[];
194                testexist=[testexist 0];
195             end
196             fct_handle=[fct_handle; {h_func}];%concatene the list of paths
197             rmpath(path)
198             menu_str=[menu_str; {file}];
199        end
200    end
201end
202fct_menu=[fct_menu;{'more...'}];
203set(handles.ActionName,'String',fct_menu)
204set(handles.ActionName,'UserData',fct_path)% store the list of path in UserData of ACTION
205menu_str=menu_str(find(testexist));
206fct_handle=fct_handle(find(testexist));
207menu_str=[menu_str;{'more...'}];
208set(handles.TransformName,'String',menu_str)
209set(handles.TransformName,'UserData',fct_handle)% store the list of path in UserData of ACTION
210
211% display the GUI for the default actionname 'check_data_files'
212ActionName_Callback(hObject, eventdata, handles)
213
214%------------------------------------------------------------------------
215% --- Outputs from this function are returned to the command line.
216function varargout = series_OutputFcn(hObject, eventdata, handles)
217%------------------------------------------------------------------------
218% varargout  cell array for returning output args (see VARARGOUT);
219% hObject    handle to figure
220% eventdata  reserved - to be defined in a future version of MATLAB
221% handles    structure with handles and user data (see GUIDATA)
222% Get default command line output from handles structure
223varargout{1} = handles.output;
224
225%------------------------------------------------------------------------
226%------------------------------------------------------------------------
227%  II - FUNCTIONS FOR INTRODUCING THE INPUT FILES
228% automatically sets the global properties when the rootfile name is introduced
229% then activate the view-field actionname if selected
230% it is activated either by clicking on the RootPath window or by the
231% browser
232%------------------------------------------------------------------------
233%------------------------------------------------------------------------
234function MenuBrowse_Callback(hObject, eventdata, handles)
235%------------------------------------------------------------------------   
236InputTable=get(handles.InputTable,'Data');
237RootPathCell=InputTable(:,1);
238SubDirCell=InputTable(:,2);
239RootFileCell=InputTable(:,3);
240oldfile=''; %default
241if isempty(RootPathCell)||isequal(RootPathCell,{''})%loads the previously stored file name and set it as default in the file_input box
242     dir_perso=prefdir;
243     profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
244     if exist(profil_perso,'file')
245          h=load (profil_perso);
246         if isfield(h,'filebase')&&ischar(h.filebase)
247                 oldfile=h.filebase;
248         end
249         if isfield(h,'RootPath')&&ischar(h.RootPath)
250                 oldfile=h.RootPath;
251         end
252     end
253 else
254     oldfile=fullfile(RootPathCell{1},SubDirCell{1},RootFileCell{1});
255 end
256[FileName, PathName, filterindex] = uigetfile( ...
257       {'*.xml;*.xls;*.png;*.tif;*.avi;*.AVI;*.nc', ' (*.xml,*.xls, *.png,*.tif, *.avi,*.nc)';
258       '*.xml',  '.xml files '; ...
259        '*.xls',  '.xls files '; ...
260        '*.png','.png image files'; ...
261        '*.tif','.tif image files'; ...
262        '*.avi;*.AVI','.avi movie files'; ...
263        '*.nc','.netcdf files'; ...
264        '*.*',  'All Files (*.*)'}, ...
265        'Pick a file',oldfile);
266fileinput=[PathName FileName];%complete file name
267sizf=size(fileinput);
268if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end
269[path,name,ext]=fileparts(fileinput);
270SeriesData=[];%dfault
271if isequal(ext,'.xml')
272     Param=xml2struct(fileinput);
273    fill_GUI(Param,handles);%fill the GUI with the parameters retrieved from the xml file
274    if isfield(Param,'CheckObject')&& Param.CheckObject
275        set_object(Param.ProjObject)
276    end
277    return
278elseif isequal(ext,'.xls')
279    msg_box_uvmat('ERROR','input file type not implemented')%A Faire: ouvrir le fichier pour naviguer
280else
281    display_file_name(handles,fileinput,0)
282     %update list of recent files in the menubar
283%     MenuFile_1=fileinput;
284%     MenuFile_2=get(handles.MenuFile_1,'Label');
285%     MenuFile_3=get(handles.MenuFile_2,'Label');
286%     MenuFile_4=get(handles.MenuFile_3,'Label');
287%     MenuFile_5=get(handles.MenuFile_4,'Label');
288%     set(handles.MenuFile_1,'Label',MenuFile_1)
289%     set(handles.MenuFile_2,'Label',MenuFile_2)
290%     set(handles.MenuFile_3,'Label',MenuFile_3)
291%     set(handles.MenuFile_4,'Label',MenuFile_4)
292%     set(handles.MenuFile_5,'Label',MenuFile_5)
293%     set(handles.MenuFile_insert_1,'Label',MenuFile_1)
294%     set(handles.MenuFile_insert_2,'Label',MenuFile_2)
295%     set(handles.MenuFile_insert_3,'Label',MenuFile_3)
296%     set(handles.MenuFile_insert_4,'Label',MenuFile_4)
297%     set(handles.MenuFile_insert_5,'Label',MenuFile_5)
298%     dir_perso=prefdir;
299%     profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
300%     if exist(profil_perso,'file')
301%         save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-append'); %store the file names for future opening of uvmat
302%     else
303%     txt=ver('MATLAB');
304%     Release=txt.Release;
305%         relnumb=str2num(Release(3:4));
306%         if relnumb >= 14
307%             save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5','-V6'); %store the file names for future opening of uvmat
308%         else
309%             save (profil_perso,'MenuFile_1','MenuFile_2','MenuFile_3','MenuFile_4', 'MenuFile_5'); %store the file names for future opening of uvmat
310%         end
311%     end
312end
313
314% --------------------------------------------------------------------
315function MenuFile_1_Callback(hObject, eventdata, handles)
316fileinput=get(handles.MenuFile_1,'Label');
317display_file_name(handles,fileinput,0)
318
319% --------------------------------------------------------------------
320function MenuFile_2_Callback(hObject, eventdata, handles)
321fileinput=get(handles.MenuFile_2,'Label');
322display_file_name(handles,fileinput,0)
323
324% --------------------------------------------------------------------
325function MenuFile_3_Callback(hObject, eventdata, handles)
326fileinput=get(handles.MenuFile_3,'Label');
327display_file_name( handles,fileinput,0)
328
329% --------------------------------------------------------------------
330function MenuFile_4_Callback(hObject, eventdata, handles)
331fileinput=get(handles.MenuFile_4,'Label');
332display_file_name(handles,fileinput,0)
333
334% --------------------------------------------------------------------
335function MenuFile_5_Callback(hObject, eventdata, handles)
336fileinput=get(handles.MenuFile_5,'Label');
337display_file_name(handles,fileinput,0)
338
339% --------------------------------------------------------------------
340function MenuBrowse_insert_Callback(hObject, eventdata, handles)
341InputTable=get(handles.InputTable,'Data');
342RootPathCell=InputTable(:,1);
343SubDirCell=InputTable(:,3);
344RootFileCell=InputTable(:,2);
345oldfile=''; %default
346if isempty(RootPathCell)||isequal(RootPathCell,{''})%loads the previously stored file name and set it as default in the file_input box
347     dir_perso=prefdir;
348     profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
349     if exist(profil_perso,'file')
350          h=load (profil_perso);
351         if isfield(h,'filebase')&ischar(h.filebase)
352                 oldfile=h.filebase;
353         end
354         if isfield(h,'RootPath')&ischar(h.RootPath)
355                 oldfile=h.RootPath;
356         end
357     end
358 else
359     oldfile=fullfile(RootPathCell{1},RootFileCell{1});
360 end
361[FileName, PathName, filterindex] = uigetfile( ...
362       {'*.xml;*.xls;*.png;*.avi;*.AVI;*.nc', ' (*.xml,*.xls, *.png, *.avi,*.nc)';
363       '*.xml',  '.xml files '; ...
364        '*.xls',  '.xls files '; ...
365        '*.png','.png image files'; ...
366        '*.avi;*.AVI','.avi movie files'; ...
367        '*.nc','.netcdf files'; ...
368        '*.*',  'All Files (*.*)'}, ...
369        'Pick a file',oldfile);
370fileinput=[PathName FileName];%complete file name
371sizf=size(fileinput);
372if (~ischar(fileinput)|~isequal(sizf(1),1)),return;end
373[path,name,ext]=fileparts(fileinput);
374if isequal(ext,'.xml')
375    msgbox_uvmat('ERROR','input file type not implemented')%A Faire: ouvrir le fichier pour naviguer
376elseif isequal(ext,'.xls')
377    msgbox_uvmat('ERROR','input file type not implemented')%A Faire: ouvrir le fichier pour naviguer
378else
379    display_file_name(handles,fileinput,1)
380end
381
382% --------------------------------------------------------------------
383function MenuFile_insert_1_Callback(hObject, eventdata, handles)
384% --------------------------------------------------------------------   
385fileinput=get(handles.MenuFile_insert_1,'Label');
386display_file_name(handles,fileinput,1)
387
388% --------------------------------------------------------------------
389function MenuFile_insert_2_Callback(hObject, eventdata, handles)
390% --------------------------------------------------------------------   
391fileinput=get(handles.MenuFile_insert_2,'Label');
392display_file_name(handles,fileinput,1)
393
394% --------------------------------------------------------------------
395function MenuFile_insert_3_Callback(hObject, eventdata, handles)
396% --------------------------------------------------------------------   
397fileinput=get(handles.MenuFile_insert_3,'Label');
398display_file_name( handles,fileinput,1)
399
400% --------------------------------------------------------------------
401function MenuFile_insert_4_Callback(hObject, eventdata, handles)
402% --------------------------------------------------------------------   
403fileinput=get(handles.MenuFile_insert_4,'Label');
404display_file_name( handles,fileinput,1)
405
406% --------------------------------------------------------------------
407function MenuFile_insert_5_Callback(hObject, eventdata, handles)
408% --------------------------------------------------------------------   
409fileinput=get(handles.MenuFile_insert_5,'Label');
410display_file_name(handles,fileinput,1)
411
412%------------------------------------------------------------------------
413% --- Executes when entered data in editable cell(s) in InputTable.
414function InputTable_CellEditCallback(hObject, eventdata, handles)
415%------------------------------------------------------------------------
416iview=eventdata.Indices(1);
417InputTable=get(handles.InputTable,'Data');
418fileinput=fullfile(InputTable{iview,1},InputTable{iview,2},[InputTable{iview,3} InputTable{iview,4} InputTable{iview,5}]);
419display_file_name(handles,fileinput,0)
420%update the output dir
421SubDir=sort(InputTable(:,2)); %set of subdirectories sorted in alphabetical order
422SubDirOut=SubDir{1};
423if numel(SubDir)>1
424    for ilist=2:numel(SubDir)
425        SubDirOut=[SubDirOut '-' SubDir{ilist}];
426    end
427end
428set(handles.OutputSubDir,'String',SubDirOut)
429
430%------------------------------------------------------------------------
431% ---  refresh the GUI data after introduction of a new file
432% INPUT:
433% handles: handles of the elements in the GUI series
434% fileinput: name of the input file
435% append: =0 to refresh the list of file series, =1 to append a new series to the list (from the menu bar option 'Open_insert')
436function display_file_name(handles,fileinput,append)
437%------------------------------------------------------------------------ 
438
439%% get the input root name, indices, file extension and nomenclature NomType
440if ~exist(fileinput,'file')
441    msgbox_uvmat('ERROR',['input file ' fileinput  ' does not exist'])
442    return
443end
444
445%% enable other menus and uicontrols
446set(handles.MenuOpen_insert,'Enable','on')
447set(handles.MenuFile_insert_1,'Enable','on')
448set(handles.MenuFile_insert_2,'Enable','on')
449set(handles.MenuFile_insert_3,'Enable','on')
450set(handles.MenuFile_insert_4,'Enable','on')
451set(handles.MenuFile_insert_5,'Enable','on')
452set(handles.RUN, 'Enable','On')
453set(handles.RUN,'BackgroundColor',[1 0 0])% set RUN button to red
454set(handles.InputTable,'BackgroundColor',[1 1 0]) % set RootPath edit box  to yellow
455drawnow
456
457%% detect root name, nomenclature and indices in the input file name:
458[FilePath,FileName,FileExt]=fileparts(fileinput);
459% detect the file type, get the movie object if relevant, and look for the corresponding file series:
460% the root name and indices may be corrected by including the first index i1 if a corresponding xml file exists
461[RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,NomType,FileType,MovieObject,i1,i2,j1,j2]=find_file_series(FilePath,[FileName FileExt]);
462if isempty(RootFile)&&isempty(i1_series)
463    errormsg='no input file in the series';
464    return
465end
466
467%% fill the list of file series
468InputTable=get(handles.InputTable,'Data');
469if append % display the input data as a new line in the table
470     lastview=size(InputTable,1)+1;
471     InputTable(lastview,:)=[{RootPath},{SubDir},{RootFile},{NomType},{FileExt}];
472    set(handles.ListView,'String',[get(handles.ListView,'String');{num2str(lastview)}])
473    set(handles.ListView,'Value',lastview)
474
475else % or re-initialise the list of  input  file series
476    lastview=1;
477    InputTable=[{RootPath},{SubDir},{RootFile},{NomType},{FileExt}];
478    set(handles.TimeTable,'Data',[{[]},{[]},{[]},{[]}])
479    set(handles.MinIndex,'Data',[{[]},{[]}])
480    set(handles.MaxIndex,'Data',[{[]},{[]}])
481    set(handles.ListView,'Value',1)
482    set(handles.ListView,'String',{'1'})
483end
484set(handles.InputTable,'Data',InputTable)
485
486%% display the min and max indices for all the file series
487i_sum=sum(sum(i1_series,2),3);%sum of i1_series on the last index
488MaxIndex_i=max(find(i_sum>0))-1;
489MinIndex_i=min(find(i_sum>0))-1;
490i2_min=[];
491if ~isempty(i2_series)
492    i2_min=i2_series(1,2);
493end
494j1_min=[];
495if ~isempty(j1_series)
496    j1_min=j1_series(1,2);
497end
498j2_min=[];
499if ~isempty(j2_series)
500    j2_min=j2_series(1,2);
501end
502if isequal(MinIndex_i,1) && exist (fullfile_uvmat(RootPath,SubDir,RootFile,FileExt,NomType,0,i2_min, j1_min,j2_min),'file')
503    MinIndex_i=0;
504end
505j_sum=sum(sum(j1_series,1),3);
506MaxIndex_j=max(find(j_sum>0))-1;
507MinIndex_j=min(find(j_sum>0))-1;
508MinIndex=get(handles.MinIndex,'Data');%retrieve the min indices in the table MinIndex
509MaxIndex=get(handles.MaxIndex,'Data');%retrieve the max indices in the table MaxIndex
510MinIndex{lastview,1}=MinIndex_i;
511MinIndex{lastview,2}=MinIndex_j;
512MaxIndex{lastview,1}=MaxIndex_i;
513MaxIndex{lastview,2}=MaxIndex_j;
514
515set(handles.MinIndex,'Data',MinIndex)%display the min indices in the table MinIndex
516set(handles.MaxIndex,'Data',MaxIndex)%display the max indices in the table MaxIndex
517
518%% adjust the first and last indices if requested by the bounds
519first_i=str2num(get(handles.num_first_i,'String'));
520ref_i=str2num(get(handles.num_ref_i,'String'));
521ref_j=str2num(get(handles.num_ref_j,'String'));
522if isempty(first_i)
523    first_i=ref_i;
524elseif first_i < MinIndex_i
525    first_i=MinIndex_i;
526end
527first_j=str2num(get(handles.num_first_j,'String'));
528if isempty(first_j)
529    first_j=ref_j;
530elseif first_j<MinIndex_j
531    first_j=MinIndex_j;
532end
533last_i=str2num(get(handles.num_last_i,'String'));
534if isempty(last_i)
535    last_i=ref_i;
536elseif last_i > MaxIndex_i
537    last_i=MaxIndex_i;
538end
539last_j=str2num(get(handles.num_first_j,'String'));
540if isempty(last_j)
541    last_j=ref_j;
542elseif last_j>MaxIndex_j
543    last_j=MaxIndex_j;
544end
545set(handles.num_first_i,'String',num2str(first_i));
546set(handles.num_first_j,'String',num2str(first_j));
547set(handles.num_last_i,'String',num2str(last_i));
548set(handles.num_last_j,'String',num2str(last_j));
549
550
551%% update the output dir
552SubDir=sort(InputTable(:,2)); %set of subdirectories sorted in alphabetical order
553SubDirOut=SubDir{1};
554if numel(SubDir)>1
555    for ilist=2:numel(SubDir)
556        SubDirOut=[SubDirOut '-' SubDir{ilist}];
557    end
558end
559set(handles.OutputSubDir,'String',SubDirOut)
560
561%% determine the selected reference field indices for pair display
562ref_i=1; %default ref_i is a reference frame index used to find existing pairs from PIV
563if ~isempty(i1)
564    ref_i=i1;
565    if ~isempty(i2)
566        ref_i=floor((ref_i+i2)/2);% reference image number corresponding to the file
567    end
568end
569set(handles.num_ref_i,'String',num2str(ref_i));
570ref_j=1; %default  ref_j is a reference frame index used to find existing pairs from PIV
571if ~isempty(j1)
572    ref_j=j1;
573    if ~isempty(j2)
574        ref_j=floor((j1+j2)/2);
575    end         
576end
577set(handles.num_ref_j,'String',num2str(ref_j));
578
579%% update the list of recent files in the menubar and save it for future opening
580MenuFile=[{get(handles.MenuFile_1,'Label')};{get(handles.MenuFile_2,'Label')};...
581    {get(handles.MenuFile_3,'Label')};{get(handles.MenuFile_4,'Label')};{get(handles.MenuFile_5,'Label')}];
582str_find=strcmp(fileinput,MenuFile);
583if isempty(find(str_find,1))
584    MenuFile=[{fileinput};MenuFile];%insert the current file if not already in the list
585end
586for ifile=1:min(length(MenuFile),5)
587    eval(['set(handles.MenuFile_' num2str(ifile) ',''Label'',MenuFile{ifile});'])
588    eval(['set(handles.MenuFile_insert_' num2str(ifile) ',''Label'',MenuFile{ifile});'])
589end
590dir_perso=prefdir;
591profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
592if exist(profil_perso,'file')
593    save (profil_perso,'MenuFile','-append'); %store the file names for future opening of uvmat
594else
595    save (profil_perso,'MenuFile','-V6'); %store the file names for future opening of uvmat
596end
597
598set(handles.InputTable,'BackgroundColor',[1 1 1])
599
600%% initiate input file series and refresh the current field view:     
601update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileType,MovieObject,lastview);
602
603%------------------------------------------------------------------------
604% --- Update information about a new field series (indices to scan, timing,
605%     calibration from an xml file, then refresh current plots
606function update_rootinfo(handles,i1_series,i2_series,j1_series,j2_series,FileType,VideoObject,iview)
607%------------------------------------------------------------------------
608
609%% enable j index visibility
610if isempty(j1_series)
611    state='off';
612else
613    state='on';
614end
615enable_j(handles,state)
616
617%% read timing and total frame number from the current file (movie files) !! may be overrid by xml file
618InputTable=get(handles.InputTable,'Data');
619FileBase=fullfile(InputTable{iview,1},InputTable{iview,3});
620time=[];%default
621% case of movies
622if strcmp(InputTable{iview,4},'*')
623    if ~isempty(VideoObject)
624        imainfo=get(VideoObject);
625        time=(0:1/imainfo.FrameRate:(imainfo.NumberOfFrames-1)/imainfo.FrameRate)';
626        set(handles.Dt_txt,'String',['Dt=' num2str(1000/imainfo.FrameRate) 'ms']);%display the elementary time interval in millisec
627        ColorType='truecolor';
628    elseif ~isempty(imformats(regexprep(InputTable{iview,5},'^.',''))) || isequal(InputTable{iview,5},'.vol')%&& isequal(NomType,'*')% multi-frame image
629        if ~isempty(InputTable{iview,2})
630            imainfo=imfinfo(fullfile(InputTable{iview,1},InputTable{iview,2},[InputTable{iview,3} InputTable{iview,5}]));
631        else
632            imainfo=imfinfo([FileBase InputTable{iview,5}]);
633        end
634        ColorType=imainfo.ColorType;%='truecolor' for color images
635        if length(imainfo) >1 %case of image with multiple frames
636            nbfield=length(imainfo);
637            nbfield_j=1;
638        end
639    end
640end
641
642%%  read image documentation file  if found%%%%%%%%%%%%%%%%%%%%%%%%%%%
643ext_imadoc='';
644if exist([FileBase '.xml'],'file')
645    ext_imadoc='.xml';
646elseif exist([FileBase '.civ'],'file')
647    ext_imadoc='.civ';
648end
649%read the ImaDoc file
650XmlData=[];
651NbSlice_calib={};
652if isequal(ext_imadoc,'.xml')
653        [XmlData,warntext]=imadoc2struct([FileBase '.xml']);
654        if isfield(XmlData,'Heading') && isfield(XmlData.Heading,'ImageName') && ischar(XmlData.Heading.ImageName)
655            [PP,FF,ext_ima_read]=fileparts(XmlData.Heading.ImageName);
656        end
657        if isfield(XmlData,'Time')
658            time=XmlData.Time;
659        end
660        if isfield(XmlData,'Camera')
661            if isfield(XmlData.Camera,'NbSlice')&& ~isempty(XmlData.Camera.NbSlice)
662                NbSlice_calib{iview}=XmlData.Camera.NbSlice;% Nbre of slices for Zindex in phys transform
663                if ~isequal(NbSlice_calib{iview},NbSlice_calib{1})
664                    msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
665                end
666            end
667            if isfield(XmlData.Camera,'TimeUnit')&& ~isempty(XmlData.Camera.TimeUnit)
668                TimeUnit=XmlData.Camera.TimeUnit;
669            end
670        end
671        if ~isempty(warntext)
672            msgbox_uvmat('WARNING',warntext)
673        end 
674elseif isequal(ext_imadoc,'.civ')
675    [error,XmlData.Time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([FileBase '.civ']);
676    time=XmlData.Time;
677    if error==2, warntext=['no file ' FileBase '.civ'];
678    elseif error==1, warntext='inconsistent number of fields in the .civ file';
679    end 
680end
681
682%% update time table
683if ~isempty(time)
684TimeTable=get(handles.TimeTable,'Data');
685first_i=str2num(get(handles.num_first_i,'String'));
686last_i=str2num(get(handles.num_last_i,'String'));
687first_j=str2num(get(handles.num_first_i,'String'));
688last_j=str2num(get(handles.num_last_i,'String'));
689MinIndexTable=get(handles.MinIndex,'Data');
690MinIndex_i=MinIndexTable{iview,1};
691MinIndex_j=MinIndexTable{iview,2};
692MaxIndexTable=get(handles.MaxIndex,'Data');
693MaxIndex_i=MaxIndexTable{iview,1};
694MaxIndex_j=MaxIndexTable{iview,2};
695if isempty(MinIndex_j)
696    if MinIndex_i>0
697    TimeTable{iview,1}=time(MinIndex_i);
698    end
699    TimeTable{iview,2}=time(first_i);
700    TimeTable{iview,3}=time(last_i);
701    TimeTable{iview,4}=time(MaxIndex_i);
702elseif ~isempty(time)
703    if MinIndex_i>0
704    TimeTable{iview,1}=time(MinIndex_i,MinIndex_j);
705    end
706    TimeTable{iview,2}=time(first_i,first_j);
707    TimeTable{iview,3}=time(last_i,last_j);
708    TimeTable{iview,4}=time(MaxIndex_i,MaxIndex_j);
709end
710set(handles.TimeTable,'Data',TimeTable)
711end
712
713%% number of slices
714NbSlice=1;%default
715if isfield(XmlData,'GeometryCalib') && isfield(XmlData.GeometryCalib,'SliceCoord')
716    siz=size(XmlData.GeometryCalib.SliceCoord);
717    if siz(1)>1
718        NbSlice=siz(1);
719    end
720end
721set(handles.num_NbSlice,'String',num2str(NbSlice))
722   
723%% update pair menus
724set(handles.Pairs,'Visible','on')
725set(handles.PairString,'Visible','on')
726ListView=get(handles.ListView,'String');
727ListView{iview}=num2str(iview);
728set(handles.ListView,'String');
729set(handles.ListView,'Value',iview)
730update_mode(handles,i1_series,i2_series,j1_series,j2_series,time)
731
732
733%% display the set of existing files as an image
734set(handles.waitbar_frame,'Units','pixels')
735pos=get(handles.waitbar_frame,'Position');
736xima=0.5:pos(3)-0.5;% pixel positions on the image representing the existing file indices
737yima=0.5:pos(4)-0.5;
738[XIma,YIma]=meshgrid(xima,yima);
739nb_i=size(i1_series,1);
740nb_j=size(i1_series,2);
741ind_i=(0.5:nb_i-0.5)*pos(3)/nb_i;
742ind_j=(0.5:nb_j-0.5)*pos(4)/nb_j;
743[Ind_i,Ind_j]=meshgrid(ind_i,ind_j);
744CData=zeros([size(XIma) 3]);
745file_ima=double((i1_series(:,:,1)>0)');
746if numel(file_ima)>=2
747if size(file_ima,1)==1
748    CLine=interp1(ind_i,file_ima,xima,'nearest');
749    CData(:,:,2)=ones(size(yima'))*CLine;
750else
751    CData(:,:,2)=interp2(Ind_i,Ind_j,file_ima,XIma,YIma,'nearest');
752end
753set(handles.waitbar_frame,'CData',CData)
754end
755set(handles.waitbar_frame,'Units','normalized')
756
757%% enable field and veltype menus
758SeriesData=get(handles.series,'UserData');
759SeriesData.FileType{iview}=FileType;
760check_civ=0;
761check_netcdf=0;
762for iview=1:length(SeriesData.FileType)
763    switch SeriesData.FileType{iview}
764        case {'civx','civdata'}
765            check_civ=check_civ+1;
766        case 'netcdf'
767            check_netcdf=check_netcdf+1;
768    end
769end
770if check_civ
771    enable='on';
772else
773    enable='off';
774end
775set(handles.VelType,'Visible',enable)
776set(handles.VelType_text,'Visible',enable)
777if check_civ>=2
778    enable='on';
779else
780    enable='off';
781end
782set(handles.VelType_1,'Visible',enable)
783set(handles.VelType_text_1,'Visible',enable)
784if check_civ || check_netcdf
785    enable='on';
786else
787    enable='off';
788end
789set(handles.FieldName,'Visible',enable)
790set(handles.Field_text,'Visible',enable)
791if check_civ+ check_netcdf>=2
792    enable='on';
793else
794    enable='off';
795end
796set(handles.FieldName_1,'Visible',enable)
797set(handles.Field_text_1,'Visible',enable)
798FieldString={''};
799if check_civ
800    FieldString=[calc_field;{'get_field...'}];
801elseif check_netcdf
802    FieldString={'get_field...'};
803end
804set(handles.FieldName,'String',FieldString)
805FieldString={''};
806if check_civ>=2
807    FieldString=[calc_field;{'get_field...'}];
808elseif check_civ+check_netcdf>=2
809    FieldString={'get_field...'};
810end
811set(handles.FieldName_1,'String',{'get_field...'})
812
813
814%% store the series info in 'UserData'
815SeriesData.i1_series{iview}=i1_series;
816SeriesData.i2_series{iview}=i2_series;
817SeriesData.j1_series{iview}=j1_series;
818SeriesData.j2_series{iview}=j2_series;
819SeriesData.FileType{iview}=FileType;
820SeriesData.Time{iview}=time;
821set(handles.series,'UserData',SeriesData)
822
823%% check for pair display
824check_pairs=0;
825for iview=1:numel(SeriesData.i2_series)
826    if ~isempty(SeriesData.i2_series{iview})||~isempty(SeriesData.j2_series{iview})
827        check_pairs=1;
828    end
829end
830if check_pairs
831    set(handles.Pairs,'Visible','on')
832    set(handles.PairString,'Visible','on')
833else
834    set(handles.Pairs,'Visible','off')
835    set(handles.PairString,'Visible','off')
836end
837
838% %% set default options in menu 'Fields'%% TODO: check VelType
839% if ~testima
840%     testcivx=0;
841%     if isfield(UvData,'FieldsString') && isequal(UvData.FieldsString,{'get_field...'})% field menu defined as input (from get_field)
842%         set(handles_Fields,'Value',1)
843%         set(handles_Fields,'String',{'get_field...'})
844%         UvData=rmfield(UvData,'FieldsString');
845%     else
846%         Data=nc2struct(FileName,'ListGlobalAttribute','Conventions','absolut_time_T0','civ');
847%         if strcmp(Data.Conventions,'uvmat/civdata') ||( ~isempty(Data.absolut_time_T0)&& ~isequal(Data.civ,0))%if the new input is Civx
848%             FieldList=calc_field;
849%             set(handles_Fields,'String',[{'image'};FieldList;{'get_field...'}]);%standard menu for civx data
850%             set(handles_Fields,'Value',2) % set menu to 'velocity'
851%             col_vec=FieldList;
852%             col_vec(1)=[];%remove 'velocity' option for vector color (must be a scalar)
853%             testcivx=1;
854%         end
855%         if ~testcivx
856%             set(handles_Fields,'Value',1) % set menu to 'get_field...
857%             set(handles_Fields,'String',{'get_field...'})
858%             col_vec={'get_field...'};
859%         end
860%         set(handles.ColorScalar,'String',col_vec)
861%     end
862% end
863% set(handles.uvmat,'UserData',UvData)
864%
865% %% set index navigation options and refresh plots
866% scan_option='i';%default
867% state_j='off'; %default
868% if index==2
869%     if get(handles.scan_j,'Value')
870%         scan_option='j'; %keep the scan option for the second fiel series
871%     end
872%     if strcmp(get(handles.j1,'Visible'),'on')
873%         state_j='on';
874%     end
875% end
876% if ~isempty(j1_series)
877%         state_j='on';
878%         if isequal(nbfield,1) &&index==1
879%             scan_option='j'; %scan j index by default if nbfield=1               
880%         end
881% end
882% if isequal(scan_option,'i')
883%      set(handles.scan_i,'Value',1)
884%      scan_i_Callback([],[], handles);
885% else
886%      set(handles.scan_j,'Value',1)
887%      scan_j_Callback([],[], handles);
888% end
889% set(handles.scan_j,'Visible',state_j)
890% set(handles.j1,'Visible',state_j)
891% set(handles.j2,'Visible',state_j)
892% set(handles.last_j,'Visible',state_j);
893% set(handles.frame_j,'Visible',state_j);
894% set(handles.j_text,'Visible',state_j);
895% if ~isempty(i2_series)||~isempty(j2_series)
896%     set(handles.CheckFixPair,'Visible','on')
897% elseif index==1
898%     set(handles.CheckFixPair,'Visible','off')
899% end
900%
901%
902% mode_Callback(hObject, eventdata, handles)
903%
904% set(handles.REFRESH_INDICES,'BackgroundColor',[0.7 0.7 0.7])
905% InputTable=get(handles.InputTable,'Data');
906% check_lines=get(handles.REFRESH_INDICES,'UserData');
907%
908% %% check the indices and FileTypes for each series (limited to the new ones to save time)
909% for ind_list=1:length(check_lines)
910%     if  check_lines(ind_list)
911%         InputLine=InputTable(ind_list,:);
912%         detect_idem=strcmp('"',InputLine);% look for '" (repeat of previous data)
913%         detect_idem=detect_idem(detect_idem>0);
914%         if ~isempty (detect_idem)
915%             InputLine(detect_idem)=InputTable(ind_list-1,detect_idem);
916%             set(handles.InputTable,'Data',InputTable)
917%         end
918%         fileinput=fullfile_uvmat(InputLine{1},InputLine{2},InputLine{3},InputLine{5},InputLine{4},1,2,1,2);
919%         %fileinput=name_generator(fullfile(InputLine{1},InputLine{3}),1,1,InputLine{5},InputLine{4},1,2,2,InputLine{2})
920%         %update file series defined by the selected line
921%         [InputTable{ind_list,3},InputTable{(ind_list),4},errormsg]=update_indices(handles,fileinput,ind_list);
922%         if ~isempty(errormsg)
923%                 msgbox_uvmat('ERROR',errormsg)
924%                 return
925%         end
926%     end
927% end
928% set(handles.InputTable,'Data',InputTable)
929% SeriesData=get(handles.series,'UserData');
930%
931% state_j='off';
932% state_Pairs='off';
933% state_InputFields='off';
934% val=get(handles.ListView,'Value');
935% ListViewString={''};
936% if ~isempty(SeriesData)
937% %     ListViewString={};
938%     for iview=1:size(InputTable,1)
939%         if ~isempty(SeriesData.j1_series{iview})
940%             state_j='on';
941%         end
942%         if ~isempty(SeriesData.i2_series{iview})||~isempty(SeriesData.j2_series{iview})
943%             state_Pairs='on';
944%             ListViewString{iview}=num2str(iview);
945%             if check_lines(iview)
946%                 val=iview;%select the last pair if it is a new entry
947%             end
948%         end
949%         if strcmp(SeriesData.FileType{iview},'civx')||strcmp(SeriesData.FileType{iview},'civdata')
950%             state_InputFields='on';
951%         end
952%     end
953% end
954% set(handles.ListView,'Value',val)
955% set(handles.ListView,'String',ListViewString)
956% if strcmp(state_Pairs,'on')
957%     ListView_Callback(hObject,eventdata,handles)
958% end
959% set(handles.PairString,'Visible',state_Pairs)
960% enable_j(handles,state_j)
961
962%------------------------------------------------------------------------
963function num_first_i_Callback(hObject, eventdata, handles)
964%------------------------------------------------------------------------
965num_last_i_Callback(hObject, eventdata, handles)
966
967%------------------------------------------------------------------------
968function num_last_i_Callback(hObject, eventdata, handles)
969%------------------------------------------------------------------------
970SeriesData=get(handles.series,'UserData');
971if ~isfield(SeriesData,'Time')
972    SeriesData.Time{1}=[];
973end
974displ_time(handles);
975
976%------------------------------------------------------------------------
977function num_first_j_Callback(hObject, eventdata, handles)
978%------------------------------------------------------------------------
979 num_last_j_Callback(hObject, eventdata, handles)
980
981%------------------------------------------------------------------------
982function num_last_j_Callback(hObject, eventdata, handles)
983%------------------------------------------------------------------------
984first_j=str2num(get(handles.num_first_j,'String'));
985last_j=str2num(get(handles.num_last_j,'String'));
986ref_j=ceil((first_j+last_j)/2);
987set(handles.num_ref_j,'String', num2str(ref_j))
988num_ref_j_Callback(hObject, eventdata, handles)
989SeriesData=get(handles.series,'UserData');
990if ~isfield(SeriesData,'Time')
991    SeriesData.Time{1}=[];
992end
993displ_time(handles);
994
995%------------------------------------------------------------------------
996% ---- find the times corresponding to the first and last indices of a series
997function displ_time(handles)
998%------------------------------------------------------------------------
999SeriesData=get(handles.series,'UserData');%
1000ref_i=[str2num(get(handles.num_first_i,'String')) str2num(get(handles.num_last_i,'String'))];
1001ref_j=[str2num(get(handles.num_first_j,'String')) str2num(get(handles.num_last_j,'String'))];
1002% last_i=str2num(get(handles.num_last_i,'String'));
1003% last_j=str2num(get(handles.num_last_j,'String'));
1004TimeTable=get(handles.TimeTable,'Data');
1005Pairs=get(handles.PairString,'Data');
1006for iview=1:size(TimeTable,1)
1007    if size(SeriesData.Time,1)<iview
1008        break
1009    end
1010    i1=ref_i;
1011    j1=ref_j;
1012    i2=ref_i;
1013    j2=ref_j;
1014    % case of pairs
1015    if ~isempty(Pairs{iview,1})
1016        r=regexp(Pairs{iview,1},'(?<mode>(Di=)|(Dj=)) -*(?<num1>\d+)\|(?<num2>\d+)','names');
1017        if isempty(r)
1018            r=regexp(Pairs{iview,1},'(?<num1>\d+)(?<mode>-)(?<num2>\d+)','names');
1019        end
1020        switch r.mode
1021            case 'Di='  %  case 'series(Di)')
1022                i1=ref_i-str2num(r.num1);
1023                i2=ref_i+str2num(r.num2);
1024            case 'Dj='  %  case 'series(Dj)'
1025                j1=ref_j-str2num(r.num1);
1026                j2=ref_j+str2num(r.num2);
1027            case '-'  % case 'bursts'
1028                j1=str2num(r.num1)*ones(size(ref_i));
1029                j2=str2num(r.num2)*ones(size(ref_i));
1030        end
1031    end
1032    TimeTable{iview,2}=[];
1033    TimeTable{iview,3}=[];
1034    if size(SeriesData.Time{iview},1)>=i2(2)&&size(SeriesData.Time{iview},1)>=j2(2)
1035        if isempty(ref_j)
1036            time_first=(SeriesData.Time{iview}(i1(1))+SeriesData.Time{iview}(i2(1)))/2;
1037            time_last=(SeriesData.Time{iview}(i1(2))+SeriesData.Time{iview}(i2(2)))/2;
1038        else
1039            time_first=(SeriesData.Time{iview}(i1(1),j1(1))+SeriesData.Time{iview}(i2(1),j2(1)))/2;
1040            time_last=(SeriesData.Time{iview}(i1(2),j1(2))+SeriesData.Time{iview}(i2(2),j2(2)))/2;
1041        end
1042        TimeTable{iview,2}=time_first; %TODO: take into account pairs
1043        TimeTable{iview,3}=time_last; %TODO: take into account pairs
1044    end
1045end
1046set(handles.TimeTable,'Data',TimeTable)
1047
1048%------------------------------------------------------------------------
1049% --- Executes when selected cell(s) is changed in PairString.
1050function PairString_CellSelectionCallback(hObject, eventdata, handles)
1051%------------------------------------------------------------------------   
1052set(handles.ListView,'Value',eventdata.Indices(1))% detect the selected raw index
1053ListView_Callback ([],[],handles) % update the list of available pairs
1054
1055%------------------------------------------------------------------------
1056%------------------------------------------------------------------------
1057%  III - FUNCTIONS ASSOCIATED TO THE FRAME SET PAIRS
1058%------------------------------------------------------------------------
1059%------------------------------------------------------------------------
1060% --- Executes on selection change in ListView.
1061function ListView_Callback(hObject, eventdata, handles)
1062%------------------------------------------------------------------------   
1063SeriesData=get(handles.series,'UserData');
1064i2_series=[];
1065j2_series=[];
1066iview=get(handles.ListView,'Value');
1067if ~isempty(SeriesData.i2_series{iview})
1068    i2_series=SeriesData.i2_series{iview};
1069end
1070if ~isempty(SeriesData.j2_series{iview})
1071    j2_series=SeriesData.j2_series{iview};
1072end
1073update_mode(handles,SeriesData.i1_series{iview},SeriesData.i2_series{iview},...
1074    SeriesData.j1_series{iview},SeriesData.j2_series{iview},SeriesData.Time{iview})
1075
1076%------------------------------------------------------------------------
1077% --- Executes on button press in mode.
1078function mode_Callback(hObject, eventdata, handles)
1079%------------------------------------------------------------------------       
1080SeriesData=get(handles.series,'UserData');
1081iview=get(handles.ListView,'Value');
1082mode_list=get(handles.mode,'String');
1083mode=mode_list{get(handles.mode,'Value')};
1084if isequal(mode,'bursts')
1085    enable_i(handles,'On')
1086    enable_j(handles,'Off') %do not display j index scanning in burst mode (j is fixed by the burst choice)
1087else
1088    enable_i(handles,'On')
1089    enable_j(handles,'Off')
1090end
1091fill_ListPair(handles,SeriesData.i1_series{iview},SeriesData.i2_series{iview},...
1092    SeriesData.j1_series{iview},SeriesData.j2_series{iview},SeriesData.Time{iview})
1093ListPairs_Callback([],[],handles)
1094
1095%-------------------------------------------------------------
1096% --- Executes on selection in ListPairs.
1097function ListPairs_Callback(hObject,eventdata,handles)
1098%------------------------------------------------------------
1099list_pair=get(handles.ListPairs,'String');%get the menu of image pairs
1100if isempty(list_pair)
1101    string='';
1102else
1103    string=list_pair{get(handles.ListPairs,'Value')};
1104    string=regexprep(string,',.*','');%removes time indication (after ',')
1105end
1106PairString=get(handles.PairString,'Data');
1107iview=get(handles.ListView,'Value');
1108PairString{iview,1}=string;
1109% report the selected pair string to the table PairString
1110set(handles.PairString,'Data',PairString)
1111
1112%------------------------------------------------------------------------
1113function num_ref_i_Callback(hObject, eventdata, handles)
1114%------------------------------------------------------------------------
1115mode_list=get(handles.mode,'String');
1116mode=mode_list{get(handles.mode,'Value')};
1117SeriesData=get(handles.series,'UserData');
1118iview=get(handles.ListView,'Value');
1119fill_ListPair(handles,SeriesData.i1_series{iview},SeriesData.i2_series{iview},...
1120    SeriesData.j1_series{iview},SeriesData.j2_series{iview},SeriesData.Time{iview});% update the menu of pairs depending on the available netcdf files
1121ListPairs_Callback([],[],handles)
1122
1123%------------------------------------------------------------------------
1124function num_ref_j_Callback(hObject, eventdata, handles)
1125%------------------------------------------------------------------------
1126num_ref_i_Callback(hObject, eventdata, handles)
1127
1128%------------------------------------------------------------------------
1129function update_mode(handles,i1_series,i2_series,j1_series,j2_series,time)
1130%------------------------------------------------------------------------   
1131check_burst=0;
1132if isempty(j2_series)% no pair menu to display
1133    if isempty(i2_series)
1134        set(handles.mode,'String',{''})
1135    else
1136        set(handles.mode,'Value',1)
1137        set(handles.mode,'String',{'series(Di)'})
1138    end
1139else
1140    nbfield=size(j2_series,1);
1141    nbfield2=size(j2_series,2);
1142    set(handles.mode,'String',{'bursts';'series(Dj)'})
1143    if nbfield2>10 || nbfield==1
1144        set(handles.mode,'Value',2);%set mode to series(Dj) if more than 10 j values
1145    else
1146        set(handles.mode,'Value',1);
1147        check_burst=1;
1148    end
1149end
1150if check_burst
1151    enable_i(handles,'On')
1152    enable_j(handles,'Off') %do not display j index scanning in burst mode (j is fixed by the burst choice)
1153else
1154    enable_i(handles,'On')
1155    if isempty(j1_series)
1156         enable_j(handles,'Off')
1157    else
1158        enable_j(handles,'On')
1159    end
1160end
1161fill_ListPair(handles,i1_series,i2_series,j1_series,j2_series,time)
1162ListPairs_Callback([],[],handles)
1163
1164%--------------------------------------------------------------
1165% determine the menu for civ1 pairstring depending on existing netcdf files
1166% with the reference indices num_ref_i and num_ref_j
1167%----------------------------------------------------------------
1168function fill_ListPair(handles,i1_series,i2_series,j1_series,j2_series,time)
1169
1170mode_list=get(handles.mode,'String');
1171mode=mode_list{get(handles.mode,'Value')};
1172ref_i=str2num(get(handles.num_ref_i,'String'));
1173ref_j=str2num(get(handles.num_ref_j,'String'));
1174if isempty(ref_i)
1175    ref_i=1;
1176end
1177if isempty(ref_j)
1178    ref_j=1;
1179end
1180TimeUnit=get(handles.TimeUnit,'String');
1181if length(TimeUnit)>=1
1182    dtunit=['m' TimeUnit];
1183else
1184    dtunit='e-03';
1185end
1186
1187displ_pair={};
1188if strcmp(mode,'series(Di)')
1189    if isempty(i2_series)
1190        msgbox_uvmat('ERROR','no i1-i2 pair available')
1191        return
1192    end
1193    diff_i=i2_series-i1_series;
1194    min_diff=min(diff_i(diff_i>0));
1195    max_diff=max(diff_i(diff_i>0));
1196    for ipair=min_diff:max_diff
1197        if numel(diff_i(diff_i==ipair))>0
1198            pair_string=['Di= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ];
1199            if ~isempty(time)
1200                Dt=time(ref_i+ceil(ipair/2),ref_j)-time(ref_i-floor(ipair/2),ref_j);
1201                pair_string=[pair_string ', Dt=' num2str(Dt) ' ' dtunit];
1202            end
1203            displ_pair=[displ_pair;{pair_string}];
1204        end
1205    end
1206    if ~isempty(displ_pair)
1207        displ_pair=[displ_pair;{'Di=*|*'}];
1208    end
1209elseif strcmp(mode,'series(Dj)')
1210    if isempty(j2_series)
1211        msgbox_uvmat('ERROR','no j1-j2 pair available')
1212        return
1213    end
1214    diff_j=j2_series-j1_series;
1215    min_diff=min(diff_j(diff_j>0));
1216    max_diff=max(diff_j(diff_j>0));
1217    for ipair=min_diff:max_diff
1218        if numel(diff_j(diff_j==ipair))>0
1219            pair_string=['Dj= ' num2str(-floor(ipair/2)) '|' num2str(ceil(ipair/2)) ];
1220            if ~isempty(time)
1221                Dt=time(ref_i,ref_j+ceil(ipair/2))-time(ref_i,ref_j-floor(ipair/2));
1222                pair_string=[pair_string ', Dt=' num2str(Dt) ' ' dtunit];
1223            end
1224            displ_pair=[displ_pair;{pair_string}];
1225        end
1226    end
1227    if ~isempty(displ_pair)
1228        displ_pair=[displ_pair;{'Dj=*|*'}];
1229    end
1230elseif strcmp(mode,'bursts')
1231    if isempty(j2_series)
1232        msgbox_uvmat('ERROR','no j1-j2 pair available')
1233        return
1234    end
1235    diff_j=j2_series-j1_series;
1236    min_j1=min(j1_series(j1_series>0));
1237    max_j1=max(j1_series(j1_series>0));
1238    min_j2=min(j2_series(j2_series>0));
1239    max_j2=max(j2_series(j2_series>0));
1240    for pair1=min_j1:min(max_j1,min_j1+20)
1241        for pair2=min_j2:min(max_j2,min_j2+20)
1242        if numel(j1_series(j1_series==pair1))>0 && numel(j2_series(j2_series==pair2))>0
1243            displ_pair=[displ_pair;{['j= ' num2str(pair1) '-' num2str(pair2)]}];
1244        end
1245        end
1246    end
1247    if ~isempty(displ_pair)
1248        displ_pair=[displ_pair;{'j=*-*'}];
1249    end
1250end
1251
1252%% display list of pairstring
1253displ_pair_list=get(handles.ListPairs,'String');
1254NewVal=[];
1255if ~isempty(displ_pair_list)
1256Val=get(handles.ListPairs,'Value');
1257NewVal=find(strcmp(displ_pair_list{Val},displ_pair),1);% look at the previous display in the new menu displ_pï¿œir
1258end
1259if ~isempty(NewVal)
1260    set(handles.ListPairs,'Value',NewVal)
1261else
1262    set(handles.ListPairs,'Value',1)
1263end
1264set(handles.ListPairs,'String',displ_pair)
1265
1266%-------------------------------------
1267function enable_i(handles,state)
1268set(handles.i_txt,'Visible',state)
1269set(handles.num_first_i,'Visible',state)
1270set(handles.num_last_i,'Visible',state)
1271set(handles.num_incr_i,'Visible',state)
1272% set(handles.num_MaxIndex_i,'Visible',state)
1273set(handles.num_ref_i,'Visible',state)
1274set(handles.ref_i_text,'Visible',state)
1275
1276%-----------------------------------
1277function enable_j(handles,state)
1278set(handles.j_txt,'Visible',state)
1279% set(handles.num_MinIndex_j,'Visible',state)
1280set(handles.num_first_j,'Visible',state)
1281set(handles.num_last_j,'Visible',state)
1282set(handles.num_incr_j,'Visible',state)
1283% set(handles.num_MaxIndex_j,'Visible',state)
1284set(handles.num_ref_j,'Visible',state)
1285set(handles.ref_j_text,'Visible',state)
1286
1287%-----------------------------------
1288function view_FieldMenu(handles,state)
1289% set(handles.FieldName,'Visible',state)
1290% set(handles.Field_text,'Visible',state)
1291set(handles.InputFields,'Visible',state)
1292
1293%-----------------------------------
1294function view_FieldMenu_1(handles,state)
1295set(handles.FieldName_1,'Visible',state)
1296set(handles.Field_text_1,'Visible',state)
1297
1298
1299%%%%%%%%%%%%%%%%%%%%
1300%%  MAIN ActionName FUNCTIONS
1301%%%%%%%%%%%%%%%%%%%%
1302%------------------------------------------------------------------------
1303% --- Executes on button press in RUN.
1304function RUN_Callback(hObject, eventdata, handles)
1305%------------------------------------------------------------------------
1306set(handles.RUN,'BusyAction','queue');
1307set(0,'CurrentFigure',handles.series)
1308set(handles.RUN, 'Enable','Off')
1309set(handles.RUN,'BackgroundColor',[0.831 0.816 0.784])
1310drawnow
1311[h_fun,Series,filexml,errormsg]=prepare_jobs(handles);
1312if ~isempty(errormsg)
1313    msgbox_uvmat('ERROR',errormsg)
1314else
1315  %Series.Specific=h_fun(Series);   
1316   Series=h_fun(Series); 
1317   if ~isempty(filexml)
1318   t=struct2xml(Series);
1319    t=set(t,1,'name','Series');
1320    save(t,filexml);
1321   end
1322%     h_fun(Series);
1323end
1324set(handles.RUN, 'Enable','On')
1325set(handles.RUN,'BackgroundColor',[1 0 0])
1326
1327%------------------------------------------------------------------------
1328function STOP_Callback(hObject, eventdata, handles)
1329%------------------------------------------------------------------------
1330set(handles.RUN, 'BusyAction','cancel')
1331set(handles.RUN,'BackgroundColor',[1 0 0])
1332set(handles.RUN,'enable','on')
1333set(handles.BATCH,'BackgroundColor',[1 0 0])
1334set(handles.BATCH,'enable','on')
1335
1336%------------------------------------------------------------------------
1337% --- Executes on button press in BATCH.
1338function BATCH_Callback(hObject, eventdata, handles)
1339%------------------------------------------------------------------------   
1340set(handles.BATCH, 'Enable','Off')
1341set(handles.BATCH,'BackgroundColor',[0.831 0.816 0.784])
1342[h_fun,Series,filexml,errormsg]=prepare_jobs(handles);
1343if ~isempty(errormsg)
1344    msgbox_uvmat('ERROR',errormsg)
1345    return
1346end
1347% update the xml file after interactive input with the function
1348Series.Specific='?';
1349Series=h_fun(Series);   
1350t=struct2xml(Series);
1351t=set(t,1,'name','Series');
1352save(t,filexml);
1353path_series=fileparts(which('series'));
1354filename_xml=fullfile(Series.OutputDir,[Series.OutputRootFile '.xml']);
1355filename_bat=fullfile(Series.OutputDir,[Series.OutputRootFile '.bat']);
1356[fid,message]=fopen(filename_bat,'w');
1357if isequal(fid,-1)
1358    msgbox_uvmat('ERROR', ['creation of .bat file: ' message]);
1359    return
1360end
1361path_fct=get(handles.ActionPath,'String');
1362text_matlabscript=[...
1363    '#!/bin/bash \n'...
1364    '. /etc/sysprofile \n'...
1365    'matlab -nodisplay -nosplash -nojvm <<END_MATLAB \n'...
1366    'cd(''' path_series '''); \n'...
1367    'addpath(''' path_fct '''); \n'...
1368    '' Series.Action  '( ''' filename_xml '''); \n'...
1369    'exit \n'...
1370    'END_MATLAB \n'];
1371fprintf(fid,text_matlabscript);
1372fclose(fid);
1373if isunix
1374    system(['chmod +x ' filename_bat]);% set the file to executable
1375    system(['. ' filename_bat ' &']);%execute fct
1376else
1377    system(filename_bat);
1378end
1379set(handles.BATCH, 'Enable','On')
1380set(handles.BATCH,'BackgroundColor',[1 0 0])
1381
1382%------------------------------------------------------------------------
1383% --- Executes on button press in BIN.
1384function BIN_Callback(hObject, eventdata, handles)
1385%------------------------------------------------------------------------
1386    cmd=['#!/bin/bash \n '...
1387        '#$ -cwd \n '...
1388        'hostname && date \n '...
1389        'umask 002 \n'...
1390        Param.xml.CivmBin ' ' Param.xml.RunTime ' ' filename_xml ' ' OutputFile '.nc'];
1391   
1392%------------------------------------------------------------------------
1393% --- Main launch command, called by RUN and BATCH
1394function [h_fun,Series,filexml,errormsg]=prepare_jobs(handles,run)
1395%------------------------------------------------------------------------
1396h_fun=[];
1397filexml='';
1398errormsg='';
1399if ~exist('run','var')
1400    run=1;
1401end
1402%% Read parameters from series
1403Series=read_GUI(handles.series);
1404if isfield(Series,'Pairs')
1405Series=rmfield(Series,'Pairs'); %info Pairs not needed for output
1406end
1407
1408%% read index ranges
1409first_i=1;
1410last_i=1;
1411incr_i=1;
1412first_j=1;
1413last_j=1;
1414incr_j=1;
1415if isfield(Series.IndexRange,'first_i')
1416    first_i=Series.IndexRange.first_i;
1417    incr_i=Series.IndexRange.incr_i;
1418    last_i=Series.IndexRange.last_i;
1419end
1420if isfield(Series.IndexRange,'first_j')
1421    first_j=Series.IndexRange.first_j;
1422    incr_j=Series.IndexRange.incr_j;
1423    last_j=Series.IndexRange.last_j;
1424end
1425
1426%% read input file parameters and set menus
1427menu_coord_state=get(handles.TransformName,'Visible');
1428if isequal(menu_coord_state,'on')
1429    menu_index=get(handles.TransformName,'Value');
1430    transform_list=get(handles.TransformName,'UserData');
1431    Series.FieldTransform.TransformHandle=transform_list{menu_index};% transform function handles
1432end
1433
1434if last_i < first_i | last_j < first_j , msgbox_uvmat('ERROR','last field number must be larger than the first one'),...
1435    set(handles.RUN, 'Enable','On'), set(handles.RUN,'BackgroundColor',[1 0 0]),return,end;
1436
1437%% projection object
1438if isfield(Series,'CheckObject')
1439    if Series.CheckObject
1440        hset_object=findobj(allchild(0),'tag','set_object');
1441        Series.ProjObject=read_GUI(hset_object);
1442        CheckObject_Callback([], [], handles)
1443    end
1444else
1445    Series.CheckObject=0;
1446end
1447
1448%% get_field GUI
1449if isfield(Series,'InputFields')&&isfield(Series.InputFields,'Field')
1450    if strcmp(Series.InputFields.Field,'get_field...')
1451        hget_field=findobj(allchild(0),'name','get_field');
1452        Series.GetField=read_GUI(hget_field);
1453    end
1454end
1455
1456if ~run
1457    return
1458end
1459
1460%% defining the ActionName function handle
1461list_action=get(handles.ActionName,'String');% list menu action
1462index=get(handles.ActionName,'Value');
1463action= list_action{index}; % selected string
1464%Series.Action=action;%name of the processing programme
1465Series.hseries=handles.series; % handles to the series GUI
1466path_series=which('series');
1467list_path=get(handles.ActionName,'UserData');
1468fct_path=list_path{index}; %path stored for the function ACTION
1469if ~isequal(fct_path,path_series)
1470    eval(['spath=which(''' action ''');']) %spath = current path of the selected function ACTION
1471    if ~exist(fct_path,'dir')
1472        errormsg=['The prescribed function path ' fct_path ' does not exist'];
1473        return
1474    end
1475    if ~isequal(spath,fct_path)
1476        addpath(fct_path)% add the prescribed path if not the current one
1477    end
1478end
1479eval(['h_fun=@' action ';'])%create a function handle for ACTION
1480if ~isequal(fct_path,path_series)
1481        rmpath(fct_path)% add the prescribed path if not the current one   
1482end
1483
1484%% create the output data directory and write in it the xml file from the GUI config
1485%determine the root file corresponding to the first sub dir
1486if isfield(Series,'OutputSubDir')
1487    SubDirOut=[Series.OutputSubDir Series.OutputDirExt];
1488    SubDirOutNew=SubDirOut;
1489    iview=1;
1490    SeriesData=get(handles.series,'UserData');
1491    if size(Series.InputTable,1)>1 && isfield(SeriesData,'AllowInputSort') && isfield(SeriesData.AllowInputSort)
1492        [tild,iview]=sort(Series.InputTable(:,2)); %subdirectories sorted in alphabetical order
1493        Series.InputTable=Series.InputTable(iview,:);
1494    end
1495    detect=exist(fullfile(Series.InputTable{1,1},SubDirOutNew),'dir');% test if  the dir  already exist
1496    check_create=1; %need to create the result directory by default
1497    while detect
1498        answer=msgbox_uvmat('INPUT_Y-N',['use existing ouput directory: ' fullfile(Series.InputTable{1,1},SubDirOutNew) ', possibly delete previous data']);
1499        if isequal(answer,'Yes')
1500            detect=0;
1501            check_create=0;
1502        else
1503            r=regexp(SubDirOutNew,'(?<root>.*\D)(?<num1>\d+)$','names');%detect whether name ends by a number
1504            if isempty(r)
1505                r(1).root=[SubDirOutNew '_'];
1506                r(1).num1='0';
1507            end
1508            SubDirOutNew=[r(1).root num2str(str2num(r(1).num1)+1)];%increment the index by 1 or put 1
1509            detect=exist(fullfile(Series.InputTable{1,1},SubDirOutNew),'dir');% test if  the dir  already exists   
1510            check_create=1;
1511        end
1512    end
1513    Series.OutputDirExt=regexprep(SubDirOutNew,Series.OutputSubDir,'');
1514    Series.OutputSubDir=SubDirOutNew;
1515    Series.OutputDir=fullfile(Series.InputTable{1,1},Series.OutputSubDir);%directory set for output results
1516    Series.OutputRootFile=Series.InputTable{1,3};% the first sorted RootFile taken for output
1517    set(handles.OutputDirExt,'String',Series.OutputDirExt)
1518    %removes redondant information
1519    Series=rmfield(Series,'OutputDirExt');
1520    Series.IndexRange=rmfield(Series.IndexRange,'TimeTable');
1521    Series.IndexRange=rmfield(Series.IndexRange,'MinIndex');
1522    Series.IndexRange=rmfield(Series.IndexRange,'MaxIndex');
1523    % create output directory
1524    if check_create
1525        [tild,msg1]=mkdir(Series.OutputDir);
1526        if ~strcmp(msg1,'')
1527            errormsg=['cannot create ' Series.OutputDir ': ' msg1];%error message for directory creation
1528            return
1529        end
1530    end
1531    filexml=fullfile(Series.OutputDir,[Series.InputTable{1,3} '.xml']);% name of the parameter xml file set in this directory
1532%     t=struct2xml(Series);
1533%     t=set(t,1,'name','Series');
1534%     save(t,filexml);
1535end
1536
1537%------------------------------------------------------------------------
1538% --- Executes on selection change in ActionName.
1539function ActionName_Callback(hObject, eventdata, handles)
1540%------------------------------------------------------------------------
1541global nb_builtin_ACTION
1542list_ACTION=get(handles.ActionName,'String');% list menu fields
1543index_ACTION=get(handles.ActionName,'Value');% selected string index
1544ACTION= list_ACTION{index_ACTION}; % selected function name
1545path_series=which('series');%path to series.m
1546list_path=get(handles.ActionName,'UserData');%list of recorded paths to functions of the list ACTION
1547default_file=fullfile(list_path{end},ACTION);
1548% add a new function to the menu if the selected item is 'more...'
1549if isequal(ACTION,'more...')
1550    pathfct=fileparts(path_series);
1551    [FileName, PathName, filterindex] = uigetfile( ...
1552       {'*.m', ' (*.m)';
1553        '*.m',  '.m files '; ...
1554        '*.*', 'All Files (*.*)'}, ...
1555        'Pick a file',default_file);
1556    if length(FileName)<2
1557        return
1558    end
1559    [pp,ACTION,ext_fct]=fileparts(FileName);%(end-1:end);
1560    if ~isequal(ext_fct,'.m')
1561        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
1562        return
1563    end
1564   
1565   % insert the choice in the actionname menu
1566   menu_str=update_menu(handles.ActionName,ACTION);%new action menu in which the new item has been appended if needed
1567   index_ACTION=get(handles.ActionName,'Value');% currently selected index in the list
1568   list_path{index_ACTION}=PathName;
1569   if length(menu_str)>nb_builtin_ACTION+5; %nb_builtin=nbre of functions always remaining in the initial menu
1570       nbremove=length(menu_str)-nb_builtin_ACTION-5;
1571       menu_str(nb_builtin_ACTION+1:end-5)=[];
1572       list_path(nb_builtin_ACTION+1:end-4)=[];
1573       index_ACTION=index_ACTION-nbremove;
1574       set(handles.ActionName,'Value',index_ACTION)
1575       set(handles.ActionName,'String',menu_str)
1576   end
1577   list_path{index_ACTION}=PathName;
1578   set(handles.ActionName,'UserData',list_path);
1579   set(handles.ActionPath,'enable','inactive')% indicate that the current path is accessible (not 'off')
1580   
1581   %record the current menu in personal file profil_perso
1582   dir_perso=prefdir;
1583   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1584   for ilist=nb_builtin_ACTION+1:length(menu_str)-1
1585       series_fct{ilist-nb_builtin_ACTION}=fullfile(list_path{ilist},[menu_str{ilist} '.m']);     
1586   end
1587   if nb_builtin_ACTION+1<=length(menu_str)-1
1588       if exist(profil_perso,'file')% && nb_builtin_ACTION+1>=length(menu_str)-1
1589           save(profil_perso,'series_fct','-append')
1590       else
1591           txt=ver('MATLAB');
1592           Release=txt.Release;
1593           relnumb=str2num(Release(3:4));
1594           if relnumb >= 14%recent relaese of Matlab
1595               save(profil_perso,'series_fct','-V6')
1596           else
1597               save(profil_perso, 'series_fct')
1598           end
1599       end
1600   end
1601end
1602
1603%check the current ActionPath to the selected function
1604PathName=list_path{index_ACTION};%current recorded path
1605set(handles.ActionPath,'String',PathName); %show the path to the senlected function
1606
1607%default setting for the visibility of the GUI elements
1608set(handles.num_NbSlice,'Visible','off')
1609set(handles.NbSlice_title,'Visible','off')
1610set(handles.VelType,'Visible','off');
1611set(handles.VelType_text,'Visible','off');
1612set(handles.VelType_1,'Visible','off');
1613set(handles.VelType_text_1,'Visible','off');
1614view_FieldMenu(handles,'off')
1615view_FieldMenu_1(handles,'off')
1616set(handles.FieldTransform,'Visible','off')
1617set(handles.CheckObject,'Visible','off');
1618set(handles.ProjObject,'Visible','off');
1619set(handles.CheckMask,'Visible','off')
1620set(handles.Mask,'Visible','off')
1621% set(handles.OutputDirExt,'Visible','off');
1622% set(handles.ParamKey,'Visible','off')
1623% set(handles.ParamVal,'Visible','off')
1624ParamKey={};
1625set(handles.FieldName,'Enable','off')
1626set(handles.VelType,'Enable','off')
1627set(handles.FieldName_1,'Enable','off')
1628set(handles.VelType_1,'Enable','off')
1629set(handles.TransformName,'Enable','off')
1630set(handles.OutputDirExt,'Visible','off')
1631set(handles.OutputSubDir,'Visible','off')
1632set(handles.OutputDir_title,'Visible','off')
1633%set the displayed GUI item needed for input parameters
1634if ~isequal(path_series,PathName)
1635    addpath(PathName)
1636end
1637eval(['h_function=@' ACTION ';']);
1638try
1639    [fid,errormsg] =fopen([ACTION '.m']);
1640    InputText=textscan(fid,'%s',1,'delimiter','\n');
1641    fclose(fid)
1642    set(handles.ActionName,'ToolTipString',InputText{1}{1})% put the first line of the selected function as tooltip help
1643end
1644if ~isequal(path_series,PathName)
1645    rmpath(PathName)
1646end
1647varargout=h_function();
1648Param_list={};
1649
1650InputTable=get(handles.InputTable,'Data');
1651nb_series=size(InputTable,1);
1652testima_series=1; %test for a list of images only
1653testima=1;
1654testima_1=1;
1655testciv_series=1;
1656for iview=1:nb_series
1657     ext=InputTable{iview,5};
1658    if length(ext)<2
1659        ext='.none';
1660    end
1661    testimaview=~isempty(imformats(ext(2:end))) || isequal(lower(ext),'.avi');
1662    if ~testimaview
1663        if iview==1
1664            testima=0;
1665        end
1666        if iview==2
1667            testima_1=0;
1668        end
1669        testima_series=0;
1670    end
1671end
1672for ilist=1:length(varargout)-1
1673    switch varargout{ilist}
1674        case 'NbViewMax'
1675            if ~isempty (varargout{ilist+1})
1676                if size(InputTable,1)>varargout{ilist+1}
1677                InputTable=InputTable(1:varargout{ilist+1},:);
1678                set(handles.InputTable,'Data',InputTable)
1679                end
1680            end
1681        case 'AllowInputSort'
1682            if isequal(lower(varargout{ilist+1}),'on')% sort the input table by alphabetical order of the SubDir
1683                SeriesData=get(handles.series,'UserData');
1684                SeriesData.AllowInputSort=1;
1685                set(handles.series,'UserData',SeriesData)
1686            end                     
1687        case 'WholeIndexRange'
1688            if isequal(lower(varargout{ilist+1}),'on')% sort the input table by alphabetical order of the SubDir
1689                MinIndex=get(handles.MinIndex,'Data');
1690                MaxIndex=get(handles.MaxIndex,'Data');
1691                if ~isempty(MinIndex)
1692                    set(handles.num_first_i,'String',num2str(MinIndex{1}))
1693                    set(handles.num_last_i,'String',num2str(MaxIndex{1}))
1694                    set(handles.num_incr_i,'String','1')
1695                    if size(MinIndex,2)>=2
1696                        set(handles.num_first_j,'String',num2str(MinIndex{1,2}))
1697                        set(handles.num_last_j,'String',num2str(MaxIndex{1,2}))
1698                        set(handles.num_incr_j,'String','1')
1699                    end
1700                end
1701            end           
1702        case 'NbSlice'   %hidden by default
1703            if isequal(lower(varargout{ilist+1}),'on')
1704                set(handles.num_NbSlice,'Visible','on')
1705                set(handles.NbSlice_title,'Visible','on')
1706            end
1707        case 'VelType'   %hidden by default
1708             if isequal(lower(varargout{ilist+1}),'one') || isequal(lower(varargout{ilist+1}),'two')
1709                set(handles.VelType,'Enable','on')
1710                if nb_series >=1 && ~testima_series
1711                    set(handles.VelType,'Visible','on')
1712                    set(handles.VelType_text,'Visible','on');
1713                end
1714             end
1715            if isequal(lower(varargout{ilist+1}),'two')
1716                set(handles.VelType_1,'Enable','on')
1717                if nb_series >=2 && ~testima_series
1718                    set(handles.VelType_1,'Visible','on')
1719                    set(handles.VelType_text_1,'Visible','on');
1720                end
1721            end
1722        case 'FieldName'   %hidden by default
1723            if isequal(lower(varargout{ilist+1}),'one')||isequal(lower(varargout{ilist+1}),'two')
1724                set(handles.FieldName,'Enable','on') % test for MenuBorser
1725                if nb_series >=1 && ~testima_series
1726                    view_FieldMenu(handles,'on')
1727                end
1728            end
1729            if isequal(lower(varargout{ilist+1}),'two')
1730                set(handles.FieldName_1,'Enable','on')
1731                if nb_series >=2 && ~testima_1
1732                    view_FieldMenu_1(handles,'on')
1733                end
1734            end
1735        case 'FieldTransform'   %hidden by default
1736            if isequal(lower(varargout{ilist+1}),'on')
1737                set(handles.TransformName,'Enable','on')
1738                set(handles.FieldTransform,'Visible','on')
1739            end
1740        case 'ProjObject'   %hidden by default
1741            if isequal(lower(varargout{ilist+1}),'on')   
1742                set(handles.CheckObject,'Visible','on')
1743                set(handles.ProjObject,'Visible','on')
1744            end
1745        case 'Mask'   %hidden by default
1746            if isequal(lower(varargout{ilist+1}),'on')   
1747                set(handles.Mask,'Visible','on')
1748                 set(handles.CheckMask,'Visible','on');
1749            end
1750        case 'PARAMETER'  % NOT USED
1751            set(handles.PARAMETERS_frame,'Visible','on')
1752            set(handles.PARAMETERS_title,'Visible','on')
1753            set(handles.ParamKey,'Visible','on')
1754            %set(handles.ParamVal,'Visible','on')
1755            Param_str=varargout{ilist+1};
1756            Param_list=[Param_list; {Param_str}];   
1757        case 'OutputDirExt'
1758            if ~isempty(varargout{ilist+1})
1759            set(handles.OutputDirExt,'String',varargout{ilist+1})
1760            set(handles.OutputDirExt,'Visible','on')
1761            set(handles.OutputSubDir,'Visible','on')
1762            set(handles.OutputDir_title,'Visible','on') 
1763            end
1764    end
1765end
1766if ~isempty(Param_list)
1767    set(handles.ParamKey,'String',Param_list)
1768    set(handles.ParamVal,'Visible','on')
1769end
1770
1771%------------------------------------------------------------------------
1772% --- Executes on selection change in FieldName.
1773function FieldName_Callback(hObject, eventdata, handles)
1774%------------------------------------------------------------------------
1775field_str=get(handles.FieldName,'String');
1776field_index=get(handles.FieldName,'Value');
1777field=field_str{field_index(1)};
1778if isequal(field,'get_field...')   
1779     hget_field=findobj(allchild(0),'name','get_field');
1780     if ~isempty(hget_field)
1781         delete(hget_field)%delete opened versions of get_field
1782     end
1783     filecell=get_file_series(read_GUI(handles.series));
1784     if exist(filecell{1,1},'file')
1785        get_field(filecell{1,1})
1786     end
1787elseif isequal(field,'more...')
1788    str=calc_field;
1789    [ind_answer,v] = listdlg('PromptString','Select a file:',...
1790                'SelectionMode','single',...
1791                'ListString',str);
1792       % edit the choice in the fields and actionname menu
1793     scalar=cell2mat(str(ind_answer));
1794     update_menu(handles.FieldName,scalar)
1795end
1796
1797%------------------------------------------------------------------------
1798% --- Executes on selection change in FieldName_1.
1799function FieldName_1_Callback(hObject, eventdata, handles)
1800%------------------------------------------------------------------------
1801field_str=get(handles.FieldName_1,'String');
1802field_index=get(handles.FieldName_1,'Value');
1803field=field_str{field_index};
1804if isequal(field,'get_field...')   
1805     hget_field=findobj(allchild(0),'name','get_field_1');
1806     if ~isempty(hget_field)
1807         delete(hget_field)
1808     end
1809     SeriesData=get(handles.series,'UserData');
1810     filename=SeriesData.CurrentInputFile_1;
1811     if exist(filename,'file')
1812        hget_field=get_field(filename);
1813        set(hget_field,'name','get_field_1')
1814     end
1815elseif isequal(field,'more...')
1816    str=calc_field;
1817    [ind_answer,v] = listdlg('PromptString','Select a file:',...
1818                'SelectionMode','single',...
1819                'ListString',str);
1820       % edit the choice in the fields and actionname menu
1821     scalar=cell2mat(str(ind_answer));
1822     update_menu(handles.FieldName_1,scalar)
1823end   
1824
1825
1826%%%%%%%%%%%%%
1827function [ind_remove]=find_pairs(dirpair,ind_i,last_i)
1828indsel=ind_i;
1829indiff=diff(ind_i); %test index increment to detect multiplets (several pairs with the same index ind_i) and holes in the series
1830indiff=[1 indiff last_i-ind_i(end)+1];%for testing gaps with the imposed bounds
1831if ~isempty(indiff)
1832    indiff2=diff(indiff);
1833    indiffp=[indiff2 1];
1834    indiffm=[1 indiff2];
1835    ind_multi_m=find((indiff==0)&(indiffm<0))-1;%indices of first members of multiplets
1836    ind_multi_p=find((indiff==0)&(indiffp>0));%indices of last members of multiplets
1837    %for each multiplet, select the most recent file
1838    ind_remove=[];
1839    for i=1:length(ind_multi_m)
1840        ind_pairs=ind_multi_m(i):ind_multi_p(i);
1841        for imulti=1:length(ind_pairs)
1842            datepair(imulti)=datenum(dirpair(ind_pairs(imulti)).date);%dates of creation
1843        end
1844        [datenew,indsort2]=sort(datepair); %sort the multiplet by creation date
1845        ind_s=indsort2(1:end-1);%
1846        ind_remove=[ind_remove ind_pairs(ind_s)];%remove these indices, leave the last one
1847    end
1848end
1849
1850%------------------------------------------------------------------------
1851% --- determine the list of index pairstring of processing file
1852function [num_i1,num_i2,num_j1,num_j2,num_i_out,num_j_out]=find_file_indices(num_i,num_j,ind_shift,NomType,mode)
1853%------------------------------------------------------------------------
1854num_i1=num_i;% set of first image numbers by default
1855num_i2=num_i;
1856num_j1=num_j;
1857num_j2=num_j;
1858num_i_out=num_i;
1859num_j_out=num_j;
1860% if isequal (NomType,'_1-2_1') || isequal (NomType,'_1-2')
1861if isequal(mode,'series(Di)')
1862    num_i1_line=num_i+ind_shift(3);% set of first image numbers
1863    num_i2_line=num_i+ind_shift(4);
1864    % adjust the first and last field number
1865        indsel=find(num_i1_line >= 1);
1866    num_i_out=num_i(indsel);
1867    num_i1_line=num_i1_line(indsel);
1868    num_i2_line=num_i2_line(indsel);
1869    num_j1=meshgrid(num_j,ones(size(num_i1_line)));
1870    num_j2=meshgrid(num_j,ones(size(num_i1_line)));
1871    [xx,num_i1]=meshgrid(num_j,num_i1_line);
1872    [xx,num_i2]=meshgrid(num_j,num_i2_line);
1873elseif isequal (mode,'series(Dj)')||isequal (mode,'bursts')
1874    if isequal(mode,'bursts') %case of bursts (png_old or png_2D)
1875        num_j1=ind_shift(1)*ones(size(num_i));
1876        num_j2=ind_shift(2)*ones(size(num_i));
1877    else
1878        num_j1_col=num_j+ind_shift(1);% set of first image numbers
1879        num_j2_col=num_j+ind_shift(2);
1880        % adjust the first field number
1881        indsel=find((num_j1_col >= 1));   
1882        num_j_out=num_j(indsel);
1883        num_j1_col=num_j1_col(indsel);
1884        num_j2_col=num_j2_col(indsel);
1885        [num_i1,num_j1]=meshgrid(num_i,num_j1_col);
1886        [num_i2,num_j2]=meshgrid(num_i,num_j2_col);
1887    end   
1888end
1889
1890%------------------------------------------------------------------------
1891% --- Executes on button press in CheckObject.
1892function CheckObject_Callback(hObject, eventdata, handles)
1893%------------------------------------------------------------------------
1894% SeriesData=get(handles.series,'UserData');
1895value=get(handles.CheckObject,'Value');
1896if value
1897     set(handles.CheckObject,'BackgroundColor',[1 1 0])%put unactivated buttons to yellow
1898     hset_object=findobj(allchild(0),'tag','set_object');%find the set_object interface handle
1899     if ishandle(hset_object)
1900         uistack(hset_object,'top')% show the GUI set_object if opened
1901     else
1902         %get the object file
1903         InputTable=get(handles.InputTable,'Data');
1904         defaultname=InputTable{1,1};
1905         if isempty(defaultname)
1906            defaultname={''};
1907         end
1908        [FileName, PathName, filterindex] = uigetfile( ...
1909       {'*.xml;*.mat', ' (*.xml,*.mat)';
1910       '*.xml',  '.xml files '; ...
1911        '*.mat',  '.mat matlab files '}, ...
1912        'Pick an xml object file (or use uvmat to create it)',defaultname);
1913        fileinput=[PathName FileName];%complete file name
1914        sizf=size(fileinput);
1915        if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end
1916        %read the file
1917        data=xml2struct(fileinput);
1918        if ~isfield(data,'Type')
1919             msgbox_uvmat('ERROR',[fileinput ' is not an object xml file'])
1920             return
1921        end
1922        if ~isfield(data,'ProjMode')
1923             data.ProjMode='none';
1924        end
1925        hset_object=set_object(data);% call the set_object interface
1926     end
1927     Object=read_GUI(hset_object);
1928     set(handles.ProjObject,'String',Object.Name);%display the object name
1929else
1930    set(handles.CheckObject,'BackgroundColor',[0.7 0.7 0.7])%put activated buttons to green
1931end
1932%set(handles.series,'UserData',SeriesData)
1933
1934%--------------------------------------------------------------
1935function CheckMask_Callback(hObject, eventdata, handles)
1936value=get(handles.CheckMask,'Value');
1937if value
1938    msgbox_uvmat('ERROR','not implemented yet')
1939end
1940%--------------------------------------------------------------
1941
1942%-------------------------------------------------------------------
1943%'uv_ncbrowser': interactively calls the netcdf file browser 'get_field.m'
1944function ncbrowser_uvmat(hObject, eventdata)
1945%-------------------------------------------------------------------
1946     bla=get(gcbo,'String');
1947     ind=get(gcbo,'Value');
1948     filename=cell2mat(bla(ind));
1949      blank=find(filename==' ');
1950      filename=filename(1:blank-1);
1951     get_field(filename)
1952
1953% ------------------------------------------------------------------
1954function MenuHelp_Callback(hObject, eventdata, handles)
1955%-------------------------------------------------------------------
1956path_to_uvmat=which ('uvmat');% check the path of uvmat
1957pathelp=fileparts(path_to_uvmat);
1958helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
1959if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package')
1960else
1961    addpath (fullfile(pathelp,'uvmat_doc'))
1962    web([helpfile '#series'])
1963end
1964
1965%-------------------------------------------------------------------
1966% --- Executes on selection change in TransformName.
1967function TransformName_Callback(hObject, eventdata, handles)
1968%-------------------------------------------------------------------
1969global nb_transform
1970
1971menu=get(handles.TransformName,'String');
1972ind_coord=get(handles.TransformName,'Value');
1973coord_option=menu{ind_coord};
1974list_transform=get(handles.TransformName,'UserData');
1975ff=functions(list_transform{end});
1976if isequal(coord_option,'more...');
1977    coord_fct='';
1978    prompt = {'Enter the name of the transform function'};
1979    dlg_title = 'user defined transform';
1980    num_lines= 1;
1981    [FileName, PathName, filterindex] = uigetfile( ...
1982       {'*.m', ' (*.m)';
1983        '*.m',  '.m files '; ...
1984        '*.*', 'All Files (*.*)'}, ...
1985        'Pick a file', ff.file);
1986    if isequal(PathName(end),'/')||isequal(PathName(end),'\')
1987        PathName(end)=[];
1988    end
1989    transform_selected =fullfile(PathName,FileName);
1990    if ~exist(transform_selected,'file')
1991          return
1992    end
1993    [ppp,transform,xt_fct]=fileparts(FileName);% removes extension .m
1994    if ~isequal(ext_fct,'.m')
1995        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
1996        return
1997    end
1998   menu=update_menu(handles.TransformName,transform);%add the selected fct to the menu
1999   ind_coord=get(handles.TransformName,'Value');
2000   addpath(PathName)
2001   list_transform{ind_coord}=str2func(transform);% create the function handle corresponding to the newly seleced function
2002   set(handles.TransformName,'UserData',list_transform)
2003   rmpath(PathName)
2004   % save the new menu in the personal file 'uvmat_perso.mat'
2005   dir_perso=prefdir;%personal Matalb directory
2006   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
2007   if exist(profil_perso,'file')
2008       for ilist=nb_transform+1:numel(list_transform)
2009           ff=functions(list_transform{ilist});
2010           transform_fct{ilist-nb_transform}=ff.file;
2011       end
2012        save (profil_perso,'transform_fct','-append'); %store the root name for future opening of uvmat
2013   end
2014end
2015
2016%check the current ActionPath to the selected function
2017if ~isempty(list_transform{ind_coord})
2018func=functions(list_transform{ind_coord});
2019set(handles.TransformPath,'String',fileparts(func.file)); %show the path to the senlected function
2020else
2021   set(handles.TransformPath,'String',''); %show the path to the senlected function
2022end
2023
2024% %------------------------------------------------------------------------
2025% % --- Executes on button press in REFRESH_INDICES.
2026%     function REFRESH_INDICES_Callback(hObject, eventdata, handles)
2027% %------------------------------------------------------------------------       
2028% % hObject    handle to REFRESH_INDICES (see GCBO)
2029% % eventdata  reserved - to be defined in a future version of MATLAB
2030% % handles    structure with handles and user data (see GUIDATA)
2031% set(handles.REFRESH_INDICES,'BackgroundColor',[0.7 0.7 0.7])
2032% InputTable=get(handles.InputTable,'Data');
2033% check_lines=get(handles.REFRESH_INDICES,'UserData');
2034%
2035% %% check the indices and FileTypes for each series (limited to the new ones to save time)
2036% for ind_list=1:length(check_lines)
2037%     if  check_lines(ind_list)
2038%         InputLine=InputTable(ind_list,:);
2039%         detect_idem=strcmp('"',InputLine);% look for '" (repeat of previous data)
2040%         detect_idem=detect_idem(detect_idem>0);
2041%         if ~isempty (detect_idem)
2042%             InputLine(detect_idem)=InputTable(ind_list-1,detect_idem);
2043%             set(handles.InputTable,'Data',InputTable)
2044%         end
2045%         fileinput=fullfile_uvmat(InputLine{1},InputLine{2},InputLine{3},InputLine{5},InputLine{4},1,2,1,2);
2046%         %fileinput=name_generator(fullfile(InputLine{1},InputLine{3}),1,1,InputLine{5},InputLine{4},1,2,2,InputLine{2})
2047%         %update file series defined by the selected line
2048%         [InputTable{ind_list,3},InputTable{(ind_list),4},errormsg]=update_indices(handles,fileinput,ind_list);
2049%         if ~isempty(errormsg)
2050%                 msgbox_uvmat('ERROR',errormsg)
2051%                 return
2052%         end
2053%     end
2054% end
2055% set(handles.InputTable,'Data',InputTable)
2056% SeriesData=get(handles.series,'UserData');
2057%
2058% state_j='off';
2059% state_Pairs='off';
2060% state_InputFields='off';
2061% val=get(handles.ListView,'Value');
2062% ListViewString={''};
2063% if ~isempty(SeriesData)
2064% %     ListViewString={};
2065%     for iview=1:size(InputTable,1)
2066%         if ~isempty(SeriesData.j1_series{iview})
2067%             state_j='on';
2068%         end
2069%         if ~isempty(SeriesData.i2_series{iview})||~isempty(SeriesData.j2_series{iview})
2070%             state_Pairs='on';
2071%             ListViewString{iview}=num2str(iview);
2072%             if check_lines(iview)
2073%                 val=iview;%select the last pair if it is a new entry
2074%             end
2075%         end
2076%         if strcmp(SeriesData.FileType{iview},'civx')||strcmp(SeriesData.FileType{iview},'civdata')
2077%             state_InputFields='on';
2078%         end
2079%     end
2080% end
2081% set(handles.ListView,'Value',val)
2082% set(handles.ListView,'String',ListViewString)
2083% if strcmp(state_Pairs,'on')
2084%     ListView_Callback(hObject,eventdata,handles)
2085% end
2086% set(handles.PairString,'Visible',state_Pairs)
2087% enable_j(handles,state_j)
2088% set(handles.REFRESH_INDICES,'BackgroundColor',[1 0 0])
2089% set(handles.REFRESH_INDICES,'visible','off')
2090
2091% -----------------------------------------------------------------------
2092% --- Update min and max indices of a file series by scanning with find_file_series
2093% --- which also changes the root file and NomType in case of movie. Also adjust the string representation of indices (e.g;
2094% --- 1 or 001 by the function find_file_series
2095% --- This function also dispaly the set of availbale files in the series
2096% --- and the menus appropriate to the file type as well as timing possibly set
2097% --- by an xml image documentation file
2098function [RootFile,NomType,errormsg]=update_indices(handles,fileinput,iview)
2099% -----------------------------------------------------------------------
2100%% look for min and max indices existing in the file series and update SeriesData
2101errormsg='';
2102[FilePath,FileName,FileExt]=fileparts(fileinput);
2103% detect the file type, get the movie object if relevant, and look for the corresponding file series:
2104% the root name and indices may be corrected by including the first index i1 if a corresponding xml file exists
2105[RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,NomType,FileType,Object,i1,i2,j1,j2]=find_file_series(FilePath,[FileName FileExt]);
2106if isempty(RootFile)&&isempty(i1_series)
2107    errormsg='no input file in the series';
2108    return
2109end
2110
2111%% adjust the min and max indices common to all the file series
2112MinIndex=get(handles.MinIndex,'Data');
2113MaxIndex=get(handles.MaxIndex,'Data');
2114MinIndex_i=min(i1_series(i1_series>0));
2115if ~isempty(i2_series)
2116    MaxIndex_i=max(i2_series(i2_series>0));
2117else
2118    MaxIndex_i=max(i1_series(i1_series>0));
2119end
2120MinIndex_j=min(j1_series(j1_series>0));
2121if ~isempty(j2_series)
2122    MaxIndex_j=max(j2_series(j2_series>0));
2123else
2124    MaxIndex_j=max(j1_series(j1_series>0));
2125end
2126MinIndex{iview,1}=MinIndex_i;
2127MinIndex{iview,2}=MinIndex_j;
2128MaxIndex{iview,1}=MaxIndex_i;
2129MaxIndex{iview,2}=MaxIndex_j;
2130set(handles.MinIndex,'Data',MinIndex)
2131set(handles.MaxIndex,'Data',MaxIndex)
2132SeriesData=get(handles.series,'UserData');
2133SeriesData.i1_series{iview}=i1_series;
2134SeriesData.i2_series{iview}=i2_series;
2135SeriesData.j1_series{iview}=j1_series;
2136SeriesData.j2_series{iview}=j2_series;
2137SeriesData.FileType{iview}=FileType;
2138
2139%% display the set of existing files as an image
2140set(handles.waitbar_frame,'Units','pixels')
2141pos=get(handles.waitbar_frame,'Position');
2142xima=0.5:pos(3)-0.5;% pixel positions on the image representing the existing file indices
2143yima=0.5:pos(4)-0.5;
2144[XIma,YIma]=meshgrid(xima,yima);
2145nb_i=size(i1_series,1);
2146nb_j=size(i1_series,2);
2147ind_i=(0.5:nb_i-0.5)*pos(3)/nb_i;
2148ind_j=(0.5:nb_j-0.5)*pos(4)/nb_j;
2149[Ind_i,Ind_j]=meshgrid(ind_i,ind_j);
2150CData=zeros([size(XIma) 3]);
2151file_ima=double((i1_series(:,:,1)>0)');
2152if numel(file_ima)>=2
2153if size(file_ima,1)==1
2154    CLine=interp1(ind_i,file_ima,xima,'nearest');
2155    CData(:,:,2)=ones(size(yima'))*CLine;
2156else
2157    CData(:,:,2)=interp2(Ind_i,Ind_j,file_ima,XIma,YIma,'nearest');
2158end
2159set(handles.waitbar_frame,'CData',CData)
2160end
2161set(handles.waitbar_frame,'Units','normalized')
2162
2163%% enable field and veltype menus
2164testfield=isequal(get(handles.FieldName,'enable'),'on');
2165testfield_1=isequal(get(handles.FieldName_1,'enable'),'on');
2166testveltype=isequal(get(handles.VelType,'enable'),'on');
2167testveltype_1=isequal(get(handles.VelType_1,'enable'),'on');
2168testtransform=isequal(get(handles.TransformName,'Enable'),'on');
2169% testnc=0;
2170% testnc_1=0;
2171% testcivx=0;
2172% testcivx_1=0;
2173% testima=0; %test for image input
2174% if isequal(lower(FileExt),'.avi') %.avi file
2175%     testima=1;
2176% elseif ~isempty(imformats(FileExt(2:end)))
2177%     testima=1;
2178% elseif isequal(FileExt,'.vol')
2179%      testima=1;
2180% end
2181%TODO: update
2182% if length(FileExtCell)==1 || length(FileExtCell)>2
2183%     for iview=1:length(FileExtCell)
2184%         if isequal(FileExtCell{iview},'.nc')
2185%             testnc=1;
2186%         end
2187%         if isequal(FileTypeCell{iview},'civx')
2188%             testcivx=1;
2189%         end
2190%     end
2191% elseif length(FileExtCell)==2
2192%     testnc=isequal(FileExtCell{1},'.nc');
2193%     testnc_1=isequal(FileExtCell{2},'.nc');
2194%     testcivx=isequal(FileTypeCell{1},'civx');
2195%     testcivx_1=isequal(FileTypeCell{2},'civx');
2196% end
2197switch FileType
2198    case {'civx','civdata'}
2199    view_FieldMenu(handles,'on')
2200    menustr=get(handles.FieldName,'String');
2201    if isequal(menustr,{'get_field...'})
2202        set(handles.FieldName,'String',{'get_field...';'velocity';'vort';'div';'more...'})
2203    end
2204    set(handles.VelType,'Visible','on')
2205    set(handles.FieldTransform,'Visible','on')
2206    %      view_TRANSFORM(handles,'on')
2207    %     TODO: second menu
2208    %           view_FieldMenu_1(handles,'on')
2209    %     if testcivx_1
2210    %         menustr=get(handles.FieldName_1,'String');
2211    %         if isequal(menustr,{'get_field...'})
2212    %             set(handles.FieldName_1,'String',{'get_field...';'velocity';'vort';'div';'more...'})
2213    %         end
2214    %     else
2215    %         set(handles.FieldName_1,'Value',1)
2216    %         set(handles.FieldName_1,'String',{'get_field...'})
2217    %     set(handles.VelType_1,'Visible','on')
2218    %     set(handles.VelType_text_1,'Visible','on');
2219    %     end
2220    %     view_FieldMenu_1(handles,'off')
2221    case 'netcdf'
2222    view_FieldMenu(handles,'on')
2223    set(handles.FieldName,'Value',1)
2224    set(handles.FieldName,'String',{'get_field...'})
2225    set(handles.FieldTransform,'Visible','off')
2226    %     view_TRANSFORM(handles,'off')
2227    case {'image','multimage','video'}
2228    view_FieldMenu(handles,'off')
2229    view_FieldMenu_1(handles,'off')
2230    set(handles.VelType,'Visible','off')
2231    set(handles.VelType_text,'Visible','off');
2232end
2233
2234
2235%TODO:update
2236% if ~isequal(FileExt,'.nc') && ~isequal(FileExt,'.cdf') && ~testima
2237%     msgbox_uvmat('ERROR',['invalid input file extension ' FileExt])
2238%     return
2239% end 
2240
2241%%  read image documentation file  if found%%%%%%%%%%%%%%%%%%%%%%%%%%%
2242ext_imadoc='';
2243FileBase=fullfile(RootPath,RootFile);
2244if isequal(FileExt,'.xml')||isequal(FileExt,'.civ')
2245    ext_imadoc=FileExt;
2246elseif exist([FileBase '.xml'],'file')
2247    ext_imadoc='.xml';
2248elseif exist([FileBase '.civ'],'file')
2249    ext_imadoc='.civ';
2250end
2251%read the ImaDoc file
2252XmlData=[];
2253NbSlice_calib={};
2254if isequal(ext_imadoc,'.xml')
2255        [XmlData,warntext]=imadoc2struct([FileBase '.xml']);
2256        if isfield(XmlData,'Heading') && isfield(XmlData.Heading,'ImageName') && ischar(XmlData.Heading.ImageName)
2257            [PP,FF,ext_ima_read]=fileparts(XmlData.Heading.ImageName);
2258        end
2259        if isfield(XmlData,'Time')
2260            time{iview}=XmlData.Time;
2261        end
2262        if isfield(XmlData,'Camera')
2263            if isfield(XmlData.Camera,'NbSlice')&& ~isempty(XmlData.Camera.NbSlice)
2264                NbSlice_calib{iview}=XmlData.Camera.NbSlice;% Nbre of slices for Zindex in phys transform
2265                if ~isequal(NbSlice_calib{iview},NbSlice_calib{1})
2266                    msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
2267                end
2268            end
2269            if isfield(XmlData.Camera,'TimeUnit')&& ~isempty(XmlData.Camera.TimeUnit)
2270                TimeUnit=XmlData.Camera.TimeUnit;
2271            end
2272        end
2273        if ~isempty(warntext)
2274            msgbox_uvmat('WARNING',warntext)
2275        end 
2276elseif isequal(ext_imadoc,'.civ')
2277    [error,XmlData.Time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([FileBase '.civ']);
2278    time{iview}=XmlData.Time;
2279    if error==2, warntext=['no file ' FileBase '.civ'];
2280    elseif error==1, warntext='inconsistent number of fields in the .civ file';
2281    end 
2282end
2283
2284%% update time table
2285TimeTable=get(handles.TimeTable,'Data');
2286TimeTable{iview,1}=time(MinIndex_i,MinIndex_j);
2287TimeTable{iview,4}=time(MaxIndex_i,MaxIndex_j);
2288set(handles.TimeTable,'Data',TimeTable)
2289
2290%% number of slices
2291if isfield(XmlData,'GeometryCalib') && isfield(XmlData.GeometryCalib,'SliceCoord')
2292       siz=size(XmlData.GeometryCalib.SliceCoord);
2293       if siz(1)>1
2294           NbSlice=siz(1);
2295       else
2296           NbSlice=1;
2297       end
2298       set(handles.num_NbSlice,'String',num2str(NbSlice))
2299end
2300% set(handles.mode,'Visible','off') % do not show index pairstring by default
2301set(handles.PairString,'Visible','off')
2302% set(handles.num_ref_i,'Visible','off')
2303% set(handles.ref_i_text,'Visible','off')
2304testpair=0;
2305%set the menus of image pairstring and default selection for series
2306%list pairstring if relevant
2307% Val=get(handles.NomType,'Value');
2308% synchronise_view(handles,Val)
2309
2310% if ~isfield(SeriesData,'j1_series')||isempty(SeriesData.j1_series{index})
2311%     state_j='off'; %no need for j index
2312% else
2313%     state_j='on'; %case of j index
2314% end
2315% show index pairstring if files exist
2316set(handles.series,'UserData',SeriesData)
2317
2318
2319% --------------------------------------------------------------------
2320function MenuExportConfig_Callback(hObject, eventdata, handles)
2321global Series
2322[tild,Series,errormsg]=prepare_jobs(handles,0);
2323% Series=read_GUI(handles.series);
2324
2325evalin('base','global Series')%make CurData global in the workspace
2326display('current series config :')
2327evalin('base','Series') %display CurData in the workspace
2328commandwindow; %brings the Matlab command window to the front
Note: See TracBrowser for help on using the repository browser.