source: trunk/src/series.m @ 440

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

bug repaired in series

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