source: trunk/src/series.m @ 372

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

many bugs repaired.

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