source: trunk/src/series.m @ 419

Last change on this file since 419 was 419, checked in by sommeria, 13 years ago

bugs corrected in series and parameter walltime parameter in oar

File size: 98.1 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=1;
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);
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,'Off')
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');
1573
1574for iview=1:size(TimeTable,1)
1575    Pairs=get(handles.PairString,'Data');
1576    i1=ref_i;
1577    j1=ref_j;
1578    i2=ref_i;
1579    j2=ref_j;
1580    if ~isempty(Pairs{iview,1})
1581        r=regexp(Param.Pairs.list_pair_civ,'(?<mode>(Di=)|(Dj=)) -*(?<num1>\d+)\|(?<num2>\d+)','names');
1582        if isempty(r)
1583            r=regexp(Param.Pairs.list_pair_civ,'(?<num1>\d+)(?<mode>-)(?<num2>\d+)','names');
1584        end
1585        switch r.mode
1586            case 'Di='  %  case 'series(Di)')
1587                i1=ref_i-str2num(r.num1);
1588                i2=ref_i+str2num(r.num2);
1589            case 'Dj='  %  case 'series(Dj)'
1590                j1=ref_j-str2num(r.num1);
1591                j2=ref_j+str2num(r.num2);
1592            case '-'  % case 'bursts'
1593                j1=str2num(r.num1)*ones(size(ref_i));
1594                j2=str2num(r.num2)*ones(size(ref_i));
1595        end
1596    end
1597    if isempty(ref_j)
1598    time_first=(SeriesData.Time{iview}(i1(1))+SeriesData.Time{iview}(i2(1)))/2;
1599    time_last=(SeriesData.Time{iview}(i1(2))+SeriesData.Time{iview}(i2(2)))/2;
1600    else
1601        time_first=(SeriesData.Time{iview}(i1(1),j1(1))+SeriesData.Time{iview}(i2(1),j2(1)))/2;
1602        time_last=(SeriesData.Time{iview}(i1(2),j1(2))+SeriesData.Time{iview}(i2(2),j2(2)))/2;
1603    end
1604    TimeTable{iview,2}=time_first; %TODO: take into account pairs
1605    TimeTable{iview,3}=time_last; %TODO: take into account pairs
1606end
1607set(handles.TimeTable,'Data',TimeTable)
1608return
1609
1610
1611NomType=InputTable(:,4);
1612mode_list=get(handles.mode,'String');
1613index_mode=get(handles.mode,'Value');
1614
1615mode=mode_list{index_mode};
1616
1617time_first=[];
1618time_last=[];
1619if ~isfield(SeriesData,'Time')
1620    SeriesData.Time{1}=[];
1621end
1622TimeTable=get(handles.TimeTable,'Data');
1623for iview=1:size(TimeTable,1)
1624    time_first_cell{iview}='?';
1625    time_last_cell{iview}='?';%default
1626    time=SeriesData.Time{iview};
1627    if isequal(NomType{iview},'_1-2_1')|isequal(NomType{iview},'_1_1-2')|isequal(NomType{iview},'#_ab')|isequal(NomType{iview},'_1-2')
1628        if isfield(SeriesData,'displ_num')& ~isempty(SeriesData.displ_num)
1629            ind_shift=SeriesData.displ_num(iview,:);
1630            if isequal(mode,'bursts')
1631                first_j=0;
1632                last_j=0;
1633            end
1634            first_i1=first_i +ind_shift(3);
1635            first_i2 =first_i +ind_shift(4);
1636            first_j1 =first_j +ind_shift(1);
1637            first_j2 =first_j +ind_shift(2);
1638            last_i1=last_i +ind_shift(3);
1639            last_i2 =last_i +ind_shift(4);   
1640            last_j1 =last_j +ind_shift(1);
1641            last_j2 =last_j +ind_shift(2);
1642            siz=size(SeriesData.Time{1});
1643            if first_i1>=1 && first_j1>=1 && siz(1)>=last_i2 && siz(2)>=last_j2
1644                time_first=(time(first_i1,first_j1)+time(first_i2,first_j2))/2;
1645                time_last=(time(last_i1,last_j1)+time(last_i2,last_j2))/2;
1646            else%read the time in the nc files
1647                RootPath=get(handles.RootPath,'String');
1648                RootFile=get(handles.RootFile,'String');
1649                SubDir=get(handles.SubDir,'String');
1650                %VelType=get(handles.VelType,'String');
1651                VelType_str=get(handles.VelTypeMenu,'String');
1652                VelType_val=get(handles.VelTypeMenu,'Value');
1653                VelType=VelType_str{VelType_val};
1654                filebase=fullfile(RootPath{1},RootFile{1});
1655                [filefirst]=name_generator(filebase,first_i1,first_j1,'.nc',NomType{iview},1,first_i2,first_j2,SubDir{iview});
1656                if  exist(filefirst,'file')
1657                    Attrib=nc2struct(filefirst,[]);
1658                    if isfield(Attrib,'Time')
1659                        time_first=Attrib.Time;
1660                    else
1661                        if isfield(Attrib,'absolut_time_T0')
1662                            time_first=Attrib.absolut_time_T0;
1663                        end
1664                        if isfield(Attrib,'absolut_time_T0_2')&&~(isequal(VelType,'civ1')||isequal(VelType,'interp1')||isequal(VelType,'filter1'))
1665                            time_first=Attrib.absolut_time_T0_2;
1666                        end
1667                    end
1668                end
1669                [filelast]=name_generator(filebase,last_i1,last_j1,'.nc',NomType{iview},1,last_i2,last_j2,SubDir{iview});
1670                if exist(filelast,'file')
1671                   Attrib=nc2struct(filelast,[]);
1672                    if isfield(Attrib,'Time')
1673                        time_last=Attrib.Time;
1674                    else
1675                        if isfield(Attrib,'absolut_time_T0')
1676                            time_last=Attrib.absolut_time_T0;
1677                        end
1678                        if isfield(Attrib,'absolut_time_T0_2')&&~(isequal(VelType,'civ1')||isequal(VelType,'interp1')||isequal(VelType,'filter1'))
1679                            time_last=Attrib.absolut_time_T0_2;
1680                        end
1681                    end
1682                end
1683            end
1684        end
1685    else
1686        siz=size(time);
1687        if siz(1)>=last_i && siz(2)>=last_j && first_i>=1 && first_j>=1
1688            time_first=times(first_i,first_j);
1689            time_last=times(last_i,last_j);
1690        end
1691    end
1692    time_first_cell{iview}=num2str(time_first,4);
1693    time_last_cell{iview}=num2str(time_last,4);
1694end
1695
1696
1697%------------------------------------------------------------------------
1698% --- Executes on selection change in ACTION.
1699function ACTION_Callback(hObject, eventdata, handles)
1700%------------------------------------------------------------------------
1701global nb_builtin_ACTION
1702list_ACTION=get(handles.ACTION,'String');% list menu fields
1703index_ACTION=get(handles.ACTION,'Value');% selected string index
1704ACTION= list_ACTION{index_ACTION}; % selected function name
1705path_series=which('series');%path to series.m
1706list_path=get(handles.ACTION,'UserData');%list of recorded paths to functions of the list ACTION
1707default_file=fullfile(list_path{end},ACTION);
1708% add a new function to the menu if the selected item is 'more...'
1709if isequal(ACTION,'more...')
1710    pathfct=fileparts(path_series);
1711    [FileName, PathName, filterindex] = uigetfile( ...
1712       {'*.m', ' (*.m)';
1713        '*.m',  '.m files '; ...
1714        '*.*', 'All Files (*.*)'}, ...
1715        'Pick a file',default_file);
1716    if length(FileName)<2
1717        return
1718    end
1719    [pp,ACTION,ext_fct]=fileparts(FileName);%(end-1:end);
1720    if ~isequal(ext_fct,'.m')
1721        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
1722        return
1723    end
1724   
1725   % insert the choice in the action menu
1726   menu_str=update_menu(handles.ACTION,ACTION);%new action menu in which the new item has been appended if needed
1727   index_ACTION=get(handles.ACTION,'Value');% currently selected index in the list
1728   list_path{index_ACTION}=PathName;
1729   if length(menu_str)>nb_builtin_ACTION+5; %nb_builtin=nbre of functions always remaining in the initial menu
1730       nbremove=length(menu_str)-nb_builtin_ACTION-5;
1731       menu_str(nb_builtin_ACTION+1:end-5)=[];
1732       list_path(nb_builtin_ACTION+1:end-4)=[];
1733       index_ACTION=index_ACTION-nbremove;
1734       set(handles.ACTION,'Value',index_ACTION)
1735       set(handles.ACTION,'String',menu_str)
1736   end
1737   list_path{index_ACTION}=PathName;
1738   set(handles.ACTION,'UserData',list_path);
1739   set(handles.path,'enable','inactive')% indicate that the current path is accessible (not 'off')
1740   
1741   %record the current menu in personal file profil_perso
1742   dir_perso=prefdir;
1743   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
1744   for ilist=nb_builtin_ACTION+1:length(menu_str)-1
1745       series_fct{ilist-nb_builtin_ACTION}=fullfile(list_path{ilist},[menu_str{ilist} '.m']);     
1746   end
1747   if nb_builtin_ACTION+1<=length(menu_str)-1
1748       if exist(profil_perso,'file')% && nb_builtin_ACTION+1>=length(menu_str)-1
1749           save(profil_perso,'series_fct','-append')
1750       else
1751           txt=ver('MATLAB');
1752           Release=txt.Release;
1753           relnumb=str2num(Release(3:4));
1754           if relnumb >= 14%recent relaese of Matlab
1755               save(profil_perso,'series_fct','-V6')
1756           else
1757               save(profil_perso, 'series_fct')
1758           end
1759       end
1760   end
1761end
1762
1763%check the current path to the selected function
1764PathName=list_path{index_ACTION};%current recorded path
1765set(handles.path,'String',PathName); %show the path to the senlected function
1766
1767%default setting for the visibility of the GUI elements
1768% set(handles.RootPath,'UserData','many')
1769% set(handles.SubDir,'Visible','on')
1770% set(handles.RootFile,'Visible','on')
1771% set(handles.NomType,'Visible','on')
1772% set(handles.FileExt,'Visible','on')
1773set(handles.num_NbSlice,'Visible','off')
1774set(handles.NbSlice_title,'Visible','off')
1775set(handles.VelTypeMenu,'Visible','off');
1776set(handles.VelType_text,'Visible','off');
1777set(handles.VelTypeMenu_1,'Visible','off');
1778set(handles.VelType_text_1,'Visible','off');
1779view_FieldMenu(handles,'off')
1780view_FieldMenu_1(handles,'off')
1781set(handles.FieldTransform,'Visible','off')
1782% view_TRANSFORM(handles,'off')Visible','off')
1783set(handles.Objects,'Visible','off');
1784set(handles.GetMask,'Visible','off')
1785set(handles.Mask,'Visible','off')
1786% set(handles.GetObject,'Visible','off');
1787set(handles.OutputDir,'Visible','off');
1788% set(handles.PARAMETERS_frame,'Visible','off');
1789% set(handles.PARAMETERS_title,'Visible','off');
1790set(handles.ParamKey,'Visible','off')
1791set(handles.ParamVal,'Visible','off')
1792ParamKey={};
1793set(handles.FieldMenu,'Enable','off')
1794set(handles.VelTypeMenu,'Enable','off')
1795set(handles.FieldMenu_1,'Enable','off')
1796set(handles.VelTypeMenu_1,'Enable','off')
1797set(handles.transform_fct,'Enable','off')
1798%set the displayed GUI item needed for input parameters
1799if ~isequal(path_series,PathName)
1800    addpath(PathName)
1801end
1802eval(['h_function=@' ACTION ';']);
1803try
1804    [fid,errormsg] =fopen([ACTION '.m']);
1805    InputText=textscan(fid,'%s',1,'delimiter','\n');
1806    fclose(fid)
1807    set(handles.ACTION,'ToolTipString',InputText{1}{1})
1808end
1809if ~isequal(path_series,PathName)
1810    rmpath(PathName)
1811end
1812varargout=h_function();
1813Param_list={};
1814
1815%nb_series=length(RootFile);
1816% FileExt=get(handles.FileExt,'String');
1817% nb_series=length(FileExt);
1818InputTable=get(handles.InputTable,'Data');
1819nb_series=size(InputTable,1);
1820% if ~isempty(checkcell)
1821% nb_series=checkcell(end);
1822% end
1823% nb_series=size(InputFiles,1)
1824testima_series=1; %test for a list of images only
1825testima=1;
1826testima_1=1;
1827testciv_series=1;
1828for iview=1:nb_series
1829     ext=InputTable{iview,5};
1830    if length(ext)<2
1831        ext='.none';
1832    end
1833    testimaview=~isempty(imformats(ext(2:end))) || isequal(lower(ext),'.avi');
1834    if ~testimaview
1835        if iview==1
1836            testima=0;
1837        end
1838        if iview==2
1839            testima_1=0;
1840        end
1841        testima_series=0;
1842    end
1843end
1844for ilist=1:length(varargout)-1
1845    switch varargout{ilist}
1846
1847                       %RootFile always visible
1848%          case 'RootPath'   %visible by default
1849%             value=lower(varargout{ilist+1});
1850%             if isequal(value,'one')||isequal(value,'two')||isequal(value,'many')
1851%                 set(handles.RootFile,'UserData',value)% for use in menu Open_insert
1852%             end
1853%         case 'SubDir' %visible by default
1854%             if isequal(lower(varargout{ilist+1}),'off')
1855%                 set(handles.SubDir,'Visible','off')
1856%             end
1857%         case 'RootFile'   %visible by default
1858%             value=lower(varargout{ilist+1});
1859%             if isequal(value,'off')
1860%                 set(handles.RootFile,'Visible','off')
1861%             elseif isequal(value,'one')||isequal(value,'two')||isequal(value,'many')
1862%                 set(handles.RootFile,'Visible','on')
1863%                 set(handles.RootFile,'UserData',value)% for use in menu Open_insert
1864%             end
1865%         case 'NomType'   %visible by default
1866%             if isequal(lower(varargout{ilist+1}),'off')
1867%                 set(handles.NomType,'Visible','off')
1868%             end
1869%         case 'FileExt'   %visible by default
1870%             if isequal(lower(varargout{ilist+1}),'off')
1871%                 set(handles.FileExt,'Visible','off')
1872%             end
1873        case 'NbSlice'   %hidden by default
1874            if isequal(lower(varargout{ilist+1}),'on')
1875                set(handles.num_NbSlice,'Visible','on')
1876                set(handles.NbSlice_title,'Visible','on')
1877            end
1878        case 'VelTypeMenu'   %hidden by default
1879             if isequal(lower(varargout{ilist+1}),'one') || isequal(lower(varargout{ilist+1}),'two')
1880                set(handles.VelTypeMenu,'Enable','on')
1881                if nb_series >=1 && ~testima_series
1882                    set(handles.VelTypeMenu,'Visible','on')
1883                    set(handles.VelType_text,'Visible','on');
1884%                     set(handles.Field_frame,'Visible','on')
1885                end
1886             end
1887            if isequal(lower(varargout{ilist+1}),'two')
1888                set(handles.VelTypeMenu_1,'Enable','on')
1889                if nb_series >=2 && ~testima_series
1890                    set(handles.VelTypeMenu_1,'Visible','on')
1891                    set(handles.VelType_text_1,'Visible','on');
1892                end
1893            end
1894        case 'FieldMenu'   %hidden by default
1895            if isequal(lower(varargout{ilist+1}),'one')||isequal(lower(varargout{ilist+1}),'two')
1896                set(handles.FieldMenu,'Enable','on') % test for MenuBorser
1897                if nb_series >=1 && ~testima_series
1898                    view_FieldMenu(handles,'on')
1899                end
1900            end
1901            if isequal(lower(varargout{ilist+1}),'two')
1902                set(handles.FieldMenu_1,'Enable','on')
1903                if nb_series >=2 && ~testima_1
1904                    view_FieldMenu_1(handles,'on')
1905                end
1906            end
1907        case 'CoordType'   %hidden by default
1908            if isequal(lower(varargout{ilist+1}),'on')
1909                set(handles.transform_fct,'Enable','on')
1910                set(handles.FieldTransform,'Visible','on')
1911%                 view_TRANSFORM(handles,'on')
1912            end
1913        case 'GetObject'   %hidden by default
1914            if isequal(lower(varargout{ilist+1}),'on')   
1915                set(handles.Objects,'Visible','on')
1916%                 set(handles.GetObject,'Visible','on');
1917            end
1918        case 'Mask'   %hidden by default
1919            if isequal(lower(varargout{ilist+1}),'on')   
1920                set(handles.Objects,'Visible','on')
1921%                 set(handles.GetMask,'Visible','on');
1922            end
1923        case 'PARAMETER' 
1924            set(handles.PARAMETERS_frame,'Visible','on')
1925            set(handles.PARAMETERS_title,'Visible','on')
1926            set(handles.ParamKey,'Visible','on')
1927            %set(handles.ParamVal,'Visible','on')
1928            Param_str=varargout{ilist+1};
1929            Param_list=[Param_list; {Param_str}];         
1930    end
1931end
1932if ~isempty(Param_list)
1933    set(handles.ParamKey,'String',Param_list)
1934    set(handles.ParamVal,'Visible','on')
1935end
1936
1937%------------------------------------------------------------------------
1938% --- Executes on selection change in FieldMenu.
1939function FieldMenu_Callback(hObject, eventdata, handles)
1940%------------------------------------------------------------------------
1941field_str=get(handles.FieldMenu,'String');
1942field_index=get(handles.FieldMenu,'Value');
1943field=field_str{field_index(1)};
1944if isequal(field,'get_field...')   
1945     hget_field=findobj(allchild(0),'name','get_field');
1946     if ~isempty(hget_field)
1947         delete(hget_field)%delete opened versions of get_field
1948     end
1949     SeriesData=get(handles.series,'UserData');
1950     filename=SeriesData.CurrentInputFile;
1951     if exist(filename,'file')
1952        get_field(filename)
1953     end
1954elseif isequal(field,'more...')
1955    str=calc_field;
1956    [ind_answer,v] = listdlg('PromptString','Select a file:',...
1957                'SelectionMode','single',...
1958                'ListString',str);
1959       % edit the choice in the fields and action menu
1960     scalar=cell2mat(str(ind_answer));
1961     update_menu(handles.FieldMenu,scalar)
1962end
1963
1964%------------------------------------------------------------------------
1965% --- Executes on selection change in FieldMenu_1.
1966function FieldMenu_1_Callback(hObject, eventdata, handles)
1967%------------------------------------------------------------------------
1968field_str=get(handles.FieldMenu_1,'String');
1969field_index=get(handles.FieldMenu_1,'Value');
1970field=field_str{field_index};
1971if isequal(field,'get_field...')   
1972     hget_field=findobj(allchild(0),'name','get_field_1');
1973     if ~isempty(hget_field)
1974         delete(hget_field)
1975     end
1976     SeriesData=get(handles.series,'UserData');
1977     filename=SeriesData.CurrentInputFile_1;
1978     if exist(filename,'file')
1979        hget_field=get_field(filename);
1980        set(hget_field,'name','get_field_1')
1981     end
1982elseif isequal(field,'more...')
1983    str=calc_field;
1984    [ind_answer,v] = listdlg('PromptString','Select a file:',...
1985                'SelectionMode','single',...
1986                'ListString',str);
1987       % edit the choice in the fields and action menu
1988     scalar=cell2mat(str(ind_answer));
1989     update_menu(handles.FieldMenu_1,scalar)
1990end   
1991
1992
1993%%%%%%%%%%%%%
1994function [ind_remove]=find_pairs(dirpair,ind_i,last_i)
1995indsel=ind_i;
1996indiff=diff(ind_i); %test index increment to detect multiplets (several pairs with the same index ind_i) and holes in the series
1997indiff=[1 indiff last_i-ind_i(end)+1];%for testing gaps with the imposed bounds
1998if ~isempty(indiff)
1999    indiff2=diff(indiff);
2000    indiffp=[indiff2 1];
2001    indiffm=[1 indiff2];
2002    ind_multi_m=find((indiff==0)&(indiffm<0))-1;%indices of first members of multiplets
2003    ind_multi_p=find((indiff==0)&(indiffp>0));%indices of last members of multiplets
2004    %for each multiplet, select the most recent file
2005    ind_remove=[];
2006    for i=1:length(ind_multi_m)
2007        ind_pairs=ind_multi_m(i):ind_multi_p(i);
2008        for imulti=1:length(ind_pairs)
2009            datepair(imulti)=datenum(dirpair(ind_pairs(imulti)).date);%dates of creation
2010        end
2011        [datenew,indsort2]=sort(datepair); %sort the multiplet by creation date
2012        ind_s=indsort2(1:end-1);%
2013        ind_remove=[ind_remove ind_pairs(ind_s)];%remove these indices, leave the last one
2014    end
2015end
2016
2017%------------------------------------------------------------------------
2018% --- determine the list of index pairstring of processing file
2019function [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)
2020%------------------------------------------------------------------------
2021num_i1=num_i;% set of first image numbers by default
2022num_i2=num_i;
2023num_j1=num_j;
2024num_j2=num_j;
2025num_i_out=num_i;
2026num_j_out=num_j;
2027% if isequal (NomType,'_1-2_1') || isequal (NomType,'_1-2')
2028if isequal(mode,'series(Di)')
2029    num_i1_line=num_i+ind_shift(3);% set of first image numbers
2030    num_i2_line=num_i+ind_shift(4);
2031    % adjust the first and last field number
2032        indsel=find(num_i1_line >= 1);
2033    num_i_out=num_i(indsel);
2034    num_i1_line=num_i1_line(indsel);
2035    num_i2_line=num_i2_line(indsel);
2036    num_j1=meshgrid(num_j,ones(size(num_i1_line)));
2037    num_j2=meshgrid(num_j,ones(size(num_i1_line)));
2038    [xx,num_i1]=meshgrid(num_j,num_i1_line);
2039    [xx,num_i2]=meshgrid(num_j,num_i2_line);
2040elseif isequal (mode,'series(Dj)')||isequal (mode,'bursts')
2041    if isequal(mode,'bursts') %case of bursts (png_old or png_2D)
2042        num_j1=ind_shift(1)*ones(size(num_i));
2043        num_j2=ind_shift(2)*ones(size(num_i));
2044    else
2045        num_j1_col=num_j+ind_shift(1);% set of first image numbers
2046        num_j2_col=num_j+ind_shift(2);
2047        % adjust the first field number
2048        indsel=find((num_j1_col >= 1));   
2049        num_j_out=num_j(indsel);
2050        num_j1_col=num_j1_col(indsel);
2051        num_j2_col=num_j2_col(indsel);
2052        [num_i1,num_j1]=meshgrid(num_i,num_j1_col);
2053        [num_i2,num_j2]=meshgrid(num_i,num_j2_col);
2054    end   
2055end
2056
2057
2058% set(handles.time_first,'Value',1)
2059% set(handles.time_last,'Value',1)
2060% set(handles.time_first,'String',time_first_cell);
2061% set(handles.time_last,'String',time_last_cell);
2062
2063%------------------------------------------------------------------------
2064% --- Executes on button press in GetObject.
2065function GetObject_Callback(hObject, eventdata, handles)
2066%------------------------------------------------------------------------
2067SeriesData=get(handles.series,'UserData');
2068value=get(handles.GetObject,'Value');
2069if value
2070     set(handles.GetObject,'BackgroundColor',[1 1 0])%put unactivated buttons to yellow
2071%      DataInit.ParentButton=handles.GetObject;
2072     hset_object=findobj(allchild(0),'tag','set_object');%find the set_object interface handle
2073     if ishandle(hset_object)
2074         uistack(hset_object,'top')
2075        %[SeriesData.hset_object,SeriesData.sethandles]=set_object(DataInit); %open the set_object interface
2076     else
2077         %get the object file
2078         InputTable=get(handles.InputTable,'Data');
2079         defaultname=InputTable{1,1};
2080%          defaultname=get(handles.RootPath,'String');
2081         if isempty(defaultname)
2082            defaultname={''};
2083         end
2084        [FileName, PathName, filterindex] = uigetfile( ...
2085       {'*.xml;*.mat', ' (*.xml,*.mat)';
2086       '*.xml',  '.xml files '; ...
2087        '*.mat',  '.mat matlab files '}, ...
2088        'Pick an xml object file (or use uvmat to create it)',defaultname{1});
2089        fileinput=[PathName FileName];%complete file name
2090        testblank=findstr(fileinput,' ');%look for blanks
2091        if ~isempty(testblank)
2092            msgbox_uvmat('ERROR','forbidden input file name: contain blanks')
2093            return
2094        end
2095        sizf=size(fileinput);
2096        if (~ischar(fileinput)||~isequal(sizf(1),1)),return;end
2097        %read the file
2098        t=xmltree(fileinput);
2099        data=convert(t);
2100        if ~isfield(data,'Style')
2101             data.Style='points';
2102        end
2103        if ~isfield(data,'ProjMode')
2104             data.ProjMode='projection';
2105        end
2106        transform_menu=get(handles.transform_fct,'String');
2107        ichoice=get(handles.transform_fct,'Value');
2108%         if isequal(transform_menu{ichoice},'px');
2109%             data.CoordType='px';
2110%         else
2111%             data.CoordType='phys';
2112%         end
2113        data.desable_plot=1;
2114        [SeriesData.hset_object,SeriesData.sethandles]=set_object(data);% call the set_object interface
2115     end
2116else
2117    set(handles.GetObject,'BackgroundColor',[0.7 0.7 0.7])%put activated buttons to green
2118%     if isfield(SeriesData,'hset_object')&& ishandle(SeriesData.hset_object)
2119%         close(SeriesData.hset_object)
2120%     end
2121end
2122set(handles.series,'UserData',SeriesData)
2123
2124%--------------------------------------------------------------
2125function GetMask_Callback(hObject, eventdata, handles)
2126value=get(handles.GetMask,'Value');
2127if value
2128    msgbox_uvmat('ERROR','not implemented yet')
2129end
2130%--------------------------------------------------------------
2131
2132%-------------------------------------------------------------------
2133%'uv_ncbrowser': interactively calls the netcdf file browser 'get_field.m'
2134function ncbrowser_uvmat(hObject, eventdata)
2135%-------------------------------------------------------------------
2136     bla=get(gcbo,'String');
2137     ind=get(gcbo,'Value');
2138     filename=cell2mat(bla(ind));
2139      blank=find(filename==' ');
2140      filename=filename(1:blank-1);
2141     get_field(filename)
2142
2143% ------------------------------------------------------------------
2144function MenuHelp_Callback(hObject, eventdata, handles)
2145%-------------------------------------------------------------------
2146path_to_uvmat=which ('uvmat');% check the path of uvmat
2147pathelp=fileparts(path_to_uvmat);
2148helpfile=fullfile(pathelp,'uvmat_doc','uvmat_doc.html');
2149if isempty(dir(helpfile)), msgbox_uvmat('ERROR','Please put the help file uvmat_doc.html in the sub-directory /uvmat_doc of the UVMAT package')
2150else
2151    addpath (fullfile(pathelp,'uvmat_doc'))
2152    web([helpfile '#series'])
2153end
2154
2155%-------------------------------------------------------------------
2156% --- Executes on selection change in transform_fct.
2157function transform_fct_Callback(hObject, eventdata, handles)
2158%-------------------------------------------------------------------
2159global nb_transform
2160
2161menu=get(handles.transform_fct,'String');
2162ind_coord=get(handles.transform_fct,'Value');
2163coord_option=menu{ind_coord};
2164list_transform=get(handles.transform_fct,'UserData');
2165ff=functions(list_transform{end});
2166if isequal(coord_option,'more...');
2167    coord_fct='';
2168    prompt = {'Enter the name of the transform function'};
2169    dlg_title = 'user defined transform';
2170    num_lines= 1;
2171    [FileName, PathName, filterindex] = uigetfile( ...
2172       {'*.m', ' (*.m)';
2173        '*.m',  '.m files '; ...
2174        '*.*', 'All Files (*.*)'}, ...
2175        'Pick a file', ff.file);
2176    if isequal(PathName(end),'/')||isequal(PathName(end),'\')
2177        PathName(end)=[];
2178    end
2179    transform_selected =fullfile(PathName,FileName);
2180    if ~exist(transform_selected,'file')
2181          return
2182    end
2183    [ppp,transform,xt_fct]=fileparts(FileName);% removes extension .m
2184    if ~isequal(ext_fct,'.m')
2185        msgbox_uvmat('ERROR','a Matlab function .m must be introduced');
2186        return
2187    end
2188   menu=update_menu(handles.transform_fct,transform);%add the selected fct to the menu
2189   ind_coord=get(handles.transform_fct,'Value');
2190   addpath(PathName)
2191   list_transform{ind_coord}=str2func(transform);% create the function handle corresponding to the newly seleced function
2192   set(handles.transform_fct,'UserData',list_transform)
2193   rmpath(PathName)
2194   % save the new menu in the personal file 'uvmat_perso.mat'
2195   dir_perso=prefdir;%personal Matalb directory
2196   profil_perso=fullfile(dir_perso,'uvmat_perso.mat');
2197   if exist(profil_perso,'file')
2198       for ilist=nb_transform+1:numel(list_transform)
2199           ff=functions(list_transform{ilist});
2200           transform_fct{ilist-nb_transform}=ff.file;
2201       end
2202        save (profil_perso,'transform_fct','-append'); %store the root name for future opening of uvmat
2203   end
2204end
2205
2206%check the current path to the selected function
2207if ~isempty(list_transform{ind_coord})
2208func=functions(list_transform{ind_coord});
2209set(handles.path_transform,'String',fileparts(func.file)); %show the path to the senlected function
2210else
2211   set(handles.path_transform,'String',''); %show the path to the senlected function
2212end
2213
2214%------------------------------------------------------------------------
2215% --- Executes on button press in REFRESH_INDICES.
2216    function REFRESH_INDICES_Callback(hObject, eventdata, handles)
2217%------------------------------------------------------------------------       
2218% hObject    handle to REFRESH_INDICES (see GCBO)
2219% eventdata  reserved - to be defined in a future version of MATLAB
2220% handles    structure with handles and user data (see GUIDATA)
2221set(handles.REFRESH_INDICES,'BackgroundColor',[0.7 0.7 0.7])
2222InputTable=get(handles.InputTable,'Data');
2223check_lines=get(handles.REFRESH_INDICES,'UserData');
2224
2225%% check the indices and FileTypes for each series (limited to the new ones to save time)
2226for ind_list=1:length(check_lines)
2227    if  check_lines(ind_list)
2228        InputLine=InputTable(ind_list,:);
2229        detect_idem=strcmp('"',InputLine);% look for '" (repeat of previous data)
2230        detect_idem=detect_idem(detect_idem>0);
2231        if ~isempty (detect_idem)
2232            InputLine(detect_idem)=InputTable(ind_list-1,detect_idem);
2233            set(handles.InputTable,'Data',InputTable)
2234        end
2235        fileinput=fullfile_uvmat(InputLine{1},InputLine{2},InputLine{3},InputLine{5},InputLine{4},1,2,1,2);
2236        %fileinput=name_generator(fullfile(InputLine{1},InputLine{3}),1,1,InputLine{5},InputLine{4},1,2,2,InputLine{2})
2237        %update file series defined by the selected line
2238        [InputTable{ind_list,3},InputTable{(ind_list),4},errormsg]=update_indices(handles,fileinput,ind_list);
2239        if ~isempty(errormsg)
2240                msgbox_uvmat('ERROR',errormsg)
2241                return
2242        end
2243    end
2244end
2245set(handles.InputTable,'Data',InputTable)
2246SeriesData=get(handles.series,'UserData');
2247
2248state_j='off';
2249state_Pairs='off';
2250state_InputFields='off';
2251val=get(handles.ListView,'Value');
2252ListViewString={''};
2253if ~isempty(SeriesData)
2254%     ListViewString={};
2255    for iview=1:size(InputTable,1)
2256        if ~isempty(SeriesData.j1_series{iview})
2257            state_j='on';
2258        end
2259        if ~isempty(SeriesData.i2_series{iview})||~isempty(SeriesData.j2_series{iview})
2260            state_Pairs='on';
2261            ListViewString{iview}=num2str(iview);
2262            if check_lines(iview)
2263                val=iview;%select the last pair if it is a new entry
2264            end
2265        end
2266        if strcmp(SeriesData.FileType{iview},'civx')||strcmp(SeriesData.FileType{iview},'civdata')
2267            state_InputFields='on';
2268        end
2269    end
2270end
2271set(handles.ListView,'Value',val)
2272set(handles.ListView,'String',ListViewString)
2273if strcmp(state_Pairs,'on')
2274    ListView_Callback(hObject,eventdata,handles)
2275end
2276set(handles.PairString,'Visible',state_Pairs)
2277enable_j(handles,state_j)
2278set(handles.REFRESH_INDICES,'BackgroundColor',[1 0 0])
2279set(handles.REFRESH_INDICES,'visible','off')
2280
2281% -----------------------------------------------------------------------
2282% --- Update min and max indices of a file series by scanning with find_file_series
2283% --- which also changes the root file and NomType in case of movie. Also adjust the string representation of indices (e.g;
2284% --- 1 or 001 by the function find_file_series
2285% --- This function also dispaly the set of availbale files in the series
2286% --- and the menus appropriate to the file type as well as timing possibly set
2287% --- by an xml image documentation file
2288function [RootFile,NomType,errormsg]=update_indices(handles,fileinput,iview)
2289% -----------------------------------------------------------------------
2290%% look for min and max indices existing in the file series and update SeriesData
2291errormsg='';
2292[FilePath,FileName,FileExt]=fileparts(fileinput);
2293% detect the file type, get the movie object if relevant, and look for the corresponding file series:
2294% the root name and indices may be corrected by including the first index i1 if a corresponding xml file exists
2295[RootPath,SubDir,RootFile,i1_series,i2_series,j1_series,j2_series,NomType,FileType,Object,i1,i2,j1,j2]=find_file_series(FilePath,[FileName FileExt]);
2296if isempty(RootFile)&&isempty(i1_series)
2297    errormsg='no input file in the series';
2298    return
2299end
2300
2301%% adjust the min and max indices common to all the file series
2302MinIndex=get(handles.MinIndex,'Data');
2303MaxIndex=get(handles.MaxIndex,'Data');
2304MinIndex_i=min(i1_series(i1_series>0));
2305if ~isempty(i2_series)
2306    MaxIndex_i=max(i2_series(i2_series>0));
2307else
2308    MaxIndex_i=max(i1_series(i1_series>0));
2309end
2310MinIndex_j=min(j1_series(j1_series>0));
2311if ~isempty(j2_series)
2312    MaxIndex_j=max(j2_series(j2_series>0));
2313else
2314    MaxIndex_j=max(j1_series(j1_series>0));
2315end
2316MinIndex{iview,1}=MinIndex_i;
2317MinIndex{iview,2}=MinIndex_j;
2318MaxIndex{iview,1}=MaxIndex_i;
2319MaxIndex{iview,2}=MaxIndex_j;
2320set(handles.MinIndex,'Data',MinIndex)
2321set(handles.MaxIndex,'Data',MaxIndex)
2322SeriesData=get(handles.series,'UserData');
2323SeriesData.i1_series{iview}=i1_series;
2324SeriesData.i2_series{iview}=i2_series;
2325SeriesData.j1_series{iview}=j1_series;
2326SeriesData.j2_series{iview}=j2_series;
2327SeriesData.FileType{iview}=FileType;
2328
2329%% display the set of existing files as an image
2330set(handles.waitbar_frame,'Units','pixels')
2331pos=get(handles.waitbar_frame,'Position');
2332xima=0.5:pos(3)-0.5;% pixel positions on the image representing the existing file indices
2333yima=0.5:pos(4)-0.5;
2334[XIma,YIma]=meshgrid(xima,yima);
2335nb_i=size(i1_series,1);
2336nb_j=size(i1_series,2);
2337ind_i=(0.5:nb_i-0.5)*pos(3)/nb_i;
2338ind_j=(0.5:nb_j-0.5)*pos(4)/nb_j;
2339[Ind_i,Ind_j]=meshgrid(ind_i,ind_j);
2340CData=zeros([size(XIma) 3]);
2341file_ima=double((i1_series(:,:,1)>0)');
2342if numel(file_ima)>=2
2343if size(file_ima,1)==1
2344    CLine=interp1(ind_i,file_ima,xima,'nearest');
2345    CData(:,:,2)=ones(size(yima'))*CLine;
2346else
2347    CData(:,:,2)=interp2(Ind_i,Ind_j,file_ima,XIma,YIma,'nearest');
2348end
2349set(handles.waitbar_frame,'CData',CData)
2350end
2351set(handles.waitbar_frame,'Units','normalized')
2352
2353%% enable field and veltype menus
2354testfield=isequal(get(handles.FieldMenu,'enable'),'on');
2355testfield_1=isequal(get(handles.FieldMenu_1,'enable'),'on');
2356testveltype=isequal(get(handles.VelTypeMenu,'enable'),'on');
2357testveltype_1=isequal(get(handles.VelTypeMenu_1,'enable'),'on');
2358testtransform=isequal(get(handles.transform_fct,'Enable'),'on');
2359% testnc=0;
2360% testnc_1=0;
2361% testcivx=0;
2362% testcivx_1=0;
2363% testima=0; %test for image input
2364% if isequal(lower(FileExt),'.avi') %.avi file
2365%     testima=1;
2366% elseif ~isempty(imformats(FileExt(2:end)))
2367%     testima=1;
2368% elseif isequal(FileExt,'.vol')
2369%      testima=1;
2370% end
2371%TODO: update
2372% if length(FileExtCell)==1 || length(FileExtCell)>2
2373%     for iview=1:length(FileExtCell)
2374%         if isequal(FileExtCell{iview},'.nc')
2375%             testnc=1;
2376%         end
2377%         if isequal(FileTypeCell{iview},'civx')
2378%             testcivx=1;
2379%         end
2380%     end
2381% elseif length(FileExtCell)==2
2382%     testnc=isequal(FileExtCell{1},'.nc');
2383%     testnc_1=isequal(FileExtCell{2},'.nc');
2384%     testcivx=isequal(FileTypeCell{1},'civx');
2385%     testcivx_1=isequal(FileTypeCell{2},'civx');
2386% end
2387switch FileType
2388    case {'civx','civdata'}
2389    view_FieldMenu(handles,'on')
2390    menustr=get(handles.FieldMenu,'String');
2391    if isequal(menustr,{'get_field...'})
2392        set(handles.FieldMenu,'String',{'get_field...';'velocity';'vort';'div';'more...'})
2393    end
2394    set(handles.VelTypeMenu,'Visible','on')
2395    set(handles.FieldTransform,'Visible','on')
2396    %      view_TRANSFORM(handles,'on')
2397    %     TODO: second menu
2398    %           view_FieldMenu_1(handles,'on')
2399    %     if testcivx_1
2400    %         menustr=get(handles.FieldMenu_1,'String');
2401    %         if isequal(menustr,{'get_field...'})
2402    %             set(handles.FieldMenu_1,'String',{'get_field...';'velocity';'vort';'div';'more...'})
2403    %         end
2404    %     else
2405    %         set(handles.FieldMenu_1,'Value',1)
2406    %         set(handles.FieldMenu_1,'String',{'get_field...'})
2407    %     set(handles.VelTypeMenu_1,'Visible','on')
2408    %     set(handles.VelType_text_1,'Visible','on');
2409    %     end
2410    %     view_FieldMenu_1(handles,'off')
2411    case 'netcdf'
2412    view_FieldMenu(handles,'on')
2413    set(handles.FieldMenu,'Value',1)
2414    set(handles.FieldMenu,'String',{'get_field...'})
2415    set(handles.FieldTransform,'Visible','off')
2416    %     view_TRANSFORM(handles,'off')
2417    case {'image','multimage','video'}
2418    view_FieldMenu(handles,'off')
2419    view_FieldMenu_1(handles,'off')
2420    set(handles.VelTypeMenu,'Visible','off')
2421    set(handles.VelType_text,'Visible','off');
2422end
2423
2424
2425%TODO:update
2426% if ~isequal(FileExt,'.nc') && ~isequal(FileExt,'.cdf') && ~testima
2427%     msgbox_uvmat('ERROR',['invalid input file extension ' FileExt])
2428%     return
2429% end 
2430
2431%%  read image documentation file  if found%%%%%%%%%%%%%%%%%%%%%%%%%%%
2432ext_imadoc='';
2433FileBase=fullfile(RootPath,RootFile);
2434if isequal(FileExt,'.xml')||isequal(FileExt,'.civ')
2435    ext_imadoc=FileExt;
2436elseif exist([FileBase '.xml'],'file')
2437    ext_imadoc='.xml';
2438elseif exist([FileBase '.civ'],'file')
2439    ext_imadoc='.civ';
2440end
2441%read the ImaDoc file
2442XmlData=[];
2443NbSlice_calib={};
2444if isequal(ext_imadoc,'.xml')
2445        [XmlData,warntext]=imadoc2struct([FileBase '.xml']);
2446        if isfield(XmlData,'Heading') && isfield(XmlData.Heading,'ImageName') && ischar(XmlData.Heading.ImageName)
2447            [PP,FF,ext_ima_read]=fileparts(XmlData.Heading.ImageName);
2448        end
2449        if isfield(XmlData,'Time')
2450            time{iview}=XmlData.Time;
2451        end
2452        if isfield(XmlData,'Camera')
2453            if isfield(XmlData.Camera,'NbSlice')&& ~isempty(XmlData.Camera.NbSlice)
2454                NbSlice_calib{iview}=XmlData.Camera.NbSlice;% Nbre of slices for Zindex in phys transform
2455                if ~isequal(NbSlice_calib{iview},NbSlice_calib{1})
2456                    msgbox_uvmat('WARNING','inconsistent number of Z indices for the two field series');
2457                end
2458            end
2459            if isfield(XmlData.Camera,'TimeUnit')&& ~isempty(XmlData.Camera.TimeUnit)
2460                TimeUnit=XmlData.Camera.TimeUnit;
2461            end
2462        end
2463        if ~isempty(warntext)
2464            msgbox_uvmat('WARNING',warntext)
2465        end 
2466elseif isequal(ext_imadoc,'.civ')
2467    [error,XmlData.Time,TimeUnit,mode,npx,npy,pxcmx,pxcmy]=read_imatext([FileBase '.civ']);
2468    time{iview}=XmlData.Time;
2469    if error==2, warntext=['no file ' FileBase '.civ'];
2470    elseif error==1, warntext='inconsistent number of fields in the .civ file';
2471    end 
2472end
2473
2474%% update time table
2475TimeTable=get(handles.TimeTable,'Data')
2476TimeTable{iview,1}=time(MinIndex_i,MinIndex_j);
2477TimeTable{iview,4}=time(MaxIndex_i,MaxIndex_j);
2478set(handles.TimeTable,'Data',TimeTable)
2479
2480%% number of slices
2481if isfield(XmlData,'GeometryCalib') && isfield(XmlData.GeometryCalib,'SliceCoord')
2482       siz=size(XmlData.GeometryCalib.SliceCoord);
2483       if siz(1)>1
2484           NbSlice=siz(1);
2485       else
2486           NbSlice=1;
2487       end
2488       set(handles.num_NbSlice,'String',num2str(NbSlice))
2489end
2490% set(handles.mode,'Visible','off') % do not show index pairstring by default
2491set(handles.PairString,'Visible','off')
2492% set(handles.num_ref_i,'Visible','off')
2493% set(handles.ref_i_text,'Visible','off')
2494testpair=0;
2495%set the menus of image pairstring and default selection for series
2496%list pairstring if relevant
2497% Val=get(handles.NomType,'Value');
2498% synchronise_view(handles,Val)
2499
2500% if ~isfield(SeriesData,'j1_series')||isempty(SeriesData.j1_series{index})
2501%     state_j='off'; %no need for j index
2502% else
2503%     state_j='on'; %case of j index
2504% end
2505% show index pairstring if files exist
2506set(handles.series,'UserData',SeriesData)
2507
2508
2509
2510% --- Executes on button press in BATCH.
2511function BATCH_Callback(hObject, eventdata, handles)
2512% hObject    handle to BATCH (see GCBO)
2513% eventdata  reserved - to be defined in a future version of MATLAB
2514% handles    structure with handles and user data (see GUIDATA)
2515Series=read_GUI(handles.series);
2516t=struct2xml(Series);
2517save(t); %TODO: determine a xml file name
2518
2519% list_action=get(handles.ACTION,'String');% list menu action
2520% index_action=get(handles.ACTION,'Value');% selected string index
2521% action= list_action{index_action}; % selected string
2522
2523%% defining the ACTION function handle
2524path_series=which('series');
2525list_path=get(handles.ACTION,'UserData');
2526index=get(handles.ACTION,'Value');
2527fct_path=list_path{index}; %path stored for the function ACTION
2528if ~isequal(fct_path,path_series)
2529    eval(['spath=which(''' action ''');']) %spath = current path of the selected function ACTION
2530    if ~exist(fct_path,'dir')
2531        msgbox_uvmat('ERROR',['The prescibed function path ' fct_path ' does not exist'])
2532        return
2533    end
2534    if ~isequal(spath,fct_path)
2535        addpath(fct_path)% add the prescribed path if not the current one
2536    end
2537end
2538eval(['h_fun=@' action ';'])%create a function handle for ACTION
2539if ~isequal(fct_path,path_series)
2540        rmpath(fct_path)% add the prescribed path if not the current one   
2541end
2542
2543h_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.