source: trunk/src/series.m @ 89

Last change on this file since 89 was 89, checked in by sommeria, 14 years ago

many bug corrections and cleaning. Activation of the BW option in uvmat. Improvement of the interaction of get_field with uvmat.

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