source: trunk/src/series.m @ 339

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

name2display replaced by fileparts_uvmat and find_file_series in series.
name2display partially replaced in civ.m (to be continued)
series.fig reorganized with panels.

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