source: trunk/src/series.m @ 341

Last change on this file since 341 was 341, checked in by sommeria, 12 years ago

various bugs corrected

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